// 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 () {
        // just doin' nothin' ;)
    }
});
// 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);
    }
}

// cp 22.05.2007
var PageManager = {};
PageManager.LturHotels = function() {};
PageManager.LturHotels.prototype = {
    setDivWaitingEnabled:function (e) {
        this.divWaitingEnabled = e;
    },
    setDivWaitingDisabled:function (e) {
        this.divWaitingDisabled = e;
    },
    setDivNumResults:function (e) {
        this.divNumResults = e;
    },
    setDivResultList:function (e) {
        this.divResultList = e;
    },
    setMinPrice:function (minPrice) {
        this.minPrice = minPrice;
    },
    setMaxPrice:function (maxPrice) {
        this.maxPrice = maxPrice;
    },
    setMinCategory:function (minCategory) {
        this.minCategory = minCategory;
    },
    setMaxCategory:function (maxCategory) {
        this.maxCategory = maxCategory;
    },
    setArrivalMinDate:function (arrivalMinDate) {
        this.arrivalMinDate = arrivalMinDate;
    },
    setArrivalMaxDate:function (arrivalMaxDate) {
        this.arrivalMaxDate = arrivalMaxDate;
    },
    setDepartureMinDate:function (departureMinDate) {
        this.departureMinDate = departureMinDate;
    },
    setDepartureMaxDate:function (departureMaxDate) {
        this.departureMaxDate = departureMaxDate;
    },
    setHotelName: function (hotelName) {
        this.hotelName = hotelName;
    },
    setServiceType: function (serviceType) {
        this.serviceType = serviceType;
    },
    setRoomType: function (roomType) {
        this.roomType = roomType;
    },
    setSortBy: function (sortBy) {
        this.sortBy = sortBy;
    },
    setView: function (v) {
        this.view = v;
    },
    setSearchId: function (id) {
        this.searchId = id;
    },
    setMaxResults: function (maxResults) {
        this.maxResults = maxResults;
    },
    fireUpdate: function () {
        this.showWaiting();

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

        new Ajax.Request('/lturhotels/ajax.ltml', 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);
        }
    },
    getCommand: function () {
        var cmd = 'cmd=filterResults&search_id=' + this.encodeURI(this.searchId) + "&";
        cmd += "minPrice="         + this.encodeURI(this.minPrice) + "&";
        cmd += "maxPrice="         + this.encodeURI(this.maxPrice) + "&";
        cmd += "minCategory="      + this.encodeURI(this.minCategory) + "&";
        cmd += "maxCategory="      + this.encodeURI(this.maxCategory) + "&";
        cmd += "serviceType="      + this.encodeURI(this.serviceType) + "&";
        cmd += "roomType="         + this.encodeURI(this.roomType) + "&";
        cmd += "hotelName="        + this.encodeURI(this.hotelName) + "&";
        cmd += "arrivalMinDate="   + this.encodeURI(this.arrivalMinDate) + "&";
        cmd += "arrivalMaxDate="   + this.encodeURI(this.arrivalMaxDate) + "&";
        cmd += "departureMinDate=" + this.encodeURI(this.departureMinDate) + "&";
        cmd += "departureMaxDate=" + this.encodeURI(this.departureMaxDate)  + "&";
        cmd += "sortBy="           + this.encodeURI(this.sortBy)  + "&";
        cmd += "maxResults="       + this.encodeURI(this.maxResults)  + "&";
        cmd += "view="             + this.encodeURI(this.view);

        return cmd;
    },
    showWaiting:function () {
        $('links').style.cursor='wait';
        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';
        this.divWaitingEnabled.style.visibility="hidden"
        this.divWaitingEnabled.style.display="none";
        this.divWaitingDisabled.style.visibility="visible";
        this.divWaitingDisabled.style.display="inline";
    },
    encodeURI: function (p) {
        if (encodeURIComponent()) {
            return encodeURIComponent(p);
        }
        if (encodeURI()) {
            return encodeURI(p);
        }
        return escape(p);
    },
    resetFilters: function (Event) {
        this.observers._each(function (observer, key) {
            observer.reset();
        });
        this.fireUpdate();
    },
    addObserver:function (observer) {
        this.observers.push(observer);
    },
    searchId:'',
    minPrice:0,
    maxPrice:0,
    minCategory:'',
    maxCategory:'',
    arrivalMinDate:0,
    arrivalMaxDate:0,
    departureMinDate:0,
    departureMaxDate:0,
    hotelName:'',
    serviceType:'',
    roomType:'',
    sortBy:'sortByPriceAsc',
    maxResults:30,
    divResultList:null,
    divNumResults:null,
    divWaitingEnabled:null,
    divWaitingDisabled:null,
    view:'viewOfferList',
    options:{
        onComplete:null,
        asynchronous:false,
        parameters:''
    },
    observers:[]
}

function TTip(txt) {
    this.ttext = txt;
    var n = document.createElement('DIV');
    var a_class = document.createAttribute('class');
    a_class.nodeValue = "highlight rollover_info";
    n.setAttributeNode(a_class);
    var t = document.createTextNode(this.ttext);
    n.appendChild(t);
    this.tooltip = n;
}
TTip.prototype = {
    isHidden: true,
    hideTTip: function (e) {
        if (!this.isHidden) {
            var ns = e.childNodes;
            for (var i=0;i<ns.length;i++) {
                if (ns[i].nodeName == "DIV") {
                    e.removeChild(ns[i]);
                    this.isHidden=true;
                }
            }
        }
        return true;
    },
    showTTip: function (e) {
        if (this.isHidden) {
            e.appendChild(this.tooltip);
            this.isHidden=false;
        }
        return true;
    }
}

function selectHotel(hotelName) {
    dd = $('filterHotelByName');
    for (var i=0; i < dd.length; i++) {
        if (hotelName == dd.options[i].value) {
            dd.options[i].selectedIndex = i;
            dd.options[i].selected = i;
            resultPageManager.setHotelName(hotelName);
            updateResultView('viewOfferList');
            return;
        }
    }
}

