

/**************************************************************************************/
/*
屏蔽F5,右键
**/
/*
var oLastBtn = 0, bIsMenu = false
if (window.Event) {
document.captureEvents(Event.MOUSEUP);
}

function nocontextmenu() {
event.cancelBubble = true;
event.returnvalue = false;
return false;
}

function norightclick(e) {
if (window.Event) {
if (e.which != 1) {
return false;
}
}
else
if (event.button != 1) {
event.cancelBubble = true;
event.returnvalue = false;
return false;
}
}

document.oncontextmenu = nocontextmenu;
document.onmousedown = norightclick;

function onKeyDown() {
if ((event.altKey) || ((event.keyCode == 8) && (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password")) || ((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82))) || (event.keyCode == 116)) {
event.keyCode = 0;
event.returnvalue = false;
return false;
}
if (event.keyCode == 27) {
OnEditHide();
}
}
document.onkeydown = onKeyDown;
/**************************************************************************************/
function format(str, args) {
    var result = str
    for (var i = 0; i < args.length; i++) {
        result = result.replace(/%s/, args[i]);
    }
    return result;
}
function G(id) {
    return document.getElementById(id);
}
function F(id) {
    return G(id).value;
}
function highlight(B) {
    var A = B.className;
    B.className = "heightlight";
    B.onmouseout = function() {
        B.className = A;
    };
}

/**************************************************************************************/
/*
表格全选代码
参数:1.触发全选的input对象,一般是this
2.全选的表格id
*/
function SelectAll(checkobj, gridobjid) {
    var tbl = document.getElementById(gridobjid);
    var ins = tbl.getElementsByTagName("input");
    for (var i = 0; i < ins.length; i++) {
        var _temp = ins[i];
        if (_temp.type == "checkbox") {
            _temp.checked = checkobj.checked;
        }
    }
}

/*
获取选中对象的值
参数:操作的表格id
*/
function GetSelectValue(gridobjid) {
    var tbl = document.getElementById(gridobjid);
    if (tbl == null) {
        return '';
    }
    var ins = tbl.getElementsByTagName("input");
    var _te = "";
    var tempid = "";
    for (var i = 0; i < ins.length; i++) {
        var _temp = ins[i];
        if (_temp.type == "checkbox") {
            tempid = _temp.id;
            if (tempid == "id") {
                if (_temp.checked == true) {
                    _te += _temp.value + ",";
                }
            }
        }
    }
    _te = _te.substring(0, _te.length - 1);
    return _te;
}
/**************************************************************************************/
/**************************************************************************************/
/*
删除方法
*/
function OnDelete() {
    var idstring = GetSelectValue(grid);
    if (idstring.length == 0) {
        alert("请选择操作的数据");
        return false;
    }
    document.getElementById(Idstring).value = GetSelectValue(grid);
    if (confirm('您确定要处理这些数据吗?')) {
        btnclick();
        return true;
    }
    else {
        return false;
    }
}
/*
编辑方法
*/
function OnEdit() {
    var idstring = GetSelectValue(grid);
    if (idstring.length == 0) {
        alert("请选择一条数据");
        return false;
    }
    var id = idstring.split(',')[0];
    document.getElementById(Idstring).value = id;

    btnclick();
    return true;
}

function btnclick() {
    Ucren.blind();
    Ucren.showLoading("<img src='/Images/loading.gif' width=16 height=16 border=0>正在加载,请稍等...")
}
/**************************************************************************************/

