﻿var markers = new Array();
var currentmarker = null;
var map = null;
var refIcon = null;
var smallIcon = null;
var tsjilIcon = null;

function mapInit() {
  map = new GMap2(document.getElementById('googlemap'));
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(52.872445,5.822754), 8, G_SATELLITE_MAP);
    
  poolIcon = new GIcon();
  poolIcon.iconSize = new GSize(74, 47);
  poolIcon.iconAnchor = new GPoint(42, 46);
  poolIcon.infoWindowAnchor = new GPoint(42, 46);
  poolIcon.image = "/interface/images/gm_aanwijzer_pool.png";
    
  aviopoolIcon = new GIcon();
  aviopoolIcon.iconSize = new GSize(60, 51);
  aviopoolIcon.iconAnchor = new GPoint(15, 51);
  aviopoolIcon.infoWindowAnchor = new GPoint(15,51);
  aviopoolIcon.image = "/interface/images/gm_aanwijzer_auviopool_oud_groot.png";
  aviopoolIcon.shadowSize = new GSize(29,23);
    
  parkIcon = new GIcon();
  parkIcon.iconSize = new GSize(19,17);
  parkIcon.iconAnchor = new GPoint(4,4);
  parkIcon.infoWindowAnchor = new GPoint(4,4);
  parkIcon.image = "/interface/images/gm_aanwijzer_klein.png";
}

// Gdirections gedeelte.
// Laden van de routebeschrijving.
var gdir;
function routeLaden(naar) {
  var route = document.getElementById("route-beschrijving");
  route.innerHTML = "";
  var route_van_straat = document.getElementById("route-straat").value;
  var route_van_nr = document.getElementById("route-nr").value;
  var route_van_plaats = document.getElementById("route-plaats").value; 
  var van = route_van_straat + " " + route_van_nr + " " + route_van_plaats + " Nederland";
  
  var melding_route = document.getElementById("melding-route");
  melding_route.innerHTML = "";
  
  if (route_van_straat == "") {
	  melding_route.innerHTML = "Vul aub de straat in waar vandaan je vertrekt";
	  document.getElementById("route-straat").focus();
  }
  else if (route_van_plaats == "") {
	  melding_route.innerHTML = "Vul aub de plaats in waar vandaan je vertrekt";	
	  document.getElementById("route-plaats").focus();
  }  
  else {
    if (gdir)
    {
      // eventuele vorige routebschrijvingen van de google-maps verwijderen.
      gdir.clear();
    }
    gdir = new GDirections(map, route);
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);
    var taal = "nl_nl";
    gdir.load("from: " + van + " to: " + naar, { "locale": taal });
  }
}

function onGDirectionsLoad() {
  var container_route = document.getElementById("container-routebeschrijving");
  try{
	  container = document.getElementById("container"); 
	}catch(e){}
  container_route.style.display = "block";
  container_route.style.left = (container.offsetLeft + 6) + "px";
  container_route.style.top = (container.offsetTop + 6) + "px"; 
  container_route.style.visibility = "visible"; 
  var sluit = document.getElementById("sluit-routebeschrijving"); 
  var iw = map.getInfoWindow();
  iw.hide();
}

function handleErrors(){
  if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
    alert("De locatie van het opgegeven vertrekadres kon niet worden bepaald. Foutcode: " + gdir.getStatus().code);
  }
  else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) {
    alert("Er is iets misgegaan. Maar het is onduidelijk WAT! Foutcode: " + gdir.getStatus().code);
  }
  else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) {
    alert("Een parameter ontbreekt. Misschien was er geen vertrekpunt ingevoerd. Foutcode: " + gdir.getStatus().code);
  }
  else if (gdir.getStatus().code == G_GEO_BAD_KEY) {
    alert("De Google Maps sleutel is ongeldig of de gebruikte sleutel is niet geldig voor dit domein. Foutcode: " + gdir.getStatus().code);
  }
  else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) {
    alert("De aanvraag voor het plannen van een route is mislukt. Foutcode: " + gdir.getStatus().code);
  }
  else {
    alert("Er is iets misgegaan. Maar het is volstrekt onduidelijk WAT de oorzaak is!");
  }
}
// Einde Gdirections gedeelte.
  
