﻿window.onload = function() {
	setHeight();
}
window.onresize = function() {
	resetHeight();
	setHeight();
}

var detect = navigator.userAgent.toLowerCase();

function resetHeight() {
	var newElement=document.getElementById('PageContent');
		newElement.style.height='auto';
}

function setHeight() {
	if (document.getElementById) {
		var SOff=0;
		var windowHeight=getWindowHeight();
		var windowWidth=getWindowWidth();
		var containerWidth=1004;
		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('PageContent');
			    contentHeight=HeightControlElement.offsetHeight;
			//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 (HeightControlElement.parentNode.id=='HeightControl'){
			    if (windowHeight-(contentHeight+67)>=0) {
			        HeightControlElement.style.height=(windowHeight-(67)-SOff)+'px';
			    }
			}
			else {
			    if (windowHeight-(contentHeight+147)>=0) {
			        HeightControlElement.style.height=(windowHeight-(147)-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;
}

