/*   
*---------------  SendTab()   -----------------   
*   SendTab() 
*   功能: 多浏览器回车跳转代码
*---------------  SendTab   -----------------   
*/
jQuery.fn.SendTab = function() {
    if ($.browser.msie) {
        $(this).bind("keydown", function(e) {
            if (e.which == 13) {
                try {
                    if (event.keyCode == 13 && event.srcElement.type != 'button' && event.srcElement.type != 'image' && event.srcElement.type != 'submit' && event.srcElement.type != 'reset' && event.srcElement.type != '')
                        event.keyCode = 9;
                } catch (e) { }
            }
        });
    }
    else {
        $("input, textarea, select").keypress(function(e) {
            var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            if (keyCode == 13) {
                var i;
                for (var i = 0; i < this.form.elements.length; i++) {
                    if (this.form.elements[i] == this)
                        break;
                }
                var el = this.form.elements[++i % this.form.elements.length];
                if (el.type != "hidden" && el.type != "img" && el.type != "file")
                    el.focus();
                else {
                    var button = $("input[type=image]");
                    for (var b = 0; b < button.length; b++) {
                        button[b].focus();
                        break;
                    }
                }
                return false;
            }
            else
                return true;

        });

        $("input[type=image]").keypress(function(e) {
            var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            if (keyCode == 13) { this.click() };
        });
    }
}



/*   
*---------------  limitRefresh()   -----------------   
*   limitRefresh() 
*   功能: 屏蔽鼠标键盘功能键、屏蔽鼠标右键、Ctrl+n、shift+F10、F5刷新、退格键
*---------------  limitRefresh   -----------------   
*/
function limitRefresh() {
    if ($.browser.msie) {
        if (window.Event) //屏蔽鼠标右键菜单
            document.captureEvents(Event.MOUSEUP);
        function nocontextmenu() {
            event.cancelBubble = true
            event.returnValue = false;
            return false;
        }
        document.oncontextmenu = nocontextmenu; // for IE5+

        document.onkeypress = function() {
            if (((window.event.altKey) && ((window.event.keyCode == 37) || (window.event.keyCode == 39))) || //屏蔽Alt+方向键
                (window.event.keyCode == 8 && event.srcElement.type != "text" && event.srcElement.type != "textarea") || //屏蔽退格
                (window.event.ctrlKey && event.keyCode == 82) ||
                (event.ctrlKey) && (event.keyCode == 78) || //屏蔽Ctrl+n
                (window.event.srcElement.tagName == "A" && window.event.shiftKey) || //shift+鼠标左键                
                (window.event.shiftKey && window.event.keyCode == 121)) //shift+F10
            {
                window.event.keyCode = 0;
                window.event.returnValue = false;
            }
            if ((window.event.altKey) && (window.event.keyCode == 115)) //屏蔽Alt+F4
            {
                window.showModelessDialog("about:blank", "", "dialogWidth:1px;dialogheight:1px");
                return false;
            }
        }
    }
    else {
        function click(e) {
            if (document.all) {
                if (event.button == 2 || event.button == 3) {
                    oncontextmenu = 'return false';
                }
            }
        }
        document.onmousedown = click;
        document.oncontextmenu = new Function("return false;");
        document.onkeypress = function(e) {
            var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            if (keyCode == 13)
                return false;
            var i;
            for (var i = 0; i < this.forms[0].elements.length; i++) {
                if (this.forms[0].elements[i] == this)
                    break;
            }
            var el = this.forms[0].elements[++i % this.forms[0].elements.length];

            if (((e.altKey) && ((keyCode == 37) || (keyCode == 39))) || //屏蔽Alt+方向键
                (keyCode == 8 && el.type != "input" && el.type != "textarea" && el.type != "hidden") || //屏蔽退格
                (e.ctrlKey && keyCode == 82) ||
                (e.ctrlKey) && (keyCode == 78) || //屏蔽Ctrl+n
            //(window.event.srcElement.tagName=="A"&&e.shiftKey)||                 
                (e.shiftKey && keyCode == 121)) //shift+F10
            {
                e.preventDefault();
            }
        }

    }
}


/*   
*---------------   textlimit(counter_el,thelimit,speed)   -----------------   
*   textlimit(thelimit)    
*   功能:限制多行文本框输入字数 
*   参数:thelimit, 限制的字数
*---------------   textlimit(thelimit)   -----------------   
*/
jQuery.fn.textlimit = function(thelimit) {
    if ($.browser.msie)    //ie浏览器
    {
        if ($(this).length != 0)
            $(this)[0].onpropertychange = handle
    }
    else {//非ie浏览器，比如Firefox
        if ($(this).length != 0)
            $(this)[0].addEventListener("input", handle, false);
    }

    function handle() {
        if ($(this)[0].value.length > thelimit)
            $(this)[0].value = $(this)[0].value.substr(0, thelimit);
    }
};