window.onload = function() {
  mapInit();
  // Map centreren op Tsjil.
  map.setCenter(new GLatLng(53.18134990842877, 6.167106628417969), 14, G_NORMAL_MAP);
  map.enableScrollWheelZoom();
  var poolMarker = new GMarker(new GLatLng(53.182835125403535,6.167350709438324), poolIcon);
  poolMarker.bindInfoWindowHtml('<div class="marker" style="width:300px;height:115px;display:block;"><span class=\x27titel\x27>Pool HiFi-Video Centre<\/span><div><i>Bezoekadres:<\/i><br/>De Dellen 2G<br/>9231 EB Surhuisterveen<br/>Telefoon: 0512 363239<br/><\/div><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x27de dellen 2g 9231 EB surhuisterveen Nederland\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(poolMarker);
  
  //Aviopool volgend jaar (2009) weer activeren.
  var aviopoolMarker = new GMarker(new GLatLng(53.180240784287996, 6.168721318244934), aviopoolIcon);
  aviopoolMarker.bindInfoWindowHtml('<div class="marker" style="width:300px;height:115px;display:block;"><span class=\x27titel\x27>AuvioPool 2009<\/span><div><i>Bezoekadres:<\/i><br/>Zalencentrum de Lantearne<br/>Jan Binneslaan 49<br/>9231 CA  Surhuisterveen<br/><\/div><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x27Jan Binneslaan 49 9231 CA  Surhuisterveen\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(aviopoolMarker);
  
  //parkeerplaatsen.
  var pMark1 = new GMarker(new GLatLng(53.18118273793013, 6.162879467010498), parkIcon);
  pMark1.bindInfoWindowHtml('<div class="marker" style="width:300px;height:30px;display:block;"><span class=\x27titel\x27>Parkeerplaats<\/span><br/><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x2753.18118273793013, 6.162879467010498\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(pMark1);
  
  var pMark2 = new GMarker(new GLatLng(53.179446698083325, 6.167793273925781), parkIcon);
  pMark2.bindInfoWindowHtml('<div class="marker" style="width:300px;height:30px;display:block;"><span class=\x27titel\x27>Parkeerplaats<\/span><br/><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x2753.179446698083325, 6.167793273925781\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(pMark2);
  
  var pMark3 = new GMarker(new GLatLng(53.18096412937185, 6.168093681335449), parkIcon);
  pMark3.bindInfoWindowHtml('<div class="marker" style="width:300px;height:30px;display:block;"><span class=\x27titel\x27>Parkeerplaats<\/span><br/><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x2753.18096412937185, 6.168093681335449\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(pMark3);
  
  var pMark4 = new GMarker(new GLatLng(53.18268724896256, 6.163029670715332), parkIcon);
  pMark4.bindInfoWindowHtml('<div class="marker" style="width:300px;height:30px;display:block;"><span class=\x27titel\x27>Parkeerplaats<\/span><br/><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x2753.18268724896256, 6.163029670715332\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(pMark4);
  
  var pMark5 = new GMarker(new GLatLng(53.183278751667316, 6.165261268615723), parkIcon);
  pMark5.bindInfoWindowHtml('<div class="marker" style="width:300px;height:30px;display:block;"><span class=\x27titel\x27>Parkeerplaats<\/span><br/><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x2753.183278751667316, 6.165261268615723\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(pMark5);
  
  var pMark6 = new GMarker(new GLatLng(53.183150164816766, 6.169273853302002), parkIcon);
  pMark6.bindInfoWindowHtml('<div class="marker" style="width:300px;height:30px;display:block;"><span class=\x27titel\x27>Parkeerplaats<\/span><br/><span id=\x27toonbeschrijving\x27>Routebeschrijving: <a href=\x22javascript:void(null);\x22 onclick=\x22document.getElementById(\x27tbx_route_van\x27).value=\x2753.183150164816766, 6.169273853302002\x27;document.getElementById(\x27container-route-van\x27).style.display=\x27block\x27;document.getElementById(\x27route-straat\x27).focus();\x22>Hier naartoe<\/a><\/span><div class=\x27spacer\x27><\/div><div style=\x27width:300px;line-height:1px;height:1px;\x27>&nbsp;<\/div><\/div>');
  map.addOverlay(pMark6);
  
  // DMV een klik op google map, de coordinaten van die click achterhalen.
  //GEvent.addListener(map, 'click', function(overlay, point) {   if (point) {   document.write('You clicked at: ' + point); alert('You clicked at: ' + point);   }});
}
