function anzeigen(id)
{
        with (document)
        {
                if (getElementById)
                        getElementById(id).style.display = 'block';
                else if (all)
                        all[id].style.display = 'block';
                else
                        layers[id].display = 'block';
        }
}

function verstecken(id)
{
        with (document)
        {
                if (getElementById)
                        getElementById(id).style.display = 'none';
                else if (all)
                        all[id].style.display = 'none';
                else
                        layers[id].display = 'none';
        }
}


function show_open(placeHolder, siteUrl, height)
{
    pos = ($(window).width() - $(placeHolder).width())/2;
    $(placeHolder).css("left", pos + "px");
    $(placeHolder).height(height);
    $(placeHolder).addClass("loading");
    $(placeHolder + ':hidden').show();
    $.ajax({type: "GET",
        url: siteUrl,
        success: function(html){
            $(placeHolder).removeClass("loading").html(html);
        }
    });
    $(placeHolder).click(function() {
        $(this).hide();
        $(this).html("");
    });
}

function close_open(placeHolder) {
    $(placeHolder + ':visible').hide();
    $(placeHolder).html("");
}

function chkFormular () {
  /*Those fields can be simply checked if there is a value present or not */
  fieldarray = new Array("Nachname", "Vorname", "Geburtsdatum", "Strasse", "Ort", "Mietobjekt");
  errorarray = new Array();
  // regex definitions for tests
  plzregex = /\d{5}/g;
  personenregex = /[1-9]{1,2}/g;
  kinderregex = /[0-9]{1,2}/g;


  for (i=0;i<fieldarray.length;i++) {
      var n = fieldarray[i].toLowerCase();
      if(document.Kontaktformular[n].value.replace(/\s+/g, "").length == 0) {
          errorarray.push("Bitte " + fieldarray[i] + " angeben!");
      }
  }
  
  if (plzregex.test(document.Kontaktformular.plz.value) == false) {
    errorarray.push("Bitte korrekte Postleitzahl angeben!");
  }

  if (personenregex.test(document.Kontaktformular.personenanzahl.value) == false) {
    errorarray.push("Bitte korrekte Personenanzahl angeben! Nur Zahlen verwenden");
  }

  if (document.Kontaktformular.kinder.value.replace(/\s+/g, "").length == 0) {
    errorarray.push("Anzahl der Kinder und Alter angeben! 0 für keine Kinder");
  }

  if (document.Kontaktformular.email.value.indexOf("@") == -1) {
    errorarray.push("Bitte korrekte Email angeben!");
  }

  if (document.Kontaktformular.abholtag.value.replace(/\s+/g, "").length == 0) {
    errorarray.push("Bitte Ihren Abholtag eingeben!");
  }

  if (document.Kontaktformular.rueckkehrtag.value.replace(/\s+/g, "").length == 0) {
    errorarray.push("Bitte Ihren Rückkehrtag eingeben!");
  }



  if (errorarray.length > 0) {
      alert(errorarray.join("\n"));
      return false;
  }
  return true;
}

 jQuery(document).ready(function() {
    var options = {
        success:       showResult,
        url:       "inquiry.php",        
        type:      'post',      
        dataType:  'json',    
        clearForm: true  
    };
    jQuery('#fhzform').ajaxForm(options);
});

function showResult(data) {
    jQuery("#msgholder").html("&nbsp;");
    if(data.status == "ok") {
        jQuery("#inquiryLink").replaceWith("Fahrzeug angefragt. Vielen Dank!");
        hideFhzForm();
    } else {
        jQuery("#msgholder").html(data.message);
    }
}

function showFhzForm() {
    var pos = jQuery("#inquiryLink").show().position();
    jQuery("#box").css('left', pos.left);
    jQuery("#box").css('top', pos.top);
    jQuery("#box").fadeIn("fast");
    
}

function hideFhzForm() {
      jQuery("#box").fadeOut("slow");
      jQuery("#msgholder").html("&nbsp;");
}

document.onkeydown = function(e){
  if (e == null) {
    keycode = event.keyCode;
  } else {
    keycode = e.which;
  }
  if(keycode == 27){
    hideFhzForm();
  }
}

