//---------------------------------------------------------------------------------------------------------
// flexMenu V6.0
// JavaScript DHTML Hierarchical Menu Class 
// Currently supported browsers: 
// IE5+, Mozilla/5 (e.g. Netscape 6+, FireBird, FireFox), Safari, Camino, Konqueror, Opera 
// 
// (C) FlexScape, LLC, Torsten Heinze 1999-2006, All rights reserved.
//
// Copying or using this code (or parts of it) without explicit permission by FlexScape, LLC is prohibited 
// and will result in proscecution and severe penalties.
//---------------------------------------------------------------------------------------------------------

var timers=new Array();
var currentRID=null; //current selected root menu
var currentMNU=null; //current selected root menu
var usePopContainer=false;
var useScriptlet=false;
//parent window containing this script (e.g. for IFRAME or SCRIPTLET mode)
var pw=self;

//IE only --------------------------------------------------------------------------
if(document.all){var checkedForControls=false;document.onreadystatechange=checkForControls;}else{var checkedForControls=true;}
function checkForControls(){
	if(document.body){
		if(document.body.readyState=="complete"){
			if(checkForControls&&usePopContainer) return;

			usePopContainer=(document.body.getElementsByTagName("IFRAME").length+
							 document.body.getElementsByTagName("SELECT").length+
							 document.body.getElementsByTagName("OBJECT").length+
							 (typeof(window.flexWriteActiveX)!="undefined"))>0;

			//if(usePopContainer)alert(" POP CONTAINER "); //DEBUG
							 
			//only IE7 does no longer support scriptlets (for editor ActiveX control)
			if(navigator.userAgent.indexOf("MSIE 7")<0){
				useScriptlet=	(document.getElementById("flexEdObj"));
				//if(useScriptlet) alert("USING SCRIPTLET "); //DEBUG
			}
			checkedForControls=true;
		}
	}
}
//-----------------------------------------------------------------------------------

function doFalse(){
	return false;
}

function doLink(el,sLink){
	if((!sLink)||(sLink=="")){return}
	if(sLink.indexOf("javascript:")>-1){ 
		eval(sLink);
	}else{
		pw.location.href=sLink;
	}
}

function doMouseOverItem(el,sOverClass,subid){
	if(!checkedForControls) checkForControls();
	doSelect(el,sOverClass,subid);
	el.onselectstart=doFalse;
}

function doSelect(el,sOverClass,subid){
	if(!el){return}
	var mid=el.getAttribute("mid");
	var mnu=document.getElementById(mid);
	//window.status+=mnu;
	if(!mnu) return;
	var rid=mnu.getAttribute("rid");
	//if moved to another menu, then hide last menu
	if(currentRID) if(currentRID!=rid) unSelect(document.getElementById(currentRID));		
	currentRID=rid;
	if(el!=mnu.current){
		unSelect(mnu);
		el.classNameOrg=el.className;
		el.className=sOverClass;
		mnu.current=el;
	}else{
		doClearHideTimer(mid);
		return;
	}
	
	if(typeof(subid)!="undefined") doShowSubMenu(el,subid);
}

function unSelect(mnu){
	doHideSubMenuChildren(mnu);
	resetClass(mnu);
}

function resetClass(mnu){
	if(mnu.current){
		mnu.current.className=mnu.current.classNameOrg;
		mnu.current=null
	}
}

function doShowMenu(id,x,y){
	var mnu=document.getElementById(id);	//the menu
	if(!mnu){return}
	var mhv=mnu.getAttribute("hv");	
	
	if(usePopContainer) mnu=doCreateContainer(id,id,mhv,mnu)
	mnu.style.left=x;
	mnu.style.top=y;
	mnu.style.visibility="visible";
	currentMNU=id;
}

