
        var item={
                  usuaid:0,
                  usuanudi:null,
                  valorTotal:0,
                  token:"",
                  localidad:""
                };

        var numberNequi ="";

        document.getElementById("nequinumber").value=item.usuanudi;  
        let spinner = document.getElementById("spinner");
        var mybar = document.getElementById("myProgress");
        var NequiThrowId=document.getElementById("waitingNequiThrowId");
        var AproveTransaction=document.getElementById("waitingUserAproveTransaction");
        showorhidde('waitingUserAproveTransaction');
        showorhidde('myProgress');

        var statusDesc1="";
        var statusDesc2="";
        var statusCode=0;

        NequiThrowId.style.visibility='visible';
        var TransactionId=null;

        // store form HTML markup in a JS variable
        var formTemplate1 = $('#form-template1 > form').clone()[0];
        $('#form-template1').remove();

        var formTemplate2 = $('#form-template2 > form').clone()[0];
        $('#form-template2').remove();

        var formTemplate3 = $('#form-template3 > form').clone()[0];
        $('#form-template3').remove();

        var formTemplate4 = $('#form-template4 > form').clone()[0];
        $('#form-template4').remove();        

        // prepare SweetAlert configuration
        var swalConfig1 = {
            title: '',
            content: formTemplate1,
            cancelButtonColor: "#DD6B55",
            //confirmButtonColor: 'LightSeaGreen',
            closeOnClickOutside: false,
            closeOnEsc: false,
            icon: 'https://api.boletosqubit.co/prod/Applications/services/web/images/checkout/QubitNequi.png',
            buttons: {
              cancel: "Desistir",
              catch: {
                text: "Pagar",
                value: "catch",
              }        
            }
        };

        var swalConfig4 = {
          title: 'Felicitaciones',
          content: formTemplate4,
          closeOnClickOutside: false,
          closeOnEsc: false,
          //confirmButtonColor: 'LightSeaGreen',
          icon: 'https://api.boletosqubit.co/prod/Applications/services/web/images/checkout/QubitNequi.png',
          buttons: {
            catch: {
              text: "Aceptar",
              value: "catch",
            }        
          }
      };        

      // prepare SweetAlert configuration
      var swalConfig2 = {
        title: 'Estamos Haciendo Peticion de Pago a Nequi',
        content: formTemplate2,
        closeOnClickOutside: false,
        closeOnEsc: false,
        buttons: false,
        icon: 'https://api.boletosqubit.co/prod/Applications/services/web/images/checkout/qubit.png',
        };
          


                    

        // handle clicks on the "Click me" button
        $('#click-me-nequi').click(function () {
            swal(swalConfig2);
            nequi();

        });

        $('#click-me-nequi-cancel-tpl1').click(function () {
          window.location.href = "https://api.boletosqubit.co/prod/Applications/services/?action=nequinotifications&status=cancel&id="+TransactionId+"&source=mobile&token="+item.token+"&userId="+item.usuaid;
          swal.close();
          
        }); 

        var swalConfig3 = {
          title:'Lo Sentimos',
          content: formTemplate3,
          closeOnClickOutside: false,
          closeOnEsc: false,
          buttons: false,
          icon: 'https://api.boletosqubit.co/prod/Applications/services/web/images/checkout/qubit.png',
          };    
          
          
        /**/
        $('#click-me-nequi-cancel').click(function () {
            swal.close();
            throwInputData();
        });
        
        $('#click-me-nequi-cancel2').click(function () {
            swal.close();
            throwInputData();
        });
        
        // handle clicks on the "Submit" button of the modal form
        $('body').on('click', '.swal-button--confirm', function() {
          //simulateAjaxRequest();
          swal(swalConfig);
        });



        function throwNequiModal(usuaid,usuanudi,token,valorTotal,localidad)
        {
            item.usuaid = usuaid;
            item.usuanudi =usuanudi;
            item.token = token;
            item.valorTotal =valorTotal;
            item.localidad = localidad;

            throwInputData();
        }

        function throwInputData()
        {
            //document.getElementById("nequinumber").value=item.usuanudi;

            //document.getElementById("localidad").value=item.localidad;
            swal(swalConfig1)
            .then((value) => {
              switch (value) {
            
              case "catch":
                numberNequi = $( "#nequinumber" ).val();
                swal(swalConfig2);
                nequi();
                break;
            
              default:
              swal("Qubit Tickets","Usted ha abortado el pago, sus boletos estarán reservados por tiempo muy limitado!","warning");
              }
            });
            $( "#valor" ).val(item.valorTotal);
            $( "#nequinumber" ).val(item.usuanudi);
            $( "#localidad" ).val(item.localidad); 
            $( "#nequinumber").focus();          
        }

        //var tid = setTimeout(mycode, 5000);
        function mycode() {
            // do some stuff...
            tid = setTimeout(mycode, 6000); // repeat myself
            move();
            validatePay();
        }
        function abortTimer() { // to be called when you want to stop the timer
          clearTimeout(tid);
          clearInterval(tid);
        }

        
        function move() {
          var i = 0;
          if (i == 0) {
            i = 1;
            var elem = document.getElementById("myBar");
            var width = 0;
            var id = setInterval(frame, 60);
            function frame() {
              if (width >= 100) {
                clearInterval(id);
                i = 0;
                //var width = 10;
              } else {
                width++;
                elem.style.width = width + "%";
                //elem.innerHTML = width + "%";
                elem.innerHTML ="Esperando Aprobación...";
              }
            }
          }
        }

        
        function nequi()
        {
          console.log(item);  
          showorhidde('transaction');
          const data = 
          {
            "action":"nequiAuth",
            "event"       : "UnregisteredPayment",
            "usuarioid"    : item.usuaid,
            "wallet" : numberNequi, //item.usuario.usuanudi, //"39987646431",
            "token"  : item.token,
            "valor"  :((item.valorTotal*10)/10)

          };
            $.ajax({
              method: "POST",
              url: "https://api.boletosqubit.co/prod/Applications/services/",
              accepts: "application/json",
              data: JSON.stringify(data),
              headers: {
                "Content-Type": "application/json",
                "Authorization" : "MzRVU1BWVUFURThLWDE4MElDTFVUMDNDTzpQSHozZitnMzNiNFpHc1R3dEtOQ2h0NzhBejNpSjdwWTIwREo5N0R2L1g42"
              },              
              cache: false
          }).then(function (data) {

              var content = JSON.parse(data);

              if (content != null) {
                  if (content.data.status == 1) {
                    //console.log("Transaccion Id: " +content.data.transactionId);
                    TransactionId = content.data.transactionId;
                    $('#transaction').html("Id:" + TransactionId);
                    showorhidde('transaction');
                    //mybar.style.visibility ='show';
                    $('.swal-title').text("Estamos esperado su aprobación");
                    mycode();
                    showorhidde('waitingUserAproveTransaction');
                    showorhidde('waitingNequiThrowId');
                    $('#waitingNequiThrowId').remove();
                    showorhidde('myProgress');
                  }
                  if (content.data.status == -1) {
                    //console.log("Transaccion Id: " +content.data.transactionId);
                    TransactionId = content.data.transactionId;
                    statusDesc1=content.data.statusDesc;
                    statusDesc2=content.data.statusDesc2
                    statusCode=content.data.statusCode;
                    swal.close();
                    swal(swalConfig3);
                    document.getElementById("nequiErrorDescription").innerHTML="<b>Situaciones Reportadas por Nequi</b> <br><br><b>1</b>- <b>"+statusCode+"</b> "+statusDesc2 + "<br>"+"<b>2</b> -"+statusDesc1+"<br><br><br>Numero: "+numberNequi+"<br>Token:"+item.token+"<br>Valor: "+item.valorTotal+"<br>Usuario :"+item.usuaid;
                }
              }

          }).catch(function (data) {
              alert(data.responseText);
          });          
        }

        function validatePay()
        {
          const data1 = 
          {
          "action"       :"nequiAuth",
          "event"        :"GetStatusPayment",
          "transactionid":TransactionId

          };
            $.ajax({
              method: "POST",
              url: "https://api.boletosqubit.co/prod/Applications/services/",
              accepts: "application/json",
              data: JSON.stringify(data1),
              headers: {
                "Content-Type": "application/json",
                "Authorization" : "MzRVU1BWVUFURThLWDE4MElDTFVUMDNDTzpQSHozZitnMzNiNFpHc1R3dEtOQ2h0NzhBejNpSjdwWTIwREo5N0R2L1g42"
              },              
              cache: false
          }).then(function (data) {

              var content = JSON.parse(data);
              if (content != null) {
                  if (content.data.status == 35) {
                    abortTimer();
                    swal.close();
                    swal(swalConfig4)
                    .then((value) => {
                      switch (value) {
                          case "catch":
                              location.href = "https://secure.boletosqubit.co/index.php?modulo=shoppingCart&controlador=ShoppingCart&funcion=getNequiPayResponse&tokenCompra="+item.token+"&TransactionId="+TransactionId;
                          break;
              
                      }
                    });      
                    
                  }
                  if (content.data.status == 33) {
                    console.log("Waiting ..... :)");
                    //"https://api.boletosqubit.co/prod/Applications/services/?action=nequinotifications&&status=cancel&id="+TransactionId+"&source=mobile&token="+item.token+"&userId="+item.usuario.usuaid;
                  }
              }

          }).catch(function (data) {
              alert(data.responseText);
          });           
        }

        function showorhidde(element) {
          var x = document.getElementById(element);
          if (x.style.visibility === 'hidden') {
            x.style.visibility = 'visible';
          } else {
            x.style.visibility = 'hidden';
          }
        }
;