function wait_button(btn)
{
    $(btn).attr("disabled", true);
}
function resume_button(btn)
{
    $(btn).attr("disabled", false);
}

var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = window.location.search.substring(1),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
    return false;
};


$(document).ready(function () {

    var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
    var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
      return new bootstrap.Popover(popoverTriggerEl)
    });

    $.each($('.fa'), function(e) {
        console.log('fa found' + $(this).data('src'));
        $(this).css('font-family', "\'Font Awesome\\ 5 Free\'");
        $(this).css('font-weight', 900);
        $(this).css('font-size', '20px');
        $(this).css('content', $(this).data('src'));
    });

    $('.diagnoses_select').select2();
    $('.routing_select2').select2();

    $('.close').click(function(){
        $('#' + $(this).data('target')).hide();
    })

    $('.kill').click(function(){
        $('#' + $(this).data('target')).remove();
    })

    $('.change-color-mode').on('click', function(){
        change_color_mode($('body'));
        change_color_mode($('.navbar'));
        change_color_mode($('.custom-nav-item'));
        change_color_mode($('.card'));
    });

    function change_color_mode(e){
        if (e.attr('data-theme')) {
            e.removeAttr('data-theme');
        } else {
            e.attr('data-theme', 'dark');
        }
    }

    //Язык для datatable
    var url = document.location.search;
    var searchParam = new URLSearchParams(url);
    var lang = searchParam.get('lang');
    if (lang == 'ru') {
        $('#datatable').DataTable({
            "language": {
                "url": "https://cdn.datatables.net/plug-ins/1.10.19/i18n/Russian.json"
            },
            "scrollX": true
        });
    } else {
        $('#datatable').DataTable({
            "language": {
                "url": "https://cdn.datatables.net/plug-ins/1.10.19/i18n/English.json"
            },
            "scrollX": true
        });
    }
    

    $('#header_tabs li a').on('click', function (e) {
      e.preventDefault()
      $(this).tab('show');
      $('#organs_group').hide();
      if ($(this).attr('id') == 'endocscopy_link')
      {
          $('#organs_group').show();
      }
      if ($(this).attr('id') == 'live_endocscopy_link')
      {
          $('#organs_group').show();
      }
    })

    $('#diagnoses_tabs li a').on('click', function (e) {
      e.preventDefault()
      $(this).tab('show');
    });

    $('#hide_deleted').click(function(){
        $('.sql_deleted').hide();
        $('#hide_deleted').hide();
        $('#show_deleted').show();
    });

    $('#show_deleted').click(function(){
        $('.sql_deleted').show();
        $('#hide_deleted').show();
        $('#show_deleted').hide();
    });

});
