  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  string $date
  * @param  bool $tohuman
  * @return -
  */ 
  function formatDate (date, tohuman) {
    if (tohuman) {
      var a=date.split ('-');
      if (a.length != 3)
        return date;
      var a2=a[2]; var a1=a[1];
      if (a2.length==1) a[2]='0'+a[2];
      if (a1.length==1) a[1]='0'+a[1];
      return a[2]+'.'+a[1]+'.'+a[0];
    } 
    else {
      var a=date.split ('.');
      if (a.length == 3) {
        var a0=a[0]; var a1=a[1];
        if (a0.length==1) a[0]='0'+a[0];
        if (a1.length==1) a[1]='0'+a[1];
        return a[2]+'-'+a[1]+'-'+a[0];
      } 
      else if (a.length == 2) {
        var a0=a[0]; var a1=a[1];
        if (a0.length==1) a[0]='0'+a[0];
        if (a1.length==1) a[1]='0'+a[1];
        return a[1]+'-'+a[0];
      }
      else 
        return date;
    }
  }
  
  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function roundWithDecimals (x, n) {
    if (n < 1 || n > 14) 
      return false;
    var e = Math.pow(10, n);
    var k = (Math.round(x * e) / e).toString();
    if (k.indexOf('.') == -1) 
      k += '.';
    k += e.toString().substring(1);
    return k.substring(0, k.indexOf('.') + n+1);
  }
  /**
  * number_format(number, decimals, dec_point, thousands_sep);
  */
  function number_format( number, decimals, dec_point, thousands_sep ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://crestidg.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     
 
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
  }
  
  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function calculateObjectprice (formindex) {
    var countpersons = document.forms[formindex].elements[0].value;
    var pricerenter  = document.forms[formindex].elements[1].value;
    var margin       = document.forms[formindex].elements[2].value;
    var priceseller  = document.forms[formindex].elements[3].value;
    
    // Personenanzahl nicht gesetzt:
    if ((countpersons == '') || (countpersons == '0')) {
      alert ('Personenanzahl darf nicht leer sein!');
      return false;
    }
    // VK-Preis ist nicht gesetzt:
    if ((priceseller == '') || (priceseller == '0.00')) {
      if ((pricerenter != '') && (pricerenter != '0.00') && (margin != '') && (margin != '0.00')) {
        priceseller = 100*pricerenter/(100-margin);
        document.forms[formindex].elements[3].value = roundWithDecimals(priceseller, 2);
      }
    }
    // Vermieterpreis ist nicht gesetzt
    else if ((pricerenter == '') || (pricerenter == '0.00')) {
      if ((priceseller != '') && (priceseller != '0.00') && (margin != '') && (margin != '0.00')) {
        pricerenter = priceseller*((100-margin)/100);
        document.forms[formindex].elements[1].value = roundWithDecimals(pricerenter, 2);
      }
    }
    // Marge ist nicht gesetzt
    else if ((margin == '') || (margin == '0.00')) {
      if ((priceseller != '') && (priceseller != '0.00') && (pricerenter != '') && (pricerenter != '0.00')) {
        margin = 100 - 100*pricerenter/priceseller;
        document.forms[formindex].elements[2].value = roundWithDecimals(margin, 2);
      }
    }
    else {
      alert ('Kein leeres Feld gefunden!');
    }  
  } 

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkMaxPersoncountForScalepriceDelete (formindex, maxpersons, cannotDeleteMaxPersoncount, question) {
    var countpersons = document.forms[formindex].elements[0].value;
    // Personenanzahl nicht gesetzt:
    if (countpersons == maxpersons) {
      alert (cannotDeleteMaxPersoncount);
      return false;
    }
    else
      return askDelete (question);
  }

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkDataForScaleprice (formindex, maxpersons, newPersoncountTooBig, newPersoncountEmpty, pricesellerEmpty, pricerenterEmpty) {
    var countpersons = document.forms[formindex].elements[0].value;
    var pricerenter  = document.forms[formindex].elements[1].value;
    var priceseller  = document.forms[formindex].elements[3].value;
    
    // Personenanzahl nicht gesetzt:
    if (countpersons > maxpersons) {
      alert (newPersoncountTooBig);
      return false;
    }
    if ((countpersons == '') || (countpersons == '0')) {
      alert (newPersoncountEmpty);
      return false;
    }
    // VK-Preis ist nicht gesetzt:
    if ((priceseller == '') || (priceseller == '0.00')) {
      alert (pricesellerEmpty);
      return false;
    }
    // Vermieterpreis ist nicht gesetzt
    if ((pricerenter == '') || (pricerenter == '0.00')) {
      alert (pricerenterEmpty);
      return false;
    }
    
    // Marge ist nicht gesetzt
    var margin = 100 - 100*pricerenter/priceseller;
    document.forms[formindex].elements[2].value = roundWithDecimals(margin, 2);
    return true;
  } 
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setNewSeasontemplate () {
    var newTemplateName = document.seasonnewtemplateform.newtemplatename.value;
    if (newTemplateName.length == 0) {
      alert ("Es wurde kein Name angegeben, unter dem die Vorlage gespeichert werden soll!");
      return;
    }
      
    var seasontimes = formatDate(document.forms[2].elements[1].value, false);
    if (seasontimes == "") {
      alert ("Der erste Eintrag ist leer!");
      return;
    }

    for (i = 2; i < document.forms.length-2; i+=2) {    
      if (document.forms[i].elements[2].value != "") {
        seasontimes += "," + formatDate(document.forms[i].elements[2].value, false);
        somethingAdded = true;
      }
    }
    query = "INSERT INTO fvt_seasontemplate (seasontemplatename, seasontimes, created) VALUES "+
            "('"+newTemplateName+"', '"+seasontimes+"', NOW())";
    xajax_query (query, "updateResult");
  }


  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function getDaysInMonth (monthNo, year) {
    monthNo -= 0;
    year -= 0;
    switch (monthNo) {
      case 1: case 3: case 5:
      case 7: case 8: case 10:
      case 12:
        return 31;
      
      case 2:
        days = 28;
        if (year % 4 == 0)   days = 29;
        if (year % 100 == 0) days = 28;
        if (year % 400 == 0) days = 29;
        return days;
        
      case 4: case 6: 
      case 9: case 11:
        return 30;
    }
  }
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkAndSetDateHiddenFields (formNo, fromfield, tofield, dateFormatInformation, setHiddenFields) {
    if (formNo == -1) {
      var datefrom = document.forms['newSeasontime'].elements[fromfield].value;
      var dateto = document.forms['newSeasontime'].elements[tofield].value;
    }
    else {
      var datefrom = document.forms[formNo].elements[fromfield].value;
      var dateto = document.forms[formNo].elements[tofield].value;
    }
    if ((datefrom[2]!='.') || (datefrom[5]!='.') || (dateto[2]!='.') || (dateto[5]!='.')) {
      alert (dateFormatInformation);
      return false;
    }
    aDate = datefrom.split('.')
    if ((aDate[0] > getDaysInMonth(aDate[1], aDate[2])) || (aDate[1] > 12)) {
      alert (dateFormatInformation);
      return false;
    }
    aDate = dateto.split('.')
    if ((aDate[0] > getDaysInMonth(aDate[1], aDate[2])) || (aDate[1] > 12)) {
      alert (dateFormatInformation);
      return false;
    }
    if (setHiddenFields) {
      document.forms[formNo].elements['datefrom'].value = datefrom;
      document.forms[formNo].elements['dateto'].value   = document.forms[formNo].elements[tofield].value;
    }
    return true;
  }
    

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setAvailabilityDate (day, month, year) {
    var newDateHuman   = day+'.'+month+'.'+year;
    var newDateMachine = formatDate(newDateHuman, false);
    var newDateHuman = formatDate(newDateMachine, true);
    // VON ist leer:
    if (document.dateform.datefrom.value == '') {
      // BIS ist nicht leer
      if (document.dateform.dateto.value != '') {
        // Neues größer als BIS?
        if (formatDate (document.dateform.dateto.value, false) < newDateMachine) {
          document.dateform.datefrom.value = document.dateform.dateto.value;
          document.dateform.dateto.value = newDateHuman;
        }
        else {
          document.dateform.datefrom.value = newDateHuman;
        }
      }
      else {
        document.dateform.datefrom.value = newDateHuman;
      }
    }
    // VON ist nicht leer
    else { 
      // BIS ist leer
      if (document.dateform.dateto.value == '') {
        // Neues kleiner als VON?
        if (formatDate (document.dateform.datefrom.value, false) > newDateMachine) {
          document.dateform.dateto.value = document.dateform.datefrom.value;
          document.dateform.datefrom.value = newDateHuman;
        }
        else {
          document.dateform.dateto.value = newDateHuman;
        }
      }
      else {
        document.dateform.datefrom.value = newDateHuman;
        document.dateform.dateto.value = '';
      }
    }
    if (document.editbookingform != null)
      document.editbookingform.arrivaldate.value = document.dateform.datefrom.value;
  }
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function askDelete ($question) {
    return confirm ($question);
  }
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function askQuestion ($question) {
    return confirm ($question);
  }
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function searchBookingForPayment (bookingid, objectid, customerlastname, customerid) {
    if (bookingid != '') {
      document.getElementById('simplesearchlist').style.display="none";
      xajax_searchBookingForPayment (document.forms[0].elements[bookingid].value, '', '', '');
    }
    else {
      document.getElementById('simplesearchlist').style.display="block";
      xajax_searchBookingForPayment ('', document.forms[1].elements[objectid].value, document.forms[1].elements[customerlastname].value, document.forms[1].elements[customerid].value);
    }
  } 
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function searchBanknameForBankaccount(banknumber) {
    xajax_searchBanknameForBankaccount (document.forms[0].elements[banknumber].value);
  } 
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function searchRenterForAccounting() {
    document.getElementById('simplesearchlist').style.display="block";
    xajax_searchRenterForAccounting (document.renter_search.lastname.value, document.renter_search.firstname.value);
  } 
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function searchPersonForSingleInvoice() {
    document.getElementById('simplesearchlist').style.display="block";
    var lastname = '';
    var firstname = '';
    var company = '';
    if (document.person_search.lastname)
      lastname = document.person_search.lastname.value;
    if (document.person_search.firstname)
      firstname = document.person_search.firstname.value
    if (document.person_search.company)
      company = document.person_search.company.value
    xajax_searchPersonForSingleInvoice (lastname, firstname, company);
  } 
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setRenterData (id, name) {
    document.getElementById('simplesearchlist').style.display="none";
    document.accountingform.renterid.value = id;
    document.accountingform.rentername.value = name;
  }
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setPersonData (personid, salutation, title, firstname, lastname, address, addressaddon, zip, city, company, email) {
    document.getElementById('simplesearchlist').style.display="none";
    document.singleinvoiceform.personid.value = personid;
    document.singleinvoiceform.salutation.value = salutation;
    document.singleinvoiceform.title.value = title;
    document.singleinvoiceform.firstname.value = firstname;
    document.singleinvoiceform.lastname.value = lastname;
    document.singleinvoiceform.address.value = address;
    document.singleinvoiceform.addressaddon.value = addressaddon;
    document.singleinvoiceform.zip.value = zip;
    document.singleinvoiceform.city.value = city;
    document.singleinvoiceform.email.value = email;
    if (document.singleinvoiceform.company)
      document.singleinvoiceform.company.value = company;
  }

  /**
  * Setzt die ID ins Vermieter/Schl?sseladdressen-Feld
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setPersonId (persontype, personid) {
    document.getElementById('simplesearchlist').style.display="none";
    if (persontype == 'renter')
      document.webform.renterid.value = personid;
    else
      document.webform.keyholderid.value = personid;
  }

  
  /**
  * Setzt die ID und den Namen ins Kundenfeld
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setPersonIdAndName (persontype, personid, firstname, lastname, email) {
    document.getElementById('simplesearchlist').style.display="none";
    if (persontype == 'customer') {
      document.webform.customerid.value = personid;
      document.webform.customerlastname.value = lastname;
      document.webform.customerfirstname.value = firstname;
      document.webform.customeremail.value = email;
    }
  }

  
  /**
  * Setzt die Objekt-ID ins entsprechende Feld
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setObjectIdAndName (objectid, objectidentifier, objectname) {
    document.getElementById('simplesearchlist').style.display="none";
    document.webform.objectid.value = objectid;
    document.webform.objectidentifier.value = objectidentifier;
    document.webform.objectname.value = objectname;
  }

  
  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setSingleInvoicePrices () {
    var sum = 0;
    if ((document.singleinvoiceform.count1.value != '') && (document.singleinvoiceform.singleprice1.value != '')) {
      var price1 = document.singleinvoiceform.singleprice1.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice1.value = price1;
      document.singleinvoiceform.price1.value = document.singleinvoiceform.count1.value * price1;
      sum += document.singleinvoiceform.count1.value * document.singleinvoiceform.singleprice1.value;
    }
    if ((document.singleinvoiceform.count2.value != '') && (document.singleinvoiceform.singleprice2.value != '')) {
      var price2 = document.singleinvoiceform.singleprice2.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice2.value = price2;
      document.singleinvoiceform.price2.value = document.singleinvoiceform.count2.value * price2;
      sum += document.singleinvoiceform.count2.value * document.singleinvoiceform.singleprice2.value;
    }
    if ((document.singleinvoiceform.count3.value != '') && (document.singleinvoiceform.singleprice3.value != '')) {
      var price3 = document.singleinvoiceform.singleprice3.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice3.value = price3;
      document.singleinvoiceform.price3.value = document.singleinvoiceform.count3.value * price3;
      sum += document.singleinvoiceform.count3.value * document.singleinvoiceform.singleprice3.value;
    }
    if ((document.singleinvoiceform.count4.value != '') && (document.singleinvoiceform.singleprice4.value != '')) {
      var price4 = document.singleinvoiceform.singleprice4.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice4.value = price4;
      document.singleinvoiceform.price4.value = document.singleinvoiceform.count4.value * price4;
      sum += document.singleinvoiceform.count4.value * document.singleinvoiceform.singleprice4.value;
    }
    if ((document.singleinvoiceform.count5.value != '') && (document.singleinvoiceform.singleprice5.value != '')) {
      var price5 = document.singleinvoiceform.singleprice5.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice5.value = price5;
      document.singleinvoiceform.price5.value = document.singleinvoiceform.count5.value * price5;
      sum += document.singleinvoiceform.count5.value * document.singleinvoiceform.singleprice5.value;
    }
    if ((document.singleinvoiceform.count6.value != '') && (document.singleinvoiceform.singleprice6.value != '')) {
      var price6 = document.singleinvoiceform.singleprice6.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice6.value = price6;
      document.singleinvoiceform.price6.value = document.singleinvoiceform.count6.value * price6;
      sum += document.singleinvoiceform.count6.value * document.singleinvoiceform.singleprice6.value;
    }
    if ((document.singleinvoiceform.count7.value != '') && (document.singleinvoiceform.singleprice7.value != '')) {
      var price7 = document.singleinvoiceform.singleprice7.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice7.value = price7;
      document.singleinvoiceform.price7.value = document.singleinvoiceform.count7.value * price7;
      sum += document.singleinvoiceform.count7.value * document.singleinvoiceform.singleprice7.value;
    }
    if ((document.singleinvoiceform.count8.value != '') && (document.singleinvoiceform.singleprice8.value != '')) {
      var price8 = document.singleinvoiceform.singleprice8.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice8.value = price8;
      document.singleinvoiceform.price8.value = document.singleinvoiceform.count8.value * price8;
      sum += document.singleinvoiceform.count8.value * document.singleinvoiceform.singleprice8.value;
    }
    if ((document.singleinvoiceform.count9.value != '') && (document.singleinvoiceform.singleprice9.value != '')) {
      var price9 = document.singleinvoiceform.singleprice9.value.replace(/,/g, ".");
      document.singleinvoiceform.singleprice9.value = price9;
      document.singleinvoiceform.price9.value = document.singleinvoiceform.count9.value * price9;
      sum += document.singleinvoiceform.count9.value * document.singleinvoiceform.singleprice9.value;
    }
    document.singleinvoiceform.sum.value = sum;
  }
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function setBookingData (bookingid, customername, customerid, objectid, status, traveldates, depositprice, priceoverall, payments) {
    document.getElementById('simplesearchlist').style.display="none";
    document.searchBooking.objectid.value = objectid;
    document.searchBooking.customerlastname.value = customername;
    document.searchBooking.customerid.value = customerid;
    document.searchBooking.traveldates.value = traveldates;
    document.searchBooking.depositprice.value = depositprice;
    document.searchBooking.priceoverall.value = priceoverall;
    document.searchBooking.status.value = status;
    document.searchBooking.payments.value = payments;
    document.forms[0].bookingid.value = bookingid;
  }
  

  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function csspopupRelative(on, id) {
    if(document.getElementById) {
  	  if (on)
        document.getElementById(id).style.display="block";
      else 
        document.getElementById(id).style.display="none"; 
      return false; 
    }
    else 
      return true; 
  }


  /**
  * ?
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function csspopup(on, id) {
    if(document.getElementById) {
  	  if (on)
        document.getElementById(id).style.display="block";
      else 
        document.getElementById(id).style.display="none"; 
      return false; 
    }
    else 
      return true; 
  }
 

  /**
  * Andere Preistabelle schlie?en, bevor eine neue aufgemacht wird
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function cssCloseAll(count) {
    for (i = 0; i < count; i++) {
      if(document.getElementById) {
  	    var id = "objectPrices" + i;
  	    document.getElementById(id).style.display="none"; 
      }
    }
    return false; 
  }

  
  /**
  * Javascript-Funktion, ein div element ausschaltet und eins wieder einschaltet.
  * @author Margrit Schnackenberg, Torsten K?hler
  * @param  block
  * @param  none
  * @return -
  */ 
  function cssDisplayChange (block, none) {
    if (block != '')
      document.getElementById(block).style.display="block";
    if (none != '')
      document.getElementById(none).style.display="none";
  }


  /**
  * Bei den Saisonzeiten im Frotnend + gegen - tauschen und andersrum
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function csstoogle(id, toogleid) {
    var inner = document.getElementById(toogleid).innerHTML;
    if (inner[1] == "-" || document.getElementById(toogleid).innerHTML == "&nbsp;-&nbsp;") {
      document.getElementById(toogleid).innerHTML = "&nbsp;+&nbsp;";
      document.getElementById(id).style.display="none";
    }
    else {
      document.getElementById(toogleid).innerHTML = "&nbsp;-&nbsp;";
      document.getElementById(id).style.display="block";
    }
    return false; 
  }


  /**
  * Pr?fen, ob die Daten f?r die Einzelrechnung ok sind
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkSingleInvoiceData(errorAddress, errorPosition, errorLengthPosition) {
    if ((document.singleinvoiceform.firstname.value == '') || (document.singleinvoiceform.lastname.value == '') ||
        (document.singleinvoiceform.zip.value == '') || (document.singleinvoiceform.city.value == '')) {
      alert (errorAddress);
      return false; 
    }
    
    var MAX_LENGTH_SINGLEINVOICE_LINE = 35;
    
    entryAvailable = false;
    if (document.singleinvoiceform.invoiceposition1.value != "") {
      if (document.singleinvoiceform.invoiceposition1.value.length > MAX_LENGTH_SINGLEINVOICE_LINE) {
        alert (errorLengthPosition + ' 1');
        return false; 
      }
      if ((document.singleinvoiceform.count1.value == "") || (document.singleinvoiceform.price1.value == "")) {
        alert (errorPosition + ' 1');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition2.value != "") {
      if ((document.singleinvoiceform.count2.value == "") || (document.singleinvoiceform.price2.value == "")) {
        alert (errorPosition + ' 2');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition3.value != "") {
      if ((document.singleinvoiceform.count3.value == "") || (document.singleinvoiceform.price3.value == "")) {
        alert (errorPosition + ' 3');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition4.value != "") {
      if ((document.singleinvoiceform.count4.value == "") || (document.singleinvoiceform.price4.value == "")) {
        alert (errorPosition + ' 4');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition5.value != "") {
      if ((document.singleinvoiceform.count5.value == "") || (document.singleinvoiceform.price5.value == "")) {
        alert (errorPosition + ' 5');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition6.value != "") {
      if ((document.singleinvoiceform.count6.value == "") || (document.singleinvoiceform.price6.value == "")) {
        alert (errorPosition + ' 6');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition7.value != "") {
      if ((document.singleinvoiceform.count7.value == "") || (document.singleinvoiceform.price7.value == "")) {
        alert (errorPosition + ' 7');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition8.value != "") {
      if ((document.singleinvoiceform.count8.value == "") || (document.singleinvoiceform.price8.value == "")) {
        alert (errorPosition + ' 8');
        return false; 
      }
      entryAvailable = true;
    }
    if (document.singleinvoiceform.invoiceposition9.value != "") {
      if ((document.singleinvoiceform.count9.value == "") || (document.singleinvoiceform.price9.value == "")) {
        alert (errorPosition + ' 9');
        return false; 
      }
      entryAvailable = true;
    }
    
    if (entryAvailable == false) {
      alert (errorPosition + ' 1-9');
      return false; 
    }
    
    return true;
  }
  
  /**
  * Pr?fen der Reisedaten
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkTraveldates (message, message_dateformat) {
    var objectid = document.dateform.objectid.value;
    var countpersons = document.dateform.countpersons.value;
    var arrivaldate = document.dateform.arrivaldate.value;
    var departuredate = document.dateform.departuredate.value;

    if ((objectid == '') || (countpersons == '') || (arrivaldate == '') || (departuredate == '')) {
      alert (message);
      return false;
    }
    if (!checkdateformat(arrivaldate)){
      alert(message_dateformat);
      return false;
    }
    if (!checkdateformat(departuredate)){
      alert(message_dateformat);
      return false;
    }
    return true
  }

  /**
  * Pr?fen der Passagierdaten
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkFormData(formname, message) {
    //alert(document.forms[formname].elements.length);
    for (i = 0; i < document.forms[formname].elements.length; i++) {
      if (document.forms[formname].elements[i].value == '' ) {
        alert(message);
        return false;
      }
    }
    return true;
  }


  /**
  * Pr?fen der Passagierdaten
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkPassengerData(count, message, message_dateformat) {
    for (i = 0; i < count*4; i++) {
      // jedes 4 Element darf leer bleiben, geburtstag muss nicht ausgef?llt werden
      if (document.passengerform.elements[i].value == '' && document.passengerform.elements[i].name.substr(0,8) != 'birthday') {
        alert(message);
        return false;
      }
      if (document.passengerform.elements[i].name.substr(0,8) == 'birthday' && document.passengerform.elements[i].value != '' ) {
        if (!checkdateformat(document.passengerform.elements[i].value)){
          alert(message_dateformat);
          return false;
        }
      } 
    }
    return true;
  }
  
  /**
  * Pr?fen des Datumsformats
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function checkdateformat(date) {
    var result = date.match(/^([0-9]{2}).([0-9]{2}).([0-9]{4})$/);
    if (result == null)
      return false;
    return (result[0] == date);
  }

  /**
  * Umschalten der Farbe, falls ein Kunde auf die Verf?gbarkeit dr?ckt
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function toogleAvailabilityColor (id) {  
/* passiert zuviel Quatsch, erstmal nicht machen!
    if (document.getElementById(id).style.backgroundColor != 'blue')
      document.getElementById(id).style.backgroundColor = 'blue';
    else
      document.getElementById(id).style.backgroundColor = '00FF00';
*/      
  }
  
  /**
  * -
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function popup(url) {
    var Fenster = window.open(url, "kleines_fenster", "width=600,height=600,scrollbars=yes,status=yes,top=50,left=200");
    Fenster.focus ();
  }
  
  /**
  * -
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */   
  function popupHasso(url) {
    var Fenster = window.open(url, "kleines_fenster", "width=800,height=700,scrollbars=yes,status=yes,top=50,left=200");
    Fenster.focus ();
  }
  
  /**
  * Merkt sich die aktuelle Mausposition
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  document.onmousemove = saveMousePosition;	
  var x = 0, oldx = 0;
  var y = 0, oldy = 0;
	
  function saveMousePosition(e) {
    if (document.all) 
      x = window.event.x + document.body.scrollLeft;
    else
      x = e.pageX;
      
    if (document.all)
      y = window.event.y + document.body.scrollTop;
    else
      y = e.pageY;
  }

  /**
  * Suche einer Person innerhalb eines Formular. Das Ergebnis kommt in die simplesearchlist
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function searchPerson(persontype) {
    document.getElementById('simplesearchlist').style.left = Math.round(x-150) +"px"; 
    document.getElementById('simplesearchlist').style.top = Math.round(y-20) +"px";

    document.getElementById('simplesearchlist').style.display="block";
    switch (persontype) {
      case 'customer':
        xajax_searchPerson(persontype, document.forms[0].elements['customerid'].value);
        break;
      case 'renter':
        xajax_searchPerson(persontype, document.forms[0].elements['renterid'].value);
        break;
      case 'keyholder':
        xajax_searchPerson(persontype, document.forms[0].elements['keyholderid'].value);
        break;
      }
  }

  /**
  * Suche ein Objekt
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function searchObjectSimple () {
    document.getElementById('simplesearchlist').style.left = Math.round(x-150) +"px"; 
    document.getElementById('simplesearchlist').style.top = Math.round(y-20) +"px";

    document.getElementById('simplesearchlist').style.display="block";
    xajax_searchObjectSimple(document.forms[0].elements['objectidentifier'].value);
  }

  /**
  * Weiterleiten zur Suche 
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function redirectToSearch(formname, withSubdestination, FE_URL) {  
    var target = FE_URL + 'index.php?site=search';
    if (document.forms[formname].destinationidentifier.value != '') {
      target += '&destinationidentifier=' + document.forms[formname].destinationidentifier.value;
    }
    if (withSubdestination && document.forms[formname].subdestination.value != '') {
      target += '&subdestination=' + document.forms[formname].subdestination.value;
    }
    window.location.href = target;
  }

  /**
  * Unter-Reiseziele hinzuf?gen
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function addOption (entry) {
    var newEntry = new Option(entry, entry, false, true);
    document.filterview.subdestination.options[document.filterview.subdestination.length] = newEntry;
  }

  /**
  * Unter-Reiseziele ?ndern
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function changeSubdestinations () {
    var cnt = document.filterview.subdestination.length;
    for(i = cnt-1; i >= 0; i--)
      document.filterview.subdestination.options[i] = null;
    xajax_getSubdestinations(document.filterview.destinationname.value);
  }
  
  /**
  * -
  * @author Margrit Schnackenberg / Torsten K?hler
  * @param  -
  * @return -
  */ 
  function abdiepost(empfaenger) {
    window.location = "mailto:" + empfaenger + "touristik.de"; 
  }
  
  /**
  * Prüft, ob die Renterid im Formular für die Abrechungen vorhanden ist
  * @author Margrit Schnackenberg / Torsten Kähler
  * @param  -
  * @return -
  */
  function checkRenterid (message) {
    if (document.accountingform.renterid.value == '') {
      alert (message);
      return false;
    }
    return true;
  }
  
  /**
  * Versucht den Ort zur eingegebenen PLZ zu ermitteln
  * @author Margrit Schnackenberg / Torsten Kähler
  * @param  -
  * @return -
  */
  function searchCity (type) {
    switch (type) {
      case 'person':
        if (document.webform.zip.value.length == 5)
          xajax_searchCity(document.webform.zip.value, 'person');
        break;
      case 'object':
        if (document.webform.objectzip.value.length == 5)
          xajax_searchCity(document.webform.objectzip.value, 'object');
        break;
    }
  }
  
