// ******************************************************************
// ******************************************************************
//
//  Fonction de menu déroulant en Javascript   (fichier TopNavi.js)
//  Développé par Pierre POISSONNIER
//  Le vendredi 9 janvier 2004 - 19h10
//
//  Créé pour les sites Intranet et Internet du groupe AREVA
//  Copyright Euriware 2004 - Groupe AREVA
//
// ******************************************************************



// ******************************************************************
// ************  REGLES SYNTAXIQUES ET GRAMMATICALES  ***************
// ******************************************************************
// 
// Element = [ Texte , Image, Href, Target, <SOUS-MENU>, Classe sous-menu, Classe case courante, Classe ss-menu sélectionné, Classe case courante sélectionné ] 
// Sous-Menu = [ Element, Element, Element, ... ]
// Menu = [ <SOUS-MENU>, Classe sous-menu, Classe ss-menu sélectionné, image de fond 1er niveau ]
// 
// APPEL DE LA FONCTION :
//	TopNavi( <MENU> , Largeur (défaut: "") , Hauteur (défaut: ""), Disposition verticale (oui:1 | non:0) );
//
// ******************************************************************
// ******************************************************************
// ******************************************************************








var ie = (document.all)? true:false;
var TopNaviWidth;
var TopNaviHeight;
var MTTN = [];
var LibImagePath = "/lib/images/"

function TopNavi(myTopNavi, myTopNaviWidth, myTopNaviHeight, IsVertical)
{
	// **************************************************************
	// FONCTION TopNavi
	// Point d'entrée pour l'affichage du menu
	// **************************************************************


	// Chargement des paramètres
	// *************************
	var myStyleNormal;
	var myStyleSelect;
	var Zindex = 500;
	var MenuStyle = myTopNavi[1];
	var MenuStyleSelected = myTopNavi[2];
	var IsVerti = 0;
	TopNaviWidth = myTopNaviWidth;
	TopNaviHeight = myTopNaviHeight;
	if (IsVertical != null)
		if (IsVertical.toString() == "1")
			IsVerti=1;
	document.write("<A ID='ATTN'></A>");
	document.write("<table ID='TTN' ");
	if (TopNaviWidth != null)
		if (IsVerti == 1)
		{
			document.write("width='" + TopNaviWidth.toString() + "' "); }
	if (TopNaviHeight != null)
		if (IsVerti != 1)
		{
			document.write("height='" + TopNaviHeight.toString() + "' "); }
	document.write("style='BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px' cellspacing='0' cellpadding='0' border='0' marginwidth='0' marginheight='0' topmargin='0' leftmargin='0'>");
	document.write("<FORM METHOD='POST' ID='TOPNAVIFORM'><tbody>");


	// Chargement du premier niveau de l arborescence
	// **********************************************
	for (i=0; i<myTopNavi[0].length; i++) {
		if ((IsVerti == 1) || (i == 0)) document.write("<tr height=' + TopNaviHeight.toString() + '>");
		TopNaviBar( "TN_" + i.toString(), myTopNavi[0][i], myTopNavi[1], myTopNavi[2], myTopNavi[3], TopNaviWidth, TopNaviHeight, IsVerti);
		if ((IsVerti == 1) || (i == myTopNavi[0].length)) document.write("</tr>");
	}
	document.write("</tbody></form></table>");


	// Chargement récursif des autres niveaux de l arborescence
	// ********************************************************
	for (i=0; i<myTopNavi[0].length; i++) {


		var myStyleNormal = myTopNavi[1];
		var myStyleSelect = myTopNavi[2];
		if (myTopNavi[0][i][5].length != 0)
			{ myStyleNormal = myTopNavi[0][i][5];}
		if (myTopNavi[0][i][7].length != 0)
			{ myStyleSelect = myTopNavi[0][i][7];}
		

		if ((myTopNavi[0][i][4].length) != 0) {
			TopNaviSub("TN", "TN_" + i.toString(), myTopNavi[0][i][4], myStyleNormal, myStyleSelect, Zindex, TopNaviWidth, TopNaviHeight ); }
	}
	

}



