﻿// check user info
function sub_mit(){
    var _v = Trim(GetE("txtUsername").value);
    var _match =/^[a-zA-Z0-9_]{6,20}$/;
    if(!_match.test(_v)){alert("注册用户名长度为6-20个字符,由英文,数字,下划线组成"); EventHalt(); GetE("txtUsername").focus();return; }
    
    GetE("txtUsername").value = _v;
    
    _v = Trim(GetE("txtPwd").value);
    _match =/^[a-zA-Z0-9_]{6,20}$/;
    if(!_match.test(_v)){alert("密码长度为6-20个字符,由英文,数字组成"); EventHalt(); GetE("txtPwd").focus();return; }
    
    _v2 = Trim(GetE("txtPwd2").value);
    _match =/^[a-zA-Z0-9_]{6,20}$/;
    if(!_match.test(_v)){alert("密码长度为6-20个字符,由英文,数字组成"); 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;

    if(!confirm("确认注册吗？")){EventHalt(); return;}
}
// check username
function CheckUsername(){
    //return;
    var _n = Trim(GetE("txtUsername").value);
    if(_n.length == 0){return;}
    var _match =/^[a-zA-Z]/;
    if(!_match.test(_n.substring(0,1))){alert("用户名第一个字符只能为英文");GetE("txtUsername").focus();return; }
    _match =/^[a-zA-Z0-9_]{6,20}$/;
    if(!_match.test(_n)){alert("注册用户名长度为6-20个字符,由英文,数字组成");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:
                    break;
                case 1101:
                    alert("用户名不合法！");GetE("txtUsername").value = "";GetE("txtUsername").focus();break;
                default:
                    alert("用户名已存在！");GetE("txtUsername").value = "";GetE("txtUsername").focus();break;
                    return;
            }
        }
    };
    xmlHttp.send(null);
}