﻿function CheckAllBox(name) {
    this.name = name;
}
CheckAllBox.prototype = new AjaxControl();
CheckAllBox.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    if (this.controlId === undefined) {
        throw new Error("Property 'controlId' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    var clickHandler = new EventHandler(this, "onClick");
    var changeHandler = new EventHandler(this, "onChange");
    this.events.add("CheckAllBox_click", element, "click", clickHandler);
    this.events.add("CheckAllBox_change", element, "change", changeHandler);
    var checkBoxes = this.getCheckBoxes();
    if (!checkBoxes.length) {
        return;
    }
    var updateHandler = new EventHandler(this, "update");
    for (var num = 0; num < checkBoxes.length; num++) {
        var checkBox = checkBoxes[num];
        if (this.allCheckMode) {
            if (element.checked) {
                checkBox.checked = true;
            }
        } else if (checkBox.checked) {
            element.checked = true;
        }
        this.events.add("CheckAllBox_" + this.elementId + num + "_click", checkBox, "click", updateHandler);
        this.events.add("CheckAllBox_" + this.elementId + num + "_change", checkBox, "change", updateHandler);
    }
    if (this.allCheckMode) {
        element.checked = (this.getCheckedItemCount() == checkBoxes.length);
    }
};
CheckAllBox.prototype.onClick = function(sender, e) {
    var checkBoxes = this.getCheckBoxes();
    var element = document.getElementById(this.elementId);
    for (var num = 0; num < checkBoxes.length; num++) {
        checkBoxes[num].checked = element.checked;
    }
};
CheckAllBox.prototype.onChange = function(sender, e) {
    var checkBoxes = this.getCheckBoxes();
    var element = document.getElementById(this.elementId);
    for (var num = 0; num < checkBoxes.length; num++) {
        var checkBox = checkBoxes[num];
        if (this.allCheckMode) {
            checkBox.checked = element.checked;
        } else if (!element.checked) {
            checkBox.checked = false;
        }
    }
    if ((typeof this.onCheckedChanged) == "function") {
        this.onCheckedChanged(sender, e);
    }
};
CheckAllBox.prototype.update = function(sender, e) {
    var element = document.getElementById(this.elementId);
    if (this.allCheckMode) {
        element.checked = (this.getCheckedItemCount() == this.getCheckBoxes().length);
    } else {
        element.checked = (this.getCheckedItemCount() != 0);
    }
};
CheckAllBox.prototype.getCheckBoxes = function() {
    var checkBoxes = new Array();
    var element = document.getElementById(this.elementId);
    var control = document.getElementById(this.controlId);
    if (control && element) {
        var inputs = control.getElementsByTagName("INPUT");
        for (var num = 0; num < inputs.length; num++) {
            var input = inputs[num];
            if (input.type.toLowerCase() == "checkbox" && input != element) {
                checkBoxes.push(input);
            }
        }
    }
    return checkBoxes;
};
CheckAllBox.prototype.getAllValues = function() {
    var checkedValues = new Array();
    var checkBoxes = this.getCheckBoxes();
    for (var num = 0; num < checkBoxes.length; num++) {
        checkedValues.push(checkBoxes[num].value);
    }
    return checkedValues;
};
CheckAllBox.prototype.getCheckedValues = function() {
    var checkedValues = new Array();
    var checkBoxes = this.getCheckBoxes();
    for (var num = 0; num < checkBoxes.length; num++) {
        var checkBox = checkBoxes[num];
        if (checkBox.checked) {
            checkedValues.push(checkBox.value);
        }
    }
    return checkedValues;
};
CheckAllBox.prototype.getCheckedItemCount = function() {
    var checkedItemCount = 0;
    var checkBoxes = this.getCheckBoxes();
    for (var num = 0; num < checkBoxes.length; num++) {
        var checkBox = checkBoxes[num];
        if (checkBox.checked) {
            checkedItemCount++;
        }
    }
    return checkedItemCount;
};
function DragPanel(name) {
    this.name = name;
}
DragPanel.prototype = new AjaxControl();
DragPanel.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    if (this.containerId == undefined) {
        throw new Error("Property 'containerId' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    if (window.browser.msie) {
        element.setAttribute("unselectable", true);
    }
    this.events.add("DragPanel_mousedown", element, "mousedown", new EventHandler(this, "mousedown"));
};
DragPanel.prototype.mousedown = function(sender, e) {
    if (!this.events.contains("DragPanel_mouseup")) {
        var element = document.getElementById(this.elementId);
        if (e.target != element) {
            var tagName = e.target.tagName.toLowerCase();
            if ((tagName == "a") && (element.href != null) && (element.href.length > 0)) {
                return;
            }
            var tagNames = ["input", "button", "select", "textarea", "label"];
            if (tagNames.contains(tagName)) {
                return;
            }
        }
        var position = $(this.containerId).position();
        this.offset = { left: (e.pageX - position.left), top: (e.pageY - position.top) };
        $(this.containerId).css({ position: "absolute" });
        this.events.add("DragPanel_mouseup", document, "mouseup", new EventHandler(this, "mouseup"));
        this.events.add("DragPanel_mousemove", document, "mousemove", new EventHandler(this, "mousemove"));
        e.preventDefault();
    }
};
DragPanel.prototype.mousemove = function(sender, e) {
    var position = { left: e.pageX - this.offset.left, top: e.pageY - this.offset.top };
    if (position.left < 0) {
        position.left = 0;
    }
    if (position.top < 0) {
        position.top = 0;
    }
    $(this.containerId).position(position);
    e.preventDefault();
};
DragPanel.prototype.mouseup = function(sender, e) {
    this.events.remove("DragPanel_mouseup");
    this.events.remove("DragPanel_mousemove");
};
function FilteredTextBox(name) {
    this.name = name;
}
FilteredTextBox.prototype = new AjaxControl();
FilteredTextBox.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    if (this.matchCharExpression) {
        var keypress = new EventHandler(this, "keypress");
        this.events.add("FilteredTextBox_keypress", element, "keypress", keypress);
    }
    if (this.matchWholeWordExpression) {
        var handler = new EventHandler(this, "update");
        this.events.add("FilteredTextBox_change", element, "change", handler);
    }
};
FilteredTextBox.prototype.keypress = function(sender, e) {
    if (e.keyCode < 32 || e.keyCode == 46 || e.ctrlKey || e.altKey || e.source.metaKey) {
        return;
    }
    if (e.keyCode == 33 || e.keyCode == 34 || e.keyCode == 35 || e.keyCode == 36) {
        return;
    }
    if (e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40) {
        return;
    }
    var charCode = String.fromCharCode(e.keyCode);
    if (!this.evaluateIsValid(charCode)) {
        e.preventDefault();
    }
};
FilteredTextBox.prototype.update = function(sender, e) {
    var element = document.getElementById(this.elementId);
    var match = element.value.match(this.matchWholeWordExpression);
    if (!match || (match[0].length != element.value.length)) {
        element.value = "";
    }
};
FilteredTextBox.prototype.evaluateIsValid = function(value) {
    return (value.match(this.matchCharExpression) ? true : false);
};
function MarkedBox(name) {
    this.name = name;
}
MarkedBox.prototype = new AjaxControl();
MarkedBox.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    if (this.rolls === undefined) {
        throw new Error("Property 'rolls' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    $(this.elementId).css({ position: "absolute", display: "none" });
};
MarkedBox.prototype.show = function(element) {
    if (element === undefined) {
        throw new Error("Parameter 'element' cannot be null.");
    }
    $(this.elementId).position($(element).position()).size($(element).size()).expand();
    if (this.timeout) {
        window.clearTimeout(this.timeout);
    }
    var markedBox = this;
    var handler = function(rolls, opacity) {
        if (opacity > 0) {
            opacity -= 0.1;
        } else if ((++rolls) < markedBox.rolls) {
            opacity = 0.6;
        } else {
            $(markedBox.elementId).opacity(0).collapse();
            return;
        }
        $(markedBox.elementId).opacity(opacity);
        markedBox.timeout = window.setTimeout(function() { handler(rolls, opacity) }, 20);
    }
    handler(0, 0.6);
};
MarkedBox.prototype.dispose = function(sender, e) {
    if (this.timeout) {
        window.clearTimeout(this.timeout);
        this.timeout = null;
    }
    this.invokeMethod(AjaxControl, "dispose", [sender, e]);
};
function MaskedBox(name) {
    this.name = name;
}
MaskedBox.prototype = new AjaxControl();
MaskedBox.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    if (this.controlId === undefined) {
        throw new Error("Property 'controlId' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    var control = $(this.controlId).current();
    if (!control) {
        throw new Error("The control was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    $(this.elementId).css({ position: "absolute", display: "none" });
    this.events.add("MaskedBox_load", window, "load", new EventHandler(this, function(sender, e) { if (!$(this.controlId).value()) { $(this.elementId).position($(this.controlId).position()).expand(); } this.events.remove("MaskedBox_load"); }));
    this.events.add("MaskedBox_resize", window, "resize", new EventHandler(this, function(sender, e) { if (!$(this.controlId).value()) { $(this.elementId).position($(this.controlId).position()); } }));
    this.events.add("MaskedBox_blur", control, "blur", new EventHandler(this, function(sender, e) { if (!$(this.controlId).value()) { $(this.elementId).position($(this.controlId).position()).expand(); } }));
    this.events.add("MaskedBox_focus", control, "focus", new EventHandler(this, function(sender, e) { $(this.elementId).collapse(); }));
    this.events.add("MaskedBox_click", element, "click", new EventHandler(this, function(sender, e) { $(this.elementId).collapse(); $(this.controlId).current().focus(); }));
};
MaskedBox.prototype.dispose = function(sender, e) {
    this.invokeMethod(AjaxControl, "dispose", [sender, e]);
};
function MaskHolder(name) {
    this.name = name;
}
MaskHolder.prototype = new AjaxControl();
MaskHolder.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    if (this.staticMode === undefined) {
        throw new Error("Property 'staticMode' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    this.timers = new TimerHandlerList();
    this.displayed = !$(this.elementId).position({ left: 0, top: 0 }).css({ position: "absolute", overflow: "hidden" }).css("display");
    this.timers.add("MaskHolder_show", 25, new EventHandler(this, "showTask"));
};
MaskHolder.prototype.show = function(callback) {
    if (!this.displayed) {
        this.displayed = true;
        if (!this.staticMode) {
            this.opacity = 0;
            this.timers.start("MaskHolder_show");
        } else {
            this.opacity = 0.66;
        }
        this.refresh();
        $(this.elementId).opacity(this.opacity).expand();
        this.events.add("MaskHolder_global_scroll", window, "scroll", new EventHandler(this, "refresh"));
        this.events.add("MaskHolder_global_resize", window, "resize", new EventHandler(this, "refresh"));
    }
};
MaskHolder.prototype.hide = function() {
    if (this.displayed) {
        this.timers.stop("MaskHolder_show");
        this.displayed = false;
        $(this.elementId).collapse();
        this.events.remove("MaskHolder_global_scroll");
        this.events.remove("MaskHolder_global_resize");
    }
};
MaskHolder.prototype.showTask = function(sender, e) {
    if (!(sender instanceof MaskHolder)) {
        throw new Error("Object of type \"" + (typeof sender) + "\" cannot be converted to type MaskHolder.");
    }
    this.opacity += 0.01;
    if (this.opacity >= 0.66) {
        this.timers.stop("MaskHolder_show");
        $(this.elementId).opacity(0.66);
        if (this.showCallback !== undefined) {
            this.showCallback.call(this, sender, e);
            delete this.showCallback;
        }
    } else {
        $(this.elementId).opacity(this.opacity);
    }
};
MaskHolder.prototype.refresh = function(sender, e) {
    var size = { height: 0, width: 0 };
    if (document.documentElement) {
        size.height = document.documentElement.clientHeight;
        size.width = document.documentElement.clientWidth;
    }
    if (size.height < document.body.offsetHeight) {
        size.height = document.body.offsetHeight;
    }
    if (size.width < document.body.offsetWidth) {
        size.width = document.body.offsetWidth;
    }
    $(this.elementId).size(size);
};
MaskHolder.prototype.dispose = function() {
    this.timers.dispose();
    delete this.timers;
    this.invokeMethod(AjaxControl, "dispose");
};
function PopupBox(name) {
    this.name = name;
}
PopupBox.prototype = new AjaxControl();
PopupBox.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    if (this.speed === undefined) {
        throw new Error("Property 'speed' cannot be null.");
    }
    if (this.hideOnClick === undefined) {
        throw new Error("Property 'hideOnClick' cannot be null.");
    }
    if (this.staticMode === undefined) {
        throw new Error("Property 'staticMode' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    this.position = new Object();
    this.timers = new TimerHandlerList();
    this.displayed = !$(this.elementId).css({ position: "absolute", overflow: "hidden" }).css("display");
    this.timers.add("PopupBox_show", this.speed, new EventHandler(this, "showTask"));
    this.timers.add("PopupBox_hide", this.speed, new EventHandler(this, "hideTask"));
    this.hideOnClickHandler = new EventHandler(this, function(sender, e) { if (!$(this.elementId).contains(e.target)) { this.hide(); } });
};
PopupBox.prototype.show = function(callback) {
    if (!this.displayed) {
        this.timers.stop("PopupBox_hide");
        this.displayed = true;
        this.opacity = 0;
        $(this.elementId).opacity(this.opacity).hide().expand();
        if (typeof this.position.left != "number") {
            this.position.left = $(document).scroll().left + (document.documentElement.clientWidth - $(this.elementId).size().width) / 2;
        }
        if (typeof this.position.top != "number") {
            this.position.top = $(document).scroll().top + (document.documentElement.clientHeight - $(this.elementId).size().height) / 2;
        }
        $(this.elementId).css({ left: this.position.left, top: this.position.top }).show();
        if (this.staticMode) {
            this.opacity = 1;
        }
        if (this.hideOnClick) {
            this.events.add("PopupBox_mousedown", document, "mousedown", this.hideOnClickHandler);
        }
        this.showCallback = callback;
        this.timers.start("PopupBox_show");
    }
};
PopupBox.prototype.hide = function(callback) {
    if (this.displayed) {
        this.events.remove("PopupBox_mousedown");
        this.timers.stop("PopupBox_show");
        this.displayed = false;
        this.opacity = 1;
        if (this.staticMode) {
            this.opacity = 0;
        }
        this.hideCallback = callback;
        this.timers.start("PopupBox_hide");
    }
};
PopupBox.prototype.showTask = function(sender, e) {
    if (!(sender instanceof PopupBox)) {
        throw new Error("Object of type \"" + (typeof sender) + "\" cannot be converted to type PopupBox.");
    }
    this.opacity += 0.25;
    if (this.opacity >= 1) {
        this.timers.stop("PopupBox_show");
        $(this.elementId).opacity(1);
        if (this.showCallback !== undefined) {
            this.showCallback.call(this, sender, e);
            delete this.showCallback;
        }
    } else {
        $(this.elementId).opacity(this.opacity);
    }
};
PopupBox.prototype.hideTask = function(sender, e) {
    if (!(sender instanceof PopupBox)) {
        throw new Error("Object of type \"" + (typeof sender) + "\" cannot be converted to type PopupBox.");
    }
    this.opacity -= 0.25;
    if (this.opacity <= 0) {
        this.timers.stop("PopupBox_hide");
        $(this.elementId).opacity(1).collapse();
        if (this.hideCallback !== undefined) {
            this.hideCallback.call(this, sender, e);
            delete this.hideCallback;
        }
    } else {
        $(this.elementId).opacity(this.opacity);
    }
};
PopupBox.prototype.dispose = function() {
    this.timers.dispose();
    delete this.timers;
    this.invokeMethod(AjaxControl, "dispose");
};
function TabStrip(name) {
    this.name = name;
}
TabStrip.prototype = new AjaxControl();
TabStrip.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    this.resetTabs();
};
TabStrip.prototype.resetTabs = function() {
    this.tabs = new Array();
    var handler = function(node, tabStrip) {
        var tab = { tabStrip: tabStrip, index: tabStrip.tabs.length, node: node };
        node.onclick = function(event) {
            tab.tabStrip.setSelectedTab(tab.index, new EventArgs(event || window.event));
        }
        tabStrip.tabs[tab.index] = tab;
    };
    var element = document.getElementById(this.elementId);
    for (var num = 0; num < element.childNodes.length; num++) {
        var childNode = element.childNodes[num];
        if (childNode.tagName) {
            handler(childNode, this);
        }
    }
};
TabStrip.prototype.setSelectedTab = function(index, e) {
    if (index < this.tabs.length) {
        var targetTab = this.tabs[index];
        var args = { tab: targetTab, target: (e ? e.target : targetTab) };
        if (typeof this.onSelectedTabChanging != "undefined") {
            this.onSelectedTabChanging(this, args);
        }
        var selectedTab = this.getSelectedTab();
        if ((!selectedTab || (selectedTab.index != index)) && !args.cancel) {
            if (selectedTab) {
                selectedTab.node.className = this.styleTab;
            }
            targetTab.node.className = this.styleSelectedTab;
            if (typeof this.onSelectedTabChanged != "undefined") {
                this.onSelectedTabChanged(this, args);
            }
        }
    }
};
TabStrip.prototype.getSelectedTab = function() {
    for (var num = 0; num < this.tabs.length; num++) {
        var tab = this.tabs[num];
        if (tab.node.className == this.styleSelectedTab) {
            return tab;
        }
    }
    return null;
};
function UpdateTextBox(name) {
    this.name = name;
}
UpdateTextBox.prototype = new AjaxControl();
UpdateTextBox.prototype.initialize = function() {
    if (this.elementId === undefined) {
        throw new Error("Property 'elementId' cannot be null.");
    }
    if (this.delayTime === undefined) {
        throw new Error("Property 'delayTime' cannot be null.");
    }
    var element = document.getElementById(this.elementId);
    if (element === null) {
        throw new Error("The element was not found.");
    }
    this.invokeMethod(AjaxControl, "initialize");
    var handler = new EventHandler(this, "update");
    this.events.add("UpdateTextBox_keyup", element, "keyup", handler);
    this.events.add("UpdateTextBox_update", element, "change", handler);
};
UpdateTextBox.prototype.update = function(sender, e) {
    if ((typeof this.onTextChanged) == "function") {
        if (this.timeout) {
            window.clearTimeout(this.timeout);
        }
        var updateTextBox = this;
        var handler = function() {
            updateTextBox.onTextChanged(sender, e);
        }
        this.timeout = window.setTimeout(handler, this.delayTime);
    }
};
UpdateTextBox.prototype.dispose = function(sender, e) {
    this.invokeMethod(AjaxControl, "dispose", [sender, e]);
    if (this.timeout) {
        window.clearTimeout(this.timeout);
        this.timeout = null;
    }
};