//gW = new Image; gW.src="/include/grid/img/30percent.png";
//--------------------------------------------------
var gB = 0;
var gI = false;	// initialise l'appel de gResize sur le window.onresize et window.onscroll
/*
gFond : le calque du fond
gCont : le calque du conteneur
*/
//--------------------------------------------------
//
//--------------------------------------------------
function gShowDiv ( div , w , h ) {

	// le fond
	gFond = document.getElementById('gFond');
	
	// cree le fond s'il n'existe pas
	if (!gFond) {
		
		gFond = document.createElement('div');
		gFond.id = 'gFond';
		gFond.style.zIndex = 2;

		gFond.style.top = 0;
		gFond.style.left = 0;
		gFond.style.position = 'absolute';

		gFond.style.width = '100%';
		gFond.style.height = '100%';

		gFond.style.cursor = 'pointer';
		
		gFond.style.background = '#EEE';
		gFond.style.filter = 'alpha(Opacity:0)';
		gFond.style.opacity = 0;
		gFond.trans = 0;

		gFond.onclick = gHide; ///function() { gHide(); };
		
		document.body.appendChild(gFond);

	}

	// affiche le calque à 0%
	gFond.style.visibility='visible';
	
	// monte à 80%
	gAppear(1);

	// le conteneur
	gCont = document.getElementById('gCont');

	// créé le conteneur s'il n'existe pas
	if (!gCont) {
		
		gCont = document.createElement('div');
		gCont.id = 'gCont';
		gCont.style.zIndex = 3;
		gCont.style.visibility = 'hidden';
		gCont.style.position = 'absolute';
		gCont.style.background = '#EEE';
		gCont.style.border = '#000 solid 1px';

		gCont.style.overflow = 'auto';
		gCont.style.padding = 10;

		document.body.appendChild(gCont);

		gCloz = document.createElement('div');
		gCloz.id = 'gCloz';
		gCloz.style.zIndex = 3;
		gCloz.style.visibility = 'hidden';
		gCloz.style.position = 'absolute';
		//gCont.style.background = '#EEE';
		//gCont.style.border = '#000 solid 1px';

		//gCloz.style.overflow = 'auto';
		//gCloz.style.padding = 10;

		document.body.appendChild(gCloz);
		gCloz.innerHTML = "<a href=# onclick=gHide();><img src=/images/close.png alt='Fermer la fenêtre' width=28 height=28 border=0 /></a>";

		// maintenant qu'on a les 2 éléments
		// aoute les fonctions de redimentionnement
		window.onresize = gSize;
		window.onscroll = gSize;

	}

	// dimension du conteneur
	var w = (w == null) ? "50%" : w;
	var h = (h == null) ? "50%" : h;

	// dimentionne le popup
	gCont.style.width = w;
	gCont.style.height = h;

	// redimentionne, même caché
	gSize(1);

	// met à jour le contenu
	gCont.innerHTML = document.getElementById(div).innerHTML;

	//gPage = document.getElementById('gPage');
	//gPage.src = page;

	// affiche le popup
	gCont.style.visibility='visible';
	gCloz.style.visibility='visible';

}

