
// function to trim the spaces
function Trim(sString)
{
	return leftTrim(rightTrim(sString));
}

//trims leading spaces
function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

// trims trailing spaces
function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

// Checks whether the Email is Valid or not
function validEmail(str,field) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	// check for empty or not
	if(str=="")
	{
		alert('Please enter Email address'+field);
		return false;
	}	
	else
	{	for(var j=0; j<str.length; j++)
		 {	var alphaa = str.charAt(j);
			var hh = alphaa.charCodeAt(0);
			if(j==0)
			{	if((hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==32); // allowed chars
				else 
				{	alert("Email Id should start with a character"+field)
					return false;
				}
			}
			else
			{	if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==32 || hh==46 || hh==95 || hh==64); // allowed chars
				else 
				{	alert("Please enter a valid Email address"+field)
					return false;
				}
			}
		}				  
	}
	if (str.indexOf(at)==-1){
	   alert("Please enter a valid Email address"+field)
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please enter a valid Email address"+field)
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter a valid Email address"+field)
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter a valid Email address"+field)
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid Email address"+field)
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter a valid Email address"+field)
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Please enter a valid Email address"+field)
		return false
	 }

	 return true					
}

// Check for specific set of chars
function alphanumeric(alphane)
{	 var srcString = alphane;
	 for(var j=0; j<srcString.length; j++)
	 {	var alphaa = srcString.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if(j==0)
		{	if((hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==32);
			else 
				return false;
		}
		else
		{	if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==32 || hh==46);
			else 
				return false;
		}
	  }			  
	 return true;
}

// Contact page Validations
function validateContact(frm)
{	var name = Trim(frm.txtName.value);
	//var mlsno = Trim(frm.txtMls.value);
	var phone = Trim(frm.txtPhone.value);
	var comments = Trim(frm.txtComments.value);

	if(name=='')
	{
		alert("Please enter Name");
		frm.txtName.focus();
		return false;
	}
	if (!alphanumeric(name))
	{	alert('Special characters are not allowed in Name');
		frm.txtName.focus();
		return false;
	}
	if(Trim(frm.txtEmail.value)=='')
	{

		alert("Please enter your Email address");
		frm.txtEmail.focus();
		return false;
	}
	if(Trim(frm.txtEmail.value)!='')
	{
		if(!validEmail(frm.txtEmail.value," in 'Your Email Address'"))
		{
			frm.txtEmail.focus();
			return false;
		}
	}
	/*
	if((mlsno!="" && !IsNumber(mlsno)) || mlsno.length != 6)
	{
		alert("Please enter a valid MLS Number");
		frm.txtMls.focus();
		return false;
	}
	*/
	if((phone!="") && !validPhone(phone))
	{
		alert("Please enter a valid Phone Number with area code \n Ex : ###-###-####");
		frm.txtPhone.focus();
		return false;
	}
	if(comments=='')
	{
		alert("Please Enter Comments");
		frm.txtComments.focus();
		return false;
	}
}


