locator={geocoder:false,gmap:false,markers:false,opts:false,firstPage:0,lastPage:false,currentPage:false,currentCenter:false,pageLength:6,init:function(c){if(GBrowserIsCompatible()){locator.opts=c;locator.geocoder=new GClientGeocoder();locator.gmap=new GMap2(document.getElementById("gmap"));locator.gmap.setCenter(new GLatLng(50,-96),3);locator.gmap.addControl(new GLargeMapControl());locator.gmap.addControl(new GScaleControl());var a=document.createElement("img");a.src="images/icons/ajax-loader.gif";a.style.display="inline";a.style.verticalAlign="middle";var b=document.createElement("span");b.innerHTML="Searching...";b.style.display="inline";b.style.verticalAlign="middle";b.style.marginLeft="5px";var d=document.createElement("div");d.id="ajaxLoader";d.style.display="none";d.appendChild(a);d.appendChild(b);document.getElementById("gsearch").appendChild(d);document.getElementById("gsearch").onsubmit=locator.submitSearchField;document.getElementById("gsubmit").onclick=locator.getSearchField;document.getElementById("gclear").onclick=locator.clearSearchResults;document.getElementById("gback").onclick=locator.getBackPage;document.getElementById("gnext").onclick=locator.getNextPage;locator.getSearchField()}},clearSearchResults:function(){var a=document.getElementById("ginput");a.value="";locator.setNoResult()},setNoResult:function(){locator.markers=false;locator.gmap.clearOverlays();var a=document.getElementById("ginput").value;if(a==""){locator.currentCenter=false}if(!locator.currentCenter){locator.gmap.setCenter(new GLatLng(50,-96),3)}else{locator.gmap.setCenter(locator.currentCenter,10)}msg=locator.opts.tHelp;if(a!=""){if(!locator.currentCenter){msg=locator.opts.tLocationError+msg}else{msg=locator.opts.tStoreError+msg}}document.getElementById("glist").innerHTML=msg;document.getElementById("ajaxLoader").style.display="none";document.getElementById("glist").style.display="block";document.getElementById("gpager").style.display="none";document.getElementById("ghelp").style.display="none"},submitSearchField:function(){locator.getSearchField();return false},getSearchField:function(){var a=document.getElementById("ginput").value;if(a==""){locator.setNoResult();return}document.getElementById("ghelp").style.display="none";document.getElementById("gpager").style.display="none";document.getElementById("glist").style.display="none";document.getElementById("ajaxLoader").style.display="block";locator.geocoder.getLatLng(a,function(b){locator.currentCenter=b;if(!locator.currentCenter){locator.setNoResult();return}locator.getSearchResults()})},getSearchResults:function(){var a=locator.opts.dCatalog+"store_locator_search.php";var b={lat:locator.currentCenter.lat(),lng:locator.currentCenter.lng()};$.ajax({url:a,data:b,type:"post",dataType:"json",success:function(c){locator.markers=c.markers;if(locator.markers.length==0){locator.setNoResult();return}locator.lastPage=Math.floor((locator.markers.length-1)/locator.pageLength);locator.currentPage=0;locator.showSearchResults()},error:function(){locator.setNoResult()}})},showSearchResults:function(){var k=document.getElementById("glist");k.style.display="none";k.innerHTML="";locator.gmap.clearOverlays();var n=locator.currentPage*locator.pageLength;var m=n+locator.pageLength;if(m>locator.markers.length){m=locator.markers.length}var b=new GLatLngBounds();for(var g=n;g<m;g++){var h=locator.markers[g];var e=locator.opts.dImages+"icons/letter_"+String.fromCharCode(97+(g-n))+".png";var d=new Array();d.push("<b>"+h.name+"</b>");if(h.local.length>0){d.push(h.local)}d.push(h.address);d.push(h.city+", "+h.state+"  "+h.zip);d.push(h.tel);var c=locator.opts.tDistance;var j=parseFloat(h.distance);var a=1.6*j;d.push(c.replace("{km}",a.toFixed(1)).replace("{mi}",j.toFixed(1)));var l=new GLatLng(parseFloat(h.lat),parseFloat(h.lng));var f=locator.createMarker(l,d,e);locator.gmap.addOverlay(f);b.extend(l);d.pop();d.pop();k.appendChild(locator.createglistEntry(f,d,e))}locator.gmap.setCenter(b.getCenter(),locator.gmap.getBoundsZoomLevel(b));if(locator.currentPage>locator.firstPage){document.getElementById("gback").className=""}else{document.getElementById("gback").className="inactive"}if(locator.currentPage<locator.lastPage){document.getElementById("gnext").className=""}else{document.getElementById("gnext").className="inactive"}document.getElementById("ajaxLoader").style.display="none";document.getElementById("glist").style.display="block";if(locator.markers.length>locator.pageLength){document.getElementById("gpager").style.display="block"}document.getElementById("ghelp").style.display="block"},createMarker:function(a,f,e){var c=new GIcon(G_DEFAULT_ICON);c.image=e;c.iconSize=new GSize(21,35);c.iconAnchor=new GPoint(6,21);c.infoWindowAnchor=new GPoint(9,5);var d=new GMarker(a,c);var b=f.join("<br/>");GEvent.addListener(d,"click",function(){this.openInfoWindowHtml(b)});return d},createglistEntry:function(b,d,c){var a=d.join("<br/>");var e=document.createElement("div");e.innerHTML=a;e.style.cursor="pointer";e.style.marginBottom="10px";e.style.paddingLeft="40px";e.style.background="url("+c+") 10px center no-repeat";GEvent.addDomListener(e,"mouseover",function(){e.style.backgroundColor="#eee"});GEvent.addDomListener(e,"mouseout",function(){e.style.backgroundColor="transparent"});GEvent.addDomListener(e,"click",function(){GEvent.trigger(b,"click")});return e},getBackPage:function(){if(locator.currentPage>locator.firstPage){locator.currentPage--;locator.showSearchResults()}},getNextPage:function(){if(locator.currentPage<locator.lastPage){locator.currentPage++;locator.showSearchResults()}}};