var visibleMenus = new Array();

function golink(el) {
	for(var i = 0; i < el.childNodes.length; i++) {
		if (el.childNodes[i].tagName == "A") {
			document.location.assign(el.childNodes[i].href);
			return;
		} else golink(el.childNodes[i]);
	}
}

function getEl(id) {
	return (document.all)?document.all[id]:(document.getElementById)?document.getElementById(id):null;
}

function getPageOffsetTop(el) {
  var y;

  y = el.offsetTop;
  if (el.offsetParent)
    y += getPageOffsetTop(el.offsetParent);
  return y;
}

function getContainerWith(node, tagName, className) {

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {
  var i, list;

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}


function getPageOffsetLeft(el) {

  var x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);
    
  return x;
}

function getPageOffsetWidth(el) {
  var x = el.offsetWidth;
  if (el.offsetParent == null)
    x += getPageOffsetWidth(el.offsetParent);

  return x;
}

function gettr(el) {
	if (!el) {
		if (window.event) {
			if (window.event.srcElement) {
				i = window.event.srcElement;
			}
		}
	} else {
		i = el;
	}
	
	return i;
}

function getx(tr, id) {
	return getPageOffsetLeft(tr) + getPageOffsetWidth(tr) - 1;
}

function gety(tr, id) {
	return getPageOffsetTop(tr);
}

var sel = null;

function showmenu(el, id) {
	if (o = getEl("menudiv_" + id)) {
		if(o.className == 'menudiv-active') return;
		if (tr = gettr(el)) {
			o.style.left = getx(tr, id) + "px";
			o.style.top = gety(tr, id) + "px";
			o.style.display = "block";
			o.here = true;
			if (p = getContainerWith(el, "DIV", "menudiv")) {
				o.parentMenu = p;
				p.hasSubMenu = true;
			}

			b = false;
			s = sel;
			while (s) {
				p = o;
				while (p) {
					if (p == s) {
						b = true;
						break;
					}
					p = p.parentMenu;
				}
				if (!b) {
					s.style.display = "none";
					s.here = false;
					s.hasSubMenu = false;
				}
				s = s.parentMenu;
			}
			sel = o;
		}
	}
}

function _priv_hidemenu(id) {
	if (o = getEl("menudiv_" + id)) {
		if(o.className == 'menudiv-active') return;
		if (!o.here && !o.hasSubMenu) {
			p = o.parentMenu;
			while (p) {
				if (!p.here) {
					p.style.display = "none";
					p.hasSubMenu = false;
					p = p.parentMenu;
				} else {
					break;
				}
				
			}
			o.hasSubMenu = false;
			o.style.display = "none";
		}
	}
}

function hidemenu(el, id) {
	if (o = getEl("menudiv_" + id)) {
		o.here = false;
	}
	setTimeout("_priv_hidemenu('"+id+"')", 50);
}

function showsubmenu(el) {
	el.here = true;
}

function hidesubmenu(el) {
	el.here = false;
	id = el.id.substr(8);
	setTimeout("_priv_hidemenu('"+id+"')", 50);
}

function replacestyle(el, src, dst) {
	if (el == null) return;

	for(var i = 0; i < el.childNodes.length; i++) {
	
		if (el.childNodes[i].className) {
			var j, list, c;
			list = el.childNodes[i].className.split(" ");
	
			c = false;
			for (j = 0; j < list.length; j++)
				if (list[j] == src) {
					list[j] = dst;
					c = true;
					break;
				}
			if (c == true) {
				var s = '';
				for (j = 0; j < list.length; j++) {
					if (j > 0)
						s = s + ' ';
					s = s + list[j];
				}
				el.childNodes[i].className = s;
			}

		}
		replacestyle(el.childNodes[i], src, dst);
	}
}

function findprev(el) {
	el = el.parentNode.parentNode;
	p = el;
	while ((p.tagName != 'TBODY') && (p.tagName != 'TABLE')) {
		p = p.parentNode;
		
		if (p == null) {
			return null;
		}
	}
	t = null;
	for(var i = 0; i < p.childNodes.length; i++) {
		if (p.childNodes[i] == el) {
			if (t)
			if (t.childNodes)
			for(var j = 0; j < t.childNodes.length; j++) {
				if (t.childNodes[j].tagName == "TD") {
					for(var k = 0; k < t.childNodes[j].childNodes.length; k++) {
						if (t.childNodes[j].childNodes[k].tagName == "TABLE") {
							return t.childNodes[j].childNodes[k];
						}
					}
				}
			}
			return null;
		}
		if (p.childNodes[i].tagName == "TR") {
			t = p.childNodes[i];
		}
	}
	return null;
}

function propagate_selection(sel)	{
	var sel = sel.split('_');
	if(o = getEl('toplink_' + sel[0])) o.className = 'active'; // highlight main menu record 
	if(o = getEl('menudiv_' + sel[0])) o.className = 'menudiv-active';
	if(o = getEl('menulink_' + sel[0] + '_' + sel[1])) o.className = 'active';
}
