/*****************************************************************************/
/* Llibreria JavaScript Botigues Ajax DRAC                                   */
/*****************************************************************************/
/*

=head1 NOM

B<Botigues DRAC - Llibreria JavaScript Ajax>

=head1 SINOPSI

   <script type="text/javascript" src="js/funcions.js"></script>

=head1 DESCRIPCIÓ

Llibreria estàndard de funcions JavaScript de les botigues Ajax. Aquesta llibreria es copia al directori C<js> de la botiga amb el nom C<funcions.js>. Tots els fonts web de la botiga fan I<include> d'aquesta llibreria o bé de la seva equivalent no-Ajax (L<fun0.js(n)>). Evidentment, aquest fonts també fan I<include> de la llibreria Ajax:

   <script type="text/javascript" src="js/ajax.js"></script>

=cut
*/
/*****************************************************************************/
/*

=head1 FUNCIONS DE LA LLIBRERIA

=head2 FUNCIONS COMUNES A TOTES LES BOTIGUES (AJAX i NO AJAX)

Això és, funcions que són B<iguals> tant en aquesta llibreria com en la llibreria equivalent de botigues NO Ajax (L<fun0.js(n)>).

=cut
*/
/*****************************************************************************/
/*

=head3 obre_bigi (port, lang, imag, text, widt, heig)

=over

=item DESCRIPCIÓ

Obre una finestra flotant d'amplada C<widt> i alcada C<heig>, centrada a la pantalla, per mostrar una imatge ampliada (habitualment, les imatges dels productes).

=item PARÀMETRES

   port: nom del portal
   lang: idioma
   imag: url de la imatge
   text: text que s'utilitza com a text alternatiu de la imatge i com a titol de la finestra
   widt: amplada de la finestra (px)
   heig: alcada de la finestra  (px)

=back

=cut
*/

function obre_bigi (port, lang, imag, text, widt, heig) {

   if (widt == '') widt = 200;
   if (heig == '') heig = 200;

   left = Math.round ((screen.availWidth  - widt) / 2);
   ttop = Math.round ((screen.availHeight - heig) / 2);

   if ( port ) {
      iurl = '/appl/botiga/bigi.php';
   } else {
      iurl = 'bigi.php';
   }

   bigi = window.open (iurl+'?lang='+lang+'&imag='+imag+'&text='+escape(text), 'bigi', 'left='+left+',top='+ttop+',width='+widt+',height='+heig+',resizable=yes,scrollbars=no,toolbar=no,locationbar=no,statusbar=no');

   bigi.focus ();

}

/*

=head3 obre_conf (port, lang, fami, cist)

=over

=item DESCRIPCIÓ

Obre el formulari de confirmacio de la comanda (L<conf(n)>).

=item PARÀMETRES

   port: nom del portal
   lang: idioma
   fami: codi de la familia que s'estava visualitzant al cataleg
   cist: objecte del portal que pinta la cistella

=back

=cut
*/

function obre_conf (port, lang, fami, cist) {

   if ( ! port ) {
      document.location = 'conf.php?lang='+lang+'&fami='+fami;
   } else {
      document.location = '/'+lang+'/'+cist+'/3/'+fami;
   }

}

/*

=head3 obre_paga (port, lang, win7, fpag, gift, ucom, upro, upai, nofp, nogi, noco, widt, heig)

=over

=item DESCRIPCIÓ

Obre el formulari de pagament (L<pag0(n)> / L<pag1(n)> / L<pag2(n)>)

=item PARÀMETRES

   port: nom del portal
   lang: idioma
   win7: mode d'obertura de la finestra ($BTG_WIN7)
   fpag: codi de la forma de pagament (1-5)
   gift: valor la variable global $BTG_GIFT
   ucom: valor la variable global $BTG_UCOM
   upro: valor la variable global $BTG_UPRO
   upai: valor la variable global $BTG_UPAI
   nofp: text d'avís quan l'usuari no ha triat la forma de pagament
   nogi: text d'avís quan l'usuari ha emplenat només parcialment els camps de tramesa de regal
   noco: text d'avís quan l'usuari no ha marcat l'acceptació de les condicions de compra
   widt: amplada de la finestra (px) quan s'obre en finestra flotant
   heig: alcada de la finestra  (px) quan s'obre en finestra flotant

=back

=cut
*/

