// Procédures globales du projet
function GET_APPELANT()
{// Cette fonction permet d'obtenir la fenetre qui a ouvert l'iframe en cours quand on est dans une iframe à un n'importe quel niveau
	
	var xAppelant ;
	var xIndice ;	
	
	if (self == top || self.name == "IFRAME1" ) // Si on n'est pas dans une iframe ou si on est dans la premiere iframe, l'appelant est forcement la page principale
	{
		xAppelant = top;
	}
	else // sinon on considere que l'appelant est l'iframe qui a l'indice juste en dessous
	{
		xIndice = Number(self.name.substr(6)) ;
		xIndice = xIndice -1 ;
		
		xAppelant = eval( "top.IFRAME"+xIndice);
		
	}
	
	return xAppelant;
}

function PGNJS_CREER_IFRAME()
{	// Cette fonction permet de creer dynamiquement une iframe ainsi qu'un calque GFI (qui imite le GFI WINDEV) pour grisé l'arriere plan
	// et renvoi le nom de l'iframe crée
	
	xRacine = top ; // A premiere vue cette variable ne sert à rien sauf que bizarrement, 
	// l'appel direct à 'top' plante dans certains cas mais en utilisant la variable ca marche ! Bizarre vous avez dit bizarre !!!
	
	if (typeof(xRacine.gTabCalqueIFrame) == "undefined") xRacine.gTabCalqueIFrame = new Array();
	if (typeof(xRacine.gTabCalqueBBFermer) == "undefined") xRacine.gTabCalqueBBFermer = new Array();
	if (typeof(xRacine.gTabCalqueGFI) == "undefined") xRacine.gTabCalqueGFI = new Array();
	if (typeof(xRacine.gTabIFrame) == "undefined") xRacine.gTabIFrame = new Array();

	
	// On recupere les dimensions de la page principale
	var xHauteurDispo = 600; // Hauteur Fixe
	var xLargeurDispo = parent.document.body.offsetWidth; // Largeur de la fenetre principale	
	
	// Determination du nom de l'iframe à utiliser
	// si on n'est pas déjà dans une iframe
	var xIndice = ( self == xRacine )?1:Number(self.name.substr(6)) + 1;		
	
	// Recherche si l'iframe est deja existante	
	if ( xIndice < xRacine.gTabIFrame.length ) // Si l'iframe existe deja on la rend visible
	{
		
		xRacine.gTabCalqueGFI[xIndice].style.width = xLargeurDispo+"px";
		xRacine.gTabCalqueGFI[xIndice].style.height = xHauteurDispo+"px";				
		
		// On centre le conteneur : ce sera le point de depart de l'animation
		xRacine.gTabCalqueIFrame[xIndice].style.top =  xHauteurDispo/2+"px";
		xRacine.gTabCalqueIFrame[xIndice].style.left =  xLargeurDispo/2+"px";
		
		xRacine.gTabCalqueIFrame[xIndice].style.height = "10px";
		xRacine.gTabCalqueIFrame[xIndice].style.width = "10px";
		
		// On le rend visible
		xRacine.gTabCalqueIFrame[xIndice].style.visibility = "visible";

		// On réaffiche l'image d'attente		
		xRacine.gTabCalqueGFI[xIndice].ImageAttente.style.display = "block";
		
		// Affichage progressif du GFI
		xRacine.$(xRacine.gTabCalqueGFI[xIndice]).fadeIn(900);				
	}else{
	
		var xNomIFrame = "IFRAME"+xIndice;
		var xNomCalqueIFrame = "CEL_IFRAME"+xIndice;
		var xNomCalqueEffet = "CEL_EFFET_IFRAME"+xIndice;
		var xNomCalqueConteneurIF = "CEL_CONTENEUR_IF"+xIndice;
		var xNomCalqueGFI = "CEL_GFI"+xIndice;
		
		// Création d'un nouveau calque conteneur pour l'iframe : 
		// Il y aura dedans 2 calques : 1 pour l'iframe, et 1 pour la croix rouge qui ferme l'iframe
		xRacine.gTabCalqueBBFermer[xIndice] = xRacine.document.createElement("DIV");
		xRacine.gTabCalqueBBFermer[xIndice].name = xNomCalqueConteneurIF;
		xRacine.gTabCalqueBBFermer[xIndice].id = xNomCalqueConteneurIF;
		xRacine.gTabCalqueBBFermer[xIndice].style.position = "absolute" ;
		xRacine.gTabCalqueBBFermer[xIndice].style.align = "center";
		xRacine.gTabCalqueBBFermer[xIndice].style.width= "10px";  
		xRacine.gTabCalqueBBFermer[xIndice].style.height = "10px";
		xRacine.gTabCalqueBBFermer[xIndice].style.top =  xHauteurDispo/2+"px";
		xRacine.gTabCalqueBBFermer[xIndice].style.left =  xLargeurDispo/2+"px";
		xRacine.gTabCalqueBBFermer[xIndice].style.zIndex = 100+xIndice*101 -1 ; // pour positionner ce calque au dessus de tous les autres deja affichés		
		xRacine.gTabCalqueBBFermer[xIndice].Indice = xIndice; // 		
		var xTmp = "";				
		xTmp = xTmp + "<div STYLE='position:absolute;right:0; top:0 ;width:10px ;height:10px;'>" ;
		xTmp = xTmp + "<img  id=IM_FERMER  src=\"/DOMINO_WEB_WEB/Annuler10_i.png\" width=10px height=10px style=\"float: right;\"   border=0  ";		
		xTmp = xTmp + "onClick='PGNJS_ANNULER_OUVERTURE_IFRAME("+xIndice+");'  onmouseover='this.src=\"/DOMINO_WEB_WEB/Annuler10_a.png\"; '  onmouseout='this.src=\"/DOMINO_WEB_WEB/Annuler10_i.png\"  ;'    ";
		xTmp = xTmp + ">"
		xTmp = xTmp + "</div>";		
		xRacine.gTabCalqueBBFermer[xIndice].innerHTML = xTmp;		
		
		// Création d'un nouveau calque	pour l'iframe
		xRacine.gTabCalqueIFrame[xIndice] = xRacine.document.createElement("DIV");
		xRacine.gTabCalqueIFrame[xIndice].name = xNomCalqueIFrame;
		xRacine.gTabCalqueIFrame[xIndice].id = xNomCalqueIFrame;
		xRacine.gTabCalqueIFrame[xIndice].style.position = "absolute" ;
		xRacine.gTabCalqueIFrame[xIndice].style.top = xHauteurDispo/2+"px";
		xRacine.gTabCalqueIFrame[xIndice].style.left = xLargeurDispo/2+"px";
		xRacine.gTabCalqueIFrame[xIndice].style.border = "1px #6E6E6E solid" ;
		xRacine.gTabCalqueIFrame[xIndice].style.backgroundColor = "#FFFFFF";
		xRacine.gTabCalqueIFrame[xIndice].style.align = "center";
		xRacine.gTabCalqueIFrame[xIndice].style.width= "10px";  // dimensions nulles pour l'instant car les dimensions dépendront de la page qu'on affiche dedans
		xRacine.gTabCalqueIFrame[xIndice].style.height = "10px";
		xRacine.gTabCalqueIFrame[xIndice].style.zIndex = 100+xIndice*101 ; // pour positionner ce calque au dessus de tous les autres deja affichés
		xRacine.gTabCalqueIFrame[xIndice].Indice = xIndice; // 
		// On met une iframe dans le calque		
		var xTmp = "";				
		xTmp = xTmp + "";
		xTmp = xTmp + "<div STYLE=' position:absolute;left:0; top:0 ;'>" ;
		xTmp = xTmp + "<iframe src='' id='"+xNomIFrame+"' name='"+xNomIFrame+"' scrolling='no' frameborder='0' height=0 width=0> </iframe>";
		xTmp = xTmp + "</div>";
		xRacine.gTabCalqueIFrame[xIndice].innerHTML = xTmp;		

		// Création d'un nouveau calque GFI (pour grisé l'arriere plan)
		// La cellule qui imite le GFI de WinDev prend toute la dimension de la page
		// Elle est semi transparente
		xRacine.gTabCalqueGFI[xIndice] = xRacine.document.createElement("DIV");
		xRacine.gTabCalqueGFI[xIndice].name = xNomCalqueGFI;
		xRacine.gTabCalqueGFI[xIndice].id = xNomCalqueGFI;
		xRacine.gTabCalqueGFI[xIndice].style.position = "absolute";
		xRacine.gTabCalqueGFI[xIndice].style.top  = 0 ;
		xRacine.gTabCalqueGFI[xIndice].style.left = 0 ;
		xRacine.gTabCalqueGFI[xIndice].style.width = xLargeurDispo+"px";
		xRacine.gTabCalqueGFI[xIndice].style.height = xHauteurDispo+"px";
		xRacine.gTabCalqueGFI[xIndice].style.filter = "alpha(opacity=0)";
		xRacine.gTabCalqueGFI[xIndice].style.opacity = 0.0;		
		xRacine.gTabCalqueGFI[xIndice].style.backgroundColor = "#FFFFFF";
//		xRacine.gTabCalqueGFI[xIndice].style.backgroundColor = "#AAFFAA";		
		xRacine.gTabCalqueGFI[xIndice].style.zIndex = 100+xIndice*100; // pour positionner ce calque au dessus de tous les autres deja affichés mais juste en dessous du calque de l'iframe
		xRacine.gTabCalqueGFI[xIndice].Indice = xIndice; // 		
		// Remplissage du calque GFI pour patienter et eventuellement annuler le chargement (si y a un plantage par exemple)
		var xTmp = "" ;
		xTmp = xTmp   +"<TABLE  width=100% height=100% ><TR><TD align='center' valign='middle'> <div id='IMG_ATTENTE_GFI_"+xIndice+"' >"
		xTmp = xTmp   + "<img src='/DOMINO_WEB_WEB/Attente.gif' width=120px height=120px   border=0 name='IM_ATTENTE'  onClick='PGNJS_ANNULER_OUVERTURE_IFRAME("+xIndice+");'>"
		xTmp = xTmp   + "<BR>"		
		xTmp = xTmp   + "<A class='Bouton-Rouge-100x26'   href='Javascript:PGNJS_ANNULER_OUVERTURE_IFRAME("+xIndice+");' >Annuler</A>"
		xTmp = xTmp   + "</div></TD></TR></TABLE>"
		xRacine.gTabCalqueGFI[xIndice].innerHTML = xTmp;
		
		// ajout des calques au document HTML
		xRacine.document.body.appendChild(xRacine.gTabCalqueGFI[xIndice]);
		xRacine.document.body.appendChild(xRacine.gTabCalqueIFrame[xIndice]);
		xRacine.document.body.appendChild(xRacine.gTabCalqueBBFermer[xIndice]);
		
		// Referencement de l'iframe dans un tableau
		xRacine.gTabIFrame[xIndice] = xRacine.document.getElementById(xNomIFrame);
		
		// Referencement de l'image d'attente (pour pouvoir la cacher plus tard)
		xRacine.gTabCalqueGFI[xIndice].ImageAttente = xRacine.document.getElementById("IMG_ATTENTE_GFI_"+xIndice);
		
		// Affichage progressif du GFI
		xRacine.$(xRacine.gTabCalqueGFI[xIndice]).fadeTo(1000,0.6);
	}

	// On renvoie le nom de l'iframe créé
	//return  xNomIFrame
	return  xRacine.gTabIFrame[xIndice].name;
}

