function toggleMenu(which) {

	var section = document.getElementById(which);
	if (!(section)) {
		alert ("No section to toggle: " + which);
		return;
	}
	if (section.style.display == 'none') {
		showSection(which);
	} else {
		hideSection(which);
	}
}

function hideSection(which){
	var section = document.getElementById(which);
	if (!(section)){
		alert ("No section " + which);
		return;
	}
	sectionWas = section.style.display;
	section.style.display = 'none';
	setCookie("leftNav" + which, "off","/");
}

function showSection(which){
	var section = document.getElementById(which);
	if (!(section))	{
		alert ("Tried to show non-existant section: " + which);
		return;
	}
	sectionWas = section.style.display;
	section.style.display = '';
	setCookie("leftNav" + which, "on","/");
}


// This function gets the leftNav cookie and opens all sections
//  of the left nav that are contained in it, closing the others
//  It should be called in the BODY onLoad event.
function displayMenu(){
	// cycle through cookies looking for leftNav ones
	var wholeCookie = document.cookie;
	var cookies = wholeCookie.split("; ");
	var cur = 0;
	var section="";
	var value="";
	for (x=0; x<cookies.length; x++ )	{
		var chunk = cookies[x];
		var crumbs = chunk.split("=");
		var pos = crumbs[0].indexOf("leftNav");
		if (pos>-1)	{
			section = crumbs[0].substring(7);
			value = trim(crumbs[1]);
			if (value=="on"){
				showSection(section);
			} else {
				hideSection(section);
			}
		}
	}
}


function debugClearCookie(){
	alert("Clearing cookie:" + document.cookie);
	deleteCookie("leftNavresearch");
	deleteCookie("leftNavinvestigators");
	deleteCookie("leftNavabout");
	alert("Cleared cookie?" + document.cookie);
}

function trim (string) {
	if ((string)) {
       return string.replace(/^\s+/,'').replace(/\s+$/,'');
    } 
   return "";
}
