
/* FONCTIONS POUR L'OUVERTURE / FERMETURE DES NOEUDS EN JAVASCRIPT */

var last_tree_opened = '';
var image_menu_ouvert = "url(/images/bgd_elementOpened.gif)";
var image_menu_ferme = "url(/images/bgd_elementClosed.gif)";

function openTree(id,onlyone){
	if(onlyone==1 && last_tree_opened!=''){
		if(document.getElementById("UL_"+last_tree_opened)) document.getElementById("UL_"+last_tree_opened).style.display = "none";
		if(document.getElementById("LI_"+last_tree_opened)) document.getElementById("LI_"+last_tree_opened).style.backgroundColor = "#F4F4EC";
		if(document.getElementById("LI_"+id)) document.getElementById("LI_"+id).style.backgroundColor = "#FFFFFF";
	}
	if(document.getElementById("A_"+id)) document.getElementById("A_"+id).style.backgroundImage = image_menu_ouvert;
	document.getElementById("UL_"+id).style.display = "block";
	last_tree_opened = id;
}
function closeTree(id,onlyone){
	if(document.getElementById("A_"+id)) document.getElementById("A_"+id).style.backgroundImage = image_menu_ferme;
	if(onlyone==1 && last_tree_opened!='' && last_tree_opened!=id && document.getElementById("LI_"+last_tree_opened)){
		document.getElementById("LI_"+last_tree_opened).style.backgroundColor = "#F4F4EC";
	}
	if(onlyone!=1 || id!=last_tree_opened){
		document.getElementById("UL_"+id).style.display = "none";
		last_tree_opened = '';
	}
}
function actionTree(id,onlyone){
	if(document.getElementById("UL_"+id)){
		if(document.getElementById("UL_"+id).style.display != "block"){
			openTree(id,onlyone);
			return true;
		}else{
			closeTree(id,onlyone);
			return false;
		}
	}
}

/* FONCTIONS POUR L'UPDATE AJAX DES NOEUDS 
	!!! ATTENTION : NECESSITE L'IMPORT DE SCRIPTS/SACK.JS !!! */

var ajax;
var content = '';

function showContentMessage(){
	content.innerHTML = ajax.response;
}
function showErrorMessage(){
	content.innerHTML = ajax.response;
}
function showWaitMessage(){
	w = h = 32;
	content.innerHTML = '<img src="/images/throbber.gif" alt="Chargement en cours" width="' + w + '" height="' + h + '" align="absmiddle" />&nbsp;Chargement en cours, patientez...';
}
function getAjaxFile(fileName,tocontent,parent){
	content = tocontent;
	if(actionTree(content)){
		content = document.getElementById("UL_"+content);
		//content.innerHTML = fileName;
		if(content.innerHTML == ""){
			ajax = new sack();
			ajax.requestFile = fileName;
			ajax.onCompletion = showContentMessage;
			ajax.onError = showErrorMessage;
			ajax.onLoading = showWaitMessage;
			ajax.runAJAX();
		}
	}
}