//$(document).ready(function (){
//  document.formSuspen.numCods.value =  document.thisform.inputvCod;
//});

function buscarVaca(b, a){
  const parametros = new FormData();
  parametros.append("numCod", document.formVaca.numCod.value);

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

      tblClear("tblVaca");
      jsonJS.regvacd.forEach(function(i){
        addRowVaca(i.rvd_cod, i.rvd_periodo, i.rvd_fdesi, i.rvd_fdesf, i.rvd_obs);
      });

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

      $("#tblVaca tbody #btnSelecVaca").click(function() {
        selectVaca(a, $(this).parents("tr"));
      });

      alClose();
    }
  });
}

function addRowVaca(cod, periodo, del, al, obs) {
  const markup =  "<tr>"
                    +"<td id='datacod' class='text-center'>"+cod+"</td>"
                    +"<td id='dataperiodo' class='text-center'>"+periodo+"</td>"
                    +"<td id='datadel' class='text-center'>"+del+"</td>"
                    +"<td id='dataal' class='text-center'>"+al+"</td>"                    
                    +"<td class='text-left'>"+obs+"</td>"
                    +"<td><button class='btn btn-sm btn-warning badge' id='btnSelecVaca'>"+textBtnSelec+"</button></td>"
                  +"</tr>";
  $("#tblVaca tbody").append(markup);
}

function selectVaca(a, tr) {
  $("#pills-"+a+"-tab").click();
  /*if (inputProvcp == "txtNit") {
    document.thisform.txtNit.value = tr.find("td:eq(0)").text();
    $("form[name='thisform'] #txtNit").trigger("change");
  } else {*/
    $("#"+inputEmple).val(tr.find("td:eq(0)").text());
    $("#"+inputDel).val(tr.find("td:eq(2)").text());
    $("#"+inputAl).val(tr.find("td:eq(3)").text());
    //if (!nomTF) {
    //  $("#"+inputEmple).trigger("change");
      //$("#"+inputAl).trigger("blur");
    //} else {
    //  $("#"+"txtNom1").val(tr.find("td:eq(1)").text());
    //}
  //}

  //$('html, body').animate( { scrollTop : 0 }, 500 );
  tblClear("tblVaca");
}