﻿function initialize() {
    if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"))
            var scltlng = new GLatLng(52.671721, -2.121413);
            map.setCenter(scltlng, 13);
            map.addControl(new GSmallMapControl());

            var marker = new GMarker(scltlng)
            GEvent.addListener(marker, 'click', function() {
                marker.openInfoWindowHtml('Sinclair Collis Ltd<br />Laches Close<br />Four Ashes<br />Wolverhampton<br />West Midlands<br />WV10 7DZ');
            });

            map.addOverlay(marker);           
    }
}

var d;
var geocoder = null;

function directions(pcode) {

    var map = new GMap2(document.getElementById("map_canvas"))
    directionsPanel = document.getElementById("route");
    var directions = new GDirections(map, directionsPanel);
    GEvent.addListener(directions, "error", handleErrors);
    directions.load("from: " + pcode + ", UK to: WV10 7DZ, UK");
    document.getElementById("route").style.display = 'block'
    document.getElementById("print").style.display = 'block'
    d = directions;
}

function handleErrors() {
    document.getElementById("route").style.display = 'none'
    document.getElementById("print").style.display = 'none'
    initialize();
    if (d.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {        
        alert("You have entered an unknown postcode, please try again.");
    }
    else {
        alert("Something went wrong, please try again");
    }

}
