//Global Variables //
var top_dot1 = "/wavemaster.internal/v6.3/components/hslc_standardpage/img/hslic/top-dot1.gif";
var top_dot = "/wavemaster.internal/v6.3/components/hslc_standardpage/img/hslic/top-dot.gif";
var btm_dot = "/wavemaster.internal/v6.3/components/hslc_standardpage/img/hslic/btm-dot.gif";
var mid_dot = "/wavemaster.internal/v6.3/components/hslc_standardpage/img/hslic/mid-dot.gif";
var mid_dot3 = "/wavemaster.internal/v6.3/components/hslc_standardpage/img/hslic/mid-dot3.gif";
var arrow = "/wavemaster.internal/v6.3/components/hslc_standardpage/img/hslic/Right_7.gif";
var clear_space = "/wavemaster.internal/v6.3/components/hslc_standardpage/img/hslic/clearpixel.gif";
var clear_space_img = document.createElement("img");
clear_space_img.src = clear_space;
clear_space_img.setAttribute('width', 1);
clear_space_img.setAttribute('height', 1);
clear_space_img.setAttribute('alt', ' ');
var hslc_parentHierName;
var createdListing = false;
/** 
 * The level to which the rollout menu will display.  
 * usually 1 or 2.  0 turns the rollout completely off.
 */ 

//if (g_hiername.charAt(0) == '/') {
//	var urlArray = g_hiername.substring(1, g_hiername.length).split('/');
//} else {
//	var urlArray = g_hiername.split("/");
//}

var currentUrl = decodeURIComponent(window.location.pathname);
var urlAction = currentUrl.split(";");
var hslc_hiername = urlAction[0];
if (hslc_hiername.charAt(0) == '/') {
  	hslc_hiername = hslc_hiername.substring(1, hslc_hiername.length);
}
var lastSlash = hslc_hiername.lastIndexOf('/');
if (lastSlash == hslc_hiername.length - 1) {
  	hslc_hiername = hslc_hiername.substring(0, hslc_hiername.length - 1);
}
var urlArray = hslc_hiername.split("/");
if( documentType != "collection" ) {
	lastSlash = hslc_hiername.lastIndexOf('/');
	hslc_parentHierName = '/' + hslc_hiername.substring(0, lastSlash);
	/*
	if( hslc_hiername.lastIndexOf('.') == -1 ) {// looking at a multicluster document
		hslc_parentHierName = hslc_hiername;
	} else {
		lastSlash = hslc_hiername.lastIndexOf('/');
		hslc_parentHierName = '/' + hslc_hiername.substring(0, lastSlash);
	}
	*/
} else {
	hslc_parentHierName = hslc_hiername;
}
//alert("hslc_parentHierName: "+hslc_parentHierName);
/** global handle for the list of menu items generated under the navbar div. */
var navList = document.createElement('UL');
var hnavList = document.createElement('UL');
var footerDivs = ""
var leftNavPath = '';

var hasHwTopic = false;

var current_table = 'leftNav';

var first_ever = true;

var doneLvl3 = false;
/** 
 * the menu item that needs to be displayed first.  
 * This menu items is the branch that should be highlighted. 
 */
var firstMenuItem = null;
var closest = null;

// the link to topic, as a shortcut to go back to the topic level.
var topic_level_link = '';
// the width of each footer menu item
var footerColWidth = 0;

// --------------------------------------------------
// Entry point. 
// "structure" is a variable defined in structure.js, 
// which is updated periodically.
// --------------------------------------------------
function create_menu_structure() {
	if (structure == undefined) {
		//alert("structure is undefined");
		return;
	}
	if (structure_h == undefined) {
		//alert("structure_h is undefined");
		return;
	}
	//create_menu_quicklinks();
	var loc = "/" + hslc_hiername;
	firstMenuItem = findFirstItem(structure, loc, null);
	if (firstMenuItem == null) {
		//alert("no item needs to be displayed first");
		if (closest != null) {
			firstMenuItem = closest;
		}
	} else {
		//alert(firstMenuItem.location);
	}
	create_menu(structure);
	//create_h_menu(structure_h);
	if (!createdListing
			&& firstMenuItem == null
			&& closest == null) {
		firstMenuItem = findFirstItem(structure_h, loc, null);
		if (firstMenuItem == null) {
			if (closest != null) {
				firstMenuItem = closest;
			}
		}
		createHeaderNavListing(structure_h);
	}
	showAdjustFontIcons();
	// append to left menu div
	//var leftnavdiv = document.getElementById('navbar');
	//leftnavdiv.appendChild(navList);
	// append to header menu div
	//var headernavdiv = document.getElementById('hnav_1');
	//headernavdiv.appendChild(hnavList);
	// append to footer menu div
	//var footernavdiv = document.getElementById('foot_top');
	//footernavdiv.innerHTML = footerDivs;
}
function createHeaderNavListing(o) {
	if (!createdListing) {
		if (show_collectionhead(o)) {
			create_collectionhead(o.submenu);
		} else if (show_collectionhead_hslcchildren(o)) {
			create_collectionhead_hslcchildren(o, hslc_children);
		} else {
			for (var i = 0; i < o.submenu.length; i++) {
				createHeaderNavListing(o.submenu[i]);
			}
		}
	}
}
function showAdjustFontIcons() {
	//var loginbox = document.getElementById("hslc_adjustFontIcons");
	//loginbox.style.visibility = 'visible';
}

/**
 * Recursively searches for the first menu item to be displayed.
 * @param {Object} menu the menu structure.  starts at /hslc and works its way down
 * @param {String} requestLoc the request location, such as /hslc/ecdh/Health
 * @param {Object} branch, the current 1st-level menu branch being searched.
 * @return {Object} returns the 1st menu item to display, or null if none was found
 */
