MRFToolBar.SelectedButton = null;

function MRFToolBar(nRows, nCols)
{
	if (nRows < 1 || nCols < 1)
	{
		alert("Failed to create tool bar.\n\nThe rows and columns of the tool bar must be greater than 0");
		return;
	}
	
	this.nRows = nRows;
	this.nCols = nCols;
	
	this.strBGColor = "#cccccc";
	
	this.aryButtons = new Array(nRows * nCols);
	
	this.AddButton = MRFToolBar_AddButton;
	this.SetBGColor = MRFToolBar_SetBGColor;
	this.Show = MRFToolBar_Show;
	this.SetSelectedButton = MRFToolBar_SetSelectedButton;
}

function MRFToolBar_SetBGColor(strColor)
{
	this.strBGColor = strColor;
}

function MRFToolBar_AddButton(oButton, nRow, nCol)
{
	if (nRow < 1 || nRow > this.nRows)
	{
		alert("The row number of a button must be between 1 and " + this.nRows);
		return;
	}
	else if (nCol < 1 || nCol > this.nCols)
	{
		alert("The column number of a button must be between 1 and " + this.nCols);
		return;
	}
	
	this.aryButtons[(nRow - 1) * this.nCols + (nCol - 1)] = oButton;
}

function MRFToolBar_Show(oDoc)
{
	oDoc.write("<!-- start of tool bar -->")
	oDoc.write("<table summary='Layout Table' border=0 cellspacing=0 cellpadding=0 bgcolor=\"" + this.strBGColor + "\">");
	
	for (i = 0; i < this.aryButtons.length; i++)
	{
		if (i % this.nCols == 0)
			oDoc.write("<tr>");
		
		oDoc.write("<td>");
		
		if (this.aryButtons[i] == null)
			oDoc.write("&nbsp;&nbsp;&nbsp;&nbsp;");
		else
			this.aryButtons[i].Show(oDoc);
		
		oDoc.write("</td>");
		
		if ((i + 1) % this.nCols == 0)
			oDoc.write("</tr>");
	}
	
	oDoc.write("</table>\n");
	oDoc.write("<!-- end of tool bar -->");
}

function MRFToolBar_SetSelectedButton(nRow, nCol)
{
	if (nRow < 1 || nRow > this.nRows)
	{
		alert("The row number of a button must be between 1 and " + this.nRows);
		return;
	}
	else if (nCol < 1 || nCol > this.nCols)
	{
		alert("The column number of a button must be between 1 and " + this.nCols);
		return;
	}
	
	var button = this.aryButtons[(nRow - 1) * this.nCols + (nCol - 1)];
	
	button.Select();
}