window.onload = function() {
	setHeight();
}
window.onresize = function() {
	resetHeight();
	setHeight();
}

var detect = navigator.userAgent.toLowerCase();

function resetHeight() {
	var newleftElement=document.getElementById('LeftContent');
		newleftElement.style.height='auto';
	var newmainElement=document.getElementById('MainContent');
		newmainElement.style.height='auto';
	var newrightElement=document.getElementById('RightContent');
		newrightElement.style.height='auto';
}

function setHeight() {
	if (document.getElementById) {
		var SOff=0;
		var windowHeight=getWindowHeight();
		var windowWidth=getWindowWidth();
		var containerElement=document.getElementById('Container');
			containerWidth=containerElement.offsetWidth
		if (windowWidth<containerWidth) {
			if (checkIt('firefox')){
				if (checkIt('mac')){
					SOff=15;
				}
				else {
					SOff=19;
				}
			}
		}
		if (windowHeight>0) {
			var contentHeight=0;
			var footerElement=document.getElementById('FooterBar');
			var footerHeight=footerElement.offsetHeight;

			var HeightControlElement=document.getElementById('HeightControlContent');
			var leftElement=document.getElementById('LeftContent');
			var leftHeight=leftElement.offsetHeight;
			var mainElement=document.getElementById('MainContent');
			var mainHeight=mainElement.offsetHeight;
			var rightElement=document.getElementById('RightContent');
			var rightHeight=rightElement.offsetHeight;
			
			if ((leftHeight>=mainHeight)&&(leftHeight>=rightHeight)) {
				contentHeight=leftHeight;
			}
			else {
				if ((mainHeight>=leftHeight)&&(mainHeight>=rightHeight)) {
					contentHeight=mainHeight;
				}
				else {
					contentHeight=rightHeight;
				}
			}
			if (windowHeight-(contentHeight+footerHeight+173)>=0) {
				HeightControlElement.style.height=(windowHeight-(footerHeight+173)-SOff)+'px';
			}
		}
	}
}

function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	}
	else {
		if (document.documentElement&&document.documentElement.clientHeight) {
			windowHeight=document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number') {
		windowWidth=window.innerWidth;
	}
	else {
		if (document.documentElement&&document.documentElement.clientWidth) {
			windowWidth=document.documentElement.clientWidth;
		}
		else {
			if (document.body&&document.body.clientWidth) {
				windowWidth=document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
