﻿
Object.prototype.extend = function(object, override) {
    var extend = function(dest, source, _override) {
        for (prop in source)
            if (_override || typeof dest[prop] == "undefined")
            dest[prop] = source[prop];
        return dest;
    }
    return extend.apply(this, [this, object, override != false]);
};
String.prototype.extend({
    endsWith: function(s) { return (this.substr(this.length - s.length) == s); }, startsWith: function(s) { return (this.substr(0, s.length) == s); }, trimLeft: function() { return this.replace(/^\s*/, ""); }, trimRight: function() { return this.replace(/\s*$/, ""); }, trim: function() { return this.trimRight().trimLeft(); }, toLower: function() { return this.toLowerCase(); }, toUpper: function() { return this.toUpperCase(); }, replaceAll: function(search, replace) {
        var regex = new RegExp(search, ["g"]); return this.replace(regex, replace);
    },
    format: function() {
        var s = this;
        for (var i = 0; i != arguments.length; i++)
            s = s.replaceAll("\\{" + i + "\\}", arguments[i]);
        return s;
    },
    isEmpty: function() { return this.trim() == ""; },
    right: function(count, fill) {
        if (count == this.length) return this;
        if (count > this.length) {
            if (fill == null || fill == undefined || fill.isEmpty()) return this;
            var s = this;
            while (s.length < count)
                s = fill.right(count - s.length) + s;
            return s;
        }
        if (count < this.length) return this.substr(this.length - count, count);
    },
    left: function(count, fill, reallength) {
        if (this.realLength() <= count) return this;
        var s = "";
        var fillLength = (fill ? fill.realLength() : 0);
        for (var i = 0; i < this.length; i++) {
            if ((s.realLength() + fillLength + String(this.charAt(i)).realLength()) <= count) s += String(this.charAt(i));
            else break;
        }
        return s + fill;
    },
    realLength: function() {
        return this.replace(/[^\x00-\xff]/g, "aa").length;
    },
    toJSONString: function() {
        var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\' };
        if (/["\\\x00-\x1f]/.test(this)) {
            return '"' + this.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                var c = m[b];
                if (c) return c;
                c = b.charCodeAt();
                return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
            }) + '"';
        }
        return '"' + this + '"';
    },
    parseJSON: function() {
        try {
            return eval('(' + this + ')');
        } catch (e) { return null; }
    }
}, false);

Object.prototype.extend({
    toJSONString: function() {
        var a = [];
        for (var k in this) {
            if (!this.hasOwnProperty(k)) continue;
            var v = this[k];
            switch (typeof (v)) {
                case 'object':
                    if (v) if (typeof v.toJSONString === 'function') a.push(k.toJSONString() + ':' + v.toJSONString());
                    else a.push(k.toJSONString() + ':null');
                    break;
                case 'string':
                case 'number':
                case 'boolean':
                    a.push(k.toJSONString() + ':' + v.toJSONString());
                    break;
            }
        }
        return '{' + a.join(',') + '}';
    }
});

Function.prototype.extend({
    createDelegate: function(thisObj) {
        var _this = this;
        return function() { _this.apply(thisObj, arguments); };
    },
    createCallback: function(method, beginMethod) {
        var _this = this;
        return function() {
            if (beginMethod) beginMethod.apply(this, arguments);
            _this.apply(this, arguments);
            method.apply(this, arguments);
        };
    }
});
Array.prototype.extend({
    toJSONString: function() {
        var a = [];
        for (var i = 0; i < this.length; i++) {
            var v = this[i];
            switch (typeof (v)) {
                case "object":
                    if (v) if (typeof v.toJSONString === 'function') a.push(v.toJSONString());
                    else a.push("null");
                    break;
                case 'string':
                case 'number':
                case 'boolean':
                    a.push(v.toJSONString());
                    break;
            }
        }
        return '[' + a.join(',') + ']';
    },
    contains: function(value) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == value) return true;
        }
        return false;
    },
    indexOf: function(value) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == value) return i;
        }
        return -1;
    },
    remove: function(value) {
        var index = this.indexOf(value);
        if (index == -1) return;
        this.splice(index, 1);
    }
});

Boolean.prototype.extend({
    toJSONString: function() {
        return String(this);
    }
});
Date.prototype.extend({
    toJSONString: function() {
        return '"' + this.format() + '"';
    },
    format: function(dateTimeFormat) {
        var formatString = dateTimeFormat || "yyyy-MM-dd hh:mm:ss";
        var matchYear = formatString.match(/(y+)/);
        var matchMonth = formatString.match(/(M+)/);
        var matchDate = formatString.match(/(d+)/);
        var matchHour = formatString.match(/(h+)/);
        var matchMinute = formatString.match(/(m+)/);
        var matchSecond = formatString.match(/(s+)/);
        if (matchYear)
            formatString = formatString.replace(matchYear[0], String(this.getFullYear()).right(matchYear[1].length, "0"));
        if (matchMonth)
            formatString = formatString.replace(matchMonth[0], String(this.getMonth() + 1).right(matchMonth[1].length, "0"));
        if (matchDate)
            formatString = formatString.replace(matchDate[0], String(this.getDate()).right(matchDate[1].length, "0"));
        if (matchHour)
            formatString = formatString.replace(matchHour[0], String(this.getHours()).right(matchHour[1].length, "0"));
        if (matchMinute)
            formatString = formatString.replace(matchMinute[0], String(this.getMinutes()).right(matchMinute[1].length, "0"));
        if (matchSecond)
            formatString = formatString.replace(matchSecond[0], String(this.getSeconds()).right(matchSecond[1].length, "0"));
        return formatString;
    },
    addDays: function(days) {
        this.setDate(this.getDate() + days);
        return this;
    },
    addTimes: function(times) {
        var time = this.getTime() + times;
        this.setTime(time);
        return this;
    }
});
Number.prototype.extend({
    toJSONString: function() {
        return isFinite(this) ? String(this) : 'null';
    },
    toFixed: function(length) {
        if (isNaN(length) || length == null) length = 0;
        else if (length < 0) length = 0;
        return Math.round(this * Math.pow(10, length)) / Math.pow(10, length);
    }
});

window.namespace = {
    register: function(name, parent) {
        var root, s = name.split(".");
        if (parent) root = parent;
        else root = window;
        for (var i = 0; i < s.length; i++) {
            if (typeof root[s[i]] == "undefined")
                root[s[i]] = {}; root = root[s[i]];
        }
    },
    $LOADING_CLASSES: {},
    require: function(className, classURI) {
        var _cls = className.replace(/\./g, "_"), result = false;
        var chkClsType = function(_className) {
            try {
                return eval("typeof " + _className);
            } catch (e) { return "undefined"; }
        }
        if (chkClsType(className) != "undefined" || this.$LOADING_CLASSES[_cls] != null) return true;
        this.$LOADING_CLASSES[_cls] = 1;
        var uri = classURI || (System.getRuntimePath() + "/" + className + ".js");
        var xmlHttp = new System.XMLHttpRequest(false);
        xmlHttp.send(uri);
        try {
            eval(xmlHttp.request.responseText);
            if (chkClsType(className) == "undefined") this.$LOADING_CLASSES[_cls] = null;
            result = true;
        } catch (e) {
            this.$LOADING_CLASSES[_cls] = null;
        }
        return result;

    }
};
namespace.register("System");

System.extend({
    $RUNTIME_PATH: null,
    $XMLHTTP_VERS: ["Microsoft.XMLHTTP", "Msxml2.XMLHTTP", "MSXML2.XmlHttp.3.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XmlHttp.6.0"],
    $XMLHTTPS: [],
    PageIsLoad: false,
    getRuntimePath: function() {
        var script = document.getElementsByTagName("script");
        if (typeof (this.$RUNTIME_PATH) == "string") return this.$RUNTIME_PATH;
        for (var i = 0; i < script.length; i++) {
            var src = script[i].getAttribute("src");
            var index = src.toLowerCase().lastIndexOf("/system.js");
            if (index >= 0) {
                this.$RUNTIME_PATH = src.substring(src, index);
                break;
            }
        }
        return this.$RUNTIME_PATH;
    },
    newGuid: function(format) {
        var guid = "{0}-{1}-{2}-{3}-{4}";
        var f1 = Math.random() * 10000000000000000;
        var f5 = Math.random() * 10000000000000000;
        var t = new Date();
        var y = String(t.getFullYear());
        var h = t.getHours() < 10 ? ("0" + String(t.getHours())) : String(t.getHours());
        var m = t.getMinutes() < 10 ? ("0" + String(t.getMinutes())) : String(t.getMinutes());
        var s = t.getSeconds() < 10 ? ("0" + String(t.getSeconds())) : String(t.getSeconds());
        var ms = String(t.getMilliseconds());
        if (t.getMilliseconds() < 10) ms = "00" + String(t.getMilliseconds());
        if (t.getMilliseconds() < 100) ms = "0" + String(t.getMilliseconds());
        var f2 = m.substr(0, 1) + ms.substr(2, 1) + y.substr(2, 1) + m.substr(1, 1);
        var f3 = y.substr(3, 1) + s.substr(0, 1) + t.getMonth().toString(16) + s.substr(1, 1);
        var f4 = h.substr(0, 1) + ms.substr(0, 1) + h.substr(1, 1) + ms.substr(1, 1);
        guid = guid.format(f1.toString(16).substr(0, 8), f2, f3, f4, f5.toString(16).substr(0, 12));
        switch ((format == null || format == undefined) ? "D" : format.toUpperCase()) {
            case "N":
                guid = guid.replace(/-/g, "");
                break;
            case "B":
                guid = "{" + guid + "}";
                break;
            case "P":
                guid = "(" + guid + ")";
                break;
            default:
            case "D":
                break;
        }
        return guid;
    },
    Exception: function(code, description, object, e) {
        this.errorCode = code;
        this.message = description;
        this.source = object;
        this.innerException = e;
    },
    XMLHttpRequest: function(_isAsyn) {
        this.isAsyn = (_isAsyn != null ? _isAsyn : true); this.onLoad = null; this.onError = null; this.onLoading = null; this.request = null; this.createRequest = function() {
            var xmlHttp = null;
            if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
            else if (window.ActiveXObject) {
                with (System) {
                    for (var i = 0; i < $XMLHTTP_VERS.length; i++) {
                        try {
                            xmlHttp = new ActiveXObject($XMLHTTP_VERS[i]);
                        }
                        catch (e) { }
                        if (xmlHttp) {
                            $XMLHTTP_VERS = [$XMLHTTP_VERS[i]];
                        }
                    }
                }
            }
            return xmlHttp;
        };
        this.send = function(uri, method, data, headers, onComplete, onException, onFailure) {
            method = method || "get";
            var xmlHttp = this.createRequest();
            if (!onComplete) onComplete = this.onLoad;
            if (!onException) onException = this.onError;
            if (!onFailure) onFailure = this.onLoading;
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200 || xmlHttp.status == 0) {
                        if (onComplete) onComplete(xmlHttp);
                    }
                    else {
                        if (onException) onException(new System.Exception(xmlHttp.status, xmlHttp.statusText, xmlHttp));
                    }
                }
                else if (onFailure) onFailure();
            }
            xmlHttp.open(method, uri, this.isAsyn);
            if (method.toLowerCase() == "post")
                xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            if (headers) {
                for (var i = 0; i < headers.length; i++)
                    xmlHttp.setRequestHeader(headers[i][0], headers[i][1]);
            }
            xmlHttp.send((method.toLowerCase() == "post") ? data : null);
            this.request = xmlHttp;
            return true;
        };
    },
    clearXmlHttps: function() {
        while (this.$XMLHTTPS.length > 0) {
            var xmlHttp = this.$XMLHTTPS.pop();
            xmlHttp = null;
            delete xmlHttp;
        }
    },
    PostData: function(url, data, method, target, form) {
        var theForm;
        if (form == null || form == undefined) {
            theForm = document.createElement("form");
            document.body.appendChild(theForm);
        }
        else theFrom = form;
        if (data != null && data != undefined) {
            var theData = data.split("&");
            for (var i = 0; i < theData.length; i++) {
                if (!theData[i].isEmpty()) {
                    var dataItem = theData[i].split("=");
                    var inputData = document.createElement("input");
                    inputData.setAttribute("type", "hidden");
                    inputData.setAttribute("name", dataItem[0]);
                    inputData.setAttribute("value", dataItem[1] ? dataItem[1] : "");
                    theForm.appendChild(inputData);
                }
            }
        }
        if (url) theForm.setAttribute("action", url);
        if (method) theForm.setAttribute("method", method || "post");
        if (target) theForm.setAttribute("target", target || "_self");
        theForm.submit();
    }
});

namespace.register("System.Event");
System.Event.extend({
    $EVENT_LISTENER: [],
    $PAGE_ISLOAD: false,
    getEvent: function() {
        if (window.event) return window.event; var method = System.Event.getEvent.caller;
        while (method != null) {
            var firstArgs = method.arguments[0];
            if (firstArgs) {
                try {
                    if (firstArgs.constructor == Event || firstArgs.constructor == MouseEvent)
                        return firstArgs;
                } catch (e) { return null; }
            }
            method = method.caller;
        }
        return null;
    },
    stop: function() {
        var e = this.getEvent();
        if (e.preventDefault) {
            e.preventDefault();
            e.stopPropagation();
        } else {
            e.cancelBubble = true;
        }
    },
    getEventPos: function() {
        var oEvent = this.getEvent();
        if (oEvent)
            return { left: oEvent.clientX, top: oEvent.clientY };
        return { left: 0, top: 0 };
    },
    getTarget: function() {
        var oEvent = this.getEvent();
        if (oEvent) return oEvent.target || oEvent.srcElement;
        return null;
    },
    addEventListenerAndCache: function(element, eventName, sEvent, useCapture) {
        if (!this.$EVENT_LISTENER)
            this.$EVENT_LISTENER = [];
        if (element.addEventListener) {
            this.$EVENT_LISTENER.push([element, eventName, sEvent, useCapture]);
            element.addEventListener(eventName, sEvent, useCapture);
        }
        else if (element.attachEvent) {
            this.$EVENT_LISTENER.push([element, eventName, sEvent, useCapture]);
            element.attachEvent('on' + eventName, sEvent);
        }
    },
    removeEventListenerCache: function() {
        if (!this.$EVENT_LISTENER)
            return;
        for (var i = 0; i < this.$EVENT_LISTENER.length; i++) {
            System.Event.removeEventListener.apply(this, this.$EVENT_LISTENER[i]);
            this.$EVENT_LISTENER[i][0] = null;
        }
        this.$EVENT_LISTENER = null;
    },
    addEventListener: function(element, eventName, sEvent, useCapture) {
        if (typeof (element) == "string") element = document.getElementById(element);
        if (!element) return;
        useCapture = useCapture || false;
        if (eventName == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || element.attachEvent))
            eventName = 'keydown';
        this.addEventListenerAndCache(element, eventName, sEvent, useCapture);
    },
    removeEventListener: function(element, eventName, sEvent, useCapture) {
        useCapture = useCapture || false;
        if (name == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || element.detachEvent))
            name = 'keydown';
        if (element.removeEventListener) {
            element.removeEventListener(eventName, sEvent, useCapture);
        }
        else if (element.detachEvent) {
            element.detachEvent('on' + eventName, sEvent);
        }
    },
    documentReady: function() {
        if (arguments.callee.done) return;
        arguments.callee.done = true;
        System.PageIsLoad = true;
        if (this._timer) clearInterval(this._timer);
        for (var i = 0; i < System.Event._readyCallbacks.length; i++)
            System.Event._readyCallbacks[i]();
        System.Event._readyCallbacks = null;
    },
    PageLoad: function(f) {
        if (System.PageIsLoad) {
            if (f) f();
            return;
        }
        if (!System.Event._readyCallbacks) {
            var domReady = System.Event.documentReady;
            if (document.addEventListener)
                document.addEventListener("DOMContentLoaded", domReady, false);


            if (/WebKit/i.test(navigator.userAgent)) {
                this._timer = setInterval(function() {
                    if (/loaded|complete/.test(document.readyState)) domReady();
                }, 10);
            }
            System.Event.addEventListener(window, 'load', domReady);
            System.Event._readyCallbacks = [];
        }
        System.Event._readyCallbacks.push(f);
    },
    PageUnLoad: function(f) {
        this.addEventListener(window, "unload", f, false);
    }
});
System.Event.PageUnLoad(System.Event.removeEventListenerCache.createDelegate(System.Event)); System.Event.PageUnLoad(System.clearXmlHttps.createDelegate(System));

