/* Custom Google Maps v3 API Implementation for Arizona Property Sales ©Trevor Boone, 2017 */ var CityViews={Flagstaff:{center:new google.maps.LatLng(35.195975,-111.633797),zoom:13},Sedona:{center:new google.maps.LatLng(34.828426,-111.773085),zoom:12},Williams:{center:new google.maps.LatLng(35.250736,-112.20294),zoom:14},"Camp Verde":{center:new google.maps.LatLng(34.5602517,-111.8603368),zoom:13},"Munds Park":{center:new google.maps.LatLng(34.942518,-111.64062),zoom:15},Parks:{center:new google.maps.LatLng(35.260899,-111.948967),zoom:12},Bellemont:{center:new google.maps.LatLng(35.218137, -111.835842),zoom:13},"All Northern Arizona":{center:new google.maps.LatLng(35.070469,-112.263794),zoom:9},"All Verde Valley":{center:new google.maps.LatLng(34.75,-111.9),zoom:10}},postAction=function(c,b){c||(c="No action given");b||(b="0.0");var d=new XMLHttpRequest;d.requestURL="postaction.php?action="+c+"&value="+b;d.open("GET",d.requestURL,!0);d.onreadystatechange=function(){};d.send()}; function HouseMarker(c,b){this.LatLng_=new google.maps.LatLng(c.lat,c.longitude);this.lat=c.lat;this.map_=b;"C"==c.type?this.altMarkerImage=this.markerImage="images/landmarker.png":(this.markerImage="images/housemarker.png",this.altMarkerImage="images/housemarkerg.png");this.imageSize={x:32,y:42};this.anchor={x:16,y:41};this.price=c.price;this.listingURL="listing.php?id="+c.id;this.imgURL=c.img;this.beds=c.beds;this.baths=c.baths;this.address=c.address;this.sqft=c.sqft;this.city=c.city;this.type= c.type;this.lotSizeAcres=c.lotSizeAcres;this.office=c.office;this.div_=null;this.setMap(b)}HouseMarker.prototype=new google.maps.OverlayView;HouseMarker.prototype.getPrice=function(){return"$"+this.price}; HouseMarker.prototype.onAdd=function(){var c=document.createElement("div");c.style.border="none";c.style.borderWidth="0px";c.style.position="absolute";c.style.cursor="pointer";c.style.zIndex=Math.floor(1E6*(37.011326-this.lat));var b=document.createElement("div");b.style.border="3px ridge #007700";b.style.backgroundColor="#fcffe2";b.style.position="absolute";b.style.fontSize="90%";b.style.width="50px";b.style.height="13px";b.style.top="-17px";b.style.left=-28+Math.round(this.imageSize.x/2)+"px";b.style.textAlign= "center";b.innerHTML=this.getPrice();c.appendChild(b);var d=document.createElement("img");d.src=this.markerImage;d.style.width="100%";d.style.height="100%";c.appendChild(d);var a=document.createElement("img");a.src=this.altMarkerImage;a.style.width="100%";a.style.height="100%";a.style.display="none";c.appendChild(a);var e=document.createElement("div");e.style.backgroundColor="#fcffe2";e.style.border="3px ridge #007700";e.style.position="absolute";e.style.width="166px";e.style.height="155px";e.style.top= "-178px";e.style.left=-81+Math.round(this.imageSize.x/2)+"px";e.style.visibility="hidden";c.appendChild(e);a=document.createElement("div");a.style.width="160px";a.style.fontSize="80%";a.style.padding="3px";a.style.textAlign="center";a.innerHTML="$"+this.price+"
"+this.address;e.appendChild(a);a=document.createElement("img");a.src=this.imgURL;a.style.height="75px";a.style.width="90px";a.style.cssFloat="left";a.style.margin="3px";a.style.marginTop="12px";e.appendChild(a);"A"==this.type? (a=document.createElement("div"),a.style.width="55px",a.style.margin="3px",a.style.textAlign="center",a.style.cssFloat="left",a.innerHTML+=this.sqft+"sqft
",a.innerHTML+=this.beds+"br/"+this.baths+"ba
",0",e.style.width="192px",e.style.left=-94+Math.round(this.imageSize.x/2)+"px",a.style.width="81px"),a.innerHTML+=''+this.office+"",e.appendChild(a)):"E"==this.type&0",0"),0",e.style.width="192px",e.style.left=-94+Math.round(this.imageSize.x/2)+"px",a.style.width="81px"),a.innerHTML+=''+this.office+"",e.appendChild(a)):"C"==this.type&&0",a.innerHTML+=''+this.office+"",e.appendChild(a)):(a.style.marginLeft="38px",a.style.marginRight="auto",a.style.cssFloat="none");this.div_=c;var m=this.listingURL;google.maps.event.addDomListener(this.div_,"click",function(){var a=document.createElement("form");a.target="_blank";a.method="POST";a.action= m;var b=document.getElementById("mapSearchCity"),d=document.getElementById("mapSearchMaxPrice"),e=document.getElementById("mapSearchMinPrice"),f=document.getElementById("mapSearchMinBeds"),r=document.getElementById("mapSearchMinBaths"),t=document.getElementById("mapSearchPropertyType"),h=document.createElement("input");h.type="hidden";h.name="city";h.value=b.value;a.appendChild(h);b=document.createElement("input");b.type="hidden";b.name="maxprice";b.value=d.value;a.appendChild(b);d=document.createElement("input"); d.type="hidden";d.name="minprice";d.value=e.value;a.appendChild(d);e=document.createElement("input");e.type="hidden";e.name="beds";e.value=f.value;a.appendChild(e);f=document.createElement("input");f.type="hidden";f.name="baths";f.value=r.value;a.appendChild(f);r=document.createElement("input");r.type="hidden";r.name="type";r.value=t.value;a.appendChild(r);c.appendChild(a);a.submit()});google.maps.event.addDomListener(d,"mouseover",function(a){return function(){c.style.zIndex=1715281844+Math.floor(1E6*(37.011326- a));e.style.visibility="visible"}}(this.lat));google.maps.event.addDomListener(b,"mouseover",function(a){return function(){c.style.zIndex=1715281844+Math.floor(1E6*(37.011326-a));e.style.visibility="visible"}}(this.lat));google.maps.event.addDomListener(d,"mouseout",function(a){return function(){c.style.zIndex=Math.floor(1E6*(37.011326-a));e.style.visibility="hidden"}}(this.lat));google.maps.event.addDomListener(b,"mouseout",function(a){return function(){c.style.zIndex=Math.floor(1E6*(37.011326-a));e.style.visibility= "hidden"}}(this.lat));this.getPanes().overlayMouseTarget.appendChild(c)};HouseMarker.prototype.draw=function(){var c=this.getProjection().fromLatLngToDivPixel(this.LatLng_),b=this.div_;b.style.left=c.x-this.anchor.x+"px";b.style.top=c.y-this.anchor.y+"px";b.style.width=this.imageSize.x+"px";b.style.height=this.imageSize.y+"px"};HouseMarker.prototype.onRemove=function(){this.div_.parentNode.removeChild(this.div_);this.div_=null}; function searchStatusOverlay(c){var b=document.createElement("div");b.style.border="none";b.style.borderWidth="0px";b.style.padding="4px";b.style.backgroundColor="#fcffe2";b.style.textAlign="center";var d=document.createElement("img");d.src="images/searching.gif";d.style.marginLeft="auto";d.style.marginRight="auto";d.style.display="none";b.appendChild(d);var a=document.createElement("div");b.appendChild(a);var e=document.createElement("div");e.style.display="none";e.innerHTML="Now Showing All Northern AZ Listings from the Last 10 Days"; b.appendChild(e);c.controls[google.maps.ControlPosition.TOP_CENTER].push(b);this.show=function(){d.style.display="block"};this.hide=function(){d.style.display="none"};this.setListingCount=function(b){a.innerHTML=b+" listings shown"};this.showWhatsNew=function(){e.style.display="block"};this.hideWhatsNew=function(){e.style.display="none"}} function errorOverlay(c){var b=document.createElement("div");b.style.border="none";b.style.borderWidth="0px";b.style.padding="0px";b.style.backgroundColor="#fcffe2";b.style.clear="both";b.style.marginBottom="300px";b.style.color="#dd0000";b.style.fontSize="150%";b.style.textAlign="center";textDiv=document.createElement("div");textDiv.style.display="none";textDiv.style.padding="4px";textDiv.innerHTML="We're sorry, there was an error getting
listing data. Please try again later.";b.appendChild(textDiv); this.show=function(){textDiv.style.display="block"};var d=this.hide=function(){textDiv.style.display="none"};dismissDiv=document.createElement("div");dismissDiv.style.fontSize="70%";dismissDiv.style.border="1px solid #000000";dismissDiv.style.backgroundColor="#d8d8d8";dismissDiv.style.cursor="pointer";dismissDiv.style.width="7em";dismissDiv.style.marginLeft="auto";dismissDiv.style.marginRight="auto";dismissDiv.innerHTML="Dismiss";google.maps.event.addDomListener(dismissDiv,"click",function(){d()}); textDiv.appendChild(dismissDiv);c.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(b)} function instructionsOverlay(c){var b=document.getElementById("mapSearchInstructionsButton"),d=document.getElementById("mapSearchInstructions"),a=document.createElement("div");a.style.backgroundColor="#fcffe2";a.style.width="86%";a.style.height="550px";a.style.padding="1%";a.style.marginBottom="28px";a.style.display="none";a.style.cursor="pointer";a.innerHTML=d.innerHTML;var e=!1;this.showInstructions=function(){e=!0;a.style.display="block";b.value="Hide Instructions"};this.hideInstructions=function(){e= !1;a.style.display="none";b.value="Instructions"};var m=this.showInstructions,p=this.hideInstructions;google.maps.event.addDomListener(b,"click",function(){e?p():(m(),postAction("Show Instructions"))});google.maps.event.addDomListener(a,"click",function(){p()});c.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(a)} function contactPromptOverlay(c){var b=document.getElementById("mapSearchContactPrompt"),d=document.createElement("div"),a=function(){};d.style.backgroundColor="#fcffe2";d.style.width="86%";d.style.height="550px";d.style.padding="1%";d.style.marginBottom="28px";d.style.display="none";d.style.cursor="pointer";d.innerHTML=b.innerHTML;this.show=function(){d.style.display="block";postAction("Show Map Search Contact Prompt")};this.hide=function(){d.style.display="none"};this.setEnableControlsCallback= function(b){a=b};var b=$(d).find("#contactPromptSubmit").get()[0],e=$(d).find('[name="name"]'),m=$(d).find('[name="email"]'),p=$(d).find('[name="phone"]'),u=$(d).find('[name="comments"]'),q=$(d).find('[name="PrimaryInterest"]'),g=$(d).find(".validationMessages").get()[0],f=this.hide;google.maps.event.addDomListener(b,"click",function(){var b=e.val(),c=m.val(),d=p.val(),v=q.val(),k=u.val(),l=!0,n={subject:"AZ Property Sales Contact Form Submission"},w=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, x=/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;g.innerHTML="";b?n.name=b:(g.innerHTML+="Please enter your name
",l=!1);w.test(c)||x.test(d)?(w.test(c)&&(n.email=c),x.test(d)&&(n.phone=d)):(g.innerHTML+="Please enter a valid email or ten-digit phone number (e.g., 123-456-7890)
",l=!1);n.PrimaryInterest=v;k&&(n.comments=k);l&&($.post("mailgunmailer.php",n),document.cookie="contact="+b+"; expires=Fri, 31 Dec 9999 23:59:59 GMT;",a(),f())});c.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(d)} function contactButton(c){c=document.getElementById("mapSearchContactButton");google.maps.event.addDomListener(c,"click",function(){postAction("Contact Button");window.open("","contactWindow");document.getElementById("propertySearchForm").submit()})} var APSMapController=function(c){var b={},d=document.getElementById("mapSearchCity"),a=document.getElementById("mapSearchMaxPrice"),e=document.getElementById("mapSearchMinPrice");document.getElementById("mapSearchUpdateCriteria");var m=document.getElementById("mapSearchMinBeds"),p=document.getElementById("mapSearchMinBaths"),u=document.getElementById("BedBathControls"),q=document.getElementById("mapSearchPropertyType"),g=document.getElementById("mapSearchWhatsNewButton"),f=new searchStatusOverlay(c), r=new errorOverlay(c);new instructionsOverlay(c);var t=new contactPromptOverlay(c);new contactButton(c);var h=!1;d.onchange=function(){h||(c.setCenter(CityViews[d.value].center),c.setZoom(CityViews[d.value].zoom),k(),f.hideWhatsNew(),postAction("City Change",d.value))};a.onchange=function(){if(!h){var b=e.children;if(parseInt(a.value)<=parseInt(e.value))for(var c=0;c=parseInt(a.value))for(var c=0;cparseInt(e.value)&&(b[c].selected=!0,c=b.length);k();f.hideWhatsNew();postAction("Min Price Change",e.value)}};q.onchange=function(){h||(u.style.visibility="A"==q.value?"visible":"hidden",k(),f.hideWhatsNew(),postAction("Property Type Change",q.value))};m.onchange=function(){h||(k(),f.hideWhatsNew(),postAction("Min Beds Change",m.value))};p.onchange=function(){h||(k(), f.hideWhatsNew(),postAction("Min Baths Change",p.value))};g.onclick=function(){h||(k("&whatsnew=true",!0),c.setCenter(CityViews["All Northern Arizona"].center),c.setZoom(CityViews["All Northern Arizona"].zoom),f.showWhatsNew(),postAction("What's new click"))};var v=function(a){a=a.split("$").join("");a=a.split(",").join("");return parseInt(a)},k=function(l,h){var g=0;if(!l){l="";var k=v(e.value);k&&(l+="&minprice="+k);var n=v(a.value);n&&(l+="&maxprice="+n);l+="&minbeds="+m.value;l+="&minbaths="+ p.value;l+="&city="+d.value;l+="&type="+q.value}for(marker in b)h||b[marker].pricen||"A"==q.value&&b[marker].bedsb?(console.log("Retrying, #"+(b+1)),window.setTimeout(function(){t(a,b+1)},200)):(r.show(),f.hide()),c="err"}"err"!=c&&(c.currentPage