var panels = new Array();

function switchPanel(id) {
	// On vérifie d'abord si le DOM est géré
	if (! document.getElementById)
		return;

	// Si l'element n'existe pas dans la page
	if (! (table = document.getElementById(id)))
		return;
	
	// On cherche le tbody parmi les fils de la table
	for (i = 0; i < table.childNodes.length ; i++) {
		if (table.childNodes[i].nodeName == "TBODY") {
			tbody = table.childNodes[i];
		}
	}

	// On ne sait jamais
	if (!tbody)
		return;
		
	// On regarde si le panel existe dans ceux qu'on a déjà utilisé
	panelFound = false;
	for (i = 0 ; i < panels.length; i++) {
		if (panels[i].id == id) {
			panelFound = true;
			panelIndex = i;
			break;
		}
	}

	// Si on ne l'a pas trouvé alors on le crée
	if (!panelFound) {
		panelIndex = panels.length;
		panels[panelIndex] = new Object();
		panels[panelIndex].id = id;
		panels[panelIndex].html = "";
	}
	
	// Ensuite si on a pas de code html associé au panel celui-ci est déployé
	if (panels[panelIndex].html == "") {
		// NS6 ne gère pas le outerHTML et IE6 déconne avec le innerHTML lors du remplacement :/
		if (table.outerHTML)
			panels[panelIndex].html = table.outerHTML;
		else
			panels[panelIndex].html = table.innerHTML;
		
		// Pour tous les fils du TBODY (sauf le premier)
		for (i = 1; i < tbody.childNodes.length; i++) {
			child = tbody.childNodes[i]; 
			
			// S'il s'agit d'un TR alors on le masque
			if (child.nodeName == "TR") {
				child.style.display = "none";
			}
		}
		
		// Enfin on met l'image appropriée si elle existe
		if (document.images[id])
			document.images[id].src="../news/plus.gif";
	}
	else { // Sinon si le tableau est replié
		// Idem que plus haut :/ Cette fois ci on rétabli le code html sauvegardé
		if (table.outerHTML)
			table.outerHTML = panels[panelIndex].html;
		else
			table.innerHTML = panels[panelIndex].html;
		
		// On vide le code html sauvegardé
		panels[panelIndex].html = "";
		
		// Et finalement on met l'image appropriée si elle existe
		if (document.images[id])
			document.images[id].src="../news/minus.gif";
	}
}
