
function oneway()
    {
        if (document.mainform.onewaybox.checked == true)
        {
            document.mainform.dstDay.disabled = true;
            document.mainform.dstMonth.disabled = true;
        }
        else
        {
            document.mainform.dstDay.disabled = false;
            document.mainform.dstMonth.disabled = false;

        }
    }

function chkFormular()
{
  if(document.bookingmain.cs_fname.value == "")  {
   alert("Bitte Ihren Namen eingeben!");
   document.bookingmain.cs_fname.focus();
   return false;
  }
}

var flyinfo_window = null;

function flyinfo(infotd, zeilen, status)
  {
  if(document.mainform.fluginfo)
    {
    if(status != 0)
      {
      if(flyinfo != null) flyinfo.focus();
      else
        {
        var flyinfo = open('', 'flyinfo', 'left=22,top=22,width='+ (infotd.length * 8 / zeilen) +',height='+ (zeilen * 20) +'');

        flyinfo_window = flyinfo;
        flyinfo.document.open();
        flyinfo.document.writeln('<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"><link rel="stylesheet" type="text/css" href="css/winglob.css"><title>Fly information<\/title><\/head><body  bgcolor=\"#e1e1e1\">');
        flyinfo.document.writeln('<div align=\"center\"><span class=\"textkopf\">'+ infotd +'<\/span><\/div>');
        flyinfo.document.writeln('<\/body><\/html>');
        flyinfo.document.close();
        }
      }
    else
      {
      if(flyinfo_window != null) flyinfo_window.close();
      }
    }
  }


function MM_popupMsg() {
  var msg   = "Flug Informationen";
  alert(msg);
}

function browser() {
  return(navigator.appName.lastIndexOf('scape') != -1 );
}
function isNavVersion4() {
  var majVers = parseInt(navigator.appVersion);
  return (browser() && majVers == 4);
}

var heuteWD    = new Date();

function writeWochentag(daySelect, monthSelect, intoDiv) {

//  if (isNavVersion4()) return;
  var dayVal   = parseInt(document.getElementById(daySelect).value,10);
  var myval    = document.getElementById(monthSelect).value;
  var monthVal = parseInt(myval.substring(0,2),10);
  var yearVal  = parseInt(myval.substring(3),10);

  var d = new Date(yearVal, monthVal-1, dayVal);
  //alert (d);
  document.getElementById(intoDiv).innerHTML=dayNames2[d.getDay()];

}


function update_pickup(){
        var Offset = 7;
        Anmiet1 = document.mainform.depMonth.value.split("-");
        Anmiet2 = document.mainform.dstMonth.value.split("-");
        datum1 = new Date(Anmiet1[1],Anmiet1[0]-1,document.mainform.depDay.value);
        datum2 = new Date(Anmiet2[1],Anmiet2[0]-1,document.mainform.dstDay.value);

        if(datum2.getTime() <= datum1.getTime()){
            switch(Anmiet1[0]){
                case "01":
                case "03":
                case "05":
                case "07":
                case "08":
                case "10":
                case "12":  max_days = 31;
                        break;

                case "04":
                case "06":
                case "09":
                case "11":  max_days = 30;
                        break;

                case "2":   if(Anmiet1[1] % 4 == 0) max_days = 29;
                        else max_days = 28;
                        break;
            }

            if(document.mainform.depDay.selectedIndex + Offset + 1 > max_days){
                document.mainform.dstMonth.selectedIndex = document.mainform.depMonth.selectedIndex + 1;
                document.mainform.dstDay.selectedIndex = (document.mainform.depDay.selectedIndex + Offset) - max_days;
            } else {
                document.mainform.dstMonth.selectedIndex = document.mainform.depMonth.selectedIndex;
                document.mainform.dstDay.selectedIndex = document.mainform.depDay.selectedIndex + Offset;
            }
            // alert("Bitte beachten Sie, das Rckgabedatum muss nach dem Anmietdatum liegen!");
    }
}


function popupMsg(msgKey) {
    alert(messages[msgKey]);
}

function MM_popupMsg(msgKey) {
    alert(messages[msgKey]);
}



// RENDER FUNCTIONS

var DHTML = (document.getElementById || document.all || document.layers);
function ap_getObj(name)
{
 if (document.getElementById)
 {
  return document.getElementById(name).style;
 }
 else if (document.all)
 {
  return document.all[name].style;
 }
 else if (document.layers)
 {
  return document.layers[name];
 }
}
function ap_showWaitMessage(div,flag)
{
 if (!DHTML) return;
 var x = ap_getObj(div);
 x.visibility = (flag) ? 'visible':'hidden'
 if(! document.getElementById)
  if(document.layers)
   x.left=280/2;
 return true;
}


// disable cvc-code-field
function cvc_disable()
{
  document.bookingmain.cs_cvc.disabled = true;
}


function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }

    if(!(x=d[n])&&d.all)
        x=d.all[n];

    for (i=0;!x&&i<d.forms.length;i++)
        x=d.forms[i][n];

    for(i=0;!x&&d.layers&&i<d.layers.length;i++)
        x=MM_findObj(n,d.layers[i].document);

    if(!x && d.getElementById)
        x=d.getElementById(n);

    return x;
}

