﻿
function viewErrorPanel(isVisible)
{
	var visible = "none";
	if(isVisible)
		visible = "block";
	
	document.getElementById("frameError").style.display = visible;
	document.getElementById("overlay").style.display = visible;
	document.getElementById("pError").style.display = visible;
	initPosition();
	
	window.onresize = function() {
		initPosition();
	}
}

function getWindowSize()
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	return [ x, y ];
}

function getBodySize()
{
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else // Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	return [ x, y ];

}

function getScrollSize()
{
	var x,y;
	if (navigator.appName == 'Microsoft Internet Explorer') x = Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
	else if (document.childNodes && !document.all && !navigator.taintEnabled) x = document.body.scrollWidth;
	else x= document.documentElement.scrollWidth;
	if (navigator.appName == 'Microsoft Internet Explorer') y= Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
	else if (document.childNodes && !document.all && !navigator.taintEnabled) y= document.body.scrollHeight;
	else y= document.documentElement.scrollHeight;
	return [ x, y ];
}

function highestValue(intArray)
{
	var max = intArray[0];
	for(i=1; i < intArray.length; i++)
	{
		if(intArray[i] > max)
			max = intArray[i];
	}
	return max;
}

function initPosition()
{
	if(document.getElementById("pError").style.display == "block")
	{
					
		var overlay = document.getElementById("overlay");
		var iframe = document.getElementById("frameError");
		var d = document.getElementById("pError");
								
		var windowSize = getWindowSize();
		var windowX = windowSize[0];
		var windowY = windowSize[1];
		
		// Taille de l'iframe
		var bodySize = getBodySize();
		var bodyX = bodySize[0];
		var bodyY = bodySize[1];
						
		// Taille de l'iframe
		var scrollSize = getScrollSize();
		var scrollX = scrollSize[0];
		var scrollY = scrollSize[1];
		
		var x = highestValue(new Array(bodyX, windowX, scrollX));
		var y = highestValue(new Array(bodyY, windowY, scrollY));
		
		
		// Positionnement du message d'erreurs
		if(d != null)
		{
			d.style.left = (windowX-d.offsetWidth)/2 + "px";
			d.style.top = (windowY-d.offsetHeight)/2 + "px";
		}
		
		// Taille de l'overlay
		overlay.style.width = x+"px";
		overlay.style.height = y+"px";
		overlay.style.top = "0px";
		overlay.style.left = "0px";
		
		// Taille de l'iframe
		iframe.style.width = x+"px";
		iframe.style.height = y+"px";
		iframe.style.top = "0px";
		iframe.style.left = "0px";
	}
}