
var queue = new Array();        //values queue 
var queueDest = new Array();    
var running = false;            //does callback completed? 
var handle;                    //handle for setInterval 


var strState;
var moz = ((document.all)? false : true);
var ie = ((document.all)? true : false);
var listingBubbleID = "myListingBubble";
var mapHeight=500;
var mapWidth=700;
var mapCenterLong; //based on domain ID and geoKeyType 11 (usp_GetEntityGeoPosition)
var mapCenterLat; //based on domain ID and geoKeyType 11 (usp_GetEntityGeoPosition)
var pushpinCount = 0;
var pagesize = 10;
var bCookie = false;
var bPan = false;
var zoomLevel = 8;
var oSchoolsJSON = null;
var oOfficesJSON = null;
var officepincount = 0;
var listingslocs = new Array;    
var schoolpincount = 0;
var bRow = false;
var bViewChanged = false;
var bChangeState = false;
var hasListings = false;
var bPan = false;
var bField = false;
var searchparams = null;
var cityLat = null;
var cityLong = null;
var bWasBirdsEye = false;
var bWasAerial = false;
var currMapStyle = '';
var savedSearchId = 0;
var oSSJSON = null;
var strmode = '';
var redirectparams = '';

var searchCat = "";
var searchCity = "";
var searchCounty = "" ;
var searchZip = "";
var searchMLS = "";
var searchMinPrice = "";
var searchMaxPrice = "";
var searchMinBed = "";
var searchMaxBed = "";
var searchMinBath = "";
var searchMaxBath = "";
var searchIncLstType = "";
var searchMinLotSizeAcre = "";
var searchMaxLotSizeAcre = "";
var searchState = "";

