﻿// JavaScript 
// Arcanodor G Maps
//<![CDATA[
// replace string

var str='';
    str+=' <form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">';
    str+='  <table id="contacttable" class="layout" cellpadding="0" cellspacing="0"><input type="hidden" name="locale" value="de"/>';
    str+='  <tr>';
    str+='     <td colspan="2">';
    str+='                     <label for="from"><span>Von<\/span><\/label>';
    str+='                     <input type="text" class="text long marginright" id="fromAddress" name="from" value="" \/>&nbsp;&nbsp;';
    str+='                 <\/td>';
    str+='                 <td colspan="2">';
    str+='                     <label for="to"><span>Nach<\/span><\/label>';
    str+='                     <input type="text" class="text long"  id="toAddress" name="to" value="Theodor-Althoff-Str. 2, 45133 Essen, Germany" \/><\/td><\/tr>';
    str+='                 <\/td>';
    str+='             <\/tr>';
    str+='             <tr>';     
    str+='              <td colspan="4" class="right" align="right" style="padding-top:5px;padding-bottom:5px;">';
    str+='                    <a style="display: none; float:right; margin-left:9px;" id="printlink" href="#" onclick="var newin=window.open(\'about:blank\',\'name\',\'height=600,width=800\');newin.document.write(\'<html><style>*{font-family:arial;}a{color:black;text-decoration:none;}#printlink,label,input{display:none!important;}table{width:100%;}#directions{position:relative;bottom:15px;}#map_canvas{margin-left:20px!important;}</style><body><h1>Wegbeschreibung</h1>\'+document.getElementById(\'singleMap\').innerHTML+\'</body></html>\');newin.print();"><img src="/de/images/buttons/dprint_btn.gif" /></a>';    
    str+='                     <input align="right" type="image" id="Submit" src="/de/images/buttons/btn_berechnen_no.gif" value="Route anzeigen" onclick="initialize()" \/>';
    //str+='                    <a style="display: block;" id="printlink" href="#" onclick="var newin=window.open(\'about:blank\',\'name\',\'height=600,width=800\');newin.document.write(\'<html><style>*{font-family:arial;}a{color:black;text-decoration:none;}#printlink,label,input{display:none!important;}table{width:100%;}#directions{position:relative;bottom:15px;}#map_canvas{margin-left:20px!important;}</style><body><h1>Wegbeschreibung</h1>\'+document.getElementById(\'singleMap\').innerHTML+\'</body></html>\');newin.print();newin.close();">drucken</a>';
    str+='                 <\/td>';
    str+='             <\/tr>';
    //str+='   <tr>';
    //str+='     <th align="right">Von:&nbsp;<\/th>';
    //str+='     <td><input type="text" size="31" id="fromAddress" name="from"';
    //str+='     value=""\/><\/td>';
    //str+='   <th align="right">&nbsp;&nbsp;Nach:&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+='     <td colspan="4" align="right">';
    //str+='    <input name="submit" type="submit" value="Route anzeigen" onclick="initialize()" \/>';
    //str+='   <\/td><\/tr>';
    //str+='   <\/table>';
    str+='    ';
    str+='  <\/form>';
    str+='    <br\/>';
    str+='    <table class="directions">';
    str+='    <tr><th><span class="headline">Wegbeschreibung<\/span><\/th><th>Karte<\/th><\/tr>';
    str+='    <tr>';
    str+='    <td valign="top"><div id="directions"><\/div><\/td>';
    str+='    <td valign="top">';
    str+='    <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);
       // GEvent.trigger(marker,'click');
      }
      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", "arcandorgmaps.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 html = "Arcandor AG<br/><br>Theodor-Althoff-Stra&szlig;e 2<br>D-45133 Essen<br><br>Telefon: +49 (0)201 727 1<br>Fax: +49 (0)201 727 52 16";
            var label = markers[i].getAttribute("label");
            var marker = createMarker(point,label,html);
          }
        }
      }
      request.send(null);
    }
    else {
      alert("Leider ist Ihr Browser nicht mit GoogleMaps kompatibel");
    }
    
// 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", "de_DE");
      }
    }
    

    function setDirections(fromAddress, toAddress, locale) {
      document.getElementById('directions').innerHTML = "";
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }
            function onGDirectionsLoad(){
                  /* We will simply scroll down to the directions, but with a little delay so it's loaded */
                  // setTimeout('eval(\'window.location = "#directions_table"\;\')', 500); /* Uncomment this line if you need to */
                  //workaround for firefox not properly resizing the directions-box, instead overlaying the following content. –jg.
                obj = document.getElementById('printlink');
                if (obj) obj.style.display = "block";
                  setTimeout('eval(\'document.getElementById("directions").innerHTML = document.getElementById("directions").innerHTML+"&nbsp;"\;\')', 500);
            }
    /*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&amp;uuml;r Ihre Eingabe gefunden. Bitte &amp;uuml;berpr&amp;uuml;fen Sie Ihre Eingabe.Es kann jedoch sein das die Adresse neu ist.");
       else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
         alert("Ein Fehler ist bei der Anfrage aufgetreten,bitte versuchen Sie es sp&amp;auml;ter nochmal.");
       
       else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
         alert("Ihre Eingabe war unvolst&auml;ndig. Bitte alle Felder bef&uuml;llen.");
         
       else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
         alert("Ihre Anfrage konnte nicht bearbeitet werden.");
        
       else alert(" Ein unbekannter Fehler ist aufgetreten. ");
       
    }
    
// Routenplanner / directions ende
// replace hack
 function replaceDiv(){
    var content = document.getElementById('singleMap').innerHTML;
    document.getElementById('singleMap').innerHTML = (str);
 }
     
// replace hack ende
//]]>