namespace.register("System.Browser");
System.Browser.extend({
    getBrowserName: function() {
        var sAgent = navigator.userAgent.toLower();
        if (sAgent.indexOf("msie 7.0") >= 0) return "IE7";
        if (sAgent.indexOf("msie") >= 0) return "IE";
        if (sAgent.indexOf("opera") >= 0) return "Opera";
        if (sAgent.indexOf("firefox") >= 0) return "Firefox";
        if (sAgent.indexOf("safari") >= 0) return "Safari";
        if (sAgent.indexOf("netscape") >= 0) return "Netscape";
        if (sAgent.indexOf("gecko") >= 0) return "Netscape";
    },
    isIE7: function() {
        return System.Browser.getBrowserName() == "IE7";
    },
    isIE: function() {
        return System.Browser.getBrowserName().indexOf("IE") >= 0;
    },
    isFirefox: function() {
        return System.Browser.getBrowserName() == "Firefox";
    },
    isOpera: function() {
        return System.Browser.getBrowserName() == "Opera";
    },
    isNetscape: function() {
        return System.Browser.getBrowserName() == "Netscape";
    },
    isSafari: function() {
        return System.Browser.getBrowserName() == "Safari";
    },
    UserAgent: navigator.userAgent
});

if (System.Browser.isFirefox() || System.Browser.isNetscape()) {
    HTMLElement.prototype.__defineSetter__("outerHTML", function(sHTML) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(sHTML);
        this.parentNode.replaceChild(df, this);
        return sHTML;
    });
    HTMLElement.prototype.__defineGetter__("outerHTML", function() {
        var attr;
        var attrs = this.attributes;
        var str = "<" + this.tagName.toLowerCase();
        for (var i = 0; i < attrs.length; i++) {
            attr = attrs[i];
            if (attr.specified) str += " " + attr.name + '="' + attr.value + '"';
        }
        if (!this.canHaveChildren) return str + ">";
        return str + ">" + this.innerHTML + "</" + this.tagName.toLowerCase() + ">";
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function() {
        switch (this.tagName.toLowerCase()) { case "area": case "base": case "basefont": case "col": case "frame": case "hr": case "img": case "br": case "input": case "isindex": case "link": case "meta": case "param": return false; }
        return true;
    });
}
if (System.Browser.isFirefox() || System.Browser.isNetscape()) {
    CSSStyleSheet.prototype.addRule = function(selectorText, cssText, index) {
        return this.insertRule("{0}{{1}}".format(selectorText, cssText), index);
    }
    CSSStyleSheet.prototype.removeRule = CSSStyleSheet.prototype.deleteRule;
} namespace.register("System.Xml");
System.Xml.extend({
    $XML_DOM_VERS: ["MSXML2.DOMDocument.6.0", "MSXML2.DOMDocument.3.0"],
    createDocument: function(rootNodeName) {
        namespace.require("System.Browser");
        var xmlDoc = null;
        if (window.ActiveXObject) {
            for (var i = 0; i < this.$XML_DOM_VERS.length; i++) {
                try {
                    xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
                    this.$XML_DOM_VERS = [this.$XML_DOM_VERS[i]];
                    break;
                } catch (e) { };
            }
        }
        else xmlDoc = document.implementation.createDocument("", "", null);
        if (!System.Browser.isOpera())
            xmlDoc.appendChild(xmlDoc.createProcessingInstruction("xml", "version='1.0'"));
        if (typeof (rootNodeName) == "string") {
            var root = xmlDoc.createElement(rootNodeName);
            xmlDoc.appendChild(root);
        }
        return xmlDoc;
    },
    serializeToString: function(sNode) {
        var sXml = "";
        switch (sNode.nodeType) {
            case 1:
                sXml = "<" + sNode.tagName;
                for (var i = 0; i < sNode.attributes.length; i++)
                    sXml += " " + sNode.attributes[i].name + "=\"" + sNode.attributes[i].value + "\"";
                sXml += ">";
                for (var i = 0; i < sNode.childNodes.length; i++)
                    sXml += System.Xml.serializeToString(sNode.childNodes[i]);
                sXml += "</" + sNode.tagName + ">";
                break;
            case 3:
                sXml = sNode.nodeValue;
                break;
            case 4:
                sXml = "<![CDATA[" + sNode.nodeValue + "]]>";
                break;
            case 7:
                sXml = "<?" + sNode.nodevalue + "?>";
                break;
            case 8:
                sXml = "<!--" + sNode.nodevalue + "-->";
                break;
            case 9:
                for (var i = 0; i < sNode.childNodes.length; i++)
                    sXml += System.Xml.serializeToString(sNode.childNodes[i]);
                break;
        }
        return sXml;
    },
    transformToText: function(oXml, oXslt) {
        var result = null;
        if (typeof XSLTProcessor != "undefined") {
            var oProcessor = new XSLTProcessor();
            oProcessor.importStylesheet(oXslt);
            var oResultDom = oProcessor.transformToDocument(oXml);
            result = this.serializeToString(oResultDom);
            if (result.indexOf("<transformiix:result") > -1)
                result = result.substring(result.indexOf(">") + 1, result.lastIndexOf("<"));
        }
        else if (window.ActiveXObject) {
            result = oXml.transformNode(oXslt);
        }
        if (result != null)
            result = result.replace(/<\?xml(.*?)\?>/, '');
        return result;
    },
    loadXML: function(sXml) {
        var xmlDoc = this.createDocument();
        xmlDoc.loadXML(sXml);
        return xmlDoc;
    }
});
if (document.implementation.hasFeature("XPath", "3.0") && typeof (window.opera) != "object") {

    XMLDocument.prototype.loadXML = function(xmlString) {
        var childNodes = this.childNodes;
        for (var i = childNodes.length - 1; i >= 0; i--)
            this.removeChild(childNodes[i]);
        var dp = new DOMParser();
        var newDOM = dp.parseFromString(xmlString, "text/xml");
        var newElt = this.importNode(newDOM.documentElement, true);
        this.appendChild(newElt);
    };
    XMLDocument.prototype.selectNodes = function(cXPathString, xNode) {
        if (!xNode) { xNode = this; }
        var oNSResolver = this.createNSResolver(this.documentElement);
        var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        var aResult = [];
        for (var i = 0; i < aItems.snapshotLength; i++)
            aResult.push(aItems.snapshotItem(i));
        return aResult;
    }
    Element.prototype.selectNodes = function(cXPathString) {
        if (this.ownerDocument.selectNodes)
            return this.ownerDocument.selectNodes(cXPathString, this);
        else
            return [];
    }
    XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode) {
        if (!xNode) { xNode = this; }
        var xItems = this.selectNodes(cXPathString, xNode);
        if (xItems.length > 0)
            return xItems[0];
        else
            return null;
    }
    Element.prototype.selectSingleNode = function(cXPathString) {
        if (this.ownerDocument.selectSingleNode)
            return this.ownerDocument.selectSingleNode(cXPathString, this);
        else
            return [];
    }
} namespace.register("System.Common");

