var map;
var gdir;
var geocoder = null;
function load() {
  if (GBrowserIsCompatible()) {
  map = new GMap2(document.getElementById("map"));
  
  map.enableScrollWheelZoom();
  map.addControl(new GSmallMapControl());
  
  map.setCenter(new GLatLng(54.322684, 10.13586), 11, G_NORMAL_MAP);
  map.addControl(new GSmallMapControl());
  map.addControl(new GHierarchicalMapTypeControl());
  
  // Icon
  icon_map_holyhat = new GIcon();
  icon_map_holyhat.image = "fileadmin/user_upload/grafik_allgemein/map_icon_holyhat.png";
  icon_map_holyhat.shadow = "fileadmin/user_upload/grafik_allgemein/map_schatten_holyhat.png";
  icon_map_holyhat.iconSize = new GSize(13, 20);
  icon_map_holyhat.shadowSize = new GSize(22, 20);
  icon_map_holyhat.iconAnchor = new GPoint(8, 15);
  icon_map_holyhat.infoWindowAnchor = new GPoint(15, 10);

  stampe = new GLatLng(54.341165, 10.01501);
  marker_stampe = new GMarker(stampe, {icon:icon_map_holyhat});
  marker_stampe_text = "<div style='width:200px; line-height:140%; color:#4c5155;'><b>&ndash; B&uuml;ro Stampe &ndash;</b><br />Alte Landstra&szlig;e 41<br />24107 Stampe bei Kiel</div>";
  GEvent.addListener(marker_stampe, "click", function() {
    marker_stampe.openInfoWindowHtml(marker_stampe_text);
  });
  map.addOverlay(marker_stampe);

  klausdorf = new GLatLng(54.297, 10.202345);
  marker_klausdorf = new GMarker(klausdorf, {icon:icon_map_holyhat});
  marker_klausdorf_text = "<div style='width:200px; line-height:140%; color:#4c5155;'><b>&ndash; B&uuml;ro Klausdorf &ndash;</b><br />Liesenh&ouml;rnweg 13<br />24222 Schwentinental/Klausdorf</div>";
  GEvent.addListener(marker_klausdorf, "click", function() {
    marker_klausdorf.openInfoWindowHtml(marker_klausdorf_text);
  });
  map.addOverlay(marker_klausdorf);
  }
  
  // Routenplaner
  gdir = new GDirections(map, document.getElementById("directions"));
  GEvent.addListener(gdir, "load", onGDirectionsLoad);
  GEvent.addListener(gdir, "error", handleErrors);
  /*setDirections("24768 Rendsburg", "Kiel", "de");*/
  
  function setDirections(fromAddress, toAddress, locale) {
	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
  }
  function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
    alert("Es wurde kein entsprechender Ort zu Ihrer Routenberechnung gefunden!");
    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
    alert("Leider konnte keine Route berechnet werden!");
    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
    alert("Der HTTP QUERY Parameter fehlt oder hat keinen Inhalt!");
    else if (gdir.getStatus().code == G_GEO_BAD_KEY)
    alert("Der angegeben API Key ist für eine andere Domain.");
    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
    alert("Leider ist ein Fehler bei der Routenberechnung aufgetreten.");
    else alert("Ein unbekannter Fehler trat auf!");
 }
 function onGDirectionsLoad(){}
}

function route() {
  setDirections(document.anfahrtform.from.value, document.anfahrtform.to.value, "de");
  function setDirections(fromAddress, toAddress, locale) {
	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
  }
  return false;
}