﻿// Vamsoft.ViewBehavior 
//
//Create a wrapper for show/hide form elements
/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit" />

Type.registerNamespace('Vamsoft');

Vamsoft.ViewBehavior = function(element) {
    Vamsoft.ViewBehavior.initializeBase(this, [element]);
    this._isactive = false;
}

Vamsoft.ViewBehavior.prototype = {
    initialize: function() {
        Vamsoft.ViewBehavior.callBaseMethod(this, 'initialize');
    },

    dispose: function() {
        Vamsoft.ViewBehavior.callBaseMethod(this, 'dispose');
    },

    get_isactive: function() {
        return this._isactive;
    },

    set_isactive: function(active) {
        if (active) this.activate();
        else this.deactivate();
    },

    activate: function() {
        this.raiseOnActivating();
        this._element.style.display = "block";
        this._element.style.visibility = "visible";
        this._isactive = true;
        this.raiseOnActivated();
    },

    deactivate: function() {
        this.raiseOnDeactivating();
        this._element.style.display = "none";
        this._element.style.visibility = "hidden";
        this._isactive = false;
        this.raiseOnDeactivated();
    },

    raiseOnActivating: function() {
        var handler = this.get_events().getHandler('activating');

        if (handler) {
            handler(this);
        }
    },

    raiseOnActivated: function() {
        var handler = this.get_events().getHandler('activated');

        if (handler) {
            handler(this);
        }
    },

    raiseOnDeactivating: function() {
        var handler = this.get_events().getHandler('deactivating');

        if (handler) {
            handler(this);
        }
    },

    raiseOnDeactivated: function() {
        var handler = this.get_events().getHandler('deactivated');

        if (handler) {
            handler(this);
        }
    },

    add_activating: function(handler) {
        this.get_events().addHandler('activating', handler);
    },

    remove_activating: function(handler) {
        this.get_events().removeHandler('activating', handler);
    },

    add_activated: function(handler) {
        this.get_events().addHandler('activated', handler);
    },

    remove_activated: function(handler) {
        this.get_events().removeHandler('activated', handler);
    },

    add_deactivating: function(handler) {
        this.get_events().addHandler('deactivating', handler);
    },

    remove_deactivating: function(handler) {
        this.get_events().removeHandler('deactivating', handler);
    },

    add_deactivated: function(handler) {
        this.get_events().addHandler('deactivated', handler);
    },

    remove_deactivated: function(handler) {
        this.get_events().removeHandler('deactivated', handler);
    }
}

Vamsoft.ViewBehavior.registerClass('Vamsoft.ViewBehavior', Sys.UI.Behavior);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
