var niveaux = new Array('serie','option','matiere');


function changeTo(element) {
	for(i=1;i<=5;i++) {
		document.getElementById('cal'+i).className = "";
	}
	element.className = "current";
}

function displayList(niv, select) {
	tag = niveaux[niv];
	todisp = document.getElementById(tag+select.value);
	div = document.getElementById(tag).childNodes;
	// On cache toutes les listes possibles sous selection actuelle
	for(i=0;i < div.length;i++) {
		if(div[i].id != null && div[i].id != "") {
			div[i].style.display = "none";
			div[i].disabled = true;
		}
	}
	// Si on a choisi autre chose qu'une valeur vide
	if (todisp.id != tag) {
		todisp.style.display = "block";
		todisp.disabled = false;
		// On vérifie qu'il n'y ait pas qu'un seul élément dans la liste, si c'est le cas on le selectionne
		if(todisp.options.length <= 2) {
			todisp.selectedIndex = todisp.options.length-1;
		}
		if((parseInt(niv) + 1) < niveaux.length) {
			displayList((parseInt(niv) + 1), todisp);
		}
		else if(todisp.value != "nil" && todisp.value != "") {
			document.getElementById('ok').style.display = "block";
			document.getElementById('nok').style.display = "none";
		}
		else {
			document.getElementById('ok').style.display = "none";
			document.getElementById('nok').style.display = "block";
		}
	}
	// Si on envoie la valeur Choisir qqchose, remet les listes en dessous en gris
	else {
		document.getElementById(tag + "_select").style.display = "block";
		// On envoie en récursif la fonction pour tout mettre à gris
		if ((parseInt(niv)+1) < niveaux.length) {
			displayList(parseInt(niv) + 1, select);	
		}
	}
}
