// Déclaration des variables //

    // pour gestion des menus //
    var titre;
    var type;type = new Array();
    var level;level = new Array();
    var texte;texte = new Array();
    var status;status = new Array();
    var image;image = new Array();
    var lien;lien = new Array();
    var pere;pere = new Array();
    var ok=0;
    var nb=1;
    var Apere=0;
    var Alevel=1;
    var oldpere=0;
    // La cible par defaut pour les liens //
    var Acible="_top";

    // pour fenêtre d'affichage du résumé //
    var optWinResume="width=450,height=50,left=300,top=200,toolbar=no,directories=no, menubar=no,scrollbars=no,resizable=no,status=no";
   
    var tableauPersonTyp = new Array();
    
    // pour traitement re-routage
    var routage = null;
    var messageAvantRoutage = null;
    var isError	= false;


//********************************************************//
//   Function reRoute()                                   //
//   Permet le reroutage vers un autre URL                //
//   positionné par l'application dans la variable globale //
//   "routage"                                            //
//   Cette méthode est appelée dans Error.xsl en cas      //
//   d'affichage de popup de message                      //
//********************************************************//
function reRoute(){
	if(!isError){
		if (messageAvantRoutage != null){
			alert(messageAvantRoutage);
			messageAvantRoutage = null;
		}
	
		if (routage != null){
			var r = routage;
			routage = null;
			document.location = r;
		}
	}
	isError = false;
}

