﻿//上一次校验时帐号文本框值
var current_account_name_old="";
var regist_page = {Version: '1.0.0.0'};
regist_page.Page = Class.create({
    initialize: function(userName_id, password_id, password1_id, email_id, _accountInfo, btn_id, agreeID) {
        this.userName = $(userName_id);
        this.password = $(password_id);
        this.password1 = $(password1_id);
        this.eMail = $(email_id);
        this.btn = $(btn_id);
        this.accountInfo = $(_accountInfo);
        this.agree = $(agreeID);
        this.validate = new passportValidate.Page();
        this.Page_Validateor = true;
    },
    showMsg: function(str, account) {
        this.password.value = "";
        this.password1.value = "";
        load = function() {
            alert(str);
        }
        if (document.all) {
            window.attachEvent('onload', load)
        }
        else {
            window.addEventListener('load', load, false);
        }
    },
    set_btn_event: function(page_obj) {
        //通过ajax验证UserName
        this.userName.onblur = function() {
            current_account_name_old = page_obj.userName.value;
            if ($j.trim(current_account_name_old) != "") {
                var result = page_obj.validate.validateEmail(page_obj.userName.value);
                if (result != true) {
                    Show('rimind4');
                    page_obj.accountInfo.innerHTML = "<i>" + result + "</i>";
                }
                else {
                    JoyPortUnionReg1_2_1.Reg_b.CheckUserNameIsExist(page_obj.userName.value, page_obj.validateUserNameIsExistCallBack);
                }
            }
            else {
                Hide('rimind4');
            }
        };
        this.btn.onclick = function() { return page_obj.submit_check(); };
    },
    //提交验证
    submit_check: function() {
        this.Page_Validateor = true;
        //this.validateUserName();
        this.validateEmail();
        this.validatePassword();
        this.validatePasswordConfirm();

        this.validateProtocol();
        if (this.Page_Validateor)
            this.btn.onclick = function() { return false; };

        return this.Page_Validateor;
    },
    //显示错误并返回this.Page_Validateor
    //Control相关控件 IsRight是否正确  Msg消息 
    ShowCheckControlResult: function(Control, IsRight, Msg) {
        if (this.Page_Validateor && !IsRight) { this.Page_Validateor = false; alert(Msg); Control.focus(); }
    },
    //验证用户名
    validateUserName: function() {
        if (this.Page_Validateor) {
            var result = this.validate.checkUserName(this.userName.value);
            if (result != true) { this.ShowCheckControlResult(this.userName, false, result); }
        }
        return this.Page_Validateor;
    },
    //验证UserName后CallBack
    validateUserNameIsExistCallBack: function(data) {
        if (data != null) { if (data.value != null) { if (data.value != "0") { Show('rimind4'); } registpage.accountInfo.innerHTML = data.value == "0" ? "<i>E-mail available.</i>" : "<i>E-mail already registered.</i>"; } }
    },
    //验证密码    
    validatePassword: function() {
        if (this.Page_Validateor) {
            var result = this.validate.checkPasssord(this.password.value, "password");
            if (result != true) { this.ShowCheckControlResult(this.password, false, result); }
        }
    },
    //验证确认密码 
    validatePasswordConfirm: function() {
        if (this.Page_Validateor) {
            var result = "Password inconsistent!";
            if (this.password1.value != this.password.value) { this.ShowCheckControlResult(this.password1, false, result); }
        }
    },
    //验证电子邮件
    validateEmail: function() {
        if (this.Page_Validateor) {
            var result = this.validate.validateEmail(this.eMail.value);
            if (result != true) { this.ShowCheckControlResult(this.eMail, false, result); }
        }
    },
    validateEmailPage: function() {
        if (this.Page_Validateor && $j.trim(this.eMail.value) != "") {
            var result = this.validate.validateEmail(this.eMail.value);
            if (result != true) { Show('rimind4'); $('rimind4').innerHTML = "<i>Invalid E-mail address.</i>"; }
            else {
                $('rimind4').innerHTML = "<i>Valid E-mail address.</i>";
                Hide('rimind4');
            }
        }
        else {
            Hide('rimind4');
        }
    },
    //验证 验证码
    validateRandomCode: function() {
        if (this.Page_Validateor) {
            result = "Input the Code.";
            if (this.code.value.length == 0) {
                this.ShowCheckControlResult(this.code, false, result);
            }
        }
        return this.Page_Validateor;
    },
    validateProtocol: function() {
        if (this.Page_Validateor) {
            var result = this.agree.checked;
            if (result != true) { this.ShowCheckControlResult(this.agree, false, "You must agree to Kingory's user agreement first."); }
        }
    },
    change_code: function() {
        this.img_code.click();
    }
});



function Show(obj){
	var divS=document.getElementById(obj);
	divS.style.display = "block";
}

function Hide(obj){
	var divS=document.getElementById(obj);
	divS.style.display="none";	
}



