// this contains all of the script functions to create a menubar.

// new function sjowDV()
function showDIV(szDivID){
// this function will take and array of DivID's and 
// set sxDivID to be visible and display to inline
// all other DivID's will be set hidden and none
// now free to do work
//first define the array
var arraysize = Top_Menu.size;
// add 2 additional elements to array item for Top_Menu and no_beans
arraysize = arraysize + 3;
// set default to hide
var showHide = 0;
// create the array of DivID's
var DivID = [arraysize];
// set next to last element in array to no_beans
DivID[arraysize-2] = "Top_Menu";
// set next to last element in array to no_beans
DivID[arraysize-1] = "no_beans";
// now set up the other elements in the array
for (divcount = 0; divcount < Top_Menu.size; divcount++)
	{div_offset = divcount+1;
	DivID[div_offset] = Top_Menu["menu" + div_offset].name;
	}
// first, show selected DivID
toggleBox(szDivID, 1);
toggleDisplay(szDivID,1);
// now turn everything else off
for (i=1; i < arraysize; i++) {
//find the entry in the table
if(DivID[i] != szDivID) {toggleBox(DivID[i], showHide);
						toggleDisplay(DivID[i], showHide);
						}
}
return;
}

// ---- new function toggleDisplay()
function toggleDisplay(szDivID, iState) {
// this function will change the display attribute of a Div class
// to either show inline or block the div.
// it attempts to be browser independent
// input sxDivId is the DivId that is to be manupulated
// input iState = 0 for None or 1 for Inline
if(document.layers)    //NN4+
    {
       document.layers[szDivID].display = iState ? "inline" : "none";
    }
    else if(document.getElementById)      //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.display = iState ? "inline" : "none";
    }
    else if(document.all)       // IE 4
    {
        document.all[szDivID].style.display = iState ? "inline" : "none";
    }
return;
}

// ---- new function toggleBox()
function toggleBox(szDivID, iState) {
// this function will change the visibility attribute of a Div class
// to either show or hide the div.
// it attempts to be browser independent
// input sxDivId is the DivId that is to be manupulated
// input iState = 0 for Hide/Hidden or 1 for show/visible

if(document.layers)    //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)      //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)       // IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
return;
}

//New Function selectclassSuffix()
function selectclassSuffix(Top_Menu_Level, createdMenu, cellContents) {
// this function will select the navTable class based upon the state of the menu selection and cell contents
// if the menu being created us the same as the Top_menu_level from createMenu
// if the cell contains valid text
// this routine will select the nav class to be navtable_select
// otherwise it will select the nav class to be navtable
// if the cell does not contain valid text, the nav class will be set to navtable_empty
var undefined_variable;
if(cellContents === undefined_variable) {return("_empty");} // cell is empty
if(Top_Menu_Level == createdMenu) {return("_select");}
return("");
}

//New Function findFileName()
function findFilename(tr){
// this function will return the file name of a file url
// if the input tr is undefined, it will look fr the file name in the current URL

if(typeof tr == "undefined"){tr = window.location.pathname;}
//if(tr === undefined){tr = window.location.pathname;}
len = tr.length; 
rs = 0;
for (i = len; i > 0; i--) { 
vb = tr.substring(i,i+1); 
if (vb == "/" && rs == 0) { 
return(tr.substring(i+1,len)); 
rs = 1 ;
} 
} 
return(null);
}

// new function scanTop_MenuObject(match_Object, object_item) 
function scanTop_MenuObject(match_object) {
// this function will scan the Top_Menu to determine is a "match_object" exists
// in an "object_item" defined in the "scanned_object"
// this function will return the found_object which is a number represent the offset for object_item
var found_object = 0;
for(i = 0; i < Top_Menu.size; i++) {
	scanned_object_offset = i + 1;
	if(Top_Menu["menu" + scanned_object_offset].name == match_object)
		{ found_object = scanned_object_offset;
		}
}
return(found_object);
}


