function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateNom(theForm.realname);
  reason += validateEmail(theForm.email);
  //reason += validateMessage(theForm.Message);
      
  if (reason != "") {
    alert("Erreur! Veuillez corriger les champs suivants:\n" + reason);
    return false;
  }

  return true;
}

function validateNom(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFEDD';
		fld.style.border = '1px solid #990000';
        error = "Veuillez entrer votre nom complet.\n"
    } else {
        fld.style.background = '#FFF';
		fld.style.border = '1px solid #A5ACB2';
    }
    return error;  
}

/*function validateMessage(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#FFFEDD';
		fld.style.border = '1px solid #990000';
        error = "Veuillez composer un message.\n"
    } else {
        fld.style.background = '#E2E8EC';
		fld.style.border = '1px solid #40617B';
    }
    return error;  
}*/


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#FFFEDD';
		fld.style.border = '1px solid #990000';
        error = "Veuillez entrer une adresse courriel valide.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFFEDD';
		fld.style.border = '1px solid #990000';
        error = "L'adresse courriel n'est pas valide.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFFEDD';
		fld.style.border = '1px solid #990000';
        error = "L'adresse courriel contient des caractères illégaux.\n";
    } else {
        fld.style.background = '#E2E8EC';
		fld.style.border = '1px solid #40617B';
    }
    return error;
}