function TrouverEtDonnerValDeCeChamp_Cplx(LeFormulaire,NomChamp,I_,Idx_,Typ_,Name_,Val_)
{
  var I = 0;
  var Nom = null;
  var Val = null;
  var Typ = null;
  var Id = 0;
  //var Fiche = window.document.Fiche;
  var Fiche = LeFormulaire;
  for (I=0; I < /*window.document.*/Fiche.elements.length; I++)
  {
    Typ = /*window.document.*/Fiche.elements[I].type;
    Nom = /*window.document.*/Fiche.elements[I].name;
    Val = /*window.document.*/Fiche.elements[I].value;//Value marche pas pour les Type "select"
    if (/*(Typ == "select") ||*/ (Typ == "select-one"))//"select" semble etre ignoré sous netscape, mais pas "select-one"...
    {
      Id = /*window.document.*/Fiche.elements[I].index;
      //if (I >= 2) alert("FICHE='"+Fiche.name+"':Le Nom='"+NomChamp+"'. Nbr.Elem='"+I+"/"+window.document.Fiche.elements.length+"'. Id = '"+Id+"'. Typ='"+Typ+"'. Nom='"+Nom+"'. Val='"+Val+"'.");
      if (Id >= 0) Val = /*window.document.*/Fiche.elements[I].options[Id].value;
    }
    //if (I >= 02) alert("Fiche='"+Fiche.name+"':Le Nom='"+NomChamp+"'. Nbr.Elem='"+I+"/"+window.document.Fiche.elements.length+"'. Id = '"+Id+"'. Typ='"+Typ+"'. Nom='"+Nom+"'. Val='"+Val+"'.");
   I_ = I;
   Idx_ = Id;
   Typ_ = Typ;
   Name_ = Nom;
   Val_ = Val;
    if (Nom == NomChamp) return(Val);
  }
  I_ = I;
  Idx_ = Id;
  Typ_ = Typ;
  Name_ = Nom;
  Val_ = Val;

  return(null);
}

function TrouverEtDonnerValDeCeChamp(LeFormulaire,NomChamp)
{
  var I = 0;
  var Nom = null;
  var Val = null;
  var Typ = null;
  var Id = 0;

  return(TrouverEtDonnerValDeCeChamp_Cplx(LeFormulaire,NomChamp,I,Id,Typ,Nom,Val));
}


function CeChampEstOk(LeChamp,NomDuChamp)
{
  /*
  Cette fonction Vérifie la validitée de la valeur d'un champ.
    Comme les champs Nom,Prenom,Sexe,NaisJj,NaisMm, et NaisAaaa
    peuvent etre soit des "Text" soit des "Select"
    La récupération de leur valeur peut varier suivant leur type.
    Cette fonction fait le distingo : tout cela dépend si CodeKms ou non
  */
  /*var Kms = document.ajout_ins.kms.value;    //c'est le deb du code kms
  var code = document.ajout_ins.code.value;  //c'est la fin du code kms
  var codeKms = KMS+'-'+CODE ;*/

  var NomChamp_msg = "";   
 
	 if (NomDuChamp == "sexe") NomChamp_msg = "SEXE";
  if (NomDuChamp == "nom") NomChamp_msg = "NOM";
  if (NomDuChamp == "prenom") NomChamp_msg = "PRENOM";
  if (NomDuChamp == "jour") NomChamp_msg = "JOUR DE NAISSANCE";
  if (NomDuChamp == "mois") NomChamp_msg = "MOIS DE NAISSANCE";
  if (NomDuChamp == "an") NomChamp_msg = "ANNEE DE NAISSANCE";
  Val = TrouverEtDonnerValDeCeChamp(document.ajout_ins,NomDuChamp)

  if (Val == "")
  {
    alert("Veuillez saisir votre "+NomChamp_msg);
    LeChamp.focus();
    return (false);
  }
  if ((NomDuChamp == "nom") || (NomDuChamp == "prenom"))
  {
    if ((Val.length < 2) || (Val.length > 40))
    {
      alert(NomChamp_msg+":'"+Val+"'\nTaille incorrecte.");
      LeChamp.focus();
      return (false);
    }
    if (!UnNomPropre(Val))
    {
      alert(NomChamp_msg+":'"+Val+"'\nValeur  incorrecte.");
      LeChamp.focus();
      return (false);
    }
    return (true);
  }//Nom,Prenom
  
  if ( (NomDuChamp == "jour") || (NomDuChamp == "mois")  || (NomDuChamp == "an") )
  {
    if ((Val.length < 2) || (Val.length > 4))
    {
      alert(NomChamp_msg+" incorrecte.");
      LeChamp.focus();
      return (false);
    }

    if (!UnEntier(Val))
    {
      alert(NomChamp_msg+" incorrecte.");
      LeChamp.focus();
      return (false);
    }
  
   if ( (NomDuChamp == "jour") && ( (Val<1) || (Val>31) ) )
    {
      alert(NomChamp_msg+" incorrecte.");
      LeChamp.focus();
      return (false);
    }

   if ( (NomDuChamp == "mois") && ( (Val<1) || (Val>31) ) )
    {
      alert(NomChamp_msg+" incorrecte.");
      LeChamp.focus();
      return (false);
    }
    
  }//if ( (NomDuChamp == "jour") || (NomDuChamp == "mois")  || (NomDuChamp == "an") )
  
  return (true);
}


