// JavaScript 
// Arcanodor G Maps
//<![CDATA[
// replace string
var str='';

 str+='<img src="/redmedia/unternehmen/img/layout/h1_routenplaner.gif"\/><p><\/p>';
 str+=' <form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">';
 str+=' <table><input type="hidden" name="locale" value="en"/>';
 str+='   <tr>';
 str+='     <th align="right">From:&nbsp;<\/th>';
 str+='     <td><input type="text" size="31" id="fromAddress" name="from"';
 str+='     value=""\/><\/td>';
 str+='   <th align="right">&nbsp;&nbsp;To:&nbsp;<\/th>';
 str+='   <td align="right"><input type="text" size="31" id="toAddress" name="to"';
 str+='     value="Theodor-Althoff-Str. 2, 45133 Essen, Germany" \/><\/td><\/tr>';
 str+='   <tr>';
 //str+='     <th>Sprache:&nbsp;<\/th>';
 str+='     <td colspan="4" align="right">';
 //<select id="locale" name="loca_le">';
 //str+='    <option value="en">English<\/option>';
 //str+='    <option value="fr">French<\/option>';
 //str+='    <option value="de" selected>German<\/option>';
 //str+='    <option value="ja">Japanese<\/option>';
 //str+='    <option value="es">Spanish<\/option>';
 //str+='    <\/select>';
 str+='    <input name="submit" type="submit" value="Show Route" onclick="initialize()" \/>';
 str+='   <\/td><\/tr>';
 str+='   <\/table>';
 str+='    ';
 str+='  <\/form>';
 str+='    <br\/>';
 str+='    <table class="directions">';
 str+='    <tr><th><span class="headline">Directions<\/span><\/th><th>Map<\/th><\/tr>';
 str+='    <tr>';
 str+='    <td valign="top"><div id="directions" style="width: 275px"><\/div><\/td>';
 str+='    <td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"><\/div><\/td>';
 str+='    <\/tr>';
 str+='    <\/table> ';
// replace string end !
// standart Map
      var side_bar_html = "";
    
      var gmarkers = [];
      var htmls = [];
      var i = 0;
      var map;
   var gdir;
   var geocoder = null;
   var addressMarker;
       if (GBrowserIsCompatible()) {
    function createMarker(point,name,html) {
        html = '<div style="white-space:nowrap;">' + html + '</div>';
        var marker = new GMarker(point, {title:name});
        
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        
        map.addOverlay(marker);
      }
      var map = new GMap2(document.getElementById("map1"));
      map.setCenter(new GLatLng(51.417150,6.980152), 15);
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      var request = GXmlHttp.create();
      request.open("GET", "/redmedia/unternehmen/download/google.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < markers.length; i++) {
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            var marker = createMarker(point,label,html);
          }
        }
      }
      request.send(null);
    }
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
 
// standart Map end !
// Routenplanner / directions
    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
  map.addControl(new GSmallMapControl());
       // GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        setDirections("", "Theodor-Althoff-Str. 2, 45133 Essen, Germany", "en_EN");
      }
    }
    
    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 wurden keine Geodaten f&uuml;r Ihre Eingabe gefunden. Bitte &uuml;berpr&uuml;fen Sie Ihre Eingabe.Es kann jedoch sein das die Adresse neu ist.\nError code: " + gdir.getStatus().code);
     alert("No matching geodata could be found. Please verify your request. It is possible that the entered address is not yet implemented.");

    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
      //alert("Ein Fehler ist bei der Anfrage aufgetreten,bitte versuchen Sie es später nochmal.\n Error code: " + gdir.getStatus().code);
      alert("Your request could not be processed");
    
    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
      alert("Your input is incomplete. Please complete all sections. ");
      
   // else if (gdir.getStatus().code == G_GEO_BAD_KEY)
      //alert("Google Key ist falsch. Bitte überprüfen. \n Error code: " + gdir.getStatus().code);
     // alert("Your Google Key is wrong. Please verify. ");
    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     // alert("An error occurred during processing. Please try again later.\n Error code: " + gdir.getStatus().code);
      alert("An error occurred during processing. Please try again later.");     
    else alert("An unknown error occured");
    
 }
 
// Routenplanner / directions ende
// replace hack
 function replaceDiv(){
 var content = document.getElementById('singleMap').innerHTML;
 document.getElementById('singleMap').innerHTML = (str);
 }
  
// replace hack ende
//]]>
