// JavaScript Document
//------redirect to state page based on country id---
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;//to check date
	var emailPat = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;//to check email
	var phonePat=/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;//to check phone number in US format


function funSubmit(formName,action)
{
	doc=eval("document."+formName);
	doc.action=action;
	doc.submit();
}

/*--------------Home page-------------------------*/
function getState(countryId)
{
	var url  = "ajax_getState.php?countryId="+countryId;
	passvalue(url,"images");	
}
function getCity(stateId)
{
	var url  = "ajax_getCity.php?stateId="+stateId;
	passvaluee(url,"images");
}
function getCountryCity(countryId) {
    var url = "ajax_getCity.php?countryId=" + countryId;
    passvaluee(url, "images");
}
function clearCity() {
    document.getElementById('div_combo').innerHTML = '<select name="cmbCity" class="list_box"><option value="0">--- Please Select---</option></select>';
}
function funSrch()
{
	var cityName="";
	if(document.frmHome.txtCode.value=="")
	{
			if(document.frmHome.cmbCity.value=="0")	
			{
				alert("Please choose a city.");	
				document.frmHome.cmbCity.focus();
				return false;
			}
			cityName=document.frmHome.cmbCity.options[document.frmHome.cmbCity.selectedIndex].text;
			//alert(cityName);
			//htaccess
			//document.frmHome.action="srchResult.php?cityName="+cityName;//"city/"+cityName+".html";;
			document.frmHome.action="city/"+cityName;

	}
	else
	{
		document.frmHome.action="city/property/search/"+document.frmHome.txtCode.value;
	}
	document.frmHome.submit();
}

