﻿function chkReg(chkType) {
    //chkType=1,是注册，2是修改
    var temp = "";

    if (g("txt_cnickname").value == "") {
        alert("请输入用户名！");
        g("txt_cnickname").focus();
        return false;
    }

    if (!isalphanumber(g("txt_cnickname").value)) {
        alert("用户名只能是英文字母、数字或者下划线组成的字符串!");
        g("txt_cnickname").focus();
        return false;

    }


    if (g("txt_cnickname").value.length > 20 || g("txt_cnickname").value.length < 3) {
        alert("用户名的长度限制为3-20个字符!");
        g("txt_cnickname").focus();
        return false;

    }




    if (g("txt_cname").value == "") {
        alert("请输入昵称！");
        g("txt_cname").focus();
        return false;
    }

    if (!isUserName(g("txt_cname").value)) {
        alert("昵称只能包含汉字、数字、字母、下划线且不能以下划线开头和结尾!");
        g("txt_cname").focus();
        return false;

    }


    if (g("txt_cpwd").value == "") {
        alert("请输入密码！");
        g("txt_cpwd").focus();
        return false;
    }

    if (g("txt_cpwd").value.length > 20 || g("txt_cpwd").value.length < 6) {
        alert("密码的长度限制为6-20个字符!");
        g("txt_cpwd").focus();
        return false;

    }

    if (chkType == 1) {
        if (g("txt_cpwdconfirm").value == "") {
            alert("请输入确认密码！");
            g("txt_cpwdconfirm").focus();
            return false;
        }

        if (g("txt_cpwd").value != g("txt_cpwdconfirm").value) {
            alert("两次输入的密码不一致!");
            g("txt_cpwd").focus();
            return false;

        }
    }


    if (!isemail(g("txt_cmail").value)) {
        alert("电子邮件格式不对,请重新输入!");
        g("txt_cmail").focus();
        return false;

    }


    if (chkType == 2) {
        temp = g("txt_newPwd");

        //如果新密码没有隐藏
        if (temp != null && temp != undefined) {
            if (g("txt_newPwd").value == "") {
                alert("请输入新密码！");
                g("txt_newPwd").focus();
                return false;
            }

            if (g("txt_newPwd").value.length > 20 || g("txt_newPwd").value.length < 6) {
                alert("密码的长度限制为6-20个字符!");
                g("txt_newPwd").focus();
                return false;

            }
            if (g("txt_confirmNewPwd").value == "") {
                alert("请输入确认新密码！");
                g("txt_confirmNewPwd").focus();
                return false;
            }

            if (g("txt_newPwd").value != g("txt_confirmNewPwd").value) {
                alert("两次输入的密码不一致!");
                g("txt_newPwd").focus();
                return false;

            }

        }


    }

    if (g("txt_valcode").value == "") {
        alert("请先输入校验码！");
        return false;
    }

    return true;
}

function g(eId) {
    return document.getElementById(eId);
}

