var isUser=navigator.userAgent.toLowerCase();
var isDom=(document.getElementById)?1:0;
var isNS=(isUser.indexOf('mozilla')!=-1&&isUser.indexOf('compatible')==-1)?1:0;
var isIE=(isUser.indexOf('msie')!=-1)?1:0;
var NS4=(isNS&&!isDom&&document.layers)?1:0;
var IE4=(isIE&&!isDom&&document.all)?1:0;
var DomNS=(isDom&&isNS)?1:0;
var loader=(isNS||isIE)?1:0;
var FLoc,SLoc,DLoc;
var winwidth,childwinwidth,winheight,loadwin;
var FirstColPos,SecColPos,DocColPos;
var initLevel=0,createLevel=0,posLevel=0;
var sFlag=0,FirstCreate=1,Loaded=0,Created=0,iFlag,fullPage=1;
var fCol=null,CurrentOver=null,CloseTimer=null;
var CenterText,TxtClose,ImgStr;
var Ztop=100;
var pageTop=StartTop,pageLeft=StartLeft;
var LeftExtra=(DomNS)?LeftPaddng:0;
var TopExtra=(DomNS)?TopPaddng:0;
var hideIt=(NS4)?'hide':'hidden';
var showIt=(NS4)?'show':'visible';
var isParent=(parent.frames[0])?parent:window;
var Trigger=(parent.frames[0]&&FrFrame==SecFrame)?(isNS)?parent.frames[FrFrame]:parent.frames[FrFrame].document.body:(isNS)?isParent:isParent.document.body;

function menuReload() {
    winwidth=(isIE)?FLoc.document.body.clientWidth:FLoc.innerWidth;
    winheight=(isIE)?FLoc.document.body.clientHeight:FLoc.innerHeight;
    childwinwidth=(isIE)?SLoc.document.body.clientWidth:SLoc.innerWidth;
    childwinheight=(isIE)?SLoc.document.body.clientHeight:SLoc.innerHeight;
    if(HorCentered)
	isLeft();
    if(VerCentered)
	isTop();
    menuPosition(fCol,StartTop,StartLeft);
}

function reDo() {
    Doc.location.reload()
}

if(DomNS)
    Trigger.addEventListener('load',Go,false);
else Trigger.onload=Go;
Trigger.onresize=(NS4)?reDo:menuReload;

function hideAll() {
    if(typeof(CloseTimer)!='undefined'&&CloseTimer)
	clearTimeout(CloseTimer);
    Loaded=0;
    Created=0;
    var menuStyle=(NS4)?fCol:fCol.style;
    menuStyle.visibility=hideIt;
}

function isTop() {
    var i=winheight;
    if(VerCentered!='top') {
	StartTop=pageTop;
	i-=(isHorizontal)?(eval('Menu1[3]')+BorderWidth):(itemNo*(eval('Menu1[3]')+BorderWidth)+BorderWidth);
	if(VerCentered=='bottom')
	    StartTop+=i;
	else 
	    StartTop+=i/2;
    }
}

function isLeft() {
    var i=winwidth;
    if(HorCentered!='left') {
	StartLeft=pageLeft;
	i-=(isHorizontal)?(itemNo*(eval('Menu1[4]')+BorderWidth)+BorderWidth):(eval('Menu1[4]')+BorderWidth);
	if(HorCentered=='right')
	    StartLeft+=i; 
	else 
	    StartLeft+=i/2;
    }
}

