// JavaScript Document
//check a text feild for content
function checkfeild(strng, stmnt){
	if(strng == ""){
			return stmnt;
	}else{
			return "";
	}
}

//check email feild
function checkemail(strng, xVar){
var stmnt = "";
var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		   stmnt = xVar+"Votre adresse électronique n’est pas valide.\n";
	}
	
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) {
	   stmnt += xVar+"Votre adresse électronique contient des caractères qui ne sont pas permis.\n";	
	}
	
	if(stmnt != ""){
		return stmnt;
	}else{
			return "";
	}
}

//check checkbox
function checkcheck(frmVar, stmnt){
	
	if(!frmVar.checked){
		return stmnt;
	}else{
		return "";
	}
	
}

//########### Validate Form
function fValidate(){	
	
	var error = "";
	var path = document.sbmtevt;	

//###############################################################################################################################
error += checkfeild(path.name.value, "Veuillez entrer votre nom.\n"); 							// name
error += checkemail(path.email.value, ""); 												//email
error += checkcheck(path.agree, "Vous devez accepter les modalités d’utilisation.");
//###############################################################################################################################

	if(error != ""){
		alert(error);
	}else{
	
		path.action = "email/submit_event.email.php";
		path.submit();

	}	
	
}