function VerifFiche(theForm)
{
  if (!CeChampEstOk(theForm.nom,"nom")) return(false);
  if (!CeChampEstOk(theForm.prenom,"prenom")) return(false);
  if (!CeChampEstOk(theForm.sexe,"sexe")) return(false);
  if (!CeChampEstOk(theForm.jour,"jour")) return(false);
  if (!CeChampEstOk(theForm.mois,"mois")) return(false);
  if (!CeChampEstOk(theForm.an,"an")) return(false);
  if (theForm.ad1.value == "")
  {
    alert("ADRESSE obligatoire.");
    theForm.ad1.focus();
    return (false);
  }
  if (theForm.ad1.value.length < 2)
  {
    alert("Adresse trop courte !");
    theForm.ad1.focus();
    return (false);
  }
  if (theForm.ad1.value.length > 40)
  {
    alert("Adresse Trop Longue !");
    theForm.ad1.focus();
    return (false);
  }  

  if (theForm.ad2.value.length > 40)
  {
    alert("Adresse(sutie) Trop Longue.");
    theForm.ad2.focus();
    return (false);
  }

  if (theForm.cp.value == "")
  {
    alert("CODE POSTAL Obligatoire.");
    theForm.cp.focus();
    return (false);
  }
  var Nbr = theForm.cp.value.length;
  if (Nbr < 3)
  {
    alert("Code Postal trop court.");
    theForm.cp.focus();
    return (false);
  }
  if (Nbr > 7)
  {
    alert("Code Postal trop long.");
    theForm.cp.focus();
    return (false);
  }

  if (theForm.ville.value == "")
  {
    alert("VILLE OBLIGATOIRE.");
    theForm.ville.focus();
    return (false);
  }
  if ((theForm.ville.value.length < 3) || (theForm.ville.value.length > 40))
  {
    alert("Ville INVALIDE. \n Verifiez la taille");
    theForm.ville.focus();
    return (false);
  }
     
  if (theForm.pays.value == "")
  {
    alert("Pays OBLIGATOIRE.");
    theForm.pays.focus();
    return (false);
  }
  if ((theForm.pays.value.length < 2) || (theForm.pays.value.length > 40))
  {
    alert("Pays INVALIDE. \n Verifiez la taille");
    theForm.pays.focus();
    return (false);
  }
 
  if (!Verif_EMail(theForm)) return (false);//Verifie l'email que si FRaisCb > 0 où si il y a quelque chose dans email
  if (theForm.tel.value == "")
  {
    alert("N° de téléphone INVALIDE \n Exp: 0892683313 \n (0033892683313)");
    theForm.tel.focus();
    return (false);
  }
  if (!CaracPermis(theForm.tel.value,"0123456789") || (theForm.tel.value.length < 8) )
    {
      alert("N° de téléphone INVALIDE \nVous ne devez saisir que DES CHIFFRES!\n Exp: 0892683313 \n (0033892683313)");
      theForm.tel.focus();
      return (false);
    }
		
  if (theForm.tst_reglement.value == "oui")
  {
    if(!theForm.reglement.checked)
    {
      alert("Acceptation réglement OBLIGATOIRE");
      theForm.reglement.focus();
      return (false);
    }
		}
  if (theForm.tst_reglement.value == "non")
		{
		  if( theForm.pasta_adulte.value=="" && theForm.pasta_enf.value=="")
    {
      alert("Nombre Pasta party INVALIDE \nVous ne devez saisir que DES CHIFFRES!\n Exp: 1");
      theForm.pasta_adulte.focus();
      return (false);
				}
		  if( theForm.pasta_adulte.value=="0" && theForm.pasta_enf.value=="0")
    {
      alert("Nombre Pasta party INVALIDE \nVous ne devez saisir que DES CHIFFRES!\n Exp: 1");
      theForm.pasta_adulte.focus();
      return (false);
				}
  }
  if (theForm.pasta_adulte.value)
		{
		  if(!CaracPermis(theForm.pasta_adulte.value,"0123456789"))
    {
      alert("Nombre Pasta party Adulte INVALIDE \nVous ne devez saisir que DES CHIFFRES!\n Exp: 1");
      theForm.pasta_adulte.focus();
      return (false);
				}
  }
  if (theForm.pasta_enf.value)
		{
		  if(!CaracPermis(theForm.pasta_enf.value,"0123456789"))
    {
      alert("Nombre Pasta party Enfants INVALIDE \nVous ne devez saisir que DES CHIFFRES!\n Exp: 1");
      theForm.pasta_enf.focus();
      return (false);
				}
  }
 return (true);
}//function VerifFiche(theForm)
          
