﻿// README
//
// There are two steps to adding a property:
//
// 1. Create a member variable to store your property
// 2. Add the get_ and set_ accessors for your property
//
// Remember that both are case sensitive!


/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit" />


Type.registerNamespace('OnLineExt.login');

OnLineExt.login.ForgetBehavior = function(element) {
    OnLineExt.login.ForgetBehavior.initializeBase(this, [element]);

    this._TextBoxEmail = null;
    this._ErrorLabel = null;
    
    this._onclickHandler = null;
    this._onclickHandlerSend = null;

    this._SendMail = null;
}
OnLineExt.login.ForgetBehavior.prototype = {
    initialize: function() {
        OnLineExt.login.ForgetBehavior.callBaseMethod(this, 'initialize');

        this._OnPopulateHandler = Function.createDelegate(this, this._onPopulate);
        this._OnFailedHandler = Function.createDelegate(this, this._onFailed);
        this._onclickHandlerSend = Function.createDelegate(this, this._onclickSend);

        
        var e = this.get_element();
        $addHandler(e, "click", this._onclickHandlerSend);

        this._resultElement = this._ErrorLabel;
        this._SendMail = e;
    },

    dispose: function() {
        var e = this.get_element();
        $removeHandler(e, "click", this._onclickHandlerSend);
        $removeHandler(this._SendMail, "click", this._onclickHandlerSend);

        OnLineExt.login.ForgetBehavior.callBaseMethod(this, 'dispose');
    },

    _onPopulate: function(result) {
        this._resultElement.innerHTML = result;
        if (result == "Письмо Вам отправлено") {
            $removeHandler(this._SendMail, "click", this._onclickHandlerSend);
            this._resultElement.innerHTML = "";
            this._SendMail.innerHTML = "Пароль выслан Вам на email";
            this._SendMail.className = "green";
        }
    },

    _onFailed: function(error) {
        this._resultElement.innerHTML = rus(101) + error._message;
    },

    _onclickSend: function() {
        EmEx_Services.checkEmail(this._TextBoxEmail.value, this._OnPopulateHandler, this._OnFailedHandler);
    },

    get_TextBoxEmail: function() {
        return this._TextBoxEmail;
    },

    set_TextBoxEmail: function(value) {
        if (this._TextBoxEmail != value) {
            this._TextBoxEmail = value;
            this.raisePropertyChanged('TextBoxEmail');
        }
    },

    get_ErrorLabel: function() {
        return this._ErrorLabel;
    },

    set_ErrorLabel: function(value) {
        if (this._ErrorLabel != value) {
            this._ErrorLabel = value;
            this.raisePropertyChanged('ErrorLabel');
        }
    }


}
OnLineExt.login.ForgetBehavior.registerClass('OnLineExt.login.ForgetBehavior', AjaxControlToolkit.BehaviorBase);
