// ************************************************************************
// Autor: Thomas Bauer                                                    *
// erstellt am: 21.04.2011                                                *
// ************************************************************************
// Funtionen:                                                             *
//    initAnfahrt:     Anfahrts-Seite initialisieren                      *
//                     FUNKTION: google-maps.js- showMap                  *
//                               google-maps.js- setRoute                 *
//                               initFormDB                               *
//                     FILE: http://www.vvs.de/...                        *
//                     FUNKTION: google-maps.js - showMaps                *
//    Funktionen fuer die Anzeige des Bahnformulares                      *
// ************************************************************************

// Anfahrts-Seite initialisieren
function initAnfahrt() {
   // Buttons initialisieren
   $('.Buttonset').buttonset();
   // Google Maps vordefinieren fuer 1. Auswahl
   var strBreite  = $('#Breitengrad_1').val();
   var strLaenge  = $('#Laengengrad_1').val();
   var strMarker  = '<table style="margin-top:10px;">'+
                    '   <tr>'+
                    '       <td><img src="'+$('#Bild_1').val()+'" width="100" height="100" style="margin-right:10px;"></td>'+
                    '       <td>&nbsp;</td>'+
                    '       <td valign="top">'+
                    '          '+$('#Name_1').val()+'<br>'+
                    '          '+$('#Strasse_1').val()+'<br><br>'+
                    '          <b>'+$('#Ort_1').val()+'</b>'+
                    '          '+
                    '       </td>'+
                    '   </tr>'+
                    '</table>';
   if(location.href.indexOf('local')==-1)
      showMap(strBreite,strLaenge,strMarker);
   // Google Maps entsprechend der Auswahl aktualisieren
   $('#Buttonset1 label span').click(function(evt) {
      var strID      = $(this).parent().attr('for');
      var intID      = $(this).parent().parent().children('#'+strID).attr('value');
      var strBreite  = $('#Breitengrad_'+intID).val();
      var strLaenge  = $('#Laengengrad_'+intID).val();
      var strMarker  = '<table style="margin-top:10px;">'+
                       '   <tr>'+
                       '       <td><img src="'+$('#Bild_'+intID).val()+'" width="100" height="100" style="margin-right:10px;"></td>'+
                       '       <td>&nbsp;</td>'+
                       '       <td valign="top">'+
                       '          '+$('#Name_'+intID).val()+'<br>'+
                       '          '+$('#Strasse_'+intID).val()+'<br><br>'+
                       '          <b>'+$('#Ort_'+intID).val()+'</b>'+
                       '          '+
                       '       </td>'+
                       '   </tr>'+
                       '</table>';
      if(location.href.indexOf('local')==-1)
         showMap(strBreite,strLaenge,strMarker);
   });
   // Berechnung der Route ueber Google Maps initialisiern
   $('#formGoogleMaps a').click(function(evt) {
      evt.preventDefault();
      var intID = $('#Buttonset1 input:checked').attr('value');
      setRoute($('#Start').val(),$('#Strasse_'+intID).val()+', '+$('#Ort_'+intID).val())
   });
   // Radplaner entsprechend der Auswahl aktualisieren
   $('#Buttonset2 label span').click(function(evt) {
      var strID      = $(this).parent().attr('for');
      var intID      = $(this).parent().parent().children('#'+strID).attr('value');
      $('#Rad_VVS').attr('src','http://www.vvs.de/fileadmin/templatesvvs/efaaufhp/scripts/php/radroutenplaner_generator.php?htmlcode=formular&fpauskunft=anreise&standort=adresse&standort_bez='+$('#Strasse_'+intID).val()+'&standort_ort='+$('#Ort_'+intID).val()+'&standort_name='+$('#Name_'+intID).val()+'&fpausgabe=neues_fenster&fpsprache=de');
   });
   // VVS-Auskunft entsprechend der Auswahl aktualisieren
   $('#Buttonset3 label span').click(function(evt) {
      var strID      = $(this).parent().attr('for');
      var intID      = $(this).parent().parent().children('#'+strID).attr('value');
      var strStrasse = $('#Strasse_'+intID).val();
      var strOrt     = $('#Ort_'+intID).val();
      var strName    = $('#Name_'+intID).val();
      $('#VVS').attr('src','http://www.vvs.de/fileadmin/templatesvvs/efaaufhp/scripts/php/efaaufhp_generator.php?htmlcode=formular&fpauskunft=anreise&standort=adresse&standort_bez='+strStrasse+'&standort_ort='+strOrt+'&standort_name='+strName+'&fpausgabe=neues_fenster&fpsprache=de&fpshowtime=true');
      $('#Stadtplanausschnitt').attr('href','http://www2.vvs.de/vvs/XSLT_ROP_REQUEST?&anyObjFilter_rop=0&deleteAssignedStops_rop=0&execInst=normal&formRopPunkte=on&itdLPxx_id_rop=:rop&itdLPxx_mdvMap_rop=3513400:754800:NBWT&language=de&locationServerActive=1&lsShowTrainsExplicit=1&mode=odv&name_rop='+strStrasse.replace(/ /g,'+')+'+'+strOrt.replace(/ /g,'+')+'&reqType=spa&requestID=0&sessionID=0&type_rop=any&w_objPrefAl=2&w_objPrefAl=12&w_regPrefAm=1&itdLPxx_openDirect=1');
      $('#Stadtplanausschnitt').attr('title','Standort: '+strName+', '+strStrasse+', '+strOrt);
   });
   // Bahnauskunft initialisieren
   initFormDB();
   // Bahnauskunft entsprechend der Auswahl initialisieren
   $('#Buttonset4 label span').click(function(evt) {
      var strID      = $(this).parent().attr('for');
      var intID      = $(this).parent().parent().children('#'+strID).attr('value');
      $('#db-ziel').val($('#Ort_'+intID).val()+', '+$('#Strasse_'+intID).val());
   });
   // entsprechenden Button (Checkbox) aktivieren (default: 1. Checkbox)
   var intAdresse = ($('#AdresseID').val()=='') ? 1 : $('#AdresseID').val() * 2 - 1;
   $('.Buttonset').each(function() { $(this).children(':eq('+intAdresse+')').children('span').click(); });
   // Google Maps oeffnen, wenn eine Adresse uebergeben wurde
   if($('#AdresseID').val()!='') {
      $('.Akkordion').accordion("activate",0);
      $('#Buttonset1 input:checked').click();
   }
}