function funKeySrch(e)
{
	if(e.keyCode==13)	
	{
		funSrch();	
	}
}
//------------Inquiries.php-------------//
function validateInquiries(formName,from,HOST)
{
	formName=eval("document."+formName);
	//alert(formName);
	if(formName.txtFirstName.value=="")
	{
		alert("Please enter First Name.");
		formName.txtFirstName.focus();
		return false;
	}
	if(formName.txtLastName.value=="")
	{
		alert("Please enter Last Name.");
		formName.txtLastName.focus();
		return false;
	}
	
	if(formName.txtEmail.value=="")
	{
		alert("Please enter Email.");
		formName.txtEmail.focus();
		return false;
	}
		//pattern to check email
	

		if(!emailPat.test(formName.txtEmail.value))
	{
	  	alert("Invalid email address.");
	  	formName.txtEmail.focus();
	  	 return false;
	}

			if(formName.txtConfirmEmail.value=="")
	{
		alert("Please enter Confirm Email.");
		formName.txtConfirmEmail.focus();
		return false;
	}

	//pattern to check email
	if(!emailPat.test(formName.txtConfirmEmail.value))
	{
	  	alert("Invalid email address.");
	  	formName.txtConfirmEmail.focus();
	  	 return false;
	}
	//check if email & confirm email are same
	var email1=formName.txtEmail.value;
	var email2=formName.txtConfirmEmail.value;
	if(!(email1==email2))
	{
		alert("Please enter the Confirm Email correctly");
		formName.txtConfirmEmail.focus();
		return false;
	}
	
	if(trim(formName.txtCountry.value)=="")
	{
		alert("Please enter your country.");
		formName.txtCountry.focus();
		return false;
	}

	/*if(formName.preferred[1].checked && trim(formName.txtPhone.value)=="")
	{
		alert("Please enter the phone number");
		formName.txtPhone.focus();
		return false;	
	}*/
	if(trim(formName.txtPhone.value)=="")
	{
		alert("Please enter the phone number");
		formName.txtPhone.focus();
		return false;	
	}
	if(from==1)//from enquiry form
	{
		if(formName.drpCountry.value=="0")
		{
			alert("Please select a country.");
			formName.drpCountry.focus();
			return false;
		}
		if(formName.drpCity.value=="0")
		{
			alert("Please select a City.");
			formName.drpCity.focus();
			return false;
		}
	}
	/*if(!phonePat.test(formName.txtPhone.value) && trim(formName.txtPhone.value)!="")
	{
		alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  formName.txtPhone.focus();
      return false;
	}*/
	/*if(formName.txtWorkphone.value=="")
	{
		alert("Please enter Work Phone.");
		formName.txtWorkphone.focus();
		return false;
	}*/
		//check if work phone is valid
    
 /*	if(!phonePat.test(formName.txtWorkphone.value) && formName.txtWorkphone.value!="")
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  formName.txtWorkphone.focus();
      return false;
   }*/
	/*if(formName.txtHomephone.value=="")
	{
		alert("Please enter Home Phone.");
		formName.txtHomephone.focus();
		return false;
	}*/
		//check if home phone is valid
    
 	/*if(!phonePat.test(formName.txtHomephone.value) && formName.txtHomephone.value!="")
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  formName.txtHomephone.focus();
      return false;
   }*/
	/*if(formName.txtCellphone.value=="")
	{
		alert("Please enter CellPhone.");
		formName.txtCellphone.focus();
		return false;
	}*/
	//check if cell is valid
   	/*if(!phonePat.test(formName.txtCellphone.value) &&  formName.txtCellphone.value!="")
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  formName.txtCellphone.focus();
      return false;
   }*/
   		/*if(formName.txtInquiryDate.value=="")
	{
		alert("Please enter Inquiry date.");
		formName.txtInquiryDate.focus();
		return false;
		
	}
		//check if date is valid

    var matchArray2 = formName.txtInquiryDate.value.match(datePat); // is the format ok?

		if (matchArray2 == null)
	{
		alert("Please enter valid date");
		return false;
    }*/
   
	if(formName.txtCheckIn.value=="")
	{
		alert("Please enter Check in date.");
		formName.txtCheckIn.focus();
		return false;
		
	}
	//check if date is valid

    var matchArray = formName.txtCheckIn.value.match(datePat); // is the format ok?

		if (matchArray == null)
	{
		alert("Please enter valid date");
		return false;
    }

		if(formName.txtCheckOut.value=="")
	{
		alert("Please enter Check out date.");
		formName.txtCheckOut.focus();
		return false;
	}
		//check if date is valid
	    var matchArray1 = formName.txtCheckOut.value.match(datePat); // is the format ok?

	if (matchArray1 == null)
	{
		alert("Please enter valid date");
		return false;
    }
	if(formName.txtNightNo.value=="")
	{
		alert("Please enter No Of Nights to stay.");
		formName.txtNightNo.focus();
		return false;
	}
	if(formName.drpAdults.value=="0")
	{
		alert("Please select No Of Adults.");
		formName.drpAdults.focus();
		return false;
	}
	if(formName.txtChildren.value=="")
	{
		alert("Please enter No Of Children below 12.");
		formName.txtChildren.focus();
		return false;
	}
	
	/*if(formName.txtChildren.value >= 12)
	{
		alert(" No Of Children. must not be greater than 12");
		formName.txtChildren.focus();
		return false;
	}*/
	if(formName.txtChildAbove.value=="")
	{
		alert("Please enter No Of Children above 12.");
		formName.txtChildAbove.focus();
		return false;
	}
	if(formName.drpProperty.value=="0")
	{
		alert("Please select property.");
		formName.drpProperty.focus();
		return false;
	}
	formName.action =HOST+"/addInquiry.php?from="+from;
	formName.submit();

	
}
function changePhoneStatus(formName)
{
	formName=eval("document."+formName);
	if(formName.preferred[1].checked)
	{
		document.getElementById('div_phone').innerHTML="<span class='textred'>&nbsp;*</span>" ;
	}
	else
	{
		document.getElementById('div_phone').innerHTML="&nbsp;" ;
	}
}
function getCityByCtryId(countryId)
{
	var url  = "ajax_getCityByCtry.php?countryId="+countryId;
	passvalue(url,"images");		
}
/*--------------------------Search Result Page------------------------------------------------*/

