// Routenplaner Google

    var map = null;
    var geocoder = null;
    var gdir;
    var adresse="Hauptstrasse 24 9042 Speicher";

function load() {
	try{
      		if (GBrowserIsCompatible()) {
        		map = new GMap2(document.getElementById("map"));
       			var mapControl = new GMapTypeControl();
       			map.addControl(mapControl);
       			map.addControl(new GLargeMapControl());
       			map.addControl(new TextualZoomControl());
       			geocoder = new GClientGeocoder();
       			showAddress(adresse,true)
		}
	}catch(e){
		alert(e);
	}
}

function TextualZoomControl() {}
	TextualZoomControl.prototype = new GControl();
    	TextualZoomControl.prototype.initialize = function(map) {
        var container = document.createElement("div");
        var zoomInDiv = document.createElement("div");
        this.setButtonStyle_(zoomInDiv);
        container.appendChild(zoomInDiv);
        zoomInDiv.appendChild(document.createTextNode("Vergrössern"));
        GEvent.addDomListener(zoomInDiv, "click", function() {
            map.zoomIn();
        });
        var zoomOutDiv = document.createElement("div");
        this.setButtonStyle_(zoomOutDiv);
        container.appendChild(zoomOutDiv);
        zoomOutDiv.appendChild(document.createTextNode("Verkleinern")); 
        GEvent.addDomListener(zoomOutDiv, "click", function() {
            map.zoomOut();
        });  map.getContainer().appendChild(container);
        return container;}
        TextualZoomControl.prototype.getDefaultPosition = function() {
        return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5, 290));
        }
        TextualZoomControl.prototype.setButtonStyle_ = function(button) {
        button.style.textDecoration = "underline";
        button.style.color = "#0000cc";
        button.style.backgroundColor = "white";
        button.style.font = "small Arial";
        button.style.border = "1px solid black";
        button.style.padding = "2px";
        button.style.marginBottom = "3px";
        button.style.textAlign = "center";
        button.style.width = "6em";
        button.style.cursor = "pointer";
}

function showAddress(address, marks) {
    try{
        if (geocoder) {
        geocoder.getLatLng(
              address,
              function(point) {
                if (!point) {
                  alert(address + " not found");
                } else {
                  map.setCenter(point, 13);
                  if(marks==true){
                      var marker = new GMarker(point);
                      map.addOverlay(marker);
		      var text = "HAUT- UND SCHMERZ-ZENTRUM HSZ <br> Hauptstrasse 24 9042 Speicher <br> Telefon: ++41 (0)71 352 52 35 <br> Fax: ++41 (0)71 352 51 03 <br> E-mail: hsz@haut-und-schmerzzentrum.ch <br> Neue Wege in der Medizin  -  seit über 10 Jahren!"
                      marker.openInfoWindowHtml(text);
                  }
                }
              }
            );
        }
    }catch(e){
        alert(e);
    }
}

function calcRoute(from){
    try{
        if(gdir==null){
            gdir = new GDirections(map, document.getElementById("directions"));
            GEvent.addListener(gdir, "load", onGDirectionsLoad);
            GEvent.addListener(gdir, "error", handleErrors);
        }
        setDirections(from, adresse, "de");
    }catch(e){
        alert(e);
    }
}

function setDirections(fromAddress, toAddress, locale) {
    try{
      gdir.clear();
      gdir.load("from: " + fromAddress + " to: " + toAddress,
            { "locale": locale });
    }catch(e){
        alert(e);
    }
}

function handleErrors(){
    try{
        if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
            alert("Es wurde keine Adresse gefunden. Entweder ist die Adresse neu, oder sie besteht nicht.\nError code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
            alert("Es ist ein unbestimmter Fehler aufgetreten.\n Error code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
            alert("Es ist ein unbestimmter Fehler aufgetreten.\n Error code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_BAD_KEY)
            alert("Es ist ein unbestimmter Fehler aufgetreten.\n Error code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
            alert("Die Route konnte nicht berechnet werden.\n Error code: " + gdir.getStatus().code);
        else alert("Es ist ein unbestimmter Fehler aufgetreten.");
    }catch(e){
        alert(e);
    }
}

function onGDirectionsLoad(){ 

}
