Type.registerNamespace( "ATLASComponents" );
ATLASComponents.ATLASDisposer = function() {
    ATLASComponents.ATLASDisposer.initializeBase( this, [true] );
    
    var _component = "";
    var _enabled = true;
    var _binding = null;
    
    var _handler = null;
    
    this.getDescriptor = function() {
        var td = ATLASComponents.ATLASDisposer.callBaseMethod( this, "getDescriptor") ;
        
        td.addProperty( "component", String );
        td.addProperty( "enabled", Boolean );
        
        return td;
    }
    
    this.get_enabled = function() {
        return _enabled;
    }
    
    this.set_enabled = function( value ) {
        if( value != this.get_enabled() ) {
            _enabled = value;
            this.raisePropertyChanged( "enabled" );
        }
    }
    
    this.get_component = function() {
        return _component;
    }
    
    this.set_component = function( value ) {
        if( this.get_component() != value ) {
            _component = value;
            this.raisePropertyChanged( "component" );
        }
    }
    
    this.initialize = function() {
        ATLASComponents.ATLASDisposer.callBaseMethod( this, "initialize" );
        
        var pageManager = $object("_PageRequestManager");
        if( pageManager != null )
        {
            _handler = Function.createDelegate( this, this._onHandleChange );
            pageManager.propertyChanged.add( _handler );
        }
    }
    
    this._onHandleChange = function(sender, eventArgs) {
         var pageManager = $object("_PageRequestManager");
        if( eventArgs.get_propertyName() == "inPostBack" && pageManager.get_inPostBack() && _enabled) {        
           var ctl = $object( _component );
           if( ctl != null ) {
                  if( Sys.IDisposable.isImplementedBy( ctl ) ) {
                    ctl.dispose();
                    Sys.Application.getMarkupContext().removeObject( ctl );
                  }
           }
        }
    }
    
    this.dispose = function()
    {           
        var pageManager = $object("_PageRequestManager");
        if( pageManager != null && _handler != null )
        {
            _handler = Function.createDelegate( this, this._onHandleChange );
        }
        ATLASComponents.ATLASDisposer.callBaseMethod( this, "dispose" );
    }
}

ATLASComponents.ATLASDisposer.registerClass( "ATLASComponents.ATLASDisposer", Sys.Component );
Sys.TypeDescriptor.addType( "script", "atlasDisposer", ATLASComponents.ATLASDisposer );