function PGNJS_FERMER_IFRAME(pParam1 , pParam2 , pParam3 , pParam4 , pParam5 , pParam6 , pParam7 , pParam8 , pParam9 , pParam10 , pParam11 , pParam12 , pParam13 , pParam14 , pParam15 , pParam16 , pParam17 , pParam18 , pParam19 , pParam20)
{	
	xRacine = top ; // A premiere vue cette variable ne sert à rien sauf que bizarrement, 
						// l'appel direct à 'top' plante dans certains cas mais en utilisant la variable ca marche ! Bizarre vous avez dit bizarre !!!
	if (typeof(xRacine.gTabIFrame) == "undefined") xRacine.gTabIFrame = new Array();
	
	var xHauteurDispo = 580; // Hauteur Fixe
	var xLargeurDispo = parent.document.body.offsetWidth; // Largeur de la fenetre principale	
	
	var xPosTop  = xHauteurDispo / 2 ;
	var xPosLeft = xLargeurDispo / 2 ;	
		
	var xAppelant = GET_APPELANT(); 		
	var xIndice = (self.name.substr(0,6)=="IFRAME")?Number(self.name.substr(6)):0
		
	if (typeof(xRacine.gTabIFrame[xIndice])!="undefined")		
	{
		xRacine.gTabIFrame[xIndice].width = 0;
		xRacine.gTabIFrame[xIndice].height = 0;
					
		xRacine.$(xRacine.gTabCalqueIFrame[xIndice]).animate({width: 0, height: 0 , top: xPosTop, left: xPosLeft }, 900 , "easeInCirc", xRacine.FinFermerIFrame);
//		xRacine.$(xRacine.gTabCalqueIFrame[xIndice]).animate({ height: 10 , top: xPosTop }, 700 )
//		.animate({width: 0 , left: xPosLeft }, 400 , "easeInCirc", xRacine.FinFermerIFrame);
		
		xRacine.$(xRacine.gTabCalqueGFI[xIndice]).fadeOut(1200);
		
		
		// Appel d'un traitement de la page appelante 
		try	{		
			xAppelant.PIN_FERMER_IFRAME(pParam1 , pParam2 , pParam3 , pParam4 , pParam5 , pParam6 , pParam7 , pParam8 , pParam9 , pParam10 , pParam11 , pParam12 , pParam13 , pParam14 , pParam15 , pParam16 , pParam17 , pParam18 , pParam19 , pParam20);			
		} catch (xException){
			// rien a faire : s'il n'y a pas de procedure PIN_FERMER_IFRAME dans la fenetre appelante : aucun traitement à faire
		}
		
		// Mise à blanc de l'iframe
		xRacine.gTabIFrame[xIndice].src = "/DOMINO_WEB_WEB/blank.html";
		
	}
	else
	{
		self.close();
	}
}

