// function to hide all open biography divs
function hideFAQs(subCatID, questionID)
{
	// set array of all content divs
	var allDivs = document.getElementById("contentContainer").getElementsByTagName('div');

	var selectedCategory = null;
	var selectedQuestion = null;
	// loop through all content divs
	for (j in allDivs)
	{
		// set variables
		switch(allDivs[j].className)
		{
		    case "faqCategory":
		        // switch all faqCategory divs to closed status
		        allDivs[j].className = "faqCategory collapsed";
		        if (allDivs[j].getAttribute("name") == subCatID) {
		            selectedCategory = allDivs[j].getElementsByTagName('a')[0];
		        }
		        break;
		    case "faqQuestionGroup":
		        allDivs[j].style.display = "none";
		        break;
		    case "faqQuestion":
		        allDivs[j].className = "faqQuestion closed";
		        if (allDivs[j].getAttribute("name") == questionID) {
		            selectedQuestion = allDivs[j].getElementsByTagName('a')[0];
		        }
		        break;
		    case "faqAnswer":
		        allDivs[j].style.display = "none";
		        break;
		}
    }

    if (selectedCategory != null)
        showHideFAQ(selectedCategory);

    if (selectedQuestion != null)
        showHideFAQ(selectedQuestion);
    
}

// function to change visibility state of faqs
function showHideFAQ(calledFrom)
{
	// locate the parent container of the clicked link
	var theParent = calledFrom.parentNode;
	var theGrandParent = calledFrom.parentNode.parentNode;

	// if the clicked link is at category level
	if (theParent.className == "faqCategory" || theParent.className == "faqCategory collapsed")
	{
		// switch the display status of the clicked link
		switch(theParent.className)
		{
			case "faqCategory":
				theParent.className = "faqCategory collapsed";
				break;
			case "faqCategory collapsed":
				theParent.className = "faqCategory";
				break;
		}
		// loop through all child divs of parent
		for (j in theGrandParent.getElementsByTagName('div'))
		{
			// if the div has class of faqQuestionGroup
			if (theGrandParent.getElementsByTagName('div')[j].className == "faqQuestionGroup")
			{
				// switch the display status of the faqs
				switch(theGrandParent.getElementsByTagName('div')[j].style.display)
				{
					case "block":
						theGrandParent.getElementsByTagName('div')[j].style.display = "none";
						break;
					case "none":
						theGrandParent.getElementsByTagName('div')[j].style.display = "block";
						break;
				}
			}
		}
	}
	// else if the clicked link is at quesion level
	else if (theParent.className == "faqQuestion" || theParent.className == "faqQuestion closed")
	{
		// switch the display status of the clicked link
		switch(theParent.className)
		{
			case "faqQuestion":
				theParent.className = "faqQuestion closed";
				break;
			case "faqQuestion closed":
				theParent.className = "faqQuestion";
				break;
		}
		// loop through all child divs of parent
		for (j in theGrandParent.getElementsByTagName('div'))
		{
			// if the div has class of faqQuestionGroup
			if (theGrandParent.getElementsByTagName('div')[j].className == "faqAnswer")
			{
				// switch the display status of the faqs
				switch(theGrandParent.getElementsByTagName('div')[j].style.display)
				{
					case "block":
						theGrandParent.getElementsByTagName('div')[j].style.display = "none";
						break;
					case "none":
						theGrandParent.getElementsByTagName('div')[j].style.display = "block";
						break;
				}
			}
		}
	}
	// Blur the focus from the selected link
	calledFrom.blur();
}
