if (!BUTTON_REFERENCE) {
	var BUTTON_REFERENCE = new Object();
}
var Button = function(divID, dataObject) {
	this.setDivID(divID);
	this.setDataObject(dataObject);
	this.setWidth("120px");
	this.setFontFamily("Verdana, Arial, Helvetica, sans-serif");
	this.setFontSize("10px");
	this.setFontWeight("bold");
	this.setMargin("0px");
	this.setPadding("1px");
	this.setTextAlign("center");
	this.setBorderStyle("solid");
	this.setBorderWidth("1px");
	this.setNormalFontColor("#FFFFFF");
	this.setOverFontColor("#000000");
	this.setDownFontColor("#000000");
	this.setNormalBackgroundColor("#DA8901");
	this.setOverBackgroundColor("#FCAA03");
	this.setDownBackgroundColor("#6D9FBC");
	this.setNormalBackgroundImage("none");
	this.setOverBackgroundImage("none");
	this.setDownBackgroundImage("none");
	this.setNormalBorderColor("#FA9D7E #FA9D7E #FA9D7E #FA9D7E");
	this.setOverBorderColor("#FA9D7E #FA9D7E #FA9D7E #FA9D7E");
	this.setDownBorderColor("#FA9D7E #FA9D7E #FA9D7E #FA9D7E");
	this.status = "NULL";
}
Button.prototype.setDivID = function(value) {
	if (document.getElementById(value)) {
		this.divID = value;
	}
}
Button.prototype.setDataObject = function(value) {
	this.dataObject = value;
}
Button.prototype.setWidth = function(value) {
	this.width = value;
}
Button.prototype.setFontFamily = function(value) {
	this.fontFamily = value;
}
Button.prototype.setFontSize = function(value) {
	this.fontSize = value;
}
Button.prototype.setFontWeight = function(value) {
	this.fontWeight = value;
}
Button.prototype.setMargin = function(value) {
	this.margin = value;
}
Button.prototype.setPadding = function(value) {
	this.padding = value;
}
Button.prototype.setTextAlign = function(value) {
	this.textAlign = value;
}
Button.prototype.setBorderStyle = function(value) {
	this.borderStyle = value;
}
Button.prototype.setBorderWidth = function(value) {
	this.borderWidth = value;
}
Button.prototype.setNormalFontColor = function(value) {
	this.normalFontColor = value;
}
Button.prototype.setOverFontColor = function(value) {
	this.overFontColor = value;
}
Button.prototype.setDownFontColor = function(value) {
	this.downFontColor = value;
}
Button.prototype.setNormalBackgroundColor = function(value) {
	this.normalBackgroundColor = value;
}
Button.prototype.setOverBackgroundColor = function(value) {
	this.overBackgroundColor = value;
}
Button.prototype.setDownBackgroundColor = function(value) {
	this.downBackgroundColor = value;
}
Button.prototype.setNormalBackgroundImage = function(value) {
	this.normalBackgroundImage = value;
}
Button.prototype.setOverBackgroundImage = function(value) {
	this.overBackgroundImage = value;
}
Button.prototype.setDownBackgroundImage = function(value) {
	this.downBackgroundImage = value;
}
Button.prototype.setNormalBorderColor = function(value) {
	this.normalBorderColor = value;
}
Button.prototype.setOverBorderColor = function(value) {
	this.overBorderColor = value;
}
Button.prototype.setDownBorderColor = function(value) {
	this.downBorderColor = value;
}
Button.prototype.checkParams = function() {
	if (this.divID && this.dataObject && this.width) {
		return true;	
	} else {
		return false;	
	}
}
Button.prototype.resize = function() {
	if (this.checkParams()) {
		document.getElementById(this.buttonDivID).style.fontFamily = this.fontFamily;
		document.getElementById(this.buttonDivID).style.fontSize = this.fontSize;
		document.getElementById(this.buttonDivID).style.fontWeight = this.fontWeight;
		document.getElementById(this.buttonDivID).style.fontFamily = this.fontFamily;
		document.getElementById(this.buttonDivID).style.fontSize = this.fontSize;
		document.getElementById(this.buttonDivID).style.fontWeight = this.fontWeight;
	}
}
Button.prototype.attach = function() {
	if (this.checkParams()) {
		BUTTON_REFERENCE[this.divID] = this;
		this.buttonDivID = this.divID + '_button';
		var name = this.dataObject.name;
		var myDiv = '<div ';
		myDiv += 'id="' + this.buttonDivID + '" ';
		myDiv += 'style=" ';
		myDiv += 'background-color:' + this.normalBackgroundColor + '; ';
		myDiv += 'background-image:' + this.normalBackgroundImage + '; ';
		myDiv += 'border-color:' + this.normalBorderColor + '; ';
		myDiv += 'color:' + this.normalFontColor + '; ';
		myDiv += 'border-style:' + this.borderStyle + '; ';
		myDiv += 'border-width:' + this.borderWidth + '; ';
		myDiv += 'cursor:pointer; ';
		myDiv += 'float:left; ';
		myDiv += 'display:block; ';
		myDiv += 'margin:' + this.margin + '; ';
		myDiv += 'padding:' + this.padding + '; ';
		myDiv += 'text-align:' + this.textAlign + '; ';
		myDiv += 'width:' + parseInt(this.width) + 'px; ';
		myDiv += '"';
		myDiv += '>';
		myDiv += name;
		myDiv += '</div>';
		document.getElementById(this.divID).innerHTML = myDiv;
		this.resize();
		if (document.all) {
			document.getElementById(this.divID).attachEvent("onmouseover", this.eventListener);
			document.getElementById(this.divID).attachEvent("onmouseout", this.eventListener);
			document.getElementById(this.divID).attachEvent("onmousedown", this.eventListener);
			document.getElementById(this.divID).attachEvent("onmouseup", this.eventListener);
		} else {
			document.getElementById(this.divID).addEventListener("mouseover", this.eventListener, false);
			document.getElementById(this.divID).addEventListener("mouseout", this.eventListener, false);
			document.getElementById(this.divID).addEventListener("mousedown", this.eventListener, false);
			document.getElementById(this.divID).addEventListener("mouseup", this.eventListener, false);
		}
	}
}
Button.prototype.eventListener = function(evt) {
	if (document.all) {
		var div = evt.srcElement;
	} else {
		var div = evt.target;
	}
	var referenceID = div.parentNode.id;
	if (referenceID) {
		switch (evt.type) {
		case "mouseover" :
			BUTTON_REFERENCE[referenceID].doRollOver(div);
			break;
		case "mouseout" :
			BUTTON_REFERENCE[referenceID].doRollOut(div);
			break;
		case "mousedown" :
			BUTTON_REFERENCE[referenceID].doPress(div);
			break;
		case "mouseup" :
			BUTTON_REFERENCE[referenceID].doRollOver(div);
			BUTTON_REFERENCE[referenceID].doRelease();
			break;
		}
	}
}

Button.prototype.doRollOut = function(div) {
	if (document.all) {
		window.status = this.status;
	}
	div.style.backgroundColor = this.normalBackgroundColor;
	div.style.backgroundImage = this.normalBackgroundImage;
	div.style.borderColor = this.normalBorderColor;
	div.style.color = this.normalFontColor;
}
Button.prototype.doRollOver = function(div) {
	if (document.all) {
		if (this.status == "NULL") {
			this.status = window.status;
		}
		var name = this.dataObject.name;
		window.status = name;
	}
	div.style.backgroundColor = this.overBackgroundColor;
	div.style.backgroundImage = this.overBackgroundImage;
	div.style.borderColor = this.overBorderColor;
	div.style.color = this.overFontColor;
}
Button.prototype.doPress = function(div) {
	div.style.backgroundColor = this.downBackgroundColor;
	div.style.backgroundImage = this.downBackgroundImage;
	div.style.borderColor = this.downBorderColor;
	div.style.color = this.downFontColor;
}
Button.prototype.doRelease = function() {
	var url = this.dataObject.url;
	var target = this.dataObject.target;
	if (!target) {
		target = "_self";
	}
	if (url) {
		window.open(url, target);
	}
}