/*   
*---------------  onlypressInt()   -----------------   
*   onlypressInt()    
*   功能:限制文本框只能输入正整数  
*---------------   onlypressInt()   -----------------   
*/
jQuery.fn.onlypressInt = function() {
    $(this).css({ imeMode: "disabled" });
    $(this).bind("keypress", function(e) {
        if (e.ctrlKey == true || e.shiftKey == true)
            return false;
        if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8)
            return true;
        else if (e.ctrlKey == true && (e.which == 99 || e.which == 118))
            return false;
        else
            return false;
    })
    .bind("contextmenu", function() { return false; })
    .bind("drop", function() { return false; })
    .bind("paste", function() { return false; });
};

/*   
*---------------  DropDownKeyDown()   -----------------   
*   DropDownKeyDown()    
*   功能:下拉文本框空格选择事件
*---------------   DropDownKeyDown()   -----------------   
*/
jQuery.fn.DropDownKeyDown = function() {
    $(this).bind("keypress", function(e) {
        if ($.browser.msie) {
            if (event.keyCode == 32 || event.keyCode == 229)
                DropDownKeyPress(this)
        }
        else {
            if (e.which == 32 || e.which == 229)
                DropDownKeyPress(this)
        }
    })
};

/*   
*---------------  DropDownKeyPress()   -----------------   
*   DropDownKeyPress()    
*   功能:下拉文本框空格选择事件  
*---------------   DropDownKeyPress()   -----------------   
*/
function DropDownKeyPress(obj) {
    var count = obj.options.length - 1;
    if (count == -1) return;
    if (obj.options.selectedIndex < count)
        obj.options.selectedIndex++;
    else
        obj.options.selectedIndex = 0;
}


/*   
*---------------  cannotPress()   -----------------   
*   cannotPress()    
*   功能:限制文本框所有状态 禁用keypress  
*---------------   cannotPress()   -----------------   
*/
jQuery.fn.cannotPress = function() {
    $(this).css({ imeMode: "disabled", '-moz-user-select': "none" });
    $(this).bind("keypress", function(e) {
        if (e.which != 13)
            return false;
    })
    .bind("contextmenu", function() { return false; })
    .bind("selectstart", function() { return false; })
    .bind("drop", function() { return false; })
    .bind("paste", function() { return false; });
};



/*   
*---------------  onlypressDecimal(n,s)   -----------------   
*   onlypressDecimal(n,s)  
*   功能:限制文本框只能输入指定格式的数字类型
*   参数:n 整数位数 数字类型
*   参数:s 小数位数 数字类型
*---------------   onlypressDecimal(n,s)   -----------------   
*/
jQuery.fn.onlypressDecimal = function(n, s) {
    $(this).css({ imeMode: "disabled" });
    var reg = new RegExp("^\\d{1," + n + "}((\\.)?(\\d{1," + s + "})?)?$");
    var vale;
    var sel = "";
    $(this).bind("keypress", function(e) {
        if (e.ctrlKey == true || e.shiftKey == true)
            return false;
        else if (e.ctrlKey == true && (e.which == 99 || e.which == 118))
            return false;
        else if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8 || e.which == 46) {
            if (e.which == 8 || e.which == 0)
                return true;
            else {
                if (e.which == 46) {
                    $(this).attr('maxlength', n + s + 1);
                }
                if ($.browser.msie)
                    sel = document.selection.createRange();
                var len = GetCursorPosition(this);
                vale = LimitMethod(this, String.fromCharCode(e.which), sel);
                if (vale.indexOf('.') == -1 && vale.length >= n + 1) { return false; }
                if (!reg.test(vale)) {
                    return false;
                }
                if ($.browser.msie) {
                    $(this).val(vale);
                    var r = event.srcElement.createTextRange();
                    r.moveStart('character', len + 1);
                    r.collapse(true);
                    r.select();
                    return false;
                }
            }
        }
        else
            return false;
    })

    .bind("contextmenu", function() { return false; })
    .bind("drop", function() { return false; })
    .bind("paste", function() { return false; });
};

