function YY_checkform()
{
  var a = YY_checkform.arguments, oo = true, v = '', s = '', err = false, r, o, at, o1, t, i, j, ma, rx, cd, cm, cy, dte, at;
  var premier = -1;
  for (i=1; i< a.length; i=i+4)
  {
    // l'attribut n°=1 doit commencer par un # sinon il n'est pas obligatoire  
    if (a[i + 1].charAt(0) == '#')
    {
      r = true;
      a[i + 1] = a[i + 1].substring(1);
    }
    else r = false;

    o = MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1 = MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    
    // si le champ est desactive alors il ne peut pas etre obligatoire   
    if (o.disabled) r = false;
    v = o.value;
    
    // t = attribut n°=2  
    t = a[i + 2];
    
    // dans le cas des chams texte  
    if (o.type == 'text' || o.type == 'password' || o.type == 'hidden')
    {
      if (r && v.length == 0) err = true;
      if (v.length > 0)
      
      //fromto
      if (t == 1)
      {
        ma = a[i + 1].split('_');
        if (isNaN(v) || v < ma[0]/1 || v > ma[1]/1) err = true;
      }
      
      else if (t == 2)
      {
        rx = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*(\.{0,1})@[_a-z0-9-]+(\.[a-z]{2,3}|\.info|\.gouv|\.name|\.museum)\$");
        if (!rx.test(v)) err = true;
      }
      
      // date
      else if (t == 3)
      {
        ma = a[i + 1].split("#");
        at = v.match(ma[0]);
        if (at)
        {
          cd = (at[ma[1]]) ? at[ma[1]]: 1;
          cm = at[ma[2]] - 1;
          cy = at[ma[3]];
          dte = new Date(cy, cm, cd);
          if (dte.getFullYear() != cy || dte.getDate() != cd || dte.getMonth() != cm) err = true;
        }
        else err = true;
      }
      
      // time
      else if (t == 4)
      {
        ma = a[i + 1].split("#");
        at = v.match(ma[0]);
        if (!at) err = true;
      }
      
      else if (t == 5)
      {
        if (o1.length)
        o1 = o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
        if (!o1.checked) err = true;
      }
      
      else if (t == 6)
      {
        // the same   
        if (v != MM_findObj(a[i + 1]).value) err = true;
      }
      
    }
    // dans les autres cas  
    // boutons radio  
    else if (!o.type && o.length > 0 && o[0].type == 'radio')
    {
      at = a[i].match(/(.*)\[(\d+)\].*/i);
      o2 = (o.length > 1) ? o[at[2]]: o;
      if (t == 1 && o2 && o2.checked && o1 && o1.value.length / 1 == 0) err = true;

      if (t == 2)
      {
        oo = false;
        for (j = 0; j < o.length; j++)
        {
          oo = oo || o[j].checked
        }
        if (!oo)
        {
          s += '* ' + a[i + 3] + '\n'
        }
      }
    }
    
    // cases à cocher
    else if (o.type == 'checkbox')
    {
      if ((t == 1 && o.checked == false) || (t == 2 && o.checked && o1 && o1.value.length / 1 == 0)) err = true;
    }
    
    // listes
    else if (o.type == 'select-one' || o.type == 'select-multiple')
    {
      if (o.size > 1)
      {
        if (r && t == 1)
        {
          cptselectionne = 0;
          for (var idx = 0; idx < o.options.length; idx++)
          {
            if (o.options[idx].selected)
            {
              cptselectionne++;
            }
          }
          err = (cptselectionne == 0);
        }
      }
      else
      {
        // dans le cas d'une liste a une seule ligne, la premiere est un libellé  
        if (r && t == 1 && o.selectedIndex / 1 == 0) err = true;
      }
    }
    
    // textarea
    else if (o.type == 'textarea')
    {
      if (v.length < a[i + 1]) err = true;
    }
    
    // file
    else if (o.type == 'file')
    {
      if (v.length < 1) err = true;
    }
    
    if (err)
    {
      s += '--> ' + a[i + 3] + '\n';
      err = false;
      if (premier == -1) premier = o;
    }
  }
  if (s != '')
  {
    alert('Le formulaire est incomplet ou contient des erreurs :\t\t\t\t\t\n\n' + s)
    if (premier.type != 'hidden') premier.focus();
  }
  document.MM_returnValue = (s == '');
}

