// JavaScript Document 90516

// $larcol : voir  panier1.php
// 90606
typrod = "n" ; // o pour DA
vcoord = "" ;
var tpanl = new Array();  var tpanq = new Array();  var tpanu = new Array();  
var tpanm = new Array();  var tpanc = new Array();  var tpan_n = new Array();  
var tpant = new Array();
var tpaniv = new Array();
totpan = 0 ;
qta = 0 ; // quantité articles (compteur PayPal)
a = 0 ;
memopan_n = 0 ;
memopan_c = 0 ;
    /*

function initpan()
{ for (n in tpanq) // pan
  { tpanm[n] = tpanq[n] * tpanu[n] ;
    totpan += tpanm[n] ;
    c = n ;
    if ( tpanq[n] > 0 )
    {
     document.getElementById("idpq"+c).innerHTML = tpanq[n] ; 
      document.getElementById("idpm"+c).innerHTML = " = " +format(tpanm[n],2," ") ; 
    }   
    else
    { document.getElementById("idpq"+c).innerHTML = "" ;
      document.getElementById("idpm"+c).innerHTML = "" ;
    } 
  }
  if ( totpan >0 )
  {
    v0 =  "<div>Commande en cours </div>" ;
    v0 += "TOTAL : "+format(totpan,2," ") +" € </div>";
  }
  else
  {
    v0 =  "<div>Votre panier est vide</div>" ;
  }
  document.getElementById("idpan_a").innerHTML = v0 ;
}

    */
function aidecom(n)
{ if (n==1)
     document.getElementById("idaidecom").style.visibility = "visible" ;
  else
     document.getElementById("idaidecom").style.visibility = "hidden" ;
}

function xajoutpan(n,c) // --- pan1 ---
{ n = c ;
  if (tpaniv[n]==1)
  {  tpanl[n] = document.getElementById("idpl"+c).innerHTML ;
     tpanq[n] = document.getElementById("ida"+c).value ; 
     t = document.getElementById("idp"+c).innerHTML ; 
     tt=t.split(",") ; t=tt.join(".");
     tpanu[n] = t ;
  }
  tpanm[n] = tpanq[n] * tpanu[n] ;
  tpanc[n] = c ;
  if ( tpanq[n] > 0 && tpaniv[n]==1 )
  {  document.getElementById("idpq"+c).innerHTML = "<b>" +tpanq[n]  + " </b>" ; 
     if (tpanm[n]>0)
     { t = formatef(tpanm[n],2) ;
       //tt=t.split(".") ; t=tt.join(",");
       document.getElementById("idpm"+c).innerHTML = " = <b>" +t + "€</b>" ; 
     }   
     else   
        document.getElementById("idpm"+c).innerHTML = "" ; 
     //document.getElementById("iddp"+c).style.fontWeight = "bold" ;
     document.getElementById("iddp"+c).className = "panip" ;
  }   
  else
  { if (tpaniv[n]==1)
    { document.getElementById("idpq"+c).innerHTML = "" ;
      document.getElementById("idpm"+c).innerHTML = "" ;
      document.getElementById("iddp"+c).className = "paniv" ;
    }  
  } 
  parent.panbd.document.f_panbd.a.value = "a" ;  
  parent.panbd.document.f_panbd.fpanl.value = tpanl[n] ;
  parent.panbd.document.f_panbd.fpanq.value = tpanq[n] ;
  parent.panbd.document.f_panbd.fpanu.value = tpanu[n] ;
  parent.panbd.document.f_panbd.fpanc.value = tpanc[n] ;
  parent.panbd.document.f_panbd.submit() ;
  totpan = 0 ;
  totalqte = 0 ;
  for (i in tpanq)
  { totpan += tpanm[i] ;
    totalqte += tpanq[i] ;
  }
  // --if ( totpan >0 )
  if ( tpanm[n] >0 ) //  totqte
  { v0 =  "<div>Ajout commande :</div>" ;
    v0 +=  "<div>" + tpanq[n] +" X "+ formatef(tpanu[n],2) + "€ = " + formatef(tpanm[n],2) /*format(tpanm[n],2," ")*/ + " €<br>";
    v0 += "TOTAL : "+ formatef(totpan,2) +" € </div>";
  }
  else
  { if (tpanq[n] >0)
    { v0 =  "<div>Ajout commande :</div>" ;
      v0 +=  "<div>" +  tpanq[n] +"<br>";
      v0 += "TOTAL : "+ formatef(totpan,2) +" € </div>";
    } 
    if (totalqte == 0)
       v0 =  "<div>Aucune commande en cours</div>" ;
  }
  document.getElementById("idpan_a").innerHTML = v0 ;
  memopan_n = n ; memopan_c = c ;
}

