//Utility function returns the available content height space in browser window
function getInsideWindowHeight() {
	if (window.innerHeight) {
	return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)	{
		return document.documentElement.clientHeight;
	}
	else if (document.body) {
		return document.body.clientHeight;  //(includes scrollbar height, otherwise body.clientHeight)
	}	
}
function getInsideWindowWidth() {
	if (window.innerWidth) {
	return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)	{
		return document.documentElement.clientWidth;
	}
	else if (document.body) {
		return document.body.clientWidth; 
	}	
}
function getObject(ElementName) {
	if (document.documentElement ) {
		return document.getElementById(ElementName);
	}
	else if (document.all) {
		return eval( "document.all." + ElementName);
	}
	else {
		return eval( "document." + ElementName)
	}
}

//Utility function returns rendered height of object content in pixels
function getObjHeight(obj) {
	if (obj.style && obj.style.height) {
		return parseInt(obj.style.height, 10); //DOM
	}
	else if (obj.clip && obj.clip.height) {
		return obj.clip.height; //NN4
	}
	else if (obj.clientHeight) {
		return obj.clientHeight; //IE	
	}
	else {
		//non DOM, NN4 or IE
	}
}

//Utility function returns rendered width of object content in pixels
function getObjWidth(obj) {
	if (obj.style && obj.style.width) {
		return parseInt(obj.style.width, 10); //DOM
	}
	else if (obj.clip && obj.clip.width) {
		return obj.clip.width; //NN4
	}
	else if (obj.clientWidth) {
		return obj.clientWidth; //IE	
	}
	else {
		//non DOM, NN4 or IE
	}
}

function getCenteredObjectX(obj) {
	return Math.round( (getInsideWindowWidth() - getObjWidth(obj))/2)
}
function getCenteredObjectY(obj) {
	return Math.round( (getInsideWindowHeight() - getObjHeight(obj))/2)
}

function setContentHeight() {
	//Sets the ContentHeight for the div tags FormContent (form) or ViewContent (view)
	//Assumes that the fixed content elements all have margin, padding, borders of 0
	var divFormContent = getObject("FormContent");
	var divViewContent = getObject("ViewContent");
	var divPageHeader = getObject("PageHeader");
	var divActionBar = getObject("ActionBar");
	var divFooter = getObject("Footer");
	var divTabArea = getObject("tabArea");
	var fixedContentHeight;
	var heightToSubtract;

	fixedContentHeight = 0;
	if (divPageHeader) {
		heightToSubtract = getObjHeight(divPageHeader);
		fixedContentHeight += (isNaN(heightToSubtract) ? 0 : heightToSubtract);
	}
	if (divActionBar) {
		heightToSubtract = getObjHeight(divActionBar);
		fixedContentHeight += (isNaN(heightToSubtract) ? 0 : heightToSubtract);
	}
	if (divTabArea) {
		heightToSubtract = getObjHeight(divTabArea);
		fixedContentHeight += (isNaN(heightToSubtract) ? 0 : heightToSubtract);
	}
	if (divFooter) {
		heightToSubtract = getObjHeight(divFooter);
		if (document.all) {
				fixedContentHeight += (isNaN(heightToSubtract) ? 0 : heightToSubtract);
		}
		else {
			fixedContentHeight += (isNaN(heightToSubtract) ? 0 : heightToSubtract);
		}
	}

	var contentHeight = getInsideWindowHeight() - fixedContentHeight -30; //-30
	contentHeight >= 50 ? true : (contentHeight = 50);
	if (divFormContent) {
		if (divFormContent.style ) {
			divFormContent.style.height = contentHeight + "px";
		}
		else if (divFormContent.height) {
			divFormContent.height = contentHeight;
		}
	}
	else if (divViewContent) {
		if (divViewContent.style ) {
			divViewContent.style.height = contentHeight + "px";
		}
		else if (divViewContent.height) {
			divViewContent.height = contentHeight;
		}
	}
	if (typeof(PostSetContentHeight) != 'undefined') PostSetContentHeight();
}
/*
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

addEvent(window, 'onload', setContentHeight);
*/

// Set the onresize event handler to the SetContentHeight function
if (document.all) {
	window.onresize = setContentHeight;
}
else {
	window.onresize = new Function( "window.location.href = window.location.href;");
}