/*   
*---------------  GetCursorPosition(txtObj)   -----------------   
*   GetCursorPosition(txtObj)    
*   功能:得到当前文本框光标位置
*---------------   GetCursorPosition(txtObj)   -----------------   
*/
function GetCursorPosition(txtObj) {
    if (!$.browser.msie) return 0;
    var obj = $(txtObj); //根据ID获得对象
    obj.focus(); //输入框获得焦点
    var workRange = document.selection.createRange(); //创建输入框文本对象
    obj.select(); //输入框获得焦点
    var allRange = document.selection.createRange(); //为新的光标位置创建文档选择对象
    workRange.setEndPoint("StartToStart", allRange);
    var len = workRange.text.length;
    workRange.collapse(false); //将不移光标移到头
    workRange.select(); //把光标恢复到以前的位置
    //alert(len);//检测
    return len;
}

function LimitMethod(obj, re, sel) {
    var vale;
    if ($.browser.msie) {
        var old = $(obj).val();
        obj.caretPos = document.selection.createRange().duplicate();
        var caretPos = obj.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? re + '' : re;
        if (sel.text != '') {
            $(obj).val(re);
            vale = re;
        }
        else {
            vale = $(obj).val();
            $(obj).val(old);
        }
    }
    else {
        var rangeStart = $(obj)[0].selectionStart;
        var rangeEnd = $(obj)[0].selectionEnd;
        var tempStr1 = $(obj)[0].value.substring(0, rangeStart);
        var tempStr2 = $(obj)[0].value.substring(rangeEnd);
        vale = tempStr1 + re + tempStr2;
    }
    return vale;
}


/*   
*---------------  ConvertToDate(n,s)   -----------------   
*   ConvertToDate(n,s)   
*   功能:限制文本框只能输入指定格式的数字类型
*   参数:n 整数位数 数字类型
*   参数:s 小数位数 数字类型
*---------------  ConvertToDate(n,s)   -----------------   
*/
function ConvertToDate(obj) {
    if (CanValidotor(obj)) {
        var sdate = $.trim($(obj).val());
        if (sdate == "") {
            // $(obj).removeClass("errorStyle");
            GetValidatorResult(obj, true);
            return true;
        }
        var year;
        var month;
        var day;

        //如果为完全日期格式
        if (sdate.length == 10 || sdate.length == 9) {
            if (isDate(sdate) == true) {
                $(obj).removeClass("errorStyle");
                GetValidatorResult(obj, true);
                return true;
            }
            else {
                SelAll(obj);
                $(obj).addClass("errorStyle");
                GetValidatorResult(obj, false);
                return false
            }
        }
        //如果为简化日期格式
        if (sdate.length == 6 || sdate.length == 8) {
            //6位简化日期格式转换
            if (sdate.length == 6) {
                //确定年范围
                year = sdate.substr(0, 2); //两位年
                if (year.substr(0, 1) != "0") {
                    if (year > 20) {
                        year = 1900 + parseInt(year);
                    }
                    else if (year < 20) {
                        year = 2000 + parseInt(year);
                    }
                    else if (year == 20)
                        year = 2000;
                }
                else {
                    year = 2000 + parseInt(year.substr(1, 1));
                }
                //确定月范围
                month = sdate.substr(2, 2);
                //确定日范围
                day = sdate.substr(4, 2);
                $(obj).val(year + "-" + month + "-" + day)
            }
            //8位简化日期格式转换
            if (sdate.length == 8) {
                //判断是否完整日期格式
                var datePat = /\d{4}-\d{1,2}-\d{1,2}/; //日期验证正则表达式
                if (datePat.test($(obj).val())) {
                    if (isDate($(obj).val())) {
                        $(obj).removeClass("errorStyle");
                        GetValidatorResult(obj, true);
                        return true;
                    }
                    else {
                        $(obj).addClass("errorStyle");
                        SelAll(obj);
                        GetValidatorResult(obj, false);
                        return false
                    }
                }
                //确定月范围
                year = sdate.substr(0, 4)
                //确定月范围
                month = sdate.substr(4, 2)
                //确定日范围
                day = sdate.substr(6, 2)
                $(obj).val(year + "-" + month + "-" + day)
            }
        }
        else {
            //其他情况
            alert('日期输入格式不正确！\n日期输入格式范例:030825 或 20030825');
            $(obj).addClass("errorStyle");
            SelAll(obj);
            GetValidatorResult(obj, false);
            return false;
        }
        //执行日期校验
        if (isDate($(obj).val())) {
            $(obj).removeClass("errorStyle");
            GetValidatorResult(obj, true);
            return true;
        }
        else {
            $(obj).val(sdate);
            $(obj).addClass("errorStyle");
            SelAll(obj);
            GetValidatorResult(obj, false);
            return false;
        }
    }
}

