<!--
/*       Copyright (C) Dynamica S.r.l. 2001-2002.

         Le informazioni, il formato e la sintassi di questo modulo
         sono  di proprieta' della  Dynamica S.r.l. che ne conserva
         tutti i diritti ai sensi della corrente normativa Italiana
         sul diritto d'autore.
         La  Dynamica  S.r.l.  non  si  fa carico  di  anomalie  da
         malfunzionamento dei propri programmi dovute a alterazioni
         e/o aggiunte apportate a questo file.

         The information in this file is provided for the exclusive use of
         the licensees of Dynamica s.r.l..  Such users have the
         right to use and  modify this code provided that it is used
         exclusively with Dynamica's products and for purposes authorized
         by the license agreement provided they include this notice and
         the associated copyright notice with any such product.
         The information in this file is provided "AS IS" without warranty.

         Dynamica S.r.l. Milano, 2001-2002.
*/

var reload_virfar=2;

var demone_refresh_inframe = null;
var oldvalrefresh = null;
var ref_orig = null;

/*
   invia_form_inframe()
   formLaunch = form della finestra contenitore 
   timeField = campo tempo restante
   stopField = campo abilitazione/disabilitazione refresh
   frameName = campo nome del frame che fa refresh
   formName = nome della form del frame da inviare
   refreshField = input text che contiene il tempo del refresh 
*/
function invia_form_inframe(formLaunch,timeField,stopField,
                            frameName,formName,refreshField,dove,refreal){
   var timeRefresh=1000;

        
   if(ref_orig==null)
      ref_orig=dove;     
   fcont=document.forms[formLaunch];
   if(fcont.elements[stopField].value!="SI"){
      if(String(fcont.elements[timeField].value)!="start") {
         if(eval(fcont.elements[timeField].value)<=0){
            fcont.elements[timeField].value='start';
            document.getElementById(frameName).src=String(dove);
            }
          }
      if(oldvalrefresh==null){
         dove=ref_orig+'&S_refr_reale='+fcont.elements[refreshField].value;
         oldvalrefresh=eval(fcont.elements[refreshField].value);
         fcont.elements[timeField].value=fcont.elements[refreshField].value;
         }
      if(fcont.elements[timeField].value=='start') 
         fcont.elements[timeField].value=eval(oldvalrefresh*1000);
      else
         fcont.elements[timeField].value=eval((fcont.elements[timeField].value - timeRefresh));
      }
   if(demone_refresh_inframe!=null) {
      clearInterval(demone_refresh_inframe);
      demone_refresh_inframe=null;
      }
   demone_refresh_inframe = setInterval('invia_form_inframe("'+formLaunch+'","'+timeField+'","'+stopField+'","'+frameName+'","'+formName+'","'+refreshField+'","'+dove+'")',timeRefresh);
   }

function invia_form_rotativo(formLaunch,timeField,stopField,
                            frameName,formName,refreshField,dove,camloop,jumpField){
   var timeRefresh=1000;
        

   if(ref_orig==null)
      ref_orig=dove;     
   fcont=document.forms[formLaunch];
   if(eval(fcont.elements[jumpField].value)==1){
       fcont.elements[timeField].value='start';
       fcont.elements[jumpField].value=0;
       }
   if(fcont.elements[stopField].value!="SI"){
      if(String(fcont.elements[timeField].value)!="start") {
         if(eval(fcont.elements[timeField].value)<=0){
            fcont.elements[timeField].value='start';
            codice=fcont.elements['codice'].value;
            _str=String(dove)+"&codice="+codice;
            if(fcont.elements[stopField].value=='LOOP')
               _str+="&loop=1";
            document.getElementById(frameName).src=_str;
            }
          }
      if(oldvalrefresh==null){
         dove=ref_orig+'&S_refr_rotativo='+fcont.elements[refreshField].value;
         oldvalrefresh=eval(fcont.elements[refreshField].value);
         fcont.elements[timeField].value=fcont.elements[refreshField].value;
         }
      if(fcont.elements[timeField].value=='start') 
         fcont.elements[timeField].value=eval(oldvalrefresh*1000);
      else
         fcont.elements[timeField].value=eval((fcont.elements[timeField].value - timeRefresh));
      }
   if(demone_refresh_inframe!=null) {
      clearInterval(demone_refresh_inframe);
      demone_refresh_inframe=null;
      }
   demone_refresh_inframe = setInterval('invia_form_rotativo("'+formLaunch+'","'+timeField+'","'+stopField+'","'+frameName+'","'+formName+'","'+refreshField+'","'+dove+'","'+camloop+'","'+jumpField+'")',timeRefresh);
   }

function HelementInRow(i,v){
   stringa='<input type="hidden" value="'+v+'" name="'+i+'">';
   return(stringa);
   }

function ImgInRow(i,s,a,riga){
   stringa='<img align="middle" id="'+i+'" src="'+s+'" alt="'+a+'">';
   return(stringa);
   }