//New Function createTop_Menu(Top_Menu_level, url_adjust) ---
function createTop_Menu(Top_Menu_level, url_adjust) {
// this function will create the Top Menu
// the output will be a string containing HTML in table format
// Top_Menu_Level represents the selected level of Top_Menu to Highlight

// now begin construction of Top_Menu
var Atagpresent = false;
var url_adjustor = "";
var Top_Menu_buffer = "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr align='center' valign='middle'>";
// now calculate cell spacing
var cellSpace = 0;
var cellContents = "";
var undefined_variable;
var Top_Menu_cellSpace = Math.round(100/Top_Menu.size);
var Top_Menu_cellSpace_adjust = 100 - (Top_Menu.size * Top_Menu_cellSpace);
var classSuffix = "";
// now set up the loop to create the table
for (menu_loop = 0; menu_loop < Top_Menu.size; menu_loop++)
	{menu_offset = menu_loop + 1;
	// first compute cell space
	cellSpace = Top_Menu_cellSpace;
	// correct for rounding of last cell
	if(menu_offset == Top_Menu.size)
		{cellSpace = Top_Menu_cellSpace + Top_Menu_cellSpace_adjust;
		}
	// now set up table element

// define the class suffix
	classSuffix = selectclassSuffix(Top_Menu_level, Top_Menu["menu" + menu_offset].name, Top_Menu["cell" +menu_offset]);
	Top_Menu_buffer = Top_Menu_buffer + '<td class="navtable' + classSuffix + '" width="' + cellSpace + '%">';
		
	// reset noAtag
	Atagpresent = false;	
	// now create cell elements  first check to see if the cell exists
	if(Top_Menu["cell" +menu_offset] === undefined_variable) 
		{cellContents = " ";}
	else {
	cellContents = '<span class="navbar'+ classSuffix + '">'+Top_Menu["cell" +menu_offset] + '</span>';
	
	// then check to see if we have a link or a rollover action
	if((Top_Menu["link" +menu_offset] != "none") || (Top_Menu["mover" +menu_offset] != "none"))
		{Atagpresent = true;
		Top_Menu_buffer = Top_Menu_buffer + '<a';
			if(Top_Menu["link" +menu_offset] != "none")
			// now check to see if the link is relative, or if it is to another web site
				{url_adjustor = url_adjust;
				if(Top_Menu["link" +menu_offset].search(/www/i) == 0)
					{url_adjustor = "http://";
					}
				// now create link
				Top_Menu_buffer = Top_Menu_buffer + ' href="' + url_adjustor + Top_Menu["link" +menu_offset] + '" target="'+ Top_Menu["target" +menu_offset]+ '"';
				}
			if(Top_Menu["mover" +menu_offset] != "none")
				{Top_Menu_buffer = Top_Menu_buffer + ' onmouseover="' + Top_Menu["mover" +menu_offset] + '"';
				}
			Top_Menu_buffer = Top_Menu_buffer + '>';
		}
		}
	// now get the cell name and close out the cell
	Top_Menu_buffer = Top_Menu_buffer + cellContents;
	// now check to see if we created the A tag
	if(Atagpresent)
		{Top_Menu_buffer = Top_Menu_buffer + "</a>";
		}
	Top_Menu_buffer = Top_Menu_buffer + "</td>\r";
	}
// now end the row and table
Top_Menu_buffer =Top_Menu_buffer + "</tr></table>";
return(Top_Menu_buffer);
}

