get_height(), load_height();
$(window).bind('resize', set_height_window);

function set_height_window() {
    setTimeout(function(){ auto_right_menus(); }, 100);
    set_height();
}

function get_height() {
    const corrected_Height = 115;
    var uiHeight = $(window).height() - corrected_Height;
    window.uiHeight = uiHeight;
}

function load_height() {
    get_height(), left_scroll(), right_scroll(), $('#main-container-left-body').perfectScrollbar({
        stopPropagationOnClick: 'false',
        suppressScrollX: 'true'
    }), $('#main-container-right-body').perfectScrollbar({
        stopPropagationOnClick: 'false',
        suppressScrollX: 'true'
    });
}

function set_height() {
    get_height(), left_scroll(), right_scroll(), $('#main-container-left-body').perfectScrollbar('update'), $('#main-container-right-body').perfectScrollbar('update');
}

function left_scroll() {
    var fixed_th_height = $("#left-fixed-th-container").height() + 1;
    $("#main-container-left-body").css('height', window.uiHeight - fixed_th_height);
}

function right_scroll() {
    var h = 0;
    h = window.uiHeight;
    $("#main-container-right-body").css('height', h);
}

function auto_right_menus() {
  var autoDIVs;
  
  if (routeTab == 'Transactions') {
    var Width = $('#rightData').width();
    if (Width < 700) {
      /* Small Vertical Monitor */
      $('.trns-th').width('14ch'); /* Transaction Type */
      $('.tth').width('auto'); /* Balences */
      $('.date-th').width('auto'); /* Date */
    } else {
      /* Normal Monitor */
      $('.trns-th').width('auto'); /* Transaction Type */
      $('.tth').width('16ch'); /* Balences */
      $('.date-th').width('9ch'); /* Date */
    }
    
    autoDIVs = ['right-secondary-menu-container', 'right-secondary-content', 'right-fixed-th'];
  } else if (routeTab == 'ViewTransaction') {
    autoDIVs = ['right-secondary-menu-container', 'right-secondary-content'];
  } else if (routeTab == 'NewMaintenance') {
    autoDIVs = ['right-secondary-menu-container'];  
  } else {
    $('#main-container-right-body').css('margin-top', '');
  }
  
  if (autoDIVs != null) {
    var array_menu_calc = calc_menus(autoDIVs);
    var the_height = array_menu_calc[0];
    const fix_seperation = 2;
    $('#main-container-right-body').css('margin-top', the_height - fix_seperation);
    set_menu(array_menu_calc);
    var uih = window.uiHeight;
    $("#main-container-right-body").css('height', uih - the_height);
  }
}

function calc_menus(a) {
  var Height = 0, Width = 0;
  for (index = 0; index < a.length; index++) { 
    Height += $('#' + a[index]).height();
    Width = $('#rightData').width();
  }
  return [Height, Width];
}

function set_menu(a) {
  var h = window.uiHeight;
  var Height = a[0];
  var Width = a[1];
  $('#right-menu-container').css('height', Height );
  $('#right-menu-container').css('width', Width);
}