function findFirstItem(menu, requestLoc, branch) {
	var firstItem = null;
	for (var i = 0; i < menu.submenu.length; i++) {
		if (menu.submenu[i].location.toLowerCase() == requestLoc.toLowerCase()) { // we found our item
			//alert("at level "+menu.level+" "+menu.submenu[i].location.toLowerCase()+" == "+requestLoc.toLowerCase());
			// what level are we on?  if it's 0, this is the first branch
			if (menu.level == 0) {
				firstItem = menu.submenu[i];
			} else {
				firstItem = branch;
			}
		} else { // haven't found current url, dig deeper
			//alert("at level "+menu.level+" "+menu.submenu[i].location.toLowerCase()+" != "+requestLoc.toLowerCase());
			if (requestLoc.toLowerCase().indexOf(menu.submenu[i].location.toLowerCase()) == 0) {
				if (closest != null) {
					if (closest.location.split("/").length < menu.submenu[i].location.split("/").length) {
						if (menu.level == 0) {
							closest = menu.submenu[i];
						} else {
							closest = branch;
						}
					}
				} else {
					if (menu.level == 0) {
						closest = menu.submenu[i];
					} else {
						closest = branch;
					}
				}
			}
			if (menu.submenu[i].submenu.length > 0) {
				if (menu.submenu[i].level == 1) {
					firstItem = findFirstItem(menu.submenu[i], requestLoc, menu.submenu[i]);
				} else {
					firstItem = findFirstItem(menu.submenu[i], requestLoc, branch);
				}
			}
		}
		if (firstItem != null) {
			break;
		}
	}
	return firstItem;
}
//****************************
//****************************
var lastIndex = false;
// ---------------------------------------------
// recursively write out the menu structure
// "o" is the JS object.
// ---------------------------------------------
function create_menu(o) {
	setTopicLevelLink(o);
	if (show_topiclevellink(o)) {
		create_topicLevelLink();
	} else if (show_topiclevellink_hslcchildren(o)) {
		create_topicLevelLink();
	}
	else {
		//alert("do NOT show toplevellink for "+o.location);
	}
	if (show_collectionhead(o)) {
		create_collectionhead(o.submenu);
	} else if (show_collectionhead_hslcchildren(o)) {
		create_collectionhead_hslcchildren(o, hslc_children);
	} else {
		//alert("do NOT show collectionhead for "+o.location);
	}
	// add items to the menu.
	// only items on levels 1 or above, or pc search on level 0 get added to the menu
	var level = parseInt(o.level);
	if (level > 0) { // items level 1 or above get added to navmenu
		create_dir_left(o);
	} else { // if pc search is on level 0, still add it to navmenu
		if (o.location == "/hslc/Program Design and Management/Head Start Requirements/HSLIC_PC_Search"){
			create_dir_left(o);
		} else { // level 0 items besides pc search not added
			//alert( "do NOT add "+o.location+" to the directory"); // debug
		}
	}
	/** code below displays all menu items without sorting. */
	if (level == 0) {
		for (var index = 0; index < o.submenu.length; index++) {
			if (index == o.submenu.length - 1) {
				lastIndex = true;
			} else {
				lastIndex = false;
			}
			if (createdListing) { // if the collection listing was created, stop processing
				index = o.submenu.length;
				continue;
			}
			create_menu(o.submenu[index]);
		}
	}
	/** removed sorting per John Graf's request
	// get next level of focus in the path
	var nextFocusIndex = -1;
	if (firstMenuItem != null) {
		var offset = firstMenuItem.location.split("/").length - 2;
	} else {
		var offset = 1;
	}
	if (level + offset < urlArray.length) {		
		var nextFocus = urlArray[level + offset];
		for (var index = 0; index < o.submenu.length; index++) {
			var loc = "/" + hslc_hiername;
			if (nextFocus.toLowerCase() == o.submenu[index].name.toLowerCase()) {
				nextFocusIndex = index;
			} else if (level == 0 
					&& loc.toLowerCase().indexOf(o.submenu[index].location.toLowerCase()) == 0) {
				nextFocusIndex = index;
			}
		}
	} else {
		//alert("no focus level below "+o.location);
	}
	if ((urlArray[level] && urlArray[level].toLowerCase() == o.name.toLowerCase())
			|| (urlArray[level] && urlArray[level].toUpperCase() == "ECLKC" && o.name.toLowerCase() == "hslc")
					|| (firstMenuItem != null && level == 1 && o.location.toLowerCase() == firstMenuItem.location.toLowerCase())) {
		if (level == 0) {
			// default top level menu
			if (nextFocusIndex == -1 && urlArray.length == 1) {
				for (var index = 0; index < o.submenu.length; index++) {
					create_menu(o.submenu[index]);
				}
			} else {
				// the one on focus is always on top
				current_table = 'insider';
				
				if (nextFocusIndex != -1) {
					create_menu(o.submenu[nextFocusIndex]);
				}
		
				current_table = 'leftNav';
				
				for (var index = 0; index < o.submenu.length; index++) {
					if (index != nextFocusIndex) {
						create_menu(o.submenu[index]);
					}
				}
			}
		} else {
			if (firstMenuItem != null
					&& level == 1
					&& o.location.toLowerCase() == firstMenuItem.location.toLowerCase()) {
				for (var index = 0; index < o.submenu.length; index++) {
					//create_menu(o.submenu[index]);
				}
			}
		}
	} else {
		//alert("NO MATCH for level "+level+" of url ("+urlArray[level]+") and location name ("+o.name+")");
	}
	*/
}
//--------------------------------------------
// determins if show the collection head list 
// of an object based on
// 1. the object is on focus AND
// 2. the object has submenu AND
// 3. the submenu is on the RHV
//--------------------------------------------
function show_collectionhead(o) {
	//return (show_topiclevellink(o) && !(o.show_contents && o.show_contents == 'false'));
	if (!show_topiclevellink(o))  return false;
	if ((o.show_contents && o.show_contents == 'false')) return false;
	//alert("show_collectionhead")
	return true;
	
}


function show_topiclevellink(o) {
	return (o.location == g_hiername && o.submenu.length > 0 && o.submenu[0].level > 4);
}


//--------------------------------------------
// determins if show the collection head list for hslc_children
// of an object based on
// 1. showDocuments() AND
// 2. hslc_children exists.
//--------------------------------------------
function show_collectionhead_hslcchildren(o) {
	return (show_topiclevellink_hslcchildren(o) && !(o.show_contents && o.show_contents == 'false'));
}
function show_topiclevellink_hslcchildren(o) {
	if (typeof(hslc_children) == "undefined") {
		//alert("hslc_children is undefined");
	} else if (hslc_children != null) {
		//alert("hslc_children is null");		
	}
	return (showDocuments(o) && typeof(hslc_children) != "undefined" && hslc_children != null && hslc_children.length > 0);
}


//-----------------------------------
// creates the collection head list
//-----------------------------------
function create_collectionhead(myarray) {
	//alert("create_collectionhead");
	if (noCollectionListing == true 
			|| (showthreeclick && showthreeclick == true)) {
		createdListing = true;
		return; 
	}
	if (createdListing) return;
	if (window.location.href.toLowerCase().indexOf("uiclass%3ahslc_userregistration") != -1
			|| currentUrl.toLowerCase().indexOf("uiclass:hslc_userregistration") != -1) {
		createdListing = true;
		return;
	}
	
	var mytable = document.getElementById('collectionhead');
	if (!mytable) {
		return;
	}
	//alert("visible");
	mytable.style.visibility = 'visible';
	
	//var blankline = document.createElement("BR");
	//mytable.appendChild(blankline);
	
	var mylist = document.createElement("UL");	
	for (var index = 0; index < myarray.length; index++) {
		var myitem = document.createElement("li");
		var mylink = document.createElement("a");
		if (myarray[index].location.indexOf("/hslc") == 0) {
			if(myarray[index].location('/') != 0)
			mylink.href = "/" + encodeURI(myarray[index].location) + userpostfix;
			else
			mylink.href = encodeURI(myarray[index].location) + userpostfix;
		} else {
			if(myarray[index].location('/') != 0)
			mylink.href = "/" + encodeURI(myarray[index].location);
			else
			mylink.href = encodeURI(myarray[index].location);
		}
		mylink.innerHTML = myarray[index].name;
		myitem.appendChild(mylink);
		mylist.appendChild(myitem);
	}
		
	mytable.appendChild(mylist);
	createdListing = true;
}
/**
 * Creates the collection head listing at the bottom of a document for hslc_children
 * @param {Object} o the menu structure object
 * @param {Object} myarray the listing of all child documents
 */
