// tblutilities.js

/******************************************************************************
MkTable (parent)
	Helper to create a table.
******************************************************************************/

function MkTable (parent)
{
	var	t = document.createElement ('table');
	parent.appendChild (t);

	return t;
}

/******************************************************************************
AddTableRow (t)
	Helper to add a row to a table.
******************************************************************************/

function AddTableRow (t)
{
	return t.insertRow (t.rows.length);
}

/******************************************************************************
ClearTable (t)
	Helper to clear a table.
******************************************************************************/

function ClearTable (t)
{
	while (t.rows.length > 0)
		t.deleteRow (0);
}

/******************************************************************************
MkTblHeading (row, itemText, itemClass, itemWidth, itemAlign)
	Helper to create a table heading.
******************************************************************************/

function MkTblHeading (row, itemText, itemClass, itemWidth, itemAlign)
{
	var	cell = document.createElement ("th");
	row.appendChild (cell);
	SetCellSelAttr (cell, itemText, itemClass, itemWidth, itemAlign);
	return cell;
}

/******************************************************************************
MkTblEntry (row, itemText, itemClass, itemWidth, itemAlign)
	Helper to create a table entry.
******************************************************************************/

function MkTblEntry (row, itemText, itemClass, itemWidth, itemAlign)
{
	var	cell = row.insertCell (row.cells.length);
	SetCellSelAttr (cell, itemText, itemClass, itemWidth, itemAlign);
	return cell;
}

/******************************************************************************
SetCellSelAttr (cell, itemText, itemClass, itemWidth, itemAlign)
	Helper to set certain attributes for a cell.
******************************************************************************/

function SetCellSelAttr (cell, itemText, itemClass, itemWidth, itemAlign)
{
	if (itemClass)
		SetClass (cell, itemClass);

	if (itemWidth)
		cell.setAttribute ("width", itemWidth);

	if (itemAlign)
		cell.setAttribute ("align", itemAlign);

/*
	if (itemText)
		cell.appendChild (document.createTextNode (itemText));
*/
	// EWZ 2007-01-25 Enable html in the text.

	if (itemText != null && itemText != undefined)
		cell.innerHTML = itemText;

	return cell;
}

/******************************************************************************
GetCellElementTable (cellel)
	Helper to return a refrence to a cell.
******************************************************************************/

function GetCellElementTable (cellel)
{
	// Get the table containing the cell element.
	//	The parent of the element is the cell (the <td>).
	//	The parent of the cell is the row (the <tr>).
	//	The parent of the row is the table section.
	//	The parent of the table section is, finally, the table.

	return cellel.parentNode.parentNode.parentNode.parentNode;
}

/******************************************************************************
GetCellItem (t, nRow, nCol)
	Helper to return a refrence to a cell.
******************************************************************************/

function GetCellItem (t, nRow, nCol)
{
	return t.rows [nRow].cells [nCol];
}

/******************************************************************************
GetEntryItem (t, nRow, nCol)
	Helper to return a refrence to the entry item for a cell.
******************************************************************************/

function GetEntryItem (t, nRow, nCol)
{
	return GetCellItem (t, nRow, nCol).firstChild;
}

/******************************************************************************
GetEntryValue (t, i, j)
	Helper to return the value in a cell.
******************************************************************************/

function GetEntryValue (t, i, j)
{
	return GetEntryItem (t, i, j).value;
}

/******************************************************************************
SetEntryValue (t, i, j,  value)
	Helper to set the value in a cell.
******************************************************************************/

function SetEntryValue (t, i, j, value)
{
	GetEntryItem (t, i, j).value = value;
}

/******************************************************************************
SetEntryIDValue (t, i, j, id, value)
	Helper to set the value in a cell.
******************************************************************************/

function SetEntryIDValue (t, i, j, id, value)
{
	GetEntryItem (t, i, j).id = id;
	GetEntryItem (t, i, j).value = value;
}

/******************************************************************************
GetEntryText (t, i, j)
	Helper to get the text in a cell.
******************************************************************************/

function GetEntryText (t, i, j)
{
	return GetEntryItem (t, i, j).data;
}

/******************************************************************************
SetEntryText (t, i, j, text)
	Helper to set the text in a cell.
******************************************************************************/

function SetEntryText (t, i, j, text)
{
	GetEntryItem (t, i, j).data = text;
}

/******************************************************************************
GetEntryAttr (t, i, j, attr)
	Helper to return the value of the requested attribute for an entry.
******************************************************************************/

function GetCellAttr (t, i, j, attr)
{
	return GetEntryItem (t, i, j).getAttribute (attr);
}

/******************************************************************************
SetEntryAttr (t, i, j, attr, value)
	Helper to set the value of the requested attribute for a entry.
******************************************************************************/

function SetEntryAttr (t, i, j, attr, value)
{
	GetEntryItem (t, i, j).setAttribute (attr, value);
}

/******************************************************************************
GetCellAttr (t, i, j, attr)
	Helper to return the value of the requested attribute for a cell.
******************************************************************************/

function GetCellAttr (t, i, j, attr)
{
	return GetCellItem (t, i, j).getAttribute (attr);
}

/******************************************************************************
SetCellAttr (t, i, j, attr, value)
	Helper to set the value of the requested attribute for a cell.
******************************************************************************/

function SetCellAttr (t, i, j, attr, value)
{
	GetCellItem (t, i, j).setAttribute (attr, value);
}

/******************************************************************************
GetRowEntryText (row, nCol)
	Helper to get the text in a cell from a row.
******************************************************************************/

function GetRowEntryText (row, nCol)
{
	return row.cells [nCol].firstChild.data;
}