System.Common.extend({
    createOrderData: function(start, end, textField, valueField) {
        var data = new Array();
        textField = textField || "text";
        valueField = valueField || "value";
        for (var i = start; i <= end; i++) {
            var o = new Object();
            o[textField] = String(i);
            o[valueField] = String(i);
            data.push(o);
        }
        return data;
    },
    formatFileSize: function(size) {
        if (size > 1024 * 1024 * 1024) {
            return String(Number(size / (1024 * 1024 * 1024)).toFixed(2)) + "GB";
        }
        else if (size > 1024 * 1024) {
            return String(Number(size / (1024 * 1024)).toFixed(2)) + "MB";
        }
        else if (size > 1024) {
            return String(Number(size / (1024)).toFixed(2)) + "KB";
        }
        else {
            return String(size) + "KB";
        }
    },
    formatTime: function(seconds) {
        if (seconds > 24 * 60 * 60) {
            return Math.ceil(seconds / (24 * 60 * 60)) + "天";
        }
        else if (seconds > 60 * 60) {
            return Math.ceil(seconds / (60 * 60)) + "小时";
        }
        else if (seconds > 60) {
            return Math.ceil(seconds / 60) + "分";
        }
        else {
            return Math.ceil(seconds) + "秒";
        }
    }
}); namespace.register("System.DateTime");
System.DateTime.extend({
    $MONTH_DAYS: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
    getDays: function(year, month) {
        if (month == 1)
            return (((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) ? 29 : 28);
        else
            return this.$MONTH_DAYS[month];
    },
    parse: function(dateVal, dateTimeFormat) {
        var format = dateTimeFormat || "yyyy-MM-dd hh:mm:ss";
        var matchYear = format.match(/(y+)/);
        var matchMonth = format.match(/(M+)/);
        var matchDate = format.match(/(d+)/);
        var matchHour = format.match(/(h+)/);
        var matchMinute = format.match(/(m+)/);
        var matchSecond = format.match(/(s+)/);
        var yearValue = 2000, monthValue = 0, dateValue = 1, hourValue = 0, minuteValue = 0, secondValue = 0;
        if (matchYear)
            yearValue = parseInt(dateVal.substr(matchYear.index, matchYear[1].length) || "2000", 10);
        if (matchMonth)
            monthValue = parseInt(dateVal.substr(matchMonth.index, matchMonth[1].length) || "1", 10) - 1;
        if (matchDate)
            dateValue = parseInt(dateVal.substr(matchDate.index, matchDate[1].length) || "1", 10);
        if (matchHour)
            hourValue = parseInt(dateVal.substr(matchHour.index, matchHour[1].length) || "0", 10);
        if (matchMinute)
            minuteValue = parseInt(dateVal.substr(matchMinute.index, matchMinute[1].length) || "0", 10);
        if (matchSecond)
            secondValue = parseInt(dateVal.substr(matchSecond.index, matchSecond[1].length) || "0", 10);
        return new Date(yearValue, monthValue, dateValue, hourValue, minuteValue, secondValue);
    }
}, false); namespace.register("System.Document");
System.Document.extend({
    $MAX_ZORDER: 1,
    $HTML_HEAD: document.getElementsByTagName("head").length > 0 ? document.getElementsByTagName("head")[0] : null,
    $DISABLE_SELECT: function() { return false; },
    selectNodes: function(htmlElement, searchPath, searchCount) {
        if (typeof (htmlElement) == "string")
            htmlElement = document.getElementById(htmlElement);
        if (!htmlElement || searchPath.isEmpty()) return [];
        var elements = [], pathNodes = searchPath.split("/");
        var searchNodes = function(htmlElements, searchOptions, result, isSearchChild) {
            for (var i = 0; i < htmlElements.length; i++) {
                if (!htmlElements[i].hasChildNodes()) continue;
                for (var n = 0; n < htmlElements[i].childNodes.length; n++) {
                    var sObject = null, cNode = htmlElements[i].childNodes[n];
                    if (cNode.nodeType == "1" && (cNode.nodeName.toLower() == searchOptions.pathNode.toLower() || searchOptions.pathNode == "*")) {
                        var isMatch = true;
                        if (!searchOptions.pathArgs.isEmpty()) {
                            isMatch = false;
                            if (searchOptions.pathArgs.charAt(0) == "@") {
                                var attribute = cNode.getAttribute(searchOptions.pathArgs.slice(1, searchOptions.pathArgs.length));
                                if (attribute && !searchOptions.pathArgsValue.isEmpty() && new RegExp(searchOptions.pathArgsValue).test(attribute)) isMatch = true;
                            }
                            else {
                                if (!cNode.hasChildNodes()) continue;
                                for (var j = 0; j < cNode.childNodes.length; j++) {
                                    if (cNode.childNodes[j].nodeType == "1" && cNode.childNodes[j].nodeName.toLower() == searchOptions.pathArgs.toLower())
                                        if (!searchOptions.pathArgsValue.isEmpty() && cNode.childNodes[j].innerHTML != null && cNode.childNodes[j].innerHTML != "undefined" && cNode.childNodes[j].innerHTML == searchOptions.pathArgsValue)
                                        isMatch = true;
                                }
                            }
                        }
                        if (isMatch) sObject = cNode;
                    }
                    if (sObject != null) result.push(sObject); else if (isSearchChild == true && cNode.nodeType == 1) result = searchNodes([cNode], searchOptions, result, isSearchChild); if (searchCount && searchCount <= result.length) break;
                }
            }
            return result;
        };
        elements.push(htmlElement);
        for (var i = 0; i < pathNodes.length; i++) {
            var options = { pathArgs: "", pathArgsValue: "" }, pathNode = pathNodes[i];
            if (pathNode.isEmpty()) continue;
            options.pathNode = pathNode;
            if (pathNode.indexOf("[") >= 0 && pathNode.indexOf("]") >= 0) {
                options.pathArgs = pathNode.slice(pathNode.indexOf("[") + 1, pathNode.indexOf("]"));
                options.pathNode = pathNode.slice(0, pathNode.indexOf("["));
                if (options.pathArgs.indexOf("=") > 0) {
                    options.pathArgsValue = options.pathArgs.slice(options.pathArgs.indexOf("=") + 1, options.pathArgs.length);
                    options.pathArgs = options.pathArgs.slice(0, options.pathArgs.indexOf("="));
                }
            }
            elements = searchNodes(elements, options, [], (i != 0 && pathNodes[i - 1].isEmpty()) || options.pathNode == "*");
        }
        if (!searchCount) return elements;
        else return elements.slice(0, searchCount);
    },
    selectSingleNode: function(htmlElement, searchPath) {
        var result = this.selectNodes(htmlElement, searchPath, 1);
        if (result.length > 0) return result[0];
        return null;
    },
    getElementSize: function(element) {
        return { width: element.offsetWidth || 0, height: element.offsetHeight || 0 };
    },
    getAbsolutePosition: function(element) {
        if (!element) return null;
        var sTop = element.offsetTop, sLeft = element.offsetLeft;
        while (element = element.offsetParent) {
            if ((element.style.overflow != 'visible' && element.style.overflow != '')) break;
            sTop += element.offsetTop;
            sLeft += element.offsetLeft;
        }
        return { top: sTop, left: sLeft };
    },
    getRelativePosition: function(element) {
        if (!element) return null;
        var sTop = element.offsetTop, sLeft = element.offsetLeft;
        while (element = element.offsetParent) {
            if ((element.style.overflow != 'visible' && element.style.overflow != '') || element.style.position == "absolute" || element.style.position == "relative") break;
            sTop += element.offsetTop;
            sLeft += element.offsetLeft;
        }
        return { top: sTop, left: sLeft };
    },
    moveElement: function(element, toPosition, speed, callback) {
        if (!(element && toPosition && toPosition.left && toPosition.top)) return;
        var sTimer = null;
        var sSpeed = speed || 20;
        sTimer = window.setInterval(function() {
            var ePos = System.Document.getAbsolutePosition(element);
            var toPos = toPosition;
            var rPos = { left: toPos.left - ePos.left, top: toPos.top - ePos.top };
            if (!(ePos.left == toPos.left && ePos.top == toPos.top)) {
                var left = 0, top = 0;
                if (rPos.left != 0) {
                    if (rPos.top != 0) left = Math.abs(Math.floor(1 * (rPos.left / rPos.top)));
                    else left = 1;
                    if (toPosition.left < ePos.left) left = 0 - left;
                }
                if (rPos.top != 0) {
                    if (rPos.left != 0) top = Math.abs(Math.floor(1 * (rPos.top / rPos.left)));
                    else top = 1;
                    if (toPosition.top < ePos.top) top = 0 - top;
                }
                element.style["top"] = (ePos.top + top) + "px";
                element.style["left"] = (ePos.left + left) + "px";
                element.style["position"] = "absolute";
                ePos = System.Document.getAbsolutePosition(element);
                rPos = { left: toPos.left - ePos.left, top: toPos.top - ePos.top };
            }
            else {
                if (sTimer) window.clearInterval(sTimer);
                if (callback) callback();
            }
        }, sSpeed);
    },
    getVisibleDocumentSize: function() {
        return { width: this.getDocumentElement().clientWidth, height: this.getDocumentElement().clientHeight };
    },
    getVisibleAreaPosition: function() {
        return [{ left: this.getScrollPosition().left, top: this.getScrollPosition().top }, { left: this.getScrollPosition().left + this.getVisibleDocumentSize().width, top: this.getScrollPosition().top + this.getVisibleDocumentSize().height}];
    },
    getVisibleArea: function() {
        return {}.extend(this.getVisibleDocumentSize()).extend(this.getScrollPosition());
    },
    getRealDocumentSize: function() {
        namespace.require("System.Browser");
        if (System.Browser.isIE7())
            return { width: document.body.scrollWidth, height: document.body.scrollHeight };
        else if (System.Browser.isFirefox() || System.Browser.isOpera())
            return { width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight };
        else
            return { width: document.body.offsetWidth, height: document.body.offsetHeight };
    },
    getScrollPosition: function() {
        return { left: this.getDocumentElement().scrollLeft, top: this.getDocumentElement().scrollTop };
    },
    createStyleSheet: function() {
        var nStyle = document.createElement("style");
        this.$HTML_HEAD.appendChild(nStyle);
        return document.styleSheets[document.styleSheets.length - 1];
    },
    getStyleSheet: function() {
        if (arguments.length == 0)
            return (document.styleSheets.length > 0) ? document.styleSheets[0] : this.createStyleSheet();
        else {
            if (!document.styleSheets[arguments[0]])
                document.styleSheets[arguments[0]] = this.createStyleSheet();
            return document.styleSheets[arguments[0]];
        }
    },
    setCookie: function(name, value) {
        var expdate = new Date();
        var argv = arguments;
        var argc = arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        if (expires != null && expires >= 0)
            expdate.setTime(expdate.getTime() + (expires * 1000));
        document.cookie = name + "=" + escape(((typeof (value) == "object") ? value.toJSONString() : value)) + ((expires == null || expires < 0) ? ((expires == -1) ? "; expires=-1" : "") : ("; expires=" + expdate.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
    },
    getQueryString: function(key) {
        key = key + "=";
        if (window.location.search.length > 0) {
            begin = window.location.search.indexOf(key);
            if (begin != -1) {
                begin += key.length;
                end = window.location.search.indexOf("&", begin);
                if (end == -1)
                    end = window.location.search.length;
                return unescape(window.location.search.substring(begin, end));
            }
            return null;
        }
        return null;
    },
    delCookie: function(name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = this.getCookie(name);
        document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    },
    getCookie: function(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]); else return null;
    },
    getDocumentElement: function() {
        namespace.require("System.Browser");
        if (System.Browser.isOpera())
            return document.body;
        else
            return (document.compatMode && document.compatMode == "BackCompat") ? document.body : document.documentElement;
    },
    scrollToElement: function(element, ralativePos) {
        if (element) {
            var ePos = this.getAbsolutePosition(element);
            if (ralativePos) {
                if (ralativePos.left) ePos.left += ralativePos.left;
                if (ralativePos.top) ePos.top += ralativePos.top;
            }
            window.scrollTo(ePos.left, ePos.top);
        }
    },
    fixedElement: function(element, pos, anchor, onscroll, timespan) {
        namespace.require("System.Event");
        var eAnchor = anchor || { horizontal: "left", vertical: "top" };
        var eTimeSpan = timespan || 10;
        var getTargetPostion = function(_element, _pos, _anchor) {
            var spos = System.Document.getScrollPosition();
            var dsize = System.Document.getVisibleDocumentSize();
            var esize = System.Document.getElementSize(_element);
            var left = _pos.left, top = _pos.top;
            switch (_anchor.horizontal) {
                case "left":
                    left = spos.left + _pos.left;
                    break;
                case "center":
                    left = Math.floor((dsize.width - esize.width) / 2) + spos.left + _pos.left;
                    break;
                case "right":
                    left = dsize.width + spos.left - _pos.left - esize.width;
                    break;
            }
            switch (_anchor.vertical) {
                case "top":
                    top = spos.top + _pos.top;
                    break;
                case "center":
                    top = Math.floor((dsize.height - esize.height) / 2) + spos.top + _pos.top;
                    break;
                case "bottom":
                    top = dsize.height + spos.top - _pos.top - esize.height;
                    break;
            }
            return { top: top, left: left };
        }
        if (onscroll) {
            System.Event.addEventListener(window, "scroll", function() {
                var spos = getTargetPostion(element, pos, eAnchor, true);
            }, false);
        }
        else {
            var sTimer = window.setInterval(function() {
                var spos = getTargetPostion(element, pos, eAnchor, false, eTimeSpan);
                element.style["top"] = spos.top + "px";
                element.style["left"] = spos.left + "px";
                element.style["position"] = "absolute";
            }, eTimeSpan);
            System.Event.addEventListener(window, "unload", function() {
                window.clearInterval(sTimer);
            }, false);
        }
    },
    dragModule: function(control, module, pos) {
        var dragEvent = {
            isDraging: false, relativeX: 0, relativeY: 0,
            onmousedown: function(e) {
                var eventPos = System.Event.getEventPos();
                var modulePos = System.Document.getRelativePosition(module);
                dragEvent.relativeX = eventPos.left - modulePos.left;
                dragEvent.relativeY = eventPos.top - modulePos.top;
                dragEvent.isDraging = true;
                module.style.position = "absolute";
                module.style.zIndex = System.Document.getNextZOrder();
                System.Event.addEventListener(document, "selectstart", function() { return false; }, false);
            },
            onmousemove: function(e) {
                if (dragEvent.isDraging == true) {
                    var pos = dragEvent.getPosition();
                    module.style.left = pos.x + "px";
                    module.style.top = pos.y + "px";
                }
            },
            onmouseout: function(e) {
                dragEvent.isDraging = false;
            },
            onmouseup: function(e) {
                dragEvent.isDraging = false;
                System.Event.removeEventListener(document, "selectstart", function() { return false; }, false);
            },
            getPosition: function() {
                var eventPos = System.Event.getEventPos();
                var x = (eventPos.left - dragEvent.relativeX);
                var y = (eventPos.top - dragEvent.relativeY);
                var moduleSize = System.Document.getElementSize(module);
                var scrollPos = System.Document.getScrollPosition();
                if (pos != null && pos != undefined) {
                    if (x < pos.left + scrollPos.left) x = pos.left + scrollPos.left;
                    else if (x > pos.width + scrollPos.left - moduleSize.width) x = pos.width + scrollPos.left - moduleSize.width;
                    if (y < pos.top + scrollPos.top) y = pos.top + scrollPos.top;
                    else if (y > pos.height + scrollPos.top - moduleSize.height) y = pos.height + scrollPos.top - moduleSize.height;
                }
                return { x: x, y: y };
            }
        };
        System.Event.addEventListener(control, "mousedown", dragEvent.onmousedown, false);
        System.Event.addEventListener(document, "mousemove", dragEvent.onmousemove, false);
        System.Event.addEventListener(document, "mouseup", dragEvent.onmouseup, false);
    },
    fadeElement: function(element, start, end, delay, callBack) {
        var delay = delay || 1;
        var start = start || 0;
        var end = end || 100;
        var direction = end > start ? "up" : "down";
        var opacity = start;
        var timer = window.setInterval(function() {
            if (direction == "up") opacity += 2;
            else opacity += -2;
            element.style.filter = "alpha(opacity=" + String(opacity) + ");";
            element.style.MozOpacity = opacity * 0.01;
            element.style.opacity = opacity * 0.01;
            if ((direction == "up" && opacity >= end) || (direction == "down" && opacity <= end)) {
                window.clearInterval(timer);
                if (callBack) callBack();
            }
        }, delay);
    },
    disableSelect: function() {
        System.Event.addEventListener(document, "selectstart", System.Document.$DISABLE_SELECT, false);
    },
    enableSelect: function() {
        System.Event.removeEventListener(document, "selectstart", System.Document.$DISABLE_SELECT, false);
    },
    getNextZOrder: function() {
        return ++this.$MAX_ZORDER;
    }
}); namespace.register("System.Validate");
System.Validate.extend({
    $V_ITEMS: {},
    $REGEXP: {
        isEmpty: /[\S]/,
        isMobile: /^(13\d{9}|159\d{8}|153\d{8}|158\d{8})$/,
        isPhone: /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^[0-9]{3,4}\-[0-9]{3,8}\-[0-9]{1,8})/,
        isEmail: /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
        isNumeric: /^(-|\+)?\d+(\.\d+)?$/, isUnsignedNumeric: /^\d+(\.\d+)?$/, isInteger: /^(-|\+)?\d+$/, isUnsignedInteger: /^\d+$/, isDate: /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/
    },
    Validator: function(element, regExp, message, validateGroup, messageElement, eventName, attributeName,
         isStatic, isNullable, isAlert, callBack) {
        this.element = element;
        this.regExp = regExp || System.Validate.$REGEXP.isEmpty;
        this.message = message;
        this.messageElement = messageElement;
        this.eventName = eventName || ["blur"];
        this.attributeName = attributeName || "value";
        this.isStatic = isStatic || false;
        this.validateGroup = validateGroup || "default";
        this.isNullable = isNullable || false;
        this.callBack = callBack;
        this.isValid = true;
        this.isAlert = isAlert || false;
        var _this = this;
        this.validate = function() {
            if (!this.element) return;
            var testValue = null;
            if (this.attributeName == "value") {
                namespace.require("System.Controls");
                var inputBox = new System.Controls.InputBox(this.element);
                inputBox.show();
                testValue = inputBox.getValue();
            }
            else {
                if (this.element[this.attributeName] != undefined && this.element[this.attributeName] != null)
                    testValue = this.element[this.attributeName];
                else
                    testValue = this.element.getAttribute(this.attributeName);
            }
            this.isValid = true;
            if (testValue == null || !this.regExp.test(testValue))
                this.isValid = (testValue == null || testValue.isEmpty()) && this.isNullable == true;
            this.show();
            if (callBack) callBack(this);
            return this.isValid;
        };
        this.show = function() {
            if (!this.message) return;
            if (this.messageElement) {
                this.messageElement.style.display = (this.isValid ? "none" : "block");
                this.messageElement.innerHTML = this.message;
                if (this.isAlert) alert(this.message);
            }
            else if (!this.isValid) {
                alert(this.message);
            }
        };
        if (typeof (this.element) == "string")
            this.element = document.getElementById(this.element);
        if (typeof (this.messageElement) == "string")
            this.messageElement = document.getElementById(this.messageElement);
        if (this.eventName instanceof Array && this.element) {
            namespace.require("System.Event");
            for (var i = 0; i < this.eventName.length; i++)
                System.Event.addEventListener(this.element, this.eventName[i], function() { _this.validate(_this, arguments); }, false);
        }
        this.show();
    },
    CustomValidator: function(method, message, args, messageElement, groupName, isAlert, callBack) {
        this.isValid = true;
        this.method = method;
        this.methodArgs = args;
        this.messageElement = messageElement;
        this.validateGroup = groupName || "default";
        this.message = message;
        this.isAlert = isAlert || false;
        this.show = function() {
            if (!this.message) return;
            if (this.messageElement) {
                this.messageElement.style.display = (this.isValid ? "none" : "block");
                this.messageElement.innerHTML = this.message;
                if (this.isAlert) alert(this.message);
            }
            else if (!this.isValid) {
                alert(this.message);
            }
        };
        this.validate = function() {
            this.isValid = this.method.apply(this, this.methodArgs || []);
            this.show();
            if (callBack) callBack(this);
            return this.isValid;
        }
        if (typeof (this.messageElement) == "string")
            this.messageElement = document.getElementById(this.messageElement);
        this.show();
    },
    append: function(validator) {
        var groupName = validator.validateGroup;
        if (!this.$V_ITEMS[groupName])
            this.$V_ITEMS[groupName] = [];
        this.$V_ITEMS[groupName].push(validator);
    },
    isValid: function(groupName, itemValidated) {
        var isValid = true;
        if (document.activeElement) {
            var isCausesValidation = document.activeElement.getAttribute("CausesValidation");
            if (isCausesValidation == "false") return true;
        }
        if (groupName && !groupName.isEmpty()) {
            if (!this.$V_ITEMS[groupName]) return isValid;
            for (var i = 0; i < this.$V_ITEMS[groupName].length; i++) {
                if (!this.$V_ITEMS[groupName][i].validate()) {
                    isValid = false;
                    if (itemValidated) itemValidated.apply(this.$V_ITEMS[groupName][i]);
                }
            }
        }
        else {
            for (var v in this.$V_ITEMS) {
                if (!(this.$V_ITEMS[v] instanceof Array)) continue;
                for (var i = 0; i < this.$V_ITEMS[v].length; i++) {
                    if (!this.$V_ITEMS[v][i].validate()) {
                        isValid = false;
                        if (itemValidated) itemValidated.apply(this.$V_ITEMS[v][i]);
                    }
                }
            }
        }
        return isValid;
    }
}); namespace.register("System.Controls");
System.Controls.extend({
    Control: function(control, parent) {
        this.tagName = "div"; this.element = control; this.parentNode = parent || (this.element && this.element.parentNode ? this.element.parentNode : document.body); this.isFadeUp = false;
        this.isFadeDown = false;
        this.alpha = 100;
        this.visible = false;
        this.onshow = null;
        this.onclose = null;
        var _this = this;
        this.create = function() {
            if (!this.element) {
                this.element = document.createElement(this.tagName);
                this.element.style.display = "none";
            }
            if (typeof (this.element) == "string") {
                var htmlElement = document.getElementById(this.element);
                if (htmlElement != null && typeof (htmlElement) == "object") {
                    this.element = htmlElement;
                    this.parentNode = this.element.parentNode;
                }
                else if (this.parentNode != null && typeof (this.parentNode) == "object") {
                    this.parentNode.innerHTML += this.element;
                    this.element = this.parentNode.lastChild;
                }
            }
            return this.element;
        };
        this.show = function() {
            if (this.onshow) this.onshow();
            this.visible = true;
            this.create();
            if (!this.parentNode)
                this.parentNode = document.body;
            if ((!this.element.parentNode || this.element.parentNode != this.parentNode) && this.parentNode.nodeType == 1)
                this.parentNode.appendChild(this.element);
            if (this.element.style && this.element.style.display == "none") {
                this.setStyle("display", "");
                if (this.isFadeUp) {
                    this.setStyle("alpha", this.alpha);
                    namespace.require("System.Document");
                    System.Document.fadeElement(this.element, 0, this.alpha, 5);
                }
            }
        };
        this.close = function() {
            if (this.onclose) this.onclose();
            this.visible = false;
            if (this.isFadeDown) {
                namespace.require("System.Document");
                System.Document.fadeElement(this.element, "down", 1, function() {
                    _this.setStyle("display", "none")
                });
            }
            else this.setStyle("display", "none");
        };
        this.setAttribute = function(name, value) {
            this.create();
            if (this.element.nodeType == 1) {
                this.element.setAttribute(name, value);
            }
        };
        this.getAttribute = function(name) {
            this.create();
            return this.element.getAttribute(name);
        };
        this.setStyle = function(key, value) {
            this.create();
            if (this.element.nodeType == 1) {
                if (key == "alpha") {
                    this.element.style.filter = "alpha(opacity=" + String(value) + ");";
                    this.element.style.MozOpacity = value * 0.01;
                    this.element.style.opacity = value * 0.01;
                    this.element.style.visibility = "hidden";
                    this.element.style.visibility = "visible";
                    this.alpha = value;
                }
                else this.element.style[key] = value;
            }
        };
        this.setCssText = function(value) {
            this.create();
            this.element.setAttribute("style", value);
            this.element.style.cssText = value;
        };
        this.setCssClass = function(value) {
            namespace.require("System.Browser");
            if (System.Browser.isIE())
                this.setAttribute("className", value);
            else
                this.setAttribute("class", value);
        };
        this.addCssRule = function(ruleName, cssText, index) {
            namespace.require("System.Document");
            namespace.require("System.Browser");
            this.create();
            var sSheet = System.Document.getStyleSheet();
            sSheet.addRule(ruleName, cssText, index);
            if (ruleName.charAt(0) == ".") {
                if (System.Browser.isIE())
                    this.setAttribute("className", ruleName);
                else
                    this.setAttribute("class", ruleName);
            }
        };
        this.setInnerHTML = function(sHtml, override) {
            this.create();
            if (override)
                this.element.innerHTML = sHtml;
            else
                this.element.innerHTML += sHtml;
        };
        this.remove = function() {
            if (this.parentNode) {
                this.parentNode.removeChild(this.element);
            }
        }
        this.addEventListener = function(eventName, sEvent, useCapture) {
            if (!this.create()) return;
            System.Event.addEventListener(this.element, eventName, sEvent, useCapture);
        }
        this.removeEventListener = function(eventName, sEvent, useCapture) {
            if (!this.create()) return;
            System.Event.removeEventListener(this.element, eventName, sEvent, useCapture);
        }
        this.position = function(absolute) {
            if (!this.create()) return;
            if (absolute) return System.Document.getAbsolutePosition(this.element);
            else return System.Document.getRelativePosition(this.element);
        }
        this.size = function() {
            if (!this.create()) return;
            return System.Document.getElementSize(this.element);
        }
        this.selectNodes = function(searchPath, searchCount) {
            if (!this.create()) return null;
            return System.Document.selectNodes(this.element, searchPath, searchCount);
        }
        this.selectSingleNode = function(searchPath) {
            if (!this.create()) return null;
            return System.Document.selectSingleNode(this.element, searchPath);
        }
    },
    InputBox: function(control, parent) {
        this.base = System.Controls.Control;
        this.base(control, parent);
        this.tagName = "input";
        var isRegisterScript = false;
        var onfocus = function() {
            if (this.getAttribute("description") && this.getValue().isEmpty()) {
                this.element.value = "";
                this.element.style.color = "#000000";
            }
            if (this.getAttribute("tooltip")) System.Controls.getToolTip().show(this.getAttribute("tooltip"));
        };
        var onblur = function() {
            if (this.getAttribute("description") && this.getValue().isEmpty()) {
                this.element.value = this.getAttribute("description");
                this.element.style.color = "#ABABAB";
            }
            System.Controls.getToolTip().close();
        };
        this.setValue = function(value) {
            if (!this.create()) return;
            if (this.getAttribute("description")) {
                if (value.isEmpty() || value == this.getAttribute("description")) {
                    this.element.value = this.getAttribute("description");
                    this.element.style.color = "#ABABAB";
                }
                else {
                    this.element.value = value;
                    this.element.style.color = "#000000";
                }
            }
            else {
                this.element.value = value;
            }
        };
        this.getValue = function() {
            if (this.getAttribute("description") && (this.element.value.trim().replaceAll("\r\n", "") == this.getAttribute("description").replaceAll("\n", "") || this.element.value.trim().replaceAll("\r\n", "") == this.getAttribute("description").replaceAll("\r\n", ""))) return "";
            else return this.element.value;
        };
        this.show = this.show.createCallback(function() {
            this.setValue(this.element.value);
            if (!isRegisterScript) {
                System.Event.addEventListener(this.element, "focus", onfocus.createDelegate(this), false);
                System.Event.addEventListener(this.element, "blur", onblur.createDelegate(this), false);
            }
        });
    },
    HyperLink: function(control, parent, sHtml, href, title) {
        this.base = System.Controls.Control;
        this.base(control, parent);
        if (!control) this.tagName = "A";
        if (sHtml != null && sHtml != undefined) this.setInnerHTML(sHtml);
        if (href == null || href == undefined) href = "javascript:void(0)";
        this.setAttribute("href", href);
        if (title != null && title != undefined) this.setAttribute("title", title);

    },
    Image: function(control, parent, src, size, zoom) {
        this.base = System.Controls.Control;
        this.base(control, parent);
        if (!control) this.tagName = "img";
        this.src = src;
        this.size = size;
        this.zoom = (zoom == null || zoom == undefined) ? 1 : zoom; this.show = this.show.createCallback(function(callBack) {
            if (this.zoom == 1) {
                namespace.require("System.Browser");
                var image = new Image();
                var oThis = this;
                var imageLoad = function() {
                    if (oThis.size) {
                        var imageScale = image.width / image.height;
                        var thisScale = oThis.size.width / oThis.size.height;
                        if (imageScale >= thisScale && image.width > oThis.size.width) {
                            oThis.setStyle("width", String(oThis.size.width) + "px");
                            oThis.setStyle("height", String(Math.floor(oThis.size.width / imageScale)) + "px");
                        }
                        else if (imageScale < thisScale && image.height > oThis.size.height) {
                            oThis.setStyle("height", String(oThis.size.height) + "px");
                            oThis.setStyle("width", String(Math.floor(oThis.size.height * imageScale)) + "px");
                        }
                    }
                    oThis.setAttribute("src", oThis.src);
                    if (callBack) callBack();
                }
                if (System.Browser.isIE()) {
                    image.onreadystatechange = function() {
                        if (image.readyState == "complete") imageLoad();
                    }
                }
                else {
                    System.Event.addEventListener(image, "load", imageLoad, false);
                }
                image.src = this.src;
            }
            else {
                if (this.size) {
                    this.setStyle("width", String(this.size.width) + "px");
                    this.setStyle("height", String(this.size.height) + "px");
                }
                this.setAttribute("src", this.src);
                if (callBack) callBack();
            }
        });
    },
    CheckBoxList: function(items) {
        this.items = items || [];
        this.setState = function(checked, index) {
            if (index == null || index == undefined) index = -1;
            for (var i = 0; i < this.items.length; i++) {
                if (i == index || index == -1) this.items[i].checked = checked == true ? true : false;
            }
        };
        this.getValue = function(checked, index) {
            var result = [];
            if (index == null || index == undefined) index = -1;
            for (var i = 0; i < this.items.length; i++) {
                if ((checked == null || checked == undefined || this.items[i].checked == checked) && (index == -1 || index == i))
                    result.push(this.items[i].value);
            }
            return result;
        };
    },
    createCheckBoxList: function(checkItems, checkAll) {
        var checkBoxList = new System.Controls.CheckBoxList(checkItems);
        if (checkAll) {
            var checkItemClick = function(checkItem) {
                checkItem.onclick = function() {
                    var checkLength = checkBoxList.getValue(checkItem.checked).length;
                    if (checkItem.checked == true && checkBoxList.items.length == checkLength) {
                        checkAll.checked = true;
                    }
                    else if (checkItem.checked == false && checkBoxList.items.length != checkLength) {
                        checkAll.checked = false;
                    }
                }
            };
            checkAll.onclick = function() {
                checkBoxList.setState(checkAll.checked);
            };
            for (var i = 0; i < checkItems.length; i++) {
                checkItemClick(checkItems[i]);
            }
        }
        return checkBoxList;
    },
    DropDownList: function(control, parent) {
        this.base = System.Controls.Control;
        this.base(control, parent);
        this.menu = new System.Controls.Menu();
        var initized = false;
        this.show = this.show.createCallback(function(text, items) {
            if (!initized) {
                this.setStyle("backgroundColor", "#ffffcc");
                this.setStyle("backgroundImage", "url({0}/images/arrow.gif)".format(System.getRuntimePath()));
                this.setStyle("backgroundPosition", "90% 50%");
                this.setStyle("backgroundRepeat", "no-repeat");
                this.setStyle("border", "1px solid #7f9db9");
                this.setStyle("color", "#333333");
                this.setStyle("cursor", "pointer");
                this.setStyle("fontSize", "12px");
                this.setStyle("styleFloat", "left");
                this.setStyle("cssFloat", "left");
                this.setStyle("padding", "3px 20px 3px 8px");
                System.Event.addEventListener(this.element, "mouseover", this.showMenu.createDelegate(this), false);
                System.Event.addEventListener(this.element, "mouseout", this.menu.close.createDelegate(this.menu));
                var sSheet = System.Document.getStyleSheet();
                sSheet.addRule(".dropdownListMenu", "text-indent:8px;border:1px solid #7f9db9;width:120px;");
                sSheet.addRule(".dropdownListMenu a", "text-decoration:none");
                sSheet.addRule(".dropdownListMenuItem", "background-color:#ffffff;font-size:12px;height:22px;line-height:22px;color:#2b7ccd");
                sSheet.addRule(".dropdownListMenuItemOver", "background-color:#ffffcc;font-size:12px;height:22px;line-height:22px;color:#2b7ccd");
                this.menu.setCssClass("dropdownListMenu");
                this.menu.defaultCssClass = "dropdownListMenuItem";
                this.menu.selectCssClass = "dropdownListMenuItemOver";
                initized = true;
            }
            if (text) this.setInnerHTML(text, true);
            if (items && items.length > 0) {
                this.menu.clear();
                for (var i = 0; i < items.length; i++)
                    this.menu.addItem(items[i]);
            }
        });
        this.showMenu = function() {
            if (this.menu.items.length == 0) return;
            var thisPos = System.Document.getAbsolutePosition(this.element);
            var thisSize = System.Document.getElementSize(this.element);
            thisPos.top += thisSize.height + 1;
            this.menu.show(thisPos);
        }
    },
    Select: function(control, parent) {
        this.base = System.Controls.Control;
        this.base(control, parent);
        this.tagName = "select";
        this.data = [];
        this.source = "";
        this.textField = "text";
        this.valueField = "value";
        this.databind = function(data) {
            if (data) this.data = data;
            if (!this.create()) return;
            var d = this.source.isEmpty() ? this.data : this.data[this.source];
            if (d && d instanceof Array) {
                this.element.length = 0;
                for (var i = 0; i < d.length; i++) {
                    this.element.add(new Option(d[i][this.textField], d[i][this.valueField]));
                }
            }
        };
        this.getValue = function() {
            if (!this.create()) return;
            return this.element.value;
        };
        this.getDataItem = function(value) {
            var d = this.source.isEmpty() ? this.data : this.data[this.source];
            for (var i = 0; i < d.length; i++) {
                if (d[i][this.valueField] == value)
                    return d[i];
            }
            return null;
        };
        this.setValue = function(value) {
            if (!this.create()) return;
            this.element.value = value;
        };
        this.insert = function(text, value, index) {
            if (!this.create()) return;
            this.element.add(new Option(text, value), index);
        };
        this.clear = function() {
            if (!this.create()) return;
            this.element.length = 0;
        };
    },
    Iframe: function(o, parent) {
        this.base = System.Controls.Control;
        this.base(o, parent);
        this.resizeMode = "none"; if (!o) this.element = "<iframe name=\"FrameControl\" frameborder=\"0\" scrolling=\"no\" onload=\"if(this.frameonload) this.frameonload()\" style=\"padding:0px\"></iframe>";
        this.onload = null; this.frame = null;
        this.editable = false;
        this.window = null;
        var _this = this;
        namespace.require("System.Document");
        this.create = this.create.createCallback(function() {
            if (System.Browser.isIE()) this.frame = document.frames[this.element.id];
            else this.frame = this.element;
            this.window = this.element.contentWindow;
        });
        this.element.frameonload = function() {
            switch (_this.resizeMode) {
                case "autosize":
                    _this.setStyle("width", String(this.contentWindow.document.documentElement.scrollWidth) + "px");
                    _this.setStyle("height", String(this.contentWindow.document.documentElement.scrollHeight) + "px");
                    break;
                case "autozoom":
                    var thisWidth = this.offsetWidth;
                    var thisHeight = this.offsetHeight;
                    var contentWidth = this.contentWindow.document.documentElement.scrollWidth;
                    var contentHeight = this.contentWindow.document.documentElement.scrollHeight;
                    var scaleX = thisWidth / contentWidth;
                    var scaleY = thisHeight / contentHeight;
                    this.contentWindow.document.body.style.zoom = (scaleX < scaleY ? scaleX : scaleY);
                    break;
                default:
                    break;
            }
            if (_this.onload) _this.onload.apply(_this);
        };
        this.show = this.show.createCallback(function(url) {
            if (this.window && url) this.window.location.replace(url);
        });
        this.invokeMethod = function(methodName) {
            var args = [];
            if (arguments.length > 1) {
                for (var i = 1; i < arguments.length; i++)
                    args.push(arguments[i]);
            }
            if (this.frame) {
                try {
                    return this.frame[methodName].apply(this.window, args);
                } catch (e) {
                    return null;
                };
            }
            return null;
        };
    }
});
System.Controls.extend({
    Panel: function(control) {
        this.base = System.Controls.Control;
        this.base();
        this.position = { left: 0, top: 0 };
        this.size = { width: 300, height: 200 };
        this.isFixed = false;
        this.canMove = true;
        this.moveArea = [];
        this.moveHander = null;
        this.anchor = { horizontal: "center", vertical: "center" };
        this.onshow = function() { };
        var state = 0;
        namespace.require("System.Browser");
        this.setStyle("position", "absolute");
        if (System.Browser.isIE()) {
            this.iframe = new System.Controls.Control();
            this.iframe.tagName = "iframe";
            this.iframe.parentNode = this.create();
            this.iframe.setCssText("Z-INDEX: -1; FILTER: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);LEFT: 0px; POSITION: absolute; TOP: 0px;");
            this.iframe.setAttribute("src", "about:blank");
        }
        this.panel = new System.Controls.Control(control);
        this.panel.parentNode = this.create();
        this.show = this.show.createCallback(function(autosize) {
            if (this.onshow) this.onshow();
            if (this.iframe) this.iframe.show();
            this.panel.show();
            if ((this.isFixed || this.canMove) && state == 0) {
                namespace.require("System.Document");
                with (System.Document) {
                    if (this.isFixed) {
                        fixedElement(this.element, this.position, this.anchor, false);
                        state += 1;
                    }
                    if (this.canMove) {
                        dragModule(this.moveHander || this.element, this.element, this.moveArea);
                        state += 2;
                    }
                }
            }
            if (this.position) this.setPosition(this.position);
            if (this.size) this.setSize(this.size);
            if (this.iframe) {
                namespace.require("System.Document");
                var oSize = System.Document.getElementSize(this.panel.element);
                this.iframe.setStyle("width", String(oSize.width) + "px");
                this.iframe.setStyle("height", String(oSize.height) + "px");
            }
        });
        var setStyle = this.setStyle;
        this.setStyle = function(key, value) {
            this.create();
            var name = key.toLower();
            if (name == "alpha" || name.indexOf('padding') >= 0 || name.indexOf('text') >= 0 || name.indexOf('background') >= 0) {
                this.panel.setStyle(key, value);
            }
            else if (name.indexOf('margin') >= 0 || name.indexOf('border') >= 0 || name == "left" || name == "top" || name == "display" || name == "position") {
                this.element.style[key] = value;
            }
            else if (name == "width" || name == "height") {
                this.element.style[key] = value;
                this.panel.setStyle(key, value);
                if (this.iframe) this.iframe.setStyle(key, value);
            }
            else {
                setStyle.apply(this, arguments); ;
                this.panel.setStyle(key, value);
            }
        };
        this.setPosition = function(pos) {
            this.setStyle("left", String(pos.left) + "px");
            this.setStyle("top", String(pos.top) + "px");
        };
        this.setSize = function(size) {
            this.setStyle("width", String(size.width) + "px");
            this.setStyle("height", String(size.height) + "px");
            this.size = size;
        };
        this.setInnerHTML = function(sHtml, override) {
            this.panel.create();
            if (override)
                this.panel.element.innerHTML = sHtml;
            else
                this.panel.element.innerHTML += sHtml;
        };
        this.setInnerText = function(text, override) {
            this.panel.create();
            if (override)
                this.panel.element.innerText = text;
            else
                this.panel.element.innerText += text;
        };
        this.appendChild = function(element) {
            this.panel.create();
            this.panel.element.appendChild(element);
        }
    }
});

