/* SVN $Id: main.js 96 2009-05-08 14:09:24Z jeroen $ */
/* SVN $URL: file:///T:/SOURCE_SVN/Start_Website/httpdocs/js/main.js $ */

/*############################################################################*/
/*# Initialize */

function Main_Initialize()
{
  if('function' == typeof GoogleLoadMap)
  {
    WHITE_AddLoadEvent(GoogleLoadMap);
	setTimeout ("hidePopup();", 10000)
  }
}

if ('function' == typeof WHITE_AddBodyLoadFunction)
{
  WHITE_AddBodyLoadFunction(Main_Initialize);
}
/*# /Initialize */
/*#############################################################################
# Google maps function
#############################################################################*/


// Put here the finish location for the Google Directions part
var sToLocation = "Geenhovensedreef 28-b, 5552 Valkenswaard";

function GoogleLoadMap() {
  var oGoogleMapDiv = WHITE_GetElementFlex('googleMaps');
  if ('object' == typeof oGoogleMapDiv)
  {
    if (GBrowserIsCompatible()) {
      var map = new GMap2(oGoogleMapDiv);
      var point = new GLatLng(51.36161, 5.45659);

      map.setCenter(point, 13);
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      map.setMapType(G_NORMAL_MAP);

      /* Part for the directions */
      gdir = new GDirections(map, document.getElementById("googleMapsDirections"));
      GEvent.addListener(gdir, "error", handleErrors);
      /* End directions */

      var marker = new GMarker(point);
      var html = "<b>Bartels &amp; Manders<\/b><br />Geenhovensedreef 28-b<br />5552 BD Valkenswaard";
      GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); });

      map.addOverlay(marker);

      marker.openInfoWindowHtml(html);
    }
  }
}

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("Er heeft zich een fout voor gedaan op de server van Google. Probeert u het nog een keer.\n Fout code code: " + gdir.getStatus().code);

else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("De HTTP q parameter mist of heeft geen waarde.\n Fout code: " + gdir.getStatus().code);

	else if (gdir.getStatus().code == G_GEO_BAD_KEY)
  	alert("De opgegeven sleutel is niet geldig. \n Fout 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 'Vertrekpunt' leeg gelaten. Deze is vereist om een route te plannen");
}

function setDirections(sFromAddress, locale) {
  gdir.load("from: " + sFromAddress +" to: "+sToLocation,{ "locale": locale });
}

function hidePopup() 
		 {
			 WHITE_AddClassName("hoverAd", "hidden");		 
		 }
			 
