/* l_lessons.js
 * Version 2.8 - 24/03/2005
 * Role : scripts pour la page Cours de la Learning Zone
 * Projet : The Web Language Lab 
 * Auteur : Etienne CHEVILLARD
 */


// nom de la division cible
divC = "lDiv";


// retourne un lien vers le cours d'index specifie
function getLessonLink(intIdx) {
	var domA;
	var strL;
  domA = document.createElement("A");
  if (tcours[intIdx][0].charAt(tcours[intIdx][0].length-1) == '.')
    strL = tcours[intIdx][0].substring(0, tcours[intIdx][0].length-1);
  else
    strL = tcours[intIdx][0];
  domA.appendChild(document.createTextNode(" " + strL));
  domA.href="javascript:execCours(" + intIdx + ")";
  return (domA);
} // fin getLessonLink(intIdx)


// genere la cellule pour le nom du cours
function createCellName(intIdx) {
	var domTD;
  domTD = document.createElement("TD");
  domTD.width="270px";
  // cas du dernier cours ajoute : NOUVEAU !
	if (intIdx == tcours.length-1) {
	  domSPA = document.createElement("SPAN");
	  domSPA.appendChild(document.createTextNode(strNew));
	  domTD.appendChild(domSPA);
  }
  // lien vers le cours
  domTD.appendChild(getLessonLink(intIdx));
  return (domTD);
} // fin createCellName(intIdx)


// genere la cellule pour le theme du cours
function createCellTheme(intIdx) {
	var domTD;
  domTD = document.createElement("TD");
  domTD.width="180px";
  domTD.appendChild(document.createTextNode(tcours[intIdx][2]));
  return (domTD);
} // fin createCellTheme(intIdx)


// genere la cellule pour le niveau du cours
function createCellLevel(intIdx) {
	var domTD;
	var domIMG;
  domTD = document.createElement("TD");
  domTD.width="60px";      
  domIMG = document.createElement("IMG");
  domIMG.src="../images/etoile" + tcours[intIdx][6] + ".gif";
  domIMG.border="0";
  domIMG.align="middle";
  domIMG.alt="";
  domTD.appendChild(domIMG);
  return (domTD);
} // fin createCellLevel(intIdx)


// genere la liste des cours dans la langue specifiee
function dispLessonsByLang(theLang, thePort) {
  var domH4;
	var domTA;
	var domTB;
	var domTR;
	var domTH
	var domTD;
	var domIMG;
	var i;
	var booLesson;
	booLesson = false;
	// en-tete du tableau
	domTA = document.createElement("TABLE");
	domTB = document.createElement("TBODY");
	domTR = document.createElement("TR");	
	for (i=0; i<tabTHLang.length; i++)	{
		domTH = document.createElement("TH");
		domTH.appendChild(document.createTextNode(tabTHLang[i]));
		domTR.appendChild(domTH);
	}
	domTB.appendChild(domTR);
  // pour chaque cours
  for(i=tcours.length-1; i>=0; i--) {
		// uniquement les cours destines a tout le monde ou au portail thePort
	  if (((tcours[i][5] == "1") || (tcours[i][5] == thePort))
      && ((tcours[i][1].toLowerCase()).indexOf(theLang.substring(0, 2).toLowerCase()) == 0)) {
      // au moins un cours
      booLesson = true;
      // creation de la ligne du tableau
      domTR = document.createElement("TR");
      // nom
      domTR.appendChild(createCellName(i));
      // date
      domTD = document.createElement("TD");
      domTD.width="100px";
      domTD.appendChild(document.createTextNode(tcours[i][4]));
      domTR.appendChild(domTD);
      // theme
      domTR.appendChild(createCellTheme(i));
      // niveau
      domTR.appendChild(createCellLevel(i));
      domTB.appendChild(domTR);
		}
	}
	domTA.appendChild(domTB);
	// si au moins un cours
	if (booLesson) {
  	// langue
  	domH4 = document.createElement("H4");
   	domIMG = document.createElement("IMG");
    domIMG.src="../images/mflag_" + theLang.substring(0, 2).toLowerCase() + ".gif";
    domIMG.width="26";
    domIMG.height="15";
    domIMG.border="0";
    domIMG.align="middle";
    domIMG.alt="";
  	domH4.appendChild(domIMG);
  	domH4.appendChild(document.createTextNode(" " + theLang));
  	document.getElementById(divC).appendChild(domH4);
	  // listes des cours
    document.getElementById(divC).appendChild(domTA);
  }
} // fin dispLessonsByLang(theLang, thePort)


