// Configuration items
selectedImage = "newimages/arrow.gif";

var gSec=-1;
var gSubSec=-1;

tab="&nbsp;&nbsp;&nbsp;";
tab2=tab+tab;
tab3=tab2+tab;
tab4=tab3+tab;

var popUpWin
function popup(url) {
	popUpWin=window.open(url,"popUpWin");
	setTimeout("popUpWin.focus()",200);
//'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450'
}

function handleDropDownNav() {
	selInd = document.ddown_nav.nav_dropdown.selectedIndex;
	document.location = document.ddown_nav.nav_dropdown.options[selInd].value;
//document.location = document.forms['ddown_nav'].nav_dropdown.value;
}

function getPageName(path) {
	return path.substring(path.lastIndexOf("/")+1, path.length);
}

function searchArray(arr, name) {
	for(z=0; z < arr.length; z++) {
		if( (arr[z][1] != null) && 
		    (arr[z][1] == name) ) {
			return z;
		}
	}
	return -1;
}

function getSectionInfo() {
	// get the current HTML page name
	str=new String(window.location);
	pageName = getPageName(str);

	// check globals for page name
	ret = searchArray(globals, pageName);
	// if found current page
	if( ret != -1 ) {
		gSec = ret;
		return 0;
	}
	//check subsections for page name
	for(y=0; y < subs.length; y++) {
		ret = searchArray(subs[y], pageName);
		if( ret != -1 ) {
			gSec = y;
			gSubSec = ret;
			return 0;
		}
	}
	return -1;
}

function displayMenu(navNumber) {
	//determine section & subsection
	getSectionInfo();
	str="";

	// Determine global index range
	endIndex = navEndIndex[navNumber];
	if( navNumber == 0 ) {
		startIndex=0;
	} else {
		startIndex = navEndIndex[navNumber-1] + 1;
	}
	// for each global link in the specified navNumber
	for(x=startIndex; x <= endIndex; x++) {

		// If in the current section
		if( x == gSec ) {
			// global nav visited link
			if( gSubSec == -1 ) {
				// no selected subsection
str += tab + "<img src=\"newimages/" + globals[x][IMAGE] + "_red.gif\"><br>";
			} else { 
				// a subsection has been selected
str += tab + "<a href=\""+ globals[x][PAGE] + "\"><img src=\"newimages/" + globals[x][IMAGE] + "_red.gif\" border=\"0\"></a><br>";
			}
			// If the subsection has links
			if( subs[x] != null ) {
				// For each subsection link
				for(y=0; y < subs[x].length; y++) {
					// if there is an element
					if( subs[x][y][0] != null) {
						// if is a Label
						if( subs[x][y][1] == null) {
							str += tab2 + "<span class=\"subnav_label\">" + subs[x][y][0] + "</span><br>";
						} else {
							// if is the selected subSection
							if(y == gSubSec) {
str += tab2 + "<img src=\"" + selectedImage + "\" width=\"11\" height=\"11\"><span class=\"selected_subnav\">" + subs[x][y][0] + "</span><br>";
							} else {
								// just a link
str += tab3 +"<a href=\"" + subs[x][y][1] + "\" class=\"subnav\">" + subs[x][y][0] + "</a><br>";
							}
						}
					}
				}
			}
		} else {
			// global nav link
str += tab + "<a href=\""+ globals[x][PAGE] + "\"><img border=0 src=\"newimages/" + globals[x][IMAGE] + "_blue.gif\"></a><br>";
		}
	}
	
	document.write(str);
}

function generateDropDown()
{
	str="<select name=\"nav_dropdown\" onchange=\"handleDropDownNav()\">";
	str += "<option selected value=\"Jump To\">--- Jump To ---</option>";
	for(x=0; x < dropdownLastIndex; x++)
	{
//str += "<optgroup label=\"" + globals[x][0] + "\">";
	   str += "<option value=\"" + globals[x][PAGE] + "\">" + globals[x][TEXT] + "</option>";

	   // If the subsection has links
	   if( subs[x] != null ) 
	   {
		// For each subsection link
		for(y=0; y < subs[x].length; y++)
		{
			// if there is an element
			if( subs[x][y][0] != null)
			{
//Need to deal with the labels!!
				// if is a Label
				if( subs[x][y][1] == null)
				{
					//str += "<optgroup label=\"" + subs[x][y][TEXT] + "\">";
				}
				else // just a link
				{
					str += "<option value=\"" + subs[x][y][PAGE] + "\">--> " + subs[x][y][TEXT] + "</option>";
				}
			}
		}
//str += "</optgroup>";
	   }
	}
	str+="</select>";
//alert(str);
	document.write(str);
}
