function setSelectVisibility(mode, obj) {
    if (isIE) {
        if (obj) {
            obj = $(obj);
        }
        else {
            obj = document.getElementsByTagName("body")[0];
        }

        var selectList = obj.getElementsByTagName("select");
        for (var i = 0; i < selectList.length; i++) {
            selectList[i].style.visibility = mode;
        }
    }
}

function changeOpacity(object, opacity) {
    opacity = (opacity >= 100) ? 99.999 : opacity;
    opacity = (opacity < 0) ? 0 : opacity;

    object.style.opacity = (opacity / 100);
    object.style.MozOpacity = (opacity / 100);
    object.style.KhtmlOpacity = (opacity / 100);
    object.style.filter = "alpha(opacity=" + opacity + ")";
}


var Alerts = {

    background: null,
    fadeTimer: 0,
    OPACITY: 21,
    STEPS: 1,

    bgFadeIn: function(max, steps, opacity) {
        var background = Alerts.background;
        var delta = max / steps

        if (opacity == null) {
            opacity = delta;
        }

        if (background && opacity <= max) {
            changeOpacity(background, opacity);
            opacity += delta;
            setTimeout("Alerts.bgFadeIn(" + max + "," + steps + "," + opacity + ")", 0);
        }
    },

    bgFadeOut: function(max, steps, opacity) {
        var background = Alerts.background;
        if (background) {
            var delta = max / steps

            if (opacity == null) {
                opacity = max - delta;
            }

            if (opacity >= 0) {
                changeOpacity(background, opacity);
                opacity -= delta;
                setTimeout("Alerts.bgFadeOut(" + max + "," + steps + "," + opacity + ")", 0);
            }
            else {
                background.parentNode.removeChild(background);
                setSelectVisibility("visible");
                Alerts.background = null;
            }
        }
    },

    killAlert : function() {
        var body = document.getElementsByTagName("body")[0];


        if (Alerts.background) {
            body.removeChild(Alerts.background);
            Alerts.background = null;
            Alerts.bgFadeOut(Alerts.OPACITY, Alerts.STEPS);
        }
        setSelectVisibility("visible");
    },

    fireMessageBox : function (options) {
        var body = document.body;

        if (!options) options = new Object();

        var modal = options.modal;

        if (!Alerts.background && modal) {
            var background = document.createElement("div");
            background.style.position = "absolute";
            background.style.top = "0";
            background.style.left = "0";
            background.style.zIndex = messageZindex-1;

            Alerts.background = background;

            background.style.backgroundColor = "#000000";
            background.style.padding=0;
            background.style.margin=0;

            changeOpacity(background, 0);
            body.appendChild(background);
            Alerts.bgFadeIn(Alerts.OPACITY, Alerts.STEPS);
        }

        setSelectVisibility("hidden");

        Alerts.resize();
        Event.observe(window, "resize", Alerts.resize)

        window.focus();
    },


    resize: function() {

        if (Alerts.background) {
            var background = Alerts.background;
            var body = document.getElementsByTagName("body")[0];

            if (!isWebKit) {
                var scrollHeight = body.scrollHeight;
                var clientHeight = body.clientHeight;

                background.style.height = (scrollHeight > clientHeight ? scrollHeight : clientHeight) + "px";
                //background.style.width = (body.offsetWidth > body.clientWidth ? body.offsetWidth : body.clientWidth) + "px";
                background.style.width = "100%";
            }
            else {
                background.style.height = body.offsetHeight + "px";
                background.style.width = body.offsetWidth + "px";
            }
        }
    }

}
