// ==============================================
// Fonctions javascript utiles
// ===============================================
function test_fonctions_js(){
	alert("fonctions.js est ... en fonction !!");
	};

function afficher(n){
	var id = "M_" + n;
	document.getElementById(id).style.display="block";
	};

function cacher(n){
	var id = "M_" + n;
	document.getElementById(id).style.display="none";
	};
	

function fermer(){
	// alert("fonction fermer");
	for(i in PHPTablePagesNum){
		niveau = PHPTablePagesNum[i][0];
		// alert("- " + i + " : " + niveau + "\n");			
		if (niveau > 0){cacher(i);};
		};
	};

function ouvrir(){
	for(i in PHPTablePagesNum){
		afficher(i);
		};
	};


function afficher1(n){	// affiche le menu parents et les frères
	// fermer();
	for(i in PHPparents[n]){
		var j = PHPparents[n][i];
		if(j>=0){	// Il faut éliminer le parent -1
			// alert("parents : " + j);
			afficher(j);
			};
		};
	for(i in PHPfreres[n]){
		var j = PHPfreres[n][i];
		// alert("frères : " + j);
		afficher(j);
		};
	};

function afficher_enfants(n){
	afficher1(n);
	for(i in PHParbre_enfants[n]){
		var j = PHParbre_enfants[n][i];
			afficher(j);
		};
	};

function cacher1(n){
	setTimeout("cacher2(" + n + ")",200);
	};

function cacher2(n){
	alert("cacher2");
	for(i in PHPfreres[n]){
		var j = PHPfreres[n][i];
		cacher(j);
		};
	};

function ouvrir_prompt(){
	var nn=prompt("Numéro de menu à ouvrir", 7);
	if (nn!=null && nn!="")
		{
			afficher1(nn);
		};
	};
function fermer_afficher_enfants(n){
	// alert("fonction fermer-afficher-enfants");
	// temp = PHPTablePagesNum[n];
	// alert("id = " . temp[1]);
	fermer();
	afficher_enfants(n);
	// alert("!!!!"  + document.getElementById('page').style.width;);
	// e = document.getElementById('page')
	// alert("!!!!");
	// fond_page_gris();
	if (n == 0){	// fond de page gris pour la page d'accueil
		fond_page_gris();
		};
	};

// Tentative non aboutie de faire que l'ouverture d'un sous-menu ne ferme pas les fréres des menus parents
function fermer_afficher_enfants1(n){
	fermer();
	for(i in PHPparents[n]){
		if(i>6){
			for (j in PHPfreres[i]){
				afficher(j);
				};
			};
		};
	afficher_enfants(n);
	};

function marquer_menu_actif(n){
	alert("!!!" . menu_actif);
	id = PHPTablePagesId('menu_actif');
	alert("!!!");
	el = document.getElementById(id);
	alert (el.innerHTML);
	};


function afficher_article(url)
{
	myRef = window.open(url, 'article', 'toolbar=1, status=1, menubar=1, scrollbars=1, resizable=1, width=750');
	myRef.focus();
};

function fond_page_gris()
{	// fond de page gris pour la page d'accueil
	e = document.getElementById('page');
	e.className = 'fondaccueil';
	// e.style.width="800px";
	// e.style.backgroundColor="rgb(120,120,120)";
	// e.style.height="600px";
};

function fond_gris()
{	// fond de page gris pour la page d'accueil
	e = document.getElementById('page');
	e.className = 'fondgris';
	// e.style.width="800px";
	// e.style.backgroundColor="rgb(120,120,120)";
	// e.style.height="600px";
};

function fond_blanc()
{	// fond de page gris pour la page d'accueil
	e = document.getElementById('page');
	e.className = 'fondblanc';
	// e.style.width="800px";
	// e.style.backgroundColor="rgb(120,120,120)";
	// e.style.height="600px";
};

function SwitchDisplayPictures()
{	// pour cacher ou afficher alternativement les images dans le bulletin de commande
	els1 = document.images;
	els2 = document.getElementsByName('indications');
	els3 = document.getElementsByName('indications1');
	for(var i = 0; i < document.images.length; i++){
		el1 = els1[i];
		el2 = els2[i];
		el3 = els3[i];
		// alert(el.src);
		if(displayinit){
			el1.style.display = "none";
			el2.style.width = "400px";
			el3.style.display = "none";
			}else{
			el1.style.display = "block";
			el2.style.width = "142px";
			el3.style.display = "inline";
			};
		// el.width = "0";
	};
	displayinit = (displayinit+1)%2;
	// alert("!!! " + els3.length);
};
