  if (document.layers) {navigator.family = "nn4"}
  if (document.all) {navigator.family = "ie4"}
  if (window.navigator.userAgent.toLowerCase().match("gecko")) {navigator.family = "gecko"}

  var downloadWin;  // handle de la fenêtre utilisée pour le download
	var displayWin;		// fenêtre d'affichage divers
	
//--------------------------------------------

	function doSubmit (toDo, toDoObj)	{
//alert ("doSubmit; toDo: " + toDo);
		toDoObj.value = toDo;

		document.myForm.submit ();
	}

//---------------------------------------------

	function doFindSolutions (toDo, toDoObj, id, idObj)	{
//alert ("doSubmit; toDo: " + toDo);
		if (id != -1) {
			idObj.value = id;
		}
		
		doSubmit (toDo, toDoObj);
	}

	//---------------------------------------------
	//
	function doSendTest (toDo, toDoObj, id) {
    // faire disparaître le bouton d'envoi pour éviter le double click
    // cela arrive et je pense que c'est dans le cas de ligne lentes (V90 56K)
//alert (navigator.family);

    if (navigator.family == "ie4") {
    	tmp = id + ".style.visibility='hidden'";
//alert (tmp);
    	eval (tmp);
    }
    else if (navigator.family == "gecko") {
      document.getElementById(id).style.visibility = "hidden";
    }
    doSubmit (toDo, toDoObj);
  }
  
	//---------------------------------------------
	//
	function doSendTestGeneric () {
    // faire disparaître le bouton pour éviter le double click
//alert (navigator.family);
		id = arguments[0];
    if (navigator.family == "ie4") {
    	//tmp = id + ".style.visibility='hidden'";
    	//eval (tmp);
//alert (tmp);
      document.getElementById(id).style.visibility = "hidden"; // nouveauté explorer 8. Version 7 : ??
    }
    else if (navigator.family == "gecko") {
      document.getElementById(id).style.visibility = "hidden";
    }
    toDo = arguments[1];
    toDoObj = arguments[2];
    
    for (i=3; i<arguments.length; i+=2) {
    	val = arguments[i];
    	valObj = arguments[i+1];
//alert (val);
//alert (valObj.name);
    	valObj.value = val;
    }
    
    doSubmit (toDo, toDoObj);
  }

	//---------------------------------------------
	// nécessite que le nombre d'arguments soit pair, et dans l'ordre
	// valeur,objet_à_attribuer_la_valeur
	// 
	function doSubmitGeneric () {
    toDo = arguments[0];
    toDoObj = arguments[1];
    
    for (i=2; i<arguments.length; i+=2) {
    	val = arguments[i];
    	valObj = arguments[i+1];
//alert (val);
//alert (valObj.name);
    	valObj.value = val;
    }
    
    doSubmit (toDo, toDoObj);
  }

//---------------------------------------------

	function doSort (toDo, toDoObj, sortBy, sortByObj, direction, directionObj) {
//alert (toDo + ";" + sortBy + ";" + direction);
		sortByObj.value = sortBy;
		directionObj.value = direction;
		doSubmit (toDo, toDoObj);
	}

//---------------------------------------------

	function doEnterModeChoice (toDo, toDoObj, val, valObj) {
//alert (toDo + "; val=" + val);
		valObj.value = val;
		doSubmit (toDo, toDoObj);
	}

//--------------------------------------------------------------------
// param unique indique qu'un seul enregistrement doit être sélectionné (=1). 
// Si absent, plusieurs sont possibles
//
	function displayTableOp (toDo, toDoObj, tableOp, tableOpObj, selectedObj, regulExp, unique, anchorObj, checkSelected) {
		// déterminer les id sélectionnés, seront collé dans l'objet approprié
		
		// opération à faire
		tableOpObj.value = tableOp;

		// un paramètre non défini pour checkSelected ne satisfait pas ce test, donc inutile de rajouter
		// le paramètre dans tous les appels de la fonction
		if (checkSelected == 0) {
			// pas nécessaire d'avoir une sélection
			selectedObj.value = "";
			
//alert ("toDo=" + toDo + "; tableOp=" + tableOp + ";regulExp=" + regulExp);
			doSubmit (toDo, toDoObj);
		}
		else {
			ret = getSelected ("checkbox", regulExp, 0, null);
			goOn = 1;
			list = ret.str;
			ancre = ret.ancre;
			autreAncre = ret.autreAncre;

//alert ("list=" + list);
//alert ("unique=" + unique);

			if (list != "") {
				if (unique) {
					tmp = list.split (",");
					if (tmp.length > 1) {
						alert ("Pour cette opération, un seul enregistrement DOIT être sélectionné");
						goOn = 0;
					}
				}
				if (goOn) {
					// liste des ids
					selectedObj.value = list;
//alert ("tableOpObj.value=" + tableOpObj.value);
//alert ("selectedObj.value=" + selectedObj.value);
//alert ("selectedObj.id=" + selectedObj.id); ???
					
					// ancre
					if (toDo == "del") anchorObj.value = autreAncre;
					else anchorObj.value = ancre;
					
//alert ("toDo=" + toDo + "; tableOp=" + tableOp + ";regulExp=" + regulExp);
					doSubmit (toDo, toDoObj);
				}
			}
			else {
				alert ("Pas d'enregistrements délectionnés !");
			}
		}
	} // end displayTableOp

