function toggleShowHide(myid,showMsg,hideMsg) {
	// Used to "show" or "hide" a div.  Used
	// in conjunction with the "shFilter" and "shInstr" id's
	//
	
	if (myid == "filter") {
		var id = "shFilter";
		var toggleId = "shTogFilter";
		}
	else if (myid == "ColSettings") {
		var id = "shColSets";
		var toggleId = "shTogColSets";
		}		
	else if (myid == "lcGamesToday") {
		var id = "lcGamesToday";
		var toggleId = "shTogGamesToday";
		}		
	else if (myid == "realNames") {
		var id = "shRealNames";
		var toggleId = "shTogRealNames";
		}		
	else {  // default to myid = 'instructions'
		var id = "shInstr";
		var toggleId = "shTogInstr";
		}
	
	var divEl = document.getElementById(id);
	var aEl = document.getElementById(toggleId);
	
	if (divEl.className == "hidden") {
		divEl.className = "";
		aEl.innerHTML = hideMsg;
		}
	else {
		divEl.className = "hidden";
		aEl.innerHTML = showMsg;
		}

	//	return false;
}

function showHideColumn(tableid,toggleid,colClass,showMsg,hideMsg) {
	// Used to "show" or "hide" a column in a table
	//
	// tableid:  id of the table
	// toggleid:  id of the anchor that acts as the toggle switch
	// colClass:  the class of the column (th and td's) that are to be hidden
	// showMsg:  the "show" link text for the toggle (e.g. "Show Real Names")
	// hideMsg:  the "hide" link text for the toggle (e.g. "Hide Real Names")
	
	
	var myToggle = document.getElementById(toggleid);

	var myTable = document.getElementById(tableid);
	var myHeaders = myTable.getElementsByTagName('TH');
	var myCells = myTable.getElementsByTagName('TD');
		
	for (i=1; i<myHeaders.length; i++)
	if (myHeaders[i].className == colClass + " hidden") {
		myHeaders[i].className = colClass;
		}
	else if (myHeaders[i].className == colClass){
		myHeaders[i].className = colClass + " hidden";
		
		}

	for (i=1; i<myCells.length; i++)
	if (myCells[i].className == colClass + " hidden") {
		myCells[i].className = colClass;
		}
	else if (myCells[i].className == colClass) {
		myCells[i].className = colClass + " hidden";
		}
	
	if (myToggle.innerHTML == hideMsg)
		myToggle.innerHTML = showMsg;
	else 
		myToggle.innerHTML = hideMsg;
		
	var standingsHeader = document.getElementById('standingsHeader');
	
	if (standingsHeader) {
		if (myToggle.innerHTML == hideMsg)
			standingsHeader.colSpan = standingsHeader.colSpan + 1;
		else 
			standingsHeader.colSpan = standingsHeader.colSpan - 1;
		}
	//	return false;
}

function help(helpid) 
{
	var r_window = window.open('help_window.cfm?helpid='+helpid,'Help','height=250,width=550,resizable,scrollbars');
	r_window.focus();
	return true;
}

function showHide(myid) {
	// Used to "show" or "hide" a div based on checking a box. 
		
	var divEl = document.getElementById(myid);
	
	if (divEl.className == "hidden") {
		divEl.className = "";
		}
	else {
		divEl.className = "hidden";
		}

	//	return false;
}

function textAreaLength(textbox,maxlength,countID) {
		var mylen = textbox.value.length;
		if (mylen > maxlength) {
			textbox.value = textbox.value.substring(0,maxlength);
			mylen = mbox.value.length;
		 }
		if (mylen > 0.9 * maxlength) {
		document.getElementById(countID).className = 'alert';
		document.getElementById(countID).innerHTML = mylen;
		} else {
		document.getElementById(countID).className = '';
		document.getElementById(countID).innerHTML = mylen;
		}
	}
	
	
/* To use this function, you need to put "name='tab'" in the anchor tag
	and id the tabs and tab panes apropriately, like id="tab_1" etc. */
