function ValideFormComptage()
{
    nbError = 0;
    msgError="";

    var testTelephone=/^\d{10,}$/;
    if(document.getElementById('nom').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre nom.\n";
    }

    if(document.getElementById('prenom').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre prénom.\n";
    }
    
    if(document.getElementById('fonction').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre fonction.\n";
    }
    
    if(document.getElementById('raison_sociale').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre société.\n";
    }
    
    if(document.getElementById('adresse').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre adresse.\n";
    }
     if(document.getElementById('code_postal').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre code postal.\n";
    }
    
     if(document.getElementById('ville').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre ville.\n";
    }
    
     if(document.getElementById('email').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre email.\n";
    }
    else
    {
       if (controlerEmail(document.fichier_ent.elements["email"].value)==false)
        {
           nbError = nbError + 1;
           msgError = msgError + "Le format de votre email est incorrect.\n";
        }
    }
    
    if(document.getElementById('telephone').value =="")
    {
      nbError = nbError + 1;
      msgError = msgError + "Vous devez saisir votre téléphone.\n";
    }
    else
    {
        if (testTelephone.test(document.fichier_ent.elements['telephone'].value)==false)
        {
           nbError = nbError + 1;
           msgError = msgError + "Le format de votre telephone est incorrect.(10 chiffres au minimum)\n";
        }
    }
    
    if(nbError>0)
    {
      alert("Il y a des erreurs dans le formulaire : \n\n"+msgError);
    }
    else
    {
        //on remplir remarque avec l'adresse la demande et 
		document.getElementById('remarque').value = "Adresse :"+document.getElementById('adresse').value +" "+document.getElementById('code_postal').value+" "+document.getElementById('ville').value+" Demande :"+document.getElementById('demande').value + " Comptage= "+document.getElementById('LIBELLE_GLOBAL_RECHERCHE_NON_FORMAT').value;
		//alert(document.getElementById('remarque').value);
		document.fichier_ent.submit();
    }
}

var oldOnglet ="1";


function ChangeOngletComptage(idDesc)
{
   oldIdDesc = oldOnglet;
   document.getElementById("ongletContenu_"+oldIdDesc).style.display = 'none';
   document.getElementById("ongletContenu_"+idDesc).style.display = 'block';

   document.getElementById("onglet_"+oldIdDesc).className = 'ongletComptOff';
   document.getElementById("onglet_"+idDesc).className = 'ongletComptOn';
   
   //on réaffiche la liste des canaux de prospection
   document.getElementById("divCanaux").style.display = 'block';
   
   if(idDesc =="5")
   {
		document.getElementById("divCanaux").style.display = 'none';
       afficheRecapitulatifDemande();
   }
   
   oldOnglet =idDesc;

}

var oldFamille ="defaut";
function ChangeFamille()
{
  if( document.getElementById('famille').options[document.getElementById('famille').selectedIndex].value)
      idFamille=document.getElementById('famille').options[document.getElementById('famille').selectedIndex].value;
  else
    idFamille="defaut";
   document.getElementById("activite_"+oldFamille).style.display = 'none';
   document.getElementById("activite_"+idFamille).style.display = 'block';

   oldFamille =idFamille;

}

var iIndexSelection=0;

function AjouterFamille()
{
 var theDest = document.getElementById("selection");
 var selRef = document.getElementById("famille");
 if (selRef.selectedIndex >= 0)
 {
  bDejaPresent = false;
  ind = 0;
  while(ind < theDest.length)
  {
   if (theDest[ind].value == "famille_"+selRef.options[selRef.selectedIndex].value)
   {
    bDejaPresent = true;
    break;
   }
   ind++;
  }
  if (!bDejaPresent)
  {
    theDest.options[theDest.length] = new Option(selRef.options[selRef.selectedIndex].text, "famille_"+selRef.options[selRef.selectedIndex].value);
    theDest.selectedIndex = theDest.length - 1;
  }
 }
}


function AjouterActivite()
{

 var theDest = document.getElementById("selection");
 var selRef = document.getElementById("famille_"+oldFamille);
 if (selRef.selectedIndex >= 0)
 {
  bDejaPresent = false;
  ind = 0;
  while(ind < theDest.length)
  {
   if (theDest[ind].value == "activite_"+selRef.options[selRef.selectedIndex].value)
   {
    bDejaPresent = true;
    break;
   }
   ind++;
  }
  if (!bDejaPresent)
  {
    theDest.options[theDest.length] = new Option(selRef.options[selRef.selectedIndex].text, "activite_"+selRef.options[selRef.selectedIndex].value);
    theDest.selectedIndex = theDest.length - 1;
  }
 }
}
function SupprimerSelection()
{
  if(document.fichier_ent.selection.selectedIndex>=0)
  document.fichier_ent.selection.options[document.fichier_ent.selection.options.selectedIndex]=null;
}

