
MMAttachEvent(window,'load',onLoad);var mapviewer,route_finder,route,loading;var max_zindex=1000;if(!MMIsSupportedBrowser()){document.write('&lt;p&gt;Sorry! Your browser does not support our maps.&lt;'+'/p&gt;');};function onLoad()
{var map=document.getElementById('MMmap');if(map==null)return false;if(initialLat==''||initialLong==''){$('#mapWrapper').hide();return false;};map.innerHTML="<img src=\"http://images.thomsonlocal.com/tlc/loading.gif\" alt=\"loading map\" id=\"mapLoading\" />";if(initialLat==undefined||initialLong==undefined){map.innerHTML="<p style=\"margin:1em;\">Sorry we cannot display a map at the moment</p>";return;};mapviewer=new MultimapViewer(map);mapviewer.goToPosition(new MMLocation(new MMLatLon(initialLat,initialLong),13));document.getElementById("mapLoading").style.display='none';mapviewer.addWidget(new MMPanZoomWidget(new MMBox(5,5)));$('#mapView').parent().addClass('selected');$('#airView').click(function(){mapviewer.setMapType(MM_WORLD_AERIAL);$('#mapView').parent().removeClass('selected');$('#airView').parent().addClass('selected');$('#hybridView').parent().removeClass('selected');return false;});$('#mapView').click(function(){mapviewer.setMapType(MM_WORLD_MAP);$('#mapView').parent().addClass('selected');$('#airView').parent().removeClass('selected');$('#hybridView').parent().removeClass('selected');return false;});$('#hybridView').click(function(){mapviewer.setMapType(MM_WORLD_HYBRID);$('#hybridView').parent().addClass('selected');$('#mapView').parent().removeClass('selected');$('#airView').parent().removeClass('selected');return false;});$('#findDirs').click(function(){window.open("/MapDirections.aspx","directions","width=650,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes");return false;});};function routeInit(){var funcRef=resultsLoaded;route_finder=new MMRouteRequester(funcRef);loading=document.getElementById('loading');loadingStatus(false);$("#routeSteps").after("<a href='#' id='clsWindow'>close window</a>");$('#clsWindow').click(function(){window.close();return false;});};function writeMapHTML(){var output="<ul id='maptab'><li><a href='' id='mapView'>map view</a></li><li><a href='' id='airView'>aerial view</a></li><li>";output+="<a href='' id='hybridView'>hybrid view</a></li><li><a href='' id='findDirs' title='opens in a new window'>get directions</a></li></ul><div id='MMmap'><img src='http://images.thomsonlocal.com/tlc/loading.gif' alt='loading map' id='mapLoading'/></div>";$("#mapWrapper").html(output).css('display','block');};function loadingStatus(bool){document.getElementById('qs1').disabled=bool;document.getElementById('qs2').disabled=bool;document.getElementById('select1').disabled=bool;document.getElementById('select2').disabled=bool;document.getElementById('submitbtn').disabled=bool;document.getElementById('submitbtn1').disabled=bool;loading.style.display=bool?'block':'none';}
function createStepMarker(location,instruction,text,zindex){var marker=mapviewer.createMarker(location,{zIndex:zindex,'text':text});marker.setInfoBoxContent('<p>'+instruction+'<'+'/p>');}
function callRoute(){cleanUp();var locations=new Array();addLocation(1,locations)
addLocation(2,locations)
loadingStatus(true);route=new MMRoute(locations);var shortest=document.getElementById('shortest').checked;if(shortest==true){route.optimize_for='distance';}else{route.optimize_for='time';}
var walking=document.getElementById('walking').checked;if(walking==true){route.mode='walking';}else{route.mode='driving';}
var exclude_highways=document.getElementById('exclude_highways').checked;if(exclude_highways){route.exclude='highways';}else{route.exclude='';}
route.optimize_intermediates='';route.lang="en_gb";route_finder.request(route);}
function cleanUp(){var stepsContainer=document.getElementById('routeSteps');while(stepsContainer.firstChild){stepsContainer.removeChild(stepsContainer.firstChild);}
stepsContainer.style.display='none';mapviewer.removeAllOverlays();markers=new Array();}
function resetData(){cleanMultipleMatches(1);cleanMultipleMatches(2);document.getElementById('driving').checked=true;document.getElementById('quickest').checked=true;document.getElementById('exclude_highways').checked=false;mapviewer.removeAllOverlays();addMarkers();}
function addLocation(num,locations){var qs=document.getElementById('qs'+num);var select=document.getElementById('select'+num);var address=new MMAddress();if(select.options&&select.options.length>1){var coords=select.options[select.selectedIndex].value.split(',');locations.push(new MMLocation(new MMLatLon(coords[0],coords[1])));}else{address.qs=qs.value;address.country_code="UK";locations.push(new MMLocation(address));}}
function cleanMultipleMatches(num){var qs=document.getElementById('qs'+num);var select=document.getElementById('select'+num);var addr=document.getElementById('addr'+num);var matches=document.getElementById('matches'+num);while(select.firstChild){select.removeChild(select.firstChild);}
qs.value='';matches.style.display='none';addr.style.display='block';}
function resultsLoaded(){if(route.error_code){if(route.error_code=='MM_ROUTE_GEOCODING_ERRORS'){processGeocodingErrors(route.geocoding_errors);}else{alert("Sorry a problem has occured"+': '+route.error_explanation);}}else{mapviewer.goToPosition(mapviewer.getAutoScaleLocation(route.bounds));displayStages(route);for(var i=0,l=route.polyLine.length;i<l;++i){mapviewer.addOverlay(route.polyLine[i]);}}
loadingStatus(false);}
function displayStages(route){var curr_step=1;var stages=route.stages;var container=document.getElementById('routeSteps');displayName=document.getElementById('select1');var displayNameSelected="";if(displayName.selectedIndex!=-1)displayNameSelected=displayName.options[displayName.selectedIndex].text;var startAddress;startAddress=stages[0].start_address;var endAddress;endAddress=stages[0].end_address;if(typeof(startAddress.display_name)=="string"){startAddress=stages[0].start_address;}
else{startAddress=displayNameSelected;}
var summary='';summary+='Start: <strong>'+startAddress+'</strong>';summary+='<br/>End: <strong>'+endAddress+'</strong>';summary+='<br />Total Distance: '+route.distance.miles+' mile(s)';summary+='<br />Estimated Total Time: ';if(route.duration.days>0){summary+=route.duration.days+' day(s) ';}
if(route.duration.hours>0){summary+=route.duration.hours+' hour(s) ';}
if(route.duration.minutes>0){summary+=route.duration.minutes+' minute(s) ';}
var p=document.createElement('p');p.innerHTML=summary;container.appendChild(p);for(var count=0;count<stages.length;count++){var stage_summary='';if(stages[count].duration.days>0){stage_summary+=stages[count].duration.days+' day(s) ';}
if(stages[count].duration.hours>0){stage_summary+=stages[count].duration.hours+' hour(s) ';}
if(stages[count].duration.minutes>0){stage_summary+=stages[count].duration.minutes+' minute(s) ';}
stage_summary+='<br />Summary: '+stages[count].summary;var p=document.createElement('p');p.innerHTML=stage_summary;container.appendChild(p);var ol=document.createElement('ol');ol.id='stage_'+count;ol.start=curr_step;var steps=stages[count].steps;for(var stepCount=0;stepCount<steps.length;stepCount++){var text=curr_step;var zindex=max_zindex-curr_step+1;if(count==stages.length-1&&stepCount==steps.length-1){zindex=max_zindex;};var instruction=steps[stepCount].instruction;var roadname=steps[stepCount].road_name;var roadnumber=steps[stepCount].road_number;if(roadname&&roadnumber){instruction+=' '+roadname+' ('+roadnumber+') ';}else if(roadname){instruction+=' '+roadname+' ';}else if(roadnumber){instruction+=' '+roadnumber+' ';}
var distance='';if(steps[stepCount].distance.miles>0){distance+='<span>'+steps[stepCount].distance.miles+' mile(s)</span> ';}
var li=document.createElement('li');li.innerHTML=instruction+distance;ol.appendChild(li);createStepMarker(steps[stepCount].start_point,instruction,text,zindex);++curr_step;}
container.appendChild(ol);}
container.style.display='block';var copyright='';if(route.copyright){copyright+='Copyright: '+route.copyright;}
if(route.disclaimer){copyright+='<br />Disclaimer:  <a href="'+route.disclaimer+'">'+route.disclaimer+'<'+'/a>';}
var p=document.createElement('p');p.innerHTML=copyright;container.appendChild(p);}
function processGeocodingErrors(errors){for(var i=0;i<errors.length;i++){if(errors[i].error_code=='MM_GEOCODE_NO_MATCHES'){alert('Please enter a starting location.');}else if(errors[i].error_code=='MM_GEOCODE_MULTIPLE_MATCHES'){var select=document.getElementById('select'+errors[i].input_id);for(var j=0;j<errors[i].results.length;j++){var displayName=errors[i].results[j].address.display_name;var point=errors[i].results[j].coords;var option=document.createElement('option');option.value=point.lat+','+point.lon;option.appendChild(document.createTextNode(displayName));select.appendChild(option);select.selectedIndex=0;}
document.getElementById('matches'+errors[i].input_id).style.display='block';document.getElementById('addr'+errors[i].input_id).style.display='none';}}};
