var aCh="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var dCh="0123456789-";
var sCh="ÀÂÃÄÅÆÇÈÉÊËÌÍÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿŠŒŽšœžŸ'_`~()^&*+-|=<>,./\{}[] ";
var asCh=aCh + dCh + "!\"#$%&'()*+,-./:;<=>?@[\]^_`{}~";

function isAlphaNum(S) {
	var AlphaNum=aCh + dCh;
	for (var i=0; i < S.length; i++) {
		if (AlphaNum.indexOf(S.charAt(i)) == -1)
			return false;
	}
	return true;
}
function isASCII(S) {
	for (var i=0; i < S.length; i++) {
		if (asCh.indexOf(S.charAt(i)) == -1)
			return false;
	}
	return true;
}
function isName(S) {
	var cName=aCh + dCh + sCh;
	for (var i=0; i < S.length; i++) {
		if (cName.indexOf(S.charAt(i)) == -1)
			return false;
	}
	return true;
}
function isEmail(S) {
	var pass=0;
	if (window.RegExp) {
		var tempS="a";
		var tempReg=new RegExp(tempS);
		if (tempReg.test(tempS)) pass=1;
	}
	if (!pass)
		return (S.indexOf(".") > 2) && (S.indexOf("@") > 0);

	var r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2=new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(S) && r2.test(S));
}
function checkReservationsForm() {

	// Check Date Arrival
	cArrivalError = "";
	if (document.DataEntry.Arrival.value.length<1) {
		cArrivalError = "Date Arrival is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.Arrival.value)){
			cArrivalError = "Date Arrival is invalid. Please use 0-9, A-Z, "+sCh+"\n";
		}
	}
	
	//Cek Date Departure	
	cDepartureError = "";
	if (document.DataEntry.Departure.value.length<1) {
		cDepartureError = " Date Departure is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.Departure.value)){
			cDepartureError = " Date Departure is invalid. Please use 0-9, A-Z, "+sCh+"\n";
		}
	}	
	
		// Cek No People Adult	
	cAdultError = "";
	if (document.DataEntry.Adult.value.length<1) {
		cAdultError = "Your No People Adult is empty.\n"; 
	} else {
		if (isNaN(document.DataEntry.Adult.value)){
			cAdultError = "Your People Adult  is invalid. Please use 0-9, "+sCh+"\n";
		}
	}	
	
	// Check the Room Type 
	cRoomTypeError = "";
	if (document.DataEntry.RoomType.value=="0") { 
		cRoomTypeError = "Room Type is not selected.\n";
	} 
	
	// Cek Real Name	
	cRealNameError = "";
	if (document.DataEntry.RealName.value.length<1) {
		cRealNameError = "Your Name is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.RealName.value)){
			cRealNameError = "Your Name is invalid. Please use 0-9, A-Z, "+sCh+"\n";
	} else {
		if (document.DataEntry.RealName.value.length<4) { 
		cRealNameError = "Name should be at least 4 characters.\n";
			}
		}
	}	

	// Cek Address	
	cAddress1Error = "";
	if (document.DataEntry.Address1.value.length<1) {
		cAddress1Error = "Your Address is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.Address1.value)){
			cAddress1Error = "Your Address is invalid. Please use 0-9, A-Z, "+sCh+"\n";
	} else {
		if (document.DataEntry.Address1.value.length<4) { 
		cAddress1Error = "Address should be at least 4 characters.\n";
			}
		}
	}
	
// Cek City	
	cCityError = "";
	if (document.DataEntry.City.value.length<1) {
		cCityError = "Your City is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.City.value)){
			cCityError = "Your City is invalid. Please use 0-9, A-Z, "+sCh+"\n";
	} else {
		if (document.DataEntry.City.value.length<4) { 
		cCityError = "City should be at least 4 characters.\n";
			}
		}
	}	
		
	// Cek State	
	cStateError = "";
	if (document.DataEntry.State.value.length<1) {
		cStateError = "Your State is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.State.value)){
			cStateError = "Your State is invalid. Please use 0-9, A-Z, "+sCh+"\n";
	} else {
		if (document.DataEntry.State.value.length<4) { 
		cStateError = "State should be at least 4 characters.\n";
			}
		}
	}	