// Function to Pass the Hidden Vales of Residential Page
function hPassValues()
{
	var iFrame = parent.frames[0]; //Get the IFRAME		
	var minBeds = parseInt(document.frmMap.selMinBedRooms.value)
	var maxBeds = parseInt(document.frmMap.selMaxBedRooms.value)
	var minSqft = parseInt(document.frmMap.selMinSqft.value)
	var maxSqft = parseInt(document.frmMap.selMaxSqft.value)
	var minPrice = parseInt(document.frmMap.selMinPrice.value)
	var maxPrice = parseInt(document.frmMap.selMaxPrice.value)
	var minBaths = parseInt(document.frmMap.selMinBathRooms.value)
	var maxBaths = parseInt(document.frmMap.selMaxBathRooms.value)
	var minAcres = parseInt(document.frmMap.selMinAcres.value)
	var maxAcres = parseInt(document.frmMap.selMaxAcres.value)
	if(document.frmMap.chkOffenders.type=='checkbox')
		var offender = document.frmMap.chkOffenders.checked;
	var viewMap = document.frmMap.chkGMap.checked;

	//	var minLots = document.frmMap.selMinPrice.value
	//	var maxLots = document.frmMap.selMaxPrice.value
	//	var county = document.frmMap.selMinPrice.value
	//	var city = document.frmMap.selMaxPrice.value
	
	if(minBeds!="Any" && maxBeds!="Any" && minBeds > maxBeds)
	{
		alert("Please enter a valid range for Bedrooms.");
		document.frmMap.selMinBedRooms.focus();
		return false;
	}
	if(minSqft!="Any" && maxSqft!="Any" && minSqft > maxSqft)
	{
		alert("Please enter a valid range for Living Square Feet.");
		document.frmMap.selMinSqft.focus();
		return false;
	}
	if(minBaths!="Any" && maxBaths!="Any" && minBaths > maxBaths)
	{
		alert("Please enter a valid range for Bathrooms.");
		document.frmMap.selMinBathRooms.focus();
		return false;
	}
	if(minAcres!="Any" && maxAcres!="Any" && minAcres!="100+" && maxAcres!="100+" && minAcres > maxAcres)
	{
		alert("Please enter a valid range for Acres.");
		document.frmMap.selMinAcres.focus();
		return false;
	}
	if(minPrice!="Any" && maxPrice!="Any" && minPrice > maxPrice)
	{
		alert("Please enter a valid range for Price.");
		document.frmMap.selMinPrice.focus();
		return false;
	}

//	document.frmMap.hdnValues.value='?hdnBedRoomVal='+document.frmMap.selBedRooms.value+'&hdnCityVal='+document.frmMap.selCity.value+'&hdnBathRoomVal='+document.frmMap.selBathRooms.value+'&hdnPriceVal='+document.frmMap.selPrice.value+'&hdnRange=0&hdnUpper=6';
//	document.frmMap.hdnListValues.value='?hdnBedRooms='+document.frmMap.selBedRooms.value+'&hdnCity='+document.frmMap.selCity.value+'&hdnBathRooms='+document.frmMap.selBathRooms.value+'&hdnPrice='+document.frmMap.selPrice.value;

	document.frmMap.hdnValues.value='?hdnMinBedVal='+document.frmMap.selMinBedRooms.value+'&hdnMaxBedVal='+document.frmMap.selMaxBedRooms.value+'&hdnMinBathVal='+document.frmMap.selMinBathRooms.value+'&hdnMaxBathVal='+document.frmMap.selMaxBathRooms.value+'&hdnMinSqftVal='+document.frmMap.selMinSqft.value+'&hdnMaxSqftVal='+document.frmMap.selMaxSqft.value+'&hdnMinPriceVal='+document.frmMap.selMinPrice.value+'&hdnMaxPriceVal='+document.frmMap.selMaxPrice.value+'&hdnMinAcresVal='+document.frmMap.selMinAcres.value+'&hdnMaxAcresVal='+document.frmMap.selMaxAcres.value+'&hdnCityVal='+document.frmMap.selCity.value+'&hdnCountyVal='+document.frmMap.selCounty.value+'&hdnWaterFrontVal='+document.frmMap.selWaterFront.value+'&hdnOffender='+document.frmMap.chkOffenders.checked;
	document.frmMap.hdnListValues.value='?hdnMinBeds='+document.frmMap.selMinBedRooms.value+'&hdnMaxBeds='+document.frmMap.selMaxBedRooms.value+'&hdnMinBaths='+document.frmMap.selMinBathRooms.value+'&hdnMaxBaths='+document.frmMap.selMaxBathRooms.value+'&hdnMinSqft='+document.frmMap.selMinSqft.value+'&hdnMaxSqft='+document.frmMap.selMaxSqft.value+'&hdnMinPrice='+document.frmMap.selMinPrice.value+'&hdnMaxPrice='+document.frmMap.selMaxPrice.value+'&hdnMinAcres='+document.frmMap.selMinAcres.value+'&hdnMaxAcres='+document.frmMap.selMaxAcres.value+'&hdnCity='+document.frmMap.selCity.value+'&hdnWaterFront='+document.frmMap.selWaterFront.value+'&hdnCounty='+document.frmMap.selCounty.value;
	document.frmMap.btnSearch.value="Search";
	document.frmMap.submit();
}
// Function to Pass the Hidden Vales of Residential Page
function lakePassValues()
{
	var iFrame = parent.frames[0]; //Get the IFRAME		
	
	if(document.frmMap.chkOffenders.type=='checkbox')
		var offender = document.frmMap.chkOffenders.checked;
	var viewMap = document.frmMap.chkGMap.checked;
	document.frmMap.hdnValues.value='?hdnWaterFrontVal='+document.frmMap.selWaterFront.value+'&hdnSelTypeVal='+document.frmMap.selType.value+'&hdnOffender='+document.frmMap.chkOffenders.checked;
	document.frmMap.hdnListValues.value='?hdnWaterFront='+document.frmMap.selWaterFront.value+'&hdnSelType='+document.frmMap.selType.value;
	document.frmMap.btnSearch.value="Search";
	document.frmMap.submit();
}
// Function to Pass the Hidden Vales of Residential Page
function cPassValues()
{
	var iFrame = parent.frames[0]; //Get the IFRAME		
	var minBeds = parseInt(document.frmMap.selMinBedRooms.value)
	var maxBeds = parseInt(document.frmMap.selMaxBedRooms.value)
	var minSqft = parseInt(document.frmMap.selMinSqft.value)
	var maxSqft = parseInt(document.frmMap.selMaxSqft.value)
	var minPrice = parseInt(document.frmMap.selMinPrice.value)
	var maxPrice = parseInt(document.frmMap.selMaxPrice.value)
	var minBaths = parseInt(document.frmMap.selMinBathRooms.value)
	var maxBaths = parseInt(document.frmMap.selMaxBathRooms.value)
	if(document.frmMap.chkOffenders.type=='checkbox')
		var offender = document.frmMap.chkOffenders.checked;
	var viewMap = document.frmMap.chkGMap.checked;

	//	var minLots = document.frmMap.selMinPrice.value
	//	var maxLots = document.frmMap.selMaxPrice.value
	//	var county = document.frmMap.selMinPrice.value
	//	var city = document.frmMap.selMaxPrice.value
	
	if(minBeds!="Any" && maxBeds!="Any" && minBeds > maxBeds)
	{
		alert("Please enter a valid range for Bedrooms.");
		document.frmMap.selMinBedRooms.focus();
		return false;
	}
	if(minSqft!="Any" && maxSqft!="Any" && minSqft > maxSqft)
	{
		alert("Please enter a valid range for Living Square Feet.");
		document.frmMap.selMinSqft.focus();
		return false;
	}
	if(minBaths!="Any" && maxBaths!="Any" && minBaths > maxBaths)
	{
		alert("Please enter a valid range for Bathrooms.");
		document.frmMap.selMinBathRooms.focus();
		return false;
	}
	if(minPrice!="Any" && maxPrice!="Any" && minPrice > maxPrice)
	{
		alert("Please enter a valid range for Price.");
		document.frmMap.selMinPrice.focus();
		return false;
	}

	document.frmMap.hdnValues.value='?hdnMinBedVal='+document.frmMap.selMinBedRooms.value+'&hdnMaxBedVal='+document.frmMap.selMaxBedRooms.value+'&hdnMinBathVal='+document.frmMap.selMinBathRooms.value+'&hdnMaxBathVal='+document.frmMap.selMaxBathRooms.value+'&hdnMinSqftVal='+document.frmMap.selMinSqft.value+'&hdnMaxSqftVal='+document.frmMap.selMaxSqft.value+'&hdnMinPriceVal='+document.frmMap.selMinPrice.value+'&hdnMaxPriceVal='+document.frmMap.selMaxPrice.value+'&hdnCityVal='+document.frmMap.selCity.value+'&hdnCountyVal='+document.frmMap.selCounty.value+'&hdnWaterFrontVal='+document.frmMap.selWaterFront.value+'&hdnOffender='+document.frmMap.chkOffenders.checked;
	document.frmMap.hdnListValues.value='?hdnMinBeds='+document.frmMap.selMinBedRooms.value+'&hdnMaxBeds='+document.frmMap.selMaxBedRooms.value+'&hdnMinBaths='+document.frmMap.selMinBathRooms.value+'&hdnMaxBaths='+document.frmMap.selMaxBathRooms.value+'&hdnMinSqft='+document.frmMap.selMinSqft.value+'&hdnMaxSqft='+document.frmMap.selMaxSqft.value+'&hdnMinPrice='+document.frmMap.selMinPrice.value+'&hdnMaxPrice='+document.frmMap.selMaxPrice.value+'&hdnCity='+document.frmMap.selCity.value+'&hdnWaterFront='+document.frmMap.selWaterFront.value+'&hdnCounty='+document.frmMap.selCounty.value;

	document.frmMap.btnSearch.value="Search";
	document.frmMap.submit();
}