function xident1() // ident par panier
{ parent.panbd.document.f_panbd.a.value = "i" ;  
  parent.panbd.document.f_panbd.fmel.value = document.f1.melec.value ;  
  parent.panbd.document.f_panbd.submit() ;
  recalcpanier(1) ;
}

vcce = 0 ;
function coord2() // commune 
{ vcoord = '<table align="left" class="ta1"cellspacing="2" cellpadding="0" border="0" width="700" >'
          +  '<col width="100"><col width="400"><col width="200">' 
          + '<tr align="left" ><td>Nom : <td>' + parent.panbd.document.f_panbd.inom.value + ' ' + parent.panbd.document.f_panbd.iprenom.value + '<br>'
          + '<td rowspan="5" align="right"> <input type="button"  class="b_bouton" value="Modifier les coordonnées" name="n2"  onClick="xscoord(1)" ><br><br>'
          + '<input type="button"  class="b_bouton" value="Déconnecter" name="n2"  onClick="xqcoord(1)" ><br><br>'
          + '<tr align="left" ><td>Adresse :  <td>' + parent.panbd.document.f_panbd.iadra.value +'<br>'
          + '<tr><td><td>' + parent.panbd.document.f_panbd.iadrb.value +'<br>'
          + '<tr><td><td>' + parent.panbd.document.f_panbd.icp.value + ' '+ parent.panbd.document.f_panbd.iville.value+'<br>';
          if (panport=="o")
              vcoord += '<tr><td><td>' +tzone[parent.panbd.document.f_panbd.i_zone.value] +'<br>' ;
          vcoord +=  '</table><br>' ;
}
function ouvrepanier()
{ document.getElementById("idmescomm").innerHTML = "" ;
  document.getElementById("idpanier").style.visibility = "visible" ;
/*
  vpanier0 = vpanier;
  for (n in tpanq)
  { if ( tpanq[n] > 0 )
    {
      vp_1 = "<tr valign='top'><td><br><td>*" ;
      vp_2 = "<td align='left'>" + tpanl[n] + "</td>" ;
      vp_3 = "<td align='right'><input type='text' id='panq"+n+"' value='" + tpanq[n] +"' style='width:35px;' onChange='recalcpanier()'> " ;
      vp_4 = "<td align='right'> "+ tpanu[n]  ;
      vp_5 = "<td align='right'> " + tpanm[n] + " </tr>";
      vpanier0 += vp_1 +  vp_2  + vp_3 +  vp_4  + vp_5 ;
    }
    document.getElementById("idpanier1").innerHTML = vpanier0 +"</table>";  
  }
*/  
  recalcpanier(0) ;
  ///
  vcce = parent.panbd.document.f_panbd.i_cident.value ;
  if (parent.panbd.document.f_panbd.adhn.value >0 || vcce == 1)
  { //vcoord= "ident" ;
    coord2() ;
    document.getElementById("idlz").style.visibility = "hidden" ;      
  }
  else
  { vcoord= '<input type="button"  class="b_bouton" value="Mes coordonnées" name="n3"  onClick="xscoord(1)" >' ;
  }
  document.getElementById("idcoordec").innerHTML = vcoord ;
}
function recoord()
{ //vcoord= "ident" ;
  coord2() ;
  document.getElementById("idcoordec").innerHTML = vcoord ;      
}

