// fonction qui vérifie si un champ texte est vide
function trim(val)
{
	if (!val) return val;

	while(val.charAt(0) == ' ') val = val.substring(1,val.length);
	while(val.charAt(length)==' ')  val = val.substring(0,val.length-1);

 	return val;
}




////////////////////////////////////////////////////////////
/// VALIDATION ET SUBMIT - FORM DE CONNEXION
////////////////////////////////////////////////////////////
function submitFormLogin()
{
	var nobug = true;
	var msg = '';
	
	if (trim(document.frmLogin.user.value) == '')
	{
		nobug = false;
		msg += 'You must enter your username\n';
	}
	
	if (trim(document.frmLogin.password.value) == '')
	{
		nobug = false;
		msg += 'You must enter your password\n';
	}
	
	if (nobug == true)
		document.frmLogin.submit();
	else
		alert(msg);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////
/// VALIDATION ET SUBMIT - FORM COURRIEL DIRECTEUR
////////////////////////////////////////////////////////////
function submitFormCourrielDir()
{
	var nobug = true;
	var msg = '';
	
	// COURRIEL DU DIRECTEUR(TRICE)
	if (trim(document.frmCourrielDir.courrielDirecteur.value) == "")
	{
		msg += "You must enter the principal's e-mail.\n";
		nobug = false;
	}
	else
	{
		value = document.frmCourrielDir.courrielDirecteur.value;
		
		if ((value.indexOf("@") == -1) || (value.indexOf(".") == -1))
		{ 
			msg += "The principal's e-mail is not valid.\n";
			nobug = false;
		}
		else
		{
			if (trim(document.frmCourrielDir.courrielDirecteurConfirm.value) == '')
			{
				msg += "You must confirm the principal's e-mail.\n";
				nobug = false;
			}
			else
			{
				if (document.frmCourrielDir.courrielDirecteur.value != document.frmCourrielDir.courrielDirecteurConfirm.value)
				{
					msg += "You did not retype the principal's e-mail correctly.\n";
					nobug = false;
				}
			}
		}
	}
	
	if (nobug == true)
		document.frmCourrielDir.submit();
	else
		alert(msg);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////
/// VALIDATION ET SUBMIT - FORM DE CRÉATION DE COMPTE
////////////////////////////////////////////////////////////
function submitFormCreateAccount()
{
	var nobug = true;
	var msg = '';
	
	
	/*
	// cs
	if(document.frmInscriptionISO.cs.value == 'choisir')
	{
		msg += "Vous devez choisir la commission scolaire de votre école.\n";
		nobug = false;
	}*/
	
	
	// choix de primaire / secondaire (au besoin)
	if(document.frmInscriptionISO.prisecFaireChoix)
	{
		if(document.frmInscriptionISO.prisecFaireChoix[0].checked == false && document.frmInscriptionISO.prisecFaireChoix[1].checked == false && document.frmInscriptionISO.prisecFaireChoix[2].checked == false)
		{
			msg += "You must specify if your school is a primary school, a high school or both.\n";
			nobug = false;
		}
	}
	
	
	// choix du niveau du formulaire - dans le cas d'une école PRI ET SEC seulement
	if(document.frmInscriptionISO.prisecFaireChoix[2].checked == true)
	{
		if(document.frmInscriptionISO.prisecGrille[0].checked == false && document.frmInscriptionISO.prisecGrille[1].checked == false)
		{
			msg += "You must choose the form level.\n";
			nobug = false;
		}
	}
	
	
	// nombre d'étudiants - Garçons
	var nbGarconsCheck = false;
	if(trim(document.frmInscriptionISO.nbEtudiantsGarcons.value) == '')
	{
		msg += "You must enter your school's number of students (boys).\n";
		nobug = false;
	}
	else if (isNaN(trim(document.frmInscriptionISO.nbEtudiantsGarcons.value)))
	{
		msg += "The  \"School's number of students (boys)\" field must be a number.\n";
		nobug = false;
	}
	else
	{
		var nbGarconsCheck = true;
	}
	
	/*
	else if (trim(document.frmInscriptionISO.nbEtudiantsGarcons.value) == 0)
	{
		msg += "Le champ \"Nombre d'étudiants (Garçons) de l'école\" doit supérieur à zéro.\n";
		nobug = false;
	}*/
	
	
	// nombre d'étudiants - Filles
	var nbFillesCheck = false;
	if(trim(document.frmInscriptionISO.nbEtudiantsFilles.value) == '')
	{
		msg += "You must enter your school's number of students (girls).\n";
		nobug = false;
	}
	else if (isNaN(trim(document.frmInscriptionISO.nbEtudiantsFilles.value)))
	{
		msg += "The  \"School's number of students (girls\" field must be a number.\n";
		nobug = false;
	}
	else
	{
		var nbFillesCheck = true;
	}
	
	/*
	else if (trim(document.frmInscriptionISO.nbEtudiantsFilles.value) == 0)
	{
		msg += "Le champ \"Nombre d'étudiants (Filles) de l'école\" doit supérieur à zéro.\n";
		nobug = false;
	}*/
	
	
	// nombre d'étudiants - Total
	if(trim(document.frmInscriptionISO.nbEtudiants.value) == '')
	{
		msg += "You must enter your school's total number of students.\n";
		nobug = false;
	}
	else if (isNaN(trim(document.frmInscriptionISO.nbEtudiants.value)))
	{
		msg += "The \"School's total number of students\" field must be a number.\n";
		nobug = false;
	}
	else if (trim(document.frmInscriptionISO.nbEtudiants.value) == 0)
	{
		msg += "The \"School's total number of students\" field must be higher than zero.\n";
		nobug = false;
	}
	else
	{
		if (nbGarconsCheck == true && nbFillesCheck == true)
		{
			var nbFilles = parseInt(document.frmInscriptionISO.nbEtudiantsFilles.value);
			var nbGarcons = parseInt(document.frmInscriptionISO.nbEtudiantsGarcons.value);
			var nbEtudTotal = parseInt(document.frmInscriptionISO.nbEtudiants.value);
			
			if (nbFilles + nbGarcons != nbEtudTotal)
			{
				msg += "The sum of the number of boys students and the number of girls students must be equal to the total number of students.\n";
				nobug = false;
			}
		}
	}
	
	
	
	// COURRIEL DU DIRECTEUR(TRICE)
	if (trim(document.frmInscriptionISO.courrielDirecteur.value) == "")
	{
		msg += "You must enter the principal's e-mail.\n";
		nobug = false;
	}
	else
	{
		value = document.frmInscriptionISO.courrielDirecteur.value;
		
		if ((value.indexOf("@") == -1) || (value.indexOf(".") == -1))
		{ 
			msg += "The principal's e-mail is not valid.\n";
			nobug = false;
		}
		else
		{
			if (trim(document.frmInscriptionISO.courrielDirecteurConfirm.value) == '')
			{
				msg += "You must confirm the principal's e-mail.\n";
				nobug = false;
			}
			else
			{
				if (document.frmInscriptionISO.courrielDirecteur.value != document.frmInscriptionISO.courrielDirecteurConfirm.value)
				{
					msg += "You did not retype the principal's e-mail correctly.\n";
					nobug = false;
				}
			}
		}
	}
	
	
	/*
	// choix ISO-Actif ou Non
	if(document.frmInscriptionISO.iso[0].checked == false && document.frmInscriptionISO.iso[1].checked == false)
	{
		msg += "Vous devez préciser si votre école est certifiée ISO-Actif ou non.\n";
		nobug = false;
	}*/
	
	
	
	
	// PRÉNOM
	if (trim(document.frmInscriptionISO.prenom.value) == '')
	{
		msg += 'You must enter your first name.\n';
		nobug = false;
	}
	
	// NOM
	if (trim(document.frmInscriptionISO.nom.value) == '')
	{
		msg += 'You must enter your last name.\n';
		nobug = false;
	}
	
	
	// FONCTION
	if (trim(document.frmInscriptionISO.fonction.value) == '')
	{
		msg += 'You must enter your function.\n';
		nobug = false;
	}
	
	// COURRIEL
	if (trim(document.frmInscriptionISO.courriel.value) == "")
	{
		msg += "You must enter your e-mail.\n";
		nobug = false;
	}
	else
	{
		value = document.frmInscriptionISO.courriel.value;
		
		if ((value.indexOf("@") == -1) || (value.indexOf(".") == -1))
		{ 
			msg += "The e-mail is not valid.\n";
			nobug = false;
		}
		else
		{
			if (trim(document.frmInscriptionISO.courrielConfirm.value) == '')
			{
				msg += 'You must confirm the e-mail.\n';
				nobug = false;
			}
			else
			{
				if (document.frmInscriptionISO.courriel.value != document.frmInscriptionISO.courrielConfirm.value)
				{
					msg += "You did not retype the e-mail correctly.\n";
					nobug = false;
				}
			}
		}
	}
	
	// TEL. TRAVAIL
	if (trim(document.frmInscriptionISO.tel_travail.value) == '')
	{
		msg += 'You must enter your phone number at work.\n';
		nobug = false;
	}
	
	// NOM D'USAGER (LOGIN)
	if (trim(document.frmInscriptionISO.login.value) == '')
	{
		msg += 'You must enter a username.\n';
		nobug = false;
	}
	
	// MOT DE PASSE 1
	if (trim(document.frmInscriptionISO.password.value) == '')
	{
		msg += 'You must enter a password.\n';
		nobug = false;
	}
	else
	{
		if (trim(document.frmInscriptionISO.password_confirm.value) == '')
		{
			msg += 'You must confirm the password.\n';
			nobug = false;
		}
		else
		{
			if (document.frmInscriptionISO.password.value != document.frmInscriptionISO.password_confirm.value)
			{
				msg += "You did not retype the password correctly.\n";
				nobug = false;
			}
		}
	}
	
	// CONFIRM AUTORISATION ET RESPONSABLE ISO
	if (document.frmInscriptionISO.confirmAutoISO.checked == false)
	{
		msg += 'You must confirm that you have authorization from the school administration to create this account and confirm that you am in charge of the school\'s ISO-Actif file.\n';
		nobug = false;
	}
	
	
	if(nobug == false)
	{
		alert(msg);
	}
	
	
	
	// NOM D'USAGER (LOGIN)
	if (!(trim(document.frmInscriptionISO.login.value) == ''))
	{
		if (nobug == true)
			verifierLogin(document.frmInscriptionISO.login.value);
	}
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////
/// VALIDATION ET SUBMIT - FORM MODIF INFOS PERSO
////////////////////////////////////////////////////////////
function submitFormModifInfosPerso()
{
	var nobug = true;
	var msg = '';
	
	
	// PRÉNOM
	if (trim(document.frmModifInfosPersoISO.prenom.value) == '')
	{
		msg += 'You must enter your first name.\n';
		nobug = false;
	}
	
	// NOM
	if (trim(document.frmModifInfosPersoISO.nom.value) == '')
	{
		msg += 'You must enter your last name.\n';
		nobug = false;
	}
	
	
	// FONCTION
	if (trim(document.frmModifInfosPersoISO.fonction.value) == '')
	{
		msg += 'You must enter your function.\n';
		nobug = false;
	}
	
	// COURRIEL
	if (trim(document.frmModifInfosPersoISO.courriel.value) == "")
	{
		msg += "You must enter your e-mail.\n";
		nobug = false;
	}
	else
	{
		var value = '';
		
		value = document.frmModifInfosPersoISO.courriel.value;
		
		if ((value.indexOf("@") == -1) || (value.indexOf(".") == -1))
		{ 
			msg += "The e-mail is not valid.\n";
			nobug = false;
		}
	}
	
	// TEL. TRAVAIL
	if (trim(document.frmModifInfosPersoISO.tel_travail.value) == '')
	{
		msg += 'You must enter your phone number at work.\n';
		nobug = false;
	}
	
	// NOM D'USAGER (LOGIN)
	if (trim(document.frmModifInfosPersoISO.login.value) == '')
	{
		msg += 'You must enter a username.\n';
		nobug = false;
	}
	
	// MOT DE PASSE 1
	if (trim(document.frmModifInfosPersoISO.password.value) == '')
	{
		msg += 'You must enter a password.\n';
		nobug = false;
	}
	else
	{
		if (trim(document.frmModifInfosPersoISO.password_confirm.value) == '')
		{
			msg += 'You must confirm the password.\n';
			nobug = false;
		}
		else
		{
			if (document.frmModifInfosPersoISO.password.value != document.frmModifInfosPersoISO.password_confirm.value)
			{
				msg += "You did not retype the password correctly.\n";
				nobug = false;
			}
		}
	}
	
	
	if(nobug == false)
	{
		alert(msg);
	}
	
	
	
	// NOM D'USAGER (LOGIN)
	if (!(trim(document.frmModifInfosPersoISO.login.value) == ''))
	{
		if (nobug == true)
			verifierLoginPourModifInfosUsager(document.frmModifInfosPersoISO.login.value , document.frmModifInfosPersoISO.id_usager.value);
	}
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////





////////////////////////////////////////////////////////////
/// VALIDATION ET SUBMIT - FORM STATS PAR ARSE
////////////////////////////////////////////////////////////
function submitFrmChoisirArseStats()
{
	var nobug = true;
	var msg = '';
	
	if (document.frmArseStats.sltQuelArse.value == 'choisir')
	{
		nobug = false;
		msg += 'You must choose a Sport Étudiant regional chapter.';
	}
	
	if (nobug == true)
		document.frmArseStats.submit();
	else
		alert(msg);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////
/// VALIDATION ET SUBMIT - FORM OUBLI INFOS
////////////////////////////////////////////////////////////
function submitFormOubli()
{
	var nobug = true;
	var msg = '';
	
	
	// COURRIEL
	if (trim(document.frmOubli.emailRetrieveInfos.value) == "")
	{
		msg += "You must enter the e-mail address that was used to create your school\'s online ISO-Actif account.\n";
		nobug = false;
	}
	else
	{
		var value = '';
		
		value = document.frmOubli.emailRetrieveInfos.value;
		
		if ((value.indexOf("@") == -1) || (value.indexOf(".") == -1))
		{ 
			msg += "The e-mail address you entered is not valid.\n";
			nobug = false;
		}
	}
	
	if (nobug == true)
		document.frmOubli.submit();
	else
		alert(msg);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////






//////////////////////////////////////////////////////////////////////////////////
/// VALIDATION ET SUBMIT - FORM DE MODIFICATION DU NOMBRE D'ÉTUDIANTS DE L'ÉCOLE
//////////////////////////////////////////////////////////////////////////////////
function submitFormModifNbEtudEcole()
{
	var nobug = true;
	var msg = '';
	
	
	// nombre d'étudiants - Garçons
	var nbGarconsCheck = false;
	if(trim(document.frmModifNbEtudEcole.nbEtudiantsGarcons.value) == '')
	{
		msg += "You must enter your school's number of students (boys).\n";
		nobug = false;
	}
	else if (isNaN(trim(document.frmModifNbEtudEcole.nbEtudiantsGarcons.value)))
	{
		msg += "The  \"School's number of students (boys)\" field must be a number.\n";
		nobug = false;
	}
	else
	{
		var nbGarconsCheck = true;
	}
	
	
	// nombre d'étudiants - Filles
	var nbFillesCheck = false;
	if(trim(document.frmModifNbEtudEcole.nbEtudiantsFilles.value) == '')
	{
		msg += "You must enter your school's number of students (girls).\n";
		nobug = false;
	}
	else if (isNaN(trim(document.frmModifNbEtudEcole.nbEtudiantsFilles.value)))
	{
		msg += "The  \"School's number of students (girls\" field must be a number.\n";
		nobug = false;
	}
	else
	{
		var nbFillesCheck = true;
	}
	
	
	// nombre d'étudiants - Total
	if(trim(document.frmModifNbEtudEcole.nbEtudiants.value) == '')
	{
		msg += "You must enter your school's total number of students.\n";
		nobug = false;
	}
	else if (isNaN(trim(document.frmModifNbEtudEcole.nbEtudiants.value)))
	{
		msg += "The \"School's total number of students\" field must be a number.\n";
		nobug = false;
	}
	else if (trim(document.frmModifNbEtudEcole.nbEtudiants.value) == 0)
	{
		msg += "The \"School's total number of students\" field must be higher than zero.\n";
		nobug = false;
	}
	else
	{
		if (nbGarconsCheck == true && nbFillesCheck == true)
		{
			var nbFilles = parseInt(document.frmModifNbEtudEcole.nbEtudiantsFilles.value);
			var nbGarcons = parseInt(document.frmModifNbEtudEcole.nbEtudiantsGarcons.value);
			var nbEtudTotal = parseInt(document.frmModifNbEtudEcole.nbEtudiants.value);
			
			if (nbFilles + nbGarcons != nbEtudTotal)
			{
				msg += "The sum of the number of boys students and the number of girls students must be equal to the total number of students.\n";
				nobug = false;
			}
		}
	}
	
	
	if(nobug == false)
	{
		alert(msg);
	}
	else
	{
		document.frmModifNbEtudEcole.submit();
	}
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
