
var niv1_courant = 0;
var niv2_courant = 0;

var num_partie = 1;
var num_chap = 1;
var num_sect = "";
var fileSommaireXML = "";

//SOMMAIRE CHAPITRES
function showHideChapitres(id) {
var idPicto = "picto_" + id;
var idsub = "";
	
	if(niv1_courant != 0 && niv1_courant != id){ 
		idPictoBis = "picto_" + niv1_courant;
		document.getElementById(niv1_courant).style.display = 'none'; 
		document.getElementById(idPictoBis).src="../Images/imagesv2/droit-travail/picto_plus.gif";
	}
	if(niv2_courant != 0 && niv2_courant != id){ 
		idPictoBis = "picto_sub_" + niv2_courant;
		idsub = "sub" + niv2_courant.toString() ; document.getElementById(idsub).style.display = 'none'; 		
		document.getElementById(idPictoBis).src="../Images/imagesv2/droit-travail/picto_plus.gif";
	}
	niv1_courant = id;
	niv2_courant = 0;
	
	if(document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display='block';
		document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_moins.gif";
		//document.getElementById(idPicto).alt = "Masquer les chapitres";
	} else { 
		document.getElementById(id).style.display='none';
		document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_plus.gif";	
		//document.getElementById(idPicto).alt = "Afficher les chapitres";
	}
}
//SOMMAIRE SOUS CHAPITRES
function showHideSousChapitres(id) {
var idPicto = "picto_sub_" + id;
var id2 = "sub" + id;
var idsub = "";
	
	//si il y a un bloc 3e niveau
	if(document.getElementById("sub"+id)) {	
		if(niv2_courant != 0 && niv2_courant != id) { 
			idsub = "sub" + niv2_courant.toString(); document.getElementById(idsub).style.display = 'none'; 
			idPictoBis = "picto_sub_" + niv2_courant;
			document.getElementById(idPictoBis).src="../Images/imagesv2/droit-travail/picto_plus.gif";
		}
		niv2_courant = id;
		
		if(document.getElementById(id2).style.display == 'none') {
			document.getElementById(id2).style.display='block';
			document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_moins.gif";	
			//document.getElementById(idPicto).alt = "Replier";
		} else {
			document.getElementById(id2).style.display='none';
			document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_plus.gif";		
			//document.getElementById(idPicto).alt = "Afficher";
		}			
	}
}
//SPECIAL MC = 4 niveaux
function showHideSousChapitres2(id) {
var idPicto = "picto_sub_" + id;
var id3 = "sub" + id;
		
		if(document.getElementById(id3).style.display == 'none') {
			document.getElementById(id3).style.display='block';
			document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_moins.gif";	
		} else {
			document.getElementById(id3).style.display='none';
			document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_plus.gif";				
		}
}

/* SOMMAIRE */
function affiche_sommaire(mode) {

	document.getElementById('cont_sommaire').style.display = 'block';
	document.getElementById('cont_index').style.display = 'none';
	document.getElementById('cont_auteurs').style.display = 'none';

	//onglets avec index
	if(mode == 'mixte') document.getElementById('sommaire_onglets').src = '../Images/imagesv2/droit-travail/sommaire_onglets_som.jpg';		
	else document.getElementById('sommaire_onglets').src = '../Images/imagesv2/droit-travail/sommaire_onglet_on.jpg';
	
	if(document.getElementById('sommaire_onglet_auteurs')) 
		document.getElementById('sommaire_onglet_auteurs').src = '../Images/imagesv2/droit-travail/sommaire_fin_droite_auteurs_off.jpg';
	
}

/* SOMMAIRE FPB */
function affiche_sommaire_FPB(mode) {

	//onglets avec index
	if(mode == '1') {
		document.getElementById('sommaire_onglets_act').src = '../Images/imagesv2/droit-travail/sommaire_onglets_act.jpg';		
		document.getElementById('cont_sommaire').style.display = 'block';
		document.getElementById('cont_FPB_act').style.display = 'none';
	}
	else { 
		document.getElementById('sommaire_onglets_act').src = '../Images/imagesv2/droit-travail/sommaire_onglets_act_on.jpg';		
		document.getElementById('cont_sommaire').style.display = 'none';
		document.getElementById('cont_FPB_act').style.display = 'block';		
	}
}

/* SOMMAIRE SM ACTUS */
function affiche_sommaire_SM(mode) {

	//onglets avec index
	if(mode == '1') {
		document.getElementById('sommaire_onglets_actus').src = '../Images/imagesv2/droit-travail/sommaire_onglets_actus.jpg';		
		document.getElementById('cont_sommaire').style.display = 'block';
		document.getElementById('cont_SM_actus').style.display = 'none';
	}
	else { 
		document.getElementById('sommaire_onglets_actus').src = '../Images/imagesv2/droit-travail/sommaire_onglets_actus_on.jpg';		
		document.getElementById('cont_sommaire').style.display = 'none';
		document.getElementById('cont_SM_actus').style.display = 'block';		
	}
}