/*   
*---------------  isDate(value)   -----------------   
*   isDate(value)
*   功能:验证字符串是否符合日期格式
*   参数:value 字符串类型
*---------------   isDate(value)   -----------------   
*/
function isDate(value) {
    var datePat = /^\d{4}-\d{1,2}-\d{1,2}$/; //日期验证正则表达式
    if (!datePat.test(value)) {
        alert('日期输入格式不正确！\n日期输入格式范例:030825 或 20030825');
        return false;
    }

    var year = value.split('-')[0];
    var month = value.split('-')[1];
    //统一月份格式
    if (month.length = 2) {
        if (month.substr(0, 1) == "0") {
            month = month.substr(1, 1)
        }
    }
    var day = value.split('-')[2];
    //统一日格式
    if (day.length = 2) {
        if (day.substr(0, 1) == "0") {
            day = day.substr(1, 1)
        }
    }
    //进行年范围验证
    if (year < 1900) {
        // 检查年范围 
        alert("年份不能小于1900年！");
        return false;
    }

    //进行年月日范围验证
    if (month < 1 || month > 12) {
        // 检查月范围 
        alert("月份超范围！");
        return false;
    }

    if (day < 1 || day > 31) {
        // 检查日范围
        alert("日期超范围！");
        return false;
    }

    if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
        // 检查月范围
        alert(month + "月份天数不能超过30天！");
        return false;
    }

    if (month == 2) {
        //检查闰年的2月份天数
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day == 29 && !isleap)) {
            alert(year + "年2月份不能大于28天！");
            return false;
        }
    }
    return true;
}

/*   
*---------------  SelAll(obj)   -----------------   
*   SelAll(obj)
*   功能:设置焦点并全选
*   参数:obj 焦点对象
*---------------   SelAll(obj)   -----------------   
*/
function SelAll(obj) {
    window.setTimeout(function() { obj.focus(); }, 0);
    obj.select();
}

/*   
*---------------  IsNotEmpty(obj, filedName)   -----------------   
*   IsNotEmpty(obj, filedName)
*   功能:判断文本框是否为空
*   参数:obj 文本框对象
*   参数:filedName 提示信息
*   返回:如果文本框不为空返回True 否则返回False
*---------------   IsNotEmpty(obj, filedName)   -----------------   
*/
function IsNotEmpty(obj, filedName) {
    if (CanValidotor(obj)) {
        if ($.trim($(obj).val()) == "") {
            alert('【' + filedName + "】不能为空！");
            $(obj).addClass("errorStyle");
            SelAll(obj);
            GetValidatorResult(obj, false);
            return false;
        }
        else {
            $(obj).removeClass("errorStyle");
            GetValidatorResult(obj, true);
            return true;
        }
    }
}

/*   
*---------------  CheckLessThanAge(obj,mess, n)   -----------------   
*   CheckLessThanAge(obj,mess, n)
*   功能:判断年龄不能大于N岁
*   参数:obj 日期文本框对象
*   参数:mess 提示信息
*   参数:n 岁数 整型
*   返回:如果满足条件返回True 否则返回False
*---------------   CheckLessThanAge(obj,mess, n)   -----------------   
*/
function CheckLessThanAge(obj, mess, n) {
    if (CanValidotor(obj)) {
        if ($(obj).val() == "") {
            //$(obj).removeClass("errorStyle");    
            GetValidatorResult(obj, true);
            return true;
        }
        var reg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})/
        if (arr = $(obj).val().match(reg)) {
            var tmp = new Date(parseInt(arr[1]) + n, arr[3] - 1, arr[4]);
            if (tmp.getTime() > (new Date().getTime())) {
                alert(mess);
                SelAll(obj);
                $(obj).addClass("errorStyle");
                GetValidatorResult(obj, false);
                return false;
            }
            $(obj).removeClass("errorStyle");
            GetValidatorResult(obj, true);
            return true;
        }
        else {
            alert(mess);
            SelAll(obj);
            $(obj).addClass("errorStyle");
            GetValidatorResult(obj, false);
            return false;
        }
    }
}