function OpenNewWindow() {
    var wide = window.screen.availWidth - 10;
    var high = window.screen.availHeight - 45;
    var arg = "menubar=no,toolbar=no,location=no,status=yes,resizable=yes,scrollbars=yes,width=" + wide + ",height=" + high + ",left=0,top=0";
    var myD = new Date();
    var mySeconds = myD.getSeconds();
    window.open(window.location, mySeconds, arg);
}
function check() {
    if (typeof (nullfiled) != 'undefined') {
        if (!YanZheng(nullfiled, messagesSourceCn[1][1], ValidateIsEmpty)) {
            //不允许为空的字段
            return false;
        }
    }
    if (typeof (numberfiled) != 'undefined') {
        if (!YanZheng(numberfiled, messagesSourceCn[2][1], ValidateNumber)) {
            //只能是数字的字段
            return false;
        }
    }
    if (typeof (datefiled) != 'undefined') {
        if (!YanZheng(datefiled, messagesSourceCn[5][1], ValidateDate)) {
            //只能是日期的字段
            return false;
        }
    }

    if (typeof (emailfiled) != 'undefined') {
        if (!YanZheng(emailfiled, messagesSourceCn[6][1], ValidateEmail)) {
            //只能是邮箱的字段
            return false;
        }
    }

    if (typeof (urlfiled) != 'undefined') {
        if (!YanZheng(urlfiled, messagesSourceCn[7][1], ValidateUrl)) {
            //只能是URL的字段
            return false;
        }
    }

    if (typeof (mobilephonefiled) != 'undefined') {
        if (!YanZheng(mobilephonefiled, messagesSourceCn[19][1], ValidateMobilePhone)) {
            //只能是手机号码的字段
            return false;
        }
    }

    if (typeof (integerfiled) != 'undefined') {
        if (!YanZheng(integerfiled, messagesSourceCn[8][1], ValidateInteger)) {
            //只能是整数的字段
            return false;
        }
    }

    if (typeof (phonefiled) != 'undefined') {
        if (!YanZheng(phonefiled, messagesSourceCn[18][1], ValidatePhone)) {
            //只能是正确的电话号码,如:0920-29392929的字段
            return false;
        }
    }

    if (typeof (ipfiled) != 'undefined') {
        if (!YanZheng(ipfiled, messagesSourceCn[17][1], ValidateIp)) {
            //只能是正确的IP地址的字段
            return false;
        }
    }

    if (typeof (chinesefiled) != 'undefined') {
        if (!YanZheng(chinesefiled, messagesSourceCn[16][1], ValidateChinese)) {
            //只能是中文的字段
            return false;
        }
    }

    if (typeof (alphanumfiled) != 'undefined') {
        if (!YanZheng(alphanumfiled, messagesSourceCn[4][1], ValidateAlphanum)) {
            //只能是英文字母或是数字的字段
            return false;
        }
    }

    if (typeof (minlengthfiled) != 'undefined') {
        if (!YanZheng(minlengthfiled, messagesSourceCn[11][1], ValidateMinlength, 48)) {
            //只能是最小长度为%s,当前长度为%s的字段
            return false;
        }
    }

    if (typeof (maxlengthfiled) != 'undefined') {
        if (!YanZheng(maxlengthfiled, messagesSourceCn[12][1], ValidateMaxlength, 48)) {
            //只能是最大长度为%s,当前长度为%s的字段
            return false;
        }
    }

    else {
        BtnOk();
    }
}

function BtnOk() {
    btnclick();
    return true;
}

/// <reference path="global.js" />

messagesSourceCn = [
	['validation-failed', '验证失败.'], //0
	['required', '请输入值.'], //1
	['validate-number', '请输入有效的数字.'], //2
	['validate-alpha', '请输入英文字母.'], //3
	['validate-alphanum', '请输入英文字母或是数字,其它字符是不允许的.'], //4
	['validate-date', '请输入有效的日期.'], //5
	['validate-email', '请输入有效的邮件地址,如 username@example.com.'], //6
	['validate-url', '请输入有效的URL地址.'], //7
	['validate-integer', '请输入正确的整数'], //8
	['min-value', '最小值为%s'], //9
	['max-value', '最大值为%s'], //10
	['min-length', '最小长度为%s,当前长度为%s.'], //11
	['max-length', '最大长度为%s,当前长度为%s.'], //12
	['validate-int-range', '输入值应该为 %s 至 %s 的整数'], //13
	['validate-float-range', '输入值应该为 %s 至 %s 的数字'], //14
	['validate-length-range', '输入值的长度应该在 %s 至 %s 之间,当前长度为%s'], //15
	['validate-chinese', '请输入中文'], //16
	['validate-ip', '请输入正确的IP地址'], //17
	['validate-phone', '请输入正确的电话号码,如:0920-29392929,当前长度为%s.'], //18
	['validate-mobile-phone', '请输入正确的手机号码,当前长度为%s.']//19
]

function YanZheng(fileds, msg, fun, ages) {
    var filed = fileds.split(',');

    var v, id, msgs;
    var res = true;
    for (var i = 0; i < filed.length; i++) {
        id = filed[i];
        if (id == '') {
            continue;
        }
        if (ages) {
            var arr = new Array();
            arr[0] = ages;
            arr[1] = F(id).length;
            msgs = format(msg, arr);
        }

        v = F(id);
        if (fun(v, ages)) {
            if (!msgs) {
                msgs = msg;
            }
            InnerText(id, msgs);
            SetFocus(id);
            res = false;
            break;
        }
        else {
            RemoverInner(id);
        }
    }
    return res;
}