function switchTab(iTab) {
		
		if (!window.myTabs) {
			// set the selected tab (hide the others)
			
			myTabPane = document.getElementById('tabPane');
			var myLinks=document.getElementsByTagName("A");
			j=0;
			myTabs = new Array;
			myTabPanes = new Array;
			for (i=0; i<myLinks.length; i++) {
			 	if (myLinks[i].name == "tab") {
					myTabs[j] = document.getElementById('tab_'+j);
					myTabPanes[j] = document.getElementById('tabPane_'+j);
					j++;
				}	
			}
			
		}
		
		for (i=0; i<myTabs.length; i++) { 
			if (i==iTab) {
				if(myTabs[i].className == 'tab selected') {
					myTabs[i].className = "tab";
					myTabPanes[i].className = "hidden";
					myTabPane.className = "tabpane hidden"
					}
				else { 
					myTabs[i].className = "tab selected";
					myTabPanes[i].className = "";
					myTabPane.className = "tabpane"
					}
			}
			else {
				myTabs[i].className = "tab";
				myTabPanes[i].className = "hidden";
			}
		}
		
		return false;
	}


/*-----------------------------------------------------------------------------
	sortTable(id, col, rev, ranks, sortTypeFlag)

	id  - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted.
	col - Index of the column to sort, 0 = first column, 1 = second column,
        etc.
  rev - If true, the column is sorted in reverse (descending) order
        initially.
  ranks - If true, the "rank" is calculated and displayed in the first column.
  
  sortTypeFlag - (optional) Generally not used, this can be used to specify the 
  sort type. Currently there are only three sort types defined: text, numeric, and count.
  

 Note: the team name column (index 1) is used as a secondary sort column and
 always sorted in ascending order.
-----------------------------------------------------------------------------*/

function sortTable(id, col, rev, ranks, sortTypeFlag)
	{
		try 
			{
				// Create the table reference
				var tbl = document.getElementById(id)
				
				// Determine how many rows are in the table
				var noRows = tbl.rows.length
						
				// Create an array to track the sort direction for each column 
				if (typeof(sortDir) == 'undefined') {sortDir = new Array()}	
				
				// If this column has not been sorted before, set the initial sort direction to the direction specified.		
				if (sortDir[col] == null) {sortDir[col] = rev}
				
				// If this column was the last one sorted, reverse its sort direction
				if (typeof(lastCol) != 'undefined' && col == lastCol) {sortDir[col] = !sortDir[col]}
				
				// Record the last column sorted
				lastCol = col	
				
				// Declare a multi-dimensional array to hold the table data. Note that it would probably be more
				// efficient to declare and populate this table array only once. This could lead to problems in cases
				// when more than one table is present on a page.
				tableArray = new Array() 
				
				// Declare the table rows
				for (var i = 0; i < noRows; i ++) {tableArray[i] = new Array(2)}

				// Populate the table array with the contents of the HTML table using the gettext function
				for (i = 0; i < noRows; i++)
					{
						tableArray[i][0] = getTextValue(tbl.rows[i].cells[col])
						tableArray[i][1] = i; // keep track of "where each row went"
					} // end for i
						
				// If a specific sortType is not provided, sort the array based on the current in-place table sort
				// implemenation. Since this technique requires data processing, we will perform this processing to the specified
				// search column in the table array before sorting the array.
				
				if (!sortTypeFlag) 
                    {
                   	// No sort type was provided; determine the sort type from the column date type
                    var sortTypeFlag = "numeric"
				    for (var i = 0; i < noRows; i ++) {if (isNaN(parseFloat(tableArray[i][0]))) {sortTypeFlag = "text"; break}} // at least one element was non-numeric}
                    } 
						
				// Update the data in the tableArray
				if (sortTypeFlag == "text") 
                    {for (var i = 0; i < noRows; i ++) {tableArray[i][0] = tableArray[i][0].toUpperCase()}}                    
				else if (sortTypeFlag == "count") 
                    {for (var i = 0; i < noRows; i ++) 
                        {
                        if (isNaN(tableArray[i][0])) {tableArray[i][0] = -1} // sort text last
                        else {tableArray[i][0] = parseInt(tableArray[i][0],10)}
                        }
                    } 
                else {for (var i = 0; i < noRows; i ++) {tableArray[i][0] = parseFloat(tableArray[i][0])}}
									
				// Sort the tableArray		
				Sort(sortDir[col]) // tableArray is global	
					
				// Adjust the ranks if requested
				if (ranks) 					
					{	
						// Declare a temporary array to store the ranks
						var rankArray = new Array(noRows)
						
						if (sortDir[col] == rev)
							{
								rankArray[0] = 1
								for (i = 1; i < noRows; i++)
									{
										if (tableArray[i][0] != tableArray[i-1][0]) {rankArray[i] = i+1}
										else {rankArray[i] = rankArray[i-1]}
									} // end i-loop 								
							} // end if
						else
							{
								rankArray[noRows-1] = 1
								for (i = noRows-2; i >= 0; i--)
									{
										if (tableArray[i][0] != tableArray[i+1][0]) {rankArray[i] = noRows-i}
										else {rankArray[i] = rankArray[i+1]}
									} // end i-loop 
							} // end else
					} // end if ranks == "true"				

				// Repopulate original HTML based on the position change of rows in the tableArray
				for (i = 0; i < noRows; i++)
					{removeRowID = tableArray[i][1]
						for (j = i; j < noRows; j++) {if (removeRowID > tableArray[j][1]){tableArray[j][1]++}}
						if (i != removeRowID) 
							{	
								tmpRow = tbl.removeChild(tbl.rows[removeRowID]); // this is the row we wish to delete and place below
								tbl.insertBefore(tmpRow,tbl.rows[i])
							}			
					} // end i-loop
					
				// Add ranks
				if (ranks)
					{
						for (i = 0; i < noRows; i++)
							{
								while (tbl.rows[i].cells[0].lastChild != null) {tbl.rows[i].cells[0].removeChild(tbl.rows[i].cells[0].lastChild)}
								tbl.rows[i].cells[0].appendChild(document.createTextNode(rankArray[i]));									
							} // end i-loop
					}							
			} // end try
		catch (er)
			{
			} // end catch
			
	return false
	} // end function sortTable

