var curmen=[];var lastmen=[];var em=[];var emt=[];
function closepopdelay(menid){
	var re = new RegExp('ect\\d+_');
	var theid=menid.replace(re,'');
	var mennum = menid.replace('ect','').replace(/_\d+/,'');
	for(var ei in emt[mennum]){
		if(ei!=0&&emt[mennum][ei]==true&&!insubmenu(ei,mennum)){
			document.getElementById('ecttop'+mennum+"_"+ei).style.display='none';
			emt[mennum][ei]=false; // closed
			removeactiveclass(mennum,ei);
		}
	}
}
function closepop(men){
	var mennum = men.id.replace('ect','').replace(/_\d+/,'');
	lastmen[mennum]=curmen[mennum];
	curmen[mennum]=0;
	setTimeout("closepopdelay('"+men.id+"')",1000);
}
function getPos(el){
	for (var lx=0,ly=0; el!=null; lx+=el.offsetLeft,ly+=el.offsetTop, el=el.offsetParent){
	};
	return{x:lx,y:ly};
}
function openpop(men,ispopout){
	var re = new RegExp('ect\\d+_');
	var theid=men.id.replace(re,'');
	var mennum = men.id.replace('ect','').replace(/_\d+/,'');
	curmen[mennum]=theid;
	if(lastmen[mennum]!=0) {
		closepopdelay('ect'+mennum+'_'+lastmen[mennum]);
	}
	if(mentop=document.getElementById('ecttop'+mennum+'_'+theid)){
		var px = getPos(men);
		if(em[theid]==0&&!ispopout){
			mentop.style.left=px.x+'px';
			mentop.style.top=(px.y+men.offsetHeight-1)+'px';
			mentop.style.display='';
		}else{
			mentop.style.left=(px.x+men.offsetWidth-1)+'px';
			mentop.style.top=px.y+'px';
			mentop.style.display='';
		}
		emt[mennum][theid]=true; // open
		addactiveclass(mennum,theid);
	}
}
function hassubs(men){
	var re = new RegExp('ect\\d+_');
	var theid=men.id.replace(re,'');
	for(var ei in em){
		if(em[ei]==theid)
			return(true);
	}
	return(false);
}
function closecascade(men){
	var re = new RegExp('ect\\d+_');
	var theid=men.id.replace(re,'');
	var mennum = men.id.replace('ect','').replace(/_\d+/,'');
	curmen[mennum]=0;
	for(var ei in emt[mennum]){
		if(ei!=0&&emt[mennum][ei]==true&&!insubmenu(ei,mennum)){
			for(var ei2 in em){
				if(em[ei2]==ei){
					document.getElementById('ect'+mennum+"_"+ei2).style.display='none';
				}
			}
		}
	}
	emt[mennum][theid]=false; // closed
	return(false);
}
function opencascade(men){
	var re = new RegExp('ect\\d+_');
	var theid=men.id.replace(re,'');
	var mennum = men.id.replace('ect','').replace(/_\d+/,'');
	if(emt[mennum][theid]==true) return(closecascade(men));
	var mennum = men.id.replace('ect','').replace(/_\d+/,'');
	curmen[mennum]=theid;
	for(var ei in em){
		if(em[ei]==theid){
			document.getElementById('ect'+mennum+'_'+ei).style.display='';
			emt[mennum][theid]=true; // open
		}
	}
	return(false);
}
function writedbg(txt){
	if(document.getElementById('debugdiv')) document.getElementById('debugdiv').innerHTML+=txt+"<br />";
}
function insubmenu(mei,mid){
	if(curmen[mid]==0)return(false);
	curm=curmen[mid];
	maxloops=0;
	while(curm!=0){
		if(mei==curm)return(true);
		curm=em[curm];
		if(maxloops++>10) break;
	}
	return(false);
}
function addsubsclass(mennum,menid){
	for(var ei in em){
		if(typeof(emt[mennum][ei])=='boolean'){
			men = document.getElementById('ect'+mennum+'_'+ei);
			if(men.className.indexOf('ectmenuhassub')==-1)men.className+=' ectmenuhassub';
		}
	}
}
function addactiveclass(mennum,theid){
	men = document.getElementById('ect'+mennum+'_'+theid);
	if(men.className.indexOf('ectmenuactive')==-1)men.className+=' ectmenuactive';
}
function removeactiveclass(mennum,theid){
	men = document.getElementById('ect'+mennum+'_'+theid);
	if(men.className.indexOf('ectmenuactive')!=-1)men.className=men.className.replace(' ectmenuactive','');
}

