// JScript 文件

    var username;
    var password;
    var checkcode;
    var returnvalue = false;
    var usernameinfo;
    var passwordinfo;
    var checkcodeinfo; 
     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 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] == "no"){
                usernameinfo.className = "regno";
                usernameinfo.innerHTML = "用户名称不存在！";
                returnvalue = false;
            }
            else{
                returnvalue = true;
                usernameinfo.className = "reg";
                usernameinfo.innerHTML = "正确";
            }
        }
        else{
            usernameinfo.className = "reg";
            usernameinfo.innerHTML = result.errorString;
        }
    }
    function ValidentLogin(name,password){
        var ajax = new Webservice("/webservice/valident.asmx","ValidentLogin",true,ValidentLoginBack);
        if(Flicker.start(ajax,"PassWordInfo","验证中")){
		    ajax.ps.name = name;
		    ajax.ps.password = password; 
		    returnvalue = false;
		    ajax.service();
        }
    }
    function ValidentLoginBack(result){
        Flicker.stop("PassWordInfo");
        if(!result.error){
            if(result[0] == "no"){
                passwordinfo.className = "regno";
                passwordinfo.innerHTML = "密码错误！";
                returnvalue = false;
            }
            else{
                returnvalue = true;
                passwordinfo.className = "reg";
                passwordinfo.innerHTML = "正确";
            }
        }
        else{
            passwordinfo.className = "reg";
            passwordinfo.innerHTML = result.errorString;
        }
    }
    function ConfirmClick(name){
        username = document.getElementById("UserName");
        password = Doc.g("PassWord");
        checkcode = Doc.g("CheckCodeText");
        usernameinfo = Doc.g("UserNameInfo");
        passwordinfo = Doc.g("PassWordInfo");
        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 == "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 if(name != null){
                passwordinfo.className = "reg";
                ValidentLogin(username.value.trim(),password.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());
            }
        }
        oldDiv = new Object();
        if(returnvalue && name == null){
            Login();
        }
    }
    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 Login(){
        var ajax = new Webservice("/webservice/Signup.asmx","login",true,LoginBack);
        ajax.ps.username = username.value;
        ajax.ps.password = password.value;
		ajax.service();
    }
    function LoginBack(result){
        if(!result.error){
            if(result[0] == "yes"){
                alert('登陆成功!');
                window.location.href = document.referrer;
            }
             else
                alert("密码或用户名不正确");
        }
        else{
            alert("密码或用户名不正确！");
        }
    }