// Submit d'un formulaire
// --> checkform (vérifier formulaire sauf avis contraire) + désactiver les champs et les boutons
function submit_form(form_name, checkform)
{
	if (validateForm(checkform))
	{
		document.getElementById(form_name).submit();
		
		// Boucle tous les formulaires "form" --> pas "menuMainForm"
		var id=1;
		var formulaire=document.getElementById('form' + id);
		while(formulaire)
		{
			for (j=0; j<formulaire.elements.length; j++)
			{
				formulaire.elements[j].disabled = true;
			}
			id++;
			formulaire=document.getElementById('form' + id);
		}
		
		// Désactive les boutons
		id=1;
		while(document.getElementById('enableb' + id))
		{
			document.getElementById('enableb' + id).style.display = 'none';
			document.getElementById('disableb' + id).style.display = '';
			id++;
		}
	}
}

// Calcule le montant HT à partir du montant TTC
function montant_HT(fieldHT, fieldTTC, taux_TVA)
{
	TVA = 1 + (taux_TVA / 100);
	
	document.getElementById(fieldHT).value = (Math.round(document.getElementById(fieldTTC).value / TVA * 100))/100;
	FormatNumerique(document.getElementById(fieldHT), 2);
	FormatNumerique(document.getElementById(fieldTTC), 2);
}

// Calcule le montant TTC à partir du montant HT
function montant_TTC(fieldHT, fieldTTC, taux_TVA)
{
	TVA = 1 + (taux_TVA / 100);

	document.getElementById(fieldTTC).value = (Math.round(document.getElementById(fieldHT).value * TVA * 100))/100;
	FormatNumerique(document.getElementById(fieldHT), 2);
	FormatNumerique(document.getElementById(fieldTTC), 2);
}

// Calcule la somme de 2 champs
function calculeLaSomme(fieldUn, fieldDeux)
{
	nombreUn = parseFloat(document.getElementById(fieldUn).value);
	nombreDeux = parseFloat(document.getElementById(fieldDeux).value);

	return (nombreUn + nombreDeux);
}

// Format un nombre sur 2 décimales
function FormatNumerique(fieldNbre, NbrDecimales)
{
	var tmp = fieldNbre.value;
	
	if (tmp == '')
	{
		if (NbrDecimales == 0) { tmp = '0'; }
		else
		{
			tmp = '0.';
			for (var i=0; NbrDecimales>i; i++) { tmp = tmp + '0'; }
		}
	}

	else if (tmp.indexOf('.', 0) != -1)
	{
		var cGauche = tmp.substring(0, tmp.indexOf('.', 1));
		var cDroite = tmp.substring(tmp.indexOf('.', 1) + 1, tmp.length);

		if(cGauche == '')
		{
			cGauche = '0';
			var cDroite = tmp.substring(tmp.indexOf('.', 0) + 1, tmp.length);
		}
		else { var cDroite = tmp.substring(tmp.indexOf('.', 1) + 1, tmp.length); }

		if (cDroite.length == NbrDecimales)
		{
			if (cGauche == '0')
			{
				// Dans le cas ou tapé par exemple : .256
				tmp = cGauche + '.' + cDroite.substring(0, NbrDecimales);
			}
		}
		else if (cDroite.length > NbrDecimales)
		{
			if (NbrDecimales == 0) { tmp = cGauche; }
			else { tmp = cGauche + '.' + cDroite.substring(0, NbrDecimales); }
		}
		else
		{
			for(var i=0; cDroite.length < NbrDecimales; i++) { cDroite = cDroite + '0'; }
			tmp = cGauche + '.' + cDroite.substring(0, NbrDecimales);
		}
	}

	else
	{
		if (NbrDecimales != 0)
		{
			tmp = tmp + '.';
			for (var i=0; NbrDecimales>i; i++) { tmp = tmp + '0'; }
		}
	}

	fieldNbre.value = tmp;
}

// Générateur de mot de passe
function password(fieldPassword)
{
	var keylist = new Array();

	consonnes = "bcdfgjklmnprstv";
	voyelles = "aeiouy";
	numeros = "0123456789";
	motdepasse = "";
	taille = 8;

	keylist[0] = consonnes;
	keylist[1] = voyelles;
	keylist[2] = consonnes;
	keylist[3] = voyelles;
	keylist[4] = consonnes;
	keylist[5] = voyelles;
	keylist[6] = numeros;
	keylist[7] = numeros;

	for(i=0;i<taille;i++)
	{
		motdepasse+=keylist[i].charAt(Math.floor(Math.random()*keylist[i].length))
	}

	getfieldPassword = document.getElementById(fieldPassword);
	getfieldPassword.value = motdepasse;
	getfieldPassword.focus();
}

