// JavaScript Document
// This script takes any HTML element and determines whether they should be visible or hidden

addLoadEvent(dynDisplay);

function dynDisplay() {	
	var data = document.getElementById("faqs");
	var container = document.getElementById("javaLinks");

	var aLink = document.createElement("a"); //Create Show / Hide Link
		aLink.href = "#";
		aLink.id = "showHide";
		aLink.onclick = function() {
			display(document.getElementById("faqs"), this);
			return false;
		}
	aLink.appendChild(document.createTextNode("Hide All"));
	var div = document.createElement("div");
		div.style.float = "left";
		div.style.display = "inline";
	div.appendChild(aLink);
	container.appendChild(div);
	
	display(data, aLink);
	
	aLink = document.createElement("a"); // Create Printer Friendly Link
		aLink.href = "#";
		aLink.id = "sendToPrint";
		aLink.onclick = function() {
			printList('SettlementPost&Beam.com | FAQs', 'faqs');
			return false;
		}
	aLink.appendChild(document.createTextNode("Printer Friendly"));
	div = document.createElement("div");
		div.style.float = "right";
		div.style.display = "inline";
	div.appendChild(aLink);
	container.appendChild(div);;
}

function setupLink(l) {
	l.onclick = function () {
		showHide(this);
		return false;
	}
}

function showHide (child) {
	var parent = child.parentNode;
	var divs = parent.getElementsByTagName("div");
	var state = "";
	for (var i=0; i < divs.length; i++) {	
			state = divs[i].style.display;
		if (state == "none") 
			divs[i].style.display = "block";
		else
			divs[i].style.display = "none";
	}
}

function display(nodes, a) {
	if (a.firstChild.nodeValue == "Show All") {
		setDisplay(nodes, "block");
		a.firstChild.nodeValue = "Hide All";
		return;
	}
	
	setDisplay(nodes, "none");
	a.firstChild.nodeValue = "Show All";
	
	function setDisplay(n, d) {
		if (n.nodeType == 1) {
			if (n.tagName == "DIV")
				n.style.display = d;
			else if (n.tagName == "A" && n.parentNode.className == "question")
				setupLink(n);
				
		for (var m = n.firstChild; m != null; m = m.nextSibling)
			setDisplay(m, d);
		}
		return;
	}
}