WHITE_AddBodyLoadFunction(GoogleCheckMap);

function GoogleCheckMap()
{
  var oGoogleMapEhv       = WHITE_GetElementFlex('map');
  var oGoogleMapAssen     = WHITE_GetElementFlex('assen');
  var oGoogleMapBladel    = WHITE_GetElementFlex('bladel');
  var oGoogleMapLelystad  = WHITE_GetElementFlex('lelystad');
  var oGoogleMapPutten    = WHITE_GetElementFlex('putten');
  var oGoogleMapOostzaan  = WHITE_GetElementFlex('oostzaan');
  var oGoogleMapRoermond  = WHITE_GetElementFlex('roermond');
  var oGoogleMapUden      = WHITE_GetElementFlex('uden');

  if ('object' == typeof oGoogleMapEhv)
  {
    GoogleLoadMap(oGoogleMapEhv,51.4459,5.4482,"Hoofdkantoor Eindhoven","Beukenlaan 60<br \/>5651 CD  Eindhoven");
  }
  else if ('object' == typeof oGoogleMapAssen)
  {
    GoogleLoadMap(oGoogleMapAssen,52.99371,6.55601,"Accountantskantoor Assen","Vaart Zuidzijde 33<br \/>9401 GG  Assen");
  }
  else if ('object' == typeof oGoogleMapBladel)
  {
    GoogleLoadMap(oGoogleMapBladel,51.3715466345801, 5.23468173933351,"Accountantskantoor Bladel","Lange Trekken 40<br \/>5531 PZ  Bladel");
  }
  else if ('object' == typeof oGoogleMapLelystad)
  {
    GoogleLoadMap(oGoogleMapLelystad,52.4748851478202, 5.49830825827579,"Accountantskantoor Lelystad","Pascallaan 68-j<br \/>8218 NJ  Lelystad");
  }
  else if ('object' == typeof oGoogleMapPutten)
  {
    GoogleLoadMap(oGoogleMapPutten,52.2503529241398, 5.60251175868762,"Accountantskantoor Putten","Midden Engweg 15-a<br \/>3882 TS Putten");
  }
  else if ('object' == typeof oGoogleMapOostzaan)
  {
    GoogleLoadMap(oGoogleMapOostzaan,52.4410039944423, 4.8749348219753,"Accountantskantoor Oostzaan","Kerkbuurt 23<br \/>1511 BB Oostzaan");
  }
  else if ('object' == typeof oGoogleMapRoermond)
  {
    GoogleLoadMap(oGoogleMapRoermond,51.19696, 5.98161,"Accountantskantoor Roermond","Looskade 17<br \/>6041 LE Roermond");
  }
  else if ('object' == typeof oGoogleMapUden)
  {
    GoogleLoadMap(oGoogleMapUden,51.664304,5.616846,"Accountantskantoor Uden","Margrietstraat 7<br \/>5401 CH Uden");
  }
}

function GoogleLoadMap(oDiv,fLocX,fLocY,sHtml,sAddress)
{
    if (GBrowserIsCompatible())
    {
      var map = new GMap2(oDiv);
      var point = new GLatLng(fLocX,fLocY );

      sDirAddress = sAddress.replace('<br \/>', ", "); // Remove break for direction search

      map.setCenter(point, 14);
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      map.setMapType(G_NORMAL_MAP);

      gdir = new GDirections(map, document.getElementById("directions"));
			GEvent.addListener(gdir, "load", onGDirectionsLoad);
      GEvent.addListener(gdir, "error", handleErrors);

      sPopupText = "<b>FoedererDFK<\/b><br \/>"+sHtml+"<br \/>"+sAddress;

      var marker = new GMarker(point);
      GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(sPopupText); });

      map.addOverlay(marker);

      marker.openInfoWindowHtml(sPopupText);
    }
}

function handleErrors(){
  if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	alert("Google heeft uw locatie niet kunnen vaststellen. De beste manier om de route te zoeken, is door het volgende formaat aan te houden: straatnaam nummer, plaats.");
	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("U heeft het veld 'van' leeg gelaten. Deze is vereist om een route te plannen");

}

function onGDirectionsLoad(){
}


function setDirections(fromAddress, locale) {
  gdir.load("from: " + fromAddress +" to: " + sDirAddress,{ "locale": locale });
}

