
// ----- FONCTIONS POUR PRÉCHARGER LES IMAGES : ---------------------------------------------------------------------------------------
function preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
// ------------------------------------------------------------------------------------------------------------------------------------


// ----- FONCTION POUR LE MOUSEOVER DU MENU PERMANENT : -------------------------------------------------------------------------------
function permon(qui) {
  document.getElementById(qui).style.backgroundColor='#B1969D';
  document.getElementById(qui).style.color='white';
}
// ------------------------------------------------------------------------------------------------------------------------------------


// ----- FONCTION POUR LE MOUSEOUT DU MENU PERMANENT : --------------------------------------------------------------------------------
function permoff(qui) {
  document.getElementById(qui).style.backgroundColor='#F4E9E9';
  document.getElementById(qui).style.color='#895F69';
}
// ------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR FAIRE CLIGNOTER LE MENU DE 2ÈME NIVEAU : ------------------------------------------------------------------------
var tempo;
function flashit(menudivx, nbdivsx, cycles){
  par1 = menudivx;
  par2 = nbdivsx;
  par3 = cycles;
  par3 = par3 + 1;
  masquemenu2(nbdivsx);
  document.getElementById(menudivx).style.visibility = 'visible';
  document.getElementById(menudivx).style.backgroundColor = '#FFFFFF';
  tempo = setTimeout("stopflash(par1, par2, par3)", 50);
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR REMETTRE LA BONNE COULEUR AU MENU DE 2ÈME NIVEAU : --------------------------------------------------------------
function stopflash(menudivx, nbdivsx, cycles){
  document.getElementById(menudivx).style.backgroundColor = '#EBC0C6';
  par1 = menudivx;
  par2 = nbdivsx;
  par3 = cycles;
  if (par3 <2){
    tempo = setTimeout("flashit(par1, par2, par3)", 50);
  }
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR AFFICHER LE MENU DE 2ÈME NIVEAU : -------------------------------------------------------------------------------
function affichemenu2(menudiv, nbdivs){
  masquemenu2(nbdivs);
  //alert (menudiv)
  document.getElementById(menudiv).style.visibility = 'visible';
  divid = menudiv.substr(6);
  //alert (divid)
  document.utile.menu2div.value = divid;
  document.utile.finalnbdivs.value = nbdivs + 1;
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR MASQUER LES MENUS DE 2ÈME NIVEAU : ------------------------------------------------------------------------------
function masquemenu2(nbdivs){
  //alert(nbdivs)
  for (i=1; i<(nbdivs+1); i++){
    ladiv = 'menu2_0' + (i);
    //alert (ladiv);
    document.getElementById(ladiv).style.visibility = 'hidden';
  }
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR GARDER AFFICHÉ LE MENU DE 2ÈME NIVEAU : -------------------------------------------------------------------------
function keepmenu2(){
  divid     = document.utile.menu2div.value;
  nbdivs    = document.utile.finalnbdivs.value;
  menu2id   = document.utile.menu2sel.value;
  menu3id   = document.utile.menu3sel.value;
  //alert("affichemenu2('menu2_" + divid + "', " + nbdivs + ")");
  eval("affichemenu2('menu2_" + divid + "', " + nbdivs + ")");
  qui = 'menu1_' + divid;
  colore(qui, nbdivs, "menu1_0");
  if (menu2id != '_'){
    colore2(menu2id);
  }
  if (menu3id != 'tout'){
    colore3(menu3id);
  }
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR HIGHLIGHTER LE MENU DE 1ER NIVEAU CHOISI : ----------------------------------------------------------------------
function colore(qui, nbitems, menu){
  if (menu == ''){
    menu = 'menu1_0';
  }
  //alert(nbitems);
  for (i=1; i<(nbitems); i++){
    menuitem = menu + i;
    //alert (menuitem);
    document.getElementById(menuitem).style.backgroundColor='#895F69';
  }
  document.getElementById('menu1_05').style.backgroundColor='#895F69';
  //alert(qui);
  document.getElementById(qui).style.backgroundColor='#D57180';
  document.getElementById(qui).style.color='white';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR HIGHLIGHTER LE MENU DE 2eme NIVEAU CHOISI : ---------------------------------------------------------------------
function colore2(qui){
  //alert (qui);
  document.getElementById(qui).style.backgroundColor='#D57180';
  document.getElementById(qui).style.color='white';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR HIGHLIGHTER LE MENU DE 3eme NIVEAU CHOISI : ---------------------------------------------------------------------
function colore3(qui){
  document.getElementById(qui).style.backgroundColor='#D57180';
  document.getElementById(qui).style.color='white';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR SOULIGNER UN ÉLÉMENT DU MENU 1 : --------------------------------------------------------------------------------
function souligne1(qui){
  document.getElementById(qui).style.color='white';
  document.getElementById(qui).style.textDecoration='underline';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR SOULIGNER UN ÉLÉMENT DU MENU 2 : --------------------------------------------------------------------------------
function souligne2(qui){
  //document.getElementById(qui).style.color='white';
  document.getElementById(qui).style.textDecoration='underline';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR SOULIGNER UN ÉLÉMENT DU MENU 3 : --------------------------------------------------------------------------------
function souligne3(qui){
  //document.getElementById(qui).style.color='white';
  document.getElementById(qui).style.textDecoration='underline';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR NE PLUS SOULIGNER UN ÉLÉMENT DU MENU 1 : ------------------------------------------------------------------------
function stopsouligne1(qui){
  document.getElementById(qui).style.color='#895F69';
  document.getElementById(qui).style.textDecoration='none';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR NE PLUS SOULIGNER UN ÉLÉMENT DU MENU 2 : ------------------------------------------------------------------------
function stopsouligne2(qui){
  //document.getElementById(qui).style.color='#895F69';
  document.getElementById(qui).style.textDecoration='none';
}
//-------------------------------------------------------------------------------------------------------------------------------------


//----- FONCTION POUR NE PLUS SOULIGNER UN ÉLÉMENT DU MENU 3 : ------------------------------------------------------------------------
function stopsouligne3(qui){
  //document.getElementById(qui).style.color='#895F69';
  document.getElementById(qui).style.textDecoration='none';
}
//-------------------------------------------------------------------------------------------------------------------------------------


// ----- FONCTIONS POUR AFFICHER UNE INFOBULLE : --------------------------------------------------------------------------------------
var div_Style = null

function pop_on(idd,evt){

  var Xmouse, Ymouse, Xdiv, Ydiv, Lpage, Yscroll, element = null;
  var offset   = 30;        // --- decalage par defaut
  div_Style    = null;
  Lpage        = document.body.clientWidth;
  element      = document.getElementById(idd);
  Xmouse       = evt.clientX;
  Ymouse       = evt.clientY;

  Xdiv         = Xmouse;
  Ydiv         = Ymouse	;

  if(evt.pageX) Xdiv = evt.pageX ; // --- (pour FIREFOX) ---
  if(evt.pageY) Ydiv = evt.pageY ; // --- (pour FIREFOX) ---

  Yscroll     = document.body.scrollTop;

  if(!evt.pageX) Ydiv = Ydiv + Yscroll; // --- (pour IE) ---
	//alert (Ydiv + 'px');

  div_Style = element.style;
	//alert (div_Style.height);

  div_Width  = parseFloat(div_Style.width);
	//alert (div_Width);
  div_Height = parseFloat(div_Style.height);

  //---- ON MET LA BULLE À DROITE DU POINTEUR (SI C'EST POSSIBLE) : ----
	//alert (Xmouse + offset);
	//alert (Lpage - div_Width);
  if (Xmouse + offset < Lpage - div_Width){
    Xdiv = Xmouse + offset;
  }else{
    Xdiv = Lpage - div_Width - offset;
    offset = offset + 30; // --- (décalera la div vers le haut pour qu'elle ne soit pas sur la souris)
  }
	//alert (Xdiv + 'px');

  /*
  //---- ON MET LA BULLE EN HAUT DU POINTEUR SI ON EST ASSEZ BAS DANS L'ÉCRAN : ----
  if (Ymouse > div_Height + offset){
    Ydiv = Ydiv - div_Height - offset;
  }else{
    Ydiv = Ydiv + offset;
  }
  */
  Ydiv = Ydiv - (div_Height + 30) - offset;

	//alert (Xdiv + 'px');
  div_Style.left = Xdiv + 'px';
  div_Style.top  = Ydiv + 'px';

  div_Style.visibility = "visible";
  div_Style.zIndex     = "99";
  //newhtml = 'Xdiv : ' + Xdiv + ' , Xmouse : ' + Xmouse;
  //document.getElementById(idd).innerHTML  = newhtml;
}

function pop_off(){
  div_Style.visibility="hidden";
}
// ------------------------------------------------------------------------------------------------------------------------------------


// ----- FONCTIONS POUR FORMATER LES PRIX À 2 CHIFFRES APRÈS LA VIRGULE : -------------------------------------------------------------
function j_formate ( nombredecimal ){
  var floa, inte, ch, len, i, enti, cent ;
  floa = nombredecimal * 100 ;
  inte  = Math.round ( floa ) ;
  inte == 0 ? ch = "000" : ch = inte.toString (10) ;
  ch = ch.length < 2 ? '0' + ch : ch ;
  len  = ch.length ;
  enti = ch.slice ( 0, len-2 ) ;
  if(enti=='')enti='0';
  cent = ch.slice (len-2, len ) ;
  for ( i = 0 ; i < Math.floor ( ( enti.length-(1+i))/3) ; i++ ){
    enti = enti.substring ( 0, enti.length - (4*i+3) ) + ' ' + enti.substring ( enti.length - (4*i+3) ) ;
  }
  return enti + "," + cent ;
}
// ------------------------------------------------------------------------------------------------------------------------------------


// ----- FONCTIONS POUR SAVOIR SI LA CHAINE EST UNE DIMENSION DU STYLE nxn : ----------------------------------------------------------
// --- fonction non utilisée ---
function j_checkdim ( chaine ){
  chaine = chaine.toLowerCase();
  t_chaine = chaine.split('x');
  notok = '';
  for (i=0; i<t_chaine.length; i++){
    if (isNaN(t_chaine[i])){
      notok += i;
    }
  }
  if (notok == ''){
    chaine += ' cm';
  }
  return chaine;
}
// ------------------------------------------------------------------------------------------------------------------------------------

// -------- FONCTION JAVASCRIPT QUI SOUMET LE FORMULAIRE DES DIMENSIONS SUR MESURE : --------------------------------------------------
function submit_surmes(what){
  if (what.prixsurmes.value != ''){
    if (j_controlint(what.qte)){
      formsurmes.submit();
    }
  }
}
// ------------------------------------------------------------------------------------------------------------------------------------

// -------- FONCTION JAVASCRIPT QUI SOUMET LE FORMULAIRE DES DIMENSIONS STANDARDS : ---------------------------------------------------
function submit_stdr(what){
  if (j_controlint(what.qte)){
    what.submit();
  }
}
// ------------------------------------------------------------------------------------------------------------------------------------

// -------- FONCTION JAVASCRIPT QUI TRAITE LE FORMULAIRE D'AJOUT DU ZOOM AU PANIER : --------------------------------------------------
function submit_zoom(what,iscaddy,nbarts){
  // --- rectangulaire, ovale ou ronde : ---
  var laforme
  t_forme = what.forme;
  for (i=0; i<t_forme.length; i++){
    if (t_forme[i].checked){
      laforme = t_forme[i].value;
    }
  }
  what.libf3.value = "nappe " + laforme;
  what.forme.value = "laforme";
  // --- si le zoom est déjà dans le caddy : ---
  if ((iscaddy == 1) && (nbarts > 0)){
    document.getElementById('warning').style.visibility='visible';
  }else{
    if (nbarts > 0){
      // --- appelle dans un IFRAME la page qui va soumettre tous les formulaires d'ajout d'articles supplémentaires au caddy : ------      
      j_zoomiframe(what);
    }else{
      j_succes();
    }
  }
}
// ------------------------------------------------------------------------------------------------------------------------------------

// ----- FONCTION JAVASCRIPT QUI TRAITE LE FORMULAIRE D'AJOUT DU ZOOM AU PANIER  : ----------------------------------------------------
function j_succes(){
  window.document.zoomform.submit();
}
// ------------------------------------------------------------------------------------------------------------------------------------

// ----- TESTE SI LA SAISIE EST BIEN UN ENTIER : --------------------------------------------------------------------------------------
function j_controlint(champ){
  num = champ.value;
  if ((isNaN(num)) || (num < 1) || (num != Math.round(num))){
    alert ("La quantité saisie est incorrecte !");
    champ.focus();
    return false;
  }else{
    return true;
  }
}
// ------------------------------------------------------------------------------------------------------------------------------------

// ----- FONCTION POUR OUVRIR UN POPUP : ----------------------------------------------------------------------------------------------
var fenetre;
function popup(lurl, larg, haut, scrol, resize){
  largeur   = larg   == '' ? 700 : larg;
  hauteur   = haut   == '' ? 500 : haut;
  scrollval = scrol  == '' ? 'no': scrol;
  resizeval = resize == '' ? 'no': resize;
  if ((fenetre)&&(!fenetre.closed)) { fenetre.close() };
  var param = 'resizable=no,'
               + 'scrollbars='+scrollval+','     // yes, no
               + 'width='+largeur+','
               + 'height='+hauteur+','
               + 'resizable='+resizeval+','     // yes, no
               + 'status=no,'
               + 'location=no,'
               + 'titlebar=no,'
               + 'toolbar=no,'
               + 'menubar=no,'
               + 'dependent=yes,'  ;
              //--------position sur l'écran---------------------
      if ( navigator.appName.indexOf("Microsoft") >= 0 ){
        param += 'left=100, top=50 ;'  ;
      }else {
        param += 'screenX=100,screenY=50 ;'   ;
      }
  fenetre=window.open(lurl, 'lafenetre', param);
}
// ------------------------------------------------------------------------------------------------------------------------------------

// ----- FONCTION POUR OUVRIR LE POPUP DU PRODUIT ASSOCIÉ : ---------------------------------------------------------------------------
var fenetre2;
function j_openasso(codeprod){
  lurl  = "ficheasso.php?";
  lurl += "cd=" + codeprod;
  largeur =  680 ;
  hauteur =  450 ;
  if ((fenetre2)&&(!fenetre2.closed)) { fenetre2.close() };
  var param = 'resizable=no,'
               + 'scrollbars=yes,'     // yes, no
               + 'width='+largeur+','
               + 'height='+hauteur+','
               + 'resizable=yes,'
               + 'status=no,'
               + 'location=no,'
               + 'titlebar=no,'
               + 'toolbar=no,'
               + 'menubar=no,'
               + 'dependent=yes,'  ;
              //--------position sur l'écran---------------------
      if ( navigator.appName.indexOf("Microsoft") >= 0 ){
        param += 'left=120, top=70 ;'  ;
      }else {
        param += 'screenX=120,screenY=70 ;'   ;
      }
  fenetre2=window.open(lurl, 'lepopup', param);
}
// ------------------------------------------------------------------------------------------------------------------------------------

// --- FONCTION QUI LANCE DANS UN IFRAME LA PAGE D'AJOUT AU CADDY POUR LES COMPOSANTS ADDITIONNELS DU ZOOM : --------------------------
var lurl;
function j_zoomiframe(what){
  params = '';
  nb_comp = what.nb_comp.value;
  for (i=0; i<nb_comp; i++){
    art = eval("what.art_" + i + ".value");
    qte = eval("what.qte_" + i + ".value");
    params += art + "&";
    params += qte + "&";
  }
  params += "nb_comp=" + nb_comp;
  lurl  = "ajoutzoom.php?" + params;
  document.getElementById('scriptiframe').src = lurl;
}
//-------------------------------------------------------------------------------------------------------------------------------------

// ----- FONCTION QUI REPRODUIT L'ÉQUIVALENT DU NUMNER_FORMAT DE PHP : ----------------------------------------------------------------
function j_number_format( number, decimals, dec_point, thousands_sep ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}