// Global Variables;
   var isNS4 = false;
   var isIE4 = false;


function FrameMenu(tName)
{// Constructor for FrameMenu Object
 	this.Name=tName;
	this.Title="";
	this.Width=100;
	this.BackColor="#C0C0C0";
	this.BorderLightColor="#FFFFFF";
	this.BorderDarkColor="808080";
	this.MenuItems= new Array();
	this.MenuCount=0;
 // Set member functions
	this.Init=FrameMenu_Init;
	this.AddItem=FrameMenu_AddItem;
	this.Draw=FrameMenu_Draw;
	this.GetMenuText=FrameMenu_GetMenuText;
	this.Click=FrameMenu_Click;
}
	

function FrameMenu_Init()
{// Initialise a FrameMenu
 	isNS4 = (document.layers)? true:false;
 	isIE4 = (document.all)? true:false;
	
	if (isNS4)
	   {document.writeln("<LAYER id='divFM_"+this.Name+"'>");
	    document.writeln(this.GetMenuText(-1));
		document.writeln("</LAYER>");
	   }
	else if (isIE4)
	   {document.writeln("<DIV id='divFM_"+this.Name+"'>");
	    document.writeln(this.GetMenuText(-1));
		document.writeln("</DIV>");
	   }
}

function FrameMenu_AddItem(tCaption, tRef, tFrame, tLevel)
{// Add an Item to the FrameMenu
	this.MenuItems[this.MenuCount] = new Array("", "", 0, 0);
	this.MenuItems[this.MenuCount]["Caption"]=tCaption;
	this.MenuItems[this.MenuCount]["Ref"]=tRef;
	this.MenuItems[this.MenuCount]["Frame"]=tFrame;
	this.MenuItems[this.MenuCount]["Level"]=tLevel;
	this.MenuItems[this.MenuCount]["QExpand"]=false;
	this.MenuCount++;
}

function FrameMenu_GetMenuText(ClickedIndex)
{// Work out the Menu text
	var NewText=""
	if (isIE4)
	   {NewText = "<font face='Arial'><table border='0' width='" + this.Width + "' cellpadding='1' cellspacing='0' bgcolor='"+this.BackColor+"'>"
			+ "<TR><TD colspan=2 bgcolor='"+this.BackColor+"'>"
			+ "<font size='2'><strong>" + this.Title+ "</strong></font>"
			+ "</TD></TR>"
	     	+ "</TABLE></font>";
			
    	for (var i=0; i<this.MenuCount; i++)
			{if (this.MenuItems[i]["Level"]==1)
	    		{// New Menu Table
				 NewText = NewText + "<font face='Arial'><table border='1' width='" + this.Width + "' cellpadding='1' cellspacing='0' bgcolor='"+this.BackColor+"' bordercolor='"+this.BackColor+"' bordercolordark='"+this.BackColor+"' bordercolorlight='"+this.BackColor+"'>"
				 		 + "<TR><TD colspan=2 bgcolor='"+this.BackColor+"' bordercolordark='"+this.BorderDarkColor+"' bordercolorlight='"+this.BorderLightColor+"'>"
						 + "<font size='2'><a "
						 + "href = '" + this.MenuItems[i]["Ref"] + "' "
						 + "onclick = 'javascript:" + this.Name + ".Draw(" + i + ");' "
						 + "target = '" + this.MenuItems[i]["Frame"] + "' "
						 + ">" +  this.MenuItems[i]["Caption"] + "</a>";
						 + "</font></TD></TR>";
        		 if (i==ClickedIndex && this.MenuItems[i]["QExpand"]==false)
			   		{// Expand sub-items
			   	   	 this.MenuItems[i]["QExpand"]=true;
				   	 while (i<this.MenuCount-1 && this.MenuItems[i+1]["Level"]==2)
				   		 {i++;
						  NewText = NewText + "<TR><TD><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;</font></TD><TD bgcolor='"+this.BackColor+"' bordercolordark='"+this.BorderDarkColor+"' bordercolorlight='"+this.BorderLightColor+"'>"
						  		  + "<font size='1'><a "
								  + "href = '" + this.MenuItems[i]["Ref"] + "' "
								  + "target = '" + this.MenuItems[i]["Frame"] + "' "
								  + ">"	+  this.MenuItems[i]["Caption"] + "</a>"
								  + "</font></TD></TR>"
						 }
					}
				else
			    	{// Collapse Sub-Items
					 this.MenuItems[i]["QExpand"]=false;
					}
				NewText = NewText + "</TABLE></font>"
	    	   }
		  }
	  }
	else if (isNS4)
	   {NewText = "<table border='0' width='" + this.Width + "' cellpadding='1' cellspacing='0' bgcolor='"+this.BackColor+"'>"
			+ "<TR><TD colspan=2 bgcolor='"+this.BackColor+"'>"
			+ "<font size='2'><strong>" + this.Title+ "</strong></font>"
			+ "</TD></TR>"
	     	+ "</TABLE>";
			
    	for (var i=0; i<this.MenuCount; i++)
			{if (this.MenuItems[i]["Level"]==1)
	    		{// New Menu Table
				 NewText = NewText + "<table border='1' width='" + this.Width + "' cellpadding='1' cellspacing='0' bgcolor='"+this.BackColor+"'>"
				 		 + "<TR><TD colspan=2 bgcolor='"+this.BackColor+"'>"
						 + "<font size='2'><a "
						 + "href = 'javascript:" + this.Name + ".Click(" + i + ");' "
						 + ">" +  this.MenuItems[i]["Caption"] + "</a>";
						 + "</font></TD></TR>";
        		 if (i==ClickedIndex && this.MenuItems[i]["QExpand"]==false)
			   		{// Expand sub-items
			   	   	 this.MenuItems[i]["QExpand"]=true;
				   	 while (i<this.MenuCount-1 && this.MenuItems[i+1]["Level"]==2)
				   		 {i++;
						  NewText = NewText + "<TR><TD><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;</font></TD><TD bgcolor='"+this.BackColor+"' bordercolordark='"+this.BorderDarkColor+"' bordercolorlight='"+this.BorderLightColor+"'>"
						  		  + "<font size='1'><a "
								  + "href = '" + this.MenuItems[i]["Ref"] + "' "
								  + "target = '" + this.MenuItems[i]["Frame"] + "' "
								  + ">"	+  this.MenuItems[i]["Caption"] + "</a>"
								  + "</font></TD></TR>"
						 }
					}
				else
			    	{// Collapse Sub-Items
					 this.MenuItems[i]["QExpand"]=false;
					}
				NewText = NewText + "</TABLE>"
	    	   }
		  }
	  }
	
	
	return NewText;
}

function FrameMenu_Click(ClickedIndex)
{top.frames[this.MenuItems[ClickedIndex]["Frame"]].location = this.MenuItems[ClickedIndex]["Ref"];
 this.Draw(ClickedIndex);
}



function FrameMenu_Draw(ClickedIndex)
{// Redraw the menu
	if (isNS4)
	   {document.layers["divFM_"+this.Name].document.open();
		document.layers["divFM_"+this.Name].document.write(this.GetMenuText(ClickedIndex));
	 	document.layers["divFM_"+this.Name].document.close();
	   }
    else if (isIE4)
	   {
		document.all["divFM_"+this.Name].innerHTML = this.GetMenuText(ClickedIndex);
	   }

}


