primpays='';var primregion='';  
var totalligne = 0, totalTva=0, soustotal = 0, totalpourport = 0; type_trs= ''; sigma_pds=0; sigma_qte=0;
var soustotal_tempo=0,  tps=0, tvp=0, passage_port=false, anc_tx_port=0, anc_tx_montant=0;
var cart = new Object;
fraisdeport= new Array(65);
fraisdeport[0] = 54;
fraisdeport[1] = 6;
fraisdeport[2] = "ESPAGNE,BELGIQUE,SUISSE,ROYAUME-UNI";
fraisdeport[3] = "LA POSTE (PTT)";
fraisdeport[4] = 0;

fraisdeport[5] = 480;
fraisdeport[6] = 12;
fraisdeport[7] = "ESPAGNE,BELGIQUE,SUISSE,ROYAUME-UNI";
fraisdeport[8] = "LA POSTE (PTT)";
fraisdeport[9] = 0;

fraisdeport[10] = 800;
fraisdeport[11] = 18;
fraisdeport[12] = "ESPAGNE,BELGIQUE,SUISSE,ROYAUME-UNI";
fraisdeport[13] = "LA POSTE (PTT)";
fraisdeport[14] = 0;

fraisdeport[15] = 100000;
fraisdeport[16] = 24;
fraisdeport[17] = "ESPAGNE,BELGIQUE,SUISSE,ROYAUME-UNI";
fraisdeport[18] = "LA POSTE (PTT)";
fraisdeport[19] = 0;

fraisdeport[20] = 54;
fraisdeport[21] = 6;
fraisdeport[22] = "FRANCE ( LA REUNION ),FRANCE ( GUYANE ),FRANCE ( POLYNESIE FRANCAISE ),FRANCE ( MARTINIQUE ),FRANCE ( NOUVELLE CALEDONIE ),FRANCE ( SAINT PIERRE ET MIQUELON ),FRANCE ( GUADELOUPE ),FRANCE ( MAYOTTE ),FRANCE ( WALLIS ET FUTUNA )";
fraisdeport[23] = "LA POSTE (PTT)";
fraisdeport[24] = 0;

fraisdeport[25] = 480;
fraisdeport[26] = 12;
fraisdeport[27] = "FRANCE ( LA REUNION ),FRANCE ( GUYANE ),FRANCE ( POLYNESIE FRANCAISE ),FRANCE ( MARTINIQUE ),FRANCE ( NOUVELLE CALEDONIE ),FRANCE ( SAINT PIERRE ET MIQUELON ),FRANCE ( GUADELOUPE ),FRANCE ( MAYOTTE ),FRANCE ( WALLIS ET FUTUNA )";
fraisdeport[28] = "LA POSTE (PTT)";
fraisdeport[29] = 0;

fraisdeport[30] = 100000;
fraisdeport[31] = 18;
fraisdeport[32] = "FRANCE ( LA REUNION ),FRANCE ( GUYANE ),FRANCE ( POLYNESIE FRANCAISE ),FRANCE ( MARTINIQUE ),FRANCE ( NOUVELLE CALEDONIE ),FRANCE ( SAINT PIERRE ET MIQUELON ),FRANCE ( GUADELOUPE ),FRANCE ( MAYOTTE ),FRANCE ( WALLIS ET FUTUNA )";
fraisdeport[33] = "LA POSTE (PTT)";
fraisdeport[34] = 0;

fraisdeport[35] = 54;
fraisdeport[36] = 12;
fraisdeport[37] = "ALGERIE,ALLEMAGNE,ANDORRE,CANADA,COTE D'IVOIRE,DANEMARK,ETATS-UNIS,FINLANDE,GABON,GRECE,IRLANDE,ISLANDE,ITALIE,LUXEMBOURG,MAROC,MAURICE,MONACO,NORVEGE,PAYS-BAS,PORTUGAL,SUEDE,TOGO,TUNISIE,TURQUIE,VATICAN";
fraisdeport[38] = "LA POSTE (PTT)";
fraisdeport[39] = 0;

