$(document).ready(function () {

    $("body").on("click", '.remove', remove);
    $("body").on("input", '.passport', Calrows);
    $("body").on("blur", '.fltdt', AddRows);
    $("body").on("blur keyup click", '.charges, .remove', Calmain);
    $("body").on("keyup blur", ".passport", getPassdetail);


    function Calmain() {
        var totamt = 0;
        $(".charges").each(function () {
          if (!isNaN(this.value) && this.value.length != 0) {
            totamt += parseFloat(this.value);
          }
        });
        $(".totamt").val(totamt);
      }


  function getPassdetail() {

    var tr = $(this).closest("tr"),
        passport = tr.find(".passport").val();

    $.ajax({
      type: "POST",
      dataType: "json",
      url: "getinvdetail.php",
      data: { passport: passport },
      success: function (response) {
        if (response != "") {
          var paxname = response.paxname;

          tr.find(".paxname").val(paxname);
          tr.find(".charges").focus();
        }
      },
      error: function (request, textStatus, errorThrown) {},
    });
  }


    $('#addnew').click(function () {
        AddRows();
    }); 
    
    function AddRows() {
        var ctr = $('#items').val();
        var hide_check = "";
        if ($("#del_all").prop("checked")) {
            hide_check = 0;
        } else {
            hide_check = 1;
        }
        $.post('acc_ent_add.php', {ctr: ctr, hide: hide_check}, function (data) {
            $(data).appendTo('#tabledata');
            ctr++;
            $('#items').val(ctr);
        });
    }

    function remove() {
        $(this).closest("tr").remove();
    }



    function Calrows() {
       var rowCount = $('#tabledata tr').length;
        $('.nofpass').val(rowCount);
    }

});