/*--------------------------Search Result Page------------------------------------------------*/
// function is used to srchResultpage -when property type is changed / search button function
function ajaxSrchPrty1(url, pg,index,type,so,propTypeId)
{ 
	for(i=0;i<3;i++)
	{
		if(document.frmSrch.chkSort[i].checked==true)	
		{
			var chkValue=i;
		}
	}
	
	if(document.frmSrch.drpProptype.value!=propTypeId)
	{		
	
	//For htaccess
		
		//var url = url+"/srchResult.php?";
		var url = url+"/city/"+document.frmSrch.cityName.value+"/"+document.frmSrch.chkSort[chkValue].value;
		//sort
		//url=url+"sort="+document.frmSrch.chkSort[chkValue].value;
		document.frmSrch.action=url;
		document.frmSrch.submit();
	}	
	else// property type is nto changed
	{
		ajaxSrchPrty(url+"/ajax_srchProperty.php",pg,index,type,so);	
		
	}

	
}
// function is used in srchResultpage-paging
function ajaxSrchPrty(url, pg,index,type,so)
{ 
	var url  = url+"?";
	for(i=0;i<3;i++)
	{
		if(document.frmSrch.chkSort[i].checked==true)	
		{
			var chkValue=i;
		}
	}
	//country id
	if(trim(document.frmSrch.cmbCountry.value)!="0")		
		url=url+"&cmbCountry="+document.frmSrch.cmbCountry.value;	
	//state id
	if(trim(document.frmSrch.cmbState.value)!="0")
		url=url+"&cmbState="+document.frmSrch.cmbState.value;	
	//cityname
	if(document.frmSrch.cityName.value!="")	
		url=url+"&cityName="+trim(document.frmSrch.cityName.value);
	//property code	
	if(document.frmSrch.txtCode.value!="" && document.frmSrch.txtCode.value!="" )
		url=url+"&txtCode="+document.frmSrch.txtCode.value;	
	//price category
	if(document.frmSrch.ptyCategoryId.value!="0")
		url=url+"&ptyCategoryId="+document.frmSrch.ptyCategoryId.value;
	//property type
	if(document.frmSrch.drpProptype.value!="0")	
		url=url+"&drpProptype="+document.frmSrch.drpProptype.value;	
	//paging param
	url=url+"&pg="+pg+"&index="+index+"&type="+type+"&so="+so;
	//sort
	url=url+"&sort="+document.frmSrch.chkSort[chkValue].value;
	//alert(url);
	passvalue(url,"images");
	
	
}
function redirPropertyDetails(url)
{
	document.frmSrch.action=url;
	document.frmSrch.submit();
}
//function cityPropertySrch(cityName,propTypeId,HOST)
function cityPropertySrch(HOST,typeId)
{
	
	/*document.frmSrch.hidCityName.value=cityName;
	document.frmSrch.hidTypeId.value=propTypeId;	
	document.frmSrch.action=HOST+"/srchResult.php?cityName="+cityName;	*/
	
	document.frmSrch.drpProptype.value=typeId;
	
	//For htaccess
	//document.frmSrch.action=HOST+"/srchResult.php";
	document.frmSrch.action=HOST+"/city/"+document.frmSrch.cityName.value;
	document.frmSrch.submit();
}

/*--------------propertyDetails.php--------------------------*/
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

function ajaxRoom(serverPath,pg,index,type,so)//url, 
{ 
	var propertyId=document.frmProperty.hidPid.value;
	var cityName=document.frmProperty.hidCityName.value;
	var pname=document.frmProperty.hidPname.value;
	//var url  = url+"?"+"pg="+pg+"&type="+type+"&so="+so+"&index="+index+"&pId="+propertyId;
	//fillupRoom();
	var url=serverPath+"/propertyDetails.php?cityName="+cityName+"&pName="+pname+"&pId="+propertyId+"&room=yes"+"&pg="+pg+"&index="+index;//"/city/"+cityName+"/"+pname+"/"+propertyId+"/room/pg"+pg+"/in"+index+".html";
	document.frmProperty.action=url;
	document.frmProperty.submit();
	//passvalue(url);
}

	function ajaxRoom1(serverPath,pg,index,type,so)//url, 
{ 
	var propertyId=document.frmProperty.hidPid.value;
	var cityName=document.frmProperty.hidCityName.value;
	var pname=document.frmProperty.hidPname.value;
	var pcode=document.frmProperty.hidPCode.value;
	//var url  = url+"?"+"pg="+pg+"&type="+type+"&so="+so+"&index="+index+"&pId="+propertyId;
	//fillupRoom();
	//Commented for url rewriting
	//	var url=serverPath+"/propertyDetails.php?cityName="+cityName+"&pName="+pname+"&pId="+propertyId+"&room=yes"+"&pg="+pg+"&index="+index;
	url=serverPath+"/city/"+cityName+"/property/"+pcode+"/room/pg"+pg+"/in"+index;
	document.frmProperty.action=url;
	document.frmProperty.submit();
	//passvalue(url);
}