// *****************************************************************************
// Funktionen fuer die Anzeige des Bahnformulares
// *****************************************************************************
function initFormDB() {
   var DBcurrentTime     = new Date();
   var DBhours           = DBcurrentTime.getHours();
   var DBminutes         = DBcurrentTime.getMinutes();
   var DBhoursDisplay    = ((DBhours < 10) ? "0" + DBhours : DBhours);
   var DBminutesDisplay  = ((DBminutes < 10) ? "0" + DBminutes : DBminutes);
   var DBfullTime        = DBhoursDisplay + ":" + DBminutesDisplay;
   document.getElementById("db-time").setAttribute("value", DBfullTime);

   var DBcurrentDate = new Date();
   var DBday         = ((DBcurrentDate.getDate()<10) ? "0" : "") + DBcurrentDate.getDate();
   var DBmonth       = (((DBcurrentDate.getMonth()+1) <10) ? "0" : "") + (DBcurrentDate.getMonth()+1);
   var DByear        = DBcurrentDate.getFullYear();var DBfullDate = DBday + "." + DBmonth + "." + DByear;
   document.getElementById("db-date").setAttribute("value", DBfullDate);

   var start_changed = 0;
   var ziel_changed  = 1;
}

function bahn_submit() {
   if ( !start_changed ) {
      document.getElementById("db-start").value = "";
   }
   var ziel_submit = document.getElementById("db-ziel").value;
}

function set_changed(which) {
   if (which == "depart") {
      start_changed = 1;
   }
   else {
      ziel_changed = 1;
   }
}
