// hierarchie.class.js (v1.0)
// Feuille de scripts JavaScript - Rubrique Etat des lieux
// Copyright 1999-2004 Versus Studio

// Scripts de définition des fonctions utilisées dans la rubrique Etat des lieux

// *
// *  Différentes constantes et variables utilisées
// *
// *
// *

var cst_nom_form = 'form_hierarchie' ;

var cst_nom_frm_chapitre = 'frm_chapitre' ;
var cst_nom_frm_niveau1  = 'frm_niveau1'  ;
var cst_nom_frm_niveau2  = 'frm_niveau2'  ;
var cst_nom_frm_niveau3  = 'frm_niveau3'  ;
var cst_nom_frm_niveau4  = 'frm_niveau4'  ;

var cst_nom_div_chapitre = 'divChapitre' ;
var cst_nom_div_niveau1  = 'divNiveau1'  ;
var cst_nom_div_niveau2  = 'divNiveau2'  ;
var cst_nom_div_niveau3  = 'divNiveau3'  ;
var cst_nom_div_niveau4  = 'divNiveau4'  ;

var cst_nom_frm_show_theme_1 = 'frm_theme' ;
var cst_nom_frm_show_theme_2 = '1'
var cst_nom_frm_show_theme   = cst_nom_frm_show_theme_1 +'='+ cst_nom_frm_show_theme_2 ;
var cst_nom_frm_theme        = 'frm_ref_theme' ;

var cst_directory = '/etat/aspects-communs/' ;
var cst_accueil = 'index.htm' ;

var currentHierarchie ;

var useTheme = false ;
var currentTheme ;

var strPage ;

var typeAffichage = 'Hierarchie' ;

// *
// *  Fonction d'actualisation et de controle des différents éléments
// *
// *
// *

function Actualise() {
	var strParamUrl ;
	var ref_theme ;
	// 1 > Récupération de l'URL de la page en cours
	var urlTEMP = unescape(window.location.href) ;
	var indice = urlTEMP.indexOf( cst_directory ) ;
	if( indice == -1 ) {
		// on n'a pas pu trouver dans l'Url le fichier en cours
		//  -> redirection vers la page d'accueil
		if( typeof(cst_accueil) != "undefined" ) window.location.href = cst_accueil ;
		else alert("Redirection impossible vers la page d'accueil") ;
	}
	// Récupération du nom de la page en cours
	strPage = urlTEMP.substring( (indice + cst_directory.length) ) ;
	// Controle s'il n'existe pas de paramètre d'Url effectif
	indice = strPage.indexOf( "?" ) ;
	strParamUrl = '' ;
	if( indice != -1 ) {
		// Récupération de la page et des paramètres d'Url
		strParamUrl = strPage.substring( (indice + 1) ) ;
		strPage = strPage.substring( 0 , indice ) ;
	}
	// 2 > Détermination du type d'affichage
	if( useTheme && (strParamUrl != '') ) {
		indice = strParamUrl.indexOf( cst_nom_frm_show_theme ) ;
		if( indice != -1 ) {
			typeAffichage = 'Theme' ;
		}
	}
	// 3 > Controle des paramètres d'Url pour la récupération de la référence du theme
	if( useTheme && (typeAffichage == 'Theme') ) {
		indice = strParamUrl.indexOf( cst_nom_frm_theme ) ;
		if( indice != -1 ) {
			// Récupération du theme
			var strTheme = strParamUrl.substring( (indice + cst_nom_frm_theme.length + 1 ) ) ;
			indice = strTheme.indexOf( "&" ) ;
			if( indice != -1 ) {
				strTheme.substring( 0 , indice ) ;
				if( strTheme.length > 0  ) {
					ref_theme = parseInt( strTheme , 10 ) ;
					// Controle de la bonne définition du theme
					if( typeof( listeThemes[ ref_theme ] ) != "undefined" ) {
						currentTheme = listeThemes[ ref_theme ] ;
						listeThemes[ref_theme].selected = true ;
					}
				}
			} else {
				if( strTheme.length > 0  ) {
					ref_theme = parseInt( strTheme , 10 ) ;
					// Controle de la bonne définition du theme
					if( typeof( listeThemes[ ref_theme ] ) != "undefined" ) {
						currentTheme = listeThemes[ ref_theme ] ;
						listeThemes[ref_theme].selected = true ;
					}
				}
			}
		}
	}
	// 4 > Mise en place de l'objet hierarchie 
	if( typeAffichage == 'Hierarchie' ) {
		currentHierarchie = new Hierarchie( listeChapitres ) ;
		currentHierarchie.Actualise( strPage ) ;
	}
}


// *
// *  Fonction d'affichage générale
// *
// *
// *

