/* This function validates numbers in the field*/
function IsNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;
   if(sText =="")
	 {
		 IsNumber = false;
	 }
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
         {
           IsNumber = false;
         }
       }
   return IsNumber;
   
 }
 
	 

/*This function validates all required fields and directs user back to respective field in case of error*/
function validateForm(form)
{
	
	var minPrice1 = form.minListPrice.value.replace(/,/g,"");
	var minPrice =parseInt(minPrice1);
	var maxPrice1 = form.maxListPrice.value.replace(/,/g,"");
	var maxPrice = parseInt(maxPrice1);
	var sqFt = document.getElementById('squareFeet');
	var minlotAcres = document.getElementById('lotAcres');
	
	if(!IsNumeric(form.minListPrice.value))
	 {
		 alert("Please enter numeric value for minPrice");
		 form.minListPrice.focus();
		 return false;
	 }
	 if(!IsNumeric(form.maxListPrice.value))
	 {
		 alert("Please enter numeric value for maxPrice");
		 form.maxListPrice.focus();
		 return false;
	 }
	
	if(minPrice >= maxPrice)
	{
	  alert("Min Price cannot be greater than Max Price");
		form.minListPrice.focus();
		return false;
	}
	if(sqFt)
	{
		 if(!IsNumeric(form.squareFeet.value))
	 {
		 alert("Please enter numeric value for Min Sq. Ft.");
		 form.squareFeet.focus();
		 return false;
	 }
	}
	if(minlotAcres)
 {
		 if(!IsNumeric(form.lotAcres.value))
	 {
		 alert("Please enter numeric value for Lot Acres");
		 form.lotAcres.focus();
		 return false;
	 }
	}
 
return true;
 
} 

