// SemSrg 08/30/2000
// MenuLib

var cmi = 0;
var ua = navigator.userAgent.toLowerCase(); 
var IE4 = (document.all!=null)?true:false;
var NS4 = (ua.indexOf('netscape') != -1 || document.layers!=null)?true:false;
var IE5 = (IE4 && document.getElementById) ? true : false;
var NS6 = (!IE4 && document.getElementById) ? true : false;

var menus = new Array();
var menuBgColor = null;
var menuTransparency = null;
var current = null;

function subMenuWrite(name)
{
	if(name == null){for(i in menus)if(menus[i].main!=null)document.write(menus[i].menuStr);}
	else document.write(menus[name].menuStr);
}

function menuWrite(name)
{
	if(name == null){for(i in menus)if(menus[i].main!=null)document.write(menus[i].menuStr);}
	else  document.write(menus["SMmm"+name].menuStr);
}

function menuInit()
{
	if(menuBgColor != null)
	{
		for(i in menus)
		{
			if(menus[i].main) continue;
			var obj = findObj(i);
			if(IE4 || NS6)obj.style.background=menuBgColor;
			else if(NS4)obj.bgColor=menuBgColor;
		}
	}
	if(IE4){for(i in document.all)if(i.indexOf("SMmm")!=-1)document.all[i].style.visibility="visible";}
	else if(NS4){for(i in document.layers)if(i.indexOf("SMmm")!=-1)document.layers[i].visibility="show";}
}

/* Important command */window.onload=menuInit;/* Important command */

function mainMenu(name,iClass,hlcolor,mode,width)
{
	this.name="SMmm"+name;
	this.iClass=iClass;
	this.hlcolor=hlcolor;

	this.current=null;
	this.main=true;
	this.mode=mode;
	this.width=width;

	this.hide=mHide;
	this.addItem=addMItem;
	this.addLine=addLine;
	this.highlight=highlight;
	this.close=endmenus;

	cmi=0;                  // clear items counter  
	current = this;
	menus[this.name]=this;	
	menus[this.name].menuStr = '<table align="center" cellspacing="0" cellpadding="1" border="0" '+((mode==2)?"width='"+((width!=null)?width:"100%")+"'":"")+'>';
}

function addMItem(name,subMenu,url)
{
	var ID = this.name+"}"+(cmi++);
	if(this.mode==2) menus[this.name].menuStr += '<tr>';
	if(IE4) menus[this.name].menuStr += '<td '+((this.mode!=2 && this.width!=null)?"width='"+this.width+"'":"")+'><div id="'+ID+'" style="width: 100%; visibility: hidden;"><a href="'+((url)?url:"javascript: menus['"+subMenu+"'].show('"+ID+"',"+this.mode+");")+'" onmouseover="return menus[\''+this.name+'\'].highlight(\''+ID+'\',1'+((url)?"":",'"+subMenu+"',"+this.mode)+')" onmouseout="return menus[\''+this.name+'\'].highlight(\''+ID+'\',0)" class="'+this.iClass+'">&nbsp;'+name+'</a></div></td>';
	else if(NS4) menus[this.name].menuStr += '<td '+((this.mode!=2 && this.width!=null)?"width='"+this.width+"'":"")+'><ilayer id="'+ID+'" width="100%" visibility="hide"><layer onmouseover="return menus[\''+this.name+'\'].highlight(\''+ID+'\',1'+((url)?"":",'"+subMenu+"',"+this.mode)+')" onmouseout="return menus[\''+this.name+'\'].highlight(\''+ID+'\',0)"><a href="'+((url)?url:"javascript: menus['"+subMenu+"'].show('"+ID+"',"+this.mode+");")+'" class="'+this.iClass+'">&nbsp;'+name+'</a></layer></ilayer></td>';
	if(this.mode==2) menus[this.name].menuStr += '</tr>';
}

function popupMenu(name,iClass,hlcolor)
{
	this.name=name;
	this.iClass=iClass;
	this.hlcolor=hlcolor;

	this.current=null;
	this.close=endmenus;
	this.addItem=addPItem;
	this.addLine=addLine;
	this.highlight=highlight;
	this.hide=hide;
	this.show=show;

	menus[name] = this;
	menus[this.name].menuStr = '<div id="'+name+'" class="'+((NS4)?"menuBoxNSStyle":"menuBoxIEStyle")+'"><table border="0" cellpadding="0" cellspacing="0" width="100%">';
	current = this;
	cmi=0;                  // clear items counter
}

function endmenus(){if(this.main)menus[this.name].menuStr += "</table>";else menus[this.name].menuStr += "</table></div>";} 
function addLine(line){menus[this.name].menuStr += '<tr><td>' + line + '</td></tr>';}

function addPItem(name,url,subMenu)
{
	var ID = this.name+"}}"+(cmi++);
	if(IE4)	menus[this.name].menuStr += '<tr><td><div id="'+ID+'" style="width: 100%"><a href="'+((subMenu==null)?url:"javascript: menus['"+subMenu+"'].show('"+ID+"',0)")+'" onmouseover="return menus[\''+this.name+'\'].highlight(\''+ID+'\',1'+((subMenu==null)?"":",'"+subMenu+"',0")+')" onmouseout="return menus[\''+this.name+'\'].highlight(\''+ID+'\',0)" class="'+this.iClass+'">&nbsp;'+name+'</a></div></td></tr>';
	else if(NS4) menus[this.name].menuStr += '<tr><td><ilayer id="'+ID+'" width="100%"><layer onmouseover="return menus[\''+this.name+'\'].highlight(\''+ID+'\',1'+((subMenu==null)?"":",'"+subMenu+"',0")+')" onmouseout="return menus[\''+this.name+'\'].highlight(\''+ID+'\',0)"><a href="'+((subMenu==null)? url:"javascript: menus['"+subMenu+"'].show('"+ID+"',0)")+'" class="'+this.iClass+'">&nbsp;'+name+'</a></layer></ilayer></td></tr>';
}