//-------------------------------------------------
// extrait les éléments html sélectionnés.
//
	function getSelected (elem, regulExp, toAdd, updateObj) {
		var els = document.myForm.elements;
		var idList = new Array ();
		var index = 0;
//alert ("regExp=" + regulExp);
		
		if (regulExp != "") {
			rE = new RegExp (regulExp);
		}
		else {
			rE = new RegExp ("/.*/");
		}

//alert (rE.toString ());
//toto = "offsetLimit";
//alert (toto.search(rE));

		oneChecked = 0;
		ancre = 0;
		// pour le cas ou l'ancre disparaitrait de la page (effacement d'enregistrement)
		autreAncre = 0; 
		
		for (i=0; i<els.length; i++){ 
			switch (els[i].type) {
				case elem:
					elemName = els[i].name;
					if (elemName.search (rE) != -1) {
//alert (els[i].type + "; " + elemName);
						if (els[i].checked) {
							tmp = els[i].name;
							val = parseInt (tmp.substr (2)) + toAdd;
//alert ("val=" + val);
							idList[index++] = val;
							if (ancre == 0) ancre = val;
							oneChecked = 1;
						}
						else {
//alert (regulExp + "; " + elemName);
							// garder le DERNIER élément avant le PREMIER SÉLECTIONNÉ
							if (!oneChecked) {
								tmp = els[i].name;
								autreAncre = parseInt (tmp.substr (2)) + toAdd;
							}
						}
					}
				break;
			}
		}
		
		tmp = "";
//alert ("idList.length=" + idList.length);
		if (idList.length > 0) {
			tmp = idList.join (",");
		}
		// mettre à jour si nécessaire
		if (updateObj != null) updateObj.value = tmp;
		
//alert ("ancre: " + ancre + "; " + autreAncre);
//alert ("tmp=" + tmp);
		ret = new Array ();
		ret.str = tmp;
		ret.ancre = ancre;
		ret.autreAncre = autreAncre;

		return ret;
	}

//---------------------------------------------

	function doTableOp (toDo, toDoObj, tableOp, tableOpObj, selectedObj) {
//alert ("toDo=" + toDo + "; tableOp=" + tableOp + "; selectedObj.name=" + selectedObj.name);
//alert ("toDo=" + toDo + "; tableOp=" + tableOp + "; selectedObj.value=" + selectedObj.value);		

		// déterminer les id sélectionnés, seront collé dans l'objet approprié
		list = selectedObj.value;
		if (list != "") {
			tableOpObj.value = tableOp;
			doSubmit (toDo, toDoObj);
		}
		else {
			alert ("Pas d'enregistrements délectionnés !");
		}
	}