function afficheRecapitulatifDemande()
{
  //Critère sur les activités :

  var theTxt = "";
  var txtTmp = "";
  
  var txtNomFormat = "";
  
  
   if (document.getElementById('e_mailing').checked) txtTmp += 'E-mailing ';
   if (document.getElementById('telephone_marketing').checked) 
   {
		if(txtTmp!="")
		 txtTmp += ' / ';
		txtTmp += 'Télémarketing  ';
   }
   if (document.getElementById('courrier').checked) 
   {
		if(txtTmp!="")
		 txtTmp += ' / ';
		txtTmp += 'Courrier  ';
   }
   if (document.getElementById('fax_mailing').checked) 
   {
		if(txtTmp!="")
		 txtTmp += ' / ';
		txtTmp += 'Fax-mailing  ';
   }
      
   if(txtTmp!="")
   {
	txtNomFormat += " Canaux de prospection : "+txtTmp;
	theTxt = "<font class='texteDefautGras'><u>Canaux de prospection :</u></font><br>"+txtTmp+"<br>";
    }
   
   txtTmp = "";
  if(document.getElementById("selection"))
  {
    var theSel = document.getElementById("selection");
    for(ind = 0;ind < theSel.length;ind++)
    {
     if (txtTmp.length > 0) txtTmp += " / ";
     txtTmp += theSel.options[ind].text;
    }
  }
  
  if (txtTmp.length > 0)
  {
   txtNomFormat += "  Activités : ";
   theTxt += "<font class='texteDefautGras'><u>Activités :</u></font><br>";
   if (document.getElementById('INVERSE_ACTIVITES').checked) 
   {
		txtNomFormat += 'Tout sauf ';
		theTxt += 'Tout sauf ';
   }
   theTxt += txtTmp;
   txtNomFormat += txtTmp;
  }
  txtTmp = "";
  //Fin activités
  
  //Critères géo
  if(document.getElementById('france_entiere').checked)
  {
	theTxt += "<br><font class='texteDefautGras'>France entière </font><br>";
	txtNomFormat += ' France entière ';
  }
  if (document.getElementById('DEPS').value.length > 0)
  {
    theTxt += "<br><font class='texteDefautGras'><u>Départements :</u></font><br>";
	txtNomFormat += ' Départements : ';
    if (document.getElementById('INVERSE_GEO').checked) 
	{
		theTxt += 'Tout sauf ';
		txtNomFormat += 'Tout sauf ';
	}
    theTxt += document.getElementById('DEPS').value;
	txtNomFormat += document.getElementById('DEPS').value;
  }
  var theUndef;
  ind = 0;
  while(document.getElementById("REGION"+ind) != theUndef)
  {
   if (document.getElementById("REGION"+ind).checked)
   {
    if (txtTmp.length > 0)  txtTmp += " / ";
	
	txtTmp += document.getElementById("REGION_LIB"+ind).value;
	
   }
   ind++;
  }
  if (txtTmp.length > 0)
  {
   theTxt += "<br><font class='texteDefautGras'><u>Régions :</u></font><br>";
   txtNomFormat += " Régions :";
   if (document.getElementById('INVERSE_GEO').checked) 
   {
	theTxt += ' Tout sauf ';
	txtNomFormat += ' Tout sauf ';
   }
   theTxt += txtTmp;
   txtNomFormat += txtTmp;
  }
  txtTmp = "";
  //Fin critères géo
  var regTir=new RegExp("-","gi");
  //Critères effectif
  ind = 1;
  
  while(document.getElementById("EFFECTIF"+ind) != theUndef)
  {
   if (document.getElementById("EFFECTIF"+ind).checked)
   {
    if (txtTmp.length > 0) txtTmp += ", ";
    if(ind != 8) txtTmp += document.getElementById("EFFECTIF"+ind).value.replace(regTir, " à ");
    else txtTmp += document.getElementById("EFFECTIF"+ind).value.substr(0,document.getElementById("EFFECTIF"+ind).value.indexOf("-"))+" et +";
   }
   ind++;
  }
  if (txtTmp.length > 0)
  {
   theTxt += "<br><font class='texteDefautGras'><u>Effectif :</u></font><br>";
   txtNomFormat += " Effectif :";
   if (document.getElementById('INVERSE_CHIFFRE').checked)
	{   
		theTxt += 'Tout sauf ';
		txtNomFormat += 'Tout sauf ';
	}
   theTxt += "Tranche(s) "+txtTmp;
   txtNomFormat += " Tranche(s) "+txtTmp;
  }
  txtTmp = "";
  if (document.getElementById("EFFECTIF_MIN").value.length > 0 || document.getElementById("EFFECTIF_MAX").value.length > 0)
  {
   theTxt += "<br><u>Effectif :</u>";
   txtNomFormat += " Effectif :";
  }
  if (document.getElementById("EFFECTIF_MIN").value.length > 0)
  {
   theTxt += "<br>- supérieur ou égal à "+document.getElementById("EFFECTIF_MIN").value+" pers" ;
   txtNomFormat += " - supérieur ou égal à "+document.getElementById("EFFECTIF_MIN").value+" pers" ;
  }
  if (document.getElementById("EFFECTIF_MAX").value.length > 0)
  {
   theTxt += "<br>- inférieur ou égal à "+document.getElementById("EFFECTIF_MAX").value+" pers" ;
   txtNomFormat += " - inférieur ou égal à "+document.getElementById("EFFECTIF_MAX").value+" pers" ;
  }
  //fin critères effectif
  
  //critères CA
  ind = 1;
  while(document.getElementById("CHIFFRE_AFFAIRES"+ind) != theUndef)
  {
   if (document.getElementById("CHIFFRE_AFFAIRES"+ind).checked)
   {
    if (txtTmp.length > 0) txtTmp += ", ";
    if(ind != 9) txtTmp += document.getElementById("CHIFFRE_AFFAIRES"+ind).value.replace(regTir, " à ");
    else txtTmp += document.getElementById("CHIFFRE_AFFAIRES"+ind).value.substr(0,document.getElementById("CHIFFRE_AFFAIRES"+ind).value.indexOf("-"))+" et +";
   }
   ind++;
  }
  if (txtTmp.length > 0)
  {
   theTxt += "<br><font class='texteDefautGras'><u>Chiffre d'affaires :</u></font><br>";
   txtNomFormat += " Chiffre d'affaires :";
   if (document.getElementById('INVERSE_CHIFFRE').checked)	
	{
		theTxt += 'Tout sauf ';
		txtNomFormat += ' Tout sauf ';
	}
   theTxt += "Tranche(s) "+txtTmp;
   txtNomFormat += " Tranche(s) "+txtTmp;
  }
  txtTmp = "";
  if (document.getElementById("CA_MIN").value.length > 0 || document.getElementById("CA_MAX").value.length > 0)
  {
   theTxt += "<br><u>Chiffre d'affaires :</u>";
   txtNomFormat += "  Chiffre d'affaires :";
  }
  if (document.getElementById("CA_MIN").value.length > 0)
  {
   theTxt += "<br>- supérieur ou égal à "+document.getElementById("CA_MIN").value+" K€" ;
   txtNomFormat += " - supérieur ou égal à "+document.getElementById("CA_MIN").value+" K€" ;
  }
  if (document.getElementById("CA_MAX").value.length > 0)
  {
   theTxt += "<br>- inférieur ou égal à "+document.getElementById("CA_MAX").value+" K€" ;
   txtNomFormat += " - inférieur ou égal à "+document.getElementById("CA_MAX").value+" K€" ;
  }
  //fin critères CA
  
  //critères fonctions
  ind = 1;
  while(document.getElementById("FONCTIONS"+ind) != theUndef)
  {
   if (document.getElementById("FONCTIONS"+ind).checked)
   {
    if (txtTmp.length > 0) txtTmp += ", ";
    txtTmp += document.getElementById("FONCTIONS_LIB"+ind).value;
   }
   ind++;
  }
  if (txtTmp.length > 0)
  {
   theTxt += "<br><font class='texteDefautGras'><u>Fonctions :</u></font><br>";
   txtNomFormat += "  Fonctions :";
   if (document.getElementById('INVERSE_FONCTION').checked)
	{   
		theTxt += 'Tout sauf ';
		txtNomFormat += '  Tout sauf ';
	}
   theTxt += txtTmp;
   txtNomFormat += txtTmp;
  }
  txtTmp = "";
  //fin critères fonctions

  if (theTxt.length == 0) 
  {
	theTxt = "<font class='texteDefautGras'>La totalité de la base</font>";
	txtNomFormat = "La totalité de la base";
  }
  document.getElementById('divRecap').innerHTML = theTxt;
  document.getElementById('LIBELLE_GLOBAL_RECHERCHE').value = theTxt;
  document.getElementById('LIBELLE_GLOBAL_RECHERCHE_NON_FORMAT').value = txtNomFormat;


}
