function getContextPath() {
  return top.settings.document.global.contextpath.value;
}

function getOffsetLeft(item) {
	var l = item.offsetLeft;
	var p = item.offsetParent;
	while ((p != null) && (p != document) && (p.style.position == 'static')) {
		l += p.offsetLeft;
		p = p.offsetParent;
	}
	return l;
}

function getOffsetTop(item) {
	var l = item.offsetTop;
	var p = item.offsetParent;
	while ((p != null) && (p != document) && (p.style.position == 'static')) {
		l += p.offsetTop;
		p = p.offsetParent;
	}
	return l;
}

function showMenu(menuID) {
	var icon = document.getElementById('icon' + menuID);
	var item = document.getElementById('item' + menuID);
	var menu = document.getElementById('menu' + menuID);
	var l = getOffsetLeft(item) - 2;
	var t = getOffsetTop(item) + item.offsetHeight;
	if ((menu != null) && (l + menu.offsetWidth > document.body.clientWidth))
		l = l + item.offsetWidth - menu.offsetWidth;
	if (icon != null)
		icon.className = 'active';
	item.className = 'active';
	if (menu != null) {
		menu.style.zIndex = 1000;
		menu.style.left = l + 'px';
		menu.style.top = t + 'px';
		menu.style.visibility = 'visible';
	}
}

function hideMenu(menuID) {
	var icon = document.getElementById('icon' + menuID);
	var item = document.getElementById('item' + menuID);
	var menu = document.getElementById('menu' + menuID);
	if (icon != null)
		icon.className = 'normal';
	item.className = 'normal';
	if (menu != null)
		menu.style.visibility = 'hidden';
}

function homeMenu(menuID) {
	top.main.location.href = '../homepage/' + menuID + '.html';
}

function groupMenu(menuID) {
	top.main.location.href = '../grouppage/' + menuID + '.html';
}

function chapterMenu(menuID) {
	top.main.location.href = '../chapterpage/' + menuID + '.html';
}

function searchMenu(menuID) {
	top.main.location.href = '../searchpage/' + menuID + '.html';
}

function textMenu(menuID) {
	top.main.location.href = '../textpage/' + menuID + '.html';
}

function userMenu(menuID) {
	top.main.location.href = '../userpage/' + menuID + '.html';
}

function copyMenu(item) {
	var menu = top.menu.document.getElementById('menu');
	if (menu == null) return;
	var dest = top.main.document.getElementById('displayMenu');
	if (dest == null) return;
	dest.innerHTML = menu.innerHTML;
}