function Affiche() {
	// Affichage de l'entete
	document.writeln('            <table width="508" border="0" cellspacing="0" cellpadding="0">') ;
	document.writeln('              <tr align="right" valign="bottom">') ;
	// Affichage de la zone d'onglet
	if( useTheme ) {
		if( typeAffichage == 'Hierarchie' ) {
			document.writeln('                <td colspan="3" height="21" style="background-image: url(../../images/onglet-fond_02.gif); background-repeat: repeat-x"><img src="../../images/transparent.gif" width="327" height="21" border="0"><img name="imgOnglet_1" border="0" src="../../images/onglet_02_01.gif" width="91" height="21"><a href="themes.htm?'+ cst_nom_frm_show_theme +'" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'imgOnglet_2\',\'\',\'../../images/onglet_02_02_over.gif\',1)"><img name="imgOnglet_2" border="0" src="../../images/onglet_02_02_down.gif" width="90" height="21"></a></td>') ;
		}	else if ( typeAffichage == 'Theme' ) {
			document.writeln('                <td colspan="3" height="21" style="background-image: url(../../images/onglet-fond_02.gif); background-repeat: repeat-x"><img src="../../images/transparent.gif" width="327" height="21" border="0"><a href="'+ strPage +'" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'imgOnglet_1\',\'\',\'../../images/onglet_02_01_over.gif\',1)"><img name="imgOnglet_1" border="0" src="../../images/onglet_02_01_down.gif" width="91" height="21"></a><img name="imgOnglet_2" border="0" src="../../images/onglet_02_02.gif" width="90" height="21"></td>') ;
		}	else {
			document.writeln('                <td colspan="3" height="21" style="background-image: url(../../images/onglet-fond_02.gif); background-repeat: repeat-x"><img src="../../images/transparent.gif" width="327" height="21" border="0"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'imgOnglet_1\',\'\',\'../../images/onglet_02_01_over.gif\',1)"><img name="imgOnglet_1" border="0" src="../../images/onglet_02_01_down.gif" width="91" height="21"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'imgOnglet_2\',\'\',\'../../images/onglet_02_02_over.gif\',1)"><img name="imgOnglet_2" border="0" src="../../images/onglet_02_02_down.gif" width="90" height="21"></a></td>') ;
		}
	} else {
		document.writeln('                <td colspan="3" height="21" style="background-image: url(../../images/onglet-fond_02.gif); background-repeat: repeat-x"><img src="../../images/transparent.gif" width="417" height="21" border="0"><img name="imgOnglet_1" border="0" src="../../images/onglet_02_01.gif" width="91" height="21"></td>') ;
	}
	// Affichage intérmédiaire 
	document.writeln('              </tr>') ;
	document.writeln('              <tr align="left" valign="top">') ;
	document.writeln('                <td width="1" bgcolor="#000000"><img src="../../images/transparent.gif" width="1" height="10" border="0"></td>') ;
	document.writeln('                <td width="506" bgcolor="#E6FAF4" align="center">') ;
	// Affichage du contenu
	if( useTheme ) {
		if( typeAffichage == 'Hierarchie' ) {
			AfficheHierarchie() ;
		}	else if ( typeAffichage == 'Theme' ) {
			AfficheTheme() ;
		}	else {
			document.writeln('<p> Type d\'affichage non reconnu.</p>') ;
		}
	} else {
		AfficheHierarchie() ;
	}
	// Affichage du pied
	document.writeln('                </td>') ;
	document.writeln('                <td width="1" bgcolor="#000000"><img src="../../images/transparent.gif" width="1" height="10" border="0"></td>') ;
	document.writeln('              </tr>') ;
	document.writeln('              <tr align="left" valign="top">') ;
	document.writeln('                <td width="1" height="1" bgcolor="#000000"><img src="../../images/transparent.gif" width="1" height="1" border="0" alt=""></td>') ;
	document.writeln('                <td width="506" height="1" bgcolor="#000000"><img src="../../images/transparent.gif" width="506" height="1" border="0" alt=""></td>') ;
	document.writeln('                <td width="1" height="1" bgcolor="#000000"><img src="../../images/transparent.gif" width="1" height="1" border="0" alt=""></td>') ;
	document.writeln('              </tr>') ;
	document.writeln('              <tr align="left" valign="top">') ;
	document.writeln('                <td width="1" height="15""><img src="../../images/transparent.gif" width="1" height="15" border="0" alt=""></td>') ;
	document.writeln('                <td width="506" height="15"><img src="../../images/transparent.gif" width="506" height="15" border="0" alt=""></td>') ;
	document.writeln('                <td width="1" height="15"><img src="../../images/transparent.gif" width="1" height="15" border="0" alt=""></td>') ;
	document.writeln('              </tr>') ;
	document.writeln('            </table>') ;
	
	// Affichage de la pagination
	if( typeAffichage == 'Hierarchie' ) {
			AfficheNavigationPage('Haut') ;
	}
}

