/***********************************************
* Contractible Headers script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Mar 23rd, 2004.
* updated 3/21/07 IAM - Internet2 
	Added Image headers that change on click inside the expandcontent() and 
	on initialization for degration purposes. 
* Visit http://www.dynamicdrive.com/ for full original source code
***********************************************/

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

//names of the classes for the menuheader and expandable elements 
var menuheader = 'expandable'; //class="expandable" for each header span 
var expcontent = 'switchcontent';  //class="switchcontent" for each expanding span, in addition to id='sc1' 

//formatting variables (you could fill these in with text as well)
var imageclosed = '<img src="/includes/bw/images/gray-right-pointer1.gif" alt="+" />';
var imageopened = '<img src="/includes/bw/images/gray-right-pointer1-down.gif" alt="-" />';

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}
}

function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(cspan, cid){
if (typeof ccollect!="undefined"){
if (collapseprevious=="yes")
contractcontent(cid)
//document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
	if(document.getElementById(cid).style.display=="block"){ //it's open, so close it 
		document.getElementById(cid).style.display="none";
		var theSpan = cspan.getElementsByTagName("span");
		theSpan[0].innerHTML = imageclosed;		
	}
	else { //it's closed so open it
		document.getElementById(cid).style.display="block";
		var theSpan = cspan.getElementsByTagName("span");
		theSpan[0].innerHTML = imageopened;
	}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

//IAM version of the getElementbyClass function
function getByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//IAM function to close content one by one, ommiting 
//where i is the index+1 for the switch content header/content to leave open
function initialize(i) { 
i=i-1; //if 0 is passed in, the value becomes -1 and is never = to an index, thus '0' means no
//default open. Otherwise, passing in 1-n will default that element to be open (by not closing it) 
var menus= getByClass(menuheader); //the clickable headers for what closes and opens 
var contents = getByClass(expcontent); //the contents that correspond to the headers
var inc=0
while (menu[inc]){
	if (inc!=i) {
		var theSpan = menus[inc].getElementsByTagName("span");
		theSpan[0].innerHTML = imageclosed;
		document.getElementById(contents[inc].id).style.display="none"; 
	}
	inc++
} //end while
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass(expcontent) //the content that closes and opens
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
}


if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById) 
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate


