
//
// Get the height of the working window for any browser
// Generic
//
function GetWindowHeight()
{
	var intHeight = 0;
	if( typeof( window.innerWidth) == "number")
	{
		intHeight= window.innerHeight;
	}

	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		intHeight= document.documentElement.clientHeight;
	}

	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		intHeight= document.body.clientHeight;
	}
	return intHeight;
}

function GetWindowWidth()
{
	var intWidth = 0;
	if( typeof( window.innerWidth) == "number")
	{
		intWidth= window.innerWidth;
	}

	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		intWidth= document.documentElement.clientWidth;
	}

	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		intWidth= document.body.clientWidth;
	}
	return intWidth;
}

//
// Stretch the page to fill available height
//
// Feed in any number of arguments for vertical element names
// One argument only may be an array...
// ... from this array of elements the largest height only will be used
// and the array will be used as the control to be adjusted.
// If there's no left and right margin the body area, for example, will
// therefore be named in an array, as the only element.
//
// Dependency:
// function GetWindowHeight()
//
function MakeFullHeight()
{

	if (document.getElementById)
	{
		var intCumulativeHeight = 0;
		var intMaxControlHeight = 0;
		var objControl = new Array();

		for(var i = 0; i < MakeFullHeight.arguments.length; i++)
		{

			// Normal header or footer type
			if (typeof(MakeFullHeight.arguments[i]) == "string")
			{
				var strObjName = MakeFullHeight.arguments[i];
				intCumulativeHeight += document.getElementById(strObjName).offsetHeight;
			}

			// Body area type where left panel, body and right panel need to be taken into account
			// ... this is an array
			else if (typeof(MakeFullHeight.arguments[i]) == "object" && MakeFullHeight.arguments[i].length)
			{
				// This array is the control object, ie, the set of heights to be adjusted
				objControl = MakeFullHeight.arguments[i];

				// Find out which of the array items is tallest
				for(var j = 0; j < MakeFullHeight.arguments[i].length; j++)
				{
					var strObjName = MakeFullHeight.arguments[i][j];
					var objDiv = document.getElementById(strObjName);

					if (objDiv)
					{
						if (objDiv.offsetHeight > intMaxControlHeight)
						{
							intMaxControlHeight = objDiv.offsetHeight;
						}
					}
				}
				intCumulativeHeight += intMaxControlHeight;
			}
		}

		// Get current window height
		var intWinAvailableHeight = GetWindowHeight();

		for(var i = 0; i < objControl.length; i++)
		{
			var ObjDiv = document.getElementById(objControl[i]);
			if (intCumulativeHeight < intWinAvailableHeight)
			{
				// Adjust all the control objects less all the other bits
				// the + 1 is to force the vertical scrollbar to appear. Without this there's a 12px hop to the right onload in non-IE browsers!
				if (ObjDiv)
					document.getElementById(objControl[i]).style.height = intWinAvailableHeight - (intCumulativeHeight - intMaxControlHeight) + 1 + "px";
			}
			else
			{
				if (ObjDiv)
					document.getElementById(objControl[i]).style.height = intMaxControlHeight + "px";
			}
		}
	}
}

