﻿function CheckNull(){
    if(this.value == ""){
        this.IsCorrect =  false;
        SetResultBG.call(this,"error", "Please enter required infomation.");
        return false;
    }
    return true;
}
/***********************For check mail start******************************/
function CheckMail(){
    if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.value)){
        SetResultBG.call(this, "error","The E-Maill your entered is invalid!");
    }else{
        CheckToServer.call(this);
    }
}
/***********************For check Recordkey start******************************/
function CheckRecordkey(){
    CheckRecordkeyLength.call(this);
    SetEachRegex.call(this.form["recordkey2"]);
}
function CheckRecordkeyLength(){
    if(!CheckLength.call(this,5,25)){
        SetResultBG.call(this, "error","The Password length at least 5.");
    }else{
        SetResultBG.call(this, "correct","Ok!");
    }
}
function CheckRecordkey2(){
    if(!CheckLength.call(this,5,25)){
        SetResultBG.call(this, "error","The Password length at least 5.");
    }else if(this.value != this.form["recordkey"].value){
        SetResultBG.call(this, "error","The two passwords do not match!");
    }else{
        SetResultBG.call(this, "correct","Ok!");
    }
}
function CheckLength(min,max){
    if(this.value.length < min || this.value.length > max) return false;
    else return true;
}
//设置结果样式
function SetResultBG(CssName, sMsg){
    if(this.CssClass)
        this.parentNode.parentNode.className = this.CssClass + CssName;
    else
        this.parentNode.parentNode.className = CssName;
    this.Relate.innerHTML = sMsg;
    if(/correct/.test(CssName))
        this.IsCorrect = true;
    else
        this.IsCorrect = false;
}
//提交注册表单
function RegisterSubmit(){
    for(var i=0,j=this.InputText.length;i<j;i++){
        if(!this.InputText[i].IsCorrect){
            if(this.InputText[i].name == "recordkey" && this.InputText[i].value != "")
                continue;
            OverInputText.call(this.InputText[i]);
            return false;
        }
    }
    DisableButton(true);
    return true;
}
function OverInputText(){
    this.focus();
    this.select();
}
//邮件验证错误
function CheckError(){
    SetResultBG.call(this.relate, "error","System is temporarily unavailable!");
}
//返回值
function returnStatus(){
    var res = this.req.responseText;
    var ReturnValue = ParseJson(res,"string");
    if(this.relate.Return){
        this.relate.Return.call(this.relate, ReturnValue);
    }else{
        ReturnDefault.call(this.relate, ReturnValue);
    }
}
function ReturnDefault(ReturnValue){
    if(ReturnValue > 0){
        SetResultBG.call(this, "error","The information your entered has existed!");
    }else{
        SetResultBG.call(this, "correct","Ok!");
    }
}
//检查验证码返回值
function returnValidate(ReturnValue){
    if(ReturnValue == "true"){
        SetResultBG.call(this, "correct","Congratulation, You are smart!");
    }else if(ReturnValue == "false"){
        SetResultBG.call(this, "error","Careless, your entered is invalid!");
    }else{
        SetResultBG.call(this, "error","Timeout, Click Validate image to refresh!");
    }
}
//登录帐号查询
function ReturnLoginAccount(ReturnValue){
    if(ReturnValue > 0){
        SetResultBG.call(this, "correct","You are welcome!");
    }else{
        SetResultBG.call(this, "error","Has not this account!");
    }
}
//设置结果样式
function SetResultBG(CssName, sMsg){
    if(this.CssClass)
        this.parentNode.parentNode.className = this.CssClass + CssName;
    else
        this.parentNode.parentNode.className = CssName;
    this.Relate.innerHTML = sMsg;
    if(/correct/.test(CssName))
        this.IsCorrect = true;
    else
        this.IsCorrect = false;
}
//刷新验证码
function refreshImg(){
    this.src = "/member/picture.xhtml?temp=" + new Date();
}
