
function get_window_height() {
	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 set_footer() {
	if (document.getElementById) {
		var windowHeight = get_window_height();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('content').offsetTop + document.getElementById('content').offsetHeight;
			var menuHeight = document.getElementById('page_menu').offsetTop + document.getElementById('page_menu').offsetHeight;

			/* loop over all children of content, some webapps use floating elements which are
			 * not counted in the offsetheight */

			for (var i = 0; i < document.getElementById('content').childNodes.length; ++i) {
				var chNode = document.getElementById('content').childNodes[i];
				var chHeight = chNode.offsetTop + chNode.offsetHeight;

				if (chHeight > contentHeight) {
					contentHeight = chHeight;
				}
			}

			if (menuHeight > contentHeight) {
				contentHeight = menuHeight;
			}
			
			var footerElement = document.getElementById('page_footer');
			var footerHeight  = footerElement.offsetHeight;

			footerElement.style.position = 'absolute';
			footerElement.style.width = '100%';
			footerElement.style.top = contentHeight + 10 + 'px';
		}
	}
}

/* other web apps may need this instead */
/*
window.onload = function() {
	set_footer();
}
*/

window.onresize = function() {
	set_footer();
}