/*   
*---------------  CheckGreaterAge(obj,Birth,mess, n)   -----------------   
*   CheckGreaterAge(obj,Birth,mess, n)
*   功能:更具出生日期判断年龄不能小于N岁
*   参数:obj 日期文本框对象
*   参数:Birth 出生日期文本框对象
*   参数:mess 提示信息
*   参数:n 岁数 整型
*   返回:如果满足条件返回True 否则返回False
*---------------   CheckGreaterAge(obj,Birth,mess, n)   -----------------   
*/
function CheckGreaterAge(obj, Birth, mess, n) {
    if (CanValidotor(obj)) {
        if ($(obj).val() == "") {
            // $(obj).removeClass("errorStyle");    
            GetValidatorResult(obj, true);
            return true;
        }
        var reg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})/
        if (arr = $(obj).val().match(reg)) {
            brr = $(Birth).val().match(reg);
            var btmp = new Date(parseInt(brr[1]) + n, brr[3] - 1, brr[4]);
            var tmp = new Date(parseInt(arr[1]), arr[3] - 1, arr[4]);
            if (tmp.getTime() < btmp.getTime()) {
                alert(mess);
                SelAll(obj);
                $(obj).addClass("errorStyle");
                GetValidatorResult(obj, false);
                return false;
            }
            $(obj).removeClass("errorStyle");
            GetValidatorResult(obj, true);
            return true;
        }
        else {
            alert(mess);
            SelAll(obj);
            $(obj).addClass("errorStyle");
            GetValidatorResult(obj, false);
            return false;
        }
    }
}

/*   
*---------------  CheckMustFill(mustObj, obj, mess)   -----------------   
*   CheckMustFill(mustObj, obj, mess)
*   功能:检查在此文本框之前是否有必须录入字段
*   参数:mustObj 优先填写文本框对象
*   参数:obj 文本框对象
*   参数:mess 提示信息
*   返回:如果满足条件返回True 否则返回False
*---------------   CheckMustFill(mustObj, obj, mess)   -----------------   
*/
function CheckMustFill(mustObj, obj, mess) {
    if (CanValidotor(mustObj)) {
        if ($(mustObj).val() == "") {
            alert("请先输入【" + mess + "】！");
            $(obj).val("");
            SelAll($(mustObj));
            GetValidatorResult($(mustObj)[0], false);
            return false;
        }
        else {
            GetValidatorResult(obj, false);
            cuertentvalodator = true;
            return true;
        }
    }
}



/*   
*---------------  CompareToNow(obj,mess, condition)   -----------------   
*   CompareToNow(obj,mess, condition)
*   功能:于当前日期比较
*   参数:obj 文本框对象
*   参数:mess 提示信息
*   参数:condition 字符串类型条件(<,>,<=,>=,!=,=)
*   返回:如果满足条件返回True 否则返回False
*---------------   CompareToNow(obj,mess, condition)   -----------------   
*/
function CompareToNow(obj, mess, condition) {
    if (CanValidotor(obj)) {
        if ($.trim($(obj).val()) == "") {
            //$(obj).removeClass("errorStyle");
            GetValidatorResult(obj, true);
            return true;
        }
        var reg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})/
        if (arr = $(obj).val().match(reg)) {
            var tmp = new Date(parseInt(arr[1]), arr[3] - 1, arr[4]);
            var result = false;
            switch (condition) {
                case ">":
                    if (tmp.getTime() > (new Date().getTime()))
                        result = true;
                    else
                        alert("【" + mess + "】必须大于当前日期！");
                    break;
                case "=":
                    if (tmp.getTime() == (new Date().getTime()))
                        result = true;
                    else
                        alert("【" + mess + "】必须等于当前日期！");
                    break;
                case "<":
                    if (tmp.getTime() < (new Date().getTime()))
                        result = true;
                    else
                        alert("【" + mess + "】必须小于当前日期！");
                    break;
                case ">=":
                    if (tmp.getTime() >= (new Date().getTime()))
                        result = true;
                    else
                        alert("【" + mess + "】必须大于等于当前日期！");
                    break;
                case "<=":
                    if (tmp.getTime() <= (new Date().getTime()))
                        result = true;
                    else
                        alert("【" + mess + "】必须小于等于当前日期！");
                    break;
                case "!=":
                    if (tmp.getTime() != (new Date().getTime()))
                        result = true;
                    else
                        alert("【" + mess + "】不能等于当前日期！");
                    break;
                default:
                    result = false;
                    break;
            }
            if (result == false) {
                SelAll(obj);
                $(obj).addClass("errorStyle");
                GetValidatorResult(obj, false);
                return false;
            }
            $(obj).removeClass("errorStyle");
            GetValidatorResult(obj, true);
            return true;
        }
        else {
            SelAll(obj);
            $(obj).addClass("errorStyle");
            GetValidatorResult(obj, false);
            return false;
        }
    }
}