function TopNaviBar( CellID, myElement, StyleNormal, StyleSelect, ImgBack, TopNaviWidth, TopNaviHeight, IsVerti)
{
	// **************************************************************
	// FONCTION TopNaviBar
	// Affiche le premier niveau de l arborescence : la barre de menu
	// **************************************************************


	// Recherche des styles à appliquer à la cellule : spécifique ou par défaut
	// ************************************************************************
	
	var LaPos;
	var myStyleNormal = StyleNormal;
	var myStyleSelect = StyleSelect;
	var myImgBack = ImgBack;
	var XoffS;
	var YoffS;

	if (myElement[6].length != 0)
		{ myStyleNormal = myElement[6];}

	if (myElement[8].length != 0)
		{ myStyleSelect = myElement[8];}
	

	// Ouverture de la balise TD avec les styles et image de fond
	// **********************************************************

	if (IsVerti != 1) { document.write("<TD WIDTH='0' HEIGHT='" + TopNaviHeight + "' VALIGN='TOP'><A ID='A" + CellID + "'></A></TD>"); }
	document.write("<TD style='");
	if (myElement[2] != null )
		if (myElement[2].length > 0)
			document.write("cursor:hand;");
			
	if (IsVerti != 1) { document.write(" padding-left:5px; padding-right:5px; border-right:1px solid #000000;"); }
	document.write("' ");
	//if (IsVerti == 1) document.write("WIDTH='" + TopNaviWidth + "' ");
	document.write("HEIGHT='" + TopNaviHeight + "' ID='" + CellID + "'");
	//if (myElement[1].length == 0) document.write(" style='BORDER-RIGHT: 1px solid #000000; BORDER-TOP: 1px; BORDER-LEFT: 1px solid #000000; BORDER-BOTTOM: 1px solid #000000'");
	if (myStyleNormal != null )
	{
		document.write(" CLASS='" + myStyleNormal + "' onMouseOut='document.getElementById(\"" + CellID + "\").className=\"" + myStyleNormal + "\";");
		if (myElement[4].length > 0)	document.write(" document.getElementById(\"T" + CellID + "\").style.visibility=\"hidden\";");
		//if (myElement[2] != null )
			//if (myElement[2].length > 0)
			{
				document.write("document.getElementById(\"" + CellID + "Lnk\").className=\"" + myStyleNormal + "\";");			
			}
		document.write("'");
	}

	document.write(" onMouseOver='LaPos = getAnchorPosition(\"A" + CellID + "\"); ");
	if (myStyleSelect != null ) { document.write("document.getElementById(\"" + CellID + "\").className=\"" + myStyleSelect + "\"; "); }
	if (myElement[4].length > 0)
	{
		if (!ie) {
			if (IsVerti == 1) { XoffS = -10; YoffS = -5 } else { XoffS = 0; YoffS = TopNaviHeight }
			document.write("document.getElementById(\"T" + CellID + "\").style.left=LaPos.x + (" + XoffS + "); ");
			document.write("document.getElementById(\"T" + CellID + "\").style.top=(LaPos.y) + (" + YoffS + "); ");
		}
		else {
			if (IsVerti == 1) { XoffS = -10; YoffS = -5 } else { XoffS = 0; YoffS = TopNaviHeight }
			document.write("document.getElementById(\"T" + CellID + "\").style.posLeft=(LaPos.x + (" + XoffS + ")); ");
			document.write("document.getElementById(\"T" + CellID + "\").style.posTop=(LaPos.y + (" + YoffS + ")); ");
		}
		document.write("document.getElementById(\"T" + CellID + "\").style.position=\"absolute\"; ");
		document.write("document.getElementById(\"T" + CellID + "\").style.visibility=\"visible\"; ");
		
	}
	if (myStyleSelect != null )
		//if (myElement[2] != null )
			//if (myElement[2].length > 0) 
			{
			document.write("document.getElementById(\"" + CellID + "\").className=\"" + myStyleSelect + "\"; ");
			document.write("document.getElementById(\"" + CellID + "Lnk\").className=\"" + myStyleSelect + "\"; ");
			}
			
	document.write("'");

	if (myElement[2] != null )
		if (myElement[2].length > 0) 
		{
		document.write(" onClick='");
		document.write("GoNavMenu(\"" + myElement[10].toString() +"\", \"" + myElement[2].toString() + "\", \"" + myElement[3].toString() + "\");")
		document.write("'");
		}

	if (ImgBack != null ) { document.write(" BACKGROUND='" + ImgBack + "'"); }
	document.write(">");
	


	// Ouverture du lien [2] s il existe, dans la fenête [5]
	// *****************************************************

	document.write("<table border='0' cellspacing='0' cellpadding='0'><tr>");
	if (IsVerti == 1) document.write("<td valign='top' width='10'><img src='" + LibImagePath + "fleche.gif' width='4' height='10' border='0'></td>");
	document.write("<td>");

	if (myElement[2] != null )
		if (myElement[2].length > 0) 
		{
			//document.write("<A ID='" + CellID + "Lnk' HREF='" + myElement[2].toString() + "'");
			document.write("<A ID='" + CellID + "Lnk' HREF='Javascript:GoNavMenu(\"" + myElement[10].toString() +"\", \"" + myElement[2].toString() + "\", \"" + myElement[3].toString() + "\");'");
			if (myStyleNormal != null ) { document.write(" CLASS='" + myStyleNormal + "' onMouseOut='document.getElementById(\"" + CellID + "Lnk\").className=\"" + myStyleNormal + "\";'"); }
			if (myStyleSelect != null )
			{
				document.write(" onMouseOver='document.getElementById(\"" + CellID + "Lnk\").className=\"" + myStyleSelect + "\";'");
			}
			//if (myElement[3] != null ) { if (myElement[3].length > 0) { document.write(" TARGET='" + myElement[3].toString() + "'"); } }
			document.write(">");
		}
		else
			{
			document.write("<FONT ID='" + CellID + "Lnk'");
			if (myStyleNormal != null ) { document.write(" CLASS='" + myStyleNormal + "' onMouseOut='document.getElementById(\"" + CellID + "Lnk\").className=\"" + myStyleNormal + "\";'"); }
			if (myStyleSelect != null )
			{
				document.write(" onMouseOver='document.getElementById(\"" + CellID + "Lnk\").className=\"" + myStyleSelect + "\";'");
			}
			document.write(">");
			}


	// Affichage de l image [1] s il existe, sinon du texte [0] s il existe
	// ********************************************************************
	document.write(myElement[0].toString());


	// Fermeture du lien [4] s il existe
	// *********************************
	if (myElement[2] != null )
		if (myElement[2].length > 0)
			document.write("</A>");
		else
			document.write("</font>");
	document.write("</td></table>");


	// Fermeture de la balise TD
	// *************************
	
	document.write("</TD>");
	if (IsVerti == 1) { document.write("<TD WIDTH='0'><A ID='A" + CellID + "'></A></TD>"); }
}







