/*
 * $Id: page.js,v 1.2.2.3 2006/08/02 20:33:49 philippe Exp $
 * 
 * Copyright (c) 2006 by Societe Astronomique de Lyon
 * Created on 19 jun. 2006 by philippe
 * 
 * Fonctions utilitaires pour la mise en page des ecrans.
 */

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 setWindowSize() {

    if (document.getElementById) {
        var windowHeight = getWindowHeight();

		if (windowHeight > 0) {
		    var screen = document.getElementById("Screen");
		    var headerElement = document.getElementById("HeaderSection");
		    var contentArea = document.getElementById("ContentArea");
		    var footerElement = document.getElementById("FooterSection");
		    var leftElement = document.getElementById("LeftSection");
		    var rightElement = document.getElementById("RightSection");
		    var size = windowHeight - (headerElement.offsetHeight + contentArea.offsetHeight + footerElement.offsetHeight);

			if (size > 0) {
			    var mainElement = document.getElementById("MainSection");
			    var contentElement = document.getElementById("ContentSection");
				var height = windowHeight - headerElement.offsetHeight;
	
				if (leftElement != null) {
					var d = leftElement.offsetHeight - height;
				    if (d > 0) {
				    	height += d;
				    	size += d;
				    	windowHeight += d;
				    }
				}
	
				if (rightElement != null) {
				    var d = rightElement.offsetHeight - height;
				    if (d > 0) {
				    	height += d;
				    	size += d;
				    	windowHeight += d;
				    }
				}

				screen.style.height = windowHeight + "px";
				mainElement.style.height = height + "px";
				contentElement.style.height = height + "px";
				footerElement.style.position = "relative";
				footerElement.style.top = size + "px";

			} else if (size < 0) {
				var height = windowHeight - size - headerElement.offsetHeight;
				size = 0;

			    if (leftElement != null) {
					var d = leftElement.offsetHeight - height;
				    if (d > 0) {
				    	height += d;
				    	size += d;
				    	windowHeight += d;
				    }
				}

			    if (rightElement != null) {
				    var d = rightElement.offsetHeight - height;
				    if (d > 0) {
				    	height += d;
				    	size += d;
				    	windowHeight += d;
				    }
				}

				if (size > 0) {
					screen.style.height = windowHeight + "px";
					mainElement.style.height = height + "px";
					contentElement.style.height = height + "px";
					footerElement.style.position = "relative";
					footerElement.style.top = size + "px";
				}

			} else {
				footerElement.style.position = "static";
			}
		}
	}
}

function openPopup(url, windowName, windowWidth, windowHeight)
{
	window.open(url, windowName, config="width=" + windowWidth + ", height=" + windowHeight + ", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
}
