var delay_menu = 1000;
var timeoutMenu = 0;
var qcm = 0;
var pres = 0;
var pres_titre = new Array("");
pres_titre.push("INTRODUCTION");
pres_titre.push("STRATEGIE GENERALE");
pres_titre.push("LES REGIMES SPECIFIQUES");
pres_titre.push("LES AROMES ET LES SAVEURS AU SECOURS DES REGIMES");
pres_titre.push("CONCLUSIONS");
pres_titre.push("CAS CLINIQUE 1");
pres_titre.push("CAS CLINIQUE 2");
pres_titre.push("CAS CLINIQUE 3");
pres_titre.push("CAS CLINIQUE 4");
pres_titre.push("CAS CLINIQUE 5");
var num = window.location.search.split("=")[1];
if(num > 0){
	pres = num;
}


//
function open_menu() {
	charge_menu('menu');
	timeoutMenu = window.setTimeout(clear_menu, delay_menu);
}
function charge_menu(div) {
	document.getElementById(div).style.display = "block";
	var contenu_div = renvoie_fichier("../htm/menu.htm");
	document.getElementById(div).innerHTML = contenu_div;
}
function survol_menu() {	stop_time_menu();
}
function sort_menu() {
	time_menu();
}
function clear_menu() {
	document.getElementById('menu').style.display = "none";
}
function time_menu(){
	timeoutMenu = window.setTimeout(clear_menu, delay_menu);
}
function stop_time_menu(){
	if(timeoutMenu){
		window.clearTimeout(timeoutMenu);
		timeoutMenu = null;
	}
}
function renvoie_fichier(fichier){
	if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else
		return(false);
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else
	return(false);
}
function go_som(){
	document.location.href = "../htm/sommaire.htm";
}
function open_pdf(choix){	if(choix == 1){		var dos = "diaporama";
	}else{		var dos = "commentaire";
	}
	if(pres < 6){		var nom = "chap_"+pres;
	}else{		var nom = "cas_"+(pres-5);
	}
	document.location.href = "../pdf/"+dos+"/"+nom+".pdf";
}
function fill_download(){	var tab = '';
	tab += '<table width="800" border="0" cellspacing="10" cellpadding="0">';
	tab += '<tr class="head">';
	tab += '<td width="500">Chapitres</td>';
	tab += '<td width="150" class="pdf">Diapositives seules</td>';
	tab += '<td width="150" class="pdf">Avec commentaires</td>';
	tab += '</tr>';
	//
	for(var C = 1; C < 6; C++){		var titre = pres_titre[C];
		tab += '<tr><td class="title">'+titre+'</td>';
		tab += '<td class="pdf"><a href="../pdf/diaporama/chap_'+C+'.pdf"></a></td>';
		tab += '<td class="pdf"><a href="../pdf/commentaire/chap_'+C+'.pdf"></a></td>';
		tab += '</tr>';
	}
	tab += '</table>';
	//
	tab += '<p class="liste_cas"><span>Cas cliniques : </span>';
	for(var C = 1; C < 6; C++){
		tab += '<span>'+C+'</span><a href="../pdf/diaporama/cas_'+C+'.pdf">&nbsp;</a>';
	}
	tab += '</p>';
	document.getElementById("download").innerHTML = tab;
}
function valid_qcm(){
	window.scrollTo(0,0);
	if(qcm == 0){		document.getElementById("total").innerHTML = "Merci de répondre avant de valider";
		document.getElementById("total").className = "vu";
	}else{
		var bon = new Array(0, 2, 2, 2, 1, 1, 2, 2, new Array(1, 2, 2, 1, 1), 3, 1);
		var tot = 0;		for(var R = 1; R < bon.length; R++){			if(document.getElementById('sol_'+R)){				var style = "solution vu ";
				if(isArray(bon[R])){
					var good = bon[R].join("_");
					var rep = qcm[R].join("_");					if(good == rep){
						style += "juste";
						tot++;
					}else{
						style += "faux";
					}
				}else{
					if(qcm[R] == bon[R]){
						style += "juste";
						tot++;
					}else{						style += "faux";
					}
				}
				document.getElementById('sol_'+R).className = style;
			}
		}
		document.getElementById("total").innerHTML = "Vous avez "+tot+"/"+(bon.length-1);
		document.getElementById("total").className = "vu";
	}
}
function choix_qcm(choix, quest, check){
	if(qcm == 0){
		qcm = new Array(1);
		for(var R = 1; R < 20; R++){
			if(document.getElementById('sol_'+R)){
				if(R == 8){					qcm.push(new Array(1, 1, 1, 1, 1));
				}else{
            		qcm.push(1);
            	}
            }
   		}
   		//alert(qcm);
  	}
  	if(check > 0){
  		qcm[quest][check] = choix.value;
  	}else{
  		qcm[quest] = choix.value;
  	}
  	//alert(qcm);
}
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1){
      return false;
   }else{
      return true;
   }
}
function open_div(div, closediv) {
	if(div == "ml"){
		document.location.href = "../pdf/ml.pdf";
	}else{
		document.getElementById(div).style.display = "block";
		document.getElementById(closediv).style.display = "none";
	}
}
function close_div(div) {
	document.getElementById(div).style.display = "none";
}
function test_vu(){	document.location.href = "Data/htm/sommaire.htm";
}
function test_retour(som){

	var contenu_div = "";
	//
   	if(som == 1){   		charge_menu('som');
   	}
	var title = "Conter la diététique pour mieux compter les aliments";
	var num = window.location.search.split("=")[1];
	if(pres > 0){		title += " : "+pres_titre[pres];
		document.getElementById("title").innerHTML = pres_titre[pres];
		contenu_div += "<ol>";
		contenu_div += '<li onmousedown="open_pdf(1)"><span class="pdf"></span><span class="titre">Diapositives</span></li>';
		if(pres < 6){
			contenu_div += '<li id="cmt_pdf" onmousedown="open_pdf(2)"><span class="pdf"></span><span class="titre">Commentaires</span></li>';
		}
		contenu_div += "</ol>";
	}
	document.title = title;
	contenu_div += renvoie_fichier("../htm/footer.htm");
	document.getElementById("footer").innerHTML = contenu_div;
}