//---------------------------------------------

	function doBackupTable (toDo, 										// 1
	                        tableName, 								// 2
	                        dbChoiceObj,							// 3
	                        exportTypeObj, 						// 4
	                        displayTypeObj, 					// 5
	                        clientsListObj, 					// 6
	                        testListObj, 							// 7
	                        startDateObj, 						// 8
	                        endDateObj, 							// 9
	                        dataContentObj,						// 10
	                        clientsListSubClients,		// 11
	                        subClientsListObj, 				// 12
	                        dataContentClientsObj, 		// 13
	                        nbListObj, 								// 14
	                        minTestNbObj,							// 15
	                        maxTestNbObj,							// 16
                          sessId,										// 17
	                        clientsListClients,				// 18
	                        idListProfilesObj) {			// 19
    str = "toDo=" + toDo;
    str += "&tableName="    + tableName;
		
		// pas d'accès direct à la valeur de l'objet, mais parcourir la collection 
		// et prendre la valeur de celui qui est sélectionné. Nécessaire en javascipt
		// pour accéder aux radio buttons

    if (dbChoiceObj.length == undefined) {
    	checkedButton = dbChoiceObj.value;
    }
    else {
	    for (i=0; i<dbChoiceObj.length; i++){
  	    if (dbChoiceObj[i].checked == "1") {
    	     checkedButton = dbChoiceObj[i].value
      	}
	    }
		}		
    str += "&db=" + checkedButton;

    for (i=0; i<exportTypeObj.length; i++){
      if (exportTypeObj[i].checked == "1") {
         checkedButton = exportTypeObj[i].value
      }
    }
    str += "&exportType="   + checkedButton;
		
    for (i=0; i<displayTypeObj.length; i++){
      if (displayTypeObj[i].checked == "1") {
         checkedButton = displayTypeObj[i].value
      }
    }
    str += "&displayType="  + checkedButton;
		
   	//--------------------------------------------
    if (tableName == "tests") {
	    index = clientsListObj.selectedIndex;
	    listSel = "";
	    for (i=0; i<clientsListObj.length; i++) {
	    	if (clientsListObj.options[i].selected) {
	    		listSel == "" ? tmp = "" : tmp = ",";
	    		listSel += tmp + clientsListObj.options[i].value;
	    	}
	    }
			str += "&clientsList=" + listSel;
	   	//val = clientsListObj.options[index].value;
	    //str += "&clientsList="   + val;
	    //val = clientsListObj.options[index].text;
	    //str += "&clientName="   + val;
	    
	    index = testListObj.selectedIndex;
	    listSel = "";
	    for (i=0; i<testListObj.length; i++) {
	    	if (testListObj.options[i].selected) {
	    		listSel == "" ? tmp = "" : tmp = ",";
	    		listSel += tmp + "'" + testListObj.options[i].value + "'";
	    	}
	    }
	    str += "&testList="     + listSel;
	
	    if (startDateObj.value != "") str += "&startDate="    + startDateObj.value;
//alert ("endDate=" + endDateObj.value);
	    if (endDateObj.value != "") str += "&endDate="    + endDateObj.value;
	    if (minTestNbObj.value != "") str += "&minNb="    + minTestNbObj.value;
	    if (maxTestNbObj.value != "") str += "&maxNb="    + maxTestNbObj.value;
	    str += "&dataContent="  + dataContentObj.value;
    	str += "&nbList="  + nbListObj.value;
    }
   	//--------------------------------------------
   	else if (tableName == "subClients") {
	    index = clientsListSubClients.selectedIndex;
	    listSel = "";
	    for (i=0; i<clientsListSubClients.length; i++) {
	    	if (clientsListSubClients.options[i].selected) {
	    		listSel == "" ? tmp = "" : tmp = ",";
	    		//listSel += tmp + "'" + clientsListSubClients.options[i].value + "'";
	    		listSel += tmp + clientsListSubClients.options[i].value;
	    	}
	    }
//alert ("listSel=" + listSel);
	    str += "&clientsList="   + listSel;

	    index = subClientsListObj.selectedIndex;
	    val = subClientsListObj.options[index].value;
	    str += "&subClientsList="   + val;
		}
   	//--------------------------------------------
    else if (tableName == "clients") {
	    index = clientsListClients.selectedIndex;
	    listSel = "";
	    for (i=0; i<clientsListClients.length; i++) {
	    	if (clientsListClients.options[i].selected) {
	    		listSel == "" ? tmp = "" : tmp = ",";
	    		listSel += tmp + clientsListClients.options[i].value;
	    	}
	    }
//alert ("listSel=" + listSel);
	    str += "&clientsList="   + listSel;

			// abandonné cette manière de faire
			//val = dataContentClientsObj.value;
			//str += "&dataContentClients="  + dataContentClientsObj.value;
		}
   	//--------------------------------------------
    else if (tableName == "profiles") {
    	str += "&idListProfiles="  + idListProfilesObj.value;
		}

    str += "&PHPSESSID="    + sessId;
//alert (str.slice(100, 170));
    url = "download.php?" + str;

    if (navigator.family == "nn4" && navigator.family == "gecko") {
      if (!downloadWin.closed ()) { downloadWin.close(); }
    }
    downloadWin = window.open (url, "downloadPage", "menubar=0,personalbar=0,status=0,scrollbars=1");
    if (window.focus) {downloadWin.focus(); }
  }

	//--------------------------------------------
	// 
	// passage d'un item cgrv au suivant ou précédent
	//
	function cgrvGoToItem (toDo, toDoObj, mAction, mActionObj, itemOffset, itemOffsetObj) {
//alert (toDo + "; " + mAction + "; " + itemOffset);
		mActionObj.value = mAction;
		itemOffsetObj.value = itemOffset;
		doSubmit (toDo, toDoObj);
	}
	
	//---------------------------------------------       
	// 
	// Gestion des intervalles dans les tests d'aptitudes
	//
	function incrementIntervalCounter (sessId) {
		intervalCounter += 1;
		// si le compteur (qui compte en secondes) dépasse 10 minutes
		// on quitte le test et on revient sur la page principale
		setTimeout ('incrementIntervalCounter ("' + sessId + '")', 1000);
//alert (intervalCounter);
		if (intervalCounter > 600) {
			theUrl = "intro.php?PHPSESSID=" + sessId;
//alert (theUrl);
			location.href=theUrl;
		}
	}

	//---------------------------------------------       

	function sendFileByMail (	toDo, fileName, mailObj) {
    str = "toDo=" + toDo;

    str += "&fileName="    + fileName;
    mail = mailObj.value;
    if (mail == "") {
    	alert ("Mail address required");
   	}
   	else {
	    str += "&mail="    + mail;
	    url = "sendByMail.php?" + str;
//alert (fileName);
//alert (url);
//alert (dataContentObj.value);

	    if (navigator.family == "nn4" && navigator.family == "gecko") {
  	    if (!downloadWin.closed ()) { downloadWin.close(); }
    	}
	    sendMailWin = window.open (url, "sendMailPage", "menubar=0,personalbar=0,status=0,scrollbars=1");
  	  if (window.focus) {sendMailWin.focus(); }
  	}
  }

