/**
*@fileoverview In dieser Datei werden Hilfsfunktionen für das LMPS Suchformular definiert
*/

var IBE = new TTIBE("IBE",port,"bengine");
IBE.jsFiles = [file_path+ibeDIR+'/jslib/formulare/'+lang+'/selectopt655.js',file_path+ibeDIR+'/jslib/core/'+lang+'/datehelper.js',
               file_path+ibeDIR+'/jslib/core/zeitraum.js',file_path+ibeDIR+'/jslib/formulare/'+lang+'/terminauswahl.js',
               file_path+ibeDIR+'/jslib/formulare/'+lang+'/formbase.js',file_path+ibeDIR+'/jslib/core/reisende.js',file_path+ibeDIR+'/'+ordner_name+'/js/markeNewSort.js'];

IBE.initOnLoad = function(){
  var bform = document.forms[this.formname];
  var mustHave = ['FormBase','DateHelperLoaded','termin_min_'+this.port,'termin_max_'+this.port,'Zeitraum','Reisende','Terminauswahl',
                  'optDauer','arrMarke_'+this.port,'toc_va_merge'];
  var injObj   = {SucheLMPS:[],Zeitraum:[],Reisende:[this.req['personen']]};

  if(this.req['formular']=='4')
    mustHave = mustHave.concat(['Zielauswahl','TTREGS_'+this.port]);
  else
    mustHave.push('TTFDRZ');
  for(var i in mustHave){
    if(typeof(window[mustHave[i]])=='undefined'){
      window.setTimeout("IBE.initOnLoad()",20);return;
    }
  }

  this.inject(injObj); this.init();
};

//___________________________________________________________________
/**
*eigene Optionsfelder
*/
var optttdays = [
    "0 n.;1",
    "1 n.;4",
    "2 n.;5",
    "3 n.;2",
    "4 n.;6",
    "5 n.;7",
    "6 n.;8",
    "7 n.;3",
    "14 n.;9",
    "21 n.;10",
    "30 n.;11",
    "90 n.;12"
];

//___________________________________________________________________



var optUsrPers = {
      erw:["",""],  // "normal"
      erw_short:["",""],         // Formular 2 / Nur Flug
      pers:["",""],        // Fewo
      kinder:["",""]
    };

/**
*@constructor
*@extends FormBase
*@requires Terminauswahl
*@requires Zielauswahl
*@requires Reisende
*@requires Kalender
*/
function SucheLMPS(){
  FormBase.apply(this);
  Terminauswahl.apply(this);

  if(this.req['formular']=='4') Zielauswahl.apply(this,[]);

  this.BookingAction = function(detail){
    var bform=document.forms[this.formname];
    bform.showresult.value='1';
    if(detail)
        bform.detail.value=detail;
    else
        detail = bform.detail.value;
    bform.termin.value=this.req['termin'];
    bform.ruecktermin.value=this.req['ruecktermin'];

    // ### EXTRA TOC FR
    if (typeof(bform.tt_region) != 'undefined'){

        if(bform.tt_region.value != '-1' && bform.tt_region.value != ''){
            var arrReg = bform.tt_region.value.split("|");
            bform.zielgebiets_kenner.value=arrReg[0];
            bform.flugdauer.value=arrReg[1];
            if (arrReg[2] != arrReg[1]){
                bform.topRegion.value=arrReg[2];
            }

            detail = 'hotel';
            bform.detail.value=detail;
        }
        else{
            bform.topRegion.value='';
            bform.flugdauer.value='';
            detail = 'zielgebiet'
            bform.detail.value=detail;
        }

    }
    if (typeof(bform.tt_countries) != 'undefined' && bform.tt_countries.value != '-1'){
        var tt_udfregionen = "";
        var arrCountry = bform.tt_countries.value.split(",");
        var txtCountry = '';
        for(var jj=0;jj<arrCountry.length;jj++){
            if(txtCountry != '')
                txtCountry+=';';
            txtCountry+=arrCountry[jj];
        }
        var zielSel = bform.elements["tt_countries"];
        var strZiel = zielSel[zielSel.selectedIndex].text;
        tt_udfregionen = strZiel+'|'+txtCountry;

        if (tt_udfregionen != ''){
            bform.topRegionen.value=txtCountry;
        }
    }
    if (typeof(bform.tt_countries) != 'undefined' && (bform.tt_countries.value == '-1' || bform.tt_countries.value == '')){
        bform.topRegion.value='';
        bform.flugdauer.value='';
        bform.udfregionen.value='';
        detail = 'zielgebiet'
        bform.detail.value=detail;
    }
    // ###

    return this.chkFormular();
  };

  this.chkFormular = function(){
    var bform=document.forms[this.formname];
    if(this.req['termin']>this.req['ruecktermin']){
      alert("Votre date de retour est située avant la date d'arrivée");
      return false;
    }
    var tmpy=bform.zimmer2;
    if(typeof(tmpy)!='undefined'){
      if(bform.zimmer[6].checked==true && bform.zimmer2.selectedIndex==0){
        alert("Veuillez sélectionner un type de chambre");
        bform.zimmer2.focus()
        return false;
      }
    }
    bform.submit();
    return false;
  };


  /**
  *Wird nach dem Laden der Seite ausgeführt
  */
  this.init = function(){


    if(!document.forms[this.formname]) return;

    //arrMarke_654 = toc_va_merge(arrVorgabe, arrMarke_654);

    // Formularfelder füllen
    with(this){
      fillSels({"dauer":optDauer,"marke":window["arrMarke_"+this.port],'ttdays':optttdays,'kategorie':optKategorie});
      fillReisende(optUsrPers);
      InitDays(1);
      InitMonth(1);
      InitDays(0);
      InitMonth(0);
      UpdateDate('k');
      UpdateDate('rueckk');
      //setTexts(['shotel']);
      UpdateRegionen();

    }

    try{
      document.getElementById('erster_termin').innerHTML  = this.erster_termin;
      document.getElementById('letzter_termin').innerHTML = this.letzter_termin;
    }catch(e){}

    try{
      var buttons = document.getElementsByName('btnFinden');
      var imgname = this.req['formular']==4?"spacer":"spacer";

      for(var i=0;i<buttons.length;i++){
        buttons[i].setAttribute("src",imgPfad+"/forms/"+imgname+".gif");
        //buttons[i].onmouseover = function(){this.src=imgPfad+"/forms/"+imgname+"_over.gif";};
        //buttons[i].onmouseout = function(){this.src=imgPfad+"/forms/"+imgname+".gif";};
      }
    }catch(e){}
  };
}