﻿var vMapMode="view";var maxZoom=14;var markersArray=[];var marker="";var html="";var arAllRoutesOnMap=[];var UserSearchField;var existingMarkers={};var geo=new GClientGeocoder();var MasterSessionTimer;var isVagueCount=0;var CurrentRouteActive=0;var CurrentRouteActiveNotOnMap="NOT ON MAP";var bounds=new GLatLngBounds();var polyline1_1=new GPolyline();var fittingRouteToMap=false;var TempEndMarkers=[];var TempStartMarkers=[];var LoadFromRouteIDCalled=false;var bolAjaxLoadInProgress=false;var KillSessionOnNextCall=false;function fnremoveRoutesFromMap(){if(arAllRoutesOnMap.length>0){map.removeOverlay(arAllRoutesOnMap[0]);arAllRoutesOnMap.pop()}if(TempEndMarkers.length>0){map.removeOverlay(TempEndMarkers[0]);TempEndMarkers.pop()}if(TempStartMarkers.length>0){map.removeOverlay(TempStartMarkers[0]);TempStartMarkers.pop()}}function DrawRouteOntoMap(a,b,c,d,e){fnremoveRoutesFromMap();polyline1_1=new GPolyline.fromEncoded({color:"#0000ff",weight:4,opacity:0.8,points:a,levels:b,zoomFactor:2,numLevels:18});arAllRoutesOnMap.push(polyline1_1);map.addOverlay(polyline1_1);TempEndMarkers.push(d);map.addOverlay(d);TempStartMarkers.push(e);map.addOverlay(e);if(c){}bolAjaxLoadInProgress=false}function StartMap(){if(!GBrowserIsCompatible()){alert("Sorry, the Google Maps API is not compatible with this browser")}else{popUpBox("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Loading map...</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");StartMapSub();var b=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(75,7));b.apply(document.getElementById("MapWorkingMsg"));map.getContainer().appendChild(document.getElementById("MapWorkingMsg"));map.enableDoubleClickZoom();map.enableContinuousZoom();document.getElementById("PostCodestatus").style.display="block";document.getElementById('FirstLoad').value="0";var x=map.getMapTypes();GEvent.addListener(map,'moveend',function(){popUpBoxClose();var a=map.getCenter();if(map.getZoom()>=maxZoom){if(fittingRouteToMap){}else{GetLocationsLoader()}StatusMsg("Tip: Click and drag the map to find more routes.")}else{StatusMsg("Tip: Zoom in to find Cycle routes.")}});AutoRunPostCodeSearch();loadOff();setSessionTimer()}popUpBoxClose()}function LoadFromRouteID(f){var g="/dotnet/GetRoute_MiniDetail.aspx?routeId="+f;GDownloadUrl(g,function(a,b){if(b==200){var c=GXml.parse(a);var d=c.documentElement.getElementsByTagName("startLat")[0].firstChild.nodeValue;var e=c.documentElement.getElementsByTagName("startLng")[0].firstChild.nodeValue;LoactionOfStartMarker=new GLatLng(d,e);map.setCenter(LoactionOfStartMarker,16);LoadFromRouteIDCalled=f}})}function ajaxLoadRoute(q){if(bolAjaxLoadInProgress==true){bolAjaxLoadInProgress=false;CurrentRouteActive=0;ajaxLoadRoute(q)}else{bolAjaxLoadInProgress=true;if(CurrentRouteActive!=q){LHS_ItemDIV="#mapInfoData_"+CurrentRouteActive;$(LHS_ItemDIV).removeClass('selected');RemoveChildDivID="#LHSRouteDetails_"+CurrentRouteActive;$(RemoveChildDivID).fadeOut(500,function(){$(RemoveChildDivID).remove()});if(CurrentRouteActive==CurrentRouteActiveNotOnMap){tempCurrentRouteActive=CurrentRouteActive;CurrentRouteActive=q;fnremoveRoutesFromMap();removeMarkerText(tempCurrentRouteActive);removeMarker(tempCurrentRouteActive)}}if(CurrentRouteActive!=q){LHS_ItemDIV="#mapInfoData_"+q;CurrentRouteActive=q;var r="/dotnet/GetRoute_MiniDetail.aspx?routeId="+q;GDownloadUrl(r,function(c,d){if(d==200){var e=GXml.parse(c);var f=e.documentElement.getElementsByTagName('Route');var g=e.documentElement.getElementsByTagName("encodePoints")[0].firstChild.nodeValue;var h=e.documentElement.getElementsByTagName("encodeLevels")[0].firstChild.nodeValue;var i=e.documentElement.getElementsByTagName("Distance")[0].firstChild.nodeValue;var j=e.documentElement.getElementsByTagName("RouteTitle")[0].firstChild.nodeValue;var k=e.documentElement.getElementsByTagName("RouteDescription")[0].firstChild.nodeValue;var l=e.documentElement.getElementsByTagName("startLat")[0].firstChild.nodeValue;var m=e.documentElement.getElementsByTagName("startLng")[0].firstChild.nodeValue;var n=e.documentElement.getElementsByTagName("endLat")[0].firstChild.nodeValue;var o=e.documentElement.getElementsByTagName("endLong")[0].firstChild.nodeValue;var p=e.documentElement.getElementsByTagName("DistanceUnits")[0].firstChild.nodeValue;LoactionOfEndMarker=new GLatLng(n,o);LoactionOfStartMarker=new GLatLng(l,m);StartMarker=new GMarker(LoactionOfStartMarker,{icon:genDynMarker("d_bubble_icon_text_small","bicycle"," Start of route ","000000","20AF34"),draggable:false,dragCrossMove:false,bouncy:false,zIndexProcess:function(a,b){return 1}});EndMarker=new GMarker(LoactionOfEndMarker,{icon:genDynMarker("d_bubble_icon_text_small","bicycle","End:"+i+p,"000000","E80C2A"),draggable:false,dragCrossMove:false,bouncy:false,zIndexProcess:function(a,b){return 1}});debugBox("- + - + - + - + - + - + - + - + - + -     StartMarker:"+StartMarker);DrawRouteOntoMap(g,h,false,EndMarker,StartMarker);if(j==""){loadOff();popUpBox("<b>Error:</b> invalid details to retrieve route id:"+q);return}$('#LHSRouteDetails_'+q).remove();$(LHS_ItemDIV).append('<div id="LHSRouteDetails_'+q+'">'+k+'<br /><a href="javascript:ShowRouteInFull('+q+');">Show full route</a></div>').fadeIn(9000);$(LHS_ItemDIV).addClass('selected')}})}}}function createMarker(c,d,e,f,g,h){var i=new GMarker(c,{icon:genDynMarker("d_bubble_icon_text_small","bicycle",f,"000000","ffffff"),draggable:false,dragCrossMove:false,bouncy:true,zIndexProcess:function(a,b){return 1}});var j='<h2>'+d+'</h2> '+e;GEvent.addListener(i,'click',function(){ajaxLoadRoute(g)});markersArray[g]=new Array(0);markersArray[g][0]=i;markersArray[g][1]=h;if(h==true){isVagueCount++}return i}function createSidebarEntry(a,b,c,d,e){var f=document.createElement('div');var g="mapInfoData_"+e;var h="";f.id=g;f.className="mapInfoData";var i=b+h;f.innerHTML=i;f.style.cursor='pointer';f.style.marginBottom='5px';GEvent.addDomListener(f,'click',function(){GEvent.trigger(a,'click')});GEvent.addDomListener(f,'mouseover',function(){if(e!=CurrentRouteActive){$(f).addClass('RouteItemHover')}});GEvent.addDomListener(f,'mouseout',function(){$(f).removeClass('RouteItemHover')});return f}function fitMapMultiMarkers(){fittingRouteToMap=true;map.setZoom(map.getBoundsZoomLevel(bounds));map.setCenter(bounds.getCenter());fittingRouteToMap=false}function GetLocationsLoader(){if(map.getZoom()>=maxZoom){loadOn();var u=document.getElementById('FirstLoad').value;var v=map.getBounds();var w=v.getSouthWest();var x=v.getNorthEast();MapBounds_CurrentNE=x.toUrlValue();MapBounds_CurrentSW=w.toUrlValue();var y='ne='+MapBounds_CurrentNE+'&sw='+MapBounds_CurrentSW;MapBounds_OldNE_HOLD=MapBounds_OldNE;MapBounds_OldSW_HOLD=MapBounds_OldSW;MapBounds_OldNE=MapBounds_CurrentNE;MapBounds_OldSW=MapBounds_CurrentSW;var z=document.getElementById("UsersGeoCode").value;if(z!=0){KillSessionOnNextCall=true;y+="&session=kill"}if(KillSessionOnNextCall==true){map.clearOverlays();MapBounds_OldNE_HOLD="49.073416,-0.331736";MapBounds_OldSW_HOLD="49.039668,-0.377741 ";document.getElementById("UsersGeoCode").value="0";document.getElementById('cycle_route_area').innerHTML="";KillSessionOnNextCall=false}y+='&old_ne='+MapBounds_OldNE_HOLD+'&old_sw='+MapBounds_OldSW_HOLD;var A="/dotnet/GetRoutes.aspx?"+y+"&user="+z;GDownloadUrl(A,function(a,b){if(b==200){var c=GXml.parse(a);var d=c.documentElement.getElementsByTagName('Route');var e=c.documentElement.getElementsByTagName('AutoSizeMap')[0].firstChild.nodeValue;var f=document.getElementById('cycle_route_area');if(d.length==0){loadOff();return}var g="";var h="";for(var i=0;i<d.length;i++){var j=GetValue(d[i].getElementsByTagName("RouteTitle")[0]);var k=GetValue(d[i].getElementsByTagName("Distance")[0]);var l=GetValue(d[i].getElementsByTagName("Marker")[0]);var m=GetValue(d[i].getElementsByTagName("styleUrl")[0]);var n=GetValue(d[i].getElementsByTagName("AddRemove")[0]);var o=GetValue(d[i].getElementsByTagName("RouteId")[0]);var p=GetValue(d[i].getElementsByTagName("DistanceUnits")[0]);var q=GetValue(d[i].getElementsByTagName("RouteDescriptionSummary")[0]);if(u!="1"&&n=="NoChange"){n="Add"}j=j.replace(/''/,"'");coordinatesXY=l.split(",");var r=new GLatLng(coordinatesXY[1],coordinatesXY[0]);var s="";bounds.extend(r);h=' - '+k+'km';s=''+k+'km';windowContent="";pageContent=q;nameDiv='<div class="LHSItemDistanceBox">'+k+p+'</div><div class="LHSItemTitle">'+j+'</div><div class="clearer"></div>';IconStyle=s;IsVague=false;if(m=="#UnverifiedMarkerIcon"){windowContent+='<br /><em>Note: map indicates street location.</em>';pageContent+="(?)";IsVague=true}if(n=="Add"){if(o!=CurrentRouteActive){var t=createMarker(r,j,windowContent,IconStyle,o,IsVague);map.addOverlay(t);var g=createSidebarEntry(t,nameDiv,pageContent,k,o);f.appendChild(g);if(o==LoadFromRouteIDCalled){ajaxLoadRoute(LoadFromRouteIDCalled)}}else{}}if(n=="Remove"){removeMarker(o);removeMarkerText(o)}}if(e=="True"){fitMapMultiMarkers();KillSessionOnNextCall=true}document.getElementById('FirstLoad').value="1"}else if(b==-1){popUpBox('Oops! There seems to be some technical issues. <a href="javascript:GetLocationsLoader();">Try again?</a>')}else{popUpBox('Oops! There seems to be some technical issues. Please try again shortly.')}loadOff()})}}function ShowRouteInFull(a){fittingRouteToMap=true;ajaxLoadRoute(a);fittingRouteToMap=true;bounds=polyline1_1.getBounds();map.setZoom(map.getBoundsZoomLevel(bounds));map.setCenter(bounds.getCenter());fittingRouteToMap=false}function removeMarkerText(a){if(a!=CurrentRouteActive){$('#mapInfoData_'+a).fadeOut(500,function(){$('#mapInfoData_'+a).remove()})}else{}}function removeMarker(a){try{map.removeOverlay(markersArray[a][0]);if(markersArray[a][1]==true){isVagueCount--}delete markersArray[a][0]}catch(err){}}