var locator=null;var numStoresPerPage=10;var classAtt="class";var classAtt1="className";var URL="";var storeLocatorType=0;var retailLocatorType=1;function StoreLocator(d,a,c,b){this.type=storeLocatorType;this.map=null;this.address=d;this.sidebar=null;this.markers=[];this.icons=[];this.radius=a;this.vendorId=c;this.startOn=0;this.endOn=0;this.center=new google.maps.LatLng(39.5,-98.35);this.searchURL=store_searchURL;this.createMarkerHTML=store_createMHTML;this.createSideBarHTML=store_createSBHTML;this.createMarker=store_createMarker;this.searchLocationsNear=searchLocationsNear;this.createSideBar=makeSideBar;this.clearAll=clearAll;this.clearSideBar=clearSideBar;this.updateTop=updateTop;this.updateBottom=updateBottom;this.store_type=b}function RetailLocator(c,b,a){this.type=retailLocatorType;this.map=null;this.address=c;this.sidebar=null;this.markers=[];this.icons=[];this.radius=b;this.startOn=0;this.endOn=0;this.center=new google.maps.LatLng(39.5,-98.35);this.searchURL=retail_searchURL;this.createMarkerHTML=retail_createMHTML;this.createSideBarHTML=retail_createSBHTML;this.createMarker=retail_createMarker;this.searchLocationsNear=searchLocationsNear;this.createSideBar=makeSideBar;this.clearAll=clearAll;this.clearSideBar=clearSideBar;this.updateTop=updateTop;this.updateBottom=updateBottom;this.cat=a}function load(e,k,j,h,d,f,g){URL=k;if(google.maps.BrowserIsCompatible()){geocoder=new google.maps.ClientGeocoder();switch(parseInt(e)){case storeLocatorType:locator=new StoreLocator(h,d,j,g);break;case retailLocatorType:locator=new RetailLocator(h,d,f);break;default:alert("locator type not specified")}locator.map=new google.maps.Map2(document.getElementById("map"));locator.map.addControl(new GSmallZoomControl());locator.sidebar=document.getElementById("app-results-items-body");locator.address=h;if(google.loader.ClientLocation&&google.loader.ClientLocation.address.country_code=="US"&&google.loader.ClientLocation.address.region){var b=google.loader.ClientLocation.address.region;var c=google.loader.ClientLocation.address.city;locator.address=c+", "+b;var a=document.getElementById("app-search-textfield");a.value=locator.address}locator.map.setCenter(locator.center,3);initSearchLocations()}}function updateTop(){var a=document.getElementById("results-count");if(this.markers.length==0){a.innerHTML="No stores found within "+this.radius+" miles of "}else{if(this.markers.length<=10){a.innerHTML=this.markers.length+" stores found within "+this.radius+" miles of "}else{a.innerHTML=(this.startOn+1)+"-"+this.endOn+" of "+this.markers.length+" stores found within "+this.radius+" miles of "}}a=document.getElementById("results-location");a.innerHTML=this.address}function updateBottom(){var a=document.getElementById("app-results-prev");if(!this.startOn){a.setAttribute(classAtt,"disabled");a.setAttribute(classAtt1,"disabled")}else{a.setAttribute(classAtt,"enabled");a.setAttribute(classAtt1,"endabled")}next=document.getElementById("app-results-next");if(locator.endOn>=locator.markers.length){next.setAttribute(classAtt,"disabled");next.setAttribute(classAtt1,"disabled")}else{next.setAttribute(classAtt,"enabled");next.setAttribute(classAtt1,"endabled")}}function retail_createMHTML(a){var b="<b>"+a.myName+"</b><br/>"+a.myAddress+"<br/>"+a.myAddress2;if(a.myPhone.length){b+="<br>"+a.myPhone}if(a.myHours.length){b+="<br>"+a.myHours}b='<div id="markerhtml">'+b+"</div>";return b}function store_createMHTML(a){var b="<b>"+a.myName+"</b><br/>"+a.myAddress+"<br/>"+a.myAddress2;if(a.myPhone.length){b+="<br>"+a.myPhone}if(a.myHours.length){b+="<br>"+a.myHours}if(a.myNotes.length){b+="<br>Notes: "+a.myNotes}b='<div id="markerhtml">'+b+"</div>";return b}function retail_createSBHTML(g){var b=document.createElement("div");b.id="app-results-item"+g.myLetter;b.setAttribute(classAtt,"result-item");b.setAttribute(classAtt1,"result-item");GEvent.addDomListener(b,"click",function(){GEvent.trigger(g,"click")});var j=document.createElement("div");j.setAttribute(classAtt,"id");j.setAttribute(classAtt1,"id");j.innerHTML=g.myLetter;b.appendChild(j);var f=document.createElement("div");f.setAttribute(classAtt,"info");f.setAttribute(classAtt1,"info");var l=document.createElement("p");l.setAttribute(classAtt,"title");l.setAttribute(classAtt1,"title");l.innerHTML=g.myName;f.appendChild(l);var a=document.createElement("p");a.setAttribute(classAtt,"street");a.setAttribute(classAtt1,"street");a.innerHTML=g.myAddress;f.appendChild(a);var k=document.createElement("p");k.setAttribute(classAtt,"city");k.setAttribute(classAtt1,"city");k.innerHTML="<br/>"+g.myAddress2;f.appendChild(k);b.appendChild(f);var d=document.createElement("div");d.setAttribute(classAtt,"found");d.setAttribute(classAtt1,"found");d.onmouseover=function(){hoverImg(d)};d.onmouseout=function(){leaveHoverImg(d)};var h=document.createElement("p");h.setAttribute(classAtt,"hits");h.setAttribute(classAtt1,"hits");h.innerHTML=g.myVendors;d.appendChild(h);var l=document.createElement("p");l.setAttribute(classAtt,"title");l.setAttribute(classAtt1,"title");l.innerHTML="Foodmakers";d.appendChild(l);b.appendChild(d);var c=document.createElement("a");c.setAttribute(classAtt,"view");c.setAttribute(classAtt1,"view");c.href="index.php?page=shop.retailer&retailer_id="+g.myId+"&category="+locator.cat;c.onmouseover=function(){hoverUnderline(c)};c.onmouseout=function(){leaveHoverUnderline(c)};c.innerHTML="More Info";var e=document.createElement("img");e.src="images/link-arrow-blue.jpg";c.appendChild(e);b.appendChild(c);return b}function store_createSBHTML(c){var b=document.createElement("tr");b.id="app-results-item"+c.myLetter;b.setAttribute(classAtt,"result-item");b.setAttribute(classAtt1,"result-item");GEvent.addDomListener(b,"click",function(){GEvent.trigger(c,"click")});var e=document.createElement("td");e.setAttribute(classAtt,"ids");e.setAttribute(classAtt1,"ids");var f=document.createElement("div");f.setAttribute(classAtt,"id");f.setAttribute(classAtt1,"id");f.innerHTML=c.myLetter;e.appendChild(f);b.appendChild(e);var k=document.createElement("td");k.setAttribute(classAtt,"title");k.setAttribute(classAtt1,"title");k.innerHTML=c.myName;b.appendChild(k);var g=document.createElement("td");g.setAttribute(classAtt,"address");g.setAttribute(classAtt1,"address");var a=document.createElement("span");a.setAttribute(classAtt,"street");a.setAttribute(classAtt1,"street");a.innerHTML=c.myAddress;g.appendChild(a);var h=document.createElement("span");h.setAttribute(classAtt,"city");h.setAttribute(classAtt1,"city");h.innerHTML="<br/>"+c.myAddress2;g.appendChild(h);b.appendChild(g);var j=document.createElement("td");j.setAttribute(classAtt,"phone");j.setAttribute(classAtt1,"phone");j.innerHTML=c.myPhone;b.appendChild(j);var d=document.createElement("td");d.setAttribute(classAtt,"hours");d.setAttribute(classAtt1,"hours");d.innerHTML=c.myHours;b.appendChild(d);return b}function store_searchURL(){return URL+"scripts/locator/storegenxml.php?lat="+this.center.lat()+"&lng="+this.center.lng()+"&radius="+this.radius+"&vid="+this.vendorId+"&type="+this.store_type}function retail_searchURL(){return"scripts/locator/retailgenxml.php?lat="+this.center.lat()+"&lng="+this.center.lng()+"&radius="+this.radius+"&cat="+this.cat}function searchLocationsNear(){google.maps.DownloadUrl(this.searchURL(),function(e){var c=GXml.parse(e);var b=c.documentElement.getElementsByTagName("marker");locator.map.clearOverlays();locator.clearAll();if(b.length==0){locator.startOn=0;locator.endOn=0;locator.markers=[];locator.updateTop();locator.updateBottom();locator.map.setCenter(locator.center);return}for(var d=0;d<b.length;d++){var a=new google.maps.LatLng(parseFloat(b[d].getAttribute("lat")),parseFloat(b[d].getAttribute("lng")));locator.createMarker(b[d],a,d+1)}locator.createSideBar()})}function store_createMarker(f,a,e){var d=new google.maps.Icon(G_DEFAULT_ICON,URL+"images/markers/marker"+e+".png");this.icons.push(d);var b=new GMarker(a,{icon:d});b.myLetter=e;b.myId=f.getAttribute("id");b.myName=f.getAttribute("name");b.myAddress=f.getAttribute("address");b.myAddress2=f.getAttribute("address2");b.myDistance=f.getAttribute("distance");b.myDesc=f.getAttribute("desc");b.myPhone=f.getAttribute("phone");b.myHours=f.getAttribute("hours");b.myNotes=f.getAttribute("notes");b.myPoint=a;var c=this.createMarkerHTML(b);GEvent.addListener(b,"click",function(){b.openInfoWindowHtml(c)});this.markers.push(b)}function retail_createMarker(f,a,e){var d=new GIcon(G_DEFAULT_ICON,"http://www.google.com/mapfiles/marker"+e+".png");this.icons.push(d);var b=new GMarker(a,{icon:d});b.myLetter=e;b.myId=f.getAttribute("id");b.myName=f.getAttribute("name");b.myAddress=f.getAttribute("address");b.myAddress2=f.getAttribute("address2");b.myDistance=f.getAttribute("distance");b.myDesc=f.getAttribute("desc");b.myPhone=f.getAttribute("phone");b.myHours=f.getAttribute("hours");b.myVendors=f.getAttribute("vendors");var c=this.createMarkerHTML(b);GEvent.addListener(b,"click",function(){b.openInfoWindowHtml(c)});this.markers.push(b);this.map.addOverlay(b)}function makeSideBar(){var a=0;var h;if(this.markers.length>0){var d=document.createElement("tr");d.setAttribute(classAtt,"results_header");d.setAttribute(classAtt1,"results_header");var j=document.createElement("th");j.innerHTML="";d.appendChild(j);var k=document.createElement("th");k.innerHTML="STORE NAME";d.appendChild(k);var c=document.createElement("th");c.innerHTML="ADDRESS";d.appendChild(c);var e=document.createElement("th");e.innerHTML="PHONE";d.appendChild(e);var g=document.createElement("th");g.innerHTML="STORE HOURS";d.appendChild(g);this.sidebar.appendChild(d)}bounds=new google.maps.LatLngBounds();for(h=this.startOn;h<this.markers.length;h++){if(a>=numStoresPerPage){break}this.map.addOverlay(this.markers[h]);bounds.extend(this.markers[h].myPoint);if(!this.markers[h].isHidden()){var b=createSideBarEntry(this.markers[h],h);this.sidebar.appendChild(b);a++}}this.endOn=this.startOn+a;this.updateTop();this.updateBottom();var f=Math.min(locator.map.getBoundsZoomLevel(bounds),15);this.map.setCenter(bounds.getCenter(),f)}function nextLocations(){if(locator.endOn<locator.markers.length){locator.clearSideBar();locator.startOn+=numStoresPerPage;locator.createSideBar()}}function prevLocations(){if(locator.startOn){locator.clearSideBar();if(locator.startOn>=numStoresPerPage){locator.startOn-=numStoresPerPage}else{locator.startOn=0}locator.createSideBar()}}function clearAll(){this.startOn=0;this.clearSideBar();this.markers=[];this.icons=[]}function clearSideBar(){if(this.sidebar.hasChildNodes()){while(this.sidebar.childNodes.length){this.sidebar.removeChild(this.sidebar.firstChild)}}for(i=this.startOn;i<this.endOn;i++){var b=this.map.removeOverlay(this.markers[i]);var a=b}}function createSideBarEntry(a,b){var c=locator.createSideBarHTML(a);return c}function searchLocations(){var d=document.getElementById("app-search-textfield").value;var b=document.getElementById("filter-radius").value;if(locator.type==storeLocatorType){var c=document.getElementById("filter-retail").value;locator.store_type=c}else{var a=document.getElementById("filter-categories").value;locator.cat=a}locator.radius=b;locator.address=d;geocoder.getLocations(d,getLocationCB)}function initSearchLocations(){address=locator.address;geocoder.getLocations(address,getLocationCB)}function getLocationCB(b){if(!b||b.Status.code!=200){locator.address="Sorry, we were unable to find that address";locator.updateTop()}else{var a=b.Placemark[0];locator.center=new GLatLng(a.Point.coordinates[1],a.Point.coordinates[0]);locator.address=a.address;locator.searchLocationsNear()}};