
    var gdir;
	var distance;
	var prijs;
    var geocoder = null;
    var addressMarker;

    function initialize() 
	{
      if (GBrowserIsCompatible()) 
	  {      
        gdir = new GDirections();
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);
		
		setDirections("Stationsplein 1, Leeuwarden", "De Fennen 29, Leeuwarden", "nl");
      }
    }
    
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Het opgegeven adres wordt niet herkend.\n \nMisschien is het adres foutief gespeld, of erg nieuw.\n \nVerbeter of probeer een andere omschrijving.\n \nError code: " + gdir.getStatus().code);
	   else if (gdir.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: " + gdir.getStatus().code);
	   
	   else if (gdir.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: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.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: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
	  var afstand = parseInt(gdir.getDistance().meters)/1000;
	  
	  if (afstand < 2) 
	  {
	  price = 7.05;
	  price = price.toFixed(2);
	  price = "uitsluitend het starttarief van <b>&nbsp;&euro;&nbsp;<font color='blue'>"+price+"</font></b>";
	  }
	  else if (afstand > 2) 
	  {
	  price = (((afstand - 2)*2.20)+7.05);
	  price = price.toFixed(2);
	  price = "ongeveer <b>&nbsp;&euro;&nbsp;<font color='blue'>"+price+"</font></b>";
	  }
	  	  
document.getElementById("distance").innerHTML = "<font color='blue'><b>"+(afstand).toFixed(1)+ "</b></font> km (Berekening via Google Maps)";
document.getElementById("prijs").innerHTML = ""+price;

	}
	
