var map;function init()
{if(GBrowserIsCompatible())
{map=new GMap(document.getElementById("map"));map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());document.getElementById("to").value=to_address;var businessLatLng=new GPoint(to_address_lat,to_address_lng);function createInfoMarker(markerPoint,markerInfo){var marker=new GMarker(markerPoint);GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(markerInfo);});return marker;}
var markerPoint=to_address_latlng;var markerInfo="<font face='Arial' size='2'><b>"+to_address+"</b></font>";var marker=createInfoMarker(businessLatLng,markerInfo);map.centerAndZoom(businessLatLng,zoom_level);map.addOverlay(marker);if(administrationMode=='on')
{GEvent.addListener(map,'click',function(overlay,latlng){addMarker(overlay,latlng);});document.getElementById("mapAdminControl").innerHTML='<b>Admin Controls:</b><br>Click map to get latitude longitude cordinates <span style="font-size:12px;">(displays in bubble &amp; below map)</span><br><input type="button" value="Clear map" onClick="map.clearOverlays();">';document.getElementById("mapAdminControl").style.display='block';}}}
window.onload=init;window.onunload=GUnload;function addMarker(overlay,latlng)
{var marker=new GMarker(latlng);map.addOverlay(marker);marker.openInfoWindowHtml('Latitude Longitude of this Marker: <br>'+latlng);document.getElementById("directions").innerHTML='<div class="bodytext">Latitude Longitude of Last Marker On Map:</div>'+latlng;}
function setto_address(address){if(geocoder){geocoder.getLatLng(address,function(point){if(!point){alert(address+" not found");}else{alert(point);map.setCenter(point,zoom_level);var marker=new GMarker(point);map.addOverlay(marker);}});}}
function getDirections()
{var from=document.getElementById("from").value;var to;var locale='en';if(to_address_latlng){to=to_address_latlng;}
else{to=to_address;}
if(window.gDirections){window.gDirections.clear();}
window.gDirections=new GDirections(map,document.getElementById("directions"));window.gDirections.load("from: "+from+" to: "+to,{"locale":locale});GEvent.addListener(window.gDirections,"error",handleErrors);}
function handleErrors(){if(window.gDirections.getStatus().code==G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\n\nHINT: Try only inputting your town and county only [e.g. Mallow, Cork] in the from text box.\n\nError code: "+ window.gDirections.getStatus().code);else if(window.gDirections.getStatus().code==G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: "+ window.gDirections.getStatus().code);else if(window.gDirections.getStatus().code==G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: "+ window.gDirections.getStatus().code);else if(window.gDirections.getStatus().code==G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: "+ window.gDirections.getStatus().code);else if(window.gDirections.getStatus().code==G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: "+ window.gDirections.getStatus().code);else alert("An unknown error occurred.");}
