﻿// check user info
function sub_mit(){
    var _v = Trim(GetE("txtUsername").value);
    var _match =/^[a-zA-Z0-9]{5,14}$/;
    if(!_match.test(_v)){alert("注册用户名长度为5-14个字符,由英文,数字组成"); EventHalt(); GetE("txtUsername").focus();return; }
    
    GetE("txtUsername").value = _v;
    
    _v = Trim(GetE("txtPwd").value);
    _match =/^[a-zA-Z0-9_]{6,12}$/;
    if(!_match.test(_v)){alert("密码长度为6-16个字符,由英文,数字组成"); EventHalt(); GetE("txtPwd").focus();return; }
    
    _v2 = Trim(GetE("txtPwd2").value);
    _match =/^[a-zA-Z0-9_]{6,12}$/;
    if(!_match.test(_v)){alert("密码长度为6-16个字符,由英文,数字组成"); EventHalt(); GetE("txtPwd2").focus();return; }
    else if(_v != _v2){alert("两次密码不一致"); EventHalt(); GetE("txtPwd2").focus();return;}

    _v = Trim(GetE("txtEmail").value);
    if(_v == ""){alert("请输入您的Email"); EventHalt(); return; }
    else if(!IsMail(_v)){alert("Email格式错误"); GetE("txtEmail").focus();EventHalt(); return; }
    GetE("txtEmail").value  = _v;
    
    _v = Trim(GetE("txtIDCard").value);
    if(_v == ""){alert("请输入您的身份证号码"); EventHalt(); return; }
    else if(!isCardNo(_v)){alert("身份证号码有错，请输入18位的身份证号码"); GetE("txtIDCard").focus();EventHalt(); return; }
    
    if(GetE("cboArea").value == ""){ alert("请选择要激活的分区"); EventHalt(); return; }
    
    _v = Trim(GetE("txtCode").value);
    _match =/^[a-zA-Z0-9]{5}$/;
    if(!_match.test(_v)){alert("验证码输入错误"); EventHalt(); GetE("txtCode").focus();return; }

    if(!confirm("确认注册吗？")){EventHalt(); return;}
}
// check username
function CheckUsername(){
    //return;
    var _n = Trim(GetE("txtUsername").value);
    if(_n.length == 0){return;}
    _match =/^[a-zA-Z0-9_]{4,12}$/;
    if(!_match.test(_n)){alert("注册用户名长度为4-12个字符,由英文,数字组成");GetE("txtUsername").focus();return; }
    AjaxUrl = "AjaxService.koc?AjaxType=Reg_CheckUsername&n=" + _n + "&time="+new Date();
    xmlHttp = CreateAjaxObj(AjaxUrl,"GET");
    xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var _r = parseInt(xmlHttp.responseText);
            switch(_r){
                case 1:
                    alert("用户名已存在！");GetE("txtUsername").value = "";GetE("txtUsername").focus();break;
                default:
                    return;
            }
        }
    };
    xmlHttp.send(null);
}