//New Function createMenu() ---
function createMenu(Top_Menu_level) {
// this function will create a multilevel menu from previously defined objects
// The primary object is called Top_Menu
// the input parameter, Top_Menu_level, describes the cell on Top Menu which should be active
// first, initialize the output_buffer
// create debug flag
var debug = false;
// now if debug - true, set all menus to be visible
var menuShow = "visibility: hidden; display: none";
if(debug) {menuShow = "visibility: visible; display: inline";}
var undefined_variable;
var output_buffer = "";

// first, identify the page that called this function
// to allow us to determine the level to use to establish html links.

var current_file_name = findFilename();
var link_pointer = 0;
var file_root_position = 0;
// first, are being called to create the 'Top_Menu"

if(Top_Menu_level != "Top_Menu")
	{// we are not being called to create the "Top_Menu"
	// are we being called by an object in the 'Top_Menu"?
	// now scan the "Top_Menu" object to determine what menu is being requested
	var Top_Menu_object_offset = scanTop_MenuObject(Top_Menu_level); 
	if(Top_Menu_object_offset != 0)
		{// the object has been found in the top menu array
		// now scan the object array to determine if the 
		// filename in the link object is the requesting file name
		// add http to "link" to create proper path to search
		if(current_file_name == findFilename("http://" + Top_Menu["link" + Top_Menu_object_offset]))
			{// we have found the file.  compute the link_pointer
			file_root_position = Top_Menu["link"+ Top_Menu_object_offset].split("/").length-1;
			}		
		else
			{
			// the file requesting the menu is not in the "Top_Menu" object.
			// look in the requesting object
			for(link_count = 0; link_count < Top_Menu["menu"+Top_Menu_object_offset].listsize; link_count++) 
				{
			// look through the Top_Menu_level object to determine which file is calling this menu
				link_count_offset = link_count +1;
				// add http to "link" to create proper path to search
				if(current_file_name == findFilename("http://" + Top_Menu["menu"+Top_Menu_object_offset]["link"+link_count_offset]))
					{// found the correct file name
					file_root_position = Top_Menu["menu"+Top_Menu_object_offset]["link"+link_count_offset].split("/").length-1;
					break;
					}
				}
			}
		}
	}

// now create URL adjust base on file_root_position
var url_adjust = "";
for (i = 0; i <file_root_position; i++)
	{url_adjust = url_adjust + "../";
	}

// now create the Division Styles for the elements in Top Menu and place in Output Buffer
var div_style_buffer = '<style type="text/css"><!--\r';
//  create Division Style specifically for Top_Menu
div_style_buffer = div_style_buffer + '#Top_Menu { visibility: visible; display: inline}\r';
for (divcount = 0; divcount < Top_Menu.size; divcount++)
	{div_offset = divcount + 1;
	div_style_buffer = div_style_buffer
					+	'#'
					+	Top_Menu["menu" + div_offset].name
					+	" { "
					+	menuShow
					+	' }\r';
	}
div_style_buffer = div_style_buffer + '--></style>\r';
// completed creating the division styles
output_buffer = output_buffer + div_style_buffer;

// now begin construction of Top_Menu
var Atagpresent = false;
var menu_buffer = "<div id='Top_Menu'>";
// Now construct Top_Menu with level set to Top_Menu and close out div
output_buffer = output_buffer + menu_buffer + createTop_Menu("Top_Menu", url_adjust) + "</div>\r";

// now create the rest of the Div's
// reset variables
menu_buffer = "";
var next_div_name = "";
var new_div_offset = 0;
var menu_cellSpace = 0;
var menu_cellSpace_adjust = 0;
var url_adjustor = "";
for(new_div_loop = 0; new_div_loop < Top_Menu.size; new_div_loop++)
	{new_div_offset = new_div_loop + 1;
	// Now create menu for div
	menu_buffer = "<div id='"
					+ Top_Menu["menu" + new_div_offset].name
					+ "'>";
	
	// Now add in the Top_Menu
	menu_buffer = menu_buffer + createTop_Menu(Top_Menu["menu" + new_div_offset].name, url_adjust);
	
	// now begin construction of Menu
	menu_buffer = menu_buffer + "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr align='center' valign='middle'>";
	Atagpresent = false;
	// now calculate cell spacing
	cellSpace = 0;
	menu_cellSpace = Math.round(100/Top_Menu["menu" + new_div_offset].size);
	menu_cellSpace_adjust = 100 - (Top_Menu["menu" + new_div_offset].size * menu_cellSpace);
	// now set up the loop to create the table
	for (menu_loop = 0; menu_loop < Top_Menu["menu" + new_div_offset].size; menu_loop++)
		{menu_offset = menu_loop + 1;
		// first compute cell space
		cellSpace = menu_cellSpace;
		// correct for rounding of last cell
		if(menu_offset == Top_Menu["menu" + new_div_offset].size)
			{cellSpace = menu_cellSpace + menu_cellSpace_adjust;
			}
		// now set up table element
		// define the class suffix
		classSuffix = selectclassSuffix(Top_Menu["menu" + new_div_offset].name, Top_Menu["menu" + new_div_offset].name, Top_Menu["menu" + new_div_offset]["cell" +menu_offset]);

		menu_buffer = menu_buffer + '<td class="navtable' + classSuffix + '" width="' + cellSpace + '%">'; //need to identify class

		// now create cell elements  first check to see if we have a link or a rollover action
		// reset noAtag
		Atagpresent = false;
		// now create cell elements  first check to see if the cell exists
		if(Top_Menu["menu" + new_div_offset]["cell" +menu_offset] === undefined_variable) 
			{cellContents = " ";}
		else {
		cellContents = '<span class="navbar' + classSuffix + '">'+ Top_Menu["menu" + new_div_offset]["cell" +menu_offset] + '</span>';
		if((Top_Menu["menu" + new_div_offset]["link" +menu_offset] != "none") || (Top_Menu["menu" + new_div_offset]["mover" +menu_offset] != "none"))
			{Atagpresent = "yes";
			menu_buffer = menu_buffer + '<a';
				if(Top_Menu["menu" + new_div_offset]["link" +menu_offset] != "none")
					{url_adjustor = url_adjust;
					if(Top_Menu["menu" + new_div_offset]["link" +menu_offset].search(/www/i) == 0)
						{url_adjustor = "http://";
						}
			// now create link
					menu_buffer = menu_buffer + ' href="' + url_adjustor + Top_Menu["menu" + new_div_offset]["link" +menu_offset] + '" target="' + Top_Menu["menu" + new_div_offset]["target" +menu_offset] + '"';
					}
				if(Top_Menu["menu" + new_div_offset]["mover" +menu_offset] != "none")
					{menu_buffer = menu_buffer + ' onmouseover="' + Top_Menu["menu" + new_div_offset]["mover" +menu_offset] + '"';
					}
				menu_buffer = menu_buffer + '>';
			}
			}
		// now get the cell name and close out the cell
		menu_buffer = menu_buffer + cellContents;
		// now check to see if we created the A tag
		if(Atagpresent)
			{menu_buffer = menu_buffer + "</a>";
			}
		menu_buffer = menu_buffer + "</td>\r";
		}
	// now end the row and table
	// finish menu by closing table and the div
	menu_buffer = menu_buffer + "</tr></table></div>\r";
	
	// now add completed div to output
	output_buffer = output_buffer +  menu_buffer;	
	}

document.write(output_buffer);
if(!debug){showDIV(Top_Menu_level);}
return;
}
