var map;var geocoder;function load(){if(GBrowserIsCompatible()){geocoder=new GClientGeocoder();map=new GMap2(document.getElementById('map'));map.addControl(new GLargeMapControl());map.setCenter(new GLatLng(54.622978,-4.3),5)}}function searchLocations(){var address=document.getElementById('addressInput').value+", UK";geocoder.getLatLng(address,function(latlng){if(!latlng){alert(address+' not found')}else{searchLocationsNear(latlng)}})}function searchLocationsNear(center){var searchUrl='../xml-driving.php?lat='+center.lat()+'&lng='+center.lng()+'&radius=500';GDownloadUrl(searchUrl,function(data){var xml=GXml.parse(data);var markers=xml.documentElement.getElementsByTagName('marker');map.clearOverlays();var sidebar=document.getElementById('sidebar');sidebar.innerHTML='';if(markers.length==0){sidebar.innerHTML='<div class="center"><p><strong>No results found. Please try entering more detail<br /> or give a different town or postcode</strong><br /></p></div>';map.setCenter(new GLatLng(54.622978,-4.3),5);return}var bounds=new GLatLngBounds();for(var i=0;i<markers.length;i++){var name=markers[i].getAttribute('name');var address=markers[i].getAttribute('address');var type=markers[i].getAttribute("type");var distance=parseFloat(markers[i].getAttribute('distance'));var point=new GLatLng(parseFloat(markers[i].getAttribute('lat')),parseFloat(markers[i].getAttribute('lng')));var marker=createMarker(point,name,address,type);map.addOverlay(marker);var sidebarEntry=createSidebarEntry(marker,name,address,distance);sidebar.appendChild(sidebarEntry);bounds.extend(point)}map.setCenter(bounds.getCenter(),(map.getBoundsZoomLevel(bounds)-1))})}function createMarker(point,name,address,type){var marker=new GMarker(point,customIcons[type]);var html='<strong>'+name+'</strong> <br />'+address+'<br /><br />';GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(html)});return marker}var icondriving=new GIcon();icondriving.image='../images/icons/drivingtest.png';icondriving.iconSize=new GSize(20,34);icondriving.iconAnchor=new GPoint(20,34);icondriving.infoWindowAnchor=new GPoint(10,17);var customIcons=[];customIcons["driving"]=icondriving;function createSidebarEntry(marker,name,address,distance){var div=document.createElement('div');var html='<p><strong>'+name+'</strong> ('+distance.toFixed(1)+' miles)<br />'+address+'<br /></p>';div.innerHTML=html;div.style.cursor='pointer';div.style.marginBottom='5px';GEvent.addDomListener(div,'click',function(){GEvent.trigger(marker,'click')});GEvent.addDomListener(div,'mouseover',function(){div.style.backgroundColor='#eee'});GEvent.addDomListener(div,'mouseout',function(){div.style.backgroundColor='#fff'});return div}