function obre_paga (port, lang, win7, fpag, gift, ucom, upro, upai, nofp, nogi, noco, widt, heig) {

   if ( fpag > 1 ) {
      if ( document.getElementById ('conf').paga.value == '' ) {
         alert (nofp);
         document.getElementById ('conf').conf_pag[0].focus();
         return false;
      }
   }
   if ( ! document.getElementById ('conf').cond.checked ) {
      alert (noco);
      document.getElementById ('conf').cond.focus();
      return false;
   }
   if ( gift ) {
      err = 0;
      ple = 0;
      if ( document.getElementById ('conf').conf_gift_noms.value == '' ) {
         if ( ple == 1 ) {
            err = 1;
         }
      } else {
         ple = 1;
      }
      if ( document.getElementById ('conf').conf_gift_addr.value == '' ) {
         if ( ple == 1 ) {
            err = 1;
         }
      } else {
         if ( ple == 0 ) {
            err = 1;
         }
      }
      if ( document.getElementById ('conf').conf_gift_pobl.value == '' ) {
         if ( ple == 1 ) {
            err = 1;
         }
      } else {
         if ( ple == 0 ) {
            err = 1;
         }
      }
      if ( document.getElementById ('conf').conf_gift_zipc.value == '' ) {
         if ( ple == 1 ) {
            err = 1;
         }
      } else {
         if ( ple == 0 ) {
            err = 1;
         }
      }
      if ( ucom ) {
         if ( document.getElementById ('conf').conf_gift_coma.value == '' ) {
            if ( ple == 1 ) {
               err = 1;
            }
         } else {
            if ( ple == 0 ) {
               err = 1;
            }
         }
      }
      if ( upro ) {
         if ( document.getElementById ('conf').conf_gift_prov.value == '' ) {
            if ( ple == 1 ) {
               err = 1;
            }
         } else {
            if ( ple == 0 ) {
               err = 1;
            }
         }
      }
      if ( upai ) {
         if ( document.getElementById ('conf').conf_gift_pais.value == '' ) {
            if ( ple == 1 ) {
               err = 1;
            }
         } else {
            if ( ple == 0 ) {
               err = 1;
            }
         }
      }
      if ( document.getElementById ('conf').conf_gift_text.value != '' ) {
         if ( ple == 0 ) {
            err = 1;
         }
      }
      if ( err == 1 ) {
         alert(nogi);
         return false;
      }
   }

   if ( port ) {

      switch (win7) {

         case 'blank':

            window.open ('/appl/botiga/paga.php?lang=$lang&paga='+document.getElementById ('conf').paga.value, 'paga');
            paga.focus ();

            break;

         case 'flot':

            if (widt == '') widt = 550;
            if (heig == '') heig = 500;
   
            left = Math.round ((screen.availWidth  - widt) / 2);
            ttop = Math.round ((screen.availHeight - heig) / 2);

            window.open ('/appl/botiga/paga.php?lang=$lang&paga='+document.getElementById ('conf').paga.value, 'paga', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width='+widt+',height='+heig+',top='+ttop+',left='+left+',resizable=yes');

            break;

         default:

            document.getElementById ('conf').action = '/appl/botiga/paga.php';
            document.getElementById ('conf').submit();

      }

   } else {

      switch (win7) {

         case 'blank':

            window.open ('paga.php?lang=$lang&paga='+document.getElementById ('conf').paga.value, 'paga');

            break;

         case 'flot':

            if (widt == '') widt = 550;
            if (heig == '') heig = 500;
   
            left = Math.round ((screen.availWidth  - widt) / 2);
            ttop = Math.round ((screen.availHeight - heig) / 2);

            window.open ('paga.php?lang=$lang&paga='+document.getElementById ('conf').paga.value, 'paga', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width='+widt+',height='+heig+',top='+ttop+',left='+left+',resizable=yes');

            break;

         default:

            document.getElementById ('conf').action='paga.php';
            document.getElementById ('conf').submit();

      }

   }

}

/*

=head3 obre_prod (port, lang, fami, codi, win1, widt, heig)

=over

=item DESCRIPCIÓ

Obre el formulari de la fitxa del producte

=item PARÀMETRES

   port: nom del portal
   lang: codi de l'idioma
   fami: codi de la familia
   codi: codi del producte
   win1: mode d'obertura de la finestra ($BTG_WIN1)
   widt: amplada de la finestra (px) quan s'obre en finestra flotant
   heig: alcada de la finestra  (px) quan s'obre en finestra flotant

=back

=cut
*/

function obre_prod (port, lang, fami, codi, win1, widt, heig) {

   if ( port ) {
      purl = '/appl/botiga/dpro.php';
   } else {
      purl = 'dpro.php';
   }

   switch (win1) {

      case "blank":

         wpro = window.open (purl+'?lang='+lang+'&codi='+codi+'&fami='+fami, 'prod');
         wpro.focus();

         break;

      case "flot":

         if (widt == '') widt = 550;
         if (heig == '') heig = 500;

         left = Math.round ((screen.availWidth  - widt) / 2);
         ttop = Math.round ((screen.availHeight - heig) / 2);

         wpro = window.open (purl+'?lang='+lang+'&codi='+codi+'&fami='+fami, 'prod', 'left='+left+',top='+ttop+',width='+widt+',height='+heig+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');

         wpro.focus();

         break;

   }

}

/*

=head3 obre_prnt (lang, widt, heig)

=over

=item DESCRIPCIÓ

Obre una finestra flotant amb la comanda, la imprimeix i la torna a tancar.

=item PARÀMETRES

   lang: codi de l'idioma
   widt: amplada de la finestra (px)
   heig: alcada de la finestra  (px)

=back

=cut
*/

function obre_prnt (lang, widt, heig) {

   if (widt == '') widt = 550;
   if (heig == '') heig = 500;

   left = Math.round ((screen.availWidth  - widt) / 2);
   ttop = Math.round ((screen.availHeight - heig) / 2);

   window.open ('/appl/botiga/resu.php?lang='+lang+'&prnt=1', 'prnt', 'left='+left+',top='+ttop+',width='+widt+',height='+heig+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');

}

/*

=head3 obre_pswd (port, lang, fami, usid, win6, widt, heig)

=over

=item DESCRIPCIÓ

   Obre el formulari de recupració de contrasenya (L<usid.php>).

=item PARÀMETRES

   port: nom del portal
   lang: codi de l'idioma
   fami: codi de la familia
   usid: valor de la variable global $BTG_BACK_USID
   win6: mode d'obertura de la finestra ($BTG_WIN66)
   widt: amplada de la finestra (px) quan s'obre en finestra flotant
   heig: alcada de la finestra  (px) quan s'obre en finestra flotant

=back

=cut
*/

function obre_pswd (port, lang, fami, usid, win6, widt, heig) {

   if ( port ) {
      purl = '/appl/botiga/usid.php';
   } else {
      purl = 'usid.php';
   }

   switch (win6) {

      case "blank":

         pswd = window.open (purl+'?lang='+lang+'&fami='+fami+'&codi=3', 'pswd');
         pswd.focus();

         break;

      case "flot":

         if (widt == '') widt = 400;
         if (heig == '') heig = 300;

         left = Math.round ((screen.availWidth  - widt) / 2);
         ttop = Math.round ((screen.availHeight - heig) / 2);

         pswd = window.open (purl+'?lang='+lang+'&fami='+fami+'codi=3', 'pswd', 'left='+left+',top='+ttop+',width='+widt+',height='+heig+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
         pswd.focus();

         break;

      default:

         if ( ! port ) {
            document.getElementById ('nopa').href = 'usid.php?lang='+lang+'&codi=3';
         } else {
            document.getElementById ('nopa').href = '/'+lang+'/'+usid+'/6/'+fami+'/3';
         }

   }

}

/*

=head3 obre_regi (port, lang, fami, vure, regi, win5, widt, heig)

=over

=item DESCRIPCIÓ

   Obre el formulari de registre de dades d'usuari (L<regi(n)>).

=item PARÀMETRES

   port: nom del portal
   lang: codi de l'idioma
   fami: codi de la familia
   vure: '1' per forçar l'usuari a registrar-se, buit altrament
   regi: valor de la variable global $BTG_BACK_REGI
   win5: mode d'obertura de la finestra ($BTG_WIN5)
   widt: amplada de la finestra (px) quan s'obre en finestra flotant
   heig: alcada de la finestra  (px) quan s'obre en finestra flotant

=back

=cut
*/

function obre_regi (port, lang, fami, vure, regi, win5, widt, heig) {

   if ( port ) {
      purl = '/appl/botiga/regi.php';
   } else {
      purl = 'regi.php';
   }

   switch (win5) {

      case "blank":

         regw = window.open (purl+'?lang='+lang+'&fami='+fami+'&codi='+vure, 'regi');
         regw.focus();

         break;

      case "flot":

         if (widt == '') widt = 550;
         if (heig == '') heig = 500;

         left = Math.round ((screen.availWidth  - widt) / 2);
         ttop = Math.round ((screen.availHeight - heig) / 2);

         regi = window.open (purl+'?lang='+lang+'&fami='+fami+'&codi='+vure, 'regi', 'left='+left+',top='+ttop+',width='+widt+',height='+heig+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
         regi.focus();

         break;

      default:

         if ( ! port ) {
            document.getElementById ('vure').href = 'regi.php?lang='+lang+'&fami='+fami+'&codi='+vure;
            document.getElementById ('usid').action = 'regi.php?lang='+lang+'&fami='+fami+'&codi='+vure;
         } else {
            if ( vure ) {
               document.getElementById ('vure').href = '/'+lang+'/'+regi+'/5/'+fami+'/1';
               document.getElementById ('usid').action = '/'+lang+'/'+regi+'/5/'+fami+'/1';
            } else {
               document.getElementById ('vure').href = '/'+lang+'/'+regi+'/5/'+fami;
               document.getElementById ('usid').action = '/'+lang+'/'+regi+'/5/'+fami;
            }
         }
         document.getElementById ('usid').submit ();

   }

}

/*

=head3 obre_text (port, lang, text, widt, heig)

=over

=item DESCRIPCIÓ

Obre el formulari de presentació de textos estàndard (L<text(n)>).

=item PARÀMETRES

   port: nom del portal
   lang: codi de l'idioma
   text: codi del text (1-5)
   widt: amplada de la finestra (px) quan s'obre en finestra flotant
   heig: alcada de la finestra  (px) quan s'obre en finestra flotant

=back

=cut
*/

function obre_text (port, lang, text, widt, heig) {

   if (widt == '') widt = 550;
   if (heig == '') heig = 500;

   left = Math.round ((screen.availWidth  - widt) / 2);
   ttop = Math.round ((screen.availHeight - heig) / 2);

   if ( port ) {
      window.open ('/appl/botiga/dtxt.php?lang='+lang+'&codi='+text+'&head=1', 'text', 'left='+left+',top='+ttop+',width='+widt+',height='+heig+',resizable=no,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
   } else {
      window.open ('dtxt.php?lang='+lang+'&codi='+text+'&head=1', 'text', 'left='+left+',top='+ttop+',width='+widt+',height='+heig+',resizable=no,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
   }

}

/*

=head3  usid_subm (blnk)

=over

=item DESCRIPCIÓ

Comprova que l'usuari ha introduït un usuari i una contrasenya. En aquest cas, fa el I<submit> del formulari per registrar-lo; en cas contrari dóna un missatge d'avís.

=item PARÀMETRES

   blnk: missatge d'avís quan l'usuari no ha emplenat els dos camps d'usuari i contrasenya

=back

=cut
*/

function usid_subm (blnk) {

   if ( (/^\s*$/.test (document.getElementById ('usid').usid_uid.value)) ||
        (/^\s*$/.test (document.getElementById ('usid').usid_pwd.value)) ) {
      alert (blnk);
      if ( /^\s*$/.test (document.getElementById ('usid').usid_uid.value) ) {
         document.getElementById ('usid').usid_uid.focus ();
      } else {
         document.getElementById ('usid').usid_pwd.focus ();
      }
   } else {
      document.getElementById ('usid').submit ();
   }

}

/*****************************************************************************/
/*

=head2 FUNCIONS ESPECÍFIQUES DE LES BOTIGUES AJAX

Això és, tres funcions que existeixen també a la llibreria de botigues NO Ajax (L<fun0.js(n)>), amb els mateixos paràmetres, però amb funcionalitat lleugerament diferent (C<obre_cist ()>, C<updt_cist()> i C<updt_prod ()>), més quatre funcions específiques de les botigues Ajax: C<form_valu ()>, C<actualitza_div ()>, C<ajaxResponseHandler ()> i C<void_cist ()>.

=cut
*/
/*****************************************************************************/

/*

=head3 obre_cist (port, lang, fami, prod, cist, form, win1, vars)

=over

=item DESCRIPCIÓ

Obre el formulari de la cistella de compra (L<cist(n)>).

=item PARÀMETRES

   port: nom del portal
   lang: idioma
   fami: codi de la familia que s'esta visualitzant al cataleg
   prod: codi del producte que s'afegeix a la cistella
   cist: objecte del portal que pinta la cistella
   form: nom del formulari des del qual s'accedeix a la cistella
   win1: mode d'obertura de la finestra ($BTG_WIN1)
   vars: valors per defecte de les variacions de producte

=back

=cut
*/

function obre_cist (port, lang, fami, prod, cist, form, win1, vars) {

   quan = document.getElementById ('cata').quan.value;

   updt_cist ('CosCistella', lang, fami, '', prod, '', quan, vars);

}  

/*

=head3 updt_prod (win1, nvar, puni, quni)

=over

=item DESCRIPCIÓ

Refresca el preu i el pes a la fitxa del producte (L<prod(n)>) d'acord amb les variacions triades

=item PARÀMETRES

   win1: mode d'obertura de la finestra ($BTG_WIN1)
   nvar: nombre de variacions del producte
   puni: literal de les unitats de preu
   quni: literal de les unitats de pes

=back

=cut
*/

function updt_prod (win1, nvar, puni, quni) {

   if ( win1 == 'self' ) {

      lang = document.getElementById ('prod').lang.value;
      preu = parseFloat (document.getElementById ('prod').preu.value);
      pesu = parseFloat (document.getElementById ('prod').pesu.value);
      quan = parseFloat (document.getElementById ('prod').quan.value);

      for (v = 0; v < nvar; v++) {

         eval ("vari = document.getElementById ('prod').vari_"+v);
         eval ("varp = mpre_"+v);
         eval ("varq = mpes_"+v);

         pvar = "";
         qvar = "";
         switch (vari.type) {
            case "select-one":
               pvar = varp[vari.value];
               qvar = varq[vari.value];
               break;
            case "checkbox":
               if ( vari.checked ) {
                  pvar = varp[0];
                  qvar = varq[0];
               }
               break;
            case "hidden":
            case "text":
               if ( vari.value != '' ) {
                  pvar = varp[0];
                  qvar = varq[0];
               }
               break;
            default:
               for (r = 0; r < vari.length; r++) {
                  if ( vari[r].checked ) {
                     pvar = varp[r];
                     qvar = varq[r];
                     break;
                  }
               }
         }

         if ( pvar != '' ) {
            if ( /^[\=\#]/.test (pvar) ) {
               preu = pvar.substr (1);
            } else {
               if ( /^\+/.test (pvar) ) {
                  pvar = pvar.substr (1);
                  if ( /\%$/.test (pvar) ) {
                     pvar = substr (0, pvar.length - 1);
                     preu = preu + (preu * (parseFloat (pvar) / 100));
                  } else {
                     preu = preu + parseFloat (pvar);
                  }
               } else {
                  if ( /^\-/.test (pvar) ) {
                     pvar = pvar.substr (1);
                     if ( /\%$/.test (pvar) ) {
                        pvar = substr (0, pvar.length - 1);
                        preu = preu - (preu * (parseFloat (pvar) / 100));
                     } else {
                        preu = preu + parseFloat (pvar);
                     }
                  }
               }
            }
         }

         if ( qvar != '' ) {
            if ( /^[\=\#]/.test (qvar) ) {
               pesu = qvar.substr (1);
            } else {
               if ( /^\+/.test (qvar) ) {
                  qvar = qvar.substr (1);
                  if ( /\%$/.test (qvar) ) {
                     qvar = qvar.substr (0, qvar.length - 1);
                     pesu = pesu + (pesu * (parseFloat (qvar) / 100));
                  } else {
                     pesu = pesu + parseFloat (qvar);
                  }
               } else {
                  if ( /^\-/.test (qvar) ) {
                     qvar = substr (1, qvar);
                     if ( /\%$/.test (qvar) ) {
                        qvar = qvar.substr (1, qvar.length - 1);
                        pesu = pesu - (pesu * (parseFloat (qvar) / 100));
                     } else {
                        pesu = pesu + parseFloat (qvar);
                     }
                  }
               }
            }
         }

      }

      preu = Math.round (preu * quan * 100);
      pesu = Math.round (pesu * quan * 100);

      document.getElementById ('ppre').innerHTML = form_valu (preu.toString (), lang) + ' ' + puni;
      document.getElementById ('ppes').innerHTML = form_valu (pesu.toString (), lang) + ' ' + quni;

   } else {

      document.getElementById('prod').submit();

   }

}

/*

=head3 form_valu (valu, lang)

=over

=item DESCRIPCIÓ

Formata un import amb dos decimals, d'acord amb l'idioma

=item PARÀMETRES

   valu: import a formatar
   lang: codi de l'idioma

=back

=cut
*/

function form_valu (valu, lang) {

   if ( valu.length < 3 ) {
      if ( valu.length < 2 ) {
         valu = '00' + valu;
      } else {
         valu = '0' + valu;
      }
   }

   dec = valu.substr (-2, 2);
   int = valu.substr (0, valu.length - 2);
   sub = new Array ();
   while ( int != '' ) {
      sub.unshift (int.substr (-3, 3));
      int = int.substr (0, int.length - 3);
   }

   if ( lang == "en" ) {
      valu = sub.join (',') + '.' + valu.substr (-2, 2);
   } else {
      valu = sub.join ('.') + ',' + valu.substr (-2, 2);
   }

   return valu;

}

/*

=head3 actualitza_div (tip, nom, url)

=over

=item DESCRIPCIÓ

Refresca el contingut d'un div de forma dinàmica

=item PARÀMETRES

   tip: GET/POST
   nom: identificador del div
   url: adreça amb el contingut de la qual es reemplaça el contingut del div

=back

=cut
*/

function actualitza_div (tip, nom, url) {

   nomdivdesti = nom;
   ajaxRequest(tip, url);

}

/* ajaxResponseHandler (responseText)

=head3

=over

=item DESCRIPCIÓ

Funció que efectua efectivament la substitució dinàmica de continguts. Està aquí i no a la llibreria C<ajax.js> perquè cal afegir-hi un postprocessament per tal que executi el codi javascript en fer la substitució dinàmica. Altrament, ho tracta com a codi "declaratiu" i no l'executa.

=item PARÀMETRES

   responseText: text HTML 

=back

=cut
*/

function ajaxResponseHandler (responseText) {

   src = ajax_http.responseText;
   document.getElementById (nomdivdesti).innerHTML = src;
   ini = src.indexOf ('<script type="text/javascript">');

   if ( ini > -1 ) {
      ini = ini + 31;
      end = ajax_http.responseText.indexOf ('</script>', ini);
      javascript = ajax_http.responseText.slice (ini, end);
      eval (javascript);
   }

}

/*

=head3 updt_cist (name, lang, fami, dele, insr, modi, quan, vars)

=over

=item DESCRIPCIÓ

Actualitza dinàmicament via Ajax el formulari de la cistella de compra (L<cist(n)>) quan l'usuari hi fa modificacions.

=item PARÀMETRES

   name: objecte del portal que pinta la cistella
   lang: idioma
   fami: codi de la familia que s'esta visualitzant al cataleg
   dele: codi d'ordre del producte que es vol suprimir
   insr: codi del producte que es vol afegir
   modi: codi d'ordre del producte que es vol modificar
   quan: quantitat del producte afegit/modificat
   vars: codi de la variació que s'està modificant (si és el cas)

=back

=cut
*/

function updt_cist (name, lang, fami, dele, insr, modi, quan, vars) {

   actualitza_div ('GET', name, '/appl/botiga/cist.php?lang='+lang+'&fami='+fami+'&dele='+dele+'&insr='+insr+'&modi='+modi+'&quan='+quan+'&vars='+vars);

}

/*

=head3 void_cist (lang, fami, mssg)

=over

=item DESCRIPCIÓ

Buida (prèvia confirmació) la cistella Ajax

=item PARÀMETRES

   lang: idioma
   fami: codi de la familia que s'esta visualitzant al cataleg
   mssg: missatge de confirmació

=back

=cut
*/

function void_cist (lang, fami, mssg) {

   if ( confirm (mssg) ) {
      updt_cist ('CosCistella', lang, fami, '-1', '', '', '', '');
   }

}

var nomdivdesti = "";

/*****************************************************************************/
/*

=head1 VEGEU TAMBÉ

L</usr/local/lib/php/Botiga2.phps>,
L</htdocs/virtuals/botigues2/gestio/src/botiga.php>,
L</htdocs/virtuals/botigues2/gestio/src/cata.php>,
L</htdocs/virtuals/botigues2/gestio/src/cerc.php>,
L</htdocs/virtuals/botigues2/gestio/src/cist.php>,
L</htdocs/virtuals/botigues2/gestio/src/conf.php>,
L</htdocs/virtuals/botigues2/gestio/src/dpro.php>,
L</htdocs/virtuals/botigues2/gestio/src/fun0.js>,
L</htdocs/virtuals/botigues2/gestio/src/pag0.php>,
L</htdocs/virtuals/botigues2/gestio/src/pag1.php>,
L</htdocs/virtuals/botigues2/gestio/src/pag2.php>,
L</htdocs/virtuals/botigues2/gestio/src/regi.php>,
L</htdocs/virtuals/botigues2/gestio/src/resu.php>,
L</htdocs/virtuals/botigues2/gestio/src/usid.php>,
L</htdocs/virtuals/botigues2/gestio/src/warn.php>

=head1 AUTOR

J. Badiella A. L<jbadiella@drac.com>

DRAC telemàtic L<http://www.drac.com>

Terrassa, Maig 2011

=cut
*/
/*****************************************************************************/

function check_imgs (codi, imag, imgs) {
   for (i = 0; i < imgs; i++) {
      document.getElementById ('link'+codi+'_'+i).style.display = 'none';
      $('#mini'+codi+'_'+i).removeClass ('BotigaCataFamiMiniAct');
      document.getElementById ('midi'+codi+'_'+i).style.display = 'none';
   }
   document.getElementById ('link'+codi+'_'+imag).style.display = 'inline';
   setTimeout ("$('#midi"+codi+"_"+imag+"').fadeIn ();", 200);
   $('#mini'+codi+'_'+imag).addClass ('BotigaCataFamiMiniAct');
}


function check_prod (prid, prva, prtx) {
   document.getElementById ('cata').prod.value = prva;
   document.getElementById ('preu'+prid).innerHTML = prtx;
   prds = eval ("document.getElementById ('cata').prod"+prid);
   for (i = 0; i < prds.length; i++) {
      if ( prds[i].checked ) {
         document.getElementById ('img'+prds[i].value).style.display = 'inline';
         document.getElementById ('lnk'+prds[i].value).style.display = 'inline';
      } else {
         document.getElementById ('img'+prds[i].value).style.display = 'none';
         document.getElementById ('lnk'+prds[i].value).style.display = 'none';
      }
   }
}


function check_acab (prid, lang) {
   prod = eval ("document.getElementById ('cata').prod"+prid);
   if ( prod.length ) {
      for (i = 0; i < prod.length; i++) {
         if ( prod[i].checked ) {
            accs = document.getElementById ('acab'+prod[i].value).value;
            break;
         }
      } 
   } else {
      accs = document.getElementById ('acab'+prod.value).value;
   }

   tmar = Math.round ((window.innerWidth - 998) / 2);
   tlef = myMouseX - tmar;
   ttop = myMouseY - 330;
   document.getElementById ('flotAcabats').style.left = tlef+'px';
   document.getElementById ('flotAcabats').style.top  = ttop+'px';

   document.getElementById ('flotAcabats').innerHTML = '';
   actualitza_div ('GET', 'flotAcabats', '/appl/botiga/acab.php?lang='+lang+'&prod='+prid+'&accs='+accs);
   document.getElementById ('flotAcabats').style.display = 'block';

}


function check_info (prid, lang) {
   prod = eval ("document.getElementById ('cata').prod"+prid);
   if ( prod.length ) {
      for (i = 0; i < prod.length; i++) {
         if ( prod[i].checked ) {
            codi = prod[i].value;
            break;
         }
      } 
   } else {
      codi = prod.value;
   }

   tmar = Math.round ((window.innerWidth - 998) / 2);
   tlef = myMouseX - tmar;
   ttop = myMouseY - 330;
   document.getElementById ('flotInformacio').style.left = tlef+'px';
   document.getElementById ('flotInformacio').style.top  = ttop+'px';

   document.getElementById ('flotInformacio').innerHTML = '';
   actualitza_div ('GET', 'flotInformacio', '/appl/botiga/info.php?lang='+lang+'&prod='+codi);
   document.getElementById ('flotInformacio').style.display = 'block';

}


function set_prod (name) {
   prod = eval ("document.getElementById ('cata')."+name);
   if ( prod.length ) {
      for (i = 0; i < prod.length; i++) {
         if ( prod[i].checked ) {
            document.getElementById ('cata').prod.value = prod[i].value;
         }
      }
   } else {
      document.getElementById ('cata').prod.value = prod.value;
   }
}


function check_bbuy (prid, mssg, port, lang, famc, cist, win1) {

   prod = 'prod'+prid;
   acod = eval ("document.getElementById ('cata').acod"+prid);
   prds = eval ("document.getElementById ('cata').prod"+prid);
   if ( prds.length ) {
      for (i = 0; i < prds.length; i++) {
         if ( prds[i].checked ) {
            accs = eval ("document.getElementById ('cata').acab"+prds[i].value);
         }
      }
   } else {
      accs = eval ("document.getElementById ('cata').acab"+prds.value);
   }

   if ( accs.value != '' ) {
      if ( acod.value == '' ) {
         alert (mssg);
         return false;
      } else {
         $('#cistForm').show ('slow');
      }
   } else {
      $('#cistForm').show ('slow');
   }

   set_prod (prod);
   kuan = eval ("document.getElementById ('cata').quan"+prid);
   document.getElementById ('cata').quan.value = kuan.value;
   document.getElementById ('cata').vars.value = acod.value;
   obre_cist (port, lang, famc, document.getElementById ('cata').prod.value, cist, 'cata', win1, acod.value);

}

/*****************************************************************************/