System.Controls.extend({
    $TOOLTIPS: [],
    ToolTip: function() {
        this.base = System.Controls.Panel;
        this.base();
        this.isFadeUp = false;
        this.isFadeDown = false;
        this.isFixed = false;
        this.canMove = false;
        this.setStyle("backgroundImage", "url(" + System.getRuntimePath() + "/images/tipbg.gif)");
        this.setStyle("backgroundPosition", "left bottom");
        this.setStyle("backgroundRepeat", "no-repeat");
        this.setStyle("paddingBottom", "4px");
        this.panel.setStyle("display", "block");
        this.panel.setStyle("styleFloat", "left");
        this.template = "<div style=\"word-break:break-all;overflow:hidden;border-left:1px solid #000000;border-right:1px solid #000000;border-top:1px solid #000000;background-color:#ffffcc;font-size:12px;padding:3px;display:block;\">{0}</div>";

        namespace.require("System.Document");
        this.show = this.show.createCallback(function() {
            this.setStyle("width", "");
            this.setStyle("height", "");
            var text = arguments[0];
            var pos = arguments[1];
            if (!pos) pos = System.Document.getRelativePosition(System.Event.getTarget());
            this.setInnerHTML(this.template.format(text), true);
            var esize = System.Document.getElementSize(this.panel.element);
            this.setStyle("width", (esize.width > 500 ? 500 : esize.width) + "px");
            this.setStyle("height", esize.height - 4 + "px");
            this.setStyle("top", pos.top - esize.height + 4 + "px");
            this.setStyle("left", pos.left + "px");
        });
    },
    getToolTip: function(parent) {
        var parent = parent || document.body, toolTip = null;
        for (var i = 0; i < System.Controls.$TOOLTIPS.length; i++) {
            if (parent == System.Controls.$TOOLTIPS[i].parentNode) {
                toolTip = System.Controls.$TOOLTIPS[i];
                break;
            }
        }
        if (toolTip == null) {
            toolTip = new System.Controls.ToolTip();
            toolTip.parentNode = parent;
            System.Controls.$TOOLTIPS.push(toolTip);
        }
        return toolTip;
    }
});