// Pass hidden values for the offenders
function taney()
{
	var iFrame = parent.frames[0]; //Get the IFRAME  
	document.frmMap.hdnValues.value='?hdnCityVal='+document.frmMap.selCity.value+'&hdnCountyVal='+document.frmMap.selCounty.value+'&hdnRange=0&hdnUpper=50';
	document.frmMap.hdnListValues.value='?hdnCity='+document.frmMap.selCity.value+'&hdnCounty='+document.frmMap.selCounty.value;
	document.frmMap.submit();
}

// Function to Pass the Hidden Vales of Commercial Page
function bPassValues()
{	
	var iFrame   = parent.frames[0]; //Get the IFRAME  
	var minPrice = parseInt(document.frmMap.selMinPrice.value)
	var maxPrice = parseInt(document.frmMap.selMaxPrice.value)
	var viewMap = document.frmMap.chkGMap.checked;
	if(document.frmMap.chkOffenders.type=='checkbox')
		var offender = document.frmMap.chkOffenders.checked;

	if(minPrice!="Any" && maxPrice!="Any" && minPrice > maxPrice)
	{
		alert("Please enter a valid range for Price.");
		document.frmMap.selMinPrice.focus();
		return false;
	}

//	document.frmMap.hdnValues.value='?hdnMinPriceVal='+document.frmMap.selMinPrice.value+'&hdnMaxPriceVal='+document.frmMap.selMaxPrice.value+'&hdnCityVal='+document.frmMap.selCity.value+'&hdnLeaseVal='+document.frmMap.selLease.value+'&hdnBusinessVal='+document.frmMap.selBusiness.value+'&hdnRange=0&hdnUpper=6';
//	document.frmMap.hdnListValues.value='?hdnMinPrice='+document.frmMap.selMinPrice.value+'&hdnMaxPrice='+document.frmMap.selMaxPrice.value+'&hdnCity='+document.frmMap.selCity.value+'&hdnLeaseSale='+document.frmMap.selLease.value+'&hdnBusiness='+document.frmMap.selBusiness.value;
	document.frmMap.btnSearch.value="Search";
	document.frmMap.hdnValues.value='?hdnCityVal='+document.frmMap.selCity.value+'&hdnCountyVal='+document.frmMap.selCounty.value+'&hdnMinPriceVal='+document.frmMap.selMinPrice.value+'&hdnMaxPriceVal='+document.frmMap.selMaxPrice.value+'&hdnBusinessVal='+document.frmMap.selBusiness.value+'&hdnSubtypesVal='+document.frmMap.selSubType.value+'&hdnLeaseVal='+document.frmMap.selLease.value+'&hdnOffender='+document.frmMap.chkOffenders.checked;
	document.frmMap.hdnListValues.value='?hdnCity='+document.frmMap.selCity.value+'&hdnCounty='+document.frmMap.selCounty.value+'&hdnMinPrice='+document.frmMap.selMinPrice.value+'&hdnMaxPrice='+document.frmMap.selMaxPrice.value+'&hdnBusiness='+document.frmMap.selBusiness.value+'&hdnSubtypes='+document.frmMap.selSubType.value+'&hdnLeaseSale='+document.frmMap.selLease.value+'&hdnOffender='+document.frmMap.chkOffenders.checked;
	document.frmMap.submit();
}

