function valid(champ,nomchamp)
{
   str=champ.value;
   if (str == "")
   {
      alert("Danke für completer das Feld \""+ 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("Gebrechliches Email."); 
      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("Der Tag ist nicht richtig.");
         champdate.focus();
         return(false);
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) )
      {
         alert("Der Monat ist nicht richtig.");
         champdate.focus();
         return(false);
      }
      if ( (isNaN(a)) && (ok==1) ) 
      {
         alert("Das Jahr ist nicht richtig.");
         champdate.focus();
         return(false);
      }

      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) 
      {
         alert("Die Halmabweiser sollen sein "+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("Dieser Datum existiert nicht !");
         champdate.focus();
         return(false);
      }
      else return(true);
}



function isNombre(champnb)
{
   nb=champnb.value;
   if (!(isNaN(nb))) return true;
   else
   {
        alert("Sie sollen eine Zahl erfassen.");
        champnb.focus();
        return(false);
   }
   return(true);
}



function validation_reservation(theform)
{
  return (
    valid(theform.nom,"Name") &&
    valid(theform.prenom,"Vorname") &&
    valid(theform.adresse,"Adresse") &&
    valid(theform.cp,"PLZ") &&
    valid(theform.ville,"Stadt") &&
    valid(theform.pays,"Land") &&
    valid(theform.tel,"Telefon") &&
    valid(theform.email,"E-mail") &&
    validemail(theform.email) && 
    valid(theform.arrivee,"Ankunft") &&
    isDate(theform.arrivee) &&
    valid(theform.nuits,"Anzahl der Übernachtungen") &&
    isNombre(theform.nuits) &&
    valid(theform.personnes,"Anzahl der Personen") &&
    isNombre(theform.personnes)
   );
}

function validation_demande_devis(theform)
{
  return (
    valid(theform.gesellschaft,"gesellschaft") &&
	valid(theform.name,"name") &&
    valid(theform.vorname,"vorname") &&
    valid(theform.telefon,"telefon") &&
    valid(theform.email,"E-mail") &&
    validemail(theform.email) && 
    valid(theform.personen,"zahl von personen") &&
    isNombre(theform.personen) &&
    valid(theform.datum,"Datum oder die gewänschte periode")
   );
}
