// JScript 文件

    var username;
    var fullname;
    var password;
    var password2;
    var true_name;
    var telephone;
    var cellphone;
    var question;
    var email;
    var sex;
    var checkcode;
    var returnvalue = false;
    var usernameinfo;
    var fullnameinfo;
    var passwordinfo;
    var password2info;
    var nameinfo;
    var telephoneinfo;
    var cellphoneinfo;
    var answerinfo;
    var emailinfo;
    var checkcodeinfo; 
        
    function ValidentUserName(name){
        var ajax = new Webservice("/Webservice/Valident.asmx","ValidentUserName",true,ValidentUserNameBack);
        if(Flicker.start(ajax,"UserNameInfo","验证中")){
		    ajax.ps.name = name;
		    returnvalue = false;
		    ajax.service();
        }
    }
    function ValidentUserNameBack(result){
        Flicker.stop("UserNameInfo");
        if(!result.error){
            if(result[0] == "yes"){
                usernameinfo.className = "regno";
                usernameinfo.innerHTML = "这个用户名称已经有人在使用啦，请另选一个！";
                returnvalue = false;
            }
            else{
                returnvalue = true;
                usernameinfo.className = "reg";
                usernameinfo.innerHTML = "正确";
            }
        }
        else{
            usernameinfo.className = "reg";
            usernameinfo.innerHTML = result.errorString;
        }
    }
    
    function ValidentEmail(email){
        var ajax = new Webservice("/Webservice/Valident.asmx","ValidentEmail",true,ValidentEmailBack);
        if(Flicker.start(ajax,"EmailInfo","验证中")){
		    ajax.ps.email = email;
		    returnvalue = false;
		    ajax.service();
        }
    }
    function ValidentEmailBack(result){
        Flicker.stop("EmailInfo");
        if(!result.error){
            if(result[0] == "yes"){
                emailinfo.className = "regno";
                emailinfo.innerHTML = "这个电子邮件已经有人在使用啦，请另选一个！";
                returnvalue = false;
            }
            else{
                returnvalue = true;
                emailinfo.className = "reg";
                emailinfo.innerHTML = "正确";
            }
        }
        else{
            emailinfo.className = "reg";
            emailinfo.innerHTML = result.errorString;
        }
    }

    function ValidentCheckCode(code){
        var ajax = new Webservice("/Webservice/Valident.asmx","ValidentCheckCode",true,ValidentCheckCodeBack);
        if(Flicker.start(ajax,"CheckCodeTextInfo","验证中")){
		    ajax.ps.code = code;
		    returnvalue = false;
		    ajax.service();
        }
    }
    function ValidentCheckCodeBack(result){
        Flicker.stop("CheckCodeTextInfo");
        if(!result.error){
            if(result[0] == "error"){
                checkcodeinfo.className = "regno";
                checkcodeinfo.innerHTML = "验证码不正确！";
                returnvalue = false;
            }
            else{
                returnvalue = true;
                checkcodeinfo.className = "reg";
                checkcodeinfo.innerHTML = "正确";
            }
        }
        else{
            checkcodeinfo.className = "reg";
            checkcodeinfo.innerHTML = result.errorString;
        }
    }
    function ConfirmClick(name){
        username = document.getElementById("UserName");
        var servicelaw = document.getElementById("serviceLaw");
        fullname = Doc.g("FullName");
        password = Doc.g("PassWord");
        true_name = Doc.g("Name");
        answer = Doc.g("Answer");
        telephone = Doc.g("TelePhone");
        cellphone = Doc.g("CellPhone");
        question = Doc.g("Question");
        password2 = Doc.g("PassWord2");
        male = document.getElementById("Male");
        female = document.getElementById("Female");
        if(male.checked){
            sex = male.value;
        }
        else
            sex = female.value;
        email = Doc.g("Email");
        checkcode = Doc.g("CheckCodeText");
        returnvalue = true;
        usernameinfo = Doc.g("UserNameInfo");
        fullnameinfo = Doc.g("FullNameInfo");
        passwordinfo = Doc.g("PassWordInfo");
        password2info = Doc.g("PassWord2Info");
        nameinfo = Doc.g("NameInfo");
        telephoneinfo = Doc.g("TelePhoneInfo");
        cellphoneinfo = Doc.g("CellPhoneInfo");
        answerinfo = Doc.g("AnswerInfo");
        emailinfo = Doc.g("EmailInfo");
        checkcodeinfo = Doc.g("CheckCodeTextInfo"); 
        
        if(name == "username" || name == null){
            if(username.value.trim() == ""){
                usernameinfo.innerHTML = "用户名称不可以为空！";
                usernameinfo.className = "regno";
                returnvalue = false;
            }
            else if(username.value.trim().length < 4){
                usernameinfo.innerHTML = "您的用户名称小于了四位，请从新填写！";
                usernameinfo.className = "regno";
                returnvalue = false;
            }        
            else if(username.value.trim().length > 20){
                usernameinfo.innerHTML = "您的用户名称大于了二十位，请从新填写！";
                usernameinfo.className = "regno";
                returnvalue = false;
            }
            else if(name != null){
                usernameinfo.className = "reg";
                ValidentUserName(username.value.trim());
            }
        }
        
        if(name == "fullname" || name == null){
             if(fullname.value.trim() == ""){
                fullnameinfo.innerHTML = "昵称不可以为空！";
                fullnameinfo.className = "regno";
                returnvalue = false;
            }
            else{
                fullnameinfo.className = "reg";
                fullnameinfo.innerHTML = "正确";
            }
        }
        
        if(name == "password" || name == null){
            if(password.value == ""){
                passwordinfo.innerHTML = "密码不可以为空！";
                passwordinfo.className = "regno";
                returnvalue = false;
            }
            else if(password.value.length < 5){
                passwordinfo.innerHTML = "您填写的密码长度小于了五位，请重新填写！";
                passwordinfo.className = "regno";
                returnvalue = false;
            }
            else if(password.value.length > 20){
                passwordinfo.innerHTML = "您填写的密码长度大于了二十位，请重新填写！";
                passwordinfo.className = "regno";
                returnvalue = false;
            }
            else{
                passwordinfo.className = "reg";
                passwordinfo.innerHTML = "正确";
            }
        }
        
        if(name == "password2" || name == null){
            if(password2.value.length == ""){
                password2info.innerHTML = "请填写重复密码！";
                password2info.className = "regno";
                returnvalue = false;
            }
            else if(password2.value.length < 5){
                password2info.innerHTML = "您填写的密码长度小于了五位，请重新填写！";
                password2info.className = "regno";
                returnvalue = false;
            }
            else if(password2.value.length > 20){
                password2info.innerHTML = "您填写的密码长度大于了二十位，请重新填写！";
                password2info.className = "regno";
                returnvalue = false;
            }
            else if(password.value != password2.value){
                password2info.innerHTML = "两次输入的密码不一致，请重新填写！";
                password2info.className = "regno";
                returnvalue = false;
            }
            else{
                password2info.className = "reg";
                password2info.innerHTML = "正确";
            }
        }
        if(name =="truename" || name == null)
        {
            if(true_name.value.trim() != ""){
                if(true_name.value.length< 3 || true_name.value.length >= 16){
                    nameinfo.innerHTML = "姓名不能小于3或者大于16位字符";
                    nameinfo.className = "regno";
                    returnvalue = false;
                }
            }
            else if(name != null){
                nameinfo.className = "reg";
                nameinfo.innerHTML = "正确";
            }
        }
        if(name =="answer" || name == null)
        {
            if(answer.value.trim() == ""){
                answerinfo.innerHTML = "请输入密码回答内容";
                answerinfo.className = "regno";
                returnvalue = false;
            }
            else if(answer.value.length< 3 || answer.value.length >= 25){
                answerinfo.innerHTML = "回答内容字符不能小于3或者大于25";
                answerinfo.className = "regno";
                returnvalue = false;
            }
            else if(name != null){
                answerinfo.className = "reg";
                answerinfo.innerHTML = "正确";
            }
        }
        if(name =="telephone" || name == null)
        {
            if(telephone.value.trim() != ""){
                if(isFixTel(telephone.value) == false){
                    telephoneinfo.innerHTML = "电话号码格式不正确！";
                    telephoneinfo.className = "regno";
                    returnvalue = false;
                 }
            }
            else if(name != null){
                telephoneinfo.className = "reg";
                telephoneinfo.innerHTML = "正确";
            }
        }
        if(name =="cellphone" || name == null)
        {
            if(cellphone.value.trim() != ""){
                if(isMoveTel(cellphone.value) == false){
                    cellphoneinfo.innerHTML = "手机号码格式不正确！";
                    cellphoneinfo.className = "regno";
                    returnvalue = false;
                }
            }
            else if(name != null){
                cellphoneinfo.className = "reg";
                cellphoneinfo.innerHTML = "正确";
            }
        }
        if(name == "email" || name == null){
            if(email.value.trim() == ""){
                emailinfo.innerHTML = "请输入电子邮件！";
                emailinfo.className = "regno";
                returnvalue = false;
            }
            else if(!isEmail(email.value.trim())){
                emailinfo.innerHTML = "电子邮件的格式不正确！";
                emailinfo.className = "regno";
                returnvalue = false;
            }
            else if(name != null){
                emailinfo.className = "reg";
                ValidentEmail(email.value.trim());
            }
        }
        if(name == "checkcode" || name == null){
            if(checkcode.value.trim() == ""){
                checkcodeinfo.innerHTML = "请输入验证码！";
                checkcodeinfo.className = "regno";
                returnvalue = false;
            }
            else if(name != null){
                checkcodeinfo.className = "reg";
                ValidentCheckCode(checkcode.value.trim());
            }
        }
        if (servicelaw.checked == false){
            alert("请选择同意本站服务条款!");
            return;
        }
        oldDiv = new Object();
        if(returnvalue && name == null){
            Register();
        }
    }
    var oldDiv = new Object();
    function TextOnfocus(obj){
        if(oldDiv.id != null){
            Doc.g(oldDiv.id).className = oldDiv.className;
        }
        var infoid = obj.id + "Info";
        var  infoDiv = Doc.g(infoid);
        oldDiv.id = infoDiv.id;
        oldDiv.className = infoDiv.className;
        infoDiv.className = "regon";
    }
    
    function Register(){
        var ajax = new Webservice("/webservice/Signup.asmx","register",true,RegisterBack);
        ajax.ps.name = true_name.value;
        ajax.ps.username = username.value;
        ajax.ps.password = password.value;
        ajax.ps.fullname = fullname.value;
        ajax.ps.telephone = telephone.value;
        ajax.ps.cellphone = cellphone.value;
        ajax.ps.email = email.value;
        ajax.ps.sex = sex;
        ajax.ps.question = question.value;
        ajax.ps.answer = answer.value;
		ajax.service();
    }
    function RegisterBack(result){
        if(!result.error){
            window.location.href = "/ok?userid="+ result[0] +"";
        }
        else{
            alert("注册出错！");
        }
    }