/* SOMMAIRE FICHES WEB sommaire+index+auteurs */
function affiche_sommaire_fichesweb(mode) {

	//onglets avec index
	if(mode == '1') {
		document.getElementById('cont_sommaire').style.display = 'block';
		document.getElementById('cont_modeles').style.display = 'none';
		document.getElementById('cont_auteurs').style.display = 'none';
		document.getElementById('sommaire_onglets_fichesweb').src = '../Images/imagesv2/droit-travail/sommaire_onglets_fichesweb_1.jpg';
		document.getElementById('sommaire_onglet_auteurs').src = '../Images/imagesv2/droit-travail/sommaire_fin_droite_auteurs_off.jpg';
	}
	if(mode == '2') {
		document.getElementById('cont_sommaire').style.display = 'none';
		document.getElementById('cont_modeles').style.display = 'block';
		document.getElementById('cont_auteurs').style.display = 'none';
		document.getElementById('sommaire_onglets_fichesweb').src = '../Images/imagesv2/droit-travail/sommaire_onglets_fichesweb_2.jpg';
		document.getElementById('sommaire_onglet_auteurs').src = '../Images/imagesv2/droit-travail/sommaire_fin_droite_auteurs_off.jpg';
	}
}
function affiche_auteurs_fichesweb() {

	document.getElementById('cont_sommaire').style.display = 'none';
	document.getElementById('cont_modeles').style.display = 'none';
	document.getElementById('cont_auteurs').style.display = 'block';

	document.getElementById('sommaire_onglets_fichesweb').src = '../Images/imagesv2/droit-travail/sommaire_onglets_fichesweb_0.jpg';
	document.getElementById('sommaire_onglet_auteurs').src = '../Images/imagesv2/droit-travail/sommaire_fin_droite_auteurs_on.jpg';
}
/* --------------------------------------------------- */

function affiche_index() {
	document.getElementById('cont_index').style.display = 'block';
	document.getElementById('cont_sommaire').style.display = 'none';
	document.getElementById('cont_auteurs').style.display = 'none';
	document.getElementById('sommaire_onglets').src = '../Images/imagesv2/droit-travail/sommaire_onglets_ind.jpg';
	document.getElementById('sommaire_onglet_auteurs').src = '../Images/imagesv2/droit-travail/sommaire_fin_droite_auteurs_off.jpg';
}

function affiche_auteurs(mode) {

	document.getElementById('cont_auteurs').style.display = 'block';
	document.getElementById('cont_sommaire').style.display = 'none';
	document.getElementById('cont_index').style.display = 'none';

	document.getElementById('sommaire_onglet_auteurs').src = '../Images/imagesv2/droit-travail/sommaire_fin_droite_auteurs_on.jpg';

	//onglets avec index
	if(mode == 'mixte') document.getElementById('sommaire_onglets').src = '../Images/imagesv2/droit-travail/sommaire_onglets_off.jpg';
	else document.getElementById('sommaire_onglets').src = '../Images/imagesv2/droit-travail/sommaire_onglet_off.jpg';		
	
}

// GST
function affiche_sommaire_gst(mode1, mode2, mode3) {

	document.getElementById('cont_sommaire').style.display = mode1;
	document.getElementById('cont_gst_2').style.display = mode2;
	document.getElementById('cont_gst_3').style.display = mode3;
	document.getElementById('cont_auteurs').style.display = 'none';

	if(mode1 == 'block') document.getElementById('sommaire_onglets_gst').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_1.jpg';
	if(mode2 == 'block') document.getElementById('sommaire_onglets_gst').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_2.jpg';
	if(mode3 == 'block') document.getElementById('sommaire_onglets_gst').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_3.jpg';
			
}
function affiche_auteurs_gst() {

	document.getElementById('cont_sommaire').style.display = 'none';
	document.getElementById('cont_gst_2').style.display = 'none';
	document.getElementById('cont_gst_3').style.display = 'none';
	document.getElementById('cont_auteurs').style.display = 'block';

	document.getElementById('sommaire_onglets_gst').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_0.jpg';
}