// Cek Country	
	cCountryError = "";
	if (document.DataEntry.Country.value.length<1) {
		cCountryError = "Your Country is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.Country.value)){
			cCountryError = "Your Country is invalid. Please use 0-9, A-Z, "+sCh+"\n";
	} else {
		if (document.DataEntry.Country.value.length<4) { 
		cCountryError = "Country should be at least 4 characters.\n";
			}
		}
	}
	
	// Cek Phone	
	cPhoneError = "";
	if (document.DataEntry.Phone.value.length<1) {
		cPhoneError = "Your Phone is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.Phone.value)){
			cPhoneError = "Your Phone is invalid. Please use 0-9, A-Z, "+sCh+"\n";
	} else {
		if (document.DataEntry.Phone.value.length<4) { 
		cPhoneError = "Phone should be at least 4 digit.\n";
			}
		}
	}	
		
	// Check the Email
	cEmailError = "";
	if (document.DataEntry.Email.value.length <1) { 
		cEmailError = "Your Email address is empty.\n";
	}	
	else { 
		dmn = document.DataEntry.Email.value.substr(document.DataEntry.Email.value.indexOf("@")+1,document.DataEntry.Email.value.length);
		if((document.DataEntry.Email.value.indexOf("@")<1) ||(dmn.indexOf("@")>-1) || (dmn.indexOf(".")<1) || (dmn.indexOf(".")>dmn.length-2)) {
			cEmailError = "Your Email address is invalid.\ne.g. : (Email@domainname.com).\n";
		}
	}
		
		
	cError = cArrivalError + cDepartureError  + cAdultError + cRoomTypeError + cRealNameError + cAddress1Error + cCityError + cStateError + cCountryError + cPhoneError + cEmailError ;
	
	if (cError.length>0) { 
		alert("Sorry, but you haven\'t filled out all fields required.\n"+cError); 
		if (cArrivalError.length>0) { document.DataEntry.Arrival.focus(); } else {
		if (cDepartureError.length>0) { document.DataEntry.Departure.focus(); } else {
		if (cAdultError.length>0) { document.DataEntry.Adult.focus();} else {
		if (cRoomTypeError.length>0) { document.DataEntry.RoomType.focus(); } else { 
		if (cRealNameError.length>0) { document.DataEntry.RealName.focus(); } else {
		if (cAddress1Error.length>0) { document.DataEntry.Address1.focus(); } else {
		if (cCityError.length>0) { document.DataEntry.City.focus(); } else {
		if (cStateError.length>0) { document.DataEntry.State.focus(); } else {
		if (cCountryError.length>0) { document.DataEntry.Country.focus(); } else { 
		if (cPhoneError.length>0) { document.DataEntry.Phone.focus(); } else { 
		if (cEmailError.length>0) { document.DataEntry.Email.focus(); } } } } } } } } } } }   
		 
	return false; 
	}
	document.DataEntry.submit();

}

function checkReservations() {
	
	// Check Date Arrival
	cArrivalError = "";
	if (document.DataEntry.Arrival.value.length<1) {
		cArrivalError = "Date Arrival is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.Arrival.value)){
			cArrivalError = "Date Arrival is invalid. Please use 0-9, A-Z, "+sCh+"\n";
		}
	}
	
	//Cek Date Departure	
	cDepartureError = "";
	if (document.DataEntry.Departure.value.length<1) {
		cDepartureError = " Date Departure is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.Departure.value)){
			cDepartureError = " Date Departure is invalid. Please use 0-9, A-Z, "+sCh+"\n";
		}
	}	

	// Cek Real Name	
	cRealNameError = "";
	if (document.DataEntry.RealName.value.length<1) {
		cRealNameError = "Your Name is empty.\n"; 
	} else {
		if (!isName(document.DataEntry.RealName.value)){
			cRealNameError = "Your Name is invalid. Please use 0-9, A-Z, "+sCh+"\n";
	} else {
		if (document.DataEntry.RealName.value.length<4) { 
		cRealNameError = "Country should be at least 4 characters.\n";
			}
		}
	}	

	// Check the Email
	cEmailError = "";
	if (document.DataEntry.Email.value.length <1) { 
		cEmailError = "Your Email address is empty.\n";
	}	
	else { 
		dmn = document.DataEntry.Email.value.substr(document.DataEntry.Email.value.indexOf("@")+1,document.DataEntry.Email.value.length);
		if((document.DataEntry.Email.value.indexOf("@")<1) ||(dmn.indexOf("@")>-1) || (dmn.indexOf(".")<1) || (dmn.indexOf(".")>dmn.length-2)) {
			cEmailError = "Your Email address is invalid.\ne.g. : (Email@domainname.com).\n";
		}
	}

	cError = cArrivalError + cDepartureError  +  cRealNameError + cEmailError ;

	if (cError.length>0) { 
		alert("Sorry, but you haven\'t filled out all fields required.\n"+cError); 
		if (cArrivalError.length>0) { document.DataEntry.Arrival.focus(); } else {
		if (cDepartureError.length>0) { document.DataEntry.Departure.focus(); } else {
		if (cRealNameError.length>0) { document.DataEntry.RealName.focus(); } else {
		if (cEmailError.length>0) { document.DataEntry.Email.focus(); } } } }    
		 
	return false; 
	}
	document.DataEntry.submit();

}

