function initializeJS() {

    $('.overlay').hide();
    
    // Button Loading Plugin
    $.fn.loadingBtn = function (options) {

        var settings = $.extend({
            text: "Loading"
        }, options);
        this.html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> ' + settings.text + '');
        this.addClass("disabled");
        this.attr("disabled", true);
    };

    $.fn.loadingBtnComplete = function (options) {
        var settings = $.extend({
            html: "submit"
        }, options);
        this.html(settings.html);
        this.removeClass("disabled");
        this.removeAttr('disabled');
    };

    
}

function showOverlay() {

    var windowHeight = $('.content-wrapper').height();
    $('.overlay').height(windowHeight);
    $('.overlay').show();
}

function hideOverlay() {

    $('.overlay').hide();
}

function flashMessage(type, message)
{
    toastr.options = {
        "closeButton": true,
        "debug": false,
        "newestOnTop": false,
        "progressBar": false,
        "positionClass": "toast-top-right",
        "preventDuplicates": false,
        "onclick": null,
        "showDuration": "300",
        "hideDuration": "1000",
        "timeOut": "5000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    };
    if (type == 's')
    {
        toastr.success(message, 'Success');
    } else if (type == 'e')
    {
        toastr.error(message, 'Error');
    } else
    {
        toastr.warning(message, 'Warning');
    }
}

function handleAjaxError(xhr, textStatus, error) {

    if (textStatus === 'timeout') {
        Swal.fire('Alert','The server took too long to send the data.','warning');
    } else if (textStatus === 'error') {
        if (error === 'Unauthorized') {
            //swal("Alert", "Session Expired", "warning");
            flashMessage('e', 'Session Expired');
            location.reload();

        } else {
            //swal("Alert", "Something Went Wrong!!", "warning");
            flashMessage('e', 'Something Went Wrong!!');
        }
    } else {
        //swal("Alert", "Something Went Wrong!!", "warning");
        flashMessage('e', 'Something Went Wrong!!');
    }
    $('.dataTables_processing').css('display', 'none');
    hideOverlay();
}

jQuery(document).ready(function () {
    initializeJS();
});