//---------------------------------------------

	function emptyPersonalDataFields () {
    document.myForm.name.value = "";
    document.myForm.firstName.value = "";
    document.myForm.age.value = "";
    document.myForm.sex[0].checked = false;
    document.myForm.sex[1].checked = false;
    document.myForm.work.value = "";
    document.myForm.nationality.value = "";

    document.myForm.mailValue.value = "";
    document.myForm.clientCode.value = "";

    document.myForm.registerPersonalData.checked = false;
    document.myForm.testType[0].checked = false;
    document.myForm.testType[1].checked = false;

    document.myForm.fieldEmptied.value = "yes";
	}

//---------------------------------------------

	function toggleVisibility (navFam, id1, state1, id2, state2) {
//alert (navFam + ";" + id1 + ";" + id2 + ";" + state1 + ";" + state2);

    if(navFam =="nn4") {
//      tmp = "document." + id + "" + state1:
//    	eval (tmp);
   	}
    else if(navFam == "ie4"){
    	if (id1 != "") {
    		tmp = id1 + ".style.visibility='" + state1 + "'";
    		eval (tmp);
    	}
    	if (id2 != "") {
	    	tmp = id2 + ".style.visibility='" + state2 + "'";
  	  	eval (tmp);
  	  }
   	}
    else if(navFam =="gecko"){
      if (id1 != "") document.getElementById(id1).style.visibility = state1;
      if (id2 != "") document.getElementById(id2).style.visibility = state2;
    }
//    obj2.style.visibility = state2;
	}

//-------------------------------------------------

	function toggleVisibilityBis (navFam) {
		for (i=1; i<arguments.length; i+=2) {
      id = arguments[i];
      state = arguments[i+1];
//alert (id + ";" + state);
	    if(navFam =="nn4") {
//      tmp = "document." + id + "" + state1:
//    	eval (tmp);
	   	}
	    else if(navFam == "ie4"){
//alert (tmp);
	    	tmp = id + ".style.visibility='" + state + "'";
	    	eval (tmp);
	   	}
	    else if(navFam =="gecko"){
	      document.getElementById(id).style.visibility = state;
	    }
	  }
	}

//-------------------------------------------------

	function switchVisibility (navFam) {
//alert ("1 =>" + navFam);
		for (i=1; i<arguments.length; i++) {
      id = arguments[i];
	    if (navFam == "nn4") {
//      tmp = "document." + id + "" + state1:
//    	eval (tmp);
	   	}
	    else if (navFam == "ie4") {
	      vis = document.getElementById(id).style.visibility;
	    	//tmp = "vis=" + id + ".style.visibility";
	    	if (vis == "visible") state = "hidden";
	    	else if (vis == "hidden") state = "visible";
	      document.getElementById(id).style.visibility = state;
	   	}
	    else if(navFam =="gecko"){
	      vis = document.getElementById(id).style.visibility;
	    	if (vis == "visible")
	    		state = "hidden";
	    	else if (vis == "hidden")
	    		state = "visible";
	      document.getElementById(id).style.visibility = state;
	    }
	  }
	}

//-------------------------------------------------

	function switchState (navFam) {
		for (i=1; i<arguments.length; i++) {
      id = arguments[i];
	    if(navFam =="nn4") {
	   	}
	    else if(navFam == "ie4"){
	      state = document.getElementById(id).disabled;
	      state = !state;
	      document.getElementById(id).disabled = state;
	   	}
	    else if(navFam =="gecko"){
	      state = document.getElementById(id).disabled;
	      state = !state;
	      document.getElementById(id).disabled = state;
	    }
	  }
	}