function create_collectionhead_hslcchildren(o, myarray) {
	if (noCollectionListing == true 
			|| (showthreeclick && showthreeclick == true)) { 
		createdListing = true;
		return; 
	}
	if (createdListing) return;
	if (window.location.href.toLowerCase().indexOf("uiclass%3ahslc_userregistration") != -1
			|| currentUrl.indexOf("UIClass:HSLC_UserRegistration") != -1) {
		createdListing = true;
		return;
	}
	
	var mytable = document.getElementById('collectionhead');
	if (!mytable) {
		createdListing = true;
		return; 
	}
	
	mytable.style.visibility = 'visible';
	var mylist = document.createElement("UL");

	for (var index = 0; index < myarray.length; index++) {
		var myitem = document.createElement("li");

		if (myarray[index].anchor == g_hiername || // if anchor is the same as g_hiername
			myarray[index].name == urlArray[urlArray.length-1] // if name is the same as the last part of url - for documents with shortcuts.
			) {
			var myspan = document.createElement("span");
			myspan.setAttribute('class', 'homeContentText');
			myspan.setAttribute('className', 'homeContentText');
			var mylink = document.createTextNode(myarray[index].title);
			myspan.appendChild(mylink);
			myitem.appendChild(myspan);
		} else if(myarray[index].anchor == "<br>") {// check for whitespace flag
			myitem = document.createElement("br");
		} else {
			var mylink = document.createElement("a");
			if (o.location.indexOf("/hslc") == 0) {
				//mylink.href = encodeURI(o.location) + "/" + (myarray[index].name)  + userpostfix;
				if(hslc_parentHierName.indexOf('/')!=0)
				mylink.href = "/" + encodeURI(hslc_parentHierName) + "/" + (myarray[index].name)  + userpostfix;
				else
				mylink.href = encodeURI(hslc_parentHierName) + "/" + (myarray[index].name)  + userpostfix;
			} else {
				//mylink.href = encodeURI(o.location) + "/" + (myarray[index].name);
				if(hslc_parentHierName.indexOf('/')!=0)
				mylink.href = "/" + encodeURI(hslc_parentHierName) + "/" + (myarray[index].name);
				else
				mylink.href = encodeURI(hslc_parentHierName) + "/" + (myarray[index].name);
			}
     //		mylink.href = encodeURI(o.location) + "/" + escape(myarray[index].name);	
			mylink.innerHTML = myarray[index].title;
			myitem.appendChild(mylink);			
		}
		mylist.appendChild(myitem);
	}
	mytable.appendChild(mylist);
	createdListing = true;
}


function create_topicLevelLink() {
	var mytable = document.getElementById('collectionhead');
	if (!mytable) {
		return;
	}

	if (!topic_level_link) {
		return;
	}
	
	if (g_hiername == topic_level_link) { // do NOT show if the topic level link is currently in display
		return;
	}
	
	var hyperlink = document.createElement("A");
	if (topic_level_link.indexOf("/hslc") == 0) {
		hyperlink.href = encodeURI(topic_level_link) + userpostfix;
	} else {
		hyperlink.href = encodeURI(topic_level_link);
	}	
	hyperlink.setAttribute('className',"nav");
	hyperlink.setAttribute('class',"nav");
	hyperlink.innerHTML = '<img src="' + back_arrow + '" border="0" alt="Up">';
	
	if (!homePageDisplay) {
		var mydiv = document.getElementById('collectionhead_back');
		mydiv.style.textIndent = "18px";
		mydiv.appendChild(hyperlink);
	}
}

/**
 * Sets the topic level link for the menu.
 * The link is set if menu item is levels 1, 2, or 3.
 * For level 1 and 2 items, the top level link is set if
 * the menu item's name matches the url (ex., Everyday 
 * Parenting on level 2 matches the url /hslc/For Parent/Everyday Parenting), 
 * and the menu item either has hw_topic or show_children set.
 * Level 3 items are always set as topic level links.
 */
function setTopicLevelLink(o) {
	var level = parseInt(o.level);
	if (level < 1 || level > 3) {
		return;
	}
	
	if (((level == 1 || level == 2) 
			&& urlArray[level] == o.name 
			&& (o.hw_topic || o.show_children == "true")) 
				|| level == 3) {		
		topic_level_link = o.location;
	}
}
/**
 * Creates inner UL for nav list items.  
 * The format of the string returned is :
 * <ul>
 *   <li><a menu item/></li>
 *    .
 *    .
 *    .
 *   <li class="nav_drop_last"><a last menu item\></li>
 * </ul>
 * @param {Object} menuItem the menu items getting the ul generated.
 * @param {String} levelsDown
 * @return {String}
 */
function createInnerUL(menuItem, levelsDown) {
	// create ul wrapper
	var ulString = "<!--[if lte IE 6]><table><tr><td><![endif]-->";
	ulString += "<UL>";
	// add list items to list
	for (var i = 0; i < menuItem.submenu.length; i++) {// append each submenu
		var submenu = menuItem.submenu[i];
		
		// set tag for list item
		if (i == menuItem.submenu.length - 1) { // last item in all menus
			ulString += "<li class=\"nav_drop_last\">";
		} else if (i == 0
				&& menuItem.HHS_Nav2D) { // first item in a compound menu
			ulString += "<li class=\"nav_drop_first\"><h4>";
		} else {
			if (menuItem.HHS_Nav2D) { // middle items in a compound menu
				ulString += "<li style=\"margin-bottom: 0px;padding-bottom: 0;\">";
			} else { // middle items in a regular menu
				ulString += "<li>";
			}
		}
		
		// add anchor for list item
		if (submenu.submenu.length > 0) {
			if (menuItem.HHS_Nav2D) { // close the header tag in a compound menu
				ulString += getNavListAnchorForMegaMenu(submenu, true);
			} else {
				ulString += getNavListAnchor(submenu, true, false);
			}
		} else {
			if (menuItem.HHS_Nav2D) { // close the header tag in a compound menu
				ulString += getNavListAnchorForMegaMenu(submenu, true);
			} else {
				ulString += getNavListAnchor(submenu, false, false);
			}
		}
		
		// create lower lists for submenu items
		if (submenu.submenu.length > 0) {
			if (levelsDown < max_ro_levels) {
				levelsDown++;
				if (submenu.location.substr(1).toLowerCase() != hslc_hiername.toLowerCase()) {
					if (menuItem.HHS_Nav2D) {
						ulString += createMegaMenu(submenu);
					} else {
						ulString += createInnerUL(submenu, levelsDown);
					}
				}
				levelsDown--;
			}
		}
		ulString += "</li>";
	}
	ulString += "</UL>";
	ulString += "<!--[if lte IE 6]></td></tr></table></a><![endif]-->";
	return ulString;
}
/**
 * Gets the html string for a nav list anchor.
 * @param {Object} o the menu item
 * @param {Boolean} checkForSubs flag indicating there should be a check for submenus
 * @param {Boolean} closeHeader flag indicating the html string should close an <h4> tag for compound menus
 * @return {String}
 */