function InnerText(id, msg) {
    var errorobj = G("span" + id);
    if (errorobj != null) {
        errorobj.innerHTML = msg;
    }
    else {
        alert(msg);
    }
}
function RemoverInner(id) {
    var errorobj = G("span" + id);
    if (errorobj != null) {
        errorobj.innerHTML = '';
    }
}
function SetFocus(id) {
    G(id).focus();
}

//请输入值 空值返回真
function ValidateIsEmpty(v) {
    return ((v == null) || (v.length == 0) || /^\s+$/.test(v));
}
//不是数字返回真
function ValidateNumber(v) {
    return ValidateIsEmpty(v) || !(!isNaN(v) && !/^\s+$/.test(v));
}
//请输入英文字母 不是英文字母返回真
function ValidateAlpha(v) {
    return ValidateIsEmpty(v) || !/^[a-zA-Z]+$/.test(v);
}
//请输入英文字母或是数字 不是英文字母或是数字返回真
function ValidateAlphanum(v) {
    return ValidateIsEmpty(v) || /\W/.test(v);
}
//请输入有效的日期 不是有效的日期返回真
function ValidateDate(v) {
    return ValidateIsEmpty(v) || !checkDate(v);
}
//请输入有效的邮件地址 不是有效的有效的邮件地址返回真
function ValidateEmail(v) {
    return ValidateIsEmpty(v) || !/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v);
}
//请输入有效的URL地址 不是有效的URL地址返回真
function ValidateUrl(v) {
    return ValidateIsEmpty(v) || !/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v);
}
//请输入正确的整数
function ValidateInteger(v) {
    return ValidateIsEmpty(v) || !(/^[-+]?[\d]+$/.test(v));
}
//请输入中文
function ValidateChinese(v) {
    return ValidateIsEmpty(v) || !(/^[\u4e00-\u9fa5]+$/.test(v));
}
//请输入正确的IP地址
function ValidateIp(v) {
    return ValidateIsEmpty(v) || !(/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(v));
}
//请输入正确的电话号码
function ValidatePhone(v) {
    return ValidateIsEmpty(v) || !/^((0[1-9]{3})?(0[12][0-9])?[-])?\d{6,8}$/.test(v);
}
//请输入正确的手机号码
function ValidateMobilePhone(v) {
    return ValidateIsEmpty(v) || !(/(^0?[1][35][0-9]{9}$)/.test(v));
}
//最大长度为
function ValidateMaxlength(v, args) {
    return ValidateIsEmpty(v) || !(v.length <= parseInt(args));
}
//最小长度为
function ValidateMinlength(v, args) {
    return ValidateIsEmpty(v) || !(v.length >= parseInt(args));
}

//输入值应该为 %s 至 %s 的整数
function ValidateIntrange(v, args1, args2) {
    return ValidateIsEmpty(v) || !(parseFloat(v) >= parseFloat(args1) && parseFloat(v) <= parseFloat(args2));
}
//输入值应该为 %s 至 %s 的数字
function ValidateFloatrange(v, args1, args2) {
    return ValidateIsEmpty(v) || !(parseInt(v) >= parseInt(args1) && parseInt(v) <= parseInt(args2));
}

//输入值的长度应该在 %s 至 %s 之间,当前长度为%s
function ValidateLengthrange(v, args1, args2) {
    return ValidateIsEmpty(v) || !(v.length >= parseInt(args1) && v.length <= parseInt(args2));
}
function checkDate(str) {
    try {
        if (/\-/.test(str) && /\//.test(str)) {
            return false;
        }

        str = str.replace(/\-/g, "/"); //必须要用正则来替换，否则只替换第一个出现的字符串
        var tmp = str.split("/");

        if (tmp.length > 3) {
            return false;
        }

        var tempDate = new Date(str);

        var year = tempDate.getYear();
        var month = tempDate.getMonth() + 1;
        var day = tempDate.getDate();

        //判断中间不允许有空格
        if (/\s/.test(tmp[0]) || /\s/.test(tmp[1]) || /\s/.test(tmp[2])) {
            alert("中间不允许出现空格！");
            return false;
        }

        //判断年、月、日位数,可以根据自己需求修改
        if (tmp[0].length < 3 || tmp[0].length > 4) {
            return false;
        }

        if (tmp[1].length > 2) {
            return false;
        }

        if (tmp[2].length > 2) {
            return false;
        }
        //判断年、月、日位数,可以根据自己需求修改

        if (tempDate != null) {
            return year == tmp[0] && month == tmp[1] && day == tmp[2];
        } else {
            return false;
        }
    } catch (ex) {
        //alert(ex.message);
        return false;
    }
}