// activate menu is used to get around IE's failure to recognize "hover" events on any page object by scripting that behavior.
activateMenu = function(nav) {
    /* currentStyle restricts the Javascript to IE only */
	if (document.all && document.getElementById(nav).currentStyle) {  
		var navroot = document.getElementById(nav);
        /* Get all the list items within the menu */
        var lis=navroot.getElementsByTagName("LI");  
		for (i=0; i<lis.length; i++) {
            /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {		
                   /* display the inner menu */
                   this.lastChild.style.display="block";
      			}
				lis[i].onmouseout=function() {                       
                    this.lastChild.style.display="none";
				}
            }
		}
	}
}	

function getRef(obj) {
	if(typeof obj == "string") {
		obj=document.getElementById(obj);
		return obj;
	}
}
	
function getStyle(obj, style){
	if(!document.getElementById) {return;}
	
	var obj = getRef(obj);
	var value = obj.style[style];
	if(!value) {
		if(document.defaultView) {
			value = document.defaultView.getComputedStyle(obj, "").getPropertyValue(style);
		} else if(obj.currentStyle) {
			value = obj.currentStyle[style];
		}
	}
	return value;
}

function setStyle(obj, style, value) {
	getRef(obj).style[style] = value;
}

function stripPx(styleWithPx) {
	var strVal = styleWithPx.substring(0,styleWithPx.length - 2);
	var styleVal = parseInt(strVal);
	return styleVal;
}

function positionFooter() {
	
	// set leftnav visible
	setStyle("left", "visibility", "visible");	
	
	// calculate total length of the page
	var midH = stripPx(getCalculatedProperty("center", "height"));
	var topH = stripPx(getStyle("header", "height"));
	var leftH = stripPx(getCalculatedProperty("lNav", "height"));

	//var leftH = stripPx(getCalculatedProperty("lNav", "height"));
	//var leftT = stripPx(getCalculatedProperty("lNav", "top"));
	//leftH = leftH+leftT;

	// don't forget to add left's top property to this too. left is a height, but that height starts at a specific point on the page. for that matter you may need to take margins into account as well.
	//var pageHeight = leftH;

	if(midH > leftH) {
		pageHeight = midH;
	} else {
		pageHeight = leftH;
	}
	
	var footerTop = topH + pageHeight + 20;
	
	/* create variuable for height of right column: needs to include height & margin of footer, 100px + 15px */
	var rightColumn = footerTop + 85;
	footerTop += "px";
	
	
	
	/* reset footer styles */
	setStyle("footer", "top", footerTop);
	setStyle("footer", "border-top", "1px solid #A6AAAB");
	setStyle("footer", "height", "70px");
	setStyle("footer", "width", "764px");
	setStyle("footer", "margin", "15px 0");	
	setStyle("footer", "background", "#D1D9E6 url(/media/images/bg_footer-nsfisr.gif)");
	setStyle("footer", "backgroundImage", "url(/media/images/bg_footer-nsfisr.gif)");
	setStyle("footer", "visibility", "visible");
	
	/* set height of border on right column */
	setStyle("right", "height", rightColumn);
	

	//alert('positionFooter');
}


function showSub(submenu){
	//alert('show');
	document.getElementById(submenu).style.display = 'block';
	document.getElementById(submenu).style.height = 'auto';
	document.getElementById(submenu).style.background = '#FFFFFF';
}

function hideSub(submenu){
	//alert('hide');
	document.getElementById(submenu).style.display = 'none';
}

function initPage(){
	//alert();
	if (leftNavPresent){
		menuInit();
	}
	activateMenu('pnav'); /* pass in the id of the top level UL */
	//maybe this function should be in utilities
	positionFooter();

}

function openPopup(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600,left = 240,top = 212');");
}

