function valid(champ,nomchamp)
{
   str=champ.value;
   if (str == "")
   {
      alert("Please enter a value for the field \""+ nomchamp +"\"");
      champ.focus();
      return(false);
   }
   return true;
}



function validemail(champ)
{
   str=champ.value;
   var format_email=new RegExp("^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$","g");
   if ( !format_email.test(str) )
   {
      alert("No valid Email address."); 
      champ.focus();
      return(false);       
   }
   return true;
}



function isDate(champdate) 
{
      // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
      // Le séparateur est défini dans la variable separateur

      d=champdate.value;

      var separateur="/"; 
      var j=d.substring(0,2);
      var m=d.substring(3,5);
      var a=d.substring(6);
      var ok=1;

      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) )
      {
         alert("The day is not correct.");
         champdate.focus();
         return(false);
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) )
      {
         alert("The month is not correct.");
         champdate.focus();
         return(false);
      }
      if ( (isNaN(a)) && (ok==1) ) 
      {
         alert("The year is not correct.");
         champdate.focus();
         return(false);
      }

      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) 
      {
         alert("Separators have to be "+separateur);
         champdate.focus();
         return(false);
      }

      var d2=new Date(a,m-1,j);
      j2=d2.getDate();
      m2=d2.getMonth()+1;
      a2=d2.getYear();
      if (a2<=100) {a2=1900+a2}
      if ( (j!=j2)||(m!=m2)||(a!=a2) ) 
      {
         alert("This date does not exist !");
         champdate.focus();
         return(false);
      }
      else return(true);
}



function isNombre(champnb)
{
   nb=champnb.value;
   if (!(isNaN(nb))) return true;
   else
   {
        alert("Please enter a number.");
        champnb.focus();
        return(false);
   }
   return true;
}



function validation_reservation(theform)
{
  return (
    valid(theform.nom,"Name") &&
    valid(theform.prenom,"Surname") &&
    valid(theform.adresse,"Address") &&
    valid(theform.cp,"City code") &&
    valid(theform.ville,"City") &&
    valid(theform.pays,"Country") &&
    valid(theform.tel,"Phone") &&
    valid(theform.email,"Email") &&
    validemail(theform.email) && 
    valid(theform.arrivee,"Arrival date") &&
    isDate(theform.arrivee) &&
    valid(theform.nuits,"Nights") &&
    isNombre(theform.nuits) &&
    valid(theform.personnes,"Number") &&
    isNombre(theform.personnes)
   );
}

function validation_demande_devis(theform)
{
  return (
    valid(theform.company,"Company") &&
	valid(theform.name,"Name") &&
    valid(theform.firstname,"First name") &&
    valid(theform.phone,"Phone") &&
    valid(theform.email,"Email") &&
    validemail(theform.email) && 
    valid(theform.people,"Number of people") &&
    isNombre(theform.people) &&
    valid(theform.dates,"Dates of stay")
   );
}