//********************************************************//
//   Function setPersonTyp                                //
//********************************************************//
function setPersonTyp() {
  var dernierElement = document.formulaire.PersonNum.length;
  for(var i=0;i < dernierElement;i++){
    if( document.formulaire.PersonNum.options.selectedIndex == i){
      document.formulaire.PersonTyp.value = tableauPersonTyp[i];
    }
  }
} 
//********************************************************//
//   Function ajoutPersonTyp                              //
//   (e) personTyp, type d'entreprise                     //
//********************************************************//
function ajoutPersonTyp(personTyp){
  tableauPersonTyp[tableauPersonTyp.length] = personTyp;
}  
//********************************************************//
//   Function OuvrirFenetreResume                         //
//   (e) resume, texte du résumé à afficher dans la popup //
//********************************************************//
function OuvrirFenetreResume(resume) {
    var w = open("","titre",optWinResume); 
    w.document.write("<html><head><title>R&eacute;sum&eacute;</title>");
    w.document.write("<link rel=\"stylesheet\" href=\"/invivo/css/styles.css\" type=\"text/css\">");
    w.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
    w.document.write("</head><body><table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"");
    w.document.write("<tr><td class=\"textecourantgrasvert\">" + resume + "</td></tr>");
    w.document.write("<tr><td> &nbsp; </td></tr>");
    w.document.write("<tr><td align=\"center\"><a href=\"#\" OnClick=\"window.close();\"><img src=\"/invivo/images/fermer.gif\" border=\"0\"/></a></td></tr>");
    w.document.write("</table>");
    w.document.write("</body></html>");
    w.document.close();
}

function titreMenu(newTitre){
    titre = newTitre;
}

function ajouterMenu(Anew,Atype,Atexte,Aimage,Alien,Astatus) {
  if (Anew==1) {
    Apere=0;
    Alevel=1;
  }
  type[nb]=Atype;
  level[nb]=Alevel;
  pere[nb]=Apere;
  status[nb]=Astatus;
  if(Anew ==0 && Astatus == 1){
  	status[Apere] = 1;
  }
  texte[nb]=Atexte;
  image[nb]=Aimage;
  lien[nb]=Alien;
  if (Atype==1) {Apere=nb;}
  nb+=1;if (Atype==1) {Alevel+=1;}
}

function ouvreMenu(num){
 status[num]=1;affMenu();
}

function fermeMenu(num){
 status[num]=0;affMenu();
}

function verifMenu(num){
 if (pere[num]!=0) {
  while (pere[num]!=0) {
   num=pere[num];
   if (status[num]==0) {ok=0;}
  }
 }
}

function affMenu(){
 var chaine = "";
 var saute=0;
 var niveau=1;
 var chainedebut = " ";
 var chainefin = " ";
 
 chaine+="<table width='145' border='0' cellpadding='0' cellspacing='0'>";
 chaine+="  <tr>"; 
 chaine+="      <td><img src='../images/spacer.gif' width='5' height='1'></td>";
 chaine+="      <td><img src='../images/spacer.gif' width='5' height='1'></td>";
 chaine+="      <td><img src='../images/spacer.gif' width='125' height='1'></td>";
 chaine+="      <td><img src='../images/spacer.gif' width='5' height='1'></td>";
 chaine+="      <td><img src='../images/spacer.gif' width='5' height='1'></td>";
 chaine+="  </tr>";
 chaine+="  <tr>"; 
 chaine+="      <td colspan='2'><img src='../images/menu_gauche_coin_haut_gauche.gif' width='10' height='10'></td>";
 chaine+="      <td background='../images/menu_gauche_trait_haut.gif'><img src='../images/spacer.gif'  height='10'></td>";
 chaine+="      <td colspan='2'><img src='../images/menu_gauche_coin_haut_droit.gif' width='10' height='10'></td>";
 chaine+="  </tr>";
 chaine+="  <tr>"; 
 chaine+="      <td background='../images/menu_gauche_trait_gauche.gif'><img src='../images/spacer.gif' width='5'></td>";
 chaine+="      <td colspan='3'>"; 
   
   // affichage du titre //
    chaine+="       <table width='135' cellspacing='0' cellpadding='0'>";
    chaine+="           <tr>";
    chaine+="               <td width='135' valign='top' class='titremenu'>"+titre+"</td>";
    chaine+="           </tr>";
    chaine+="           <tr>";
    chaine+="               <td width='135' colspan='3' valign='top'><img src='../images/spacer.gif' height='5'></td>";
    chaine+="           </tr>";
    chaine+="       </table>";

 chaine+="      </td>";
 chaine+="      <td background='../images/menu_gauche_trait_droit.gif'> <img src='../images/spacer.gif' width='5'></td>";
 chaine+="  </tr>";
  
 for (var i = 1; i < texte.length; i++) {
  ok=1;
  verifMenu(i);
  if (ok==1) {
    
 chaine+="  <tr>"; 
 chaine+="      <td background='../images/menu_gauche_trait_gauche.gif'><img src='../images/spacer.gif' width='5'></td>";
 chaine+="      <td colspan='3'>"; 
    
   if (level[i]==1) {
        // service non vide//
        chaine+="       <table width='135' cellspacing='0' cellpadding='0'>";
        chaine+="           <tr>";
        if (status[i]==0) {        
        	chaine+="           <td width='10' valign='top'><img src='../images/menu_gauche_fleche_verte_off.gif' width='10' height='10' onmouseup='ouvreMenu("+i+")'></td>";
        } else {
            chaine+="           <td width='10' valign='top'><img src='../images/menu_gauche_fleche_verte_on.gif' width='10' height='10' onmouseup='fermeMenu("+i+")'></td>";
        }
        chaine+="               <td width='5'><img src='../images/spacer.gif' width='5'></td>";
        if(type[i] == 1) {
	        if (status[i]==0) {
	        	chaine+="           <td width='120' valign='top' class='serviceactif'><A HREF='javascript:ouvreMenu("+i+")' class='menu'>"+texte[i]+"</A></td>";
        	} else {
	        	chaine+="           <td width='120' valign='top' class='serviceactif'><A HREF='javascript:fermeMenu("+i+")' class='menu'>"+texte[i]+"</A></td>";
        	}
        } else {
        	chaine+="       <td width='120' valign='top' class='serviceactif'><A HREF='"+lien[i]+"' target='"+Acible+"' class='menu'>"+texte[i]+"</A></td>";
        }
        chaine+="           </tr>";
        chaine+="           <tr>";
        chaine+="               <td width='135' colspan='3' valign='top'><img src='../images/spacer.gif' height='5'></td>";
        chaine+="           </tr>";
        chaine+="       </table>";
   }
   else {
   // rubrique //
     chaine+="<table width='135' cellspacing='0' cellpadding='0'>";
     chaine+="  <tr>";
     chaine+="      <td width='10'><img src='../images/spacer.gif' width='10'></td>";
     if (status[i]==0) {
	    chaine+="      <td width='10' valign='top'><img src='../images/puce_vert.gif' width='10' height='8'></td>";
     } else {
     	chaine+="      <td width='10' valign='top'><img src='../images/puce_vert_select.gif' width='10' height='10'></td>";
     }
	     
     chaine+="      <td width='115' valign='top' class='serviceactif'><A HREF='"+lien[i]+"' target='"+Acible+"' class='menu' >"+texte[i]+"</A></td>";
     chaine+="  </tr>";
     chaine+="  <tr>";
     chaine+="      <td width='135' colspan='3' valign='top'><img src='../images/spacer.gif' height='5'></td>";
     chaine+="  </tr>";
     chaine+="</table>";
   
   }
 chaine+="      </td>";
 chaine+="      <td background='../images/menu_gauche_trait_droit.gif'> <img src='../images/spacer.gif' width='5'></td>";
 chaine+="  </tr>";

  }
 }

 chaine+="  <tr>"; 
 chaine+="      <td colspan='2'><img src='../images/menu_gauche_coin_bas_gauche.gif' width='10' height='10'></td>";
 chaine+="      <td background='../images/menu_gauche_trait_bas.gif'> <img src='../images/spacer.gif' height='5'></td>";
 chaine+="      <td colspan='2'> <img src='../images/menu_gauche_coin__bas_droit.gif' width='10' height='10'></td>";
 chaine+="  </tr>";
 chaine+="</table>";
 
 
 if (navigator.appName=="Netscape"){
  document.layers['menu'].document.write(chaine);
  document.layers['menu'].document.close();
 }
 else{
  menu.innerHTML=chaine;
 }
}

//*******************************************************//
//  Ouverture fermeture liste arborescence               //
//*******************************************************//
function OuvrirOuFermer(nomNiveau) {
	var niveau = document.getElementById(nomNiveau);	if(niveau !=null){
	    if (niveau.style.display == "none") {	
	    	niveau.style.display = "";	
	    } else {	
	    	niveau.style.display = "none";	
	    }	}
}

//*******************************************************//
//  Ouverture liste arborescence               //
//*******************************************************//
function OuvrirNiveau(nomNiveau) {
	var niveau = document.getElementById(nomNiveau);	if(niveau !=null){
    	niveau.style.display = "";	}
}
//*******************************************************////  Fermeture liste arborescence               ////*******************************************************//function FermerNiveau(nomNiveau) {	var niveau = document.getElementById(nomNiveau);	if(niveau !=null){    	niveau.style.display = "none";	}}

function hideOrShow(niveau) {
    if (navigator.appName!="Netscape"){
      niveau.style.display = "none";
    } 
}

//********************************************************//

//   Function openNewWindow                               //

//   (e) url, lien vers la page à afficher                //

//********************************************************//

function openNewWindow(url) {

    var option="toolbar=no,directories=no, menubar=no,scrollbars=yes,resizable=yes,status=no";

    var w = window.open(url,"NewWindow", option); 

}


function twAjusteIFrame(sObjet) {
// Code gratuit des Trucsweb.com
//alert(document.getElementById(sObjet).contentWindow.document.body.clientHeight);
var nHauteur = document.getElementById(sObjet).contentWindow.document.body.scrollHeight;
if (nHauteur > 580){
    document.getElementById(sObjet).style.height = nHauteur+20;
} else {
    document.getElementById(sObjet).style.height = 600;
}
}

