function isString(aValue, iSizeMin, iSizeMax, iNullAllowed)
{
    //get length of string
    iLength = aValue.length;
    //check if null
    if (iLength == 0 && iNullAllowed == 1)
        return true;
    if ( iLength < iSizeMin || iLength > iSizeMax)
        return false;
    return true;
}

function isNum(iValue, iValueMin, iValueMax, iNullAllowed)
{
    //get length of string
    iLength = iValue.length;
    //check if null
    if (iLength == 0 && iNullAllowed == 1)
        return true;
    if ( iValue > iValueMin && iValue < iValueMax)
        return true;
    return false;
}

function isEmail(aValue, iNullAllowed){

    //get length of string
    iLength = aValue.length;
    //check if null
    if (iLength == 0 && iNullAllowed == 1)
        return true;
    re = /^[a-zA-Z0-9_.\-]+\@[a-zA-Z0-9_.\-]+\.[a-zA-Z0-9_\-]+$/;
    iSearch = re.exec(aValue);
    if (iSearch == null)
        return false;
        return true;
}

function isIdem(aChampA,aChampB)
{
   if (aChampA == aChampB) { return true; }
   else { return false; }
}

function ValidForm()
{
      var strErreur= "";
      if(!isString(document.main.prenom.value, 1, 50,0)) { strErreur += " Prenom\n"; }
      if(!isString(document.main.nom.value, 1, 50,0)) { strErreur += " Nom\n"; }
      if(document.main.date_n_j.value=="") { strErreur += " Vous n'avez pas sélectionné votre jour de naissance \n"; }
      if(document.main.date_n_m.value=="") { strErreur += " Vous n'avez pas sélectionné votre mois de naissance \n"; }
      if(!isNum(document.main.date_n_an.value, 1900, 2000,0)) { strErreur += "  Année de naissance\n"; }
      if(!isString(document.main.addr.value, 1, 200,0)) { strErreur += " Adresse\n"; }
      if(!isString(document.main.ville.value, 1, 51,0)) { strErreur += " Ville\n"; }
      if(!isString(document.main.cp.value, 1, 10,0)) { strErreur += " Code Postal\n"; }
      if(!isEmail(document.main.email.value,0)) { strErreur += " Email\n"; }
      if(!isString(document.main.phone.value, 1, 21,1)) { strErreur += " Telephone\n"; }
      if(document.main.reg_id.value=="") { strErreur += " Vous n'avez pas sélectionné votre region \n"; }
      if(document.main.reg_ok.checked==false) { strErreur += " Vous n'avez pas coché la case\n Je certifie sur l'honneur être sociétaire de la Caisse d'Epargne \n"; }
      if (strErreur != "")
      { 
      	alert("Votre Formulaire comporte des erreurs \nsur les champs suivant :\n" + strErreur);
        return false; 
      }
      else
      { return true }
}

function ValidForm2()
{
      var strErreur= "";
      if(!isString(document.main.prenom.value, 1, 50,0)) { strErreur += " Prenom\n"; }
      if(!isString(document.main.nom.value, 1, 50,0)) { strErreur += " Nom\n"; }
      if(document.main.date_n_j.value=="") { strErreur += " Vous n'avez pas sélectionné votre jour de naissance \n"; }
      if(document.main.date_n_m.value=="") { strErreur += " Vous n'avez pas sélectionné votre mois de naissance \n"; }
      if(!isNum(document.main.date_n_an.value, 1900, 2000,0)) { strErreur += "  Année de naissance\n"; }
      if(!isString(document.main.addr.value, 1, 200,0)) { strErreur += " Adresse\n"; }
      if(!isString(document.main.ville.value, 1, 51,0)) { strErreur += " Ville\n"; }
      if(!isString(document.main.cp.value, 1, 10,0)) { strErreur += " Code Postal\n"; }
      if(!isEmail(document.main.email.value,0)) { strErreur += " Email\n"; }
      if(!isString(document.main.phone.value, 1, 21,1)) { strErreur += " Telephone\n"; }
      if(document.main.reg_id.value=="") { strErreur += " Vous n'avez pas sélectionné votre region \n"; }
      if(isString(document.main.new_pass.value, 1, 21,0))
      {
	if(!isIdem(document.main.new_pass.value,document.main.conf_new_pass.value)) { strErreur += " Confirmation de mot de passe\n"; }
      }
      if (strErreur != "")
      { 
      	alert("Votre Formulaire comporte des erreurs \nsur les champs suivant :\n" + strErreur);
        return false; 
      }
      else
      { return true }
}

function ValidForm3()
{
      var strErreur= "";
      if(!isString(document.main.prenom.value, 1, 50,0)) { strErreur += " Prenom\n"; }
      if(!isString(document.main.nom.value, 1, 50,0)) { strErreur += " Nom\n"; }
      if(!isEmail(document.main.email.value,0)) { strErreur += " Email\n"; }
      if(!isString(document.main.message.value, 1, 1000,0)) { strErreur += " Entrez un message\n"; }
      if (strErreur != "")
      { 
      	alert("!! Votre Formulaire comporte des erreurs \nsur les champs suivant :\n" + strErreur);
        return false; 
      }
      else
      { return true }
}

