﻿//自定义组件，用于验证两次输入的密码是否相同

Type.registerNamespace('NBBS.CustomControl');

NBBS.CustomControl.PasswordCheckValidator = function(associatedElement) {
    NBBS.CustomControl.PasswordCheckValidator.initializeBase(this, [associatedElement]);
}

NBBS.CustomControl.PasswordCheckValidator.prototype = {
    _data: null,
    _checkData: null,
    _isPass :false,
    
    get_data: function() {
        return this._data;
    },

    set_data: function(value) {
        if (this._data !== value) {
            this._data = value;
            this.raisePropertyChanged('data');
        }
    },
    
    get_checkData: function() {
    return this._checkData;
    },

    set_checkData: function(value) {
        if (this._checkData !== value) {
            this._checkData = value;
            this.raisePropertyChanged('checkData');
        }
    },
    
    get_isPass: function() {
        return this._isPass;
    },

    set_isPass: function(value) {
        if (this._isPass !== value) {
            this._isPass = value;
            this.raisePropertyChanged('isPass');
        }
    },

    initialize: function() {
        //构造函数
        NBBS.CustomControl.PasswordCheckValidator.callBaseMethod(this, 'initialize');
    
        this.get_element().innerHTML="<font color=\"#CCCCCC\">请再次输入密码</font>";
        this.set_isPass(false);
    },

    dispose: function() {
        //析构函数
        if(this.get_element())
        {
            this.get_element().innerHTML="";
        }
    
        NBBS.CustomControl.PasswordCheckValidator.callBaseMethod(this, 'dispose');
    },

    validate: function() {
        //验证数据
        this.get_element().innerHTML="<img src=\"Icons/loading_validate.gif\" alt=\"\" />&nbsp;<font color=\"CCCCCC\">正在验证密码是否一致……</font>";
        Validate.ValidateCheckPassword(this.get_data(),this.get_checkData(),this.onSucceeded,this.onFailed,this);
    },

    onSucceeded: function(result,validator) {
        //执行成功时的回调函数
        switch(result)
        {
            case 0:
                validator.get_element().innerHTML="<font color=\"#FF0000\">两次输入的密码不一致</font>";
                validator.set_isPass(false);
                break;
            case 1:
                validator.get_element().innerHTML="<img src=\"Icons/icon_ok.gif\" alt=\"\" />";
                validator.set_isPass(true);
                break;
            default:
                break; 
        }
    },
    
    onFailed: function(error,validator) {
        validator.get_element().innerHTML="<font color=\"#FF0000\">内部错误，无法完成检验，请与管理员联系</font>";
    }
}

NBBS.CustomControl.PasswordCheckValidator.registerClass('NBBS.CustomControl.PasswordCheckValidator', Sys.UI.Control);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
