var envoyer;
envoyer = 0;

//+------------------------------------------+
//|    Formulaire d'authentification         |
//+------------------------------------------+


  function auth()
  {
  c1 = document.form.id.value;
  c2 = document.form.pass.value;

  verif = true;

    if(verif)
    {
      if(!c1 || c1=="")
      {
      alert ('Veuillez indiquer votre ID !');
      document.form.id.focus ();
      document.form.id.select ();
      verif = false;
      }
    }

    if(verif)
    {
      if(!c2 || c2=="")
      {
      alert ('Veuillez indiquer votre PASSWORD !');
      document.form.pass.focus ();
      document.form.pass.select ();
      verif = false;
      }
    }

    if(verif)
    envoyer++;

    if(verif && envoyer==1)
    document.form.submit();

  return verif;
  }


//+------------------------------------------+
//|    Action recharger                      |
//+------------------------------------------+

  function ext_rchgr()
  {
  document.ext.submit();
  }


//+------------------------------------------+
//|    Action du menu principal              |
//+------------------------------------------+

  function action (cp_num,action)
  {
  document.form.cp_num.value = cp_num;
  document.form.action.value = action;

  test = false;

    if(action == "supprimer")
      test = window.confirm("Vous êtes sur le point de supprimer un compteur.\nVeuillez confirmer ou annuler.");
    else
      test = true;

    if(test)
    envoyer++;

    if(envoyer==1 && test)
    document.form.submit();
  }

//+------------------------------------------+
//|    Action de création d'un nouveau       |
//|           Compteur..                     |
//+------------------------------------------+

  function creation ()
  {
  envoyer++;

  c1 = document.form.cp_num.value = "";
  c2 = document.form.action.value = "nouveau";

    if(envoyer==1)
    document.form.submit();
  }


//+------------------------------------------+
//|    Formulaire de personnalisation        |
//+------------------------------------------+


  function perso()
  {
  verif = true;

  c1  = document.form.cp_libelle.value;
  c2  = document.form.cp_description.value;



  if(c1=="" && verif)
  {
  alert ('Veuillez indiquer le libellé du compteur !');
  document.form.cp_libelle.focus ();
  document.form.cp_libelle.select ();
  verif = false;
  }


  if(c2=="" && verif)
  {
  alert ('Veuillez indiquer une brève description du compteur !');
  document.form.cp_description.focus ();
  document.form.cp_description.select ();
  verif = false;
  }



  if(verif)
  {
  NbChar     = c2.length;
  NbCharMax  = 200;

    if(NbChar>NbCharMax)
    {
    alert ('Votre brève description comporte ' + NbChar + ' caractères ! \n' 
           + 'Le maximum est fixé à '+ NbCharMax +' caractères.');
    document.form.cp_description.focus ();
    document.form.cp_description.select ();
    verif = false;
    }
  }

  if(verif)
  envoyer++;


    if(envoyer==1 && verif)
    document.form.submit();
  }

//+------------------------------------------+
//|    Action de restauration                |
//+------------------------------------------+

  function restaurer()
  {
    if(window.confirm('Vous êtes sur le point de restaurer les paramètres du compteur.\nVeuillez confirmer ou annuler.'))
    {
    document.form.cp_description.value  =  "Description du compteur";
    document.form.cp_libelle.value      =  "Mon Compteur";
    document.form.cp_format.value       =  1;

    cpt_img();
    }
  }
  
//+------------------------------------------+
//|    Retour au menu principal              |
//+------------------------------------------+

  function retour()
  {
  envoyer++;

    if(envoyer==1)
    document.form_retour.submit();
  }


//+------------------------------------------+
//|    Paginations - transmission POST       |
//+------------------------------------------+

  function Pagination(action,page,cp_num,tri,me_page)
  {
    if(action)
    document.form_pgnt.action.value  = action;

    if(page)
    document.form_pgnt.Page.value    = page;

    if(cp_num)
    document.form_pgnt.cp_num.value  = cp_num;

    if(tri)
    document.form_pgnt.tri.value     = tri;

    if(me_page)
    document.form_pgnt.me_Page.value = me_page;

  document.form_pgnt.submit();
  }

//+------------------------------------------+
//|    Changer de PASSWORD ADMIN             |
//+------------------------------------------+

  function chg_pw()
  {
  c1 = document.form_chg_pw.npw.value;
  c2 = document.form_chg_pw.npw2.value;

  verif = true;

    if(verif)
    {
      if(!c1 || c1=="")
      {
      alert ('Veuillez indiquer votre nouveau PASSWORD !');
      document.form_chg_pw.npw.focus ();
      document.form_chg_pw.npw.select ();
      verif = false;
      }
    }

    if(verif)
    {
      if(c1 != c2)
      {
      alert ('Nouveaux PASSWORD différents !');
      document.form_chg_pw.npw.focus ();
      document.form_chg_pw.npw.select ();
      verif = false;
      }
    }

    if(verif)
    {
      if(c1.indexOf('\\') != -1 ||
         c1.indexOf('\"') != -1 ||
         c1.indexOf('\'') != -1 ||
         c1.indexOf('\`') != -1 )
      {
      alert ('Votre PASSWORD ne peut pas contenir les caractères suivants : \\\"\'\`');
      document.form_chg_pw.npw.focus ();
      document.form_chg_pw.npw.select ();
      verif = false;
      }
    }

    if(verif)
    envoyer++;

    if(verif && envoyer==1)
    document.form_chg_pw.submit();

  return verif;
  }

//+------------------------------------------+
//|    Mise à Jour des données personnelles  |
//+------------------------------------------+

  function chg_infos()
  {
  c1 = document.form_chg_infos.nemail.value;
  c2 = document.form_chg_infos.nurl.value;

  verif = true;

    if(verif)
    {
      if((!c1) || ((c1.indexOf('@')) == -1) || ((c1.indexOf('.')) == -1))
      {
      alert ('Veuillez indiquer votre email !');
      document.form_chg_infos.nemail.focus ();
      document.form_chg_infos.nemail.select ();
      verif = false;
      }
    }

    if(verif)
    {
      if(((c2.indexOf('http://')) == -1) || (c2=="http://"))
      {
      alert ('Veuillez indiquer l\'adresse de votre site Web !');
      document.form_chg_infos.nurl.focus ();
      document.form_chg_infos.nurl.select ();
      verif = false;
      }
    }

    if(verif)
    envoyer++;

    if(verif && envoyer==1)
    document.form_chg_infos.submit();

  return verif;
  }


//+------------------------------------------+
//|     Affichage/Masquage des Infos sur     |
//|          les Compteurs (main)            |
//+------------------------------------------+

function info(id)
{

var VarTableau;
VarTableau = document.getElementById(id);

  if (VarTableau.style.visibility == "hidden")
  {
  VarTableau.style.visibility = "visible";
  VarTableau.style.display    = "block";
  }
  else
  {
  VarTableau.style.visibility = "hidden";
  VarTableau.style.display    = "none";
  }

}

//+------------------------------------------+
//|    Masquage/Affichage de la selection de |
//|    l'image de son compteur               |
//+------------------------------------------+

  function cpt_img()
  {
  var choix;
  choix = document.form.cp_format.value;

    if (choix == 2)
    {
    document.all.divpp.style.visibility = "visible";
    document.all.divpp.style.display    = "block";
    document.form.cp_format_img[0].checked = 1;
    }
    else
    {
    document.all.divpp.style.visibility = "hidden";
    document.all.divpp.style.display    = "none";
    }
  }
