/**
 * $Id: jquery.appMain.js 2538 2010-03-26 08:28:00Z bjoern.moenikes $
 **/


(function($){

  $.fn.extend({
    appMain : function(options)
    {
      if (!$.event._amCache) $.event._amCache = [];

      // initialise the application main controller with the relevant settings...
      options = $.extend(
      {
        id : '',
        $context : ''
      }
      , options
      );

      return this.each(
        function()
        {
          var $this = $(this);
          var alreadyExists = true;

          if (!this._amId) {
            this._amId = $.event.guid++;
            $.event._amCache[this._amId] = new AppMain(this);
            alreadyExists = false;
          }

          var controller = $.event._amCache[this._amId];

          controller.init(options);

          $this.amSetSlideManager(new SlideManager());
          $this.amSetStepManager(new StepManager());
          $this.amGetSlideManager().init();
          $this.amGetSlideManager().initalizeScrollStates(
            function(){
              $this.amOneTimeInit();
              $("#initPanel").hide();
              //              C.log("FINISHED WITH INITIALISATION");

              $("#information").informationController();
              $("#information2").informationController();

              $(".helpCenter").helpCenterController({
                "buttons" : "default #bbStartseite #pricebyebye #bbModifySearch #bbFlightInfo #bbFlightFilter #bbHotelInfo #bbHotelsFiltern #bbExtrasInfo #bbExtrasFiltern #cmdBack #cmdStop #cmdFastForward #cmdNext #cmdBook #cmdPrint"
              });
              $('#templates .helpCenter').appendTo('#contentRight');

              if (initParams.step[phpConst.step.currentStep] != phpConst.step.searchmask)
                $this.amGetStepManager().restoreToStep(initParams.searchParam[phpConst.searchParam.engineKind],initParams.step[phpConst.step.currentStep]);
              else {
                $this.amGetSlideManager().slideShow("#modifySearch");
                if (initParams.searchParam[phpConst.searchParam.engineKind] == phpConst.engineKind.hotelOnly) 
                  $this.amGetSlideManager().executeAction(function(){
                    $("#modifySearch").msSetHotelOnly();
                  });
              }
              return;
            });
        }
        )
    },


    amShowResponse : function(response, id)
    {
      var $table = $(id);
      // hide loading dialog
      if (!$("#loadMessagePanel-container").is(":hidden"))
        $("#loadMessageBox").lmcHide();

      var sessionInvalid = false;
      if (response.fieldErrors[phpConst.sessionInvalid] != undefined)
        sessionInvalid = true;

      var errorMsg = "<ul>";
      if (response.errorMessages.length > 0)
        errorMsg = "<li>"+response.errorMessages+"</li>";
      else
        for (var item in response.fieldErrors)
          errorMsg += "<li>"+response.fieldErrors[item]+"</li>";
      errorMsg += "</ul>";


      $("#errorMessageBox").emcShow(getText('txt.dialog.error'),getText('txt.dialog.txt.error')+"<br />"+getText('txt.dialog.txt.errorReport')+"<br /><div style='overflow: none; height: 180px; width:100%;'>"+
        errorMsg+"</div>", sessionInvalid);
    //alert ("jquery.tableMananger.js: showResponse():" + response); // +js_beautify($.toJSON(response)));
    },


    amSwitchToSSL : function()
    {
      var $sm = $("#bookingArea").amGetStepManager();
      $("#loadMessageBox").lmcShow('ssl', function(){
        $sm.sendBookInit(
          function() {
            $("#bookingArea").amGetStepManager().executeDummyBooking(function()
            {
              window.location.href = bookingURL /*+ $.cookie('jsonCommunicationId')*/;
            },getShowResponse());
          },
          getShowResponse());
      });
    },

    amOneTimeInit : function()
    {
      // install handler for all gui components and panel:
      $("#modifySearch").modifySearchController({
        okCallback: function() {          
          $("#bookingArea").amModifySearchCallback();
        }
      });


      $("#progressBar").progressBarController({});
      $("#progressBar").pbcSetMode(phpConst.engineKind.individualTravel);

      $(".statusPanel").statusPanelController({
        id : ".statusPanel",
        bbStartseiteCallback : function() {
          if (!isUIblocking())
            window.location.pathname = '';
        },
        bbModifySearchCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").ambbModifySearchCallback();
        },
        bbFlightInfoCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").ambbFlightInfoCallback();
        },
        bbFlightFilterCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").ambbFlightFilterCallback();
        },
        bbHotelInfoCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").ambbHotelInfoCallback();
        },
        bbHotelsFilternCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").ambbHotelsFilternCallback();
        },
        bbExtrasInfoCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").ambbExtrasInfoCallback();
        },
        bbExtrasFilternCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").ambbExtrasFilternCallback();
        },
        cmdBackCallback : function() {
          if (!isUIblocking())
          {            
            $("#cmdBack a").addClass("pressed");
            $("#bookingArea").amcmdBackCallback();
          }
        },
        cmdStopCallback : function() {
          if (!isUIblocking())
          {            
            $("#cmdStop a").addClass("pressed");
            $("#bookingArea").amcmdStopCallback();
          }
        },
        cmdFastForwardCallback : function() {
          if (!isUIblocking())
          {
            $("#cmdFastForward a").addClass("pressed");
            $("#bookingArea").amcmdFastForwardCallback();
          }
        },
        cmdNextCallback : function() {
          if (!isUIblocking())
          {            
            $("#cmdNext a").addClass("pressed");
            $("#bookingArea").amcmdNextCallback();
          }
        },
        cmdBookCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").amcmdBookCallback();
        },
        cmdPrintCallback : function() {
          if (!isUIblocking())
            $("#bookingArea").amcmdPrintCallback();
        }
      });


      $("#chooseFlight").chooseFlightController({
        selectFlightTableCallback : function($tab) {
          $("#bookingArea").amSelectInFlightController($tab);
        }
      });
      $("#filterFlights").filterFlightsController({});
      $("#chooseHotel").chooseHotelController({});
      $("#filterHotels").filterHotelsController({});
      $("#chooseCar").chooseCarController({});
      $("#errorMessageBox").errorMessageController({});
      $("#loadMessageBox").loadMessageController({});


    },

    amSelectInFlightController : function($tab)
    {
      $("#chooseFlight").cfcUpdateGUI();
    },



    // called by Modify Search, after search has been started (==ok button pressed)
    amModifySearchCallback : function()
    {
      // close all child age boxes
      $("#modifySearch").msCloseAllPopups();

      var back = function()
      {
        getSlideManager().slideShow("#modifySearch");
      }

      if (!$("#modifySearch").msAllChildAgesFilled())
        $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.modifySearch.error.childAgeMissing'), undefined, back);
      else if (!$("#modifySearch").isCompletelyFilled())
        $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'), undefined, back);
      //      else if (!$("#modifySearch").msAllChildAgesValid())
      //        $("#errorMessageBox").emcShow(getText('txt.singleDatePickerPopup.invalidDate.head'),
      //          getText('txt.singleDatePickerPopup.invalidDate.text'), undefined, back);
      else
      {
        $("#modifySearch").firstTimeCheck();
        //        C.log("---------------");
        var $ba = $("#bookingArea");
        var sk = $("#modifySearch").msGetSearchKind();
        $ba.amGetStepManager().init(sk);
        //$ba.amGetSlideManager().setStorage("");
        $("#progressBar").pbcSetMode(sk);
        $("#bookingArea").amGetStepManager().nextStep();
      }
    },
    
    ambbModifySearchCallback : function()
    {
      var innerAmbbModifySearchCallback = function()
      {
        var $sm = getSlideManager();
        $sm.slideToggle("#modifySearch",function(){
          //          C.log("ambbModifySearchCallback");
          //          C.log(restore);
          if (restore)
          {
            var $sm = $("#bookingArea").amGetSlideManager();
            var $stm = $("#bookingArea").amGetStepManager();
            var $sp = $(".statusPanel",$("#bookingArea"));
            $sp.spcRestoreCmdState();
            $stm.restoreStepStatus();
            var step = $stm.getStep();
            //            C.log("STEP:");
            //            C.log(step);
            switch(step){
              case phpConst.step.flight:
                $sm.slideShow("#chooseFlight");
                break;
              case phpConst.step.hotel:
                $sm.slideShow("#chooseHotel");
                break;
              case phpConst.step.rentalCar:
                $sm.slideShow("#chooseCar");
                break;
              default:
                C.log("defaulting!!!");
            }
          }
        });
      }
      var $sp = $(".statusPanel",$("#bookingArea"));
            
      var restore = false;

      if ($("#modifySearch-container").is(":hidden"))
      {
        //        C.log("hidden");
        $sp.spcSaveCmdState();
        $("#bookingArea").amGetStepManager().saveStepStatus();
        $("#bookingArea").amGetSlideManager().hideMainPanel(innerAmbbModifySearchCallback);
        $sp.setCommandPanelButtons(false,false,false,false);
      }
      else
      {
        restore = true;
        innerAmbbModifySearchCallback();
      }      
    },
    
    ambbFlightInfoCallback : function()
    {
      if ($("#airlineInformation-container").is(":hidden"))
        $("#airlineInformation").aiUpdateAirlineInformationController(function()
        {
          $("#bookingArea").amGetSlideManager().slideShow("#airlineInformation");
        },getShowResponse());
      else
        $("#bookingArea").amGetSlideManager().slideHide("#airlineInformation");

    },

    amToggleFlightFilter : function()
    {
      this.amGetSlideManager().slideToggle("#filterFlights");
    },
    ambbFlightFilterCallback : function()
    {
      this.amGetSlideManager().slideToggle("#filterFlights");
    },
    
    ambbHotelInfoCallback : function()
    {
      var data = $("#chooseHotel").chcGetData();
      var cH = phpConst.hotel;

      $("#information").icToggleByURL(phpConst.config.path_prefix+"hotelinfos/" +
        data[cH.seasonCode] + "/hotel_" + data[cH.hotelCode] + ".html?type=9",function (){
          $('#hotelInfoCycler').cycle({
            fx:     'fade',
            speed:  'fast',
            timeout: 0,
            next:   '#hotelInfoCyclerForward',
            prev:   '#hotelInfoCyclerBack'
          });
        },"#informationData");
    },
    ambbHotelsFilternCallback : function()
    {
      this.amGetSlideManager().slideToggle("#filterHotels");
    },
    ambbExtrasInfoCallback : function()
    {
      var data = $("#chooseCar").cccGetData();
      var pc = phpConst.car;

      // do not update, if no rental car is selected
      if (   data[pc.mobility] == pc.mobility_trans
        || data[pc.mobility] == pc.mobility_notrans )
        return;

      var $i2 = $("#information2");

      $i2.icToggleByJSON(data, "info_cars",   function(response)
      {


        var cC = phpConst.car;
        var $ci = $("#carInfo").clone();

        //        C.log("1    KKKKK");

        var directive = {
          //'.header h3 .name': cC.stationName,
          '.car_info .image img[src]': function(){ 
            return("/fileadmin/images/rental/sixt.gif");
          },
          '.text': cC.stationRentCond,
          '.car_info .telephone' : cC.stationTelefon,
          '.car_info .fax' : cC.stationFax
        };

        //        C.log("2    KKKKK");
        //        C.log($ci);
        //        C.log(response["data"]);
        //        C.log(directive);

        $('.content div', $i2).remove();
        $('.content', $i2).append($ci);
        $ci.autoRender(response["data"], directive);

        //        C.log("3    KKKKK");
        //        C.log(response);


        $('.header .name', $i2).text(response[cC.stationName]);


        $('#carInformation .header .close a', $i2).click(function(){
          $(".statusPanel").spbbExtrasInfoButton();
        });

      }, undefined,getText('txt.panel.rentalcarinfos'));


    },
    ambbExtrasFilternCallback : function()
    {
      $("#information2").icToggleByURL("/index.php?id=27&type=9",function (){},$("#information2 .content"),getText('txt.panel.transferinfos'));
    },
    amcmdBackCallback : function()
    {
      this.amPreviousStep();
    },
    amcmdStopCallback : function()
    {
      this.amStopStep();
    },
    amcmdFastForwardCallback : function()
    {
      this.amFastForwardStep();
    },
    amcmdNextCallback : function()
    {
      this.amNextStep();
    //C.log("amcmdNextCallback in appController");
    },

    amNextStep : function()
    {
      $("#bookingArea").amGetStepManager().nextStep();

    },
    amPreviousStep : function()
    {
      $("#bookingArea").amGetStepManager().previousStep();
    },
    amStopStep : function()
    {
      $("#bookingArea").amGetStepManager().stopStep();

    },
    amFastForwardStep : function()
    {
      $("#bookingArea").amGetStepManager().fastForwardStep();
    },


    amcmdBookCallback : function()
    {
      C.log("amcmdBookCallback in appController");
    },
    amcmdPrintCallback : function()
    {
      C.log("amcmdPrintCallback in appController");
    },
    amSetSlideManager : function(slideManager)
    {
      return _w.call(this, 'setSlideManager', slideManager);
    },
    amGetSlideManager : function()
    {
      var c = _getController(this[0]);
      if (c) {
        return c.getSlideManager();
      }
      return null;
    },
    amSetStepManager : function(slideManager)
    {
      return _w.call(this, 'setStepManager', slideManager);
    },
    amGetStepManager : function()
    {
      var c = _getController(this[0]);
      if (c) {
        return c.getStepManager();
      }
      return null;
    },

    _amDestroy : function()
    {
    // TODO - implement this?
    }
  });

  // private internal function to cut down on the amount of code needed where we forward
  // dp* methods on the jQuery object on to the relevant DatePicker controllers...
  var _w = function(f, a1, a2, a3)
  {
    return this.each(
      function()
      {
        var c = _getController(this);
        if (c) {
          c[f](a1, a2, a3);
        }
      }
      );
  };



  function AppMain(ele)
  {
    this.ele = ele;

    // initial values...
    this.id			=	'#bookingArea';
    this.$context = undefined;
    this.slideManager = undefined;
    this.stepManager = undefined;


  }
  $.extend(
    AppMain.prototype,
    {
      init : function(s)
      {
        this.id = s.id;
        this.$context = $(s.id);
        this.slideManager = undefined;
        this.stepManager = undefined;
      },
      setSlideManager :function(slideManager)
      {
        this.slideManager = slideManager;
      },
      getSlideManager :function()
      {
        return this.slideManager;
      },
      setStepManager :function(stepManager)
      {
        this.stepManager = stepManager;
      },
      getStepManager :function()
      {
        return this.stepManager;
      }

    }
    );



  // StepManager
  // always knows where we are and where we'd like to go
  function StepManager()
  {
    this.stepStatus = {};
    this.stepStatus[phpConst.searchParam.engineKind] = phpConst.engineKind.notDefined;
    this.stepStatus[phpConst.step.steps] = [];
    this.stepStatus[phpConst.step.currentStep] = undefined;
    /* one of:  notDefined  individualTravel flightOnly hotelOnly flyDrive  */

    this.tempStepStatus = {}; // used for temporary storage of stepStatus


    $.extend(
      StepManager.prototype,
      {
        init : function(engineKind) {
          if (!engineKind)
            engineKind = phpConst.engineKind.individualTravel;

          var cSK = phpConst.engineKind;
          var cS = phpConst.step;

          this.stepStatus[phpConst.searchParam.engineKind] = engineKind;
          this.stepStatus[phpConst.step.currentStep] = phpConst.step.searchmask;
          this.stepStatus[phpConst.step.steps] = {};

          switch(this.stepStatus[phpConst.searchParam.engineKind])
          {
            case cSK.individualTravel:
              this.initStepStatus(cS.undef, cS.undef, cS.undef);
              break;
            case cSK.flightOnly:
              this.initStepStatus(cS.undef, cS.notAvailable, cS.notAvailable);
              break;
            case cSK.hotelOnly:
              this.initStepStatus(cS.notAvailable, cS.undef, cS.notAvailable);
              break;
            case cSK.flyDrive:
              this.initStepStatus(cS.undef, cS.notAvailable, cS.undef);
              break;
            default:
              this.initStepStatus(cS.undef, cS.undef, cS.undef);
              break;
          }
        },

        getTablePriceClass : function()
        {
          var xclass = "price price";
          //          C.log("getTablePriceClass()");
          //          C.log(this.stepStatus);
          if ( (this.stepStatus[phpConst.step.steps][phpConst.step.flight] == phpConst.step.valid)
            || (this.stepStatus[phpConst.step.currentStep] == phpConst.step.flight) )
            xclass += "Flight"
          if ( (this.stepStatus[phpConst.step.steps][phpConst.step.hotel] == phpConst.step.valid)
            || (this.stepStatus[phpConst.step.currentStep] == phpConst.step.hotel) )
            xclass += "Hotel"
          if ( (this.stepStatus[phpConst.step.steps][phpConst.step.rentalCar] == phpConst.step.valid)
            || (this.stepStatus[phpConst.step.currentStep] == phpConst.step.rentalCar) )
            xclass += "RentalCar"
          return xclass;
        },

        saveStepStatus : function()
        {
          var cS = phpConst.step;
          this.tempStepStatus = {};
          this.tempStepStatus[phpConst.searchParam.engineKind] = this.stepStatus[phpConst.searchParam.engineKind];
          this.tempStepStatus[cS.currentStep] = this.stepStatus[cS.currentStep];
          this.tempStepStatus[cS.steps] = {};
          this.tempStepStatus[cS.steps][cS.flight] = this.stepStatus[cS.steps][cS.flight];
          this.tempStepStatus[cS.steps][cS.hotel] = this.stepStatus[cS.steps][cS.hotel];
          this.tempStepStatus[cS.steps][cS.rentalCar] = this.stepStatus[cS.steps][cS.rentalCar];
        },

        restoreStepStatus : function()
        {
          this.stepStatus = this.tempStepStatus;
        },

        updatePriceDescription : function()
        {
          var cS = phpConst.step;
          var selector = '';

          if (!this.stepStatus || !this.stepStatus[phpConst.step.steps])
            return;

          if ( this.stepStatus[phpConst.step.steps][cS.flight] == cS.valid
            || this.stepStatus[phpConst.step.currentStep] == cS.flight )
            selector += 'Flight';

          if (    this.stepStatus[phpConst.step.steps][cS.hotel] == cS.valid
            || this.stepStatus[phpConst.step.currentStep] == cS.hotel )
            selector += 'Hotel';

          if (    this.stepStatus[phpConst.step.steps][cS.rentalCar] == cS.valid
            || this.stepStatus[phpConst.step.currentStep] == cS.rentalCar )
            {
            var price = $("#chooseCar").attr("priceType");
            selector += price ? price : "";
          }

          if (selector == '')
            selector = 'Default';

          // default text: Price (incl. Kerosin etc.)
          // when in hotel.solo: no additional extra information shall be displayed
          var text = 'txt.status.price.sub.Default';
          if ($("#bookingArea").amGetStepManager().stepStatus[phpConst.searchParam.engineKind] == phpConst.engineKind.hotelOnly)
             text = 'txt.status.price.sub.noExtras';

          $(".statusPanel").spSetPriceDescription(getText('txt.status.price.'+selector),
            getText(text));
        },

        getEngineKind : function()
        {
          return this.stepStatus[phpConst.searchParam.engineKind];
        },
        getSteps : function()
        {
          return this.stepStatus[phpConst.step.steps];
        },
        getStep : function()
        {
          return this.stepStatus[phpConst.step.currentStep];
        },
        setStep : function(step)
        {
          this.stepStatus[phpConst.step.currentStep] = step;
        },

        initStepStatus : function(flightStatus, hotelStatus, rentalCarStatus)
        {
          var cS = phpConst.step;

          this.stepStatus[phpConst.step.steps][cS.flight] = flightStatus;
          this.stepStatus[phpConst.step.steps][cS.hotel] = hotelStatus;
          this.stepStatus[phpConst.step.steps][cS.rentalCar] = rentalCarStatus;
        },

        setStepStatus : function(key, value)
        {
          this.stepStatus[phpConst.step.steps][key] = value;
        },

        getStepStatus : function()
        {
          return this.stepStatus;
        },

        restoreToStep : function(engine, step)
        {

          var cSK = phpConst.engineKind;
          var cS = phpConst.step;

          //          C.log("restoreToStep")
          //          C.log(engine);
          //          C.log(step);

          var setTableLoad = function(load)
          {
            if (load == undefined)
              load = true;
            $("#leftFlightTable").tmSetShowLoadOnUpdate(load);
            $("#rightFlightTable").tmSetShowLoadOnUpdate(load);
            $("#chooseFlight").tmSetShowLoadOnUpdate(load);
            $("#hotelTable").tmSetShowLoadOnUpdate(load);
            $("#roomDescTable").tmSetShowLoadOnUpdate(load);
            $("#carTable").tmSetShowLoadOnUpdate(load);
          }

          setTableLoad(false);

          this.stepStatus[phpConst.searchParam.engineKind] = engine;
          this.stepStatus[phpConst.step.currentStep] = phpConst.step.undef;
          this.stepStatus[phpConst.step.steps] = {};
          this.stepStatus[phpConst.step.steps][phpConst.step.flight] = initParams.step[phpConst.step.steps][phpConst.step.flight];
          this.stepStatus[phpConst.step.steps][phpConst.step.hotel] = initParams.step[phpConst.step.steps][phpConst.step.hotel];
          this.stepStatus[phpConst.step.steps][phpConst.step.rentalCar] = initParams.step[phpConst.step.steps][phpConst.step.rentalCar];
          $("#progressBar").pbcSetMode(engine);
          $("#progressBar").pbcSetStep(step);
          $("#progressBar").pbcUpdateStepStatus(this.stepStatus);


          switch(engine)
          {
            case cSK.individualTravel:
              if (step == cS.flight)
              {
                $("#bookingArea").amGetStepManager().switch2FlightTable(setTableLoad);
              }
              else if (step == cS.hotel)
              {
                $("#bookingArea").amGetStepManager().switch2FlightTable(
                  function(){
                    $("#bookingArea").amGetStepManager().switch2HotelTable(setTableLoad)
                  },false,true);
              }
              else if (step == cS.rentalCar)
              {
                $("#bookingArea").amGetStepManager().switch2FlightTable(
                  function(){
                    $("#bookingArea").amGetStepManager().switch2HotelTable(
                      function(){
                        $("#bookingArea").amGetStepManager().switch2CarTable(setTableLoad);
                      }, false, true);
                  },false,true);
              }
              else
                C.log("Unknown step in restoreToStep: "+step)
              break;
            case cSK.flightOnly:
              $("#bookingArea").amGetStepManager().switch2FlightTable(setTableLoad);
              break;
            case cSK.hotelOnly:
              $("#bookingArea").amGetStepManager().switch2HotelTable(setTableLoad);
              break;
            case cSK.flyDrive:
              if (step == cS.flight)
              {
                $("#bookingArea").amGetStepManager().switch2FlightTable(setTableLoad);
              }
              else if (step == cS.rentalCar)
              {
                $("#bookingArea").amGetStepManager().switch2FlightTable(
                  function(){
                    $("#bookingArea").amGetStepManager().switch2CarTable(setTableLoad);
                  }, false, true);
              }
              break;
            default:
              C.log("Unknown engineKind in restoreToStep: "); //+$sm.stepStatus[phpConst.searchParam.engineKind])
              break;
          }

        },


        sendSearchData : function(onSuccess_, onFailure_, id_)
        {
          var onSuccess = onSuccess_;
          var onFailure = onFailure_;
          var id = id_;
          var myself = this;
          var action = function(){
            var cSP = phpConst.searchParam;
            var data = $("#modifySearch").msGetData();
            data[phpConst.processdata.datatype] = phpConst.processdata.searchParam;
            data[phpConst.step.stepData] = myself.stepStatus;
            doJSON ("data_process",
              data,
              onSuccess,
              onFailure,
              onFailure,
              id
              );
          }
          $("#bookingArea").amGetSlideManager().setStorage("#modifySearch");
          $("#bookingArea").amGetSlideManager().slideHide("#modifySearch", action );
        },

        sendFlightData : function(onSuccess_, onFailure_, id_)
        {
          var onSuccess = onSuccess_;
          var onFailure = onFailure_;
          var id = id_;
          var myself = this;

          var action = function(){
            var cSP = phpConst.searchParam;
            var cF = phpConst.flight;
            data[phpConst.processdata.datatype] = phpConst.processdata.flight;
            data[cF.outFlightId] = data[cSP.flightDirOutbound][cF.flightId],
            data[cF.retFlightId] = data[cSP.flightDirReturn][cF.flightId]
            data[phpConst.step.stepData] = myself.stepStatus;

            doJSON ("data_process",
              data,
              onSuccess,
              onFailure,
              onFailure,
              id
              );
          }
          var data = $("#chooseFlight").cfcGetData();
          // sorting key and dir are integrated in cfcGetData()
          $("#bookingArea").amGetSlideManager().setStorage("#chooseFlight");
          $("#bookingArea").amGetSlideManager().hideSubPanel(function(){
            $("#bookingArea").amGetSlideManager().slideHide("#chooseFlight", action);
          });

        },
        sendHotelData : function(onSuccess_, onFailure_, id_)
        {
          var onSuccess = onSuccess_;
          var onFailure = onFailure_;
          var id = id_;
          var myself = this;
          var action = function(){
            var hotel = $("#chooseHotel").chcGetData();
            var cH = phpConst.hotel;
            var data = {};
            data[cH.hotelCode] = hotel[cH.hotelCode];
            data[cH.roomMealId] = hotel[cH.roomMealId];
            data[phpConst.processdata.datatype] = phpConst.processdata.hotel;
            data[phpConst.step.stepData] = myself.stepStatus;
            data[phpConst.sort.key] = $("#hotelTable").tmGetSortingKey();
            data[phpConst.sort.dir] = $("#hotelTable").tmGetSortingDir();

            doJSON ("data_process",
              data,
              onSuccess,
              onFailure,
              onFailure,
              id);
          }

          $("#bookingArea").amGetSlideManager().setStorage("#chooseHotel");
          $("#bookingArea").amGetSlideManager().hideSubPanel(function(){
            $("#bookingArea").amGetSlideManager().slideHide("#chooseHotel", action);
          });
        },
        sendCarData : function(onSuccess_, onFailure_, id_)
        {
          var onSuccess = onSuccess_;
          var onFailure = onFailure_;
          var id = id_;
          var myself = this;
          var action = function(){
            var data = $("#chooseCar").cccGetData();
            data[phpConst.processdata.datatype] = phpConst.processdata.mobility;

            data[phpConst.step.stepData] = myself.stepStatus;
            data[phpConst.sort.key] = $("#chooseCar").tmGetSortingKey();
            data[phpConst.sort.dir] = $("#chooseCar").tmGetSortingDir();
            doJSON ("data_process",
              data,
              onSuccess,
              onFailure,
              onFailure,
              id);
          }
          $("#bookingArea").amGetSlideManager().setStorage("#chooseCar");
          $("#bookingArea").amGetSlideManager().hideSubPanel(function(){
            $("#bookingArea").amGetSlideManager().slideHide("#chooseCar", action);
          });
        },

        sendBookInit : function(onSuccess, onFailure, id)
        {
          var data = {};
          data[phpConst.processdata.datatype] = phpConst.processdata.bookDataInit;
          //$("#loadMessageBox").lmcShow('testBook');
          data[phpConst.step.stepData] = this.stepStatus;
          doJSON ("data_init",
            data,
            onSuccess,
            onFailure,
            onFailure,
            id);
        },


        showHeader : function(id)
        {
          var header = "#modifySearch #chooseFlight #chooseHotel #chooseCar".split(" ");
          for (var j = 0; j < header.length; j++)
            id == header[j] ?  $(header[j]+"-infoHeader").show()  :  $(header[j]+"-infoHeader").hide();
        },

        switch2FlightTable : function(onSuccess, noUpdate, hidden)
        {
          //          C.log("entering switch2FlightTable");
          var guiUpdate = function(hidden){
            $("#bookingArea .statusPanel").setBlueButtons(true, true, true, true, false, false, false, false,false);
            var cSK = phpConst.engineKind;
            var dis = !$("#cmdStop a").hasClass("disabled");
            switch($("#bookingArea").amGetStepManager().stepStatus[phpConst.searchParam.engineKind])
            {
              case cSK.individualTravel:
                $("#bookingArea .statusPanel").setCommandPanelButtons(false,true,true,true);
                $("#chooseFlight").attr("stopavailable","true");
                break;
              case cSK.flightOnly:
                $("#bookingArea .statusPanel").setCommandPanelButtons(false,false,false,true);
                $("#chooseFlight").attr("stopavailable","false");
                break;
              case cSK.hotelOnly:
                ; // impossible
                break;
              case cSK.flyDrive:
                $("#bookingArea .statusPanel").setCommandPanelButtons(false,true,false,true);
                $("#chooseFlight").attr("stopavailable","true");
                break;
              default:
                $("#bookingArea .statusPanel").setCommandPanelButtons(false,false,false,false);
                $("#chooseFlight").attr("stopavailable","false");
                break;
            }
            $("#bookingArea .statusPanel").setCommandPanelButtons(undefined, dis, undefined, undefined);
            $("#chooseFlight").cfcByebyePriceCheck();

            //              $("#chooseFlight").cfcUpdateStatusPanel();
            $("#bookingArea").amGetStepManager().setStep(phpConst.step.flight);
            $("#bookingArea .progressBar").pbcUpdateStepStatus($("#bookingArea").amGetStepManager().stepStatus);

            // TODO FIXME due to an limitaion in jquery.ui slider, moving the slider
            // is only possible when flightFilterPanel is shown
            $("#filterFlights-container").show();
            $("#filterFlights-container").ffcAdjustFlightFilter();
            $("#filterFlights-container").hide();

            $("#leftFlightTable th.columnPrice div").removeClass().addClass(getStepManager().getTablePriceClass());
            $("#rightFlightTable th.columnPrice div").removeClass().addClass(getStepManager().getTablePriceClass());

            if (!hidden)
            {
              $("#bookingArea .progressBar").pbcSetStep(phpConst.step.flight);

              $("#bookingArea").amGetSlideManager().executeAction(function(){
                $("#bookingArea").amGetStepManager().showHeader("#chooseFlight");
                $(".helpCenter").hccBindCallback("#pricebyebye");
              }
              );


              $("#bookingArea").amGetSlideManager().slideShow("#chooseFlight",function(){
                $("#chooseFlight").cfcScrollIntoView();
                $(".statusPanel").spcRemovePressedState();
              });
            }

            $("#chooseFlight").cfcUpdateGUI();
            $("#bookingArea").amGetStepManager().updatePriceDescription();
          }
          var cS = phpConst.step;
          var data = {};

          if (noUpdate){
            guiUpdate(hidden);
            return;
          }

          $("#leftFlightTable").update(data, function(){
            //            $("#bookingArea").amGetSlideManager().setStorage("");
            guiUpdate(hidden);
            if (onSuccess && typeof(onSuccess)=='function')
              onSuccess();
          });
        },

        switch2HotelTable : function(onSuccess, noUpdate, hidden)
        {
          //          C.log("entering switch2HotelTable");
          var guiUpdate = function(hidden){

            $("#bookingArea .statusPanel").setBlueButtons(true, true, false, false, true, true, false, false,false);

            var cSK = phpConst.engineKind;
            switch($("#bookingArea").amGetStepManager().stepStatus[phpConst.searchParam.engineKind])
            {
              case cSK.individualTravel:
                $("#bookingArea .statusPanel").setCommandPanelButtons(true,true,true,true);
                $(".statusPanel").spSetPriceDescription(null, getText('txt.status.price.sub.Default'));
                break;
              case cSK.flightOnly:
                ; // impossible
                break;
              case cSK.hotelOnly:
                $("#bookingArea .statusPanel").setCommandPanelButtons(false,false,false,true);
                $(".statusPanel").spSetPriceDescription(null, getText('txt.status.price.sub.noExtras'));
                break;
              case cSK.flyDrive:
                ; // impossible
                break;
              default:
                $("#bookingArea .statusPanel").setCommandPanelButtons(false,false,false,false);
                break;
            }

            //              $("#chooseHotel").chcUpdateStatusPanel();
            $("#bookingArea").amGetStepManager().setStep(phpConst.step.hotel);
            $("#bookingArea .progressBar").pbcUpdateStepStatus($("#bookingArea").amGetStepManager().stepStatus);
            $("#hotelTable th.columnPrice div").removeClass().addClass(getStepManager().getTablePriceClass());

            $("#filterHotels-container").show();
            $("#filterHotels-container").fhcAdjustHotelFilter();
            $("#filterHotels-container").hide();


            if (!hidden)
            {
              $("#bookingArea .progressBar").pbcSetStep(phpConst.step.hotel);
              $("#bookingArea").amGetSlideManager().executeAction(function(){
                $("#bookingArea").amGetStepManager().showHeader("#chooseHotel");
                $("#pricebyebye").hide();
                $("#priceStandard").show();
              });

              $("#bookingArea").amGetSlideManager().slideShow("#chooseHotel",function(){
                $("#chooseHotel").chcScrollIntoView();
                $(".statusPanel").spcRemovePressedState();
              });
            }
            $("#bookingArea").amGetSlideManager().executeAction(function(){
              $("#chooseHotel").chcUpdateGUI(true);
              $("#bookingArea").amGetStepManager().updatePriceDescription();
            });
          }
          var cS = phpConst.step;
          var data = {};
          //data[cS.steps] = this.stepStatus;

          if (noUpdate){
            guiUpdate(hidden);
            return;
          }

          //$("#bookingArea").amGetSlideManager().setStorage("#chooseHotel");
          $("#hotelTable").update(data,function()
          {
            //            $("#bookingArea").amGetSlideManager().setStorage("");
            guiUpdate(hidden);
            if (onSuccess && typeof(onSuccess)=='function')
              onSuccess();
          });
        },


        switch2CarTable : function(onSuccess, noUpdate,hidden)
        {
          //          C.log("entering switch2CarTable");
          var guiUpdate = function(hidden){
            var hotel = $("#hotelTable").chcGetData();
            $("#bookingArea .statusPanel").setBlueButtons(true, true, false, false, false, false, true, true,false);

            var cSK = phpConst.engineKind;
            switch($("#bookingArea").amGetStepManager().stepStatus[phpConst.searchParam.engineKind])
            {
              case cSK.individualTravel:
                $("#bookingArea .statusPanel").setCommandPanelButtons(true,false,false,true);
                break;
              case cSK.flightOnly:
                ; // impossible
                break;
              case cSK.hotelOnly:
                ; // impossible
                break;
              case cSK.flyDrive:
                $("#bookingArea .statusPanel").setCommandPanelButtons(true,false,false,true);
                break;
              default:
                $("#bookingArea .statusPanel").setCommandPanelButtons(false,false,false,false);
                break;
            }
            $("#bookingArea").amGetStepManager().setStep(phpConst.step.rentalCar);
            $("#bookingArea .progressBar").pbcUpdateStepStatus($("#bookingArea").amGetStepManager().stepStatus);
            $("#carTable th.columnPrice div").removeClass().addClass(getStepManager().getTablePriceClass());
            if (!hidden)
            {
              $("#bookingArea .progressBar").pbcSetStep(phpConst.step.rentalCar);
              $("#bookingArea").amGetSlideManager().executeAction(function(){
                // if in flyDrive booking line or if no hotel was choosen, hide "oder Transfer" in headline
                if ( (getStepManager().getEngineKind() == phpConst.engineKind.flyDrive)
                  || getStepManager().getSteps()[phpConst.step.hotel] != phpConst.step.valid )
                  $("#chooseCar-infoHeader span.headlineOptional").hide();
                else
                  $("#chooseCar-infoHeader span.headlineOptional").show();
                $("#bookingArea").amGetStepManager().showHeader("#chooseCar");
                $("#pricebyebye").hide();
                $("#priceStandard").show();
              });

              $("#bookingArea").amGetSlideManager().slideShow("#chooseCar",function(){
                $("#chooseCar").cccScrollIntoView();
                $(".statusPanel").spcRemovePressedState();
              });
            }            $("#chooseCar").cccUpdateGUI();
            $("#bookingArea").amGetStepManager().updatePriceDescription();
          }

          var cS = phpConst.step;
          var data = {};
          //data[cS.steps] = this.stepStatus;

          if (noUpdate){
            guiUpdate(hidden);
            return;
          }

          //$("#bookingArea").amGetSlideManager().setStorage("#chooseCar");
          $("#carTable").update(data, function() {
            //            $("#bookingArea").amGetSlideManager().setStorage("");
            guiUpdate(hidden);
            if (onSuccess && typeof(onSuccess)=='function')
              onSuccess();
          });
        },


        stopStep : function()
        {
          var cSK = phpConst.engineKind;
          switch(this.stepStatus[phpConst.searchParam.engineKind])
          {
            case cSK.individualTravel:
              this.stopStep_IT();
              break;
            case cSK.flightOnly:
              ; // impossible
              break;
            case cSK.hotelOnly:
              ; // impossible
              break;
            case cSK.flyDrive:
              this.stopStep_FD();
              break;
            default:
              break;
          }

        },

        stopStep_IT : function()
        {
          var ignoreError = false;

          switch (this.stepStatus[phpConst.step.currentStep])  // step == 1 means, advance from step1 to step2
          {
            case phpConst.step.searchmask:
              ; // impossible
              break;

            case phpConst.step.flight:
              if (( !ignoreError) && !($("#chooseFlight").cfcFlightCombinationValid()))
                $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.returnBeforDeparture'));
              else if (( !ignoreError) && !($("#chooseFlight").cfcAllFormfieldsFilled()) )
                $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
              else{
                $("#bookingArea").amGetStepManager().saveStepStatus();
                $sm = $("#bookingArea").amGetStepManager();
                $sm.setStepStatus(phpConst.step.flight, phpConst.step.valid);
                $sm.setStepStatus(phpConst.step.hotel, phpConst.step.skip);
                $sm.setStepStatus(phpConst.step.rentalCar, phpConst.step.skip);
                this.sendFlightData(function(response)
                {
                  C.log("SSL/Debug Check");
                  C.log(response);
                  if (response && response["data"] && response["data"][phpConst.debugMode])
                  {
                    C.log("DEBUG MODE");
                    C.log("value: "+phpConst.debugMode)
                    C.log(response);
                  }
                  else
                  {
                    $("#bookingArea").amSwitchToSSL();
                  }
                }
                , getShowResponse(), "#hotelTable" );
              }
              break;

            case phpConst.step.hotel:
              if (!ignoreError && !($("#chooseHotel").chcAllFormfieldsFilled()))
                $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
              else{
                $("#bookingArea").amGetStepManager().saveStepStatus();
                $sm = $("#bookingArea").amGetStepManager();
                $sm.setStepStatus(phpConst.step.hotel, phpConst.step.valid);
                $sm.setStepStatus(phpConst.step.rentalCar, phpConst.step.skip);
                this.sendHotelData(function(response)
                {
                  C.log("SSL/Debug Check");
                  C.log(response);
                  if (response && response["data"] && response["data"][phpConst.debugMode])
                  {
                    C.log("DEBUG MODE");
                    C.log("value: "+phpConst.debugMode)
                    C.log(response);
                  }
                  else
                  {
                    $("#bookingArea").amSwitchToSSL();
                  }
                },getShowResponse(), "#carTable");
              }
              break;
            case phpConst.step.rentalCar:
              ; // does not make sense
              break;
            default: $("#errorMessage").emcShow("ERROR STEP"+this.stepStatus[phpConst.step.currentStep],"This should never be visible.");
              break;
          }

        },


        stopStep_FD : function()
        {
          var ignoreError = false;

          switch (this.stepStatus[phpConst.step.currentStep])  // step == 1 means, advance from step1 to step2
          {
            case phpConst.step.searchmask:
              ; // impossible
              break;
            case phpConst.step.flight:  if (( !ignoreError) && !($("#chooseFlight").cfcFlightCombinationValid()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.returnBeforDeparture'));
            else if (( !ignoreError) && !($("#chooseFlight").cfcAllFormfieldsFilled()) )
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else{
              $("#bookingArea").amGetStepManager().saveStepStatus();
              $sm = $("#bookingArea").amGetStepManager();
              $sm.setStepStatus(phpConst.step.flight, phpConst.step.valid);
              this.sendFlightData(
                function(response){
                  C.log("SSL/Debug Check");
                  C.log(response);
                  if (response && response["data"] && response["data"][phpConst.debugMode])
                  {
                    C.log("DEBUG MODE");
                    C.log("value: "+phpConst.debugMode)
                    C.log(response);
                  }
                  else
                  {
                    $("#bookingArea").amSwitchToSSL();
                  }
                }
                , getShowResponse(), "#hotelTable"  );
            }
            break;
            case phpConst.step.rentalCar:
              ; // does not make sense
              break;
            default: $("#errorMessage").emcShow("ERROR STEP"+this.stepStatus[phpConst.step.currentStep],"This should never be visible.");
              break;
          }
        },

        fastForwardStep : function()
        {
          var cSK = phpConst.engineKind;
          switch(this.stepStatus[phpConst.searchParam.engineKind])
          {
            case cSK.individualTravel:
              this.fastForwardStep_IT();
              break;
            case cSK.flightOnly:
              ; // impossible
              break;
            case cSK.hotelOnly:
              ; // impossible
              break;
            case cSK.flyDrive:
              ; // impossible
              break;
            default:
              break;
          }

        },
        fastForwardStep_IT : function()
        {
          // possible situations:  flight or hotel panel shown
          var ignoreError = false;

          switch (this.stepStatus[phpConst.step.currentStep])  // step == 1 means, advance from step1 to step3
          {
            case phpConst.step.flight:
              if (( !ignoreError) && !($("#chooseFlight").cfcFlightCombinationValid()))
                $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.returnBeforDeparture'));
              else if (( !ignoreError) && !($("#chooseFlight").cfcAllFormfieldsFilled()) )
                $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
              else
              {
                $("#bookingArea").amGetStepManager().saveStepStatus();
                $sm = $("#bookingArea").amGetStepManager();
                $sm.setStepStatus(phpConst.step.flight, phpConst.step.valid);
                $sm.setStepStatus(phpConst.step.hotel, phpConst.step.skip);

                this.sendFlightData(
                  function() {
                    $sm = $("#bookingArea").amGetStepManager();
                    $sm.switch2CarTable(function(){
                      $("#chooseCar").cccScrollIntoView();
                    });
                  },
                  getShowResponse(),                  "#hotelTable"
                  );
              }
              break;

            case phpConst.step.hotel:
              if (!ignoreError && !($("#chooseHotel").chcAllFormfieldsFilled()))
                $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
              else{
                $("#bookingArea").amGetStepManager().saveStepStatus();
                $sm = $("#bookingArea").amGetStepManager();
                $sm.setStepStatus(phpConst.step.hotel, phpConst.step.valid);
                $sm.setStepStatus(phpConst.step.rentalCar, phpConst.step.skip);
                this.sendHotelData(
                  function(response){
                    C.log("SSL/Debug Check");
                    C.log(response);
                    if (response && response["data"] && response["data"][phpConst.debugMode])
                    {
                      C.log("DEBUG MODE");
                      C.log("value: "+phpConst.debugMode)
                      C.log(response);
                    }
                    else
                    {
                      $("#bookingArea").amSwitchToSSL();
                    }
                  },getShowResponse(),
                  "#carTable");
              }
              break;
            default: $("#errorMessage").emcShow("ERROR STEP"+this.stepStatus[phpConst.step.currentStep],"This should never be visible.");
              break;
          }

        },


        previousStep : function(){
          var $sm = $("#bookingArea").amGetStepManager();
          switch(this.stepStatus[phpConst.step.currentStep]) {
            case phpConst.step.hotel:
              if ($sm.stepStatus[phpConst.step.steps][phpConst.step.flight] == phpConst.step.valid)
                $sm.switch2FlightTable(undefined, true);
              break;
            case phpConst.step.rentalCar:
              if ($sm.stepStatus[phpConst.step.steps][phpConst.step.hotel] == phpConst.step.valid)
                $sm.switch2HotelTable(undefined, true);
              else  {
                $sm.stepStatus[phpConst.step.steps][phpConst.step.hotel] = phpConst.step.undef;
                if ($sm.stepStatus[phpConst.step.steps][phpConst.step.flight] == phpConst.step.valid)
                  $sm.switch2FlightTable(undefined, true);
              }
              break;

            case phpConst.step.commit:
              if ($sm.stepStatus[phpConst.step.steps][phpConst.step.rentalCar] == phpConst.step.valid)
                $sm.switch2CarTable(undefined, true);
              else  {
                $sm.stepStatus[phpConst.step.steps][phpConst.step.rentalCar] = phpConst.step.undef;

                if ($sm.stepStatus[phpConst.step.steps][phpConst.step.hotel] == phpConst.step.valid)
                  $sm.switch2HotelTable(undefined, true);
                else  {
                  $sm.stepStatus[phpConst.step.steps][phpConst.step.rentalCar] = phpConst.step.undef;

                  if ($sm.stepStatus[phpConst.step.steps][phpConst.step.flight] == phpConst.step.valid)
                    $sm.switch2FlightTable(undefined, true);
                }
              }
              break;

            case phpConst.step.searchmask:
            case phpConst.step.flight:
            default:
              $("#errorMessage").emcShow(getText('txt.dialog.info'),"Not yet possible");
              break;
          }
          $("#bookingArea .progressBar").pbcSetStep($sm.getStep());
        },

        nextStep : function()
        {
          var cSK = phpConst.engineKind;
          switch(this.stepStatus[phpConst.searchParam.engineKind])
          {
            case cSK.individualTravel:
              this.nextStep_IT();
              break;
            case cSK.flightOnly:
              this.nextStep_FO();
              break;
            case cSK.hotelOnly:
              this.nextStep_HO();
              break;
            case cSK.flyDrive:
              this.nextStep_FD();
              break;
            default:
              break;
          }
        },


        nextStep_IT : function()
        {
          var ignoreError = false;

          switch (this.stepStatus[phpConst.step.currentStep])  // step == 1 means, advance from step1 to step2
          {
            case phpConst.step.searchmask:
              this.sendSearchData(
                function() {
                  $sm = $("#bookingArea").amGetStepManager();
                  //  $sm.setStepStatus(phpConst.step.flight, phpConst.step.valid);
                  $sm.switch2FlightTable();
                },
                getShowResponse(),"#flightTable");
              break;

            case phpConst.step.flight:  if (( !ignoreError) && !($("#chooseFlight").cfcFlightCombinationValid()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.returnBeforDeparture'));
            else if (( !ignoreError) && !($("#chooseFlight").cfcTravelDurationBelowMaxTravelDuration()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.maxDurationExceeded', phpConst.travel.maxTravelDurationValue));
            else if (( !ignoreError) && !($("#chooseFlight").cfcAllFormfieldsFilled()) )
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else{
              $("#bookingArea").amGetStepManager().saveStepStatus();
              $sm = $("#bookingArea").amGetStepManager();
              $sm.setStepStatus(phpConst.step.flight, phpConst.step.valid);
              this.sendFlightData(
                function() {
                  $sm = $("#bookingArea").amGetStepManager();
                  $sm.switch2HotelTable();
                }, getShowResponse(),
                "#hotelTable"
                );
            }
            break;

            case phpConst.step.hotel:  if (!ignoreError && !($("#chooseHotel").chcAllFormfieldsFilled()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else{
              $("#bookingArea").amGetStepManager().saveStepStatus();
              $sm = $("#bookingArea").amGetStepManager();
              $sm.setStepStatus(phpConst.step.hotel, phpConst.step.valid);
              this.sendHotelData(
                function() {
                  $sm = $("#bookingArea").amGetStepManager();
                  $sm.switch2CarTable();
                },getShowResponse(),
                "#carTable");
            }
            break;
            case phpConst.step.rentalCar: if (!ignoreError && !($("#chooseCar").cccAllFormfieldsFilled()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else{
              $("#bookingArea").amGetStepManager().saveStepStatus();
              $sm = $("#bookingArea").amGetStepManager();
              $sm.setStepStatus(phpConst.step.rentalCar, phpConst.step.valid);
              this.sendCarData(
                function(response){
                  $sm = $("#bookingArea").amGetStepManager();
                  C.log("SSL/Debug Check");
                  C.log(response);
                  if (response && response["data"] && response["data"][phpConst.debugMode])
                  {
                    C.log("DEBUG MODE");
                    C.log("value: "+phpConst.debugMode)
                    C.log(response);
                  }
                  else
                  {
                    $("#bookingArea").amSwitchToSSL();
                  }
                },
                getShowResponse(),
                this.id);
            }
            break;
            default: $("#errorMessage").emcShow("ERROR STEP"+this.stepStatus[phpConst.step.currentStep],"This should never be visible.");
              break;
          }

        },


        nextStep_FD : function()
        {
          var ignoreError = false;
          switch (this.stepStatus[phpConst.step.currentStep])  // step == 1 means, advance from step1 to step2
          {
            case phpConst.step.searchmask:
              this.sendSearchData(
                function() {
                  $sm = $("#bookingArea").amGetStepManager();
                  $sm.switch2FlightTable();
                },
                getShowResponse());
              break;
            case phpConst.step.flight:  if (( !ignoreError) && !($("#chooseFlight").cfcFlightCombinationValid()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.returnBeforDeparture'));
            else if (( !ignoreError) && !($("#chooseFlight").cfcTravelDurationBelowMaxTravelDuration()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.maxDurationExceeded', phpConst.travel.maxTravelDuration));
            else if (( !ignoreError) && !($("#chooseFlight").cfcAllFormfieldsFilled()) )
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else{
              $("#bookingArea").amGetStepManager().saveStepStatus();
              $sm = $("#bookingArea").amGetStepManager();
              $sm.setStepStatus(phpConst.step.flight, phpConst.step.valid);
              this.sendFlightData(
                function() {
                  $sm = $("#bookingArea").amGetStepManager();
                  $sm.switch2CarTable();
                },getShowResponse(),
                "#hotelTable"
                );
            }
            break;
            case phpConst.step.rentalCar: if (!ignoreError && !($("#chooseCar").cccAllFormfieldsFilled()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else{
              $("#bookingArea").amGetStepManager().saveStepStatus();
              $sm = $("#bookingArea").amGetStepManager();
              $sm.setStepStatus(phpConst.step.rentalCar, phpConst.step.valid);
              this.sendCarData(
                function(response){
                  C.log("SSL/Debug Check");
                  C.log(response);
                  if (response && response["data"] && response["data"][phpConst.debugMode])
                  {
                    C.log("DEBUG MODE");
                    C.log("value: "+phpConst.debugMode)
                    C.log(response);
                  }
                  else
                  {
                    $("#bookingArea").amSwitchToSSL();
                  }
                },getShowResponse(),
                this.id);
            }
            break;
            default: $("#errorMessage").emcShow("ERROR STEP"+this.stepStatus[phpConst.step.currentStep],"This should never be visible.");
              break;
          }
        },


        nextStep_FO : function()
        {
          var ignoreError = false;
          switch (this.stepStatus[phpConst.step.currentStep])  // step == 1 means, advance from step1 to step2
          {
            case phpConst.step.searchmask:
              this.sendSearchData(
                function() {
                  $sm = $("#bookingArea").amGetStepManager();
                  $sm.switch2FlightTable();
                },
                getShowResponse());
              break;
            case phpConst.step.flight:  if (( !ignoreError) && !($("#chooseFlight").cfcFlightCombinationValid()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.returnBeforDeparture'));
            else if (( !ignoreError) && !($("#chooseFlight").cfcTravelDurationBelowMaxTravelDuration()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),"");
            else if (( !ignoreError) && !($("#chooseFlight").cfcAllFormfieldsFilled()) )
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else
              this.sendFlightData(
                function(response){
                  C.log("SSL/Debug Check");
                  C.log(response);
                  if (response && response["data"] && response["data"][phpConst.debugMode])
                  {
                    C.log("DEBUG MODE");
                    C.log("value: "+phpConst.debugMode)
                    C.log(response);
                  }
                  else
                  {
                    $("#bookingArea").amSwitchToSSL();
                  }
                },
                getShowResponse());
            break;

            default: $("#errorMessage").emcShow("ERROR STEP"+this.stepStatus[phpConst.step.currentStep],"This should never be visible.");
              break;
          }
        },


        nextStep_HO : function()
        {
          var ignoreError = false;
          switch (this.stepStatus[phpConst.step.currentStep])  // step == 1 means, advance from step1 to step2
          {
            case phpConst.step.searchmask:
              this.sendSearchData(function() {
                $sm = $("#bookingArea").amGetStepManager();
                $sm.switch2HotelTable();
              },
              getShowResponse());
              break;
            case phpConst.step.hotel:  if (!ignoreError && !($("#chooseHotel").chcAllFormfieldsFilled()))
              $("#errorMessage").emcShow(getText('txt.dialog.info'),getText('txt.error.allFieldsNeedToBeFilled'));
            else{
              $("#bookingArea").amGetStepManager().saveStepStatus();
              this.sendHotelData(
                function(response){
                  $sm = $("#bookingArea").amGetStepManager();
                  $sm.setStepStatus(phpConst.step.hotel, phpConst.step.valid);
                  C.log("SSL/Debug Check");
                  C.log(response);
                  if (response && response["data"] && response["data"][phpConst.debugMode])
                  {
                    C.log("DEBUG MODE");
                    C.log("value: "+phpConst.debugMode)
                    C.log(response);
                  }
                  else
                  {
                    $("#bookingArea").amSwitchToSSL();
                  }
                },getShowResponse(),
                "#carTable");
            }
            break;
            default: $("#errorMessage").emcShow("ERROR STEP"+this.stepStatus[phpConst.step.currentStep],"This should never be visible.");
              break;
          }
        },

        // initial call after app has just been inited
        // TODO FIXME   add later, again
        executeDummyBooking : function(onSuccess, onFailure)
        {
          var cS = phpConst.step;

          var data = {};
          data[cS.steps] = this.stepStatus;
          data[phpConst.commit.bookingType] = phpConst.commit.bookingType_Dummy;

          doJSON('booking', data, onSuccess,onFailure, onFailure);

        }


      });
  }

 
  var onAfterFuncWrap = function()
  {
    if ($.isFunction(onAfterFuncOut))
      onAfterFuncOut();
    if (queue == undefined || queue.length == 0)    // We have finished, when queue is empty
    {
      //      C.log("XY moreAnimSteps(): false");
      $("#bookingArea").removeClass("animating");
      return false;
    }
    //    C.log("XY moreAnimSteps(): true");
    return true;
  }



  function _getController(ele)
  {
    if (ele._amId) return $.event._amCache[ele._amId];
    return false;
  };

  // make it so that no error is thrown if bgIframe plugin isn't included (allows you to use conditional
  // comments to only include bgIframe where it is needed in IE without breaking this plugin).
  if ($.fn.bgIframe == undefined) {
    $.fn.bgIframe = function() {
      return this;
    };
  };


  // clean-up
  $(window)
  .bind('unload', function() {
    var els = $.event._amCache || [];
    for (var i in els) {
      $(els[i].ele)._amDestroy();
    }
  });


})(jQuery);