function AffichePiedPage() {
	// Affichage de la pagination
	if( typeAffichage == 'Hierarchie' ) {
			AfficheNavigationPage('Bas') ;
	}
}

// *
// *  Fonction d'affichage de la zone de navigation thématique
// *
// *
// *

function AfficheTheme() {
	document.writeln('<form name="'+ cst_nom_form +'" method="get" action="themes.htm" style="margin: 0px">') ;
	document.writeln('									<input type="hidden" name="'+ cst_nom_frm_show_theme_1 +'" value="'+ cst_nom_frm_show_theme_2 +'">') ;
	document.writeln('									<table width="100%" border="0" cellspacing="2" cellpadding="0" id="ZoneContenu">') ;
	document.writeln('                    <tr align="left" valign="top">') ;
	document.writeln('                      <td width="70" height="2"><img src="../../images/transparent.gif" width="1" height="2" border="0"></td>') ;
	document.writeln('                      <td height="2"><img src="../../images/transparent.gif" width="1" height="2" border="0"></td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('										<tr align="left" valign="middle">') ;
	document.writeln('    									<td width="70" height="20"><b>Th&egrave;me</b></td>') ;
	document.writeln('								    	<td height="20">') ;
	document.writeln('												<select name="'+ cst_nom_frm_theme +'">') ;
	var i ;
	for( i=0 ; i<listeThemes.length ; i++ ) {
		listeThemes[i].AfficheTheme() ;
	}
	document.writeln('</select>') ;
	document.writeln('								    	</td>') ;
	document.writeln('								  	</tr>') ;
	document.writeln('                    <tr align="right" valign="bottom">') ;
	document.writeln('    									<td width="70" height="20">&nbsp;</td>') ;
	document.writeln('								    	<td height="20"><a href="javascript: SubmitForm(\''+ cst_nom_form +'\')"><img src="../../images/ico-aide_01.gif" width="17" height="11" align="absmiddle" border="0">Afficher les pages du th&egrave;me s&eacute;lectionn&eacute;</a></td>') ;
	document.writeln('								  	</tr>') ;
	document.writeln('									</table>') ;
	document.writeln('								</form>') ;
}

// *
// *  Fonction d'affichage de la liste des pages du thème en cour 
// *
// *
// *

function AffichePageTheme() {
	if( typeof(currentTheme) == 'undefined' ) { 
		document.write('<p>Aucun th&egrave;me s&eacute;lectionn&eacute; actuellement.</p>') ;
	} else {
		currentTheme.AffichePageTheme( cst_nom_frm_show_theme, cst_nom_frm_theme ) ;
	}
}


// *
// *  Fonction d'affichage de la zone de navigation hiérarchique
// *
// *
// *

function AfficheHierarchie() {
	document.writeln('<form name="'+ cst_nom_form +'" method="get" action="" style="margin: 0px">') ;
	document.writeln('                  <table width="100%" border="0" cellspacing="2" cellpadding="0" id="ZoneContenu">') ;
	document.writeln('                    <tr align="left" valign="top">') ;
	document.writeln('                      <td width="70" height="2"><img src="../../images/transparent.gif" width="1" height="2" border="0"></td>') ;
	document.writeln('                      <td height="2"><img src="../../images/transparent.gif" width="1" height="2" border="0"></td>') ;
	document.writeln('                      <td width="70" height="2"><img src="../../images/transparent.gif" width="1" height="2" border="0"></td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('                    <tr align="left" valign="middle">') ;
	document.writeln('                      <td width="70" height="20"><b>Chapitre</b></td>') ;
	document.writeln('                      <td height="20">') ;
	AfficheChapitre() ; 
	document.writeln('                      </td>') ;
	document.writeln('                      <td width="70" height="20">') ;
	AffichePdfChapitre() ;
	document.writeln('                      </td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('                    <tr align="left" valign="middle">') ;
	document.writeln('                      <td width="70" height="20"><b>Niveau 1</b></td>') ;
	document.writeln('                      <td height="20">') ;
	AfficheNiveau1() ; 
	document.writeln('                      </td>') ;
	document.writeln('                      <td width="70" height="20">&nbsp;</td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('                    <tr align="left" valign="middle">') ;
	document.writeln('                      <td width="70" height="20"><b>Niveau 2</b></td>') ;
	document.writeln('                      <td height="20">') ;
	AfficheNiveau2() ; 
	document.writeln('                      </td>') ;
	document.writeln('                      <td width="70" height="20">&nbsp;</td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('                    <tr align="left" valign="middle">') ;
	document.writeln('                      <td width="70" height="20"><b>Niveau 3</b></td>') ;
	document.writeln('                      <td height="20">') ;
	AfficheNiveau3() ; 	
	document.writeln('                      </td>') ;
	document.writeln('                      <td width="70" height="20">&nbsp;</td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('                    <tr align="left" valign="middle">') ;
	document.writeln('                      <td width="70" height="20"><b>Niveau 4</b></td>') ;
	document.writeln('                      <td height="20">') ;
	AfficheNiveau4() ; 	
	document.writeln('                      </td>') ;
	document.writeln('                      <td width="70" height="20">&nbsp;</td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('                    <tr align="right" valign="bottom">') ;
	document.writeln('                      <td colspan="3" height="20"><a href="javascript:void(0);" onClick="var popSommaire = window.open(\'pop-sommaire.htm#'+ AfficheNameAnchor( strPage ) +'\',\'winBOPopup\',\'scrollbars=yes,width=450,height=550\'); popSommaire.focus() ;" title="&gt; Aspects communs : Sommaire"><img src="../../images/ico-aide_01.gif" width="17" height="11" align="absmiddle" border="0">Afficher le sommaire</a></td>') ;
	document.writeln('                    </tr>') ;
	document.writeln('                  </table>') ;
	document.writeln('								</form>') ;
}

// *
// *  Fonction d'affichage de la liste déroulante des chapitres
// *
// *
// *

function AfficheChapitre() {
	if( typeof(currentHierarchie) == 'undefined' ) { 
		document.write('&nbsp;') ;
	} else {
		currentHierarchie.AfficheChapitre() ;
	}
}

// *
// *  Fonction d'affichage de la liste déroulante des chapitres
// *
// *
// *

function AffichePdfChapitre() {
	if( typeof(currentHierarchie) == 'undefined' ) { 
		document.write('&nbsp;') ;
	} else {
		currentHierarchie.AffichePdfChapitre() ;
	}
}


// *
// *  Fonction d'affichage de la liste déroulante des niveaux 1
// *
// *
// *

function AfficheNiveau1() {
	if( typeof(currentHierarchie) == 'undefined' ) { 
		document.write('&nbsp;') ;
	} else {
		currentHierarchie.AfficheNiveau1() ;
	}
}

// *
// *  Fonction d'affichage de la liste déroulante des niveaux 2
// *
// *
// *

function AfficheNiveau2() {
	if( typeof(currentHierarchie) == 'undefined' ) { 
		document.write('&nbsp;') ;
	} else {
		currentHierarchie.AfficheNiveau2() ;
	}
}

// *
// *  Fonction d'affichage de la liste déroulante des niveaux 3
// *
// *
// *

function AfficheNiveau3() {
	if( typeof(currentHierarchie) == 'undefined' ) { 
		document.write('&nbsp;') ;
	} else {
		currentHierarchie.AfficheNiveau3() ;
	}
}

// *
// *  Fonction d'affichage de la liste déroulante des niveaux 4
// *
// *
// *

function AfficheNiveau4() {
	if( typeof(currentHierarchie) == 'undefined' ) { 
		document.write('&nbsp;') ;
	} else {
		currentHierarchie.AfficheNiveau4() ;
	}
}

// *
// *  Fonction d'affichage de la navigation entre les pages
// *
// *
// *

function AfficheNavigationPage( strPosition ) {
	if( typeof(currentHierarchie) != 'undefined' ) { 
		currentHierarchie.AfficheNavigationPage( strPosition ) ;
	}
}

// *
// *  Fonction de changement de chapitre
// *
// *
// *

function ChangementChapitre() {
	if( typeof(currentHierarchie) != 'undefined' ) { 
		currentHierarchie.ChangementChapitre() ;
	}
}

// *
// *  Fonction de changement du niveau 1
// *
// *
// *

function ChangementNiveau1() {
	if( typeof(currentHierarchie) != 'undefined' ) { 
		currentHierarchie.ChangementNiveau1() ;
	}
}

// *
// *  Fonction de changement du niveau 2
// *
// *
// *

function ChangementNiveau2() {
	if( typeof(currentHierarchie) != 'undefined' ) { 
		currentHierarchie.ChangementNiveau2() ;
	}
}

// *
// *  Fonction de changement du niveau 3
// *
// *
// *

function ChangementNiveau3() {
	if( typeof(currentHierarchie) != 'undefined' ) { 
		currentHierarchie.ChangementNiveau3() ;
	}
}

// *
// *  Fonction de changement du niveau 4
// *
// *
// *

function ChangementNiveau4() {
	if( typeof(currentHierarchie) != 'undefined' ) { 
		currentHierarchie.ChangementNiveau4() ;
	}
}

// *
// * Fonction utile : affichage en fonction d'une page de l'ancre nommée
// *

function AfficheNameAnchor( strPage_P ) {
	var indice = strPage_P.indexOf( '.' ) ;
	if( indice == -1 ) {
		return strPage_P ;
	} else {
		return ( strPage_P.substring( 0, (indice-2) ) ) ;
	}
}

