function buscarCta(b, a){
  const parametros = new FormData();
  parametros.append("txtNom", document.formCuentas.txtNom.value);
  parametros.append("txtCod", document.formCuentas.txtCod.value);

  $.ajax({
    data:  parametros,
    url:   "busCuentas/data.php",
    type:  "post",
    contentType: false,
    processData: false,
    beforeSend: function () {
      alLoad("Consultando...")
    },
    success: function (jsonPhp) {
      const jsonJS = JSON.parse(jsonPhp);

      tblClear("tblCta");
      jsonJS.cuentas.forEach(function(i){
        addRowCta(i.cta, i.cta_nom, i.cta_con);
      });

      $("#tblCta tbody tr").dblclick(function() {
        selecCta(a, $(this));
      });

      $("#tblCta tbody #btnSelecCta").click(function() {
        selecCta(a, $(this).parents("tr"));
      });

      alClose();
    }
  });
}

function addRowCta(cod, nom, con) {
  const markup =  "<tr>"
                    +"<td>"+cod+"</td>"
                    +"<td>"+nom+"</td>"
                    +"<td class='d-none'>"+con+"</td>"
                    +"<td><button class='btn btn-sm btn-warning badge' id='btnSelecCta'>"+textBtnSelec+"</button></td>"
                  +"</tr>";
  $("#tblCta tbody").append(markup);
}

function selecCta(a, tr) {
  if (inputCta == "txtCod") {
    document.thisform.txtCod.value = tr.find("td:eq(0)").text();
    $("form[name='thisform'] #txtCod").trigger("change");
  } else {
    $("#"+inputCta).val(tr.find("td:eq(0)").text());
    $("#"+inputCta+"Nom").val(tr.find("td:eq(1)").text());
  }

  $("#pills-"+a+"-tab").click();
  $('html, body').animate( { scrollTop : 0 }, 500 );
  tblClear("tblCta");
}