// cp 22.05.2007
// Callback: onReset hinzugefügt
Object.extend(Control.Slider.prototype, {
    pageManager:null,
    register: function(objSubject) {
        objSubject.addObserver(this);
    },
    reset:function () {
        this.onReset();
    },
    onReset:function () {
        this.options.reset();
        var tmpMethod = this.options.onChange;
        this.options.onChange=this.dummyFunc;
        var slider = this;
        this.handles.each( function(h,i) {
          i = slider.handles.length-1-i;
          slider.setValue(parseFloat(
            (slider.options.sliderValue instanceof Array ? 
              slider.options.sliderValue[i] : slider.options.sliderValue) || 
             slider.range.start), i);
          Element.makePositioned(h); // fix IE
          Event.observe(h, "mousedown", slider.eventMouseDown);
        });
        this.options.onChange=tmpMethod;
    },
    addPageManager:function (objP) {
        this.options.pageManager = objP;
        this.register(objP);
    },
    dummyFunc:function () {
        
    }
});
// cp 29.06.2007
var DropDown = {}
DropDown.Resetter = function() {};
DropDown.Resetter.prototype = {
    pageManager:null,
    resetFunc:null,
    setResetCmd:function (f) {
        this.resetFunc = f;
    },
    reset:function () {
        this.resetFunc();
    },
    register: function(objSubject) {
        objSubject.addObserver(this);
    },
    addPageManager:function (objP) {
        this.pageManager = objP;
        this.register(objP);
    }
}

var PageManager = {};
PageManager.LturFly = function() {};
PageManager.LturFly.prototype = {
    minPrice:0,
    maxPrice:0,
    stops:0,
    airline:'',
    outboundMinFlex:0,
    outboundMaxFlex:0,
    inboundMinFlex:0,
    inboundMaxFlex:0,
    outboundMinTime:0,
    outboundMaxTime:24,
    inboundMinTime:0,
    inboundMaxTime:24,
    sortBy:'sortByPriceASC',
    searchId:'',
    divResultList:null,
    divNumResults:null,
    observers:[],
    options:{
        onComplete:null,
        asynchronous:false,
        parameters:''
    },
    specialMessage:'',
    setDivResultList:function (d) {
        this.divResultList = d;
    },
    setDivNumResults:function (d) {
        this.divNumResults = d;
    },
    setDivWaitingEnabled:function (e) {
        this.divWaitingEnabled = e;
    },
    setDivWaitingDisabled:function (e) {
        this.divWaitingDisabled = e;
    },
    setMinPrice:function (minPrice) {
        this.minPrice = minPrice;
    },
    setMaxPrice:function (maxPrice) {
        this.maxPrice = maxPrice;
    },
    setStops:function (stops) {
        this.stops = stops;
    },
    setAirline:function (airline) {
        this.airline = airline;
    },
    setOutboundMinFlex:function (outboundMinFlex) {
        this.outboundMinFlex = outboundMinFlex;
    },
    setOutboundMaxFlex:function (outboundMaxFlex) {
        this.outboundMaxFlex = outboundMaxFlex;
    },
    setInboundMinFlex:function (inboundMinFlex) {
        this.inboundMinFlex = inboundMinFlex;
    },
    setInboundMaxFlex:function (inboundMaxFlex) {
        this.inboundMaxFlex = inboundMaxFlex;
    },
    setOutboundMinTime:function (outboundMinTime) {
        this.outboundMinTime = outboundMinTime;
    },
    setOutboundMaxTime:function (outboundMaxTime) {
        this.outboundMaxTime = outboundMaxTime;
    },
    setInboundMinTime:function (inboundMinTime) {
        this.inboundMinTime = inboundMinTime;
    },
    setInboundMaxTime:function (inboundMaxTime) {
        this.inboundMaxTime = inboundMaxTime;
    },
    setSortBy:function (sortBy) {
        this.sortBy = sortBy;
    },
    setSearchId:function (searchId) {
        this.searchId = searchId;
    },
    setAjaxURL:function (url) {
        this.ajaxURL = url;
    },
    fireUpdate: function () {
        this.showWaiting();

        this.options.onComplete   = this.onComplete.bind(this);
        this.options.asynchronous = true;
        this.options.parameters   = this.getCommand();

        new Ajax.Request(this.ajaxURL, this.options);
    },
    onComplete: function (request) {
        this.hideWaiting();

        var response = request.responseText;
        var posDelim = response.indexOf('|');
        if (-1 != posDelim) {
            this.divNumResults.innerHTML = response.substr(0, posDelim)
            this.divResultList.innerHTML = response.substr(posDelim + 1);
            DetailsPageManager.evalScript(response);
        }
        $('errorMessage').innerHTML = this.getAndCleanSpecialMessage();
    },
    getCommand: function () {
        var cmd = 'cmd=filterFlightResults&search_id=' + this.encodeURI(this.searchId) + '&';
        cmd += "minPrice="        + this.encodeURI(this.minPrice) + "&";
        cmd += "maxPrice="        + this.encodeURI(this.maxPrice) + "&";
        cmd += "stops="           + this.encodeURI(this.stops) + "&";
        cmd += "airline="         + this.encodeURI(this.airline) + "&";
        cmd += "outboundMinFlex=" + this.encodeURI(this.outboundMinFlex) + "&";
        cmd += "outboundMaxFlex=" + this.encodeURI(this.outboundMaxFlex) + "&";
        cmd += "inboundMinFlex="  + this.encodeURI(this.inboundMinFlex) + "&";
        cmd += "inboundMaxFlex="  + this.encodeURI(this.inboundMaxFlex) + "&";
        cmd += "outboundMinTime=" + this.encodeURI(this.outboundMinTime) + "&";
        cmd += "outboundMaxTime=" + this.encodeURI(this.outboundMaxTime) + "&";
        cmd += "inboundMinTime="  + this.encodeURI(this.inboundMinTime) + "&";
        cmd += "inboundMaxTime="  + this.encodeURI(this.inboundMaxTime) + "&";
        cmd += "sortBy="  + this.encodeURI(this.sortBy) + "";
        return cmd;
    },
    encodeURI: function (p) {
        if (encodeURI()) {
            return encodeURI(p);
        }
        return escape(p);
    },
    showWaiting:function () {
        $('links').style.cursor='wait';
        $('errorMessage').innerHTML='';
        this.divWaitingEnabled.style.visibility="visible"
        this.divWaitingEnabled.style.display="inline";
        this.divWaitingDisabled.style.visibility="hidden";
        this.divWaitingDisabled.style.display="none";
    },
    hideWaiting:function () {
        $('links').style.cursor='default';
        $('errorMessage').innerHTML='';
        this.divWaitingEnabled.style.visibility="hidden"
        this.divWaitingEnabled.style.display="none";
        this.divWaitingDisabled.style.visibility="visible";
        this.divWaitingDisabled.style.display="inline";
    },
    resetFilters: function (Event) {
        this.observers._each(function (observer, key) {
            observer.reset();
        });
        this.fireUpdate();
    },
    addObserver:function (observer) {
        this.observers.push(observer);
    },
    setSpecialMessage:function (msg) {
        this.specialMessage = msg;
    },
    getAndCleanSpecialMessage:function () {
        var msg = this.specialMessage;
        this.specialMessage = '';
        return msg;
    }
}