function ItextInRow(i,v,s,m,change){
   stringa='<input class="ilista1" type="text" value="'+v+'" size="'+s+'" name="'+i+'" id="'+i+'" maxlength="'+m+'" '+(change!=''?'onchange="'+change+'"':'')+'>';
   return(stringa);
   }
function DatePopupInRow(form_name,css,sca){
  switch(css){
   case 'li':
      css_cal='little';
      break;
   case 'me':
      css_cal='medium';
      break;
   case 'la':
      css_cal='large';
      break;
     }

   stringa='&nbsp;&nbsp;<a border="0" href="javascript:show_calendar(\''+form_name+'\',\''+sca+'\',\''+css_cal+'\');" onMouseover="window.status=\'Date Picker\';return true" onMouseout="window.status=\'\';return true;"><img border="0" src="/img/'+css+'ICcalen.gif"></a>';
   return(stringa);
   }

function addrow(riga,css,baco,desc,ean,prezzo,form_name){
   restanti=parent.document.forms[form_name].elements['maxhiddenrow'].value;
   if(restanti==0){
      divlast=parent.xbGetElementById('ultimo');
      divlast_s=new xbStyle(divlast);
      divlast_s.setInnerHTML('ATTENZIONE !!! RAGGIUNTO IL LIMITE MASSIMO !!!');
      G_SID=parent.document.forms[form_name].elements['G_SID'].value;
      parent.document.getElementById('play_frame').src=proxy_js+'play_isound.php?G_SID=' + G_SID + '&suono=ERRORE';
      return true;
      }
   restanti--;
   parent.document.forms[form_name].elements['maxhiddenrow'].value=restanti;
   cp=new Array();
   cps=new Array();
   for(i=0;i<11;i++){
      nome='r'+riga+'c'+i;
      cp[i]=parent.document.getElementById(nome);
      cps[i]=new xbStyle(cp[i]);
      }
   cps[0].setInnerHTML(eval(riga)+1);
   cps[1].setInnerHTML(baco);
   cps[2].setInnerHTML(desc);
   cps[3].setInnerHTML(prezzo);
   cps[4].setInnerHTML('0');
   cps[5].setInnerHTML(ItextInRow('CON_'+riga,0,4,4,'')+HelementInRow('BAC_'+riga,baco)+HelementInRow('EAN_'+riga,ean)+HelementInRow('PRE_'+riga,prezzo));
   cps[6].setInnerHTML(ItextInRow("PEN_"+riga,1,4,4,'cambio_manuale('+riga+')')+HelementInRow("QTA_"+riga,0));
   cps[7].setInnerHTML('<div id=\'spunta_'+riga+'\'>'+ImgInRow('stato-h-'+riga,'/img/'+css+'non-spunta.gif','differenza-'+riga,riga)+'</div>');
   cps[8].setInnerHTML(ItextInRow('BOL_'+riga,'',5,15,'')+HelementInRow('FOR_'+riga,''));
   cps[9].setInnerHTML(ItextInRow('FAT_'+riga,'',5,15,'')+HelementInRow('TIP_'+riga,'')+HelementInRow('DES_'+riga,desc)+HelementInRow('JDES_'+riga,desc));
   cps[10].setInnerHTML(ItextInRow('SCA_'+riga,'',10,10,'')+DatePopupInRow(form_name,css,'SCA_'+riga));
   barcode=parent.document.forms[form_name].elements['virt_barcode'].value;
   parent.document.forms[form_name].elements['virt_barcode'].value=barcode + ',\'' + parseInt(baco,10) + '\'';
   ean13=parent.document.forms[form_name].elements['virt_ean13'].value;
   parent.document.forms[form_name].elements['virt_ean13'].value=ean13 + ',\'' + parseInt(ean,10) + '\'';
   nome='JDES_'+riga;
   descrizione=parent.document.forms[form_name].elements[nome].value;
   nome='PEN_'+riga;
   vpenna=parent.document.forms[form_name].elements[nome].value;
   divlast=parent.xbGetElementById('ultimo');
   divlast_s=new xbStyle(divlast);
   divlast_s.setInnerHTML('ultima lettura: '+descrizione+' (qta. '+vpenna+')');
   }

function dyna_exec(a) {
   b=proxy_js+'baco_frame.php?' + a[0] + document.getElementById(a[1]).value;
   document.getElementById('baco_frame').src=b;
   }

function stampa_frame(gsid,nomefile,nomeframe,nomecampo,titolo,copie) {
   alert('stampa di ' + titolo + ' accodata.');
   x=document.forms['chiudiVendita'].elements[nomecampo];
   p=x[x.selectedIndex].value;
   c=document.forms['chiudiVendita'].elements[copie].value;
   b=proxy_js+'stampa_frame.php?G_SID=' + gsid + '&file=' + nomefile + '&printer=' + p + '&copie=' + c;
   document.getElementById(nomeframe).src=b;
   }

/* parte per ordine in ingresso */

function img_conf_onclick_ordine() {
   if (stato == 1) {
      alert("prima di confermare:\naspettare risposta automatica server\n\ngrazie");
      return;
      }
   var error = ck_ordine();
   if (error == '') {
    //if (confirm("controllare l\'inserimento e\npremere OK per confermare!!\n\ngrazie")) {
         document.getElementById('C_conferma_x').value = 33;
         document.getElementById('ordine').submit();
    //   }
      }
   else
      alert(error + "\ngrazie");
   }

