var map;
var geocoder;

    function init_map() {
      map = new GMap2(document.getElementById("map"));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(34, 0), 1);
      geocoder = new GClientGeocoder();
    }

    // 1. Suchaddresse in Inputfeld schreiben
    function findLocation(address) {
      document.forms['frm_add'].addresse.value = address;
      showLocation();
    }

    function showLocation2() {
    var address = document.forms['frm_add'].addresse.value;
    geocoder.getLocations(address, addAddressToMap);
    }  
    function showLocation3() {
    addKOORToMap();
    koor_x = document.forms['frm_add'].koor_x.value;
    koor_y = document.forms['frm_add'].koor_y.value;
    zoom = document.forms['frm_add'].zoom.value;
    point = new GLatLng(koor_y,koor_x);   
    new_marker(point);
    center_map(koor_x,koor_y,zoom);
    }

    function showLocation9(x,y) {
        map.clearOverlays();
        point = new GLatLng(x, y);
        new_marker(point);
        map.setCenter(point, 12);
    } 
    
    function center_map(koor_x,koor_y,zoom) {
    document.forms['frm_add'].koor_x.value = koor_x;
    document.forms['frm_add'].koor_y.value = koor_y;
    document.forms['frm_add'].zoom.value = zoom;
    map.closeInfoWindow();
    point = new GLatLng(koor_y,koor_x);
            if (zoom=='1'){zoom = 1}
            if (zoom=='2'){zoom = 2}
            if (zoom=='3'){zoom = 3}
            if (zoom=='4'){zoom = 4}
            if (zoom=='5'){zoom = 5}
            if (zoom=='6'){zoom = 6}
            if (zoom=='7'){zoom = 7}
            if (zoom=='8'){zoom = 8}
            if (zoom=='9'){zoom = 9}
            if (zoom=='10'){zoom = 10}
            if (zoom=='11'){zoom = 11}
            if (zoom=='12'){zoom = 12}
            if (zoom=='13'){zoom = 13}
    map.setCenter(point, zoom);
    }     
    
    // Übernahme der Adresse aus der Form
    // Mit dem  Geocoder aus der Addresse den Punkt finden

    function showLocation() {
    var xkoor = document.forms['frm_add'].koor_x.value;
    var ykoor = document.forms['frm_add'].koor_y.value;
            if (xkoor != "")
              {
              addKOORToMap()
              }
              else
              {
              var address = document.forms['frm_add'].addresse.value;
              //alert ("Jetzt wird der GeoCoder angesteuert");
              geocoder.getLocations(address, addAddressToMap);
              }
    } 
    
    
    
    function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Die Adresse kann nicht in Koordinaten umgesetzt werden");
      } else {
        // aus dem Response die Punkt-Koodinaten holen
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        // 
        var text = document.forms['frm_add'].addresse.value;
        document.forms['frm_add'].koor_x.value = point.x;
        document.forms['frm_add'].koor_y.value = point.y;
        document.forms['frm_add'].zoom.value = 8;
        new_marker(point);
        // zentrieren

        map.setCenter(point, 8);
      }
    }


    function addKOORToMap() {  
    var xkoor = document.forms['frm_add'].koor_x.value;
    var ykoor = document.forms['frm_add'].koor_y.value;
      map.clearOverlays();
        point = new GLatLng(ykoor,xkoor);
        document.forms['frm_add'].koor_x.value = xkoor;
        document.forms['frm_add'].koor_y.value = ykoor;    
        new_marker(point);
        // zentrieren
        map.setCenter(point, 13);
    }  

  
   
    // Marker setzen
    // Übergabe 1. der Punkt, 1. der Text für das Infofenster

    function createMarker(point, text) {  
    var icon = new GIcon();
    icon.image = "http://www.das-buchungsportal.de/mm_20_red.png";
    icon.iconSize = new GSize(13, 20);
    icon.iconAnchor = new GPoint(5, 5);
    icon.infoWindowAnchor = new GPoint(5, 5);
        marker = new GMarker(point, icon);
        GEvent.addListener(marker, "click", function() {    
        marker.openInfoWindowHtml("<b>" + text + "</b>");  });  
        map.addOverlay(marker);
    } 
   
   function new_marker(point)
   {
   var marker = new GMarker(point, {draggable: true});
   GEvent.addListener(marker, "dragstart", function() {  
   map.closeInfoWindow();  });
   GEvent.addListener(marker, "dragend", function() 
        {  
            point = marker.getPoint();
            document.forms['frm_add'].koor_x.value = point.x;
            document.forms['frm_add'].koor_y.value = point.y;
            marker.openInfoWindowHtml("Diese Position wird nun gespeichert...");  
        }
                    );
   map.addOverlay(marker);
   
   }

   function new_marker1(point)
   {
   var marker = new GMarker(point, {draggable: true});
   GEvent.addListener(marker, "dragstart", function() {  
   map.closeInfoWindow();  });
   GEvent.addListener(marker, "dragend", function() 
        {  
            point = marker.getPoint();
            document.forms['frm_add'].koor_x.value = point.x;
            document.forms['frm_add'].koor_y.value = point.y; 
        }
                    );
   map.addOverlay(marker);
   
   }

      
 // Dartellen einer Marke
    function Show_Rest_in_Map(xkoor, ykoor, text, markername) { 
        var icon = new GIcon();
        icon.image = "http://www.das-buchungsportal.de/mm_20_red.png";
        icon.iconSize = new GSize(13, 20);
        icon.iconAnchor = new GPoint(5, 5);
        icon.infoWindowAnchor = new GPoint(5, 5);   
        point = new GLatLng(ykoor,xkoor);
        markername = new GMarker(point, icon);
        GEvent.addListener(markername, "click", function() {     
        point = markername.getPoint();
        map.openInfoWindowHtml(point,text);  
        map.panTo(point);
        });  
        map.addOverlay(markername);
    } 
    
    function zoom_map(xkoor, ykoor, zoom)
    {
        var icon = new GIcon();
        var text = xkoor+" - "+ykoor+" - "+zoom;
        icon.image = "http://www.das-buchungsportal.de/mm_20_gruen.png";
        icon.iconSize = new GSize(13, 20);
        icon.iconAnchor = new GPoint(5, 5);
        icon.infoWindowAnchor = new GPoint(5, 5);   
        point = new GLatLng(ykoor,xkoor);
        markername = new GMarker(point, icon);
        GEvent.addListener(markername, "click", function() {     
        point = markername.getPoint();
        map.openInfoWindowHtml(point,text);  
        map.panTo(point);
        });  
        map.addOverlay(markername);    
        alert("zoom:"+zoom);
        map.setCenter(point, zoom);
    }  
 
     function Show_User_in_Map(xkoor, ykoor, text, markername) { 
        var icon = new GIcon();
        icon.image = "http://www.das-buchungsportal.de/mm_20_gruen.png";
        icon.iconSize = new GSize(13, 20);
        icon.iconAnchor = new GPoint(5, 5);
        icon.infoWindowAnchor = new GPoint(5, 5);   
        point = new GLatLng(ykoor,xkoor);
        markername = new GMarker(point, icon);
        GEvent.addListener(markername, "click", function() {     
        point = markername.getPoint();
        map.openInfoWindowHtml(point,text);  
        map.panTo(point);
        });  
        map.addOverlay(markername);     
    } 
    
      function Center_Town(xkoor, ykoor) {  
        point = new GLatLng(ykoor,xkoor);
        map.setCenter(point, 11);
    } 
  
  