vscoor = 0 ; // drapeau nouv /modif
function xscoord(n)
{ if (n==1)
     document.getElementById("idlz").style.visibility = "visible" ;
  document.f1.cnom.value = parent.panbd.document.f_panbd.inom.value ;
  document.f1.cpren.value = parent.panbd.document.f_panbd.iprenom.value ;
  document.f1.cadra.value = parent.panbd.document.f_panbd.iadra.value ;
  document.f1.cadrb.value = parent.panbd.document.f_panbd.iadrb.value ;
  
  document.f1.ccodepost.value = parent.panbd.document.f_panbd.icp.value ;
  document.f1.cville.value = parent.panbd.document.f_panbd.iville.value ;
  document.f1.cpays.value = parent.panbd.document.f_panbd.ipays.value ;
  if (panport=="o")
     document.f1.fzone.value = parent.panbd.document.f_panbd.i_zone.value ;
  document.f1.cmel.value = parent.panbd.document.f_panbd.fmel.value ;
  document.f1.ctel.value = parent.panbd.document.f_panbd.itel.value ;
  document.f1.cfax.value = parent.panbd.document.f_panbd.ifax.value ;

 if (typrod == "o" )
    for (i=1; i<=2 ; i++) // tiz 
      //i=2 ;
     {  tcp = parent.panbd.tpconso[i] ; x=1 ;
       if (tcp == 1) 
          //document.f1.ce1.checked = true ;
          document.getElementById("ce"+i).checked = true ;
       else
          //document.f1.ce1.checked = false ;
          document.getElementById("ce"+i).checked = false ;
     }    
/**/     
  //document.f1.cmel.value = parent.panbd.document.f_panbd.iadrb.value ;
// liste var : $fmel $i_zone $i_nom $i_prenom  $iadra  $iadrb  $icp  $iville  $itel  $ifax  $new1 $conso1  $adhn 
 
  
  
  vscoor = n ; // pour valco
}

function xqcoord(n) // déconnecte
{ parent.panbd.document.f_panbd.a.value = "j" ;  
  parent.panbd.document.f_panbd.fmel.value = " " ;  
  document.f1.repan.value = 1 ;
  parent.panbd.document.f_panbd.submit() ;
}