function gShow ( page , w , h ) {

	// le fond
	gFond = document.getElementById('gFond');
	
	// cree le fond s'il n'existe pas
	if (!gFond) {
		
		gFond = document.createElement('div');
		gFond.id = 'gFond';
		gFond.style.zIndex = 2;

		gFond.style.top = 0;
		gFond.style.left = 0;
		gFond.style.position = 'absolute';

		gFond.style.width = '100%';
		gFond.style.height = '100%';

		gFond.style.cursor = 'pointer';
		
		gFond.style.background = '#EEE';
		gFond.style.filter = 'alpha(Opacity:0)';
		gFond.style.opacity = 0;
		gFond.trans = 0;

		gFond.onclick = gHide; ///function() { gHide(); };
		
		document.body.appendChild(gFond);

	}

	// affiche le calque à 0%
	gFond.style.visibility='visible';
	
	// monte à 80%
	gAppear(1);

	// le conteneur
	gCont = document.getElementById('gCont');

	// créé le conteneur s'il n'existe pas
	if (!gCont) {
		
		gCont = document.createElement('div');
		gCont.id = 'gCont';
		gCont.style.zIndex = 3;
		gCont.style.visibility = 'hidden';
		gCont.style.position = 'absolute';
		gCont.style.background = 'transparent url(/images/loading.gif) center center no-repeat';
		//gCont.style.border = '#000 solid 1px';

		document.body.appendChild(gCont);

		gCloz = document.createElement('div');
		gCloz.id = 'gCloz';
		gCloz.style.zIndex = 3;
		gCloz.style.visibility = 'hidden';
		gCloz.style.position = 'absolute';
		//gCont.style.background = '#EEE';
		//gCont.style.border = '#000 solid 1px';

		//gCloz.style.overflow = 'auto';
		//gCloz.style.padding = 10;

		document.body.appendChild(gCloz);
		gCloz.innerHTML = "<a href=# onclick=gHide();><img src=/images/close.png alt='Fermer la fen&ecirc;tre' width=28 height=28 border=0 /></a>";

		// maintenant qu'on a les 2 éléments
		// aoute les fonctions de redimentionnement
		window.onresize = gSize;
		window.onscroll = gSize;

	}

	// dimension du conteneur
	var w = (w == null) ? "50%" : w+'px';
	var h = (h == null) ? "50%" : h+'px';

	// dimentionne le popup
	gCont.style.width = w;
	gCont.style.height = h;

	// redimentionne, même caché
	gSize(1);

	// met à jour le contenu
	gCont.innerHTML = '<iframe id="gPage" name="gPage" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" vspace="0" hspace="0" src="'+page+'" width="100%" height="100%" style="display:none" onload="this.style.display=\'block\';"></iframe>';
	// onLoad="alert(\'ok\');"

	//gPage = document.getElementById('gPage');
	//gPage.src = page;

	// affiche le popup
	gCont.style.visibility='visible';
	gCloz.style.visibility='visible';

	return false;
}
//--------------------------------------------------
//
//--------------------------------------------------
function gAppear(v) {

	// sens
	if (v==1) {
		t = 10;
		tr = 'gFond.trans < 80';
		vi = 'visible';
	} else {
		t = -10;
		tr = 'gFond.trans >= 0';
		vi = 'hidden';
	}
	
	gFond.trans += t;
	
	if(eval(tr)) {
		gFond.style.opacity = gFond.trans / 100;
		gFond.style.filter = 'alpha(Opacity:'+gFond.trans+')';
		setTimeout( function() { gAppear(v); }, 50);
		//setTimeout( gAppear(v) , 50);
	} else {
		gFond.style.visibility = vi ;
	}
}
//--------------------------------------------------
//
//--------------------------------------------------
function gSize(x) {

	// si le fonds est visible, redimentionne-le
	if (gFond.style.visibility=='visible' || x==1) {

		// fonds à 100%
		gFond.style.width = document.body.scrollWidth;
		gFond.style.height = document.body.scrollHeight;
		
		// récupère la taille du cadre
		gW = parseInt(gCont.offsetWidth); // sans le 'px'
		gH = parseInt(gCont.offsetHeight);
		
		// enlève le 'px'
		//gW = gW.substr(0,gW.length-2);
		//gH = gH.substr(0,gH.length-2)
		document.title = document.body.scrollTop;
		
		// recentre le cadre
		h = document.body.scrollTop + ((document.body.clientHeight - gH)/2);
		w = document.body.scrollLeft + ((document.body.clientWidth - gW)/2);

		// place le
		gCont.style.left  = w + 'px';
		gCont.style.top   = h + 'px';
		
		gCloz.style.left = w + gW + 20;
		gCloz.style.top  = h;

	}
}
//--------------------------------------------------
//
//--------------------------------------------------
function gHide () {

	if (gB==0) {

		gCloz.style.visibility='hidden';
		gCont.style.visibility='hidden';
		gAppear(0);

		gCont.innerHTML = '';
	}
}
//--------------------------------------------------
//
//--------------------------------------------------
function gWidth() {

	scrol = 21;
	return (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth-scrol : document.body.offsetWidth-scrol;
}
//--------------------------------------------------
//
//--------------------------------------------------
function gHeight() {
	
	scrol = 0
	return (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight-scrol : document.body.offsetHeight-scrol;
}
//--------------------------------------------------
//
//--------------------------------------------------
function gLock () {

	gB = 1;
	gFond.style.cursor = 'wait';
}
//--------------------------------------------------
//
//--------------------------------------------------
function gUnLock () {

	gB = 0;
	gFond.style.cursor = 'pointer';
}
//--------------------------------------------------

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
        document.body.lastChild);

    // Pixel width of the scroller
    return (wNoScroll - wScroll);
}

