function MasternautMap(){var _mapContainer=null;var _popupContainer=null;var _map=null;var _mapEvents=[];var _isBE=false;var _is3D=false;var _newContact=null;var _nearestContact=false;var _nearestVehicle=false;var _divNearestVehicle=null;var _filterNearestVehicle=null;var _divTags=null;var _divTagHistory=null;var _loactionVicinity=false;var _divLocationVicinity=null;var _multipleJourney=null;var self=this;this.SeeContactCategory=-1;var _initDone=false;var _simulationStarted=false;this.Journey=null;var _locator=null;var _locatorRefreshId=null;var _locatorShowing=false;var _locatorFilter={groupMCUCode:[0],mcuCode:0,groupDriverCode:[0],driverCode:0};var _locatorClustered=false;var _locatorWithAddress=false;var _locatorWithPrivate=false;var _trackModeEnabled=false;var _showTraffic={getRoadCondition:false,getDelays:false};var _jobRefreshId=null;var _showJob=false;var _jobXml=null;var _jobCurrentEngineer=0;var _jobCurrentMCU=0;var _alertRefreshId=null;var _showAlert=false;var _alertXml=null;var _trafficXml=null;var _trafficTimerId=null;var _trafficCamDisplayed=false;var _poiTypeToDisplay=-1;var _hgvRestrictionTypeToDisplay=-1;var _location=null;var _familyLoc=null;var _routeGeofence=null;var _territory=null;this.LbsPushpin=null;var _vehicleCaption="none";var _contactCaption="none";var _contactMaxResult=null;var _jobCaption="none";var _alertCaption="none";this.SetContainers=function(mapContainer,popupContainer){_mapContainer=mapContainer;_popupContainer=popupContainer;initMap()};this.GetContainer=function(){return _popupContainer};this.AttachEvent=function(name,evt){if(_mapEvents[name]==null){_mapEvents[name]=[]}_mapEvents[name].push(evt)};function runMapEvent(name){if(_mapEvents[name]!=undefined){for(var i=0;i<_mapEvents[name].length;i++){_mapEvents[name][i](arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8])}}}this.DetachEvent=function(name,evt){for(var i=0;i<_mapEvents[name].length;i++){if(_mapEvents[name][i]==evt){_mapEvents[name].splice(i,1);i--}}};function initMap(){if(_initDone){return }if(typeof (VEMap)!="function"){_mapContainer.innerHTML="<br><h2>"+lang["map.err.open"]+"<br><br><a style='text-decoration:underline' href='https://www.masternaut.co.uk/common/pdf/Virtual Earth Configuration.pdf'>"+lang["map.err.openL"]+"</a>";return }_map=new VEMap(_mapContainer.id);var defaultView=readCookie("defaultMapView");if(defaultView==null){switch(_defaultCountry){case"IR":_map.LoadMap(new VELatLong(53.5,-7.7),6,"s",false);break;case"AU":_map.LoadMap(new VELatLong(-25.7,132),4,"s",false);break;case"NZ":_map.LoadMap(new VELatLong(-41,174),5,"s",false);break;default:_map.LoadMap(new VELatLong(54.5,-4),5,"s",false);break}}else{defaultView=eval("["+defaultView+"]")[0];if(getParameter("mcuCode")==""){_locator=""}_map.LoadMap(new VELatLong(defaultView.lat,defaultView.lon),defaultView.zoom,defaultView.style,false)}_map.HideDashboard();_map.SetMouseWheelZoomToCenter(false);if(_defaultDistance=="km"){_map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers)}if(!document.maps){document.maps=[]}document.maps.push(_map);var layers=["Locator","Contact","Territory","Journey","Traffic","Search","Lbs","Mvi","RouteGeofence","Job","Poi","TrafficCam","zoneLCC","zoneLEZ","Alert","Misc","Watch","HGVRestriction","RoutePlanner","ShapeDrawer","Alarm"];for(var i=0;i<layers.length;i++){var newLayerLocator=new VEShapeLayer();newLayerLocator.SetTitle(layers[i]);_map.AddShapeLayer(newLayerLocator)}_map.AttachEvent("ontokenexpire",function(){addToQueue("map_xml.aspx?mode=refreshToken",3,false,function(xml){_map.SetClientToken(readCookie("VEToken"))})});_map.AttachEvent("onmousemove",function(e){if(_newContact!=null&&_newContact.DrawingPolygon){_newContact.PolygonDrawer.MapMouseMove(_map.PixelToLatLong(new VEPixel(e.mapX,e.mapY)))}runMapEvent("mapmousemove",_map.PixelToLatLong(new VEPixel(e.mapX,e.mapY)))});_map.AttachEvent("onmouseout",function(){runMapEvent("onmouseout")});_map.AttachEvent("onmouseup",function(){runMapEvent("onmouseup")});_map.AttachEvent("onmousedown",function(e){if(e.elementID!=null){window.event.cancelBubble=false;runMapEvent("onshapemousedown",_map.GetShapeByID(e.elementID));if(window.event.cancelBubble){return true}}});_map.AttachEvent("onmouseover",function(e){if(_newContact!=null&&_newContact.DrawingPolygon){return true}if(e.elementID!=null){runMapEvent("onmouseover",_map.GetShapeByID(e.elementID))}return true});_map.AttachEvent("onchangeview",function(e){viewChanged(e)});_map.AttachEvent("onclick",function(e){var posXY=null;var latLong=null;if(e.latLong){latLong=e.latLong;var pixelPos=_map.LatLongToPixel(e.latLong);posXY=[pixelPos.x+_map.GetLeft(),pixelPos.y+_map.GetTop()]}else{posXY=[e.mapX+_map.GetLeft(),e.mapY+_map.GetTop()];latLong=_map.PixelToLatLong(new VEPixel(e.mapX,e.mapY))}var event=event?event:{clientX:posXY[0],clientY:posXY[1]};window.event.cancelBubble=false;runMapEvent((e.leftMouseButton?"mapleftclick":"maprightclick"),latLong);if(window.event.cancelBubble){return }if(_newContact!=null&&_newContact.DrawingPolygon){if(!_isBE){if(e.leftMouseButton){_newContact.PolygonDrawer.AddSide(latLong);return }if(e.rightMouseButton){_newContact.PolygonDrawer.FinishDrawing(latLong);return }}else{alert(lang["map.err.BE"])}}if(!e.rightMouseButton){return }if(_newContact!=null&&_newContact.MoveMode){if(!_isBE){_newContact.MovePushPin(latLong)}else{alert(lang["map.err.BE"])}return }var shapeType;var isCluster=false;var clickedShape;var icon;if(e.elementID!=null){clickedShape=_map.GetShapeByID(e.elementID);shapeType=clickedShape.GetShapeLayer().GetTitle();isCluster=clickedShape.GetShapeLayer()._isClusterLayer;icon=(clickedShape.GetCustomIcon().Image?"<img src='"+clickedShape.GetCustomIcon().Image+"'>":clickedShape.GetCustomIcon())}if(isCluster){clickedShape=getShapeInCluster(self.GetShapeLayer(MasternautMapLayer.Locator),clickedShape);shapeType="Locator"}switch(shapeType){case"Locator":runMapEvent("onlocatorclick",event,clickedShape,_locator);break;case"Mvi":runMapEvent("onmviclick",event,self.Journey.GetMviDetail(clickedShape.GetTitle()));break;case"Journey":if(self.Journey){runMapEvent("onjourneyclick",event,clickedShape,self.Journey)}break;case"Contact":runMapEvent("oncontactclick",event,clickedShape.MasternautId,_location.selectNodes("location/loc[@id="+clickedShape.MasternautId+"]")[0]);break;case"Territory":runMapEvent("onterritoryclick",event,clickedShape);break;case"Search":runMapEvent("onsearcheditemclick",event,clickedShape);break;case"Traffic":runMapEvent("ontrafficclick",event,clickedShape);break;case"Poi":runMapEvent("onpoiclick",event,clickedShape);break;case"HGVRestriction":runMapEvent("onrestrictionclick",event,clickedShape);break;case"RouteGeofence":if(_routeGeofence[clickedShape.MasternautId]){runMapEvent("onroutegeofenceclick",event,clickedShape,_routeGeofence)}break;case"Job":runMapEvent("onjobclick",event,clickedShape,_jobXml.selectNodes("jobs/job[@id='"+clickedShape.MasternautId+"']")[0]);break;case"Alert":runMapEvent("onalertclick",event,clickedShape,_alertXml.selectNodes("alert/al[@id="+clickedShape.MasternautId+"]")[0]);break;case"TrafficCam":runMapEvent("ontrafficcamclick",event,clickedShape);break;case"Alarm":runMapEvent("onalarmclick",event,clickedShape);break;default:if(!_isBE){runMapEvent("onmapclick",event,latLong)}break}runMapEvent("onmaprightclick",event,clickedShape,shapeType);event.cancelBubble=true});_map.DisambiguationCallback=function(e){hideWaitWindow();var win=new MasternautWindows(document.body,0,0,450,250,"z-index:1000;",null,true,lang["map.search.res"],false,true,true,false,true,false,true,0,true);addChildObj("div",win.divContent,"","<b>"+lang["map.err.search"]+"</b>:<br><br>");for(var x=0;x<e.length;x++){var lnk=addChildObj("div",win.divContent,"",e[x].Name,"link bullet");lnk.LatLong=e[x].LatLong;lnk.onclick=function(){handleSearchResult(0,0,this.LatLong.Latitude,this.LatLong.Longitude,"","",this.innerText,"","","",16);win.close()}}};viewChanged(null);_initDone=true}function viewChanged(e){_is3D=_map.GetMapMode()==VEMapMode.Mode3D;_isBE=_map.GetMapStyle()==VEMapStyle.BirdseyeHybrid;if(_isBE){var view=_map.GetBirdseyeScene().GetBoundingRectangle()}else{var view=_map.GetMapView()}if(_is3D||_isBE){if(view.TopLeftLatLong.Latitude<view.BottomRightLatLong.Latitude){var tmp=view.TopLeftLatLong.Latitude;view.TopLeftLatLong.Latitude=view.BottomRightLatLong.Latitude;view.BottomRightLatLong.Latitude=tmp}if(view.TopLeftLatLong.Longitude>view.BottomRightLatLong.Longitude){var tmp=view.TopLeftLatLong.Longitude;view.TopLeftLatLong.Longitude=view.BottomRightLatLong.Longitude;view.BottomRightLatLong.Longitude=tmp}self.RedrawVehicleLivePushpin()}_topLeft=view.TopLeftLatLong;_bottomRight=view.BottomRightLatLong;if(self.Journey&&!_simulationStarted){self.Journey.ShowJourneyInCurrentView(_topLeft,_bottomRight)}if(self.SeeContactCategory!=-1){self.ShowAllContacts()}if(_trafficCamDisplayed){self.ShowTrafficCam()}if(_poiTypeToDisplay!=-1){self.ShowPOI(_poiTypeToDisplay)}if(_hgvRestrictionTypeToDisplay!=-1){self.ShowHGVRestriction(_hgvRestrictionTypeToDisplay)}if(self.LbsPushpin){showLbs()}if(_newContact!=null){_newContact.DrawRadiusShape()}if(document.contextMenu){document.onclick()}runMapEvent("onviewchanged")}function getShapeInCluster(layer,clusterShape){for(var i=0;i<layer.Clusters.length;i++){if(layer.Clusters[i].GetClusterShape()==clusterShape){return layer.Clusters[i].Shapes}}return[]}this.GetVEMap=function(){return _map};this.EnableTrackMode=function(){_trackModeEnabled=true;self.ontrackmodeenable()};this.DisableTrackMode=function(){_trackModeEnabled=false;self.ontrackmodedisable()};this.SetNewContact=function(newContact){_newContact=newContact};this.UnsetNewContact=function(doClear){if(doClear){_newContact.Clear()}_newContact=null};this.SetNearestVehicleMode=function(){_nearestVehicle=true};this.SetNearestContactMode=function(){_nearestContact=true};this.GetFilterNearestVehicle=function(){return _filterNearestVehicle};this.SetLocationVicinityMode=function(){_loactionVicinity=true};this.SetMultipleJourney=function(multipleJourney){_multipleJourney=multipleJourney};this.UnsetMutipleJourney=function(){_multipleJourney=null};this.GetDirections=function(locations,options){_map.GetDirections(locations,options)};this.GetOrientation=function(){return(!_isBE?"North":_map.GetBirdseyeScene().GetOrientation())};this.DeleteRoute=function(){_map.DeleteRoute();this.DeleteShapes(MasternautMapLayer.RoutePlanner)};this.SetCenter=function(latitude,longitude){_map.SetCenter(new VELatLong(latitude,longitude))};this.GetZoomLevel=function(){return _map.GetZoomLevel()};this.SetZoomLevel=function(zoomLevel){_map.SetZoomLevel(zoomLevel)};this.SetMapStyle=function(style){_map.SetMapStyle(style)};this.GetMapStyle=function(){return _map.GetMapStyle()};this.SetMapMode=function(mode){_map.SetMapMode(mode);_is3D=(mode==VEMapMode.Mode3D);runMapEvent("onmodechanged")};this.SetPrintOptions=function(option){_map.SetPrintOptions(option)};this.Resize=function(width,height){_map.Resize(width,height)};this.SetCursor=function(cursor){_mapContainer.childNodes[0].style.cursor=cursor};this.SetMapView=function(latLongs){_map.SetMapView(latLongs)};this.ShowMiniMap=function(){_map.ShowMiniMap(_mapContainer.offsetWidth-160,0,VEMiniMapSize.Small);document.getElementById("MSVE_minimap_resize").style.visibility="hidden";runMapEvent("onminimapdisplayed")};this.HideMiniMap=function(){_map.HideMiniMap();runMapEvent("onminimaphidden")};this.ZoomIn=function(latitude,longitude,zoomLevel,pointing){if(latitude&&longitude){if(zoomLevel==null){zoomLevel=_map.GetZoomLevel()+4}_map.SetCenterAndZoom(new VELatLong(latitude,longitude),zoomLevel);if(pointing){self.AddShape(0,self.DeleteShapes(MasternautMapLayer.Misc),"",latitude,longitude,"/common/images/map/location_arrow_red.gif","","",1020)}}else{if(zoomLevel==null){_map.ZoomIn()}else{_map.SetZoomLevel(zoomLevel)}}};this.ZoomOut=function(){_map.ZoomOut()};this.Is3D=function(){return _is3D};this.Control3D=function(lat,lon,altitude,pitch,heading){_map.SetMapView(new VEMapViewSpecification(new VELatLong(lat,lon),1,altitude,pitch,heading))};this.ZoomToFavouriteView=function(viewCode){var viewXml=self.favourite.selectNodes("favourite/fav[@id="+viewCode+"]");if(viewXml[0]){_map.SetMapView([new VELatLong(viewXml[0].getAttribute("lat1"),viewXml[0].getAttribute("lon1")),new VELatLong(viewXml[0].getAttribute("lat2"),viewXml[0].getAttribute("lon2"))])}_map.SetZoomLevel(_map.GetZoomLevel()+1)};this.ZoomToJourney=function(){_map.Pan(1,1);_map.SetMapView([new VELatLong(this.Journey.minLat,this.Journey.minLon),new VELatLong(this.Journey.maxLat,this.Journey.maxLon)])};this.SimulateJourney=function(){if(this.Journey&&this.Journey.length>0){if(_isBE){alert(lang["map.err.BE"]);return }_simulationStarted=true;this.DeleteShapes(MasternautMapLayer.Locator);this.DeleteShapes(MasternautMapLayer.Journey);this.DeleteShapes(MasternautMapLayer.Mvi);this.ZoomToJourney();this.Journey.Simulator=new MasternautJourneySimulator(this,this.Journey.GetCurrentStopXml(),_popupContainer);this.Journey.Simulator.onstop=function(){_simulationStarted=false;viewChanged(null);self.RedrawVehicleLivePushpin()};this.Journey.Simulator.Start()}else{alert(lang["map.err.noMis"])}};function handleSearchResult(locCode,mcuCode,lat,lon,name,description,road,town,postCode,country,zoomLevel){runMapEvent("onsearchresult",lat,lon,name,description,road);if(_newContact){if(locCode!=0){_newContact.Load(locCode)}else{if(mcuCode==0){_newContact.ChangeAddress(road,town,postCode,country,lat,lon);if(name!=""){_newContact.ChangeName(name)}}}}else{if(_nearestVehicle){self.ShowNearestVehicle(lat,lon)}else{if(_nearestContact){self.ShowNearestContact(lat,lon)}else{if(_loactionVicinity){self.ShowLocationVicinity(lat,lon)}else{if(zoomLevel){_map.SetCenterAndZoom(new VELatLong(lat,lon),zoomLevel)}if(locCode!=0){self.ShowAllContacts(0)}else{if(mcuCode==0){var searchLayer=self.GetShapeLayer(MasternautMapLayer.Search);searchLayer.DeleteAllShapes();self.AddShape(0,searchLayer,"",lat,lon,"/common/images/map/location_flag-yellow.gif",name,description,1013)}}if(_multipleJourney&&mcuCode!=0){var mcuXml=_locator.selectNodes("locator/group/loc[@mcuC="+mcuCode+"]")[0];groupCode=mcuXml.parentNode.getAttribute("id");_multipleJourney.AddVehicle(mcuCode,name,groupCode)}}}}}}this.AddViewToFavourite=function(){if(_isBE){alert(lang["map.err.BE"]);return }var viewName=prompt(lang["map.err.viewN"],"");if(viewName!=null&&viewName!=""){var rect=_map.GetMapView();addToQueue("map_xml.aspx?mode=manageFavourite&saveView=1&newViewName="+viewName+"&newViewLat1="+rect.TopLeftLatLong.Latitude+"&newViewLon1="+rect.TopLeftLatLong.Longitude+"&newViewLat2="+rect.BottomRightLatLong.Latitude+"&newViewLon2="+rect.BottomRightLatLong.Longitude,2,true);runMapEvent("onviewlistchanged")}};this.SetViewAsDefault=function(){if(_isBE){alert(lang["map.err.BE"]);return }createCookie("defaultMapView","{lat:"+_map.GetCenter().Latitude+",lon:"+_map.GetCenter().Longitude+",zoom:"+_map.GetZoomLevel()+',style:"'+_map.GetMapStyle()+'"}',30)};this.DeleteViewFromFavourite=function(viewCode,viewName){if(viewCode&&viewCode!=0){if(confirm(lang["map.err.viewD"]+" "+viewName+"?")){addToQueue("map_xml.aspx?mode=manageFavourite&delView=1&delViewCode="+viewCode,2,true);runMapEvent("onviewlistchanged")}}};this.RenameFavouriteView=function(viewCode,viewName){if(viewCode&&viewCode!=0){var newName=prompt(lang["map.err.viewR"],viewName);if(newName!=null&&newName!=""&&newName!=viewName){addToQueue("map_xml.aspx?mode=manageFavourite&renameView=1&oldViewCode="+viewCode+"&newViewName="+newName,2,true);runMapEvent("onviewlistchanged")}}};this.GetKmPerPixel=function(){initMap();return _map.vemapcontrol.GetMetersPerPixel()/1000};this.ShowWeather=function(lat,lon){addToQueue("map_xml.aspx?mode=loadWeather&lat="+lat+"&lon="+lon+"&style=full",3,true,function(xml){if(xml.getElementsByTagName("stationName").length==0){s=["No station found"]}else{s=[xml.getElementsByTagName("stationName")[0].text];s.push(xml.getElementsByTagName("clouds")[0].text);s.push(xml.getElementsByTagName("temperature")[0].text+"°C "+parseInt((parseInt(xml.getElementsByTagName("temperature")[0].text,10)*1.8+32))+"°F");s.push(lang["map.wea.hum"]+": "+xml.getElementsByTagName("humidity")[0].text+"%");s.push(lang["map.wea.wind"]+": "+Speed(parseInt(xml.getElementsByTagName("windSpeed")[0].text,10)*1.609)+"<img src='/common/images/map/arrow_"+getDegresGifVehicle(xml.getElementsByTagName("windDirection")[0].text,"North")+".gif' align='absmiddle'>")}var div=addChildObj("div",null,null,s.join("<br>"));new MasternautWindows(document.body,0,0,210,110,"z-index:10001;",div,false,lang["map.wea"],false,true,true,false,true,false,false,0,true)})};this.ShowTrafficCam=function(){_trafficCamDisplayed=true;var url="map_xml.aspx?mode=loadTrafficCam&maxResult=100&minlat="+_bottomRight.Latitude+"&minLon="+_topLeft.Longitude+"&maxLat="+_topLeft.Latitude+"&maxLon="+_bottomRight.Longitude+"&zoomLevel="+this.GetZoomLevel();addToQueue(url,2,false,trafficCamLoaded)};function trafficCamLoaded(xml){var items=xml.getElementsByTagName("cam");var newShape=self.AddShape;var shapes=[];for(var i=0;i<items.length;i++){shapes.push(newShape(items[i].getAttribute("id"),null,"cam",items[i].getAttribute("lat"),items[i].getAttribute("lon"),"/common/images/map/camera_"+(items[i].getAttribute("id")=="0"?"g":items[i].getAttribute("work"))+".gif",items[i].getAttribute("det"),"",1004))}var layer=self.DeleteShapes(MasternautMapLayer.TrafficCam);layer.AddShape(shapes)}this.HideTrafficCam=function(){_trafficCamDisplayed=false;self.DeleteShapes(MasternautMapLayer.TrafficCam)};this.ShowPOI=function(poiType){if(poiType.length==0){this.HidePOI()}else{_poiTypeToDisplay=poiType;var url="map_xml.aspx?mode=loadPOIList&typeId="+poiType.join(",")+"&maxResult=100&minlat="+_bottomRight.Latitude+"&minLon="+_topLeft.Longitude+"&maxLat="+_topLeft.Latitude+"&maxLon="+_bottomRight.Longitude;addToQueue(url,2,false,poiLoaded)}};function poiLoaded(xml){var items=xml.getElementsByTagName("poi");var newShape=self.AddShape;var shapes=[];for(var i=0;i<items.length;i++){shapes.push(newShape(i,null,"poi",items[i].getAttribute("lat"),items[i].getAttribute("lon"),"/common/images/map2/poi/poi_"+items[i].getAttribute("typ")+".gif",items[i].getAttribute("nam"),"",1004))}var layer=self.DeleteShapes(MasternautMapLayer.POI);layer.AddShape(shapes)}this.HidePOI=function(){_poiTypeToDisplay=-1;self.DeleteShapes(MasternautMapLayer.POI)};this.ShowHGVRestriction=function(restType){if(restType.length==0){this.HideHGVRestriction()}else{_hgvRestrictionTypeToDisplay=restType;var url="map_xml.aspx?mode=loadHGVRestrictionList&typeId="+restType.join(",")+"&maxResult=100&minlat="+_bottomRight.Latitude+"&minLon="+_topLeft.Longitude+"&maxLat="+_topLeft.Latitude+"&maxLon="+_bottomRight.Longitude;addToQueue(url,2,false,restLoaded)}};function restLoaded(xml){var items=xml.getElementsByTagName("rest");var newShape=self.AddShape;var shapes=[];for(var i=0;i<items.length;i++){shapes.push(newShape(i,null,"poi",items[i].getAttribute("lat"),items[i].getAttribute("lon"),"/common/images/map/location_rest"+items[i].getAttribute("typ")+".gif",items[i].getAttribute("add"),items[i].getAttribute("imp")+" ("+items[i].getAttribute("met")+")",1004))}var layer=self.DeleteShapes(MasternautMapLayer.HGVRestriction);layer.AddShape(shapes)}this.HideHGVRestriction=function(){_hgvRestrictionTypeToDisplay=-1;self.DeleteShapes(MasternautMapLayer.HGVRestriction)};this.LoadKMZ=function(kmzUrl,layer,iconUrl){var veLayerSpec=new VEShapeSourceSpecification(VEDataType.ImportXML,kmzUrl,layer);_map.ImportShapeLayerData(veLayerSpec,function(layer){var numShapes=layer.GetShapeCount();for(var i=0;i<numShapes;++i){layer.GetShapeByIndex(i).SetCustomIcon("<img src='"+iconUrl+"'/>")}},true)};this.ShowCustomLayer=function(){addToQueue("map_xml.aspx?mode=getOverlayFolder",3,true,function(xml){var tileSourceSpec=new VETileSourceSpecification("overlay","/commonBig/overlay/"+xml.getElementsByTagName("overlay")[0].getAttribute("folder")+"/%4.png");tileSourceSpec.MaxZoomLevel=22;tileSourceSpec.Opacity=0.7;_map.AddTileLayer(tileSourceSpec,true)})};this.HideCustomLayer=function(){_map.DeleteTileLayer("overlay")};this.ShowTrafficPushpin=function(getRoadCondition,getDelays,historicTrafficDate){if(getRoadCondition||historicTrafficDate){_showTraffic.getRoadCondition=true;_trafficXml=null}if(getDelays||historicTrafficDate){_showTraffic.getDelays=true;_trafficXml=null}_showTraffic.historicTrafficDate=(historicTrafficDate?new Date(historicTrafficDate):null);if(_trafficXml==null){loadTraffic();return }var items=_trafficXml.getElementsByTagName("incident");if(items.length===0){return }var newShape=self.AddShape;var shapes=[];for(var i=0;i<items.length;i++){if(items[i].getAttribute("kmh")){var trafficShape=new VEShape(VEShapeType.Pushpin,[new VELatLong(parseFloat(items[i].getAttribute("lat")),parseFloat(items[i].getAttribute("lon")))]);trafficShape.SetTitle(items[i].getAttribute("add"));trafficShape.SetDescription(items[i].getAttribute("desc"));trafficShape.SetCustomIcon("<div class='trafficDelay' style='background: url(/common/images/map2/traffic_"+items[i].getAttribute("col")+(items[i].getAttribute("dir")?"_"+items[i].getAttribute("dir"):"")+".gif)'>"+items[i].getAttribute((_defaultCountry=="UK"?"mph":"kmh"))+"</div>");shapes.push(trafficShape)}else{shapes.push(newShape(i,null,"incident",items[i].getAttribute("lat"),items[i].getAttribute("lon"),"/common/images/map/traffic_"+items[i].getAttribute("type")+".gif",items[i].getAttribute("add"),items[i].getAttribute("desc"),1004))}}var trafficLayer=self.DeleteShapes(MasternautMapLayer.Traffic);trafficLayer.AddShape(shapes);runMapEvent("ontrafficinfoloaded",_showTraffic.getRoadCondition,_showTraffic.getDelays)};this.HideTrafficPushpin=function(hideRoadCondition,hideDelays){if(hideRoadCondition){_showTraffic.getRoadCondition=false;_trafficXml=null}if(hideDelays){_showTraffic.getDelays=false;_trafficXml=null}if(_showTraffic.getRoadCondition||_showTraffic.getDelays){self.ShowTrafficPushpin()}else{self.DeleteShapes(MasternautMapLayer.Traffic)}};function loadTraffic(){initMap();if(_showTraffic.getRoadCondition||_showTraffic.getDelays){addToQueue("map_xml.aspx?mode=loadTraffic&getRoadCondition="+(_showTraffic.getRoadCondition?1:0)+"&getDelays="+(_showTraffic.getDelays?1:0)+(_showTraffic.historicTrafficDate?"&historicTrafficDate="+myDateTime(_showTraffic.historicTrafficDate):""),1,false,function(xml){_trafficXml=xml;self.ShowTrafficPushpin();if(_trafficTimerId!=null){window.clearTimeout(_trafficTimerId)}if(_trafficXml.getElementsByTagName("traffic")[0].getAttribute("historicTrafficDate")==undefined){_trafficTimerId=setTimeout(loadTraffic,120000)}})}}this.ShowAlert=function(dateStart,alertType,caption){initMap();_showAlert=true;if(caption){_alertCaption=caption}if(dateStart!=null&&dateStart!=""&&typeof dateStart!="number"){dateStart=new Date(dateStart)}else{if(_alertXml!=null){dateStart=new Date(_alertXml.getElementsByTagName("alert")[0].getAttribute("dateStart"));alertType=_alertXml.getElementsByTagName("alert")[0].getAttribute("alertType")}else{dateStart=new Date();alertType=0}}var dateEnd=new Date();dateEnd.setDate(dateStart.getDate()+1);addToQueue("map_xml.aspx?mode=loadAlert&alertType="+alertType+"&dateStart="+dateStart.getUTCFullYear()+"-"+(dateStart.getMonth()+1)+"-"+dateStart.getDate()+"&dateEnd="+dateEnd.getUTCFullYear()+"-"+(dateEnd.getMonth()+1)+"-"+dateEnd.getDate(),1,false,alertLoaded)};this.HideAlert=function(){if(_alertRefreshId!=null){window.clearTimeout(_alertRefreshId)}_alertXml==null;_showAlert=false;self.DeleteShapes(MasternautMapLayer.Alert);runMapEvent("onalerthidden")};function alertLoaded(xml){_alertXml=xml;var alertLayer=self.DeleteShapes(MasternautMapLayer.Alert);var items=_alertXml.getElementsByTagName("al");if(items.length==0){return }var newShape=self.AddShape;var newCaption=self.AddCaption;var shapes=[];for(var i=0;i<items.length;i++){if(_alertCaption!="none"){shapes.push(newCaption(items[i].getAttribute("id"),null,items[i].getAttribute("lat"),items[i].getAttribute("lon"),items[i].getAttribute(_alertCaption),items[i].getAttribute("dat"),items[i].getAttribute("dri"),1013))}shapes.push(newShape(items[i].getAttribute("id"),null,"alert",items[i].getAttribute("lat"),items[i].getAttribute("lon"),"/common/images/map2/alert_"+items[i].getAttribute("typ")+".gif",items[i].getAttribute("dat"),items[i].getAttribute("dri"),1013))}try{alertLayer.AddShape(shapes);if(_alertRefreshId!=null){window.clearTimeout(_alertRefreshId)}_alertRefreshId=setTimeout(self.ShowAlert,180000);runMapEvent("onalertloaded")}catch(ex){alert(ex.message)}}this.ShowJob=function(jobDate,driverCode,caption,mcuCode){initMap();_showJob=true;if(caption){_jobCaption=caption}if(jobDate!=null&&jobDate!=""&&typeof jobDate!="number"){jobDate=new Date(jobDate)}else{if(_jobXml!=null){jobDate=new Date(_jobXml.getElementsByTagName("jobs")[0].getAttribute("date"));_jobCurrentEngineer=_jobXml.getElementsByTagName("jobs")[0].getAttribute("driverCode");_jobCurrentMCU=_jobXml.getElementsByTagName("jobs")[0].getAttribute("mcuCode")}else{jobDate=new Date();_jobCurrentEngineer=0;_jobCurrentMCU=0}}if(driverCode){_jobCurrentEngineer=driverCode}if(mcuCode){_jobCurrentMCU=mcuCode}addToQueue("map_xml.aspx?mode=loadJob&driverCode="+_jobCurrentEngineer+"&mcuCode="+_jobCurrentMCU+"&jobDate="+myDate(jobDate),1,false,jobLoaded)};this.HideJob=function(){if(_jobRefreshId!=null){window.clearTimeout(_jobRefreshId)}_jobXml==null;_showJob=false;self.DeleteShapes(MasternautMapLayer.Job);runMapEvent("onjobhidden")};function jobLoaded(xml){_jobXml=xml;var jobLayer=self.DeleteShapes(MasternautMapLayer.Job);var items=_jobXml.getElementsByTagName("job");if(items.length===0){return }var newShape=self.AddShape;var newCaption=self.AddCaption;var shapes=[];for(var i=0;i<items.length;i++){if(_jobCurrentEngineer==0||_jobCurrentEngineer==items[i].getAttribute("engId")){if(_jobCaption!="none"&&items[i].getAttribute(_jobCaption)!=""){shapes.push(newCaption(items[i].getAttribute("id"),null,items[i].getAttribute("lat"),items[i].getAttribute("lon"),items[i].getAttribute(_jobCaption),items[i].getAttribute("loc"),items[i].getAttribute("sta")+" - "+items[i].getAttribute("end")+" "+items[i].getAttribute("eng"),1013))}shapes.push(newShape(items[i].getAttribute("id"),null,"job",items[i].getAttribute("lat"),items[i].getAttribute("lon"),"/common/images/map/location_flag-"+items[i].getAttribute("col")+".gif",items[i].getAttribute("loc"),items[i].getAttribute("sta")+" - "+items[i].getAttribute("end")+" "+items[i].getAttribute("eng"),1013))}}jobLayer.AddShape(shapes);if(_jobRefreshId!=null){window.clearTimeout(_jobRefreshId)}_jobRefreshId=setTimeout(self.ShowJob,120000);runMapEvent("onjobloaded",_jobXml)}this.LoadJourney=function(journeyDate,mcuCode,withSpeedInfringement,shiftStart,vehicleSpeedCategory){initMap();if(!shiftStart){shiftStart=0}journeyDate=new Date(journeyDate);addToQueue("map_xml.aspx?mode=loadJourney&date="+myDate(journeyDate)+"&mcucode="+mcuCode+"&shiftStart="+shiftStart+"&withSpeedInfringement="+(withSpeedInfringement?1:0)+"&vehicleSpeedCategory="+(vehicleSpeedCategory?vehicleSpeedCategory:""),3,true,journeyLoaded)};this.ClearJourney=function(){if(this.Journey){if(this.Journey.Menu){this.Journey.Menu.Dispose()}this.Journey.dispose();this.Journey=null;this.DeleteRoute()}};function journeyLoaded(xml){if(self.Journey){self.ClearJourney()}self.Journey=new MasternautJourney(self,xml);if(self.Journey.length>0){self.Journey.Menu=new MasternautJourneyMenu(self,_popupContainer);self.ZoomToJourney();if(_trackModeEnabled){self.DisableTrackMode()}}else{showJourneyDatePicker(self.Journey.date,self.Journey.mcuCode,self.Journey.lastDrive);self.ClearJourney()}runMapEvent("onjourneyloaded")}function showJourneyDatePicker(dateDisplayed,mcuCode,lastDrive){var popupContent=document.createElement("div");addChildObj("span",popupContent,null,lang["map.err.noMiss1"]+(lastDrive?"<br>"+lang["map.err.noMiss2"]+" "+lastDrive:"")+"<br><br>"+lang["map.err.noMiss3"]+" ");var txtDate=addChildObj("input",popupContent,"width:95px;");txtDate.value=dateDisplayed;var win=new MasternautWindows(document.body,0,0,230,130,"z-index:1000;",popupContent,false,lang["map.err.noMiss4"],false,true,true,false,true,false,true,0,true);var cal=new MasternautCalendar(txtDate);cal.onSelectDate=function(){win.close();self.LoadJourney(this.selectedDate,mcuCode)}}this.SendSMS=function(txt,phone){var win=new MasternautWindows(document.body,0,0,320,200,"z-index:1000;",null,false,lang["map.sms"],true,true,true,false,true,false,true,4,true);addChildObj("span",win.divContent,"",lang["map.phone"]+" ");var txtPhone=addInput(win.divContent,"text","","",(phone?phone:""));addChildObj("div",win.divContent,"",lang["map.mess"]);var txtMessage=addChildObj("textarea",win.divContent,"height:80px; width:300px; margin-bottom:5px");txtMessage.value=unescape(txt);txtMessage.onkeyup=function(){txtCount.innerHTML="<br>"+(160-txtMessage.value.length)+" "+lang["map.char"]};var txtCount=addChildObj("span",win.divContent,"","<br>"+(160-txtMessage.value.length)+" "+lang["map.char"]);var btnSend=addChildObj("div",win.divContent,"margin-left:120px",lang["map.sms"],"link");btnSend.onclick=function(){addToQueue("map_xml.aspx?mode=sendSMS&phoneNo="+encodeURI(txtPhone.value)+"&message="+encodeURI(txtMessage.value),3,true);win.close()}};this.SendVDT=function(mcuCode){document.VDTPopup=new MasternautWindows(document.body,0,0,505,380,"z-index:1000;",null,false,lang["map.vdt"],true,true,true,false,true,false,true,4,true);document.VDTPopup.divContent.innerHTML="<iframe src='redirect.aspx?sso=1&url=/mweb/mes_VDTNewMes.aspx?mcuCode="+mcuCode+"' frameborder=0 width='100%' height='100%' scrolling='no'></iframe>"};this.ServiceRequest=function(mcuCode){var win=new MasternautWindows(document.body,0,0,320,200,"z-index:1000;",null,false,lang["map.serv"],true,true,true,false,true,false,true,4,true);addChildObj("span",win.divContent,"",lang["map.serv.issue"]+" ");var cmbIssue=new MasternautCombo(addInput(win.divContent,"text","","width:175px"));cmbIssue.options.addBatch([new Option(lang["map.serv.sub0"],0),new Option(lang["map.serv.sub1"],1),new Option(lang["map.serv.sub2"],2)]);addChildObj("div",win.divContent,"",lang["map.mess"]);var txtMessage=addChildObj("textarea",win.divContent,"height:80px; width:300px; margin-bottom:5px");var btnSend=addChildObj("div",win.divContent,"margin-left:120px",lang["map.send"],"link");btnSend.onclick=function(){addToQueue("map_xml.aspx?mode=sendServiceRequest&mcucode="+mcuCode+"&subject="+cmbIssue.value+"&body="+encodeURI(txtMessage.value),3,true);win.close()}};this.DeleteContact=function(locCode){if(confirm(lang["map.con.del"])){addToQueue("map_xml.aspx?mode=deleteContact&locCode="+locCode,2,true,function(xml){viewChanged();if(_newContact){_newContact.Clear()}})}};this.AddEditContactFromMap=function(lat,lon){this.AddEditContact(0,"",lat,lon,document.divToChangeAfterCallback.Road,document.divToChangeAfterCallback.Town,document.divToChangeAfterCallback.PostCode,document.divToChangeAfterCallback.Country)};this.AddEditContact=function(locCode,locName,locLatitude,locLongitude,locRoad,locTown,locPostcode,locCountry){if(_newContact==null){runMapEvent("onnewcontactinterfaceneeded",locCode,locName,locLatitude,locLongitude,locRoad,locTown,locPostcode,locCountry)}else{if(locCode>0){var contactLayer=this.GetShapeLayer(MasternautMapLayer.Contact);var locShape=this.GetShapeByMasternautId(MasternautMapLayer.Contact,locCode);var radiusShape=this.GetShapeByMasternautId(MasternautMapLayer.Contact,"R"+locCode);contactLayer.DeleteShape(locShape);if(radiusShape!=null){contactLayer.DeleteShape(radiusShape)}_newContact.Load(locCode)}else{_newContact.DisplayDetail(0,unescape(locName),"",0,"","/common/images/map/location_flag-yellow.gif","",false,unescape(locRoad),unescape(locTown),unescape(locPostcode),locCountry,locLatitude,locLongitude,"","","","","",[],50)}}};this.ShowLocationVicinity=function(latitude,longitude,groupMcuCode,week){if(week==null){week=new Date();week.setDate(week.getDate()-(week.getDay()===0?6:week.getDay()-1))}addToQueue("map_xml.aspx?mode=loadLocationVicinity&lat="+latitude+"&lon="+longitude+"&groupMcuCode="+(groupMcuCode?groupMcuCode:"0")+"&week="+week.getUTCFullYear()+"-"+(week.getMonth()+1)+"-"+week.getDate(),2,true,locationVicinityLoaded)};function locationVicinityLoaded(xml){if(_divLocationVicinity==null){var win=new MasternautWindows(document.body,0,0,600,370,"z-index:1000;",null,true,lang["map.ctx.vic"],true,true,true,false,true,false,false,1,true,false,true);win.onClose=function(){_divLocationVicinity=null};addChildObj("div",win.divContent,"height:5px");addChildObj("span",win.divContent,"","&nbsp;"+lang["map.vehG"]+"&nbsp;");var cmbGroupMcu=new MasternautCombo(addChildObj("input",win.divContent,"width:87px;"),160);cmbGroupMcu.SetComboToAutoLoad("loadVehicleGroup","group","id","name",lang["map.any"]);addChildObj("span",win.divContent,"margin-left:7px",lang["map.weekC"]+" ");var cmbWeek=new MasternautCombo(addChildObj("input",win.divContent,"width:40px;"));var day=new Date();day.setDate(day.getDate()-(day.getDay()===0?6:day.getDay()-1));for(var i=0;i<16;i++){cmbWeek.options.add(new Option(day.getDate()+" "+month(day.getMonth()),day.getMonth()+1+"/"+day.getDate()+"/"+day.getUTCFullYear()));day.setDate(day.getDate()-7)}cmbWeek.selectItem(0);var btnSearch=addChildObj("span",win.divContent,"margin-left:15px;",lang["map.search"],"link");btnSearch.onclick=function(){self.ShowLocationVicinity(xml.getElementsByTagName("locationVicinity")[0].getAttribute("lat"),xml.getElementsByTagName("locationVicinity")[0].getAttribute("lon"),cmbGroupMcu.value,new Date(cmbWeek.value))};_divLocationVicinity=addChildObj("div",win.divContent,"margin-top:3px")}MasternautTable(_divLocationVicinity,xml,"add",[lang["map.dri"],lang["map.veh"],lang["map.dat"],lang["map.loc"],lang["map.sta"],lang["map.speed"],lang["map.dist"]],["dri","veh","day","add","sta","spe","dist"],3,self.ZoomIn,[{type:"field",attribute:"lat"},{type:"field",attribute:"lon"},{type:"value",value:15}])}this.PredictNextStop=function(mcuCode,lat,lon,direction,includeIdling){addToQueue("map_xml.aspx?mode=predictNextStop&mcucode="+mcuCode+"&lat="+lat+"&lon="+lon+"&direction="+direction+"&includeIdling="+(includeIdling?1:0),3,true,function(xml){var win=new MasternautWindows(document.body,0,0,270,180,"z-index:1000;",null,true,lang["map.ctx.pre"],true,true,true,false,true,false,false,5,true);win.onClose=function(){self.DeleteShapes(MasternautMapLayer.Misc)};if(xml.getElementsByTagName("loc").length==0){win.divContent.innerHTML=lang["map.err.pre"]}else{var table=MasternautTable(win.divContent,xml,"loc",[lang["map.box.cOrPC"],lang["map.box.trip"],lang["map.box.proba"]],["nam","nbTrip","stat"],0,self.ZoomIn,[{type:"field",attribute:"lat"},{type:"field",attribute:"lon"},{type:"value",value:17},{type:"value",value:true}]);MasternautETACalculator(self,table,{lat:lat,lon:lon},xml,"loc")}})};this.ShowTags=function(mcuCode,tagGroup,status,lastMovedMin,lastMovedMax){addToQueue("map_xml.aspx?mode=loadTags&mcuCode="+mcuCode+"&group="+tagGroup+"&status="+status+"&lastMovedMin="+lastMovedMin+"&lastMovedMax="+lastMovedMax,2,true,tagsLoaded)};this.ShowNearestTags=function(mcuCode,tagGroup,status,lastMovedMin,lastMovedMax,originLat,originLon){addToQueue("map_xml.aspx?mode=loadNearestTags&mcuCode="+mcuCode+"&group="+tagGroup+"&status="+status+"&lastMovedMin="+lastMovedMin+"&lastMovedMax="+lastMovedMax+"&originLat="+originLat+"&originLon="+originLon,2,true,tagsLoaded)};function tagsLoaded(xml){var hasDistance=(xml.getElementsByTagName("tags")[0].getAttribute("originLat")!=null);if(_divTags==null){var win=new MasternautWindows(document.body,0,0,470,450,"z-index:1000;",null,true,(hasDistance?lang["map.tag.near"]:lang["map.tag.list"]),true,true,true,false,true,false,false,5,true);win.onClose=function(){_divTags=null};addChildObj("span",win.divContent,"","&nbsp;"+lang["map.group"]+"&nbsp;");var tagGroup=new MasternautCombo(addChildObj("input",win.divContent,"width:80px;"),160);tagGroup.SetComboToAutoLoad("loadTagGroup","group","id","nam",lang["map.any"]);addChildObj("span",win.divContent,"","&nbsp;"+lang["map.sta"]+"&nbsp;");var cmbStatus=new MasternautCombo(addChildObj("input",win.divContent,"width:55px"));cmbStatus.options.addBatch([new Option(lang["map.any"],-1),new Option(lang["map.tag.att"],1),new Option(lang["map.tag.det"],0)]);cmbStatus.selectItem(0);addChildObj("span",win.divContent,"","&nbsp;"+lang["map.tag.last"]+"&nbsp;");var cmbDateMoved=new MasternautCombo(addChildObj("input",win.divContent,"width:75px"),100);cmbDateMoved.options.addBatch([new Option(lang["map.tag.any"],"-10000|1"),new Option(lang["map.today"],"0|1"),new Option("< "+lang["map.tag.7"],"-7|1"),new Option("> "+lang["map.tag.7"],"-10000|-7"),new Option("< "+lang["map.tag.30"],"-30|1"),new Option("> "+lang["map.tag.30"],"-10000|-30")]);cmbDateMoved.selectItem(0);var btnSearch=addChildObj("div",win.divContent,"float:right;",lang["map.search"],"bullet link");btnSearch.onclick=function(){if(hasDistance){self.ShowNearestTags(xml.getElementsByTagName("tags")[0].getAttribute("mcuCode"),tagGroup.value,cmbStatus.value,cmbDateMoved.value.split("|")[0],cmbDateMoved.value.split("|")[1],xml.getElementsByTagName("tags")[0].getAttribute("originLat"),xml.getElementsByTagName("tags")[0].getAttribute("originLon"))}else{self.ShowTags(xml.getElementsByTagName("tags")[0].getAttribute("mcuCode"),tagGroup.value,cmbStatus.value,cmbDateMoved.value.split("|")[0],cmbDateMoved.value.split("|")[1])}};_divTags=addChildObj("div",win.divContent,"margin-top:3px")}var headers=[lang["map.nam"],lang["map.group"],lang["map.dat"],lang["map.tag.reader"],lang["map.sta"],lang["map.tag.last"]];var tagName=["nam","gr","dat","veh","sta","day"];if(hasDistance){headers.push("Dist.");tagName.push("dist")}MasternautTable(_divTags,xml,"tag",headers,tagName,0,self.ShowTagHistory,[{type:"field",attribute:"id"}])}this.ShowTagHistory=function(idTag,dateMin,dateMax){addToQueue("map_xml.aspx?mode=loadTagHistory&idTag="+idTag+(dateMin?"&dateMin="+myDate(dateMin):"")+(dateMax?"&dateMax="+myDate(dateMax):""),3,true,tagHistoryLoaded)};function tagHistoryLoaded(xml){if(_divTagHistory==null){var win=new MasternautWindows(document.body,0,0,510,370,"z-index:1000;",null,true,lang["map.tag.hist"]+" - "+xml.getElementsByTagName("TagHistory")[0].getAttribute("name"),true,true,true,false,true,false,false,5,true);win.onClose=function(){_divTagHistory=null};addChildObj("span",win.divContent,null,lang["map.from"]+" ");var dateMin=new MasternautCalendar(addChildObj("input",win.divContent,"width:110px"));var d=new Date();d.setDate(d.getDate()-7);dateMin.selectCal(d);addChildObj("span",win.divContent,null," "+lang["map.to"]+" ");var dateMax=new MasternautCalendar(addChildObj("input",win.divContent,"width:110px"));dateMax.selectCal(new Date());var btnSearch=addChildObj("span",win.divContent,"margin-left:15px;",lang["map.search"],"link");btnSearch.onclick=function(){self.ShowTagHistory(xml.getElementsByTagName("TagHistory")[0].getAttribute("id"),dateMin.selectedDate,dateMax.selectedDate)};_divTagHistory=addChildObj("div",win.divContent,"margin-top:3px")}MasternautTable(_divTagHistory,xml,"hist",[lang["map.dat"],lang["map.sta"],lang["map.tag.reader"],lang["map.loc"]],["dat","sta","mcu","loc"],3,self.ZoomIn,[{type:"field",attribute:"lat"},{type:"field",attribute:"lon"},{type:"value",value:15}])}this.ShowNearestVehicle=function(latitude,longitude,types,attributes,skills,allSkill,stopped,driving,idling,working,groupMcuCode,limit){addToQueue("map_xml.aspx?mode=loadNearestVehicle&lat="+latitude+"&lon="+longitude+"&types="+(types?types:"")+"&attributes="+(attributes?attributes:"")+"&skills="+(skills?skills:"")+"&allSkill="+(allSkill?allSkill:0)+"&driving="+(driving==false?0:1)+"&stopped="+(stopped==false?0:1)+"&idling="+(idling==false?0:1)+"&working="+(working==false?0:1)+"&groupMcuCode="+(groupMcuCode?groupMcuCode:0)+"&limit="+(limit?limit:10),2,true,nearestVehicleLoaded)};function nearestVehicleLoaded(xml){var origin={lat:xml.getElementsByTagName("nearestVehicle")[0].getAttribute("lat"),lon:xml.getElementsByTagName("nearestVehicle")[0].getAttribute("lon")};if(_divNearestVehicle==null){var win=new MasternautWindows(document.body,0,0,600,370,"z-index:1000;",null,true,lang["map.nearV"],true,true,true,false,true,false,false,5,true,false,true);win.onClose=function(){_divNearestVehicle=null;_filterNearestVehicle=null;self.RedrawVehicleLivePushpin()};addChildObj("span",win.divContent,"","&nbsp;"+lang["map.vehG"]+"&nbsp;");var vehicleGroup=new MasternautCombo(addChildObj("input",win.divContent,"width:87px;"),160);vehicleGroup.SetComboToAutoLoad("loadVehicleGroup","group","id","name",lang["map.any"]);addChildObj("span",win.divContent," margin-left:45px",lang["map.nearV.lim"]+" ");var cmbLimit=new MasternautCombo(addChildObj("input",win.divContent,"width:40px"));cmbLimit.options.addBatch([new Option("5",5),new Option("10",10),new Option("50",50),new Option("100",100),new Option("200",200)]);cmbLimit.selectItem(1);addChildObj("span",win.divContent,null,"&nbsp;"+lang["map.vehs"]+"<br>");var skillPicker=new MasternautSkillPicker(win.divContent);addChildObj("span",win.divContent,null,"<br>");var typeAttributePicker=new MasternautTypeAndAttributePicker(win.divContent);addChildObj("span",win.divContent,null,"<br>&nbsp;"+lang["map.nearV.sta"]);var chkStop=addCheckbox(win.divContent,true,lang["map.sta.stop"]);var chkDrive=addCheckbox(win.divContent,true,lang["map.sta.dri"]);var chkIdle=addCheckbox(win.divContent,true,lang["map.sta.idl"]);var chkWork=addCheckbox(win.divContent,true,lang["map.sta.work"]);var btnSearch=addChildObj("span",win.divContent,"margin-left:15px;",lang["map.search"],"link");btnSearch.onclick=function(){self.ShowNearestVehicle(origin.lat,origin.lon,typeAttributePicker.SelectedTypes,typeAttributePicker.SelectedAttributes,skillPicker.SelectedSkills,skillPicker.AllSkill(),chkStop.checked,chkDrive.checked,chkIdle.checked,chkWork.checked,vehicleGroup.value,cmbLimit.value)};_divNearestVehicle=addChildObj("div",win.divContent,"margin-top:3px")}var table=MasternautTable(_divNearestVehicle,xml,"veh",[lang["map.dri"],lang["map.veh"],lang["map.day"],lang["map.hour"],lang["map.loc"],lang["map.sta"],lang["map.dist"]],["dri","mcu","day","hr","add","sta","dist"],1,self.ZoomIn,[{type:"field",attribute:"lat"},{type:"field",attribute:"lon"},{type:"value",value:15}]);MasternautETACalculator(self,table,origin,xml,"veh");_filterNearestVehicle=[];_filterNearestVehicle.points=[];_filterNearestVehicle.distances=[];var vehicles=xml.getElementsByTagName("veh");for(var i=0;i<vehicles.length;i++){_filterNearestVehicle[vehicles[i].getAttribute("mcuC")]=true;_filterNearestVehicle.points.push([new VELatLong(parseFloat(vehicles[i].getAttribute("lat")),parseFloat(vehicles[i].getAttribute("lon"))),new VELatLong(parseFloat(vehicles[i].parentNode.getAttribute("lat")),parseFloat(vehicles[i].parentNode.getAttribute("lon")))]);_filterNearestVehicle.distances.push(vehicles[i].getAttribute("dist"))}self.RedrawVehicleLivePushpin()}this.ShowNearestContactFromMcu=function(mcuCode){addToQueue("map_xml.aspx?mode=loadNearestContactFromMcu&mcuCode="+mcuCode,3,true,function(xml){runMapEvent("onnearestcontactloaded",xml)})};this.ShowNearestContact=function(lat,lon,familyLocCode){addToQueue("map_xml.aspx?mode=loadNearestContact&lat="+lat+"&lon="+lon+"&familyLocCode="+(familyLocCode?familyLocCode:0),3,true,function(xml){runMapEvent("onnearestcontactloaded",xml)})};this.CreateJob=function(locCode){var win=new MasternautWindows(document.body,0,0,772,380,"z-index:1000;",null,false,lang["map.ctx.job"],true,true,true,false,true,false,true,4,true);win.divContent.innerHTML="<iframe src='redirect.aspx?sso=1&url=/jobscheduling/job.aspx?locCode="+locCode+"' frameborder=0 width='100%' height='100%' scrolling='yes'></iframe>"};this.EditJob=function(jobCode){var win=new MasternautWindows(document.body,0,0,772,380,"z-index:1000;",null,false,lang["map.ctx.jobE"],true,true,true,false,true,false,true,4,true);win.divContent.innerHTML="<iframe src='redirect.aspx?sso=1&url=/jobscheduling/job.aspx?jobCode="+jobCode+"' frameborder=0 width='100%' height='100%' scrolling='yes'></iframe>"};this.ShowCoordinate=function(latitude,longitude){var win=new MasternautWindows(document.body,0,0,250,125,"z-index:1000;",null,true,lang["map.coord"],false,true,true,false,true,false,true,0,true);win.divContent.innerHTML="<b>"+lang["map.coord.lat"]+":</b> "+latitude+"<br><b>"+lang["map.coord.lon"]+":</b> "+longitude+"<br>";if(window.clipboardData){var lnk=addChildObj("span",win.divContent,"margin-left:50px;",lang["map.coord.copy"],"link");lnk.onclick=function(){window.clipboardData.setData("Text",latitude+", "+longitude);win.close()}}var options=new VEImageryMetadataOptions();options.LatLong=new VELatLong(latitude,longitude);_map.SetClientToken(readCookie("VEToken"));_map.GetImageryMetadata(function(metaData){if(metaData.DateRangeStart&&metaData.DateRangeEnd.getUTCFullYear()!=1980){win.divContent.innerHTML+="<br><br>Imagery taken "+(myDate(metaData.DateRangeStart)!=myDate(metaData.DateRangeEnd)?"between<br>":"on ")+metaData.DateRangeStart.getDate()+"/"+(metaData.DateRangeStart.getMonth()+1)+"/"+metaData.DateRangeStart.getUTCFullYear()+(myDate(metaData.DateRangeStart)!=myDate(metaData.DateRangeEnd)?" and "+metaData.DateRangeEnd.getDate()+"/"+(metaData.DateRangeEnd.getMonth()+1)+"/"+metaData.DateRangeEnd.getUTCFullYear():"");_map.SetClientToken(null)}},options)};this.ShowContact=function(code,name,latitude,longitude){if(arguments.length==1){addToQueue("map_xml.aspx?mode=loadContact&locCode="+locCode+"&fullDetail=1&withLocFamilyRefTable=1",1,false,function(xml){if(xml.getElementsByTagName("loc").length>0){var locXml=xml.getElementsByTagName("loc")[0];self.ShowContact(locXml.getAttribute("id"),locXml.getAttribute("name"),locXml.getAttribute("lat"),locXml.getAttribute("lon"))}else{alert(lang["map.con.err"])}})}else{handleSearchResult(code,0,latitude,longitude,name,"",name,"","","",17)}};this.ShowAddress=function(searchedString,address,poi){initMap();if(searchedString==""){return }if(address&&isUkPostCode(searchedString)){this.ShowPostCode(searchedString);return }if(address&&searchedString.substr(searchedString.lastIndexOf(" ")+1).toLowerCase()=="ireland"&&searchedString.toLowerCase().indexOf("northern ireland")<1){addToQueue("map_xml.aspx?mode=IrelandSearch&searchedString="+escape(searchedString),2,true,function(xml){irelandSearchGeocoded(xml.getElementsByTagName("add"))});return }var what=(poi?searchedString:null);var where=(address?searchedString:null);_map.LastSearchedAddress=where;if(_isBE){_map.SetMapStyle(VEMapStyle.Hybrid)}showWaitWindow();var addressToCheckIfNoPOIFound=null;if(what&&where){addressToCheckIfNoPOIFound=where;where=null}_map.Find(what,where,null,null,0,20,false,false,false,true,function(a,results,places,d,e){hideWaitWindow();if(places&&places.length>0){handleSearchResult(0,0,places[0].LatLong.Latitude,places[0].LatLong.Longitude,"","",places[0].Name,"","","")}if(results&&results.length>0){if(results.length==1){handleSearchResult(0,0,results[0].LatLong.Latitude,results[0].LatLong.Longitude,results[0].Name,results[0].Phone+"<br>"+results[0].Description,results[0].Description.split(",")[0],results[0].Description.split(",")[1],results[0].Description.split(",")[2],"")}else{var searchLayer=self.GetShapeLayer(MasternautMapLayer.Search);searchLayer.DeleteAllShapes();for(var i=0;i<results.length;i++){self.AddShape(i,searchLayer,"",results[i].LatLong.Latitude,results[i].LatLong.Longitude,"/common/images/map/location_flag-yellow.gif",results[i].Name,results[i].Phone+"<br>"+results[i].Description,1013)}}}if(!places&&!results){if(addressToCheckIfNoPOIFound!=null){self.ShowAddress(addressToCheckIfNoPOIFound,true,false)}else{var win=new MasternautWindows(document.body,0,0,240,90,"z-index:1000;",null,false,lang["map.search.res"],false,true,true,false,true,false,true,0,true);if(what==null){addChildObj("div",win.divContent,null,lang["map.err.search2"]+"<br><br>")}else{addChildObj("div",win.divContent,null,lang["map.err.search3"])}}}})};this.FindNearby=function(lat,lon){addToQueue("map_xml.aspx?mode=searchNearBy&lat="+lat+"&lon="+lon,2,true,postCodeLoaded)};this.ShowPostCode=function(postCode){addToQueue("map_xml.aspx?mode=searchPostCode&postCode="+escape(postCode),2,true,postCodeLoaded)};function irelandSearchGeocoded(add){if(add.length==1){handleSearchResult(0,0,add[0].getAttribute("lat"),add[0].getAttribute("lon"),"","",add[0].getAttribute("name"),"","","",13)}else{var win=new MasternautWindows(document.body,0,0,450,300,"z-index:1000;",null,true,lang["map.search.res"],false,true,true,false,true,false,true,0,true);for(var i=0;i<add.length;i++){var lnk=addChildObj("div",win.divContent,"",add[i].getAttribute("name"),"link bullet");lnk.param=[add[i]];lnk.onclick=function(){irelandSearchGeocoded(this.param);win.close()}}if(add.length==0){addChildObj("div",win.divContent,null,lang["map.err.search2"])}else{_map.SetCenterAndZoom(new VELatLong(add[0].getAttribute("lat"),add[0].getAttribute("lon")),13)}}}this.SetRoutePlanner=function(masternautRoutePlanner){runMapEvent("onrouteplannerset",masternautRoutePlanner)};this.AddStopToRoutePlanner=function(name,stop){runMapEvent("onstopaddedtoplanner",name,stop)};this.ShowDriveTimeZone=function(lat,lon,journeyTime,weekday,hour,vehicleType){if(!vehicleType){vehicleType="lgv"}if(weekday==undefined||weekday==null){weekday=new Date().getDay()}if(hour==undefined||hour==null){hour=new Date().getHours()}var date=new Date(2008,8,14+parseInt(weekday,10),hour,0,0);addToQueue("map_xml.aspx?mode=timeAreaChart&lat="+lat+"&lon="+lon+"&date="+myDateTime(date)+"&journeyTime="+journeyTime+"&vehicleType="+vehicleType,3,true,driveTimeZoneLoaded)};function driveTimeZoneLoaded(xml){var tac=xml.getElementsByTagName("tac")[0];var coords=tac.getElementsByTagName("pt");var nbCoord=coords.length;var points=[];for(var i=0;i<nbCoord;i++){points.push(new VELatLong(parseFloat(coords[i].getAttribute("lat")),parseFloat(coords[i].getAttribute("lon"))))}var layer=self.DeleteShapes(MasternautMapLayer.Misc);self.AddPoly(1,layer,true,points,new VEColor(50,50,255,0.3),1,new VEColor(50,50,255,0.6),null,"","",1000);self.AddShape(2,layer,"",tac.getAttribute("lat"),tac.getAttribute("lon"),"/common/images/map/location_circle-blue.gif","","",1020);_map.SetMapView(layer.GetBoundingRectangle());if(self.menuTAC==null){self.menuTAC=new MasternautWindows(_popupContainer,8,48,287,null,"z-index:1001; font-size:8pt",null,false,lang["map.DTZ"],false,true,true,false,true,false,false,0,false,false,true);self.menuTAC.onClose=function(){self.DeleteShapes(MasternautMapLayer.Misc);self.menuTAC=null}}else{self.menuTAC.divContent.innerHTML=""}var coords=tac.getElementsByTagName("pt");addChildObj("span",self.menuTAC.divContent,null,lang["map.box.weekday"]+" ");var cmbWeekday=new MasternautCombo(addChildObj("input",self.menuTAC.divContent,"width:70px;"));cmbWeekday.options.addBatch([new Option(lang["map.day.1"],1),new Option(lang["map.day.2"],2),new Option(lang["map.day.3"],3),new Option(lang["map.day.4"],4),new Option(lang["map.day.5"],5),new Option(lang["map.day.6"],6),new Option(lang["map.day.0"],0)]);cmbWeekday.selectValue(new Date(tac.getAttribute("dateChart")).getDay());var cmbTime=new MasternautTimePicker(self.menuTAC.divContent,"&nbsp;",false,false,tac.getAttribute("timeChart"));addChildObj("span",self.menuTAC.divContent,null,"<br>"+lang["map.box.tra"]+" ");var cmbJourneyTime=new MasternautCombo(addChildObj("input",self.menuTAC.divContent,"width:63px"));for(var i=10;i<=90;i+=10){cmbJourneyTime.options.add(new Option(i+" "+lang["map.min"],i))}cmbJourneyTime.selectValue(tac.getAttribute("journeyTime"));var cmbVehicleType=new MasternautCombo(addChildObj("input",self.menuTAC.divContent,"margin-left:4px; width:41px"));cmbVehicleType.options.addBatch([new Option(lang["map.box.speedC"],"lgv"),new Option(lang["map.box.speedL"],"hgv")]);cmbVehicleType.selectValue(tac.getAttribute("vehicleType"));var btnTAC=addChildObj("span",self.menuTAC.divContent,"margin-left:3px",lang["map.menu.view"]+"<hr>","link");btnTAC.onclick=function(){self.ShowDriveTimeZone(tac.getAttribute("lat"),tac.getAttribute("lon"),cmbJourneyTime.value,cmbWeekday.value,cmbTime.value.substr(0,2),cmbVehicleType.value)};if(tac.getElementsByTagName("pc").length>0){pcXml=tac.getElementsByTagName("pc")[0];addChildObj("div",self.menuTAC.divContent,"height:100px; overflow-y:scroll","<b>"+lang["map.box.dtz1"]+"</b> "+pcXml.getAttribute("nam")+"<br><b>"+lang["map.box.dtz2"]+"</b> "+pcXml.getAttribute("large")+"<br><b>"+lang["map.box.dtz3"]+"</b> "+pcXml.getAttribute("nonRes")+"<br><b>"+lang["map.box.dtz4"]+"</b> "+pcXml.getAttribute("res"))}if(tac.getElementsByTagName("loc").length>0){addChildObj("div",self.menuTAC.divContent,null,"<hr><b>"+lang["map.box.dtz5"]+"</b> "+tac.getElementsByTagName("loc").length);new MasternautTable(addChildObj("div",self.menuTAC.divContent,"height:170px; overflow-y:scroll"),tac,"loc",[lang["map.nam"],lang["map.con.ref2"]],["name","ref"],0,self.ShowContact,[{type:"field",attribute:"id"},{type:"field",attribute:"name"},{type:"field",attribute:"lat"},{type:"field",attribute:"lon"}])}addChildObj("hr",self.menuTAC.divContent);var lnkSave=addChildObj("div",self.menuTAC.divContent,"",lang["map.box.dtz6"],"link bullet");lnkSave.onclick=function(){self.menuTAC.close();self.onTerritoryWindowOpened=function(){_newContact.DisplayDetail(0,"","","yellow","yellow","/common/images/map/location_territoryY.gif","",false,"","","","",0,0,"","","","","",coords,0)};showTerritoryWindow()};self.menuTAC.updateContentSize()}this.LoadLbs=function(lat,lon,name,radius){initMap();this.LbsPushpin=new MasternautLbsPushpin(lat,lon,name,radius);showLbs()};showLbs=function(){var lbsLayer=self.DeleteShapes(MasternautMapLayer.Lbs);var pixRadius=self.LbsPushpin.Radius/(self.GetKmPerPixel()*1000);self.AddRadius(1,lbsLayer,"radius",self.LbsPushpin.Lat,self.LbsPushpin.Lon,"green",Math.round(pixRadius/5)*5,1001);self.AddShape(0,lbsLayer,"lbs",self.LbsPushpin.Lat,self.LbsPushpin.Lon,"/common/images/map/mobile.gif",self.LbsPushpin.Name,"Radius: "+self.LbsPushpin.Radius,1013)};this.ShowTerritory=function(refresh){initMap();if(_territory==null||refresh){addToQueue("map_xml.aspx?mode=loadTerritory",2,false,function(xml){_territory=xml.getElementsByTagName("territory");territoryLoaded()})}else{territoryLoaded()}};function territoryLoaded(){var layerTerritory=self.GetShapeLayer(MasternautMapLayer.Territory);self.HideTerritory();for(var i=0;i<_territory.length;i++){var polyPoint=_territory[i].getElementsByTagName("coord");if(polyPoint.length>2){var points=new Array();for(var j=0;j<polyPoint.length;j++){points.push(new VELatLong(parseFloat(polyPoint[j].getAttribute("lat")),parseFloat(polyPoint[j].getAttribute("lon"))))}var terColor=_territory[i].getAttribute("color");var polyColor;switch(terColor){case"blue":polyColor=new VEColor(0,0,255,0.2);break;case"green":polyColor=new VEColor(0,255,0,0.2);break;case"#D2691E":polyColor=new VEColor(255,127,0,0.2);break;case"purple":polyColor=new VEColor(255,0,255,0.2);break;case"red":polyColor=new VEColor(255,0,0,0.2);break;case"yellow":polyColor=new VEColor(255,255,0,0.2);break}self.AddPoly(_territory[i].getAttribute("id"),layerTerritory,true,points,polyColor,1,polyColor,"/common/images/map/location_territory"+(terColor.substr(0,1)=="#"?"O":terColor.substr(0,1))+".gif",_territory[i].getAttribute("name"),_territory[i].getAttribute("ref"),1004)}}runMapEvent("onterritoryloaded")}function showTerritoryWindow(){if(_newContact==null){var win=new MasternautWindows(_popupContainer,8,48,260,200,"z-index:1001;",null,false,lang["map.ter.det"],false,true,true,false,true,false,false,0);win.onClose=function(){self.UnsetNewContact(true)};LazyLoad("/common/javascript/2.3/MasternautNewContact.js","MasternautNewContact",function(){_newContact=new MasternautNewContact(self,win.divContent,true);_newContact.onsave=win.close;self.onTerritoryWindowOpened();self.onTerritoryWindowOpened=null})}else{self.onTerritoryWindowOpened();self.onTerritoryWindowOpened=null}}this.EditTerritory=function(terCode){var territoryLayer=this.GetShapeLayer(MasternautMapLayer.Territory);for(var i=0;i<territoryLayer.GetShapeCount();i++){territoryLayer.GetShapeByIndex(i).Show()}var terShape=this.GetShapeByMasternautId(MasternautMapLayer.Territory,terCode);terShape.Hide();for(var i=0;i<_territory.length;i++){if(_territory[i].getAttribute("id")==terCode){break}}var terXml=_territory[i];var terColor=terXml.getAttribute("color");self.onTerritoryWindowOpened=function(){_newContact.DisplayDetail(terCode,terXml.getAttribute("name"),terXml.getAttribute("ref"),terColor,(terColor.substr(0,1)=="#"?"orange":terColor),"/common/images/map/location_territory"+(terColor.substr(0,1)=="#"?"O":terColor.substr(0,1))+".gif","",false,"","","","",0,0,"","","","","",terXml.getElementsByTagName("coord"),0)};showTerritoryWindow()};this.DeleteTerritory=function(terCode){if(confirm(lang["map.ter.sure"])){addToQueue("map_xml.aspx?mode=deleteTerritory&terCode="+terCode,2,true,function(){ShowNotify(lang["map.ter.del"]);self.ShowTerritory(true);runMapEvent("onterritorydeleted")})}};this.HideTerritory=function(){var layerTerritory=this.GetShapeLayer(MasternautMapLayer.Territory);layerTerritory.DeleteAllShapes();runMapEvent("onterritoryhidden")};this.ShowAllContacts=function(cat,caption,maxResult){initMap();if(caption){_contactCaption=caption}if(maxResult!=undefined){_contactMaxResult=maxResult;createCookie("maxContactDisplayed",_contactMaxResult,31)}if(_contactMaxResult==null){_contactMaxResult=readCookie("maxContactDisplayed");if(_contactMaxResult==null){_contactMaxResult=50}}if(cat!==null&&cat!==undefined){if(cat.join){this.SeeContactCategory=cat.join("|")}else{this.SeeContactCategory=cat}}if(_bottomRight.Latitude!=null){var url="map_xml.aspx?mode=loadContact&cat="+this.SeeContactCategory+"&minlat="+_bottomRight.Latitude+"&minLong="+_topLeft.Longitude+"&maxLat="+_topLeft.Latitude+"&maxLong="+_bottomRight.Longitude+"&withLocFamilyRefTable="+(_familyLoc==null?"1":"0")+"&maxResult="+_contactMaxResult+(_contactCaption.substring(0,4)=="cust"?"&getCustomField="+_contactCaption.substr(_contactCaption.length-1,1):"");addToQueue(url,3,false,contactsLoaded)}};function contactsLoaded(xml){_location=xml;var locGroup=xml.getElementsByTagName("fLoc");if(locGroup.length>0){_familyLoc=locGroup}var items=xml.getElementsByTagName("loc");var contactLayer=self.DeleteShapes(MasternautMapLayer.Contact);if(items.length>0){var meterPerPixel=self.GetKmPerPixel()*1000;var newShape=self.AddShape;var newRadius=self.AddRadius;var editedLocation=(_newContact?_newContact.GetLocCode():0);for(var i=0;i<items.length;i++){if(items[i].getAttribute("id")!=editedLocation){if(_contactCaption!="none"&&items[i].getAttribute(_contactCaption)!=null){self.AddCaption(items[i].getAttribute("id"),contactLayer,items[i].getAttribute("lat"),items[i].getAttribute("lon"),items[i].getAttribute(_contactCaption),items[i].getAttribute("name"),items[i].getAttribute("ref"),1005)}var locGif="/common/images/map/location_"+getLocFamilyGif(items[i].getAttribute("fam"))+".gif";var polyPoint=items[i].getElementsByTagName("poly");if(polyPoint.length==0){var pixRadius=items[i].getAttribute("rad")/meterPerPixel;newRadius(items[i].getAttribute("id"),contactLayer,"radius",items[i].getAttribute("lat"),items[i].getAttribute("lon"),(items[i].getAttribute("flag")=="0"?"blue":"red"),Math.round(pixRadius/5)*5,1001);newShape(items[i].getAttribute("id"),contactLayer,"contact",items[i].getAttribute("lat"),items[i].getAttribute("lon"),locGif,items[i].getAttribute("name"),items[i].getAttribute("ref"),1005)}else{if(polyPoint.length>2){var points=new Array();for(var j=0;j<polyPoint.length;j++){points.push(new VELatLong(parseFloat(polyPoint[j].getAttribute("lat")),parseFloat(polyPoint[j].getAttribute("lon"))))}var polyColor=new VEColor(0,0,255,0.2);if(items[i].getAttribute("flag")=="1"){polyColor=new VEColor(255,0,0,0.2)}self.AddPoly(items[i].getAttribute("id"),contactLayer,true,points,polyColor,1,polyColor,locGif,items[i].getAttribute("name"),items[i].getAttribute("ref"),1005)}}}}}runMapEvent("oncontactloaded",xml)}this.HideContact=function(){this.SeeContactCategory=-1;this.DeleteShapes(MasternautMapLayer.Contact);runMapEvent("oncontacthidden")};this.AddCaption=function(id,layer,lat,lon,caption,title,description,zIndex){if(!caption){return }var newShape=new VEShape(VEShapeType.Pushpin,[new VELatLong(parseFloat(lat),parseFloat(lon))]);newShape.SetTitle(title);newShape.SetDescription(description);newShape.SetCustomIcon("<span class='caption' style='position:relative; top:23px; left:-"+(caption.length*2.3-8)+"px'><nobr>"+caption+"</nobr></span>");newShape.SetZIndex(zIndex);newShape.MasternautId=id;if(layer!=null){layer.AddShape(newShape)}return newShape};this.AddShape=function(id,layer,cat,lat,lon,imageUrl,title,description,zIndex){initMap();var newShape=new VEShape(VEShapeType.Pushpin,[new VELatLong(parseFloat(lat),parseFloat(lon))]);newShape.SetTitle(title);newShape.SetDescription(description);newShape.SetCustomIcon(imageUrl);newShape.SetZIndex(zIndex);newShape.MasternautId=id;if(layer!=null){layer.AddShape(newShape)}return newShape};this.AddRadius=function(id,layer,cat,lat,lon,color,radius,zIndex){if(_is3D||radius<10||radius>1000){return }initMap();var newShape=new VEShape(VEShapeType.Pushpin,new VELatLong(parseFloat(lat),parseFloat(lon)));if(IsIE6){newShape.SetCustomIcon("<img src='/common/images/map/circle_"+color+".gif' width='"+(radius*2)+"' height='"+(radius*2)+"' style='position:relative; top:-"+(-11+radius)+"px; left:-"+(-11+radius)+"px; filter:alpha(opacity=30);'>")}else{newShape.SetCustomIcon("<img src='/common/images/map2/circle_"+color+".png' width='"+(radius*2)+"' height='"+(radius*2)+"' style='position:relative; top:-"+(-11+radius)+"px; left:-"+(-11+radius)+"px'>")}newShape.SetZIndex(zIndex);newShape.MasternautId=id;if(layer!=null){layer.AddShape(newShape)}return newShape};this.AddPoly=function(id,layer,polygon,points,fillColor,lineWidth,lineColor,icon,title,description,zIndex){var shapeType=(polygon&&points.length>2?VEShapeType.Polygon:VEShapeType.Polyline);var poly=new VEShape(shapeType,points);if(fillColor){poly.SetFillColor(fillColor)}poly.SetLineWidth(lineWidth);if(icon==null){poly.HideIcon()}poly.SetCustomIcon(icon);poly.SetLineColor(lineColor);poly.SetTitle(title);poly.SetDescription(description);poly.SetZIndex(zIndex);poly.MasternautId=id;layer.AddShape(poly);return poly};this.DeleteShapes=function(layerType){var layer=this.GetShapeLayer(layerType);layer.DeleteAllShapes();return layer};this.GetShapeLayer=function(layerType){initMap();return _map.GetShapeLayerByIndex(layerType)};this.GetShapeByMasternautId=function(layerType,masternautId){var layer=this.GetShapeLayer(layerType);for(var i=0;i<layer.GetShapeCount();i++){if(masternautId==layer.GetShapeByIndex(i).MasternautId){return layer.GetShapeByIndex(i)}}return null};function postCodeLoaded(xml){var win=new MasternautWindows(document.body,0,0,450,300,"z-index:1000;",null,true,lang["map.search.res"],false,true,true,false,true,false,true,0,true);streetXml=xml.getElementsByTagName("street");if(streetXml.length>0){for(var i=0;i<streetXml.length;i++){var lnk=addChildObj("div",win.divContent,"",streetXml[i].getAttribute("nam"),"link bullet");lnk.PcId=streetXml[i].getAttribute("id");lnk.onclick=function(){addToQueue("map_xml.aspx?mode=searchPostCodeDetail&id="+this.PcId+(_newContact?"&fullDetail=1":"")+"&road="+this.innerText+"&postCode="+xml.getElementsByTagName("postCode")[0].getAttribute("value"),3,true,function(xml){var addressXml=xml.getElementsByTagName("postCodeDetail")[0];handleSearchResult(0,0,addressXml.getAttribute("lat"),addressXml.getAttribute("lon"),addressXml.getAttribute("nam"),"",addressXml.getAttribute("rd"),addressXml.getAttribute("tow"),addressXml.getAttribute("pc"),addressXml.getAttribute("cy"),13)});win.close()}}}else{addChildObj("span",win.divContent,"","<br><center><i>"+lang["map.err.search4"]+".</i></center>")}}function getLocFamilyGif(familyLocCode){for(var i=0;i<_familyLoc.length;i++){if(_familyLoc[i].getAttribute("id")==familyLocCode){return _familyLoc[i].getAttribute("gif")}}}this.SetVehicleCaption=function(vehicleCaption){_vehicleCaption=vehicleCaption};this.SetLocatorCluster=function(locatorClustered){_locatorClustered=locatorClustered};this.ZoomToSelectedVehicleGroup=function(){var locatorLayer=self.GetShapeLayer(MasternautMapLayer.Locator);_map.SetMapView(locatorLayer.GetBoundingRectangle())};this.ZoomToVehicle=function(id){this.RedrawVehicleLivePushpin();if(id==0){this.ZoomToSelectedVehicleGroup()}else{if(_locator){var mcuXml=_locator.selectNodes("locator/group/loc[@mcuC="+id+"]");if(mcuXml[0]){if(mcuXml[0].getAttribute("priv")){alert(lang["map.err.pri"])}else{handleSearchResult(0,id,mcuXml[0].getAttribute("lat"),mcuXml[0].getAttribute("lon"),mcuXml[0].getAttribute("mcu"),"","","","","",14)}}else{showJourneyDatePicker("",id)}}}};this.ZoomToDriver=function(id){this.RedrawVehicleLivePushpin();if(id==0){this.ZoomToSelectedVehicleGroup()}else{if(_locator){var mcuXml=_locator.selectNodes("locator/group/loc[@driC="+id+"]");if(mcuXml[0]){if(mcuXml[0].getAttribute("priv")){alert(lang["map.err.pri"])}else{handleSearchResult(0,mcuXml[0].getAttribute("mcuC"),mcuXml[0].getAttribute("lat"),mcuXml[0].getAttribute("lon"),mcuXml[0].getAttribute("mcu"),"","","","","",14)}}else{alert(lang["map.err.noTrack"])}}}};function updateLocatorFilter(groupMCUCode,mcuCode,groupDriverCode,driverCode){var filterChanged=false;if(groupMCUCode!=undefined&&groupMCUCode!=null&&(groupMCUCode>=0||groupMCUCode instanceof Array)){if(groupMCUCode instanceof Array){_locatorFilter.groupMCUCode=groupMCUCode}else{_locatorFilter.groupMCUCode=[groupMCUCode]}filterChanged=true}if(mcuCode!=undefined&&mcuCode!=null&&mcuCode>=0){_locatorFilter.mcuCode=mcuCode;filterChanged=true}if(groupDriverCode!=undefined&&groupDriverCode!=null&&(groupDriverCode>=0||groupDriverCode instanceof Array)){if(groupDriverCode instanceof Array){_locatorFilter.groupDriverCode=groupDriverCode}else{_locatorFilter.groupDriverCode=[groupDriverCode]}filterChanged=true}if(driverCode!=undefined&&driverCode!=null&&driverCode>=0){_locatorFilter.driverCode=driverCode;filterChanged=true}if(filterChanged){runMapEvent("onlocatorfilterchanged",_locatorFilter)}}this.GetLocatorFilter=function(){return _locatorFilter};this.SelectVehicle=function(mcuCode){updateLocatorFilter(null,mcuCode,0,0);if(_locator==null||!_locatorShowing){this.LoadJourney((getParameter("journeyDate")!=""?getParameter("journeyDate"):new Date()),mcuCode)}else{this.ZoomToVehicle(mcuCode)}};this.FilterVehiclesOfSelectedGroup=function(mcuGroupCode){updateLocatorFilter(mcuGroupCode,0,0,0);this.RedrawVehicleLivePushpin();this.ZoomToSelectedVehicleGroup()};this.SelectDriver=function(driverCode){updateLocatorFilter(0,0,null,driverCode);if(_locator!=null&&_locatorShowing){this.ZoomToDriver(driverCode)}};this.FilterDriversOfSelectedGroup=function(driverGroupCode){updateLocatorFilter(0,0,driverGroupCode,0);this.RedrawVehicleLivePushpin();this.ZoomToSelectedVehicleGroup()};this.HideVehicleLive=function(){_locatorShowing=false;this.DeleteShapes(MasternautMapLayer.Locator);if(_locatorRefreshId){window.clearTimeout(_locatorRefreshId)}};this.ShowVehicleLive=function(mcuGroupCode,mcuCode,captionType,withAddress,withPrivate,driving,stop,idling,work,dontZoom){initMap();updateLocatorFilter(mcuGroupCode,mcuCode);_locatorShowing=true;if(_simulationStarted){return }if(captionType){_vehicleCaption=captionType}if(withAddress!=null&&withAddress!=undefined){_locatorWithAddress=withAddress}if(withPrivate!=null&&withPrivate!=undefined){_locatorWithPrivate=withPrivate}if(dontZoom){_locator=""}var url="map_xml.aspx?mode=loadVehicleLive&mcuGroupCode="+(mcuGroupCode?mcuGroupCode:0)+"&mcuCode="+(mcuCode?mcuCode:0)+"&withAddress="+(_locatorWithAddress?1:"")+"&withPrivate="+(_locatorWithPrivate?1:"")+"&driving="+(driving?"true":"")+"&stop="+(stop?"true":"")+"&idling="+(idling?"true":"")+"&work="+(work?"true":"");addToQueue(url,1,false,function(xml){locatorLoaded(xml,true)})};this.RedrawVehicleLivePushpin=function(captionType){if(_locator!=null){if(captionType){_vehicleCaption=captionType}locatorLoaded(_locator,false)}};function locatorLoaded(xml,refresh){if(!_locatorShowing){return }var veryFirstLoad=(_locator==null);_locator=xml;if(veryFirstLoad&&!_trackModeEnabled&&(_locator.getElementsByTagName("locator")[0].getAttribute("mcuCode")!="0"||_locator.getElementsByTagName("locator")[0].getAttribute("mcuGroupCode")!="0")){self.EnableTrackMode()}var items=_locator.getElementsByTagName("loc");if(items.length===0||!_locatorShowing){return }var orientation=self.GetOrientation();var newShape=self.AddShape;var locatorLayer=self.DeleteShapes(MasternautMapLayer.Locator);if(!_is3D&&_locatorClustered){var clusterOption=new VEClusteringOptions();clusterOption.Icon=new VECustomIconSpecification;clusterOption.Icon.Image="/common/images/map2/clustered_vehicles.gif";clusterOption.Callback=function(clusters){locatorLayer.Clusters=clusters};locatorLayer.SetClusteringConfiguration(VEClusteringType.Grid,clusterOption)}else{locatorLayer.SetClusteringConfiguration(VEClusteringType.None)}for(var i=0;i<items.length;i++){if(parseInt(items[i].getAttribute("lat"),10)!=0&&self.VehicleIsShown(items[i])){if(_vehicleCaption!="none"&&!_locatorClustered&&(_vehicleCaption!="mph"||(_vehicleCaption=="mph"&&!items[i].getAttribute("hideMileageAndSpeed")))){self.AddCaption(items[i].getAttribute("mcuC"),locatorLayer,items[i].getAttribute("lat"),items[i].getAttribute("lon"),(_vehicleCaption=="mph"?Speed(items[i].getAttribute(_vehicleCaption)):items[i].getAttribute(_vehicleCaption)),items[i].getAttribute("mcu"),items[i].getAttribute("dri"),1012)}newShape(items[i].getAttribute("mcuC"),locatorLayer,"mcu",items[i].getAttribute("lat"),items[i].getAttribute("lon"),"/common/images/map/vehicle_"+items[i].getAttribute("typ")+"_"+items[i].getAttribute("evn")+(items[i].getAttribute("isAsset")==null?"_"+getDegresGifVehicle(items[i].getAttribute("dir"),orientation):"")+".gif",items[i].getAttribute("mcu"),items[i].getAttribute("dri"),1012)}}if(refresh){if(_trackModeEnabled||veryFirstLoad){if(_locatorFilter.mcuCode!=0){self.ZoomToVehicle(_locatorFilter.mcuCode)}else{self.ZoomToSelectedVehicleGroup()}}if(_locatorRefreshId){window.clearTimeout(_locatorRefreshId)}var refreshDuration=parseInt(_locator.getElementsByTagName("locator")[0].getAttribute("refresh"),10);if(refreshDuration>0){_locatorRefreshId=setTimeout(function(){self.ShowVehicleLive()},1000*refreshDuration)}}if(_filterNearestVehicle){for(var i=0;i<_filterNearestVehicle.points.length;i++){self.AddPoly(i,locatorLayer,false,_filterNearestVehicle.points[i],null,3,new VEColor(0,255,0,0.4),"<span class='caption'>"+Distance(_filterNearestVehicle.distances[i])+"</span>","","",1000)}if(locatorLayer.GetShapeCount()>0){self.SetMapView(locatorLayer.GetBoundingRectangle())}}showPanicAlarm();runMapEvent("onlocatorloaded",xml)}function showPanicAlarm(){var alarms=_locator.getElementsByTagName("alarm");var layer=self.DeleteShapes(MasternautMapLayer.Alarm);for(var i=0;i<alarms.length;i++){var mcuXml=_locator.selectNodes("locator/group/loc[@mcuC="+alarms[i].getAttribute("mcuC")+"]")[0];self.AddShape(i,layer,"",alarms[i].getAttribute("lat"),alarms[i].getAttribute("lon"),"/common/images/map2/alarm.gif",mcuXml.getAttribute("mcu"),alarms[i].getAttribute("dat"),1025)}}this.VehicleIsShown=function(veh){var vehicleGroupOk=(indexOfValueInArray(0,_locatorFilter.groupMCUCode)!=-1||indexOfValueInArray(veh.parentNode.getAttribute("id"),_locatorFilter.groupMCUCode)!=-1);var vehicleOk=(_locatorFilter.mcuCode==0||_locatorFilter.mcuCode==veh.getAttribute("mcuC"));var driverGroupOk=(indexOfValueInArray(0,_locatorFilter.groupDriverCode)!=-1||indexOfValueInArray(veh.getAttribute("driG"),_locatorFilter.groupDriverCode)!=-1);var driverOk=(_locatorFilter.driverCode==0||_locatorFilter.driverCode==veh.getAttribute("driC"));var businessKey=!veh.getAttribute("priv");var NearestFilterOk=(_filterNearestVehicle==null||_filterNearestVehicle[veh.getAttribute("mcuC")]==true);return vehicleGroupOk&&vehicleOk&&driverGroupOk&&driverOk&&businessKey&&NearestFilterOk};this.ShowOsGridRef=function(OSRef){addToQueue("map_xml.aspx?mode=loadLatLongFromOSRef&OSRef="+OSRef,2,true,function(xml){latLongTag=xml.getElementsByTagName("latLongFromOs");handleSearchResult(0,0,latLongTag[0].getAttribute("lat"),latLongTag[0].getAttribute("lon"),"OS Grid reference: "+latLongTag[0].getAttribute("OSRef"),"","OS Grid reference: "+latLongTag[0].getAttribute("OSRef"),"","","",16)})};this.HideRouteGeofence=function(){var routeGeofence=self.GetShapeLayer(MasternautMapLayer.RouteGeofence);routeGeofence.DeleteAllShapes();_routeGeofence=null};this.DeleteRouteGeofence=function(id){if(id==null){alert(lang["map.geo.err"])}else{if(confirm(lang["map.geo.sure"])){addToQueue("map_xml.aspx?mode=deleteRouteGeofence&id="+id,3,true,function(xml){ShowNotify(lang["map.geo.del"]);self.DeleteShapes(MasternautMapLayer.RouteGeofence);runMapEvent("onroutegeofencedeleted")})}}};this.ShowRouteGeofence=function(id){initMap();addToQueue("map_xml.aspx?mode=loadRouteGeofence&id="+id,2,true,routeGeofenceLoaded)};function routeGeofenceLoaded(xml){_routeGeofence=xml.getElementsByTagName("point");var layerRouteGeofence=self.DeleteShapes(MasternautMapLayer.RouteGeofence);var points=[];var newShape=self.AddShape;for(var i=0;i<_routeGeofence.length;i++){points.push(new VELatLong(parseFloat(_routeGeofence[i].getAttribute("lat")),parseFloat(_routeGeofence[i].getAttribute("lon"))));if(i==_routeGeofence.length-1||_routeGeofence[i].getAttribute("action")!=_routeGeofence[i+1].getAttribute("action")){self.AddPoly(i,layerRouteGeofence,false,points,null,2,_routeGeofence[i].getAttribute("action")=="1"?new VEColor(255,0,0,1):new VEColor(0,0,255,1),null,"","",1000);points=[new VELatLong(parseFloat(_routeGeofence[i].getAttribute("lat")),parseFloat(_routeGeofence[i].getAttribute("lon")))]}newShape(i,layerRouteGeofence,"",_routeGeofence[i].getAttribute("lat"),_routeGeofence[i].getAttribute("lon"),"/common/images/map/geofence_"+(_routeGeofence[i].getAttribute("action")=="1"?"red":"blue")+".gif",_routeGeofence[i].getAttribute("min"),_routeGeofence[i].getAttribute("html"),1006)}_map.SetMapView(layerRouteGeofence.GetBoundingRectangle())}}function MasternautJourneySimulator(M,G,N){var O=this;var D=M;var K=G;var F=D.GetShapeLayer(MasternautMapLayer.Journey);var L=0;var U=(D.Is3D()?4000:100);var V;var B;var H;var Q;var A;var E=[];var P=false;function S(){B=new MasternautWindows(N,8,D.Journey.Menu.GetBottom()+2,177,127,"z-index:1001; ",null,false,lang["map.box.play"],false,true,true,false,true,false,false,0);B.onClose=function(X){O.Stop(X,true)};H=addChildObj("div",B.divContent,null,"<b>"+lang["map.dat"]+":<br>"+lang["map.dri"]+":<br>"+lang["map.speed"]+":<br>"+lang["map.stop"]+":</b>");var W=addChildObj("div",B.divContent,"height:12px; width:155px; margin-top:10px; background-image:url(/common/images/map2/playBar.gif); background-repeat:repeat-x;");Q=addChildObj("div",W,"position:absolute; left:0px; top:"+W.offsetTop+"px; height:12px; width:9px; margin-top:-5px; background-image:url(/common/images/map2/playCursor.gif);");addImage(B.divContent,"/common/images/map2/control_eject_blue.png","Stop",O.Stop,"margin-right:12px; margin-left:17px");addImage(B.divContent,"/common/images/map2/control_previous_blue.png","Previous stop",O.PreviousStop,"margin-right:5px");addImage(B.divContent,"/common/images/map2/control_rewind_blue.png","Slower",function(){U+=(U<1500?400:0)},"margin-right:5px");A=addImage(B.divContent,"/common/images/map2/control_play_blue.png","Play",function(){if(this.src.indexOf("play")>0){O.Start()}else{O.Pause()}},"margin-right:5px");addImage(B.divContent,"/common/images/map2/control_fastforward_blue.png","Faster",function(){U-=(U>400?400:0)},"margin-right:5px");addImage(B.divContent,"/common/images/map2/control_next_blue.png","Next stop",O.NextStop,"margin-right:5px");J()}function J(){var X=[23,68,113,158,203,248,293,338];var W=K[0].parentNode.parentNode.getAttribute("typ");for(var Y=0;Y<X.length;Y++){E[X[Y]]=new Image();E[X[Y]].src="/common/images/map/vehicle_"+W+"_5_"+X[Y]+".gif"}}function I(){var X=[23,68,113,158,203,248,293,338];var W=true;for(var Y=0;Y<X.length;Y++){W=W&&imageIsLoaded(E[X[Y]])}return W}this.onstop=function(){};this.Start=function(){A.src="/common/images/map2/control_pause_blue.png";A.alt="Pause";T()};this.Stop=function(W,X){if(V){clearTimeout(V)}if(!X){B.close()}B=null;D.Journey.Simulator=null;O.onstop()};this.Pause=function(){if(V){clearTimeout(V)}A.src="/common/images/map2/control_play_blue.png";A.alt="Play"};this.PreviousStop=function(){if(V){clearTimeout(V)}var W=parseInt(K[L].parentNode.getAttribute("nb"),10);while(L>0&&parseInt(K[L].parentNode.getAttribute("nb"),10)>W-2){L--}L++;if(A.innerHTML.indexOf("pause")>0){T()}else{C()}};this.NextStop=function(){if(V){clearTimeout(V)}var W=parseInt(K[L].parentNode.getAttribute("nb"),10);while(L<K.length-1&&parseInt(K[L].parentNode.getAttribute("nb"),10)<W+1){L++}if(A.innerHTML.indexOf("pause")>0){T()}else{C()}};function C(){var W=L;var X=K[W].getAttribute("det").split("~");var Y=K[W].getAttribute("dir");if(D.Is3D()){D.Control3D(K[W].getAttribute("lat"),K[W].getAttribute("lon"),220,-20,K[W].getAttribute("dir"));Y=0}F.DeleteAllShapes();D.AddShape(W,F,"simulate",K[W].getAttribute("lat"),K[W].getAttribute("lon"),E[getDegresGifVehicle(Y,"North")].src,X[0],K[W].parentNode.getAttribute("dri"),1012);H.innerHTML="<b>"+lang["map.time"]+": </b>"+X[0]+"<br><b>"+lang["map.dri"]+": </b>"+K[W].parentNode.getAttribute("dri")+(D.Journey.hideMileageAndSpeed?"":"<br><b>"+lang["map.speed"]+": </b>"+Speed(X[1]))+"<br><b>"+lang["map.stop"]+": </b>"+(parseInt(K[W].parentNode.getAttribute("nb"),10)+1)+"/"+(parseInt(K[K.length-1].parentNode.getAttribute("nb"),10)+1);R()}function R(){var X=0;var W=145;Q.style.left=(X+L*(W-X)/K.length)+"px";Q.style.top=Q.parentElement.offsetTop+"px"}function T(){if(!P){if(!I()){V=setTimeout(T,U);return }else{P=true}}C();L+=(U>0?1:-1);if(L<K.length&&L>0){V=setTimeout(T,U)}else{L=0}}S()}function MasternautJourney(A,D){var I=A;var K=D.getElementsByTagName("item");var B=D.getElementsByTagName("mvi");var H=D.getElementsByTagName("temp");var G=D.getElementsByTagName("gritter");var F=K;var L=this;var E=D.getElementsByTagName("journey")[0];this.info=D.getElementsByTagName("info")[0];this.mcuCode=E.getAttribute("mcuCode");this.mcuName=E.getAttribute("mcuName");this.date=E.getAttribute("date");this.length=K.length;this.stopsNb=D.getElementsByTagName("stop").length;this.currentStop=0;this.hourMin="00:00";this.hourMax="24:00";this.shiftStart=E.getAttribute("shiftStart");this.withSpeedInfringement=E.getAttribute("withSpeedInfringement")=="1";this.vehicleSpeedCategory=E.getAttribute("vehSpeedCat");this.hideMileageAndSpeed=E.getAttribute("hideMileageAndSpeed")=="1";this.isAsset=E.getAttribute("isAsset")=="1";this.lastDrive=E.getAttribute("lastDrive");this.maxLon=-180;this.minLon=180;this.maxLat=-90;this.minLat=90;this.HasMVI=function(){return(B.length>0)};this.GetSummaryXML=function(){var P=D.getElementsByTagName("stop");for(var N=0;N<P.length;N++){P[N].setAttribute("no",parseInt(P[N].getAttribute("nb"),10)+1);var O=P[N].getElementsByTagName("item");P[N].setAttribute("start",O[0].getAttribute("det").split("~")[0]);P[N].setAttribute("stop",O[O.length-1].getAttribute("det").split("~")[0]);var M="";if(O[O.length-1].getAttribute("det").split("~").length>=4){M=O[O.length-1].getAttribute("det").split("~")[4].replace("<br>",", ")}P[N].setAttribute("add",M)}return D};function C(M){if(M.length>0){L.maxLon=-180;L.minLon=180;L.maxLat=-90;L.minLat=90;for(var O=0;O<M.length;O++){var N=M[O].getAttribute("det").split("~")[0];if(L.hourMin<=N&&N<=L.hourMax){if(M[O].getAttribute("lon")>L.maxLon){L.maxLon=M[O].getAttribute("lon")}if(M[O].getAttribute("lon")<L.minLon){L.minLon=M[O].getAttribute("lon")}if(M[O].getAttribute("lat")>L.maxLat){L.maxLat=M[O].getAttribute("lat")}if(M[O].getAttribute("lat")<L.minLat){L.minLat=M[O].getAttribute("lat")}}}}}this.GetTemperatureAtTime=function(N){if(H.length>0){for(var M=0;M<H.length-1;M++){if(H[M].getAttribute("hr")<=N&&H[M+1].getAttribute("hr")>N){return[J(N,M,1),J(N,M,2),J(N,M,3),J(N,M,4)]}}}return[]};function J(P,N,O){var M=(TimeToSeconds(P)-TimeToSeconds(H[N].getAttribute("hr")))/(TimeToSeconds(H[N+1].getAttribute("hr"))-TimeToSeconds(H[N].getAttribute("hr")));return Math.round((parseFloat(H[N].getAttribute("t"+O))+M*(parseFloat(H[N+1].getAttribute("t"+O))-parseFloat(H[N].getAttribute("t"+O))))*10)/10}this.GetCurrentStopXml=function(M){var N=(this.currentStop>0?"[@nb="+(this.currentStop-1)+"]":"");return D.selectNodes("journey/stop"+N+"/item"+(M!=undefined?M:""))};this.ShowJourneyInCurrentView=function(O,N){I.DeleteShapes(MasternautMapLayer.Journey);I.DeleteShapes(MasternautMapLayer.Mvi);var M="[@lat<="+O.Latitude+" and @lat>="+N.Latitude+" and @lon>="+O.Longitude+" and @lon<="+N.Longitude+"]";F=this.GetCurrentStopXml(M);this.AddJourneyPOI(O,N)};this.ZoomToStop=function(P,M){L.currentStop=P;var O=L.GetCurrentStopXml();var N;var R;var Q=0;if(P>0){N=O[0].parentNode.getAttribute("duration");R=O[0].parentNode.getAttribute("dist");Q=O[0].parentNode.getAttribute("cost")}else{N=L.info.getAttribute("duration");R=L.info.getAttribute("dist");Q=L.info.getAttribute("cost")}M.innerHTML="<br><b>"+lang["map.dur"]+"</b>: "+N;if(!L.hideMileageAndSpeed){M.innerHTML+="<br><b>"+lang["map.box.dist"]+"</b>: "+Distance(R)+"<br>"+(Q>0?"<b>"+(P>0?lang["map.box.jCost"]:lang["map.box.shiftC"])+"</b>: "+Cost(Q)+"<br>":"")}C(O);I.ZoomToJourney()};this.ZoomToTime=function(N,M){L.hourMin=N;L.hourMax=M;C(F);I.ZoomToJourney()};this.AddJourneyPOI=function(Y,U){var V=0;var N=I.GetKmPerPixel();var e=I.AddShape;var X=[];var O=I.GetOrientation();for(var Z=0;Z<F.length;Z++){var d=F[Z];var R=d.getAttribute("det").split("~");var h=parseFloat(R[2]);if(L.hourMin<=R[0]&&R[0]<=L.hourMax){if(h<V){V=0}var Q=(d.getAttribute("type")=="arrow"||d.getAttribute("type")=="arrowG"||d.getAttribute("type")=="arrowO");var g=(d.getAttribute("type")=="arrowR");if(!Q||L.isAsset||L.hideMileageAndSpeed||h-V>N*18){var W;switch(d.getAttribute("type")){case"idling":W=1008;break;case"stop":W=1009;break;case"start":W=1010;break;default:W=1007;break}var S=(Q||g?"_"+getDegresGifVehicle(d.getAttribute("dir"),O):(d.getAttribute("sType")?"_"+d.getAttribute("sType"):""));var c=(L.isAsset&&Q?"asset_moving":d.getAttribute("type")+S);X.push(e(Z,null,d.getAttribute("type"),d.getAttribute("lat"),d.getAttribute("lon"),"/common/images/map/"+c+".gif",d.parentNode.getAttribute("dri"),R[0]+(d.getAttribute("max")?" - "+Speed(R[1])+"/"+Speed(d.getAttribute("max")):""),W));V=h}}}var a=I.GetShapeLayer(MasternautMapLayer.Journey);a.AddShape(X);X=[];if(F.length>0&&B.length>0){var b=F[0].getAttribute("det").split("~")[0];var T=F[F.length-1].getAttribute("det").split("~")[0];var P=D.selectNodes("journey/mvi[@lat<="+Y.Latitude+" and @lat>="+U.Latitude+" and @lon>="+Y.Longitude+" and @lon<="+U.Longitude+"]");for(var Z=0;Z<P.length;Z++){if(b<=P[Z].getAttribute("dat")&&P[Z].getAttribute("dat")<=T){X.push(e(Z,f,"action",P[Z].getAttribute("lat"),P[Z].getAttribute("lon"),"/common/images/map/action_"+(P[Z].getAttribute("on")==1?"on":"off")+".gif",P[Z].getAttribute("dat"),P[Z].getAttribute("cap"),1008))}}}if(F.length>0&&G.length>0){var M=D.selectNodes("journey/gritter[@lat<="+Y.Latitude+" and @lat>="+U.Latitude+" and @lon>="+Y.Longitude+" and @lon<="+U.Longitude+"]");for(var Z=0;Z<M.length;Z++){X.push(e(Z,f,"action",M[Z].getAttribute("lat"),M[Z].getAttribute("lon"),"/common/images/map/action_on.gif",M[Z].getAttribute("dat"),"Gritter",1008))}}var f=I.GetShapeLayer(MasternautMapLayer.Mvi);f.AddShape(X)};this.GetPoiDetail=function(N){var M=F[N].getAttribute("det").split("~");M.lat=F[N].getAttribute("lat");M.lon=F[N].getAttribute("lon");M.driver=F[N].parentNode.getAttribute("dri");M.direction=F[N].getAttribute("dir");return M};this.GetMviDetail=function(N){var M=D.selectNodes('journey/mvi[@dat="'+N+'"]')[0];if(!M){M=D.selectNodes('journey/gritter[@dat="'+N+'"]')[0]}return M};this.CalculateBestRoute=function(Q){var N=new VERouteOptions();N.RouteOptimize=(Q?VERouteOptimize.MinimizeDistance:VERouteOptimize.MinimizeTime);N.ShowErrorMessages=false;N.DrawRoute=false;I.GetVEMap().SetClientToken(readCookie("VEToken"));N.RouteCallback=function(R){I.GetVEMap().SetClientToken(null);hideWaitWindow();if(R.ShapePoints.length>1){var S=I.DeleteShapes(MasternautMapLayer.Search);I.AddPoly(0,S,false,R.ShapePoints,null,7,new VEColor(75,225,255,0.7),null,"","",1004)}var T=new Date(2000,1,1,0,0,R.Time);T=(T.getDate()>1?T.getDate()-1+" day"+(T.getDate()>2?"s":"")+" ":"")+(T.getHours()>=10?T.getHours():"0"+T.getHours())+":"+(T.getMinutes()>=10?T.getMinutes():"0"+T.getMinutes())+":"+(T.getSeconds()>=10?T.getSeconds():"0"+T.getSeconds());L.Menu.UpdateBestRouteDetail(T,R.Distance.toFixed(1))};var M=this.GetCurrentStopXml();var P=[];for(var O=0;O<M.length;O++){if(O==0||O==M.length-1||M[O].parentNode.getAttribute("nb")!=M[O-1].parentNode.getAttribute("nb")){P.push(new VELatLong(M[O].getAttribute("lat"),M[O].getAttribute("lon")))}}if(P.length>25){alert(lang["map.rteHas"]+" "+P.length+" "+lang["map.rteHas2"]);return }showWaitWindow();I.GetDirections(P,N)};this.dispose=function(){if(this.Simulator){this.Simulator.Stop()}I.DeleteShapes(MasternautMapLayer.Journey);I.DeleteShapes(MasternautMapLayer.Mvi);I.DeleteShapes(MasternautMapLayer.Search)};C(K)}var MasternautMapLayer={Locator:1,Contact:2,Territory:3,Journey:4,Traffic:5,Search:6,Lbs:7,Mvi:8,RouteGeofence:9,Job:10,POI:11,TrafficCam:12,ZoneLCC:13,ZoneLEZ:14,Alert:15,Misc:16,Watch:17,HGVRestriction:18,RoutePlanner:19,ShapeDrawer:20,Alarm:21};function MasternautLbsPushpin(C,D,B,A){this.Lat=C;this.Lon=D;this.Name=B;this.Radius=A}function getDegresGifVehicle(B,A){B=parseInt(B,10);switch(A){case"East":B=(B>=90?B-90:B+270);break;case"West":B=(B<=270?B+90:B-270);break;case"South":B=(B>=180?B-180:B+180);break}if(B>=0&&B<=45){return 23}if(B>=46&&B<=90){return 68}if(B>=91&&B<=135){return 113}if(B>=136&&B<=180){return 158}if(B>=181&&B<=225){return 203}if(B>=226&&B<=270){return 248}if(B>=271&&B<=315){return 293}if(B>=316&&B<=360){return 338}}document.write('<script type="text/javascript" src="/common/javascript/2.3/MasternautObjects.js"><\/script>');document.write('<script type="text/javascript" src="'+window.location.protocol+"//ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt="+lang["map.ve.mkt"]+(window.location.protocol=="https:"?"&s=1":"")+'"><\/script>');
