// This is required since Firefox take the strong doctype seriously
function setPixelHeight(targetStyle, size)
{
	targetStyle.height = size + 'px';
}

function setWindowSizes(localNavInitialHeight, contentInitialHeight)
{
	var contentHeight;
	localNavDiv = document.getElementById("localNav");
	contentDiv  = document.getElementById("content");
	footerDiv   = document.getElementById("footer");

	// Initialize this to a small number so on a resize it does not stay huge
	if(resizable)
	{
		setContentHeight(contentInitialHeight);
	}
	contentDiv.style.height  = contentInitialHeight;
	localNavDiv.style.height = localNavInitialHeight;

	windowHeight  = getWindowHeight();
	headerHeight  = document.getElementById("header").clientHeight;
	genNavHeight  = document.getElementById("generalNav").clientHeight;
	contentHeight = contentDiv.clientHeight;
	footerHeight  = footerDiv.clientHeight;
	bodyHeight    = contentHeight;
	if (localNavInitialHeight > contentHeight)
	{
		bodyHeight = localNavInitialHeight;
	}
	nonContentHeight = headerHeight + genNavHeight + footerHeight;

	totalHeight = nonContentHeight + bodyHeight;
	
	if (totalHeight < windowHeight)
	{
		bodyHeight = windowHeight - nonContentHeight;
		totalHeight = nonContentHeight + bodyHeight;
	}
	
	resetOpaqueOverlaySize(totalHeight);
	setNavHeight(bodyHeight);
	if (resizable)
	{
		setContentHeight(bodyHeight);
	} else
	{
		setPixelHeight(contentDiv.style, bodyHeight);
	}
}

// Resets the overlay to be the window size, or the alternate height, whichever is bigger.
function resetOpaqueOverlaySize(alternateHeight)
{
	overlayDiv = document.getElementById("opaqueOverlay");
	windowHeight = getWindowHeight();
	if (alternateHeight > windowHeight)
	{
		overlayDiv.style.height = alternateHeight + 'px';
	} else
	{
		overlayDiv.style.height = windowHeight + 'px';
	}
	
	overlayDiv.style.width = getWindowWidth() + 'px';
}

// Find the top pixel spot of an Element
// obj - the object to find the top of
// relativeParentId - a parent name you want to find the top of relative to, instead of the window top
function findTopOfElement(obj, relativeParentId)
{
	var currentTop = 0;
	if(obj.offsetParent)
	{
		while(1)
		{
			currentTop = currentTop + obj.offsetTop;
			if(! obj.offsetParent)
			{
				break;
			}
			if(obj.id == relativeParentId)
			{
				break;
			}
			
			obj = obj.offsetParent;
		} 
	} else if (obj.y)
	{
		currentTop = currentTop + obj.y;
	}
	return currentTop;
}

// Find the left pixel spot of an Element
// obj - the object to find the left of
// relativeParentId - a parent name you want to find the left of relative to, instead of the window top
function findLeftOfElement(obj, relativeParentId)
{
	var currentLeft = 0;
	if(obj.offsetParent)
	{
		while(1)
		{
			currentLeft = currentLeft + obj.offsetLeft;
			if(! obj.offsetParent)
			{
				break;
			}
			if(obj.id == relativeParentId)
			{
				break;
			}
			obj = obj.offsetParent;
		} 
	} else if (obj.x)
	{
		currentLeft = currentLeft + obj.x;
	}
	return currentLeft;
}

function getWindowHeight()
{
	if (isIE()) 
	{
		return document.body.offsetHeight;
	} else
	{
		return window.innerHeight;
	}
}

function getWindowWidth()
{
	if (isIE()) 
	{
		return document.body.offsetWidth;
	} else
	{
		return window.innerWidth;
	}
}
