// Quelque functions pour la validation des form
// 
function checkContactForm(theForm, langue) {
    var why = "";

	// Check mandatory fields
	if (langue == "EN") {
		//why += isVide(theForm.name.value, "Nom", langue);	
		why += isVide(theForm.name.value, "First Name", langue);	
		why += checkCourriel(theForm.email.value,langue);
		why += isVide(theForm.subject.value, "Subject", langue);	
		why += isVide(theForm.message.value, "Message", langue);	
		
		
				
	} else {
		
		why += isVide(theForm.name.value, "Nom", langue);	
		why += checkCourriel(theForm.email.value,langue);
		why += isVide(theForm.subject.value, "Sujet", langue);	
		why += isVide(theForm.message.value, "Message", langue);
		
			
	}

	if (why != "") {
	
       alert(why);
       return false;
    }
	
return true;
}

function checkFanForm(theForm, langue) {
    var why = "";

	// Check mandatory fields
	if (langue == "EN") {
		why += isVide(theForm.name.value, "First Name", langue);	
		why += checkCourriel(theForm.email.value,langue);
		why += isVide(theForm.subject.value, "Subject", langue);	
		
				
	} else {
		
		why += isVide(theForm.name.value, "Nom", langue);	
		why += checkCourriel(theForm.email.value,langue);
		why += isVide(theForm.subject.value, "Sujet", langue);	
			
	}

	if (why != "") {
	
       alert(why);
       return false;
    }
	
return true;
}

function checkAlertForm(theForm, langue) {
    var why = "";

	// Check mandatory fields
	if (langue == "FR") {
		
		why += checkCourriel(theForm.email.value,langue);
		why += isVide(theForm.event.value, "Evenement", langue);	
		
				
	} else {
		
		why += checkCourriel(theForm.email.value,langue);
		why += isVide(theForm.event.value, "Event Name", langue);	
			
	}

	if (why != "") {
	
       alert(why);
       return false;
    }
	
return true;
}

function isVide(strng, fieldname, langue) {
var error = "";
  if (strng.length == 0) {
	  if (langue == "FR")
		{
			error = "Le champ obligatoire " + fieldname + " n'a pas été saisie.\n";
		}
		else
		{
			error = "The mandatory text area " + fieldname + " has not been filled in.\n";
		}
     
  }
return error;	  
}


function checkCourriel (strng,langue) {
var error="";
if (strng == "") {
	if (langue == "FR")
	{
		error = "Vous devez saisir une adresse de courriel.\n";
	}
	else
	{
		error = "You didn't enter an email address.\n";
	}
   
}
else {
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
		if (langue == "FR")
		{
			error = "Vous devez saisir une adresse de courriel valide.\n";
		}
		else
		{
			error = "Please enter a valid email address.\n";
		}

    }
    else {
		//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          	if (langue == "FR")
			{
				error = "Vous devez saisir une adresse de courriel valide.\n";
			}
			else
			{
				error = "Please enter a valid email address.\n";
			}
       }
    }
}
return error;    
}
