var globalScroll;
function PopUp_displayPopupPanel(isVisible, clientID, popupFix)
{
    // On définit l'affchage de nos divs en none/block suivant la valeur de isVisible
    var visible = "none";

    if(isVisible)
    {
        visible = "block";
        globalScroll = PopUp_getScrollSize()[1];
    }
    else
    {
        window.scrollTo(0,globalScroll);
    }

    // Récupération de l'overlay
    var overlay = clientID + "_overlay";

    // Si on désactive la page
    if(document.getElementById(overlay) != null)
    {
        // Récupération de notre frame d'erreur pour IE6
        var framePopup = clientID + "_framePopup";

        // Affichage des divs
        document.getElementById(overlay).style.display = visible;
        document.getElementById(framePopup).style.display = visible;
    }
    
    // Récupération et affichage de notre div contenant la popup
    var panelPopup = clientID + "_panelPopup";
    document.getElementById(panelPopup).style.display = visible;

    // On initialise les positions
    PopUp_initPosition(clientID, popupFix);

    // En cas de redimensionnement, on recalcul les positions
    window.onresize = function()
    {
        PopUp_initPosition(clientID, popupFix);
    }
}

// Récupération de la taille de la fenêtre
// Retourne : [x,y]
function PopUp_getWindowSize()
{
    var x,y;
    // Pour tous les navigateurs sauf IE
    if (self.innerHeight)
    {
        x = self.innerWidth;
        y = self.innerHeight;
    }
    // Pour IE
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
    }
    // Autres
    else if (document.body)
    {
        x = document.body.clientWidth;
        y = document.body.clientHeight;
    }

    return [ x, y ];
}

// Récupére la taille du corp de la page
// Retourne : [x,y]
function PopUp_getBodySize()
{
    var x,y;

    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    // Tous sauf les navigateurs MAC
    if (test1 > test2)
    {
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
    }
    else
    {
        x = document.body.offsetWidth;
        y = document.body.offsetHeight;
    }
    return [ x, y ];
}

// Fonction pour obtenir la valeur (en px) de scroll du navigateur en X et Y
// Retourne : [x,y]
function PopUp_getScrollSize()
{
    var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) 
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} 
	else if(document.body && ( document.body.scrollLeft || document.body.scrollTop))
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} 
	else if(document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

// Récupére la plus grande valeur
// Retourne : int
function PopUp_highestValue(intArray)
{
    var max = intArray[0];

    // On passe dans toutes les données
    for(i=1; i < intArray.length; i++)
    {
        if(intArray[i] > max)
            max = intArray[i];
    }

    return max;
}

// Initialisation de la position
function PopUp_initPosition(clientID, popupFix)
{
	// ArtPopup.browser
	strChUserAgent = navigator.userAgent;
	intSplitStart = strChUserAgent.indexOf("(",0);
	intSplitEnd = strChUserAgent.indexOf(")",0);
	strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
	browser = (strChMid.indexOf("MSIE 6") != -1)? "ie6":"standard";

    // Positionnement de la popup
    var panelPopup = clientID + "_panelPopup";
    var panelPopupElement = document.getElementById(panelPopup);
    panelPopupElement.style.position = (browser == "ie6") ? "absolute" : "fixed";

    // Taille de la fenêtre
    var windowSize = PopUp_getWindowSize();
    var windowX = windowSize[0];
    var windowY = windowSize[1];

    // Taille de l'iframe
    var bodySize = PopUp_getBodySize();

    // Taille de l'iframe
    var scrollSize = PopUp_getScrollSize();

    var x = PopUp_highestValue(new Array(bodySize[0], windowX));
    var y = PopUp_highestValue(new Array(bodySize[1], windowY));
    
    // Récupération de la frame d'erreur
    var framePopup = clientID + "_framePopup";
    var iframeElement = document.getElementById(framePopup);
    
    // Si l'iframe est affichée
    if(iframeElement != null && iframeElement.style.display == "block")
    {
        var overlay = clientID + "_overlay";
        var overlayElement = document.getElementById(overlay);

        // Taille de l'overlay
        overlayElement.style.width = x+"px";
        overlayElement.style.height = y+"px";
        overlayElement.style.top = "0px";
        overlayElement.style.left = "0px";
        overlayElement.style.position = (browser == "ie6") ? "absolute" : "fixed";
        
        // Taille de l'iframe
        iframeElement.style.width = x+"px";
        iframeElement.style.height = y+"px";
        iframeElement.style.top = "0px";
        iframeElement.style.left = "0px";
        iframeElement.style.position = (browser == "ie6") ? "absolute" : "fixed";
    }

    // Si la popup doit être centré
    if(!popupFix && panelPopupElement != null && panelPopupElement.style.display == "block")
    {    
        var top = (windowY-panelPopupElement.offsetHeight)/2;
        // Si le top est négatif on le fixe à 0
        if(top < 0)
            top = 0;

        // On positionne la popup
        panelPopupElement.style.left = (windowX-panelPopupElement.offsetWidth )/2 + "px";
        
        if(browser == "ie6")
        {
            if(scrollSize[1] == 0)
                panelPopupElement.style.top = (top) + "px";
            else
                panelPopupElement.style.top = (scrollSize[1]+20) + "px";
        }
        else{
            panelPopupElement.style.top = (top) + "px";
        }
    }
}