﻿function __SearchZipCodes()
{
	this.SearchText = "";
	this.SearchParam = "";
	this.HideMessage = true;
	
	this.SearchFor = function(pControlName, pHideMessage)
	{
		this.HideMessage = (pHideMessage == null) ? this.HideMessage : pHideMessage;
		return this.Search(pControlName);
	}
	
	this.Search = function(pZipCode)
	{
		var objControl = document.getElementById(pZipCode);
		var objDivision = document.getElementById("divResults");
						
		function ValidateSearch(pValue)
		{
			var blnCanSearch = true;
			
			if (pValue == "")
			{
				alert("Please enter something to search on", "Invalid Search Value", "AlertWarning");
				blnCanSearch = false;
			}
			
			return blnCanSearch;
		}
			
		if (objControl != null)
		{
			if (this.SearchText == "")
			{
				this.SearchText = objDivision.innerHTML;
			}
				
			if (ValidateSearch(objControl.value) == true)
			{
				objDivision.innerHTML = this.SearchText;
				objDivision.style.height = "100%";
				objDivision.style.visibility = "visible";
				
				var strZipCode = objControl.value;
				
				this.SearchParam = strZipCode;
				
				setTimeout("SearchZipCodes.SearchZipCode(\"" + strZipCode + "\")", 100);
			}
			else
			{
				objDivision.style.height = "0px";
				objDivision.style.visibility = "hidden";
			}
		}
		
		return false;
	}

	this.NavigateSearch = function(pPage)
	{
		setTimeout("SearchZipCodes.SearchZipCode(\"" + this.SearchParam + "&page=" + pPage + "\")", 100);
	}
	
	this.SearchZipCode = function(pZipCode)
	{
		var objDivision = document.getElementById("divResults");
		var strUrl = "../App_Pages/ScriptSupport/ZipCodeSearch.aspx";
		strUrl += "?zipcode=" + pZipCode;
		
		var strResponse = WallArtCore.DoCallBack(strUrl, false);
		objDivision.innerHTML = strResponse;
		
		if (this.HideMessage)
		{
			var UNF = document.getElementById("divUrlNotFound");
			if (UNF != null)
			{
				UNF.style.display = "none";
			}
		}
	}
}

SearchZipCodes = new __SearchZipCodes;
			