var interval=0;
var jsTopLoaderAjax =
{
    blockDiv : null,
	innerErrorDiv : null,
	innerTheDiv : null,
	innerTimerDiv : null,

    showDiv : function(contenu,wid,hei)
	//Affiche une div de contenu avec un fond gris de bloquage
    {
		jsTopLoaderAjax.showBlockDiv();
        var handle = document.getElementById('topLoader'); 
        handle.style.display = 'block';
		document.body.appendChild(jsTopLoaderAjax.showTheDiv(contenu,wid,hei));
    },	
	
	
    hideDiv : function()
	// Cache une div de contenu sur fond de bloquage 
    {
        var handle = document.getElementById('topLoader');
        handle.style.display = 'none';
		jsTopLoaderAjax.hideTheDiv();
        jsTopLoaderAjax.hideBlockDiv();
    },

	
	
	showTheDiv : function(contenu,wid,hei)
	//Créé et détermine le contenu de la Div qui se surimpose sur une div de bloquage
	{
		innerTheDiv 						= document.createElement('div');
		innerTheDiv.style.position        	= 'absolute';
		innerTheDiv.style.zIndex          	= 300;
 		innerTheDiv.style.opacity         	= 0.99;
        innerTheDiv.style.khtmlOpacity    	= '0.99';
        innerTheDiv.style.mozOpacity     	= '0.99';
        innerTheDiv.style.filter         	= 'alpha(opacity = 99)';
        innerTheDiv.style.backgroundColor 	= 'white';		
		var pagePosition 					= jsTopLoaderAjax.positionBlock(wid,hei);
		
		innerTheDiv.style.top 				= pagePosition[2] + 'px';
		innerTheDiv.style.left				= pagePosition[3] + 'px';	
		innerTheDiv.style.width 			= pagePosition[1] + 'px';
		innerTheDiv.innerHTML				= "<div class='topinnerdiv'><a href='javascript:jsTopLoaderAjax.hideDiv();'><img src='images/fermer.png' border='0' /></a></div><br />"+contenu;

		document.body.appendChild(innerTheDiv);
		return innerTheDiv;

	},	

	
    showBlockDiv : function()
    {
        
		blockDiv = document.createElement('div');
        blockDiv.onclick = function()
        {
            return false;
        };
        blockDiv.style.opacity         = 0.15;
        blockDiv.style.khtmlOpacity    = '0.15';
        blockDiv.style.mozOpacity      = '0.15';
        blockDiv.style.filter          = 'alpha(opacity = 15)';
        blockDiv.style.backgroundColor = 'black';
        blockDiv.style.position        = 'absolute';
        blockDiv.style.top             = '0px';
        blockDiv.style.left            = '0px';
        blockDiv.style.width           = '100%';
		blockDiv.style.color           = 'RED';
        blockDiv.style.zIndex          = 200;

        var pageInfo = jsTopLoaderAjax.getPageInfo();
        blockDiv.style.height = pageInfo[0] + 'px';
        document.body.appendChild(blockDiv);

    },

    hideBlockDiv : function()
    {
        blockDiv.style.display = 'none';
        document.body.removeChild(blockDiv);
        blockDiv = null;
    },

	

	
	hideTheDiv : function()
    {
        innerTheDiv.style.display='none';
        document.body.removeChild(innerTheDiv);
        innerTheDiv = null;
    },
	
	positionBlock : function(wid,hei)
	//Calcul du positionnement des div en surimpression
	{
		var pageInfo,hauteur,haut,largeur,gauche;
		
		coef = 0.5;
		
		pageInfo = jsTopLoaderAjax.getPageInfo();
		windowInfo = jsTopLoaderAjax.getScrollXY();
		
		if (wid == null) {
			largeur = parseInt(pageInfo[3]*coef);
		} else
		{ 	
			largeur	= wid;
		}
			
		if (hei == null) {
			hauteur = parseInt(pageInfo[2]*coef);
		} else
		{ 	
			hauteur = hei;		
		}
		
		gauche = parseInt((pageInfo[3]-largeur)/2);
		haut = parseInt((pageInfo[2]-hauteur)/2+windowInfo[1]);
	
		arrayPosition = new Array(hauteur,largeur,haut,gauche);

        return arrayPosition;
		
	},

    getPageInfo : function()
    {
            var xScroll, yScroll;
            if (window.innerHeight && window.scrollMaxY)
            {
                    xScroll = document.body.scrollWidth;
                    yScroll = window.innerHeight + window.scrollMaxY;
            }
            else if (document.body.scrollHeight > document.body.offsetHeight)
            {
                    xScroll = document.body.scrollWidth;
                    yScroll = document.body.scrollHeight;
            }
            else
            {
                    xScroll = document.body.offsetWidth;
                    yScroll = document.body.offsetHeight;
            }

            var windowWidth, windowHeight;

            if (self.innerHeight)
            {
                    windowWidth = self.innerWidth;
                    windowHeight = self.innerHeight;
            }
			else if (document.documentElement && document.documentElement.clientHeight)
            {
                    windowWidth = document.documentElement.clientWidth;
                    windowHeight = document.documentElement.clientHeight;
            }
            else if (document.body)
            {
                    windowWidth = document.body.clientWidth;
                    windowHeight = document.body.clientHeight;
            }

            if (yScroll < windowHeight)
            {
                    pageHeight = windowHeight;
            }
            else
            {
                    pageHeight = yScroll;
            }

            if (xScroll < windowWidth)
            {
                    pageWidth = windowWidth;
            }
            else
            {
                    pageWidth = xScroll;
            }

            arrayPageSize = new Array(pageHeight, pageWidth, windowHeight, windowWidth);

            return arrayPageSize;
    },
	
	getScrollXY : function  () {
		  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;
		  }
		  
		  arrayWindowSize = new Array(scrOfX, scrOfY);
		  return arrayWindowSize;
	}

} 
