function deux_dec(nombre_in) {
  var nombre = new String(nombre_in);
  nombre = nombre.replace("-.", "-0.");
  //  var out = new String('');
  var Taille = nombre.length;
  var Position = -1;
  if (Taille == 0) {
    out = "0.00";
  } else {
    for (cont = 0; cont < Taille; cont++) {
      if (nombre.charCodeAt(cont) == 46) {
        Position = cont;
      } else {
      }
    }
    var Diff = Taille - Position;
    if (Position == -1) {
      out = nombre + ".00";
    } else {
      if (Diff < 3) {
        out = nombre;
        for (cont = Diff; cont < 3; cont++) {
          out = out + "0";
        }
      } else {
        out = nombre.substring(0, Position + 3);
      }
    }
  }
  return out;
}

function edit_tab() {
  no = this.document.forms["info"].liste_articles.selectedIndex;
  //  no=this.document.forms['info'].elements['liste_articles'].value
  this.document.forms["info"].ElementActuel.value = no;
  nom = "MemTypeData" + no;
  TypeData = this.document.forms["info"].elements[nom].value;
  switch (parseInt(TypeData)) {
    case 0:
      nom = "MemNoArticle" + no;
      this.document.forms["info"].NoArticle.value =
        this.document.forms["info"].elements[nom].value;
      nom = "MemDescription" + no;
      this.document.forms["info"].Description.value =
        this.document.forms["info"].elements[nom].value;
      nom = "MemPrix" + no;
      this.document.forms["info"].Prix.value =
        this.document.forms["info"].elements[nom].value;
      nom = "MemTVA" + no;
      this.document.forms["info"].TVA.value =
        this.document.forms["info"].elements[nom].value;
      nom = "MemQuantite" + no;
      this.document.forms["info"].Quantite.value =
        this.document.forms["info"].elements[nom].value;
      nom = "MemRabais" + no;
      this.document.forms["info"].Rabais.value =
        this.document.forms["info"].elements[nom].value;
      nom = "MemGM" + no;
      this.document.forms["info"].GM.value =
        this.document.forms["info"].elements[nom].value;
      nom = "MemStock" + no;
      this.document.forms["info"].Stock.value =
        this.document.forms["info"].elements[nom].value;
      if (this.document.forms["info"].IsCommande.value == 1) {
        nom = "MemDest" + no;
        this.document.forms["info"].Destinataire.value =
          this.document.forms["info"].elements[nom].value;
      }
      this.document.forms["info"].modif_data.disabled = false;
      this.document.forms["info"].modif_text.disabled = true;
      break;
    case 1:
      /*      ok=true;
      cpt=no;
      while(ok)
      {
        nom='MemTypeData' + cpt;
        TypeData=this.document.forms['info'].elements[nom].value;
        if(parseInt(TypeData)!=1)
        {
          cpt++;
          ok=false;
        }
        else
        {
          cpt--;
        }
        if(parseInt(cpt)<0)
        {
          cpt=0;
          ok=false;
        }
      }
      tmp_txt='';
      ok=true;
      while(ok)
      {
        nom='MemTypeData' + cpt;
        TypeData=this.document.forms['info'].elements[nom].value;
        if(parseInt(TypeData)==1)
        {
          nom='MemDescription' + cpt;
          tmp_txt += this.document.forms['info'].elements[nom].value + '\\r\\n';
          cpt++;
        }
        else
        {
          ok=false;
          this.document.forms['info'].Texte_libre.value=tmp_txt;
        }
      } */

      //      alert('long texte');
      nom = "MemDescription" + no;
      //      alert(nom + ' ' + this.document.forms['info'].elements[nom].value);
      this.document.forms["info"].Texte_libre.value =
        this.document.forms["info"].elements[nom].value;
      this.document.forms["info"].modif_data.disabled = true;
      this.document.forms["info"].modif_text.disabled = false;
      break;
    case 2:
      this.document.forms["info"].modif_data.disabled = true;
      this.document.forms["info"].modif_text.disabled = true;
      alert(
        "Vous ne pouvez pas modifier une ligne total intermédiaire. Vous pouvez seulement la déplacer ou la supprimer"
      );
      break;
  }
}
function clear_data() {
  this.document.forms["info"].NoArticle.value = "";
  this.document.forms["info"].Description.value = "";
  this.document.forms["info"].Prix.value = "0.00";
  this.document.forms["info"].TVA.value = "0.00";
  this.document.forms["info"].Quantite.value = "0.00";
  this.document.forms["info"].Rabais.value = "0.00";
  this.document.forms["info"].GM.value = "0";
  this.document.forms["info"].Stock.value = "0";
  if (this.document.forms["info"].IsCommande.value == 1) {
    this.document.forms["info"].Destinataire.value = "Stock";
  }
  this.document.forms["info"].modif_data.disabled = true;
  this.document.forms["info"].modif_text.disabled = true;
}
function clear_texte() {
  this.document.forms["info"].Texte_libre.value = "";
  this.document.forms["info"].modif_data.disabled = true;
  this.document.forms["info"].modif_text.disabled = true;
}
function tot_inter_newfact(text = "") {
  AsChange = 1;
  var id = this.document.forms["info"].current_cpt.value;
  this.document.forms["info"].current_cpt.value = parseInt(id) + 1;
  var table = document.getElementById("tblBody");
  var nb_rows = table.rows.length;
  var row = table.insertRow(nb_rows);
  row.setAttribute("type", "article");
  row.setAttribute("id", "el" + id);
  var cell1 = document.createElement("td");
  cell1.className = "edit";
  var img1_1 = document.createElement("img");
  img1_1.setAttribute("src", "images/up_down.png");
  img1_1.setAttribute("class", "handle");
  cell1.appendChild(img1_1);
  var a1_3 = document.createElement("a");
  a1_3.setAttribute("href", "javascript:del('el" + id + "');");
  var img1_3 = document.createElement("img");
  img1_3.setAttribute("src", "images/b_drop.png");
  img1_3.setAttribute("border", "0");
  a1_3.appendChild(img1_3);
  cell1.appendChild(a1_3);
  var inp1_4 = document.createElement("input");
  inp1_4.setAttribute("type", "hidden");
  inp1_4.setAttribute("id", "pos" + id);
  inp1_4.setAttribute("name", "pos" + id);
  inp1_4.setAttribute("value", id);
  cell1.appendChild(inp1_4);
  var inp1_5 = document.createElement("input");
  inp1_5.setAttribute("type", "hidden");
  inp1_5.setAttribute("id", "type" + id);
  inp1_5.setAttribute("name", "type" + id);
  inp1_5.setAttribute("value", "inter");
  cell1.appendChild(inp1_5);
  row.appendChild(cell1);
  var cell2 = document.createElement("td");
  cell2.className = "total_intermediaire_visu";
  cell2.colSpan = 7;
  var inp2_1 = document.createElement("input");
  inp2_1.setAttribute("type", "text");
  inp2_1.setAttribute("name", "Description" + id);
  inp2_1.setAttribute("id", "Description" + id);
  inp2_1.setAttribute("maxlength", "40");
  inp2_1.setAttribute("size", "40");
  //inp2_1.setAttribute("value",this.document.forms['info'].Description.value);
  inp2_1.setAttribute("value", text);
  cell2.appendChild(inp2_1);
  row.appendChild(cell2);
  var cell3 = document.createElement("td");
  cell3.className = "total_intermediaire";
  cell3.setAttribute("id", "inter" + id);
  var text3_1 = document.createTextNode(
    this.document.forms["info"].Total_commande.value
  );
  cell3.appendChild(text3_1);
  row.appendChild(cell3);
  var cell4 = document.createElement("td");
  row.appendChild(cell4);
  $(".total_intermediaire_visu input").autocomplete({ source: valTotInter });
  compte_lignes_newfact();
}
function tot_partiel_newfact(text = "") {
  AsChange = 1;
  var id = this.document.forms["info"].current_cpt.value;
  this.document.forms["info"].current_cpt.value = parseInt(id) + 1;
  var table = document.getElementById("tblBody");
  var nb_rows = table.rows.length;
  var row = table.insertRow(nb_rows);
  row.setAttribute("type", "partiel");
  row.setAttribute("id", "el" + id);
  var cell1 = document.createElement("td");
  cell1.className = "edit";
  var img1_1 = document.createElement("img");
  img1_1.setAttribute("src", "images/up_down.png");
  img1_1.setAttribute("class", "handle");
  cell1.appendChild(img1_1);
  var a1_3 = document.createElement("a");
  a1_3.setAttribute("href", "javascript:del('el" + id + "');");
  var img1_3 = document.createElement("img");
  img1_3.setAttribute("src", "images/b_drop.png");
  img1_3.setAttribute("border", "0");
  a1_3.appendChild(img1_3);
  cell1.appendChild(a1_3);
  var inp1_4 = document.createElement("input");
  inp1_4.setAttribute("type", "hidden");
  inp1_4.setAttribute("id", "pos" + id);
  inp1_4.setAttribute("name", "pos" + id);
  inp1_4.setAttribute("value", id);
  cell1.appendChild(inp1_4);
  var inp1_5 = document.createElement("input");
  inp1_5.setAttribute("type", "hidden");
  inp1_5.setAttribute("id", "type" + id);
  inp1_5.setAttribute("name", "type" + id);
  inp1_5.setAttribute("value", "partiel");
  cell1.appendChild(inp1_5);
  row.appendChild(cell1);
  var cell2 = document.createElement("td");
  cell2.className = "total_partiel_visu";
  cell2.colSpan = 7;
  var inp2_1 = document.createElement("input");
  inp2_1.setAttribute("type", "text");
  inp2_1.setAttribute("name", "Description" + id);
  inp2_1.setAttribute("id", "Description" + id);
  inp2_1.setAttribute("maxlength", "40");
  inp2_1.setAttribute("size", "40");
  //inp2_1.setAttribute("value",this.document.forms['info'].Description.value);
  inp2_1.setAttribute("value", text);
  cell2.appendChild(inp2_1);
  row.appendChild(cell2);
  var cell3 = document.createElement("td");
  cell3.className = "total_partiel";
  cell3.setAttribute("id", "partiel" + id);
  var text3_1 = document.createTextNode(
    this.document.forms["info"].Total_commande.value
  );
  cell3.appendChild(text3_1);
  row.appendChild(cell3);
  var cell4 = document.createElement("td");
  row.appendChild(cell4);
  calcule_total_newfact();
  $(".total_partiel_visu input").autocomplete({ source: valTotPartiel });
  compte_lignes_newfact();
}
function tot_partiel2_newfact(text = "") {
  AsChange = 1;
  var id = this.document.forms["info"].current_cpt.value;
  this.document.forms["info"].current_cpt.value = parseInt(id) + 1;
  var table = document.getElementById("tblBody");
  var nb_rows = table.rows.length;
  var row = table.insertRow(nb_rows);
  row.setAttribute("type", "partiel2");
  row.setAttribute("id", "el" + id);
  var cell1 = document.createElement("td");
  cell1.className = "edit";
  var img1_1 = document.createElement("img");
  img1_1.setAttribute("src", "images/up_down.png");
  img1_1.setAttribute("class", "handle");
  cell1.appendChild(img1_1);
  var a1_3 = document.createElement("a");
  a1_3.setAttribute("href", "javascript:del('el" + id + "');");
  var img1_3 = document.createElement("img");
  img1_3.setAttribute("src", "images/b_drop.png");
  img1_3.setAttribute("border", "0");
  a1_3.appendChild(img1_3);
  cell1.appendChild(a1_3);
  var inp1_4 = document.createElement("input");
  inp1_4.setAttribute("type", "hidden");
  inp1_4.setAttribute("id", "pos" + id);
  inp1_4.setAttribute("name", "pos" + id);
  inp1_4.setAttribute("value", id);
  cell1.appendChild(inp1_4);
  var inp1_5 = document.createElement("input");
  inp1_5.setAttribute("type", "hidden");
  inp1_5.setAttribute("id", "type" + id);
  inp1_5.setAttribute("name", "type" + id);
  inp1_5.setAttribute("value", "partiel2");
  cell1.appendChild(inp1_5);
  row.appendChild(cell1);
  var cell2 = document.createElement("td");
  cell2.className = "total_partiel2_visu";
  cell2.colSpan = 7;
  var inp2_1 = document.createElement("input");
  inp2_1.setAttribute("type", "text");
  inp2_1.setAttribute("name", "Description" + id);
  inp2_1.setAttribute("id", "Description" + id);
  inp2_1.setAttribute("maxlength", "40");
  inp2_1.setAttribute("size", "40");
  inp2_1.setAttribute("value", text);
  //inp2_1.setAttribute("value",this.document.forms['info'].Description.value);
  cell2.appendChild(inp2_1);
  row.appendChild(cell2);
  var cell3 = document.createElement("td");
  cell3.className = "total_partiel2";
  cell3.setAttribute("id", "partiel2_" + id);
  var text3_1 = document.createTextNode(
    this.document.forms["info"].Total_commande.value
  );
  cell3.appendChild(text3_1);
  row.appendChild(cell3);
  var cell4 = document.createElement("td");
  row.appendChild(cell4);
  calcule_total_newfact();
  $(".total_partiel2_visu input").autocomplete({ source: valTotPartiel });
  compte_lignes_newfact();
}
function tot_inter() {
  AsChange = 1;
  if (this.document.forms["info"].modif_data != undefined) {
    this.document.forms["info"].modif_data.disabled = true;
  }
  if (this.document.forms["info"].modif_text != undefined) {
    this.document.forms["info"].modif_text.disabled = true;
  }
  no = this.document.forms["info"].liste_articles.length;
  nom = "MemTypeData" + no;
  this.document.forms["info"].elements[nom].value = 2;
  nom = "MemNoArticle" + no;
  this.document.forms["info"].elements[nom].value = "";
  StrLen = 0;
  texte = "";
  max = 16;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = texte2 + " ";
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte2;
  texte2 = "==============================";
  texte_final =
    texte_final +
    texte2 +
    "                0.00   0.00   0.00     0.00      0.00";
  nom = "MemDescription" + no;
  this.document.forms["info"].elements[nom].value = texte2;
  nom = "MemPrix" + no;
  this.document.forms["info"].elements[nom].value = "0.00";
  nom = "MemRabais" + no;
  this.document.forms["info"].elements[nom].value = "0.00";
  nom = "MemTVA" + no;
  this.document.forms["info"].elements[nom].value = "0.00";
  nom = "MemQuantite" + no;
  this.document.forms["info"].elements[nom].value = "0.00";
  nom = "MemPrixTotal" + no;
  this.document.forms["info"].elements[nom].value = "0.00";
  nom = "MemStock" + no;
  this.document.forms["info"].elements[nom].value = "0.00";
  nom = "MemGM" + no;
  this.document.forms["info"].elements[nom].value = "0";
  if (this.document.forms["info"].IsCommande.value == 1) {
    nom = "MemDest" + no;
    this.document.forms["info"].elements[nom].value = "";
    nom = "MemNbRecu" + no;
    this.document.forms["info"].elements[nom].value = "0";
    nom = "MemDateRecu" + no;
    this.document.forms["info"].elements[nom].value = "";
  }
  o = new Option(texte_final, no);
  if (!ie) {
    var reg = new RegExp("( )", "g");
    lolo = texte_final.replace(reg, "&nbsp;");
    o.innerHTML = lolo;
  }
  this.document.forms["info"].liste_articles.options[no] = o;
  this.document.forms["info"].NbElements.value =
    1 + parseInt(this.document.forms["info"].NbElements.value);
}
function sort_table() {
  jQuery("#tblBody").sortable({
    axis: "y",
    //handle : '.handle',
    opacity: 0.2,
    update: function () {
      var order = jQuery("#tblBody").sortable("toArray");
      //alert(\"position \"+order)
      //var obj = jQuery(\"#info\");
      //obj[0].innerHTML = order.length + \"<BR/>\";
      var pos = 1;
      for (var i in order) {
        //obj[0].innerHTML = obj[0].innerHTML + order[i] + \"<BR/>\";
        //alert(order[i]);
        var num = order[i].substr(2);
        //alert(num);
        var obj = jQuery("#pos" + num);
        obj[0].value = pos;
        pos++;
      }
      calcule_total_newfact();
    },
  });
}

