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

function obre_bigi (port, lang, img, alt) {
   wid = 100;
   hei = 100;
   lef = Math.round ((screen.availWidth  - wid) / 2);
   ttp = Math.round ((screen.availHeight - hei) / 2);
   if ( port ) {
      window.open ('/appl/botiga/bigi.php?lang='+lang+'&img='+img+'&alt='+escape(alt), 'bigi', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=no,toolbar=no,locationbar=no,statusbar=no');
   } else {
      window.open ('bigi.php?lang='+lang+'&img='+img+'&alt='+escape(alt), 'bigi', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=no,toolbar=no,locationbar=no,statusbar=no');
   }
}

function obre_cata (port, lang, cata, mssg) {
   
   if ( document.getElementById ('cist').modi.value == '1' ) {
      document.getElementById ('cist').save.focus ();
      if ( confirm (mssg) ) {
         gosh = true;
      } else {
         gosh = false;
      }
   } else {
      gosh = true;
   }
   if ( gosh ) {
      if ( port ) {
         document.getElementById ('cist').oper.value = '';
         document.getElementById ('cist').action = cata;
         document.getElementById ('cist').submit ();
      } else {
         document.getElementById ('cist').action = cata;
         document.getElementById ('cist').submit ();
      }
   }

}

function obre_cisc (port) {
   if ( port ) {
      document.getElementById ('conf').oper.value = '2';
      document.getElementById ('conf').submit ();
   } else {
      document.getElementById ('conf').action = 'cist.php';
      document.getElementById ('conf').submit ();
   }
}

function obre_cist (port, lang, cist, codi) {
   if ( port ) {
      document.getElementById ('cata').oper.value = '2';
      document.getElementById ('cata').codi.value = codi;
      document.getElementById ('cata').action = '/'+lang+'/'+cist+'/2/'+codi;
      document.getElementById ('cata').submit();
   } else {
      document.getElementById ('cata').codi.value = codi;
      document.getElementById ('cata').action = 'cist.php';
      document.getElementById ('cata').submit();
   }
}

function obre_cisp (port, lang, cist, varp, codi, win1) {
   if ( (win1 == 'flot') || (win1 == 'blank') ) {
      for (v = 0; v < varp; v++) {
         type = eval ('document.getElementById (\"prod\").vari_' + v + '.type');
         if ( ! type ) {
            long = eval ('document.getElementById (\"prod\").vari_' + v + '.length');
            for (i = 0; i < long; i++) {
               if ( eval ('document.getElementById (\"prod\").vari_' + v + '[' + i +'].checked') ) {
                  vari = eval ('document.getElementById (\"prod\").vari_' + v + '[' + i + '].value');
                  break;
               }
            }
            eval ('window.opener.document.getElementById (\"cata\").vari_' + v + '.value = "' + vari + '"');
         } else {
            switch (type) {
               case 'text':
                  vari = eval ('document.getElementById (\"prod\").vari_' + v + '.value');
                  eval ('window.opener.document.getElementById (\"cata\").vari_' + v + '.value = "' + vari + '"');
                  break;
               case 'checkbox':
                  if ( eval ('document.getElementById (\"prod\").vari_' + v + '.checked') ) {
                     eval ('window.opener.document.getElementById (\"cata\").vari_' + v + '.value = 1');
                  } else {
                     eval ('window.opener.document.getElementById (\"cata\").vari_' + v + '.value = 0');
                     vari = 0;
                  }
               default:
                  vari = eval ('document.getElementById (\"prod\").vari_' + v + '.value');
                  eval ('window.opener.document.getElementById (\"cata\").vari_' + v + '.value = "' + vari + '"');
                  break;
            } 
         }
      }
      if ( port ) {
         window.opener.document.getElementById ('cata').oper.value = '2';
         window.opener.document.getElementById ('cata').codi.value = codi;
         window.opener.document.getElementById ('cata').quan.value = document.getElementById ('prod').quan.value;
         window.opener.document.getElementById ('cata').action = '/'+lang+'/'+cist+'/2/'+codi;
         window.opener.document.getElementById ('cata').submit();
         window.close();
      } else {
         window.opener.document.getElementById ('cata').action = 'cist.php';
         window.opener.document.getElementById ('cata').codi.value = codi;
         window.opener.document.getElementById ('cata').quan.value = document.getElementById('prod').quan.value;
         window.opener.document.getElementById ('cata').submit();
         window.close();
      }
   } else {
      if ( port ) {
         document.getElementById ('prod').oper.value = '2';
         document.getElementById ('prod').action = '/'+lang+'/'+cist+'/2/'+codi;
         document.getElementById ('prod').submit();
      } else {
         document.getElementById ('prod').action = 'cist.php';
         document.getElementById ('prod').codi.value = codi;
         document.getElementById ('prod').submit();
      }
   }
}

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

   if ( document.getElementById ('cist').modi.value == '1' ) {
      document.getElementById ('cist').save.focus ();
      alert (mssg);
   } else {
      if ( port ) {
         document.getElementById ('cist').oper.value = '3';
         document.getElementById ('cist').action = '/'+lang+'/'+cist+'/3';
         document.getElementById ('cist').submit ();
      } else {
         document.getElementById ('cist').action = 'conf.php';
         document.getElementById ('cist').submit ();
      }
   }

}

function obre_prnt (port, lang, cist, ncom) {

   wid = 700;
   hei = 500;
   lef = Math.round ((screen.availWidth  - wid) / 2);
   ttp = Math.round ((screen.availHeight - hei) / 2);

   if ( port ) {
      window.open ('/'+lang+'/'+cist+'/4', 'prnt', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
   } else {
      window.open ('resu.php?lang='+lang, 'prnt', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
   }

}

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

   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 (win6) {
         case 'blank':
            window.open ('/appl/botiga/paga.php?lang=$lang&paga='+document.getElementById ('conf').paga.value, 'paga', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,width=800,height=600,top=0,left=0,resizable=yes');
            paga.focus ();
            break;
         case 'flot':
            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=600,height=400,top=100,left=100,resizable=no');
            break;
         default:
            document.getElementById ('conf').action = '/appl/botiga/paga.php';
            document.getElementById ('conf').submit();
      }
   } else {
      switch (win6) {
         case 'blank':
            window.open ('paga.php?lang=$lang&paga='+document.getElementById ('conf').paga.value, 'paga', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,width=800,height=600,top=0,left=0,resizable=yes');
            break;
         case 'flot':
            paga = window.open ('paga.php?lang=$lang&paga='+document.getElementById ('conf').paga.value, 'paga', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=600,height=400,top=100,left=100,resizable=no');
            break;
         default:
            document.getElementById ('conf').action='paga.php';
            document.getElementById ('conf').submit();
      }
   }

}

function obre_pswd (port, lang, back, cist, win66) {
   if ( port ) {
      switch (win66) {
         case 'blank':
            window.open ('/'+lang+'/'+cist+'/6');
            break;
         case 'flot':
            wid = 400;
            hei = 300;
            lef = Math.round ((screen.availWidth  - wid) / 2);
            ttp = Math.round ((screen.availHeight - hei) / 2);
            window.open ('/'+lang+'/'+cist+'/6', 'pswd', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            /*
            window.top.document.getElementById (back).action = '/'+lang+'/'+cist+'/6';
            window.top.document.getElementById (back).oper.value = '6';
            window.top.document.getElementById (back).submit ();
            */
      }
   } else {
      switch (win66) {
         case 'blank':
            window.open ('pswd.php?lang=$lang');
            break;
         case 'flot':
            wid = 400;
            hei = 300;
            lef = Math.round ((screen.availWidth  - wid) / 2);
            ttp = Math.round ((screen.availHeight - hei) / 2);
            window.open ('pswd.php?lang=$lang', 'pswd', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            /*
            window.top.document.getElementById (back).action = 'pswd.php';
            window.top.document.getElementById (back).submit ();
            */
      }
   }
}

function obre_prod (port, lang, cata, prod, codi, win1) {
   if ( port ) {
      switch (win1) {
         case 'blank':
            window.open ('/'+lang+'/'+prod+'/1/'+codi);
            break;
         case 'flot':
            wid = 750;
            hei = 570;
            lef = Math.round ((screen.availWidth  - wid) / 2);
            ttp = Math.round ((screen.availHeight - hei) / 2);
            window.open ('/'+lang+'/'+prod+'/1/'+codi, 'prod', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            document.getElementById ('cata').oper.value = '1';
            document.getElementById ('cata').codi.value = codi;
            document.getElementById ('cata').action = '/'+lang+'/'+cata+'/1/'+codi;
            document.getElementById ('cata').submit();
      }
   } else {
      switch (win1) {
         case 'blank':
            window.open ('dpro.php?lang='+lang+'&codi='+codi);
            break;
         case 'flot':
            wid = 600;
            hei = 500;
            lef = Math.round ((screen.avalWidth - wid) / 2);
            ttp = Math.round ((screen.avalWidth - hei) / 2);
            window.open ('dpro.php?lang='+lang+'&codi='+codi, 'prod', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            document.getElementById ('cata').codi.value = codi;
            document.getElementById ('cata').action = 'dpro.php';
            document.getElementById ('cata').submit();
      }
   }
}

function obre_regi (port, lang, cist, win5) {

   if ( port ) {
      switch (win5) {
         case 'blank':
            window.open ('/'+lang+'/'+cist+'/5', 'regi', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=800,height=600,top=0,left=0,resizable=no');
            break;
         case 'flot':
            wid = 700;
            hei = 500;
            lef = Math.round ((screen.availWidth  - wid) / 2);
            ttp = Math.round ((screen.availHeight - hei) / 2);
            window.open ('/'+lang+'/'+cist+'/5', 'regi', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            window.location = '/'+lang+'/'+cist+'/5';
      }
   } else {
      switch (win5) {
         case 'blank':
            window.open ('regi.php?lang='+lang, 'regi', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=800,height=600,top=0,left=0,resizable=no');
            break;
         case 'flot':
            wid = 700;
            hei = 500;
            lef = Math.round ((screen.availWidth  - wid) / 2);
            ttp = Math.round ((screen.availHeight - hei) / 2);
            window.open ('regi.php?lang='+lang, 'regi', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            window.location = 'regi.php?lang='+lang;
      }
   }

}

function obre_text (port, lang, cata, oper, wino) {
   if ( port ) {
      switch (wino) {
         case 'blank':
            window.open ('/'+lang+'/'+cata+'/9/'+oper);
            break;
         case 'flot':
            wid = 600;
            hei = 400;
            lef = Math.round ((screen.availWidth  - wid) / 2);
            ttp = Math.round ((screen.availHeight - hei) / 2);
            window.open ('/'+lang+'/'+cata+'/9/'+oper, 'text', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=no,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            window.location = '/'+lang+'/'+cata+'/9/'+oper;
      }
   } else {
      switch (wino) {
         case 'blank':
            window.open ('text.php?lang='+lang+'&oper='+oper);
            break;
         case 'flot':
            wid = 600;
            hei = 400;
            lef = Math.round ((screen.availWidth  - wid) / 2);
            ttp = Math.round ((screen.availHeight - hei) / 2);
            window.open ('text.php?lang='+lang+'&oper='+oper, 'text', 'left='+lef+',top='+ttp+',width='+wid+',height='+hei+',resizable=no,scrollbars=yes,toolbar=no,locationbar=no,statusbar=no');
            break;
         default:
            window.location = 'text.php?lang='+lang+'&oper='+oper;
      }
   }
}

function regi_clos (port, lang, back, win5, canc) {
   if ( canc == '1' ) {
      if ( win5 == 'blank' || win5 == 'flot' ) {
         window.close ();
      } else {
         window.location = back;
      }
   } else {
      if ( win5 == 'blank' || win5 == 'flot' ) {
         window.opener.location = back;
         window.close ();
      } else {
         window.location = back;
      }
   }
}

function usid_subm (blnk) {

   if ( document.getElementById ('usid').usid_uid.value == '' ||
        document.getElementById ('usid').usid_pwd.value == '' ) {
      alert (blnk);
      if ( document.getElementById ('usid').usid_uid.value == '' ) {
         document.getElementById ('usid').usid_uid.focus ();
      } else {
         document.getElementById ('usid').usid_pwd.focus ();
      }
   } else {
      document.getElementById ('usid').submit ();
   }

}

function testcook (init, nock) {
   /*
   if ( document.cookie.length <= 0 ) {
      alert(nock);
      document.location = init;
      return false;
   } else {
   */
      if ( (document.cookie.indexOf ('BTG_SES') == -1) ||
           (document.cookie.indexOf ('BTG_UID') == -1) ) {
         alert(nock);
         document.location = init;
         return false;
      } else {
         return true;
      }
   /*
   }
   */
}

/*****************************************************************************/
/* J. Badiella A. jbadiella@drac.com                                         */
/* DRAC telemātic  http://www.drac.com                                       */
/* Terrassa, Abril 2008                                                      */
/*****************************************************************************/
