$(function () {
    "use strict";
    if($('.tooltipster-top').length>0){
        $('.tooltipster-top').tooltipster({
            position: "top"
        });
    } 
});

$(function () {
    "use strict";
    if($('.chosenSelect').length>0){
        $('.chosenSelect').chosen();
    }
});

$(function () {
    "use strict";
    if($('#blockList').length>0){
        $('#blockList').dataTable({
            ordering: false,
            searching: false,
            paging: false,
            info: false,
            dom: '<f<t><"bottom"ilp>><"clear">',
            language: {
                url: language,
            }
        });
    }
});

$(function () {
    "use strict";
    if($('.itemHTMLTable').length>0){
            $('.itemHTMLTable').DataTable(
                {
                    ordering: false,
                    searching: true,
                    paging: false,
                    info: false,
                    "dom": '<f<t><"bottom"ilp>><"clear">',
                    language: {
                        url: language,
                    }
                }
            );
        
        $('.searchThisGroup').on( 'keyup', function () {
            var table = $(this).attr('data-table');
            $('.'+table).DataTable().search( this.value ).draw();
        } );
        $('.collapseAll').on('click', function () {
            $('.boxPagesGroup').removeClass('collapsed-box');
            $('.collapseExpand').click();
        });
        $('.expandAll').on('click', function () {
            $('.collapsed-box .collapseExpand').click();
        })

    }
});

$(function () {
    "use strict";
    // wyświetlanie stron
    $('.selectCategory').change(function () {
        $('#selectCategoryForm').submit();
    });
    //wysyłanie formularza paginacji
    $('select[name=per_page]').change(function () {
        $(this).parent().submit();
    })
})


$(function () {
    "use strict";
    // usuwanie pytania
    $('#deleteItemHTML').change(function () {
        if (this.checked) {
            $('#ItemHTMLDeleteInput').removeAttr('disabled');
        } else {
            $('#ItemHTMLDeleteInput').attr('disabled', 'disabled');
        }


    });
});

// Chosen
$(function () {
    "use strict";
    // Włączenie chosen - dodawanie i edycja newsa - wybór kategorii
    if($('.chosenSelectGroup').length>0){
        $('.chosenSelectGroup').chosen();
    }
})

$(function() {
    if($('.dateStart').length>0){
        $('.dateStart').datetimepicker({
            format: 'Y/m/d',
            onShow: function (ct) {
                this.setOptions({
                    maxDate: jQuery('.dateEnd').val() ? jQuery('.dateEnd').val() : false
                })
            },
            timepicker: false,
            closeOnDateSelect: true,
            scrollInput: false
        });
    }
    if($('.dateEnd').length>0){
        $('.dateEnd').datetimepicker({
            format: 'Y/m/d',
            onShow: function (ct) {
                this.setOptions({
                    minDate: jQuery('.dateStart').val() ? jQuery('.dateStart').val() : false
                })
            },
            timepicker: false,
            closeOnDateSelect: true,
            scrollInput: false
        });
    }
});