System.Controls.extend({
    Calendar: function(year, month, date) {
        this.base = System.Controls.Panel;
        this.base();
        this.isFadeUp = false;
        this.isFadeDown = false;
        this.isFixed = false;
        this.canMove = false;
        this.selectedDate = new Date(year, month, date);
        this.weekNames = ["日", "一", "二", "三", "四", "五", "六"];
    },
    DateTime: function(o, parent, minValue, maxValue, defaultValue, interval, skinHtml) {
        this.base = System.Controls.Control;
        this.base(o, parent);
        this.tagName = "span";
        this.minValue = minValue || new Date(1900, 0, 1);
        this.maxValue = maxValue || new Date(2050, 0, 1);
        this.interval = ((interval == null || interval == undefined) ? 0 : parseInt(interval, 10));
        this.defaultValue = defaultValue || new Date().addTimes(this.interval);
        this.yearControl = null;
        this.monthControl = null;
        this.dateControl = null;
        this.hourControl = null;
        this.minuteControl = null;
        this.secondControl = null;
        this.onchange = null;
        namespace.require("System.Common");
        namespace.require("System.DateTime");
        this.applySkin = function(sHtml) {
            if (!this.create()) return;
            this.element.innerHTML = sHtml;
            with (System) {
                this.yearControl = new Controls.Select(Document.selectSingleNode(this.element, "//*[@name=year]"));
                this.monthControl = new Controls.Select(Document.selectSingleNode(this.element, "//*[@name=month]"));
                this.dateControl = new Controls.Select(Document.selectSingleNode(this.element, "//*[@name=date]"));
                this.hourControl = new Controls.Select(Document.selectSingleNode(this.element, "//*[@name=hour]"));
                this.minuteControl = new Controls.Select(Document.selectSingleNode(this.element, "//*[@name=minute]"));
                this.secondControl = new Controls.Select(Document.selectSingleNode(this.element, "//*[@name=second]"));
            }
            if (!this.yearControl) return;
            this.yearControl.element.onchange = this.setValue.createDelegate(this);
            if (!this.monthControl) return;
            this.monthControl.element.onchange = this.setValue.createDelegate(this);
            if (!this.dateControl) return;
            this.dateControl.element.onchange = this.setValue.createDelegate(this);
            if (!this.hourControl) return;
            this.hourControl.element.onchange = this.setValue.createDelegate(this);
            if (!this.minuteControl) return;
            this.minuteControl.element.onchange = this.setValue.createDelegate(this);
            if (!this.secondControl) return;
            this.setValue(this.defaultValue);
        };
        this.getValue = function() {
            var datetime = new Date().addTimes(this.interval);
            var _year = datetime.getFullYear(), _month = datetime.getMonth(), _date = datetime.getDate(), _hour = datetime.getHours(), _minute = datetime.getMinutes(), _second = datetime.getSeconds();
            if (this.yearControl && this.yearControl.element.value) _year = parseInt(this.yearControl.element.value, 10);
            if (this.monthControl && this.monthControl.element.value) _month = parseInt(this.monthControl.element.value, 10) - 1;
            if (this.dateControl && this.dateControl.element.value) _date = parseInt(this.dateControl.element.value, 10);
            if (this.hourControl && this.hourControl.element.value) _hour = parseInt(this.hourControl.element.value, 10);
            if (this.minuteControl && this.minuteControl.element.value) _minute = parseInt(this.minuteControl.element.value, 10);
            if (this.secondControl && this.secondControl.element.value) _second = parseInt(this.secondControl.element.value, 10);
            var days = System.DateTime.getDays(_year, _month);
            _date = _date > days ? days : _date;
            return new Date(_year, _month, _date, _hour, _minute, _second);
        };
        this.setValue = function(datetime) {
            datetime = datetime || this.getValue();
            if (datetime < this.minValue) datetime = this.minValue;
            if (datetime > this.maxValue) datetime = this.maxValue;
            this.setYear(datetime);
            this.setMonth(datetime);
            this.setDate(datetime);
            this.setHours(datetime);
            this.setMinutes(datetime);
            this.setSeconds(datetime);
            if (this.onchange) this.onchange.apply(this);
        };
        this.setYear = function(datetime) {
            if (!this.yearControl) return;
            this.yearControl.data = System.Common.createOrderData(this.minValue.getFullYear(), this.maxValue.getFullYear());
            this.yearControl.databind();
            this.yearControl.setValue((datetime || new Date()).getFullYear());
        };
        this.setMonth = function(datetime) {
            if (!this.monthControl) return;
            var startMonth = 1;
            var endMonth = 12;
            if (datetime.getFullYear() <= this.minValue.getFullYear())
                startMonth = this.minValue.getMonth() + 1;
            if (datetime.getFullYear() >= this.maxValue.getFullYear())
                endMonth = this.maxValue.getMonth() + 1;
            this.monthControl.data = System.Common.createOrderData(startMonth, endMonth);
            this.monthControl.databind();
            this.monthControl.setValue(datetime.getMonth() + 1);
        };
        this.setDate = function(datetime) {
            if (!this.dateControl) return;
            var startDate = 1;
            var endDate = System.DateTime.getDays(datetime.getFullYear(), datetime.getMonth());
            if (datetime.getFullYear() <= this.minValue.getFullYear() && datetime.getMonth() <= this.minValue.getMonth())
                startDate = this.minValue.getDate();
            if (datetime.getFullYear() >= this.maxValue.getFullYear() && datetime.getMonth() >= this.maxValue.getMonth())
                endDate = this.maxValue.getDate();
            this.dateControl.data = System.Common.createOrderData(startDate, endDate);
            this.dateControl.databind();
            this.dateControl.setValue(datetime.getDate());
        };
        this.setHours = function(datetime) {
            if (!this.hourControl) return;
            var startHour = 0;
            var endHour = 23;
            if (datetime.getFullYear() <= this.minValue.getFullYear() && datetime.getMonth() <= this.minValue.getMonth() && datetime.getDate() <= this.minValue.getDate())
                startHour = this.minValue.getHours();
            if (datetime.getFullYear() >= this.maxValue.getFullYear() && datetime.getMonth() >= this.maxValue.getMonth() && datetime.getDate() >= this.maxValue.getDate())
                endHour = this.maxValue.getHours();
            this.hourControl.data = System.Common.createOrderData(startHour, endHour);
            this.hourControl.databind();
            this.hourControl.setValue(datetime.getHours());
        };
        this.setMinutes = function(datetime) {
            if (!this.minuteControl) return;
            var startMinute = 0;
            var endMinute = 59;
            if (datetime.getFullYear() <= this.minValue.getFullYear() && datetime.getMonth() <= this.minValue.getMonth() && datetime.getDate() <= this.minValue.getDate() && datetime.getHours() <= this.minValue.getHours())
                startMinute = this.minValue.getMinutes();
            if (datetime.getFullYear() >= this.maxValue.getFullYear() && datetime.getMonth() >= this.maxValue.getMonth() && datetime.getDate() >= this.maxValue.getDate() && datetime.getHours() >= this.maxValue.getHours())
                endMinute = this.maxValue.getMinutes();
            this.minuteControl.data = System.Common.createOrderData(startMinute, endMinute);
            this.minuteControl.databind();
            this.minuteControl.setValue(datetime.getMinutes());
        };
        this.setSeconds = function(datetime) {
            if (!this.secondControl) return;
            var startSecond = 0;
            var endSecond = 59;
            if (datetime.getFullYear() <= this.minValue.getFullYear() && datetime.getMonth() <= this.minValue.getMonth() && datetime.getDate() <= this.minValue.getDate() && datetime.getHours() <= this.minValue.getHours() && datetime.getMinutes() <= this.minValue.getMinutes())
                startSecond = this.minValue.getMinutes();
            if (datetime.getFullYear() >= this.maxValue.getFullYear() && datetime.getMonth() >= this.maxValue.getMonth() && datetime.getDate() >= this.maxValue.getDate() && datetime.getHours() >= this.maxValue.getHours() && datetime.getMinutes() >= this.maxValue.getMinutes())
                endSecond = this.maxValue.getMinutes();
            this.secondControl.data = System.Common.createOrderData(startSecond, endSecond);
            this.secondControl.databind();
            this.secondControl.setValue(datetime.getSeconds());
        };
        this.applySkin(skinHtml || "<select name=\"year\"></select>年<select name=\"month\"></select>月<select name=\"date\"></select>日<select name=\"hour\"></select>时<select name=\"minute\"></select>分<select name=\"second\"></select>秒");
    }
});

