// 
//	TYGR Productions Interactive Statistics
//	
//	This file contains JavaScript support functions for TYGR Productions' Interactive Statistics.  The code contained herein
//  is NOT in the public domain.  This file is provided for download to personal computers and is only authorized for personal 
//  use in conjuction with TYGR Productions' Interactive Statistics.  Copying or reposting this file in whole or in part on 
//  any web server or other network server, or reusing any portion of the code is not allowed without express written consent 
//  of the author.  Any commercial use is strictly prohibited.
//	
//	Copyright (c) 2005 by Jon T. Camp.  All rights reserved.
// 
function drawBodyCell(cell, bSorted, bLeftAligned, bAlternateRow, cTeamName)
{
	var cTeamClass = cTeamName.replace(" ", "");
	
	if (bSorted)
	{
		if (cFavoriteTeam == cTeamName)
		{
			if (bLeftAligned) cell.className = "td" + cTeamClass + "sort1";
			else cell.className = "td" + cTeamClass + "sort";
		}
		else if (bAlternateRow) 
		{
			if (bLeftAligned) cell.className = "tdhighalt1";
			else cell.className = "tdhighalt";
		}
		else 
		{
			if (bLeftAligned) cell.className = "tdhigh1";
			else cell.className = "tdhigh";
		}
	}
	else if (cFavoriteTeam == cTeamName)
	{
		if (bLeftAligned) cell.className = "td" + cTeamClass + "1";
		else cell.className = "td" + cTeamClass;
	}
	else 
	{
		if (bLeftAligned) cell.className = "td1";
		else cell.className = "";
	}
}

function drawHeaderCell(cell, bSorted, bLeftAligned)
{
	if (bSorted)
	{
		if (bLeftAligned) cell.className = "thhigh1";
		else cell.className = "thhigh";
	}
	else
	{
		if (bLeftAligned) cell.className = "th1";
		else cell.className = "";
	}
}

function drawHighlight(tableData) 
{
	var cell;
	var nMod;
	var nRowDelta = (bDefaultFormat || !bDivideRows ? 1 : 2);
	var row;
	
	for (var i = 0; i < tableData.DataColCount; i++) 
	{
		row = tableData.Table.tHead.rows[dataColToTableHeaderRow(tableData, i)];
		cell = row.cells[dataColToTableHeaderCol(tableData, i)];
		drawHeaderCell(cell, i == tableData.SortIndex, tableData.LeftAlign[i]);
	}
	
	var nodeElement = tableData.Node.getElementsByTagName(tableData.Elements[0]).item(0);
	var nodeList = nodeElement.getElementsByTagName(tableData.IDs[0]);
	
	for (var i = 0; i < tableData.Table.tBodies[0].rows.length; i += nRowDelta) 
	{
		row = tableData.Table.tBodies[0].rows[i];
		
		for (var j = 0; j < tableData.DataColCount; j++) 
		{
			cell = row.cells[dataColToTableCol(j)];
			nMod = (tableRowToDataRow(i) + 1) % 6;
			drawBodyCell(cell, j == tableData.SortIndex, tableData.LeftAlign[j], (nMod == 0) || (nMod > 3), 
										nodeList.item(tableData.Ptr[tableRowToDataRow(i)]).firstChild.nodeValue);
		}
	}			
}

function paintTables()
{
	for (var i = 0; i < aTableData.length; i++) drawHighlight(aTableData[i]);
}

function refreshTotals(tableData) 
{
	calcRank(tableData);
	sortPointers(tableData);
	loadTable(tableData);
}

function selectFavoriteTeamChange(target, selObj)
{
	setCookieData(cFavoriteTeamCookieName, (selObj.selectedIndex).toString());
	if (selObj.selectedIndex > 0) cFavoriteTeam = selObj.item(selObj.selectedIndex).text;
	else cFavoriteTeam = "";
	
	paintTables();
}

function selectFormatChange(target, selObj)
{
	setCookieData(cStatCookieName, (selObj.selectedIndex).toString());
	document.location.reload();
}

