
window.menusWritten=false;
window.highlight=new Array();
window.container=null;
window.comboboxen=new Array();
document.onmouseup=hideAll;
window.activeMenu=null;

// show menu if exists
function sMiE(menuname, event, menuid, parentmenu) {
	var m=findMenu(menuname);
	if (m) {
		m.showMenu(event, menuid, 0)
	} else {
		if (parentmenu) {
			m=findMenu(parentmenu);
			if (m) m.hideSubmenus();
		} else {
			hideAll();
		}
	}
}

function hideAll(event) {
	var p=window.activeMenu;
	while (p) {
		p.hideMenu();
		p=p.parentMenu;
	}
	showComboBoxen('visible');
}

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, width1) {

	if (!window.menus) window.menus=new Array();

	var menu=window.menus[parentid];
	this.parentMenu=menu;

	this.width1=width1;

	if (document.layers) {
		menu=document.layers[this.menuid];
	} else 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);
//		alert("registered menu " + this.menuid + " to parent " + this.parentMenu.menuid);
	} else {
//		alert("registered menu " + this.menuid + " to no parent");
	}
}

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 registerChild(menu) {
	if (!this.children) this.children=new Array();
	this.children[this.children.length]=menu;
	menu.level=this.level+1;
}

function hideSisters() {
	if (this.parentMenu && this.parentMenu.children) {
		for (var i=0; i<this.parentMenu.children.length; i++) {
			this.parentMenu.children[i].hideMenu();
		}
	}
}


function showMenu(event, A, B) {
	if (!this) return;
	showComboBoxen('hidden');
	window.activeMenu=this;

	if (this.visible) return;

	this.hideSisters();

	if (!this.pos) this.pos=getXYcoord( 'pixel_' + A);

	if (document.layers) {
		eval("document.height")
		this.menu.zindex=1000;
		if (this.parentMenu.menu) {
			this.menu.left=this.pos.X;
			this.menu.top=this.pos.Y;
		} else {
			this.menu.left=this.pos.X;
			this.menu.top=this.pos.Y;
		}
		this.menu.visibility="visible";
		this.visible=true;
	}
	else if (document.all || document.getElementById)
	{
   	  if (this.parentMenu.menu) {
	    this.menu.style.left = this.pos.x;
	    this.menu.style.top = this.pos.y;
		} else {
	    this.menu.style.left = this.pos.x+5;
	    this.menu.style.top = this.pos.y+5;
		}
	  this.menu.style.visibility="visible";
	  this.visible=true;
	}
		findComboBoxen();

}

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();
	if (document.layers)
		this.menu.visibility="hidden";
	else
		this.menu.style.visibility="hidden";

	this.visible=false;
/*
	if (this.parentMenu && this.parentMenu.parentMenu==null) {
		if (document.all) {

     		}
	   }
	   else {
       if (document.all) {

       	}
	   }
*/
}

function hideSubmenus() {
	if (this.children) {
		for (var i=0; i<this.children.length; i++)
			this.children[i].hideMenu();
	}
}

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 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;
		}
	}
}