/*----------------Tell a friend-------------------------------*/
function funTellFriend()
{
	if(document.frmTell.txtUname.value=="")	
	{
		alert("Please enter your name.");	
		document.frmTell.txtUname.focus();
		return false;
	}
	if(document.frmTell.txtUEmail.value=="")	
	{
		alert("Please enter your email address.");	
		document.frmTell.txtUEmail.focus();
		return false;
	}
	if(!emailPat.test(document.frmTell.txtUEmail.value))
	{
	  	alert("Invalid email address.");
	  	document.frmTell.txtUEmail.focus();
	  	 return false;
	}
	if(document.frmTell.txtFEmail.value=="")	
	{
		alert("Please enter your friend's email address.");	
		document.frmTell.txtFEmail.focus();
		return false;
	}
	/*if(!emailPat.test(document.frmTell.txtFEmail.value))
	{
	  	alert("Invalid email address.");
	  	document.frmTell.txtFEmail.focus();
	  	 return false;
	}*/
	if(document.frmTell.txtComments.value=="")	
	{
		alert("Please enter your comments.");	
		document.frmTell.txtComments.focus();
		return false;
	}
	url="tellFriend1.php?uName="+document.frmTell.txtUname.value+"&uEmail="+document.frmTell.txtUEmail.value+"&fEmail="+document.frmTell.txtFEmail.value+"&comments="+document.frmTell.txtComments.value+"&link="+document.frmTell.txtHttp.value;
	passvalue(url,"images");
}

