
   /******************************************************************
    GOOGLE MAPS ROUTENPLANER
    *****************************************************************/

   var geocoder = new GClientGeocoder();


   function gmaps_routenplaner_load() {

      if (GBrowserIsCompatible()) {

         map = new GMap2(document.getElementById("routenplaner"));

         map.addControl(new GLargeMapControl());
         map.addControl(new GMapTypeControl());

         map.disableDoubleClickZoom();
         map.enableScrollWheelZoom();

         if(LC_MULTIADDRESS) {

            gmaps_routenplaner_xml();

         } else {

            gmaps_routenplaner_config();

         }

      } else {

         alert("Leider ist Ihr Browser nicht kompatibel mit Google Maps.");

      }

   }


   function gmaps_routenplaner_xml() {

      GDownloadUrl("./xml/routenplaner.xml", function(data, responseCode) {

         var xml = GXml.parse(data);
         var markers = xml.documentElement.getElementsByTagName("marker");

         for (var i = 0; i < markers.length; i++) {

            var itemdata = new Array();

            itemdata["MB_OWNERNAME"]    = markers[i].getAttribute("firma");
            itemdata["MB_OWNERSTREET"]  = markers[i].getAttribute("strasse");
            itemdata["MB_OWNERPLZ"]     = markers[i].getAttribute("plz");
            itemdata["MB_OWNERORT"]     = markers[i].getAttribute("ort");
            itemdata["MB_OWNERLAND"]    = markers[i].getAttribute("land");
            itemdata["MB_OWNERFON"]     = markers[i].getAttribute("telefon");
            itemdata["MB_OWNERFAX"]     = markers[i].getAttribute("telefax");
            itemdata["MB_OWNERINT"]     = markers[i].getAttribute("int");
            itemdata["MB_OWNERLOGO"]    = markers[i].getAttribute("logo");
            itemdata["MB_OWNERICON"]    = markers[i].getAttribute("icon");
            itemdata["MB_ICONSIZE"]     = markers[i].getAttribute("iconsize");

            gmaps_routenplaner_data(itemdata["MB_OWNERSTREET"] + ', ' + itemdata["MB_OWNERPLZ"] + ' ' + itemdata["MB_OWNERORT"] + ', ' + itemdata["MB_OWNERLAND"], itemdata);

         }

      });

   }


   function gmaps_routenplaner_config() {

      var itemdata = new Array();

      itemdata["MB_OWNERNAME"]    = LC_OWNERNAME;
      itemdata["MB_OWNERSTREET"]  = LC_OWNERSTREET;
      itemdata["MB_OWNERPLZ"]     = LC_OWNERPLZ;
      itemdata["MB_OWNERORT"]     = LC_OWNERORT;
      itemdata["MB_OWNERLAND"]    = LC_OWNERLAND;
      itemdata["MB_OWNERFON"]     = LC_OWNERFON;
      itemdata["MB_OWNERFAX"]     = LC_OWNERFAX;
      itemdata["MB_OWNERINT"]     = LC_OWNERINT;
      itemdata["MB_OWNERLOGO"]    = LC_OWNERLOGO;
      itemdata["MB_OWNERICON"]    = LC_OWNERICON;
      itemdata["MB_ICONSIZE"]     = LC_OWNERICONSIZE;

      gmaps_routenplaner_data(itemdata["MB_OWNERSTREET"] + ', ' + itemdata["MB_OWNERPLZ"] + ' ' + itemdata["MB_OWNERORT"] + ', ' + itemdata["MB_OWNERLAND"], itemdata);

   }


   function gmaps_routenplaner_data(address, itemdata) {

      geocoder.getLatLng(address, function(point) {

         if (point) {

            map.setCenter(point, LC_ZOOMLEVEL, LC_MAPTYPE);

            if(LC_BOXTYPE == 'info') { gmaps_routenplaner_info(point, itemdata); return; }
            if(LC_BOXTYPE == 'navi') { gmaps_routenplaner_navi(point, itemdata); return; }
            if(LC_BOXTYPE == 'flag') { gmaps_routenplaner_flag(point, itemdata); return; }

         } else {

            alert(address + " nicht gefunden");

         }

      });

   }


   function gmaps_routenplaner_icon(coords, itemdata) {

      if(itemdata["MB_OWNERICON"] && itemdata["MB_ICONSIZE"]) {

         baseIcon                   = new GIcon();
         baseIcon.image             = itemdata["MB_OWNERICON"];
         baseIcon.iconSize          = new GSize(itemdata["MB_ICONSIZE"].split(",")[0], itemdata["MB_ICONSIZE"].split(",")[1]);
         baseIcon.iconAnchor        = new GPoint((itemdata["MB_ICONSIZE"].split(",")[0])/2, (itemdata["MB_ICONSIZE"].split(",")[1])/2);
         baseIcon.infoWindowAnchor  = new GPoint((itemdata["MB_ICONSIZE"].split(",")[0])/2, (itemdata["MB_ICONSIZE"].split(",")[1])/2);

         return new GMarker(coords, new GIcon(baseIcon));

      } else {

         return new GMarker(coords);

      }

   }


   function gmaps_routenplaner_info(coords, itemdata) {

      var marker = gmaps_routenplaner_icon(coords, itemdata);

      var html   = '<div class="gmaps_info">';

         if(itemdata["MB_OWNERNAME"])    html += '<b>' + itemdata["MB_OWNERNAME"] + '</b><br />';
         if(itemdata["MB_OWNERSTREET"])  html += itemdata["MB_OWNERSTREET"] + ', ';
         if(itemdata["MB_OWNERORT"])     html += itemdata["MB_OWNERPLZ"] + ' ' + itemdata["MB_OWNERORT"] + '<br />';
         if(itemdata["MB_OWNERFON"])     html += 'Telefon: ' + itemdata["MB_OWNERFON"] + '<br />';
         if(itemdata["MB_OWNERFAX"])     html += 'Telefax: ' + itemdata["MB_OWNERFAX"] + '<br />';
         if(itemdata["MB_OWNERINT"])     html += '<a href="' + itemdata["MB_OWNERINT"] + '">Weitere Informationen</a><br />';

      html += '</div>';

      GEvent.addListener(marker, "click", function() {
         marker.openInfoWindowHtml(html);
      });

      map.addOverlay(marker);

   }


   function gmaps_routenplaner_navi(coords, itemdata) {

      var marker = gmaps_routenplaner_icon(coords, itemdata);

      var html   = '<div class="gmaps_navi">';

      html += '<img src="'+itemdata["MB_OWNERLOGO"]+'" alt="'+itemdata["MB_OWNERNAME"]+'" />';
      html += '<form name="routenplaner_form" class="routenplaner_form" method="get" action="http://maps.google.de/maps" target="_blank">';
      html += '<input name="f" type="hidden" value="d" /><input name="hl" type="hidden" value="de" />';
      html += '<input name="daddr" type="hidden" value="'+itemdata["MB_OWNERSTREET"]+', '+itemdata["MB_OWNERPLZ"]+' '+itemdata["MB_OWNERORT"]+', '+itemdata["MB_OWNERLAND"]+' " />';
      html += '<input name="t" type="hidden" value="h" /><input name="om" type="hidden" value="1" />';
      html += '<input name="saddr" type="text" value="Ihre Adresse..." onFocus="this.value=\'\'" />';
      html += '<input type="submit" name="Submit" value="Route berechnen" />';

      html += '</form></div>';

      GEvent.addListener(marker, "click", function() {
         marker.openInfoWindowHtml(html);
      });

      map.addOverlay(marker);

   }


   function gmaps_routenplaner_flag(coords, itemdata) {

      var marker = gmaps_routenplaner_icon(coords, itemdata);

      map.addOverlay(marker);

   }


