/********************************************************/
/* THIS JAVASCRIPT BELOW OPENS AND CLOSES THE NAVIGATION*/
/********************************************************/

/*
 * pageSections and pageNavTiers are used to open the navigation to the correct location, based on the file name.
 * e.g.
 * 	page "aboutus-history.php" will open the navigation to "sub1".
 *  page "grantsagency-literacyforlife.php" will open the navigation to "sub3"
 *  If a file name does not begin with any of the values in pageSections, then all navigation is closed.
 */
var pageSections = new Array(
	'',
	'',
	'aboutus',
	'applicants',
	'registration',
	'memberinfo',
	'publications',
	'resources',
	'complaintsresolution',
	'events',
	'news',
	'contactus',
	'blogs'
);
var pageNavTiers = new Array(
	'sub1',
	'sub2',
	'sub3',
	'sub4',
	'sub5',
	'sub6',
	'sub7',
	'sub8',
	'sub9',
	'sub10',
	'sub11',
	'sub12',
	'sub13'
);

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.tiersub{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	// set the 'Current Navigation Position' cookie
	document.cookie="CNP="+obj+"; path=/";

	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="tiersub")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

// Function to retrieve the value of the navigation cookie.
function getCookie(name)
{
	var dc = document.cookie;
	var index = dc.indexOf(name + "=");
	if (index == -1) return null;
	index = dc.indexOf("=", index) + 1;
	var endstr = dc.indexOf(";", index);
	if (endstr == -1) endstr = dc.length;
	return unescape(dc.substring(index, endstr));
}

// Function to remember which navigation header was open.
function setNavigation()
{
	var navitem = getCookie("CNP");
	if (navitem > "") SwitchMenu(navitem);
}

// Function to auto-set navigation based on page prefix.
function openNavigation(page) {
	var navObj = 'sub2';
	var x = 0;
	for (x=0; x < pageSections.length; x++) {
		if (page.search(pageSections[x]) > 0) {
			navObj = pageNavTiers[x];
			document.cookie="CNP="+navObj+"; path=/";
		}
	}
}

// call the function to reset the nav bar.
// see the image load at the end of the navigation list (line 131).

/********************************************************/
/* THIS JAVASCRIPT ABOVE OPENS AND CLOSES THE NAVIGATION*/
/********************************************************/