﻿var boolemail,boolname,boolpwd,boolrepwd,boolvaliimg;
//验证邮箱
function ValidatorEmail()
{
    var email = document.getElementById("txtEmail").value;
    
    if(cTrim(email,0) != "")
    {
        if(ismail(email))
        {
            Register.ValidatorUserEamil(email,GetEmailErrorInfo);
        }
        else
        {
            document.getElementById("imgEamil").style.display="";
            var divemail = document.getElementById("diveamil");
            document.getElementById("trEmail").style.display = "";
            document.getElementById("imgEamil").src = "../../Common/Images/cuowu.gif";
            divemail.innerHTML = "<font color='red'>请输入正确的Email地址！</font>";
        }
    }
    else
    {
        document.getElementById("imgEamil").style.display="none";
        document.getElementById("trEmail").style.display = "none";
    }
}
function GetEmailErrorInfo(response)
{
    document.getElementById("imgEamil").style.display="";
    var divemail = document.getElementById("diveamil");
    if (response.value != null && response.value != "")
    {   
        document.getElementById("trEmail").style.display = "";
        document.getElementById("imgEamil").src = "../../Common/Images/cuowu.gif";
        divemail.innerHTML = "<font color='red'>"+response.value+"</font>";
        boolemail = false;
    }
    else
    {
        document.getElementById("trEmail").style.display = "none";
        document.getElementById("imgEamil").src = "../../Common/Images/zhengque.gif";
        divemail.innerHTML = "";
        boolemail = true;
    }
    return true;
}

function ismail(mail)
{
    return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}

//验证用户昵称
function ValidatorName()
{
    var name = document.getElementById("txtNiceName").value;
    if(cTrim(name,0) != "")
    {
        if(name.indexOf("'") == -1 && name.indexOf('"') == -1 && name.indexOf('%') == -1 && name.indexOf('#') == -1)
            Register.ValidatorUserName(name,GetUserNameErrorInfo);
        else
        {
            var divename = document.getElementById("divNiceName");
            document.getElementById("trNoceName").style.display = "";
            document.getElementById("imgNiceName").src = "../../Common/Images/cuowu.gif";
            divename.innerHTML = "<font color='red'>用户名不能包含特殊字符！</font>";
            boolname = false;
        }
    }
    else
    {
        document.getElementById("imgNiceName").style.display="none";
        document.getElementById("trNoceName").style.display = "none";
    }
}
function GetUserNameErrorInfo(response)
{
    document.getElementById("imgNiceName").style.display="";
    var divename = document.getElementById("divNiceName");
    if (response.value != null && response.value != "")
    {   
        document.getElementById("trNoceName").style.display = "";
        document.getElementById("imgNiceName").src = "../../Common/Images/cuowu.gif";
        divename.innerHTML = "<font color='red'>"+response.value+"</font>";
        boolname = false;
    }
    else
    {
        document.getElementById("trNoceName").style.display = "none";
        document.getElementById("imgNiceName").src = "../../Common/Images/zhengque.gif";
        divename.innerHTML = "";
        boolname = true;
    }
    return true;
}
//验证密码
function ValidatorPwd()
{   
    var pwd = document.getElementById("txtPwd").value;
    document.getElementById("imgPwd").style.display = "";
    var divpwd = document.getElementById("divPwd");
    var sun = pwd.replace(/[^x00-xFF]/g,'**').length;
    if(cTrim(pwd,0) != "")
    {
        if(sun >5 && sun<16)
        {
            document.getElementById("trPwd").style.display = "none";
            document.getElementById("imgPwd").src = "../../Common/Images/zhengque.gif";
            divpwd.innerHTML = "";
            document.getElementById("txtRePwd").readOnly = false;
            if(cTrim(document.getElementById("txtRePwd").value,0)!="")
                ValidatorRePwd();
            boolpwd = true;
        }
        else
        {
            document.getElementById("trPwd").style.display = "";
            document.getElementById("imgPwd").src = "../../Common/Images/cuowu.gif";
            divpwd.innerHTML = "<font color='red'>密码必须在6到15位之间！</font>";
            boolpwd = false;
        }
    }
    else
    {
        document.getElementById("trPwd").style.display = "none";
        document.getElementById("imgPwd").src = "../../Common/Images/zhengque.gif";
        document.getElementById("imgPwd").style.display = "none";
        divpwd.innerHTML = "";
        boolpwd = false;
        ValidatorRePwd()
    }
    return boolpwd;
}
//验证重复密码
function ValidatorRePwd()
{  
    var pwd = document.getElementById("txtPwd").value;
    var Repwd = document.getElementById("txtRePwd").value;
    document.getElementById("imgRePwd").style.display = "";
    var divRePwd = document.getElementById("divRePwd");
    if(cTrim(Repwd,0) != "")
    {
        if(pwd == Repwd)
        {
            document.getElementById("trRePwd").style.display = "none";
            document.getElementById("imgRePwd").src = "../../Common/Images/zhengque.gif";
            divRePwd.innerHTML = "";
            boolrepwd = true;
        }
        else
        {
            document.getElementById("trRePwd").style.display = "";
            document.getElementById("imgRePwd").src = "../../Common/Images/cuowu.gif";
            divRePwd.innerHTML = "<font color='red'>两次密码输入不一致，请重新输入！</font>";
            boolrepwd = false;
        }
    }
    else
    {
        document.getElementById("trRePwd").style.display = "none";
        document.getElementById("imgRePwd").src = "../../Common/Images/zhengque.gif";
        document.getElementById("imgRePwd").style.display = "none";
        divRePwd.innerHTML = "";
        boolrepwd = false;
    }
}
//验证验证码
function ValidatorImageCode()
{
    var txtValiCode = document.getElementById("txtValiCode").value;
    if(cTrim(txtValiCode,0) != "")
    {
        Register.ValidatorValiCode(txtValiCode,GetValiCodeErrorInfo);
    }
    else
    {
        document.getElementById("imgValiCode").style.display="none";
        document.getElementById("trValiCode").style.display = "none";
    }
}




