
	var mainNamingContainer;
	var moz = ((document.all)? false : true);
    var ie = ((document.all)? true : false);
    en_instr = "Enter address or MLS#";
    en_instr_az = "Enter Street Name or MLS#";
    sp_instr = "Entre la Dirección o Número de MLS"
   
    function SetClientID(ClientID) {
		mainNamingContainer = ClientID;
	}
	
	function changeCat()
	{
		if(mainNamingContainer == null)
			return;
		var strCat = document.getElementById(mainNamingContainer + "Cat").value;
		document.getElementById(mainNamingContainer + "res").style.display = "none";
		document.getElementById(mainNamingContainer + "lnd").style.display = "none";
		document.getElementById(mainNamingContainer + "inc").style.display = "none";
		document.getElementById(mainNamingContainer + "bus").style.display = "none";
		document.getElementById(mainNamingContainer + "mob").style.display = "none";
		document.getElementById(mainNamingContainer + "all").style.display = "none";
		document.getElementById(mainNamingContainer + strCat).style.display = "block";
		return;
	}
	function clearSearchForm() 
	{
		if(mainNamingContainer == null)
			return;
		document.getElementById(mainNamingContainer + "alllstCity").value = "";
		
		if(document.getElementById(mainNamingContainer + "alllstCounty") != null)
		{
			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 = "";
		if (document.getElementById(mainNamingContainer + "btnClear").value == "Borrar")
		{
			document.getElementById(mainNamingContainer + "ignlstMLSAddress").value = sp_instr;
		}
		else // button label is "Clear"
		{
			document.getElementById(mainNamingContainer + "ignlstMLSAddress").value = en_instr;
		}	
		document.getElementById("alllstAddress").value = "";
		document.getElementById("alllstMLSListingID").value = "";
		var Cat = document.getElementById(mainNamingContainer + "Cat");
		if (Cat != null)
		{
			for(i=0; i<Cat.options.length; i++)
			{
				if(Cat.options[i].value == "res")
					Cat.selectedIndex = i;
			}
		}
		changeCat();
		clearCatSpecificFields("all");
	}	
	function clearCatSpecificFields(strCat)
	{
		if(mainNamingContainer == null)
			return;
		if(strCat != "res")
		{
			document.getElementById(mainNamingContainer + "resminBedrooms").selectedIndex = 0;
			document.getElementById(mainNamingContainer + "resminBathsFull").selectedIndex = 0;
		}
		if(strCat != "mob")
		{
			document.getElementById(mainNamingContainer + "mobminBedrooms").selectedIndex = 0;
			document.getElementById(mainNamingContainer + "mobminBathsFull").selectedIndex = 0;
		}
		if(strCat != "lnd")
		{
			document.getElementById(mainNamingContainer + "lndminLotSizeAcre").value = "";
			document.getElementById(mainNamingContainer + "lndmaxLotSizeAcre").value = "";
		}
		if(strCat != "inc")
		{
			inclstType = document.getElementById(mainNamingContainer + "inclstType");
			for(i=0;i<inclstType.options.length;i++)
				inclstType.options[i].selected = false;
		}	
	}
	function ClearAddress()
	{
		ignlstMLSAddressID = mainNamingContainer + "ignlstMLSAddress";
		if (document.getElementById(ignlstMLSAddressID).value == en_instr
			|| document.getElementById(ignlstMLSAddressID).value == en_instr_az
			|| document.getElementById(ignlstMLSAddressID).value.substring(0,15) == sp_instr.substring(0,15))
			document.getElementById(ignlstMLSAddressID).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":
				case "TX-Dallas":
				case "TX-Austin":
					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 trim (s) { 
		return s.replace(/^\s+|\s+$/g, ''); 
    }
	
	function doSubmit(myArg)
	{
		var ErrorTxt = "";
		if(mainNamingContainer == null)
			return;
		// remove any remaining settings on other property categories
		var strCat = document.getElementById(mainNamingContainer + "Cat").value
		clearCatSpecificFields(strCat);
		
		// set the mlsid or address
		if (!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
				document.getElementById(mainNamingContainer + "alllstCity").value = trim(document.getElementById(mainNamingContainer + "alllstCity").value);
				if(document.getElementById(mainNamingContainer + "alllstCounty") != null)
				{
					document.getElementById(mainNamingContainer + "alllstCounty").value = trim(document.getElementById(mainNamingContainer + "alllstCounty").value);
				}
				document.getElementById(mainNamingContainer + "alllstPostalCode").value = trim(document.getElementById(mainNamingContainer + "alllstPostalCode").value);
				
				
				if(document.getElementById(mainNamingContainer + "alllstCounty") != null)
				{
					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";
				}else
				{
					if(document.getElementById(mainNamingContainer + "alllstCity").value == "" && document.getElementById(mainNamingContainer + "alllstPostalCode").value == "" && document.getElementById("alllstAddress").value == "" && document.getElementById("alllstMLSListingID").value == "")
						ErrorTxt = ErrorTxt + "- City 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;
					
					if(document.getElementById(mainNamingContainer + "alllstStateOrProvince") != null)
					{
						strState = document.getElementById(mainNamingContainer + "alllstStateOrProvince").options[document.getElementById(mainNamingContainer + "alllstStateOrProvince").selectedIndex].value;
					}else
					{
						strState = "CA";
					}
					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(strCat == "lnd")
				{
					// validate lot size
					var minLotSizeAcre = document.getElementById(mainNamingContainer + "lndminLotSizeAcre");
					var maxLotSizeAcre = document.getElementById(mainNamingContainer + "lndmaxLotSizeAcre");
					if(minLotSizeAcre != null && minLotSizeAcre.value != "" && isNaN(minLotSizeAcre.value))
						ErrorTxt = ErrorTxt + "- Lot size minimum value must be numeric\n";
					if(maxLotSizeAcre != null && maxLotSizeAcre.value != "" && isNaN(maxLotSizeAcre.value))
						ErrorTxt = ErrorTxt + "- Lot size maximum value must be numeric\n";
					if(minLotSizeAcre != null && maxLotSizeAcre != null)
					{
						if(minLotSizeAcre.value != "" && maxLotSizeAcre.value != "" && parseFloat(minLotSizeAcre.value) > parseFloat(maxLotSizeAcre.value))
						ErrorTxt = ErrorTxt + "- Lot size minimum value must be less than the maximum\n";
					}
				}
				else if(strCat == "inc")
				{
					var inclstType = document.getElementById(mainNamingContainer + "inclstType");
					var bNoneSelected = true;
					for(i=0; i<inclstType.options.length; i++)
					{
						if(inclstType.options[i].selected)
							bNoneSelected = false;
					}
					if (bNoneSelected)
						ErrorTxt = ErrorTxt + "-Type must be selected\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 != "")
				{
					if(document.getElementById(mainNamingContainer + "alllstStateOrProvince") != null)
					{
						strState = document.getElementById(mainNamingContainer + "alllstStateOrProvince").options[document.getElementById(mainNamingContainer + "alllstStateOrProvince").selectedIndex].value;
					}else
					{
						strState = "CA";
					}
					
					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(mainNamingContainer + "ignlstMLSAddress").value;
		myMlsAddressText = myMlsAddressText.replace(/^\s*/, ''); 
		myMlsAddressText = myMlsAddressText.replace(/\s*$/, ''); 
		
		if(myMlsAddressText == "" || myMlsAddressText == en_instr || myMlsAddressText == en_instr_az || myMlsAddressText.substring(0,15) == sp_instr.substring(0,15))
		{
			document.getElementById("alllstAddress").value = "";
			document.getElementById("alllstMLSListingID").value = "";
			return false;
		}
		else
		{
			var myMlsTorF = new Boolean();
			myMlsTorF = false;
			if(!isNaN(myMlsAddressText))
				myMlsTorF = myMlsPattern.test(myMlsAddressText);
			if (myMlsTorF)// == 1)
			{
				document.getElementById("alllstMLSListingID").value = myMlsAddressText;
				document.getElementById("alllstAddress").value = "";
			}
			else
			{
				document.getElementById("alllstMLSListingID").value = "";
				document.getElementById("alllstAddress").value = myMlsAddressText;
			}
			return true;
		}
	}
	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 = "";
		if(control.id.indexOf("alllstPostalCode") == -1 && alllstPostalCode != null)
			alllstPostalCode.value = "";
		if(control.id.indexOf("alllstCity") == -1 && alllstCity != null)
			alllstCity.value = "";
	}
	function ClearAndKeyDown(control, e)
	{
		locationChange(control);
		KeyDown(e);
	}