// Function to Pass the Hidden Vales of Land/lots Page
function lPassValues()
{		
	var iFrame = parent.frames[0]; //Get the IFRAME  
	var minPrice = parseInt(document.frmMap.selMinPrice.value)
	var maxPrice = parseInt(document.frmMap.selMaxPrice.value)
	var minAcres = document.frmMap.txtMinAcres.value
	var maxAcres = document.frmMap.txtMaxAcres.value
	var viewMap = document.frmMap.chkGMap.checked;
	if(document.frmMap.chkOffenders.type=='checkbox')
		var offender = document.frmMap.chkOffenders.checked;

	if(!IsNumeric(minAcres) || !IsNumeric(maxAcres))
	{	alert("Please enter only numeric values for Acres");
		if(!IsNumeric(minAcres))
			document.frmMap.txtMinAcres.focus();
		else
			document.frmMap.txtMaxAcres.focus();
		return false;
	}
	if((minAcres == "" && maxAcres != "")||(minAcres != "" && maxAcres == ""))
	{	alert("Please specify both the lower and upper limit for Acres");
		if(minAcres == "")
			document.frmMap.txtMinAcres.focus();
		else
			document.frmMap.txtMaxAcres.focus();
		return false;
	}
	if(parseInt(minAcres) > parseInt(maxAcres))
	{	
		alert("Please enter a valid range for Acres");
		document.frmMap.txtMinAcres.focus();
		return false;
	}
	if(minPrice > maxPrice)
	{
		alert("Please enter a valid Price range");
		document.frmMap.selMaxPrice.focus();
		return false;
	}
	document.frmMap.btnSearch.value="Search";
	document.frmMap.hdnValues.value='?hdnMinPriceVal='+document.frmMap.selMinPrice.value+'&hdnMaxPriceVal='+document.frmMap.selMaxPrice.value+'&hdnCityVal='+document.frmMap.selCity.value+'&hdnCountyVal='+document.frmMap.selCounty.value+'&hdnMinAcresVal='+document.frmMap.txtMinAcres.value+'&hdnMaxAcresVal='+document.frmMap.txtMaxAcres.value+'&hdnWaterFrontVal='+document.frmMap.selWaterFront.value+'&hdnOffender='+document.frmMap.chkOffenders.checked;
	document.frmMap.hdnListValues.value='?hdnMinPrice='+document.frmMap.selMinPrice.value+'&hdnMaxPrice='+document.frmMap.selMaxPrice.value+'&hdnCity='+document.frmMap.selCity.value+'&hdnCounty='+document.frmMap.selCounty.value+'&hdnMinAcres='+document.frmMap.txtMinAcres.value+'&hdnMaxAcres='+document.frmMap.txtMaxAcres.value+'&hdnWaterFront='+document.frmMap.selWaterFront.value+'&hdnOffender='+document.frmMap.chkOffenders.checked;
	document.frmMap.submit();
}

