/* #############################################################################

NS: TESCO.lib.UI.button
	static: yes

dependancies:
	TESCO.system.event
	TESCO.system.DOM.node
	
############################################################################# */

if(!TESCO.lib.UI) {
	TESCO.lib.UI = {};
}

TESCO.lib.UI.button = new function() {
	this.VERSION = "1.0.0";
	this.NAME = "TESCO.lib.UI.button";

	var _self = this;
	
	this.insert = function(id, buttonText, functionPointer, imgSrc) {
		if(document.getElementById && document.createTextNode) {
			var o = document.getElementById(id);
			if(o) {
				o.className = (o.className + " button").trim();
				var oA = TESCO.system.DOM.node.create("a");
				oA.style.textDecoration = "none";
				oA.href = "#";
				oA.tabIndex = -1;
				oA.setAttribute("buttonId", id);
				TESCO.system.event.attach(oA, "click", functionPointer);
				o.appendChild(oA);
		
				if(imgSrc) {
					var oImg = TESCO.system.DOM.node.create("img");
					oImg.src = imgSrc;
					oImg.alt = buttonText;
					oA.appendChild(oImg);
				} else {
					var oButton = TESCO.system.DOM.node.create("input");
					oButton.type = "button";
					oButton.value = buttonText;
					oA.appendChild(oButton);
				}
			}
		}
		
		return false;
	}
	
	this.print = function(id, buttonText, imgSrc) {
		if(window.print) {
			return _self.insert(id, (buttonText ? buttonText : "Print this page"),
				function(e) {
					e.stopEvent();
					window.print();
				},
				(imgSrc ? imgSrc : "/i/b/btnPrintPage.gif"));
		}
	}

	this.close = function(id, buttonText, imgSrc) {
		if(window.print) {
			return _self.insert(id, (buttonText ? buttonText : "Close this window"),
				function(e) {
					e.stopEvent();
					self.close();
				},
				(imgSrc ? imgSrc : "/i/b/btnClose.gif"));
		}
	}
}


