/** 
 * FUNCTION:    whereIsHere
 * DESCRIPTION: Sets the class name of certain menu items to "here" in 
 *              order to implement a "you are here" type of feature.
 * INPUTS:      hereIds - array of strings that are ID attributes of 
 *                        menu items to be classed as "here"
 */
function whereIsHere(hereIds)
{
	if(hereIds == null) return;
   for(var i in hereIds)
	{
		var elem = document.getElementById(hereIds[i]);
		if(elem != null) elem.className = "here";
	}
}








/** 
 * FUNCTION:    shadeOddRows
 * DESCRIPTION: Shades the odd rows within the TBODY tags of the 
 *              tables identified.
 * INPUTS:      tableIds - array of strings that are ID attributes of 
 *                         tables intended to be shaded
 */
function shadeOddRows(tableIds)
{
	if(tableIds == null) return;
   for(var t in tableIds)
	{
		var tbl = document.getElementById(tableIds[t]);
		if(tbl == null) continue;
		
		var tbodies = tbl.getElementsByTagName('tbody');
		if(tbodies == null) continue;
		
      for(var b = 0; b < tbodies.length; b++)
		{
			var rows = tbodies[b].getElementsByTagName('tr');
			if(rows == null) continue;
			
			var r_init = 1; // skip row zero
			var r_step = 2; // skip every other row
			for(var r = r_init; r < rows.length; r += r_step)
			{
            rows[r].className = "odd";
			}
		}
	}
}






/** 
 * FUNCTION:    showDefinition
 * DESCRIPTION: Given a <dt>, displays the corresponding <dd> and
 *              hides all other <dd> content.
 * INPUTS:      dt - HTMLElement object. Selected <dt>
 */
function showDefinition(dt)
{
	if(dt == null) return;
	
	// get enclosing definition list
	var dl = dt.parentNode;
	if(dl == null) return;
	
	// get all <dt> and <dd> elements
	var dts = dl.getElementsByTagName('dt');
	var dds = dl.getElementsByTagName('dd');
	
	// hide all <dd> elements except the one associated
	// with the selected <dt> element
	for(var i = 0; i < dts.length; i++)
	{
		if(dts[i] == dt)
			dds[i].style.display = "block";
		else
			dds[i].style.display = "none";
	}
}






/** 
 * FUNCTION:    body_onLoad
 * DESCRIPTION: Runs several functions that modify page formatting
 *              after the page has loaded.
 */
function body_onLoad()
{
   if(typeof(hereIds) != "undefined") 
      whereIsHere(hereIds);



	if(typeof(stripeTableIds) != "undefined")
      shadeOddRows(stripeTableIds);
}






/** 
 * FUNCTION:    hover
 * DESCRIPTION: Applies or removes "hover" class to the given element.
 * INPUTS:      id - String. ID of element to be modified
 *              on - Boolean. True: apply hover class; False: remove 
 *                   hover class.
 */
function hover(id, on)
{
	if(id == null) return;
   var elem = document.getElementById(id);
	if(elem != null) 
	{
		if(on) elem.className = "hover";
		else elem.className = "";
	}
}