/*   
*---------------   CompareDate(obj, beginTime,endTime, bfield, efield, condition)   -----------------   
*  CompareDate(obj, beginTime,endTime, bfield, efield, condition)     
*   功能: 日期比较功能
*   参数:obj, 当前文本框对象.   
*   参数:beginTime,验证开始日期 文本框对象
*   参数:endTime, 验证结束日期 文本框对象
*   参数:bfield, 开始文字
*   参数:efield, 结束文字
*   参数:condition, 字符串类型条件(<,>,<=,>=,!=,=)
*   返回:满足条件返回true 否则 返回 false
*---------------  CompareDate(obj, beginTime,endTime, bfield, efield, condition)   -----------------   
*/
function CompareDate(obj, beginTime, endTime, bfield, efield, condition) {
    if (CanValidotor(obj)) {
        if ($(beginTime).val() == "" || $(endTime).val() == "") {
            GetValidatorResult(obj, true);
            return true;
        }
        else {
            var reg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})/
            if (brr = $(beginTime).val().match(reg)) {
                endrr = $(endTime).val().match(reg);
                var btmp = new Date(parseInt(brr[1]), brr[3] - 1, brr[4]);
                var etmp = new Date(parseInt(endrr[1]), endrr[3] - 1, endrr[4]);
                var result = false;
                switch (condition) {
                    case ">":
                        if (btmp.getTime() > etmp.getTime())
                            result = true;
                        else
                            alert("【" + bfield + "】必须大于【" + efield + "】！");
                        break;
                    case "=":
                        if (btmp.getTime() == etmp.getTime())
                            result = true;
                        else
                            alert("【" + bfield + "】必须等于【" + efield + "】！");
                        break;
                    case "<":
                        if (btmp.getTime() < etmp.getTime())
                            result = true;
                        else
                            alert("【" + bfield + "】必须小于【" + efield + "】！");
                        break;
                    case ">=":
                        if (btmp.getTime() >= etmp.getTime())
                            result = true;
                        else
                            alert("【" + bfield + "】必须大于等于【" + efield + "】！");
                        break;
                    case "<=":
                        if (btmp.getTime() <= etmp.getTime())
                            result = true;
                        else
                            alert("【" + bfield + "】必须小于等于【" + efield + "】！");
                        break;
                    case "!=":
                        if (btmp.getTime() != etmp.getTime())
                            result = true;
                        else
                            alert("【" + bfield + "】不能等于【" + efield + "】！");
                        break;
                    default:
                        result = false;
                        break;
                }
                if (result == false) {
                    SelAll(obj);
                    $(obj).addClass("errorStyle");
                    GetValidatorResult(obj, false);
                    return false;
                }
                $(obj).removeClass("errorStyle");
                GetValidatorResult(obj, true);
                return true;
            }
            else {
                SelAll(obj);
                $(obj).addClass("errorStyle");
                GetValidatorResult(obj, false);
                return false;
            }
        }
    }
}


/*   
*---------------   DateAdd(interval,number,date)   -----------------   
*   DateAdd(interval,number,date)     
*   功能:实现VBScript的DateAdd功能.   
*   参数:interval,字符串表达式，表示要添加的时间间隔.   
*   参数:number,数值表达式，表示要添加的时间间隔的个数.   
*   参数:date,时间对象.   
*   返回:新的时间对象.   
*   var   now   =   new   Date();   
*   var   newDate   =   DateAdd("d",5,now);
*---------------   DateAdd(interval,number,date)   -----------------   
*/
function DateAdd(obj, interval, number) {
    var reg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})/
    if (arr = $(obj).val().match(reg)) {
        var tmp = new Date(parseInt(arr[1]), arr[3] - 1, arr[4]);
        tmp = new Date(tmp)
        switch (interval) {
            case "y":
                tmp.setFullYear(tmp.getFullYear() + number);
                break;
            case "q":
                tmp.setMonth(tmp.getMonth() + number * 3);
                break;
            case "m":
                tmp.setMonth(tmp.getMonth() + number);
                break;
            case "w":
                tmp.setDate(tmp.getDate() + number * 7);
                break;
            case "d":
                tmp.setDate(tmp.getDate() + number);
                break;
            case "h":
                tmp.setHours(tmp.getHours() + number);
                break;
            case "m":
                tmp.setMinutes(tmp.getMinutes() + number);
                break;
            case "s":
                tmp.setSeconds(tmp.getSeconds() + number);
                break;
            default:
                tmp.setDate(tmp.getDate() + number);
                break;
        }
        var m = tmp.getMonth() + 1;
        if (m.toString().length == 1)
            m = "0" + m;
        var d = tmp.getDate();
        if (d.toString().length == 1)
            d = "0" + d;
        var dateresult = tmp.getFullYear() + "-" + m + "-" + d;
        return dateresult;
    }
}