function doShowSubMenu(el,id){
	if(!id){return}
	var mnu=document.getElementById(id);	//the (sub) menu
	if(!mnu){return}
	
	var mid=el.getAttribute("mid");
	
	var parentMenu=document.getElementById(mid); 		// parent menu
	var rid = mnu.getAttribute("rid");					// root menu id
	
	var mhv=mnu.getAttribute("hv");						// direction of menu (horizontal or vertical)
	var phv=parentMenu.getAttribute("hv");				// direction of parent menu (horizontal or vertical)
	
	var w=mnu.offsetWidth;
	var h=mnu.offsetHeight;
	
	//determine positioning parent
	if(mhv=="|"){
		var pel=el;
		//make it look better if parent item width > submenu width
		if((phv=="-")&&(pel.offsetWidth>(w))){mnu.style.width=pel.offsetWidth;w=pel.offsetWidth;}
	}else{
		var pel=parentMenu;
		//horizontal, so same width as parentMenu
		mnu.style.width=parentMenu.offsetWidth;
	}
	
	//determine new position based on parent
	if(phv=="|"){
		var x=mnuGetLeft(pel)+pel.offsetWidth;
		var y=mnuGetTop(pel);
	}else{
		var x=mnuGetLeft(pel);
		var y=mnuGetTop(pel)+ pel.offsetHeight;
	}
			
	if((typeof(parentMenu)!="undefined")||(parentMenu.style.position=="absolute")){
		if(typeof(parentMenu.w)!="undefined"){
		var parw=parentMenu.w;
		var parh=parentMenu.h;
		}else{
		var parw=parentMenu.offsetWidth;
		var parh=parentMenu.offsetHeight;
		}
	}else{
		var parw=0;
		var parh=0;
	}	
	
	var w=mnu.offsetWidth;
	var h=mnu.offsetHeight;
	
	//for vertical menus, adjust scrolling and body width, so it fits always in visible window
	if(mhv=="|"){
		if((x+w)>=(document.body.clientWidth+document.body.scrollLeft)){
			if(phv!="-"){
				x-=w+parw-2;
			}else{
				x=document.body.clientWidth+document.body.scrollLeft-w;
			}
			//window.status=phv+":"+w+":"+parw+":"+x+":"+document.body.clientWidth+":"+document.body.scrollLeft;
		}
			
		/*
		if((y+h)>=(document.body.clientHeight+document.body.scrollTop)){
			window.status=mnu.tagName+":"+((document.body.clientHeight+document.body.scrollTop)-y-10);
			mnu.style.width=w+20;
			mnu.style.height=(document.body.clientHeight+document.body.scrollTop)-y-10;
			//mnu.style.overflowY="scroll";
			mnu.scrolling="yes";
		}
		*/
	}

	if(usePopContainer){
		//1st level sub menu is an IFRAME or SCRIPTLET so apply correct position to 2nd level one
		//since el in sub menu 1 is now positioned relative to it's IFRAME or SCRIPTLET document, 
		//must add parentMenu offset (only if vertical)
		if((mhv=="|")&&(parentMenu.style.position=="absolute")){
	 			x+=parentMenu.offsetLeft;
	 			y+=parentMenu.offsetTop;
	 	}

	 	mnu=doCreateContainer(id,rid,mhv,mnu)
	}

	mnu.style.left=x;
	mnu.style.top=y;
	//mnu.style.filter="BlendTrans(duration=0.3)";
	mnu.style.visibility="visible";
	parentMenu.childMenu=mnu;	//link with parent
	mnu.parentMenu=parentMenu; 
}

function doInitScriptlet(id){
 try{
	var scr=document.getElementById(id);
	if(scr.readyState!="4") setTimeout("doInitScriptlet('"+id+"')",0);
	scr.init(id,scr.HTML);
 }catch(e){}
}

