/****************************************************************************/
/* Contractible Headers script - © Dynamic Drive (www.dynamicdrive.com)     */
/* This notice must stay intact for legal use. Last updated Mar 23rd, 2004. */
/* Visit http://www.dynamicdrive.com/ for full source code                  */
/****************************************************************************/

var	enablePersist="yes"     // yes/no - Enable saving state of content structure using session cookies?
var	collapsePrevious="no"  // yes/no - Collapse previously open content when opening present?

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	(t=0; t < allTags.length; t++) {
		if (allTags[t].className == className) {
			cCollect[inc++] = allTags[t]
		}
	}
}

function contractContent(omitId) {
	var	inc=0

	while (cCollect[inc]) {
		if (cCollect[inc].id != omitId) {
			cCollect[inc].style.display = "none"
		}
		inc++
	}
}

function expandContent(cid, focusid) {
	if ((typeof cCollect) != "undefined") {
		if (collapsePrevious == "yes") {
			contractContent(cid)
		}

		if (document.getElementById(cid).style.display != "block") {
		    document.getElementById(cid).style.display = "block"
		    if (focusid != null) {
                document.getElementById(focusid).focus()
                document.getElementById(focusid).select()
            }
    	} else {
    	    document.getElementById(cid).style.display = "none"
        }
	}
}

function reviveContent() {
	contractContent("omitnothing")
	selectedItem = getSelectedItem()
	selectedComponents = selectedItem.split("|")
	
	for	(c=0; c < selectedComponents.length - 1; c++) {
		document.getElementById(selectedComponents[c]).style.display = "block"
	}
}

function getCookie(Name) {	
	var	search = Name +	"="
	var	result = "";
	
	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
			}
			
			result = unescape(document.cookie.substring(offset, end))
		}
	}
	
	return result;
}

function getSelectedItem() {
	var result = ""
	
	if (getCookie(window.location.pathname) !=	""){
		selectedItem = getCookie(window.location.pathname)
		result = selectedItem
	}
	
	return result
}

function saveSwitchState() {
	var	inc = 0
	var selectedItem = ""
	
	while (cCollect[inc]){
		if (cCollect[inc].style.display == "block") {
			selectedItem += cCollect[inc].id + "|"
		}
		inc++
	}
	
	document.cookie = window.location.pathname + "=" + selectedItem
}

function doOnLoad() {
	uniqueidn = window.location.pathname + "firstTimeLoad"
	getElementbyClass("switchcontent")
	
	if ((enablePersist == "yes") && ((typeof cCollect) != "undefined")) {
		document.cookie = uniqueidn + "=" + ((getCookie(uniqueidn) == "") ? "1" : "0")
		firstTimeLoad = (getCookie(uniqueidn) == 1) ? 1 : 0 //check if this is 1st page load
		
		if (!firstTimeLoad) {
			reviveContent()
		}
	}
}

if (window.addEventListener) {
	window.addEventListener("load",	doOnLoad, false)
} else if (window.attachEvent) {
	window.attachEvent("onload", doOnLoad)
} else if (document.getElementById) {
	window.onload=doOnLoad
}

if ((enablePersist == "yes") && (document.getElementById)) {
	window.onunload=saveSwitchState
}