var invalids="/:,;!~$";			//lists the characters that shouldn't be included 

function isValid(string){
	for(var i=0; i<string.length; i++){
	  if(invalids.indexOf(string.charAt(i)) != -1)
		return false;
	}
	return true;
}
function validateMailFm(){

	var errmsg = "";
	
	// Check Name
	var tmpname = document.mailform.fname.value;
	if(tmpname=="") errmsg += "Please provide your name\n";
	if(!isValid(tmpname)) errmsg += "\"" + invalids + "\" characters are invalid for name";
	// Check email
	var tmpemail=document.mailform.femail.value;
	if (tmpemail=="") errmsg += "Please provide your email address\n";
	if(!isValid(tmpemail)) errmsg += "The email you provided is not in valid format\n";
	if(tmpemail.indexOf("@") == -1) errmsg += "The valid email format is name@domain.ext \n";
	if(tmpemail.indexOf(".") == -1) ;
	// Check Subject
	var tmpsub = document.mailform.fsubject.value;
	if(tmpsub=="") errmsg += "Please provide the subject of your inquiry\n";
	if(!isValid(tmpsub)) errmsg += "\"" + invalids + "\" characters are invalid in subject field";
	// Check message
	var tmpmsg = document.mailform.fmessage.value;
	if(tmpmsg=="") errmsg += "Please provide the message of your inquiry\n";
	//if(!isValid(tmpmsg)) errmsg += "Please remove \"" + invalids + "\" characters";
	
	// Display error message if any	
	if(errmsg!=""){
		alert(errmsg);
		return false;
	}else{
		document.mailform.submit();
	}
}

var myimages=new Array();

function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image();
		myimages[i].src=preloadimages.arguments[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_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_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];}
}



var selectedcheckin = new Date();	// place holder for current selected checkin date
//var c;
var checkinoffset = 1;				// number of days in advance the user can book
var yearoffset = 1;					// number of year in advance the user can book
var now = new Date();
//var src;
var calinselect;					// flags showing if checkin date calendar is selected



// check if user has provided checkin date
function checkin(){
    if(document.getElementsByName("expbook").length > 0) {
	if(document.expbook.checkindate.value == ""){
		calout.disabledDatesExpression=""; 		// clear the disable dates of checkout cal. i.e. all dates are enabled
		calout.addDisabledDates(null,formatDate(now,"MMM dd, yyyy"));
		calout.addDisabledDates(formatDate(now,"MMM dd, yyyy"),null);
	}		
    }
    if(document.getElementsByName("booking").length > 0){	// set flag that the checkin cal is selected							
	if(document.booking.checkindate.value == ""){
		calout.disabledDatesExpression=""; 		// clear the disable dates of checkout cal. i.e. all dates are enabled
		calout.addDisabledDates(null,formatDate(now,"MMM dd, yyyy"));
		calout.addDisabledDates(formatDate(now,"MMM dd, yyyy"),null);
	}		
     }
}

// edit or change this function to specify behavior of the checkin date calendar
function checkinclick(calitem){
	calitem.disabledDatesExpression=""; 		// clear the disable dates of checkout cal. i.e. all dates are enabled
 	calinselect=true;
	if(document.getElementsByName("booking").length > 0){	// set flag that the checkin cal is selected							
		document.booking.checkoutdate.value=""; 	// clear checkout date text field
 		document.booking.nights.value=""; 			// clear number of nights text field
	}
	if(document.getElementsByName("expbook").length > 0) {
		document.expbook.checkoutdate.value="";
	}
	return false;
}


// edit or change this function to specify behavior of the checkout date calendar
function checkoutclick(){
	calinselect=false;							// clear the flag that checkin cal is selected
}

// this function is included in the CalendarPopup.js to set the checkout date according
// to the checkin date selected
function setcheckoutdate(checkoutcal,day,nightobj){
	if(calinselect==true){						// check if checkin cal is selected
		// disable dates in checkout calendar according to the checkin date selected
		checkoutcal.addDisabledDates(null,formatDate(day,"MMM dd, yyyy"));	
		selectedcheckin = day;
	}else{
		// if checkout cal is selected, calculate the number of nights and display it
		var nights = day - selectedcheckin;
		if(nightobj){
			nightobj.value = Math.round(nights/86400000);
		}
	}
}

// This function is called when number of nights text field is changed
// the checkout date will be changed according to the number of nights
function updatecheckoutdate(coobj, nobj){
	// Check if number of nights entered is number and greater than 0
	// reset the number to 1 if it isn't
	if((nobj.value<1)|| (isNaN(nobj.value))){
		nobj.value=1;
	}
	nobj.value = Math.round(nobj.value);
	var a = new Date();
	a.setTime(selectedcheckin.getTime()+60000*60*24*nobj.value);
	coobj.value=formatDate(a,"MMM dd, yyyy");
	calout.disabledDatesExpression=""; 		// clear the disable dates of checkout cal. i.e. all dates are enabled
	calout.addDisabledDates(null,formatDate(selectedcheckin,"MMM dd, yyyy"));
}
