
var cbStart = new Array();
$(document).ready(function() {
    //alert($('#tageskarte').height());
    fixScreenLayout()    
    reservierung();
    send_reserv();
     for (var i = 0; i < cbStart.length; ++i) {
       eval("try { " + cbStart[i] + " } catch(e) {} ");
     }
     $(".tisch[title]").tooltip({

     });
     
     
});

function reservierung() {
    $('.tisch', '#reserv_tischkarte').click(function(){
        $('.tisch_aktiv', '#reserv_tischkarte').removeClass('tisch_aktiv');
        var wert= $(this).attr('wert');
        $('input[name="tischnummer"]').val(wert);
        $(this).addClass('tisch_aktiv');
        
    })
} 

function send_reserv() {
    
    
    $('#send_reserv', '#reserv_tischkarte').click(function(){
        var url = location.host + "/cbmodule/reservierung";
        name1 = $('input[name="name"]').val();
        datum1 = $('input[name="datum"]').val();
        uhrzeit1= $('input[name="uhrzeit"]').val();
        email1 = $('input[name="email"]').val();
        tischnummer1 = $('input[name="tischnummer"]').val();
        anzahl1 = $('input[name="anzahl"]').val();
        telefon1 = $('input[name="telefon"]').val();
        NodeID1 = $('input[name="NodeID"]').val();
        bemerkungen1 = $('#reserv_bemerkung').val();
        var formIsOkay = checkForm(name1, datum1, uhrzeit1, telefon1, email1, tischnummer1, anzahl1)
        if (formIsOkay) {
            $.ajax({
              url: "http://" +location.host + "/cbmodule/reservierung" ,
              type: "POST",
              data: ({name : name1, datum : datum1, NodeID: NodeID1, uhrzeit : uhrzeit1, email : email1, tischnummer: tischnummer1, anzahl : anzahl1, telefon: telefon1, bemerkungen: bemerkungen1}),
              success: function(msg){
              
                    $('input[name="name"]').val("");
                    $('input[name="datum"]').val("");
                    $('input[name="uhrzeit"]').val("");
                    $('input[name="email"]').val("");
                    $('input[name="tischnummer"]').val("");
                    $('input[name="anzahl"]').val("");
                    $('input[name="telefon"]').val("");
                    $('#reserv_bemerkung').val("");
                     
                alert('Ihre Anfrage wurde verschickt.');
                
              }
            });            
        }


    })
}

function checkForm(name, datum, uhrzeit, telefon, email, tischnummer, anzahl)
{
    fError = false;
    errorString = "";
    var check = true;


    if (name.length == 0) {
      fError = true;
      errorString = errorString + "\nName";
    }
    if (datum.length == 0) {
      fError = true;
      errorString = errorString + "\nDatum";
    }
    if (uhrzeit.length == 0) {
      fError = true;
      errorString = errorString + "\nUhrzeit";
    }
    if (telefon.length == 0) {
      fError = true;
      errorString = errorString + "\nTelefon";
    }
    if (email.length == 0) {
      fError = true;
      errorString = errorString + "\nE-Mail";
    }
    if (tischnummer.length == 0) {
      fError = true;
      errorString = errorString + "\nTischnummer";
    }
    if (anzahl.length == 0) {
      fError = true;
      errorString = errorString + "\nAnzahl Personen";
    }

    if (fError == true) {
      alert( "Folgende Felder müssen ausgefüllt werden:\n" + errorString );
      check = false;
    } 
    return check;
}

function fixScreenLayout() {
    var tageskarteH = $('#tageskarte').height();
    var inhaltH = $('#inhalt').height();
    var height = 0; 
    
    if ( tageskarteH > inhaltH ) {
        $('#inhalt').height(tageskarteH)
        height = tageskarteH; 
    } else {
        heigth = inhaltH;
    }
    
    var documentH = $(document).height();
    
    if ( documentH > height + 440 ) {
        $('#inhalt').height(documentH - 440);
    } 
       
}

$(window).resize(function() {
  fixScreenLayout();
});     