function add_new_newfact(total) {
  AsChange = 1;
  var id = this.document.forms["info"].current_cpt.value;
  this.document.forms["info"].current_cpt.value = parseInt(id) + 1;
  //  var table = document.getElementById("table_articles");
  var table = document.getElementById("tblBody");
  var nb_rows = table.rows.length;
  var row = table.insertRow(nb_rows);
  row.setAttribute("type", "article");
  row.setAttribute("id", "el" + id);
  //  row.setAttribute("style","z-index: 1000; filter:  alpha(opacity=100); ZOOM: 1;");
  var cell1 = document.createElement("td");
  cell1.className = "edit";
  //  var a1_1 = document.createElement("a");
  //  a1_1.setAttribute("href","javascript:up('el" + id + "');");
  var img1_1 = document.createElement("img");
  img1_1.setAttribute("src", "images/up_down.png");
  img1_1.setAttribute("class", "handle");
  //  a1_1.appendChild(img1_1);
  cell1.appendChild(img1_1);
  //  var a1_2 = document.createElement("a");
  //  a1_2.setAttribute("href","javascript:down('el" + id + "');");
  //  var img1_2 = document.createElement("img");
  //  img1_2.setAttribute("src","images/down.gif");
  //  img1_2.setAttribute("border","0");
  //  a1_2.appendChild(img1_2);
  //  cell1.appendChild(a1_2);
  var a1_3 = document.createElement("a");
  a1_3.setAttribute("href", "javascript:del('el" + id + "');");
  var img1_3 = document.createElement("img");
  img1_3.setAttribute("src", "images/b_drop.png");
  img1_3.setAttribute("border", "0");
  a1_3.appendChild(img1_3);
  cell1.appendChild(a1_3);
  var inp1_4 = document.createElement("input");
  inp1_4.setAttribute("type", "hidden");
  inp1_4.setAttribute("id", "pos" + id);
  inp1_4.setAttribute("name", "pos" + id);
  inp1_4.setAttribute("value", id);
  cell1.appendChild(inp1_4);
  var inp1_5 = document.createElement("input");
  inp1_5.setAttribute("type", "hidden");
  inp1_5.setAttribute("id", "type" + id);
  inp1_5.setAttribute("name", "type" + id);
  inp1_5.setAttribute("value", "article");
  cell1.appendChild(inp1_5);
  row.appendChild(cell1);
  var cell2 = document.createElement("td");
  cell2.className = "no_article";
  var inp2_1 = document.createElement("input");
  inp2_1.setAttribute("type", "text");
  inp2_1.setAttribute("name", "NoArticle" + id);
  inp2_1.setAttribute("id", "NoArticle" + id);
  //inp2_1.setAttribute("readonly","readonly");
  inp2_1.readOnly = true;
  inp2_1.setAttribute("value", this.document.forms["info"].NoArticle.value);
  cell2.appendChild(inp2_1);
  row.appendChild(cell2);
  var cell3 = document.createElement("td");
  cell3.className = "description";
  var inp3_1 = document.createElement("input");
  inp3_1.setAttribute("type", "text");
  inp3_1.setAttribute("name", "Description" + id);
  inp3_1.setAttribute("id", "Description" + id);
  inp3_1.setAttribute("maxlength", "40");
  inp3_1.setAttribute("size", "40");
  inp3_1.setAttribute("value", this.document.forms["info"].Description.value);
  cell3.appendChild(inp3_1);
  row.appendChild(cell3);
  var cell4 = document.createElement("td");
  cell4.className = "prix_unit";
  var inp4_1 = document.createElement("input");
  inp4_1.setAttribute("type", "text");
  inp4_1.setAttribute("name", "Prix" + id);
  inp4_1.setAttribute("id", "Prix" + id);
  inp4_1.setAttribute("maxlength", "10");
  inp4_1.setAttribute("size", "10");
  inp4_1.setAttribute("value", this.document.forms["info"].Prix.value);
  inp4_1.onchange = maj_article_fact_new;
  cell4.appendChild(inp4_1);
  row.appendChild(cell4);
  var cell5 = document.createElement("td");
  cell5.className = "rabais";
  var inp5_1 = document.createElement("input");
  inp5_1.setAttribute("type", "text");
  inp5_1.setAttribute("name", "Rabais" + id);
  inp5_1.setAttribute("id", "Rabais" + id);
  inp5_1.setAttribute("maxlength", "7");
  inp5_1.setAttribute("size", "7");
  inp5_1.setAttribute("value", this.document.forms["info"].Rabais.value);
  inp5_1.onchange = maj_article_fact_new;
  cell5.appendChild(inp5_1);
  row.appendChild(cell5);
  var cell6 = document.createElement("td");
  cell6.className = "tva";
  var inp6_1 = document.createElement("input");
  inp6_1.setAttribute("type", "text");
  inp6_1.setAttribute("name", "TVA" + id);
  inp6_1.setAttribute("id", "TVA" + id);
  inp6_1.setAttribute("maxlength", "6");
  if (readonlytva) {
    inp6_1.setAttribute("readonly", "readonly");
  }
  inp6_1.setAttribute("size", "6");
  inp6_1.setAttribute("value", this.document.forms["info"].TVA.value);
  inp6_1.onchange = maj_article_fact_new;
  cell6.appendChild(inp6_1);
  row.appendChild(cell6);
  var cell7 = document.createElement("td");
  cell7.className = "gm";
  var inp7_1 = document.createElement("input");
  inp7_1.setAttribute("type", "text");
  inp7_1.setAttribute("name", "GM" + id);
  inp7_1.setAttribute("id", "GM" + id);
  inp7_1.setAttribute("maxlength", "3");
  inp7_1.setAttribute("size", "3");
  //inp7_1.setAttribute("readonly","readonly");
  inp7_1.readOnly = true;
  //inp7_1.setAttribute("disabled","disabled");
  inp7_1.setAttribute("value", this.document.forms["info"].GM.value);
  cell7.appendChild(inp7_1);
  row.appendChild(cell7);
  var cell8 = document.createElement("td");
  cell8.className = "quantite";
  var inp8_1 = document.createElement("input");
  inp8_1.setAttribute("type", "text");
  inp8_1.setAttribute("name", "Quantite" + id);
  inp8_1.setAttribute("id", "Quantite" + id);
  inp8_1.setAttribute("maxlength", "7");
  inp8_1.setAttribute("size", "7");
  inp8_1.setAttribute("value", this.document.forms["info"].Quantite.value);
  inp8_1.onchange = maj_article_fact_new;
  cell8.appendChild(inp8_1);
  row.appendChild(cell8);
  var cell9 = document.createElement("td");
  cell9.className = "prix";
  cell9.setAttribute("id", "tot" + id);
  var valeur_final =
    deux_dec(this.document.forms["info"].Quantite.value) *
    deux_dec(this.document.forms["info"].Prix.value) *
    ((100.0 + parseFloat(deux_dec(this.document.forms["info"].Rabais.value))) /
      100.0);
  if (this.document.forms["info"].TVA.value > 0) {
    valeur_final =
      valeur_final *
      ((100.0 + parseFloat(deux_dec(this.document.forms["info"].TVA.value))) /
        100.0);
  }
  if (this.document.forms["info"].IsCommande.value == 1) {
    valeur_final = Math.round(100.0 * valeur_final) / 100;
  } else {
    valeur_final = Math.round(20.0 * valeur_final) / 20;
  }
  var texte = deux_dec(valeur_final);
  var text9_1 = document.createTextNode(texte);
  var inp11 = document.createElement("input");
  inp11.setAttribute("type", "hidden");
  inp11.setAttribute("name", "Total" + id);
  inp11.setAttribute("value", texte);
  var new_total =
    parseFloat(texte) +
    parseFloat(this.document.forms["info"].Total_commande.value);
  if (this.document.forms["info"].IsCommande.value == 1) {
    new_total = Math.round(100.0 * new_total) / 100;
  } else {
    new_total = Math.round(20.0 * new_total) / 20;
  }
  this.document.forms["info"].Total_commande.value = deux_dec(new_total);
  var total_el = document.getElementById("total");
  total_el.innerHTML = deux_dec(new_total);
  cell9.appendChild(text9_1);
  row.appendChild(cell9);
  var cell10 = document.createElement("td");
  cell10.className = "stock";
  var span10_1 = document.createElement("span");
  span10_1.setAttribute("id", "Stock" + id);
  texte = Math.round(this.document.forms["info"].Stock.value);
  texte = texte + "";
  var text10_1 = document.createTextNode(texte);
  span10_1.appendChild(text10_1);
  cell10.appendChild(span10_1);
  texte = this.document.forms["info"].LieuxStock.value;
  var span10_2 = document.createElement("span");
  span10_2.setAttribute("id", "Stock" + id);
  if (texte.length > 0) {
    var text10_2 = document.createTextNode(texte);
    var text10_3 = document.createTextNode(" (");
    var text10_4 = document.createTextNode(")");
    span10_2.appendChild(text10_3);
    span10_2.appendChild(text10_2);
    span10_2.appendChild(text10_4);
  }
  cell10.appendChild(span10_2);
  row.appendChild(cell10);
  if (this.document.forms["info"].IsCommande.value == 1) {
    var cell11 = document.createElement("td");
    cell11.className = "destinataire";
    var inp11_1 = document.createElement("input");
    inp11_1.setAttribute("type", "text");
    inp11_1.setAttribute("name", "Destinataire" + id);
    inp11_1.setAttribute("maxlength", "50");
    inp11_1.setAttribute("size", "50");
    inp11_1.setAttribute(
      "value",
      this.document.forms["info"].Destinataire.value
    );
    cell11.appendChild(inp11_1);
    row.appendChild(cell11);
    var cell12 = document.createElement("td");
    cell12.className = "nb_recu";
    var inp12_1 = document.createElement("input");
    inp12_1.setAttribute("type", "text");
    inp12_1.setAttribute("name", "NbRecu" + id);
    inp12_1.setAttribute("id", "NbRecu" + id);
    inp12_1.setAttribute("maxlength", "7");
    inp12_1.setAttribute("size", "7");
    inp12_1.setAttribute("value", "0.00");
    inp12_1.onchange = change_recu_new;
    cell12.appendChild(inp12_1);
    var inp12_2 = document.createElement("input");
    inp12_2.setAttribute("type", "hidden");
    inp12_2.setAttribute("name", "DateRecu" + id);
    inp12_2.setAttribute("id", "DateRecu" + id);
    inp12_2.setAttribute("value", "0000-00-00");
    cell12.appendChild(inp12_2);
    row.appendChild(cell12);
    var cell13 = document.createElement("td");
    cell13.className = "date";
    cell13.setAttribute("id", "DateRecuStr" + id);
    row.appendChild(cell13);
  }
  row.appendChild(inp11);
  this.document.forms["info"].NoArticle.value = "";
  this.document.forms["info"].Description.value = "";
  this.document.forms["info"].Prix.value = "0.00";
  this.document.forms["info"].Rabais.value = "0.00";
  this.document.forms["info"].TVA.value = "0.00";
  this.document.forms["info"].GM.value = "0";
  this.document.forms["info"].Stock.value = "0";
  this.document.forms["info"].Quantite.value = "1.00";
  if (this.document.getElementById("Stock") != null)
    this.document.getElementById("Stock").innerText = "";
  if (this.document.getElementById("LieuxStock") != null)
    this.document.getElementById("LieuxStock").innerText = "";
  if (this.document.forms["info"].NoArticle != undefined) {
    if (this.document.forms["info"].NoArticle.type == "text") {
      this.document.forms["info"].NoArticle.focus();
    }
  }
  if (total) calcule_total_newfact();
  var i = 2;
  compte_lignes_newfact();
}
function add_new(total) {
  AsChange = 1;
  if (this.document.forms["info"].modif_data != undefined) {
    this.document.forms["info"].modif_data.disabled = true;
  }
  if (this.document.forms["info"].modif_text != undefined) {
    this.document.forms["info"].modif_text.disabled = true;
  }
  this.document.forms["info"].ElementActuel.value = -1;
  no = this.document.forms["info"].liste_articles.length;
  StrLen = this.document.forms["info"].NoArticle.value.length;
  if (StrLen == 0) {
    alert("Vous devez entrer un numéro d'article");
    return 0;
  }
  texte = this.document.forms["info"].NoArticle.value;
  nom = "MemTypeData" + no;
  this.document.forms["info"].elements[nom].value = 0;
  nom = "MemNoArticle" + no;
  this.document.forms["info"].elements[nom].value =
    this.document.forms["info"].NoArticle.value;
  max = 16;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = texte2 + " ";
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte2;
  StrLen = this.document.forms["info"].Description.value.length;
  texte = this.document.forms["info"].Description.value;
  max = 40;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = texte2 + " ";
    }
  }
  nom = "MemDescription" + no;
  this.document.forms["info"].elements[nom].value = texte;
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].Prix.value);
  StrLen = texte.length;
  nom = "MemPrix" + no;
  this.document.forms["info"].elements[nom].value = texte;
  max = 9;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].Rabais.value);
  StrLen = texte.length;
  nom = "MemRabais" + no;
  this.document.forms["info"].elements[nom].value = texte;
  max = 6;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].TVA.value);
  StrLen = texte.length;
  nom = "MemTVA" + no;
  //  this.document.forms['info'].elements[nom].value=this.document.forms['info'].TVA.value;
  this.document.forms["info"].elements[nom].value = texte;
  max = 6;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].Quantite.value);
  StrLen = texte.length;
  nom = "MemQuantite" + no;
  //  this.document.forms['info'].elements[nom].value=this.document.forms['info'].Quantite.value;
  this.document.forms["info"].elements[nom].value = texte;
  max = 8;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  valeur_final =
    deux_dec(this.document.forms["info"].Quantite.value) *
    deux_dec(this.document.forms["info"].Prix.value) *
    ((100.0 + parseFloat(deux_dec(this.document.forms["info"].Rabais.value))) /
      100.0);
  if (this.document.forms["info"].TVA.value > 0) {
    valeur_final =
      valeur_final *
      ((100.0 + parseFloat(deux_dec(this.document.forms["info"].TVA.value))) /
        100.0);
  }
  if (this.document.forms["info"].IsCommande.value == 1) {
    valeur_final = Math.round(100.0 * valeur_final) / 100;
  } else {
    valeur_final = Math.round(20.0 * valeur_final) / 20;
  }
  texte = deux_dec(valeur_final);
  StrLen = texte.length;
  nom = "MemPrixTotal" + no;
  this.document.forms["info"].elements[nom].value = texte;
  max = 9;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  //  texte2 = texte2 + ' ';
  texte_final = texte_final + texte2;
  texte = Math.round(this.document.forms["info"].Stock.value);
  texte = texte + "";
  StrLen = texte.length;
  nom = "MemStock" + no;
  //  this.document.forms['info'].elements[nom].value=this.document.forms['info'].Quantite.value;
  this.document.forms["info"].elements[nom].value = texte;
  max = 5;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = " " + texte2;
  texte_final = texte_final + texte2;
  //  texte_final=texte_final + ' ' + deux_dec(valeur_final);
  nom = "MemGM" + no;
  texte = this.document.forms["info"].GM.value;
  if (texte.length == 0) texte = "0";
  if (texte == 0) {
    alert("Le groupe marchnadise doit être différent de 0 !");
    return 0;
  }
  this.document.forms["info"].elements[nom].value = texte;
  if (this.document.forms["info"].IsCommande.value == 1) {
    nom = "MemDest" + no;
    texte = this.document.forms["info"].Destinataire.value;
    StrLen = texte.length;
    this.document.forms["info"].elements[nom].value = texte;
    max = 14;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = texte2 + " ";
      }
    }
    texte_final = texte_final + " " + texte2;
    texte_final = texte_final + "      NON           ";
    nom = "MemNbRecu" + no;
    this.document.forms["info"].elements[nom].value = "0";
    nom = "MemDateRecu" + no;
    this.document.forms["info"].elements[nom].value = "";
  }
  o = new Option(texte_final, no);
  if (!ie) {
    var reg = new RegExp("( )", "g");
    lolo = texte_final.replace(reg, "&nbsp;");
    o.innerHTML = lolo;
  }
  this.document.forms["info"].liste_articles.options[no] = o;
  this.document.forms["info"].NbElements.value =
    1 + parseInt(this.document.forms["info"].NbElements.value);
  this.document.forms["info"].NoArticle.value = "";
  this.document.forms["info"].Description.value = "";
  this.document.forms["info"].Prix.value = "0.00";
  this.document.forms["info"].Rabais.value = "0.00";
  this.document.forms["info"].TVA.value = "0.00";
  this.document.forms["info"].GM.value = "0";
  this.document.forms["info"].Stock.value = "0";
  this.document.forms["info"].Quantite.value = "1.00";
  if (this.document.forms["info"].modif_data != undefined)
    this.document.forms["info"].NoArticle.focus();
  if (total) calcule_total();
}
function add_new_tva() {
  AsChange = 1;
  this.document.forms["info"].ElementActuel.value = -1;
  no = this.document.forms["info"].liste_articles.length;
  StrLen = 3;
  texte = "TVA";
  nom = "MemTypeData" + no;
  this.document.forms["info"].elements[nom].value = 3;
  nom = "MemNoArticle" + no;
  this.document.forms["info"].elements[nom].value = "TVA";
  max = 16;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = texte2 + " ";
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte2;
  StrLen = 9;
  texte = "TVA Marge";
  max = 40;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = texte2 + " ";
    }
  }
  nom = "MemDescription" + no;
  this.document.forms["info"].elements[nom].value = texte2;
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].Prix.value);
  StrLen = texte.length;
  nom = "MemPrix" + no;
  this.document.forms["info"].elements[nom].value = texte;
  max = 9;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].Rabais.value);
  StrLen = texte.length;
  nom = "MemRabais" + no;
  this.document.forms["info"].elements[nom].value = texte;
  max = 6;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].TVA.value);
  StrLen = texte.length;
  nom = "MemTVA" + no;
  //  this.document.forms['info'].elements[nom].value=this.document.forms['info'].TVA.value;
  this.document.forms["info"].elements[nom].value = texte;
  max = 6;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  texte = deux_dec(this.document.forms["info"].Quantite.value);
  StrLen = texte.length;
  nom = "MemQuantite" + no;
  //  this.document.forms['info'].elements[nom].value=this.document.forms['info'].Quantite.value;
  this.document.forms["info"].elements[nom].value = texte;
  max = 8;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  valeur_final =
    deux_dec(this.document.forms["info"].Quantite.value) *
    deux_dec(this.document.forms["info"].Prix.value) *
    ((100.0 + parseFloat(deux_dec(this.document.forms["info"].Rabais.value))) /
      100.0);
  if (this.document.forms["info"].TVA.value > 0) {
    valeur_final =
      valeur_final *
      ((100.0 + parseFloat(deux_dec(this.document.forms["info"].TVA.value))) /
        100.0);
  }
  valeur_final = Math.round(20.0 * valeur_final) / 20.0;
  texte = deux_dec(valeur_final);
  StrLen = texte.length;
  nom = "MemPrixTotal" + no;
  this.document.forms["info"].elements[nom].value = texte;
  max = 9;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  //  texte2 = texte2 + ' ';
  texte_final = texte_final + texte2;
  //  texte_final=texte_final + ' ' + deux_dec(valeur_final);
  texte = "0";
  StrLen = texte.length;
  nom = "MemStock" + no;
  //  this.document.forms['info'].elements[nom].value=this.document.forms['info'].Quantite.value;
  this.document.forms["info"].elements[nom].value = texte;
  max = 5;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = " " + texte2;
  texte_final = texte_final + texte2;
  nom = "MemGM" + no;
  texte = this.document.forms["info"].GM.value;
  if (texte.length == 0) texte = "0";
  this.document.forms["info"].elements[nom].value = texte;
  if (this.document.forms["info"].IsCommande.value == 1) {
    nom = "MemDest" + no;
    texte = this.document.forms["info"].Destinataire.value;
    StrLen = texte.length;
    this.document.forms["info"].elements[nom].value = texte;
    max = 14;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = texte2 + " ";
      }
    }
    texte_final = texte_final + " " + texte2;
    texte_final = texte_final + "      NON           ";
    nom = "MemNbRecu" + no;
    this.document.forms["info"].elements[nom].value = "0";
    nom = "MemDateRecu" + no;
    this.document.forms["info"].elements[nom].value = "";
  }
  o = new Option(texte_final, no);
  if (!ie) {
    var reg = new RegExp("( )", "g");
    lolo = texte_final.replace(reg, "&nbsp;");
    o.innerHTML = lolo;
  }
  this.document.forms["info"].liste_articles.options[no] = o;
  this.document.forms["info"].NbElements.value =
    1 + parseInt(this.document.forms["info"].NbElements.value);
  this.document.forms["info"].NoArticle.value = "";
  this.document.forms["info"].Description.value = "";
  this.document.forms["info"].Prix.value = "0.00";
  this.document.forms["info"].Rabais.value = "0.00";
  this.document.forms["info"].TVA.value = "0.00";
  this.document.forms["info"].GM.value = "0";
  this.document.forms["info"].Stock.value = "0";
  this.document.forms["info"].Quantite.value = "1.00";
  if (this.document.forms["info"].modif_data != undefined)
    this.document.forms["info"].NoArticle.focus();
  calcule_total();
}
function add_text_type(no_commande) {
  var $tt = $("#Texte_type").val();
  $.ajax({
    url: "textetype.php",
    data: { id: $tt, nocommande: no_commande },
  }).done(function (data) {
    var ta = $(".ta_texte_libre");
    if (ta.val() != "") {
      ta.val(ta.val() + "\n");
    }
    ta.val(ta.val() + data);
  });
}
function add_text_type_auto(no_texte, no_commande, no_vhc) {
  $.ajaxSetup({ async: false });
  $.get(
    "textetype.php",
    { id: no_texte, nocommande: no_commande, novhc: no_vhc },
    function (data) {
      var ta = $(".ta_texte_libre");
      if (ta.val() != "") {
        ta.val(ta.val() + "\n");
      }
      ta.val(ta.val() + data);
      add_new_text_newfact();
    }
  );
  $.ajaxSetup({ async: true });
}
function add_new_text_newfact($gras = false) {
  AsChange = 1;
  var id = this.document.forms["info"].current_cpt.value;
  this.document.forms["info"].current_cpt.value = parseInt(id) + 1;
  var table = document.getElementById("tblBody");
  var nb_rows = table.rows.length;
  //var order = jQuery('#tblBody').sortable('toArray');
  //alert(order);
  var row = table.insertRow(nb_rows);
  row.setAttribute("type", "text");
  row.setAttribute("id", "el" + id);
  var cell1 = row.insertCell(0);
  //var cell1 = document.createElement("td");
  cell1.className = "edit";
  var img1_1 = document.createElement("img");
  img1_1.setAttribute("src", "images/up_down.png");
  img1_1.setAttribute("class", "handle");
  cell1.appendChild(img1_1);
  var a1_3 = document.createElement("a");
  a1_3.setAttribute("href", "javascript:del('el" + id + "');");
  var img1_3 = document.createElement("img");
  img1_3.setAttribute("src", "images/b_drop.png");
  img1_3.setAttribute("border", "0");
  a1_3.appendChild(img1_3);
  cell1.appendChild(a1_3);
  var inp1_4 = document.createElement("input");
  inp1_4.setAttribute("type", "hidden");
  inp1_4.setAttribute("id", "pos" + id);
  inp1_4.setAttribute("name", "pos" + id);
  inp1_4.setAttribute("value", id);
  cell1.appendChild(inp1_4);
  var inp1_5 = document.createElement("input");
  inp1_5.setAttribute("type", "hidden");
  inp1_5.setAttribute("id", "type" + id);
  inp1_5.setAttribute("name", "type" + id);
  inp1_5.setAttribute("value", "texte");
  cell1.appendChild(inp1_5);
  row.appendChild(cell1);
  var cell2 = row.insertCell(1);
  //var cell2 = document.createElement("td");
  cell2.colSpan = "9";
  cell2.className = "edit";
  //cell2.setAttribute("colspan","9");
  var textarea2_1 = document.createElement("textarea");
  textarea2_1.setAttribute("name", "Texte" + id);
  textarea2_1.setAttribute("cols", "92");
  textarea2_1.setAttribute("wrap", "hard");
  textarea2_1.setAttribute("onkeyup", "update_free_text(this);");
  var texte = this.document.forms["info"].Texte_libre.value;
  //var reg=new RegExp("\r", "g");
  //texte = texte.replace(reg,"");
  var arr = texte.split("\n");
  //var arr2 = texte.split("\r");
  //var arr3 = texte.split("\n\r");
  //var arr4 = texte.split("\r\n");
  //alert(arr.length + " " + arr2.length+ " " + arr3.length+ " " + arr4.length)
  textarea2_1.setAttribute("rows", arr.length);
  //var text2_1 = document.createTextNode(texte);
  //textarea2_1.appendChild(text2_1);
  textarea2_1.value = texte;
  var bold2_2 = document.createElement("b");
  bold2_2.innerHTML = "gras";
  var input2_3 = document.createElement("input");
  input2_3.setAttribute("type", "checkbox");
  input2_3.setAttribute("name", "Gras" + id);
  if ($gras) input2_3.setAttribute("checked", "checked");
  cell2.appendChild(textarea2_1);
  cell2.appendChild(bold2_2);
  cell2.appendChild(input2_3);
  row.appendChild(cell2);
  this.document.forms["info"].Texte_libre.value = "";
  compte_lignes_newfact();
}
function add_new_text() {
  AsChange = 1;
  o = new Array();
  if (this.document.forms["info"].modif_data != undefined) {
    this.document.forms["info"].modif_data.disabled = true;
  }
  if (this.document.forms["info"].modif_text != undefined) {
    this.document.forms["info"].modif_text.disabled = true;
  }
  this.document.forms["info"].ElementActuel.value = -1;
  no = this.document.forms["info"].liste_articles.length;
  //  StrLen=this.document.forms['info'].NoArticle.value.length;
  texte = this.document.forms["info"].Texte_libre.value;
  taille = texte.length;
  start = 0;
  tmp_no = no;
  nb_lignes = 0;
  ligne = texte;
  for (cont = 0; cont < taille; cont++) {
    if (texte.charCodeAt(cont) == 10) {
      if (cont - 1 - start > 120) ligne = texte.substring(start, start + 120);
      else ligne = texte.substring(start, cont - 1);
      nom = "MemTypeData" + tmp_no;
      this.document.forms["info"].elements[nom].value = 1;
      nom = "MemDescription" + tmp_no;
      this.document.forms["info"].elements[nom].value = ligne;
      nom = "MemNoArticle" + tmp_no;
      this.document.forms["info"].elements[nom].value = "";
      nom = "MemPrix" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemRabais" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemTVA" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemQuantite" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemPrixTotal" + no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemStock" + no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemGM" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0;
      o[nb_lignes] = new Option(ligne, tmp_no);
      if (!ie) {
        var reg = new RegExp("( )", "g");
        lolo = ligne.replace(reg, "&nbsp;");
        o[nb_lignes].innerHTML = lolo;
      }
      this.document.forms["info"].liste_articles.options[tmp_no] = o[nb_lignes];
      start = parseInt(cont) + 1;
      nb_lignes++;
      tmp_no++;
    }
  }
  if (start != taille) {
    if (taille - 1 - start > 120) ligne = texte.substring(start, start + 120);
    else ligne = texte.substring(start, taille);
    nom = "MemTypeData" + tmp_no;
    this.document.forms["info"].elements[nom].value = 1;
    nom = "MemDescription" + tmp_no;
    this.document.forms["info"].elements[nom].value = ligne;
    nom = "MemNoArticle" + tmp_no;
    this.document.forms["info"].elements[nom].value = "";
    nom = "MemPrix" + tmp_no;
    this.document.forms["info"].elements[nom].value = 0.0;
    nom = "MemRabais" + tmp_no;
    this.document.forms["info"].elements[nom].value = 0.0;
    nom = "MemTVA" + tmp_no;
    this.document.forms["info"].elements[nom].value = 0.0;
    nom = "MemQuantite" + tmp_no;
    this.document.forms["info"].elements[nom].value = 0.0;
    nom = "MemPrixTotal" + no;
    this.document.forms["info"].elements[nom].value = 0.0;
    nom = "MemStock" + no;
    this.document.forms["info"].elements[nom].value = 0.0;
    nom = "MemGM" + tmp_no;
    this.document.forms["info"].elements[nom].value = 0;
    o[nb_lignes] = new Option(ligne, tmp_no);
    if (!ie) {
      var reg = new RegExp("( )", "g");
      lolo = ligne.replace(reg, "&nbsp;");
      o[nb_lignes].innerHTML = lolo;
    }
    this.document.forms["info"].liste_articles.options[tmp_no] = o[nb_lignes];
    nb_lignes++;
    tmp_no++;
  }
  this.document.forms["info"].NbElements.value =
    parseInt(nb_lignes) +
    parseInt(this.document.forms["info"].NbElements.value);
  this.document.forms["info"].Texte_libre.value = "";
}
function modif_select() {
  AsChange = 1;
  no = this.document.forms["info"].ElementActuel.value;
  //  alert(no);
  if (this.document.forms["info"].NoArticle.value.length == 0) {
    alert("Vous devez entrer un numéro d'article");
    return 0;
  }
  this.document.forms["info"].modif_data.disabled = true;
  this.document.forms["info"].modif_text.disabled = true;
  if (no != -1) {
    nom = "MemNoArticle" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].NoArticle.value;
    nom = "MemDescription" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Description.value;
    nom = "MemPrix" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Prix.value;
    nom = "MemRabais" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Rabais.value;
    nom = "MemTVA" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].TVA.value;
    nom = "MemQuantite" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Quantite.value;
    valeur_final =
      deux_dec(this.document.forms["info"].Quantite.value) *
      deux_dec(this.document.forms["info"].Prix.value) *
      ((100.0 +
        parseFloat(deux_dec(this.document.forms["info"].Rabais.value))) /
        100.0);
    if (this.document.forms["info"].TVA.value > 0) {
      valeur_final =
        valeur_final *
        ((100.0 + parseFloat(deux_dec(this.document.forms["info"].TVA.value))) /
          100.0);
    }
    if (this.document.forms["info"].IsCommande.value == 1) {
      valeur_final = Math.round(100.0 * valeur_final) / 100;
    } else {
      valeur_final = Math.round(20.0 * valeur_final) / 20;
    }
    texte = deux_dec(valeur_final);
    nom = "MemPrixTotal" + no;
    this.document.forms["info"].elements[nom].value = texte;
    nom = "MemStock" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Stock.value;
    nom = "MemGM" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].GM.value;
    if (this.document.forms["info"].IsCommande.value == 1) {
      nom = "MemDest" + no;
      this.document.forms["info"].elements[nom].value =
        this.document.forms["info"].Destinataire.value;
    }
    refresh_data(no);
  }
  calcule_total();
  clear_data();
}
function modif_select2() {
  AsChange = 1;
  no = this.document.forms["info"].ElementActuel.value;
  //  alert(no);
  this.document.forms["info"].modif_data.disabled = true;
  this.document.forms["info"].modif_text.disabled = true;
  if (no != -1) {
    StrLen = this.document.forms["info"].NoArticle.value.length;
    texte = this.document.forms["info"].NoArticle.value;
    nom = "MemNoArticle" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].NoArticle.value;
    max = 16;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = texte2 + " ";
      }
    }
    texte2 = texte2 + " ";
    texte_final = texte2;
    StrLen = this.document.forms["info"].Description.value.length;
    texte = this.document.forms["info"].Description.value;
    nom = "MemDescription" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Description.value;
    max = 40;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = texte2 + " ";
      }
    }
    texte2 = texte2 + " ";
    texte_final = texte_final + texte2;
    texte = deux_dec(this.document.forms["info"].Prix.value);
    StrLen = texte.length;
    nom = "MemPrix" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Prix.value;
    max = 9;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = " " + texte2;
      }
    }
    texte2 = texte2 + " ";
    texte_final = texte_final + texte2;
    texte = deux_dec(this.document.forms["info"].Rabais.value);
    StrLen = texte.length;
    nom = "MemRabais" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Rabais.value;
    max = 6;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = " " + texte2;
      }
    }
    texte2 = texte2 + " ";
    texte_final = texte_final + texte2;
    texte = deux_dec(this.document.forms["info"].TVA.value);
    StrLen = texte.length;
    nom = "MemTVA" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].TVA.value;
    max = 6;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = " " + texte2;
      }
    }
    texte2 = texte2 + " ";
    texte_final = texte_final + texte2;
    texte = deux_dec(this.document.forms["info"].Quantite.value);
    StrLen = texte.length;
    nom = "MemQuantite" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Quantite.value;
    max = 8;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = " " + texte2;
      }
    }
    texte2 = texte2 + " ";
    texte_final = texte_final + texte2;
    valeur_final =
      this.document.forms["info"].Quantite.value *
      this.document.forms["info"].Prix.value *
      ((100.0 + parseFloat(this.document.forms["info"].Rabais.value)) / 100.0);
    if (this.document.forms["info"].TVA.value > 0) {
      valeur_final =
        valeur_final *
        ((100.0 + parseFloat(this.document.forms["info"].TVA.value)) / 100.0);
    }
    valeur_final = Math.round(20.0 * valeur_final) / 20.0;
    texte = deux_dec(valeur_final);
    StrLen = texte.length;
    nom = "MemPrixTotal" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].Prix.value;
    max = 9;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = " " + texte2;
      }
    }
    texte_final = texte_final + texte2;
    //  o=new Option(texte_final,no);
    texte = Math.round(this.document.forms["info"].Stock.value);
    texte = texte + "";
    StrLen = texte.length;
    nom = "MemStock" + no;
    //  this.document.forms['info'].elements[nom].value=this.document.forms['info'].Quantite.value;
    this.document.forms["info"].elements[nom].value = texte;
    max = 5;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = " " + texte2;
      }
    }
    texte2 = " " + texte2;
    texte_final = texte_final + texte2;
    this.document.forms["info"].liste_articles.options[no].text = texte_final;
    nom = "MemGM" + no;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].GM.value;
  }
  calcule_total();
  clear_data();
}
function modif_select_text() {
  texte = this.document.forms["info"].Texte_libre.value;
  taille = texte.length;
  start = 0;
  tmp_no = no;
  nb_lignes = 0;
  ligne = texte;
  for (cont = 0; cont < taille; cont++) {
    if (texte.charCodeAt(cont) == 10) {
      if (nb_lignes == 0) {
        if (cont - 1 - start > 120) ligne = texte.substring(start, start + 120);
        else ligne = texte.substring(start, cont - 1);
        nom = "MemTypeData" + tmp_no;
        this.document.forms["info"].elements[nom].value = 1;
        nom = "MemDescription" + tmp_no;
        this.document.forms["info"].elements[nom].value = ligne;
        nom = "MemNoArticle" + tmp_no;
        this.document.forms["info"].elements[nom].value = "";
        nom = "MemPrix" + tmp_no;
        this.document.forms["info"].elements[nom].value = 0.0;
        nom = "MemRabais" + tmp_no;
        this.document.forms["info"].elements[nom].value = 0.0;
        nom = "MemTVA" + tmp_no;
        this.document.forms["info"].elements[nom].value = 0.0;
        nom = "MemQuantite" + tmp_no;
        this.document.forms["info"].elements[nom].value = 0.0;
        nom = "MemPrixTotal" + no;
        this.document.forms["info"].elements[nom].value = 0.0;
        nom = "MemStock" + no;
        this.document.forms["info"].elements[nom].value = 0.0;
        nom = "MemGM" + tmp_no;
        this.document.forms["info"].elements[nom].value = 0;
        this.document.forms["info"].liste_articles.options[no].text = ligne;
        start = parseInt(cont) + 1;
      }
      nb_lignes++;
      tmp_no;
    }
  }
  if (start != taille) {
    if (nb_lignes == 0) {
      if (taille - 1 - start > 120) ligne = texte.substring(start, start + 120);
      else ligne = texte.substring(start, taille);
      nom = "MemTypeData" + tmp_no;
      this.document.forms["info"].elements[nom].value = 1;
      nom = "MemDescription" + tmp_no;
      this.document.forms["info"].elements[nom].value = ligne;
      nom = "MemNoArticle" + tmp_no;
      this.document.forms["info"].elements[nom].value = "";
      nom = "MemPrix" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemRabais" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemTVA" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemQuantite" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemPrixTotal" + no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemStock" + no;
      this.document.forms["info"].elements[nom].value = 0.0;
      nom = "MemGM" + tmp_no;
      this.document.forms["info"].elements[nom].value = 0;
      this.document.forms["info"].liste_articles.options[no].text = ligne;
    }
    nb_lignes++;
    tmp_no;
  }
  AsChange = 1;
  this.document.forms["info"].modif_data.disabled = true;
  this.document.forms["info"].modif_text.disabled = true;
  this.document.forms["info"].ElementActuel.value = -1;
  this.document.forms["info"].Texte_libre.value = "";
}
function delete_select() {
  AsChange = 1;
  if (this.document.forms["info"].modif_data != undefined) {
    this.document.forms["info"].modif_data.disabled = true;
  }
  if (this.document.forms["info"].modif_text != undefined) {
    this.document.forms["info"].modif_text.disabled = true;
  }
  this.document.forms["info"].ElementActuel.value = -1;
  //  no=this.document.forms['info'].liste_articles.selectedIndex;
  nb = this.document.forms["info"].liste_articles.length;
  for (pos = nb - 1; pos >= 0; pos--) {
    if (this.document.forms["info"].liste_articles.options[pos].selected) {
      nb = this.document.forms["info"].liste_articles.length;
      this.document.forms["info"].liste_articles.options[pos] = null;
      for (cpt = pos + 1; cpt < nb; cpt++) {
        //    this.document.forms['info'].liste_articles.options[cpt-1]=this.document.forms['info'].liste_articles.options[cpt];
        nom = "MemTypeData" + cpt;
        nom2 = "MemTypeData" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemNoArticle" + cpt;
        nom2 = "MemNoArticle" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemDescription" + cpt;
        nom2 = "MemDescription" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemPrix" + cpt;
        nom2 = "MemPrix" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemTVA" + cpt;
        nom2 = "MemTVA" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemQuantite" + cpt;
        nom2 = "MemQuantite" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemRabais" + cpt;
        nom2 = "MemRabais" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemGM" + cpt;
        nom2 = "MemGM" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemPrixTotal" + cpt;
        nom2 = "MemPrixTotal" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        nom = "MemStock" + cpt;
        nom2 = "MemStock" + (cpt - 1);
        this.document.forms["info"].elements[nom2].value =
          this.document.forms["info"].elements[nom].value;
        if (this.document.forms["info"].IsCommande.value == 1) {
          nom = "MemDest" + cpt;
          nom2 = "MemDest" + (cpt - 1);
          this.document.forms["info"].elements[nom2].value =
            this.document.forms["info"].elements[nom].value;
          nom = "MemNbRecu" + cpt;
          nom2 = "MemNbRecu" + (cpt - 1);
          this.document.forms["info"].elements[nom2].value =
            this.document.forms["info"].elements[nom].value;
          nom = "MemDateRecu" + cpt;
          nom2 = "MemDateRecu" + (cpt - 1);
          this.document.forms["info"].elements[nom2].value =
            this.document.forms["info"].elements[nom].value;
        }
      }
      this.document.forms["info"].NbElements.value -= 1;
    }
  }
  calcule_total();
}
function move_up() {
  AsChange = 1;
  if (this.document.forms["info"].modif_data != undefined) {
    this.document.forms["info"].modif_data.disabled = true;
  }
  if (this.document.forms["info"].modif_text != undefined) {
    this.document.forms["info"].modif_text.disabled = true;
  }
  this.document.forms["info"].ElementActuel.value = -1;
  no = this.document.forms["info"].liste_articles.selectedIndex;
  if (no > 0) {
    tmp_text = this.document.forms["info"].liste_articles.options[no].text;
    this.document.forms["info"].liste_articles.options[no].text =
      this.document.forms["info"].liste_articles.options[no - 1].text;
    this.document.forms["info"].liste_articles.options[no - 1].text = tmp_text;
    nom = "MemTypeData" + no;
    nom2 = "MemTypeData" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemNoArticle" + no;
    nom2 = "MemNoArticle" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemDescription" + no;
    nom2 = "MemDescription" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemPrix" + no;
    nom2 = "MemPrix" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemTVA" + no;
    nom2 = "MemTVA" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemQuantite" + no;
    nom2 = "MemQuantite" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemRabais" + no;
    nom2 = "MemRabais" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemGM" + no;
    nom2 = "MemGM" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemPrixTotal" + no;
    nom2 = "MemPrixTotal" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemStock" + no;
    nom2 = "MemStock" + (no - 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    if (this.document.forms["info"].IsCommande.value == 1) {
      nom = "MemDest" + no;
      nom2 = "MemDest" + (no - 1);
      tmp_value = this.document.forms["info"].elements[nom].value;
      this.document.forms["info"].elements[nom].value =
        this.document.forms["info"].elements[nom2].value;
      this.document.forms["info"].elements[nom2].value = tmp_value;
      nom = "MemNbRecu" + no;
      nom2 = "MemNbRecu" + (no - 1);
      tmp_value = this.document.forms["info"].elements[nom].value;
      this.document.forms["info"].elements[nom].value =
        this.document.forms["info"].elements[nom2].value;
      this.document.forms["info"].elements[nom2].value = tmp_value;
      nom = "MemDateRecu" + no;
      nom2 = "MemDateRecu" + (no - 1);
      tmp_value = this.document.forms["info"].elements[nom].value;
      this.document.forms["info"].elements[nom].value =
        this.document.forms["info"].elements[nom2].value;
      this.document.forms["info"].elements[nom2].value = tmp_value;
    }
    this.document.forms["info"].liste_articles.selectedIndex = no - 1;
  }
}
function move_down() {
  AsChange = 1;
  if (this.document.forms["info"].modif_data != undefined) {
    this.document.forms["info"].modif_data.disabled = true;
  }
  if (this.document.forms["info"].modif_text != undefined) {
    this.document.forms["info"].modif_text.disabled = true;
  }
  this.document.forms["info"].ElementActuel.value = -1;
  no = this.document.forms["info"].liste_articles.selectedIndex;
  if (no + 1 != this.document.forms["info"].liste_articles.length) {
    tmp_text = this.document.forms["info"].liste_articles.options[no].text;
    this.document.forms["info"].liste_articles.options[no].text =
      this.document.forms["info"].liste_articles.options[no + 1].text;
    this.document.forms["info"].liste_articles.options[no + 1].text = tmp_text;
    nom = "MemTypeData" + no;
    nom2 = "MemTypeData" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemNoArticle" + no;
    nom2 = "MemNoArticle" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemDescription" + no;
    nom2 = "MemDescription" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemPrix" + no;
    nom2 = "MemPrix" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemTVA" + no;
    nom2 = "MemTVA" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemQuantite" + no;
    nom2 = "MemQuantite" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemRabais" + no;
    nom2 = "MemRabais" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemGM" + no;
    nom2 = "MemGM" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemPrixTotal" + no;
    nom2 = "MemPrixTotal" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    nom = "MemStock" + no;
    nom2 = "MemStock" + (no + 1);
    tmp_value = this.document.forms["info"].elements[nom].value;
    this.document.forms["info"].elements[nom].value =
      this.document.forms["info"].elements[nom2].value;
    this.document.forms["info"].elements[nom2].value = tmp_value;
    if (this.document.forms["info"].IsCommande.value == 1) {
      nom = "MemDest" + no;
      nom2 = "MemDest" + (no + 1);
      tmp_value = this.document.forms["info"].elements[nom].value;
      this.document.forms["info"].elements[nom].value =
        this.document.forms["info"].elements[nom2].value;
      this.document.forms["info"].elements[nom2].value = tmp_value;
      nom = "MemNbRecu" + no;
      nom2 = "MemNbRecu" + (no + 1);
      tmp_value = this.document.forms["info"].elements[nom].value;
      this.document.forms["info"].elements[nom].value =
        this.document.forms["info"].elements[nom2].value;
      this.document.forms["info"].elements[nom2].value = tmp_value;
      nom = "MemDateRecu" + no;
      nom2 = "MemDateRecu" + (no + 1);
      tmp_value = this.document.forms["info"].elements[nom].value;
      this.document.forms["info"].elements[nom].value =
        this.document.forms["info"].elements[nom2].value;
      this.document.forms["info"].elements[nom2].value = tmp_value;
    }
    this.document.forms["info"].liste_articles.selectedIndex = no + 1;
  }
}
function recherche_article() {
  alert("old version");
  NoArticle = document.forms["info"].elements["NoArticle"].value;
  NoClient = document.forms["info"].elements["NoClient"].value;
  IsCommande = document.forms["info"].elements["IsCommande"].value;
  IsAchatMarchandise =
    document.forms["info"].elements["IsAchatMarchandise"].value;
  commande_ajax_javascript(
    "recherche_article.php?NoArticle=" +
      NoArticle +
      "&NoClient=" +
      NoClient +
      "&Commande=" +
      IsCommande +
      "&AchatMarchandise=" +
      IsAchatMarchandise
  );
}
function calcule_total() {
  total = 0.0;
  form = document.forms["info"];
  nb = form.NbElements.value;
  for (cpt = 0; cpt < nb; cpt++) {
    nom = "MemTypeData" + cpt;
    TypeData = form.elements[nom].value;
    switch (parseInt(TypeData)) {
      case 0:
        nom = "MemPrix" + cpt;
        Prix = form.elements[nom].value;
        nom = "MemTVA" + cpt;
        TVA = form.elements[nom].value;
        nom = "MemQuantite" + cpt;
        Quantite = form.elements[nom].value;
        nom = "MemRabais" + cpt;
        Rabais = form.elements[nom].value;
        valeur_final =
          deux_dec(Quantite) *
          deux_dec(Prix) *
          ((100.0 + parseFloat(deux_dec(Rabais))) / 100.0);
        if (TVA > 0) {
          valeur_final =
            valeur_final * ((100.0 + parseFloat(deux_dec(TVA))) / 100.0);
        }
        if (this.document.forms["info"].IsCommande.value == 1) {
          valeur_final = Math.round(100.0 * valeur_final) / 100.0;
        } else {
          valeur_final = Math.round(20.0 * valeur_final) / 20.0;
        }
        texte = deux_dec(valeur_final);
        total = total + parseFloat(texte);
        break;
    }
  }
  total = Math.round(20.0 * total) / 20.0;
  texte = deux_dec(total);
  longueur = texte.length;
  plus = "";
  for (cpt = 0; cpt < 9 - longueur; cpt++) {
    plus = plus + " ";
  }
  texte_liste =
    "                                                                                           " +
    plus +
    texte;
  nom = "liste_total";
  this.document.forms["info"].elements[nom].value = texte_liste;
}
function refresh_data(pos) {
  var cpt;
  nom = "MemNoArticle" + pos;
  texte = this.document.forms["info"].elements[nom].value;
  StrLen = texte.length;
  max = 16;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = texte2 + " ";
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte2;
  nom = "MemDescription" + pos;
  texte = this.document.forms["info"].elements[nom].value;
  StrLen = texte.length;
  max = 40;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = texte2 + " ";
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  nom = "MemPrix" + pos;
  texte = this.document.forms["info"].elements[nom].value;
  StrLen = texte.length;
  max = 9;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  nom = "MemRabais" + pos;
  texte = this.document.forms["info"].elements[nom].value;
  StrLen = texte.length;
  max = 6;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  nom = "MemTVA" + pos;
  texte = this.document.forms["info"].elements[nom].value;
  StrLen = texte.length;
  max = 6;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  nom = "MemQuantite" + pos;
  texte = this.document.forms["info"].elements[nom].value;
  StrLen = texte.length;
  max = 8;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = texte2 + " ";
  texte_final = texte_final + texte2;
  nom = "MemQuantite" + pos;
  nom2 = "MemPrix" + pos;
  nom3 = "MemRabais" + pos;
  nom4 = "MemTVA" + pos;
  valeur_final =
    this.document.forms["info"].elements[nom].value *
    this.document.forms["info"].elements[nom2].value *
    ((100.0 + parseFloat(this.document.forms["info"].elements[nom3].value)) /
      100.0);
  if (this.document.forms["info"].elements[nom4].value > 0) {
    valeur_final =
      valeur_final *
      ((100.0 + parseFloat(this.document.forms["info"].elements[nom4].value)) /
        100.0);
  }
  if (this.document.forms["info"].IsCommande.value == 1) {
    valeur_final = Math.round(100.0 * valeur_final) / 100.0;
  } else {
    valeur_final = Math.round(20.0 * valeur_final) / 20.0;
  }
  texte = deux_dec(valeur_final);
  StrLen = texte.length;
  max = 9;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte_final = texte_final + texte2;
  nom = "MemStock" + pos;
  texte = this.document.forms["info"].elements[nom].value;
  StrLen = texte.length;
  max = 5;
  if (StrLen > max) {
    texte2 = texte.substring(0, max);
    texte = texte2;
  } else {
    texte2 = texte;
    for (cpt = StrLen; cpt < max; cpt++) {
      texte2 = " " + texte2;
    }
  }
  texte2 = " " + texte2;
  texte_final = texte_final + texte2;
  if (this.document.forms["info"].IsCommande.value == 1) {
    nom = "MemQuantite" + pos;
    nom2 = "MemNbRecu" + pos;
    nom3 = "MemDateRecu" + pos;
    nom4 = "MemDest" + pos;
    texte = this.document.forms["info"].elements[nom4].value;
    StrLen = texte.length;
    max = 14;
    if (StrLen > max) {
      texte2 = texte.substring(0, max);
      texte = texte2;
    } else {
      texte2 = texte;
      for (cpt = StrLen; cpt < max; cpt++) {
        texte2 = texte2 + " ";
      }
    }
    texte_final = texte_final + " " + texte2;
    if (this.document.forms["info"].elements[nom2].value == 0) {
      texte_final = texte_final + "      NON           ";
    } else if (
      this.document.forms["info"].elements[nom].value ==
      this.document.forms["info"].elements[nom2].value
    ) {
      d = this.document.forms["info"].elements[nom3].value;
      texte_final =
        texte_final +
        "      OUI " +
        d.substr(8, 2) +
        "." +
        d.substr(5, 2) +
        "." +
        d.substr(0, 4);
    } else {
      d = this.document.forms["info"].elements[nom3].value;
      texte = this.document.forms["info"].elements[nom2].value;
      StrLen = texte.length;
      max = 9;
      if (StrLen > max) {
        texte2 = texte.substring(0, max);
        texte = texte2;
      } else {
        texte2 = texte;
        for (cpt = StrLen; cpt < max; cpt++) {
          texte2 = " " + texte2;
        }
      }
      texte_final = texte_final + texte2;
      texte_final =
        texte_final +
        " " +
        d.substr(8, 2) +
        "." +
        d.substr(5, 2) +
        "." +
        d.substr(0, 4);
    }
  }
  this.document.forms["info"].liste_articles.options[pos].text = texte_final;
}
function recep_comp() {
  AsChange = 1;
  nb = this.document.forms["info"].NbElements.value;
  dt = new Date();
  date = dt.getFullYear() + "-";
  if (parseInt(dt.getMonth()) + 1 < 10) date = date + "0";
  date = date + (parseInt(dt.getMonth()) + 1) + "-";
  if (parseInt(dt.getDate()) < 10) date = date + "0";
  date = date + dt.getDate();
  for (cpt = 0; cpt < nb; cpt++) {
    nom = "MemTypeData" + cpt;
    TypeData = this.document.forms["info"].elements[nom].value;
    if (TypeData == 0) {
      nom = "MemQuantite" + cpt;
      Quantite = this.document.forms["info"].elements[nom].value;
      nom = "MemNbRecu" + cpt;
      NbRecu = this.document.forms["info"].elements[nom].value;
      if (Quantite != NbRecu) {
        this.document.forms["info"].elements[nom].value = Quantite;
        nom = "MemDateRecu" + cpt;
        this.document.forms["info"].elements[nom].value = date;
        refresh_data(cpt);
      }
    }
  }
}
function recep_comp_newfact() {}
function recep_art() {
  AsChange = 1;
  cpt = this.document.forms["info"].liste_articles.selectedIndex;
  if (cpt != -1) {
    dt = new Date();
    date = dt.getFullYear() + "-";
    if (parseInt(dt.getMonth()) + 1 < 10) date = date + "0";
    date = date + (parseInt(dt.getMonth()) + 1) + "-";
    if (parseInt(dt.getDate()) < 10) date = date + "0";
    date = date + dt.getDate();
    nom = "MemTypeData" + cpt;
    TypeData = this.document.forms["info"].elements[nom].value;
    if (TypeData == 0) {
      nom = "MemQuantite" + cpt;
      Quantite = this.document.forms["info"].elements[nom].value;
      nom = "MemNbRecu" + cpt;
      NbRecu = this.document.forms["info"].elements[nom].value;
      if (Quantite != NbRecu) {
        this.document.forms["info"].elements[nom].value = Quantite;
        nom = "MemDateRecu" + cpt;
        this.document.forms["info"].elements[nom].value = date;
        refresh_data(cpt);
      }
    }
  }
}
function recep_part() {
  AsChange = 1;
  cpt = this.document.forms["info"].liste_articles.selectedIndex;
  if (cpt != -1) {
    dt = new Date();
    date = dt.getFullYear() + "-";
    if (parseInt(dt.getMonth()) + 1 < 10) date = date + "0";
    date = date + (parseInt(dt.getMonth()) + 1) + "-";
    if (parseInt(dt.getDate()) < 10) date = date + "0";
    date = date + dt.getDate();
    nom = "MemTypeData" + cpt;
    TypeData = this.document.forms["info"].elements[nom].value;
    if (TypeData == 0) {
      nom = "MemQuantite" + cpt;
      Quantite = this.document.forms["info"].elements[nom].value;
      nom = "MemNbRecu" + cpt;
      NbRecu = this.document.forms["info"].elements[nom].value;
      NbRecu =
        parseFloat(NbRecu) +
        parseFloat(this.document.forms["info"].NbPart.value);
      this.document.forms["info"].elements[nom].value = deux_dec(NbRecu);
      nom = "MemDateRecu" + cpt;
      this.document.forms["info"].elements[nom].value = date;
      Reste = parseFloat(Quantite) - parseFloat(NbRecu);
      this.document.forms["info"].NbPart.value = deux_dec(Reste);
      refresh_data(cpt);
    }
  }
}
function change_position() {
  if (this.document.forms["info"].IsCommande.value == 1) {
    cpt = this.document.forms["info"].liste_articles.selectedIndex;
    nom = "MemQuantite" + cpt;
    Quantite = this.document.forms["info"].elements[nom].value;
    nom = "MemNbRecu" + cpt;
    NbRecu = this.document.forms["info"].elements[nom].value;
    Reste = parseFloat(Quantite) - parseFloat(NbRecu);
    this.document.forms["info"].NbPart.value = deux_dec(Reste);
  }
}
function copyToClipboard_newfact() {
  var order = jQuery("#tblBody").sortable("toArray");
  var total = 0;
  var txt = "";
  var first = true;
  for (var i in order) {
    var num = order[i].substr(2);
    var obj = jQuery("#type" + num);
    if (obj[0].value == "article") {
      if (!first) {
        txt += "\n";
      }
      first = false;
      obj = jQuery("#NoArticle" + num);
      txt += obj[0].value;
      txt += "\t";
      obj = jQuery("#Quantite" + num);
      txt += "" + parseInt(obj[0].value);
      if (this.document.forms["info"].IsCommande.value == 1) {
        txt += "\t";
        obj = jQuery("#Destinataire" + num);
        txt += obj[0].value;
      }
    }
  }
  this.document.forms["info"].elements["FullText"].value = txt;
  // Copie du contenu du textarea caché dans le presse-papier
  var fullText = this.document.forms["info"].elements["FullText"];
  fullText.select();
  fullText.focus();
  //var textRange = fullText.createTextRange();
  var textRange = fullText.createTextRange();
  //alert("av copy");
  //window.clipboardData.setData('text', txt);
  textRange.execCommand("Copy");
  //alert("ap copy");
  //  fullText.blur();
}
function copyToClipboard_newfact_ff() {
  var order = jQuery("#tblBody").sortable("toArray");
  var total = 0;
  var txt = "";
  var first = true;
  for (var i in order) {
    var num = order[i].substr(2);
    var obj = jQuery("#type" + num);
    if (obj[0].value == "article") {
      if (!first) {
        txt += "\n";
      }
      first = false;
      obj = jQuery("#NoArticle" + num);
      txt += obj[0].value;
      txt += "\t";
      obj = jQuery("#Quantite" + num);
      txt += "" + parseInt(obj[0].value);
      if (this.document.forms["info"].IsCommande.value == 1) {
        txt += "\t";
        obj = jQuery("#Destinataire" + num);
        txt += obj[0].value;
      }
    }
  }
  this.document.forms["info"].elements["presse_papier"].value = txt;
  // Copie du contenu du textarea caché dans le presse-papier
  var fullText = this.document.forms["info"].elements["presse_papier"];
  fullText.focus();
  fullText.setSelectionRange(0, 0);
  fullText.select();
}
function copyToClipboard() {
  // Création du texte complet et copie dans le textarea caché
  nb = this.document.forms["info"].NbElements.value;
  var txt = "";
  for (i = 0; i < nb; i++) {
    nom = "MemTypeData" + i;
    texte = this.document.forms["info"].elements[nom].value;
    if (texte == 0) {
      nom = "MemNoArticle" + i;
      texte = this.document.forms["info"].elements[nom].value;
      txt += texte;
      txt += "\t";
      nom = "MemQuantite" + i;
      texte = this.document.forms["info"].elements[nom].value;
      txt += "" + parseInt(texte);
      if (this.document.forms["info"].IsCommande.value == 1) {
        txt += "\t";
        nom = "MemDest" + i;
        texte = this.document.forms["info"].elements[nom].value;
        txt += texte;
      }
      if (i + 1 < nb) {
        txt += "\n";
      }
    }
  }
  this.document.forms["info"].elements["FullText"].value = txt;
  // Copie du contenu du textarea caché dans le presse-papier
  var fullText = this.document.forms["info"].elements["FullText"];
  fullText.select();
  fullText.focus();
  //var textRange = fullText.createTextRange();
  var textRange = fullText.createTextRange();
  //alert("av copy");
  //window.clipboardData.setData('text', txt);
  textRange.execCommand("Copy");
  //alert("ap copy");
  //  fullText.blur();
}
function pasteFromClipboard_newfact() {
  IsCommande = document.forms["info"].elements["IsCommande"].value;
  textRange = document.forms["info"].elements["FullText"].createTextRange();
  //  textRange.execCommand("RemoveFormat");
  textRange.execCommand("Paste");
  //  txt=doPaste(document.forms['info'].elements['FullText']);
  txt = document.forms["info"].elements["FullText"].value;
  var temp;
  var continuer = true;
  var reg1 = new RegExp("\n", "g");
  var timeout = 0;
  var reg2 = new RegExp("\t", "g");
  var tableau = txt.split(reg1);
  for (var i = 0; i < tableau.length; i++) {
    tableau[i] = tableau[i].split(reg2);
  }
  if (!confirm("Tri par no d'article")) {
    continuer = false;
  }
  while (continuer) {
    continuer = false;
    for (var i = 0; i < tableau.length - 1; i++) {
      if (tableau[i + 1][0] < tableau[i][0]) {
        temp = tableau[i];
        tableau[i] = tableau[i + 1];
        tableau[i + 1] = temp;
        continuer = true;
      }
    }
  }
  for (var i = 0; i < tableau.length; i++) {
    NoArticle = tableau[i][0];
    NbArticles = tableau[i][1];
    NoClient = this.document.forms["info"].elements["NoClient"].value;
    commande_ajax_javascript(
      "recherche_article.php?NoArticle=" +
        NoArticle +
        "&NoClient=" +
        NoClient +
        "&Commande=" +
        IsCommande +
        "&NbArticles=" +
        NbArticles +
        "&go_last=1"
    );
    if (IsCommande) {
      //document.info.Destinataire.value = tableau[i][2];
    }
    add_new_newfact(false);
  }

  calcule_total_newfact();
}
function pasteFromClipboard_newfact_ff() {
  IsCommande = document.forms["info"].elements["IsCommande"].value;
  txt = document.forms["info"].elements["presse_papier"].value;
  var temp;
  var continuer = true;
  var reg1 = new RegExp("\n", "g");
  var timeout = 0;
  var reg2 = new RegExp("\t", "g");
  var tableau = txt.split(reg1);
  for (var i = 0; i < tableau.length; i++) {
    tableau[i] = tableau[i].split(reg2);
  }
  if (!confirm("Tri par no d'article")) {
    continuer = false;
  }
  while (continuer) {
    continuer = false;
    for (var i = 0; i < tableau.length - 1; i++) {
      if (tableau[i + 1][0] < tableau[i][0]) {
        temp = tableau[i];
        tableau[i] = tableau[i + 1];
        tableau[i + 1] = temp;
        continuer = true;
      }
    }
  }
  for (var i = 0; i < tableau.length; i++) {
    NoArticle = tableau[i][0];
    NbArticles = tableau[i][1];
    NoClient = this.document.forms["info"].elements["NoClient"].value;
    commande_ajax_javascript(
      "recherche_article.php?NoArticle=" +
        NoArticle +
        "&NoClient=" +
        NoClient +
        "&Commande=" +
        IsCommande +
        "&NbArticles=" +
        NbArticles +
        "&go_last=1"
    );
    if (IsCommande) {
      //document.info.Destinataire.value = tableau[i][2];
    }
    add_new_newfact(false);
  }

  calcule_total_newfact();
}

function pasteFromClipboard() {
  IsCommande = document.forms["info"].elements["IsCommande"].value;
  textRange = document.forms["info"].elements["FullText"].createTextRange();
  //  textRange.execCommand("RemoveFormat");
  textRange.execCommand("Paste");
  //  txt=doPaste(document.forms['info'].elements['FullText']);
  txt = document.forms["info"].elements["FullText"].value;
  var temp;
  var continuer = true;
  var reg1 = new RegExp("\n", "g");
  var timeout = 0;
  var reg2 = new RegExp("\t", "g");
  var tableau = txt.split(reg1);
  for (var i = 0; i < tableau.length; i++) {
    tableau[i] = tableau[i].split(reg2);
  }
  if (!confirm("Tri par no d'article")) {
    continuer = false;
  }
  while (continuer) {
    continuer = false;
    for (var i = 0; i < tableau.length - 1; i++) {
      if (tableau[i + 1][0] < tableau[i][0]) {
        temp = tableau[i];
        tableau[i] = tableau[i + 1];
        tableau[i + 1] = temp;
        continuer = true;
      }
    }
  }
  for (var i = 0; i < tableau.length; i++) {
    NoArticle = tableau[i][0];
    NbArticles = tableau[i][1];
    NoClient = this.document.forms["info"].elements["NoClient"].value;
    commande_ajax_javascript(
      "recherche_article.php?NoArticle=" +
        NoArticle +
        "&NoClient=" +
        NoClient +
        "&Commande=" +
        IsCommande +
        "&NbArticles=" +
        NbArticles +
        "&go_last=1"
    );
    add_new(false);
  }
  calcule_total();
}
function add_bultin() {
  cpt = this.document.forms["info"].liste_bultin.selectedIndex;
  if (cpt != -1) {
    cpt = this.document.forms["info"].liste_bultin.options[cpt].value;
    nom = "Bul" + cpt;
    NoCommande = this.document.forms["info"].elements[nom].value;
    commande_ajax_javascript("import_bultin.php?NoCommande=" + NoCommande);
    no = this.document.forms["info"].liste_bultin.selectedIndex;
    this.document.forms["info"].liste_bultin.options[no] = null;
    calcule_total();
    MustSave = 1;
  }
}
function add_bultin_newfact() {
  cpt = this.document.forms["info"].liste_bultin.selectedIndex;
  if (cpt != -1) {
    cpt = this.document.forms["info"].liste_bultin.options[cpt].value;
    nom = "Bul" + cpt;
    NoCommande = this.document.forms["info"].elements[nom].value;
    commande_ajax_javascript(
      "import_bultin_newfact.php?NoCommande=" + NoCommande
    );
    no = this.document.forms["info"].liste_bultin.selectedIndex;
    this.document.forms["info"].liste_bultin.options[no] = null;
    calcule_total();
    MustSave = 1;
  }
}
function vendre_vhc(NoClient, NoClient2, NoCommande, Devis) {
  cpt = this.document.forms["info"].liste_vhc_vente.selectedIndex;
  if (cpt != -1) {
    cpt = this.document.forms["info"].liste_vhc_vente.options[cpt].value;
    nom = "Vhc" + cpt;
    NoChasis = this.document.forms["info"].elements[nom].value;
    nom = "VhcType" + cpt;
    Type = this.document.forms["info"].elements[nom].value;
    commande_ajax_javascript(
      "import_vhc_vente.php?Mode=0&NoCommande=" +
        NoCommande +
        "&NoChasis=" +
        NoChasis +
        "&Type=" +
        Type +
        "&NoClient=" +
        NoClient +
        "&NoClient2=" +
        NoClient2 +
        "&Devis=" +
        Devis
    );
  }
}
function vendre_vhc_newfact(NoClient, NoClient2, NoCommande, Devis) {
  if (NoClient == 0) {
    alert("Vous devez saisir un client avant d'effectuer un vente de véhicule");
    return;
  }
  cpt = this.document.forms["info"].liste_vhc_vente.selectedIndex;
  if (cpt != -1) {
    cpt = this.document.forms["info"].liste_vhc_vente.options[cpt].value;
    nom = "Vhc" + cpt;
    NoChasis = this.document.forms["info"].elements[nom].value;
    nom = "VhcType" + cpt;
    Type = this.document.forms["info"].elements[nom].value;
    commande_ajax_javascript(
      "import_vhc_vente_newfact.php?Mode=0&NoCommande=" +
        NoCommande +
        "&NoChasis=" +
        NoChasis +
        "&Type=" +
        Type +
        "&NoClient=" +
        NoClient +
        "&NoClient2=" +
        NoClient2 +
        "&Devis=" +
        Devis
    );
  }
}
function achat_vhc(NoClient, NoCommande, Type) {
  NoChasis = this.document.forms["info"].NoChasisAchat.value;
  commande_ajax_javascript(
    "import_vhc_achat.php?Mode=0&NoCommande=" +
      NoCommande +
      "&NoChasis=" +
      NoChasis +
      "&Type=" +
      Type +
      "&NoClient=" +
      NoClient
  );
}
function achat_vhc_newfact(NoClient, NoCommande, Type) {
  NoChasis = this.document.forms["info"].NoChasisAchat.value;
  commande_ajax_javascript(
    "import_vhc_achat_newfact.php?Mode=0&NoCommande=" +
      NoCommande +
      "&NoChasis=" +
      NoChasis +
      "&Type=" +
      Type +
      "&NoClient=" +
      NoClient
  );
}
function insertNoCommande_newfact(mode) {
  NoCommande = this.document.forms["info"].NoImport.value;
  commande_ajax_javascript(
    "import_commande_newfact.php?NoCommande=" + NoCommande + "&mode=" + mode
  );
}
function insertNoModele() {
  NoCommande = $(".select_modele").val();
  //alert(NoCommande);
  mode = 2;
  commande_ajax_javascript(
    "import_commande_newfact.php?NoCommande=" + NoCommande + "&mode=" + mode
  );
}
function insertNoCommande(mode) {
  NoCommande = this.document.forms["info"].NoImport.value;
  commande_ajax_javascript(
    "import_commande.php?NoCommande=" + NoCommande + "&mode=" + mode
  );
}
//----------------------------------------------------------------------------------------------------------------------------
function update_free_text(obj) {
  //alert(obj.value);
  rows = get_num_row(obj.value);
  if (obj.rows != rows) {
    obj.rows = rows;
    compte_lignes_newfact();
  }
}
function get_num_row(text) {
  nb_return = 0;
  pos = 0;
  pos_return = text.indexOf("\n", pos);
  while (pos_return != -1) {
    nb_return++;
    //alert(pos_return);
    if (pos_return > pos + 91) {
      pos += 91;
    } else {
      pos = pos_return + 1;
    }
    pos_return = text.indexOf("\n", pos);
  }
  return nb_return + 1;
}
function up(id) {
  tab = document.getElementById("table_articles");
  pos = 0;
  for (cpt = 0; cpt < tab.rows.length; cpt++) {
    //alert(tab.rows[cpt].id);
    if (tab.rows[cpt].id == id) {
      pos = cpt;
      //alert("found row at pos "+cpt);
    }
  }
  if (pos > 1) {
    tab = move(tab, pos, -1);
  }
}
function down(id) {
  tab = document.getElementById("table_articles");
  pos = 0;
  for (cpt = 0; cpt < tab.rows.length; cpt++) {
    //alert(tab.rows[cpt].id);
    if (tab.rows[cpt].id == id) {
      pos = cpt;
      //alert("found row at pos "+cpt);
    }
  }
  if (pos < tab.rows.length - 3) {
    tab = move(tab, pos, 1);
  }
}
function move(tbl, rowindx, direction) {
  var aRowIndex = rowindx + direction;
  var curr = tbl.rows[rowindx];
  var othr = tbl.rows[aRowIndex];

  if (direction == -1) {
    othr.parentNode.insertBefore(curr, othr);
  }
  if (direction == 1) {
    othr.parentNode.insertBefore(curr, othr.nextSibling);
  }
}
function del(id) {
  tab = document.getElementById("table_articles");
  pos = 0;
  for (cpt = 0; cpt < tab.rows.length; cpt++) {
    //alert(tab.rows[cpt].id);
    if (tab.rows[cpt].id == id) {
      rIndex = tab.rows[cpt].sectionRowIndex;
      tab.rows[cpt].parentNode.deleteRow(rIndex);
    }
  }
  calcule_total_newfact();
  compte_lignes_newfact();
}
function maj_article_fact_new(e) {
  var tmp_name = this.name;
  while (isNaN(tmp_name)) {
    tmp_name = tmp_name.substring(1);
  }
  maj_article_fact(tmp_name);
}
function maj_article_fact(id) {
  var prix = this.document.forms["info"]["Prix" + id].value;
  this.document.forms["info"]["Prix" + id].value = deux_dec(
    this.document.forms["info"]["Prix" + id].value
  );
  var rabais = this.document.forms["info"]["Rabais" + id].value;
  this.document.forms["info"]["Rabais" + id].value = deux_dec(
    this.document.forms["info"]["Rabais" + id].value
  );
  var tva = this.document.forms["info"]["TVA" + id].value;
  this.document.forms["info"]["TVA" + id].value = deux_dec(
    this.document.forms["info"]["TVA" + id].value
  );
  var quantite = this.document.forms["info"]["Quantite" + id].value;
  this.document.forms["info"]["Quantite" + id].value = deux_dec(
    this.document.forms["info"]["Quantite" + id].value
  );
  var valeur_final =
    quantite * prix * ((100.0 + parseFloat(deux_dec(rabais))) / 100.0);
  if (tva > 0) {
    valeur_final = valeur_final * ((100.0 + parseFloat(deux_dec(tva))) / 100.0);
  }
  if (this.document.forms["info"].IsCommande.value == 1) {
    valeur_final = Math.round(100.0 * valeur_final) / 100;
  } else {
    valeur_final = Math.round(20.0 * valeur_final) / 20;
  }
  var texte = deux_dec(valeur_final);
  obj = this.document.getElementById("tot" + id);
  obj.innerHTML = texte;
  calcule_total_newfact();
}
function calcule_total_newfact() {
  var order = jQuery("#tblBody").sortable("toArray");
  var total = 0;
  var partiel = 0;
  var partiel2 = 0;
  for (var i in order) {
    var num = order[i].substr(2);
    var obj = jQuery("#type" + num);
    if (obj[0].value == "article") {
      obj = jQuery("#tot" + num);
      total += 1 * obj[0].innerHTML;
      partiel += 1 * obj[0].innerHTML;
      partiel2 += 1 * obj[0].innerHTML;
    }
    if (obj[0].value == "ajouttva") {
      obj = jQuery("#tot" + num);
      total += 1 * obj[0].innerHTML;
      partiel += 1 * obj[0].innerHTML;
      partiel2 += 1 * obj[0].innerHTML;
    }
    if (obj[0].value == "inter") {
      var obj2 = jQuery("#inter" + num);
      if (this.document.forms["info"].IsCommande.value == 1) {
        total = Math.round(100.0 * total) / 100;
      } else {
        total = Math.round(20.0 * total) / 20;
      }
      obj2[0].innerHTML = deux_dec(total);
    }
    if (obj[0].value == "partiel") {
      var obj2 = jQuery("#partiel" + num);
      if (this.document.forms["info"].IsCommande.value == 1) {
        partiel = Math.round(100.0 * partiel) / 100;
      } else {
        partiel = Math.round(20.0 * partiel) / 20;
      }
      obj2[0].innerHTML = deux_dec(partiel);
      partiel = 0;
    }
    if (obj[0].value == "partiel2") {
      var obj2 = jQuery("#partiel2_" + num);
      if (this.document.forms["info"].IsCommande.value == 1) {
        partiel2 = Math.round(100.0 * partiel2) / 100;
      } else {
        partiel2 = Math.round(20.0 * partiel2) / 20;
      }
      obj2[0].innerHTML = deux_dec(partiel2);
      partiel2 = 0;
    }
  }
  if (this.document.forms["info"].IsCommande.value == 1) {
    total = Math.round(100.0 * total) / 100;
  } else {
    total = Math.round(20.0 * total) / 20;
  }
  var texte = deux_dec(total);
  var obj_total = jQuery("#total");
  obj_total[0].innerHTML = texte;
  AsChange = 1;
  //alert("refresh sort");
  //sort();
  //jQuery("#tblBody").sortable( "destroy" );
  //jQuery("#tblBody").sortable("refreshPositions");
  //sort_table();
}
function recep_comp_newfact() {
  var order = jQuery("#tblBody").sortable("toArray");
  var total = 0;
  var dt = new Date();
  var date = dt.getFullYear() + "-";
  var date_str = "." + dt.getFullYear();
  if (parseInt(dt.getMonth()) + 1 < 10) {
    date_str = ".0" + (parseInt(dt.getMonth()) + 1) + date_str;
    date = date + "0";
  } else {
    date_str = "." + (parseInt(dt.getMonth()) + 1) + date_str;
  }
  date = date + (parseInt(dt.getMonth()) + 1) + "-";
  if (parseInt(dt.getDate()) < 10) {
    date_str = "0" + parseInt(dt.getDate()) + date_str;
    date = date + "0";
  } else {
    date_str = "" + parseInt(dt.getDate()) + date_str;
  }
  date = date + dt.getDate();
  for (var i in order) {
    var num = order[i].substr(2);
    var obj = jQuery("#type" + num);
    if (obj[0].value == "article") {
      var obj2 = jQuery("#Quantite" + num);
      var obj3 = jQuery("#NbRecu" + num);
      if (obj3[0].value != obj2[0].value) {
        var obj4 = jQuery("#DateRecu" + num);
        var obj5 = jQuery("#DateRecuStr" + num);
        obj3[0].value = obj2[0].value;
        obj4[0].value = date;
        obj5[0].innerHTML = date_str;
      }
    }
  }
}
function change_recu_new(e) {
  change_recu(this.name.substring(6));
}
function change_recu(num) {
  var obj_val = jQuery("#NbRecu" + num);
  obj_val[0].value = deux_dec(obj_val[0].value);
  var dt = new Date();
  var date = dt.getFullYear() + "-";
  var date_str = "." + dt.getFullYear();
  if (parseInt(dt.getMonth()) + 1 < 10) {
    date_str = ".0" + (parseInt(dt.getMonth()) + 1) + date_str;
    date = date + "0";
  } else {
    date_str = "." + (parseInt(dt.getMonth()) + 1) + date_str;
  }
  date = date + (parseInt(dt.getMonth()) + 1) + "-";
  if (parseInt(dt.getDate()) < 10) {
    date_str = "0" + parseInt(dt.getDate()) + date_str;
    date = date + "0";
  } else {
    date_str = "" + parseInt(dt.getDate()) + date_str;
  }
  date = date + dt.getDate();
  var obj = jQuery("#DateRecu" + num);
  var obj2 = jQuery("#DateRecuStr" + num);
  obj[0].value = date;
  obj2[0].innerHTML = date_str;
}
valTotInter = [
  "A payer net :",
  "Total des travaux effectués :",
  "Solde à payer :",
];
valTotPartiel = [
  "Total des fournitures :",
  "Total main d'oeuvre :",
  "Total pour service :",
];
$(function () {
  $(".total_intermediaire_visu input").autocomplete({ source: valTotInter });
  $(".total_partiel_visu input").autocomplete({ source: valTotPartiel });
});
function affiche_prix(obj) {
  var table_prix = $("#table_articles");
  if (obj.checked) {
    table_prix.removeClass("hide_prix");
  } else {
    table_prix.addClass("hide_prix");
  }
}

function compte_lignes_newfact() {
  //alert("Compte");
  var nb_lignes = 0;
  $("#table_articles tbody > tr").each(function (index) {
    var obj = $(this);
    //alert(obj.attr("type"));
    switch (obj.attr("type")) {
      case "text":
        var ta = obj.find("textarea");
        nb_lignes = nb_lignes + parseInt(ta.attr("rows"));
        break;
      default:
        nb_lignes++;
        break;
    }
  });
  nb_pages = Math.floor((nb_lignes - 1) / 35);
  nb_pages++;
  var texte_info_page = "Nb lignes " + nb_lignes + " Pages " + nb_pages;
  $("#info_lignes").html(texte_info_page);
  if (nb_pages > 1) {
    $("#info_lignes").css("background-color", "orange");
  } else {
    $("#info_lignes").css("background-color", "");
  }
}