totqte=0;
function recalcpanier(a)
{ vpanier0 = vpanier ;
  totpan = 0 ;
  lig=0 ;
  totq=0; totqte = 0 ;
  //comel = "" ;
  comel2 = vpanier ; // format HTML
  for (n in tpanq)
  { if (a >0 && tpanq[n] > 0 ) 
    { tpanq[n] = document.getElementById("panq"+n).value ;
      if (tpaniv[n]==1)
      { document.getElementById("ida"+n).value = tpanq[n];   
        document.getElementById("iddp"+c).className = "paniv" ;
      }   
      if (n==a)
       xajoutpan(n,n) ;
    }   
    totqte+= tpanq[n] ;
    if (tpanq[n] > 0)
    { if ( lig == 0 )   {   vclas= "panlig0" ; lig = 1 ; }  
      else   {   vclas= "panlig1" ; lig = 0 ; }     
      vp_1 = "<tr  class='" +vclas +"' >" ; //valign='top'
      vp_2 = "<td class='panil2' align='left'>" + tpanl[n] + "</td>" 
      vp_3 = "<td class='panil3' align='right'><input type='text' id='panq"+n+"' value='" +tpanq[n] +"' style='width:35px;' onChange='recalcpanier(" +n +")'> " ;
      vp_3m = "<td class='panil3' align='right'>" +tpanq[n]  ;
      if (tpanu[n]>0)
      { vp_4 = "<td class='panil3' align='right'> "+ formatef(tpanu[n],2)  ;
      } 
      else  
        vp_4 = "<td class='panil3' colspan='2'>Demande de devis " ;
      tpanm[n] =  tpanq[n] * tpanu[n] ;
      //tpanm[n] = format(tpanm[n],2," ") ;
      if (tpanm[n]>0)
      { vp_5 = "<td class='panil3' align='right'> " + formatef(tpanm[n],2) + " </tr>";
      }
        
      else   
         vp_5 = "  </tr>";
      vpanier0 +=  vp_1 +  vp_2  + vp_3 +  vp_4  + vp_5 ;
      totpan += tpanm[n] ;
      qta ++ ;
      //comel += tpanq[n] + "  "+tpanl[n] + " à " + format(tpanu[n],2," ") + " = " + format(tpanm[n],2," ") + " \n" ;
      comel2 += vp_1 +  vp_2  + vp_3m +  vp_4  + vp_5 ;
    }
  }
  vp_t = "<tr valign='top'><td><br><td class='panil4' colspan='2'>S/TOTAL<td class='panil4' align='right'>" + formatef(totpan,2) ;
  //comel += "S/TOTAL : " + format(totpan,2," ");
  //comel2 += vp_t ;
  vp_port = "";
  totfrais = 0 ;
  if (panport=="o")
  { vzone = document.getElementById("fzone").value ;
    vcomm = tcomm[vzone] ;
    if (totpan < vcomm)
       totfrais = tfrais[vzone] ;
    vp_port = "<tr valign='top'><td class='panil2'>Pour commande inférieure à " + formatef(vcomm,2) +" €<td class='panil5' colspan='2'>Frais de port<td class='panil5' align='right'>" + formatef(totfrais,2) ;
  }
  if (totpan==0)
      totg = 0 ;
  else    
      totg = totpan + totfrais ; ////   ;//
  vp_tt = "<tr valign='top'><td><td class='panil4' colspan='2'>TOTAL<td class='panil4' align='right'>" + formatef(totg,2) ;
  vpanier0 += vp_t + vp_port + vp_tt +"</table>" ;//</div>
  //comel +=  "Pour commande inférieure à " +format(vcomm,2," ") +" € : Frais de port" + format(totfrais,2," ")+ "\n";
  //comel +=  "TOTAL : " + format(totg,2," ") ;
  //--  if ( document.getElementById("idpan_a").innerHTML == 0 )
  if (totqte == 0)
     vpanier0 =  "Aucune commande en cours" ; ///<div></div>
  document.getElementById("idpanier1").innerHTML = vpanier0 ;  
  xbtajtpan() ;
  document.getElementById("idnom").innerHTML = parent.panbd.document.f_panbd.fpan_n.value ;
  document.f1.cmel.value = parent.panbd.document.f_panbd.fmel.value ;  
  comel2 += vp_t + vp_port + vp_tt +"</table>" ; ; // --  ++
}