//IE4+ and ActiveX, Frames, Flash put everything in IFRAME or SCRIPTLET now, so zIndex is correct
//tricky: move existing mnu (outer TABLE) into a new created IFRAME or SCRIPTLET
function doCreateContainer(id,rid,mhv,mnu){
	if(mnu.tagName=="OBJECT" || mnu.tagName=="IFRAME") return mnu;
	//remember properties of mnu
	mnu.style.margin="0";
	var sMenuHTML=mnu.outerHTML;
	var w=mnu.offsetWidth;
	var h=mnu.offsetHeight;
	//destroy mnu original, because IFRAME or SCRIPTLET will become new mnu
	mnu.outerHTML="";
		
	//SCRIPTLET OBJECT container
	if(useScriptlet){
		var sHTML='<OBJECT id="'+id+'" type="text/x-scriptlet" data="../_js/flexMenuScriptlet.html" style="position:absolute;border:0px;padding:0px;margin:0px;top:0px;left:0px;width:'+w+'px;height:'+h+'px;visibility:hidden;"></OBJECT>';
		document.body.insertAdjacentHTML("AfterBegin",sHTML);
		var cnt=document.getElementById(id);
		cnt.HTML=sMenuHTML;
		setTimeout("doInitScriptlet('"+id+"')",0);
	//IFRAME container
	}else{
		var sHTML='<IFRAME id="'+id+'" src="javascript:false" style="position:absolute;border:0px;padding:0px;margin:0px;top:0px;left:0px;width:'+w+'px;height:'+h+'px;visibility:hidden;" frameborder=0 scrolling=no></IFRAME>';
		document.body.insertAdjacentHTML("AfterBegin",sHTML);
		var sty="";
		//insert styles into iframe as well
		for (var i=0; i<document.styleSheets.length;i++){
			var styleSrc=document.styleSheets[i].href;
			if((styleSrc)&&(styleSrc!="")) sty+='<link REL="stylesheet" TYPE="text/css" HREF="'+styleSrc+'">\n';
		}
		var scr='<script language="JavaScript">var pw=parent;onload=doShow;function doShow(){'+id+'.style.visibility="visible";'+id+'.onmousemove=null;'+id+'.onmouseout=null;};setTimeout("doShow()",10);</script>';
		var t=eval(id+".document");
		t.open();
		t.writeln(sty+scr+'\n<body TOPMARGIN=0 LEFTMARGIN=0 RIGHTMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0 onmouseover="pw.doClearHideTimer(\''+id+'\')" onmousemove="pw.doClearHideTimer(\''+id+'\')" onmouseout="pw.doSetHideTimer(\''+id+'\')">'+sMenuHTML+'</body>');
		t.close();
		var cnt=document.getElementById(id);
	}
	cnt.rid=rid;
	cnt.hv=mhv;
	mnu=cnt;
	return mnu;
} 
	
function doClearHideTimer(id){
	var mnu=document.getElementById(id);
	var rid=mnu.getAttribute("rid");
	//window.status=mnu.id+":"+rid+" hide timer cleared";
	if(timers[rid]){clearTimeout(timers[rid]);timers[rid]=null}
}

function doSetHideTimer(id){
	var mnu=document.getElementById(id);
	if(!mnu) return;
	var rid=mnu.getAttribute("rid");
	doClearHideTimer(id);
	timers[rid]=setTimeout("doHideSubMenuRecurse('"+id+"')",450);
}
	
function doHideSubMenuChildren(mnu){
	//close all children
	while(mnu.childMenu){
		resetClass(mnu.childMenu);
		pot=document.getElementById(mnu.childMenu.id);
		if(pot) pot.style.visibility="hidden";
		closedMenu=mnu;
		mnu=mnu.childMenu;
		closedMenu.childMenu=null;
	}
}
 
function doHideSubMenuRecurse(id){
	var mnu=document.getElementById(id);
	doHideSubMenuChildren(mnu);
	if(mnu.childMenu){return}
	//close menus all the way up to root-parent
	while(mnu){
		resetClass(mnu);
		mnu.childMenu=null; //unlink
		pot=document.getElementById(mnu.id);
		if(pot)if(pot.style.position=="absolute") pot.style.visibility="hidden";
		mnu=mnu.parentMenu;
	}
}
	 
/* ------------- get Element Absolute Left ------------------------------------------------------ */
function mnuGetLeft(el) {
	var x=0;
	while (el!= null){x += el.offsetLeft;el = el.offsetParent;}
	return x;
}

/* ------------- get Element Absolute Top	------------------------------------------------------ */
function mnuGetTop(el) {
	var y=0;
	while (el!= null) {if(el.tagName!="TR"){y += el.offsetTop};el = el.offsetParent;}
	return y;
}

//---------------------------------------------------------------------------------------------------------
//Menu Class Object
//---------------------------------------------------------------------------------------------------------

var zIndex=0;