function riempi_campi_ordine(gsid,indice,contatore_js,valore) {
   if (trim(valore) == '') {
      document.getElementById('_qta'  + '_' + indice + '_' + contatore_js).value = '1';
      document.getElementById('_baco'  + '_' + indice + '_' + contatore_js).value = '';
      document.getElementById('_desc'  + '_' + indice + '_' + contatore_js).value = '';
      document.getElementById('_ean13'  + '_' + indice + '_' + contatore_js).value = '';
      document.getElementById('_iva'  + '_' + indice + '_' + contatore_js).value = '20';
      document.getElementById('_lotto'  + '_' + indice + '_' + contatore_js).value = '';
      document.getElementById('_sconto'  + '_' + indice + '_' + contatore_js).value = '0,00';
      document.getElementById('_prez'  + '_' + indice + '_' + contatore_js).value = '0,000';
      spara_focus('_baco' + '_' + indice + '_' + contatore_js,1);
      return;
      }
   stato = 1;  
   var var_url = '';
   var oggetto = new Object();
   var obj = GetXmlHttpObject();

   if (obj == null)
      return;
   var_url += '?G_SID=' + gsid;
   var_url += url_random();
   obj.open('POST',proxy_js + 'PH_ordine.php' + var_url,true);
   obj.onreadystatechange = function() {
      if (obj.readyState == 4) {
         if (obj.status == 200) {
            var struct = JSON.parse(obj.responseText);
            if (struct.ok > 0) {
               document.getElementById('_baco'    + '_' + indice + '_' + contatore_js).value = struct.baco;
               document.getElementById('_desc'    + '_' + indice + '_' + contatore_js).value = struct.descr;
               document.getElementById('_ean13'   + '_' + indice + '_' + contatore_js).value = struct.ean13;
               document.getElementById('_iva'     + '_' + indice + '_' + contatore_js).value = struct.iva;
               document.getElementById('_lotto'   + '_' + indice + '_' + contatore_js).value = struct.lotto;
               document.getElementById('_sconto'  + '_' + indice + '_' + contatore_js).value = struct.sconto;
               document.getElementById('_prez'    + '_' + indice + '_' + contatore_js).value = struct.prezzo;
               var next_contatore = (contatore_js + 1);
               var next_indice    = (indice + 1);
               if (document.getElementById('_baco'  + '_' + indice + '_' + next_contatore))
                  document.getElementById('_baco'  + '_' + indice + '_' + next_contatore).focus();
               else if (document.getElementById('_baco'  + '_' + next_indice + '_0'))
                  document.getElementById('_baco'  + '_' + next_indice + '_0').focus();
               }
            else {
               alert('riga n.' + (contatore_js + 1) + ' assegnazione non valida !!');
               document.getElementById('_qta'     + '_' + indice + '_' + contatore_js).value = '1';
               document.getElementById('_baco'    + '_' + indice + '_' + contatore_js).value = '';
               document.getElementById('_desc'    + '_' + indice + '_' + contatore_js).value = '';
               document.getElementById('_ean13'   + '_' + indice + '_' + contatore_js).value = '';
               document.getElementById('_iva'     + '_' + indice + '_' + contatore_js).value = '20';
               document.getElementById('_lotto'   + '_' + indice + '_' + contatore_js).value = '';
               document.getElementById('_sconto'  + '_' + indice + '_' + contatore_js).value = '0,00';
               document.getElementById('_prez'    + '_' + indice + '_' + contatore_js).value = '0,000';
               spara_focus('_baco' + '_' + indice + '_' + contatore_js,1);
               }
            //alert(struct.where); //debug
            stato = 0;
            }
         obj = null;
         }
      }
   oggetto.indice       = indice;
   oggetto.contatore_js = contatore_js;
   oggetto.baco         = valore;
   oggetto.cliente      = document.getElementById('_cliente').value;
   obj.send(JSON.stringify(oggetto));
   }

function ck_enter(id,e) {
   myVal=(document.all ? window.event.keyCode : eval(e.which));
   if (myVal == 13)
      document.getElementById(id).blur();
   }

function spara_focus(id,sec) {
   setTimeout('document.getElementById("' + id + '").focus()',(sec * 1000));
   }

function put_img_conferma() {
   if (document.getElementById('browser_but-conferma'))
      document.getElementById('browser_but-conferma').innerHTML = img_conf;
   }

function ck_ordine() {
   var error = '';
   var check = 0;
   for (var indice = 1;1;indice++) {
      if (!document.getElementById('_baco_' + indice + '_0'))
          break;
      for (var i = 0;1;i++) {
         if (!document.getElementById('_baco_' + indice + '_' + i))
            break;
         if (document.getElementById('_baco_' + indice + '_' + i).value != '') {
            check = 1;
            break;
            }
         }
      }
   if (!check)
      error = "inserire almeno una riga\n";
   return error;
   }


//-->

