	var mainNamingContainer;
	var moz = ((document.all)? false : true);
    var ie = ((document.all)? true : false);
   
    function SetClientID(ClientID) {
		mainNamingContainer = ClientID;
		// start event listener
		// document.onkeyup = KeyDown;
	}
	function KeyDown(e)
	{
		var key_index;
		if(moz)
			key_index = e.which;
		else
			key_index = window.event.keyCode;
		if(key_index == 13)
		{
			document.getElementById("btnSearch").focus();
			doSubmit('results');
		}
		return;
	}
	function clearSearchForm() 
	{
		if(mainNamingContainer == null)
			return;
		document.getElementById(mainNamingContainer + "alllstCity").value = "";
		document.getElementById(mainNamingContainer + "alllstCounty").value = "";
		document.getElementById(mainNamingContainer + "alllstPostalCode").value = "";
		document.getElementById(mainNamingContainer + "ignminListPrice").value = "";
		document.getElementById(mainNamingContainer + "ignmaxListPrice").value = "";
		document.getElementById(mainNamingContainer + "allminListPrice").value = "";
		document.getElementById(mainNamingContainer + "allmaxListPrice").value = "";
		document.getElementById("ignlstMLSAddress").value = "Enter address or MLS#";
		document.getElementById("alllstAddress").value = "";
		document.getElementById("alllstMLSListingID").value = "";
	}	
	function ClearAddress()
	{
		if(document.getElementById("ignlstMLSAddress").value == "Enter address or MLS#")
			document.getElementById("ignlstMLSAddress").value = "";
	}
	
	function validateStateZip(strPostalCode, strState)
	{
		// validate postal code
		switch (strState) { 
				case "CA":
					if(strPostalCode.indexOf("90") != 0 && strPostalCode.indexOf("91") != 0 && strPostalCode.indexOf("92") != 0
						&& strPostalCode.indexOf("93") != 0 && strPostalCode.indexOf("94") != 0 && strPostalCode.indexOf("95") != 0
						&& strPostalCode.indexOf("960") != 0 && strPostalCode.indexOf("961") != 0)
					{
						return "- " + strPostalCode + " is not a valid California zip code.\n";
					}
					break;
				case "NV":
					if(strPostalCode.indexOf("889") != 0 && strPostalCode.indexOf("89") != 0)
					{
						return "- " + strPostalCode + " is not a valid Nevada zip code.\n";
					}
					break;
				case "TX":
					if(strPostalCode.indexOf("733") != 0 && strPostalCode.indexOf("75") != 0 && strPostalCode.indexOf("76") != 0
							&& strPostalCode.indexOf("77") != 0 && strPostalCode.indexOf("78") != 0 && strPostalCode.indexOf("79") != 0
							&& strPostalCode.indexOf("885") != 0)
					{
						return "- " + strPostalCode + " is not a valid Texas zip code.\n";
					}
					break;
				case "AZ":
					if (strPostalCode.indexOf("85") != 0 && strPostalCode.indexOf("86") != 0)
					{
						return "- " + strPostalCode + " is not a valid Arizona zip code.\n";
					}
					break;
				default:
					break;		
		}
		return "";
	} 
	
	function doSubmit(myArg)
	{
		var ErrorTxt = "";
		if(mainNamingContainer == null)
			return;
		// remove any remaining settings on other property categories
		//document.getElementById(mainNamingContainer + "resminBedrooms").selectedIndex = 0;
		//document.getElementById(mainNamingContainer + "resminBathsFull").selectedIndex = 0;
		
		// set the mlsid or address
		SetMlsAddress();
		
		var ignminListPrice = document.getElementById(mainNamingContainer + "ignminListPrice");
		var ignmaxListPrice = document.getElementById(mainNamingContainer + "ignmaxListPrice");
		var allminListPrice = document.getElementById(mainNamingContainer + "allminListPrice");
		var allmaxListPrice = document.getElementById(mainNamingContainer + "allmaxListPrice");
		
		if(myArg.indexOf("results") != -1)
		{
			// perform validation
			if(document.getElementById(mainNamingContainer + "alllstCity").value == "" && document.getElementById(mainNamingContainer + "alllstCounty").value == "" && document.getElementById(mainNamingContainer + "alllstPostalCode").value == "" && document.getElementById("alllstAddress").value == "" && document.getElementById("alllstMLSListingID").value == "")
				ErrorTxt = ErrorTxt + "- City, County or Zip Code is required\n";
				
			if(document.getElementById(mainNamingContainer + "alllstPostalCode") != null)
			{
				var alllstPostalCode = document.getElementById(mainNamingContainer + "alllstPostalCode");
				var strPostalCodes = alllstPostalCode.value;
				var bInvalidZip = false;
				var strState = document.getElementById(mainNamingContainer + "alllstStateOrProvince").options[document.getElementById(mainNamingContainer + "alllstStateOrProvince").selectedIndex].value;
				if(strPostalCodes != "")
				{
					var zipCheck = strPostalCodes.split(",");
					for(i=0;i<zipCheck.length;i++)
					{
						zipCheck[i] = zipCheck[i].replace(/\s/,"");
						ErrorTxt = ErrorTxt + validateStateZip(zipCheck[i], strState);
						if(isNaN(zipCheck[i]) || zipCheck[i].length != 5)
							bInvalidZip = true;
					}
					if(bInvalidZip)
						ErrorTxt = ErrorTxt + "- Zip code must be a comma-separated list of 5 digit numeric value(s)\n";
				}
			}
				
			if(ignminListPrice.value != "" && isNaN(ignminListPrice.value))
				ErrorTxt = ErrorTxt + "- Minimum price value must be numeric\n";
			if(ignmaxListPrice.value != "" && isNaN(ignmaxListPrice.value))
				ErrorTxt = ErrorTxt + "- Maximum price value must be numeric\n";
			if(ignminListPrice.value != "" && !isNaN(ignminListPrice.value) && ignmaxListPrice.value != "" && !isNaN(ignmaxListPrice.value) && parseFloat(ignmaxListPrice.value) < parseFloat(ignminListPrice.value))
				ErrorTxt = ErrorTxt + "- Maximum price value must greater than the minimum price\n";
				
			if(ErrorTxt != "")
			{
				alert("Please fix the following errors:\n" + ErrorTxt);
				return;
			}
		}
		else
		{
			alllstPostalCode = document.getElementById(mainNamingContainer + "alllstPostalCode");
			strPostalCodes = alllstPostalCode.value;
			bInvalidZip = false;
			if(strPostalCodes != "")
			{
				strState = document.getElementById(mainNamingContainer + "alllstStateOrProvince").options[document.getElementById(mainNamingContainer + "alllstStateOrProvince").selectedIndex].value;
				zipCheck = strPostalCodes.split(",");
				for(i=0;i<zipCheck.length;i++)
				{
					zipCheck[i] = zipCheck[i].replace(/\s/,"");
					if(validateStateZip(zipCheck[i], strState) != "" || isNaN(zipCheck[i]) || zipCheck[i].length != 5)
						bInvalidZip = true;
				}
				if(bInvalidZip)  // ignore the zip code value when going to advanced search
					alllstPostalCode.value = "";
			}
		}
		
		// populate the list price hidden fields
		if(ignminListPrice.value != "" && !isNaN(ignminListPrice.value))
			allminListPrice.value = ignminListPrice.value * 1000;
		if(ignmaxListPrice.value != "" && !isNaN(ignmaxListPrice.value))
			allmaxListPrice.value = ignmaxListPrice.value * 1000;
	
		if(ErrorTxt == "")
			__doPostBack("btnSubmit", myArg);
	}
	function SetMlsAddress()
	{
		if(mainNamingContainer == null)
			return;
		var myMlsPattern = /\d{5,15}/g;
		var myMlsAddressText = "";
		myMlsAddressText = document.getElementById("ignlstMLSAddress").value;
		myMlsAddressText = myMlsAddressText.replace(/^\s*/, ''); 
		myMlsAddressText = myMlsAddressText.replace(/\s*$/, ''); 
		
		if(myMlsAddressText == "" || myMlsAddressText == "Enter address or MLS#")
		{
			document.getElementById("alllstAddress").value = "";
			document.getElementById("alllstMLSListingID").value = "";
		}
		else
		{
			var myMlsTorF = new Boolean();
			myMlsTorF = false;
			if(!isNaN(myMlsAddressText))
				myMlsTorF = myMlsPattern.test(myMlsAddressText);
			if (myMlsTorF)
			{
				document.getElementById("alllstMLSListingID").value = myMlsAddressText;
				document.getElementById("alllstAddress").value = "";
			}
			else
			{
				document.getElementById("alllstMLSListingID").value = "";
				document.getElementById("alllstAddress").value = myMlsAddressText;
			}
		}
	}
	function locationChange(control)
	{
		var alllstCounty = document.getElementById(control.id.substring(0, control.id.indexOf("_alllst")+1) + "alllstCounty");
		var alllstPostalCode = document.getElementById(control.id.substring(0, control.id.indexOf("_alllst")+1) + "alllstPostalCode");
		var alllstCity = document.getElementById(control.id.substring(0, control.id.indexOf("_alllst")+1) + "alllstCity");
		if(control.id.indexOf("alllstCounty") == -1 && alllstCounty != null)
		{
			alllstCounty.value = "";
			// gray out this textbox
		}
		if(control.id.indexOf("alllstPostalCode") == -1 && alllstPostalCode != null)
		{
			alllstPostalCode.value = "";
			// gray out this textbox
		}
		if(control.id.indexOf("alllstCity") == -1 && alllstCity != null)
		{
			alllstCity.value = "";
			// gray out this textbox
		}
	}
	function ClearAndKeyDown(control, e)
	{
		locationChange(control);
		KeyDown(e);
	}