
var hilite_sorted = "#AFAFAF";

/*-----------------------------------------------------------------------------------------------*\
** cols is an array of objects with the following fields:
** hdr_id:		Table header id
** body_id:		Table body id, will have _(rownum) appended (starting at 0)
** align:		Table body alignment
** nowrap:		1 or 0
\*-----------------------------------------------------------------------------------------------*/
function TableSkeleton(table_id, cols, numrows, stylestr, mover_func, mout_func, mclk_func)
{
	var tbg = "666666";
	if (typeof(table_bdr) == "string" && table_bdr.length > 0) tbg = table_bdr;

	var str = "<table id='" + table_id + "' border='0' cellpadding='0' cellspacing='1' style='background-color: #" + tbg + ";";
	if (typeof(stylestr) != "undefined" && stylestr != null && stylestr.length > 0) str += stylestr;
	str += "'><tr id='" + table_id + "'_hdr_row' bgcolor='#";
	if (typeof(table_bg) == "string" && table_bg.length > 0) str += table_bg;
	else str += "DFDFDF";
	str += "'>";

	for (var i = 0 ; i < cols.length;  i++)
	{
		str += "<th id='" + cols[i].hdr_id + "' style='padding: 4px;'";
		if (typeof cols[i].width != "undefined" && cols[i].width)
		{
			str += " width='" + cols[i].width + "'";
		}
		str += ">";
	}
	str += "</tr>";

	var cellid = null;
	var rowid = null;
	for (var i = 0 ; i < numrows ; i++)
	{
		rowid = table_id + "_row_" + i;
		str += "<tr id='" + rowid + "' bgcolor='#";
		if (typeof(table_bg) == "string" && table_bg.length > 0) str += table_bg;
		else str += "FFFFFF";
		str += "'";
		if (typeof(mover_func) != "undefined" && mover_func != null && mover_func.length > 0) str += " onMouseOver='" + mover_func + "(\"" + rowid + "\")'";
		if (typeof(mout_func) != "undefined" && mout_func != null && mout_func.length > 0) str += " onMouseOut='" + mout_func + "(\"" + rowid + "\")'";
		if (typeof(mclk_func) != "undefined" && mclk_func != null && mclk_func.length > 0) str += " onClick='" + mclk_func + "(\"" + rowid + "\")'";
		str += ">";
		for (var j = 0 ; j < cols.length ; j++)
		{
			cellid = cols[j].body_id + "_" + i;
			str += "<td id='" + cellid + "'" + " align='" + cols[j].align + "'";
			if (cols[j].nowrap) str += " nowrap";
			if (typeof cols[j].width != "undefined" && cols[j].width)
			{
				str += " width='" + cols[j].width + "'";
			}
			str += "><span class='gray italic'>" + cellid + "</span></td>";
		}
		str += "</tr>";
	}

	str += "</table>";

	return str;
}

/*-----------------------------------------------------------------------------------------------*/
function TableSkeletonHdr(hdr_id, curr_sort, col_sort, hdr_str, sort_func, title)
{
	var hdr_elem = document.getElementById(hdr_id);

	if (curr_sort && curr_sort == col_sort)
	{
		if (title) str = "<div title='" + title + "'>" + hdr_str + "</div>";
		else str = hdr_str;
		//hdr_elem.style.backgroundColor = hilite_sorted;
	}
	else
	{
		if (sort_func)
		{
			str = "<a href='javascript:" + sort_func + "(\"" + col_sort + "\")'";
			if (title) str += " title='" + title + "'";
			str += ">" + hdr_str + "</a>";
		}
		else if (title) str = "<div title='" + title + "'>" + hdr_str + "</div>";
		else str = hdr_str;
		//hdr_elem.style.backgroundColor = "#DFDFDF";
	}
	hdr_elem.innerHTML = str;
}

/*-----------------------------------------------------------------------------------------------*/
function TableSkeletonHdrId(id, hdr_base, curr_sort, col_sort, hdr_str, sort_func)
{
	var hdr_id = hdr_base + "_" + id;
	var hdr_elem = document.getElementById(hdr_id);

	if (curr_sort && curr_sort == col_sort)
	{
		str = hdr_str;
		//hdr_elem.style.backgroundColor = hilite_sorted;
	}
	else
	{
		if (sort_func)
		{
			str = "<a href='javascript:" + sort_func + "(" + id + ",\"" + col_sort + "\")'>"
					+ hdr_str + "</a>";
		}
		else str = hdr_str;
		//hdr_elem.style.backgroundColor = "#DFDFDF";
	}
	hdr_elem.innerHTML = str;
}