function Go() {
    if(Loaded||!loader)
	return;
    Created=0;
    Loaded=1;
    if(FirstCreate) {
	if(FrFrame =="" || !parent.frames[FrFrame]) {
	    FrFrame=SecFrame;
	}
	if(FrFrame =="" || !parent.frames[FrFrame]) {
	    FrFrame=SecFrame=DocFrame;
	}
	if(FrFrame =="" || !parent.frames[FrFrame]) {
	    FrFrame=SecFrame=DocFrame=(parent.frames[0])?parent.frames[0].name:'';
	}
	if(SecFrame =="" || !parent.frames[SecFrame])
	    SecFrame=DocFrame;
	if(SecFrame =="" || !parent.frames[SecFrame])
	    SecFrame=DocFrame=FrFrame;
	if(DocFrame =="" || !parent.frames[DocFrame])
	    DocFrame=SecFrame;
	FLoc=(FrFrame)?parent.frames[FrFrame]:window;
	SLoc=(SecFrame)?parent.frames[SecFrame]:window;
	DLoc=(DocFrame)?parent.frames[DocFrame]:window;
	if (FLoc==SLoc) 
	    fullPage=0;
	if (fullPage)
	    isHorizontal=(isVertical)?0:1;
	    winwidth=(isIE)?FLoc.document.body.clientWidth:FLoc.innerWidth;
	    winheight=(isIE)?FLoc.document.body.clientHeight:FLoc.innerHeight;
	    childwinwidth=(isIE)?SLoc.document.body.clientWidth:SLoc.innerWidth;
	    childwinheight=(isIE)?SLoc.document.body.clientHeight:SLoc.innerHeight;
	if(HorCentered) 
	    isLeft();
	if(VerCentered) 
	    isTop();
	if(!isDom) {
	    CenterText=(TextCentered)?(isNS)?"<DIV ALIGN='CENTER'>":"ALIGN='CENTER'":"";
	    if(isNS)
	    	TxtClose="</FONT>"+(TextCentered)?"</DIV>":"";
	}
    }
    FirstColPos=(NS4)?FLoc.document:FLoc.document.body;
    SecColPos=(NS4)?SLoc.document:SLoc.document.body;
    DocColPos=(NS4)?DLoc.document:SLoc.document.body;
    if (TakeOverBgColor)
	FirstColPos.bgColor=(fullPage)?SecColPos.bgColor:DocColPos.bgColor;
    if(FirstCreate) {
	fCol=createMenu('Menu',itemNo);FirstCreate=0;
    }
    else recreateMenu('Menu',itemNo);
    menuPosition(fCol,StartTop,StartLeft);
    iFlag=1;	
    Initiate(); 
    iFlag=0;
    Created=1; 
    loadwin=(isIE)?SLoc.document.body:SLoc;
    loadwin.onunload=hideAll;
}

function menuPosition(CntnrPntr,Tp,Lt) {
    var Topi,Lefti,Hori;
    var Cntnr=CntnrPntr;
    var item=Cntnr.FirstItem;
    var CntnrStyle=(!NS4)?Cntnr.style:Cntnr;
    var itemStyle=(!NS4)?item.style:item;
    var PadLeft=(item.value.indexOf('<')==-1)?LeftExtra:0;
    var PadTop=(item.value.indexOf('<')==-1)?TopExtra:0;
    var itemWidth=(!NS4)?parseInt(itemStyle.width)+PadLeft:itemStyle.clip.width;
    var itemHeight=(!NS4)?parseInt(itemStyle.height)+PadTop:itemStyle.clip.height;
    var CntnrWidth=(!NS4)?parseInt(CntnrStyle.width):CntnrStyle.clip.width;
    var CntnrHeight=(!NS4)?parseInt(CntnrStyle.height):CntnrStyle.clip.height;
    var SubTp,SubLt;
    posLevel++;
    if (posLevel==1 && fullPage)(!isVertical)?Tp=winheight-CntnrHeight+((NS4)?4:0):Lt=winwidth-CntnrWidth;
    if (posLevel==2 && fullPage)(!isVertical)?Tp=0:Lt=0;
    if (posLevel==2 && fullPage) {
	Tp+=VerCorrect;
	Lt+=HorCorrect;
    }
    CntnrStyle.top=Cntnr.OrgTop=Tp;
    CntnrStyle.left=Cntnr.OrgLeft=Lt;
    if (posLevel==1 && isHorizontal) {
	Hori=1; 
	Lefti=CntnrWidth-itemWidth-2*BorderWidth;
	Topi=0;
    }
    else {
 	Hori=Lefti=0; 
	Topi=CntnrHeight-itemHeight-2*BorderWidth;
    }
    while(item!=null){
	PadLeft=(item.value.indexOf('<')==-1)?LeftExtra:0;
	PadTop=(item.value.indexOf('<')==-1)?TopExtra:0;
	itemStyle=(!NS4)?item.style:item;
	itemWidth=(!NS4)?parseInt(itemStyle.width)+PadLeft:itemStyle.clip.width;
	itemHeight=(!NS4)?parseInt(itemStyle.height)+PadTop:itemStyle.clip.height;
	itemStyle=(!NS4)?item.style:item;
	itemStyle.left=Lefti+BorderWidth;
	itemStyle.top=Topi+BorderWidth;
	if(NS4)
	    item.CmdLyr.moveTo(Lefti+BorderWidth,Topi+BorderWidth);
	if(item.ChildCntnr) {
	    if(Hori) {
		SubTp=Tp+Topi+itemHeight+BorderWidth; 
		SubLt=Lt+Lefti;
	    }
	    else {
		SubLt=Lt+Lefti+(1-ChildOverlap)*itemWidth+BorderWidth; 
		SubTp=Tp+Topi+ChildVerticalOverlap*itemHeight;
	    }
	    menuPosition(item.ChildCntnr,SubTp,SubLt);
	}
	(Hori)?Lefti-=(BorderSpacing)?(itemWidth+BorderWidth):(itemWidth):Topi-=(BorderSpacing)?(itemHeight+BorderWidth):(itemHeight);
	item=item.PrevItem;
    }
    posLevel--;
}