//-------------------------------------------------

  function editFile (toDo, toDoObj, fileName, fileNameObj) {
    fileNameObj.value = fileName;
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------

  function handleEditFile (toDo, toDoObj) {
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------

  function handleEditParam (toDo, toDoObj) {
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------

  function delRecord (toDo, toDoObj, id, idObj, anchorId, anchorObj) {
    if (confirm ("Voulez vous effacer définitivement cet enregistrement (id = " + id + ") ?")) {
      idObj.value = id;
			anchorObj.value = anchorId;
      doSubmit (toDo, toDoObj);
    }
  }

//-------------------------------------------------

  function editRecord (toDo, toDoObj, id, idObj, anchorObj) {
    idObj.value = id;
		anchorObj.value = id;
//alert (anchorObj.value);
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------

  function depouilleRecord (toDo, pId, db, displayTypeObj, sessId) {
    // ouvrir une nouvelle fenêtre, y faire le calcul et afficher le résultat dedans.
    url = "callDepouillement.php?";
    url += "toDo=" + toDo;
    url += "&id=" + pId;
    url += "&db=" + db;
    
    for (i=0; i<displayTypeObj.length; i++){
//alert (exportTypeObj[i].checked);
      if (displayTypeObj[i].checked == "1") {
         displayType = displayTypeObj[i].value
      }
    }
    url += "&displayType=" + displayType;
    url += "&PHPSESSID=" + sessId;
//alert (url);
    if (navigator.family == "nn4" && navigator.family == "gecko") {
      if (!downloadWin.closed ()) { downloadWin.close(); }
    }
    downloadWin = window.open (url, "downloadPage", "resizable=1,menubar=0,personalbar=0,status=0,scrollbars=1");
    if (window.focus) {downloadWin.focus(); }
    idObj.value = id;
  }

//-------------------------------------------------

  function saveRecord (toDo, toDoObj, valObj, valArr) {
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------

  function addRecord (toDo, toDoObj) {
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------

  function reloadPage (toDo, toDoObj, firstObj, firstVal, valueObj, val) {
    
    firstObj.value = firstVal;
    valueObj.value = val;
//alert (val);
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------
// changement de l'image quand la souris est dessus
  function changeImage (newImage, imgObj) {
//alert (imgObj.src);
    imgObj.src = newImage;
  }
  
//-------------------------------------------------
// 
  function loadPersonalTestData (str, strIn) {
//alert (str + "; " + strIn);
    if (str.search(strIn) != -1) {
//if (strIn == str) {
      document.myForm.name.value = "c";
      document.myForm.firstName.value = "s";
      document.myForm.age.value = "12";
      document.myForm.sex[0].checked = true;
      document.myForm.work.value = "qwer";
      document.myForm.nationality.value = "suisse";
    }
  }

//-------------------------------------------------
// 
  function checkNumericalValue (obj, min, max, msg1, msg2) {
    val = obj.value;
//alert ("1) " + val + "; " + min + "; " + max + ";" + isNaN (val));
    ok = 1;
    
    if (val != "") {
	    if (val.length > 1) {
  	    ok = 0;
//alert ("1: " + val);
    	}
	    else if (val.search ("[^0-9]") != -1) {
  	    // si le caractère n'est pas entre 0 et 9
    	  ok = 0;
//alert ("2: " + val);
	    }
  	  else if (val < min || val > max) {
    	  // caractère pas dans les bornes
      	ok = 0;
//alert ("2: " + val);
	    }
  	}
  	  
    if (!ok) {
      obj.value = "";
      msg = msg1 + " " + min + " " + msg2 + " " + max + " !";
      alert (msg);
//      obj.focus ();
    }
  }

//-------------------------------------------------
// 
  function checkRgcgEnterValue (obj, min, max, msg1, msg2, symbolsChoice) {
    val = obj.value;
//alert ("1) " + val + "; " + min + "; " + max + ";" + isNaN (val));
    ok = 1;
    
    if (val != "") {
	    if (val.length > 1) {
  	    ok = 0;
//alert ("1: " + val);
    	}
    	else {
		    if (symbolsChoice == "letters") {
		    	// transformer l'entrée lettre en chiffre en soustrayant le code ascii de A
	  	  	val = val.toUpperCase ();
	    		code = val.charCodeAt (0);
	    		if (code < "A".charCodeAt (0) || code > "Z".charCodeAt (0)) {
						ok = 0;
					}
					// convertir en string
					val = String (val);
		    }
		    else if (symbolsChoice == "numbers") {
					val = String (val);
//alert ("val=" + val);
			    if (val.search ("[^0-9]") != -1) {
	  		    // si le caractère n'est pas un chiffre entre 0 et 9
		    	  ok = 0;
	//alert ("2: " + val);
			    }
	  		  else if (val < min || val > max) {
	    		  // caractère pas dans les bornes
	      		ok = 0;
	//alert ("2: " + val);
					}
		  	}
    	}
  	}
  	
    if (!ok) {
      obj.value = "";
      if (symbolsChoice == "letters") {
				minStr = String.fromCharCode ("A".charCodeAt (0));
				maxStr = String.fromCharCode ("Z".charCodeAt (0));
				msg = msg1 + " " + minStr + " " + msg2 + " " + maxStr + " !";
			}
			else {
				msg = msg1 + " " + min + " " + msg2 + " " + max + " !";
			}
      
      alert (msg);
//      obj.focus ();
    }
  }  // end checkRgcgEnterValue

//-------------------------------------------------
// idem à la  précédente mais sans l'intervalle (du fait
// que la saisie lettre peut contenir une des 
// 
  function checkRgcgEnterValue2 (obj, min, max, msg1, msg2, symbolsChoice) {
    val = obj.value;
//alert ("1) " + val + "; " + min + "; " + max + ";" + isNaN (val));
    ok = 1;
    
    if (val != "") {
	    if (val.length > 1) {
  	    ok = 0;
//alert ("1: " + val);
    	}
    	else {
		    if (symbolsChoice == "letters") {
		    	// transformer l'entrée lettre en chiffre en soustrayant le code ascii de A
	  	  	val = val.toUpperCase ();
	    		val = val.charCodeAt (0) - "A".charCodeAt (0);
					// convertir en string
					val = String (val);
		    }
		    else if (symbolsChoice == "numbers") {
		    	
		    }
//alert ("val=" + val);
		    if (val.search ("[^0-9]") != -1) {
  		    // si le caractère n'est pas entre 0 et 9
	    	  ok = 0;
//alert ("2: " + val);
		    }
  		  else if (val < min || val > max) {
    		  // caractère pas dans les bornes
      		ok = 0;
//alert ("2: " + val);
				}
	    }
  	}
  	  
    if (!ok) {
      obj.value = "";
      if (symbolsChoice == "letters") {
				minStr = String.fromCharCode ("A".charCodeAt (0) + min);
				maxStr = String.fromCharCode ("Z".charCodeAt (0) + max);
				msg = msg1 + " " + minStr + " " + msg2 + " " + maxStr + " !";
			}
			else {
				msg = msg1 + " " + min + " " + msg2 + " " + max + " !";
			}
      
      alert (msg);
//      obj.focus ();
    }
  }  // end checkRgcgEnterValue2

//-------------------------------------------------
// 
  function checkBlocLettreEnterValue (obj, validLettersCodes, msg1, msg2) {
    val = obj.value;
//alert (val + ";" + msg1 + ";" + msg2);
//alert ("code ascii=" + val.charCodeAt (0));
//alert (val.charCodeAt (0) + "; " + validLettersCodes);
//toto = '233,224,232,249,226,234,238,244,251,246,252,228';
//tata = 228;
//regExp = "/^" + tata + ",.*|.*," + tata + ",.*|.*," + tata + "$/";
//regE = new RegExp (".*," + tata + ",.*");
//regE = new RegExp ("^" + tata + ",.*|.*," + tata + ",.*|.*," + tata + "$");
//alert (regE.toString ());
//alert (toto.search(regE));
    ok = 1;
    
    if (val != "") {
	    if (val.length > 1) {
  	    ok = 0;
				alert (msg1);
    	}
    	else {
		    // vérifier si c'est une lettre, et convertir en majuscule
		    valCode = val.charCodeAt (0);
				regExp = new RegExp ("^" + valCode + ",.*|.*," + valCode + ",.*|.*," + valCode + "$");
//alert (regExp);
		    if ((val.charCodeAt(0) >= "a".charCodeAt(0) && val.charCodeAt(0) <= "z".charCodeAt(0)) ||
		    		(val.charCodeAt(0) >= "A".charCodeAt(0) && val.charCodeAt(0) <= "Z".charCodeAt(0)) ||
		    		(validLettersCodes.search(regExp) != -1)) {
	    		// transformer l'entrée lettre en chiffre en soustrayant le code ascii de A
	    		// pas valable pour les majuscules accentuées et le ç
  	  		val = val.toUpperCase ();
//alert ("val=" + val);
				}
				else {
					ok = 0;
	    		alert (msg2);
	    	}
	    }
  	}
//alert ("ok=" + ok);
    if (ok) {
      obj.value = val;
    }
    else {
    	obj.value = "";
    }
  }  // end checkBlocLettreEnterValue

//-------------------------------------------------
// 
  function incrementField (obj) {
    val = parseInt (obj.value);
    obj.value = val + 1;
  }

//-------------------------------------------------
// 
  function previousNext (toDo, toDoObj, direction, firstObj, pOffset, nbElem) {
    first = parseInt (firstObj.value);
    if (direction == "next") {
      if (first + pOffset <= nbElem) {
        // il y a encore des enregistrement à récupérer
        first += pOffset;
      }
    }
    else if (direction == "prev") {
      if (first - pOffset >= 0) {
        // il y a encore des enregistrement à récupérer
        first -= pOffset;
      }
    }
    firstObj.value = first;
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------
// 
  function previousNextLastFirst (toDo, toDoObj, direction, firstObj, pOffset, speed, nbElem) {
    first = parseInt (firstObj.value);
		pOffset = speed * parseInt (pOffset);
//alert (first + "; " + direction + "; " + speed + "; " + pOffset + "; " + nbElem);
    if (direction == "next") {
      if (first + parseInt (pOffset) <= nbElem) {
        // il y a encore des enregistrement à récupérer
        first += pOffset;
      }
    }
    else if (direction == "prev") {
      if (first - pOffset >= 0) {
        // il y a encore des enregistrement à récupérer
        first -= pOffset;
      }
    }
    else if (direction == "first") {
      if (first - pOffset >= 0) {
        // il y a encore des enregistrement à récupérer
        first = 0;
      }
    }
    else if (direction == "last") {
      tmp = nbElem / pOffset;
      tmp1 = Math.floor (tmp) 
      // pour le cas limite ou nbElem  % pOffset == 0
      if (nbElem % pOffset == 0)
        first = pOffset * (Math.floor (tmp)-1);
      else
        first = pOffset * (Math.floor (tmp));
    }
//alert (first);
    firstObj.value = first;
    doSubmit (toDo, toDoObj);
  }

//-------------------------------------------------
// 
  function copyInTextarea (msg, textObj) {
    textObj.value = msg;
  }

//-------------------------------------------------
// 
	function checkAll (elem, toDo, nameMask) {
		var els = document.myForm.elements;
		var idList = new Array ();


//		var index = 0;
		
		for (i=0; i<els.length; i++){ 
			switch (els[i].type){
				case elem:
					elemName = els[i].name;
					if (elemName.search (nameMask) != -1) {
//alert (elemName);
						els[i].checked = toDo;
					}
//					tmp = els[i].name;
//					idList[index++] = tmp.substr (2);
					break;
			}
		}
	}

	
//-------------------------------------------------
// 
	function setColor (elem) {
		if (elem.className == "noHighlight") {
			elem.className = "highlight";
		}
		else {
			elem.className = "noHighlight";
		}
//alert (elem.className);
	}

//-------------------------------------------------
// 
	function addTableNameToField (selectObj, fieldObj, prefix) {
		index = selectObj.selectedIndex;
//alert (index);
		val = prefix + selectObj.options[index].value;
		fieldObj.value = val;
	}
	
//-------------------------------------------------
// 
	function linkedFieldDisplay (getParam) {
		
		url = "editDb.php?" + getParam;

		if (navigator.family == "nn4" && navigator.family == "gecko") {
      if (!displayWin.closed ()) { displayWin.close(); }
    }
//alert (url);
    
    displayWin = window.open (url, "displayPage", "menubar=0,personalbar=0,status=0,scrollbars=1");
    if (window.focus) {displayWin.focus(); }
	}
	
	//-------------------------------------------------
	// 
	function checkUnicity (valObj, valArr) {
		found = 0;
		val = valObj.value;
		
		for (i = 0; i < valArr.length && !found; i++) {
			if (valArr[i] == val) {
				found = 1;
			}
		}
//alert (found);
		
		if (found) {
			alert ("La valeur " + val + " est déjà prise. Choisisez-en une autre SVP");
		}
		else {
			alert ("Valeur disponible !");
		}
	}

	//-------------------------------------------------
	//
	var helpWin;
	
	function openHelpWin (url) {
    if (helpWin) {
    	helpWin.close ();
    }
    helpWin = window.open (url, "Help", "menubar=0,personalbar=0,status=0,scrollbars=1,height=600,width=900,resizable=yes");
	}

	//-------------------------------------------------
	//
	var myWin;
	
	function openPayWin (url, paramObj) {
    if (myWin) {
    	myWin.close ();
    }
//alert (paramObj.length);

	    for (i=0; i<paramObj.length; i++) {
//alert (i + "; " + paramObj[i].checked);
    	if (paramObj[i].checked == true) {
//alert (i + " sélectionné");
    		val = paramObj[i].value;
    		name = paramObj[i].name;
    	}
    }
//alert (name);
//alert (val);
    url += "&" + name + "=" + val;
//alert (url);
    myWin = window.open (url, "pay", "menubar=0,personalbar=0,location=1,toolbar=1,scrollbars=1,height=800,width=1200,resizable=yes");
    //payWin = window.open (url, "pay");
	}

	//-------------------------------------------------
	//	affichage d'un pdf
	//	
	function showPDF (sessId, pdfName) {
		if (sessId != "")
			url = "showPdf.php?PHPSESSID=" + sessId + "&pdfName=" + pdfName;
		else 
			url = "showPdf.php?pdfName=" + pdfName;
		
    // si la fenêtre est ouverte la fermer
    if (displayWin != undefined)
    	displayWin.close();
//alert (url);
		displayWin = window.open (url, "", "toolbar=1,menubar=1,personalbar=0,status=0,scrollbars=1");
	}

//---------------------------------------------       

	function doPDFShow (textObj) {
    text = textObj.value;

    url = "download.php?toDo=showPDF&text=" + text;
//alert (url);
    if (navigator.family == "nn4" && navigator.family == "gecko") {
      if (!downloadWin.closed ()) { downloadWin.close(); }
    }
    downloadWin = window.open (url, "pdfPage", "menubar=0,personalbar=0,status=0,scrollbars=1");
    textObj.value = text;
  }

//---------------------------------------------       

	function closeWin () {
    window.close ();
  }

	//-------------------------------------------------
	//
	var downloadWin;
	
	function openWin (url) {
//alert (url);
    if (downloadWin) {
    	downloadWin.close ();
    }
    downloadWin = window.open (url, "download", "menubar=0,personalbar=0,location=1,toolbar=1,scrollbars=1,height=400,width=400,resizable=no");
	}

	//-------------------------------------------------
	//	Ajout d'un test à un 360
	//	
	function addTestTo36 (toDo, toDoObj, id360, id360Obj) {
		id360Obj.value = id360;
		
		doSubmit (toDo, toDoObj);
		
	}

	//-------------------------------------------------
	//	Retrait d'un test d'un 360
	//	
	function removeTestFrom36 (toDo, toDoObj, id360, id360Obj, testNb, testNbObj) {
		if (confirm ("Ceci retirera votre test de la liste attribuée à ce 360°.")) {
			id360Obj.value = id360;
			testNbObj.value = testNb;
		
			doSubmit (toDo, toDoObj);
		}
	}

	//-------------------------------------------------
	//	Retrait d'un test d'un 360
	//	
	function depouille36 (toDo, toDoObj, id360, id360Obj) {
		if (confirm ("Ceci provoquera le dépouillement des test individuels et combinés.")) {
			id360Obj.value = id360;
			testNbObj.value = testNb;
		
			doSubmit (toDo, toDoObj);
		}
	}

	//-------------------------------------------------
	//	Ajout d'un test à un groupe
	//	
	function addTestToGroup (toDo, toDoObj, idGroup, idGroupObj) {
		idGroupObj.value = idGroup;
		
		doSubmit (toDo, toDoObj);
	}

	//-------------------------------------------------
	//	Retrait d'un test d'un groupe
	//	
	function removeTestFromGroup (toDo, toDoObj, idGroup, idGroupObj, testNb, testNbObj) {
		if (confirm ("Ceci retirera votre test de la liste attribuée à ce groupe.")) {
			idGroupObj.value = idGroup;
			testNbObj.value = testNb;
		
			doSubmit (toDo, toDoObj);
		}
	}

	//-------------------------------------------------
	//	Ajout d'un test à un groupe
	//	on a ici besoin du numéro de test dans un champ hidden
	//
	function addTestToGroup2 (toDo, toDoObj, tableOp, tableOpObj, idGroup, idGroupObj, testId, testIdObj) {
//alert (tableOp);
		tableOpObj.value = tableOp;
		idGroupObj.value = idGroup;
		testIdObj.value = testId;
		
		doSubmit (toDo, toDoObj);
	}


	//-------------------------------------------------
	//	Retrait d'un test d'un groupe
	//	
	function removeTestFromGroup2 (toDo, toDoObj, tableOp, tableOpObj, idGroup, idGroupObj, testNb, testNbObj) {
		if (confirm ("Ceci retirera votre test de la liste attribuée à ce groupe.")) {
			tableOpObj.value = tableOp;
			idGroupObj.value = idGroup;
			testNbObj.value = testNb;
		
			doSubmit (toDo, toDoObj);
		}
	}

	//-------------------------------------------------
	// change la définition affichée dans un problème cgrv	
	//	
	function toggleDefinitions (id, rowNb, newDiff) {
	}

