WL.Controls = {};
WL.Controls.Control = WL.Class( Object, function()
{
	this.constructor = function()
	{
		this.onDisableChanging	= new WL.Objects.Event(); // { state: boolean }
		this.onDisableChange	= new WL.Objects.Event(); // { state: boolean }	
			
		this._disabled = false;
		
		WL.attachListener( window, "unload", this.unload.bind(this) );
	}

	this.getContainer = function() { return WL.$( this.c_id ); }
	
	this.generate = function( uniqueID )
	{
		this.u_id = uniqueID;
		this.c_id = uniqueID.split('$').join('_');
		
		var c = WL.$(this.c_id);
			c.control = this;		
		this.ongenerate(c);
	}

	this.generate2 = function(c)
	{
		this.c_id = WL.uniqueID(c);
		c.control = this;
		this.ongenerate(c);
	}

	this.ongenerate = function(c) {}
	
	this.unload = function()
	{
		var c = WL.$(this.c_id);
		if( c != null )
		{
			this.onunload();
			c.control = null;
		}
	}
	
	this.onunload = function() {}

	this.disable = function( disable )
	{	
		if( this._disabled == disable ) return;		
		if( this.onDisableChanging.invoke( this, {state: disable} ) )
		{
			this._disabled = disable;
			this.onDisableChange.invoke( this, { state: disable } );
			this.ondisabled( disable );
		}
	}

	this.ondisabled = function( disabled ) {}
		
	this.isDisabled = function() { return this._disabled; }
} );