function Initiate() {
    if(iFlag) 
	Init(fCol);
}

function Init(CntnrPntr) {
    var ItemContainer=CntnrPntr;
    var Item=ItemContainer.FirstItem;
    var MCStyle=(NS4)?ItemContainer:ItemContainer.style;
    initLevel++;
    MCStyle.visibility=(initLevel==1)?showIt:hideIt;
    while(Item!=null) {
	if(Item.ChildCntnr) Init(Item.ChildCntnr);
	    Item=Item.PrevItem;
    }
    initLevel--;
}

function hideChild(Pntr,ChldPntr) {
    var CPCCStyle;
    while (Pntr) {
	if(Pntr.ChildCntnr) {
	     CPCCStyle=(NS4)?Pntr.ChildCntnr:Pntr.ChildCntnr.style;
	     if(Pntr.ChildCntnr!=ChldPntr)CPCCStyle.visibility=hideIt;
		 hideChild(Pntr.ChildCntnr.FirstItem,ChldPntr)
	}
	Pntr=Pntr.PrevItem;
    }
}	

function GoTo() {
    if(this.LinkTxt) {
	if(NS4) {
	    if(this.LowLyr.value.indexOf('<IMG')==-1) {
		this.LowLyr.bgColor=this.LowLyr.LowBack;
		this.LowLyr.document.write(this.LowLyr.value);
		this.LowLyr.document.close();
	    }
	}
	else {
	    this.style.backgroundColor=this.LowBack;
	    this.style.color=this.LowFontColor;
	}
	(this.LinkTxt.indexOf('javascript:')!=-1)?eval(this.LinkTxt):DLoc.location.href=this.LinkTxt;
    }
}

