// JavaScript Document
function SubmitForm() {
		var strNom=document.form_email.txtNom.value;
		var strPrenom=document.form_email.txtPrenom.value;
		var strMessage=document.form_email.txtMessage.value;
		var strEmail=CheckMail();
		var objType=document.form_email.rbType;
		var strType="";
		var strTypeAutre=document.form_email.txtTypeAutre.value;
		
		var bolError = 0;
		var strErrorMessage = "Veuillez corriger le(s) point(s) suivant(s) :\n\n";
	
		// Validation des champs
		if (strNom=="") {strErrorMessage += "- Le champ \"nom\" est vide\n";bolError = 1;}
		if (strPrenom=="") {strErrorMessage += "- Le champ \"prenom\" est vide\n";bolError = 1;}
		if(objType[3].checked == true){
			if(strTypeAutre == "") {strErrorMessage += strType +"- Veuillez préciser le champ \"Autres\"\n";bolError = 1;}
		}
		if (strMessage=="") {strErrorMessage += "- Le champ \"Message\" est vide\n";bolError = 1;}
		if(strEmail!=""){strErrorMessage += strEmail + "\n";bolError = 1;}
		// Envoi du résultat
		if(bolError == 0) {return true;}
		else {alert(strErrorMessage); return false;}
}

function CheckMail() {

		var emailStr=document.form_email.email.value
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr.match(emailPat)
		var $resultat = "";
		if (matchArray==null) {
		  /* Too many/few @'s or something; basically, this address doesn't
			 even fit the general mould of a valid e-mail address. */
			$resultat = "- L'adresse Email est incorrecte !!"
			return $resultat
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		
		// See if "user" is valid 
		if (user.match(userPat)==null) {
			// user is not valid
			$resultat = "- Le nom d'utilisateur de l'adresse email n'est pas valide !!"
			return $resultat
		}
		
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		   host name) make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			// this is an IP address
			  for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					$resultat = "- L'adresse IP de l'adresse email renseignée n'est pas valide !!"
				return $resultat
				}
			}
			return $$resultat
		}
		
		// Domain is symbolic name
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			$resultat  = "- Le nom de domaine de l'adresse email renseignée n'est pas valide !!"
			return $resultat
		}
		
		/* domain name seems valid, but now make sure that it ends in a
		   three-letter word (like com, edu, gov) or a two-letter word,
		   representing country (uk, nl), and that there's a hostname preceding 
		   the domain or country. */
		
		/* Now we need to break up the domain to get a count of how many atoms
		   it consists of. */
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
		   // the address must end in a two letter or three letter word.
		   $resultat  = "- L'extension de l'adresse email est incorrecte !!"
		   return $resultat
		}
		
		// Make sure there's a host name preceding the domain.
		if (len<2) {
		   $resultat = "- L'adresse email est incorrecte gars!!"
		   return $resultat
		}
		
		// If we've gotten this far, everything's valid!
		return $resultat;
}