var VEMap=new Class({initialize:function(hrsMapOrDivName){if(typeof(hrsMapOrDivName)=="object"){this.iframe=(window.iframeMap||parent.iframeMap||window.frames.iframeMap||parent.frames.iframeMap);
this.hrsMap=hrsMapOrDivName
}else{this.iframe=null;
this.hrsMap=HRSMaps.newHRSMap($(hrsMapOrDivName));
var onHRSMarkerMouseOver=function(hrsMarker){if(hrsMarker){if(hrsMarker){hrsMarker.showInfoBox(hrsMarker)
}}};
var onHRSMarkerClick=function(hrsMarker){if(hrsMarker){if(hrsMarker.hotel_keylist){openDetailsHotel(hrsMarker.hotel_keylist,"showHotel","mapsearch","selectNoBundle")
}else{hrsMarker.showInfoBox(hrsMarker)
}}};
this.hrsMap.setOnHRSMarkerMouseOver(onHRSMarkerMouseOver);
this.hrsMap.setOnHRSMarkerClick(onHRSMarkerClick)
}HRSMaps._window.document.addEvent("keydown",function(event){if((event.key=="left")||(event.key=="right")||(event.key=="up")||(event.key=="down")){event.stop()
}HRSMaps.onKeyDown(event.key)
});
this.activeLayer=0;
return this
},_iFrameOrWindow:function(){return this.iframe?this.iframe:window
},getHRSMarker:function(lat,lon,hrsMapObj){return HRSMaps.newHRSMarker(lat,lon,hrsMapObj)
},getAShape:function(marker,latlon){return new VEShape(marker,latlon)
},getBounds:function(SW,NE){return HRSMaps.newGLatLngBounds(SW,NE)
},removeGoogleEventListeners:function(obj,evName){return HRSMaps.GEventclearListeners(obj,evName)
},getGoogleMapStyles:function(bingType){return(this.hrsMap.adapterGetGoogleMapStyleFromBingMapStyle(bingType))
},reduceToThisLayerIndex:function(index){this.hrsMap.adapterHideHRSMarkersWithZIndexOtherThan(index);
this.activeLayer=0
},LoadMap:function(){},Dispose:function(){this.hrsMap.adapterDispose()
},AddShapeLayer:function(index){this.activeLayer=index
},AddShape:function(shapeWrapper){var shapeWrapperMarker=shapeWrapper.marker;
shapeWrapperMarker.adapterSetShape(shapeWrapper);
this.hrsMap.adapterAddOverlay(shapeWrapperMarker,this.activeLayer,this.hrsMap)
},ShowInfoBox:function(shapeWrapper){shapeWrapper.marker.showInfoBox()
},HideInfoBox:function(){this.hrsMap.hideInfoBox()
},AddTileLayer:function(){},DeleteAllShapes:function(){this.activeLayer=0;
return this.hrsMap.adapterClearOverlays()
},SetTileBuffer:function(number){},AttachEvent:function(bingevent,listener){this.hrsMap.adapterGetGoogleEvent(this._iFrameOrWindow(),this.mapEvent(bingevent),listener)
},SetCenterAndZoom:function(LatLng,zoom){this.hrsMap.adapterSetCenterAndZoom(LatLng,zoom)
},GetMapStyle:function(){return this.hrsMap.adapterGetCurrentMapType()
},SetMapStyle:function(style){var googlestyle=HRSMaps.adapterGetGoogleMapStyleFromBingMapStyle(style);
this.hrsMap.adapterSetMapType(googlestyle)
},SetMouseWheelZoomToCenter:function(Bool){this.hrsMap.adapterEnableScrollWheelZoom(Bool);
this.hrsMap.adapterEnableContinuousZoom(Bool)
},HideDashboard:function(){},HideControl:function(){},Hide3DNavigationControl:function(){if(this.iframe==null){this.hrsMap.adapterAddGSmallMapControl()
}},showGoogleDNavigationControl:function(){if(this.iframe==null){this.hrsMap.adapterAddMapControl();
this.hrsMap.adapterAddGSmallMapControl()
}},GetMapView:function(){var googleRec=this.hrsMap.adapterGetBounds();
var NE=googleRec.getNorthEast();
var SW=googleRec.getSouthWest();
var myRec=Array();
myRec.BottomRightLatLong=Array();
myRec.BottomRightLatLong.Latitude=SW.lat();
myRec.BottomRightLatLong.Longitude=NE.lng();
myRec.TopLeftLatLong=Array();
myRec.TopLeftLatLong.Latitude=NE.lat();
myRec.TopLeftLatLong.Longitude=SW.lng();
return myRec
},SetMapView:function(myLatLongs,obj){var aktZoom=this.hrsMap.adapterGetZoom();
var aktCenter=this.hrsMap.adapterGetCenter();
if(myLatLongs.length==1){center=myLatLongs[0];
if(this.iframe==null){}else{zoom=15
}}else{var SW=new Array();
var NE=new Array();
if(myLatLongs[1].lat()<myLatLongs[0].lat()){SW[0]=(myLatLongs[1].lat());
NE[0]=(myLatLongs[0].lat())
}else{SW[0]=(myLatLongs[0].lat());
NE[0]=(myLatLongs[1].lat())
}if(myLatLongs[1].lng()<myLatLongs[0].lng()){SW[1]=(myLatLongs[1].lng());
NE[1]=(myLatLongs[0].lng())
}else{SW[1]=(myLatLongs[0].lng());
NE[1]=(myLatLongs[1].lng())
}var N=this._iFrameOrWindow().getVELatLong(NE[0],NE[1]);
var S=this._iFrameOrWindow().getVELatLong(SW[0],SW[1]);
var bounds=this.getBounds(S,N);
if(myLatLongs.length>2){for(var i=2;
i<myLatLongs.length;
i++){bounds.extend(this._iFrameOrWindow().getVELatLong(myLatLongs[i].lat(),myLatLongs[i].lng()))
}}var zoom=this.hrsMap.adapterGetBoundsZoomLevel(bounds);
var center=bounds.getCenter();
if(!(zoom==aktZoom&&center.lat()==aktCenter.lat()&&center.lng()==aktCenter.lng())){this.hrsMap.adapterSetCenterAndZoom(center,zoom);
var aktZoomdanach=this.hrsMap.adapterGetZoom();
var aktCenterdanach=this.hrsMap.adapterGetCenter()
}}},GetShapeLayerByIndex:function(index){},GetCenter:function(){var myCenter=Array();
var hrsMapAdapterCenter=this.hrsMap.adapterGetCenter();
myCenter.Latitude=hrsMapAdapterCenter.lat();
myCenter.Longitude=hrsMapAdapterCenter.lng();
return myCenter
},SetCenter:function(LatLng){this.hrsMap.adapterSetCenter(LatLng)
},SetScaleBarDistanceUnit:function(unit){},ShowMiniMap:function(){},GetZoomLevel:function(){return this.hrsMap.adapterGetZoom()
},SetZoomLevel:function(zoom){return this.hrsMap.adapterSetZoom(zoom)
},StartContinuousPan:function(x,y){this.hrsMap.panByXY(x,y)
},EndContinuousPan:function(){return
},PixelToLatLong:function(pixel){return this.hrsMap.adapterFromContainerPixelToLatLng(pixel)
},LatLongToPixel:function(VELatLng){return this.hrsMap.adapterFromLatLngToContainerPixel(this._iFrameOrWindow().getVELatLong(VELatLng.Latitude,VELatLng.Longitude))
},mapEvent:function(bingEventType){switch(bingEventType){case"onclick":return"click";
case"onchangemapstyle":return"maptypechanged";
case"onendzoom":return"zoomend";
case"onmouseup":return"click";
case"onmouseover":return"mouseover";
case"ontokenerror":return;
case"ontokenexpire":return;
case"onendpan":return"dragend";
case"onobliqueenter":return;
case"onobliqueleave":return;
case"onchangeview":return;
default:return null
}}});
var VEShape=new Class({initialize:function(hrsMarker,latlon,mapObj){if(typeof(hrsMarker)=="object"){this.marker=hrsMarker
}else{var hrsMarker=HRSMaps.newHRSMarker(latlon.lat(),latlon.lng());
this.marker=hrsMarker
}return this
},getaMarker:function(hrsMarker){this.marker=hrsMarker;
return this.marker
},setZIndex:function(index){this.marker.adapterSetZIndex(index)
},getaShape:function(){return this
},SetCustomIcon:function(html){this.marker.SetCustomIcon(html)
},SetTitle:function(html){this.marker.SetTitle(html)
},SetDescription:function(html){this.marker.SetDescription(html)
}});
VEDistanceUnit=new Array();
VEDistanceUnit.Miles="Miles";
VEDistanceUnit.Kilometers="Kilometers";
VEShapeType=new Array();
VEShapeType.Pushpin="Pushpin";
VEShapeType.Polyline="Polyline";
VEShapeType.Polygon="Polygon";
VEMapStyle=new Array();
VEMapStyle.Road="Road";
VEMapStyle.Hybrid="Hybrid";
VEMapStyle.Aerial="Aerial";
VEMapStyle.Shaded="Shaded";
VEMapStyle.Oblique="Oblique";
VEMapStyle.Birdseye="Birdseye";
VEMapStyle.BirdseyeHybrid="BirdseyeHybrid";
var VELatLong=new Class({initialize:function(lat,lng){var iframe=(window.iframeMap||parent.iframeMap||window.frames.iframeMap||parent.frames.iframeMap);
if(iframe){return iframe.getVELatLong(lat,lng)
}else{return getVELatLong(lat,lng)
}}});
var Dashboard=new Class({options:{},initialize:function(mapWindow,mapObject){this.mapWindow=mapWindow;
this.mapObject=mapObject;
this.isbirdsEye=false;
this.hasHybrid=false;
this.hasBirdsEyeHybrid=false;
this.mapStyles={shaded:"Shaded",road:"Road",hybrid:"Hybrid",aerial:"Aerial",birdseyeHybrid:"BirdseyeHybrid",birdseye:"Birdseye"};
var iframe=$(mapWindow.document.body);
$("dashboard").removeClass("hide").setStyle("visibility","visible");
$("dashboard").style.display="block";
$$("#compassCard, #mapSliderBox").setStyle("position","relative");
$$("#compassCard, #mapSliderBox").setStyle("position","absolute");
this.addSlider();
this.addSearch();
this.addlayerButtons();
mapObject.AttachEvent("onendzoom",this.zoomStepEvent.bind(this));
mapObject.SetMouseWheelZoomToCenter(false);
mapObject.SetMapStyle(this.currentMapStyle);
this.toggleMapType({mapStyle:this.currentMapStyle});
this.zoomStepEvent()
},tokenErrorHandler:function(event){alert("token error: "+event)
},tokenExpireHandler:function(event){alert("token expired: "+event)
},addMinimap:function(){this.mapObject.ShowMiniMap($(this.mapObject.mapelement).getSize().x-150,0,this.mapWindow.getVEMiniMapSize("Small"));
$(this.mapWindow.document.getElementById("MSVE_minimap_resize")).addEvent("click",this.toggleMiniMap.bind(this));
this.minimap=$(this.mapWindow.document.getElementById("MSVE_minimap"));
this.minimapStatus=true;
this.toggleMiniMap()
},addSlider:function(){this.slider=new Slider($("mapSlider"),$("mapSliderKnob"),{steps:18,mode:"vertical",offset:0,initialStep:null,onComplete:this.doZoomStep.bind(this)});
$("zoomout").addEvent("click",this.zoom.bind(this,-1));
$("zoomin").addEvent("click",this.zoom.bind(this,1))
},addSearch:function(){var fieldset=$("searchMap");
if(fieldset){fieldset.getElement("span.button").addEvent("click",this.search.bind(this));
var input=fieldset.getElement("input");
input.addEvents({keydown:function(e){this.keydownSearch(e)
}.bind(this)});
var i=new InputInitalValue([input])
}},addlayerButtons:function(){this.currentMapStyle=this.mapStyles.shaded;
var mapStyleList=$("mapStyle");
this.mapStyleButtons={};
this.mapStyleButtons[this.mapStyles.shaded]=mapStyleList.getElement("li.shaded").toggleClass("highlight").addEvent("click",this.toggleMapType.bind(this,{mapStyle:this.mapStyles.shaded}));
this.mapStyleButtons[this.mapStyles.aerial]=mapStyleList.getElement("li.aerial");
var hybridCheckBox=this.mapStyleButtons[this.mapStyles.aerial].getElement("label");
this.mapStyleButtons[this.mapStyles.aerial].addEvents({click:this.toggleMapType.bind(this,{mapStyle:this.mapStyles.aerial}),mouseenter:function(e){this.showHybridCheckbox(hybridCheckBox,true)
}.bind(this),mouseleave:function(e){this.showHybridCheckbox(hybridCheckBox,false)
}.bind(this)});
this.currentMapStyleButton=this.mapStyleButtons[this.mapStyles.shaded];
$("compassCard").addEvents({mousedown:this.panTo.bind(this),mouseup:this.panEnd.bind(this)});
$$("#showHybrid, #showBirdsEyeHybrid").addEvent("click",function(e){this.toggleHybrid(e)
}.bind(this))
},addBirdseyeOrientation:function(){$$("#birdseyeOrientation li").each(function(li){li.getElement("span.button").addEvent("click",this.toggleBirdsEyeOrientation.pass(li.id,this))
},this)
},toggleMiniMap:function(){this.minimap[(this.minimapStatus?"remove":"add")+"Class"]("toggle");
this.minimapStatus=!this.minimapStatus
},zoomStepEvent:function(){this.slider.set((this.isbirdsEye?2:19)-this.mapObject.GetZoomLevel())
},zoom:function(value){this.doZoomStep((this.isbirdsEye?2:19)-this.mapObject.GetZoomLevel()-value)
},doZoomStep:function(zoomLevel){zoomLevel=(this.isbirdsEye?2:19)-zoomLevel;
if(zoomLevel!=null&&zoomLevel!=this.mapObject.GetZoomLevel()){if(zoomLevel<=(this.isbirdsEye?2:19)){this.mapObject.SetZoomLevel(zoomLevel)
}}},panTo:function(event){var speed=50;
switch(new Event(event).target.id){case"downRight":var x=-speed,y=-speed;
break;
case"down":var x=0,y=-speed;
break;
case"downLeft":var x=speed,y=-speed;
break;
case"right":var x=-speed,y=0;
break;
case"left":var x=speed,y=0;
break;
case"upRight":var x=-speed,y=speed;
break;
case"up":var x=0,y=speed;
break;
case"upLeft":var x=speed,y=speed;
break
}if(x||y){this.mapObject.StartContinuousPan(x,y)
}},panEnd:function(){this.mapObject.EndContinuousPan()
},toggleMapType:function(event){if(event){var mapStyle=event.mapStyle
}if(mapStyle===this.mapStyles.hybrid){mapStyle=this.mapStyles.aerial
}this.currentMapStyleButton.removeClass("highlight");
this.currentMapStyleButton=this.mapStyleButtons[mapStyle].addClass("highlight");
if(mapStyle===this.mapStyles.aerial&&this.hasHybrid){mapStyle=this.mapStyles.hybrid
}if(mapStyle){this.mapObject.SetMapStyle(mapStyle);
this.currentMapStyle=mapStyle
}var currentMapStyle=this.mapObject.GetMapStyle();
this.isbirdsEye=currentMapStyle===this.mapStyles.birdseye||currentMapStyle===this.mapStyles.birdseyeHybrid
},showHybridCheckbox:function(checkbox,isShow){if(!checkbox.getParent().hasClass("disabled")){checkbox.style.display=isShow?"block":"none"
}},toggleHybrid:function(event){var target=$(event.target),isAerial=target.getParent().getParent().hasClass("aerial");
this[isAerial?"hasHybrid":"hasBirdsEyeHybrid"]=target.checked;
this.toggleMapType({mapStyle:this.mapStyles[isAerial?(target.checked?"hybrid":"aerial"):(target.checked?"birdseyeHybrid":"birdseye")]})
},toggleBirdseye:function(){$("birdseyeOrientation")[(this.isbirdsEye?"remove":"add")+"Class"]("hide");
this.mapStyleButtons[this.mapStyles.birdseye][(this.mapObject.IsBirdseyeAvailable()?"remove":"add")+"Class"]("disabled");
this.slider.element[(this.isbirdsEye?"add":"remove")+"Class"]("birdseye");
this.slider.options.steps=this.isbirdsEye?1:19
},toggleBirdsEyeOrientation:function(id){this.mapObject.SetBirdseyeOrientation(this.mapWindow.getVEOrientation(id.capitalize()));
$$("#birdseyeOrientation li").each(function(li){li[(li.id===id?"add":"remove")+"Class"]("active")
})
},keydownSearch:function(event){var event=new Event(event);
if(event.key==="enter"){event.preventDefault();
this.search()
}},search:function(){if(this.mapObject.extTileLayer){this.mapObject.extTileLayer.resetTileLayerSwitch()
}var searchTxt=$("HRS_SEARCHBOX").value;
if(this.mapObject.GetMapStyle()===this.mapStyles.birdseye){this.toggleMapType({mapStyle:this.mapStyles.shaded})
}var geoCoder=HRSMaps.newGClientGeocoder();
geoCoder.getLocations(searchTxt,this.geoCodeSearchLocationHandler)
},geoCodeSearchLocationHandler:function(locations){var mapObj=parent.map.veMap;
if(locations){if(this.searchPushpin){this.searchPushpin=null
}if(locations.Placemark){var place=locations.Placemark[0];
if(mapObj.iframe){this.searchPushpin=mapObj.iframe.getVEShape(place.Point.coordinates[1],place.Point.coordinates[0]);
mapObj.hrsMap.adapterSetCenter(mapObj.iframe.getVELatLong(place.Point.coordinates[1],place.Point.coordinates[0]))
}else{this.searchPushpin=getVEShape(place.Point.coordinates[1],place.Point.coordinates[0]);
mapObj.hrsMap.adapterSetCenter(getVELatLong(place.Point.coordinates[1],place.Point.coordinates[0]))
}var laLoSW=HRSMaps.newGLatLng(place.ExtendedData.LatLonBox.south,place.ExtendedData.LatLonBox.west);
var laLoNE=HRSMaps.newGLatLng(place.ExtendedData.LatLonBox.north,place.ExtendedData.LatLonBox.east);
var bounds=HRSMaps.newGLatLngBounds(laLoSW,laLoNE);
var zoomLevel=mapObj.hrsMap.adapterGetBoundsZoomLevel(bounds);
mapObj.hrsMap.adapterSetZoom(zoomLevel);
mapObj.AddShapeLayer(1);
mapObj.AddShape(this.searchPushpin);
this.searchPushpin.SetTitle(locations.Placemark[0].address);
this.searchPushpin.SetDescription("<h1></h1>");
this.searchPushpin.SetCustomIcon('<div class="pushPin searchCenter"> </div>');
mapObj.HideInfoBox();
if(mapObj.iframe){parent.map.renderPushpins()
}}else{var reasons=[];
reasons[G_GEO_SUCCESS]="Success";
reasons[G_GEO_MISSING_ADDRESS]="Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS]="Unknown Address:  No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]="Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY]="Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES]="Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR]="Server error: The geocoding request could not be successfully processed.";
var reason="Code "+locations.Status.code;
if(reasons[locations.Status.code]){reason=reasons[locations.Status.code]
}alert('Could not find "'+locations.name+'". '+reason)
}}},moreResults:function(layer,resultsArray,places,hasMore,veErrorMessage){if(!this.searchlayer){this.searchlayer=this.mapWindow.getVEShapeLayer();
this.mapObject.AddShapeLayer(this.searchlayer)
}if(places!=null&&places.length>0){if(this.searchPushpin){this.mapObject.DeleteShape(this.searchPushpin);
this.searchPushpin=null
}var latLong=places[0].LatLong;
this.searchPushpin=this.mapWindow.getVEShape(latLong.Latitude,latLong.Longitude);
this.searchPushpin.SetTitle(places[0].Name);
this.searchPushpin.SetCustomIcon('<div class="pushPin searchCenter"> </div>');
this.searchlayer.DeleteAllShapes();
this.searchlayer.AddShape(this.searchPushpin)
}else{this.mapObject.ShowMessage(veErrorMessage)
}}});
var MWSLayer=new Class({options:{layers:{railroadTransportation:{name:"SICMaj40"},waterTransportation:{name:"SICMaj44"},busStation:{name:"SIC4170"},airport:{name:"SIC4581"},golf:{name:"SIC7992"},parkRecreationArea:{name:"SIC7947"},touristAttraction:{name:"SIC7999"},hospital:{name:"SICInd806"},museum:{name:"SIC8410"},fun:{name:"SIC7996"},sportsComplex:{name:"SIC7940"},restaurants:{name:"SIC5800"}},hasInit:false},initialize:function(mapWindow,mapObject){this.mapWindow=mapWindow;
this.mapObject=mapObject;
this.defaultRadius=400;
mapObject.mwsLayer=this;
$("poiToggler").addEvent("click",this.togglePoiLayer)
},init:function(){for(var key in this.options.layers){var input=$(key),layer=this.options.layers[key];
if(input){layer.shapeLayer=this.mapWindow.getVEShapeLayer();
layer.shapeLayer.Hide();
input.addEvent("click",function(e){this.getMWSData(e)
}.bind(this))
}}},calculateRadius:function(){var view=this.mapObject.GetMapView();
var topLeft=this.mapWindow.getVELatLong(view.TopLeftLatLong.Latitude,view.TopLeftLatLong.Longitude);
var bottomLeft=this.mapWindow.getVELatLong(view.BottomRightLatLong.Latitude,view.TopLeftLatLong.Longitude);
var radius=Math.round(getDistance(topLeft,bottomLeft)/2);
if(radius>this.defaultRadius){radius=this.defaultRadius
}return radius
},refreshLayer:function(){for(key in map.mwsLayer.options.layers){var layer=map.mwsLayer.options.layers[key];
if(layer.isOnMap){var latlon=this.mapObject.GetCenter();
DynamicMap.getDataFromMWS(latlon.Latitude,latlon.Longitude,this.calculateRadius(),layer.name,"map.mwsLayer.options.layers['"+key+"']",function(jsResult){if(jsResult!=null){eval(jsResult.result)
}})
}}},getMWSData:function(event){var target=event.target,key=target.id,load=target.checked;
layer=this.options.layers[key];
if(layer){if(load){if(!layer.isOnMap){var latlon=this.mapObject.GetCenter();
var isIframe=(window.iframeMap||parent.iframeMap)?true:false;
DynamicMap.getDataFromMWS(latlon.Latitude,latlon.Longitude,this.calculateRadius(),layer.name,"map.mwsLayer.options.layers['"+key+"']",isIframe,function(jsResult){if(jsResult!=null){eval(jsResult.result)
}})
}if(layer.shapeLayer){layer.shapeLayer.Show()
}}else{this.mapObject.DeleteShapeLayer(layer.shapeLayer);
this.options.layers[key].shapeLayer=this.mapWindow.getVEShapeLayer()
}layer.isOnMap=load
}},reinitMWSLayer:function(){this.options.layers.each(function(item){var layer=item.shapeLayer;
layer.DeleteAllShapes();
this.mapObject.DeleteShapeLayer(layer);
layer=this.mapWindow.getVEShapeLayer()
})
},resetIsOnMap:function(){for(var key in this.options.layers){this.options.layers[key].isOnMap=false
}},enableCheckBoxes:function(enable){for(var key in this.options.layers){var input=$(key);
if(input){if(!enable){input.checked=enable
}input.disabled=!enable
}}},togglePoiLayer:function(){var lis=$$("#routingMask, #pois");
lis[lis.length-1].toggleClass("show");
if(lis.length>1){lis[0].removeClass("show");
lis[0].getElement("h5 strong").removeClass("open")
}this.getElement("strong").toggleClass("open")
}});
function getDistance(p1,p2){var p1Lat=latLonToRadians(p1.Latitude);
var p1Lon=latLonToRadians(p1.Longitude);
var p2Lat=latLonToRadians(p2.Latitude);
var p2Lon=latLonToRadians(p2.Longitude);
var R=6371;
var dLat=p2Lat-p1Lat;
var dLong=p2Lon-p1Lon;
var a=Math.sin(dLat/2)*Math.sin(dLat/2)+Math.cos(p1Lat)*Math.cos(p2Lat)*Math.sin(dLong/2)*Math.sin(dLong/2);
var c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));
return(R*c)
}function latLonToRadians(point){return point*Math.PI/180
}var InputInitalValue=new Class({initialize:function(inputs){inputs.each(function(input){var initialValue=input.value;
input.addEvent("focus",this.toggle.bind(input,initialValue,true)).addEvent("blur",this.toggle.bind(input,initialValue,false)).setStyle("color","#808080")
},this)
},toggle:function(initialValue,isFocus){if(typeof arguments[0]=="object"){var intVal=arguments[0][0],isFoc=arguments[0][1]
}else{var intVal=initialValue,isFoc=isFocus
}if(this.value===""||this.value===intVal){this.setStyle("color",isFoc?"":"#808080").value=isFoc?"":intVal
}}});
var Routing=new Class({Implements:Options,options:{start:"",end:"",minutes:"",hours:"",totalRange:""},initialize:function(mapWindow,mapObject,routingPopupUrl,options){this.mapWindow=mapWindow;
this.mapObject=mapObject;
this.routingPopupUrl=routingPopupUrl;
this.setOptions(options);
mapObject.routing=this;
$("routingButton").addEvent("click",function(e){this.initRouting(e)
}.bind(this));
$("routingToggler").addEvent("click",this.togglerRoutingLayer);
$("routingStartAddress").addEvent("keypress",function(e){this.remFreeRoutingPoint(e,"start")
}.bind(this));
$("routingEndAddress").addEvent("keypress",function(e){this.remFreeRoutingPoint(e,"end")
}.bind(this));
mapObject.hrsMap.adapterGetGoogleEvent(mapWindow,"singlerightclick",this.clickToRouting.bind(this))
},init:function(){this.routingAddress={start:null,end:null};
this.freeRoutingPoints={start:null,end:null};
this.evaluateLocation={start:function(locations){if(!locations||locations.Status.code!=200){alert("Error Status Code:"+locations.Status.code);
return
}else{map.routing.setRoutingAddress((locations!=null?locations.Placemark[0].address:map.routing.options.start),"start")
}},end:function(locations){if(!locations||locations.Status.code!=200){alert("Error Status Code:"+locations.Status.code);
return
}else{map.routing.setRoutingAddress((locations!=null?locations.Placemark[0].address:map.routing.options.end),"end")
}}}
},initRouting:function(event){if($("routingStartAddress").value!=""&&$("routingEndAddress").value!=""){this.closeRoutingPopup();
if(event&&event.type=="click"){var target=event.target;
if(target.form.id=="jsContentForm"){function test(e){new Event(e).stop();
this.removeEvent("submit",test)
}$("jsContentForm").addEvent("submit",test)
}}HRSMaps.routing=this;
this.routeSrcName=$("routingStartAddress").value;
this.routeDstName=$("routingEndAddress").value;
this.routeSrc=this.freeRoutingPoints.start?this.freeRoutingPoints.start.toUrlValue():this.routeSrcName;
this.routeDst=this.freeRoutingPoints.end?this.freeRoutingPoints.end.toUrlValue():this.routeDstName;
HRSMaps._hrsMap.showRoutePlacePlace(this.routeSrc,this.routeDst);
this.routingPopup=window.open(this.routingPopupUrl,"routing","width=425,height=550,left=50,top=0,scrollbars=yes,menubar=yes, resize=yes")
}},swapRoutingAddresses:function(){var swapHelper;
var routingStartAddress=$("routingStartAddress");
var routingEndAddress=$("routingEndAddress");
var freeRoutingPoints=this.freeRoutingPoints;
swapHelper=routingStartAddress.value;
routingStartAddress.value=routingEndAddress.value;
routingEndAddress.value=swapHelper;
swapHelper=freeRoutingPoints.start;
freeRoutingPoints.start=freeRoutingPoints.end;
freeRoutingPoints.end=swapHelper;
this.initRouting()
},openRoutingPopup:function(){if(this.routingPopup){if($(this.routingPopup.document.getElementById("routing_address_switch"))){this.initializePopup()
}else{if(Browser.ie){this.routingPopup.attachEvent("onload",this.initializePopup.bind(this));
this.routingPopup.attachEvent("onunload",this.clearRoutingPopup.bind(this))
}else{this.routingPopup.addEventListener("load",this.initializePopup.bind(this),false)
}}}},createRoutePointShapes:function(veLatLon,title,description,icon){var shape=this.mapWindow.getVEShape(veLatLon.Latitude,veLatLon.Longitude);
shape.SetTitle(""+title);
shape.SetDescription(description);
shape.SetCustomIcon(icon);
this.veRoutingLayer.AddShape(shape)
},routingWarning:function(alertMessage){},evaluateRoute:function(veRoute){map.routing.toggleRouteWaiting(false);
if(veRoute&&veRoute.RouteLegs&&veRoute.RouteLegs.length!=0){map.routing.getRoutingGeometries(veRoute)
}else{map.routing.closeRoutingPopup()
}},switchRoutingAddresses:function(){this.routingAddress={start:this.routingAddress.end,end:this.routingAddress.start};
this.freeRoutingPoints={start:this.freeRoutingPoints.end,end:this.freeRoutingPoints.start};
this.setRoutingAddress(this.routingAddress.start,"start",this.freeRoutingPoints?this.freeRoutingPoints.start:null);
this.setRoutingAddress(this.routingAddress.end,"end",this.freeRoutingPoints?this.freeRoutingPoints.end:null);
this.initRouting()
},setRoutingAddress:function(address,startEnd,point){this.routingAddress[startEnd]=address;
$("routing"+startEnd.capitalize()+"Address").value=this.routingAddress[startEnd];
if(point){if(!this.freeRoutingPoints){this.freeRoutingPoints={}
}this.freeRoutingPoints[startEnd]=point
}this.showRoutingLayer()
},clickToRouting:function(point,src,overlay){if(point){if(!this.routingLayer){this.initFreeRouting(point,src,overlay)
}this.routingLayer.removeClass("hide").setStyles({top:Math.min(point.y,this.layerMaxPosition.top),left:Math.min(point.x,this.layerMaxPosition.left)});
this.freeRoutingPoint=this.mapObject.PixelToLatLong(this.mapWindow.getVEPixel(point.x,point.y))
}else{if(this.routingLayer){this.routingLayer.addClass("hide")
}}},setFreeRoutingPoint:function(event,startEnd){this.routingLayer.addClass("hide");
this.freeRoutingPoints[startEnd]=this.freeRoutingPoint;
var geoCoder=HRSMaps.newGClientGeocoder();
geoCoder.getLocations(this.freeRoutingPoint,this.evaluateLocation[startEnd])
},remFreeRoutingPoint:function(event,startEnd){event=new Event(event);
var target=event.target;
if(event.key=="enter"){event.stop();
if(target.form.id=="jsContentForm"){function test(e){new Event(e).stop();
this.removeEvent("submit",test)
}event.target.form.addEvent("submit",test)
}this.initRouting(event)
}map.routing.freeRoutingPoints[startEnd]=null
},initFreeRouting:function(point,src,overlay){this.mapObject.AddShapeLayer(1);
this.routingLayer=$(this.mapWindow.document.getElementById("routeStartEnd")).dispose().inject(this.mapObject.hrsMap._div,"inside");
this.routingLayer.getElements("a").each(function(a,cnt){a.addEvent("click",function(e){this.setFreeRoutingPoint(e,cnt?"end":"start")
}.bind(this))
},this);
this.routingLayer.setStyle("visibility","hidden").removeClass("hide");
var layerSize=this.routingLayer.getSize(),mapSize=$(this.mapObject.hrsMap._div).getSize();
this.routingLayer.setStyle("visibility","visible").addClass("hide");
this.layerMaxPosition={top:mapSize.y-layerSize.y,left:mapSize.x-layerSize.x}
},initializePopup:function(){$(this.routingPopup.document.getElementById("routing_address_switch")).addEvent("click",this.switchRoutingAddresses.bind(this));
map.routing.writeRoutingDetails()
},closeRoutingPopup:function(){if(this.routingPopup){this.routingPopup.close()
}},clearRoutingPopup:function(){this.routingPopup=null
},writeRoutingDetails:function(){var doc=map.routing.routingPopup.document;
doc.getElementById("routingStartAddress").innerHTML=this.routingAddress.start;
doc.getElementById("routingEndAddress").innerHTML=this.routingAddress.end
},toggleRouteWaiting:function(onOff){$("routingMask").setStyle("opacity",onOff?0.8:1)
},showRoutingLayer:function(){var lis=$$("#routingMask, #pois");
lis[0].addClass("show");
lis[0].getElement("strong").toggleClass("open")
},togglerRoutingLayer:function(){var lis=$$("#routingMask, #pois");
lis[0].toggleClass("show");
this.getElement("strong").toggleClass("open")
},startRouting:function(){},wait:function(millis){var date=new Date();
var curDate=null;
do{curDate=new Date()
}while(curDate-date<millis)
},stopFormSubmit:function(event){},getRoutingGeometries:function(veRoute){if(!this.veRoutingLayer){this.veRoutingLayer=this.mapWindow.getVEShapeLayer();
map.veMap.AddShapeLayer(this.veRoutingLayer)
}else{this.veRoutingLayer.DeleteAllShapes()
}if(this.routingLayer){this.freeRoutingShapes.start.Hide();
this.freeRoutingShapes.end.Hide()
}this.routingDetails={routingAddress:this.routingAddress};
var waypointIconDistance=31;
var waypoints=new Array();
for(i=0,l=veRoute.RouteLegs.length;
i<l;
i++){var routeLegs=veRoute.RouteLegs[i].Itinerary.Items;
for(var j=0,m=routeLegs.length;
j<m;
j++){var item=routeLegs[j];
this.routingDetails.routingDirections[j]={num:j+1,description:item.Text,latitude:item.LatLong.Latitude,longitude:item.LatLong.Longitude,distance:item.Distance.toFixed(1)};
waypoints[j]=item.LatLong.Latitude+","+item.LatLong.Longitude;
this.createRoutePointShapes(item.LatLong,this.routingDetails.routingDirections[j].num,item.Text,'<div class="waypoint" style="background-position:0 -'+(j*waypointIconDistance)+'px"></div>')
}}var points=veRoute.ShapePoints;
var routeShape=null;
if(Browser.ie6||Browser.ie7){var i=0;
var partSize=5000;
var partStart=(i)*partSize;
var partEnd=partStart+partSize;
this.pointsPart=new Array();
this.generateRoute=new Array();
var j=0;
while(partEnd!=points.length-1){partStart=(i)*partSize;
partEnd=partStart+partSize;
if(partEnd>points.length){partEnd=points.length-1;
this.pointsPart[i]=points.slice(partStart)
}else{this.pointsPart[i]=points.slice(partStart,partEnd)
}this.generateRoute[i]=function(){var routeShape=map.routing.mapWindow.getVEShapePolyline(map.routing.pointsPart[j]);
routeShape.SetLineColor(map.routing.mapWindow.getVEColor(50,220,250,0.7));
routeShape.SetLineWidth(3);
routeShape.HideIcon();
routeShape.SetTitle("Route");
routeShape.SetDescription("Route");
map.routing.veRoutingLayer.AddShape(routeShape);
j++
};
i++
}this.generateRoute.each(function(item){item.delay(100)
},this)
}else{routeShape=this.mapWindow.getVEShapePolyline(points);
routeShape.SetLineColor(this.mapWindow.getVEColor(50,220,250,0.7));
routeShape.SetLineWidth(3);
routeShape.HideIcon();
routeShape.SetTitle("Route");
routeShape.SetDescription("Route");
this.veRoutingLayer.AddShape(routeShape)
}this.createRoutePointShapes(points[0],this.options.start,this.routingAddress.start,'<div  class="startRoute"></div>');
this.createRoutePointShapes(points[points.length-1],this.options.end,this.routingAddress.end,'<div  class="endRoute"></div>');
var boundingRectangle=this.veRoutingLayer.GetBoundingRectangle();
map.veMap.SetMapView(boundingRectangle);
var mapRouting={routingMapZoom:map.veMap.GetZoomLevel(),routingMapCenterLat:map.veMap.GetCenter().Latitude,routingMapCenterLon:map.veMap.GetCenter().Longitude,routingShapes:points.join(";"),routingWaypoints:waypoints.join(";"),routingWaypointIconDistance:waypointIconDistance,routingMapNorthWestLat:boundingRectangle.TopLeftLatLong.Latitude,routingMapNorthWestLon:boundingRectangle.TopLeftLatLong.Longitude,routingMapSouthEastLat:boundingRectangle.BottomRightLatLong.Latitude,routingMapSouthEastLon:boundingRectangle.BottomRightLatLong.Longitude};
var pixel=map.veMap.LatLongToPixel(points[0]);
if(pixel.x<30||pixel.y<30){map.veMap.SetZoomLevel(map.veMap.GetZoomLevel()-1)
}DynamicMap.setMapRouting(mapRouting,function(data){map.routing.openRoutingPopup()
})
}});
var BingMapsExtTileLayer=new Class({initialize:function(mapWindow,mapObject,chinaFlag,dituZoomLevel){return
},getMMBounds:function(){var bounds=new Array();
bounds.push(this.mapWindow.getVELatLongRectangle(47.754097979680026,66.44531249999999,-9.102096738726443,135.35156250000003));
bounds.push(this.mapWindow.getVELatLongRectangle(31.728167146023935,34.18945312500001,14.008696370634683,60.62304687500001));
bounds.push(this.mapWindow.getVELatLongRectangle(63.97596090918337,38.583984375000014,47.754097979680026,177.5390625));
bounds.push(this.mapWindow.getVELatLongRectangle(60.630101766266684,28.388671874999993,56.80087831233044,38.583984375000014));
bounds.push(this.mapWindow.getVELatLongRectangle(56.80087831233044,31.376953125000018,52.26815737376816,38.583984375000014));
bounds.push(this.mapWindow.getVELatLongRectangle(47.754097979680026,38.056640625,43.06888777416962,50.296875));
bounds.push(this.mapWindow.getVELatLongRectangle(41.9022770409637,26.455078125000014,36.24427318493909,45.00000000000001));
return bounds
},getDituBounds:function(){var bounds=new Array();
bounds.push(this.mapWindow.getVELatLongRectangle(42.811,77.343,26.588,126.683));
bounds.push(this.mapWindow.getVELatLongRectangle(26.588,96.503,20.632,126.683));
bounds.push(this.mapWindow.getVELatLongRectangle(53.8,110.17,42.811,135.087));
bounds.push(this.mapWindow.getVELatLongRectangle(42.811,126.683,40.713,132.209));
bounds.push(this.mapWindow.getVELatLongRectangle(50.064,78.925,42.811,97.822));
bounds.push(this.mapWindow.getVELatLongRectangle(41.508,73.212,35.029,77.343));
bounds.push(this.mapWindow.getVELatLongRectangle(20.632,106.083,17.978,114.96));
return bounds
},createTileLayerSwitch:function(id,bounds,callbackFnt,zIndex){var tileSourceSpec=this.mapWindow.getVETileSourceSpecification(id,"",1,bounds,1,17,callbackFnt,1,zIndex);
this.mapObject.AddTileLayer(tileSourceSpec,true)
},onChangeView:function(e){this.mapObject.vemapcontrol.RefreshTileLayers();
if(this.dituBoxesInView){this.dituBoxesInView=false
}else{if(this.dituLayerEnabled){this.hideLayer(this.dituSwitchId)
}else{if(this.mmBoxesInView){this.mmBoxesInView=false
}else{if(this.mmLayer!=null){this.hideLayer(this.mmSwitchId)
}}}}},onChangeMapStyle:function(e){if(this.mmLayer==null&&!this.dituLayerEnabled&&this.mapObject.GetMapStyle()==this.mmSwitchedMapStyle){this.mapObject.ShowBaseTileLayer();
this.mmSwitchedMapStyle=null
}if(this.dituLayerEnabled&&this.mapObject.GetMapStyle()!=this.mapWindow.getVEMapStyle("Road")&&this.mapObject.GetMapStyle()!=this.mapWindow.getVEMapStyle("Shaded")){this.hideLayer(this.dituSwitchId)
}},showLayer:function(id){if(id==this.dituSwitchId){this.hideLayer(this.mmSwitchId);
this.showDituLayer()
}else{if(id==this.mmSwitchId){if(this.dituLayerEnabled){return
}this.showMMLayer()
}}this.mmSwitchedMapStyle=this.mapObject.GetMapStyle();
this.mapObject.HideBaseTileLayer();
this.mapObject.AttachEvent("onchangeview",this.onChangeViewHandler)
},hideLayer:function(id){if(id==this.mmSwitchId){if(this.mmLayer!=null){this.hideMMLayer()
}}else{if(id==this.dituSwitchId){if(this.dituLayerEnabled){this.hideDituLayer()
}}}if(!this.dituLayerEnabled&&this.mmLayer==null){this.mapObject.DetachEvent("onchangeview",this.onChangeViewHandler);
this.mapObject.ShowBaseTileLayer()
}},showMMLayer:function(){this.mmLayer=this.mapWindow.getMMMapFactory(this.mapObject);
this.mmLayer.draw();
this.mmLayer.addEventHandler("coverageUpdated",this.coverageUpdatedHandler.bind(this));
this.mapWindow.setMMDataPreferences(this.mapObject.GetMapStyle(),this.mapWindow.getMMDataPreferences(this.mapObject.GetMapStyle()));
this.mmLayer.redraw()
},showDituLayer:function(){this.dituLayerEnabled=true;
var tilesource="http://r%2.tiles.ditu.live.com/tiles/r%4.png?g=41";
var tileSourceSpecDitu=this.mapWindow.getVETileSourceSpecification(this.dituId,tilesource,3,null,this.dituZoomLevel,17,null,1,1);
this.mapObject.AddTileLayer(tileSourceSpecDitu,true)
},layerInitialised:function(layerId){return(this.mapObject.m_vetilesourcemanager.GetSourceById(layerId)!=null)
},hideMMLayer:function(){if(this.mmLayer!=null&&typeof this.mmLayer.mmkm!="undefined"&&this.mmLayer.mmkm!=null&&this.layerInitialised(this.mmLayer.mmkm)){this.mmLayer.dispose();
this.mmLayer=null;
this.removeMMcopy()
}else{setTimeout(this.hideMMLayer.bind(this.mapObject.extTileLayer),1000)
}},hideDituLayer:function(){this.mapObject.DeleteTileLayer(this.dituId);
this.dituLayerEnabled=false;
this.mapObject.vemapcontrol.RefreshTileLayers()
},removeMMcopy:function(){var divs=this.mapWindow.document.getElementsByTagName("div");
for(var i=divs.length-1;
i>=0;
i--){div=divs[i];
var s=div.innerHTML.substring(30,0);
if(s.search(/NAVTEQ|MapABC|Loading copyright data|Map Data|Infomap/)>=0){div.parentNode.removeChild(div);
break
}}},coverageUpdatedHandler:function(){var center=this.mapObject.GetCenter();
var zoomLevel=this.mapObject.GetZoomLevel();
var mapStyle=this.mapObject.GetMapStyle();
var coverage=this.mapWindow.getMMCoverage(center,zoomLevel,mapStyle);
if(coverage=="undefined"){this.hideLayer(this.mmSwitchId)
}},switchMMLayerByTileLoad:function(tileContext){if(this.checkTileLayer(this.mmSwitchId,tileContext)){this.mmBoxesInView=true;
if(this.mmLayer!=null&&tileContext.ZoomLevel<this.mmZoomLevel){this.hideLayer(this.mmSwitchId)
}else{if(this.mmLayer==null&&tileContext.ZoomLevel>=this.mmZoomLevel){this.showLayer(this.mmSwitchId)
}}}return this.blankImgPath
},switchDituLayerByTileLoad:function(tileContext){if(this.checkTileLayer(this.dituSwitchId,tileContext)){this.dituBoxesInView=true;
if(this.dituLayerEnabled!=false&&tileContext.ZoomLevel<this.dituZoomLevel){this.hideLayer(this.dituSwitchId)
}else{if(this.dituLayerEnabled==false&&tileContext.ZoomLevel>=this.dituZoomLevel){this.showLayer(this.dituSwitchId)
}}}return this.blankImgPath
},checkTileLayer:function(id,tileContext){if(id==this.mmSwitchId){if(this.dituLayerEnabled&&this.dituBoxesInView){return false
}}else{if(id==this.dituSwitchId){if(!this.chinaFlag){return false
}else{if((this.mapObject.GetMapStyle()!=this.mapWindow.getVEMapStyle("Road"))&&(this.mapObject.GetMapStyle()!=this.mapWindow.getVEMapStyle("Shaded"))){return false
}}}}return true
},resetTileLayerSwitch:function(){this.mmBoxesInView=false;
this.dituBoxesInView=false
},showTileLayerBoxes:function(boxes){this.boxLayer=this.mapWindow.getVEShapeLayer();
this.boxLayer.ZIndex=1001;
this.mapObject.AddShapeLayer(this.boxLayer);
var color=this.mapWindow.getVEColor(parseInt(Math.random()*100),parseInt(Math.random()*100),parseInt(Math.random()*100),0.5);
for(i=0;
i<boxes.length;
i++){var rec=boxes[i];
var topRightLatLong=this.mapWindow.getVELatLong(rec.TopLeftLatLong.Latitude,rec.BottomRightLatLong.Longitude);
var bottomLeftLatLon=this.mapWindow.getVELatLong(rec.BottomRightLatLong.Latitude,rec.TopLeftLatLong.Longitude);
var shape=this.mapWindow.getVEShapePolygon(new Array(rec.TopLeftLatLong,topRightLatLong,rec.BottomRightLatLong,bottomLeftLatLon));
shape.HideIcon();
shape.SetLineWidth(1);
shape.SetLineColor(color);
shape.SetFillColor(color);
shape.SetZIndex(1001);
this.boxLayer.AddShape(shape)
}}});