function ValidForm4()
{
      var strErreur= "";
      if(!isString(document.main.message.value, 1, 1000,0)) { strErreur += " Entrez un message\n"; }
      if (strErreur != "")
      { 
      	alert("Votre Formulaire comporte des erreurs \nsur les champs suivant :\n" + strErreur);
        return false; 
      }
      else
      { return true }
}

function ValidForm5()
{
      var strErreur= "";
      if(!isEmail(document.main.from_email.value,0)) { strErreur += " Votre adresse email.\n"; }
      if(!isEmail(document.main.dest_email.value,0)) { strErreur += " Adresse email du destinataire.\n"; }
      if (strErreur != "")
      { 
      	alert("Votre Formulaire comporte des erreurs \nsur les champs suivant :\n" + strErreur);
        return false; 
      }
      else
      { return true }
}

function ValidCharte()
{
      var strErreur= "";
      if(document.charte.charteok.checked==false) { strErreur += " Vous devez accepter les conditions pour pouvoir continuer\n"; }
      if (strErreur != "")
      { 
      	alert(strErreur);
        return false; 
      }
      else
      { return true }
}

function ValidFormmail()
{
      var strErreur= "";
      if(!isEmail(document.fmail.reg_admin_mail.value,0)) { strErreur += " Adresse mail Contact non valide\n"; }
      if (strErreur != "")
      { 
      	alert("Votre Formulaire comporte des erreurs :\n" + strErreur);
        return false; 
      }
      else
      { return true }
}

function check_mail()
{
  if(!isEmail(document.search_form.email_search.value,0))
  {
    alert("Veuillez saisir un email")
    return false;
  }
  return true;	
}

function ValidFormAdm()
{
      var strErreur= "";
      if(document.main.del_soc.checked==true)
      {
        if(confirm("Etes-vous certain de vouloir supprimer\ndéfinitivement ce sociétaire ?"))
        {
          return true;	
        }
        else
        {
          return false;	
        }	
      }
      else
      {
	      if(!isString(document.main.prenom.value, 1, 50,0)) { strErreur += " Prenom\n"; }
	      if(!isString(document.main.nom.value, 1, 50,0)) { strErreur += " Nom\n"; }
	      if(document.main.date_n_j.value=="") { strErreur += " Vous n'avez pas sélectionné un jour de naissance \n"; }
	      if(document.main.date_n_m.value=="") { strErreur += " Vous n'avez pas sélectionné un mois de naissance \n"; }
	      if(!isNum(document.main.date_n_an.value, 1900, 2000,0)) { strErreur += "  Année de naissance\n"; }
	      if(!isString(document.main.addr.value, 1, 200,0)) { strErreur += " Adresse\n"; }
	      if(!isString(document.main.ville.value, 1, 51,0)) { strErreur += " Ville\n"; }
	      if(!isString(document.main.cp.value, 1, 10,0)) { strErreur += " Code Postal\n"; }
	      if(!isEmail(document.main.email.value,0)) { strErreur += " Email\n"; }
	      if(!isString(document.main.phone.value, 1, 21,1)) { strErreur += " Telephone\n"; }
	      if(document.main.reg_id.value=="") { strErreur += " Vous n'avez pas sélectionné une region \n"; }
	       if (strErreur != "")
	      { 
	      	alert("Votre Formulaire comporte des erreurs \nsur les champs suivant :\n" + strErreur);
	        return false; 
	      }
	      else
	      { return true }
      }
}

function ValidAnnonce()
{
      var strErreur= "";
      if(document.main.ann_type.value=="") { strErreur += " - Vous n'avez pas indiqué de type d'annonce \n"; }
      if(document.main.cat_id.value=="") { strErreur += " - Vous n'avez pas indiqué de rubrique d'annonce \n"; }
      if(!isString(document.main.txt_ann.value, 1, 1000,0)) { strErreur += " - Entrez un texte pour l'annonce\n"; }
      if(document.main.ann_type.value=="vente")
      {
      	if(!isNum(document.main.prix.value, 1, 1000000,0)) { strErreur += " - Indiquer un tarif valide SVP\n"; }
      }
      if(!isString(document.main.depart.value, 2, 20,0)) { strErreur += " - Département / Code postal\n"; }
      if(!isString(document.main.phone.value, 1, 20,0) && !isEmail(document.main.mail.value,0)) 
      {
        strErreur += " - Indiquez un telephone ou un email\n"; 	
      }
      if (strErreur != "")
      { 
      	alert("Votre Formulaire comporte des erreurs sur les champs suivant :\n\n" + strErreur);
        return false; 
      }
      else
      { return true }
}

function DelAnnonce()
{
      var strErreur= "";
      if(document.frmdel.del_ann.checked==true) 
      { 
      	 if(confirm("Etes-vous certain de vouloir supprimer cette annonce ?"))
      	 {
      	   return true; 	
      	 }
      	 else
      	 {
      	   return false; 	
      	 }
      }
      else
      {
      	alert("Merci de confirmer la suppression en cochant la case ci contre.");
        return false; 
      }
}