function vs_aus(nam,bild) {
        document.images[nam].src = bild;
        }
  
    
 function ok(s1)
      {
      hide_div('0');
      hide_div('1');
      hide_div('2');
      hide_div('3');
      hide_div('4');
      hide_div('5');
      show_div(s1);
      }
      
function show_info(s1) {    if (s1 == '5')    {        init_map();        var xkoor = document.forms['frm_add'].koor_x.value;
        var ykoor = document.forms['frm_add'].koor_y.value;          document.forms['frm_add'].action="javascript:addKOORToMap()";        document.forms['frm_add'].submit();    }hide_div('1');hide_div('2');hide_div('3');hide_div('4');hide_div('5');show_div(s1);}
   
 function uwe11(xkoor, ykoor)
 {     
      point = new GLatLng(ykoor,xkoor);
      map.setCenter(point, 11);
 }  
  function uwe12(xkoor, ykoor)
 {
     point = new GLatLng(ykoor,xkoor);
     map.panTo(point);
     map.closeInfoWindow();
 }  


  function bl1(bild) 
        {
        var bild0 = "img/" + bild + ".gif";
        document.images['karte'].src = bild0;           
        }
  function show_stadtliste()
        {
        document.forms['frm_add'].stadt.style.visibility = "visible";
        }
  function bl2(bild, name,typ)
        {
        document.forms['frm_add'].typ.value = typ;
        document.forms['frm_add'].stadt.value = '0';
        document.forms['frm_add'].stname.value = '';            
        document.forms['frm_add'].tabelle.value = 'z_bundeslaender';
        document.forms['frm_add'].bl.value = bild;
        document.forms['frm_add'].blname.value = name;
        var bild0 = "../img/" + bild + ".gif";
        document.images['orgkarte'].src = bild0;
        document.forms['frm_add'].action="geo_suche.php?typ="+typ;        document.forms['frm_add'].submit();
        }
function bl4(typ)
        {
        document.forms['frm_add'].typ.value = typ;
        document.forms['frm_add'].tabelle.value = 'z_stadt';
        document.forms['frm_add'].stname.value = document.forms['frm_add'].stadt.value;
        document.forms['frm_add'].action="geo_suche.php?typ="+typ;        document.forms['frm_add'].submit();            
        } 
function wert_geaendert(){        document.forms['suchen'].action="suche_eingabe.php";        document.forms['suchen'].submit();        }function show_div (divname) {
        document.getElementById(divname).style.visibility = "visible";
        }
function hide_div (divname) {
        document.getElementById(divname).style.visibility = "hidden";
        }        function show_liste () {          hide_div('suchfelder');          show_div('erg_liste');        }function show_suche () {          show_div('suchfelder');          hide_div('erg_liste');          }  function show_agb(a1){        hide_div('agb1');        hide_div('agb2');            if (a1 == '1')             {            show_div('agb1');            }            if (a1 == '2')             {            show_div('agb2');            }        }             function show_gastro(a1){        hide_div('gastro1');        hide_div('gastro2');            if (a1 == '1')             {            show_div('gastro1');            }            if (a1 == '2')             {            show_div('gastro2');            }        }              function show_details(a1){init_map();show_div (a1);}
