WL.Controls.Button = WL.Class( WL.Controls.Control, function( base )
{
	this.constructor = function()
	{
		base.constructor.call( this );
		this.onCheck	= new WL.Objects.Event(); // {}
		this.onClick	= new WL.Objects.Event(); // {}			
		this.isPostBack = false;
	}

	this.ongenerate = function()
	{
		var c = WL.$(this.c_id);
		if( c.firstChild == null ) c.appendChild( WL.$e("span") );
		if( c.firstChild.firstChild == null ) c.firstChild.appendChild( WL.$e("span") );
		c.onclick = this.click.bind( this );
	}

	var returnTrue = function(){ return true; }
	                             
	this.setCssClass = function( cssClass )
	{
		var c = WL.$(this.c_id);
		if( c )
		{
			WL.Utils.setNew( c, "className", "button " + cssClass );
			WL.Utils.setNew( c.firstChild, "className", "b-b" );
			WL.Utils.setNew( c.firstChild.firstChild, "className", "b-t" );
		}
	}
	
	this.setText = function( text )
	{
		var c = WL.$(this.c_id);
		if( c ) { c.title = text; c.firstChild.firstChild.innerHTML=""; c.firstChild.firstChild.appendChild(document.createTextNode(text)); }
	}
	this.setRID = function( rid )
	{
		var c = WL.$(this.c_id);
		if( c )
		{
			if( c.firstChild.attributes["localeID"] == null )
				c.firstChild.setAttribute("localeID",0);
			c.firstChild.attributes["localeID"].nodeValue=rid;
			c.title = WL.S(rid);
			c.firstChild.firstChild.innerHTML=""; 
			c.firstChild.firstChild.appendChild(document.createTextNode(WL.S(rid)));
		}
	}
			
	this.click = function(e)
	{
		var cancel = true;
		if( !this.isDisabled() &&
			this.onCheck.invoke( this ) &&
			this.onClick.invoke( this ) )
		{
			cancel = false;
			if( this.isPostBack ) this.doPostBack();
		}
			
		e = WL.getEvent(e);
		if(e) {
			try
			{
				var c = WL.$(this.c_id); 				
				if( c.href.indexOf("#") >= 0 ) cancel = true;
				c.blur();
			} catch(ex){}
			if( cancel ) return WL.returnEvent(e, false);
		}
	}
	
	this.doPostBack = function() { __doPostBack( this.u_id, "" ); }
	
	this.ondisabled = function( state )
	{
	/*	var c = WL.$(this.c_id);
		if( state )
		{
			c.style.cursor = "default";
			
			var height = c.offsetHeight;
			if( height == 0 )
				c.style.backgroundPositionY = "-" + c.currentStyle.height;
			else
				c.style.backgroundPositionY = -height + "px";
		}
		else
		{
			c.style.cursor = "auto";
			c.style.backgroundPositionY = "0px";
		}*/
	}
} );
