/**	lib:			js-dfc-button*	*	description:	button implementation**	created:		Sep. 10, 2002*	*	contributed:	Wolfgang Schramm**	methods:		new				create				createConfiguration				enable				select				getData				setStatus					events:		onCommand				onBeforeCommand*/DFCButtonConfig = function() {	this.alignVertical	= true;			// icon/label alignment: vertical or horizontal	this.showIcon		= false;	this.showLabel		= true;	this.selectOnDown	= false;			// 2-state button behaviour	this.noDeselect	= false;			// true: deselect can only be done with the select(false) method	this.keyAccess		= false;			// accessability option: true makes the button accessable									// with the tab key	this.cssButtonEnabled		= '';	this.cssButtonDisabled		= '';	this.cssButtonOver			= '';	this.cssButtonOverSelected	= '';	this.cssButtonDown			= '';	this.cssButtonSelected		= '';	this.cssLabelEnabled		= '';	this.cssLabelDisabled		= '';	this.cssLabelDown			= '';	this.cssLabelSelected		= '';		this.iconEnabled			= null;	this.iconDisabled			= null;	this.iconDown				= null;};DFCButton = function(opt_sLabel, opt_jsData) {		DFCEvent.call(this);			this._sLabel			= opt_sLabel || '';		// label	this._jsData			= opt_jsData || '';//	this.title			= '';				// tool-tip//	this.accessKey			= '';					this.isSelected		= false;				// read only		this._isEnabled		= true;	// create default button configuration	this._hDFCConfig		= new DFCConfig(DFCButtonConfig);		this._domButton		= null;	this._domIcon			= null;	this._domIconCont		= null;				// TD which contains the icon div	this._domLabel			= null;	this._domLabelCont		= null;				// TD which contains the label div	this._domAccess		= null;	this._domFocus			= null;		this._sEvent_onCommand		= 'onCommand';	this._sEvent_onBeforeCommand	= 'onBeforeCommand';	this._registerEvent(this._sEvent_onCommand);	this._registerEvent(this._sEvent_onBeforeCommand);		this._onBeforeCommandStatus	= null;			// true/false};DFCButton.prototype = new DFCEvent();DFCButton.prototype.createFromDFCTag = function(hWin, domDFCTag) {	this._sLabel	= domDFCTag.getAttribute('label');	var sConfig	= domDFCTag.getAttribute('config');	var hConfig	= eval(sConfig);		this.createConfiguration(hConfig);	this.create(hWin, domDFCTag.parentNode);}DFCButton.prototype.createConfiguration = function(hConfig, opt_sKey, opt_sConfigInherit) {	// create a new button configuration	// hConfig			DFCButtonConfig structure	// opt_sKey			key for this configuration, null if this is the default	// opt_sConfigInherit	key where the configuration is inheriting from		this._hDFCConfig.create(hConfig, opt_sKey, opt_sConfigInherit);};DFCButton.prototype.enable = function(isEnabled) {	var hConfig		= this._hConfig;	this._isEnabled	= isEnabled;		if (isEnabled) {		this._domButton.className = hConfig.cssButtonEnabled;		if (this._domIcon) {			this._domIcon.src = hConfig.iconEnabled;		}	} else {			this._domButton.className = hConfig.cssButtonDisabled;		if (this._domIcon) {			this._domIcon.src = hConfig.iconDisabled;		}	}};DFCButton.prototype.select = function(isSelected) {	// select/deselect button		var hConfig		= this._hConfig;	this.isSelected	= isSelected;	if (this.isSelected) {		// select		this._domButton.className	= hConfig.cssButtonSelected;				this._domLabel.className		= hConfig.cssLabelDown;	} else {		// deselect		this._domButton.className	= hConfig.cssButtonEnabled;		this._domLabel.className		= hConfig.cssLabelEnabled;	}};DFCButton.prototype.getData = function() {	// return custom data	return this._jsData;};DFCButton.prototype.setStatus = function(sType, bStatus) {	// multi purpose status setter		switch(sType) {	case 'onBeforeCommand':		this._onBeforeCommandStatus	= bStatus;		break;	}};DFCButton.prototype.create = function(hWin, opt_domParent) {	// hWin			window object where the button will be created	// opt_domParent	DOM parent element for the button		this._hWin		= hWin;	this._hDoc		= hWin.document;	this._domParent	= opt_domParent || hWin.document.body;		var hConfig		= this._hDFCConfig.get();	var domDoc		= this._hDoc;		var domBtnCont, domLabel;	var domT, domTB, domTR, domTD, domDIV, domImg;		this._hConfig = hConfig;		// ---------------------------- ICON ---------------------------------	if (hConfig.showIcon) {		domTD = domDoc.createElement('td');					domImg = domDoc.createElement('img');				domImg.setAttribute('src', hConfig.iconEnabled, 0);			domImg.setAttribute('border', '0', 0);						this._domIcon 	= domTD.appendChild(domImg);		this._domIconCont = domTD;	}		// ---------------------------- LABEL ---------------------------------	if (hConfig.showLabel) {			domTD = domDoc.createElement('td');			domLabel = domDoc.createElement('div');				domLabel.className = this._isEnabled ?								hConfig.cssLabelEnabled :								hConfig.cssLabelDisabled;				if (hConfig.keyAccess) {									this._domFocus = dfc.createAccessableText(domLabel, this._sLabel);					domLabel.EventButton = this;					dfc.addEventListener(domLabel, 'keydown', this._onEvent);									} else {					domLabel.appendChild(domDoc.createTextNode(this._sLabel));									}			this._domLabel	= domTD.appendChild(domLabel);										this._domLabelCont = domTD;	}			// ---------------------------- BUTTON CONTAINER ---------------------------------	// button container is a table to limit the button's width by it's 'natural' size,	// this prevent's the button to expand to the width of the containing element	domBtnCont = domDoc.createElement('table');	domBtnCont.setAttribute('border', '0', 0);	domBtnCont.setAttribute('cellpadding', '0', 0);	domBtnCont.setAttribute('cellspacing', '0', 0);		domTB = domDoc.createElement('tbody');			domTR = domDoc.createElement('tr');							domTD = domDoc.createElement('td');				domTD.className	= hConfig.cssButtonEnabled;				this._domButton = domTR.appendChild(domTD);			domTB.appendChild(domTR);			domBtnCont.appendChild(domTB);			// ------------------- BUTTON ------------------------					// ------------------- TABLE ------------------------				domT	= domDoc.createElement('table');				domT.setAttribute('border', '0', 0);		domT.setAttribute('cellpadding', '0', 0);		domT.setAttribute('cellspacing', '0', 0);				domTB = domDoc.createElement('tbody');			if (hConfig.alignVertical) {							// ------------------- vertical alignment ------------------------					if (hConfig.showIcon) {							domTR = domDoc.createElement('tr');					domTR.appendChild(this._domIconCont);					domTB.appendChild(domTR);				}					if (hConfig.showLabel) {							domTR = domDoc.createElement('tr');					domTR.appendChild(this._domLabelCont);					domTB.appendChild(domTR);				}			} else {							// ------------------- horizontal alignment ------------------------					domTR = domDoc.createElement('tr');				if (hConfig.showIcon) {							domTR.appendChild(this._domIconCont);				}				if (hConfig.showLabel) {							domTR.appendChild(this._domLabelCont);				}				domTB.appendChild(domTR);			}			domT.appendChild(domTB);		this._domButton.appendChild(domT);			domBtnCont = this._domParent.appendChild(domBtnCont);	dfc.preventTextSelection(domBtnCont);			domBtnCont.EventButton	= this;	dfc.addEventListener(domBtnCont, 'mousemove',	this._onEvent);	dfc.addEventListener(domBtnCont, 'mouseover',	this._onEvent);	dfc.addEventListener(domBtnCont, 'mouseout',		this._onEvent);	dfc.addEventListener(domBtnCont, 'mousedown',	this._onEvent);	dfc.addEventListener(domBtnCont, 'mouseup',		this._onEvent);};		// --------------------------------------------- EVENTS ---------------------------------------DFCButton.prototype._onEvent = function(hEvent) {	hEvent = hEvent || dfc.event(this, hEvent);	var hBtn		= this.EventButton || hEvent.srcElement.EventButton;	var hConfig	= hBtn._hConfig;	if (!hBtn._isEnabled) { return; }		// shortcuts cn=className	var domBtn	= hBtn._domButton;	var domLbl	= hBtn._domLabel;			switch (hEvent.type) {		case 'mousedown':			domBtn.className = hConfig.cssButtonDown;		domLbl.className = hConfig.cssLabelDown;				break;	case 'keydown':	case 'mouseup':		// keyboard events are translated into the corresponding mouse events		var isKeySelect	= false;			if (hEvent.type == 'keydown') {			switch (hEvent.keyCode.toString()) {			case '13':		// enter			case '32':		// space = select				isKeySelect	= true;				break;			}						if (!(isKeySelect)) { break; }		}		if (hConfig.selectOnDown) {			// button can be selected						if (!hBtn.isSelected || (hBtn.isSelected && hConfig.noDeselect == false)) {							// raise 'onBeforeCommand' event				hBtn._onBeforeCommandStatus = true;				hBtn._raiseEvent(hBtn._sEvent_onBeforeCommand, hBtn);								if (hBtn._onBeforeCommandStatus == true) {									// button can be selected									// change selection					hBtn.isSelected = ! hBtn.isSelected;										if (hBtn.isSelected) {						// select now						domBtn.className = hConfig.cssButtonOverSelected;						domLbl.className = hConfig.cssLabelSelected;												// set focus						if (hBtn._domFocus) {							hBtn._domFocus.focus();						}					} else {						// deselect now						domBtn.className = hConfig.cssButtonOver;						domLbl.className = hConfig.cssLabelEnabled;								}					hBtn._raiseEvent(hBtn._sEvent_onCommand, hBtn);				} else {					// button cannot be selected					domBtn.className = hConfig.cssButtonOver;					domLbl.className = hConfig.cssLabelEnabled;				}			} else {				// button is selected but is not allowed to deselect				domBtn.className = hConfig.cssButtonOverSelected;				domLbl.className = hConfig.cssLabelSelected;							}		} else {			// button will not be selected			domBtn.className = hConfig.cssButtonOver;			domLbl.className = hConfig.cssLabelEnabled;			hBtn._raiseEvent(hBtn._sEvent_onCommand, hBtn);		}				break;			case 'mouseover':		if (dfc.isMouseOver(this, hEvent)) {			if (hConfig.selectOnDown) {				if (hBtn.isSelected) {					domBtn.className = hConfig.cssButtonOverSelected;				} else {					domBtn.className = hConfig.cssButtonOver;				}			} else {				domBtn.className = hConfig.cssButtonOver;			}		}		break;	case 'mouseout':		if (dfc.isMouseOut(this, hEvent)) {					if (hConfig.selectOnDown) {				if (hBtn.isSelected) {					domBtn.className = hConfig.cssButtonSelected;					domLbl.className = hConfig.cssLabelSelected;				} else {					domBtn.className = hConfig.cssButtonEnabled;					domLbl.className = hConfig.cssLabelEnabled;				}			} else {				domBtn.className = hConfig.cssButtonEnabled;				domLbl.className = hConfig.cssLabelEnabled;			}			}				break;	}		dfc.stopPropagation(hEvent);};