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

    $dataTable = $('#mainGrid');
    $dataTable.DataTable({
        ajax: {
            url: $dataTable.attr('data-url'),
            data: function (d) {
                d.Keywords = $("#Keywords").val();
            }
        },
        columns: [
            { data: "IsActive", name: "AcActive", render: $.fn.dataTable.render.toggle("T", true), className: 'dt-body-center dt-head-center' },
            { data: "Id", name: "ACSTATEMENT", filtertype: "text", render: $.fn.dataTable.render.link("Id") },
            { data: "Name", name: "ACNAME", filtertype: "text", render: $.fn.dataTable.render.link("Id") },
            { data: "Description", name: "AcDesc", filtertype: "text" }
        ]
    });

    $("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);
    });
}

function initializeDocumentTextEdit() {
    $(document).ready(function () {
        $('#Id').focus();

        var elems = Array.prototype.slice.call(document.querySelectorAll('#docTextForm .js-switch'));
        elems.forEach(function (html) {
            var switchery = new Switchery(html, { size: 'small' });
        });
    });
}

function removeDocText() {
    $().customModal({
        destroyOnClose: true,
        showCloseButton: true,
        type: "question",
        text: $("#ConfirmDeleteLoc").val(),
        buttons: [
            {
                icon: 'fa fa-times',
                text: $("#NoLoc").val(),
                closeOnAction: true,
                type: 'ghost'
            },
            {
                icon: 'fa fa-check',
                text: $("#YesLoc").val(),
                action: async function () {
                    var elementId = $("#Id").val();
                    const config = {
                        method: 'POST',
                        headers: {
                            'Accept': 'application/json',
                            'Content-Type': 'application/json'
                        },
                        body: JSON.stringify({ id: elementId })
                    };

                    const response = await fetch($("#RemoveDocTextUrl").val(), config);
                    if (response.ok) {
                        const json = await response.json();
                        if (json.IsDeleted === true)
                            window.location = $("#DocTextIndexUrl").val();
                        else {
                            $().customModal({
                                destroyOnClose: true,
                                showCloseButton: true,
                                type: "alert",
                                text: $("#DeleteWasNotSuccessfulLoc").val(),
                                buttons: [
                                    {
                                        icon: 'fa fa-check',
                                        text: $("#ConfirmLoc").val(),
                                        closeOnAction: true,
                                        type: 'primary'
                                    }
                                ]
                            });
                        }
                    }
                },
                closeOnAction: true,
                type: 'primary'
            }
        ]
    });
}