/**
 * @import com.emaildatasource.eds.punt.client.taglib.tagjsp.button_jsp.BUTTON button.button
 */
eds.punt.client.widget.Button = function(domIds, principalObj, onImage, offImage) {

	var messageSystem;

	var that = this;

	var keys = eds.punt.client.KeyChain.button;

	var enabled = false;

	if ( arguments.length != 4 ) {
		throw "button wrong number of elements";
	}

	eds.webapp.widget.Widget.call(this, domIds);

	this.init = function() {

		if ( principalObj ) {
			principalObj.addButton(this);
		}
	}

	this.destroy = function() { }

	function setSrc(image) {
		that.setElSrc(keys.button, IMAGE_ROOT + '/' + image);
	}

	this.enable = function() {

		if ( enabled ) {
			return;
		}

		that.enableEl(keys.button);
		setSrc(onImage);
		enabled = true;
	}

	this.disable = function() {

		if ( !enabled ) {
			return;
		}

		that.disableEl(keys.button);
		setSrc(offImage);
		enabled = false;
	}

	this.click = function() {
		if ( this.getEl(keys.button).disabled ) {
			return;
		}
		this.dispatchOnClickEvent();
	}

	this.dispatchOnClickEvent = function() {
		var button = this.getEl(keys.button);

		if ( principalObj ) {
			principalObj.acceptButtonClickedEvent();
		}
	}

	this.toString = function() {
		return '[button object]';
	}
}

eds.punt.client.widget.Button.prototype = new eds.webapp.widget.Widget(null);