fraisdeport[40] = 480;
fraisdeport[41] = 26;
fraisdeport[42] = "ALGERIE,ALLEMAGNE,ANDORRE,CANADA,COTE D'IVOIRE,DANEMARK,ETATS-UNIS,FINLANDE,GABON,GRECE,IRLANDE,ISLANDE,ITALIE,LUXEMBOURG,MAROC,MAURICE,MONACO,NORVEGE,PAYS-BAS,PORTUGAL,SUEDE,TOGO,TUNISIE,TURQUIE,VATICAN";
fraisdeport[43] = "LA POSTE (PTT)";
fraisdeport[44] = 0;

fraisdeport[45] = 800;
fraisdeport[46] = 36;
fraisdeport[47] = "ALGERIE,ALLEMAGNE,ANDORRE,CANADA,COTE D'IVOIRE,DANEMARK,ETATS-UNIS,FINLANDE,GABON,GRECE,IRLANDE,ISLANDE,ITALIE,LUXEMBOURG,MAROC,MAURICE,MONACO,NORVEGE,PAYS-BAS,PORTUGAL,SUEDE,TOGO,TUNISIE,TURQUIE,VATICAN";
fraisdeport[48] = "LA POSTE (PTT)";
fraisdeport[49] = 0;

fraisdeport[50] = 950;
fraisdeport[51] = 56;
fraisdeport[52] = "ALGERIE,ALLEMAGNE,ANDORRE,CANADA,COTE D'IVOIRE,DANEMARK,ETATS-UNIS,FINLANDE,GABON,GRECE,IRLANDE,ISLANDE,ITALIE,LUXEMBOURG,MAROC,MAURICE,MONACO,NORVEGE,PAYS-BAS,PORTUGAL,SUEDE,TOGO,TUNISIE,TURQUIE,VATICAN";
fraisdeport[53] = "LA POSTE (PTT)";
fraisdeport[54] = 0;

fraisdeport[55] = 1500;
fraisdeport[56] = 75;
fraisdeport[57] = "ALGERIE,ALLEMAGNE,ANDORRE,CANADA,COTE D'IVOIRE,DANEMARK,ETATS-UNIS,FINLANDE,GABON,GRECE,IRLANDE,ISLANDE,ITALIE,LUXEMBOURG,MAROC,MAURICE,MONACO,NORVEGE,PAYS-BAS,PORTUGAL,SUEDE,TOGO,TUNISIE,TURQUIE,VATICAN";
fraisdeport[58] = "LA POSTE (PTT)";
fraisdeport[59] = 0;

fraisdeport[60] = 100000;
fraisdeport[61] = 120;
fraisdeport[62] = "ALGERIE,ALLEMAGNE,ANDORRE,CANADA,COTE D'IVOIRE,DANEMARK,ETATS-UNIS,FINLANDE,GABON,GRECE,IRLANDE,ISLANDE,ITALIE,LUXEMBOURG,MAROC,MAURICE,MONACO,NORVEGE,PAYS-BAS,PORTUGAL,SUEDE,TOGO,TUNISIE,TURQUIE,VATICAN";
fraisdeport[63] = "LA POSTE (PTT)";
fraisdeport[64] = 0;


function calculport() {
  trouve = false;
  totalP = 0;
  compare = primpays;
  x_p = 0;
  z = 0;
  document.itemsform.trouve_port_transporteur.value="false";
  for (var i=0; i<= 44; i=i+5) {
    if (trouve==false) {
      listepays = fraisdeport[i+2]+',';
      debcompte = 0;
      taille = listepays.length;
      debitem = 0;
      for (var j=0; j<=listepays.length; j++) {
        if (listepays.substring(j,j+1)==',') {
	  cepays=listepays.substring(debitem,j);
	  debitem=j+1;
	  if (cepays.toUpperCase() == compare.toUpperCase() && trouve == false && fraisdeport[i+3]==document.itemsform.type_trs.value ){
            document.itemsform.trouve_port_transporteur.value="true";
            if (totalpourport <= fraisdeport[i]  && fraisdeport[i+3]==document.itemsform.type_trs.value) {
	      totalP=fraisdeport[i+1];
	      trouve=true;j=100;
	    }
	  }
	  if (cepays=='AUTRES' && compare != 'none' && compare != '') {
	    if (totalpourport <= fraisdeport[i] && fraisdeport[i+3]==document.itemsform.type_trs.value) {
	      totalP=fraisdeport[i+1];
	    }
	  }
	}
      }
    }
  }
  if (document.itemsform.trouve_port_transporteur.value=="false"  && passage_port==true) {
  }
  passage_port=true;

  document.itemsform.AfPort.value = totalP;
  document.itemsform.Total_Port.value = arr(totalP);
  document.itemsform.TotalAchat.value = soustotal;
  document.itemsform.TotalAchat2.value = arr(soustotal);
  document.itemsform.Total_cde.value = arr(Number(totalP)+Number(soustotal));
  document.itemsform.HTotal_cde.value = arr(Number(totalP)+Number(soustotal));
  euro = (Number(totalP)+Number(soustotal))*6.55957
  euro = arr(euro);
  document.itemsform.Toteuro.value = euro;
}