function clsMenu(){
	this.Name="";
	this.RootName="";
	this.hv="|";
	this.ItemCount=0;
	this.MenuClass="";
	this.ItemSeparatorClass="";
	this.sHTML="";
	this.bIsFirst=true;
	this.CreateMenu=CreateMenu;
	this.CreateSubMenu=CreateSubMenu;
	this.OpenSubMenu=OpenSubMenu;
	this.AddItem=AddItem;
	this.AddSubMenuLink=AddSubMenuLink;
	this.MakeItemSeparator=MakeItemSeparator;
	this.WrapMenu=WrapMenu;
	this.CloseMenu=CloseMenu;
	this.CloseSubMenu=CloseSubMenu;
	this.ExpanderArrow="V";
	this.AbsolutePosition=false;
}
 
function CreateMenu(sName,sDirection,sClass,sExpanderArrow,sItemSeparatorClass){
	this.Name=sName;
	this.RootName=sName;
	this.hv=sDirection;
	this.MenuClass=sClass;
	this.ItemSeparatorClass=sItemSeparatorClass;
	this.ExpanderArrow=sExpanderArrow;
		
	if((!this.AbsolutePosition)&&(this.hv=="|")){var sWidth=" width=\"100%\" "}else{var sWidth=""}	
	
	if(this.AbsolutePosition){var sAbs="position:absolute;top:0px;left:0px;visibility:hidden;"}else{var sAbs=""}
	
	this.sHTML+="<table "+sWidth+" onselectstart=\"return false\" class=\""+ this.MenuClass +"\" style=\"border-collapse:separate;"+sAbs+"\" hv=\""+ 
				sDirection +"\" id="+ sName +" rid="+ this.RootName +" onmousemove=\"pw.doClearHideTimer('"+ sName +"')\" onmouseout=\"pw.doSetHideTimer('"+ sName +"')\" border=0 cellPadding=0 cellSpacing=0>\n";
	if(this.hv=="-"){
		this.sHTML+="<tr><td><table onselectstart=\"return false\" class=\""+ this.MenuClass +"\" style=\"border-collapse:separate;margin:0px;padding:0px;border:0px;background:none;\" border=0 cellPadding=0 cellSpacing=0><tr>\n";
	}
}

function CreateSubMenu(sDirection,sLink,sTitle,sClass,sItemClass,sItemClassOver,sItemSeparatorClass){
	var sName="";
	var sText="";
	sText=sTitle;
	zIndex+=1;
	sName=this.Name + "_" + zIndex;

	if (this.hv=="|"){
		//--- expander arrow vertical
		if (this.ExpanderArrow.indexOf("V")>-1){
			if (this.ExpanderArrow.indexOf("C")>-1) { 
				sText="<img class=mnuArrowV width=12 height=12 border=0 align=right src=\"../_icons/pt.gif\">"+ sText;
			}else{
				sText="<img width=10 height=10 border=0 style=\"margin-left:0px;margin-top:2px;padding:0px;\" align=right src=\"../_icons/ico_arrow_right_small.gif\">"+ sText;
			}
		}
	}else{
		//--- expander arrow horizontal
		if (this.ExpanderArrow.indexOf("H")>-1) {
			if (this.ExpanderArrow.indexOf("C")>-1) { 
				sText=sText +"&nbsp;<img class=mnuArrowH width=12 height=12 border=0 align=absmiddle src=\"../_icons/pt.gif\">";
			}else{
				sText=sText +"&nbsp;<img width=10 height=10 border=0 align=absmiddle src=\"../_icons/ico_arrow_down_small.gif\">";
			}
		}
	}

	this.AddSubMenuLink(sName,sLink,sText,sItemClass,sItemClassOver);
	var rCreateSubMenu=new clsMenu();
	rCreateSubMenu.ExpanderArrow=this.ExpanderArrow;
	rCreateSubMenu.ItemSeparatorClass=sItemSeparatorClass;
	rCreateSubMenu.OpenSubMenu(sName,this.RootName,sDirection,sClass);
	return rCreateSubMenu;
}
	
function OpenSubMenu(sName,sRootName,sDirection,sClass){
	this.hv=sDirection;
	this.Name=sName;
	this.RootName=sRootName;
	this.sHTML+="<table width=150 id="+ this.Name +" hv=\""+ this.hv +"\" rid="+ this.RootName +" class=\""+ sClass +"\" border=0 cellPadding=0 cellSpacing=0 style=\"z-index:"+ 
				zIndex +";position:absolute;top:0px;left:0px;visibility:hidden;border-collapse:separate;\" "+
				" onmousemove=\"pw.doClearHideTimer('"+ this.Name +"')\" onmouseout=\"pw.doSetHideTimer('"+ this.Name +"')\" >\n";
	if(this.hv=="-") {this.sHTML+="<tr>\n"}
}