function makeMenu() {
    if(!Loaded||!Created) 
	return;
    var TopScrolled=(fullPage)?(isIE)?SLoc.document.body.scrollTop:SLoc.pageYOffset:0;
    var LeftScrolled=(fullPage)?(isIE)?SLoc.document.body.scrollLeft:SLoc.pageXOffset:0;
    var ChildCont=(NS4)?this.LowLyr.ChildCntnr:this.ChildCntnr;
    var ThisHeight=(NS4)?this.clip.height:parseInt(this.style.height);
    var ThisWidth=(NS4)?this.clip.width:parseInt(this.style.width);
    CurrentOver=this; 
    iFlag=0;
    if(sFlag) {
	hideChild(this.Container.FirstItem,ChildCont); 
	if(this.Level==1) 
	    sFlag=0;
    }
    if(NS4) {
	if(this.LowLyr.value.indexOf('<IMG')==-1) {
	    this.LowLyr.bgColor=this.LowLyr.HighBack;
	    this.LowLyr.document.write(this.LowLyr.Overvalue);
	    this.LowLyr.document.close();
	}
    }
    else {
	this.style.backgroundColor=this.HighBack;
	this.style.color=this.HighFontColor;
    }
    if(ChildCont!=null)	{
	var ChildContWidth=(NS4)?this.LowLyr.ChildCntnr.clip.width:parseInt(this.ChildCntnr.style.width);
	var ChildContHeight=(NS4)?this.LowLyr.ChildCntnr.clip.height:parseInt(this.ChildCntnr.style.height);
	var ChCntTL=(NS4)?this.LowLyr.ChildCntnr:this.ChildCntnr.style;
	var SubLt=ChildCont.OrgLeft+LeftScrolled;
	var SubTp=ChildCont.OrgTop+TopScrolled;
	while(SubLt+ChildContWidth>childwinwidth+LeftScrolled) {
	    if(this.Level==1)
		SubLt=childwinwidth+LeftScrolled-ChildContWidth;
	    else SubLt-=10;
	}
	while(SubTp+ChildContHeight>TopScrolled+childwinheight) {
	    if(this.Level==1)
		SubTp=TopScrolled+childwinheight-ChildContHeight;
	    else SubTp-=10;
	}
	ChCntTL.top=SubTp;
	ChCntTL.left=SubLt;
	ChCntTL.visibility=showIt;
	sFlag=1;
    }
}	

function CloseMenu() {
    if(!Loaded||!Created)
	return;
    if(NS4) {
	if(this.LowLyr.value.indexOf('<img')==-1) {
	    this.LowLyr.bgColor=this.LowLyr.LowBack;
	    this.LowLyr.document.write(this.LowLyr.value);
	    this.LowLyr.document.close();
 	}
    }
    else {
	this.style.backgroundColor=this.LowBack;
	this.style.color=this.LowFontColor;
    }
    if(this==CurrentOver) {
	iFlag=1;
	if (CloseTimer)
	    clearTimeout(CloseTimer);
	    CloseTimer=setTimeout('Initiate(CurrentOver)',500);
    }
}

function menuSetup(Wdth,Hght,NoOff) {
    this.FirstItem=null;
    this.OrgLeft=0;
    this.OrgTop=0;
    if (createLevel==1&&isHorizontal) {
	Wdth=(BorderSpacing)?NoOff*(Wdth+BorderWidth)+BorderWidth:NoOff*Wdth+2*BorderWidth;
	Hght+=2*BorderWidth;
    }
    else {
	Hght=(BorderSpacing)?NoOff*(Hght+BorderWidth)+BorderWidth:NoOff*Hght+2*BorderWidth;
	Wdth+=2*BorderWidth;
    }
    if(NS4) {
	this.visibility='hide';
	this.bgColor=BorderColor;
	this.resizeTo(Wdth,Hght);
    }
    else {
	this.Level=createLevel;
	this.style.backgroundColor=BorderColor;
	this.style.width=Wdth;
	this.style.height=Hght;
	this.style.fontFamily=FontFamily;
	this.style.fontWeight=(FontBold)?'bold':'normal';
	this.style.fontStyle=(FontItalic)?'italic':'normal';
	this.style.fontSize=FontSize+'pt';
	this.style.zIndex=createLevel+Ztop;
    }
}

