﻿var CenterHelper = Class.create();
CenterHelper.prototype = {

    initialize: function() { },

    set_position: function(_object) {
        var object = $(_object);
        var arrayPageSize = this.getPageSize();
        var arrayPageScroll = this.getPageScroll();
        var top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - object.clientHeight) / 2) + 'px');
        var left = (((arrayPageSize[0] - 20 - object.clientWidth) / 2) + 'px');
        object.style.left = left;
        object.style.top = top;
    },

    getPageScroll: function() {
        var yScroll;

        if (self.pageYOffset) {
            yScroll = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {
            yScroll = document.documentElement.scrollTop;
        } else if (document.body) {
            yScroll = document.body.scrollTop;
        }

        arrayPageScroll = new Array('', yScroll)
        return arrayPageScroll;
    },

    getPageSize: function() {

        var xScroll, yScroll;

        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) {
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else {
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }

        var windowWidth, windowHeight;
        if (self.innerHeight) {
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) {
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        // for small pages with total height less then height of the viewport
        if (yScroll < windowHeight) {
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }

        // for small pages with total width less then width of the viewport
        if (xScroll < windowWidth) {
            pageWidth = windowWidth;
        } else {
            pageWidth = xScroll;
        }


        arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
        return arrayPageSize;
    }
}

var AjaxRequestHelper = Class.create();
AjaxRequestHelper.prototype = {

    container: null,
    indicator: null,
    indicator_layout: null,
    indicator_overlay: null,
    set_style: true,

    initialize: function(_container, _indicator, _indicator_layout, _indicator_overlay, _set_style) {
        this.container = _container;
        this.indicator = $(_indicator);
        this.indicator_layout = $(_indicator_layout);
        this.indicator_overlay = $(_indicator_overlay);
        this.set_style = _set_style;

        Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE") + 5)) == 6;
        Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE") + 5)) == 7;
        Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;

    },

    // showIndicator
    showIndicator: function() {
        if (Prototype.Browser.IE6) {
            var arrSelect = $$("select"); // delete all the select for IE6
            arrSelect.each(function(elemClass) {
                elemClass.hide();
            })
        };
        //$("book_booknow").disable(); // hide searchbutton 

        if (this.indicator_layout) {
            if (this.set_style) {
                this.indicator_layout.setStyle({ height: document.body.clientHeight + 'px' });
                this.indicator_layout.setStyle({ width: document.body.clientWidth + 'px' });
            }
            this.indicator_layout.show();
        }
        if (this.indicator_overlay) {
            if (this.set_style) {
                this.indicator_overlay.setStyle({ height: document.body.clientHeight + 'px' });
                this.indicator_overlay.setStyle({ width: document.body.clientWidth + 'px' });
            }
            this.indicator_overlay.show();
        }
        if (this.indicator != null) {
            if (this.set_style) {
                c = new CenterHelper().set_position(this.indicator.id);
            }
            this.indicator.show();
        }
    },


    // hideindicator
    hideIndicator: function() {
        if (Prototype.Browser.IE6) {
            var arrSelect = $$("select"); // delete all the select for IE6
            arrSelect.each(function(elemClass) {
                elemClass.show();
            })
        };
        //$("book_booknow").enable(); // shows again button

        if (this.indicator != null) {
            if (this.indicator_layout) {
                this.indicator_layout.hide();
            }
            if (this.indicator_overlay) {
                this.indicator_overlay.hide();
            }
            if (this.indicator != null) {
                this.indicator.hide();
            }
        }
    }
}