/*--------------------join Now----------------------------*/
function getStateByCtryId(countryId)
{
	url="ajax_getStateByCtryId.php?countryId="+countryId;
	passvalue(url,"images");
}
function getCityByStateId(stateId)
{
	url="ajax_getCityByStateId.php?stateId="+stateId;	
	passvaluee(url,"images");
}
function funJoinNow()
{
	if(document.frmJoin.txtFirstName.value=="")
	{
		alert("Please enter your first name.");	
		document.frmJoin.txtFirstName.focus();
		return false;
	}
	if(document.frmJoin.txtLastName.value=="")
	{
		alert("Please enter your last name.");	
		document.frmJoin.txtLastName.focus();
		return false;
	}
	if(document.frmJoin.txtAddress.value=="")
	{
		alert("Please enter your address.");	
		document.frmJoin.txtAddress.focus();
		return false;
	}
	if(document.frmJoin.drpCountry.value=="0")
	{
		alert("Please select a country.");	
		document.frmJoin.drpCountry.focus();
		return false;
	}
	if(document.frmJoin.drpState.value=="0")
	{
		alert("Please select a state.");	
		document.frmJoin.drpState.focus();
		return false;
	}
	if(document.frmJoin.drpCity.value=="0")
	{
		if(trim(document.frmJoin.txtyourcity.value)=="")
		{
		alert("Please select a city.");	
		document.frmJoin.drpCity.focus();
		return false;
		}
	}
	if(document.frmJoin.txtZip.value=="")
	{
		alert("Please enter zip code.");	
		document.frmJoin.txtZip.focus();
		return false;
	}
	if(document.frmJoin.txtLoginName.value=="")
	{
		alert("Please enter Login Name.");	
		document.frmJoin.txtLoginName.focus();
		return false;
	}
	if(document.frmJoin.txtPassword.value=="")
	{
		alert("Please enter password.");	
		document.frmJoin.txtPassword.focus();
		return false;
	}
	
	/* if(checkint(document.frmJoin.txtZip.value)==false)
	{
	    alert("Please enter valid zip.");
	    document.frmJoin.txtZip.value="";
	    document.frmJoin.txtZip.focus();
	    return false;
	}	*/
	if(document.frmJoin.txtEmail.value=="")
	{
		alert("Please enter email id.");	
		document.frmJoin.txtEmail.focus();
		return false;
	}
	if(!emailPat.test(document.frmJoin.txtEmail.value))
	{
	  	alert("Invalid email address.");
	  	document.frmJoin.txtEmail.focus();
	  	 return false;
	}
	/*if(document.frmJoin.txtWorkphone.value=="")
	{
		alert("Please enter work phone.");	
		document.frmJoin.txtWorkphone.focus();
		return false;
	}*/
	
	/*if(document.frmJoin.txtWorkphone.value!="" && !phonePat.test(document.frmJoin.txtWorkphone.value))
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  document.frmJoin.txtWorkphone.focus();
      return false;
   }*/
/*	if(document.frmJoin.txtHomephone.value=="")
	{
		alert("Please enter Home Phone.");
		document.frmJoin.txtHomephone.focus();
		return false;
	}
	*/	//check if home phone is valid
    
 /*	if(document.frmJoin.txtHomephone.value!="" && !phonePat.test(document.frmJoin.txtHomephone.value))
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  document.frmJoin.txtHomephone.focus();
      return false;
   }*/
	/*if(document.frmJoin.txtCellphone.value=="")
	{
		alert("Please enter CellPhone.");
		document.frmJoin.txtCellphone.focus();
		return false;
	}*/
	//check if cell is valid
  /* 	if(document.frmJoin.txtCellphone.value!="" && !phonePat.test(document.frmJoin.txtCellphone.value))
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	  document.frmJoin.txtCellphone.focus();
      return false;
   }*/
	/*if(document.frmJoin.txtFax.value=="")
	{
		alert("Please enter fax number.");
		document.frmJoin.txtFax.focus();
		return false;
	}*/
	//check if cell is valid
   /*	if(document.frmJoin.txtFax.value!="" && !phonePat.test(document.frmJoin.txtFax.value))
   {
      alert("The fax number you entered is not valid.\r\nPlease enter a fax number with the format xxx-xxx-xxxx.");
	  document.frmJoin.txtFax.focus();
      return false;
   }*/
   
	document.frmJoin.action="joinNow1.php";
	document.frmJoin.submit();
}

function Choose_city()
{
	if((document.frmJoin.drpCity.value)=="new")
	{
		document.getElementById('choose_city').innerHTML="<input name='txtCity' type='text' class='text_box' />";
	}
}


/*---------- informadmin.php----------------*/
function validateInformAdmin()
{
	
	if(document.frminform.drpCountry.value=="0")
	{
		alert("Please select country.");	
		document.frminform.drpCountry.focus();
		return false;
	}
	else if(document.frminform.drpState.value=="0")
	{
		alert("Please select state.");	
		document.frminform.drpState.focus();
		return false;
	}
	else if(trim(document.frminform.city.value)=="")
	{
		alert("Please enter desired city name.");	
		document.frminform.city.focus();
		return false;
	}
	else
		return true;
		
		
}
//Function used in joinNow.php for city
function callCity()
{
	if(document.frmJoin.drpCity.value=="0")
	{
		document.getElementById("defcity").innerHTML="&nbsp;";
		document.getElementById("ycity").innerHTML="<span class='textred'>&nbsp;*</span>";
	}
	else
	document.frmJoin.txtyourcity.value="";
}
function getStateByCtryValue(countryId)
{
	document.getElementById("defcity").innerHTML="<span class='textred'>&nbsp;*</span>";
	document.getElementById("ycity").innerHTML="&nbsp;";
	url="ajax_getStateByCtryValue.php?countryId="+countryId;
	passvalue(url,"images");
}
function getCityByStateValue(stateId)
{
	document.getElementById("defcity").innerHTML="<span class='textred'>&nbsp;*</span>";
	document.getElementById("ycity").innerHTML="&nbsp;";
	url="ajax_getCityByStateValue.php?stateId="+stateId;	
	passvaluee(url,"images");
}
//end Function used in joinNow.php for city