/*<!-- Build Number: 01.01.071 LKH.WIDX 1/7/2008 -->
*/
function blockChars(string, para) 
	{
		var validchars = para;
		var parsed = true;
		for (var i=0; i < string.length; i++) {
			var letter = string.charAt(i);
			if (validchars.indexOf(letter) == -1)
				continue;
			if (blockChars.arguments.length==3){
				if (blockChars.arguments[2] == 0){
					alert(letter + " is not allowed.");
				}
			}else{
				alert(letter + " is not allowed.");
			}
			parsed = false;
			break;
		}
		return parsed;
	}

/*	FUNCTION allowValidChars	*/
/*	Usage -> allowValidChars(Checking String, integer, space [Optional])	*/
function allowValidChars(string) {
	var parsed = true;
	var blockCharacters = "~`!@#$%^&*()+=|\\{[}]:;\"'<,>.?/";
	parsed = blockChars(string, blockCharacters,1);
	if (parsed==false){
		if ((allowValidChars.arguments.length==1) || 
		(allowValidChars.arguments.length==2 && allowValidChars.arguments[1] == 0)){
			alert("Invalid Character(s) Used!\nAllowed Characters: [A-Z], [a-z], [0-9],  ,_");
		}
	}
	return parsed;
}
	
//function below is used in both /includes/o-quicksearch and property_search.shtml	

function validaAdvSearch(forma)
{
//bathrooms
	forma.BathMin.optional=true; 
	forma.BathMax.optional=true; 
	forma.BathMin.integer=true; 
	forma.BathMax.integer=true; 
//bedrooms	
	forma.BedMin.integer=true; 
	forma.BedMax.integer=true;
	forma.BedMin.optional=true; 
	forma.BedMax.optional=true; 
//sqft
	forma.SQFTMin.optional=true; 
	forma.SQFTMax.optional=true; 
	forma.SQFTMin.integer=true;
	forma.SQFTMax.integer=true;
//price	
	forma.PriceMin.optional=false;
	forma.PriceMin.decimal=true;
	forma.PriceMax.optional=false;
	forma.PriceMax.decimal=true;
	
//location
	forma.StreetNumber.optional=true;
	forma.StreetName.optional=true;
	forma.StreetDir.optional=true;
	forma.StreetType.optional=true;
	forma.City.optional=true;
	forma.State.optional=true;
	forma.ZipCode.optional=true;
	forma.ZipCode.integer=true;

//other
	forma.MLSID.optional=true;
	forma.Ad.optional=true;
	forma.Category.optional=true;
	forma.Keyword.optional=true;
	forma.ID.optional=true;
	
	
	//new descriptions	sample: forma.city.description="City";
	

	
	if(allowValidChars (forma.ZipCode.value)== false) 
	{
		forma.ZipCode.select(); 
		forma.ZipCode.focus(); 
		return false;
	}
	if(allowValidChars (forma.Ad.value)== false) 
	{
		forma.Ad.select(); 
		forma.Ad.focus(); 
		return false;
	}
	if(allowValidChars (forma.City.value)== false) 
	{
		forma.City.select(); 
		forma.City.focus(); 
		return false;
	}

	if ( 
		(isblank(forma.City.value) && (forma.City.value.search(" - City -")==-1) && (forma.City.value.search("- City -")==-1))
		&&
		( 
			isblank(forma.State.value) && (forma.State.value.search(" - State -")==-1) && (forma.State.value.search("- State -")==-1)
		)
		|| 
			isblank(forma.ZipCode.value) && (forma.ZipCode.value.search(" - Zip Code -")==-1) && (forma.ZipCode.value.search("- Zip Code -")==-1)
		|| 
		(
			isblank(forma.Ad.value) && (forma.Ad.value.search(" - Ad Code -")==-1)&& (forma.Ad.value.search("- Ad Code -")==-1)
		)
		
		|| 
			isblank(forma.MLSID.value) && (forma.MLSID.value.search(" - MLS # -")==-1) && (forma.MLSID.value.search("- MLS # -")==-1)

		|| 
		(
			 forma.StreetName.value !="" && forma.StreetName.value.search !=" - Street Name -" && forma.StreetName.value.search !="- Street Name -")
		&&
		( 
			isblank(forma.City.value) && (forma.City.value.search(" - City -")==-1) && (forma.City.value.search("- City -")==-1)
		)
		&&
		( 
			isblank(forma.State.value) && (forma.State.value.search(" - State -")==-1) && (forma.State.value.search("- State -")==-1)
		)
		||
		(
			 forma.StreetName.value !="" && forma.StreetName.value.search !=" - Street Name -" && forma.StreetName.value.search !="- Street Name -")
		&&
		( 
			isblank(forma.ZipCode.value) && (forma.ZipCode.value.search(" - Zip Code -")==-1) && (forma.ZipCode.value.search("- Zip Code -")==-1)
		)
		||
		(
			 forma.StreetNumber.value !="" && forma.StreetNumber.value.search !=" - Street # -" && forma.StreetNumber.value.search !="- Street # -")
		&&
		( 
			isblank(forma.StreetName.value) && (forma.StreetName.value.search(" - Street Name -")==-1) && (forma.StreetName.value.search("- Street Name -")==-1)
		)

	)
	{
		if (isblank(forma.PriceMin.value) && isblank(forma.PriceMax.value) )
		{
			var pricemin;
			if (parseFloat(forma.PriceMin.value)>=parseFloat(forma.PriceMax.value))
				{
					alert("Maximum price must be higher than minimum price.");
					return false;
				}
		}
		
		if (isblank(forma.BedMin.value) && isblank(forma.BedMax.value) )
		{
			var bedmin;
			if (parseFloat(forma.BedMin.value)>=parseFloat(forma.BedMax.value))
				{
					alert("Maximum number of bedrooms must be higher than minimum number of bedrooms.");
					return false;
				}
		}
		if (isblank(forma.BathMin.value) && isblank(forma.BathMax.value) )
		{
			var bathmin;
			if (parseFloat(forma.BathMin.value)>=parseFloat(forma.BathMax.value))
				{
					alert("Maximum number of bathrooms must be higher than minimum number of bathrooms.");
					return false;
				}
		}
		
		if (isblank(forma.SQFTMin.value) && isblank(forma.SQFTMax.value) )
		{
			var sqftmin;
			if (parseFloat(forma.SQFTMin.value)>=parseFloat(forma.SQFTMax.value))
				{
					alert("Maximum square footage must be higher than minimum square footage.");
					return false;
				}
		}

		if	(forma.ZipCode.value != "" && forma.ZipCode.value !=" - Zip Code -" && forma.ZipCode.value !="- Zip Code -" && (isNaN(forma.ZipCode.value))) 
		{
			alert("Please enter a valid Zip Code and then press Search");
			forma.ZipCode.focus();
			return false;
		}
		
		return MailValidator(forma);
		//return false;
	}
	else
	{
		alert("To perform a search you must use one of the following methods:\n\n 1) a Street Name + City/State OR \n 2) a Street Name + Zip Code OR \n 3) a City + State OR \n 4) just a Zip Code OR \n 5) just an MLS# OR \n 6) just an Ad Code");
		return false;
	}
	
}


                                          