function ItemSetUp(itemCntnr,Pritem,WhatMenu,Wdth,Hght) {
    var Location=(createLevel==1)?FLoc:SLoc;
    var htmlStr=eval(WhatMenu+'[0]');
    var t,T,L,W,H,S;
    this.value=htmlStr;
    this.ChildCntnr=null;
    this.PrevItem=Pritem;
    this.Level=createLevel;
    this.LinkTxt=eval(WhatMenu+'[1]');
    this.Container=itemCntnr;
    this.style.cursor='default';
    if(htmlStr.indexOf('<')==-1) {
	this.style.width=Wdth-LeftExtra; 
	this.style.height=Hght-TopExtra; 
	this.style.paddingLeft=LeftPaddng; 
	this.style.paddingTop=TopPaddng;
    }
    else {
	this.style.width=Wdth; 
	this.style.height=Hght;
    }
    this.style.overflow='hidden';
    this.LowBack=LowBgColor;
    this.LowFontColor=FontLowColor;
    this.HighBack=(htmlStr.indexOf('<img')==-1)?HighBgColor:LowBgColor;
    this.HighFontColor=(htmlStr.indexOf('<img')==-1)?FontHighColor:FontLowColor; 
    this.style.color=this.LowFontColor;
    this.style.backgroundColor=this.LowBack;
    if(TextCentered)
	this.style.textAlign='center';
    if(htmlStr.indexOf('<')==-1&&isDom) {
	t=Location.document.createTextNode(htmlStr);
	this.appendChild(t);
    }
    else 
	this.innerHTML=htmlStr;
    if(htmlStr.indexOf('<img')==-1&&eval(WhatMenu+'[2]')) {
	S=(createLevel==1&&isHorizontal)?'images/tridown.gif':'images/tri.gif';
	W=(createLevel==1&&isHorizontal)?10:5;
	H=(createLevel==1&&isHorizontal)?5:10;
	T=(createLevel==1&&isHorizontal)?Hght-7:Hght/2-5;
	L=(createLevel==1&&isHorizontal)?Wdth-12:Wdth-7;
	if(isDom) {
	    t=Location.document.createElement('img');
	    this.appendChild(t);
	    t.style.position='absolute';
	    t.src=S;
	    t.style.width=W;
	    t.style.height=H; 
	    t.style.top=T; 
	    t.style.left=L;
	}
	else {
	    htmlStr+="<div style='position:absolute; top:"+T+"; left:"+L+"; width:"+W+"; height:"+H+";visibility:inherit'><img src='"+S+"'></div>"; 
	    this.innerHTML=htmlStr;
	}
    }
    if(isIE) {
	this.onmouseover=makeMenu; 
	this.onmouseout=CloseMenu; 
	this.onclick=GoTo;
    }
    else {
 	this.addEventListener('mouseover',makeMenu,false); 
	this.addEventListener('mouseout',CloseMenu,false); 
	this.addEventListener('click',GoTo,false);
    }
}

function itemSetup(itemCntnr,Pritem,WhatMenu,Wdth,Hght) {
    this.value=eval(WhatMenu+'[0]');
    if(LeftPaddng&&this.value.indexOf('<')==-1&&!TextCentered)
 	this.value='&nbsp\;'+this.value;
    if(FontBold)
	this.value=this.value.bold();
    if(FontItalic)
	this.value=this.value.italics();
	this.Overvalue=this.value;
	this.value=this.value.fontcolor(FontLowColor);
	this.Overvalue=this.Overvalue.fontcolor(FontHighColor);
	this.value=CenterText+"<font face='"+FontFamily+"' point-size='"+FontSize+"' color='"+FontLowColor+"'>"+this.value+TxtClose;
	this.Overvalue=CenterText+"<font face='"+FontFamily+"' point-size='"+FontSize+"' color='"+FontHighColor+"'>"+this.Overvalue+TxtClose;
	this.LowBack=LowBgColor;
	this.HighBack=HighBgColor;
	this.visibility='inherit';
	this.ChildCntnr=null;
	this.PrevItem=Pritem;
	this.bgColor=LowBgColor;
	this.resizeTo(Wdth,Hght);
	this.document.write(this.value);
	this.document.close();
	this.CmdLyr=new Layer(Wdth,itemCntnr);
	this.CmdLyr.visibility='inherit';
	this.CmdLyr.Level=createLevel;
	this.CmdLyr.LinkTxt=eval(WhatMenu+'[1]');
	this.CmdLyr.onmouseover=makeMenu;
	this.CmdLyr.onmouseout=CloseMenu;
	this.CmdLyr.captureEvents(Event.MOUSEUP);
	this.CmdLyr.onmouseup=GoTo;
	this.CmdLyr.LowLyr=this;
	this.CmdLyr.Container=itemCntnr;
	this.CmdLyr.resizeTo(Wdth,Hght);
    if(this.value.indexOf('<img')==-1 &&eval(WhatMenu+'[2]')){
	this.CmdLyr.ImgLyr=new Layer(10,this.CmdLyr);
	this.CmdLyr.ImgLyr.visibility='inherit';
	this.CmdLyr.ImgLyr.top=(createLevel==1&&isHorizontal)?Hght-7:Hght/2-5;
	this.CmdLyr.ImgLyr.left=(createLevel==1&&isHorizontal)?Wdth-12:Wdth-7;
	this.CmdLyr.ImgLyr.width=(createLevel==1&&isHorizontal)?10:5;
	this.CmdLyr.ImgLyr.height=(createLevel==1&&isHorizontal)?5:10;
	ImgStr=(createLevel==1&&isHorizontal)?"<img src='tridown.gif'>":"<img src='tri.gif'>";
	this.CmdLyr.ImgLyr.document.write(ImgStr);
	this.CmdLyr.ImgLyr.document.close();
    }
}

