// JavaScript Document

function getParentElement(currentElement, nodeType) {
	currentElement=currentElement.parentNode; // get the parent of the passed node
	while (currentElement!=null) {	// while a parent can be found
		if (currentElement.nodeName.toUpperCase()==nodeType.toUpperCase()) { // if the element's node name matches the node type we're looking for
			return currentElement; // return the node
		}
		currentElement=currentElement.parentNode; // get the next parent
	}
	return null; // if nothing was found, return null
}

function getChildElementByClass(parentElement, nodeType, nodeClass) {
	elementArray = parentElement.getElementsByTagName(nodeType); // get all child nodes that of the requested node type
	for(arrayKey in elementArray) { // move through that array, getting each key
		currentElement = elementArray[arrayKey]; // get the current element from the element array at position arrayKey
		if (typeof currentElement  == "object") { // only pay attention to objects - ignore info about the array
			if (currentElement.className) { // make sure the current object has a class name
				if (currentElement.className.toUpperCase() == nodeClass.toUpperCase()) { // if the current object's class name matches the class name we are looking for
					return currentElement; // return the current object
				}
			}
		}
	}
	return null; // if nothing was found, return null
}

function complexToggleFAQ(targetElement) {
	parentDiv = getParentElement(targetElement, "div"); // get the first parent div
	if (parentDiv!=null) { // assuming we can find one
		answerNode = getChildElementByClass(parentDiv, "a", "answer"); // get it's first child of node type "a" and class name "answer"
		if (answerNode!=null) { // assuming we can find one
			currentDisplayStyle = answerNode.style.display; // get it's display style
			if (currentDisplayStyle.indexOf("none") == -1) { // check to see if the word "none" can be found anywhere in the display style
				answerNode.style.display = "none"; // if it can't, change the display style to "none"
				parentDiv.className = "faq_closed"; // change the parentDiv class name to "faq_closed"
			} else {
				answerNode.style.display = "block"; // change the parentDiv class name to "faq_open"
				parentDiv.className = "faq_open";
			}
		} else {
			alert("toggleFAQ: answerNode could not be found.");
		}
	} else {
		alert("toggleFAQ: parentDiv could not be found.");
	}
}

function toggleFAQ(targetElement) {
	parentDiv = getParentElement(targetElement, "div"); // get the first parent div
	if (parentDiv!=null) { // assuming we can find one
		if (parentDiv.className.indexOf("faq_closed") == -1) { // check to see if the word "faq_closed" can be found anywhere in the current class name
			parentDiv.className = "faq_closed"; // change the parentDiv class name to "faq_closed"
		} else {
			parentDiv.className = "faq_open"; // change the parentDiv class name to "faq_open"
		}
	} else {
		alert("toggleFAQ: parentDiv could not be found.");
	}
}

