var theSuffix = "_Answer";
var theSelectedClass = "Current";
var theQuestionsContainer = "Questions";
var theAnswersContainer = "Answers";

function addOnloadEvent(theFunction) {

	if (typeof window.addEventListener != "undefined") {
		window.addEventListener("load", theFunction, false);

	} else {

		if (typeof window.attachEvent != "undefined") {
			window.attachEvent("onload", theFunction);

		} else {

			if (window.onload != null) {
				var OldLoad = window.onload;

				window.onload = function (e) {
					OldLoad(e);
					window[theFunction]();

				};

			} else {
				window.onload = theFunction;

			}

		}

	}

}

function getElementByDocumentSupport(theID) {

	if (!theID.nodeName) {

		if (typeof document.getElementById != "undefined") {
			return document.getElementById(theID);

		} else {

			if (typeof document.layers != "undefined") {
				return document.theID;

			} else {
				return document.all.theID;

			}

		}

	} else {
		return theID;

	}

}

function getElementsByTagSupport(theTag, thePrefix) {
	thePrefix = (typeof thePrefix != "undefined") ? ((!thePrefix.nodeName) ? getElementByDocumentSupport(thePrefix) : thePrefix) : document;

	if (typeof document.getElementsByTagName != "undefined") {
		return thePrefix.getElementsByTagName(theTag);

	} else {

		if (typeof document.all != "undefined") {
			return thePrefix.all.tags(theTag);

		} else {
			return thePrefix.tags.theTag;

		}

	}

}

Array.prototype.in_array = function(theValue) {

	for (var i = 0; i < this.length; i++) {

		if (this[i] == theValue) {
			return true;

		}

	}

	return false;

};

function loadPage() {
	getElementByDocumentSupport(theAnswersContainer).style.display = "none";
	var theQuestions = getElementsByTagSupport("a", theQuestionsContainer);

	for (var i = 0; i < theQuestions.length; i++) {

		if (theQuestions[i].nodeName) {

			if (theQuestions[i].href.indexOf("#") != -1) {

				theQuestions[i].onclick = function() {
					return toggleAnswer(this);

				};

				theQuestions[i].onkeypress = function() {
					return toggleAnswer(this);

				};

			}

		}

	}

	window.AnswerDivs = new Array();
	var answerNodes = getElementByDocumentSupport(theAnswersContainer).childNodes;

	if (typeof Array.prototype.push != "function") {

		Array.prototype.push = function(theValue) {
			this[this.length] = theValue;

		};

	}

	for (var j = 0; j < answerNodes.length; j++) {

		if (answerNodes[j].nodeName == "DIV" && answerNodes[j].getAttribute("id") != null) {
			window.AnswerDivs.push(answerNodes[j].getAttribute("id"));

		}

	}

}

function toggleAnswer(theElement) {
	if (!theElement.nodeName) {
		theElement = getElementByDocumentSupport(theElement);

	}

	var theAnswer = theElement.href.substring(theElement.href.indexOf("#") + 1);

	if (window.AnswerDivs.in_array(theAnswer)) {
		var pseudoAnswer = new Object;
		var theQuestions = getElementsByTagSupport("a", theQuestionsContainer);
		var isCurrent = (theElement.className.indexOf(theSelectedClass) != -1) ? true : false;

		for (var i = 0; i < theQuestions.length; i++) {

			if (theQuestions[i].nodeName) {

				if (theQuestions[i].className.indexOf(theSelectedClass) != -1 && theQuestions[i].href.indexOf("#") != -1) {
					pseudoAnswer = getElementByDocumentSupport(theQuestions[i].href.substring(theQuestions[i].href.indexOf("#") + 1) + theSuffix);

					if (pseudoAnswer.nodeName) {
						theQuestions[i].parentNode.removeChild(pseudoAnswer);

					}

					theQuestions[i].className = theQuestions[i].className.replace((theQuestions[i].className.match(" " + theSelectedClass)) ? " " + theSelectedClass : theSelectedClass, "");

				}

			}

		}

		if (isCurrent != true) {
			var theContainer = new Object;
			theAnswer = getElementByDocumentSupport(theAnswer);
			theContainer = document.createElement("div");
			theContainer.setAttribute("id", theAnswer.id + theSuffix);
			if (navigator.appName == "Microsoft Internet Explorer") {
				// Detect IE
				theContainer.setAttribute("className", "boxFAQ");
			}
			else {
				// All Other Browsers
				theContainer.setAttribute("class", "boxFAQ");
			}
			theContainer.innerHTML = theAnswer.innerHTML;
			theElement.parentNode.appendChild(theContainer);
			theElement.className += (theElement.className) ? " " + theSelectedClass : theSelectedClass;

		}

		return false;

	} else {
		return true;

	}

}

addOnloadEvent(loadPage);