var map;var car;var fc;var bounds;var center;var allowedBounds;var startZoom=10;var mapData=null;var servicesArr=[["RR",0,"Accessible Restrooms"],["ATM",0,"ATM"],["CW",0,"Carwash"],["S",0,"Convenience Store"],["D",0,"Diesel Fuel"],["F",0,"Fuel Call"]];var markercnt=0;var printflag=0;var controlbar=null;var tabs=null;var helptab=null;var countytab=null;var newchoice=null;var sidebarlist=null;var countyOptionsArr=null;var markerID=0;var MPVAControl=function(a){this.url_=a};function redrawMap(xhr){sidebarlist.innerHTML="";collectCheckboxValues();document.getElementById("printlist").style.display="block";var mapData=eval("("+xhr.responseText+")");countyName=mapData.countyName;countyNum=mapData.countyNum;for(var i=0;i<countyOptionsArr.length;i++){var arr=countyOptionsArr[i].value.split(",");if(arr[0]==countyNum){newchoice.value=countyOptionsArr[i].value;break}}markers=mapData.markers;for(id in markers){if(markers[id].fuelcall==null||markers[id].fuelcall==0){initializePoint(markers[id],car)}else{initializePoint(markers[id],fc)}}if(markercnt==0){printNoResults("noresults")}else{printServicesList()}controlbar.style.display="none"}function getMarkers(){var b=map.getCenter();centerLong=b.lng();centerLat=b.lat();if(map.getZoom()>5){controlbar.style.display="block";bounds=map.getBoundsLatLng();var a="js/mapdata.php?cnty="+countyNum+"&right="+bounds.maxX+"&left="+bounds.minX+"&top="+bounds.maxY+"&bottom="+bounds.minY+"&cntrlat="+centerLat+"&cntrlng="+centerLong;sendRequest(a,redrawMap)}else{map.clearOverlays();sidebarlist.innerHTML="";printNoResults("zoomin")}}function moveToCounty(){var a=document.getElementById("newchoice").value.split(",");countyNum=a[0];centerLat=a[1];centerLong=a[2];map.setCenter(new GLatLng(centerLat,centerLong));bounds=map.getBoundsLatLng();if(map.getZoom()>6){var b="js/mapdata.php?cnty="+countyNum+"&right="+bounds.maxX+"&left="+bounds.minX+"&top="+bounds.maxY+"&bottom="+bounds.minY+"&cntrlat="+centerLat+"&cntrlng="+centerLong;sendRequest(b,redrawMap)}else{map.clearOverlays();sidebarlist.innerHTML="";printNoResults("zoomin")}}var deselectCurrent=function(){};function initializePoint(l,j){var c=0;var g=servicesArr.length;for(var d=0;d<g;d++){if(servicesArr[d][1]==0||(servicesArr[d][1]==1&&l.services[d]==1)){c++}}if(c==g){var k=new GLatLng(l.latitude,l.longitude);var e=new GMarker(k,j);var a=document.createElement("li");var b=document.createElement("a");b.href="#";b.innerHTML='<span style="font-weight: bold;">'+l.name;if(l.fuelcall==1){b.innerHTML+='&nbsp;&nbsp;<img src="../../images/fuelcall20.png" height="20" width="20" border="0" alt="" />'}b.innerHTML+="</span><br />";b.innerHTML+="<span>"+l.address1+"</span><br />";if(l.address2!=null&&l.address2!="NULL"&&l.address2!=""){b.innerHTML+="<span>"+l.address2+"</span><br />"}b.innerHTML+="<span>"+l.city+", MI  "+l.zip+"</span><br />";b.innerHTML+="<span>"+l.telephone+"</span><br />";b.innerHTML+="<span>"+l.hours+"</span>";var h="";for(var d=0;d<servicesArr.length;d++){if(l.services[d]==1){h+=servicesArr[d][0]+","}}if(h!=""){b.innerHTML+="<br /><span>"+h.substring(0,h.lastIndexOf(","))+"</span>"}if(l.other!=null&&l.other!="NULL"&&l.other!=""){b.innerHTML+="<br /><span>"+l.other+"</span>"}var f=function(){deselectCurrent();markerID=l.id;a.className="current";deselectCurrent=function(){a.className=""};var o="";if(l.fuelcall==1){o='<img style="float:right;margin-right: 30px;width:20px;" src="../../images/fuelcall20.png" height="20" width="20" border="0" alt="" />'}o+='<div style="line-height: 100%;"><span style="font: .7em Helvetica,sans-serif;"><span style="font-weight: bold;">'+l.name+"</span><br />"+l.address1+"<br />";if(l.address2!=null&&l.address2!="NULL"&&l.address2!=""){o+=l.address2+"<br />"}o+=l.city+", MI<br />"+l.telephone+"<br />"+l.hours;if(l.other!=null&&l.other!="NULL"&&l.other!=""){o+="<br />"+l.other}var n="";for(var m=0;m<servicesArr.length;m++){if(l.services[m]==1){n+=servicesArr[m][2]+", "}}if(n!=""){o+='<div style="border-top: 1px solid #aaa; margin-top: 3px; padding-top: 3px;">'+n.substring(0,n.lastIndexOf(","))+"</div>"}o+="</span></div>";e.openInfoWindowHtml(o);return false};GEvent.addListener(e,"click",f);b.onclick=f;a.appendChild(b);document.getElementById("sidebar-list").appendChild(a);map.addOverlay(e);markercnt++}}function windowHeight(){if(self.innerHeight){return self.innerHeight}if(document.documentElement&&document.documentElement.clientHeight){return document.documentElement.clientHeight}if(document.body){return document.body.clientHeight}return 0}function handleResize(){var a=windowHeight()-document.getElementById("toolbar").offsetHeight-30;document.getElementById("map").style.height=a+"px";document.getElementById("sidebar").style.height=a+"px"}function changeBodyClass(b,a){document.body.className=document.body.className.replace(b,a);return false}function applyServicesFilter(b){map.clearOverlays();collectCheckboxValues();document.getElementById("printlist").style.display="block";var a=document.getElementById("sidebar-list");a.innerHTML="";for(id in markers){initializePoint(markers[id],car)}if(markercnt==0){printNoResults("noresults")}else{printServicesList()}markercnt=0}function collectCheckboxValues(){var b=document.getElementsByTagName("input");for(var a=0;a<servicesArr.length;a++){if(b[a].getAttribute("type")=="checkbox"&&b[a].checked==true){servicesArr[a][1]=1}else{servicesArr[a][1]=0}}for(var a=0;a<servicesArr.length;a++){}}function printNoResults(a){var b=document.createElement("li");b.setAttribute("style","display: block; padding-top: 5px; padding-left: 16px;");if(a=="noresults"){var c=document.createTextNode("Sorry, there were no station locations found for your choices.")}else{var c=document.createTextNode("Please zoom in closer to display station locations.")}b.appendChild(c);document.getElementById("sidebar-list").appendChild(b);document.getElementById("printlist").style.display="none"}function createPlacemarkIcon(){var a=new GIcon();a.iconSize=new GSize(20,17);a.shadowSize=new GSize(40,17);a.iconAnchor=new GPoint(10,17);a.infoWindowAnchor=new GPoint(10,0);car=new GIcon(a,"http://www.thepumpguide.com/images/redcar20.png");fc=new GIcon(a,"http://www.thepumpguide.com/images/fuelcall20.png")}function checkBounds(){if(allowedBounds.contains(map.getCenter())){return}var e=map.getCenter();centerLong=e.lng();centerLat=e.lat();var b=allowedBounds.getNorthEast().lng();var a=allowedBounds.getNorthEast().lat();var d=allowedBounds.getSouthWest().lng();var c=allowedBounds.getSouthWest().lat();if(centerLong<d){centerLong=d}if(centerLong>b){centerLong=b}if(centerLat<c){centerLat=c}if(centerLat>a){centerLat=a}map.setCenter(new GLatLng(centerLat,centerLong))}function switchTabs(b){var a=document.getElementById("countyblock");var c=document.getElementById("helpblock");b.className="current";if(b.id=="helptab"){document.getElementById("countytab").className="";c.style.display="block";a.style.display="none"}else{document.getElementById("helptab").className="";c.style.display="none";a.style.display="block"}}function highlightTab(a){if(a.style.textDecoration=="underline"){a.style.textDecoration="none"}else{if(a.className!="current"){a.style.textDecoration="underline"}}}function init(){sidebarlist=document.getElementById("sidebar-list");controlbar=document.getElementById("loadingmessage");controlbar.style.display="block";document.getElementById("button-sidebar-hide").onclick=function(){return changeBodyClass("sidebar-right","nosidebar")};document.getElementById("button-sidebar-show").onclick=function(){return changeBodyClass("nosidebar","sidebar-right")};var e=document.getElementsByTagName("input");for(var c=0;c<e.length;c++){if(e[c].getAttribute("type")=="checkbox"){e[c].checked=false;e[c].onclick=function(){return applyServicesFilter(this)}}}tabs=document.getElementById("tabs").childNodes;for(var c=0;c<tabs.length;c++){if(tabs[c]){tabs[c].onmouseover=function(){return highlightTab(this)};tabs[c].onmouseout=function(){return highlightTab(this)};tabs[c].onclick=function(){return switchTabs(this)}}}newchoice=document.getElementById("newchoice");if(newchoice){newchoice.onchange=function(){return moveToCounty();return false}}countyOptionsArr=document.getElementsByTagName("option");for(var c=0;c<countyOptionsArr.length;c++){var a=countyOptionsArr[c].value.split(",");if(a[0]==countyNum){newchoice.value=countyOptionsArr[c].value;break}}createPlacemarkIcon();handleResize();map=new GMap(document.getElementById("map"));map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());map.addControl(new MPVAControl());if(fuelcall==1){startZoom=6;var d=document.getElementById("fuelcall");d.checked=true}map.setCenter(new GLatLng(centerLat,centerLong),startZoom);bounds=map.getBoundsLatLng();var b=map.getMapTypes();for(var c=0;c<b.length;c++){b[c].getMinimumResolution=function(){return 6};b[c].getMaximumResolution=function(){return 16}}allowedBounds=new GLatLngBounds(new GLatLng(41.55667,-89.7),new GLatLng(47.5,-81.246214));GEvent.addListener(map,"zoomend",function(){getMarkers()});GEvent.addListener(map,"moveend",function(){getMarkers()});GEvent.addListener(map,"move",function(){checkBounds()});getMarkers()}window.onresize=handleResize;window.onload=init;function printServicesList(){var e=document.getElementById("printservices");e.innerHTML="";var d=document.getElementById("offering");d.innerHTML="";var b="";var a=0;var f=servicesArr.length;for(var c=0;c<f;c++){if(servicesArr[c][1]==1){var g=document.createElement("li");b=servicesArr[c][2];g.appendChild(document.createTextNode(b));e.appendChild(g);a++}}if(a==0){d.appendChild(document.createTextNode("These stations may or may not offer accessible restrooms, ATM, carwash, convenience store, or diesel fuel.  Please call ahead if you need any of these services."))}else{d.appendChild(document.createTextNode("The owners of the stations in this list claim to offer the following specific services:"))}}MPVAControl.prototype=new GControl(true);MPVAControl.prototype.initialize=function(){var a=document.createElement("div");a.innerHTML='<img style="cursor: pointer;" src="http://www.thepumpguide.com/images/mpvalogo_map.gif" border="0" alt="The Pump Guide" />';a.style.width="90px";a.style.height="90px";url=this.url_;GEvent.addDomListener(a,"click",function(){document.location=url});map.getContainer().appendChild(a);return a};MPVAControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(5,50))};
