﻿function G(id) {
    return document.getElementById(id);
}

String.prototype.Trim = function()      //去除字符串前后空格
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function SearchFocus(con) {
    if (con.value == "输入查找的设备名...") {
        con.value = "";
    }
}

function SearchBlur(con) {
    if (con.value.Trim() == "") {
        con.value = "输入查找的设备名...";
    }
}


//检查秘密强度
function CheckPasswordStrength1(txtPwd, controlId)//6-16
{
    var length = txtPwd.value.length;
    var obj = G(controlId);
    if (length > 5 && length < 10)//6-9
    {
        obj.innerHTML = "密码强度:弱";
        obj.style.background = "pink";

    }
    else if (length > 9 && length < 14)//10-13
    {
        obj.innerHTML = "密码强度:中";
        obj.style.background = "#FFFF80";
    }
    else if (length > 13 && length < 17)//14-16
    {
        obj.innerHTML = "密码强度:强";
        obj.style.background = "#C0FFC0";
    }
    else {
        obj.innerHTML = "";
    }
}

//v:密码 id:显示强度的控件
function CheckPasswordStrength2(v, id) {
    var lv = -1;
    if (v.match(/[a-z]/ig)) { lv++; }
    if (v.match(/[0-9]/ig)) { lv++; }
    if (v.match(/(.[^a-z0-9])/ig)) { lv++; }
    if (v.length < 8 && lv > 0) { lv--; }

    iss.reset(id);
    switch (lv) {
        case 0:
            iss.level0(id);
            break;
        case 1:
            iss.level1(id);
            break;
        case 2:
            iss.level2(id);
            break;
        default:
            iss.reset(id);
    }
}

var iss =
{
    reset: function(id) {
        G(id).className = "state0";
    },
    level0: function(id) {
        G(id).className = "state1";
    },
    level1: function(id) {
        G(id).className = "state2";
    },
    level2: function(id) {
        G(id).className = "state3";
    }
}

//关闭窗体
function CloseAll() {
    window.opener = null;
    window.open("", '_self', "");
    window.close();
}


/* 权限管理选中菜单 */
function CheckAll(chk) {
    var name1 = chk.id.substring(0, chk.id.indexOf('_chk'))
    var items = document.getElementsByTagName("input");
    for (i = 0; i < items.length; i++) {
        var e = items[i];
        if (e.type == 'checkbox') {
            var name2 = e.id.substring(0, e.id.indexOf('_chk'))
            if (name1 == name2)//取出_chk前的用户控件名称相同则在一个里面的
            {
                e.checked = chk.checked;
            }
        }
    }
}

function CheckOnly(paramId) {
    var name1 = paramId.substring(0, paramId.indexOf('_chk'));
    var items = document.getElementsByTagName("input");
    for (i = 0; i < items.length; i++) {
        var e = items[i];
        var eId = e.id;
        var name2 = eId.substring(0, eId.indexOf('_chk'))

        if (e.type == 'checkbox' && name1 == name2) {
            if (eId.indexOf('chkParentMenu') != -1)//如果是这个控件里的父checkbox
            {
                e.checked = true;
                break;
            }
        }
    }
}

//导航显示隐藏下拉菜单
function navover(nav_sub) {
    G("nav_sub" + nav_sub).className = 'nav_sub';
}
function navout(nav_sub) {
    G("nav_sub" + nav_sub).className = 'hidden';
}

//用户名显示下拉菜单
function showMenu(a, b) {
    G(a).style.display = "block";
    G(b).className = "username item-expand hover";
}

function hideMenu(a,b) {
    G(a).style.display = "none";
    G(b).className = "username item-expand";
}

//弹出提示
function showMsg(text,time)
{
    if($("#message").is(":visible"))    //隐藏了才显示
    { 
        return; 
    }
    if(!time)
    {
        time=5000;  //默认5秒
    }
    var topHeight = document.documentElement.scrollTop + document.documentElement.clientHeight - 145;
    $(document.body).prepend('<div id="message" style="background:url(images/msgbg.gif) no-repeat;z-index:10002;width:250px;height:145px;position:absolute;right:20;overflow:hidden;text-align: left;font-size:14px;color:#000;top:'+ topHeight+'px"><div style="width:100%;margin:45px 8px 8px 8px;overflow:hidden;">'+text+'</div></div>');
    $("#message").fadeIn();
    setTimeout(function(){$('#message').fadeOut(1000)},time);
}

//检查秘密强度
function CheckPasswordStrength(txtPwd,controlId)//6-16
{
    var length = txtPwd.value.length;
    var obj = G(controlId);
    if(length>5 && length<10)//6-9
    {
        obj.innerHTML="密码强度:弱";
        obj.style.background="pink";

    }
    else if(length>9 && length<14)//10-13
    {
        obj.innerHTML="密码强度:中";
        obj.style.background="#FFFF80";
    }
    else if(length>13 && length<17)//14-16
    {
        obj.innerHTML="密码强度:强";
        obj.style.background="#C0FFC0";
    }
    else
    {
        obj.innerHTML="";
    }
}