function absVal(ID,what)
{
	var i=0;
	if(IE4) { 
		var o = document.all[ID];
		switch(what){
			case 'w':i=o.clientWidth;break;
			case 'h':i=o.clientHeight;break;
			default: {
				i = (what=='x')?o.offsetLeft:o.offsetTop;
				var tmpEl = o.offsetParent;
				while(tmpEl!=null) {
					i+=(what=='x')? tmpEl.offsetLeft:tmpEl.offsetTop;
					tmpEl=tmpEl.offsetParent;
				}
			}
		}
	}
	else if(NS6) { 
		var o = document.getElementById(ID);
		switch(what){
			case 'w':i=o.style.width;break;
			case 'h':i=o.style.height;break;
			default: {
				i = (what=='x')?o.offsetLeft:o.offsetTop;
				var tmpEl = o.offsetParent;
				while(tmpEl!=null) {
					i+=(what=='x')? tmpEl.offsetLeft:tmpEl.offsetTop;
					tmpEl=tmpEl.offsetParent;
				}
			}
		}
	}
	else {
		var o=findObj(ID);
		switch(what){
			case 'w':i=o.clip.width;break;
			case 'h':i=o.clip.height;break;
			case 'x':i=o.pageX;break;
			default:i=o.pageY;
		}
	}
	return i;
}

function mHide() {};
function hideAll(e){if(mouseInMenu(e)==false)for(i in menus)menus[i].hide();}
if(IE4) document.onmousedown=hideAll;
if(NS4) {window.captureEvents(Event.MOUSEDOWN); window.onmousedown=hideAll;} 

function mouseInMenu(e) 
{ 
	if(IE4){e=window.event;if(e.clientX>document.body.scrollWidth) return true;}
	for(i in menus){
		if(menus[i].main) continue;
		var obj=findObj(i);
		if(IE4){  
			if(obj.style.visibility=="visible"){
				if((obj.offsetLeft<e.clientX)&&
					(e.clientX<(obj.offsetWidth+obj.offsetLeft))&&
					((obj.offsetHeight+obj.offsetTop-document.body.scrollTop)>e.clientY)&&
					((obj.offsetTop-document.body.scrollTop)<e.clientY)) return true;
			}
		}
		else if(obj.visibility=="show"){
				if((obj.pageX<e.pageX)&&
					(e.pageX<(obj.clip.width+obj.pageX))&&
					((obj.clip.height+obj.pageY)>e.pageY)&&
					(obj.pageY<e.pageY)) return true;
		}
	}
	return false; 
}

function findObj(ID)
{
	if(IE4) return document.all[ID];
	else if(NS6) return document.getElementById(ID);
	else if(NS4) {var names=ID.split('}}');
		var obj='document';
		for(i in names) 
			obj+='.layers[\''+names[i]+'\']';
		return eval(obj);
	}
	return null;
}

function highlight(ID,show,subMenu,mode)
{
	var obj = findObj(ID);  
	if(IE4 || NS6) obj.style.backgroundColor=((show)?this.hlcolor:"");
	else if(NS4) obj.document.bgColor=((show)?this.hlcolor:null);
	if(show) {
		if(this.current) this.current.hide();
		if(subMenu!=null) menus[subMenu].show(ID,mode);
	}
	window.status = "Done";
	return true;
}

function hide()
{
	var obj = findObj(this.name);

	if(this.current){this.current.hide();this.current=null;}
	if(IE4) { obj.style.visibility = "hidden"; obj.style.zIndex = 0;}
	else if(NS4 && !NS6) {obj.visibility = "hide";obj.zIndex = 0;}
}

function show(ID,mode)
{
	var x, y, obj = findObj(this.name); 
	if(ID){
		menus[ID.substring(0,ID.indexOf("}"))].current=this;
		switch(mode)
		{
			case 0:
				x = absVal(ID,'x')+absVal(ID,'w');
				y = absVal(ID,'y');
			break;
			case 1:
				x = absVal(ID,'x');
				y = absVal(ID,'y')+absVal(ID,'h');
			break;
			case 2:
				x = absVal(ID,'x')+absVal(ID,'w');
				y = absVal(ID,'y')-(absVal(this.name,'h')/2);
			break;
		}
		if(IE4) {
			obj.style.posLeft = ((obj.offsetWidth+x)<document.body.scrollWidth)?x:(document.body.scrollWidth-obj.offsetWidth);
			obj.style.posTop = (y>document.body.scrollTop)?y:document.body.scrollTop;
			if(menuTransparency != null) obj.style.filter="alpha(opacity="+menuTransparency+")";
		}
		else if(NS6) {
			obj.style.left = ((obj.style.width+x)<self.document.width)?x:(self.document.width-obj.style.width-15); 
			obj.style.top = (y>self.pageYOffset)?y:(self.pageYOffset);
		}
		else {
			obj.left = ((obj.clip.width+x)<self.document.width)?x:(self.document.width-obj.clip.width-15); 
			obj.top = (y>self.pageYOffset)?y:(self.pageYOffset);
		}
	}
	if(IE4 || NS6)	obj.style.visibility = "visible",obj.style.zIndex = 100;
	else if(NS4) obj.visibility = "show",obj.zIndex = 100;
}