function getNavListAnchor(o, checkForSubs, closeHeader) {
	var gtitle 	  = o.title;
	// replace underscore in title with space using regular expression
	gtitle = gtitle.replace(/_/g, ' ');
	var gname 	  = o.name;
	var gdesc 	  = o.desc;
	var glocation = o.location;
	// add user postfix to href
	if (glocation.indexOf("/hslc") == 0) {
		var href = encodeURI(glocation)  + userpostfix;
	} else {
		var href = encodeURI(glocation);
	}
	var anchor = "<a HREF=\"";
	anchor += href;
	anchor += "\" ";
	// set target for PDFs
	if (gname.substring(gname.length - 4).toLowerCase() == '.pdf') {
		anchor += "TARGET=\"_blank\" ";
	}
	anchor += "TITLE=\"";
	anchor += gtitle;
	anchor += "\">";	
	anchor += gtitle;
	if (o.submenu.length > 0 && checkForSubs) { // item has submenus
		anchor += "<!--[if IE 7]><!--></a><!--<![endif]-->";
	} else {
		anchor += "</a>";
	}
	if (closeHeader) {
		anchor += "</h4>";
	}
	return anchor;
}
/**
 * Gets the html string for a standard nav list anchor.
 * @param {Object} o the menu item
 * @param {Boolean} checkForSubs flag indicating there should be a check for submenus
 * @param {Boolean} closeHeader flag indicating the html string should close an <h4> tag for compound menus
 * @return {String}
 */
function getStdNavListAnchor(o) {
	var gtitle 	  = o.title;
	// replace underscore in title with space using regular expression
	gtitle = gtitle.replace(/_/g, ' ');
	var gname 	  = o.name;
	var gdesc 	  = o.desc;
	var glocation = o.location;
	// add user postfix to href
	if (glocation.indexOf("/hslc") == 0) {
		var href = encodeURI(glocation)  + userpostfix;
	} else {
		var href = encodeURI(glocation);
	}
	var anchor = "<a HREF=\"";
	anchor += href;
	anchor += "\" ";
	// set target for PDFs
	if (gname.substring(gname.length - 4).toLowerCase() == '.pdf') {
		anchor += "TARGET=\"_blank\" ";
	}
	anchor += "TITLE=\"";
	anchor += gtitle;
	anchor += "\">";	
	anchor += gtitle;
	anchor += "</a>";
	return anchor;
}
/**
 * Gets the html string for a top nav list anchor. This html
 * includes the IE7 fix.
 * @param {Object} o the menu item
 * @param {Boolean} checkForSubs flag indicating there should be a check for submenus
 * @param {Boolean} closeHeader flag indicating the html string should close an <h4> tag for compound menus
 * @return {String}
 */
function getTopNavListAnchor(o) {
	var gtitle 	  = o.title;
	// replace underscore in title with space using regular expression
	gtitle = gtitle.replace(/_/g, ' ');
	var gname 	  = o.name;
	var gdesc 	  = o.desc;
	var glocation = o.location;
	// add user postfix to href
	if (glocation.indexOf("/hslc") == 0) {
		var href = encodeURI(glocation)  + userpostfix;
	} else {
		var href = encodeURI(glocation);
	}
	var anchor = "<a HREF=\"";
	anchor += href;
	anchor += "\" ";
	// set target for PDFs
	if (gname.substring(gname.length - 4).toLowerCase() == '.pdf') {
		anchor += "TARGET=\"_blank\" ";
	}
	anchor += "TITLE=\"";
	anchor += gtitle;
	anchor += "\">";	
	anchor += gtitle;
	anchor += "<!--[if IE 7]><!--></a><!--<![endif]-->";
	return anchor;
}
/**
 * Gets the html string for a nav list anchor.
 * @param {Object} o the menu item
 * @param {Boolean} checkForSubs flag indicating there should be a check for submenus
 * @param {Boolean} closeHeader flag indicating the html string should close an <h4> tag for compound menus
 * @return {String}
 */
function getNavListAnchorForMegaMenu(o, closeHeader) {
	var gtitle 	  = o.title;
	// replace underscore in title with space using regular expression
	gtitle = gtitle.replace(/_/g, ' ');
	var gname 	  = o.name;
	var gdesc 	  = o.desc;
	var glocation = o.location;
	// add user postfix to href
	if (glocation.indexOf("/hslc") == 0) {
		var href = encodeURI(glocation)  + userpostfix;
	} else {
		var href = encodeURI(glocation);
	}
	var anchor = "<a HREF=\"";
	anchor += href;
	anchor += "\" ";
	// set target for PDFs
	if (gname.substring(gname.length - 4).toLowerCase() == '.pdf') {
		anchor += "TARGET=\"_blank\" ";
	}
	anchor += "TITLE=\"";
	anchor += gtitle;
	anchor += "\">";	
	anchor += gtitle;
	anchor += "</a>";
	if (closeHeader) {
		anchor += "</h4>";
	}
	return anchor;
}
/**
 * Creates nested UL for nav list items.  
 * The format of the string returned is :
 * <ul>
 *   <li><a menu item/></li>
 *    .
 *    .
 *    .
 *   <li class="nav_drop_last"><a last menu item\></li>
 * </ul>
 * @param {Object} menuItem the menu items getting the ul generated.
 * @param {Boolean} flag indicating if a highlight has been applied.
 *                  if true, that means the top-level menu item has
 *                  the nav_selected class and no further highlight
 *					is needed; otherwise a menu item
 *					still needs to be highlighted
 * @return {String}
 */