function GetValiCodeErrorInfo(response)
{
    document.getElementById("imgValiCode").style.display="";
    var divemail = document.getElementById("divValiCode");
    if (response.value != null && response.value != "")
    {   
        document.getElementById("trValiCode").style.display = "";
        document.getElementById("imgValiCode").src = "../../Common/Images/cuowu.gif";
        divemail.innerHTML = "<font color='red'>"+response.value+"</font>";
        document.getElementById("ValiCode").src="../../Common/Public/Other/ValidatorImg.aspx?"+Math.random();
        boolvaliimg=false;
    }
    else
    {
        document.getElementById("trValiCode").style.display = "none";
        document.getElementById("imgValiCode").src = "../../Common/Images/zhengque.gif";
        divemail.innerHTML = "";
        boolvaliimg=true;
    }
    return true;
}
//重新加载验证码
function reloadvcode()
{
    document.getElementById("txtValiCode").value = "";
    document.getElementById("imgValiCode").style.display="none";
    document.getElementById("trValiCode").style.display="none";
    document.getElementById("ValiCode").src="../../Common/Public/Other/ValidatorImg.aspx?"+Math.random();
}
function reloadimg()
{
    document.getElementById("ValiCode").src="../../Common/Public/Other/ValidatorImg.aspx?"+Math.random();
    document.getElementById("txtValiCode").value = "";
}
function ValidatorCheckContext()
{
    var check = document.getElementById("cboxOk");
    
    
    var HidYear  = document.getElementById("HidYear");
    var HidDay   = document.getElementById("HidDay");
    var HidMonth = document.getElementById("HidMonth");
    
    if(check.checked == true)
    {
        return SunValidator();
    }
    else
    {
        alert("请阅读注册协议！");
        return false;
    }
}