/*   
*---------------    CheckYear(obj)   -----------------   
*   CheckYear(obj)    
*   功能:判断输入的是否为年.   
*   参数:date,时间对象.   
*   返回:新的时间对象. 
*---------------    CheckYear(obj)   -----------------   
*/
function CheckYear(obj) {
    var now = new Date();
    var value = $(obj).val();
    var year;

    if (value == "") {
        //$(obj).removeClass("errorStyle");
        GetValidatorResult(obj, true);
        return true;
    }

    if (value.length == 0)
        $(obj).val(now.getFullYear())

    if (value.length == 4) {
        if (parseInt(value) > 2051 || parseInt(value) < 1900) {
            alert("输入的年必须在1900到2050之间");
            SelAll(obj);
            $(obj).addClass("errorStyle");
            GetValidatorResult(obj, false);
            return false;

        }
    }


    if (value.length == 1 || value.length == 3 || value.length > 4) {
        alert("请输入4位或2位");
        SelAll(obj);
        $(obj).addClass("errorStyle");
        GetValidatorResult(obj, false);
        return false;
    }

    if (value.length == 2) {
        year = value.substr(0, 2); //两位年
        if (year.substr(0, 1) != "0") {
            if (year > 50) {
                year = 1900 + parseInt(year);
            }
            if (year <= 50) {
                year = 2000 + parseInt(year);
            }
        }
        else {
            year = 2000 + parseInt(year.substr(1, 1));
        }
        $(obj).val(year);
    }
    $(obj).removeClass("errorStyle");
    GetValidatorResult(obj, true);
    return true;
}


/*   
*---------------    ValidateLength(obj,length,filedName)   -----------------   
*   ValidateLength(obj,length,filedName)   
*   功能:验证字符串指定长度.   
*   参数:obj,对象.   
*   参数:length,长度 数字.
*   参数:filedName,字段名称 
*   返回:新的时间对象.   
*---------------    ValidateLength(obj,length,filedName)   -----------------   
*/
function ValidateLength(obj, length, filedName) {
    if ($(obj).val().length > length) {
        alert('【' + filedName + "】长度不能超过" + length + "个字符！\n");
        SelAll(obj);
        $(obj).addClass("errorStyle");
        GetValidatorResult(obj, false);
        return false;
    }
    else {
        $(obj).removeClass("errorStyle");
        GetValidatorResult(obj, true);
        return true;
    }
}


/*   
*---------------   ValidateFixLength(obj, length, filedName)   -----------------   
*   ValidateLength(obj,length,filedName)   
*   功能:验证长度必须为某个长度的字符.   
*   参数:obj,对象.   
*   参数:length,长度 数字.
*   参数:filedName,字段名称 
*---------------    ValidateFixLength(obj, length, filedName)   -----------------   
*/
function ValidateFixLength(obj, length, filedName) {
    if ($(obj).val().length != length && $(obj).val().length != 0) {
        alert('【' + filedName + "】长度必须为" + length + "个字符！\n");
        SelAll(obj);
        $(obj).addClass("errorStyle");
        GetValidatorResult(obj, false);
        return false;
    }
    else {
        $(obj).removeClass("errorStyle");
        GetValidatorResult(obj, true);
        return true;
    }
}


