function valid(champ,nomchamp)
{
   str=champ.value;
   if (str == "")
   {
      alert("Merci de saisir une valeur pour le champ \""+ 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("Adresse email invalide."); 
      champ.focus();
      return(false);       
   }
   return true;
}

/*
function validemail(champ)
{
  str= champ.value;
  if (str != "")
  {
     if (str.indexOf('@',0) == -1)
     {      
        alert("Adresse email invalide.");
        champ.focus();
        return(false);
     }
     if (str.indexOf('.',0) == -1)
     { 
        alert("Adresse email invalide.");
        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("Le jour n'est pas correct.");
         champdate.focus();
         return(false);
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) )
      {
         alert("Le mois n'est pas correct.");
         champdate.focus();
         return(false);
      }
      if ( (isNaN(a)) && (ok==1) ) 
      {
         alert("L'année n'est pas correcte.");
         champdate.focus();
         return(false);
      }

      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) 
      {
         alert("Les séparateurs doivent être des "+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("Cette date n'existe pas !");
         champdate.focus();
         return(false);
      }
      else return(true);
}



function isNombre(champnb)
{
   nb=champnb.value;
   if (!(isNaN(nb))) return true;
   else
   {
        alert("Vous devez saisir un nombre.");
        champnb.focus();
        return(false);
   }
   return(true);
}



function validation_reservation(theform)
{
  return (
    valid(theform.nom,"Nom") &&
    valid(theform.prenom,"Prénom") &&
    valid(theform.adresse,"Adresse") &&
    valid(theform.cp,"Code postal") &&
    valid(theform.ville,"Ville") &&
    valid(theform.pays,"Pays") &&
    valid(theform.tel,"Téléphone") &&
    valid(theform.email,"Email") &&
    validemail(theform.email) && 
    valid(theform.arrivee,"Date arrivée") &&
    isDate(theform.arrivee) &&
    valid(theform.nuits,"Nombre de nuits") &&
    isNombre(theform.nuits) &&
    valid(theform.personnes,"Nombre de personnes") &&
    isNombre(theform.personnes)
   );
}

function validation_demande_devis(theform)
{
  return (
    valid(theform.societe,"Société") &&
	valid(theform.nom,"Nom") &&
    valid(theform.prenom,"Prénom") &&
    valid(theform.tel,"Téléphone") &&
    valid(theform.email,"Email") &&
    validemail(theform.email) && 
    valid(theform.personnes,"Nombre de personnes") &&
    isNombre(theform.personnes) &&
    valid(theform.dateperiode,"Date ou période souhaitée")
   );
}