var xmlhttp;
var alista=new Array();
var statusdata=new Array();
var checkfields=new Array('statreceiver','sw1','sw2','sw3','fl1','fl2','fl3','fl4','fl5','fl6','fl7','fl8','fl9','fl10','sel1','hid1','hid2');
var fotos=new Array();
var opacix= new Array();
var opacie= new Array();

function correvideo(divmovile)
{
  divmovil=divmovile;
  document.getElementById(divmovil+"0").style.opacity=1;
  document.getElementById(divmovil+"1").style.opacity=1;
  document.getElementById(divmovil+"0").style.backgroundImage="url(\"fotos/"+fotos[0]+"\")";
  document.getElementById(divmovil+"1").style.backgroundImage="url(\"fotos/"+fotos[1]+"\")";
  t=setTimeout("loopvideo()",50);
  moviendo=1; //div que está recibiendo el cambio de opacidad
  signo=-1; //descendiendo o perdiendo opacidad; +1 = adquiriendo más opacidad
  nivelactual=100;
  proximage=1;
  imagesign=1;
}

function loopvideo()
{
  t=setTimeout("loopvideo()",10);
    nivelactual=nivelactual+signo;
    manda=opacix[nivelactual];
    mandie=opacie[nivelactual];
    document.getElementById(divmovil+"1").style.opacity=manda;
    document.getElementById(divmovil+"1").style.filter=mandie;
//    document.getElementById(divmovil+"1").innerHTML=manda;
    if (nivelactual<1) {
     clearTimeout(t);
     t=setTimeout("loopvideo()",5000);
      signo=5;
      proximage=proximage+imagesign;
      if (proximage>fotos.length-1) {
        proximage=0;
      }
      document.getElementById(divmovil+"1").style.backgroundImage="url(\"fotos/"+fotos[proximage]+"\")";
    }
    if (nivelactual>99) {
     clearTimeout(t);
     t=setTimeout("loopvideo()",5000);
      signo=-5;
      proximage=proximage+imagesign;
      if (proximage>fotos.length-1) {
        proximage=0;
      }
      document.getElementById(divmovil+"0").style.backgroundImage="url(\"fotos/"+fotos[proximage]+"\")";
    }
}

function getwhichkey(e) {
if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
}

function focusea(cual)
{
   document.getElementById(cual).focus();
}

function remuevefila(e,proceso) {
  getwhichkey(e);
  if (keynum == 13) {
    valore=document.getElementById("delreceiv").value;
    document.getElementById("delreceiv").value='';
    valore=valore - 1;
    if (valore>=0 && valore<alista.length) {
      alista.splice(valore,1);
      transmite(proceso);
    }
  }
}

function conectafila(e,proceso) {
  getwhichkey(e);
  if (keynum == 13) {
    valore=document.getElementById("linkreceiv").value;
    document.getElementById("linkreceiv").value='';
    valore=valore - 1;
    if (valore>=0 && valore<alista.length) {
      str=getfields();
      if (str && str.length>0) {
        alista[valore]=str;
        transmite(proceso);
      }
    }
  }
}


function transmite(proceso)
{
    str=alista.join(";");

// agregar concatenando más valores a str separando con pipes, según otras cosas que requieran leerse.
    xmlhttp=GetXmlHttpObject();

    if (xmlhttp==null)
    {
      alert ("Your browser does not support AJAX!");
      return;
    }

    var url="ajaxer.php";
        url=url+"?q="+proceso+"&data="+str; 
//proceso es pdv u otro, o más si se crean en ajaxer.php, el cual es un distribuidor con encabezado XML y de ahí se llaman otras rutinas según el valor de q.  Data lleva el dato leído en el campo statreceiver.
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    
}

function getfields()
{
  ssx=document.getElementById("statreceiver").value;
  document.getElementById("statreceiver").value='';
  if (ssx.length>0) {
    for (a in checkfields) {
       if (document.getElementById(checkfields[a])) {
         if (checkfields[a]=='sw1' || checkfields[a]=='sw2' || checkfields[a]=='sw3') {
           if (document.getElementById(checkfields[a]).checked) {
             ssx=ssx+"|"+document.getElementById(checkfields[a]).value;
           }
         }
         else if (checkfields[a]=='sel1') {
           ssx=ssx+"|"+document.getElementById(checkfields[a]).selectedIndex;
         }
         else {
           sub3=checkfields[a].substr(0,3);
           if (sub3=='hid') {
               ssx=ssx+"|("+document.getElementById(checkfields[a]).value+")";
           }
           else {
             if (document.getElementById(checkfields[a]).value != '') {
               ssx=ssx+"|"+document.getElementById(checkfields[a]).value
             }
           }
         }
       }
    }
    return ssx;
  }
}

function extrae(e,proceso,sp)
{
  getwhichkey(e);
  if (keynum == 13) {
    if (!document.getElementById("linkreceiv") || document.getElementById("linkreceiv") && document.getElementById("linkreceiv").value=='') {
      str=getfields();
      alista[alista.length]=str;
      if (str && str.length>0) {
        transmite(proceso);
      }
    }
    else {
      conectafila(e,proceso)
    }
  }
  else if (sp=='transmite') {
    transmite(proceso);
  }
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
st=xmlhttp.responseText;
document.getElementById("statreturn").innerHTML=st;
document.getElementById("statreceiver").focus();
statusdata=st.split("-");
folio=statusdata[2];
folionum=folio.split(":");
  if (folionum[1]!='') {
    alert("La operación se ha cerrado con el folio #"+folionum[1]);
    document.getElementById("enviar").disabled=true;
    document.getElementById("enviar").style.backgroundColor="#cccccc";
    document.getElementById("enviar").style.color="#ffffff";
  }
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


       function tdactiva(a,cn)
       {
         document.getElementById(a).className=cn;
       }
       function incdec(a,masmenos)
       {
         valor=document.getElementById(a).value;
         if (masmenos==-1) {
           valor--;
         }
         if (masmenos==1) {
           valor++;
         }
         if (masmenos==0) {
           valor='';
         }
         document.getElementById(a).value=valor;
       }

      function findinselect(formaname,selname,sample)
      {
        selector=eval("document."+formaname+"."+selname);
        muestra=eval("document."+formaname+"."+sample+".value");
        muestrau=muestra.toUpperCase();
        for (i=0; i<selector.length; i++) {
          var stron=selector.options[i].text;
          strup=stron.toUpperCase();
          testeado=strup.match(muestrau);
          result=eval(testeado);
          if (result) {
            selector.selectedIndex=i;
            break;
          }
        }
      }



 
