//JavaScript source for VECC

//Simple Browser check
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

//Menu Hack for IE5+ - doesn't support hover on all elements 
function sfHover() 
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) 
	{
		sfEls[i].onmouseover=function() 
		{
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() 
		{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

//Constructor for a menu Item
function Item(text, href, submenu, isDBOption)
{
   	this.text = text;
   	this.href = href;
   	this.submenu = submenu;
	this.isDBOption = isDBOption;
   	// Reference to the object's style properties (set later).
   	this.ref = null;
}

//Recursively called function to build the nested menu lists
function BuildMenu(currMenu)
{
	var strHTML = '';
	
	var currItem;
	//alert('Build Menu : Length:' + menu[currMenu].length);
	for (currItem = 0; currItem < menu[currMenu].length; currItem++)
	{
		with (menu[currMenu][currItem])
            {
			//Start the link item
			strHTML = strHTML + '<li>';
			//Add the anchor - we always have an anchor even if there's no link
			strHTML = strHTML + '<a '; 
			if(text == 'Help')
			{
				strHTML = strHTML + ' target="_blank" ';
			}
			//Only put a ref if needed
			if(href != 'noref')
			{
				//Check if the href is a full path or just within our site.
				if(href.substr(0,7).toLowerCase() == 'http://')
            	{
					//If its an external site open it in a new window.
					strHTML = strHTML + 'href="' + href + '" target="_blank" ';
            	}
            	else
            	{
			    	strHTML = strHTML + 'href="'  + pageRoot + href + '" ';
            	}
				
			}
			strHTML = strHTML + '>'
			//Add the lock icon if needed 
			if(isDBOption==1)
			{
				strHTML = strHTML + '<img src="' + pageRoot + 'graphics/nav_lock.gif" border="0" hspace="2" width="15" height="15" />';
			}
			//Now the text
			strHTML = strHTML + text;
			strHTML = strHTML  + '</a>';

			//alert('Build Menu: html: ' + strHTML);
			if(submenu > 0)
			{
				//Whoops a bit of recursion here ... 
				strHTML = strHTML + '<ul>' + BuildMenu(submenu) + '</ul>';
			}
			strHTML = strHTML + '</li>';
		}
	}
	//alert('BuildMenu: ' + strHTML);
	return strHTML;
}

//Main function to load the menus called in <body onLoad= >
function LoadMenus()
{
	//Most browsers are these days - do we care about older ones?
	if (isDOM)
	{
		var rootList = document.createElement('ul');
		rootList.id = 'nav';
		document.getElementsByTagName('body').item(0).appendChild(rootList);
		rootList.innerHTML = BuildMenu(0);
	}
				
	//A vain attempt to get NS4 to play with the menu stuff
	if (isNS4)
	{
		//alert('NS4 may not display correctly');
		var ref = new Layer(6);
		var str = '<ul id="nav">' + BuildMenu(0) + '</ul>';
		//alert(str);
        ref.document.write(str);
        ref.document.close();
	}
	if (isIE4)
	{
		alert('IE earlier versions may not display correctly');
	}
}