function createNestedUL(menuItem, highlighted) {
	// create ul wrapper
	var ulString = "<!--[if lte IE 6]><table><tr><td><![endif]-->";
	ulString += "<ul style=\"display: block; visibility: visible;position: static;\">";
	// add list items to list
	for (var i = 0; i < menuItem.submenu.length; i++) {// append each submenu
		var submenu = menuItem.submenu[i];
		
		// check to see if this list item should be highlighted
		var doHighlight = false;
		//alert("highlighted: "+highlighted);
		//alert("submenu.location: "+submenu.location.substr(1).toLowerCase()+"||);
		if (!highlighted
				&& hslc_hiername.toLowerCase().indexOf(submenu.location.substr(1).toLowerCase()) == 0) {
			// there is no top-level highlight, and the current menu item 
			// either matches or is a parent of the displayed webpage
			doHighlight = true;
		}
		// set tag for list item
		if (i == menuItem.submenu.length - 1) { // last item in all menus
			if (doHighlight) {
			ulString += "<li class=\"nav_drop_last nav_selected\">";
			} else {
			ulString += "<li class=\"nav_drop_last\">";
			}
		} else {
			if (doHighlight) {
				ulString += "<li class=\"nav_selected\">";
			} else {
				ulString += "<li>";
			}
		}
		
		// add anchor for list item
		if (submenu.submenu.length > 0) { // list item has submenus
			ulString += getTopNavListAnchor(submenu);
		} else {
			ulString += getStdNavListAnchor(submenu);
		}
		
		// create lower lists for submenu items
		if (submenu.submenu.length > 0) {
			if (roLevels < max_ro_levels) {
				roLevels++;
				ulString += createInnerUL(submenu, 1);
				roLevels--;
			}
		}
		ulString += "</li>";
	}
	ulString += "</UL>";
	ulString += "<!--[if lte IE 6]></td></tr></table></a><![endif]-->";	
	return ulString;
}
/**
 * Creates a left-hand nav item for the first <LI> element displayed.
 * The first menu item will usually display its submenus and have a
 * highlight.
 * @param {Object} o the menu structure object.
 * @return {Object}
 */
function getFirstNavListItem(o) {
	var highlighted = false;
	var gtitle 	  = o.title;
	// replace underscore in title with space using regular expression
	gtitle = gtitle.replace(/_/g, ' ');
	var gname 	  = o.name;
	var gdesc 	  = o.desc;
	var glocation = o.location;
	var listItem = document.createElement('LI');
	// CHECK FOR NAV2D
	
	if (o.location.substr(1).toLowerCase() == hslc_hiername.toLowerCase()) {
		listItem.className = "nav_show nav_selected";
		highlighted = true;
	} else {
		listItem.className = "nav_show";
	}
	var inner = getStdNavListAnchor(o);
	// check for submenus
	if (o.submenu.length > 0) {
		inner += createNestedUL(o, highlighted);
	}
	listItem.innerHTML = inner;
	return listItem;
}
//***************************
//		MEGA MENUS
//***************************
/**
 * Splits the mega menu submenus into left- and right-column items for display.
 * @param {Object} menuItem the menu item whose submenus are being shown
 * @return {String} the html for displaying submenus in left- and right-columns
 */
function splitMegaMenuSubmenus(menuItem) {
	// split the menu in half
	var half = Math.ceil(menuItem.submenu.length / 2);
	var list = "<ul>";
	for (var i = 0; i < menuItem.submenu.length; i++) {
		var submenu = menuItem.submenu[i];
		if (i == half && menuItem.submenu.length > 1) {
			list += "</ul><ul>";
		}
		list += "<li>";
		list += getAnchor(submenu)
		list += "</a>";
		list += "</li>";
	}
	list += "</ul>";
	list += "<div>&nbsp;</div>";
	return list;
	/**
		<ul>
			<li><a href="/ECLKC_prototyping/build_me/for_parents/parenting/family_life/" title="Family Life">Family Life</a></li>
			<li><a href="/ECLKC_prototyping/build_me/for_parents/parenting/fatherhood/" title="Fatherhood">Fatherhood</a></li>
			<li><a href="/ECLKC_prototyping/build_me/for_parents/parenting/parents_as_teachers/" title="Parents as Teachers">Parents as Teachers</a></li>
		</ul>
		<ul>
			<li><a href="/ECLKC_prototyping/build_me/for_parents/parenting/readiness/" title="School Readiness">School Readiness</a></li>
			<li><a href="/ECLKC_prototyping/build_me/for_parents/parenting/milestones/" title="Developmental Milestones">Developmental Milestones</a></li>
			<li><a href="/ECLKC_prototyping/build_me/for_parents/parenting/resources/" title="Parenting Resources">Parenting Resources</a></li>
		</ul>
		<div>&nbsp;</div>
	*/
}
/**
 * Gets the 'header' anchor for the mega menu, that appears in the mega menu table.
 * @param {Object} menuItem the mega menu header
 * @return {String} the html for the header anchor
 */
function getMegaMenuHeaderAnchor(menuItem) {
	var anchor = "<h4>";
	anchor += getAnchor(menuItem);
	anchor += "</a>";
	anchor += "</h4>";
	return anchor;
}
/**
 * Gets the mega menu table displayed after hovering over a
 * mega menu item in the left-hand navigation.  The table format
 * is a header with submenus displayed below it, split into a left-
 * and right-side column.
 * @param {Object} menuItem the mega menu branch being generated
 * @return {String} the html for the mega menu table
 */
function getMegaMenuTable(menuItem) {
	// create ul wrapper
	var ulString = "<!--[if lte IE 6]><table><tr><td><![endif]-->";
	ulString += "<UL>";
	// add list items to list
	for (var i = 0; i < menuItem.submenu.length; i++) {// append each submenu
		var submenu = menuItem.submenu[i];
		
		// set tag for list item
		if (i == 0) { // first item 
			ulString += "<li class=\"nav_drop_first\">";
		} else if (i == menuItem.submenu.length - 1) { // last item
			ulString += "<li class=\"nav_drop_last\">";
		} else {
			ulString += "<li>";
		}
		ulString += getMegaMenuHeaderAnchor(submenu);
		// create lower lists for submenu items
		if (submenu.submenu.length > 0) {
			ulString += splitMegaMenuSubmenus(submenu);
			/*
			if (levelsDown < max_ro_levels) {
				levelsDown++;
				if (submenu.location.substr(1).toLowerCase() != hslc_hiername.toLowerCase()) {
					ulString += splitMegaMenuSubmenus(submenu);
				}
				levelsDown--;
			}
			*/
		}
		ulString += "</li>";
	}
	ulString += "</ul>";
	ulString += "<!--[if lte IE 6]></td></tr></table></a><![endif]-->";
	return ulString;
}
/**
 * Gets the 'lead' anchor for the mega menu, the one that always appears in the
 * left-hand navigation.
 * @param {Object} o the mega menu branch
 * @return {String} the html for the lead anchor
 */
function getMegaMenuLeadAnchor(o) {
	var anchor = getAnchor(o);
	anchor += "<!--[if IE 7]><!--></a><!--<![endif]-->";
	return anchor;
}
/**
 * Creates a mega menu.
 * @param {Object} o the menu branch displaying the mega menu
 * @return {String} the html of the completed mega menu
 */