System.Controls.extend({
    $WINDOWBASE: {},
    WindowBase: function(windowSkin) {
        namespace.require("System.Document");
        this.base = System.Controls.Control;
        this.base();
        this.floatPanel = new System.Controls.Panel();
        this.floatPanel.canMove = false;
        this.floatPanel.show();
        this.floatPanel.close();
        this.floatPanel.size = System.Document.getVisibleDocumentSize();
        this.moveArea = {}.extend({ top: 0, left: 0 }).extend(System.Document.getVisibleDocumentSize());
        this.size = { width: 300, height: 200 };
        this.windowHeader = null;
        this.windowTitle = null;
        this.windowBody = null;
        this.windowFooter = null;
        this.windowContent = null;
        this.windowStatus = null;
        this.buttonClose = null;
        this.isDrag = false;
        this.isInitEvent = false;
        this.applySkin = function(sHtml) {
            if (!this.create()) return;
            this.element.innerHTML = sHtml;
            with (System) {
                this.windowHeader = new Controls.Control(Document.selectSingleNode(this.element, "//*[@name=windowHeader]"));
                this.windowBody = new Controls.Control(Document.selectSingleNode(this.element, "//*[@name=windowBody]"));
                this.windowFooter = new Controls.Control(Document.selectSingleNode(this.element, "//*[@name=windowFooter]"));
                this.windowTitle = new Controls.Control(Document.selectSingleNode(this.element, "//*[@name=windowTitle]"));
                this.windowContent = new Controls.Control(Document.selectSingleNode(this.element, "//*[@name=windowContent]"));
                this.windowStatus = new Controls.Control(Document.selectSingleNode(this.element, "//*[@name=windowStatus]"));
                this.buttonClose = new Controls.Control(Document.selectSingleNode(this.element, "//*[@name=buttonClose]"));
            }
            this.moveHander = this.windowHeader.element;
            if (this.buttonClose.create()) System.Event.addEventListener(this.buttonClose.element, "click", this.close.createDelegate(this), false);
            this.setDrag(true);
        };
        this.setDrag = function(enable) {
            if (this.moveHander) {
                if (enable && !this.isDrag) {
                    System.Document.dragModule(this.moveHander || this.element, this.element, this.moveArea);
                }
            }
        };
        this.setTitle = function(sTitle) {
            if (this.windowTitle.create())
                this.windowTitle.element.innerHTML = sTitle;
        };
        this.setInnerHTML = function(sHtml) {
            if (this.windowContent.create()) {
                this.windowContent.element.innerHTML = sHtml;
                this.resize();
            }
        };
        this.appendChild = function(htmlNode) {
            if (this.windowContent.create() && typeof (htmlNode) == "object")
                this.windowContent.element.appendChild(htmlNode);
        };
        this.resize = function() {
            var winsize = System.Document.getElementSize(this.element);
            var panelSize = System.Document.getElementSize(this.floatPanel.element);
            var visibleArea = System.Document.getVisibleArea();
            this.setPosition({ left: visibleArea.left + Math.floor((visibleArea.width - winsize.width) / 2), top: visibleArea.top + Math.floor((visibleArea.height - winsize.height) / 2) });
            this.floatPanel.setPosition({ left: visibleArea.left + Math.floor((visibleArea.width - panelSize.width) / 2), top: visibleArea.top + Math.floor((visibleArea.height - panelSize.height) / 2) });
            var headerSize = { width: 0, height: 0 }, footerSize = { width: 0, height: 0 };
            if (this.windowHeader.create()) headerSize = System.Document.getElementSize(this.windowHeader.element);
            if (this.windowFooter.create()) footerSize = System.Document.getElementSize(this.windowFooter.element);
            if (this.windowBody.create() && this.windowContent.create()) {
                var bodySize = System.Document.getElementSize(this.windowBody.element);
                if (this.windowContent.element.parentNode) {
                    var parentSize = System.Document.getElementSize(this.windowContent.element.parentNode);
                    this.windowContent.setStyle("height", String(this.size.height - headerSize.height - footerSize.height - bodySize.height + parentSize.height) + "px");
                }
            }
        };
        this.show = this.show.createCallback(function(sHtml, sTitle) {
            if (sHtml) this.setInnerHTML(sHtml);
            if (sTitle) this.setTitle(sTitle);
            if (this.size) this.setSize(this.size);
            if (!this.isInitEvent) {
                this.timer = window.setInterval(function() {
                    var winsize = System.Document.getElementSize(this.element);
                    var panelSize = System.Document.getElementSize(this.floatPanel.element);
                    var visibleArea = System.Document.getVisibleArea();
                    this.setPosition({ left: visibleArea.left + Math.floor((visibleArea.width - winsize.width) / 2), top: visibleArea.top + Math.floor((visibleArea.height - winsize.height) / 2) });
                    this.floatPanel.setPosition({ left: visibleArea.left + Math.floor((visibleArea.width - panelSize.width) / 2), top: visibleArea.top + Math.floor((visibleArea.height - panelSize.height) / 2) });
                } .createDelegate(this), 20);
            }
            this.floatPanel.show();
            this.resize();
        });
        this.close = this.close.createCallback(function() {
            this.floatPanel.close();
        });
        this.setPosition = function(pos) {
            this.setStyle("left", String(pos.left) + "px");
            this.setStyle("top", String(pos.top) + "px");
        };
        this.setSize = function(size) {
            this.setStyle("width", String(size.width) + "px");
            this.setStyle("height", String(size.height) + "px");
        };
        this.setStyle = function(name, value) {
            this.create();
            if (name.toLower().indexOf('overflow') >= 0 && this.windowContent)
                this.windowContent.setStyle(name, value);
            else
                this.element.style[name] = value;
        };
        this.applySkin(windowSkin || "<table name=\"windowHeader\" style=\"width: 100%; font-size: 12px;\" cellspacing=\"0\"cellspadding=\"0\" border=\"0\"><tbody><tr><td class=\"windowHeaderLeft\"></td><td class=\"windowHeaderCaption\"><table style=\"height: 100%; width: 100%\"><tbody><tr><td class=\"windowHeaderCaptionImage\" name=\"windowTitle\"></td></tr></tbody></table></td><td class=\"windowHeaderButtons\" align=\"right\"><a name=\"buttonClose\" href=\"javascript:void(0)\"><font style=\"color:#ffffff;text-decoration:none\">[关闭]</font></a></td><td class=\"windowHeaderRight\"></td></tr></tbody></table><table name=\"windowBody\" style=\"width: 100%; height: 150px;\" cellspacing=\"0\" cellspadding=\"0\"border=\"0\"><tbody><tr><td class=\"windowContentLeft\"></td><td class=\"windowContentCenter\" valign=\"top\"><div name=\"windowContent\" style=\"width:100%;\"></div></td><td class=\"windowContentRight\"></td></tr></tbody></table><table name=\"windowFooter\" style=\"width: 100%; height: 25px;\" cellspacing=\"0\" cellspadding=\"0\"border=\"0\"><tbody><tr><td class=\"windowContentLeft\"></td><td class=\"windowContentCenter\" name=\"windowStatus\"></td><td class=\"windowContentRight\"></td></tr><tr style=\"height:5px\"><td class=\"windowBottomLeft\"></td><td class=\"windowBottomCenter\"></td><td class=\"windowBottomRight\"></td></tr></tbody></table>");
        this.setStyle("position", "absolute");
    },
    getWindowBase: function(windowName) {
        windowName = windowName || "default";
        if (!this.$WINDOWBASE[windowName]) this.$WINDOWBASE[windowName] = new this.WindowBase();
        return this.$WINDOWBASE[windowName];
    }
});
System.Controls.extend({
    $DIALOGBOX: {},
    DialogBox: function(dialogSkin, windowSkin) {
        this.base = System.Controls.Control;
        this.base();
        this.window = new System.Controls.WindowBase(windowSkin);
        this.parentNode = this.window.windowContent.create();
        this.controlMessage = null;
        this.buttonSure = null;
        this.buttonCancel = null;
        this.size = { width: 300, height: 200 };
        this.onsure = null;
        this.oncancel = null;
        this.show = this.show.createCallback(function(message, title) {
            if (message != null && message != undefined) this.setMessage(message);
            if (title != null && message != undefined) this.setTitle(title);
            this.resize();
            this.window.size = this.size;
            this.window.show();

        });
        this.resize = function() {
            var thisSize = System.Document.getElementSize(this.element);
            this.window.windowContent.setStyle("height", String(thisSize.height) + "px");
        };
        this.close = this.close.createCallback(function() {
            this.window.close();
        });
        this.sure = function() {
            if (this.onsure) this.onsure(this);
            this.close();
        };
        this.cancel = function() {
            if (this.oncancel) this.oncancel(this);
            this.close();
        };
        this.setMessage = function(message) {
            if (this.controlMessage.create())
                this.controlMessage.element.innerHTML = message;
        };
        this.setTitle = function(title) {
            this.window.setTitle(title);
        };
        this.applySkin = function(sHtml) {
            this.element = sHtml;
            this.create();
            with (System) {
                this.controlMessage = new System.Controls.Control(Document.selectSingleNode(this.parentNode, "//*[@name=controlMessage]"));
                this.buttonSure = new System.Controls.Control(Document.selectSingleNode(this.parentNode, "//*[@name=buttonSure]"));
                this.buttonCancel = new System.Controls.Control(Document.selectSingleNode(this.parentNode, "//*[@name=buttonCancel]"));
                if (this.buttonSure.create()) System.Event.addEventListener(this.buttonSure.element, "click", this.sure.createDelegate(this), false);
                if (this.buttonCancel.create()) System.Event.addEventListener(this.buttonCancel.element, "click", this.cancel.createDelegate(this), false);
            }
        };
        this.applySkin(dialogSkin || "<table style=\"width:100%;height:100%;\" border=\"0\"><tr><td name=\"controlMessage\" style=\"font-size:12px;padding:10px\" valign=\"top\"></td></tr><tr><td style=\"height:25px;text-align:center\"><input class=\"windowInputButton\" name=\"buttonSure\" type=\"button\" value=\"确定\" />  <input class=\"windowInputButton\" name=\"buttonCancel\" type=\"button\" value=\"取消\" /></td></tr></table>");
        this.window.windowFooter.setStyle("height", "13px");
    },
    getDialogBox: function(dialogBoxName) {
        dialogBoxName = dialogBoxName || "default";
        if (!this.$DIALOGBOX[dialogBoxName]) this.$DIALOGBOX[dialogBoxName] = new this.DialogBox();
        return this.$DIALOGBOX[dialogBoxName];
    }
});


System.Controls.extend({
    $PROGRESS: [],
    Progress: function() {
        this.base = System.Controls.Control;
        this.base();
        this.progress = 0;
        this.description = "";
        this.title = "";
        this.window = new System.Controls.WindowBase();
        this.window.size = { width: 350, height: 200 };
        this.parentNode = this.window.windowContent.create();
        this.controlDescription = null;
        this.controlProgressBar = null;
        this.controlProgress = null;
        this.show = this.show.createCallback(function(progress, title, description) {
            this.setProgress(progress || this.progress);
            this.setTitle(title || this.title);
            this.setDescription(description || this.description);
            this.window.show();
        });
        this.setTitle = function(title) {
            this.window.setTitle(title);
        };
        this.setProgress = function(progress) {
            this.controlProgressBar.setStyle("width", String(progress) + "%");
            this.controlProgress.setInnerHTML(String(progress) + "%", true);
        };
        this.setDescription = function(description) {
            this.controlDescription.setInnerHTML(description, true);
        };
        this.close = this.close.createCallback(function() {
            this.window.close();
        });
        this.applySkin = function(sHtml) {
            this.element = sHtml;
            this.create();
            with (System) {
                this.controlDescription = new Controls.Control(Document.selectSingleNode(this.parentNode, "//*[@name=controlDescription]"));
                this.controlProgressBar = new Controls.Control(Document.selectSingleNode(this.parentNode, "//*[@name=controlProgressBar]"));
                this.controlProgress = new Controls.Control(Document.selectSingleNode(this.parentNode, "//*[@name=controlProgress]"));
            }
        };
        this.applySkin("<div style=\"display: block;text-align:center\"><table width=\"95%\"><tbody><tr><td name=\"controlDescription\" style=\"height:70px;text-align:left\"></td></tr><tr><td><div style=\"text-align:left;border: #008800 1px solid; height: 1.5em;overflow:hidden\"><div name=\"controlProgressBar\" style=\"width: 0%; height: 1.5em; background-color: #00ee00\"></div><div style=\"position: relative; top: -1.35em; text-align: center\" name=\"controlProgress\">0 %</div></div></td></tr></tbody></table></div>");
    },
    getProgress: function(progressName) {
        progressName = progressName || "default";
        if (!this.$PROGRESS[progressName]) this.$PROGRESS[progressName] = new this.Progress();
        return this.$PROGRESS[progressName];
    }
});

System.Controls.extend({
    $FILEUPLOADID: 0,
    FileUpload: function(object, parent) {

        this.progress = System.Controls.getProgress("FileUpload");
        this.uploadId = System.newGuid();
        this.getProgressUrl = "FileUpload/UploadProgress.ashx?RequestID={0}";
        this.timer = 0;
        this.description = "共{0}个文件,{1}<br />{2}/秒<br />剩余{3}";
        this.oncomplete = null;
        this.upload = function(form, target) {
            if (!this.visible) this.show();
            if (target) form.target = target;
            form.action = form.action + (form.action.indexOf("?") > 0 ? "&" : "?") + "IsAjaxUpload=true&RequestID={0}".format(this.uploadId);
            form.submit();
            this.progress.progress = 0;
            this.progress.title = "文件上传0%";
            this.progress.description = "正在初始化...";
            this.progress.show();
            this.timer = window.setTimeout(this.getProgress.createDelegate(this), 10);
        };
        this.complete = function(result) {
            if (this.oncomplete)
                this.oncomplete(result);
        }
        this.getProgress = function() {
            var xmlHttp = new System.XMLHttpRequest();
            xmlHttp.send(this.getProgressUrl.format(this.uploadId), "get", null, [], function(request) {
                var result = request.responseText.parseJSON();
                if (result == null && this.progress.progress == 0) {
                    window.setTimeout(this.getProgress.createDelegate(this), 10);
                    return;
                }
                else if (result != null) {
                    var timeOut = result.NowTime - result.StartTime;
                    var speed = System.Common.formatFileSize(result.BytesRead / timeOut * 1000);
                    var remain = System.Common.formatTime((result.ContentLength - result.BytesRead) / (result.BytesRead / timeOut * 1000));
                    this.progress.progress = (Number(result.BytesRead * 100 / result.ContentLength).toFixed(2));
                    this.progress.description = this.description.format(1, System.Common.formatFileSize(result.ContentLength), speed, remain);
                }
                if (result == null || result.BytesRead == result.ContentLength) {
                    this.progress.title = "上传完成";
                    this.complete(result);
                    window.setTimeout(this.progress.close.createDelegate(this.progress), 1000);
                }
                else {
                    this.progress.title = "文件上传{0}%".format(this.progress.progress);
                    window.setTimeout(this.getProgress.createDelegate(this), 10);
                }
                this.progress.show();
            } .createDelegate(this));
        };
        this.show = function() {
        };
    }
});

