/*
  PMI website common functions
  

Author: Brendan O'Connor
Date: December 23, 2003
*/
var subMenu = "sub99";

function getAndSetShow( aLabel, aShowType )
{
  x = 0;
  while ( document.getElementsByName( aLabel )[x] != undefined )
  {
    activeTab = document.getElementsByName( aLabel )[x++];
    activeTab.style.display = aShowType;  
  } 
}

function getObjectStyle(obj) 
{
	var theObj
	if (document.layers) {
		if (typeof obj == "string") {
			// just one layer deep
			return document.layers[obj]
		} else {
			// can be a nested layer
			return obj
		}
	}
	if (document.all) {
		if (typeof obj == "string") {
			return document.all(obj).style
		} else {
			return obj.style
		}
	}
	if (document.getElementById) {
		if (typeof obj == "string") {
			return document.getElementById(obj).style
		} else {
			return obj.style
		}
	}
	return null
}

function getObject(obj) {
	var theObj
	if (document.all) {
		if (typeof obj == "string") {
			return document.all(obj)
		} else {
			return obj.style
		}
	}
	if (document.getElementById) {
		if (typeof obj == "string") {
			return document.getElementById(obj)
		} else {
			return obj.style
		}
	}
	return null
}

function hideMenu()
{
  var subTable = null
	if ( subMenu != "sub99" )
	{       
		subTable = getObjectStyle(subMenu);
		subTable.display = "none";
	}
}

function showMenu()
{
  var subTable = null
 	if ( subMenu != "sub99" )
 	{ 
 		subTable = getObjectStyle(subMenu)
 		subTable.display = "inline";
	}
  else
  {
    hideMenu()
  }
}

function activateMenu( aSubMenu )
{
 	if ( aSubMenu != "sub99" )
 	{ 
    subMenu = "sub" + aSubMenu;
  }
}

function loadRow( aRanking, aHeader, aBody, aDetailLink)
{
  var oneRecord = new Object()
  oneRecord.aRanking = aRanking
  oneRecord.aHeader= aHeader
  oneRecord.aBody= aBody
  oneRecord.aDetailLink= aDetailLink
  
  return oneRecord
}

function deleteRows(tbl) 
{
  if ( tbl != null )
  {
  	while (tbl.rows.length > 0) 
  	{
  		tbl.deleteRow(0)
  	}
  }
}

/*******************
  UTILITY FUNCTIONS
********************/
// day of week of month's first day
function getFirstDay(theYear, theMonth){
	var firstDate = new Date(theYear,theMonth,1)
	return firstDate.getDay()
}
// number of days in the month
function getMonthLen(theYear, theMonth) {
//	var oneDay = (1000 * 60 * 60 * 23.95)
  var oneDay = 86220000;
	var thisMonth = new Date(theYear, theMonth, 1)
	var nextMonth = new Date(theYear, theMonth + 1, 1)
	var len = Math.floor((nextMonth.getTime() - thisMonth.getTime())/oneDay)
	return len
}

function doPrintPrep()
{
  switchPrint( getObject("headPanel"), "none" )
  switchPrint( getObject("navPanel"), "none" )
  var main = getObject("main")
  main.className = "printBody";
  var mainPanel = getObject("detailPanel");
  mainPanel.className = "";
  var mainTable = getObject("detailTable");
  mainTable.width = "70%"
  resizePage();  
}

function doPrintDone()
{
  switchPrint( getObject("headPanel"), "inline" );
  switchPrint( getObject("navPanel"), "inline" );
  var main = getObject("main");
  main.className = "pageBody";
  var mainPanel = getObject("detailPanel");
  mainPanel.className = "detailPanel";  
  var mainTable = getObject("detailTable");
  mainTable.width = "80%"
  resizePage();
}

function switchPrint( aObject, aType )
{
  aObject.style.display = aType
}

function getCurrentYear()
{
	var today = new Date()
  var thisMonth = today.getMonth()
	return today.getFullYear()
}

function monthDayFormat(val) 
{   // convert month or day number to string, padding with leading zero if needed
	if (isNaN(val) || val == 0) 
  {
		return "01"
	}
  else if (val < 10) 
  {
		return "0" + val	
	}
	return "" + val
}

function clearTable(aTableName)
{
  deleteRows(getObject(aTableName));
}

function addHardLine(aTableName)
{
  newRow = getObject(aTableName).insertRow(rowId++);
  emptyRow( newRow, 5, "<hr>")
  
}

function emptyCell(Trow, aValue)
{
	var newCell = Trow.insertCell(Trow.cells.length)
  if ( aValue != undefined )
  {
    newCell.innerHTML = aValue
  }
  else
  {
    newCell.innerHTML = "&nbsp;"
  }
}

function emptyRow(Trow, cellCount, aValue)
{
  var cells = 0
  while ( cells < cellCount )
  {
    emptyCell( Trow, aValue )
    cells++
  }
}

function loadXMLNodes(aFileName)
{
  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.load(aFileName);
  
  return xmlDoc.documentElement.childNodes;
}

function getXMLElementValue( aElement, aValue )
{
 return aElement.getElementsByTagName(aValue).item(0).text
}

function getCurrentDate()
{
  var today = new Date()
  var thisDay = today.getDate()
  var thisMonth = today.getMonth()
	var thisYear = today.getFullYear()
  return thisYear + "/" + monthDayFormat((thisMonth+1))+"/" +monthDayFormat((thisDay))
}