function initializeDuty() {
    $("#Keywords").attr('placeholder', $('#searchPlaceholder').val());

    $dataTable = $('#mainGrid');
    $dataTable.DataTable({
        ajax: {
            url: $dataTable.attr('data-url'),
            data: function (d) {
                d.Keywords = $("#Keywords").val();
            }
        },
        columns: [
            { data: "SetOfTax", name: "AcSetOfTax", className: 'dt-body-center' },
            { data: "Name", name: "AcName", filtertype: "text", render: $.fn.dataTable.render.textbox() },
            {
                data: "DutyType", name: "AcDutyType", filtertype: "text", render: $.fn.dataTable.render.dropdown([
                    { value: "C", name: $("#dutyLoc").val() },
                    { value: "D", name: $("#vatLoc").val() },
                    { value: "T", name: $("#exciseDutyLoc").val() },
                    { value: "0", name: $("#otherLoc").val() }
                ])
            },
            { data: "IncBase", name: "AcIncBase", filtertype: "text", className: 'dt-body-center', render: $.fn.dataTable.render.checkbox() },
            { data: "IncStockValue", name: "AcIncStockValue", filtertype: "text", className: 'dt-body-center', render: $.fn.dataTable.render.checkbox() },
            { data: "InCalcRvc", name: "AcInCalcRvc", filtertype: "text", className: 'dt-body-center', render: $.fn.dataTable.render.checkbox() },
            { data: "HrspendTax", name: "AcHrspendTax", filtertype: "text", className: 'dt-body-center', render: $.fn.dataTable.render.checkbox() }, //TODO: display only on HR
            {
                data: "HrsubType", name: "AcHrsubType", filtertype: "text", render: $.fn.dataTable.render.dropdown([
                    { value: "", name: "" },
                    { value: "V", name: $("#wineLoc").val() },
                    { value: "Z", name: $("#spiritDrinkLoc").val() },
                    { value: "P", name: $("#beerLoc").val() },
                    { value: "B", name: $("#nonAlcoholicDrinkLoc").val() }
                ])}, //TODO: display only on HR
            { data: "IncSuppForPay", name: "AcIncSuppForPay", filtertype: "text", className: 'dt-body-center', render: $.fn.dataTable.render.checkbox() },
            { data: "Hrdeposit", name: "AcHrdeposit", filtertype: "text", className: 'dt-body-center', render: $.fn.dataTable.render.checkbox() } //TODO: display only on HR
        ],
        createdRow: function (row, data, dataIndex) {
            $(row).attr("data-qid", data.AnQid);
            $(row).find("input[type=text]").on("blur", function () {
                updateDuty($(this).closest("tr"));
            });
            $(row).find("input[type=text]").on("keydown", function (e) {
                if (e.keyCode === 13) $(this).blur();
            });
            $(row).find("input[type=checkbox], select").on("change", function () {
                updateDuty($(this).closest("tr"));
            });
        }
    });

    function updateDuty($row) {
        $row.css("cursor", "progress");
        $row.find("input, select").attr("disabled", true).css("cursor", "progress");

        $.ajax({
            url: $("#updateDutyUrl").val(),
            dataType: 'json',
            data: {
                anQid: $row.attr('data-qid'),
                setOfTax: $row.find('td:eq(0)').text(),
                name: $row.find('td:eq(1) input').val(),
                dutyType: $row.find('td:eq(2) select').val(),
                incBase: $row.find('td:eq(3) input').is(':checked'),
                incStockValue: $row.find('td:eq(4) input').is(':checked'),
                inCalcRvc: $row.find('td:eq(5) input').is(':checked'),
                hrspendTax: $row.find('td:eq(6) input').is(':checked'),
                hrsubType: $row.find('td:eq(7) select').val(),
                incSuppForPay: $row.find('td:eq(8) input').is(':checked'),
                hrdeposit: $row.find('td:eq(9) input').is(':checked')
            },
            method: "POST",
            success: function (data) {
                if (data === true) {
                    $row.css("cursor", "");
                    $row.find("input, select").attr("disabled", false).css("cursor", "");
                }
                else {
                    swal({
                        title: '',
                        text: $("#generalErrorLoc").val(),
                        type: "warning",
                        showCancelButton: true,
                        showConfirmButton: false,
                        cancelButtonText: $("#okLoc").val()
                    });
                }
            },
            fail: function () {
                swal({
                    title: '',
                    text: $("#generalErrorLoc").val(),
                    type: "warning",
                    showCancelButton: true,
                    showConfirmButton: false,
                    cancelButtonText: $("#okLoc").val()
                });
            }
        });
    }

    $("select").off("change.tableReload");
    $("select").on("change.tableReload", function () {
        $.fn.dataTable.reload($dataTable);
    });

    var typingTimer;
    var doneTypingInterval = 600;
    $('#Keywords').off('keyup');
    $('#Keywords').on('keyup', function () {
        clearTimeout(typingTimer);
        typingTimer = setTimeout(function () { $.fn.dataTable.reload($dataTable); }, doneTypingInterval);
    });
}