﻿// JScript 文件
function txtUser_blur()
{
    var userID = document.getElementById("ctl00_ContentPlaceHolder1_txtUserID").value;
    var chkDiv = document.getElementById("chkUserDiv");
    var re= /^[a-zA-Z_0-9]+$/;
    var tmp = false;
    if(userID == null || userID == "")
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "请输入用户名";        
    }
    else if(userID.length < 4 || userID.length > 20)
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "4-20个字符,包括:字母、数字、下划线";
    }    
    else if(!re.test(userID))
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "4-20个字符,包括:字母、数字、下划线";        
    }
    else
    {
        var result = getHttpRequestTxt("inc/checkUser.aspx?u=" + encodeURIComponent(userID));
        if(result == "1")
        {
            chkDiv.className = "wrong";
            chkDiv.innerHTML = "非常抱歉，此用户名已被使用";        
        }
        else
        {
            chkDiv.className = "right";
            chkDiv.innerHTML = "恭喜您，此用户名可以使用";
            tmp = true;
        }
    }
    
    if(tmp == true)
    {
        document.getElementById("ctl00_ContentPlaceHolder1_userRight").value = "1";
    }
    else
    {
        document.getElementById("ctl00_ContentPlaceHolder1_userRight").value = "0";
    }
    
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
}

function ctl_focus(chkDivId,txt)
{
    document.getElementById(chkDivId).className = "inputing";
    document.getElementById(chkDivId).innerHTML = txt;
    document.getElementById(chkDivId).parentNode.parentNode.parentNode.className = "margin_top inputing_td";
}
function optionalCtl_blur(chkDivId)
{
    document.getElementById(chkDivId).className = "wait";  
    document.getElementById(chkDivId).parentNode.parentNode.parentNode.className = "margin_top";   
}
function checkPwd(pwdCtl,chkDivId)
{
    var pwd = pwdCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    var tmp = false;
    if(pwd == "")
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "请输入登陆密码";        
    }
    else if(pwd.length < 6 || pwd.length > 20)
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "密码长度为6-20位，字母请区分大小写";       
    }
    else
    {
        chkDiv.className = "right";
        chkDiv.innerHTML = "密码长度为6-20位，字母请区分大小写";
        tmp = true;
    }
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    return tmp;
}
function checkPwdR(pwdrCtl,chkDivId)
{
    var pwd = document.getElementById("ctl00_ContentPlaceHolder1_txtPwd").value;
    var pwdR = pwdrCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    if(pwdR == "")
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "请再次输入登陆密码";
        return true;
    }
    else if(pwd != pwdR)
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "两次输入的登陆密码不一致";        
        return false;
    }
    else
    {
        chkDiv.className = "right";
        chkDiv.innerHTML = "请再次输入登陆密码";
        return true;
    }
}
function checkPayPwd(pwdCtl,chkDivId)
{
    var pwd = pwdCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    var tmp = false;
    if(pwd == "")
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "请输入支付密码";        
    }
    else if(pwd.length < 6 || pwd.length > 20)
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "密码长度为6-20位，字母请区分大小写";       
    }
    else
    {
        chkDiv.className = "right";
        chkDiv.innerHTML = "密码长度为6-20位，字母请区分大小写";
        tmp = true;
    }
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    return tmp;
}
function checkPayPwdR(pwdrCtl,chkDivId)
{
    var pwd = document.getElementById("ctl00_ContentPlaceHolder1_txtPayPwd").value;
    var pwdR = pwdrCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    if(pwd != pwdR)
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "两次输入的支付密码不一致";        
        return false;
    }
    else
    {
        chkDiv.className = "right";
        chkDiv.innerHTML = "请再次输入支付密码";
        return true;
    }    
}
function checkEmail(emailCtl,chkDivId)
{
    var email = emailCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    if(email == null || email == "")
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "请输入电子邮箱，用于取回密码使用，填写以后将不可修改";
        return false;
    }
    re=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if(!re.test(email))
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "您输入的电子邮件格式不正确，请重新填写！";
        return false;
    }
    
    chkDiv.className = "right";   
    return true;
}
function checkCredit(creditCtl,chkDivId)
{
    var credit = creditCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    
    if(credit == null || credit == "")
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "请如实填写身份证号码，填写以后将不可更改";
        return false;
    }
    
    if(checkCreditValue(credit) == false)
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "您输入的身份证号码格式不正确，请重新填写！";
        return false;
    }
    
