var proxyServerName="",proxyServerPort="",ProxyServerPath="/maps/JSReqHandler",geoServerName="geocode.access.mapquest.com",geoServerPort="80",geoServerPath="mq",routeServerName="route.access.mapquest.com",routeServerPort="80",routeServerPath="mq",mapServerName="map.access.mapquest.com",mapServerPort="80",mapServerPath="mq",mymap=null,orig=null,dest=null,sessId,boundingBox,toFac=true,lpad=0,rpad=0,tpad=0,bpad=0,mapSize=new MQA.Size,windowHeight,windowWidth,mapHeight,mapWidth,mapDivHeight,mapDivWidth,
addrPad,mapPad;
function readyPage(){$("#print").click(printPage);$("#print").mouseenter(showPointer);$("#print").mouseleave(showDefault);$("#close").click(closePage);$("#close").mouseenter(showPointer);$("#close").mouseleave(showDefault);var b=location.search;b=$.query.get("name");var a=$.query.get("address"),f=$.query.get("address2"),c=$.query.get("city"),g=$.query.get("stateProvince"),e=$.query.get("postalCode"),i=$.query.get("phone"),d=$.query.get("lat").toString(),h=$.query.get("lng").toString();orig=new MQGeoAddress;
orig.setStreet(a);orig.setCity(c);orig.setState(g);orig.setPostalCode(e);orig.setCountry("US");if(d!=null)d=d.replace(/^\s*/,"");if(h!=null)h=h.replace(/^\s*/,"");if(d==null||d.length==0||h==null||h.length==0){d=new MQExec(geoServerName,geoServerPath,geoServerPort,proxyServerName,ProxyServerPath,proxyServerPort);h=new MQAddress;var j=new MQLocationCollection;h.setStreet(a);h.setCity(c);h.setState(g);h.setPostalCode(e);h.setCountry("US");d.geocode(h,j);if(j.getSize()>0)orig=j.getAt(0);else{alert("address couldn't be found");
return}}else{orig.getMQLatLng().setLatitude(d);orig.getMQLatLng().setLongitude(h)}d="<strong>";if(b!=null&&b.length>0)d=d+b+"<br/>";if(a!=null&&a.length>0)d+=a+"<br/>";if(f!=null&&f.length>0)d+=f+"<br/>";if(c!=null&&c.length>0&&g!=null&&g.length>0&&e!=null&&e>0)d+=c+", "+g+" "+e+"<br/>";else{a="";if(c!=null&&c.length>0)a=c;if(g!=null&&g.length>0)if(a.length>0)a+=", "+g;else a=g;if(e!=null&&e>0)if(a.length>0)a+=" "+e;else a=e.toString();if(a.length>0)d+=a+"<br/>"}if(i!=null&&i.length>0)d+=i+"<br/>";
d+="</strong>";$("#origDiv").html(d);c=document.getElementById("mapDiv");mymap=new MQA.TileMap(c,11,orig.getMQLatLng());c=new MQA.Icon("images/blueplus.gif",16,16);c=new MQA.Poi(orig.getMQLatLng(),c);c.infoTitleHTML="<strong>"+b+"</strong>";c.infoContentHTML=d;c.labelText=b;mymap.addShape(c);b=new MQA.LargeZoomControl;mymap.addControl(b);b=new MQA.ViewControl(mymap);mymap.addControl(b);$("#directionsLink").click(handleClick);$("#route").click(findRoute);$("#reverseDir").click(reverseDirections)}
function handleClick(){$("#destDiv").hasClass("filtered")?$("#destDiv").removeClass("filtered"):$("#destDiv").addClass("filtered");toFac=true;return false}
function findRoute(){try{var b=getDestination();if(b!=null){mymap.addRouteHighlight?mymap.addRouteHighlight(boundingBox,"http://"+mapServerName,sessId,true):alert("addRouteHighlight not supported");b.getTrekRoutes||alert("get trek routes not supported");b!=null&&b.getTrekRoutes()!=null?printDirs(b):alert("No directions found "+b)}}catch(a){alert(a.message)}return false}
function getDestination(){var b=new MQExec(routeServerName,routeServerPath,routeServerPort,proxyServerName,ProxyServerPath,proxyServerPort),a=new MQRouteOptions;a.setMaxShapePointsPerManeuver(200);var f=new MQLocationCollection("MQGeoAddress"),c=new MQRouteResults;boundingBox=new MQA.RectLL(MQA.LatLng(),MQA.LatLng());sessId=b.createSessionEx(new MQSession);getDestAddr();if(orig==null||dest==null)alert("Either the beginning or end of this journey cannot be determined");else{if(toFac){f.add(dest);f.add(orig)}else{f.add(orig);
f.add(dest)}try{b.doRoute(f,a,c,sessId,boundingBox)}catch(g){alert("Exception thrown in routeExec "+g.message)}}return c}
function printDirs(b){var a=b.getTime/60;if(a>60)a=a/60==1?"1 hr ":Math.round(a/60*100)/100+" hrs";a=Math.round(b.getDistance()*100)/100;b=b.getTrekRoutes();b=b.get(0).getManeuvers();a="<ul>";for(x=0;x<b.getSize();x++){manDist=Math.round(b.get(x).getDistance())*100/100;manStr=x+1+". "+b.get(x).getNarrative()+"(Distance: "+manDist+" mi)";a+=x==0?"<li class='begin'>":x==b.getSize()-1?"<li class='end'>":"<li>";a=a+manStr+"</li>"}a+="</ul>";a.indexOf("<li")>-1&&$("#directions").html(a)}
function getDestAddr(){var b=$("#destStreet").val(),a=$("#destCity").val(),f=$("#destState").val(),c=$("#destZip").val();if((a==null||a.length==0||f==null||f.length==0)&&(c==null||c.length==0))throw new Error("You must have either city and state, or zip code to get driving directions");else{var g=new MQExec(geoServerName,geoServerPath,geoServerPort,proxyServerName,ProxyServerPath,proxyServerPort),e=new MQAddress,i=new MQLocationCollection("MQGeoAddress");e.setStreet(b);e.setCity(a);e.setState(f);
e.setCountry("US");e.setPostalCode(c);g.geocode(e,i);if(i.getSize()>0)dest=i.getAt(0);else throw new Error("The address entered could not be found.");}}function reverseDirections(){toFac=!toFac;findRoute();return false}
function sizeMap(){if(mapSize==null)mapSize=new MQA.Size;mapSize.setWidth(1);mapSize.setHeight(1);mymap.setSize(mapSize);lpad=$("#mapDiv").outerWidth(true)-$("#mapDiv").innerWidth();tpad=$("#mapDiv").outerHeight(true)-$("#mapDiv").innerHeight();windowHeight=$(window).height()-30;windowWidth=$(window).width()-10;addrHeight=$("#addrInfo").height()+$("#widgets").height();mapDivHeight=windowHeight-(addrHeight+tpad);mapWidth=mapDivWidth=windowWidth-lpad;mapHeight=mapDivHeight;$("#mapDiv").height(mapDivHeight);
$("#mapDiv").width(mapDivWidth);$("#main").height(windowHeight);$("#main").width(windowWidth);if(mapWidth<400)mapWidth=400;if(mapHeight<350)mapHeight=350;mapSize.setWidth(mapWidth);mapSize.setHeight(mapHeight);mymap.setSize(mapSize)}function closePage(){window.close()}function printPage(){window.print()}function showPointer(){$(this).addClass("pointer")}function showDefault(){$(this).removeClass("pointer")};