var moduleHeight = 0;
var moduleFooterHeight = 53;
var spacerImgPath = '/images/global/space.gif';

function getModuleHeight(arTags) {
	var i;
	var h = 0;
	for (i=0;i<arTags.length;i++) 
	{
		// Only get the height on visible elements, skipping the footer.
		if ( arTags[i].id.indexOf("footer") < 0  &&
			 arTags[i].style.display != 'none' && 
			 arTags[i].style.display != 'hidden' &&
			 arTags[i].style.visibility != 'hidden' &&
			 (arTags[i].offsetTop + arTags[i].offsetHeight) > h )
		{
			h = (arTags[i].offsetTop + arTags[i].offsetHeight);
		}
	}
	return h;
}

function setSpacer ( iHeight ) {
	document.getElementById('spacerDiv').innerHTML = 
		"<div style='height:" + iHeight + "px;'><img src='/images/global/space.gif' border='0' alt='' width='1' height='" + iHeight + "' /></div>";
}

// WDR 4/13/07: Redid this a little to check div's and table's,
// using the above function (which filters the 'footer' object).
// This seems to be working better with the cms pages.
function moveFooter(){
	var i;
	var footerLayer;
	
	if (document.layers) return;

	// If there's a footer, just set the spacer there.	
	var objFooter = document.getElementById('footer');
	var objWrapper = document.getElementById('ModuleWrapper');
	if ( objFooter && objFooter.offsetTop ) {
		moduleHeight = objFooter.offsetTop;
		if ( objWrapper ) {
			//var h = objWrapper.clientHeight ? objWrapper.clientHeight : objWrapper.offsetTop;
			var h = objWrapper.offsetHeight;
			if ( h < moduleHeight ) {
				// WDR: had to hard-code this....
				moduleHeight -= 96;
				//moduleHeight -= h;
			}
		}
		setSpacer ( moduleHeight );
		objFooter.style.display = 'none';
		return;
	}
	
	// If there's no footer but there is a module wrapper,
	// then this page is probably a floating layout, so
	// no spacer needed.
	if ( objWrapper && !objFooter ) {
		return;
	}
	
	// Compute the spacer by looking at the height of all the divs.
	if (document.getElementsByTagName ) {
		//var tagAry1 = document.getElementsByTagName('div');
		var tagAry1 = objWrapper.getElementsByTagName('div');
		//var tagAry2 = objWrapper.getElementsByTagName('table');
		
		var h1 = getModuleHeight(tagAry1);
		var h2 = 0; //getModuleHeight(tagAry2);
		if ( h1 > moduleHeight ) {
			moduleHeight = h1;
		}
		if ( h2 > moduleHeight ) {
			moduleHeight = h2;
		}
		
		moduleHeight = moduleHeight - 96; // compensate for CMS footer height
		setSpacer ( moduleHeight );
	} 
	
	// Hide the footer
	if (!document.getElementById('footer')) return;
	footerLayer = new elcLayer( 'footer' );
	footerLayer.hide();
	
}


// WDR: old version for reference
function moveFooter_OLD(){
	var i;
	if (document.layers) return;
	if (document.getElementsByTagName && !document.all) {
		if (!document.getElementById('footer')) return;
		tagAry = document.getElementsByTagName('div');
		for (i=0;i<tagAry.length;i++){
			if ((tagAry[i].offsetTop + tagAry[i].offsetHeight) > moduleHeight){moduleHeight = (tagAry[i].offsetTop + tagAry[i].offsetHeight);}
		}
//		moduleHeight= (moduleHeight - 101);
//		alert( 'moduleHeight: ' + moduleHeight );
		document.getElementById('spacerDiv').innerHTML = "<div style='height:" + moduleHeight + "px;'><img src='/images/global/space.gif' border='0' alt='' width='1' height='" + moduleHeight + "' /></div>";
	} else if(document.all.tags && document.all.spacerDiv){
		if (!document.all.footer) return;
		len = document.all.tags('div').length;
     		for (i=0;i<len;i++){
			ieHeight = parseInt(document.all.tags('div')[i].offsetHeight);
			ieTop = parseInt(document.all.tags('div')[i].offsetTop);
			if ((parseInt(document.all.tags('div')[i].offsetHeight) + parseInt(document.all.tags('div')[i].offsetTop)) > moduleHeight){moduleHeight = (parseInt(document.all.tags('div')[i].offsetHeight) + parseInt(document.all.tags('div')[i].offsetTop));}
		}
//		alert( 'moduleHeight: ' + moduleHeight );
		document.all.spacerDiv.innerHTML = "<img src='/images/global/space.gif' border='0' alt='' width='1' height=\"" + moduleHeight + "\"' />";  }
}