function AddItem(sLink,sTitle,sClass,sClassOver){
 	var re = new RegExp("'","ig");
	var sLink=sLink.replace(re,"\\'");
	var sText=sTitle;
	this.ItemCount+=1;
	this.MakeItemSeparator(this.ItemSeparatorClass);
	if(this.hv=="|") {this.sHTML+="<tr>\n"}
	this.sHTML+="<td mid="+ this.Name +" style=\"cursor:pointer;\" onclick=\"pw.doLink(this,'"+ sLink +"')\" " +
	 					" onmouseover=\"pw.doMouseOverItem(this,'"+ sClassOver +"')\" class=\""+ sClass +"\" >"+ sText +"</td>\n";
 	if(this.hv=="|") {this.sHTML+="</tr>\n"}
}

function AddSubMenuLink(sSubName,sLink,sTitle,sClass,sClassOver){
 	var re = new RegExp("'","ig");
	var sLink=sLink.replace(re,"\\'");
	var sText=sTitle;
	this.ItemCount+=1;
	this.MakeItemSeparator(this.ItemSeparatorClass);
	if(this.hv=="|") {this.sHTML+="<tr>\n"}
	this.sHTML+="<td mid="+ this.Name +" style=\"cursor:pointer;\" onclick=\"pw.doMouseOverItem(this,'"+ sClassOver +"','"+ sSubName +"');pw.doLink(this,'"+ sLink +"');\" " +
					" onmouseover=\"pw.doMouseOverItem(this,'"+ sClassOver +"','"+ sSubName +"')\" class=\""+ sClass +"\" >"+ sText +"</td>\n";
 	if(this.hv=="|") {this.sHTML+="</tr>\n"}
}
 
//default separator
function MakeItemSeparator(sClass){
 	//make default item separator
	if(!this.bIsFirst) {
		if(this.hv=="-") {
	 	this.sHTML+="<td height=100% valign=middle class=\""+ sClass +"\" style=\"margin:0px;border:0px;padding:0px;width:0px;background:none;\"><img class=\""+ sClass +"\" width=1 height=100% alt=\"\" src=\"../_icons/pt.gif\"></td>";
		}else{
	 	this.sHTML+="<tr class=\""+ sClass +"\" style=\"margin:0px;padding:0px;border:0px;background:none;\"><td align=center><img class=\""+ sClass +"\" width=100% height=1 alt=\"\" src=\"../_icons/pt.gif\"></td></tr>";
		}
	}else{
		this.bIsFirst=false;
	}
}

function WrapMenu(){
 	if(this.hv=="-") {
 		this.sHTML+="</tr></table><table onselectstart=\"return false\" class=\""+ this.MenuClass +"\" style=\"border-collapse:separate;margin:0px;padding:0px;border:0px;background:none;\" border=0 cellPadding=0 cellSpacing=0><tr>\n";
		this.bIsFirst=true;
	}
}
 
function CloseMenu(){
	if(this.hv=="-") {this.sHTML+="</tr></table></td></tr>\n"}
	this.sHTML +="</table>\n";
	return this.sHTML;
}

function CloseSubMenu(){
	if(this.hv=="-") {this.sHTML+="</tr>\n"}
	this.sHTML+="</table>\n";
	return this.sHTML;
}

//only for MakeMenuVerticalList Navigation Module ---------------------------------------------
var openListItems=new Array();
function toggleListMenu(id,depth){
	if(!document.getElementById) return;
	
	if(document.getElementById(openListItems[depth])){
	 	if(openListItems[depth]!=id) document.getElementById(openListItems[depth]).style.display="none";
	}
	
	if(document.getElementById(id)){
	 	if(document.getElementById(id).style.display=="none"){
			document.getElementById(id).style.display="";
			openListItems[depth]=id;
		}else{
			document.getElementById(id).style.display="none";
		}
	}
}
//----------------------------------------------------------------------------------------------
