var map = null;
var dir = null;

var latStart = 50.863841;
var lonStart = 5.712204;

var paginaTaal = "nl_NL";

function GLoad()
{   
    if (GBrowserIsCompatible())
    {         
        map = new GMap2(document.getElementById("routeGoogleMaps"));
       
        map.setCenter(new GLatLng(latStart, lonStart), 12);
        map.enableContinuousZoom();
        map.enableScrollWheelZoom();
        
        dir = new GDirections(map, document.getElementById("routeGoogleDirs"));
        
        GEvent.addListener(dir, "load", onGDirectionsLoad);
        GEvent.addListener(dir, "error", handleErrors);
    }
}

function handleErrors()
{
	/*
    if (dir.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.\nError code: " + dir.getStatus().code);
    else if (dir.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: " + dir.getStatus().code);
    else if (dir.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: " + dir.getStatus().code);
    else if (dir.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: " + dir.getStatus().code);
    else if (dir.getStatus().code == G_GEO_BAD_REQUEST)
        alert("A directions request could not be successfully parsed.\n Error code: " + dir.getStatus().code);
    else
        alert("An unknown error occurred.");
	*/
	alert("De route kon niet worden bepaald. Controleer uw vertrekpunt.\n \nDirections could not be calculated. Please verify your departure.");
}

function onGDirectionsLoad()
{ 
    // Use this function to access information about the latest load() results. e.g.
}

function setDirections(fromAddress)
{
    dir.load("from: " + fromAddress + " to: Meerssenerweg 166, 6222AK Maastricht, Nederland", { "locale": paginaTaal });
}

function handleEnterGoogleRoute(field, event)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13)
    {
        setDirections(document.getElementById('vertrekPunt').value);
        return false;
    }
}