function createMegaMenu(o) {	
	var megaMenu = getMegaMenuLeadAnchor(o);
	megaMenu += getMegaMenuTable(o);
	return megaMenu;
}
//***************************
//***************************
//***************************
//		STANDARD MENUS
//***************************
function getStandardMenuListing(menuItem, levelsDown) {
	// create ul wrapper
	var ulString = "<!--[if lte IE 6]><table><tr><td><![endif]-->";
	ulString += "<UL>";
	// add list items to list
	for (var i = 0; i < menuItem.submenu.length; i++) {// append each submenu
		var submenu = menuItem.submenu[i];
		
		// set tag for list item
		if (i == menuItem.submenu.length - 1) { // last item
			ulString += "<li class=\"nav_drop_last\">";
		} else {
			ulString += "<li>";
		}
		ulString += getStandardAnchor(submenu, levelsDown);
		// create lower lists for submenu items
		if (submenu.submenu.length > 0) {
			if (levelsDown < max_ro_levels) {
				levelsDown++;
				ulString += getStandardMenuListing(submenu, levelsDown);
				levelsDown--;
			}
		}
		ulString += "</li>";
	}
	ulString += "</ul>";
	ulString += "<!--[if lte IE 6]></td></tr></table></a><![endif]-->";
	return ulString;
}
/**
 * Gets the 'lead' anchor for the standard menu, the one that always appears in the
 * left-hand navigation.
 * @param {Object} o the standard menu branch
 * @return {String} the html for the lead anchor
 */
function getStandardAnchor(o, levelsDown) {
	var anchor = getAnchor(o);
	if (o.submenu.length > 0
			&& levelsDown < max_ro_levels) {
		anchor += "<!--[if IE 7]><!--></a><!--<![endif]-->";
	} else {
		anchor += "</a>";
	}
	return anchor;
}
/**
 * Create standard menu.
 * @param {Object} o the menu branch displaying the mega menu
 * @return {String} the html of the completed mega menu
 */
function createStandardMenu(o) {	
	var menu = getStandardAnchor(o, 0);
	if (o.submenu.length > 0) {
		menu += getStandardMenuListing(o, 1);
	}
	return menu;
}
//***************************
//***************************
function getSelectedMenuListing(menuItem, levelsDown) {
	// create ul wrapper
	var ulString = "<!--[if lte IE 6]><table><tr><td><![endif]-->";
	ulString += "<UL>";
	// add list items to list
	for (var i = 0; i < menuItem.submenu.length; i++) {// append each submenu
		var submenu = menuItem.submenu[i];
		
		// set tag for list item
		if (levelsDown == 1
				&& hslc_hiername.toLowerCase().indexOf(submenu.location.substr(1).toLowerCase()) == 0) {			
			if (i == menuItem.submenu.length - 1) { // last item
				ulString += "<li class=\"nav_drop_last nav_selected\">";
			} else {
				ulString += "<li class=\"nav_selected\">";
			}
		} else {
			if (i == menuItem.submenu.length - 1) { // last item
				ulString += "<li class=\"nav_drop_last\">";
			} else {
				ulString += "<li>";
			}
		}
		ulString += getStandardAnchor(submenu, levelsDown);
		// create lower lists for submenu items
		if (submenu.submenu.length > 0) {
			if (levelsDown < max_ro_levels) {
				levelsDown++;
				ulString += getStandardMenuListing(submenu, levelsDown);
				levelsDown--;
			}
		}
		ulString += "</li>";
	}
	ulString += "</ul>";
	ulString += "<!--[if lte IE 6]></td></tr></table></a><![endif]-->";
	return ulString;
}
/**
 * Create selected menu.
 * @param {Object} o the menu branch displaying the mega menu
 * @return {String} the html of the completed mega menu
 */
function createSelectedMenu(o) {	
	var menu = getStandardAnchor(o, 0);
	if (o.submenu.length > 0) {
		menu += getSelectedMenuListing(o, 1);
	}
	return menu;
}
/**
 * Creates a left-hand nav item, starting with the first list item under the main UL.
 * @param {Object} o the menu structure object
 */
function getNavListItem(o) {
	var listItem = document.createElement('LI');
	if (firstMenuItem != null
			&& firstMenuItem.location.toLowerCase() == o.location.toLowerCase()) {
		listItem.className = "nav_show";
		listItem.innerHTML = createSelectedMenu(o);
	} else if (o.HHS_Nav2D) {
		listItem.className = "nav2d";
		listItem.innerHTML = createMegaMenu(o);
	} else if (lastIndex) {
		listItem.className = "nav_drop_last";
		listItem.innerHTML = createStandardMenu(o);
	} else {
		listItem.innerHTML = createStandardMenu(o);
	}
	/*
	var inner = getNavListAnchor(o, true, false);
	if (o.submenu.length == 0 // no submenus under this cell
			/*|| submenusListedInLHN(o)*//*) { // submenus displayed already
	} else {
		if (firstMenuItem != null 
				&& parseInt(o.level) == 1
				&& o.location.toLowerCase() == firstMenuItem.location.toLowerCase()
				&& o.location.substr(1).toLowerCase() != hslc_hiername.toLowerCase()) {
			inner += createInnerUL(o, 1);
		} else {
			inner += createInnerUL(o, 1);
		}
	}*/
	//alert(inner);
	return listItem;	
}
/**
 * Creates the left-hand navigation menu by creating TR and TD elements 
 * to be attached to specific tables in hslc_leftnav.xml.
 * The left-hand nav is a table that places 5 inner tables on separate rows:
 * ROW 1 - firstEver - the first nav link placed.  it will only have one link.
 * ROW 2 - insider - starts with the 2nd nav link.  nav links are added to this for levels 1 and 2.
 * ROW 3 - insider_3 - starts with the first level 3 nav link. nav links are added to this for level 3 and then remaining level 2
 * ROW 4 - leftNav - all remaining level 1 links
 * ROW 5 - menu_quicklinks - self-explanatory
 * The TR and TD elements created in this method are placed dependent 
 * on their level and the lowest level reached.
 * @param {Object} o
 */
function create_dir_left(o) {
	var level = parseInt(o.level);
	// Policy Clarification level is 3 but never reach here!!!	
	if (level < 1 || level > 3) { // never go beyond 3rd level down for menu
		return;
	}
	
	navList.appendChild(getNavListItem(o));
	/*
	//var focus = leftOnFocus(o);
	if (firstMenuItem != null 
			&& parseInt(o.level) == 1
			&& o.location.toLowerCase() == firstMenuItem.location.toLowerCase()) {
		navList.appendChild(getFirstNavListItem(o));
	} else {
		navList.appendChild(getNavListItem(o));
	}
	*/
}
/**
 * Gets an html anchor for the given navigation item.
 * @param {Object} o the navigation item the anchor is created for.
 * @return {String} the html for the anchor, in the form of '<a href="asdf" title="asdf">TITLE', 
 * but without the closing '</a>' tag.
 */
