/* script for left navigation links - user-editable items on lines 5 thru 10; last modified by renn 02-22-07 */

var anchorCount=1;

//defines the name of the container in which the left nav actions should be added
var container = 'leftcontainer';

// defines with div id's to skip when adding left nav rollovers, etc. 
var divsToSkip = new Array('lefttopcontent','leftbottomcontent','leftnews');

function generateNav() {
	var nav = document.getElementById(container);
	if(nav == null) return;
	doAnchors(nav);
	doSubNavs(nav);
	makeVisible(nav);
}

function makeVisible(nav) {
	nav.className = 'NavLeftShow';
	}
		

function doAnchors(n) {

   if (n == null) 
      return;
	  
 var numNodes = n.childNodes.length;

for (var i = 0; i < numNodes; i++) {
	 var status = 'inactive'

		if(divsToSkip.indexOf(n.getAttribute('id')) >= 0) { 
			return;
		}

		else if(n.nodeName.toLowerCase() == 'a'){
			   
			var isActivePage = checkURL(n);
			
			if (isActivePage){
			status = 'active';
			}
	
			applyAnchorStyles(n,status,anchorCount);
			applyTableStyles(n,status);
			addTableRowAndImage(n,status);
			anchorCount++
			return;
			}
		
	  else {	

	  doAnchors(n.childNodes[i]);
			if (numNodes < n.childNodes.length) {
				// we added elements
				i++;
			}
		}
   }   

}

function doSubNavs(n) {

   if (n == null) 
      return;
	  
var numNodes = n.childNodes.length;

for (var i = 0; i < numNodes; i++) {
	
	if(n.className == 'NavLeftActiveSel'){
	
	
	anchorNum = parseInt(n.getAttribute('id'));
	
	activeNode = document.getElementById(anchorNum);
	nextNode = document.getElementById(anchorNum+1);

	if(!checkIfSubNav(activeNode) && checkIfSubNav(nextNode) ){
	subParentNumber = anchorNum;
	lastSubNavItem = getLastSubNavItem(anchorNum+1);
	}
	else {
	subParentNumber = getSubParentNumber(anchorNum);
	lastSubNavItem = getLastSubNavItem(anchorNum);
	}
	
	applySubNavStyles(subParentNumber,lastSubNavItem);

		}
		
	  else {	

	  doSubNavs(n.childNodes[i]);
	
		}
   }   

}

function getSubParentNumber(a) {
	while (a != 0) {	
	if(!checkIfSubNav(document.getElementById(a))) {	
	return a;
	}
	a--;
	}		
}


function getLastSubNavItem(a) {
	while (a != 100) {	
	if(!checkIfSubNav(document.getElementById(a))) {	
	return a;
	}
	a++;
	}		
}




function applySubNavStyles(first,last) {
	for (var i = first; i < last; i++) {		
	node= document.getElementById(i)	
	applyTableStyles(node,'active');	
	}
}



function checkIfSubNav(n) {


	 if (n == null) {
      return false;
	 }
	  
anchorCount = n.getAttribute('id');	  
var numNodes = n.childNodes.length;

for (var i = 0; i < numNodes; i++) {
	if(n.nodeName.toLowerCase() == 'a' && n.getAttribute('id') == anchorCount){		
		if(getParentDiv(n).getAttribute('id') == 'subnavigation' ||
			getParentDiv(n).getAttribute('id') == 'subsubnavigation'							
										) {
			return true;
			}

		}
		
	  else {	

	  checkIfSubNav(n.childNodes[i]);
			
			}
		}
		 return false;
   }   
   
	

function getParentDiv(node) {
while (node.nodeName.toLowerCase() != container) {	
	if(node.nodeName.toLowerCase() == 'div') {	
	return node;
	break;
	}
	node = node.parentNode;
	}	
}



function checkURL(node) {
	host=window.location.hostname; 
	path=window.location.pathname; 
	var url = "http://"+host + path; 
	var urlS = "https://"+host + path; 

	if(node.getAttribute('href') == url || node.getAttribute('href') == urlS){
	return true;
	}
	else {
	return false; 
	}
}

function applyAnchorStyles(node,status,achorCount) {

	if(status == 'active') {
	node.className='NavLeftActiveSel';
	node.setAttribute('id',anchorCount);
	node.className='NavLeftActiveSel';
	}
	
	if(status == 'inactive') {
	node.className='NavLeft';
	node.setAttribute('id',anchorCount);
	}
}


