// JavaScript Document

    //<![CDATA[

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function load() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map"));

        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
		map.addControl(new GSmallMapControl ());
		map.addControl(new GMapTypeControl ());
		
		// set the geocoder
		geocoder = new GClientGeocoder();
		
		// Set the map center
		map.setCenter(new GLatLng(52.08789885845448, 5.111807584762573), 13);
        showAddress("Stokstraat 26,Kruishoutem,Belgium");
      }
    }
	
	function showAddress(address) {
		if (geocoder) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						alert("Het adres \"Stokstraat 26\" kon niet gevonden worden op de kaart.");
					} else {
						map.setCenter(point, 13);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						GEvent.addListener(marker, "click", function() {
							marker.openInfoWindowHtml('<div><div class="DetailURL"><a href=\"http://www.fatnv.be \" target=\"_blank\">FAT nv</a></div><div class="DetailNAW"></div>Stokstraat 26<br />9770 Kruishoutem<br /></div>');
						});
					}
				}
			);
		}
	}	
    
    function setDirections(street,location,country, toAddress, locale) {
      gdir.load("from: " + street + "," + location + ","+country + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Dit adres werd niet teruggevonden. Gelieve nogmaals te proberen.");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("Het adres kon niet worden opgevraagd.");
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("Het adres kon niet worden opgevraagd.");

	//   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("Het adres kon niet worden opgevraagd.");

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("Het adres kon niet worden opgevraagd.");
	    
	   else alert("Het adres kon niet worden opgevraagd.");
	   
	}

	function onGDirectionsLoad(){ 
          // Use this function to access information about the latest load()
          // results.

          // e.g.
	  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}


    //]]>