System.Controls.extend({
    ObjectControl: function() {
        namespace.require("System.Browser");
        this.params = {};
        this.attributes = {};
        this.controlType = System.Browser.isIE() ? "ActiveX" : "PlugIn";
        this.onshow = null;
        this.type = "";
        this.pluginspage = "";
        this.classid = "";
        this.codebase = "";
        this.show = function(container, override) {
            if (this.onshow) this.onshow();
            if (typeof (container) == "string") container = document.getElementById(container);
            if (override) container.innerHTML = this.create();
            else container.innerHTML += this.create();
        };
        this.write = function() {
            document.write(this.create());
        };
        this.create = function() {
            var sHtml = "";
            if (this.controlType == "PlugIn") sHtml += " <embed pluginspage=\"{0}\" type=\"{1}\" ".format(this.type, this.pluginspage);
            else sHtml += "<object classid=\"{0}\" codebase=\"{1}\"".format(this.classid, this.codebase);
            if (this.getAttribute("id") == "") {
                this.setAttribute("id", System.newGuid("N"));
            }
            for (var a in this.attributes) {
                if (typeof (this.attributes[a]) != "object" && typeof (this.attributes[a]) != "function")
                    sHtml += " {0}=\"{1}\" ".format(a, this.attributes[a]);
            }
            if (this.controlType == "ActiveX") sHtml += " > ";
            for (var p in this.params) {
                if (typeof (this.params[p]) != "object" && typeof (this.params[p]) != "function") {
                    if (this.controlType == "PlugIn") sHtml += " {0}=\"{1}\" ".format(p, this.params[p]);
                    else sHtml += "<param name=\"{0}\" value=\"{1}\" />".format(p, this.params[p]);
                }
            }
            if (this.controlType == "PlugIn") sHtml += "/>";
            else sHtml += "</object>";
            return sHtml;
        };
        this.setAttribute = function(name, value) {
            this.attributes[name] = value;
        };
        this.getAttribute = function(name) {
            if (this.attributes[name] != null && this.attributes[name] != "undefined")
                return this.attributes[name];
            return "";
        };
        this.setParameter = function(name, value) {
            this.params[name] = value;
        };
        this.getParameter = function(name) {
            return this.params[name];
        };
    },
    FlashPlayer: function(src, width, height) {
        this.base = System.Controls.ObjectControl;
        this.base();
        this.variables = {};
        this.type = "application/x-shockwave-flash";
        this.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
        this.codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0";
        this.pluginspage = "http://www.macromedia.com/go/getflashplayer";
        var _create = this.create;
        this.create = function() {
            var vars = [];
            for (var v in this.variables) {
                if (typeof (this.variables[v]) == "string")
                    vars.push("{0}={1}".format(v, this.variables[v]));
            }
            this.setAttribute("FlashVars", vars.join("&"));
            this.setParameter("FlashVars", vars.join("&"));
            return _create.apply(this);
        };
        this.setVariable = function(name, value) {
            this.variables[name] = value;
        };
        this.getVariable = function(name) {
            return this.variables[name];
        };
        if (width) this.setAttribute("width", width);
        if (height) this.setAttribute("height", height);
        if (src) this.setParameter("src", src);
        this.setParameter("quality", "high");
    },
    MediaPlayer: function(fileName) {
        this.base = System.Controls.ObjectControl;
        this.base();
        this.autoRewind = true;
        this.showControls = true;
        this.loop = true;
        this.showPositionControls = false;
        this.showAudioControls = true;
        this.showTracker = true;
        this.showDisplay = false;
        this.showStatusBar = true;
        this.showGotoBar = false;
        this.showCaptioning = false;
        this.autoStart = true;
        this.volume = -1;
        this.animationAtStart = false;
        this.transparentAtStart = false;
        this.allowChangeDisplaySize = false;
        this.allowScan = false;
        this.enableContextMenu = false;
        this.clickToPlay = false;
        this.codebase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715";
        this.classid = "CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95";
        this.type = "application/x-oleobject";
        var _create = this.create;
        this.create = function() {
            this.setParameter("AutoRewind", this.autoRewind ? "1" : "0");
            this.setParameter("ShowControls", this.showControls ? "1" : "0");
            this.setParameter("loop", this.loop ? "1" : "0");
            this.setParameter("ShowPositionControls", this.showPositionControls ? "1" : "0");
            this.setParameter("ShowAudioControls", this.showAudioControls ? "1" : "0");
            this.setParameter("ShowTracker", this.showTracker ? "1" : "0");
            this.setParameter("ShowDisplay", this.showDisplay ? "1" : "0");
            this.setParameter("ShowStatusBar", this.showStatusBar ? "1" : "0");
            this.setParameter("ShowGotoBar", this.showGotoBar ? "1" : "0");
            this.setParameter("ShowCaptioning", this.showCaptioning ? "1" : "0");
            this.setParameter("AutoStart", this.autoStart ? "1" : "0");
            this.setParameter("Volume", String(this.volume));
            this.setParameter("AnimationAtStart", this.animationAtStart ? "1" : "0");
            this.setParameter("TransparentAtStart", this.transparentAtStart ? "1" : "0");
            this.setParameter("AllowChangeDisplaySize", this.allowChangeDisplaySize ? "1" : "0");
            this.setParameter("AllowScan", this.allowScan ? "1" : "0");
            this.setParameter("EnableContextMenu", this.enableContextMenu ? "1" : "0");
            this.setParameter("ClickToPlay", this.clickToPlay ? "1" : "0");
            return _create.apply(this);
        };
        if (fileName) this.setParameter("fileName", fileName);
        this.setAttribute("hspace", "1");
        this.setAttribute("height", "68");
    },
    RealPlayer: function(fileName) {
        this.base = System.Controls.ObjectControl;
        this.base();
        this.autoStart = true;
        this.backGroundColor = null;
        this.center = false;
        this.classid = "clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA";
        var _create = this.create;
        this.create = function() {
            return _create.apply(this);
        }
        if (fileName) this.setParameter("src", fileName);
    }
});


System.Controls.extend({
    Wizard: function() {
        this.steps = []; this.activeStepIndex = 0; this.onshow = null;
        this.show = function(stepIndex) {
            if (stepIndex == null || stepIndex == undefined) stepIndex = this.activeStepIndex;
            else stepIndex = parseInt(stepIndex, 10);
            if (stepIndex < 0 || stepIndex >= this.steps.length) stepIndex = this.activeStepIndex;
            for (var i = 0; i < this.steps.length; i++) {
                if (!this.steps[i] || !this.steps[i].style) continue;
                this.steps[i].style.display = (i == stepIndex) ? "" : "none";
            }
            this.activeStepIndex = stepIndex;
            if (this.onshow) this.onshow.applay(this);
        };
        for (var i = 0; i < arguments.length; i++) {
            if (!arguments[i]) this.steps.push(null);
            else if (typeof (arguments[i]) == "string") this.steps.push(document.getElementById(arguments[i]));
            else this.steps.push(arguments[i]);
        }
        this.show(0);
    },
    Marquee: function(control, parent) {
        this.base = System.Controls.Control;
        this.base(control, parent);
        this.direction = "auto"; this.timer = null;
        this.delay = 30; this.amount = 1; this.contentSize = { width: 0, height: 0 };
        this.contentControl = null;
        this.onscroll = null;
        this.show = this.show.createCallback(function(content) {
            this.setStyle("overflow", "hidden");
            if (content) {
                this.setInnerHTML("", true);
                this.contentControl = null;
                if (typeof (content) == "object") this.element.appendChild(content);
                else this.setInnerHTML(String(content), true);
            }
            var firstChild = null;
            for (var i = 0; i < this.element.childNodes.length; i++) {
                if (this.element.childNodes[i].nodeType == 1) {
                    firstChild = this.element.childNodes[i];
                    break;
                }
            }
            if (!firstChild) return;
            namespace.require("System.Document");
            var thisSize = System.Document.getElementSize(this.element);
            this.contentSize = System.Document.getElementSize(firstChild);
            if (!this.contentControl) {
                var sHtml = firstChild.outerHTML;
                this.setInnerHTML("", true);
                this.contentControl = new System.Controls.Control();
                this.contentControl.parentNode = this.element;
                this.contentControl.show();
                this.contentControl.setInnerHTML(sHtml, true);
                System.Event.addEventListener(this.contentControl.element, "mouseover", this.stop.createDelegate(this));
                System.Event.addEventListener(this.contentControl.element, "mouseout", this.start.createDelegate(this));
            }
            if (this.direction == "auto") {
                if (thisSize.width < this.contentSize.width) this.direction = "left";
                else if (thisSize.height < this.contentSize.height) this.direction = "up";
            }
            switch (this.direction) {
                default:
                case "left":
                case "right":
                    this.contentControl.setStyle("whiteSpace", "nowrap");
                    this.contentControl.setStyle("width", String(this.contentSize.width * 2 + 10) + "px");
                    this.contentControl.element.firstChild.style.styleFloat = "left";
                    this.contentControl.element.firstChild.style.display = "block";
                    if (thisSize.width < this.contentSize.width) {
                        this.contentControl.setInnerHTML(this.contentControl.element.innerHTML);
                    }
                    break;
                case "up":
                case "down":
                    this.contentControl.setStyle("width", String(this.contentSize.width) + "px");
                    this.contentControl.element.firstChild.style.styleFloat = "none";
                    this.contentControl.element.firstChild.style.display = "block";
                    if (thisSize.height < this.contentSize.height) {
                        this.contentControl.setInnerHTML(this.contentControl.element.innerHTML);
                    }
                    break;
            }
            this.start();
        });
        this.scroll = function() {
            switch (this.direction) {
                default:
                case "left":
                    if (this.contentSize.width - this.element.scrollLeft <= 0)
                        this.element.scrollLeft -= this.contentSize.width;
                    else
                        this.element.scrollLeft += this.amount;
                    break;
                case "right":
                    if (this.element.scrollLeft == 0)
                        this.element.scrollLeft = this.contentSize.width;
                    else
                        this.element.scrollLeft -= this.amount;
                    break;
                case "up":
                    if (this.contentSize.height - this.element.scrollTop <= 0)
                        this.element.scrollTop -= this.contentSize.height;
                    else
                        this.element.scrollTop += this.amount;
                    break;
                case "down":
                    if (this.element.scrollTop == 0)
                        this.element.scrollTop = this.contentSize.height;
                    else
                        this.element.scrollTop -= this.amount;
                    break;
            }
            if (this.onscroll) this.onscroll();
        };
        this.start = function() {
            if (!this.timer) this.timer = window.setInterval(this.scroll.createDelegate(this), this.delay);
        };
        this.stop = function() {
            if (this.timer) window.clearInterval(this.timer);
            this.timer = null;
        };
    }
});
System.Controls.extend({
    HtmlEditor: function(editorFrame) {
        this.base = System.Controls.Control;
        this.base(editorFrame);
        this.document = null;
        this.window = null;
        this.create = this.create.createCallback(function() {
            this.window = this.element.contentWindow;
            this.document = this.element.contentWindow.document;

            this.setEditable(true);

        });
        this.setEditable = function(enable) {
            this.document.designMode = enable == false ? "Off" : "On";
            this.document.contentEditable = enable == false ? false : true;
            if (!System.Browser.isIE()) this.document.execCommand("useCSS", false, true);
        };
        this.setValue = function(value, override) {
            if (override == false)
                this.document.body.innerHTML = value;
            else
                this.document.body.innerHTML += value;
        };
        this.getValue = function() {
            return this.document.body.innerHTML;
        };
        this.getSelectedText = function() {
            if (this.document.selection && this.document.selection.type == "Text")
                return this.document.selection.createRange().text;
            else if (this.window.getSelection)
                return this.window.getSelection();
            else
                return "";
        };
        this.setSelectedText = function(text, markup) {
            if (this.document.selection && this.document.selection.type == "Text") {
                var range = this.document.selection.createRange();
                range.pasteHTML(markup.format(range.htmlText));
            }
            else if (this.window.getSelection) {
            }
        };
        this.insertImage = function(imageUrl) {
            this.document.execCommand("InsertImage", false, imageUrl);
        };
        this.setFontName = function(fontName) {
            this.document.execCommand("FontName", false, fontName);
        };
        this.setFontSize = function(fontSize) {
            this.document.execCommand("FontSize", false, fontSize);
        };
        this.createLink = function(link) {
            this.document.execCommand("CreateLink", false, link);
        };
        this.setForeColor = function(color) {
            this.document.execCommand("ForeColor", false, color);
        };
        this.clear = function() {
            this.document.body.innerHTML = "";
        };
    }
});

System.Controls.extend({
    Slider: function(control, parent) {
        this.base = System.Controls.Control;
        this.base(control, parent);
        this.value = 0;
        this.minValue = 0;
        this.maxValue = 100;
        this.direction = "horizontal"; this.size = { width: 100, height: 20 };
        this.status = 0; this.slider = null;
        this.bar = null;
        this.onchange = null;
        namespace.require("System.Document");
        namespace.require("System.Event");
        var rPos = { left: 0, right: 0 };
        this.create = this.create.createCallback(function() {
            if (!this.slider) {
                this.slider = new System.Controls.Control();
                this.slider.parentNode = this.element;
                this.slider.setStyle("position", "absolute");
                System.Event.addEventListener(this.slider.element, "click", this.click.createDelegate(this), false);
            }
            if (!this.bar) {
                this.bar = new System.Controls.Control();
                this.bar.parentNode = this.element;
                this.bar.setStyle("position", "absolute");
                this.bar.setStyle("display", "block");
                System.Event.addEventListener(this.bar.element, "mousedown", this.start.createDelegate(this), false);
                System.Event.addEventListener(document, "mousemove", this.change.createDelegate(this), false);
                System.Event.addEventListener(document, "mouseup", this.end.createDelegate(this), false);
            }
        });
        this.show = this.show.createCallback(function() {
            this.setStyle("width", this.size.width + "px");
            this.setStyle("height", this.size.height + "px");
            this.slider.setStyle("width", this.size.width + "px");
            this.slider.setStyle("height", this.size.height + "px");
            this.slider.show();
            this.bar.show();

        });
        this.start = function() {
            this.status = 1;
            var bPos = System.Document.getAbsolutePosition(this.bar.element);
            var ePos = System.Event.getEventPos();
            rPos.left = bPos.left - ePos.left;
            rPos.top = bPos.top - ePos.top;
            System.Document.disableSelect();
        };
        this.change = function(enable) {
            if (enable == true || this.status == 1) {
                var tPos = System.Document.getAbsolutePosition(this.element);
                var ePos = System.Event.getEventPos();
                var tSize = System.Document.getElementSize(this.slider.element);
                var bSize = System.Document.getElementSize(this.bar.element);
                if (this.direction == "horizontal") {
                    var width = tSize.width - bSize.width;
                    var unit = width / (this.maxValue - this.minValue);
                    var left = ePos.left - tPos.left + rPos.left;
                    if (left < 0) left = 0;
                    if (left > width) left = width;
                    this.value = this.minValue + Math.ceil(left / unit);
                    if (this.value > this.maxValue) this.value = this.maxValue;
                    this.bar.setStyle("left", left + tPos.left + "px");
                }
                else {
                }
                if (this.onchange) this.onchange.apply(this);
            }
        };
        this.click = function() {
            this.change(true);
        };
        this.end = function() {
            this.status = 0;
            System.Document.enableSelect();
        };
        this.setValue = function(value) {
            var tPos = System.Document.getAbsolutePosition(this.element);
            var tSize = System.Document.getElementSize(this.element);
            var bSize = System.Document.getElementSize(this.bar.element);
            this.value = value;
            if (this.value > this.maxValue) this.value = this.maxValue;
            if (this.direction == "horizontal") {
                var width = tSize.width - bSize.width;
                var unit = width / (this.maxValue - this.minValue);
                this.bar.setStyle("left", (this.value - this.minValue) * unit + tPos.left + "px");
            }
        };
        this.getValue = function() {
            return this.value;
        };
    }
});