function multi_prix(indice,nom, qte, prix2, tva, ref,formulaire) {
  donne = prix2.split("|");
  var champ = new String("");
  champ = formulaire["article" + num_prod];
  champ.value=nom;
  top.cart[indice]=new top.Item(nom+' '+donne[0],donne[1], qte, indice, tva , ref, '',donne[2],donne[1] );
}


function Item(nom, prix, quantite, abrev, taux,reference,cde, sig_qte, sig_pds)   // constructeur d'article
{
  if (reference=="") {reference="aucune";}
  this.nom = nom;this.prix = prix;this.quantite = quantite;this.abrev = abrev;this.taux=taux; this.ref=reference; this.sig_qte=sig_qte; this.sig_pds=sig_pds;
}


function verif_limit(qte,limitb, limith) {
  if (qte<limitb && qte>0) {
    alert("Quantité commandée insuffisante");
    return false;
  }

  if (qte>limith) {
    alert("Quantité commandée trop élevée");
    return false;
  }
  return true;
}


function arr(soustotal)
{
  if (soustotal == 0) {
    return "0.00";
  }
  else {
    var tmp = "" + Math.round(soustotal*100);
    if (tmp.length==1) {
      return("0.0" + tmp);
    }
    else {
      return(tmp.substring(0, tmp.length-2) + "." + tmp.substring(tmp.length-2, tmp.length));
    }
  }
}


function changement(num_prod,prix,nom,qte,formulaire, taux, poids)
{
  var champ = new String("");
  champ = formulaire["prix" + num_prod];
  champ.value=arr(prix*qte);
  champ = formulaire["article" + num_prod];
  champ.value=nom;
  sigma_qte = 0;
  sigma_pds = 0;
  cart[num_prod]=new Item(nom,prix, qte, 'num_prod', taux , '', '',1,poids );
  calculcde();
}


function montant_multi(valeur)
{
  donne = valeur.split("|");
  return donne[1];
}


function libelle_multi(valeur,complement)
{
  donne = valeur.split("|");
  return donne[0]+" "+complement;
}


function poids_multi(valeur)
{
  donne = valeur.split("|");
  return donne[2];
}


function calculcde()
{
  var i; var d; var j;
  var test;
  totalligne = 0.0, soustotal = 0.0, totalTva=0.0, totalpourport = 0.0, tx_prod=1;
  document.itemsform.liste_prod.value="";
  for ( i in top.cart) {
    if (top.cart[i].quantite > 0) {
      document.itemsform.liste_prod.value += top.cart[i].nom+"<>"+top.cart[i].quantite+"<>"+arr(top.cart[i].prix)+"<>";
      document.itemsform.liste_prod.value += top.cart[i].prix+"<>"+top.cart[i].ref+"<>"+tx_prod+"|";
      totalligne = arr(top.cart[i].quantite * top.cart[i].prix);
      sigma_qte = Number(sigma_qte)+ Number(arr(top.cart[i].sig_qte * top.cart[i].quantite));
      sigma_pds = Number(sigma_pds) + Number(arr(top.cart[i].sig_pds * top.cart[i].quantite));
      totalpourport = parseFloat(totalpourport) + parseFloat(totalligne);
      soustotal = parseFloat(soustotal)+parseFloat(totalligne);
    }
  }
  soustotal = arr(soustotal);
  soustotal = arr(parseFloat(soustotal));
  calculport();
  document.itemsform.trouve_port_transporteur.value="true";
}