function fermepanier()
{ document.getElementById("idpanier").style.visibility = "hidden" ;
  if ( totpan >0 )
  { document.getElementById("idpan_a").innerHTML = "Total commande : "+ formatef(totpan,2) + "€"; 
  }   
  else    
     document.getElementById("idpan_a").innerHTML = ""; 
  document.getElementById("idlz").style.visibility = "hidden" ;   
}
function xvalco() //////////******************************
{ r=0;
//document.getElementById("idlz").style.visibility = "hidden" ; 
  vcnom = document.f1.cnom.value ;    if (vcnom =="") r++;
  vcpren = document.f1.cpren.value ;  if (vcpren =="") r++;
  vcadra = document.f1.cadra.value ;  if ( vcadra=="") r++;
  vcadrb = document.f1.cadrb.value ;  //if ( vcadrb=="") r++;
  vcodepost = document.f1.ccodepost.value  ; if (vcodepost =="") r++;
  vcville = document.f1.cville.value ;  if (vcville =="") r++;
  vcpays = document.f1.cpays.value ; 
  if (panport=="o") 
  {   vfzonel = document.f1.fzone.value ;  
  }
  typrod = "n" ;
  vconso= "" ;
  if (typrod == "o" )
  { if (document.f1.ce1.checked==true) vce1 = 1 ; else vce1 = 0;
    if (document.f1.ce2.checked==true) vce2 = 1 ; else vce2 = 0;
    if (document.f1.ce3.checked==true) vce3 = 1 ; else vce3 = 0;
    if (document.f1.ce4.checked==true) vce4 = 1 ; else vce4 = 0;
    if (document.f1.ce5.checked==true) vce5 = 1 ; else vce5 = 0;
    if (document.f1.ce6.checked==true) vce6 = 1 ; else vce6 = 0;
    vconso= "" +vce1+ vce2 +vce3 +vce4 +vce5 +vce6 ;
  }
  vcmel = document.f1.cmel.value ;  if (vcmel =="") r++; 
  vctel = document.f1.ctel.value ;
  vcfax = document.f1.cfax.value ; 
  //
  if (r==0 || vcmel != "")
  { document.getElementById("idlz").style.visibility = "hidden" ; 
    vcce = 1 ; 
    parent.panbd.document.f_panbd.i_cident.value = vcce ;
    parent.panbd.document.f_panbd.inom.value = vcnom ;
    parent.panbd.document.f_panbd.iprenom.value = vcpren ;
    parent.panbd.document.f_panbd.iadra.value = vcadra ;
    parent.panbd.document.f_panbd.iadrb.value = vcadrb ;
    parent.panbd.document.f_panbd.icp.value = vcodepost ;
    parent.panbd.document.f_panbd.iville.value = vcville ;
    parent.panbd.document.f_panbd.ipays.value = vcpays ;
    if (panport=="o") 
    { parent.panbd.document.f_panbd.i_zone.value = vfzonel ; 
    }
    parent.panbd.document.f_panbd.fmel.value = vcmel ;
    parent.panbd.document.f_panbd.itel.value = vctel ;
    parent.panbd.document.f_panbd.ifax.value = vcfax ;
    //
    parent.panbd.document.f_panbd.conso1.value = vconso ;
    
    if (vscoor==0) // nouveau
    { parent.panbd.document.f_panbd.a.value = "n" ;
    }
    else // modif
    { parent.panbd.document.f_panbd.a.value = "m" ;
    }
    parent.panbd.document.f_panbd.submit() ;
    document.f1.repan.value = 1 ;
    ouvrepanier();
  }
  else
  //if ( vcmel != "" )
    document.getElementById("idcmess").innerHTML = "Complétez le formulaire SVP"; 
}