function MM_showHideLayers() { //v6.0
    var i,p,v,obj,args=MM_showHideLayers.arguments;
    for (i=0; i<(args.length-2); i+=3)
        if  ((obj=MM_findObj(args[i]))!=null) {
            v=args[i+2];
            if (obj.style) {
                obj=obj.style;
                v=(v=='show')?'visible':(v=='hide')?'hidden':v;
            }
            obj.visibility=v;
        }
}

function strpos(haystack, needle, offset){
    if (haystack == '' || needle == '') return (false);
    var i = (haystack+'').indexOf(needle, offset);
    return (i===-1 ? false : i);
}

function str_replace(search, replace, subject){
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

    while (j = 0, i--){
        if (s[i]){
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){}
        }
    }

    return (sa ? s : s[0]);
}

function checkInSpecialBags(selBagValue){
    for (i=0; i<specialBagsCombi.length; i++){
        if (strpos(selBagValue, specialBagsCombi[i], startFrom) !== false){
            return (i);
        }
    }
    return (null);
}

function checkSelectedBags(direction, nPaxes){
    specialBagIndex = null;

    if (specialBagsCombi.length == 0){
        // wir haben keinen specialBagsCombi carrier
        return (true);
    }
    var dropKeyTmp = direction == 'inbound' ? 'low_baggageI_' : 'low_baggage_';

    // pax1 ist master fuer alle anderen paxe
    if (document.getElementById(dropKeyTmp+'1')){
        specialBagIndex = checkInSpecialBags(document.getElementById(dropKeyTmp+'1').value);

        if (specialBagIndex == null){
            // wir haben ein problem - breche ab mit ok um ein error zu vermeiden !!
            return (true);
        }

        // ueberpruefe ob eine genaue UEbereinstimmung gebraucht wird
        if (strpos(specialBagsWith[specialBagIndex], '%', startFrom) !== false){
            neededAxact = false;
            equalString = str_replace('%', '', specialBagsWith[specialBagIndex]);
        }else{
            neededAxact = true;
            equalString = specialBagsWith[specialBagIndex];
        }
    }

    if (specialBagIndex == null){
        // wir haben ein problem - breche ab mit ok um ein error zu vermeiden !!
        return (true);
    }

    for (i=2; i<=nPaxes; i++){
        if (document.getElementById(dropKeyTmp+i)){
            if (neededAxact){
                if (document.getElementById(dropKeyTmp+i).value != equalString){
                    alert(lowBaggageSpecialWarning[specialBagIndex]);
                    return (false);
                }
            }else{
                if (strpos(document.getElementById(dropKeyTmp+i).value, equalString, startFrom) === false){
                    alert(lowBaggageSpecialWarning[specialBagIndex]);
                    return (false);
                }
            }
        }
    }
}

function calcBaggePrice(nPaxes){
alert('000000000');
    checkSelectedBags('outbound', nPaxes);
    if (hasInbound) checkSelectedBags('inbound', nPaxes);

    var totalPrice    = 0.00;
    var agentBagPrice = 0.00;
    var totalAllPrice = 0.00;

    for (i=1; i<=nPaxes; i++){
        tmp = "low_baggage_"+i;
        index = document.getElementById(tmp).value;

        if (baggCurrency != agentCurrency){
            totalPrice    = totalPrice + baggPricesArray[0][index];
            totalPriceStr = roundPrice(totalPrice)+" "+baggCurrency;
            agentBagPrice = agentBagPrice + baggPricesArray2[0][index];
            agentPriceStr = roundPrice(agentBagPrice)+" "+agentCurrency;
            nfTotalPrice  = agentBagPrice + nf_zwischensumme;

            totalAllPriceStr = agentBagPrice + priceSumAll;
            totalAllPriceStr = roundPrice(totalAllPriceStr)+" "+priceSumAllCur;

        }else{
            totalPrice    = totalPrice + baggPricesArray[0][index];
            totalPriceStr = roundPrice(totalPrice)+" "+baggCurrency;
            nfTotalPrice  = totalPrice + nf_zwischensumme;
            totalAllPriceStr = totalPrice + priceSumAll;
            totalAllPriceStr = roundPrice(totalAllPriceStr)+" "+priceSumAllCur;
        }

        document.getElementById("baggPriceTotal").innerHTML   = totalPriceStr;
        document.getElementById("total").innerHTML   = totalAllPriceStr;
    }
    return (totalPrice);
}

function roundPrice( nPreis ){
    var cPrice = "" + nPreis;
    var nLen = cPrice.length;
    var nPos = cPrice.indexOf(".");

    // aufrunden wenn dritte nachkommastelle groesser als 4
    if( nPos >= 0 && nPos < nLen-3 ) {
        if( parseInt( cPrice.charAt( nPos + 3)) >= 5 )
            cPrice = "" + ( nPreis + 0.01 );
    }

    // 2 nachkommastellen anhaengen
    if( nPos == -1)
        cPrice += ".00";
    // 1 nachkommastelle anhaengen
    else if( nPos == (nLen-2))
        cPrice += "0";
        // auf 2 nachkommastellen ablaengen
        else
            cPrice = cPrice.substring( 0, nPos + 3 );
    // ersetze dezimalpunkt durch komma
    nPos = cPrice.indexOf(".");
    cPrice = cPrice.substring( 0, nPos) + "." + cPrice.substring(nPos+1);

    return cPrice;
}
