// ==========================================================
// getElementsByClassName
// ==========================================================
// define a function to allow us to get elements by className

document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i=i+1) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

/* this swaps out the plus/minus signs to visually indicate if a row can be expanded or contracted */
function plusMinus(moreLess) {  // receives self-reference from cell that needs to be changed
	if (moreLess.innerHTML == 'more') { // check if plus is displayed
		//alert('plus!');
		moreLess.innerHTML = 'less' // if so, change to minus
	}
	else {
		moreLess.innerHTML = 'more'
		//alert('minus!');
	}
}

/* this shows and hides table rows in the search results table. it receives the id of the table row to be hidden as an argument */
function toggle(whichSection) {
/*alert(whichSection)*/
 var thisOne = document.getElementById(whichSection) // assign row to a varaiable for easy reference
 if(thisOne.style.display=='none' ){ // check if row is currently hidden
   thisOne.style.display = 'block'; // if so, unhide
 }else{
   thisOne.style.display = 'none'; // if not, hide it
 }
}

function expandAllSections() {
	 var allExpandables = document.getElementsByClassName('expandable');
	
	for (i=0; i<allExpandables.length; i=i+1) {
  			allExpandables[i].style.display = "block";
  	}
  	
  	var plusMinusContainers = document.getElementsByClassName('plusMinus');
		//alert(plusMinusContainers.length);
			for (var j = 0; j < plusMinusContainers.length; j=j+1) {
			
				plusMinusContainers[j].innerHTML = 'less'
		}
	
	/*
	if (document.getElementById) {
		navRoot = document.getElementById('latestColumn');
		for (i=0; i<navRoot.childNodes.length; i++) {
  			node = navRoot.childNodes[i];
  			if (node.className=="panel") {
  				node.style.display = "block";
			}
		}
		
		tabRoot = document.getElementById('latestColumn');
		tabs = tabRoot.getElementsByTagName("a");
		for (i=0; i<tabs.length; i++) {
  			tab = tabs[i];
  			if (tab.className=="tab") {
  				tab.className = "tabOn";
			}
		}

		
	}*/
}

function collapseAllSections() {

	var allExpandables = document.getElementsByClassName('expandable');
	
	for (i=0; i<allExpandables.length; i=i+1) {
  			allExpandables[i].style.display = "none";
  	}
  	
  	var plusMinusContainers = document.getElementsByClassName('plusMinus');
		//alert(plusMinusContainers.length);
			for (var j = 0; j < plusMinusContainers.length; j=j+1) {
			
				plusMinusContainers[j].innerHTML = 'more'
		}


	/*if (document.getElementById) {
		navRoot = document.getElementById('latestColumn');
		for (i=0; i<navRoot.childNodes.length; i++) {
  			node = navRoot.childNodes[i];
  			if (node.className=="panel") {
  				node.style.display = "none";
			}
		}
		
		tabRoot = document.getElementById('latestColumn');
		tabs = tabRoot.getElementsByTagName("a");
		for (i=0; i<tabs.length; i++) {
  			tab = tabs[i];
  			if (tab.className=="tabOn") {
  				tab.className = "tab";
			}
		}
		
		var plusMinusContainers = document.getElementsByClassName('plusMinus');
		//alert(plusMinusContainers.length);
			for (var j = 0; j < plusMinusContainers.length; j++) {
			
				plusMinusContainers[j].innerHTML = 'more'
		}
	}*/
}


//NOTE: DUE TO ACCESSIBILITY CONCERNS, ALL SECTIONS ARE EXPANDED ON THE PAGE BY DEFAULT. THIS FUNCTION RUNS WHEN THE PAGE LOADS AND (ASSUMING THAT JAVASCRIPT IS ENABLED) COLLAPSES ALL SECTIONS EXCEPT FOR THE ONES SPECIFIED IN THE 'sectionsToOpen' ARRAY. TO KEEP SPECIFIC SECTIONS OPEN ON THE PAGE, SIMPLY ADD THE NUMBER OF THE SECTIONS THAT SHOULD STAY OPEN TO THIS ARRAY. NOTE THAT ONLY THE NUMBER OF THE ARRAY IS NEEDED - NOT IT'S FULL ID.
function collapseOnLoad() {
	
	collapseAllSections();

/*	sectionsToOpen = new Array('2', '8', '9', '10', '11', '16', '17');
	
	for (i = 0; i < sectionsToOpen.length; i++) {
		if (document.getElementById('section'+sectionsToOpen[i])) {
			document.getElementById('section'+sectionsToOpen[i]).style.display = "block";
			plusMinus(document.getElementById('expand'+sectionsToOpen[i]));
		}
	} */
}

	