// Fonction appelée à la fin de l'animation
function FinFermerIFrame(){
	var xRacine = top ;
	xIndice = this.Indice;
	xRacine.gTabCalqueBBFermer[xIndice].style.visibility = "hidden";	
	xRacine.gTabCalqueIFrame[xIndice].style.visibility = "hidden";
}

function PGNJS_MISE_EN_PAGE_IFRAME(pLargeur,pHauteur,pCallBack)
{
	
	gCallBack = pCallBack;
	
	xRacine = top ; // A premiere vue cette variable ne sert à rien sauf que bizarrement, 
	// l'appel direct à 'top' plante dans certains cas mais en utilisant la variable ca marche ! Bizarre vous avez dit bizarre !!!
	if (typeof(xRacine.gTabIFrame) == "undefined") return;
	
	// On recupere les dimensions de la page principale
	var xHauteurDispo = 580; // Hauteur Fixe
	var xLargeurDispo = parent.document.body.offsetWidth; // Largeur de la fenetre principale	
	
	var xPosTop  = ( xHauteurDispo - pHauteur ) / 2 ;
	var xPosLeft = ( xLargeurDispo - pLargeur ) / 2 ;	
	
	var xHauteurCel=($.browser.msie)?pHauteur + 2:pHauteur;
	var xLargeurCel=($.browser.msie)?pLargeur + 2:pLargeur;
	var xLargeurCelConteneur=xLargeurCel + 12;	
	
	var xIndice = (self.name.substr(0,6)=="IFRAME")?Number(self.name.substr(6)):0
	
	if (typeof(xRacine.gTabIFrame[xIndice])!="undefined")
	{
		xRacine.gTabIFrame[xIndice].style.visibility = "hidden";
		// on stock les dimension de l'iframe redimensionne l'iframe...
		xRacine.gTabIFrame[xIndice].height = pHauteur+"px";
		xRacine.gTabIFrame[xIndice].width = pLargeur+"px";		
		
		// on cache les scrollbars pour Firefox
		xRacine.gTabIFrame[xIndice].scrolling = "no";
		
		// Positionnement de l'iframe
//		$(xRacine.gTabCalqueConteneurIFrame[xIndice]).animate({height: xHauteurCel, width: xLargeurCelConteneur, top: xPosTop, left: xPosLeft }, 900 )
		xRacine.gTabCalqueBBFermer[xIndice].style.width= xLargeurCelConteneur+"px";
		xRacine.gTabCalqueBBFermer[xIndice].style.height= xHauteurCel+"px";
		xRacine.gTabCalqueBBFermer[xIndice].style.left= xPosLeft+"px";
		xRacine.gTabCalqueBBFermer[xIndice].style.top= xPosTop+"px";
		xRacine.gTabCalqueBBFermer[xIndice].style.visibility = "visible";
		
		
//		$(xRacine.gTabCalqueIFrame[xIndice]).animate({height: xHauteurCel, width: xLargeurCel}, 900 , FinMiseEnPageIFrame);
		$(xRacine.gTabCalqueIFrame[xIndice]).animate({width: xLargeurCel , left: xPosLeft}, 600 , "easeOutBounce" )
		.animate({height: xHauteurCel , top: xPosTop}, 600 , "easeOutBounce" , FinMiseEnPageIFrame);
		
	}
}