// genere la liste des cours crees ou modifies dans l'annee specifiee (YYYY)
function dispLessonsByYear(theYear, thePort) {
  var domH4;
	var domTA;
	var domTB;
	var domTR;
	var domTH
	var domTD;
	var domIMG;
	var domSPA;
	var i;
	var booLesson;
	booLesson = false;
	// en-tete du tableau
	domTA = document.createElement("TABLE");
	domTB = document.createElement("TBODY");
	domTR = document.createElement("TR");	
	for (i=0; i<tabTHYear.length; i++)	{
		domTH = document.createElement("TH");
		domTH.appendChild(document.createTextNode(tabTHYear[i]));
		domTR.appendChild(domTH);
	}
	domTB.appendChild(domTR);
  // pour chaque cours
  for(i=tcours.length-1; i>=0; i--) {
		// uniquement les cours destines a tout le monde ou au portail thePort
	  if (((tcours[i][5] == "1") || (tcours[i][5] == thePort))
      && (tcours[i][4].indexOf("/" + theYear) != -1)) {
      // au moins un cours
      booLesson = true;
      // creation de la ligne du tableau
      domTR = document.createElement("TR");
      // nom
      domTR.appendChild(createCellName(i));
      // langue
      domTD = document.createElement("TD");
      domTD.width="100px";
      domTD.appendChild(document.createTextNode(tcours[i][1]));
      domTR.appendChild(domTD);
      // theme
      domTR.appendChild(createCellTheme(i));
      // niveau
      domTR.appendChild(createCellLevel(i));
      domTB.appendChild(domTR);
      domTB.appendChild(domTR);
		}
	}
	domTA.appendChild(domTB);
	// si au moins un cours
	if (booLesson) {
  	// annee
  	domH4 = document.createElement("H4");
  	domIMG = document.createElement("IMG");
    domIMG.src="../images/calendar.gif";
    domIMG.width="30";
    domIMG.height="30";
    domIMG.border="0";
    domIMG.align="middle";
    domIMG.alt="";
  	domH4.appendChild(domIMG);
  	domH4.appendChild(document.createTextNode(" " + strYear + " " + theYear));
  	document.getElementById(divC).appendChild(domH4);
	  // listes des cours
    document.getElementById(divC).appendChild(domTA);
  }
} // fin dispLessonsByYear(theYear, thePort)


// affiche la liste des cours par annee, de 2009 a 2001
function listeCoursParDate() {
	var i;
	document.getElementById(divC).innerHTML = "";
  for(i=9; i>0; i--) {
    dispLessonsByYear("200" + i, "2");
  }
	return;
} // fin listeCoursParDate()


// affiche la liste des cours par langue
function listeCoursParLangue() {
	var i;
	document.getElementById(divC).innerHTML = "";
  for(i=0; i<tabLang.length; i++) {
    dispLessonsByLang(tabLang[i], "2");
  }
	return;
} // fin listeCoursParLangue()


// execute le cours de numero specifie
function execCours(noCours) {
	// demarre le cours dans une nouvelle fenetre
	var objFnt;
	var strAdr = "../lessons/lesson" + noCours + "/index.html";
	var strFid = "lesson"+ noCours;
  var strPrp = "top=20,left=4,width=783,height=440";
  strPrp += ",toolbar=1,location=0,directories=0,menubar=0,scrollbars=1,resizable=1,status=1";
  objFnt= window.open(strAdr, strFid, strPrp);
  objFnt.focus();
  return;
} // fin execCours(noCours)
