// JavaScript Document
function champVide(msg,nom){
	if((nom.value.length < 1) || (nom.value.length > 250)){
		alert(msg);
		return false;
	}
	return true;
}
function textareaVide(msg,nom){
	if((nom.value.length < 5) || (nom.value.length > 2000)){
		alert(msg);
		return false;
	}
	return true;
}
function verif_courriel(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if (str.indexOf(" ")!=-1){
		return false;
	}
	return true;
}
function tel(selection,prochain){
	if(document.getElementById(selection).value.length >= 3){
		var next = document.getElementById(prochain);
		next.focus();
	}
}

function vInscription(benevoles){
	var form = eval("document."+benevoles);
	var str_courriel = (document.benevoles.courriel.value);
	
	if((champVide("Vous devez inscrire votre nom.",form.nom))&&
	   (champVide("Vous devez inscrire pr\351nom.",form.prenom))&&
	   (champVide("Vous devez inscrire votre date de naissance.",form.jour))&&
	   (champVide("Vous devez inscrire votre date de naissance.",form.mois))&&
	   (champVide("Vous devez inscrire votre date de naissance.",form.annee))&&
	   (champVide("Vous devez inscrire votre nationalit\351.",form.nationalite))&&
	   (champVide("Vous devez inscrire votre adresse postale.",form.adresse))&&
	   (champVide("Vous devez inscrire votre ville.",form.ville))&&
	   (champVide("Vous devez inscrire votre province ou d\351partement.",form.province))&&
	   (champVide("Vous devez inscrire votre pays.",form.pays))&&
	   (champVide("Vous devez inscrire votre num\351ro de t\351l\351phone.",form.telA))&&
	   (champVide("Vous devez inscrire votre num\351ro de t\351l\351phone.",form.telB))&&
	   (champVide("Vous devez inscrire votre num\351ro de t\351l\351phone.",form.telC))&&
	   (champVide("Vous devez inscrire votre courriel.",form.courriel))&&
	   (champVide("Vous devez inscrire votre langue maternelle.",form.langue_maternelle))
	   ){
			var total=0;
			for(var i=0; i <= 19; i++){
				if(document.getElementById('secteurs'+i).checked == true){
					total =total +1;
				}
			}
			if(total == 0){
					alert("Veuillez cocher au moins un secteur qui vous int\351resse.");
					return false;
			}
			
			if((champVide("Vous devez inscrire votre disponibilité avant le Moot.",form.avant_moot))&&
				(champVide("Vous devez inscrire votre disponibilité pendant le Moot.",form.pendant_moot))&&
				(champVide("Vous devez inscrire votre disponibilité apr\350s le Moot.",form.apres_moot))){
				if(verif_courriel(str_courriel)){
					form.submit();  	
				}else{
					alert("Votre adresse courriel ne semble pas valide.");
					return false;
				}
			}
	}
	return false;
}
function vInscription_en(volunteers){
	var form = eval("document."+volunteers);
	var str_courriel = (document.volunteers.courriel.value);
	
	if((champVide("Please enter your last name.",form.nom))&&
	   (champVide("Please enter your first name.",form.prenom))&&
	   (champVide("Please enter your date of birth.",form.jour))&&
	   (champVide("Please enter your date of birth.",form.mois))&&
	   (champVide("Please enter your date of birth.",form.annee))&&
	   (champVide("Please enter your nationality.",form.nationalite))&&
	   (champVide("Please enter your mailling address.",form.adresse))&&
	   (champVide("Please enter your city.",form.ville))&&
	   (champVide("Please enter your province or department.",form.province))&&
	   (champVide("Please enter your country.",form.pays))&&
	   (champVide("Please enter your telephone.",form.telA))&&
	   (champVide("Please enter your telephone.",form.telB))&&
	   (champVide("Please enter your telephone.",form.telC))&&
	   (champVide("Please enter your e-mail.",form.courriel))&&
	   (champVide("Please enter your mother tongue.",form.langue_maternelle))
	   ){
			var total=0;
			for(var i=0; i <= 19; i++){
				if(document.getElementById('secteurs'+i).checked == true){
					total =total +1;
				}
			}
			if(total == 0){
					alert("Please check at least one area you are interested in.");
					return false;
			}
			
			if((champVide("Please indicate your availability before the Moot.",form.avant_moot))&&
				(champVide("Please indicate your availability during the Moot.",form.pendant_moot))&&
				(champVide("Please indicate your availability after the Moot.",form.apres_moot))){
				if(verif_courriel(str_courriel)){
					form.submit();  	
				}else{
					alert("Please enter a valid email address.");
					return false;
				}
			}
	}
	return false;
}
function vInscription_es(voluntarios){
	var form = eval("document."+voluntarios);
	var str_courriel = (document.voluntarios.courriel.value);
	
	if((champVide("Por favor, introduzca su apellido.",form.nom))&&
	   (champVide("Por favor ingrese su nombre de pila.",form.prenom))&&
	   (champVide("Por favor, introduzca su fecha de nacimiento.",form.jour))&&
	   (champVide("Por favor, introduzca su fecha de nacimiento.",form.mois))&&
	   (champVide("Por favor, introduzca su fecha de nacimiento.",form.annee))&&
	   (champVide("Por favor, introduzca su nacionalidad.",form.nationalite))&&
	   (champVide("Por favor, introduzca su dirección de mailling.",form.adresse))&&
	   (champVide("Por favor, introduzca su ciudad.",form.ville))&&
	   (champVide("Por favor, introduzca su provincia o departamento.",form.province))&&
	   (champVide("Por favor, introduzca su país.",form.pays))&&
	   (champVide("Por favor, introduzca su teléfono.",form.telA))&&
	   (champVide("Por favor, introduzca su teléfono.",form.telB))&&
	   (champVide("Por favor, introduzca su teléfono.",form.telC))&&
	   (champVide("Por favor, introduzca su dirección de e-mail.",form.courriel))&&
	   (champVide("Por favor, introduzca su lengua materna.",form.langue_maternelle))
	   ){
			var total=0;
			for(var i=0; i <= 19; i++){
				if(document.getElementById('secteurs'+i).checked == true){
					total =total +1;
				}
			}
			if(total == 0){
					alert("Marque al menos una zona en la que está interesado pulg.");
					return false;
			}
			
			if((champVide("Por favor, indique su disponibilidad ante el Concurso.",form.avant_moot))&&
				(champVide("Por favor, indique su disponibilidad en el Concurso.",form.pendant_moot))&&
				(champVide("Por favor, indique su disponibilidad después del Moot.",form.apres_moot))){
				if(verif_courriel(str_courriel)){
					form.submit();  	
				}else{
					alert("Por favor, introduzca una dirección de correo electrónico válida.");
					return false;
				}
			}
	}
	return false;
}
function vInscription_infolettre(name){
	var form = eval("document."+name);
	var str_courriel = eval("document."+name+".courriel_infolettre.value");
	
	if(verif_courriel(str_courriel)){
		form.submit();  	
	}else{
		alert("Votre adresse courriel ne semble pas valide.");
		return false;
	}
}
function vInscription_infolettre_en(name){
	var form = eval("document."+name);
	var str_courriel = eval("document."+name+".courriel_infolettre.value");
	
	if(verif_courriel(str_courriel)){
		form.submit();  	
	}else{
		alert("Please enter a valid email address.");
		return false;
	}
}
function vInscription_infolettre_es(name){
	var form = eval("document."+name);
	var str_courriel = eval("document."+name+".courriel_infolettre.value");
	
	if(verif_courriel(str_courriel)){
		form.submit();  	
	}else{
		alert("Por favor, introduzca una dirección de correo electrónico válida.");
		return false;
	}
}