function getAnchor(o) {
	var gtitle 	  = o.title;
	// replace underscore in title with space using regular expression
	gtitle = gtitle.replace(/_/g, ' ');
	var gname 	  = o.name;
	var gdesc 	  = o.desc;
	var glocation = o.location;
	// add user postfix to href
	if (glocation.indexOf("/hslc") == 0) {
		var href = encodeURI(glocation)  + userpostfix;
	} else {
		var href = encodeURI(glocation);
	}
	var anchor = "<a HREF=\"";
	anchor += href;
	anchor += "\" ";
	// set target for PDFs
	if (gname.substring(gname.length - 4).toLowerCase() == '.pdf') {
		anchor += "TARGET=\"_blank\" ";
	}
	anchor += "TITLE=\"";
	anchor += gtitle;
	anchor += "\">";	
	anchor += gtitle;
	return anchor;
}
function showDocuments(o) {
	var level = parseInt(o.level);
	
	if (onFocus(o.name, o.level) && 
		((level == 4 && o.title != 'Related Resources' && !isReferenceCenter() && (typeof(hslc_children) != "undefined" && hslc_children != null))  // subjects
		|| level == 6  // Related Resources
		|| ((level == 4 || level == 5) && isReferenceCenter()) // Reference Center
		|| (level == 5 && o.show_children == "true")
		)) {
		return true;
	}
	/*
	if (hslc_parentHierName
			&& o.location
			&& hslc_parentHierName.toLowerCase() == o.location.toLowerCase()
			&& (o.show_children=="true" 
					|| o.submenu.length == 0)
			//TODO: need a better fix
			&& o.location.indexOf('/hslc/hsd') == -1  // make an exception for Directories
			&& o.location.indexOf('/hslc/Program Design and Management/Head Start Requirements/FY 2008 OHS Monitoring Protocol') == -1  // make an exception for HS Monitor
			&& o.location.indexOf('/ECLKC/customerservice/Feedback') == -1  // make an exception for Feedback/Suggestions
		) {
		return true;
	}
	*/
	var branchFound = false;
	if (hslc_parentHierName && o.location && closest) {
		if (hslc_parentHierName.toLowerCase() == o.location.toLowerCase()) {
			branchFound = true;
		} else if (o.location.toLowerCase() == closest.location.toLowerCase()) {
			//alert("match");
			branchFound = true;
		}
	}
	if (branchFound
			&& (o.show_children=="true" 
					|| o.submenu.length == 0)
			//TODO: need a better fix
			&& o.location.indexOf('/hslc/hsd') == -1  // make an exception for Directories
			&& o.location.indexOf('/hslc/Program Design and Management/Head Start Requirements/FY 2008 OHS Monitoring Protocol') == -1  // make an exception for HS Monitor
			&& o.location.indexOf('/ECLKC/customerservice/Feedback') == -1  // make an exception for Feedback/Suggestions
		&& typeof(hslc_children) != "undefined" 
			&& hslc_children != null 
			||  location.href.indexOf("EsSearch")) {
		return true;
	}
	if (branchFound
			&& typeof(hslc_children) != "undefined" && hslc_children != null) {
		return true;
	}
	
	// show children for left nav menu
	if (level < 4 && onFocus(o.name, o.level)) {
		if (typeof(hslc_children) != "undefined" && hslc_children != null) {
			return true;
		}
	}
	//alert("level = " + level);
	//alert("o.name = " + o.name);
	return false;
}
// check if the request object is within 'Reference Center'
function isReferenceCenter() {
	var fixed_level = 3; // Reference Center has a fixed level 3
	if (urlArray.length >= fixed_level + 1 && urlArray[fixed_level] == 'Reference Center') {
		return true;
	}
	
	return false;
}
var roLevels = 0;
var roItems = 0;
var roText = "";
var roOutArr = new Array();
/**
 * Gets all lists used in the rollout menu
 * @param {Object} menuItem
 * @return{Object} ul element
 */
