var parentX=-1;
var parentY=+12;
var menuX=0;
var menuY=1;

window.highlight=new Array();
window.comboboxen=new Array();
window.activeMenu=null;

document.onmouseup=hideAll;

function sMiE(px, menuname, event, menuid, parentmenu) {
    
    
	var m=findMenu(menuname);
	
	if (m) {
		m.showMenu(event, menuid, 0, px)
	} else {
		if (parentmenu) {
			m=findMenu(parentmenu);
			if (m) m.hideSubmenus();
		} else {
			hideAll();
		}
	}
	
}

function sMiE2(px, menuname, event, menuid, parentmenu) {
	parentX=-1;
	parentY=+12;
	var m=findMenu(menuname);
	if (m) {
		m.showMenu(event, menuid, 0, px)
	} else {
		if (parentmenu) {
			m=findMenu(parentmenu);
			if (m) m.hideSubmenus();
		} else {
			//hideAll();
		}
	}
}

function showMenu(event, A, B, px) {
	if (!this) return;
	showComboBoxen('hidden');
	window.activeMenu=this;

	if (this.visible) return;
	this.hideSisters();

	if (!this.pos) this.pos=getXYcoord( px + '_' + A);

	if (document.all || document.getElementById)
	{
   	  if (this.parentMenu.menu) {
	    this.menu.style.left = this.pos.x+menuX;
	    this.menu.style.top = this.pos.y+menuY;
		} else {
	    this.menu.style.left = this.pos.x+parentX;
	    this.menu.style.top = this.pos.y+parentY;
		}
	  this.menu.style.visibility="visible";
	  this.visible=true;
	}
}

function findMenu(menu) {
	if (window.menus) return menus[menu];
	return null;
}

function hideAll(event) {
	var p=window.activeMenu;
	while (p) {
		p.hideMenu();
		p=p.parentMenu;
	}
	showComboBoxen('visible');
}


function showParents(visibility) {
	if (this.parentMenu) {
		if (document.layers)
			this.parentMenu.menu.visibility=visibility;
		else
			this.parentMenu.menu.style.visibility=visibility;
		this.parentMenu.showParents(visibility);
	}
}

function colorMe(id, color) {
	if (!document.layers) {
		var o=window.highlight[id];
		if (!o) {
			if (document.all)
				o=document.all[id];
			else if (document.getElementById)
				o=document.getElementById(id);

			window.highlight[id]=o;
		}
		if (o) { o.style.backgroundColor=color; }
	}
}

function getXYcoord ( pixel ) {
     var el = document.images[pixel];
     if ( document.layers ) return el;
     var xy = { x:0 ,y:0 };
     do { 
        xy.x += parseInt( el.offsetLeft );
        xy.y += parseInt( el.offsetTop );
        el = el.offsetParent;
     } while ( el );
   xy.x++; xy.y--;
   return xy;
}

function hideMenu() {
	if (!this.menu) return;
	if (!this.visible) return;

	this.hideSubmenus();
	this.menu.style.visibility="hidden";

	this.visible=false;
}

function hideSubmenus() {
	if (this.children) {
		for (var i=0; i<this.children.length; i++)
			this.children[i].hideMenu();
	}
}

function hideSisters() {
	if (this.parentMenu && this.parentMenu.children) {
		for (var i=0; i<this.parentMenu.children.length; i++) {
			this.parentMenu.children[i].hideMenu();
		}
	}
}

function Menu(menuid) {
	this.menuid=menuid;
	this.menu=null;
	this.parentMenu=null;
	this.visibility=false;
	this.level=0;

	this.registerMenu=registerMenu;
	this.showParents=showParents;
	this.hideMenu=hideMenu;
	this.hideSubmenus=hideSubmenus;
	this.hideSisters=hideSisters;
	this.registerChild=registerChild;
	this.showMenu=showMenu;

	this.children=null;
}

function registerMenu(parentid) {
	if (!window.menus) window.menus=new Array();

	var menu=window.menus[parentid];
	this.parentMenu=menu;

	if (document.all) {
		menu=document.all[this.menuid];
	} else if (document.getElementById) {
		menu=document.getElementById(this.menuid);
	}
	this.menu=menu;

	window.menus[window.menus.length]=this;
	window.menus[this.menuid]=this;

    if (this.parentMenu) {
		this.parentMenu.registerChild(this);
	} 
}

function registerChild(menu) {
	if (!this.children) this.children=new Array();
	this.children[this.children.length]=menu;
	menu.level=this.level+1;
}

function findComboBoxen() {
    var COMBOBOX=0;
    if ((document.getElementsByTagName("SPAN"))) {
      var el = document.getElementsByTagName("SPAN");
      var sName;
      for (var i=0; i<el.length; i++) {
        sName=el[i].id;
        if (el[i].id=="hideme") {
		window.comboboxen[COMBOBOX++]=el[i];
	}
      }
    }
}

function showComboBoxen(x) {
	if (!document.layers && document.all) {
		for (var i=0; i<window.comboboxen.length; i++) {
			window.comboboxen[i].style.visibility=x;
		}
	}
}

var id=null;
function setTimeout_(checkTime){
	if (checkTime)
	{
	  if (id!=null)
	   clearTimeout(id);
	  id=window.setTimeout("hidell();",500);
	}
	else
   {
	  if (id!=null)
	    clearTimeout(id);
	  id=null;
	}
}

function hidell() {
 var p=window.activeMenu;
 while (p) {
  p.hideMenu();
  p=p.parentMenu;
 }
 showComboBoxen('visible');
}


