function SyntaxeEmail(sMail)
{
var re=/^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi;
return (sMail.match(re)==sMail)&&(sMail.substr(sMail.lastIndexOf("@")).length<=256);
}
/*-- Vérifie que le Top Level Domain existe ------------------------------------
Passer le courriel en entier. Attention les, ".eu" sont notés !
La liste est à jour (jeudi 19 janvier 2006) et en avance pour les ".eu"
var re= ... $/gi; doit être sur une seule ligne.
(enlever les retour chariot, mis ici pour la présentation)
------------------------------------------------------------------------------*/
function DomainTLD(sMail)
{
var re=/^(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|aero|arpa|biz|com|coop|edu|eu|gov|info|int|mil|museum|name|net|org|pro|jobs|travel)$/gi;
return sMail.substr(sMail.lastIndexOf(".") + 1).match(re)!=null;
}

function check_mail() {
	//alert(document.form.mail.value);
	if (!SyntaxeEmail(document.form.mail.value)) {
       	document.form.mail.style.backgroundColor='red';
		alert("Votre mail est incorrect.\nVeuillez le vérifier.");
       	document.form.mail.focus();
      	return false;
    }
   	if (!DomainTLD(document.form.mail.value)) {
       	document.form.mail.style.backgroundColor='red';
       	alert("Votre mail est incorrect.\nVeuillez vérifier le nom de domaine.");
       	document.form.mail.focus();
      	return false;
	}
}

function check_fields() {
	var f = 0;
	if (document.form.mail.value == "") {
       	document.form.mail.style.backgroundColor='red';		
	    document.form.mail.focus();	
		f++;
	}
	if (document.form.prenom.value == "") {
       	document.form.prenom.style.backgroundColor='red';		
	    document.form.prenom.focus();	
		f++;
	}
	if (document.form.nom.value == "") {
       	document.form.nom.style.backgroundColor='red';		
	    document.form.nom.focus();	
		f++;
	}
	if (document.form.tel.value == "" || check_phone(document.form.tel.value)==false) {
       	document.form.tel.style.backgroundColor='red';		
	    document.form.tel.focus();	
		f++;
	}
	if (document.form.activite.value == "") {
       	document.form.activite.style.backgroundColor='red';		
	    document.form.activite.focus();	
		f++;
	}
	if (document.form.question.value == "") {
       	document.form.question.style.backgroundColor='red';		
	    document.form.question.focus();	
		f++;
	}
	if (document.form.statut[0].checked == document.form.statut[1].checked) {
       	alert("Merci de préciser votre statut");
		f++;
	}
	
	if (f != 0) {
		return false;
	}
}

function check_phone(num_tel)
{
	// Definition du motif a matcher
	var regex = new RegExp(/^(01|02|03|04|05|06|08)[0-9]{8}/gi);
	
	// Definition de la variable booleene match
	var match = false;
	
	// Test sur le motif
	if(regex.test(num_tel))
	{
		match = true;
	}
	  else
	{
		match = false;
	}
	
	// On renvoie match
	return match;
}


function check_all() {
if (check_fields() == false) { return false; }
if (check_mail() == false) { return false; }
return true;
}



