//changement de page
function SetPage(nomPage)
{
	document.frmglobal.page.value=nomPage;
	document.frmglobal.submit();
}

function SetPagePerso(nomPage)
{
	document.frmglobal.page_perso.value=nomPage;
	document.frmglobal.page.value="perso";
	document.frmglobal.submit();
}

function SetValCours(valeur)
{
	document.frmglobal.valcours.value=valeur;
}

function SetId(valeur)
{
	document.frmglobal.id.value=valeur;
}

function SetType(valeur)
{
	document.frmglobal.type.value=valeur;
}

function SetNiveau(valeur)
{
	document.frmglobal.selNiveau.value=valeur;
}

function SetMd5()
{
	pass=document.frmidentification.txtPassword.value;
	document.frmidentification.txtPassword.value="";
	buf=md5(pass);
	document.frmidentification.md5.value=buf;

  return true;
}

//applique la couleur de fond "couleur" a l'element "idElement"
function ChangeCouleur(idElement, couleur)
{
	document.getElementById(idElement).style.backgroundColor=couleur;
}

//affiche le div fils passe en parametre
//change la couleur de fond du div parent
function AfficherDivPartenaire(tabDivFils, idDivFils, tabDivImg, idDivImg)
{
	for(var i=0 ; i<tabDivFils.length ; i++){
		if(tabDivFils[i] != idDivFils){
			document.getElementById(tabDivFils[i]).style.display="none";
			document.getElementById(tabDivImg[i]).style.backgroundImage='url(Design/Images/Presentation/plus.png)';
		}
		else{
			if(document.getElementById(idDivFils).style.display=="none"){
				document.getElementById(idDivFils).style.display="block";
				document.getElementById(idDivImg).style.backgroundImage='url(Design/Images/Presentation/moins.png)';
			}
			else{
				document.getElementById(idDivFils).style.display="none";
				document.getElementById(idDivImg).style.backgroundImage='url(Design/Images/Presentation/plus.png)';
			}
		}
	}
}

//ouvre un PopUp nomme "nom" contenant la page "page"
function OuvrirDetail(page, nom)
{
	var top=(screen.height-350)/2;
	var left=(screen.width-450)/2;
	var option="status=no,location=no,titlebar=no,toolbar=no,resizable=no,scrollbars=no";
	window.open(page, nom, "top=" + top + ",left=" + left + ",width=" + 450 + ",height=" + 350 +"," + option);
}

//verifie que les champs de formulaire de "tabChamps" sont remplis.
//affiche un message si ce n'est pas le cas
//retourne un booleen
function VerifChamps(tabChamps)
{
	var msg="Les éléments suivants ne sont pas renseignés : \n";
	var vide=0;
	var retour=true;
	
	for(var i=0 ; i<tabChamps.length ; i++){
		if(document.getElementById(tabChamps[i]).value == ""){
			msg+=" - " + tabChamps[i].substring(3,(tabChamps[i].length)) +"\n";
			document.getElementById(tabChamps[i]).style.backgroundColor='#FFCC33';
			vide++;
		}
		else{
			document.getElementById(tabChamps[i]).style.backgroundColor='';
		}
	}
	
	if(vide > 0){
		alert(msg);
		retour=false;
	}
	
	return retour;
}

//recherche le contenu d'un textbox dans une liste deroulante
//recherche : id du textbox
//nom : id de la liste deroulante
function positionrecherche(recherche,nom)
{
	var tmp=document.getElementById(recherche).value.toLowerCase();
	var pos;
    for (var n=0;n<document.getElementById(nom).length;n++){
		pos=document.getElementById(nom)[n].text.toLowerCase();
		pos=pos.replace(/[éèêë]/g,"e");
	    if ( pos >= tmp ){
			document.getElementById(nom).selectedIndex=n;
	    	n=document.getElementById(nom).length;
	    }
	}
}

function VerifMail(email) { // vérif validité email par REGEXP
   var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/
   return (reg.exec(email)!=null)
}