(function() {
    if (typeof document.activeElement == "undefined") {
        document.activeElement = document.body;
        var handler = function(event) { document.activeElement = event.target; };
        if (document.addEventListener) {
            document.addEventListener("click", handler, false);
        } else {
            document.attachEvent("onclick", handler);
        }
    }
    theForm.__nonMSDOMBrowser = (window.navigator.appName.toLowerCase().indexOf('explorer') == -1);
})();
function __doPostBack(eventTarget, eventArgument) {
    theForm.__EVENTTARGET.value = eventTarget;
    theForm.__EVENTARGUMENT.value = eventArgument;
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.submit();
    }
}
theForm.isPostBack = function() {
    if (!theForm.__EVENTTARGET.value) {
        var element = window.document.activeElement;
        if (element && element.name) {
            if (element.tagName == "INPUT" && (element.type == "submit" || element.type == "image")) {
                theForm.__EVENTTARGET.value = element.name;
            }
            if (element.tagName == "BUTTON" && element.type == "submit") {
                theForm.__EVENTTARGET.value = element.name;
            }
        }
    }
    var element = this.getElementByUniqueID(theForm.__EVENTTARGET.value);
    while (element) {
        var length = this.triggers.length();
        for (var num = 0; num < length; num++) {
            var trigger = this.triggers.item(num);
            if ((trigger == element.name) || (trigger.replace(/\$/g, "_") == element.id)) {
                return true;
            }
        }
        element = element.parentNode;
    }
    return false;
};
theForm.doCallback = function() {
    this.status.toggle(this.__EVENTTARGET.value, true);
    var collection = ["__CALLBACKID=", this.encodeCallback(this.name)];
    var formElementCount = this.elements.length;
    for (var num = 0; num < formElementCount; num++) {
        var element = this.elements[num];
        if (element.name) {
            this.callbackObject.appendElement(collection, element);
        }
    }
    this.__EVENTTARGET.value = "";
    this.__EVENTARGUMENT.value = "";
    if (this["__EVENTVALIDATION"]) {
        collection.push("&__EVENTVALIDATION=");
        collection.push(this.encodeCallback(this["__EVENTVALIDATION"].value));
    }
    var xmlRequest = this.callbackObject.XMLHttpRequest();
    if (xmlRequest && (typeof xmlRequest.setRequestHeader != "undefined")) {
        var callbackObject = { eventTarget: this.__EVENTTARGET.value, xmlRequest: xmlRequest };
        xmlRequest.onreadystatechange = function() {
            theForm.callbackComplete(callbackObject);
        };
        xmlRequest.open("POST", this.action, true);
        xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        xmlRequest.send(collection.join(""));
    }
    return false;
};
theForm.callbackComplete = function(callbackObject) {
    if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4)) {
        this.status.toggle(callbackObject.eventTarget, false);
        var response = callbackObject.xmlRequest.responseText;
        if (response.charAt(0) == "s") {
            this.eventCallback(callbackObject.eventTarget, response.substring(1));
        } else if (response.charAt(0) == "e") {
            this.errorCallback(callbackObject.eventTarget, response.substring(1));
        } else {
            var separatorIndex = response.indexOf("|");
            if (separatorIndex != -1) {
                var validationFieldLength = parseInt(response.substring(0, separatorIndex), 10);
                if (!isNaN(validationFieldLength)) {
                    var validationField = response.substring(separatorIndex + 1, separatorIndex + validationFieldLength + 1);
                    if (validationField) {
                        var validationFieldElement = theForm["__EVENTVALIDATION"];
                        if (!validationFieldElement) {
                            validationFieldElement = document.createElement("INPUT");
                            validationFieldElement.type = "hidden";
                            validationFieldElement.name = "__EVENTVALIDATION";
                            this.appendChild(validationFieldElement);
                        }
                        validationFieldElement.value = validationField;
                    }
                    this.eventCallback(callbackObject.eventTarget, response.substring(separatorIndex + validationFieldLength + 1));
                }
            }
        }
    }
};
theForm.errorCallback = function(eventTarget, eventArgument) {
    if (!this.debuger) {
        this.debuger = document.createElement("DIV");
        var handler = function(event) { theForm.debuger.style.display = "none"; };
        if (this.debuger.addEventListener) {
            this.debuger.addEventListener("dblclick", handler, false);
        } else {
            this.debuger.attachEvent("ondblclick", handler);
        }
        if (!this.firstChild) {
            this.appendChild(this.debuger);
        } else {
            this.insertBefore(this.debuger, this.firstChild);
        }
    }
    this.debuger.innerHTML = eventArgument.replace(/\r\n/g, "<br />");
    this.debuger.style.display = "";
};
theForm.eventCallback = function(eventTarget, eventArgument) {
    if (eventArgument.length) {
        var arguments = eventArgument.split("&");
        var results = { fields: [], contents: [], scriptBlocks: [], scriptIncludes: [], startupScripts: [], queueIndex: -1 };
        for (var num = 0; num < arguments.length; num++) {
            var element = arguments[num].split("|");
            var value = this.decodeCallback(element[2]);
            switch (element[0]) {
                case "Field":
                    results.fields.push({ id: element[1], value: value });
                    break;
                case "Html":
                    results.contents.push({ id: element[1], html: value });
                    break;
                case "ScriptBlock":
                    results.scriptBlocks.push(value);
                    break;
                case "ScriptInclude":
                    results.scriptIncludes.push(value);
                    break;
                case "StartupScript":
                    results.startupScripts.push(value);
                    break;
                case "StyleSheet":
                    results.styleSheet = value;
                    break;
            }
        }
        this.callbackObject.results.push(results);
        if (!this.callbackObject.executing) {
            this.callbackObject.execute();
        }
    }
};
theForm.callbackObject = { executing: false, results: new Array() };
theForm.callbackObject.appendElement = function(collection, element) {
    var tagName = element.tagName.toLowerCase();
    if (tagName == "input") {
        var type = element.type;
        if ((type == "text" || type == "hidden" || type == "password" || ((type == "checkbox" || type == "radio") && element.checked)) && (element.id != "__EVENTVALIDATION")) {
            collection.push("&" + theForm.encodeCallback(element.name) + "=" + theForm.encodeCallback(element.value));
        }
    } else if (tagName == "select") {
        var selectCount = element.options.length;
        for (var num = 0; num < selectCount; num++) {
            var selectChild = element.options[num];
            if (selectChild.selected) {
                collection.push("&" + theForm.encodeCallback(element.name) + "=" + theForm.encodeCallback(element.value));
            }
        }
    } else {
        if (tagName == "textarea") {
            collection.push("&" + theForm.encodeCallback(element.name) + "=" + theForm.encodeCallback(element.value));
        }
    }
};
theForm.callbackObject.execute = function() {
    this.executing = true;
    if (!this.results.length) {
        this.executing = false;
        return;
    }
    var results = this.results[0];
    if (results.styleSheet !== undefined) {
        var childNodes = document.getElementsByTagName("HEAD").item(0).childNodes;
        for (var num = childNodes.length - 1; num > -1; num--) {
            var childNode = childNodes[num];
            if (childNode.tagName == "STYLE") {
                childNode.parentNode.removeChild(childNode);
            }
        }
        if (theForm.__nonMSDOMBrowser) {
            var style = document.createElement("STYLE");
            style.type = "text/css";
            style.innerHTML = results.styleSheet;
            document.getElementsByTagName("HEAD").item(0).appendChild(style);
        } else {
            document.createStyleSheet().cssText = results.styleSheet;
        }
    }
    while (results.fields.length) {
        var field = results.fields[0];
        var element = theForm[field.id];
        if (!element) {
            element = document.createElement("INPUT");
            element.type = "hidden";
            element.id = field.id;
            element.name = field.id;
            theForm.insertBefore(element, theForm.firstChild);
        }
        element.value = field.value;
        results.fields.splice(0, 1);
    }
    results.queueIndex = -1;
    this.process(results);
};
theForm.callbackObject.process = function(results) {
    results.queueIndex++;
    if (results.queueIndex >= results.scriptIncludes.length) {
        while (results.scriptBlocks.length) {
            var content = results.scriptBlocks[0];
            if (window.execScript !== undefined) {
                window.execScript(content);
            } else {
                window.eval(content);
            }
            results.scriptBlocks.splice(0, 1);
        }
        while (results.contents.length) {
            var content = results.contents[0];
            var element = document.getElementById(content.id);
            if (element) {
                element.innerHTML = content.html;
            }
            results.contents.splice(0, 1);
        }
        while (results.startupScripts.length) {
            var content = results.startupScripts[0];
            if (window.execScript !== undefined) {
                window.execScript(content);
            } else {
                window.eval(content);
            }
            results.startupScripts.splice(0, 1);
        }
        this.results.splice(0, 1);
        this.execute();
    } else {
        var url = results.scriptIncludes[results.queueIndex];
        var scripts = document.getElementsByTagName("SCRIPT");
        for (var num = 0; num < scripts.length; num++) {
            var script = scripts[num];
            if (script.src && (script.src.substring(script.src.length - url.length) == url)) {
                this.process(results);
                return;
            }
        }
        var element = document.createElement("SCRIPT");
        element.src = url;
        element.type = "text/javascript";
        if (theForm.__nonMSDOMBrowser) {
            element.onload = function(event) {
                theForm.callbackObject.process(results);
            };
        } else {
            element.onreadystatechange = function(event) {
                if ((element.readyState == "complete") || (element.readyState == "loaded")) {
                    theForm.callbackObject.process(results);
                }
            };
        }
        this.appendChild(element);
    }
};
theForm.callbackObject.XMLHttpRequest = function() {
    try {
        return new XMLHttpRequest();
    } catch (e) { }
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) { }
    return null;
};
theForm.triggers = { elements: new Array() };
theForm.triggers.add = function(trigger) {
    var length = this.elements.length;
    for (var num = 0; num < length; num++) {
        if (trigger == this.elements[num]) {
            return;
        }
    }
    this.elements.push(trigger);
};
theForm.triggers.length = function() {
    return this.elements.length;
};
theForm.triggers.item = function(index) {
    return this.elements[index];
};
theForm.status = { elements: new Array() };
theForm.status.add = function(id, controlId, delayTime) {
    var length = this.elements.length;
    for (var num = 0; num < length; num++) {
        var status = this.elements[num];
        if (status.id == id) {
            status.controlId = controlId;
            status.delayTime = delayTime;
            return;
        }
    }
    this.elements.push({ id: id, number: 0, controlId: controlId, delayTime: delayTime });
};
theForm.status.length = function() {
    return this.elements.length;
};
theForm.status.item = function(index) {
    return this.elements[index];
};
theForm.status.toggle = function(eventTarget, state) {
    var element = theForm.getElementByUniqueID(eventTarget);
    var length = this.length();
    for (var num = 0; num < length; num++) {
        var status = this.item(num);
        if (!status.controlId) {
            this.toggleItem(status, state);
        } else {
            var current = element;
            while (current) {
                if ((status.controlId == current.name) || (status.controlId.replace(/\$/g, "_") == current.id)) {
                    this.toggleItem(status, state);
                    break;
                }
                current = current.parentNode;
            }
        }
    }
};
theForm.status.toggleItem = function(status, state) {
    if (state) {
        if (++status.number < 2) {
            status.timer = window.setTimeout(function() { var element = document.getElementById(status.id); if (status.dynamic === undefined) { status.dynamic = element.style.display == "none"; } if (status.dynamic) { element.style.display = ""; } else { element.style.visibility = "visible"; } }, status.delayTime);
        }
    } else {
        if (--status.number < 1) {
            status.number = 0;
            if (status.timer) {
                window.clearTimeout(status.timer);
                delete status.timer;
            }
            var element = document.getElementById(status.id);
            if (status.dynamic === undefined) {
                status.dynamic = element.style.display == "none";
            }
            if (status.dynamic) {
                element.style.display = "none";
            } else {
                element.style.visibility = "hidden";
            }
        }
    }
};
theForm.encodeCallback = function(parameter) {
    if (encodeURIComponent) {
        return encodeURIComponent(parameter);
    }
    return escape(parameter);
};
theForm.decodeCallback = function(parameter) {
    if (decodeURIComponent) {
        return decodeURIComponent(parameter.replace(/\+/g, "%20"));
    }
    return unescape(parameter.replace(/\+/g, "%20"));
};
theForm.getElementByUniqueID = function(uniqueID) {
    if (this[uniqueID]) {
        return this[uniqueID];
    }
    while (uniqueID && uniqueID.length > 0) {
        var clientID = uniqueID.replace(/\$/g, "_");
        var element = document.getElementById(clientID);
        if (element) {
            return element;
        }
        var indexOfLastDollar = uniqueID.lastIndexOf("$");
        if (indexOfLastDollar == -1) {
            return null;
        }
        uniqueID = uniqueID.substring(0, indexOfLastDollar);
    }
    return null;
};