function applyTableStyles(node,status) {
	
	if (node == null) 
      return;
	
	var tableNode = getTableNode(node);

	var bgColor = '';
	if(status == 'active') {
	bgColor = '#ffffff';
	}
	
	if (tableNode.addEventListener) {
	if(status == 'inactive') {
	tableNode.addEventListener("mouseover", inactiveOn, false);
	tableNode.addEventListener("mouseout", inactiveOff, false);
	}
	if(status == 'active') {
	tableNode.addEventListener("mouseover", activeOn, false);
	tableNode.addEventListener("mouseout", activeOff, false); 
	}
	}


	if (tableNode.attachEvent){	
	if(status == 'inactive') {
	tableNode.attachEvent("onmouseover", inactiveOn);
	tableNode.attachEvent("onmouseout",  inactiveOff);
	}
	if(status == 'active') {
	tableNode.attachEvent("onmouseover", activeOn);
	tableNode.attachEvent("onmouseout", activeOff);
	}
	}
	
	tableNode.setAttribute('bgColor',bgColor);	

	}


//this function is not being used
function addDivAndImage(node,status) {
	
	
	if (node == null) 
      return;
	
	var tableCellNode = getTableCellNode(node);
	
	var newDiv = document.createElement('div');
	newDiv.className ='NavLeftText';

	tableCellNode.insertBefore(newDiv,tableCellNode.firstChild);
	
	}
	
function addTableRowAndImage(node,status) {

	var width = 8; 
	
	
	if (node == null) 
      return;
	
	var tableRowNode = getTableRowNode(node);
	
	var newTableCell = document.createElement('td');
	newTableCell.setAttribute('width',width);
	var image = createImage(status);
	
	newTableCell.appendChild(image);	
	tableRowNode.insertBefore(newTableCell,tableRowNode.firstChild);
	
	}

function createImage(status) {
	var imgsrc = leftNavSpacerImage;
	if(status == 'active'){
	imgsrc = leftNavActiveImage;
	}

	var border = 0; 
	var height = 7; 
	var width = 8;
	var vspace = 5;
	var image = document.createElement('img');
	image.setAttribute('src',imgsrc);
	image.setAttribute('border',border);
	image.setAttribute('height',height);
	image.setAttribute('width',width);
	image.setAttribute('vspace', vspace);

return image;
  
}



function getTableNode(node) {
while (node.nodeName.toLowerCase() != container) {	
	if(node.nodeName.toLowerCase() == 'table') {	
	return node;
	}
	node = node.parentNode;
	}	
}

function getTableRowNode(node) {
while (node.nodeName.toLowerCase() != container) {	
	if(node.nodeName.toLowerCase() == 'tr') {	
	return node;
	}
	node = node.parentNode;
	}	
}

function getTableCellNode(node) {
while (node.nodeName.toLowerCase() != container) {	
	if(node.nodeName.toLowerCase() == 'td') {	
	return node;
	}
	node = node.parentNode;
	}	
}

function inactiveOn(e) {
	var targ;
	var tname;
	if(!e) e = window.event;
	if (e.target) {targ = e.target }
	else if (e.srcElement) {targ = e.srcElement}	
	
	var tableNode = getTableNode(targ);
	if(tableNode)tableNode.className='NavLeftOver';
}


function inactiveOff(e) {
	
	var targ;
	var tname;
	if(!e) e = window.event;
	if (e.target) {targ = e.target }
	else if (e.srcElement) {targ = e.srcElement}	
	
	var tableNode = getTableNode(targ);
	tableNode.className = 'NavLeft';
}

function activeOn(e) {
	
	var targ;
	var tname;
	if(!e) e = window.event;
	if (e.target) {targ = e.target }
	else if (e.srcElement) {targ = e.srcElement}	
	
	var tableNode = getTableNode(targ);
	tableNode.className='NavLeftActiveOver';

}

function activeOff(e) {
	
	var targ;
	var tname;
	if(!e) e = window.event;
	if (e.target) {targ = e.target }
	else if (e.srcElement) {targ = e.srcElement}	
	
	var tableNode = getTableNode(targ);
	tableNode.className='NavLeftActive';
}

