// COPYRIGHT Arnaud Vial - ADN 2005 - LYON
// JavaScript Document
/**
* Script permettant de regenrer le menu 
* de l'index à apartir de la page body
*
* ce .js est à mettre dans les pages body
*/	

// on recupere l'uri en cours 
		var body_uri= self.location.href.toString();
		var structure_uri = new Array();
		structure_uri = body_uri.split("/");
		var len = structure_uri.length;
		/*
		* On recherche si le menu corespondant à la page est ouvert
		* Si oui on vérifie le sousmenu
		* Si non on re-intialise le menu pour le re-ouvrir corectement
		*/
		var id_menu = structure_uri[len-3].substring(0,1)+structure_uri[len-2].substring(0,2);
        var current_page = structure_uri[len-1];
		var tmenu = "menu_"+id_menu; 
		var is_menu_open = eval("window.top.frames['index']."+tmenu);
		var pos_smenu = getPos(id_menu,structure_uri[len-2]+"/"+current_page) ; 
		
				   if (!is_menu_open){ 		
					// ce n'est pas le bon menu
					init();
					// on ouvre le bon
					window.top.frames['index'].gest_menu(id_menu);
					// on positionne la couleur du menu
					var obj1 = window.top.frames['index'].document.getElementById(id_menu+"__1");
					 if (obj1!=null){
					  obj1.style.color='#0F4781';
					 }
					// et on positionne la bonne couleur du sous menu
					var obj = window.top.frames['index'].document.getElementById("href_"+id_menu+"_"+pos_smenu);
							if (obj!= null){
							obj.style.color='#0F4781';
							}
					}else{
					// c'est le bon menu
					// on verifie que le bon sous menu est coloré
					// et on ferme tous les menu sauf celui qui nous interesse					
					      init(id_menu);
						  // on positionne la couleur du menu
							var obj1 = window.top.frames['index'].document.getElementById(id_menu+"__1");
							 if (obj1!=null){
							  obj1.style.color='#0F4781';
							 }
						  
							if (pos_smenu!=-1){
							// on recherche la pos de cui allumé
							 var red_pos = getRedPos(id_menu);
							 if(red_pos!=-1){
							 var obj = window.top.frames['index'].document.getElementById("href_"+id_menu+"_"+red_pos);
							  obj.style.color='#333333';
							 }
							      
							var obj = window.top.frames['index'].document.getElementById("href_"+id_menu+"_"+pos_smenu);
							if (obj!= null){
								if (obj.style.color!='#0F4781')
							  	obj.style.color='#0F4781';
							 }
							}
					}
//_____________________________Recuperation de la position ds le menu courant______________________________

function getPos(current_menu,current_p){
var current_table = new Array();
var pos=-1;
current_table = eval("window.top.frames['index'].tab_"+current_menu+"_link");
if (current_table!=null){
 for (t=0;t<current_table.length;t++){
   var pp = current_table[t].toLowerCase().indexOf(current_p);
   if (pp!=-1){
    pos = t;
	break;
   }// f if
 }
 }// f for
return pos;
}		

function getRedPos(current_menu){
var pos=-1;
current_table = eval("window.top.frames['index'].tab_"+current_menu+"_link");
 for (t=0;t<current_table.length;t++){
   var obj = window.top.frames['index'].document.getElementById("href_"+id_menu+"_"+t);
   if (obj!=null){
	if (obj.style.color=='#0F4781'){
	pos=t;
	break;
	}
   }
 }// f for
return pos;

}



		
//______________________________ Initialisation du menu de l'index_________________________________
// on peut lui passer l id d'un menu a ne pas fermer !!
function init(){
var menu_to_keep="";
var args = init.arguments;
if (args.length>0)
menu_to_keep="menu_"+args[0];

// recuperation des objets TBODY de l'index
var t_body = window.top.frames['index'].document.getElementsByTagName("TBODY");
      for (k=0;k<t_body.length;k++){
        if((t_body[k].id!=null) && (t_body[k].id!=menu_to_keep)){
		
	       if (t_body[k].id.length>0){
		    var pmenu=t_body[k].id.indexOf("menu_");
			  if(pmenu!=-1){
			   // c'est un id qui nous concerne
			   // on verifie si le menu est ouvert
			    var is_menu_open = eval("window.top.frames['index']."+t_body[k].id);
				if (is_menu_open){
				 // on eteint le titre du menu 
				   window.top.frames['index'].document.getElementById((t_body[k].id).substring(pmenu+5)+"__1").style.color="#333333";
				 // on remet la fleche dans le bon sens 
				   window.top.frames['index'].document.getElementById((t_body[k].id).substring(pmenu+5)+"_img").src="../images/fleche_right.gif";
				 // et on ferme le menu ouvert  
				   window.top.frames['index'].gest_menu((t_body[k].id).substring(pmenu+5));
				 }
			 }
		  
		  }
	    }
      }
	  
}// fin init()
//_________________________________________________________________________________________________________