// Fonction appelée à la fin de l'animation
function FinMiseEnPageIFrame(){
	var xRacine = top ; 
	var xIndice = this.Indice

	// On réaffiche l'iframe
	xRacine.gTabIFrame[xIndice].style.visibility = "visible";
	// On cache l'image d'attente car elle fait tourner IE à fond
	xRacine.gTabCalqueGFI[xIndice].ImageAttente.style.display = "none";
	
	//xRacine.gTabIFrame[xIndice].focus();
	
	if (gCallBack) eval(gCallBack);
	
	PGNJS_REDUIT_PAGE(); 
	
}
function PGNJS_ANNULER_OUVERTURE_IFRAME(pIndice)
{
	xRacine = top ; // A premiere vue cette variable ne sert à rien sauf que bizarrement, 
	// l'appel direct à 'top' plante dans certains cas mais en utilisant la variable ca marche ! Bizarre vous avez dit bizarre !!!
	var xHauteurDispo = 580; // Hauteur Fixe
	var xLargeurDispo = parent.document.body.offsetWidth; // Largeur de la fenetre principale	
	
	var xPosTop  = xHauteurDispo / 2 ;
	var xPosLeft = xLargeurDispo / 2 ;	
	
	var xAppelant = GET_APPELANT(); 
	var xIndice = isNaN(pIndice)? pIndice.toString():pIndice
	
	if (typeof(xRacine.gTabIFrame[xIndice])!="undefined")		
	{
		xRacine.gTabIFrame[xIndice].width = 0;
		xRacine.gTabIFrame[xIndice].height = 0;
		
		xRacine.$(xRacine.gTabCalqueIFrame[xIndice]).animate({width: 0, height: 0 , top: xPosTop, left: xPosLeft }, 900 , "easeInCirc", xRacine.FinFermerIFrame);
		
		xRacine.$(xRacine.gTabCalqueGFI[xIndice]).fadeOut(1000);
		
		
		// Appel d'un traitement de la page appelante 
		try	{		
			xAppelant.PIN_FERMER_IFRAME(pParam1 , pParam2 , pParam3 , pParam4 , pParam5 , pParam6 , pParam7 , pParam8 , pParam9 , pParam10 , pParam11 , pParam12 , pParam13 , pParam14 , pParam15 , pParam16 , pParam17 , pParam18 , pParam19 , pParam20);			
			} catch (xException){
			// rien a faire : s'il n'y a pas de procedure PIN_FERMER_IFRAME dans la fenetre appelante : aucun traitement à faire
			}
		
		// Mise à blanc de l'iframe
		xRacine.gTabIFrame[xIndice].src = "/DOMINO_WEB_WEB/blank.html";
		
	}else
	{
		self.close();
	}
}
	