function SunValidator()
{
    if(boolemail == true && boolname == true && boolpwd ==true && boolrepwd==true && boolvaliimg == true)
    {
        return true;
    }
    else
    {
        alert("请认真填写注册信息！");
        return false;
    }
}

//清除空格
//****************************************************************
// Description: sInputString 为输入字符串，iType为类型，分别为
// 0 - 去除前后空格; 1 - 去前导空格; 2 - 去尾部空格
//****************************************************************
function cTrim(sInputString,iType)
{
    var sTmpStr = ' '
    var i = -1

    if(iType == 0 || iType == 1)
    {
        while(sTmpStr == ' ')
        {
            ++i
            sTmpStr = sInputString.substr(i,1)
        }
        sInputString = sInputString.substring(i)
    }

    if(iType == 0 || iType == 2)
    {
        sTmpStr = ' '
        i = sInputString.length
        while(sTmpStr == ' ')
        {
            --i
            sTmpStr = sInputString.substr(i,1)
        }
        sInputString = sInputString.substring(0,i+1)
    }
    return sInputString
}

//快速注册
function showInfo(obj)
{
    var info = document.getElementById("Info");
    if(obj == 1)
        info.innerHTML= "提示：请填写真实邮箱，以便找回密码。";
    else if (obj == 2)
        info.innerHTML= "提示：给自己起个名字，中英文都可以。";   
    else if (obj == 3)
        info.innerHTML= "提示：6~15位，字母(区分)大小写或数字 。";  
    else if (obj == 4)
        info.innerHTML= "提示：再输入一遍刚才的密码。";  
    else if (obj == 5)
        info.innerHTML= "<span class=\"link_12_blu_chi_lin_blu\">提示：请输入右边图片中的文字,可<a href=\"javascript:void(0)\" onclick=\"reloadimg()\">点击切换图片</a></span>";
}

function showError(val)
{
    var info = document.getElementById("Error");
    if( val != null && val != "")
        info.innerHTML= "错误：" + val;
    else
        info.innerHTML="&nbsp;";
}
//验证用户名
function VEmail()
{
    var email = document.getElementById("txtEmail").value;
    if(cTrim(email,0) != "")
    {
        if(ismail(email))
            PlayGames.ValidatorUserEamil(email,ShowErrorMessage);
        else
            showError("Email格式有误！");
    }
    else
        document.getElementById("Error").innerHTML = "&nbsp;";
}
//验证用户昵称
function ValidatorName2()
{
    var name = document.getElementById("txtName").value;
    if(cTrim(name,0) != "")
        PlayGames.ValidatorUserName(name,ShowErrorMessage);
    else
        showError("昵称不能为空！");
}
//验证密码
function ValidatorPwd2()
{   
    var pwd = document.getElementById("txtRePassword").value;
    var sun = pwd.replace(/[^x00-xFF]/g,'**').length;
    if(sun >5 && sun<16)
    {
        showError("");
        if(cTrim(document.getElementById("txtRRepassword").value,0)!="")
            ValidatorRePwd2();
        return true;
    }
    else
    {
        showError("密码必须在6到15位之间！");
        return false;
    }
}
//验证重复密码
function ValidatorRePwd2()
{
    var pwd = document.getElementById("txtRePassword").value;
    var Repwd = document.getElementById("txtRRepassword").value;
    if(pwd == Repwd)
        showError("");
    else
        showError("两次密码输入不一致，请重新输入！");
}
//验证验证码
function ValidatorImageCode2()
{
    var txtValiCode = document.getElementById("txtValiCode").value;
    if(cTrim(txtValiCode,0) != "")
    {
        PlayGames.ValidatorValiCode(txtValiCode,ShowErrorMessage);
    }
    else
        showError("请输入验证码");
}

//获得并设置错误信息
function ShowErrorMessage(response)
{
    showError(response.value);
}

function sucesspage()
{
    document.getElementById("divExpLogin").style.className="divlogin";
    document.getElementById("divSuccess").style.display = "block";
    document.getElementById("Table").style.display = "none";
    document.getElementById("tabLogin").style.display = "none";
}
