/**
*@fileoverview In dieser Datei werden Hilfsfunktionen für das Flug-Suchformular definiert
*/
var IBE = new TTIBE("IBE",port,"bengine");
IBE.jsFiles = [file_path+'booking/jslib/core/datehelper.js',file_path+'booking/jslib/core/zeitraum.js',
               file_path+'booking/jslib/formulare/terminauswahl.js',file_path+'booking/jslib/formulare/formbase.js',
               file_path+'booking/jslib/core/reisende.js',file_path+'booking/js/ttfdrz.js'];

IBE.initOnLoad = function(){
  var mustHave = ['FormBase','DateHelperLoaded','termin_min_'+this.port,'termin_max_'+this.port,'Zeitraum','Reisende','Terminauswahl',
                  'TTFDRZ','TTAFH','arrMarke_'+this.port];
  var injObj   = {SucheFlug:[],Zeitraum:[],Reisende:[this.req['personen']]};
  for(var i in mustHave){
    if(typeof(window[mustHave[i]])=='undefined'){
      window.setTimeout("IBE.initOnLoad()",20);return;
    }
  }
  this.inject(injObj); IBE.init();
};

/**
*@constructor
*@extends FormBase
*@requires Terminauswahl
*@requires Zielauswahl
*@requires Reisende
*@requires Kalender
*/
function SucheFlug(){
  FormBase.apply(this);
  Terminauswahl.apply(this);

  this.flugdauer = (this.req['flugdauer']!='' && this.req['flugdauer']!='0')?this.req['flugdauer']:'-1';

  this.BookingAction = function(detail){
    var bform=document.forms[this.formname];
    bform.showresult.value='1';
    if(detail)
      bform.detail.value=detail;
    bform.termin.value=this.req['termin'];
    bform.ruecktermin.value=this.req['ruecktermin'];
    return this.chkFormular();
  };

  this.chkFormular = function(){
    var bform=document.forms[this.formname];
    if(this.req['termin']>this.req['ruecktermin']){
      alert("Ihr Rückreisedatum liegt vor dem Hinreisedatum");
      return false;
    }
    bform.submit();
    return false;
  };

  this.check_flugdauer=function(){
    var fel=document.forms[this.formname].flugdauer;
    if(fel.value != this.flugdauer){
      document.forms[this.formname].detail.value='zielgebiet';
      document.forms[this.formname].zielgebiets_kenner.value='-1';
    }
  }

  /**
  *Wird nach dem Laden der Seite ausgeführt
  */
  this.init = function(){
    if(!document.forms[this.formname]) return;
    
    // Formularfelder füllen
    with(this){
      fillSels({'marke':window["arrMarke_"+this.port]});
      fillSelFromArray('abflughafen',TTAFH);
      fillSelFromArray('flugdauer',TTFDRZ);
      dauert();
      fillReisende();
      setTexts(['preis']);
      InitDays(1);
      InitMonth(1);
      InitDays(0);
      InitMonth(0);
      UpdateDate('k');
      UpdateDate('rueckk');
    }
    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 = "form4submit";
        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){}

  };
}
/*
function BookingAction(param){
  IBE.BookingAction(param);
} */
