function ButtonGroup(bgName)
{
	this.name = bgName;
	this.buttons = new Array();
	this.buttonsHtml = "ButtonGroup: Html not created...";
	this.selectedIndex = 0;
	this.oldVal = 0;
	this.listeners = new Array();

	this.buttonPadding = 10;
	this.buttonTopPadding = 0;
	this.buttonSpacing = 2;
	this.buttonColor = "#305";
	this.buttonFontFamily = "Trebuchet MS, Arial, Helvetica, sans-serif";
	this.buttonFontSize = 12;
	this.buttonFontStyle = "normal";
	this.buttonFontWeight = "bold";
	this.buttonBackgroundColor = "transparent";
	this.buttonBorderColor = "transparent";
	this.buttonBorderStyle = "solid";
	this.buttonBorderWidth = 2;
	this.buttonHighlightColor = "white";
	this.buttonHighlightBackgroundColor = "#305";
	this.buttonHighlightBorderColor = "#305";
	this.buttonSelectedBackgroundColor = "white";
	this.buttonSelectedBorderColor = "#305";
	this.buttonSelectedColor = "#305";
}


function buttongroup_actionPerformed(index)
{
	this.unhighlightButton(index);
	this.unhighlightButton(this.oldVal);
	this.oldVal = index;
}

function buttongroup_addActionListener(listener)
{
	this.listeners[this.listeners.length] = "action";
	this.listeners[this.listeners.length] = listener;
}

function buttongroup_addButton(text)
{
	this.buttons[this.buttons.length] = new ButtonLabel(text);
}

function buttongroup_addChangeListener(listener)
{
	this.listeners[this.listeners.length] = "change";
	this.listeners[this.listeners.length] = listener;
}

function buttongroup_createButtonsHtml()
{
	this.buttonsHtml = "<table style='border-spacing: " + this.buttonSpacing + "px 0px;'>";
	this.buttonsHtml += "<tr>";

	for(var i = 0; i < this.buttons.length; i++)
	{
		this.buttonsHtml += "<td id='" + this.buttons[i].name + "' ";
		this.buttonsHtml += "style='";
		this.buttonsHtml += "cursor: pointer; ";
		this.buttonsHtml += "color: " + this.buttonColor + "; ";
		this.buttonsHtml += "font-family: " + this.buttonFontFamily + "; ";
		this.buttonsHtml += "font-size: " + this.buttonFontSize + "pt; ";
		this.buttonsHtml += "font-style: " + this.buttonFontStyle + "; ";
		this.buttonsHtml += "font-weight: " + this.buttonFontWeight + "; ";
		this.buttonsHtml += "border-style: " + this.buttonBorderStyle + "; ";
		this.buttonsHtml += "border-color: " + this.buttonBorderColor + "; ";
		this.buttonsHtml += "border-width: " + this.buttonBorderWidth + "px; ";
		this.buttonsHtml += "padding-top: " + this.buttonTopPadding + "px; ";
		this.buttonsHtml += "padding-bottom: " + this.buttonTopPadding + "px; ";
		this.buttonsHtml += "padding-left: " + this.buttonPadding + "px; ";
		this.buttonsHtml += "padding-right: " + this.buttonPadding + "px;' ";
		this.buttonsHtml += "onmouseover='top." + this.name;
			this.buttonsHtml += ".fireStateChanged(\"onmouseover\", " + i + ")' ";
		this.buttonsHtml += "onmouseout='top." + this.name;
			this.buttonsHtml += ".fireStateChanged(\"onmouseout\", " + i + ")' ";
		this.buttonsHtml += "onclick='top." + this.name;
			this.buttonsHtml += ".fireActionPerformed(" + i + ")' ";
		this.buttonsHtml += ">";

		this.buttonsHtml += this.buttons[i].label;

		this.buttonsHtml += "</td>";
	}

	this.buttonsHtml += "</tr>";
	this.buttonsHtml += "</table>"
}

function buttongroup_fireActionPerformed(index)
{
	this.selectedIndex = index;

	for(var i = 0; i < this.listeners.length; i+=2)
	{
		if(this.listeners[i] == "action")
		{
			eval(this.listeners[i+1] + ".actionPerformed(" + index + ");");
		}
	}
}

function buttongroup_fireStateChanged(eType, index)
{
	for(var i = 0; i < this.listeners.length; i+=2)
	{
		if(this.listeners[i] == "change")
		{
			eval(this.listeners[i+1] + ".stateChanged(\"" + eType + "\", " + index + ")");
		}
	}
}

function buttongroup_getElementAt(index)
{
	return this.buttons[index];
}

function buttongroup_getHtml()
{
	return this.buttonsHtml;
}

function buttongroup_getLength()
{
	return this.buttons.length;
}

function buttongroup_highlightButton(index)
{
	eval("var element = pageFrame.document.getElementById(\"" + this.buttons[index].name + "\")");

	element.style.backgroundColor = this.buttonHighlightBackgroundColor;
	element.style.color = this.buttonHighlightColor;
	element.style.borderColor = this.buttonHighlightBorderColor;
}

function buttongroup_stateChanged(eType, index)
{
	if(eType == "onmouseover")
	{
		this.highlightButton(index);
	}
	else if(eType == "onmouseout")
	{
		this.unhighlightButton(index);
	}
}

function buttongroup_unhighlightButton(index)
{
	eval("var element = pageFrame.document.getElementById(\"" + this.buttons[index].name + "\")");

	if(index == this.selectedIndex)
	{
		element.style.backgroundColor = this.buttonSelectedBackgroundColor;
		element.style.color = this.buttonSelectedColor;
		element.style.borderColor = this.buttonSelectedBorderColor;
	}
	else
	{
		element.style.backgroundColor = this.buttonBackgroundColor;
		element.style.color = this.buttonColor;
		element.style.borderColor = this.buttonBorderColor;
	}
}

ButtonGroup.prototype.actionPerformed = buttongroup_actionPerformed;
ButtonGroup.prototype.add = buttongroup_addButton;
ButtonGroup.prototype.addActionListener = buttongroup_addActionListener;
ButtonGroup.prototype.addChangeListener = buttongroup_addChangeListener;
ButtonGroup.prototype.createHtml = buttongroup_createButtonsHtml;
ButtonGroup.prototype.fireActionPerformed = buttongroup_fireActionPerformed;
ButtonGroup.prototype.fireStateChanged = buttongroup_fireStateChanged;
ButtonGroup.prototype.getElementAt = buttongroup_getElementAt;
ButtonGroup.prototype.getHtml = buttongroup_getHtml;
ButtonGroup.prototype.getLength = buttongroup_getLength;
ButtonGroup.prototype.highlightButton = buttongroup_highlightButton;
ButtonGroup.prototype.stateChanged = buttongroup_stateChanged;
ButtonGroup.prototype.unhighlightButton = buttongroup_unhighlightButton;

