var geopts=[];function clearDrives(){if(hoversInitialized)document.getElementById('hoverdrive').innerHTML='';for (var i=0;i<geopts.length;i++){geopts[i].setMap(null);}clearHighlightedDrive();geopts=[];}function mkPtAr(pt){if(!(pt instanceof Array)){return google.maps.geometry.encoding.decodePath(pt);}var p=new google.maps.MVCArray();for(var i=0;i<(pt.length/2);++i)p.push(mkLaLn(pt[i*2],pt[(i*2)+1]));return p;}var polyClick=null;var polylineOpacity=1.0;var polyColor='#663311';function drawDrive(pn){var p=new google.maps.Polyline({strokeColor:polyColor,strokeOpacity:polylineOpacity,strokeWeight:4,clickable:clickHandler!=null||polyClick!=null});p.setPath(mkPtAr(pn));p.setMap(map);geopts.push(p);if(hoversInitialized){google.maps.event.addListener(p,'click',clickHandler);}else if(polyClick){google.maps.event.addListener(p,'click',polyClick);}}var hidri=null;function highlightDrive(pts){if(hidri==null)hidri=[];var h=new google.maps.Polyline({strokeColor:'#728315',strokeOpacity:1.0,strokeWeight:4,clickable:true});h.setPath(mkPtAr(pts));h.setMap(map);hidri.push(h);document.getElementById(mapDiv).style.cursor='pointer';if(hoversInitialized){google.maps.event.addListener(h,'click',clickHandler);}}function clearHighlightedDrive(){document.getElementById(mapDiv).style.cursor='default';if(hidri!=null){for(var i=0;i<hidri.length;++i)hidri[i].setMap(null);hidri=null;}}function clickHandler(e){var cmd=document.getElementById('context_menu');if(cmd!=null){rmChild('context_menu');if(cmd.style.display!='none'){return false;}}var c=e.latLng;if(!overlay.getProjection()){return;}var p=overlay.getProjection().fromLatLngToContainerPixel(c);var matches=[];for(var i=0;i<drives.drives.length;++i)if(isInPoly(drives.drives[i].outrect,c.lat(),c.lng()))matches.push(drives.drives[i]);if(matches.length==1){OpenPage(matches[0].name,matches[0].iurl,matches[0].url);}else if(matches.length>1){try{instContMen();}catch(e){}var div=document.createElement('div');div.setAttribute('id','context_menu');div.style.display='block';var ul=document.createElement('ul');ul.setAttribute('class','cmenu');div.appendChild(ul);for(var i=0;i<matches.length;++i){var li=document.createElement('li');li.innerHTML='<a href="'+matches[i].url+'" onclick="hideElement(\'context_menu\');OpenPage(\''+matches[i].name+'\',\''+matches[i].iurl+'\',\''+matches[i].url+'\');return false;">'+matches[i].name+'</a>';ul.appendChild(li);}var off=getComputedRealXY(document.getElementById('welmap'));var st=document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;st+=off[1];var sl=document.body.scrollLeft?document.body.scrollLeft:document.documentElement.scrollLeft;sl+=off[0];div.style.left=(p.x+sl)+'px';div.style.top=(p.y+st)+'px';document.body.appendChild(div);}}function mouseMoveHandler(e){if(drives==null){return;}clearHighlightedDrive();if(!e)e=window.event;var mapId='welmap';if(document.getElementById(mapId)==null)mapId='drivemap';if(document.getElementById(mapId)==null)mapId='rtmap';var off=getComputedRealXY(document.getElementById(mapId));if(!overlay.getProjection()){return;}var c=overlay.getProjection().fromContainerPixelToLatLng(new google.maps.Point(e.clientX-off[0],e.clientY-off[1]));var matches=[];for(var i=0;i<drives.drives.length;++i)if(isInPoly(drives.drives[i].outrect,c.lat(),c.lng())){matches.push(drives.drives[i]);highlightDrive(drives.drives[i].points);}var status='';for(var i=0;i<matches.length;++i){if(status.length)status+=', ';if(i!=0&&i+1==matches.length)status+='and ';status+='<a href="'+matches[i].url+'">'+matches[i].name+'</a>';}document.getElementById('hoverdrive').innerHTML=status;}var hoversInitialized=false;function handleHovers(){if(!hoversInitialized){hoversInitialized=true;if(hovers)google.maps.event.addListener(map,'MouseMove',mouseMoveHandler);google.maps.event.addListener(map,'click',clickHandler);}}function mkLaLn(la,lo){return new google.maps.LatLng(la,lo);}function redrawMap(lat,lng,rad,trLat,trLong,blLat,blLong,f){if(!f&&desCntr!=null&&desCntr.lat()==lat&&desCntr.lng()==lng){return;}desCntr=mkLaLn(lat,lng);desBnds=new google.maps.LatLngBounds(mkLaLn(blLat,trLong),mkLaLn(trLat,blLong));adjustZoom();}function adjustZoom(){resetMapLocation();}function MsdOverlay(map){this.setMap(map);}MsdOverlay.prototype=new google.maps.OverlayView;MsdOverlay.prototype.onAdd=function(){};MsdOverlay.prototype.onRemove=function(){};MsdOverlay.prototype.draw=function(){};function MsdPoiOverlay(map,cntr,lab,sd,d,u,del,param,onDel,opt){this.setMap(map);this.cntr_=cntr;this.lab_=lab;this.onDel_=onDel;this.desc_='';this.url_=u&&u.length>1?u:null;this.del_=del;this.opt_=opt?opt:'';this.onDelParam_=param;this.shouldShow_=false;if(d&&d.length!=0)this.desc_='<p>'+d.replace(/"/g,'&quot;').replace(/\'/g,'\\\'').replace(/\n/g,'<br />')+'</p>';switch(this.lab_.charAt(0)){case 'F':this.labPrefix_='Food: ';this.labSuffix_=' ('+lab+')';break;case 'I':this.labPrefix_='Information: ';this.labSuffix_=' ('+lab+')';break;case 'S':this.labPrefix_='Services: ';this.labSuffix_=' ('+lab+')';break;default:this.labPrefix_=lab+': ';this.labSuffix_='';break;}this.sd_=sd.replace(/\'/,'&amp;#39;');}MsdPoiOverlay.prototype=new google.maps.OverlayView;MsdPoiOverlay.prototype.onAdd=function(){var div=this.div_=document.createElement('div');div.id=mkUniqField();div.poi=this;div.style.position='absolute';div.style.display='block';div.style.visibility='hidden';div.className='msdPoiOverlay';var l=(this.url_?('<a href=&quot;'+this.url_+'&quot;'+'>'):'');var lc=(this.url_?('</a>'):'');div.innerHTML='<div class="'+this.lab_.charAt(0)+'" onclick="var e=createPOITip(document.getElementById(\''+div.id+'\'));e.innerHTML=\'<p class=&quot;title&quot;>'+l+this.labPrefix_+this.sd_+this.labSuffix_+lc+'</p>'+this.desc_+'\'+e.innerHTML;return false;" onMouseOver="var e=createPOITip(document.getElementById(\''+div.id+'\'));e.innerHTML=\'<p class=&quot;title&quot;>'+l+this.labPrefix_+this.sd_+this.labSuffix_+lc+'</p>'+this.desc_+'\'+e.innerHTML;">'+this.lab_+'</div>';google.maps.event.addListener(this,'click',function(){var e=createPOITip(document.getElementById(div.id));e.innerHTML='<p class=&quot;title&quot;>'+l+this.labPrefix_+this.sd_+this.labSuffix_+lc+'</p>'+this.desc_+e.innerHTML;return false;});this.div_=div;this.getPanes().floatShadow.appendChild(div);if(this.shouldShow_){this.show();this.shouldShow_=false;}};MsdPoiOverlay.prototype.getCenter=function(){return this.cntr_;};MsdPoiOverlay.prototype.canDelete=function(){return this.del_;};MsdPoiOverlay.prototype.getOptions=function(){return this.opt_;};MsdPoiOverlay.prototype.onRemoveMarker=function(){if(this.onDel_){this.onDel_(this.onDelParam_);}};MsdPoiOverlay.prototype.onRemove=function(){if(this.div_){this.div_.parentNode.removeChild(this.div_);this.div_=null;rmChild('poiTip');}};MsdPoiOverlay.prototype.draw=function(){var prj=this.getProjection();var pos=prj.fromLatLngToDivPixel(this.cntr_);var div=this.div_;div.style.left=pos.x+'px';div.style.top=pos.y+'px';};MsdPoiOverlay.prototype.isDisplayed=function(){if(this.div_)return this.div_.style.visibility!='hidden';else return false;};MsdPoiOverlay.prototype.hide=function(){if(this.div_)this.div_.style.visibility='hidden';rmChild('poiTip');};MsdPoiOverlay.prototype.show=function(){if(this.div_)this.div_.style.visibility='visible';else this.shouldShow_=true;rmChild('poiTip');};var geopts=[];function clearDrives(){if(hoversInitialized)document.getElementById('hoverdrive').innerHTML='';for (var i=0;i<geopts.length;i++){geopts[i].setMap(null);}clearHighlightedDrive();geopts=[];}function mkPtAr(pt){if(!(pt instanceof Array)){return google.maps.geometry.encoding.decodePath(pt);}var p=new google.maps.MVCArray();for(var i=0;i<(pt.length/2);++i)p.push(mkLaLn(pt[i*2],pt[(i*2)+1]));return p;}var polyClick=null;var polylineOpacity=1.0;var polyColor='#663311';function drawDrive(pn){var p=new google.maps.Polyline({strokeColor:polyColor,strokeOpacity:polylineOpacity,strokeWeight:4,clickable:clickHandler!=null||polyClick!=null});p.setPath(mkPtAr(pn));p.setMap(map);geopts.push(p);if(hoversInitialized){google.maps.event.addListener(p,'click',clickHandler);}else if(polyClick){google.maps.event.addListener(p,'click',polyClick);}}var hidri=null;function highlightDrive(pts){if(hidri==null)hidri=[];var h=new google.maps.Polyline({strokeColor:'#728315',strokeOpacity:1.0,strokeWeight:4,clickable:true});h.setPath(mkPtAr(pts));h.setMap(map);hidri.push(h);document.getElementById(mapDiv).style.cursor='pointer';if(hoversInitialized){google.maps.event.addListener(h,'click',clickHandler);}}function clearHighlightedDrive(){document.getElementById(mapDiv).style.cursor='default';if(hidri!=null){for(var i=0;i<hidri.length;++i)hidri[i].setMap(null);hidri=null;}}function clickHandler(e){var cmd=document.getElementById('context_menu');if(cmd!=null){rmChild('context_menu');if(cmd.style.display!='none'){return false;}}var c=e.latLng;if(!overlay.getProjection()){return;}var p=overlay.getProjection().fromLatLngToContainerPixel(c);var matches=[];for(var i=0;i<drives.drives.length;++i)if(isInPoly(drives.drives[i].outrect,c.lat(),c.lng()))matches.push(drives.drives[i]);if(matches.length==1){OpenPage(matches[0].name,matches[0].iurl,matches[0].url);}else if(matches.length>1){try{instContMen();}catch(e){}var div=document.createElement('div');div.setAttribute('id','context_menu');div.style.display='block';var ul=document.createElement('ul');ul.setAttribute('class','cmenu');div.appendChild(ul);for(var i=0;i<matches.length;++i){var li=document.createElement('li');li.innerHTML='<a href="'+matches[i].url+'" onclick="hideElement(\'context_menu\');OpenPage(\''+matches[i].name+'\',\''+matches[i].iurl+'\',\''+matches[i].url+'\');return false;">'+matches[i].name+'</a>';ul.appendChild(li);}var off=getComputedRealXY(document.getElementById('welmap'));var st=document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;st+=off[1];var sl=document.body.scrollLeft?document.body.scrollLeft:document.documentElement.scrollLeft;sl+=off[0];div.style.left=(p.x+sl)+'px';div.style.top=(p.y+st)+'px';document.body.appendChild(div);}}function mouseMoveHandler(e){if(drives==null){return;}clearHighlightedDrive();if(!e)e=window.event;var mapId='welmap';if(document.getElementById(mapId)==null)mapId='drivemap';if(document.getElementById(mapId)==null)mapId='rtmap';var off=getComputedRealXY(document.getElementById(mapId));if(!overlay.getProjection()){return;}var c=overlay.getProjection().fromContainerPixelToLatLng(new google.maps.Point(e.clientX-off[0],e.clientY-off[1]));var matches=[];for(var i=0;i<drives.drives.length;++i)if(isInPoly(drives.drives[i].outrect,c.lat(),c.lng())){matches.push(drives.drives[i]);highlightDrive(drives.drives[i].points);}var status='';for(var i=0;i<matches.length;++i){if(status.length)status+=', ';if(i!=0&&i+1==matches.length)status+='and ';status+='<a href="'+matches[i].url+'">'+matches[i].name+'</a>';}document.getElementById('hoverdrive').innerHTML=status;}var hoversInitialized=false;function handleHovers(){if(!hoversInitialized){hoversInitialized=true;if(hovers)google.maps.event.addListener(map,'MouseMove',mouseMoveHandler);google.maps.event.addListener(map,'click',clickHandler);}}var clp=null;var clpLoc=null;function setMyLocation(lat,lng){if(clp!=null&&clpLoc!=null&clpLoc.lat()==lat&&clpLoc.lng()==lng)return;if(clp!=null){clp.setMap(null);}clpLoc=mkLaLn(lat,lng);clp=new google.maps.Marker({clickable:false,draggable:false,icon:'/my_location.png',map:map,position:clpLoc,shape:[0,0,0,10,10,10,10,0],title:'Your location',visible:true});}function delMyLocation(){if(clp)clp.setMap(null);clp=null;}function showOrHidePOI(pois,chk){for(var i=0;i<pois.length;++i){if(chk){pois[i].show();}else{pois[i].hide();}}}var poiInit=false;function makePoi(la,lo,c,lab,sd,d,url,del,param,onDel,onEdt){if(!poiInit){google.maps.event.addListener(map,'dragstart',function(){rmChild('poiTip');});poiInit=true;}return new MsdPoiOverlay(map,mkLaLn(la,lo),lab,sd,d,url,del,param,onDel,onEdt);}function isMarkerDisplayed(p){return p.getMap()!=null&&p.isDisplayed();}function displayMarker(p){p.show();rmChild('poiTip');}function hideMarker(p){p.hide();rmChild('poiTip');}function removeMarker(p){p.setMap(null);rmChild('poiTip');}var clp=null;var clpLoc=null;function setPointOfInterest(lat,lng,title){if(clp!=null&&clpLoc!=null&clpLoc.lat()==lat&&clpLoc.lng()==lng)return;if(clp!=null){clp.setMap(null);}clpLoc=mkLaLn(lat,lng);clp=new google.maps.Marker({clickable:false,draggable:false,raiseOnDrag:false,zIndex:5,map:map,position:clpLoc,title:title,visible:true});}function expandRegions(){try{instContMen();}catch(e){}var div=document.getElementById('context_menu');if(div!=null){rmChild('context_menu');if(div.style.display!='none'){return false;}}div=document.createElement('div');div.setAttribute('id','context_menu');var ul=document.createElement('ul');ul.setAttribute('class','cmenu');div.appendChild(ul);var li;div.style.display='block';li=document.createElement('li');li.innerHTML='<a href=\'/regions/alaska\'>Alaska</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/arizona\'>Arizona</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/arkansas\'>Arkansas</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/california\'>California</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/colorado\'>Colorado</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/idaho\'>Idaho</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/kansas\'>Kansas</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/massachusetts\'>Massachusetts</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/montana\'>Montana</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/nevada\'>Nevada</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/new-hampshire\'>New Hampshire</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/new-mexico\'>New Mexico</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/new-york\'>New York</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/north-carolina\'>North Carolina</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/oklahoma\'>Oklahoma</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/oregon\'>Oregon</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/south-dakota\'>South Dakota</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/tennessee\'>Tennessee</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/texas\'>Texas</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/utah\'>Utah</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/vermont\'>Vermont</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/virginia\'>Virginia</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/washington\'>Washington</a>';ul.appendChild(li);li=document.createElement('li');li.innerHTML='<a href=\'/regions/wyoming\'>Wyoming</a>';ul.appendChild(li);var off=getComputedRealXY(document.getElementById('regionsPicker'));var st=off[1]+18;var sl=off[0];div.style.left=sl+'px';div.style.top=st+'px';document.body.appendChild(div);}function removeAllMarkers(p){if(p==null)return;for(var i=0;i<p.length;++i)removeMarker(p[i]);}function showAllMarkers(p){for(var i=0;i<p.length;++i)displayMarker(p[i]);}
