﻿// 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!
//

Type.registerNamespace('OnLineExt.login');

OnLineExt.login.LgBehavior = function(element) {
    OnLineExt.login.LgBehavior.initializeBase(this, [element]);

    this._loginElement = null;
    this._passwordElement = null;
    this._resultElement = null;
    this._onclickHandler = null;

    this._UserPostBack = null;
    this._UserPostBackArg = OnLineExt.PostBackArg.undef;

    this._emptyString = "&nbsp;";
}

OnLineExt.login.LgBehavior.prototype = {

    initialize: function() {
        OnLineExt.login.LgBehavior.callBaseMethod(this, 'initialize');
        this._onclickHandler = Function.createDelegate(this, this._onclick);
        this.OK = this.get_element();
        $addHandler(this.OK, "click", this._onclickHandler);

        this._OnPopulateHandler = Function.createDelegate(this, this._onPopulate);
        this._OnFailedHandler = Function.createDelegate(this, this._windowUnloadHandler);

    },

    dispose: function() {
        var e = this.get_element();
        $removeHandler(e, "click", this._onclickHandler);
        OnLineExt.login.LgBehavior.callBaseMethod(this, 'dispose');
    },

    get_loginElement: function() {
        return this._loginElement;
    },

    set_loginElement: function(value) {
        if (this._loginElement != value) {
            this._loginElement = value;
            this.raisePropertyChanged('loginElement');
        }
    },

    get_passwordElement: function() {
        return this._passwordElement;
    },

    set_passwordElement: function(value) {
        if (this._passwordElement != value) {
            this._passwordElement = value;
            this.raisePropertyChanged('passwordElement');
        }
    },

    get_resultElement: function() {
        return this._resultElement;
    },

    set_resultElement: function(value) {
        if (this._resultElement != value) {
            this._resultElement = value;
            this.raisePropertyChanged('resultElement');
        }
    },

    get_UserPostBackArg: function() {
        return this._UserPostBackArg;
    },

    set_UserPostBackArg: function(value) {
        this._UserPostBackArg = value;
    },

    get_UserPostBack: function() {
        return this._UserPostBack;
    },

    set_UserPostBack: function(value) {
        this._UserPostBack = value;
    },

    _onPopulate: function(result) {
        if (result == "")
            result = this._emptyString;
        this._resultElement.innerHTML = result;
        if (result == this._emptyString) {
            var postbackCode = this._UserPostBack;
            window.setTimeout(postbackCode, 0);
        }
        this.OK.disabled = false;
    },


    _onFailed: function(error) {
        this._resultElement.innerHTML = rus(101) + error._message;
        this.OK.disabled = false;
    },

    _onclick: function(e) {

        this.OK.disabled = true;
        this._resultElement.innerHTML = this._emptyString;
        // ��� ������� �� ������ �� ���� ������� �����, ��� ��� ��������� ��� � ���������
        EmEx_Services.checklg(this._loginElement.value, this._passwordElement.value, this._OnPopulateHandler, this._OnFailedHandler);

        if (window.event) // for FF comp.
            window.event.returnValue = false;
        else {
            e.preventDefault();
            e.stopPropagation();
        }
    }
}

OnLineExt.login.LgBehavior.registerClass('OnLineExt.login.LgBehavior', AjaxControlToolkit.BehaviorBase);