System.Controls.extend({
    Menu: function() {
        this.base = System.Controls.Panel;
        this.base();
        this.items = []; this.position = null;
        this.size = null;
        this.canMove = false;
        this.autoHidden = true;
        this.parent = null;
        this.defaultCssClass = null;
        this.selectCssClass = null;
        this.getArea = null;
        this.isMouseAbove = false;
        this.showPosition = "right";
        this.elementClick = false;
        this.show = this.show.createCallback(function(pos, area) {
            this.setStyle("position", "absolute");
            if (pos) {
                if (this.parent) {
                    var area = area || System.Document.getVisibleArea();
                    var mSize = System.Document.getElementSize(this.element);
                    var iSize = System.Document.getElementSize(this.parent.element);
                    if (pos.left + mSize.width > area.width + area.left || (this.parent.menu && this.parent.menu.showPosition == "left")) {
                        pos.left = pos.left - iSize.width - mSize.width + 1;
                        this.showPosition = "left";
                    }
                }
                this.setStyle("left", String(pos.left) + "px");
                this.setStyle("top", String(pos.top) + "px");
            }
        });
        this.close = this.close.createCallback(function() {
            for (var i = 0; i < this.items.length; i++) {
                if (this.items[i].submenu != null) this.items[i].submenu.close();
            }
            if (this.parent != null && this.parent.isSelect) this.parent.mouseout();
        });
        this.addItem = function(text, action) {
            this.create();
            this.panel.create();
            var item = new System.Controls.MenuItem(text, this);
            if (action) item.onclick = action;
            item.defaultCssClass = this.defaultCssClass;
            item.selectCssClass = this.selectCssClass;
            if (this.getArea) item.getArea = this.getArea;
            if (item.defaultCssClass) item.setCssClass(this.defaultCssClass);
            this.items.push(item);
            return item;
        };
        this.clear = function() {
            while (true) {
                var item = this.items.pop();
                if (!item) break;
                if (item.submenu) item.submenu.clear();
                item.remove();
            }
        }
        this.click = function() {
            //System.Event.stop();
            this.elementClick = true;
        };
        this.documentClick = function() {
            if (this.autoHidden == true && !this.elementClick) this.close();
            this.elementClick = false;
        };
        this.mouseover = function() {
            this.isMouseAbove = true;
            this.show();
        };
        this.mouseout = function() {
            var visible = false;
            for (var i = 0; i < this.items.length; i++) {
                if (this.items[i].submenu != null && (this.items[i].submenu.isMouseAbove == true)) {
                    visible = true;
                    break;
                }
            }
            if (visible == false && this.isMouseAbove == false) {
                this.close();
                if (this.parent && this.parent.menu) this.parent.menu.mouseout();
            }
        };
        this.create();
        System.Event.addEventListener(document, "click", this.documentClick.createDelegate(this), false);
        System.Event.addEventListener(this.element, "click", this.click.createDelegate(this), false);
        System.Event.addEventListener(this.element, "mouseover", this.mouseover.createDelegate(this), false);
        System.Event.addEventListener(this.element, "mouseout", function() {
            this.isMouseAbove = false;
            window.setTimeout(this.mouseout.createDelegate(this), 0);
        } .createDelegate(this), false);
    },
    MenuItem: function(text, menu) {
        this.base = System.Controls.Control;
        this.base(null, menu.panel.element);
        this.onclick = null;
        this.onmouseover = null;
        this.onmouseout = null;
        this.submenu = null;
        this.menu = menu;
        this.defaultCssClass = null;
        this.selectCssClass = null;
        this.isSelect = false;
        this.getArea = null;
        this.click = function() {
            if (this.onclick) this.onclick();
        };
        this.mouseover = function() {
            this.isSelect = true;
            for (var i = 0; i < this.menu.items.length; i++) {
                if (this.menu.items[i].submenu != null && this.menu.items[i] != this) this.menu.items[i].submenu.close();
            }
            if (this.submenu != null) {
                namespace.require("System.Document");
                with (System.Document) {
                    var oPos = getAbsolutePosition(this.element);
                    var oSize = getElementSize(this.element);
                    var mPos = { left: oPos.left + oSize.width - 0, top: oPos.top - 0 };
                    this.submenu.show(mPos, this.getArea ? this.getArea() : null);
                }
            }
            if (this.selectCssClass != null) this.setCssClass(this.selectCssClass);
            if (this.onmouseover) this.onmouseover();
        };
        this.mouseout = function() {
            if (this.submenu == null || this.submenu.visible == false) {
                this.isSelect = false;
                if (this.onmouseout) this.onmouseout();
                if (this.defaultCssClass != null) this.setCssClass(this.defaultCssClass);
            }
        };
        this.createMenu = function() {
            this.submenu = new System.Controls.Menu();
            this.submenu.parent = this;
            this.submenu.defaultCssClass = this.defaultCssClass;
            this.submenu.selectCssClass = this.selectCssClass;
            if (this.getArea) this.submenu.getArea = this.getArea;
            return this.submenu;
        };
        this.setInnerHTML(text);
        this.setStyle("width", "100%");
        this.setStyle("cursor", "default");
        this.show();
        System.Event.addEventListener(this.element, "click", this.mouseover.createDelegate(this), false);
        System.Event.addEventListener(this.element, "mouseover", this.mouseover.createDelegate(this), false);
        System.Event.addEventListener(this.element, "mouseout", this.mouseout.createDelegate(this), false);
    },
    createMenu: function() {
    }
});

System.Controls.extend({
    Tree: function() {
        this.base = System.Controls.Control;
        this.base();
        this.data = null;
        this.show = this.show.createCallBack(function() {

        });

    }
});

System.Controls.extend({
    ChatRoom: function(server, user, displayObject) {
        this.base = System.Controls.Control;
        this.base(displayObject);
        this.users = []; this.user = user || {};
        this.server = server || "Handlers/ChatRoom.ashx"; this.timestamp = null;
        var timer = null;
        this.send = function(message, params) {
            var xmlHttp = new System.XMLHttpRequest();
            xmlHttp.send(this.server, "post", message, this.getHeaders().concat(params && (params instanceof Array) ? params : []), this.complete.createDelegate(this), this.onerror.createDelegate(this));
        };
        this.getHeaders = function() {
            var headers = [];
            for (var key in this.user) {
                if (typeof (this.user[key]) == "string")
                    headers.push([key, this.user[key]]);
            }
            if (this.timestamp)
                headers.push(["timestamp", this.timestamp]);
            return headers;
        };
        this.complete = function(request) {
            var result = request.responseText.parseJSON();
            this.show(request.responseText);
        };
        this.onerror = function(request) {
            alert(request.statusText);
        };
        this.show = this.show.createCallback(function(o) {
            if (timer == null) timer = window.setInterval(this.send.createDelegate(this), 1000);
            this.setInnerHTML(String(o));
        });
    }
});
//window.Alert = window.alert;
//window.alert = function(message, title, onOk) {
//    var dialogBox = System.Controls.getDialogBox("alert");
//    dialogBox.buttonCancel.close();
//    dialogBox.show(message, title || "提示");
//    if (onOk) dialogBox.onsure = onOk;
//};
window.alertAndRedirect = function(message, uri, title) {
    var dialogBox = System.Controls.getDialogBox("alertAndRedirect");
    dialogBox.buttonCancel.close();
    dialogBox.onsure = function() {
        window.location.href = uri;
    };
    dialogBox.show(message, title || "提示");
};
function $() {
    return document.getElementById(arguments[0]);
}
function $V() {
    return new System.Controls.InputBox(arguments[0]).getValue();
}
function $v() {
    new System.Controls.InputBox(arguments[0]).setValue(arguments[1]);
}
function $description() {
    var inputbox = new System.Controls.InputBox(arguments[0]);
    inputbox.setAttribute("description", arguments[1]);
    inputbox.show();
    return inputbox;
}
window.namespace.register("AsynPage");

AsynPage.extend({
    Reflection: function(assemblyName, nameSpace, className, memberName, isStatic, parameters) {
        this.AssemblyName = assemblyName || "";
        this.NameSpace = nameSpace || "";
        this.ClassName = className || "";
        this.MemberName = memberName || "";
        this.IsStatic = isStatic || true;
        this.Parameters = parameters || {};
        this.ReturnValue = {};
        this.InvokeMethod = function(callback, headers) {
            var jsonString = this.toJSONString();
            var xmlHttp = new System.XMLHttpRequest(true);
            xmlHttp.send("Pages/Invoke.ashx", "post", jsonString, headers || [], callback, function() {
                alert("发生了异常");
            }, null);
        }
    },
    getCurrentPageInfo: function() {
        var PageInfo = document.getElementById('PageInfo');
        if (!PageInfo) {
            PageInfo = document.getElementById('ctl00_PageInfo');
        }
        if (PageInfo) {
            var _assemblyName, _className;
            var classInfo = PageInfo.value.split("|");
            _assemblyName = classInfo.pop();
            _className = classInfo.pop();
            return { AssemblyName: _assemblyName, ClassName: _className };
        }
        else {
            return null;
        }
    },
    Call: function(methodName, callback, parameters, headers, isStatic, assembly) {
        var pageInfo = {
            ClassName: "",
            AssemblyName: ""
        }
        if (assembly) {
            pageInfo.AssemblyName = assembly.AssemblyName;
            pageInfo.ClassName = assembly.ClassName;
        }
        else pageInfo = AsynPage.getCurrentPageInfo();
        pageInfo.ClassName += "." + methodName;
        var ref = new AsynPage.Reflection();
        var classTree = pageInfo.ClassName.split(".");
        ref.MemberName = classTree.pop();
        ref.ClassName = classTree.pop();
        ref.NameSpace = classTree.join(".");
        ref.IsStatic = isStatic;
        ref.AssemblyName = pageInfo.AssemblyName;
        ref.Parameters = parameters;
        ref.InvokeMethod(callback, headers);
    },
    CallPage: function(methodName, callback, parameters, headers, isStatic) {
        var pageInfo = AsynPage.getCurrentPageInfo();
        if (pageInfo) {
            AsynPage.Call(pageInfo.ClassName + "." + methodName, callback, parameters || {}, headers, isStatic || false, pageInfo.AssemblyName);
        }
    }
});
namespace.require("System.Controls");
System.Controls.extend({
    $POPSELECT: {},
    PopSelect: function() {
        this.base = System.Controls.WindowBase;
        this.base();

        this.dataSource = [];
        this.dataValueField = "value";
        this.dataTextField = "text";
        this.colums = 4;
        this.size = { width: 550, height: 230 };

        this.showObject = null; this.closeObject = this.floatPanel.panel.element; this.showEventName = "click"; this.closeEventName = "click";
        this.bindTextObject = null;
        this.bindValueObject = null;
        this.bindTextProperty = "value";
        this.bindValueProperty = "value";

        this.itemCommand = null;

        var _base = this;


        this.attchItemEvent = function(item) {
            item.onclick = function() {
                if (_base.bindTextObject && _base.bindTextProperty) {
                    _base.bindTextObject[_base.bindTextProperty] = item.getAttribute("text");
                }
                if (_base.bindValueObject && _base.bindValueProperty) {
                    _base.bindValueObject[_base.bindValueProperty] = item.getAttribute("value");
                }
                _base.close();
                if (_base.itemCommand) {
                    _base.itemCommand(item.text, item.value);
                }
            }
        };
        this.render = function() {
            this.setStyle("border", "0px");
            var sTable = "<table style=\"margin-top:5px;width:100%;font-size:12px\" cellspadding=\"3\"><tbody>{0}</tbody></table>";
            var sTr = "<tr>{0}</tr>";
            var sTd = "<td style=\"height:20px;line-height:20px;text-align:left\">{0}</td>";
            var item = "<a href=\"javascript:void(0);\" index=\"{0}\" value=\"{1}\" style=\"text-decoration:none\" text=\"{2}\"><font color='#ff6600'>·</font><font color=\"#000000\">{3}<font></a>";
            var sRow = "";
            var sItem = "";
            var itemCount = ((this.dataSource.length % this.colums) == 0 ? this.dataSource.length : (parseInt(this.dataSource.length / this.colums) + 1) * this.colums);
            for (var i = 1; i <= itemCount; i++) {
                if (this.dataSource[i - 1]) {
                    sItem += sTd.format(item.format(i - 1, this.dataSource[i - 1][this.dataValueField], this.dataSource[i - 1][this.dataTextField], this.dataSource[i - 1][this.dataTextField]));
                }
                else {
                    sItem += sTd.format("&nbsp;");
                }
                if ((i % this.colums) == 0) {
                    sRow += sTr.format(sItem);
                    sItem = "";
                }
            }
            sTable = sTable.format(sRow);
            this.setInnerHTML(sTable, true);
            this.resize();
            var s = System.Document.selectNodes(this.windowContent.element, '//a');
            for (var i = 0; i != s.length; i++) {
                this.attchItemEvent(s[i]);
            }
            this.buttonClose.setInnerHTML("<font color='#ffffff'>[ 关闭 ]</font> ", true);
        };
    },
    getPopSelect: function(name) {
        name = name || "default";
        if (!System.Controls.$POPSELECT[name]) System.Controls.$POPSELECT[name] = new System.Controls.PopSelect();
        return System.Controls.$POPSELECT[name];
    }
});
window.onerror = function() {
    return true;
}
