//==========================================================
//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++) {
		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 == '+') { // check if plus is displayed
		//alert('plus!');
		moreLess.innerHTML = '-' // if so, change to minus
	}
	else {
		moreLess.innerHTML = '+'
		//alert('minus!');
	}
}

/* this swaps out the plus/minus signs to visually indicate if a row can be expanded or contracted */
function plusMinus2(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 variable 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++) {
			allExpandables[i].style.display = "block";
	}
	
	var plusMinusContainers = document.getElementsByClassName('plusMinus');
		//alert(plusMinusContainers.length);
			for (var j = 0; j < plusMinusContainers.length; j++) {
			
				plusMinusContainers[j].innerHTML = '-'
		}
	
}

function collapseAllSections() {

	var allExpandables = document.getElementsByClassName('expandable');
	
	for (i=0; i<allExpandables.length; i++) {
			allExpandables[i].style.display = "none";
	}
	
	var plusMinusContainers = document.getElementsByClassName('plusMinus');
		//alert(plusMinusContainers.length);
			for (var j = 0; j < plusMinusContainers.length; j++) {
			
				plusMinusContainers[j].innerHTML = '+'
		}


}

//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();

}