function getTextValue(el) {

  var i;
  var s;

	// This code is necessary for browsers that don't reflect the DOM constants
	// (like IE).
	if (document.ELEMENT_NODE == null) 
		{
  		document.ELEMENT_NODE = 1;
  		document.TEXT_NODE = 3;
		}

  // Find and concatenate the values of all text nodes contained within the
  // element.
  s = "";
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[i]);

  return normalizeString(s);
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) 
	{
		// Regular expressions for normalizing white space.
		var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
		var whtSpMult = new RegExp("\\s\\s+", "g");
  	s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  	s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.
	  return s;
	}

function Sort(dir) 
	{
			// Sort the array
			if (!dir) {tableArray = merge_sort(tableArray,SortA)}
			else {tableArray = merge_sort(tableArray,SortD)}
				
			function merge(left,right,comparison)
				{
					var result = new Array();
					while((left.length > 0) && (right.length > 0))
						{
							if(comparison(left[0],right[0]) <= 0)
								{result.push(left.shift())}
							else
								{result.push(right.shift())}
						} // end while		
					while(left.length > 0) {result.push(left.shift())}
					while(right.length > 0) {result.push(right.shift())}
					return result;
				} // end function merge


			function merge_sort(array,comparison)
				{
					if(array.length < 2) {return array}
					var middle = Math.ceil(array.length/2);
					return merge(merge_sort(array.slice(0,middle),comparison), merge_sort(array.slice(middle),comparison), comparison);
				}	// end function merge_sort

			function SortA(x1,x2) {if (x1[0] == x2[0]) return 0; if (x1[0] > x2[0]) return 1; return -1}
			function SortD(x1,x2) {if (x1[0] == x2[0]) return 0; if (x1[0] < x2[0]) return 1; return -1}

	} // end function Sort

