function setValeurForm(ceForm,idInput,valeurInput) {
    //if (valeurInput == 0) valeurInput = "";
    if (ceForm.elements[idInput]) { 
	    ceForm.elements[idInput].value = valeurInput;
    }
}

document.getElementsByClass = function (needle)
{
  var my_array = document.getElementsByTagName("*");
  var retvalue = new Array();
  var i = 0;
  var j = 0;
  for (i = 0, j= 0; i < my_array.length; i++)
  {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + needle + " ") != -1)
      retvalue[j++] = my_array[i];
  }
  return retvalue;
}


// cette fonction formatte un nombre au format monétaire
function monetaire(x) {
   var cents = Math.round(x*100) - Math.floor(x)*100;
   if (cents >= 100) {
       cents = cents - 100;
       x = x+1;
   }
   if (cents < 10) cents = "0" + cents;
   x = Math.floor(x) + "," + cents;
   return x;
}

function setPrixTTC(prixht,taux,idttc) {
    prixht=prixht.replace(',','.');
    if (isNaN(prixht)) {
        alert('Le prix que vous avez saisi n\'est pas un nombre');
        return false;
    }
    else {
        document.getElementById(idttc).value=monetaire(prixht*(1+(taux/100)));
        document.getElementById('products_prices').value=prixht*1;
    }
}

function setPrixHT(prixttc,taux,idht) {
    prixttc=prixttc.replace(',','.');
    if (isNaN(prixttc)) {
        alert('Le prix que vous avez saisi n\'est pas un nombre');
        return false;
    }
    else {
        document.getElementById(idht).value=monetaire(prixttc/(1+(taux/100)));
        var prixht = monetaire(prixttc/(1+(taux/100)));
        var prixht = prixht.replace(',','.');
        document.getElementById('products_prices').value=prixht*1;
    }
}

function TestModifyQte() {
    var listeEle = document.getElementsByClass("caseqte");
    var test=true;
    for (i = 0; i < listeEle.length; i++) {
        var ele = listeEle[i];
        var qte = ele.value;
        var qtetest = -1;
        if (document.getElementById("test"+ele.id)) {
            var qtetest = document.getElementById("test"+ele.id).value;
        }
        if (qte != qtetest) test = false;
    }
    if (test == false) return confirm("Vous avez modifiez une/des quantité(s) sans recalculer votre panier.\nCe sont donc les quantités d'origine qui seront prisent en compte.\nEtes vous sur de vouloir continuer ?");
    else return true;
}

function addLoadEvent(func)
{
   var oldonload = window.onload;
   if(typeof window.onload != 'function')
   {
      window.onload = func;
   }
   else
   {
      window.onload = function()
      {
         oldonload();
         func();
      }
   }
}

function AddToOnloadUser() {
    if (document.getElementById("menu-onglet")) initUserMenu();
    if (document.getElementById("accept")) document.getElementById("accept").focus();
    if (document.getElementById("variantemaj")) window.opener.location= document.getElementById("returnurl").value;
}
addLoadEvent(AddToOnloadUser);