// TSE
function affiche_sommaire_tse(mode1, mode2, mode3) {

	document.getElementById('cont_sommaire').style.display = mode1;
	document.getElementById('cont_tse_2').style.display = mode2;
	document.getElementById('cont_tse_3').style.display = mode3;
	document.getElementById('cont_auteurs').style.display = 'none';

	if(mode1 == 'block') document.getElementById('sommaire_onglets_tse').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_1.jpg';
	if(mode2 == 'block') document.getElementById('sommaire_onglets_tse').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_2.jpg';
	if(mode3 == 'block') document.getElementById('sommaire_onglets_tse').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_3.jpg';
			
}
function affiche_auteurs_tse() {

	document.getElementById('cont_sommaire').style.display = 'none';
	document.getElementById('cont_tse_2').style.display = 'none';
	document.getElementById('cont_tse_3').style.display = 'none';
	document.getElementById('cont_auteurs').style.display = 'block';

	document.getElementById('sommaire_onglets_tse').src = '../Images/imagesv2/droit-travail/sommaire_onglets_gst_0.jpg';
}

/* SOMMAIRE CCN */
function showNiv3Ccn(id, niv) {
var idPicto = "picto_" + niv + "_" + id;
var idNiv = niv + "_" + id;
	
	if(document.getElementById(idNiv).style.display == 'none') {
		document.getElementById(idNiv).style.display='block';
		document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_moins.gif";	
	} else {
		document.getElementById(idNiv).style.display='none';
		document.getElementById(idPicto).src="../Images/imagesv2/droit-travail/picto_plus.gif";				
	}
			
}

/* index TSE */
function load_contenu(p) {
	window.parent.location.href=p;
}

function manageBlock(b) {
	
	if(document.getElementById('indsub'+b).style.display == 'none') {
		document.getElementById('indsub'+b).style.display='block';	
		document.getElementById('picto'+b).src = "../Images/imagesv2/droit-travail/picto_moins.gif";
	}
	else {
		document.getElementById('indsub'+b).style.display='none';	
		document.getElementById('picto'+b).src = "../Images/imagesv2/droit-travail/picto_plus.gif";
	}
}

// fonctions du sommaire V2 dans l'ouvrage
var ouvert = false;

function _initSommaire(url) {	
var path_btn_fermer = "../Images/imagesv2/droit-travail/btn_fermer_sommaire.gif";
var path_btn_ouvrir = "../Images/imagesv2/droit-travail/btn_ouvrir_sommaire.gif";

	if(!ouvert) {		
		var ifr = document.getElementById("sommaireContenu");
		ifr.src = url;	
		document.getElementById("btn_sommaire_iframe").src = path_btn_fermer;
		ouvert = true;
	}
	else {
		ouvert = false;
		document.getElementById("btn_sommaire_iframe").src = path_btn_ouvrir;
	}
}

//P5CA1S2
function initCombos() {
	var codeSpace = urlvar['codeSpace'];
	var tmpChap = urlvar['chapitre'];
	
	switch(codeSpace) {
		//P1CAS2
		case "BP0":		
		num_chap = (tmpChap.indexOf('S') != -1) ? tmpChap.substring(tmpChap.indexOf('C')+1, tmpChap.indexOf('S')):tmpChap.substring(tmpChap.indexOf('C')+1);
		num_sect = tmpChap.substring(tmpChap.indexOf('S')+1);
		//alert(num_chap);
		//alert(num_sect);
		break;	
	}
	
	num_partie = urlvar['pageNumber'];	
	afficheSommaireAjax();
}

function updateComboSommairePartie(f, val) {
	num_partie = val;
	num_chap = "0";
	num_sect = "0";
	afficheSommaireAjax();
}

function updateComboSommaireChap(val, f) {
	num_partie = f.parties.value;
	num_chap = val;
	num_sect = "0";
	codeSpace = urlvar['codeSpace'];
	afficheSommaireAjax();
}

function getLettre(num) {
	var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return(alpha.substr(num-1, 1));
}
function getNum(lettre) {
	var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return(alpha.indexOf(lettre)+1);
}

function changeURL(f) {	
	var url = document.location.href;
	var urlFinale = url.substring(0, url.indexOf('idSGML'));
	
	var codeSpace = urlvar['codeSpace'];
	var codeCategory = urlvar['codeCategory'];
	var idSGML = urlvar['idSGML'];
	var pageNumber = f.parties.value;
	var chapitreNumber = f.chapitres.value;
	var sectionStr = "0";
	var chapitre = "";
	//si il y a des sections
	if(f.sections) sectionStr = f.sections.value;

	switch(codeSpace) {
		//P1CAS2
		case "BP0":		
		sectionNumber = sectionStr.substring(sectionStr.indexOf('F'), sectionStr.length);
		chapitre = "P" + pageNumber + "C" + chapitreNumber + "S" + sectionNumber;
		break;	
	}
	
	urlFinale += "idSGML=" + idSGML + "&codeCategory=" + codeCategory + "&codeSpace=" + codeSpace + "&chapitre=" + chapitre + "&pageNumber=" + pageNumber;
	document.location = urlFinale;		
}


/* OLD FUNCTIONS  */
var nodeSommaire = "";
var ht = 0;
var rd = 0;
var hauteur = 0;