function createMenu(MenuName,ind) {
    createLevel++;
    var i,subItem,Item;
    var pItem=null;
    var WhichMenu=MenuName+'1';
    var MenuHeight=eval(WhichMenu+'[3]');
    var MenuWidth=eval(WhichMenu+'[4]');
    var Location=(createLevel==1)?FLoc:SLoc;
    if(isDom) {
	var ItemContainer=Location.document.createElement("DIV");
	ItemContainer.style.position='absolute';
	ItemContainer.style.visibility='hidden';
	Location.document.body.appendChild(ItemContainer);
    }
    else if(NS4) 
    	var ItemContainer=new Layer(MenuWidth,Location);
    else {
 	WhichMenu+='c';
	Location.document.body.insertAdjacentHTML("AfterBegin","<div id='"+WhichMenu+"' style='visibility:hidden; position:absolute;'><\/div>"); 
	var ItemContainer=Location.document.all[WhichMenu];
    }
    ItemContainer.SetUp=menuSetup;
    ItemContainer.SetUp(MenuWidth,MenuHeight,ind);
    if(IE4) {
	ItemContainer.InnerString='';
	for(i=1;i<ind+1;i++) {
	    WhichMenu=MenuName+eval(i);
	    subItem=eval(WhichMenu+'[2]');
	    ItemContainer.InnerString+="<div id='"+WhichMenu+"' style='position:absolute;'><\/div>";
	}
	ItemContainer.innerHTML=ItemContainer.InnerString;
    }
    for(i=1;i<ind+1;i++) {
	WhichMenu=MenuName+eval(i);
	subItem=eval(WhichMenu+'[2]');
	if(isDom) {
	    Item=Location.document.createElement("div");
	    Item.style.position='absolute';
	    Item.style.visibility='inherit';
	    ItemContainer.appendChild(Item);
	    Item.SetUp=ItemSetUp;
	}
	else if(NS4) {
	    Item=new Layer(MenuWidth,ItemContainer);
	    Item.SetUp=itemSetup;
	}
	else {
	    Item=Location.document.all[WhichMenu];
	    Item.SetUp=ItemSetUp;
	}
	Item.SetUp(ItemContainer,pItem,WhichMenu,MenuWidth,MenuHeight);
    	if(subItem) 
    	    Item.ChildCntnr=createMenu(WhichMenu+'_',subItem);
    	    pItem=Item;
    }
    ItemContainer.FirstItem=Item;
    createLevel--;
    return(ItemContainer);
}

function recreateMenu(MenuName,ind) {
    var i,WhichMenu,subItem;
    var pItem,Item=fCol.FirstItem;
    createLevel++;
    for(i=ind;i>0;i--) {
 	WhichMenu=MenuName+eval(i);
	subItem=eval(WhichMenu+'[2]');
	pItem=Item;
	if(subItem) 
	Item.ChildCntnr=createMenu(WhichMenu+'_',subItem);
	Item=Item.PrevItem;
    }
    createLevel--;
}