// Validations for the Equibuilder Home Maps
function homeValidate(frm)
{
	var minBeds = frm.selMinBedrooms.value;
	var maxBeds = frm.selMaxBedrooms.value;
	var minBaths = frm.selMinBathrooms.value;
	var maxBaths = frm.selMaxBathrooms.value;
	var minSqft = frm.selMinSquareFeet.value;
	var maxSqft = frm.selMaxSquareFeet.value;
	var minPrice = frm.selMinPrice.value;
	var maxPrice = frm.selMaxPrice.value;
	var mls = Trim(frm.txtMLSNo.value);
		
	if(parseInt(minBeds) > parseInt(maxBeds))
	{	alert("Please enter a valid range for Bedrooms");
		frm.selMinBedrooms.focus();
		return false;
	}
	if(parseInt(minBaths) > parseInt(maxBaths))
	{	alert("Please enter a valid range for Bathrooms");
		frm.selMinBathrooms.focus();
		return false;
	}
	if(parseInt(minSqft) > parseInt(maxSqft))
	{	alert("Please select a valid range for Living Space Square Feet.");
		frm.selMinSquareFeet.focus();
		return false;
	}
	if(parseInt(minPrice) > parseInt(maxPrice))
	{	alert("Please enter a valid range for Price");
		frm.selMinPrice.focus();
		return false;
	}
	if(mls!="" && !IsNumber(mls))
	{
		alert("Please enter a valid MLS No.");
		frm.txtMLSNo.focus();
		return false;
	}
}

// Validations for the Equibuilder Business Maps
function commValidate(frm)
{	
	var minPrice = frm.selMinPrice.value;
	var maxPrice = frm.selMaxPrice.value;
	var mls = Trim(frm.txtMLSNo.value);
		
	if(parseInt(minPrice) > parseInt(maxPrice))
	{	alert("Please enter a valid range for Price");
		frm.selMinPrice.focus();
		return false;
	}
	if(mls!="" && !IsNumber(mls))
	{
		alert("Please enter a valid MLS No.");
		frm.txtMLSNo.focus();
		return false;
	}
}

// Validations for the Equibuilder Land Maps
function landValidate(frm)
{	
	var minAcres = frm.txtMinAcres.value;
	var maxAcres = frm.txtMaxAcres.value;
	var minPrice = frm.selMinPrice.value;
	var maxPrice = frm.selMaxPrice.value;
	var mls = Trim(frm.txtMLSNo.value);
	
	if(!IsNumeric(minAcres) || !IsNumeric(maxAcres))
	{
		alert("Please enter only numberic values for Acres");
		if(!IsNumeric(minAcres))
			frm.txtMinAcres.focus();
		else
			frm.txtMaxAcres.focus();
		return false;
	}
	if(parseInt(minAcres) > parseInt(maxAcres))
	{	alert("Please enter a valid range for Acres");
		frm.txtMinAcres.focus();
		return false;
	}
	if(parseInt(minPrice) > parseInt(maxPrice))
	{	alert("Please enter a valid range for Price");
		frm.selMinPrice.focus();
		return false;
	}
	if(mls!="" && !IsNumber(mls))
	{
		alert("Please enter a valid MLS No.");
		frm.txtMLSNo.focus();
		return false;
	}
	
}
//  check for valid numeric strings	
function IsNumeric(strString)   
{
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
        blnResult = false;
   }
   return blnResult;
}

// Validation for Numbers only fields
function IsNumber(strString)   
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
        blnResult = false;
   }
   return blnResult;
}

// Validate the phone number
function validPhone(strString)   
{
  var result=true;
  if((strString.match(/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null) && (strString.match(/^[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null))
	result=false;
  return result;
}