function growSommaire() {

	hauteur += 90;
	nodeSommaire.style.height = hauteur + "px";				
		
	if(hauteur == 540) {
		clearInterval(ht);		
	}
}
function reduceSommaire() {

	hauteur -= 90;
	nodeSommaire.style.height = hauteur + "px";					
	
	if(hauteur == 0) {
		clearInterval(red);
		document.getElementById("sommaireOuvrage").style.display = 'none';
	}
}
function initSommaire(url) {	
	
var path_btn_fermer = "../Images/imagesv2/droit-travail/btn_fermer_sommaire.gif";
var path_btn_ouvrir = "../Images/imagesv2/droit-travail/btn_ouvrir_sommaire.gif";


	if(!ouvert) {
		document.getElementById("btn_sommaire_iframe").src = path_btn_fermer;
		var ifr = document.getElementById("sommaireContenu");
		nodeSommaire = document.getElementById("sommaireOuvrage");
		document.getElementById("sommaireOuvrage").style.display = 'block';		
		ifr.src = url;	
		
		ht = setInterval("growSommaire()", 10);
		ouvert = true;
	}
	else { 
		hideSommaire();
		document.getElementById("btn_sommaire_iframe").src = path_btn_ouvrir;
	}
}
function hideSommaire() {
	red = setInterval("reduceSommaire()", 10);	
	ouvert = false;
}

/* SOMMAIRE TISSOT */
function showSource(id) {
	if(document.getElementById("source_"+id).style.display == 'none') document.getElementById("source_"+id).style.display = 'block';
	//document.getElementById("img"+id).src = "../Images/dot.gif";
	document.getElementById("source_closed_"+id).style.display = 'none';
}
function closeSource(id) {
	if(document.getElementById("source_"+id).style.display == 'block') document.getElementById("source_"+id).style.display = 'none';	
	//document.getElementById("img"+id).src = "../Images/imagesv2/images-agr/picto_sources.gif";
	document.getElementById("source_closed_"+id).style.display = 'block';
}

/* ------------- fonctions sommaires ------------------------ */
function toggleConvention(idTbl, idImg) {
	
	var etat = document.getElementById(idTbl).style.display;
	var srcMoins = "../Images/imagesv2/droit-travail/picto_moins.gif";
	var srcPlus = "../Images/imagesv2/droit-travail/picto_plus.gif";

	if(etat == 'none'){
		document.getElementById(idTbl).style.display = 'block';
		if(idImg != '') document.getElementById(idImg).src = srcMoins; 
	}
	else { 
		document.getElementById(idTbl).style.display = 'none';
		if(idImg != '') document.getElementById(idImg).src = srcPlus; 
	}
}

/* index CCN OLD ??? */ 
function affiche_sommaire_ccn() {

	document.getElementById('cont_sommaire').style.display = 'block';
	document.getElementById('cont_sommaire_tissot').style.display = 'none';

	//onglets avec index
	document.getElementById('sommaire_onglets_ccn').src = '../Images/imagesv2/droit-travail/onglets_sommaires_CCN_som.jpg';		
}
function affiche_sommaire_tissot_ccn() {

	document.getElementById('cont_sommaire').style.display = 'none';
	document.getElementById('cont_sommaire_tissot').style.display = 'block';

	//onglets avec index
	document.getElementById('sommaire_onglets_ccn').src = '../Images/imagesv2/droit-travail/onglets_sommaires_CCN_tissot.jpg';	
}
//--------------


//affiche l'onglet sommaire thématique
function affiche_sommaire_thematique() {

	document.getElementById('cont_sommaire_thematique').style.display = 'block';
	document.getElementById('cont_sommaire_off').style.display = 'none';

	//onglets avec index
	document.getElementById('sommaire_onglets_thematique').src = '../Images/imagesv2/convention-collective/onglets_sommaire_thematique.jpg';		
}
//affiche l'onglet sommaire thématique
function affiche_sommaire_officiel() {

	document.getElementById('cont_sommaire_thematique').style.display = 'none';
	document.getElementById('cont_sommaire_off').style.display = 'block';

	//onglets avec index
	document.getElementById('sommaire_onglets_thematique').src = '../Images/imagesv2/convention-collective/onglets_sommaire_officiel.jpg';		
}

//affiche l'onglet sommaire thématique
function toggleSommaireArticlesMC(id) {
var idImg = "img_" + id;

	if(document.getElementById(id).style.display == 'none') { 
		document.getElementById(id).style.display = 'block';
		document.getElementById(idImg).src = '../Images/imagesv2/droit-travail/picto_moins.gif';
	}
	else { 
		document.getElementById(id).style.display = 'none';
		document.getElementById(idImg).src = '../Images/imagesv2/droit-travail/picto_plus.gif';
	}
	
}


