
function checkForm(form)
{
//return alert("Vous avez saisi le pseudo : " + document.getElementById("registration").elements["login"].value);

  if(!checkStrLength(form.last_name.value, 2, 25))
  {
    form.last_name.style.backgroundColor = "#fba";
    alert("Le nom n'est pas valide.");
    return false;
  }

  if(!checkStrLength(form.first_name.value, 2, 25))
  {
    form.first_name.style.backgroundColor = "#fba";
    alert("Le prénom n'est pas valide.");
    return false;
  }

  if(!checkMail(form.email.value))
  {
    form.email.style.backgroundColor = "#fba";
    alert("L'email n'est pas valide.");
    return false;
  }

  if(!checkNbLength(form.year.value, 4))
  {
    form.year.style.backgroundColor = "#fba";
    alert("L'année n'est pas valide.");
    return false;
  }

  if(!checkEmpty(form.address.value))
  {
    form.address.style.backgroundColor = "#fba";
    alert("Veuillez entrer votre adresse.");
    return false;
  }

  if(!checkNbLength(form.code.value, 5))
  {
    form.code.style.backgroundColor = "#fba";
    alert("Le code postal n'est pas valide.");
    return false;
  }

  if(!checkStrLength(form.city.value, 2, 25))
  {
    form.city.style.backgroundColor = "#fba";
    alert("Le nom de la ville n'est pas valide.");
    return false;
  }

  if(!checkTel(form.tel_1.value))
  {
    form.tel_1.style.backgroundColor = "#fba";
    alert("Le numéro de téléphone n'est pas valide.");
    return false;
  }

  if(!checkEmpty(form.message.value))
  {
    form.message.style.backgroundColor = "#fba";
    alert("Veuillez rédiger votre message.");
    return false;
  }
}

////////// FONCTIONS DE VERIFICATION ////////////////////////

function checkMail(value)
{
  var regex = /^[a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/;
    // Utilise la méthode test(str) de l'objet RegExp
    if(!regex.test(value))
      return false;
    else
      return true;
}

//Fonction générique qui vérifie si le champ contient au 
//minimum min caractères et au maximum max caractères
function checkStrLength(value, min, max)
{
   if(value.length < min || value.length > max)
      return false;
   else
      return true;
}

//Fonction générique qui vérifie si le champ contient un
//nombre d'une longueur length.
function checkNbLength(value, length)
{
  //Pour insérer une variable dans une regex, il
  //faut utiliser l'objet RegExp.
  var regex = new RegExp('^[0-9]{'+length+'}$');

   if(!regex.test(value))
      return false;
   else
      return true;
}


function checkStrCompare(str1, str2)
{
   if(str1 != str2)
      return false;
   else
      return true;
}

//Vérifie la validité d'un numéro de téléphone (en France)
function checkTel(value)
{
  var regex = /^(0[1-68])(?:[ _.-]?(\d{2})){4}$/;

  if(!regex.test(value))
    return false;
  else
    return true;
}


function checkEmpty(value)
{
  if(value == '')
    return false;
  else
    return true;
}

