<script>
<!--
  jQuery.noConflict();
  [% PROCESS _header_initial_states.tt -%]
  var thruk_static_export = false;
  var refresh_rate        = [% IF refresh_rate %][% refresh_rate %][% ELSE %]null[% END %];
  [%- IF auto_reload_fn +%]
  var auto_reload_fn      = function(cb) { return([% auto_reload_fn %](cb)) };
  var datetime_format_long = '[% datetime_format_long %]';
  [%- END +%]
  var enable_shinken_features = [% enable_shinken_features %];
  [%- IF enable_shinken_features +%]
  var priorities          = new Array('[% FOREACH prio = priorities.keys.sort.reverse %][% priorities.$prio %][% UNLESS loop.last %]', '[% END %][% END %]');
  [%- END +%]
  var url_prefix          = '[% url_prefix %]';
  var product_prefix      = '[% product_prefix %]';
  var cookie_path         = '[% cookie_path %]';
  var theme               = '[% theme %]';
  var theme_default       = '[% c.config.default_theme %]';
  var theme_default_dark  = '[% c.config.default_theme_dark %]';
  var has_expire_acks     = [% IF has_expire_acks %]true[% ELSE %]false[% END %];
  var fav_counter         = [% IF fav_counter +%]true[% ELSE %]false[% END %];
  var perf_bar_mode       = '[% perf_bar_mode %]';
  var perf_bar_pnp_popup  = '[% perf_bar_pnp_popup %]';
  var jquery_ui_url       = '[% url_prefix %]vendor/jquery-ui-[% c.config.jquery_ui %]/js/jquery-ui-[% c.config.jquery_ui %].custom.min.js';
  var jquery_ui_css       = '[% url_prefix %]vendor/jquery-ui-[% c.config.jquery_ui %]/css/smoothness/jquery-ui-[% c.config.jquery_ui %].custom.min.css';
  var thruk_debug_js      = [% IF thruk_author %]true[% ELSE %]false[% END %];
  var minimal             = [% IF minimal %]true[% ELSE %]false[% END %];
  var CSRFtoken           = '[% get_user_token(c) %]';
[%- IF c.user_exists %]
  var remote_user         = '[% remote_user %]';
  var remote_groups       = [% json_encode(c.user.groups) %];
  var thruk_user          = [% json_encode(c.user.js_data) %];
[%- END %]
  var omd_site            = '[% omd_site %]';
  var referer             = '[% escape_js(uri_with(c, '_' => 'undef' )) %]';
  var full_uri            = '[% escape_html(full_uri(c, 1)).replace('&amp;', '&').replace('&amp;', '&') %]';
  var original_uri        = '[% IF original_url %][% original_url.replace('^http.*cgi\-bin\/', '').replace('&amp;', '&') | uri %][% END %]';
  var show_sitepanel      = '[% show_sitepanel %]';
  var param_backend       = [% json_encode(param_backend.list) %];
  var backend_chooser     = '[% backend_chooser %]';
  var downtime_duration   = [% downtime_duration %];
  var has_debug_options   = [% has_debug_options %];
  var maximum_search_boxes = [% c.config.maximum_search_boxes %];
  var escape_html_tags    = [% IF escape_html_tags %]true[% ELSE %]false[% END %];
  var is_executing_timeout = [% 1000 * c.config.is_executing_timeout %];
  var sort_options        = [% json_encode(data_sorted) %];
  var menuState           = [% json_encode(menu_states) %];
  var server_time_unix_millis = [% ts = date_now_millis(); ts %];
  var server_time_str         = "[% tsu = ts / 1000; date_format(c, tsu, '%Y-%m-%d %H:%M:%S') %]";
  [% IF defined("pager") -%]
  var pager = [% json_encode(pager) %];
  [%- END %]
  [%- PROCESS _common_js_bugs.tt -%]

  [%- IF disable_backspace -%]
  jQuery(document).on("keydown", function (e) {
    if(e.which === 8 && !jQuery(e.target).is("input, textarea")) {
      e.preventDefault();
    }
  });
  [%- END -%]

  [%- IF original_url -%]
  var history_url = '[% original_url %]';
  history_url     = history_url.replace(/&amp;/g, '&');
  if(history.replaceState) {
    history.replaceState({}, "", history_url);
  }
  [%- END -%]

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

  [%- IF fav_counter -%]
  /* favicon counter */
  [%- totals = set_favicon_counter(c) -%]
    [%- IF totals.red > 0 && totals.yellow == 0 && totals.orange == 0 -%]
      updateFaviconCounter([% totals.red %], '#FF5B33');
    [%- ELSIF totals.red == 0 && totals.yellow > 0 && totals.orange == 0 -%]
      updateFaviconCounter([% totals.yellow %], '#FFDE00');
    [%- ELSIF totals.red == 0 && totals.yellow == 0 && totals.orange > 0 -%]
      updateFaviconCounter([% totals.orange %], '#FF9E00');
    [%- ELSE -%]
      updateFaviconCounter([% totals.red + totals.yellow + totals.orange %], '#FF9E00');
    [%- END -%]
  [%- END -%]

  [%# switch to dark theme if preferred by the user #%]
  [% IF !c.req.parameters.defined("theme") %]
  var cookieTheme = readCookie('thruk_theme');
  if(!cookieTheme || cookieTheme.match(/^auto:/)) {
    switchTheme(cookieTheme);
  }
  // watch for changes
  if(window.matchMedia) {
    window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
      switchTheme(cookieTheme);
    });
  }
  if (window.location.hash) {
    document.documentElement.classList.add('page-has-hash');
  }
  [% END %]
-->
</script>