function xvalca()
{ document.getElementById("idlz").style.visibility = "hidden" ; 
}
function valid_panier()
{ if ( totqte > 0 && parent.panbd.document.f_panbd.fmel.value != "" ) //document.f1.cmel.value
  { vcnom = document.f1.cnom.value ; 
    vcmel = document.f1.cmel.value ; 
    vmodepaie = "" ;
    //document.getElementById("idmescomm").innerHTML = totpan +" * " + parent.panbd.document.f_panbd.fmel.value ; // mop ****
    //document.getElementById("idmescomm").innerHTML = vcnom+"/"; // document.f1.cnom.value document.paiement.business.value ;
    document.paiement.amount_1.value = totg ; // document.f1.ccodepost.value    ; //
    if (totpan> 0) 
    {  if ( activ_pp=="o" && document.f1.modep[0].checked == false && document.f1.modep[1].checked == false ) ///
       { document.getElementById("idmescomm").innerHTML = "<b>Choisir un mode de paiement SVP<b>";
       }
       else
       { if ( totpan > 0 && activ_pp=="o" && document.f1.modep[0].checked == true )
         { document.paiement.submit(); 
           vmodepaie = "<br><b>Mode de paiement : PayPal</b><br>" ;
         }
         if ( totpan > 0 && document.f1.modep[1].checked == true )
         { vmodepaie = "<br><b>Mode de paiement : non défini</b><br>" ;
         }
       }
    }
    else // devis
    { document.f1.modep[1].checked == true ;
      vmodepaie = "<br><b>Pas de paiement</b><br>" ;
    }
    if (vmodepaie != "" )
    { panpp = "" ;
     qt = 0 ;
     // --------
     commande = comel2 + vmodepaie ; // Commande DA Conseils Café<br>
     
     parent.panbd.document.f_panbd.a.value = "x" ; 
     //parent.panbd.document.f_panbd.sitec.value = sitec ; 
     //parent.panbd.document.f_panbd.fmel.value = document.f1.cmel.value ; // melec
     parent.panbd.document.f_panbd.fcommande.value = commande ;
     parent.panbd.document.f_panbd.submit() ;
     
     // --------
     for (i in tpanq)  //vide prépa 
     { tpanq[i] = 0 ;
       tpanm[i] = 0 ;
     }
     totpan = 0 ;
     recalcpanier(0) ;
     initpan();
     xbtajtpan() ; 
     document.getElementById("idmescomm").innerHTML = "<b>Commande enregistrée  - copie à : " + vcmel +"</b><br>"; //document.f1.cmel.valuemelec
    }
  }
  else 
  { //document.getElementById("idmescomm").innerHTML = totpan +" * " + parent.panbd.document.f_panbd.fmel.value ; //document.f1.cmel.value
    document.getElementById("idmescomm").innerHTML = "<b>Conditions de commande non remplies</b>" ;
  }
}
/*
function valid_panier_anc1()
{ if ( totpan > 0 && parent.panbd.document.f_panbd.fmel.value != "" ) //document.f1.cmel.value
  { vcnom = document.f1.cnom.value ; 
    vcmel = document.f1.cmel.value ; 
    //document.getElementById("idmescomm").innerHTML = totpan +" * " + parent.panbd.document.f_panbd.fmel.value ; // mop ****
    //document.getElementById("idmescomm").innerHTML = vcnom+"/"; // document.f1.cnom.value document.paiement.business.value ;
    document.paiement.amount_1.value = totpan ; // document.f1.ccodepost.value    ; // 
    if (document.f1.modep[0].checked == false && document.f1.modep[1].checked == false)
    { document.getElementById("idmescomm").innerHTML = "<b>Choisir un mode de paiement SVP<b>";
    }
    else
    {
    if ( totpan > 0 && activ_pp=="o" && document.f1.modep[0].checked == true )
       document.paiement.submit(); 
     panpp = "" ;
     qt = 0 ;
     // --------
     commande = "" ; // Commande DA Conseils Café<br>
     for (n in tpanq)
     { if (tpanq[n] > 0)
       { commande +=  tpanq[n] +" X " +tpanl[n] + " à " +format(tpanu[n],2," ") +"€ = " +format(tpanm[n],2," ") + "€<br>" ;
       }
     }
     commande +=  "TOTAL : " +format(totpan,2," ") + "€" ;
     
     parent.panbd.document.f_panbd.a.value = "x" ; 
     //parent.panbd.document.f_panbd.sitec.value = sitec ; 
     //parent.panbd.document.f_panbd.fmel.value = document.f1.cmel.value ; // melec
     parent.panbd.document.f_panbd.fcommande.value = commande ;
     parent.panbd.document.f_panbd.submit() ;
     
     // --------
     for (i in tpanq)  //vide prépa 
     { tpanq[i] = 0 ;
       tpanm[i] = 0 ;
     }
     totpan = 0 ;
     recalcpanier(0) ;
     initpan();
     xbtajtpan() ; 
     document.getElementById("idmescomm").innerHTML = "<b>Commande enregistrée  - copie à : " + vcmel +"</b><br>"; //document.f1.cmel.valuemelec
    }
  }
  else 
  { document.getElementById("idmescomm").innerHTML = totpan +" * " + parent.panbd.document.f_panbd.fmel.value ; //document.f1.cmel.value
  }
}
*/
function voir_panier()
{ document.formpaypal.display.value = 1 ;
  document.formpaypal.submit();
}
function xbtajtpan()
{   if ( totqte >0 && parent.panbd.document.f_panbd.adhn.value >0 ) //
    { document.getElementById("idbtverif").innerHTML =  bt_verif ;
      document.getElementById("idbtajt").innerHTML =  bt_ajoutpan ;
    } 
    else
    { document.getElementById("idbtverif").innerHTML =  "" ;
      document.getElementById("idbtajt").innerHTML =  "" ;
    }   
       
}
// --------------------------

// D'autres scripts sur http://www.toutjavascript.com
// Si vous utilisez ce script, merci de m'avertir !

// Merci à Nicolas pour sa petite rustine !

function format(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

function formatef(val,dec) // format français
{ t = format(val,dec," ") ;
  tt=t.split(".") ; t=tt.join(",");
  return t ;
}

