var activesubmenu = false;
var oldsubmenu = 0;
var oldtab = 0;
var forcedhidden = false; // If a submenu was already forced to close we don't want to close it again

function hidemenu(id, tab) {
  var menu = 'submenu_' + id;
  if (!activesubmenu && !forcedhidden) {
    document.getElementById(menu).style.display = 'none';
    
    // Hide tab
    var tabmenu = 'menutab' + tab;
    var tabel = document.getElementById(tabmenu);
    if (tabel) {
      tabel.style.display = 'none';
    }
  }
  
  forcedhidden = false;
}

function hidetopmenu(id) {
  var menu = 'topmenu_' + id;
  if (!activesubmenu) {
    document.getElementById(menu).style.display = 'none';
  }
}

function setactivetab(id) {
  var tabmenu = 'menutab' + id;
  if (tabmenu) {
    document.getElementById(tabmenu).style.display = 'block';
  }
}

function submenuactive() {
  activesubmenu = true;
}

function setmainmenu(id, tab) {
  var menu = 'submenu_' + id;
  var submenu = document.getElementById(menu);
  if (submenu) {
    submenu.style.display = 'block';
  }
  
  // Set tab
  var tabmenu = 'menutab' + tab;
  var tabel = document.getElementById(tabmenu);
  if (tabel) {
	tabel.style.display = 'block';
  }
  
  // Hide the old submenu if it is different from the one to be visible
  var menu = 'submenu_' + oldsubmenu;
  if (oldsubmenu != id) {
	forcedhidden = true;
	var oldsubmenuel = document.getElementById(menu);
	if (oldsubmenuel) {
	  oldsubmenuel.style.display = 'none';
	}
  }
  
  // Hide the old tab if it is different from the one to be visible
  var tabmenu = 'menutab' + oldtab;
  if (oldtab != tab) {
    var tabel = document.getElementById(tabmenu);
    if (tabel) {
	  tabel.style.display = 'none';
    }
  }
  
  oldsubmenu = id;
  oldtab = tab;
}

function settopmenu(id) {
  var menu = 'topmenu_' + id;
  document.getElementById(menu).style.display = 'block';
}

function submenuinactive() {
 activesubmenu = false;
}

function setTall() {
  if (document.getElementById) { // Do you know the DOM?
    var maxheight = document.getElementById('contentContainerhome').offsetHeight;
	document.getElementById('container').style.height = maxheight + 140;
	document.getElementById('shadowcontainer').style.height = maxheight;
  }
}

window.onload = function() {
  setTall();
}