function getROLists(menuItem) {
	// create unordered list
	var ul = document.createElement("ul");
	for (var i = 0; i < menuItem.submenu.length; i++) {// append each submenu as a list item
		var submenu = menuItem.submenu[i];
		// create new link
		var a = document.createElement("a");
		if (submenu.location.indexOf("/hslc") == 0) {
			a.href = encodeURI(submenu.location)  + userpostfix;
		} else {
			a.href = encodeURI(submenu.location);
		}
		roItems++;
		roText += roItems + " " + a.href + "\n";
		if (roItems % 15 == 0) {
			roOutArr.push(roText);
			roText = ""
		}
		// replace underscore with space using regular expression
		a.innerHTML = submenu.title.replace(/_/g, ' ');
		//
		if (submenu.submenu.length > 0) {
			a.className = "dropdown";
			if (roLevels == max_ro_levels) {
				a.className = "dropdown2";
			}
		} else {
			a.className = "dropdown2";			
		}
		// create new list item
		var li = document.createElement("li");
		// append link to list item
		li.appendChild(a);
		if (submenu.submenu.length > 0) {// create lower lists for submenu items
			if (roLevels < max_ro_levels) {
				roLevels++;
				li.appendChild(getROLists(submenu));
				roLevels--;
			}
		}
		ul.appendChild(li); // append the list item to the unordered list
	}
	return ul;
}
// ------------------------------
// create a table cell 
// ------------------------------
function get_cell(o,menuLvl,span,focus, padding){
	var gtitle 	  = o.title;
	var gname 	  = o.name;
	var gdesc 	  = o.desc;
	var glocation = o.location;
	var mycurrent_cell = document.createElement('TD');
	//var mycurrent_cell = "<td style=\"padding-left:" + padding + "px;\">";
	//mycurrent_cell.setAttribute('colSpan', span);
	//mycurrent_cell.setAttribute('style', "padding-left:" + padding + "px;");
	
	var currentlink = document.createElement("a");
	if (glocation.indexOf("/hslc") == 0) {
		currentlink.href = encodeURI(glocation)  + userpostfix;
	} else {
		currentlink.href = encodeURI(glocation);
	}
	roItems++;
	roText += roItems + " " + currentlink.href + "\n";
	if(roItems % 15 == 0) {
		roOutArr.push(roText);
		roText = ""
	}
	var isIE = false;
	var isIE7 = false;
	if (navigator.userAgent.indexOf('MSIE') != -1) { // IE
		if (navigator.userAgent.indexOf('MSIE 7.0') != -1) { // IE 7.0
			isIE7 = true;
		} else {
			isIE = true;
		}
	}
	if (focus) {
		currentlink.setAttribute('className',"quickLink");
		currentlink.setAttribute('class',"quickLink");
	} else {
		currentlink.setAttribute('className',"navmenu");
		currentlink.setAttribute('class',"navmenu");
	}

	if (gname.substring(gname.length - 4) == '.pdf') {
		currentlink.setAttribute('target',"_blank");
	}
	// replace underscore with space using regular expression
	currentlink.innerHTML = gtitle.replace(/_/g, ' ');
	// fix cell height for IE
	if (isIE || isIE7) {
		if (padding == 7) {
			if (gtitle.length <= 31) {
				mycurrent_cell.setAttribute("className", "leftNav" + padding + "IE");
				mycurrent_cell.setAttribute("class", "leftNav" + padding + "IE");
			} else {
				mycurrent_cell.setAttribute("className", "leftNav" + padding + "IETall");
				mycurrent_cell.setAttribute("class", "leftNav" + padding + "IETall");				
			}
		} else if (padding == 17) {
			if (gtitle.length <= 29) {
				mycurrent_cell.setAttribute("className", "leftNav" + padding + "IE");
				mycurrent_cell.setAttribute("class", "leftNav" + padding + "IE");
			} else {
				mycurrent_cell.setAttribute("className", "leftNav" + padding + "IETall");
				mycurrent_cell.setAttribute("class", "leftNav" + padding + "IETall");				
			}			
		} else if (padding == 27) {
			if (gtitle.length <= 26) {
				mycurrent_cell.setAttribute("className", "leftNav" + padding + "IE");
				mycurrent_cell.setAttribute("class", "leftNav" + padding + "IE");
			} else if (gtitle.length > 26
					&& gtitle.length <= 46) {
				mycurrent_cell.setAttribute("className", "leftNav" + padding + "IETall");
				mycurrent_cell.setAttribute("class", "leftNav" + padding + "IETall");				
			} else {
				mycurrent_cell.setAttribute("className", "leftNav" + padding + "IETallest");
				mycurrent_cell.setAttribute("class", "leftNav" + padding + "IETallest");				
			}
		}
	} else {
		mycurrent_cell.setAttribute("className", "leftNav" + padding);
		mycurrent_cell.setAttribute("class", "leftNav" + padding);
	}
	if (max_ro_levels == 0) { // no rollout menu displayed
		mycurrent_cell.appendChild(currentlink);		
		return  mycurrent_cell;
	}
	if (o.submenu.length == 0 // no submenus under this cell
			|| submenusListedInLHN(o)) { // submenus displayed already
		if (isIE) { //IE 6.0 or less
			var ul = document.createElement('<ul id="rolloutIE6" name="rolloutIE6">');
		} else if (isIE7) { // IE 7.0 or greater
			var ul = document.createElement('<ul id="rollout" name="rollout">');
		} else { // Opera, Safari, or FF
			try {
				var ul = document.createElement('<ul id="rollout" name="rollout">');
			} catch (err) { // FF
				var ul = document.createElement("ul");
				ul.setAttribute('id',"rollout");
			}			
		}
		ul.setAttribute("className", "leftNav" + padding);
		ul.setAttribute("class", "leftNav" + padding);
		var li = document.createElement("li");
		li.appendChild(currentlink);
		// append 1st level item to 1st level list
		ul.appendChild(li);
		// append 1st level list to cell
		mycurrent_cell.appendChild(ul);
	} else { // create rollout menu for this cell
		// create <ul id="rollout">
		if (navigator.userAgent.indexOf('MSIE') != -1) { // IE
			if (navigator.userAgent.indexOf('MSIE 7.0') != -1) { // IE 7.0
				var ul = document.createElement('<ul id="rollout" name="rollout">');
			} else { // IE 6.0 or lower
				var ul = document.createElement('<ul id="rolloutIE6" name="rolloutIE6">');
			}
		} else { // Opera, Safari, or FF
			try {
				var ul = document.createElement('<ul id="rollout" name="rollout">');
			} catch (err) { // FF
				var ul = document.createElement("ul");
				ul.setAttribute('id', "rollout");
			}
		}	
		// create <li> and append current link	
		var li = document.createElement("li");
		if (focus) {
			currentlink.className = "dropdownFocus";
		} else {
			currentlink.className = "dropdownLeftNav";
		}
		li.appendChild(currentlink);
		// html reads: <ul id='rollout'><li><a>
		roLevels = 1;
		li.appendChild(getROLists(o));		
		// append 1st level item to 1st level list
		ul.appendChild(li);
		// append 1st level list to cell
		mycurrent_cell.appendChild(ul);
	}
	return  mycurrent_cell;
}
// ------------------------------
// create an empty cell 
// ------------------------------
function get_empty_cell_with_width(w) {
	var mycurrent_cell=document.createElement('TD');
	mycurrent_cell.setAttribute('width', w);
	mycurrent_cell.appendChild(clear_space_img);
	return mycurrent_cell;
}
/**
 * Checks to see if an object's submenus are listed in the
 * left-hand navigation menu displayed on the screen.
 * @param {Object} o the object being checked.
 * @return {Boolean}
 */
function submenusListedInLHN(o) {
	var exclude = false;
	var level = parseInt(o.level);
	if (level <= 2
			&& (level < urlArray.length
					&& urlArray[level]
					&& urlArray[level].toLowerCase() == o.name.toLowerCase())
					|| (firstMenuItem != null 
							&& o.location.toLowerCase() == firstMenuItem.location.toLowerCase())) {
		exclude = true;
	}
	if (exclude 
			&& (firstMenuItem != null 
					&& o.location.toLowerCase() != firstMenuItem.location.toLowerCase())) {
		exclude = false;
	}
	return exclude;
}

// -----------------------------------
// if a menu item on left is on focus
// -----------------------------------
function leftOnFocus(o) {
	var level = parseInt(o.level);
	
	if (level == 1
			&& (urlArray[level]
					&& urlArray[level].toLowerCase() == o.name.toLowerCase())
			&& (urlArray.length == 2
					|| o.submenu.length == 0  // such as /hslc/wc, which has no sub-collection but a list of documents
					|| (urlArray.length == 3 
							&& documentType != 'collection'))) { // to handle url like /hslc/Family%20and%20Community%20Partnerships/commtopics_intro.html (full collection head)
		return true;
	}
	
	if (level == 2
			&& (urlArray[level]
					&& urlArray[level].toLowerCase() == o.name.toLowerCase())
			&& o.hw_topic) {
		hasHwTopic = true;
		return true;
	}

	if (level == 2
			&& (urlArray[level]
					&& urlArray[level].toLowerCase() == o.name.toLowerCase())
			&& o.show_children) {
		return true;
	}

	if (level == 2
			&& (urlArray[level]
					&& urlArray[level].toLowerCase() == o.name.toLowerCase())
			&& (urlArray.length == 3 
					|| o.submenu.length == 0
					|| (urlArray.length == 4 
							&& documentType != 'collection'))) {
		return true;
	}
	//alert("level= " + level);
	//alert("o.name= " + o.name);
	if (level == 3 
			&& (urlArray[level]
					&& urlArray[level].toLowerCase() == o.name.toLowerCase())) {
		return true;
	}
	//alert("level= " + level);
	//alert("o.name= " + o.name);
	
	return false;
}


// -----------------------------------
// if the current object is on focus 
// -----------------------------------
function onFocus(name, level) {
	var mylevel = parseInt(level);
	
	if (mylevel == -1) {
		if (urlArray[urlArray.length - 1].toLowerCase() == name.toLowerCase()) {
			return true;
		} 
	} else {
		if (urlArray[urlArray.length - 1].toLowerCase() == name.toLowerCase()
				&& mylevel == urlArray.length - 1) {
			return true;
		} 
		
		// take care of HW_Topic, which makes a jump in level
		if (hasHwTopic) {
			if (urlArray[urlArray.length - 1].toLowerCase() == name.toLowerCase()
					&& mylevel == urlArray.length) {
				return true;
			} 
		}
	}
	
	return false;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function setFont(size) {
	setCookie("font_size", size, null);
	window.location.reload();
}