// JavaScript Document

// VALIDATION FORMULAIRE
function champVide(msg,nom){
	if((nom.value.length < 1) || (nom.value.length > 200)){
		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 vInfolettre(name){
	var form = eval("document."+name);
	var str_courriel = eval("document."+name+".courriel.value");

	if(verif_courriel(str_courriel)){
		form.submit();  
	}else{
		alert("L'adresse courriel ne semble pas valide.");  
    }
}
function vReactivations(name){
	var form = eval("document."+name);
	var str_courriel = eval("document."+name+".courriel.value");
	
	if((champVide("Vous devez inscrire votre nom.",form.nom))&&
	   (champVide("Vous devez inscrire votre adresse.",form.adresse))&&
	   (champVide("Vous devez inscrire votre ville.",form.ville))&&
	   (champVide("Vous devez choisir votre province.",form.province))&&
	   (champVide("Vous devez inscrire votre code postal.",form.code_postal))&&
	   (champVide("Vous devez inscrire votre t\351l\351phone.",form.telephone1))&&
	   (champVide("Vous devez inscrire votre t\351l\351phone.",form.telephone2))&&
	   (champVide("Vous devez inscrire votre tél\351phone.",form.telephone3))&&
	   (champVide("Vous devez inscrire votre \342ge.",form.age))&&
	   (champVide("Vous devez inscrire votre distance \340 parcourir.",form.km_jour))&&
	   (champVide("Vous devez inscrire votre engagement par semaine.",form.fois_semaine))&&
	   (champVide("Vous devez inscrire le m\351dium qui vous a incit\351 \340 vous r\351inscrire.",form.medium))){
	   
	   if(verif_courriel(str_courriel)){
		   if(form.courriel.value != form.courriel2.value){
			 alert("Votre courriel et votre courriel de confirmation doit \352tre le m\352me.");  
		   }else{
				form.submit();   
		   }
	   }else{
		   alert("Vous devez entrer un format de courriel valide.");
	   }
	}
}
function vActivations(name){
	var form = eval("document."+name);
	if((champVide("Vous devez inscrire votre nom.",form.m_nom))&&
	   (champVide("Vous devez votre No de membre.",form.m_numero))){
		form.submit();
	}
}
function vInscriptions(name){
	var form = eval("document."+name);
	var str_courriel = eval("document."+name+".courriel.value");
	
	if((champVide("Vous devez inscrire votre nom.",form.nom))&&
	   (champVide("Vous devez inscrire votre adresse.",form.adresse))&&
	   (champVide("Vous devez inscrire votre ville.",form.ville))&&
	   (champVide("Vous devez choisir votre province.",form.province))&&
	   (champVide("Vous devez inscrire votre code postal.",form.code_postal))&&
	   (champVide("Vous devez inscrire votre t\351l\351phone.",form.telephone1))&&
	   (champVide("Vous devez inscrire votre t\351l\351phone.",form.telephone2))&&
	   (champVide("Vous devez inscrire votre tél\351phone.",form.telephone3))&&
	   (champVide("Vous devez inscrire votre \342ge.",form.age))&&
	   (champVide("Vous devez inscrire votre distance \340 parcourir.",form.km_jour))&&
	   (champVide("Vous devez inscrire votre engagement par semaine.",form.fois_semaine))&&
	   (champVide("Vous devez inscrire le m\351dium qui vous a incit\351 \340 vous inscrire.",form.medium))){
	   
	   if(verif_courriel(str_courriel)){
		   if(form.courriel.value != form.courriel2.value){
			 alert("Votre courriel et votre courriel de confirmation doit \352tre le m\352me.");  
		   }else{
				form.submit();   
		   }
	   }else{
		   alert("Vous devez entrer un format de courriel valide.");
	   }
	}
}

