﻿
 	var GotoURL = "";
 	var CurrentAddr ="";
 	var CurrentZipCode = "";
 	
 	function Initialize(){
 		var Site = $get("hSiteCode").value;
 		
 		FixNoCookieLinks();
 		
 		GoogleAnalytics();
 		
 		var oDiv = $get("flashcontent")
 				BgColor = oDiv.getAttribute("bgColor");
 				PMovie = oDiv.getAttribute("pMovie");
 				AttribID = oDiv.getAttribute("attribID");
 				AttribName = oDiv.getAttribute("attribName");
 				EmbedPath = oDiv.getAttribute("embedPath");
 				EmbedWidth = oDiv.getAttribute("embedWidth");
 				EmbedHeight = oDiv.getAttribute("embedHeight");

 			if("COOP"==Site){
				var flashvars = {};
				var params = {
					quality: "high",
					play: "true",
					loop: "true",
					scale: "showall",
					wmode: "transparent",
					devicefont: "false",
					bgcolor: "#ffffff",
					menu: "true",
					allowfullscreen: "false",
					allowscriptaccess: "sameDomain",
					movie: "SiteContent/OKC/Images/OKC_Map_w5.swf"
				};
				var attributes = {
					id: "MyMLSMapW9",
					name: "MyMLSMapW9",
					align: "middle",
					wmode: "transparent"
				};
				// need to adjust map size to fit space available
				// image is oversized so that background is consistent for odd-shaped browser windows
				var h = 1.6* GetScreenHeight();
				var w = 1.6* GetScreenWidth();
				var AspectRatio = 900.0/645.0;
				w = Math.min(w,h*AspectRatio);
				h = Math.min(h,w/AspectRatio);
				var oImg = $get("imgMap")
				oImg.style.width=w+"px";
		
				swfobject.embedSWF("Images/MyMLSMapW08.swf", "flashcontent", w, h, "9.0.0", flashvars, params, attributes);
 			}
 			else
 			{
 				var flashvars = {};
				var params = {
					quality: "high",
					play: "true",
					loop: "true",
					scale: "showall",
					wmode: "transparent",
					devicefont: "false",
					bgcolor: BgColor,
					menu: "true",
					allowfullscreen: "false",
					allowscriptaccess: "sameDomain",
					movie: PMovie
				};
				var attributes = {
					id: AttribID,
					name: AttribName,
					wmode: "transparent",
					align: "middle"
				};
				swfobject.embedSWF(EmbedPath, "flashcontent", EmbedWidth, EmbedHeight, "9.0.0", flashvars, params, attributes);
 				return;
 				}
 	}
 	
 		
	function Goto(Location){
		var Area = "";
		var Site = $get("hSiteCode").value;
		var ID = $get("hEncryptedVisitorID").value
			
				switch(Site)
				{
					case "Demo":
						switch (Location){
							case "LAS": Area="Las Vegas, NV"; break;
							case "HHI": Area="Hilton Head, SC"; break;
							case "MFR": Area="Polk County, FL"; break;
						}
						MyAjaxService.RememberSetting("ZoomLevel",0,ID); // Reset the map to center on default address
						document.location.href=FullURL("SiteContent/PropertySearch.aspx?Area=" + Area);
						return;		
						break;
						
				
					case "HHI":
					case "LAS":
					case "MFR":
						switch (Location){
							case "BR" : Area = "Brevard County, FL"; break;
							case "CH" : Area = "Charlotte County, FL"; break;
							case "DS" : Area = "DeSoto County, FL"; break;
							case "HD" : Area = "Hardee County, FL"; break;
							case "HC" : Area = "Hernando County, FL"; break;
							case "HL" : Area = "Highlands County, FL"; break;
							case "HB" : Area = "Hillsborough County, FL"; break;
							case "IR" : Area = "Indian River County, FL"; break;
							case "LK" : Area = "Lake County, FL"; break;
							case "MT" : Area = "Manatee County, FL"; break;
							case "MA" : Area = "Marion County, FL"; break;
							case "OK" : Area = "Okeechobee County, FL"; break;
							case "OC" : Area = "Orange County, FL"; break;
							case "OS" : Area = "Osceola County, FL"; break;
							case "PO" : Area = "Pasco County, FL"; break;
							case "PN" : Area = "Pinellas County, FL"; break;
							case "PK" : Area = "Polk County, FL"; break;
							case "SA" : Area = "Sarasota County, FL"; break;
							case "SM" : Area = "Seminole County, FL"; break;
							case "SU" : Area = "Sumter County, FL"; break;
							case "SL" : Area = "St. Lucie County, FL"; break;
							case "VL" : Area = "Volusia County, FL"; break;
							default: alert("Unknown region: " + Location); Area=""; return;
						}

						MyAjaxService.RememberSetting("ZoomLevel",0,ID); // Reset the map to center on default address
						document.location.href=FullURL("SiteContent/PropertySearch.aspx?Area=" + Area);
						return;		
						break;
						
						
					case "OKC":
						switch (Location){
							case "CA": Area="Canadian County, OK"; break;
							case "PK": Area="Oklahoma County, OK"; break;
							case "LI": Area="Lincoln County, OK"; break;
							case "CD": Area="Caddo County, OK"; break;
							case "GR": Area="Grady County, OK"; break;
							case "MC": Area="McClain County, OK"; break;
							case "CL": Area="Cleveland County, OK"; break;
							case "PO": Area="Pottawatomie County, OK"; break;
							case "KF": Area="Kingfisher County, OK"; break;
							case "LO": Area="Logan County, OK"; break;
							//top unkowns
							case "MA": Area="Major County, OK"; break;
							case "GF": Area="Garfield County, OK"; break;
							case "NO": Area="Noble County, OK"; break;
							case "PY": Area="Payne County, OK"; break;
							case "PW": Area="Pawnee County, OK"; break;
							//left side unknowns
							case "DW": Area="Dewey County, OK"; break;
							case "CU": Area="Custer County, OK"; break;
							case "WA": Area="Washita County, OK"; break;
							case "KI": Area="Kiowa County, OK"; break;
							case "BL": Area="Blaine County, OK"; break;
							case "CO": Area="Comanche County, OK"; break;
							//right side unknowns
							case "CK": Area="Creek County, OK"; break;ar
							case "OF": Area="Okfuskee County, OK"; break;
							case "SE": Area="Seminole County, OK"; break;
							case "PT": Area="Pontotoc County, OK"; break;
							//bottom unknowns
							case "SN": Area="Stephens County, OK"; break;
							case "GV": Area="Garvin County, OK"; break;
								//Area="Extended Area in OK"; break;
								
							default: alert("Unknown region: " + Location); Area=""; return;
						}
						MyAjaxService.RememberSetting("ZoomLevel",0,ID); // Reset the map to center on default address
						document.location.href=FullURL("SiteContent/PropertySearch.aspx?Area=" + Area);
						return;		
						break;		
					
					case "COOP": parent.MenuFrame.ToggleMLSList(Location);
						return;
						
					default: alert("Missing Site: " +Site);
		
				}
				document.location.href="NotAvail.htm";
	}
	
	
	function GetVal(CtrlName)
	{
		var oCtrl = $get(CtrlName);
		var Val = oCtrl.value
		// Remove the help text taht might be in an empty field
		var Text = "!"
		if (oCtrl.getAttribute) Text = oCtrl.getAttribute("title");
		return Val.replace(Text,"");		
	}

	function StartAreaSearch(CtrlName)
	{
		// If user enters a City, Zip or Subdivision, go to Search screen with search criteria filled in.
		var Entry = TRIM(GetVal(CtrlName));
		var VisitorID = $get("hEncryptedVisitorID").value
		DimPage()
 		MyAjaxService.ValidAreaLookup(Entry,VisitorID,ValidAreaCallBack, FailedCallback);			
	}
	
	function ValidAreaCallBack(Parms)
	{
		// We wait for return to sure that the Area field has been filled in.
		var SiteCode = $get("hSiteCode").value;
		switch (SiteCode){
 			case "MFR":
 			case "OKC":
 			case "NYS":
 			case "Demo":
 				GotoURL = FullURL("SiteContent/PropertySearch.aspx" ); break;
 			case "LAS": GotoURL = FullURL("SiteContent/LAS/PropertySearchLAS.aspx" ); break;
 			default:alert("Missing SiteCode Handler in StartAreaSearch():" + SiteCode);
 		}
		document.location.href=GotoURL;	
	}
	
	function DimPage()
	{
		$get("form1").style.backgroundColor="#cccccc";
		$get("form1").style.backgroundColor="#999999";
	}
	
	function AddressGo(DefaultCityStZip){
		var ContentFrame = document.Content;
		var SiteCode = $get("hSiteCode").value;
		var Addr=TRIM(GetVal("Address"));

		// If no entry exit early.
		if (0 == Addr.length)  return;
	
		DimPage();
		
		// peel off just the zipcode if it exists
		var Zip = ""
		var aZip = Addr.replace(/\,/g," ").split(" ");
		if (aZip.length>0) Zip = aZip[aZip.length-1];

		// If no zipcode supplied make sure we are in the right state		
		if (isNaN(Zip) || (0==parseInt(Zip)) || (5!=Zip.length))
		{
			Addr += ", " + DefaultCityStZip;
			Zip="";			
		}
			
		// If no MLS property found, prepare to do a property search but build the Search Page URL 
		// we will navigate after the area has been cleared. 	
		var url = "?Addr=" + escape(Addr) + "&CityStZip=" + escape(Zip)
 		switch (SiteCode){
 			case "MFR": 
 			case "OKC":
 			case "NYS":
 			case "Demo":
 				GotoURL = FullURL("SiteContent/PropertySearch.aspx" + url); break;
 			case "LAS": GotoURL = FullURL("SiteContent/LAS/PropertySearchLAS.aspx" + url); break;
 			default:alert("Missing SiteCode Handler in AddressGo():" + SiteCode);
 		}
		MyAjaxService.ConfigMapSearch($get("hEncryptedVisitorID").value,AddressGoCallBack,FailedCallback);
	}
	
	function AddressGoCallBack()
	{
		document.location.href=GotoURL;
	}
	
	function AddrCallBack(SysPropID)
	{	
	// If this address is for an active listing, then show the detail, else just go to 
	// regular property search centered on this address
		if (SysPropID.length>0){
			GotoURL = CreateNoCookieURL("SiteContent/PropDetail.aspx?N=0&S=" + SysPropID.replace(",","&Id="));
			var SiteCode = $get("hSiteCode").value;
			if (SiteCode=="Demo") GotoURL = GotoURL.replace("Content/PropDetail.aspx","Content/Demo/PropDetailDemo.aspx");
			document.location.href=GotoURL;
			return
		} 
	// If not found but there are more than 2 words to this address, try dropping the last word (e.g. street) and try again
		var aAddr = CurrentAddr.split(" ");
		if (aAddr.length>2)
		{
			CurrentAddr = aAddr.slice(0,length-1).join(" ");
			MyAjaxService.PropertyAddressLookup(CurrentAddr,CurrentZipCode,AddrCallBack, FailedCallback);
			return;
		}
	
		document.location.href=GotoURL;
		
	}


	function MLNumGo(oInput)
	{
		var ML = document.getElementById("MLNum").value
		if (0==ML.length) return;
		MyAjaxService.PropertyMLLookup(ML, "0,0,0,0", MLNumGoCallBack, FailedCallback);
	}
	

	function MLNumGoCallBack(Result){
		if (0==Result.length){
			var ML = document.getElementById("MLNum").value
			if ("0"==ML.substring(0,1)){ // Try replacing 0 with the letter O
				MyAjaxService.PropertyMLLookup("O"+ML.substr(1), "0,0,0,0", MLNumGoCallBack, FailedCallback);
			} else 	 alert("Listing # Not found")
		 return;
		}
		var Res = (Result + ",").split(",")
		GotoURL = CreateNoCookieURL("SiteContent/PropDetail.aspx?N=0&S=" + Res[0] + "&ID=" + Res[1]);
		if (SiteCode=="Demo") GotoURL = GotoURL.replace("Content/PropDetail.aspx","Content/Demo/PropDetailDemo.aspx");
		document.location.href= GotoURL;
	}
	