var wtsearchCat = "";
var wtsearchCity  = "";
var wtsearchCounty  = "";
var wtsearchZip  = "";
var wtsearchMLS  = "";
var wtsearchMinPrice  = "";
var wtsearchMaxPrice  = "";
var wtsearchMinBed  = "";
var wtsearchMaxBed  = "";
var wtsearchMinBath  = "";
var wtsearchMaxBath  = "";
var wtsearchIncLstType  = "";
var wtsearchMinLotSizeAcre  = "";
var wtsearchMaxLotSizeAcre  = "";
var wtsearchState  = "";
var wtminLatitude  = "";
var wtmaxLatitude  = "";
var wtminLongitude  = "";
var wtmaxLongitude  = "";
var wtcenterlat  = "";
var wtcenterlon  = "";
var wtmapzoom  = "";
var wtmapstyle  = "";
var strcancel = "";
var domainid = 0;
var iClientId = 0;

	function getCurrentState()
	{
		var strHref = window.location.href;
		if(strHref.indexOf("prurealty") >= 0)
		{
			strState = "CA";
			mapCenterLat = 37.834948933372203;
			mapCenterLong = -121.752225568653;
		}
		else if(strHref.indexOf("prunevada") >= 0)
		{
			strState = "NV";
			mapCenterLat = 39.5245220474904;
			mapCenterLong = -119.81166770313;
		}
		else if(strHref.indexOf("prudentialtexasrealty") >= 0) //5
		{
			strState = "TX";
			mapCenterLat = 30.267631552169199;
			mapCenterLong = -97.742875702333905;
		}
		else if(strHref.indexOf("prudentialtexas") >= 0) //4
		{
			strState = "TX";
			mapCenterLat = 32.778091487269499;
			mapCenterLong = -96.795583105966401;
		}
		else if(strHref.indexOf("gotucson") >= 0)
		{
			strState = "AZ";
			mapCenterLat =  32.221513032183502;
			mapCenterLong = -110.969769256495;
		}
		else
		{
			strState = "CA";
			mapCenterLat = 37.834948933372203;
			mapCenterLong = -121.752225568653;
		}
		
	}
	function getDomain()
	{
		if(domainid == 1)
		{
			strState = "CA";
			mapCenterLat = 37.834948933372203;
			mapCenterLong = -121.752225568653;
		}
		else if(domainid == 3)
		{
			strState = "NV";
			mapCenterLat = 39.5245220474904;
			mapCenterLong = -119.81166770313;
		}
		else if(domainid == 5) //5
		{
			strState = "TX";
			mapCenterLat = 30.267631552169199;
			mapCenterLong = -97.742875702333905;
		}
		else if(domainid == 4) //4
		{
			strState = "TX";
			mapCenterLat = 32.778091487269499;
			mapCenterLong = -96.795583105966401;
		}
		else if(domainid == 2)
		{
			strState = "AZ";
			mapCenterLat =  32.221513032183502;
			mapCenterLong = -110.969769256495;
		}
		else
		{
			strState = "CA";
			mapCenterLat = 37.834948933372203;
			mapCenterLong = -121.752225568653;
		}
	}
	function lastMapConfig(){
		var z=oMap.GetZoomLevel();
		var lat=oMap.GetCenter().Latitude;
		var lon=oMap.GetCenter().Longitude;
		var s=oMap.GetMapStyle();
		var lmc=z + ", " + lat + ", " + lon + ", " + s;
		
		if (isWebtop == 'False') document.cookie = "zll=" + lmc + "; path=/; ";
	}
	
	function changeCat()
	{
	
		var s=oMap.GetMapStyle();
		if (s == VEMapStyle.Birdseye)
		{
			oMap.SetMapStyle(VEMapStyle.Road);
		}
		
		var strCat = $("cat").value;
		$("res").style.display = "none";
		$("lnd").style.display = "none";
		$("inc").style.display = "none";
		$("bus").style.display = "none";
		$("mob").style.display = "none";
		$(strCat).style.display = "block";
		
		if(strCat == "inc")
		{
			inclstType = document.getElementById("inclstType");
			for(i=0;i<inclstType.options.length;i++)
				inclstType.options[i].selected = true;
		}
		if (isWebtop == 'False') document.cookie = "cat=" + document.getElementById("cat").value+ "; path=/; ";
		searchCat = document.getElementById("cat").value;
		
	}
	
	var url = "/include/ajax/mapsearch/searchResults.aspx";
	var oJSON = null;
	var o = null;
	var dsb = null;
	var oMap = null;
	//window.onload = function()
	//window.addEvent('domready', function()
	Event.onDOMReady(function() 
	{
		if (whichbrowser())
		{
			bRow = true;
			if (isWebtop == 'True') getDomain();
			else getCurrentState();
			if (isWebtop == 'False') document.cookie = "alllstStateOrProvince=" + strState + "; path=/; ";
			searchState = strState;
			searchCat = document.getElementById("cat").value;
			resetForm();	
			$('ListingBubble').style.display='none';
			if (strState == "TX") LoadCategories();
			if (scope == 'client' || scope == 'client_buyer' || scope == 'client_seller') 
			{
				iClientId = readCookie("ignCurrentClientID");
			}
			LoadMap();
			var strHref = window.location.href;
			if(strHref.toLowerCase().indexOf("savedsearchid=") >= 0)
			{
				var pos = strHref.toLowerCase().indexOf("savedsearchid=");
				savedSearchId = strHref.substr(pos+14);
			}
			if (savedSearchId > 0)
			{
				strmode = 'savedsearch' ; //this variable is used for grid display from saved search 
				//load saved search info.
				getSavedSearchData();
				if (isWebtop == 'True' && strHref.indexOf("cmc") < 0) $('spnSavedSearches').style.display = 'block';
			}
			else
			{
				//if (checkCookie() || checkOther() || (readCookie("redirect") != null && strmode=='return') || strcancel == 'True') //for the back button
				if ((readCookie("redirect") != null && strmode=='return') || strcancel == 'True') //for the back button
				{
					bViewChanged = true;
					AddRequest('listings');
					if (readCookie("redirect") == null && strmode == '') AddRequest('grid'); //grid was mising from back button click, so added the if
					
				}
			}
			populateHiddenFields();
			if (readCookie("redirect") != null && strmode != 'return') DeleteCookie("redirect","/"); //browser back button click
		}
		else 
		{
			$('mySearchForm').style.display = 'none';
			alert("This browser version does not support the feature you are trying to access. Please upgrade your browser!");
		}
	});
	function getSavedSearchData()
	{
		var ssurl = "/include/ajax/mapsearch/savedSearchInfo.aspx";
		var savedsearchparams = "savedsearchid=" + savedSearchId ;
		fnSearching();
		var myAjax = new Ajax.Request(
		ssurl, 
		{
			method: 'get', 
			parameters: savedsearchparams, 
			onComplete: savedsearchResponse
		});
	}
	function getListings()
	{	
		var sscenterLat ;
		var sscenterLon ;
		var sszoom;
		var ssmapstyle;
		var minLat = GetBottomLat();
		var maxLat = GetTopLat();
		var minLong = GetLeftLong();
		var maxLong = GetRightLong();
		var s=oMap.GetMapStyle();
		
		if (oMap.GetZoomLevel() <= 4 && (!checkCookie()) && s != VEMapStyle.Birdseye) 
		{
			$('listingCount').innerHTML = "Unable to retrieve listings at this zoom level";
			$('listingCount').style.display='block';
			fnSearching();
			$('delay').style.display = 'none';
			queue = new Array();
		}
		else
		{
			if (s != VEMapStyle.Birdseye)
			{
				if (savedSearchId > 0 && strcancel != 'True')
				{
					if (oSSJSON != null && oSSJSON != '')
					{
						for (var i=0; i<oSSJSON.savedsearch.length; i++)
						{
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allminlatitude') minLat = oSSJSON.savedsearch[i].fieldValue;
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allmaxlatitude') maxLat = oSSJSON.savedsearch[i].fieldValue;
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allminlongitude') minLong = oSSJSON.savedsearch[i].fieldValue;
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allmaxlongitude') maxLong = oSSJSON.savedsearch[i].fieldValue;
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allignvemapcenterlat') sscenterLat = oSSJSON.savedsearch[i].fieldValue;
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allignvemapcenterlon') sscenterLon = oSSJSON.savedsearch[i].fieldValue;
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allignvemapzoom') sszoom = oSSJSON.savedsearch[i].fieldValue;
							if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allignvemapstyle') ssmapstyle = oSSJSON.savedsearch[i].fieldValue;
						}
						if (!checkCookie()) document.cookie = "cords=" + minLat + "," + maxLat + "," + minLong + "," + maxLong + "; path=/; ";
						else DeleteCookie("cords","/");
						redirectparams = minLat + "," + maxLat + "," + minLong + "," + maxLong;
						if (sscenterLat != null && sscenterLon != null && sszoom != null)
						{
							var centermap = new VELatLong(sscenterLat,sscenterLon);
							bViewChanged = true;
							oMap.SetCenterAndZoom(centermap,sszoom);
						}
						if (ssmapstyle != null && ssmapstyle != 'r') 
						{
							bViewChanged = true;
							oMap.SetMapStyle(ssmapstyle);
						}
					}
				}
				else
				{
					$('listingCount').style.display='none';
					if (checkCookie()) 
					{
						if (bPan) document.cookie = "cords=" + minLat + "," + maxLat + "," + minLong + "," + maxLong + "; path=/; ";
						else DeleteCookie("cords","/");
					}
					else document.cookie = "cords=" + minLat + "," + maxLat + "," + minLong + "," + maxLong + "; path=/; ";
					
					redirectparams = minLat + "," + maxLat + "," + minLong + "," + maxLong; //back button
					if (readCookie("redirect") != null && strmode=='return') //from back button
					{
						var zll = readCookie("zll");
						if (zll != null && zll != '')
						{
							zll = zll.split(",");
							if (zll[3] != null)
							{
								bViewChanged = true;
								switch (zll[3]){
									case "r":
										oMap.SetMapStyle(VEMapStyle.Road);
										break;
									case "a":
										oMap.SetMapStyle(VEMapStyle.Aerial);
										break;
									case "h":
										oMap.SetMapStyle(VEMapStyle.Hybrid);
										break;
									default:
										oMap.SetMapStyle(VEMapStyle.Road);
										break;
								}
							}					
							if (zll[0] != null && zll[1] != null && zll[2] != null)
							{
								bViewChanged = true;
								var centermap = new VELatLong(zll[1],zll[2]);
								oMap.SetCenterAndZoom(centermap,zll[0]);
							}
						}
						
						var so = readCookie("so");
						{
							if (so != null && so != '')
							{
								so = so.split(",");
								if (so[0] != null)
								{
									if (so[0] == 1) $('chkSchools').checked = true;
								}
								if (so[1] != null)
								{
									if (so[1] == 1) $('chkOffices').checked = true;
								}
							}
						}
						bViewChanged = false;
					}
					else if (strcancel == 'True') //webtop cancel click
					{
						fnSearching();
						if (!checkCookie()) document.cookie = "cords=" + wtminLatitude + "," + wtmaxLatitude + "," + wtminLongitude + "," + wtmaxLongitude + "; path=/; ";
						else DeleteCookie("cords","/");
						if (wtcenterlat != null && wtcenterlon != null && wtmapzoom != null)
						{
							var centermap = new VELatLong(wtcenterlat,wtcenterlon);
							bViewChanged = true;
							if (centermap != null) oMap.SetCenterAndZoom(centermap,wtmapzoom);
						}
						if (wtmapstyle != null && wtmapstyle != 'r') 
						{
							bViewChanged = true;
							oMap.SetMapStyle(wtmapstyle);
						}
					}
				}
				if (document.getElementById("cat").value == "res" || document.getElementById("cat").value == "mob")
				{
					searchparams = 	"cat=" + searchCat + "&city=" + searchCity + "&county=" + searchCounty + "&zip=" + searchZip ;	
					searchparams += "&mls=" + searchMLS + "&minP=" + searchMinPrice + "&maxP=" + searchMaxPrice ;	
					searchparams +=  "&minBed=" + searchMinBed + "&maxBed=" + searchMaxBed + "&minBath=" + searchMinBath ;
					searchparams +=  "&maxBath=" + searchMaxBath + "&state=" + searchState;
				}
				else if (document.getElementById("cat").value == "inc" )
				{
					searchparams = 	"cat=" + searchCat + "&city=" + searchCity + "&county=" + searchCounty + "&zip=" + searchZip ;	
					searchparams += "&mls=" + searchMLS + "&minP=" + searchMinPrice + "&maxP=" + searchMaxPrice ;
					searchparams += "&inc=" + searchIncLstType + "&state=" + searchState;
				}
				else if (document.getElementById("cat").value == "lnd" )
				{
					searchparams = 	"cat=" + searchCat + "&city=" + searchCity + "&county=" + searchCounty + "&zip=" + searchZip ;	
					searchparams += "&mls=" + searchMLS + "&minP=" + searchMinPrice + "&maxP=" + searchMaxPrice ;
					searchparams += "&minlot=" + searchMinLotSizeAcre + "&maxlot=" + searchMaxLotSizeAcre + "&state=" + searchState;
				}
				else if (document.getElementById("cat").value == "bus" )
				{
					searchparams = 	"cat=" + searchCat + "&city=" + searchCity + "&county=" + searchCounty + "&zip=" + searchZip ;	
					searchparams += "&mls=" + searchMLS + "&minP=" + searchMinPrice + "&maxP=" + searchMaxPrice + "&state=" + searchState;
				}
			//	alert("isFineHome:" + isFineHome);
				if(isFineHome)
				{
					searchparams += "&IsFineHome=1"
				}	
				if (savedSearchId == 0 || strcancel != 'True') fnSearching();
				var myAjax = new Ajax.Request(
				url, 
				{
					method: 'get', 
					parameters: searchparams, 
					onComplete: showResponse
				});
			}
		}
		callkeydata();
	}
	function showResponse(originalRequest)
	{
		try
		{
			oJSON = null;
			var response = originalRequest.responseText;
			//alert(response);
			if (response != null) 
			{
				oJSON = eval('(' + response + ')');
			}
			//alert(oJSON);
			if (response != '{}' && oJSON != null && oJSON != '')
			{
				if (oJSON.listings.length > 200)
				{
					$('ListingMessage').style.display='block';
					$('ListingMessage').innerHTML = 'More than 200 listings found';
				}
				else $('ListingMessage').style.display='none';
				
				addPushPins();
				if (readCookie("redirect") != null || strmode == 'savedsearch' || strcancel == 'True') //grid was mising from back button click , so calling set grid in show response in this case.
				{
					SetGrid();
					if (strmode == 'savedsearch') strmode = '';
				}
				
			}
				
			$('delay').style.display = 'none';
			if (queue.length == 0) { 
				clearInterval(handle); 
			} 
			running = false;
			DeleteCookie("redirect","/");
			DeleteCookie("so","/");
			
			AddRequest('schools');
			AddRequest('offices');
			if (strcancel == 'True') strcancel = 'False';
			if (scope == 'client' || scope == 'client_buyer' || scope == 'client_seller') 
			{
				if (readCookie("ignCurrentClientID") == null)
				{
					document.cookie = "ignCurrentClientID=" + iClientId + "; path=/; ";
				}
			}
		}
		catch (err)
		{
			//alert(err.message);
			$('delay').style.display = 'none';
			queue = new Array();
			if (queue.length == 0) { 
			clearInterval(handle); 
			} 
			running = false;
			$('listingCount').innerHTML = "Unable to retrieve listings";
			$('listingCount').style.display='block';
		}
	}

	function savedsearchResponse(originalRequest)
	{
		try
		{
			oSSJSON = null;
			var response = originalRequest.responseText;
			if (response != null) 
			{
				oSSJSON = eval('(' + response + ')');
			}
			if (response != '{}' && oSSJSON != null && oSSJSON != '')
			{
				setFields();
				doSearch();
			}
			else
			{
				$('delay').style.display = 'none';
			}
				
		}
		catch (err)
		{
			
		}
	}
	function setFields()
	{
		if (oSSJSON.savedsearch != null)
		{
			for (var i=0; i<oSSJSON.savedsearch.length; i++)
			{
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'alllststateorprovince')
				{
					strState = oSSJSON.savedsearch[i].fieldValue;
				}
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'cat')
				{
					document.getElementById("cat").value = oSSJSON.savedsearch[i].fieldValue;
					if (oSSJSON.savedsearch[i].fieldValue == 'res') document.getElementById("cat").options[0].selected = true; 
					else if (oSSJSON.savedsearch[i].fieldValue == 'lnd') document.getElementById("cat").options[1].selected = true; 
					else if (oSSJSON.savedsearch[i].fieldValue == 'inc') document.getElementById("cat").options[2].selected = true; 
					else if (oSSJSON.savedsearch[i].fieldValue == 'bus') document.getElementById("cat").options[3].selected = true; 
					else if (oSSJSON.savedsearch[i].fieldValue == 'mob') document.getElementById("cat").options[4].selected = true; 
				}
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'alllstcity') 
				{
					document.getElementById("alllstCity").value = oSSJSON.savedsearch[i].fieldValue;
				}
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allchkisfinehome') 
				{
					isFineHome = 1;
					if(document.getElementById("chkFineHomes") != null)
						document.getElementById("chkFineHomes").checked = true;
				}
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'alllstmlslistingid') document.getElementById("ignlstMLSAddress").value = oSSJSON.savedsearch[i].fieldValue;
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allstrcounty') document.getElementById("alllstCounty").value = oSSJSON.savedsearch[i].fieldValue;
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'alllstpostalcode') document.getElementById("alllstPostalCode").value = oSSJSON.savedsearch[i].fieldValue;
				//if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'alllstmlsid') document.getElementById("ignlstMLSAddress").value = oSSJSON.savedsearch[i].fieldValue;
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allminlistprice') document.getElementById("ignminListPrice").value = oSSJSON.savedsearch[i].fieldValue/1000;
				if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'allmaxlistprice') document.getElementById("ignmaxListPrice").value = oSSJSON.savedsearch[i].fieldValue/1000;
				if (document.getElementById("cat").value == "res")
				{
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'resminbedrooms')
					{
						document.getElementById("resminBedroom").value = oSSJSON.savedsearch[i].fieldValue;
						if (oSSJSON.savedsearch[i].fieldValue > 0) document.getElementById("resminBedroom").options[oSSJSON.savedsearch[i].fieldValue].selected = true;
						else document.getElementById("resminBedroom").options[0].selected = true;
					}
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'resmaxbedrooms')
					{
						document.getElementById("resmaxBedroom").value = oSSJSON.savedsearch[i].fieldValue;
						if (oSSJSON.savedsearch[i].fieldValue > 0) document.getElementById("resmaxBedroom").options[oSSJSON.savedsearch[i].fieldValue].selected = true;
						else document.getElementById("resmaxBedroom").options[0].selected = true;
					}
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'resminbathsfull')
					{
						document.getElementById("resminBathsFull").value = oSSJSON.savedsearch[i].fieldValue;
						var j = getpartialbathIndex(oSSJSON.savedsearch[i].fieldValue);
						document.getElementById("resminBathsFull").options[j].selected = true;
					}
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'resmaxbathsfull')
					{
						document.getElementById("resmaxBathsFull").value = oSSJSON.savedsearch[i].fieldValue;
						j = getpartialbathIndex(oSSJSON.savedsearch[i].fieldValue);
						document.getElementById("resmaxBathsFull").options[j].selected = true;
					}
				}
				else if (document.getElementById("cat").value == "mob")
				{
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'mobminbedrooms')
					{
						document.getElementById("resminBedroommob").value = oSSJSON.savedsearch[i].fieldValue;
						if (oSSJSON.savedsearch[i].fieldValue > 0) document.getElementById("resminBedroommob").options[oSSJSON.savedsearch[i].fieldValue].selected = true;
						else document.getElementById("resminBedroommob").options[0].selected = true;
					}
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'mobmaxbedrooms')
					{
						document.getElementById("resmaxBedroommob").value = oSSJSON.savedsearch[i].fieldValue;
						if (oSSJSON.savedsearch[i].fieldValue > 0) document.getElementById("resmaxBedroommob").options[oSSJSON.savedsearch[i].fieldValue].selected = true;
						else document.getElementById("resmaxBedroommob").options[0].selected = true;
					}
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'mobminbathsfull')
					{
						document.getElementById("resminBathsFullmob").value = oSSJSON.savedsearch[i].fieldValue;
						var j = getpartialbathIndex(oSSJSON.savedsearch[i].fieldValue);
						document.getElementById("resminBathsFullmob").options[j].selected = true;
					}
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'mobmaxbathsfull')
					{
						document.getElementById("resmaxBathsFullmob").value = oSSJSON.savedsearch[i].fieldValue;
						var j = getpartialbathIndex(oSSJSON.savedsearch[i].fieldValue);
						document.getElementById("resmaxBathsFullmob").options[j].selected = true;
					}
				}
				else if (document.getElementById("cat").value == "inc")
				{
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'inclsttype')
					{
						//deselect both
						document.getElementById("inclstType").options[0].selected = false; 
						document.getElementById("inclstType").options[1].selected = false;
						if (oSSJSON.savedsearch[i].fieldValue.indexOf(",") > 0) //resinc,resinc5
						{
							document.getElementById("inclstType").options[0].selected = true; 
							document.getElementById("inclstType").options[1].selected = true;
						}
						else
						{
							if (oSSJSON.savedsearch[i].fieldValue.indexOf("5") > 0) {document.getElementById("inclstType").options[1].selected = true; }
							else document.getElementById("inclstType").options[0].selected = true;
						}
						document.getElementById("inclstType").value = oSSJSON.savedsearch[0].inclstType ;
					}
				}
				else if (document.getElementById("cat").value == "lnd")
				{
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'lndminlotsizeacre') document.getElementById("lndminLotSizeAcre").value = oSSJSON.savedsearch[i].fieldValue;
					if (oSSJSON.savedsearch[i].fieldName.toLowerCase() == 'lndmaxlotsizeacre') document.getElementById("lndmaxLotSizeAcre").value = oSSJSON.savedsearch[i].fieldValue;
				}
			}
		}
				 
		 if ($('cat').value == "mob")
		 {
			$('mob').style.display = "block";
			$('res').style.display = "none";
		 }
		 else if ($('cat').value == "lnd")
		 {
			$('lnd').style.display = "block";
			$('res').style.display = "none";
		 }
		 else if ($('cat').value == "inc")//"inc"
		 {
			$('inc').style.display = "block";
			$('res').style.display = "none";
		 }
		 else if ($('cat').value == "bus")//"bus"
		 {
			$('res').style.display = "none";
		 }
	}
	function getpartialbathIndex(strVal)
	{
		var iIndex = 0;
		switch (strVal)
		{
			case '' :
			{
				iIndex = 0;
				break;
			}
			case '1':
			{
				iIndex = 1;
				break;
			}
			case '1.5':
			{
				iIndex = 2;
				break;
			}
			case '2':
			{
				iIndex = 3;
				break;
			}
			case '2.5':
			{
				iIndex = 4;
				break;
			}
			case '3':
			{
				iIndex = 5;
				break;
			}
			case '3.5':
			{
				iIndex = 6;
				break;
			}
			case '4':
			{
				iIndex = 7;
				break;
			}
			case '4.5':
			{
				iIndex = 8;
				break;
			}
			case '5':
			{
				iIndex = 9;
				break;
			}
			case '5.5':
			{
				iIndex = 10;
				break;
			}
		}
		return iIndex;
	}
	function LoadMap()
	{	
		try
		{
			oMap = new VEMap('Map1');
			var centerPoint = new VELatLong(mapCenterLat, mapCenterLong);
			if (token.length>0) { oMap.SetClientToken(token) };
			oMap.LoadMap(centerPoint, zoomLevel,'r',false,VEMapMode.Mode2D,false);
			oMap.HideFindControl();
		
			oMap.AttachEvent('onendcontinuouspan', fnPanEnd);
			oMap.AttachEvent('onclick', fnViewChange); //since we use view change now
			oMap.AttachEvent('onchangeview', ChangeMapStyle);
			
			//lastMapConfig();
		}
		catch (err)
		{
			//fix for firefox 2.0
			oMap.AttachEvent('onendcontinuouspan', fnPanEnd);
			oMap.AttachEvent('onclick', fnViewChange); //since we use view change now
			oMap.AttachEvent('onchangeview', ChangeMapStyle);
			return;
		}
	}
	
	function fnSearching()
	{
		oMap.Clear();
		$('delay').style.display = 'block';
		$('ListingBubble').style.display = 'none';
		$('officeBubble').style.display = 'none';
		$('schoolBubble').style.display = 'none';
		$('cyclelinks').style.display = 'none';
		$('ListingMessage').style.display = 'none';
		$('SchoolMessage').style.display = 'none';
		$('ResultsGrid').innerHTML = '';
		$('btnSaveSearch').disabled = false;
		
		if($('custCapLinksHref') != null)
		{
			$('custCapLinksHref').setAttribute('href','javascript:saveDynMapSearch(\'propertyalert\');');
		}
		lastMapConfig();
	}
	function fnViewChange(e)
	{
		HideListingBubble();
		CloseOfficeBubble();
		CloseSchoolBubble();
	}
	function fnPanEnd(e)
	{
		bPan = true;
	}
	function mapCenterChanged(e)
	{
		AddRequest('listings');
		AddRequest('grid');
		AddRequest('schools');
		AddRequest('offices');
	}	
	function addPushPins()
	{
		
		var loc;
		var iLat;
		var iLong;
		var strListings = '';
		var  price;
		var address;
		var city;
		var bedrooms;
		var bathsfull;
		var bathspartial;
		var LivingArea;
		var iLat;
		var iLong;
		var showingtime = '';
		var mlsLogo = '';
		var listOfficeName, listingId, state, zip, isPruList, listAgentAgentId, officeId, mlsId, listAgentName;
		
		oMap.Clear();
		listingslocs = new Array;
		pushpinCount = 0;
 		if (oJSON != null && oJSON != '')
		{
			var listingcount = 0;
			if (oJSON.listings.length > 200) listingcount = 200;
			else listingcount = oJSON.listings.length;
			
			
			for (var i=0; i<listingcount; i++)
			{
				iLat = oJSON.listings[i].latitude;
				iLong = oJSON.listings[i].longitude;
				if (iLat != '0' && iLong != '0' && iLat != '0.0' && iLong != '0.0' && iLat != null && iLong != null && iLat != '' && iLong != '')
				{
					loc = new VELatLong(iLat, iLong);
					listingslocs.push(loc);
					AddPushPin('listing' + i,iLat,iLong,oJSON.listings[i])
					pushpinCount ++;
				
				}
			}
			
			$('listingCount').style.display='block';
			if ($('ignlstMLSAddress').value != null && $('ignlstMLSAddress').value != '' && pushpinCount == 0) 
			{
				$('listingCount').innerHTML = "Unable to map this property";
				//code to position to the nearest city if property cannot be mapped.
				/*if (oJSON.listings[0] != null && oJSON.listings[0].address != null && oJSON.listings[0].city != null)
				{
					FindLoc(oJSON.listings[0].address + "," + oJSON.listings[0].city);
					if (cityLat != null && cityLong != null) oMap.SetCenter(new VELatLong(cityLat, cityLong));
				}*/
				
			}
			else 
			{
				if (pushpinCount <= 0) $('listingCount').innerHTML = "No listings found";
				else $('listingCount').innerHTML = pushpinCount + " listings displayed";
			}
			
			if (pushpinCount > 0) hasListings = true;
			else hasListings = false;
			
			if (checkCookie() && !hasListings) bViewChanged = false;
			
			if (pushpinCount <= pagesize) 
			{
				$('cyclelinks').style.display = 'none';
			}
			else
				$('cyclelinks').style.display = 'block';
			if (listingslocs.length > 0 && strmode != 'savedsearch' && strcancel != 'True') //do it only if not saved search or not cancel click in webtop
			{
				DoBestMap(listingslocs);
			}
			//store the current map style.
			currMapStyle=oMap.GetMapStyle();
			if (checkOtherFields() && !checkCookie()) bViewChanged = false; //do best map  doesnt happen in this case, so bViewChanged is not reset.
 		}
 	}
	function GetTopLat(){
		var pix = new VEPixel(0, 0);
		var ll = oMap.PixelToLatLong(pix)
		return ll.Latitude
	}
	function GetBottomLat(){
		var pix = new VEPixel(mapWidth, mapHeight);
		var ll = oMap.PixelToLatLong(pix)
		return ll.Latitude
	}
	function GetLeftLong(){
		var pix = new VEPixel(0, 0);
		var ll = oMap.PixelToLatLong(pix)
		return ll.Longitude
	}
	function GetRightLong(){
		var pix = new VEPixel(mapWidth, mapHeight);
		var ll = oMap.PixelToLatLong(pix)
		return ll.Longitude
	}
	
	function AddPushPin(id,lat,lon,l){
		var pushpin = oMap.vemapcontrol.AddPushpin(id, lat, lon, 1, 1,'listingIcon','',500); 
		pushpin.listing = l;
		pushpin.onmouseover = OnListingMouseOver;
		pushpin.onclick = OnListingClick;
		//pushpin.onmouseout = HideListingBubble;
	}
	function OnListingMouseOver(e)
	{
		var t;
		var ex =GetEvent(e);
		if (ex.target) t = ex.target;
		else if (ex.srcElement) t = ex.srcElement;
		var velatlon = new VELatLong(t.listing.latitude, t.listing.longitude);
		var pix = oMap.LatLongToPixel(velatlon);
		ShowListingBubble(pix.x,pix.y,t.listing);
		toggle('details', '')
		CloseOfficeBubble();
		CloseSchoolBubble();

	}
	function OnListingClick(e)
	{
		//OnListingMouseOver(e)
		HideListingBubble();
		var t;
		var ex =GetEvent(e);
		if (ex.target) t = ex.target;
		else if (ex.srcElement) t = ex.srcElement;
		var velatlon = new VELatLong(t.listing.latitude, t.listing.longitude);
		var pix = oMap.LatLongToPixel(velatlon);
		ShowListingBubble(pix.x,pix.y,t.listing);
		toggle('details', '')
		CloseOfficeBubble();
		CloseSchoolBubble();
	}
	function DoBestMap(locs)
    {
		if (locs != null && (checkCookie()))
		{
			if (($('ignlstMLSAddress').value != null && $('ignlstMLSAddress').value != ''))
			{
				bViewChanged = true;
			}
			oMap.SetMapView(locs);
			if (($('ignlstMLSAddress').value != null && $('ignlstMLSAddress').value != ''))
			{
				bViewChanged = true;
				if (oMap.GetZoomLevel() > 15) oMap.SetZoomLevel(15);
			}	
		}
	}
	
	function readCookie(name) 
	{

		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	function DeleteCookie(name, path) 
	{
		if (readCookie(name) != null ) document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}

	function checkCookie()
	{
		var city = document.getElementById("alllstCity");
		var county = document.getElementById("alllstCounty");
		var zipcode = document.getElementById("alllstPostalCode");
		var mlsaddress = document.getElementById("ignlstMLSAddress");
		if ((city.value != null && city.value != '')|| (county.value != null && county.value != '')|| (zipcode.value != null && zipcode.value != '') || (mlsaddress.value != null && mlsaddress.value != '') || bChangeState)
		{
			bCookie = true;
		}
		else bCookie = false;
		return bCookie;	
	}
	function clickSearch()
	{
		doSearch();
	}
	
	function clickSearchFineHome()
	{
		isFineHome = 1;
		doSearch();
	}
	
	function doSearch()
	{
		var s=oMap.GetMapStyle();
		if (s == VEMapStyle.Birdseye)
		{
			oMap.SetMapStyle(VEMapStyle.Road);
		}
		if( document.getElementById("chkFineHomes") != null)
		{
			if( document.getElementById("chkFineHomes").checked) isFineHome = 1;
			else isFineHome = 0;
		}
		searchCat = document.getElementById("cat").value;
		searchCity = document.getElementById("alllstCity").value;
		searchCounty = document.getElementById("alllstCounty").value;
		searchZip = document.getElementById("alllstPostalCode").value;
		verifyMLSNumorAddress(); 
		if (document.getElementById("ignminListPrice").value != null && document.getElementById("ignminListPrice").value != '') searchMinPrice = document.getElementById("ignminListPrice").value * 1000;
		else searchMinPrice = "";
		if (document.getElementById("ignmaxListPrice").value != null && document.getElementById("ignmaxListPrice").value != '') searchMaxPrice = document.getElementById("ignmaxListPrice").value * 1000;
		else searchMaxPrice = "";
		if (document.getElementById("cat").value == "res")
		{
			searchMinBed = document.getElementById("resminBedroom").value ;
			searchMaxBed = document.getElementById("resmaxBedroom").value ;
			searchMinBath= document.getElementById("resminBathsFull").value ;
			searchMaxBath= document.getElementById("resmaxBathsFull").value ;
		}
		else if (document.getElementById("cat").value == "mob")
		{
			searchMinBed = document.getElementById("resminBedroommob").value;
			searchMaxBed = document.getElementById("resmaxBedroommob").value ;
			searchMinBath = document.getElementById("resminBathsFullmob").value;
			searchMaxBath= document.getElementById("resmaxBathsFullmob").value ;
		}
		else if (document.getElementById("cat").value == "inc")
		{
			if(document.getElementById("inclstType").options[0].selected && document.getElementById("inclstType").options[1].selected)
			{
				searchIncLstType = "resinc,resinc5" ;
			}
			else if (document.getElementById("inclstType").options[0].selected )
			{
				searchIncLstType = "resinc" ;
			}
			else if (document.getElementById("inclstType").options[1].selected)
			{
				searchIncLstType = "resinc5" ;
			}
		}
		else if (document.getElementById("cat").value == "lnd")
		{
			searchMinLotSizeAcre = document.getElementById("lndminLotSizeAcre").value ;
			searchMaxLotSizeAcre =  document.getElementById("lndmaxLotSizeAcre").value ;
		}
		searchState = strState ;

		running = false;
		bPan = false;
		bViewChanged = true;
		
		if (savedSearchId == 0)
		{
			if (doValidate())
			{
				AddRequest('listings');
				if (savedSearchId == 0) AddRequest('grid');
			}
			else
			{
				oMap.Clear();
				$('cyclelinks').style.display = 'none';
				$('ResultsGrid').innerHTML = '';
				$('listingCount').style.display='none';
				$('ListingMessage').style.display='none';
			}
		}
		else AddRequest('listings');  //do not validate if loading from saved search
		populateHiddenFields();
	}
	
	function setCookie(field)
	{
		var s=oMap.GetMapStyle();
		if (s == VEMapStyle.Birdseye)
		{
			oMap.SetMapStyle(VEMapStyle.Road);
		}
		
		if (isWebtop == 'False') document.cookie = "cat=" + document.getElementById("cat").value+ "; path=/; ";
		searchCat =  document.getElementById("cat").value;
		switch(field.id)
		{
			case "alllstCity" :
			{
				if (isWebtop == 'False') document.cookie = "alllstCity=" + field.value + "; path=/; ";
				searchCity =  field.value;
				break;
			}
			case "alllstCounty" :
			{
				if (isWebtop == 'False') document.cookie = "allstrCounty=" + field.value + "; path=/; ";
				searchCounty =  field.value;
				break;
			}
			case "alllstPostalCode":
			{
				if (isWebtop == 'False') document.cookie = "alllstPostalCode=" + field.value + "; path=/; ";
				searchZip =  field.value;
				break;
			}
			case "ignlstMLSAddress" :
			{
				verifyMLSNumorAddress();
				bField = true;
				break;
			}
			case "ignminListPrice" :
			{
				if (isWebtop == 'False')
				{
					if ((field.value) != null && (field.value) != '') document.cookie = "allminListPrice=" + (field.value)*1000 + "; path=/; ";
					else DeleteCookie("allminListPrice","/");
				}
				if ((field.value) != null && (field.value) != '') searchMinPrice = (field.value)*1000;
				else searchMinPrice = "";
				bField = true;
				break;
			}
			case "ignmaxListPrice" :
			{
				if (isWebtop == 'False')
				{
					if ((field.value) != null && (field.value) != '') document.cookie = "allmaxListPrice=" + (field.value)*1000 + "; path=/; ";
					else DeleteCookie("allmaxListPrice","/");
				}
				if ((field.value) != null && (field.value) != '') searchMaxPrice = (field.value)*1000;
				else searchMaxPrice = "";
				bField = true;
				break;
			}
			case "cat" :
			{
				
				break;
			}
			case "resminBedroom":
			{
				if (isWebtop == 'False') document.cookie = "minB=" + field.value + "; path=/; ";
				searchMinBed = field.value;
				bField = true;
				break;
			}
			case "resmaxBedroom" :
			{
				if (isWebtop == 'False') document.cookie = "maxB=" + field.value + "; path=/; ";
				searchMaxBed = field.value ;
				bField = true;
				break;
			}
			case "resminBathsFull" :
			{
				if (isWebtop == 'False') document.cookie = "minBath=" + field.value + "; path=/; ";
				searchMinBath =  field.value;
				bField = true;
				break;
			}
			case "resmaxBathsFull" :
			{
				if (isWebtop == 'False') document.cookie = "maxBath=" + field.value + "; path=/; ";
				searchMaxBath = field.value;
				bField = true;
				break;
			}
			case "lndminLotSizeAcre" :
			{
				if (isWebtop == 'False') document.cookie = "lndminLotSizeAcre=" + field.value + "; path=/; ";
				searchMinLotSizeAcre = field.value;
				break;
			}
			case "lndmaxLotSizeAcre" :
			{
				if (isWebtop == 'False') document.cookie = "lndmaxLotSizeAcre=" + field.value + "; path=/; ";
				searchMaxLotSizeAcre = field.value;
				break;
			}
			
			case "resminBedroommob":
			{
				if (isWebtop == 'False') document.cookie = "minB=" + field.value + "; path=/; ";
				searchMinBed = field.value;
				bField = true;
				break;
			}
			case "resmaxBedroommob" :
			{
				if (isWebtop == 'False') document.cookie = "maxB=" + field.value  + "; path=/; ";
				searchMaxBed = field.value;
				bField = true;
				break;
			}
			case "resminBathsFullmob" :
			{
				if (isWebtop == 'False') document.cookie = "minBath=" + field.value + "; path=/; ";
				searchMinBath = field.value;
				bField = true;
				break;
			}
			case "resmaxBathsFullmob" :
			{
				if (isWebtop == 'False') document.cookie = "maxBath=" + field.value + "; path=/; ";
				searchMaxBath = field.value;
				bField = true;
				break;
			}
			case "inclstType":
			{
				if(field.options[0].selected && field.options[1].selected)
				{
					searchIncLstType = "resinc,resinc5";
				}
				else if (field.options[0].selected)
				{
					if (isWebtop == 'False') document.cookie = "inc=" + field.value + "; path=/; ";
					searchIncLstType = "resinc";
				}
				else if (field.options[1].selected)
				{
					if (isWebtop == 'False') document.cookie = "inc=" + field.value + "; path=/; ";
					searchIncLstType = "resinc5";
				}
				bField = true;
				break;
			}
			default:
			{
				if (isWebtop == 'False')
				{
					document.cookie = "alllstStateOrProvince=" + strState + "; path=/; ";
					document.cookie = "cat=" + document.getElementById("cat").value+ "; path=/; ";
				}
				searchState = strState;
				searchCat = document.getElementById("cat").value;
			}
		}
	}
	
	
function ClearAndKeyDown(control, e)
{
	var alllstCounty = document.getElementById("alllstCounty");
	var alllstPostalCode = document.getElementById("alllstPostalCode");
	var alllstCity = document.getElementById("alllstCity");
	if(control.id.indexOf("alllstCounty") == -1 && alllstCounty != null)
	{
		alllstCounty.value = "";
		document.cookie = "allstrCounty=" + alllstCounty.value + "; path=/; ";
	}
	if(control.id.indexOf("alllstPostalCode") == -1 && alllstPostalCode != null)
	{
		alllstPostalCode.value = "";
		document.cookie = "alllstPostalCode=" + alllstPostalCode.value + "; path=/; ";
	}
	if(control.id.indexOf("alllstCity") == -1 && alllstCity != null)
	{
		alllstCity.value = "";
		document.cookie = "alllstCity=" + alllstCity.value + "; path=/; ";
	}
	handleEnterKey(e);
}
/*function onEnterKeyPress(control, e)
	{
		var key_index;
		
		var e = (e) ? e : window.event;
		
		if (e.which)
			key_index = e.which;
		if (e.keyCode)
			key_index = e.keyCode;
		
		if(key_index == 13)
			setCookie(control);

		return;
}*/

function verifyMLSNumorAddress()
{
	var en_instr = "Enter address or MLS#";
	var sp_instr = "Entre la Dirección o Número de MLS";
	var myMlsPattern = /\d{5,15}/g;
	var myMlsAddressText = "";
	myMlsAddressText = document.getElementById("ignlstMLSAddress").value;
	myMlsAddressText = myMlsAddressText.replace(/^\s*/, ''); 
	myMlsAddressText = myMlsAddressText.replace(/\s*$/, ''); 

	if(myMlsAddressText == "" || myMlsAddressText == en_instr || myMlsAddressText == sp_instr)
	{
		document.cookie = "alllstMLSListingID=" + "" + "; path=/; ";
		searchMLS = "";
		
		return false;
	}
	else
	{
		var myMlsTorF = new Boolean();
		myMlsTorF = false;
		if(!isNaN(myMlsAddressText))
			myMlsTorF = myMlsPattern.test(myMlsAddressText);
			
		if (isWebtop == 'False') document.cookie = "alllstMLSListingID=" + myMlsAddressText + "; path=/; ";
		searchMLS = myMlsAddressText;
		return true;
	}
	
}
function AddRequest(fn) 
{	
    queue.push(fn);
    if (running == false) 
    { 
       handle = setInterval("ProcessRequest()",500); 
    } 
} 


function ProcessRequest() 
{ 
    if (queue.length > 0) { 
        if (running == false) { 
            var value = queue.shift(); 
            running = true; 
            if (value == 'listings') getListings();
            else if (value == 'offices') showoffices();
            else if (value == 'schools') showschools();
            else if (value == 'grid') SetGrid();
           
         } 
    } 
} 
function showschools()
	{
		var schoolsurl = "/include/ajax/mapsearch/schoolList.aspx";
		var searchparams = '';
		if (document.getElementById("chkSchools").checked)
		{
			if (oMap.GetZoomLevel() > 11)
			{
				$('SchoolMessage').style.display = 'none';
				var minLat = GetBottomLat();
				var maxLat = GetTopLat();
				var minLong = GetLeftLong();
				var maxLong = GetRightLong();
				
				searchparams = "minLat=" + minLat + "&maxLat=" + maxLat + "&minLong=" + minLong + "&maxLong=" + maxLong ;
				var myAjax = new Ajax.Request(
				schoolsurl, 
				{
					method: 'get', 
					parameters: searchparams, 
					onComplete: showSchoolsResponse
				});
			}
			else 
			{
				$('SchoolMessage').style.display = 'block';
				$('SchoolMessage').innerHTML = "Unable to display schools at this zoom level. Please zoom in to view the schools";
				if (queue.length == 0) { 
					clearInterval(handle); 
				} 
				//ajax callback finished, another request allowed 
				running = false; 
			}
		}
		else
		{
			if (oMap.GetZoomLevel() > 11)
			{
				HideSchoolBubble();
				DeleteSchoolPushPins();
			}
			$('SchoolMessage').style.display= 'none';
			if (queue.length == 0) { 
					clearInterval(handle); 
			} 
			//ajax callback finished, another request allowed 
			running = false; 
		}
	}
	function showSchoolsResponse(originalRequest)
	{
		var response = originalRequest.responseText;
		if (response != null) 
		{
			oSchoolsJSON = eval('(' + response + ')');
		}
		if (response != '{}' && oSchoolsJSON != null && oSchoolsJSON != '')
		{
			addSchoolsPushPins();
		}
		  //check queue size 
		if (queue.length == 0) { 
			clearInterval(handle); 
		} 
		//ajax callback finished, another request allowed 
		running = false; 
	}
	function AddSchoolPushPin(id,lat,lon,s){
		var pushpin = oMap.vemapcontrol.AddPushpin(id, lat, lon, 1, 1,'schoolIcon','',500); 
		pushpin.school = s;
		pushpin.onmouseover = OnSchoolMouseOver;
		//pushpin.onmouseout = CloseSchoolBubble;
		pushpin.onclick = OnSchoolClick;
	}
	function addSchoolsPushPins()
	{
		var locs = new Array;
		var loc;
		var iLat;
		var iLong;
		
		schoolpincount = 900;
		if (oSchoolsJSON != null && oSchoolsJSON != '')
		{
			for (var i=0; i<oSchoolsJSON.Schools.length; i++)
			{
				iLat = oSchoolsJSON.Schools[i].Lat;
				iLong = oSchoolsJSON.Schools[i].Lon;
				if (iLat != '0' && iLong != '0' && iLat != '0.0' && iLong != '0.0' && iLat != null && iLong != null && iLat != '' && iLong != '')
				{
					loc = new VELatLong(iLat, iLong);
					locs.push(loc);
					AddSchoolPushPin(schoolpincount,iLat,iLong,oSchoolsJSON.Schools[i])
					schoolpincount ++;
				}
			}
		}
	}
	function OnSchoolMouseOver(e)
	{
		var t;
		var ex=GetEvent(e);
		if (ex.target) t = ex.target;
		else if (ex.srcElement) t = ex.srcElement;
		var velatlon = new VELatLong(t.school.Lat, t.school.Lon);
		var pix = oMap.LatLongToPixel(velatlon);
		ShowSchoolBubble(pix.x,pix.y,t.school);
		CloseOfficeBubble();
		HideListingBubble();
	}
	function OnSchoolClick(e)
	{
		OnSchoolMouseOver(e);
	}
	
	function DeletePin(id)
	{  
		try
		{ 
			if (id!=null)
			{
				//oMap.DeletePushpin(id);
				oMap.vemapcontrol.RemovePushpin(id);
			}
			else
			{
				oMap.DeleteAllPushpins();
			}
		}
		catch (err)
		{
			alert(err.message);
			return;
		}
	}   

	function DeleteSchoolPushPins()
	{
		for (var i=900; i<schoolpincount; i++)
		{
			DeletePin(i);
		}
		running = false;
	}

function ShowSchoolBubble(x, y, school){

	var horizontalAdjust = x+5;
	var verticalAdjust = y;
	var mapWidth = document.getElementById('Map1').offsetWidth; 	
	var mapHeight = document.getElementById('Map1').offsetHeight;
	var bubbleHeight=130;
	var bubbleWidth=300;
	var adjustheight = 0;
	var adjustwidth = 0;
	var bubble = $('schoolBubble');
		
	bubble.innerHTML = buildSchoolBubbleHtml(school);
	bubble.style.display='block';
	var strHref = window.location.href.toLowerCase();
	if(x < 0){x=0;}
	if(y < 0){y=0;}

	if (isWebtop == 'True') 
	{	
		if (strHref.indexOf("cmc") > 0) adjustheight = 30;//-120;
		else if (strHref.indexOf("savedsearchid") > 0) adjustheight = 60;//-120;
		else 
		{
			adjustheight = 47 ;
			adjustwidth = 20;
		}
	}
	if (scope == 'client' || scope == 'client_buyer' || scope == 'client_seller')  adjustheight = 45;
	else if (scope == 'office') adjustheight = 50;
	if(x+bubbleWidth >= mapWidth)
	{ 
		horizontalAdjust = x-bubbleWidth-1;
	}
	
	if(y < bubbleHeight)
	{ 
		verticalAdjust = y+bubbleHeight;
		if (isWebtop == 'True') 
		{
			if (strHref.indexOf("cmc") > 0) adjustheight = 44;//-120;
			else if (strHref.indexOf("savedsearchid") > 0) adjustheight = 85;//-120;
			else 
			{
				adjustheight = 64 ;
				adjustwidth = 20;
			}
		}
		if (scope == 'client' || scope == 'client_buyer' || scope == 'client_seller')  adjustheight = 55;
	}
	
	if (scope == 'domain') adjustheight = 40;
	else if (scope == 'office') adjustheight = 50;
	else if (scope == 'agent' || scope == 'agent_finehomes' || scope == 'team')
	{
		if (websitecateg == "AGENT/DESIGNER") 
		{
			if (theme == 'DEFAULT') adjustheight = 60;
			else adjustheight = 55 ;
		}
		else 
		{	
			if (theme == 'DEFAULT') adjustheight = 60;
			else adjustheight = 60 ;
		}
	}
	//if (is.gecko) {adjustheight += -20;}
	
	verticalAdjust = verticalAdjust + adjustheight;
	horizontalAdjust = horizontalAdjust + adjustwidth;
	bubble.className = 'schoolBubble';
	bubble.style.left = horizontalAdjust + 'px';
	bubble.style.top = verticalAdjust + 'px';
	
}
function buildSchoolBubbleHtml(oPP)
{
	var htmlFragArray = new Array();
	var htmlFrag = "";

	htmlFragArray.push("<div id=bubble class=mapbubble>");
		htmlFragArray.push("<div class=bubbleTitlebar><h3>School Info</h3>");
		htmlFragArray.push("<a href='javascript:CloseSchoolBubble()'><img class='remove' src=/images/removeButton.gif border=0></a></div>");
		htmlFragArray.push("<div class=bubbleData>");
			
			htmlFragArray.push("<div class=bubbleInfo><p>");
				htmlFragArray.push(oPP.SchoolName + "<br />");
				htmlFragArray.push(oPP.Street + "<br />" );
				htmlFragArray.push( oPP.City + "," + oPP.State + " " + oPP.Zip + "<br /><br/>");
				htmlFragArray.push("Phone: " + oPP.Phone + "<br />" );
				htmlFragArray.push("Fax: " + oPP.Fax +  "</p>" );
				if (isWebtop == 'False') htmlFragArray.push("<p><a href=javascript:schoolDetailsredirect('" + oPP.UniversalID + "')>more..</a></p>");
			htmlFragArray.push("</div>");
		htmlFragArray.push("</div>");
	htmlFragArray.push("</div>");

	htmlFrag = htmlFragArray.join('');	
	return htmlFrag;
}
function schoolDetailsredirect(uId)
{
	var strUrl = "SchoolDetails.aspx?SchoolID=" + uId + "#ModuleControlSchoolDetails" ;
	document.cookie = "cords=" + redirectparams + "; path=/; ";
	document.cookie = "redirect=" + "true" + "; path=/; ";
	//document.cookie = "sort=" + sortcolumnname + "," + sortdirection + "; path=/; ";
	var s = 0;
	var o = 0;
	if ($('chkSchools') != null) 
	{
		if ($('chkSchools').checked) s = 1;
		else s = 0;
	}
	if ($('chkOffices') != null)
	{
		if ($('chkOffices').checked) o = 1;
		else o = 0;
	}
	if (s==1 && o==1) document.cookie = "so=1,1" + "; path=/; ";
	else if (s==0 && o==1) document.cookie = "so=0,1" + "; path=/; ";
	else if (s==1 && o==0) document.cookie = "so=1,0" + "; path=/; ";
		
	window.location.href = strUrl;
}
function HideSchoolBubble(e)
{
	CloseSchoolBubble();	
}

function CloseSchoolBubble(){
	$('schoolBubble').style.display='none'; 
}

function showoffices()
{
	var locs = new Array;
	var loc;
	var iLat;
	var iLong;

	var officeurl = "/include/ajax/mapsearch/officeList.aspx";
	var searchparams;
	if (document.getElementById("chkOffices").checked)
	{
		var minLat = GetBottomLat();
		var maxLat = GetTopLat();
		var minLong = GetLeftLong();
		var maxLong = GetRightLong();
		
		searchparams = "minLat=" + minLat + "&maxLat=" + maxLat + "&minLong=" + minLong + "&maxLong=" + maxLong ;
		var myAjax = new Ajax.Request(
		officeurl, 
		{
			method: 'get', 
			parameters: searchparams, 
			onComplete: showOfficesResponse
		});
	}
	else
	{
		HideOfficeBubble();
		DeleteOfficePushPins();
	}
}
	function showOfficesResponse(originalRequest)
	{
		var response = originalRequest.responseText;
		//alert(response);
		if (response != null) 
		{
			oOfficesJSON = eval('(' + response + ')');
		}
		if (response != '{}' && oOfficesJSON != null && oOfficesJSON != '')
		{
			addOfficePushPins();
		}
		if (queue.length == 0) { 
        clearInterval(handle); 
		} 
		//ajax callback finished, another request allowed 
		running = false;
	}
	function AddOfficePushPin(id,lat,lon,o){
		var pushpin = oMap.vemapcontrol.AddPushpin(id, lat, lon, 1, 1,'officeIcon','',500); 
		pushpin.office = o;
		pushpin.onmouseover = OnOfficeMouseOver;
		pushpin.onclick = OnOfficeClick;
	}
	function addOfficePushPins()
	{
		var locs = new Array;
		var loc;
		var iLat;
		var iLong;
		
		officepincount = 800;
		if (oOfficesJSON != null && oOfficesJSON != '')
		{
			for (var i=0; i<oOfficesJSON.offices.length; i++)
			{
				iLat = oOfficesJSON.offices[i].Latitude;
				iLong = oOfficesJSON.offices[i].Longitude;
				if (iLat != '0' && iLong != '0' && iLat != '0.0' && iLong != '0.0' && iLat != null && iLong != null && iLat != '' && iLong != '')
				{
					loc = new VELatLong(iLat, iLong);
					locs.push(loc);
					AddOfficePushPin(officepincount,iLat,iLong,oOfficesJSON.offices[i])
					officepincount ++;
				}
				
			}
			
		}
	}
	function OnOfficeMouseOver(e)
	{
		var t;
		var ex=GetEvent(e);
		if (ex.target) t = ex.target;
		else if (ex.srcElement) t = ex.srcElement;
		var velatlon = new VELatLong(t.office.Latitude, t.office.Longitude);
		var pix = oMap.LatLongToPixel(velatlon);
		ShowSOfficeBubble(pix.x,pix.y,t.office);
		HideListingBubble();
		CloseSchoolBubble();
	}
	function OnOfficeClick(e)
	{
		OnOfficeMouseOver(e);
	}
	function DeleteOfficePushPins()
	{
		for (var i=800; i<officepincount; i++)
		{
			DeletePin(i);
		}
		running = false;
	}
	function ShowSOfficeBubble(x, y, office)
	{
		var horizontalAdjust = x+5;
		var verticalAdjust = y;
		var mapWidth = document.getElementById('Map1').offsetWidth; 	
		var mapHeight = document.getElementById('Map1').offsetHeight;
		var bubbleHeight=130;
		var bubbleWidth=300;
		var adjustheight = 0;
		var adjustwidth = 0;
		var bubble = $('officeBubble');
			
		bubble.innerHTML = buildOfficeBubbleHtml(office);
		bubble.style.display='block';
		
		if(x < 0){x=0;}
		if(y < 0){y=0;}

		if (isWebtop == 'True') adjustheight = 47 ;
		else if (scope == 'client' || scope == 'client_buyer' || scope == 'client_seller')  adjustheight = 50;
		else if (scope == 'office') adjustheight = 15;
		if(x+bubbleWidth >= mapWidth)
		{ 
			horizontalAdjust = x-bubbleWidth-1;
		}
		
		if(y < bubbleHeight)
		{ 
			verticalAdjust = y+bubbleHeight;
			if (isWebtop == 'True') adjustheight = 64 ;
			if (scope == 'client' || scope == 'client_buyer' || scope == 'client_seller')  adjustheight = 55;
		}

		if (scope == 'domain') adjustheight = 40;
		else if (scope == 'office') adjustheight = 45;
		else if (scope == 'agent' || scope == 'agent_finehomes' || scope == 'team')
		{
			if (websitecateg == "AGENT/DESIGNER") 
			{
				if (theme == 'DEFAULT') adjustheight = 60;
				else adjustheight = 55 ;
			}
			else 
			{	
				if (theme == 'DEFAULT') adjustheight = 60;
				else adjustheight = 60 ;
			}
		}
		
		verticalAdjust = verticalAdjust + adjustheight;
		horizontalAdjust = horizontalAdjust + adjustwidth;
		bubble.className = 'officeBubble';
		bubble.style.left = horizontalAdjust + 'px';
		bubble.style.top = verticalAdjust + 'px';
		
	}

function buildOfficeBubbleHtml(oPP){
	var htmlFragArray = new Array();
	var htmlFrag = "";

	htmlFragArray.push("<div id=bubble class=mapbubble>");
	htmlFragArray.push("<div class=bubbleTitlebar><h3>Office Info</h3>");
		htmlFragArray.push("<a href='javascript:CloseOfficeBubble()'><img class='remove' src=/images/removeButton.gif border=0></a></div>");
		htmlFragArray.push("<div class=bubbleData>");
			
			htmlFragArray.push("<div class=bubbleInfo>");
				if(oPP.CompanyOwned == 0)
					htmlFragArray.push("<p><a href=javascript:officeredirect('" + oPP.homePage + "')>" + oPP.officeName + "</a> **<br />");
				else 
					htmlFragArray.push("<p><a href=javascript:officeredirect('" + oPP.homePage + "')>" + oPP.officeName + "</a><br />");
				htmlFragArray.push(oPP.address + "<br />");				
				htmlFragArray.push(oPP.cityStateZip + "<br />");
				if((oPP.phone.length > 0) || (oPP.fax.length > 0)){
					htmlFragArray.push("<br />");
				}
				if(oPP.phone.length > 0){
					htmlFragArray.push("Phone: " + oPP.phone + "<br>");				
				}
				if(oPP.fax.length > 0){
					htmlFragArray.push("Fax: " + oPP.fax);			
				}
			htmlFragArray.push("</p></div>");
			htmlFragArray.push("<div class='listing-photo'><img src='" + imageServerURL + "/include/imageServer.aspx?officeID=" + oPP.officeID + "&height=75&width=-1' height=75 border='0' /></div>");
		htmlFragArray.push("</div>");
	htmlFragArray.push("</div>");

	htmlFrag = htmlFragArray.join('');	
	
	return htmlFrag;
}
function officeredirect(url)
{
	/*document.cookie = "cords=" + redirectparams + "; path=/; ";
	document.cookie = "redirect=" + "true" + "; path=/; ";
	var s = 0;
	var o = 0;
	if ($('chkSchools') != null) 
	{
		if ($('chkSchools').checked) s = 1;
		else s = 0;
	}
	if ($('chkOffices') != null)
	{
		if ($('chkOffices').checked) o = 1;
		else o = 0;
	}
	if (s==1 && o==1) document.cookie = "so=1,1" + "; path=/; ";
	else if (s==0 && o==1) document.cookie = "so=0,1" + "; path=/; ";
	else if (s==1 && o==0) document.cookie = "so=1,0" + "; path=/; ";
	window.location.href = url;*/
	var ltop = (screen.availHeight - 550)/2	;
	var lleft = (screen.availWidth - 920)/2 ;
	window.open(url,null,"top=" + ltop + ",left=" + lleft + ",height=550,width=920,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes" );
}
function HideOfficeBubble(e)
{
	CloseOfficeBubble('');	
}

function CloseOfficeBubble(){
	$('officeBubble').style.display='none'; 
}	
	function SetGrid()
	{
		/* grid stuff starts*/
		var  price;
		var address;
		var city;
		var bedrooms;
		var bathsfull;
		var bathspartial;
		var LivingArea;
		var iLat;
		var iLong;
		var showingtime = '';
		var mlsLogo = '';
		var listOfficeName, listingId, state, zip, isPruList, listAgentAgentId, officeId, mlsId, listAgentName;
		/* grid stuff ends*/
		pushpinCount = 0;
 		if (oJSON != null && oJSON != '')
		{
		
			var listingcount = 0;
			if (oJSON.listings.length > 200) listingcount = 200;
			else listingcount = oJSON.listings.length;
			
			var htmlFragArray = new Array();
			var htmlFrag = "";
			/* grid stuff starts*/
			if(domainid == 4 || domainid == 5)
			{
				htmlFragArray.push("<table id='tbListings' class='sortable' border='0' cols='7' width='100%'><tr id='trHeader' width='100%'>");
				if ($('cat').value == 'res' || $('cat').value == 'mob')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th class='br'>BR</th><th class='ba'>BA Full</th><th class='ba'>BA Partial</th><th class='sqft'>Sq Ft</th><th style=display:none>jsonindex</th></tr>");
				else if ($('cat').value == 'lnd')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th class='lotsize'>Lot Size</th><th style=display:none>jsonindex</th></tr>");
				else if ($('cat').value == 'inc')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th class='units'>Units</th><th style=display:none>jsonindex</th></tr>");
				else if ($('cat').value == 'bus')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th style=display:none>jsonindex</th></tr>");
			}
			else{
				htmlFragArray.push("<table id='tbListings' class='sortable' border='0' cols='8' width='100%'><tr id='trHeader' width='100%'>");
				if ($('cat').value == 'res' || $('cat').value == 'mob')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th class='br'>BR</th><th class='ba'>BA Full</th><th class='ba'>BA Partial</th><th class='sqft'>Sq Ft</th><th class='listdate'>List Date</th><th style=display:none>jsonindex</th></tr>");
				else if ($('cat').value == 'lnd')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th class='lotsize'>Lot Size</th><th class='listdate'>List Date</th><th style=display:none>jsonindex</th></tr>");
				else if ($('cat').value == 'inc')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th class='units'>Units</th><th class='listdate'>List Date</th><th style=display:none>jsonindex</th></tr>");
				else if ($('cat').value == 'bus')
					htmlFragArray.push("<th class='price'>Price</th><th class='address'>Address</th><th class='city'>City</th><th class='listdate'>List Date</th><th style=display:none>jsonindex</th></tr>");
				
			}
			/* grid stuff ends*/
			for (var i=0; i<listingcount; i++)
			{
				iLat = oJSON.listings[i].latitude;
				iLong = oJSON.listings[i].longitude;
				if(domainid == 4 || domainid == 5)
				{
					if (iLat != '0' && iLong != '0' && iLat != '0.0' && iLong != '0.0' && iLat != null && iLong != null && iLat != '' && iLong != '')
					{
						pushpinCount ++;

						htmlFragArray.push("<tr id='trRow' onmouseover=\"AddRow(" + pushpinCount + "," + i + ")\" >");
						if (isWebtop == 'True') htmlFragArray.push("<td class='price'>$" + fmtMoney(oJSON.listings[i].ListPrice,0,'.',',') + "</td><td class='address' width='32%'><a href=javascript:webtopPropertyDetail('" + oJSON.listings[i].mlslistingid + "','" + oJSON.listings[i].mlsid + "')>" + oJSON.listings[i].address + " " + oJSON.listings[i].unitnumber + "</a></td><td class='city'>" + oJSON.listings[i].city + "</td>");
						else htmlFragArray.push("<td class='price'>$" + fmtMoney(oJSON.listings[i].ListPrice,0,'.',',') + "</td><td class='address' width='32%'><a href=javascript:redirect('" + oJSON.listings[i].listingid + "')>" + oJSON.listings[i].address + " " + oJSON.listings[i].unitnumber + "</a></td><td class='city'>" + oJSON.listings[i].city + "</td>");
						if ($('cat').value == 'res' || $('cat').value == 'mob')
						{
							htmlFragArray.push("<td class='br'>" + oJSON.listings[i].Bedrooms + "</td><td class='ba'>" + oJSON.listings[i].bathsfull + "</td><td class='ba'>" + oJSON.listings[i].bathspartial + "</td>");
							htmlFragArray.push("<td class='sqft'>" + oJSON.listings[i].LivingArea + "</td><td class='listdate'></td><td style=display:none>" + i + "</td></tr>");
						}
						else if ($('cat').value == 'lnd')
						{
							htmlFragArray.push("<td class='lotsize'>" + oJSON.listings[i].lotsizeacre + "</td><td class='listdate'></td><td style=display:none>" + i + "</td></tr>");
						}
						else if ($('cat').value == 'inc')
						{
							htmlFragArray.push("<td class='units'>" + oJSON.listings[i].multitotalunits + "</td><td class='listdate'></td><td style=display:none>" + i + "</td></tr>");
						}
						else if ($('cat').value == 'bus')
						{
							htmlFragArray.push("<td class='listdate'></td><td style=display:none>" + i + "</td></tr>");
						}
					}
				}else
				{
					if (iLat != '0' && iLong != '0' && iLat != '0.0' && iLong != '0.0' && iLat != null && iLong != null && iLat != '' && iLong != '')
					{
						pushpinCount ++;

						htmlFragArray.push("<tr id='trRow' onmouseover=\"AddRow(" + pushpinCount + "," + i + ")\" >");
						if (isWebtop == 'True') htmlFragArray.push("<td class='price'>$" + fmtMoney(oJSON.listings[i].ListPrice,0,'.',',') + "</td><td class='address' width='32%'><a href=javascript:webtopPropertyDetail('" + oJSON.listings[i].mlslistingid + "','" + oJSON.listings[i].mlsid + "')>" + oJSON.listings[i].address + " " + oJSON.listings[i].unitnumber + "</a></td><td class='city'>" + oJSON.listings[i].city + "</td>");
						else htmlFragArray.push("<td class='price'>$" + fmtMoney(oJSON.listings[i].ListPrice,0,'.',',') + "</td><td class='address' width='32%'><a href=javascript:redirect('" + oJSON.listings[i].listingid + "')>" + oJSON.listings[i].address + " " + oJSON.listings[i].unitnumber + "</a></td><td class='city'>" + oJSON.listings[i].city + "</td>");
						if ($('cat').value == 'res' || $('cat').value == 'mob')
						{
							htmlFragArray.push("<td class='br'>" + oJSON.listings[i].Bedrooms + "</td><td class='ba'>" + oJSON.listings[i].bathsfull + "</td><td class='ba'>" + oJSON.listings[i].bathspartial + "</td>");
							htmlFragArray.push("<td class='sqft'>" + oJSON.listings[i].LivingArea + "</td><td class='listdate'>" + getDateString(oJSON.listings[i].ListDate) + "</td><td style=display:none>" + i + "</td></tr>");
						}
						else if ($('cat').value == 'lnd')
						{
							htmlFragArray.push("<td class='lotsize'>" + oJSON.listings[i].lotsizeacre + "</td><td class='listdate'>" + getDateString(oJSON.listings[i].ListDate) + "</td><td style=display:none>" + i + "</td></tr>");
						}
						else if ($('cat').value == 'inc')
						{
							htmlFragArray.push("<td class='units'>" + oJSON.listings[i].multitotalunits + "</td><td class='listdate'>" + getDateString(oJSON.listings[i].ListDate) + "</td><td style=display:none>" + i + "</td></tr>");
						}
						else if ($('cat').value == 'bus')
						{
							htmlFragArray.push("<td class='listdate'>" + getDateString(oJSON.listings[i].ListDate) + "</td><td style=display:none>" + i + "</td></tr>");
						}
					}
				}
			}
			/* grid stuff */
			htmlFragArray.push("</table>");
			htmlFrag = htmlFragArray.join('');	
			
			document.getElementById("ResultsGrid").innerHTML = htmlFrag;//strListings;
			sortables_init();
			//resort is commented out to optimize performance.
			//if (readCookie("sort") != null) ts_resortTable(sortcolumnname, document.getElementById(sortcolumnname),sortcolumnNum);
			//DeleteCookie("sort","/");
			setPager();
			
			if (queue.length == 0) { 
				clearInterval(handle); 
			} 
			//ajax callback finished, another request allowed 
			running = false; 
		}
	}
	function displayForDallas(mlsId, domainid)
	{
		if (domainid == 4 && mlsId == 12) return true;
		else return false;
	}
	function getShowingTimeUrl(listOfficeName, listingId, address, city, state, zip, price, isPruList, listAgentAgentId, officeId,domID)
	{
		
		var url = "http://links.showingtime.com/external/?";

		if(domID==4){
			url += "siteid=PRUDENTIALTEXAS.COM";
		}else{
			url += "siteid=PRUREALTY.COM";
		}

		url += "&broker=";
		url += encodeParams(listOfficeName);
		
		if(domID==4){
			url += "&mlsid=PRUTX";
		}else{
			url += "&mlsid=PRUCAL";
		}
			
		url += "&listingid=" + listingId;
		url += "&paddr=" + encodeParams(address);
		url += "&pcity=" + encodeParams(city);
		url += "&pstate=" + state;
		url += "&pzip=" + zip;
		url += "&price=" + price;
		url += "&laid=";
		if (isPruList == 1)
		{
			url += listAgentAgentId;
			url += "&listingoffice=";
			url += officeId ;
		}
		else
		{
			url += "IDX&listingoffice=";
			url += encodeParams(listOfficeName);
		}
		return url;
	}
	function encodeParams(par)
	{
		var param;
		if (window.encodeURIComponent) 
			param = encodeURIComponent(par); 
		else if (window.escape) 
			param = escape(par); 
		return param;
			
	}
	function getMLSLogoId(mlsid, isprulist)
	{
		var mlslogoid;
		if (strState == "AZ")
		{
			if (isprulist == 1) mlslogoid = "RE";
			else mlslogoid = mlsid;
		}
		else  mlslogoid = mlsid;
		return mlslogoid;
	}
	function getListAgentName(listAgentName, mlsid, isprulist)
	{
		var strAgentname = listAgentName +  "&nbsp;|&nbsp;" ;
		if (domainid == 2)
		{
			if (mlsid == 16) strAgentname = listAgentName +  "&nbsp;|&nbsp;" ;
			else
			{
				if(isprulist == "0") strAgentname = "";
			}
		}
		else
		{
			if (mlsid==19 || mlsid==17 || mlsid==5 || mlsid==10)
			{
				strAgentname = "";
			}
		}
		return strAgentname;
	}
	function fnToggleGridRow(iRow, len)
	{

		for (var i=0; i<len; i++)
		{
			if (document.getElementById('listDetail' + i) != null) 
			{
				document.getElementById('listDetail' + i).className = 'togglegridrow1';
			}
		}
		document.getElementById('listDetail' + iRow).className = 'togglegridrow2';
		Effect.Appear('listDetail' + iRow);
		
	}
	function AddRow(rowindex, jsonindex)
	{
		var l = oJSON.listings[jsonindex];
		var price = l.ListPrice;
		var listOfficeName = l.listOfficeName;
		var listingId = l.listingid;
		var state = l.stateorprovince;
		var zip = l.postalcode;
		var isPruList = l.isprulist;
		var listAgentAgentId = l.listagentagentid;
		var listAgentUserId = l.userId;
		var officeId = l.officeID;
		var mlsId = l.mlsid;
		var listAgentName = getListAgentName(l.listAgentName,mlsId,isPruList);
		var address = l.address;
		var city = l.city;
		var tbl = document.getElementById('tbListings');
		
		for (var ti=0;ti<tbl.rows.length;ti++) 
		{
			var thisrow = tbl.rows[ti];
			if (thisrow.id == 'sRow')
			{
				tbl.deleteRow(ti);
			}
        }
       
		var showingtime;
		if ((domainid == 1 || domainid == 4) && scope == 'domain') showingtime = "<a class=showing-time id=lnkShowingTime href='" + getShowingTimeUrl(listOfficeName,listingId,address, city, state, zip,price, isPruList, listAgentUserId, officeId,domainid) + "' target=_blank>Schedule a Showing</a>" + "&nbsp;&nbsp;|&nbsp;&nbsp;";
		else showingtime = "";

		var strHtml = "";
		var mlsLogo = getMLSLogoId(mlsId, isPruList)
		
		if (bRow==true || rowindex > 1)
		{
			var row = tbl.insertRow(rowindex+1);
			row.id = "sRow";
			var cell0 = row.insertCell(0);
			cell0.innerHTML = showingtime + listOfficeName + "&nbsp;|&nbsp;" + listAgentName  + "<span class='logo-16px'><img src='/images/IDXLogo_" + mlsLogo + ".gif'/></span>";
			if ($('cat').value == 'res' || $('cat').value == 'mob') cell0.setAttribute('colSpan',8);
			else if ($('cat').value == 'lnd' || $('cat').value == 'inc' ) cell0.setAttribute('colSpan',5);
			else if ($('cat').value == 'bus') cell0.setAttribute('colSpan',4);
		}
		
		var velatlon = new VELatLong(l.latitude, l.longitude);
		var pix = oMap.LatLongToPixel(velatlon);
		HideOfficeBubble();
		HideSchoolBubble();
		ShowListingBubble(pix.x,pix.y,l);
	}
	function DeleteRow(rowindex)
     {
         
	}
	function setPager()
	{
		o = new Pager('tbListings');
		o.PageSize = pagesize;
		o.AbsolutePage = 1;
		o.display();
		o.navBar('o','cyclelinks');
	}
	
	function isClientLoggedIn()
	{
		if (readCookie("ignCurrentClientID") == null || readCookie("ignCurrentClientID") == '') return false;
		else return true;
	}
	function ChangeMapStyle()
	{	
		if (($('btnSaveSearch') != null) &&  savedSearchId==0) {
			$('btnSaveSearch').disabled = false;
		}
		
		HideListingBubble();
		HideSchoolBubble();
		HideOfficeBubble();
		if (queue.length == 0) { 
			clearInterval(handle); 
		} 
		running = false; // start running the next request.
		var s=oMap.GetMapStyle();
		if (savedSearchId == 0)
		{
			if (!bViewChanged && (s==currMapStyle || currMapStyle=='') && readCookie("redirect") == null)
			{
				document.getElementById("alllstCity").value = "";
				document.getElementById("alllstCounty").value = "";
				document.getElementById("alllstPostalCode").value = "";
				document.getElementById("ignlstMLSAddress").value = "";
				DeleteCookie("alllstCity", "/") ;
				DeleteCookie("allstrCounty", "/") ;
				DeleteCookie("alllstPostalCode", "/") ;
				DeleteCookie("alllstMLSListingID", "/") ;
				DeleteCookie("alllstaddress", "/") ;
				searchCity = "";
				searchCounty = "";
				searchZip = "";
				searchMLS = "";
							
				bPan = true;
				AddRequest('listings');
				AddRequest('grid');
				//AddRequest('schools');
				//AddRequest('offices');
				
			}
			else 
			{
				bViewChanged = false;
			}
		}
		else
		{
			bViewChanged = false;
			savedSearchId = 0 ;
		}
		if (s == VEMapStyle.Birdseye)
		{
			$('ListingMessage').style.display='none';
			$('listingCount').style.display='none';
			$('chkSchools').disabled = true;
			$('chkOffices').disabled = true;
		}
		else
		{
			$('listingCount').style.display='block';
			if (oJSON !=null && oJSON.listings.length > 200)
			{
				$('ListingMessage').style.display='block';
				$('ListingMessage').innerHTML = 'More than 200 listings found';
			}
			$('chkSchools').disabled = false;
			$('chkOffices').disabled = false;
		}
		currMapStyle = oMap.GetMapStyle();
		var minLat = GetBottomLat();
		var maxLat = GetTopLat();
		var minLong = GetLeftLong();
		var maxLong = GetRightLong();
		if (strmode != 'savedsearch' && strcancel != 'True') document.cookie = "cords=" + minLat + "," + maxLat + "," + minLong + "," + maxLong + "; path=/; ";
		redirectparams = minLat + "," + maxLat + "," + minLong + "," + maxLong; //back button
		if (readCookie("redirect") != null && checkCookie()) DeleteCookie("cords","/"); //from back button the listing count was different
		//populate hidden for saved search
		populateHiddenFields();	
	}
	function populateHiddenFields()
	{
		$('allminlatitude').value = GetBottomLat();
		$('allmaxlatitude').value = GetTopLat();
		$('allminlongitude').value = GetLeftLong();
		$('allmaxlongitude').value = GetRightLong();
		$('allignvemapcenterlat').value = oMap.GetCenter().Latitude;
		$('allignvemapcenterlon').value = oMap.GetCenter().Longitude;
		$('allignvemapzoom').value = oMap.GetZoomLevel();
		$('allignvemapstyle').value = oMap.GetMapStyle();
	}
	function whichbrowser()
	{
		var bool = true;
		if (!isIE3Mac && is.gecko)
		{
			// JavaScript here for user agents implementing Gecko layout engine}
			bool = true; //firefox 1.5.07
		}
		else if  (!isIE3Mac && is.nav4)
		{
		// JavaScript here for Navigator 4
			bool = false;
		}
		else if (!isIE3Mac && (is.ie6 || is.ie6up))
		{
			bool = true;
		}
		else if (!isIE3Mac && (is.ie5 || is.ie5up))
		{
		// JavaScript here for IE 5 and later
			bool = false;
		}
		
		else if (!isIE3Mac && (is.nav3 || is.opera))
		{
		// JavaScript here for Nav3 and Opera 
			bool = false;
		}
		else 
		{
		// JavaScript here for Nav2 and IE 3
			bool = false; 
		}
		return bool;
	}
	function getDateString(DateToCheck)
	{
		var dt =new Date(DateToCheck);
		var monthnumber = dt.getMonth() + 1;
		var monthday    = dt.getDate();
		var year        = dt.getUTCFullYear();//dt.getYear();
		
		if (monthnumber < 10) monthnumber = '0' + monthnumber ;
		if (monthday < 10) monthday = '0' + monthday;
		
		var strDate = monthnumber + "/" + monthday + "/" + year;
		return strDate;
		
	}
	
	function resetForm()
	{
		//back
		if (readCookie("redirect") != null && strmode=='return' && isWebtop == 'False')
		{
			if (readCookie("alllstStateOrProvince") != null) searchState = readCookie("alllstStateOrProvince");
			if (readCookie("allminListPrice") != null && readCookie("allminListPrice") != '') 
			{
				document.getElementById("ignminListPrice").value = (readCookie("allminListPrice"))/1000;
				searchMinPrice = readCookie("allminListPrice");
			}
			if (readCookie("allmaxListPrice") != null && readCookie("allmaxListPrice") != '') 
			{
				document.getElementById("ignmaxListPrice").value = (readCookie("allmaxListPrice"))/1000;
				searchMaxPrice = readCookie("allmaxListPrice");
			}
			if (readCookie("alllstMLSListingID") != null) 
			{
				document.getElementById("ignlstMLSAddress").value  = readCookie("alllstMLSListingID");
				searchMLS = readCookie("alllstMLSListingID");
			}
			if (readCookie("alllstCity") != null) 
			{
				document.getElementById("alllstCity").value  = readCookie("alllstCity");
				searchCity = readCookie("alllstCity");
			}
			if (readCookie("allstrCounty") != null) 
			{
				document.getElementById("alllstCounty").value  = readCookie("allstrCounty");
				searchCounty = readCookie("allstrCounty");
			}
			if (readCookie("alllstPostalCode") != null) 
			{
				document.getElementById("alllstPostalCode").value  = readCookie("alllstPostalCode");
				searchZip = readCookie("alllstPostalCode");
			}
			if (readCookie("cat") != null)
			{
				searchCat = readCookie("cat");
				if (readCookie("cat") == 'res') 
				{
					document.getElementById("cat").options[0].selected = true; 
					if (readCookie("minB") != null) 
					{
						document.getElementById("resminBedroom").value  = readCookie("minB");
						searchMinBed = readCookie("minB");
						if (readCookie("minB") > 0) document.getElementById("resminBedroom").options[readCookie("minB")].selected = true;
						else document.getElementById("resminBedroom").options[0].selected = true;
					}
					if (readCookie("maxB") != null)
					{
						document.getElementById("resmaxBedroom").value = readCookie("maxB");
						searchMaxBed = readCookie("maxB");
						if (readCookie("maxB") > 0) document.getElementById("resmaxBedroom").options[readCookie("maxB")].selected = true;
						else document.getElementById("resmaxBedroom").options[0].selected = true;
					}
					if (readCookie("minBath") != null)
					{	
						document.getElementById("resminBathsFull").value = readCookie("minBath");
						searchMinBath = readCookie("minBath");
						var j = getpartialbathIndex(readCookie("minBath"));
						document.getElementById("resminBathsFull").options[j].selected = true;
					}
					if (readCookie("maxBath") != null)
					{
						document.getElementById("resmaxBathsFull").value = readCookie("maxBath");
						searchMaxBath = readCookie("maxBath");
						j = getpartialbathIndex(readCookie("maxBath"));
						document.getElementById("resmaxBathsFull").options[j].selected = true;
					}
				}
				else if (readCookie("cat") == 'lnd') 
				{
					document.getElementById("cat").options[1].selected = true; 
					if (readCookie("lndminLotSizeAcre") != null) 
					{
						document.getElementById("lndminLotSizeAcre").value  = readCookie("lndminLotSizeAcre");
						searchMinLotSizeAcre = readCookie("lndminLotSizeAcre");
					}
					if (readCookie("lndmaxLotSizeAcre") != null) 
					{
						document.getElementById("lndmaxLotSizeAcre").value  = readCookie("lndmaxLotSizeAcre");
						searchMaxLotSizeAcre = readCookie("lndmaxLotSizeAcre");
					}
				}
				else if (readCookie("cat") == 'inc') 
				{
					document.getElementById("cat").options[2].selected = true; 
					if (readCookie("inc") != null)
					{
						document.getElementById("inclstType").options[0].selected = false; 
						document.getElementById("inclstType").options[1].selected = false;
						if (readCookie("inc").indexOf(",") > 0) //resinc,resinc5
						{
							document.getElementById("inclstType").options[0].selected = true; 
							document.getElementById("inclstType").options[1].selected = true;
						}
						else
						{
							if (readCookie("inc").indexOf("5") > 0) {document.getElementById("inclstType").options[1].selected = true; }
							else document.getElementById("inclstType").options[0].selected = true;
						}
						searchIncLstType = readCookie("inc");
					}
				}
				else if (readCookie("cat") == 'bus') 
				{
					document.getElementById("cat").options[3].selected = true; 
				}
				else if (readCookie("cat") == 'mob') 
				{
					document.getElementById("cat").options[4].selected = true;
					if (readCookie("minB") != null) 
					{
						document.getElementById("resminBedroommob").value  = readCookie("minB");
						searchMinBed = readCookie("minB");
						if (readCookie("minB") > 0) document.getElementById("resminBedroommob").options[readCookie("minB")].selected = true;
						else document.getElementById("resminBedroommob").options[0].selected = true;
					}
					if (readCookie("maxB") != null)
					{
						document.getElementById("resmaxBedroommob").value = readCookie("maxB");
						searchMaxBed = readCookie("maxB");
						if (readCookie("maxB") > 0) document.getElementById("resmaxBedroommob").options[readCookie("maxB")].selected = true;
						else document.getElementById("resmaxBedroommob").options[0].selected = true;
					}
					if (readCookie("minBath") != null)
					{	
						document.getElementById("resminBathsFullmob").value = readCookie("minBath");
						searchMinBath = readCookie("minBath");
						var j = getpartialbathIndex(readCookie("minBath"));
						document.getElementById("resminBathsFullmob").options[j].selected = true;
					}
					if (readCookie("maxBath") != null)
					{
						document.getElementById("resmaxBathsFullmob").value = readCookie("maxBath");
						searchMaxBath = readCookie("maxBath");
						j = getpartialbathIndex(readCookie("maxBath"));
						document.getElementById("resmaxBathsFullmob").options[j].selected = true;
					} 
				}
			}
		}
		else
		{
			if (isWebtop == 'False')
			{
				document.cookie = "cat=" + document.getElementById("cat").value + "; path=/; ";
				document.cookie = "alllstCity=" + document.getElementById("alllstCity").value + "; path=/; ";
				document.cookie = "allstrCounty=" + document.getElementById("alllstCounty").value + "; path=/; ";
				document.cookie = "alllstPostalCode=" + document.getElementById("alllstPostalCode").value + "; path=/; ";
				document.cookie = "alllstStateOrProvince=" + strState + "; path=/; ";//document.getElementById("alllstStateOrProvince").value + "; path=/; ";
				document.cookie = "alllstMLSListingID=" + document.getElementById("ignlstMLSAddress").value + "; path=/; ";
				document.cookie = "allminListPrice=" + document.getElementById("ignminListPrice").value + "; path=/; ";
				document.cookie = "allmaxListPrice=" + document.getElementById("ignmaxListPrice").value + "; path=/; ";
				
				if (readCookie("cat") == "res")
				{
					document.cookie = "minB=" + document.getElementById("resminBedroom").value + "; path=/; ";
					document.cookie = "maxB=" + document.getElementById("resmaxBedroom").value + "; path=/; ";
					document.cookie = "minBath=" + document.getElementById("resminBathsFull").value + "; path=/; ";
					document.cookie = "maxBath=" + document.getElementById("resmaxBathsFull").value + "; path=/; ";
				}
				if (readCookie("cat") == "lnd")
				{
					document.cookie = "lndminLotSizeAcre=" + document.getElementById("lndminLotSizeAcre").value + "; path=/; ";
					document.cookie = "lndmaxLotSizeAcre=" + document.getElementById("lndmaxLotSizeAcre").value + "; path=/; ";
				}
				if (readCookie("cat") == "mob")
				{
					document.cookie = "minB=" + document.getElementById("resminBedroommob").value + "; path=/; ";
					document.cookie = "maxB=" + document.getElementById("resmaxBedroommob").value + "; path=/; ";
					document.cookie = "minBath=" + document.getElementById("resminBathsFullmob").value + "; path=/; ";
					document.cookie = "maxBath=" + document.getElementById("resmaxBathsFullmob").value + "; path=/; ";
				}
				$('chkOffices').checked = false;
				$('chkSchools').checked = false;
			}
			else
			{
				//iswebtop & cancel button hit after save search click
				
				if (strcancel == 'True')
				{
					searchCat = wtsearchCat;
					if (wtsearchCat == "res")
					{
						document.getElementById("cat").options[0].selected = true; 
						searchMinBed = wtsearchMinBed;
						searchMaxBed = wtsearchMaxBed;
						searchMinBath = wtsearchMinBath;
						searchMaxBath = wtsearchMaxBath;
						if (wtsearchMinBed > 0) document.getElementById("resminBedroom").options[wtsearchMinBed].selected = true;
						else document.getElementById("resminBedroom").options[0].selected = true;
						if (wtsearchMaxBed > 0) document.getElementById("resmaxBedroom").options[wtsearchMaxBed].selected = true;
						else document.getElementById("resmaxBedroom").options[0].selected = true;
						var j = getpartialbathIndex(wtsearchMinBath);
						document.getElementById("resminBathsFull").options[j].selected = true;
						j = getpartialbathIndex(wtsearchMaxBath);
						document.getElementById("resmaxBathsFull").options[j].selected = true;
					}
					else if (wtsearchCat == "mob")
					{
						document.getElementById("cat").options[4].selected = true;
						searchMinBed = wtsearchMinBed;
						searchMaxBed = wtsearchMaxBed;
						searchMinBath = wtsearchMinBath;
						searchMaxBath = wtsearchMaxBath;
						if (wtsearchMinBed > 0) document.getElementById("resminBedroommob").options[wtsearchMinBed].selected = true;
						else document.getElementById("resminBedroommob").options[0].selected = true;
						if (wtsearchMaxBed > 0) document.getElementById("resmaxBedroommob").options[wtsearchMaxBed].selected = true;
						else document.getElementById("resmaxBedroommob").options[0].selected = true;
						var j = getpartialbathIndex(wtsearchMinBath);
						document.getElementById("resminBathsFullmob").options[j].selected = true;
						j = getpartialbathIndex(wtsearchMaxBath);
						document.getElementById("resmaxBathsFullmob").options[j].selected = true;
					}
					else if (wtsearchCat == "lnd")
					{
						document.getElementById("cat").options[1].selected = true; 
						document.getElementById("lndminLotSizeAcre").value = wtsearchMinLotSizeAcre;
						searchMinLotSizeAcre = wtsearchMinLotSizeAcre;
						document.getElementById("lndmaxLotSizeAcre").value = wtsearchMaxLotSizeAcre;
						searchMaxLotSizeAcre = wtsearchMaxLotSizeAcre;
					}
					else if (wtsearchCat == "inc")
					{
						document.getElementById("cat").options[2].selected = true; 
						searchIncLstType = wtsearchIncLstType;
						document.getElementById("inclstType").options[0].selected = false; 
						document.getElementById("inclstType").options[1].selected = false;
						if (wtsearchCat.indexOf(",") > 0) //resinc,resinc5
						{
							document.getElementById("inclstType").options[0].selected = true; 
							document.getElementById("inclstType").options[1].selected = true;
						}
						else
						{
							if (wtsearchCat.indexOf("5") > 0) {document.getElementById("inclstType").options[1].selected = true; }
							else document.getElementById("inclstType").options[0].selected = true;
						}
					}
					else if (wtsearchCat == "bus") document.getElementById("cat").options[3].selected = true; 
					
					document.getElementById("alllstCity").value = wtsearchCity;
					searchCity = wtsearchCity;
					document.getElementById("alllstCounty").value = wtsearchCounty;
					searchCounty = wtsearchCounty ;
					document.getElementById("alllstPostalCode").value = wtsearchZip;
					searchZip = wtsearchZip;
					document.getElementById("ignlstMLSAddress").value = wtsearchMLS;
					searchMLS = wtsearchMLS;
					if (wtsearchMinPrice != '' && wtsearchMinPrice != null) 
					{
						document.getElementById("ignminListPrice").value = wtsearchMinPrice/1000; 
						searchMinPrice = wtsearchMinPrice;
					}
					if (wtsearchMaxPrice != '' && wtsearchMaxPrice != null) 
					{
						document.getElementById("ignmaxListPrice").value = wtsearchMaxPrice/1000;
						searchMaxPrice = wtsearchMaxPrice;
					}
					searchState = wtsearchState;
				}
			}
		}
		
		
		 if ($('cat').value == "mob")
		 {
			$('mob').style.display = "block";
			$('res').style.display = "none";
		 }
		 else if ($('cat').value == "lnd")
		 {
			$('lnd').style.display = "block";
			$('res').style.display = "none";
		 }
		 else if ($('cat').value == "inc")//"inc"
		 {
			$('inc').style.display = "block";
			$('res').style.display = "none";
		 }
		 else if ($('cat').value == "bus")//"bus"
		 {
			$('res').style.display = "none";
		 }
		
	}
	function doValidate()
	{
		var ErrorTxt = "";
		// remove any remaining settings on other property categories
		var strCat = document.getElementById("cat").value;
		clearCatSpecificFields(strCat);
		
		// set the mlsid or address
		if (!verifyMLSNumorAddress())
		{
			var ignminListPrice = document.getElementById("ignminListPrice");
			var ignmaxListPrice = document.getElementById("ignmaxListPrice");
			var resminBedroom = document.getElementById("resminBedroom");
			var resmaxBedroom = document.getElementById("resmaxBedroom");
			var resminBathsFull = document.getElementById("resminBathsFull");
			var resmaxBathsFull = document.getElementById("resmaxBathsFull");
			var resminBedroommob = document.getElementById("resminBedroommob");
			var resmaxBedroommob = document.getElementById("resmaxBedroommob");
			var resminBathsFullmob = document.getElementById("resminBathsFullmob");
			var resmaxBathsFullmob = document.getElementById("resmaxBathsFullmob");
				
				// perform validation
				document.getElementById("alllstCity").value = trim(document.getElementById("alllstCity").value);
				document.getElementById("alllstCounty").value = trim(document.getElementById("alllstCounty").value);
				document.getElementById("alllstPostalCode").value = trim(document.getElementById("alllstPostalCode").value);
				if(document.getElementById("alllstPostalCode") != null)
				{
					var alllstPostalCode = document.getElementById("alllstPostalCode");
					var strPostalCodes = alllstPostalCode.value;
					var bInvalidZip = false;
					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(resminBedroom.value != "" && !isNaN(resminBedroom.value) && resmaxBedroom.value != "" && !isNaN(resmaxBedroom.value) && parseInt(resmaxBedroom.value) < parseInt(resminBedroom.value))
					ErrorTxt = ErrorTxt + "- Max Bed rooms must greater than the minimum \n";	
					
				if(resminBathsFull.value != "" && !isNaN(resminBathsFull.value) && resmaxBathsFull.value != "" && !isNaN(resmaxBathsFull.value) && parseInt(resmaxBathsFull.value) < parseInt(resminBathsFull.value))
					ErrorTxt = ErrorTxt + "- Max Bathrooms must greater than the minimun \n";
					
				if(strCat == "lnd")
				{
					var minLotSizeAcre = document.getElementById("lndminLotSizeAcre");
					var maxLotSizeAcre = document.getElementById("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("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";
				}
				else if (strCat == "mob")
				{
					if(resminBedroommob.value != "" && !isNaN(resminBedroommob.value) && resmaxBedroommob.value != "" && !isNaN(resmaxBedroommob.value) && (resmaxBedroommob.value) < (resminBedroommob.value))
					ErrorTxt = ErrorTxt + "- Max Bed rooms must greater than the minimum \n";	
					
					if(resminBathsFullmob.value != "" && !isNaN(resminBathsFullmob.value) && resmaxBathsFullmob.value != "" && !isNaN(resmaxBathsFullmob.value) && (resmaxBathsFullmob.value) < (resminBathsFullmob.value))
					ErrorTxt = ErrorTxt + "- Max Bathrooms must greater than the minimun \n";	
				}
		}
		else
		{
			if ((isNaN(document.getElementById("ignlstMLSAddress").value)) || (document.getElementById("ignlstMLSAddress").value.indexOf(",") > 0))
				ErrorTxt = ErrorTxt + "- Please enter a single valid MLS Number \n";	
		} 
		if(ErrorTxt != "")
		{
			alert("Please fix the following errors:\n" + ErrorTxt);
			return false;
		}
		else 
		{
			return true;
		}
	}
	function clearCatSpecificFields(strCat)
	{
		if(strCat != "res")
		{
			document.getElementById("resminBedroom").selectedIndex = 0;
			document.getElementById("resminBathsFull").selectedIndex = 0;
			document.getElementById("resmaxBathsFull").selectedIndex = 0;
			document.getElementById("resmaxBedroom").selectedIndex = 0;
		}
		if(strCat != "mob")
		{
			document.getElementById("resminBedroommob").selectedIndex = 0;
			document.getElementById("resmaxBedroommob").selectedIndex = 0;
			document.getElementById("resminBathsFullmob").selectedIndex = 0;
			document.getElementById("resmaxBathsFullmob").selectedIndex = 0;
		}
		if(strCat != "lnd")
		{
			document.getElementById("lndminLotSizeAcre").value = "";
			document.getElementById("lndmaxLotSizeAcre").value = "";
		}
		if(strCat != "inc")
		{
			inclstType = document.getElementById("inclstType");
			for(i=0;i<inclstType.options.length;i++)
				inclstType.options[i].selected = false;
		}	
	}
	function validateStateZip(strPostalCode, strState)
	{
		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 checkOther() //this is used onload
	{
		
		var minPrice = $('ignminListPrice');
		var maxPrice = $('ignmaxListPrice');
		var minBed = $('resminBedroom');
		var maxBed = $('resmaxBedroom');
		var minBath = $('resminBathsFull');
		var maxBath = $('resmaxBathsFull');
		var categ = $('cat');
		if ((minPrice.value != null && minPrice.value != '')|| (maxPrice.value != null && maxPrice.value != '')|| (minBed.value != null && minBed.value != '') || (maxBed.value != null && maxBed.value != '') || (minBath.value != null && minBath.value != '') || (maxBath.value != null && maxBath.value != '') || (categ.value != 'res') )
		{
			return true;
		}
		return false;
	}
	function checkOtherFields()
	{
		var minPrice = $('ignminListPrice');
		var maxPrice = $('ignmaxListPrice');
		var minBed = $('resminBedroom');
		var maxBed = $('resmaxBedroom');
		var minBath = $('resminBathsFull');
		var maxBath = $('resmaxBathsFull');
		var lndMin = $('lndminLotSizeAcre');
		var lndMax = $('lndmaxLotSizeAcre');
		var inclstType = $('inclstType');
		var mobresminBedroom = $('resminBedroommob');
		var mobresmaxBedroom = $('resmaxBedroommob');
		var mobresminBathsFull = $('resminBathsFullmob');
		var mobresmaxBathsFull = $('resmaxBathsFullmob');
		var categ = $('cat');
		if (categ.value == 'res')
		{
			if ((minPrice.value != null && minPrice.value != '')|| (maxPrice.value != null && maxPrice.value != '')|| (minBed.value != null && minBed.value != '') || (maxBed.value != null && maxBed.value != '') || (minBath.value != null && minBath.value != '') || (maxBath.value != null && maxBath.value != '') || (categ.value == 'res'))
			{
				return true;
			}
		}
		else if (categ.value == 'lnd')
		{
			if ((minPrice.value != null && minPrice.value != '')|| (maxPrice.value != null && maxPrice.value != '')|| (lndMin.value != null && lndMin.value != '') || (lndMax.value != null && lndMax.value != '') || (categ.value == 'lnd'))
			{
				return true;
			}
		}
		else if (categ.value == 'inc')
		{
			if ((minPrice.value != null && minPrice.value != '')|| (maxPrice.value != null && maxPrice.value != '')|| (inclstType.value != null && inclstType.value != '') || (categ.value == 'inc'))
			{
				return true;
			}
		}
		else if (categ.value == 'mob')
		{
			if ((minPrice.value != null && minPrice.value != '')|| (maxPrice.value != null && maxPrice.value != '')|| (mobresminBedroom.value != null && mobresminBedroom.value != '') || (mobresmaxBedroom.value != null && mobresmaxBedroom.value != '') || (mobresminBathsFull.value != null && mobresminBathsFull.value != '') || (mobresmaxBathsFull.value != null && mobresmaxBathsFull.value != '') || (categ.value == 'mob'))
			{
				return true;
			}
		}
		return false;
	}
	function LoadCategories()
	{
		var categ = $('cat');
		categ.options.length = 4;
		categ.options[0].value = "res";
		categ.options[0].text = "Residential";
		categ.options[1].value = "lnd";
		categ.options[1].text = "Lots and Acreage";
		categ.options[2].value = "inc";
		categ.options[2].text = "Residential Income";
		//categ.options[3].value = "bus";
		//categ.options[3].text = "Business Opportunity";
	}
	fmtMoney = function( n, c, d, t ) 
	{
		var m = ( c = Math.abs( c ) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec( n + "" ) ), x = m[1].length % 3;
		return ( x ? m[1].substr( 0, x ) + t : "" ) + m[1].substr( x ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + ( +m[2] ).toFixed( c ).substr( 2 ) : "" );
	};
	/*function FindLoc(address)
    {
		oMap.FindLocation(address, onFoundResults);
    }
    function onFoundResults(e)
    {
		if (e.length > 0) 
		{
			cityLat = e[0].LatLong.Latitude;
			cityLong = e[0].LatLong.Latitude;
		}
		//var results="More than one location was retruned. Please select the location you were looking for:<br>";
		//for (x=0; x<e.length; x++)
		//{
			//results+="<a href='javascript:map.FindLocation(\""+e[x].ID+"\");'>"+e[x].ID+"</a><br>";
			//results+=e[x].LatLong
		//}
		
		//alert(e[0].ID);
		//alert(e[0].LatLong);
    }*/
    function handleEnterKey(evt){
		var charCode = (evt.charCode)?evt.charCode:((evt.which)?evt.which:evt.keyCode);
		if (charCode == 13){
			doSearch();
		}
	}
	
	//Evisit Analyst code: track dynamic map search criterias
	//City:			id = 39
	//County:		id = 40
	//Zip:			id = 41
	//MLS #:		id = 42
	//Price Min:	id = 43
	//Price Max:	id = 44
	//Category:		id = 45
	//Bedroom Min:	id = 46
	//Bedroom Max:	id = 47
	//Bath Min:		id = 48
	//Bath Max:		id = 49
	//State:		id = 50
	//Map center Lat: id = 51
	//Map center Long: id = 52
	function callkeydata() {
	
		var evaimage = new Image;
		var eVisitID = 21951;
		var evisitUrl = "http://prubroker.evisitanalyst.com/cgi-bin/insite/harvest/custom.pl?id=";
		switch (domainid)
		{
			case 1: //prurealty.com
				eVisitID = 21951;
				break;
			case 2: //gotucson.com
				eVisitID = 28270;
				break;
			case 3: //prunevada.com
				eVisitID = 13679;
				break;
			case 4: //prudentialtexas.com
				eVisitID = 27237;
				break;
			case 5: //prudentialtexasrealty.com
				eVisitID = 10710;
				break;
			default:
				break;
		}
		if(searchCity != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT39=" + searchCity;
		if(searchCounty != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT40=" + searchCounty;
		if(searchZip != "")			evaimage.src = evisitUrl + eVisitID + "&ID_CT41=" + searchZip;
		if(searchMLS != "")			evaimage.src = evisitUrl + eVisitID + "&ID_CT42=" + searchMLS;
		if(searchMinPrice != "")	evaimage.src = evisitUrl + eVisitID + "&ID_CT43=" + searchMinPrice;
		if(searchMaxPrice != "")	evaimage.src = evisitUrl + eVisitID + "&ID_CT44=" + searchMaxPrice;
		if(searchCat != "")			evaimage.src = evisitUrl + eVisitID + "&ID_CT45=" + searchCat;
		if(searchMinBed != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT46=" + searchMinBed;
		if(searchMaxBed != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT47=" + searchMaxBed;
		if(searchMinBath != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT48=" + searchMinBath;
		if(searchMaxBath != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT49=" + searchMaxBath;
		if(searchState != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT50=" + searchState;
		if(mapCenterLat != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT51=" + mapCenterLat;
		if(mapCenterLong != "")		evaimage.src = evisitUrl + eVisitID + "&ID_CT52=" + mapCenterLong;		
	}