//    if(credit.length != 15 && credit.length != 18)
//    {
//        chkDiv.className = "wrong";
//        chkDiv.innerHTML = "您输入的身份证号码格式不正确，请重新填写！";
//        return false;
//    }
//    else
//    {
//        for(i = 0;i < credit.length;i++)
//        {
//            c = credit.substring(i,1);
//            if(i == 0 && (isNaN(c) || c == 0))
//            {
//                chkDiv.className = "wrong";
//                chkDiv.innerHTML = "您输入的身份证号码格式不正确，请重新填写！";
//                return false;
//            }
//            else if(i == 17 && isNaN(c) && i != 'x' && i != 'X')
//            {
//                chkDiv.className = "wrong";
//                chkDiv.innerHTML = "您输入的身份证号码格式不正确，请重新填写！";
//                return false;
//            }
//            else if(isNaN(c))
//            {
//                chkDiv.className = "wrong";
//                chkDiv.innerHTML = "您输入的身份证号码格式不正确，请重新填写！";
//                return false;
//            }
//        }
//    }
    
    chkDiv.className = "right";   
    return true;
}

//校验身份证号码   
function checkCreditValue(idCard)
{   
    var id=idCard;   
    var id_length=id.length;   
  
    if (id_length==0)
    {
        return false;
    }
  
    if (id_length!=15 && id_length!=18)
    {   
        return false;
    }   
  
    if (id_length==15)
    {   
        yyyy="19"+id.substring(6,8);   
        mm=id.substring(8,10);   
        dd=id.substring(10,12);   
  
        if (mm>12 || mm<=0)
        {               
            return false;   
        }   
  
        if (dd>31 || dd<=0)
        {   
            return false;   
        }   
  
        birthday=yyyy+ "-" +mm+ "-" +dd;   
  
        if ("13579".indexOf(id.substring(14,15))!=-1)
        {   
            sex="1";   
        }
        else
        {   
            sex="2";   
        }   
    }
    else if (id_length==18)
    {   
        if (id.indexOf("X") > 0 && id.indexOf("X")!=17 || id.indexOf("x")>0 && id.indexOf("x")!=17)
        {               
            return false;   
        }   
  
        yyyy=id.substring(6,10);   
        if (yyyy>2200 || yyyy<1930)
        {
            return false;   
        }   
  
        mm=id.substring(10,12);   
        if (mm>12 || mm<=0)
        {
            return false;   
        }   
  
        dd=id.substring(12,14);   
        if (dd>31 || dd<=0)
        {
            return false;   
        }   
  
        if (id.charAt(17)=="x" || id.charAt(17)=="X")   
        {   
            if ("x"!=GetVerifyBit(id) && "X"!=GetVerifyBit(id))
            { 
                return false;   
            }   
  
        }
        else
        {   
            if (id.charAt(17)!=GetVerifyBit(id))
            { 
                return false;   
            }   
        }   
  
        birthday=id.substring(6,10) + "-" + id.substring(10,12) + "-" + id.substring(12,14);   
        if ("13579".indexOf(id.substring(16,17)) > -1)
        {   
            sex="1";   
        }
        else
        {   
            sex="2";   
        }   
    }   
  
    return true;   
}   
//15位转18位中,计算校验位即最后一位   
function GetVerifyBit(id){   
    var result;   
    var nNum=eval(id.charAt(0)*7+id.charAt(1)*9+id.charAt(2)*10+id.charAt(3)*5+id.charAt(4)*8+id.charAt(5)*4+id.charAt(6)*2+id.charAt(7)*1+id.charAt(8)*6+id.charAt(9)*3+id.charAt(10)*7+id.charAt(11)*9+id.charAt(12)*10+id.charAt(13)*5+id.charAt(14)*8+id.charAt(15)*4+id.charAt(16)*2);   
    nNum=nNum%11;   
    switch (nNum) {   
       case 0 :   
          result="1";   
          break;   
       case 1 :   
          result="0";   
          break;   
       case 2 :   
          result="X";   
          break;   
       case 3 :   
          result="9";   
          break;   
       case 4 :   
          result="8";   
          break;   
       case 5 :   
          result="7";   
          break;   
       case 6 :   
          result="6";   
          break;   
       case 7 :   
          result="5";   
          break;   
       case 8 :   
          result="4";   
          break;   
       case 9 :   
          result="3";   
          break;   
       case 10 :   
          result="2";   
          break;   
    }   
    //document.write(result);   
    return result;   
}   
//15位转18位   
function Get18(idCard)
{   
     if (CheckValue(idCard))
     {   
          var id = idCard;   
          var id18=id;   
          if (id.length==0)
          {
            return false;   
          }   
          if (id.length==15)
          {   
               if (id.substring(6,8)>20)
               {   
                    id18=id.substring(0,6)+"19"+id.substring(6,15);   
               }
               else
               {   
                    id18=id.substring(0,6)+"20"+id.substring(6,15);   
               }
          
               id18=id18+GetVerifyBit(id18);   
          }   
          
          return id18;   
     }
     else
     {   
        return false;   
     }   
}  