function TopNaviSub(CellIDM, CellID, myElement, StyleNormal, StyleSelect, Zindex, TopNaviWidth, TopNaviHeight )
{
	// **************************************************************
	// FONCTION TopNaviSub
	// Affiche les niveaux supérieurs à 2 : les sous menus
	// **************************************************************

	var i;
	var LaPos;
	var myStyleNormal;
	var myStyleSelect;

	// Création d un DIV contenant le sous-menu
	// ****************************************

	document.write("<SCRIPT LANGUAGE='JavaScript'> var MT" + CellID + " = [ \"T" + CellID + "\", MT" + CellIDM + " ] ; </SCRIPT>");
        document.write("<div ID='T" + CellID + "' style='position : absolute; visibility: hidden; z-index: " + (Zindex + 2).toString() + ";' ID='T" + CellID + "' onmouseover='this.style.visibility=\"visible\"; TopNaviOpenMenu(MT" + CellID + ");' onmouseout='this.style.visibility=\"hidden\"; TopNaviCloseMenu(MT" + CellID + ");'>");
	document.write("<A ID='AT" + CellID + "'></A><TABLE ");
	document.write("style='BORDER-RIGHT: 0px; BORDER-TOP: 1px solid #000000; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px' cellspacing='0' cellpadding='3' border='0' marginwidth='0' marginheight='0' topmargin='0' leftmargin='0'>");
	document.write("<tbody>");


	// Balayage des cellules du sous menu
	// **********************************
	for (i=0; i<myElement.length; i++)
	{
		myStyleNormal = StyleNormal;
		myStyleSelect = StyleSelect;
		if (myElement[i][6].length != 0)
			{ myStyleNormal = myElement[i][6]; }
		if (myElement[i][8].length != 0)
			{ myStyleSelect = myElement[i][8]; }


		document.write("<tr>");

		// Ouverture de la balise TD avec les styles et image de fond
		// **********************************************************

		document.write("<TD VALIGN='middle' ID='" + CellID + "_" + i.toString() + "' style='");
		
		if (myElement[i][2] != null )
			if (myElement[i][2].length > 0) 
				document.write("cursor:hand; ");
				
		document.write("BORDER-RIGHT: 1px solid #000000; BORDER-TOP: 0px; BORDER-LEFT: 1px solid #000000; BORDER-BOTTOM: 1px solid #000000'");
		if (myStyleNormal != null ) { 
			document.write(" CLASS='" + myStyleNormal + "' ");
		}
		document.write("onMouseOut='");
		if (myStyleNormal != null ) {
			document.write("document.getElementById(\"" + CellID + "_" + i.toString() + "\").className=\"" + myStyleNormal + "\"; ");
			document.write("document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleNormal + "\";");			
		}
		if (myElement[i][4].length > 0)
		{
			document.write("document.getElementById(\"T" + CellID + "_" + i.toString() + "\").style.visibility=\"hidden\"; ");
		}

		document.write("'");

		document.write(" onMouseOver='");
		if (myElement[i][4].length > 0)
		{
			document.write("LaPos = getAnchorPosition(\"A" + CellID  + "_" + i.toString() + "\"); ");
			if (!ie) {
				document.write("document.getElementById(\"T" + CellID + "_" + i.toString() + "\").style.left=LaPos.x; ");
				document.write("document.getElementById(\"T" + CellID + "_" + i.toString() + "\").style.top=(LaPos.y); ");
			}
			else {
				document.write("document.getElementById(\"T" + CellID + "_" + i.toString() + "\").style.posLeft=LaPos.x; ");
				document.write("document.getElementById(\"T" + CellID + "_" + i.toString() + "\").style.posTop=(LaPos.y); ");
			}
			
			document.write("document.getElementById(\"T" + CellID + "_" + i.toString() + "\").style.position=\"absolute\"; ");
			document.write("document.getElementById(\"T" + CellID + "_" + i.toString() + "\").style.visibility=\"visible\"; ");

		}
		
		if (myStyleSelect != null )
		{
			document.write("document.getElementById(\"" + CellID + "_" + i.toString() + "\").className=\"" + myStyleSelect + "\"; ");
			document.write("document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleSelect + "\"; ");
		}
		document.write("'");

		if (myElement[i][2] != null )
			if (myElement[i][2].length > 0) 
			{
				document.write(" onClick='");
				document.write("GoNavMenu(\"" + myElement[i][10].toString() +"\", \"" + myElement[i][2].toString() + "\", \"" + myElement[i][3].toString() + "\");")
				document.write("'");
			}

		document.write(">");

		
		
		document.write("<TABLE BORDER='0' HEIGHT='2' WIDTH='100%' CELLSPACING='0' CELLPADDING='0'><TR><TD ALIGN='left'><NOBR>");

		// Ouverture du lien [2] s il existe, dans la fenête [3]
		// *****************************************************

		if (myElement[i][2] != null )
		{
			if (myElement[i][2].length > 0) 
			{
				//document.write("<A ID='" + CellID + "_" + i.toString() + "Lnk' HREF='" + myElement[i][2].toString() + "'");
				document.write("<A ID='" + CellID + "_" + i.toString() + "Lnk' HREF='Javascript:GoNavMenu(\"" + myElement[i][10].toString() +"\", \"" + myElement[i][2].toString() + "\", \"" + myElement[i][3].toString() + "\");'");
				if (myStyleNormal != null ) { document.write(" CLASS='" + myStyleNormal + "' onMouseOut='document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleNormal + "\";'"); }
				if (myStyleSelect != null ) { document.write(" onMouseOver='document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleSelect + "\";'"); }
				//if (myElement[i][3] != null ) { if (myElement[i][3].length > 0) { document.write(" TARGET='" + myElement[i][3].toString() + "'"); } }
				document.write(">");
			}
			else
			{
				document.write("<FONT ID='" + CellID + "_" + i.toString() + "Lnk'");
				if (myStyleNormal != null ) { document.write(" CLASS='" + myStyleNormal + "' onMouseOut='document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleNormal + "\";'"); }
				if (myStyleSelect != null ) { document.write(" onMouseOver='document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleSelect + "\";'"); }
				document.write(">");
			}
		}
		else
		{
				document.write("<FONT ID='" + CellID + "_" + i.toString() + "Lnk'");
				if (myStyleNormal != null ) { document.write(" CLASS='" + myStyleNormal + "' onMouseOut='document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleNormal + "\";'"); }
				if (myStyleSelect != null ) { document.write(" onMouseOver='document.getElementById(\"" + CellID + "_" + i.toString() + "Lnk\").className=\"" + myStyleSelect + "\";'"); }
				document.write(">");
		}


		// Affichage de l image [1] s il existe, sinon du texte [0] s il existe
		// ********************************************************************

		if (myElement[i][1] == null ) {
			if (myElement[i][0] != null ) { document.write(myElement[i][0].toString()); }
		}
		else {
			if (myElement[i][1].length == 0 ) {
				if (myElement[i][0] != null ) { document.write(myElement[i][0].toString()); }
			}
			else
				document.write("<IMG SRC='" + myElement[i][1].toString() + "' BORDER='0'>");
		}

		// Fermeture du lien [4] s il existe
		// *********************************
		if (myElement[i][2] != null )
		{
			if (myElement[i][2].length > 0) {
				document.write("</A>");
			}
			else document.write("</FONT>");
		}
		else {
			document.write("</FONT>");
		}

		if (myElement[i][4].length > 0) {
			document.write("</NOBR></TD><TD ALIGN='right'>");
			document.write("<img src='" + LibImagePath + "empty.gif' width='10'><A ID='A" + CellID + "_" + i.toString() + "'><img src='" + LibImagePath + "TopNaviArrow.gif' border='0' align='absmiddle'></A>");	
		}
		document.write("</TD></TR></TABLE>");


		// Fermeture de la cellule
		// ***********************
		
		document.write("</TD>");
		document.write("</tr>");
	}

	// Fermeture du DIV contenant le sous-menu
	// ***************************************
	document.write("</tbody></table></div>");



	// Chargement récursif des autres niveaux de l arborescence
	// ********************************************************
	for (i=0; i<myElement.length; i++) {


		var myStyleNormalB = myStyleNormal;
		var myStyleSelectB = myStyleSelect;
		if (myElement[i][5].length != 0)
			{ myStyleNormalB = myElement[i][5];}
		if (myElement[i][7].length != 0)
			{ myStyleSelectB = myElement[i][7];}
		

		if ((myElement[i][4].length) != 0) {
			TopNaviSub(CellID, CellID + "_" + i.toString(), myElement[i][4], myStyleNormalB, myStyleSelectB, (Zindex+1) );
		}
	}
}




// ************************************************************************
// FONCTIONS TopNaviOpenMenu ET TopNaviCloseMenu
// Gèrent l'ouverture et la fermeture récursives des divers niveaux de menu
// ************************************************************************

function TopNaviOpenMenu(myTabi)
{
	if (myTabi != null)
		if (myTabi.length > 0)
		{
			document.getElementById(myTabi[0]).style.visibility='visible';
			if (myTabi.length > 1) { TopNaviOpenMenu(myTabi[1]); }
		}
}

function TopNaviCloseMenu(myTabi)
{
	if (myTabi != null)
		if (myTabi.length > 0)
		{
			document.getElementById(myTabi[0]).style.visibility='hidden';
			if (myTabi.length > 1) { TopNaviCloseMenu(myTabi[1]); }
		}
}




// ***************************************************************************
// FONCTIONS getAnchorPosition ET AnchorPositionXXXXXXXXXXXX
// Utilisées pour capturer les positions d'ancres et y afficher les sous-menus
// ***************************************************************************

function getAnchorPosition(anchorname) {
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}
	
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

// --- END ---












