var DownMenu = {
    _downMenuList: new Array(), _downMenuObjList: new Array(), _downMenuObjHtml: new Array(),
    open: function (idstr) {
        this.close();
        var ulobj = document.getElementById(idstr); var lilist = ulobj.getElementsByTagName("li");
        for (var i = 0; i < lilist.length; i++) { if (lilist[i].attributes["childmenu"] != null) { lilist[i].style.display = ""; break; } }
        this._downMenuList.push(ulobj);
    },
    close: function () {
        while (this._downMenuList.length > 0) {
            var ulobj = this._downMenuList.pop(); var lilist = ulobj.getElementsByTagName("li");
            for (var i = 0; i < lilist.length; i++) { if (lilist[i].attributes["childmenu"] != null) { lilist[i].style.display = "none"; } }
        }
    },
    load: function (ulobj, depth) {
        if (ulobj != null) {
            var menuhtml = ulobj.innerHTML; depth = depth != null ? depth : 1; var pnode = ulobj.parentNode;
            if (pnode != null && pnode.tagName.toLowerCase() != "div") { var div = document.createElement("div"); div.appendChild(ulobj); pnode.appendChild(div); }
            var lilist = ulobj.getElementsByTagName("li"); pnode.className = "downmenu"; var downmenuul = document.createElement("ul");
            if (lilist.length > depth) {
                lilist[depth - 1].innerHTML = lilist[depth - 1].innerHTML + "<a class=\"DownMenuArrow\" href=\"javascript:\" onclick=\"DownMenu.imgclick(event);DownMenu.open('" + ulobj.id + "');\" ><img src=\"/Images/ui/icon_header_arrow.gif\"/></a>";
                for (var i = depth; i < lilist.length; i++) { var li = document.createElement("li"); li.innerHTML = lilist[i].innerHTML; downmenuul.appendChild(li); }
                while (lilist.length > depth) { ulobj.removeChild(ulobj.lastChild); }
                var li = document.createElement("li"); li.className = "expand"; li.appendChild(downmenuul); li.setAttribute("childmenu", "true"); li.style.display = "none"; ulobj.appendChild(li);
                this.LoadGridViewRightKey(ulobj, menuhtml);//初始化完成后添加右键(限td)
                if (document.attachEvent) { document.attachEvent("onclick", function () { DownMenu.close(); }) } else { document.addEventListener("click", function () { DownMenu.close(); }, true); }
            }
        } else {
            this.LoadGridViewRightKey();
        }
    },
    LoadGridViewRightKey: function (ulobj, menuhtml) {
        if (ulobj != null) { this._downMenuObjList.push(ulobj); this._downMenuObjHtml.push(menuhtml); } else {//初始化完成
            while (this._downMenuObjList.length > 0) { var obj = this._downMenuObjList.pop(); var html = this._downMenuObjHtml.pop(); var node = obj.parentNode.parentNode.parentNode; this.tdrightkey(node, html); }//这里为tr里的右键解决方式(GridView使用)
        }
    },
    tdrightkey: function (trnode, menuhtml) {
        if (trnode != null && trnode.tagName.toLowerCase() == "tr") {
            var tdlist = trnode.getElementsByTagName("td"); var tdobj;
            for (var i = 0; i < tdlist.length; i++) {
                tdobj = tdlist[i]; var div1 = document.createElement("div"); var div2 = document.createElement("div"); var html = tdobj.innerHTML;
                div2.innerHTML = tdobj.innerHTML + "&nbsp;"; tdobj.innerHTML = ""; div2.innerHTML = html; div2.style.cssText = "height:30px;"; div1.style.cssText = "position:relative;";
                div2.oncontextmenu = function (e) { follow.rightkey(e, this, "<div class=\"rightmenu\"><ul style=\"background-color:#fff;\">" + menuhtml + "</ul></div>"); return false; }
                div1.appendChild(div2); tdobj.appendChild(div1);
            }
        }
    },
    imgclick: function (e) { if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }
}
function Alert(_msg, _callback) {
    art.dialog({ content: _msg, lock: true, opacity: 0, ok: function () { if (typeof _callback == "function") { _callback(true); } } });
}
function Confirm(_msg, _callback) {
    art.dialog({
        title: '确认消息', content: _msg, lock: true, opacity: 0, width: "280px", height: "50px", okVal: "确认", cancelVal: "取消", ok: function () { if (_callback != null) { _callback(true); } },
        cancel: function () { if (_callback != null) { _callback(false); } }
    });
}
function DelConfirm(_callback) { Confirm("确定删除?", _callback); }
var Validator = {
    Email: function (source, arguments) { arguments.IsValid = this.email(arguments.Value); },
    Digit: function (source, arguments) { arguments.IsValid = this.digit(arguments.Value); },
    Letter: function (source, arguments) { arguments.IsValid = this.letter(arguments.Value); },
    DigitLetter: function (source, arguments) { arguments.IsValid = this.digitLetter(arguments.Value); },
    Decimal: function (source, arguments) { arguments.IsValid = this.decimal(arguments.Value); },
    Word: function (source, arguments) { arguments.IsValid = this.word(arguments.Value); },//任何单词匹配
    Telephone: function (source, arguments) { arguments.IsValid = this.telephone(arguments.Value); },//国内电话
    MobilePhone: function (source, arguments) { arguments.IsValid = this.mobilePhone(arguments.Value); },//移动电话
    ChineseCharacter: function (source, arguments) { arguments.IsValid = this.chineseCharacter(arguments.Value); },//汉字
    Date: function (source, arguments) { arguments.IsValid = this.date(arguments.Value); },//日期(如2012-01-01)
    Datetime: function (source, arguments) { arguments.IsValid = this.datetime(arguments.Value); },//日期+时间
    Url: function (source, arguments) { arguments.IsValid = this.url(arguments.Value); },
    NonEmpty: function (source, arguments) { arguments.IsValid = this.nonEmpty(arguments.Value); },//非空
    email: function (data) { return this.test(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/, data); },
    digit: function (data) { return this.test(/^\d+$/, data); },
    letter: function (data) { return this.test(/^[A-Za-z]+$/, data) },
    digitLetter: function (data) { return this.test(/^[A-Za-z0-9]+$/, data); },
    decimal: function (data) { return this.test(/^\d+(\.\d+)?$/, data); },
    word: function (data) { return this.test(/^\w+$/, data); },
    telephone: function (data) { return this.test(/(\d{3}-|\d{4}-)?(\d{8}|\d{7})/, data); },
    mobilePhone: function (data) { return this.test(/^1{1}\d{10}$/, data); },
    chineseCharacter: function (data) { return this.test(/[\u4e00-\u9fa5]+/, data); },
    date: function (data) { return this.test(/^\d{4}\W\d{1,2}\W\d{1,2}$/, data); },
    datetime: function (data) { return this.test(/^((((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-9]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/, data); },
    url: function (data) { return this.test(/^[a-zA-z]+:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$/, data); },
    nonEmpty: function (data) { if (data != null && data != "") { return true; } return false; },
    test: function (express, data) { return new RegExp(express).test(data); }
};
var DropDownList = function (ddlid) {
    function id(idv) {
        return document.getElementById(idv);
    };
    var _ddlid = ddlid + "_dropdownlist", _spanid = ddlid + "_dropdownlistspan", _spanlistid = ddlid + "_dropdownlistspanlist";
    var uiobj = bx;
    var _liminwidth = "0px";
    this.initial = function (vallist, params) {
        params = params != null ? params : "";
        var obj = id(ddlid);
        var span = document.createElement("span");
        span.id = _spanid; span.className = "dropdownlist";
        var spanlist = document.createElement("span");
        spanlist.id = _spanlistid;
        span.appendChild(spanlist);
        if (typeof (obj) == "select") {
            span.appendChild(obj);
        }
        else {
            var selectobj = document.createElement("select");
            selectobj.id = _ddlid;
            selectobj.style.display = "none";
            var isselected = false;
            for (var key in vallist) {
                var option = document.createElement("option");
                option.innerHTML = key;
                option.value = vallist[key];
                if (params.value != null && params.value == option.value)//初始值
                {
                    id(ddlid).value = key;
                    option.selected = true;
                } else if (params.value == null && isselected == false) {//如果不指定选项则选择第一个
                    id(ddlid).value = key;
                    option.selected = isselected = true;
                }
                selectobj.appendChild(option);
            }
            span.appendChild(selectobj);
            //id(ddlid).value = selectobj.options[selectobj.selectedIndex].innerHTML;
        }
        if (params.extend != null && params.extend == true) {//默认不使用选项延伸
            _liminwidth = obj.style.width;
        }
        obj.parentNode.appendChild(span);
        obj.onclick = this.dropdownlisttextevent;
        var otersnode = obj.parentNode.getElementsByTagName("a");
        if (otersnode != null)//为其它需要触发的事件添加事件
        {
            for (var x = 0; x < otersnode.length; x++) {
                otersnode[x].onclick = this.dropdownlisttextevent;
            }
        }
        uiobj.utility.addEvent(document, "click", this.dropdownlisttextblur);
    };
    this.get = function () {
        return uiobj.dom.select.get(_ddlid);
    };
    this.dropdownlisttextevent = function (e) {
        var span = id(_spanlistid);
        var ul = document.createElement("ul");
        var options = id(_ddlid).options;
        for (var i = 0; i < options.length; i++) {
            var li = document.createElement("li");
            li.innerHTML = options[i].innerHTML;
            li.setAttribute("value", options[i].value);
            li.onclick = function () {
                id(ddlid).value = this.innerHTML;
                uiobj.dom.select.set(_ddlid, this.attributes["value"].value);
            };
            ul.appendChild(li);
        }
        if (_liminwidth != null && _liminwidth != "" && _liminwidth != "0px") {
            ul.style.minWidth = _liminwidth;
            ul.style.cssText = "position:absolute;";
        }
        span.innerHTML = "";
        span.appendChild(ul);
        if (e && e.stopPropagation) {
            e.stopPropagation();
        }
        else {
            window.event.cancelBubble = true;
        }
    };
    this.dropdownlisttextblur = function () {
        id(_spanlistid).innerHTML = "";
    };

}