// JavaScript Document
function openWin(theURL,winName,wWidth,wHeigt) 
	{
	sWidth = wWidth;
	sHeight = wHeigt;
	pTop = (screen.height) ? (screen.height-wHeigt)/2 : 0;
	pLeft =  (screen.width) ? (screen.width-sWidth)/2 : 0;
	settings = 'height='+sHeight+',width='+sWidth+',top='+pTop+',left='+pLeft+',toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=0'
	window.open(theURL,winName,settings);
}
function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}
function goodchars(e, goods, field)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;

keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();

// check goodkeys
if (goods.indexOf(keychar) != -1)
	return true;
// control keys
if ( key==null || key==0 || key==8 || key==9 || key==27 )
   return true;
   
if (key == 13) {
	var i;
	for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
			break;
	i = (i + 1) % field.form.elements.length;
	field.form.elements[i].focus();
	return false;
	};
// else return false
return false;
}
function handleEnter (field, event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
}
function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}
function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}
function Back()
{
	if (window.history.back) window.history.back();
}
function isEmail(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
	return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
	return false
	}
	if (str.indexOf(" ")!=-1){
	return false
	}
	return true
}
function CekPesan(theForm) 
{
	if(trim(theForm.fnama.value) == "" || trim(theForm.fnama.value) == "-") 
	{
		alert('Please type your name!');
		theForm.fnama.focus();
		return(false);
	}
	else if(trim(theForm.falamat.value) == '' || trim(theForm.falamat.value) == "-") 
	{
		alert('Please type your city!');
		theForm.falamat.focus();
		return(false);
	}
	else if (trim(theForm.femail.value) != '' && !isEmail(trim(theForm.femail.value)))
	{
		alert('Type your email or leave blank!');
		theForm.femail.focus();
		return(false);
	}
	else if(trim(theForm.fpesan.value) == '' || trim(theForm.fpesan.value) == "-") 
	{
		alert('Please type your message!');
		theForm.fpesan.focus();
		return(false);
	}
	else if(trim(theForm.fvalidasi.value) == "" || trim(theForm.fvalidasi.value) == "-") 
	{
		alert("Please type random string!");
		theForm.fvalidasi.focus();
		return(false);
	}
	return(true);
}
function cekContact(theForm) 
{
	if(trim(theForm.name.value) == "" || trim(theForm.name.value) == "-") 
	{
		alert('Please type your name!');
		theForm.name.focus();
		return(false);
	}
	else if(!isEmail(trim(theForm.email.value))) 
	{
		alert('Please type your email!');
		theForm.email.focus();
		return(false);
	}	
	else if(trim(theForm.subject.value) == "" || trim(theForm.subject.value) == "-") 
	{
		alert('Please type your subject!');
		theForm.subject.focus();
		return(false);
	}
	else if(trim(theForm.message.value) == "" || trim(theForm.message.value) == "-") 
	{
		alert('Please type your message!');
		theForm.message.focus();
		return(false);
	}
	else if(trim(theForm.fvalidasi.value) == "" || trim(theForm.fvalidasi.value) == "-") 
	{
		alert("Please type random string!");
		theForm.fvalidasi.focus();
		return(false);
	}
	return (true);
}
function setNightsDropDown()
{
	var f = document.form_booking;
	var ChkInDate;
	var ChkOutDate;
	var thisDate = new Date();
	var thisMonth = thisDate.getMonth() + 1; // need to increment arrivalMonth and arrivaldate b/c they are arrays
	var thisYear = thisDate.getFullYear();
	var thisDay = thisDate.getDate();
	DateNow = thisMonth + "/" + thisDay + "/" + thisYear;
	ChkInDate = f.month1.value + "/" + f.day1.value + "/" + f.year1.value;
	ChkOutDate = f.month2.value + "/" + f.day2.value + "/" + f.year2.value;

	var dateArrival = new Date(ChkInDate);
	var dateDepart = new Date(ChkOutDate);
	var daysBetween = getDateDifference(dateArrival, dateDepart);

	f.numnights.selectedIndex = daysBetween - 1
}
function getDateDifference(startDate, endDate)
{
	var dateDif;

	dateDif = endDate.getTime() - startDate.getTime();
	dateDif = Math.round(dateDif/(1000 * 60 * 60 * 24));
	return dateDif;
}
function cekBooking(theForm) 
{
	var ChkInDate;
	var ChkOutDate;
	var thisDate = new Date();
	var thisMonth = thisDate.getMonth() + 1; // need to increment arrivalMonth and arrivaldate b/c they are arrays
	var thisYear = thisDate.getFullYear();
	var thisDay = thisDate.getDate();
	DateNow = thisMonth + "/" + thisDay + "/" + thisYear;
	ChkInDate = theForm.month1.value + "/" + theForm.day1.value + "/" + theForm.year1.value;
	ChkOutDate = theForm.month2.value + "/" + theForm.day2.value + "/" + theForm.year2.value;
	if(trim(theForm.guestname.value) == "" || trim(theForm.guestname.value) == "-") 
	{
		alert("Please enter your full name!");
		theForm.guestname.focus();
		return(false);
	}
	else if(trim(theForm.address.value) == "" || trim(theForm.address.value) == "-") 
	{
		alert("Please enter your address!");
		theForm.address.focus();
		return(false);
	}
	else if(trim(theForm.phone.value) == "" || trim(theForm.phone.value) == "-") 
	{
		alert("Please enter your phone!");
		theForm.phone.focus();
		return(false);
	}
	else if(!isEmail(trim(theForm.email.value))) 
	{
		alert("Please enter your email!");
		theForm.email.focus();
		return(false);
	}	
	else if (Date.parse(ChkInDate) >= Date.parse(ChkOutDate))
	{
		alert ("The Check Out Date needs to be after the Check In Date.");
		theForm.day1.focus();
		return (false);
	}
	else if (Date.parse(ChkInDate) < Date.parse(theForm.hiddenDate.value))
	{
		alert ("You are not allowed to book any days earlier than 2");
		theForm.day1.focus();
		return (false);
	}
	else if(trim(theForm.numnights.value) == "") 
	{
		alert("Please select Number of nights");
		theForm.numnights.focus();
		return(false);
	}
	else if(trim(theForm.fvalidasi.value) == "" || trim(theForm.fvalidasi.value) == "-") 
	{
		alert("Please type random string!");
		theForm.fvalidasi.focus();
		return(false);
	}
	return (true);
}
function showDIV(objName)
{
	hideDIV(objName);
	document.getElementById(objName).style.display="block"
}
function hideDIV(objName)
{
	document.getElementById(objName).style.display="none"
}