function verifier_fiche(Fiche)
{ 
  if (VerifFiche(Fiche))
  {
    Fiche.submit(); 
		return (true);
  }
  return false;
}





function Verif_EMail(Fiche)//Verifie l'email que si FRaisCb > 0 où si il y a quelque chose dans email
{
	 var EMail=Fiche.email.value;
  if (!EMailValide(EMail))
  {
    alert("Adresse EMail \n'"+EMail.value+"' \n Invalide !");
    Fiche.email.focus();
    return (false);
  }
  return(true);
}//function Verif_EMail(Fiche)

function EMailValide(EMail)
{

  if ( (EMail == "") || (EMail.length < 5) ) return(false);
  
  if (EMail.length < 5) return false

  if (!CaracPermis(EMail,"@.0123456789-abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ+"))
  {
    return (false);
  }

  var LeAt = EMail.indexOf("@")+1;
  //var LePt = EMail.indexOf(".")+1;//Attention, si le point est avant le "@" , on s'en rendra pas compte !
  var LePt = EMail.lastIndexOf(".")+1;
  
  //alert("email="+EMail+" - At="+LeAt+" - Pt(dernier)="+LePt);
  
  //if ( (LeAt <= 1) || (LePt < 1) || (LeAt == EMail.length) || (LePt == EMail.length) ) return(false);//Attention, si le point est avant le "@" , on s'en rendra pas compte !
  if ( (LeAt <= 1) || (LePt <= 1) || (LePt < LeAt) || (LeAt == EMail.length) || (LePt == EMail.length) || (EMail.charAt(LeAt-2)==".") ) return(false);
 
  return(true);
}


function UnEntier(Ent)
{
  var checkOK = "0123456789";
  var checkStr = Ent;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    C = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (C == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += C;
  }
  if (!allValid)
  {
    return (false);
  }
  return(true);
}

function UnNomPropre(Ch)
{
  var checkStr = Ch;
  var checkOK = "- '.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    C = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (C == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      return(false);
    }
    return(true);
  }
}
  
function CaracPermis(Ch,Carac)
{
  var checkOK = Carac;
  var checkStr = Ch;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    C = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
    if (C == checkOK.charAt(j)) break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += C;
  }
  if (!allValid)
  {
    return (false);
  }
  return(true);
}


function verif_date(input)
{
// Fonction de vérification de date avec les années bissextile par jerome.o
// Accepte en entrée les dates sous la forme : 02/02/2004, 2-2-2004 avec des / ou -
// Retourne false si la date est fausse ou érronée


var regex = new RegExp("[/-]");
var date = input.split(regex);
var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
var result = true;

if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
nbJours['2'] = 29;

if( isNaN(date['2']) )
result=false;

if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
result=false;

if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
result=false;

return result;
}