/*   
*---------------   模式窗口  -----------------   
*     
*   功能:跨浏览器仿模式窗体.   
*   
*---------------   模式窗口   -----------------   
*/
var dialog = new windows_dialog();
function windows_dialog() {
    this.params_up = new Array();
    this.params_down = new Array();
    this.callback = "";
    this.win = null;
    this.backid = "dialog_backid";
    //
    this.dialogInit = function() {
        var back = document.getElementById(this.backid);
        if (back == null) {
            var div = document.createElement("div");
            div.innerHTML = "<div id='" + this.backid + "' onmouseup='dialog.dialogMouseUp();return false;' style='position:absolute;z-index:10000;top:0;left:0;width:1px;height:1px;background-color:#666666;-moz-opacity:0.7;filter:alpha(opacity=70);'></div>";
            document.body.appendChild(div.firstChild);
        }
    };
    this.dialogMouseUp = function() {
        if (this.win != null) {
            if (this.win.closed == false) {
                if (navigator.appName == "Microsoft Internet Explorer") {
                    this.win.focus();
                }
                else {
                    this.win.open().close();
                    this.win.focus();
                }
            }
            else {
                this.dialogMin();
            }
        }
        else {
            this.dialogMin();
        }
    };
    this.dialogMin = function() {
        var back = document.getElementById(this.backid);
        if (back != null) {
            back.style.width = "1px";
            back.style.height = "1px";
        }
    };
    this.dialogMax = function() {
        var back = document.getElementById(this.backid);
        if (back != null) {
            var iWidth = document.body.scrollWidth;
            if (iWidth < 1000) {
                iWidth = 1000;
            }
            var iHeight = document.body.scrollHeight;
            if (iHeight < 1000) {
                iHeight = 1000;
            }
            back.style.width = iWidth + "px";
            back.style.height = iHeight + "px";
        }
    };
    this.dialogOpen = function(sUrl, iWidth, iHeight, arrUpParams, sCallBack, sWindowName) {
        this.params_up = arrUpParams;
        this.params_down = null;
        this.callback = sCallBack;
        this.dialogInit();
        this.dialogMax();
        var left = (screen.availWidth - iWidth) / 2;
        var top = (screen.availHeight - iHeight) / 2;
        var sProps = 'menubar=0,location=0,status=no,dialog=yes,modal=yes,scrollbars=0,resizable=1,width=' + iWidth + ',height=' + iHeight + ',left=' + left + ',top=' + top;
        if (this.win != null) {
            this.win.close();
            this.win = null;
        }
        this.win = window.open(sUrl, sWindowName, sProps);
        this.win.focus();

    };
    this.dialogClose = function(arrDownParams, bOk) {
        this.dialogMin();
        if (this.win != null) {
            this.win.close();
            this.win = null;
        }
        if (bOk) {
            this.params_down = arrDownParams;
            eval(this.callback);
        }
    };
}


/*   
*---------------  IsSpecialXmlChar()   -----------------   
*   onlypressInt()    
*   功能:判断输入的码值是否为 html 的特殊字符
*---------------   IsSpecialXmlChar()   -----------------   
*/
jQuery.fn.IsSpecialXmlChar = function() {
    $(this).bind("keydown", function(e) {
        var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
        if (e.shiftKey == true) {
            if (keyCode == 222 || keyCode == 188 || keyCode == 190 || keyCode == 50) {
                return false;
            }
        }
        else {
            if (keyCode == 222 || keyCode == 220) {
                return false;
            }
        }
        return true;
    })
};

function ValidateNotContainsXmlChar(obj, mess) {
    // var reg = new RegExp("[~`!@#$%^&*()\-+={}\[\]:;'<>,./?\\|'']+");
    var reg = new RegExp("[^a-zA-Z0-9\_\u4e00-\u9fa5]", "i");
    if (reg.test($(obj).val())) {
        if (message == "")
            message += "【" + mess + "】不能包含特殊字符 (<,\",>,',&)！";
        else
            message += "\r\n【" + mess + "】不能包含特殊字符 (<,\",>,',&)！";
        $(obj).addClass("errorStyle");
        SetDefaultControl(obj);
        obj.RemoveDropdownListErrCss();
    }
    else {
        $(obj).removeClass("errorStyle");
    }
}

/*   
*---------------  IsSpecialXmlChar(obj, reg, isEmpty, mess)   -----------------   
*   IsSpecialXmlChar(obj, reg, isEmpty, mess)    
*   功能:验证是否符合正则表达式
*   参数:obj,对象.   
*   参数:reg,正则表达式
*   参数:isEmpty,是否允许为空   
*   参数:mess,提示信息   
*---------------   IsSpecialXmlChar(obj, reg, isEmpty, mess)   -----------------   
*/
function CheckRegular(obj, reg, isEmpty, mess) {
    if (isEmpty && $(obj).val() == "") {
        $(obj).removeClass("errorStyle");
        return;
    }
    var re = new RegExp(reg, "");
    if (!re.test($(obj).val())) {
        if (message == "")
            message += "【" + mess + "】格式不正确！";
        else
            message += "\r\n【" + mess + "】格式不正确！";
        $(obj).addClass("errorStyle");
        SetDefaultControl(obj);
    }
    else {
        $(obj).removeClass("errorStyle");
    }
}