function checkAccountName(nameCtl,chkDivId)
{
    var name = nameCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    if(name == null || name == "" || name.length < 2 || name == encodeURIComponent(name))
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "为保证您的资金安全，请如实填写，填写以后将不能更改";
        return false;
    }
    chkDiv.className = "right";
    chkDiv.innerHTML = "为保证您的资金安全，请如实填写，填写以后将不能更改";
    return true;
}

function checkMobile(mobileCtl,chkDivId)
{
    var mobile = mobileCtl.value;
    var chkDiv = document.getElementById(chkDivId);
    chkDiv.parentNode.parentNode.parentNode.className = "margin_top";
    if(mobile == null || mobile == "")
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "请输入手机号码";
        return false;
    }
    
    if(!(/^13\d{9}$/g.test(mobile)) && !(/^14\d{9}$/g.test(mobile)) && !(/^15\d{9}$/g.test(mobile)) && !(/^18\d{9}$/g.test(mobile)))
    {
        chkDiv.className = "wrong";
        chkDiv.innerHTML = "您输入的手机号码不正确，请重新填写！";
        return false;
    }
    
    chkDiv.className = "right";   
    return true;
}
function checkPwdStrength(pwdCtl,preStr)
{
    var pwd = pwdCtl.value;
    var s = document.getElementById(preStr + "_s");
    var m = document.getElementById(preStr + "_m");
    var l = document.getElementById(preStr + "_l");
    var t = document.getElementById(preStr + "_t");
    if(pwd.length < 6)
    {
        s.className = "mima_false";
        m.className = "mima_false";
        l.className = "mima_false";
        t.innerHTML = "无";
    }
    else if(pwd.length >= 6 && pwd.length <= 8)
    {
        s.className = "mima_true";
        m.className = "mima_false";
        l.className = "mima_false";
        t.innerHTML = "弱";
    }
    else if(pwd.length > 8 && pwd.length < 12)
    {
        s.className = "mima_true";
        m.className = "mima_true";
        l.className = "mima_false";
        t.innerHTML = "中";
    }
    else
    {
        s.className = "mima_true";
        m.className = "mima_true";
        l.className = "mima_true";
        t.innerHTML = "强";
    }
}

function checkForm()
{
    var ctl = document.getElementById("ctl00_ContentPlaceHolder1_userRight");
    if(ctl.value != "1")
    {
        alert("用户名不正确，请重新输入");
        return false;
    }
    ctl = document.getElementById("ctl00_ContentPlaceHolder1_txtPwd");
    if(checkPwdStrength(ctl,'pwdStrength') == false)
    {
        alert("请输入登陆密码");        
        return false;
    }
    ctl = document.getElementById("ctl00_ContentPlaceHolder1_txtPwdR");
    if(checkPwdR(ctl,'chkPwdRDiv') == false)
    {
        alert("请再次输入登陆密码");
        return false;
    }    
    ctl = document.getElementById("ctl00_ContentPlaceHolder1_txtEmail");
    if(checkEmail(ctl,'chkEmailDiv') == false)
    {
        alert("电子邮箱地址不正确");        
        return false;
    }
    ctl = document.getElementById("ctl00_ContentPlaceHolder1_chkUserProtocol");
    if(ctl.checked == false)
    {
        alert("请先阅读并同意\"uu898用户服务协议\"");
        return false;
    }
    return true;
}
