var calWin = null;
var calendarField;
function popCalendar( field,dt,choice ) {
    calendarField = field;
    window.open( pathinfo + '/property/popcalendar.php?dialog=1&callback=setCalendar&date='+dt+"&choice="+choice,'calwin', 'top=250,left=250,width=280, height=250, scollbars=false' );
}

function setCalendar( idate,fdate ) {
    dt=idate.substr(4,2)+"/"+idate.substr(6,2)+"/"+idate.substr(0,4);
	fld_fdate = eval( 'document.frm.' + calendarField );
    fld_fdate.value = dt;
	fld_fdate.focus();
}


function valid(){	

	var mphone;
	var meamil;
	var trimFname;
	var trimLname;
	var strValidChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var strValidPhoneChars = "0123456789";
	var blnResult = true;
	
	trimFname=document.frm.fname.value;
	while (trimFname.substring(0,1) == ' ')
	{
	  trimFname = trimFname.substring(1,trimFname.length);
	}
	while (trimFname.substring(trimFname.length-1,trimFname.length) == ' ')
	{
			trimFname = trimFname.substring(0,trimFname.length-1);
	}
	/*for (i = 0; i < trimFname.length && blnResult == true; i++){
		strChar = trimFname.charAt(i);
		if (strValidChars.indexOf(strChar) == -1){
			alert("Please enter your valid first name without special characters");
			document.frm.fname.focus();
			blnResult = false;
			return;
		}
	}*/
	
	trimLname=document.frm.lname.value;
	while (trimLname.substring(0,1) == ' ')
	{
	  trimLname = trimLname.substring(1,trimLname.length);
	}
	while (trimLname.substring(trimLname.length-1,trimLname.length) == ' ')
	{
			trimLname = trimLname.substring(0,trimLname.length-1);
	}
	/*for (i = 0; i < trimLname.length && blnResult == true; i++){
		strChar = trimLname.charAt(i);
		if (strValidChars.indexOf(strChar) == -1){
			alert("Please enter your valid last name without special characters");
			document.frm.lname.focus();
			blnResult = false;
			return;
		}
	}*/
	memail=document.frm.email.value;
	if(memail==""){
		alert("An email address is required.  Please enter your email address to continue.");
		document.frm.email.focus();
		return;
	}
		while (memail.substring(0,1) == ' ')
		{
			  memail = memail.substring(1,memail.length);
		}
		while (memail.substring(memail.length-1,memail.length) == ' ')
		{
				memail = memail.substring(0,memail.length-1);
		}
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(memail))){
	     alert("An email address is required.  Please enter your email address to continue.");
    	document.frm.email.focus();
    	return;
	}
	if(document.frm.cfemail.value!=document.frm.email.value){
     alert("The confirm email address must match the email address above.  Please make this correction to continue.");
     document.frm.cfemail.focus();
     return;
   }
   if(document.frm.cfemail.value!=false)
   {
    var found1=0;
    if((document.frm.cfemail.value.indexOf("@")==-1)||(document.frm.cfemail.value.indexOf(".")==-1))
    {
    found1=1
    }
    if(document.frm.cfemail.value.indexOf(" ")>0)
    {
    found1=1
    }
    if(found1==1)
    {
      alert("Please confirm your email address to continue ");
      document.frm.cfemail.focus();
      return;
    }
    if (document.frm.cfemail.value.length==0)
    {
      alert("Please confirm your email address to continue ");
      return;
    }
    if(document.frm.cfemail.value==false)
    {
      alert("Please confirm your email address to continue ");
      document.frm.cfemail.focus();
      return;
    }
    if(document.frm.cfemail.value!=document.frm.email.value){
      alert("The confirm email address is same as the email is required .  Please enter a same confirm email address ");
      document.frm.cfemail.focus();
      return;
    }
   }
	
	mphone=document.frm.phone.value;
	if((mphone=="") || (mphone==false)) {
		alert("Please enter your valid phone number to continue ");
		document.frm.phone.focus();
		return;
	}
	if((document.frm.phone.value=="") || (document.frm.phone.value==false)) {
		alert("Please enter your valid phone number to continue ");
		document.frm.phone.focus();
		return;
	}


	/*while (mphone.substring(0,1) == ' ')
	{
		  mphone = mphone.substring(1,mphone.length);
	}
	while (mphone.substring(mphone.length-1,mphone.length) == ' ')
	{
			mphone = mphone.substring(0,mphone.length-1);
	}
	for (i = 0; i < mphone.length && blnResult == true; i++)
	{
		strChar = mphone.charAt(i);
		if (strValidPhoneChars.indexOf(strChar) == -1)
		{
			alert("Phone number is a numeric field.  Either leave the phone number blank or enter a valid phone number without any “-“ or “/” etc");
			document.frm.phone.focus();
			blnResult = false;
			return;
		}
	}*/

	/*
	if(document.frm.secText.value == '')
	{
		alert(" Please enter security code to continue");
				document.frm.secText.focus();
				return;
	}
		
	if(document.frm.secText.value != document.frm.secCodeEnc.value)
	{
		alert("Please enter the case-sensitive security code");
			document.frm.secText.focus();
				return;
	}


	if(document.frm.fdate.value == '')
	{
		alert(" Please select arrival date to continue");
				document.frm.fdate.focus();
				return;
	}
	if(document.frm.tdate.value == '')
	{
		alert(" Please select departure date to continue");
				document.frm.tdate.focus();
				return;
	}

		var dtfrom=document.frm.fdate;
		var dtTo=document.frm.tdate;
	
			
		if(dtTo.value!=""){
			if(isDate(dtTo.value,'To')==false){
   					dtTo.focus();
  					return;
				}
		}

		if(dtfrom.value!=""){
				if(isDate(dtfrom.value,'To')==false){
   					dtfrom.focus();
  					return;
				}
		}
		if(dtTo.value!="" || dtfrom.value!= ""){			
			if(compareDates(dtTo.value,dtfrom.value)==-1){
				alert("The Arrival date must be before the Departure Date.  Please reenter a valid arrival date to continue");
				dtfrom.focus();
				return;
			}
		}
		if(dtTo.value!="" || dtfrom.value!= ""){			
			if(compareDates(dtfrom.value,document.frm.curdt.value)==-1){
				alert("The Arrival date is not to be a date in the past. Please enter today's date or a future date in the arrival date field.");
				dtTo.focus();
				return;
			}
		}

		if(dtTo.value!="" || dtfrom.value!= ""){			
			if(compareDates(dtTo.value,document.frm.curdt.value)==-1){
				alert("The Arrival date must be before the Departure Date.  Please reenter a valid arrival date to continue");
				dtTo.focus();
				return;
			}
		}

		if((document.frm.comments.value==false) || (document.frm.comments.value.length < 10))
		{
			alert("Please enter a message with at least 25 characters in order to continue");
			document.frm.comments.focus();
			return;
		}
		*/
	
	document.frm.submit();
}



function textLimit(field, maxlen,fieldcap) {
	if (field.value.length > maxlen + 1)
		alert(fieldcap+' should be less than 1000 characters!');
	if (field.value.length > maxlen)
		field.value = field.value.substring(0, maxlen);
}