//----------------------------------------------------------
// Browser Detection
//----------------------------------------------------------
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1) ? true:false;
Firefox = (navigator.userAgent.indexOf('Firefox')!=-1) ? true:false;

//----------------------------------------------------------
// Find the bottom of the page
//----------------------------------------------------------
function calcBottomOfPage(flag) {

	var bottomOfPage = 0;
	var divElements = document.getElementsByTagName('div');
	for(i = 0; i < divElements.length; i++) {
		var thisDiv = divElements[i];
		var tempTop = 0;
		if (flag) {
			while (thisDiv != null) {
				tempTop += thisDiv.offsetTop;
				thisDiv = thisDiv.offsetParent;
			}
		}
		if((divElements[i].offsetHeight + tempTop) > bottomOfPage) {
			if (divElements[i])
			{			
				bottomOfPage = divElements[i].offsetHeight + tempTop;
			} 
		}
	}
	return bottomOfPage;
}

//----------------------------------------------------------
// Position the footer
//----------------------------------------------------------
function positionDivisions() {

	var bottomPos = 0;
	
	// Calculate the bottom of the page
	bottomPos = calcBottomOfPage(true);
	var disclaimer = document.getElementById("disclaimer");
	if (disclaimer != null) {
		disclaimer.style.top = bottomPos + "px";
		disclaimer.style.visibility = "visible";
		bottomPos = bottomPos + disclaimer.offsetHeight;
	}

	var footer = document.getElementById("footer");
	if (footer != null) {
		var browserHeight = getBrowserHeight();
		var footerTop = bottomPos;
		var footerHeight = footer.offsetHeight;
		footer.style.top = bottomPos + "px";
		if ((footerTop + footerHeight) < browserHeight) {
			footer.style.top = (browserHeight - footerHeight) + "px";
		}

		footer.style.visibility = "visible";
	}
	tmp = document.getElementsByTagName('div');
	for (i=0;i<tmp.length;i++) {
	
		if (tmp[i].className.indexOf("dotsVert")>-1) {
			tmp[i].style.height = bottomPos-495 + "px";
		}
	}
}

function repositionDivisions(height) { 
	
	// Calculate the bottom of the page
	bottomPos = calcBottomOfPage(false);
	var column = document.getElementById("columnContainer");
	// ADDED BECAUSE FF ALWAYS RETURNS 0 FOR COLUMN OFFSET HEIGHT
	if (Firefox == true) {
		centerHt = document.getElementById("centerContainer").offsetHeight;
		leftHt = document.getElementById("leftContainer").offsetHeight;
		if (centerHt > leftHt) {
			newOffset = centerHt;	
		} else {
			newOffset = leftHt;	
		}
	}	
	
	var minTop = 0;
	if (column) {
		minTop = column.offsetTop + column.offsetHeight;
		// ADDED BECAUSE FF ALWAYS RETURNS 0 FOR COLUMN OFFSET HEIGHT
		if (Firefox == true) {
			minTop = column.offsetTop + newOffset;
		}
	}
	
	var disclaimer = document.getElementById("disclaimer");
	if (disclaimer != null) {
		var browserHeight = getBrowserHeight();
		var disclaimerTop = bottomPos;
		var disclaimerHeight = disclaimer.offsetHeight;
		disclaimer.style.top  = (bottomPos > minTop ? bottomPos : minTop) + "px";
		bottomPos = (bottomPos > minTop ? bottomPos : minTop) + disclaimerHeight;
		if ((disclaimerTop + disclaimerHeight) < browserHeight) {
			disclaimer.style.top = (browserHeight - disclaimerHeight) + "px";
		}
		disclaimer.style.visibility = "visible";
	}
	

	var footer = document.getElementById("footer");
	if (footer != null) {
		var browserHeight = getBrowserHeight();
		var footerTop = bottomPos;
		var footerHeight = footer.offsetHeight;
		footer.style.top = bottomPos + "px";
		if ((footerTop + footerHeight) < browserHeight) {
			footer.style.top = (browserHeight - footerHeight) + "px";
		}

		footer.style.visibility = "visible";
	}
	tmp = document.getElementsByTagName('div');
	for (i=0;i<tmp.length;i++) {
	
		if (tmp[i].className.indexOf("dotsVert")>-1) {
			tmp[i].style.height = bottomPos-495 + "px";
		}
	}
}

//----------------------------------------------------------
// Returns width of the browser window
//----------------------------------------------------------
function getBrowserWidth() {
	var browserWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
    	//Non-IE
    	browserWidth = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
    	//IE 6+ in 'standards compliant mode'
    	browserWidth = document.documentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
    	//IE 4 compatible
    	browserWidth = document.body.clientWidth;
	}
	return browserWidth;
}

//----------------------------------------------------------
// Returns height of the browser window
//----------------------------------------------------------
function getBrowserHeight() {
	var browserHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
    	//Non-IE
    	browserHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
    	//IE 6+ in 'standards compliant mode'
    	browserHeight = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
    	//IE 4 compatible
    	browserHeight = document.body.clientHeight;
	}
	return browserHeight;
}

//----------------------------------------------------------
// Position the footer at the bottom of the page upon
// page load.  Templates using nested div tags may require 
// nested=true to render properly
//----------------------------------------------------------

window.onresize = repositionDivisions;
safeOnload(positionDivisions);