//-- ----------------------------------------------------------------------------------------------------
//-- NAME: FAQ-Utilities.js
//-- ABSTRACT: Utilities to be used with /Contents/Support/Documentation/FAQ pages.  It is used mainly
//--		   Show and hide the FAQ answers.  The FAQ must be well formed as stated by the following
//--		   markup:  <ol class='clsFAQ'><li><h4>QUESTION</h4><div>ANSWER</div></li></ol>
//--
//--	       * These scripts rely on functions in Client-Utilities-1.js
//--
//-- AUTHOR: Brian van Loveren Geis
//-- DATE: 02-10-08
//-- ----------------------------------------------------------------------------------------------------

//-- ----------------------------------------------------------------------------------------------------
//-- CONSTANTS
//-- ----------------------------------------------------------------------------------------------------


//-- ----------------------------------------------------------------------------------------------------
//-- Variables
//-- ----------------------------------------------------------------------------------------------------



	// -------------------------------------------------------------------------
	//  Name: InitializeFAQ
	//  Abstract:  Find and hide all FAQ answers.  The answer should be inside a
	//             div that is after a h4 that is inside a li of the ol.  ie.
	//             <ol class='clsFAQ'><li><h4>QUESTION</h4><div>ANSWER</div></li></ol>
	// -------------------------------------------------------------------------
      function InitializeFAQ()
      {
      	try
		{
			var aolLists = 0;
			var liFAQs = 0;
			var intIndex = 0;
			var intListItemIndex = 0;
			var h4Question = 0;
			var divAnswer = 0;
					    
			// Get get all ordered lists
			aolLists = document.getElementsByTagName('ol');
					    
			// Loop through the ordered lists
			for( intIndex = 0; intIndex < aolLists.length; intIndex++ )
			{ 
				// Is this a FAQ?
				if( aolLists[intIndex].className=='clsFAQ' )
				{
					// Yes, get all of it's LI elements
					liFAQs = aolLists[intIndex].getElementsByTagName('li');
					            
					// Did I get them?
					if( liFAQs )
					{
						// Yes, loop through them
						for( intListItemIndex = 0; intListItemIndex < liFAQs.length; intListItemIndex++ )
						{
							// Get the answer ( which is in the h4 tag.  Should be the only one. )
						      h4Question = liFAQs[intListItemIndex].getElementsByTagName('h4');
					                    
						      // Did I find it?
						      if( h4Question.length > 0 )
						      {
						      	// Yes, get the answer div
						            divAnswer = h4Question[0].nextSibling;
					                        
						            // Is this the DIV? ( Firefox does not skip white space text nodes like IE does )
				            	      if( divAnswer.nodeName.toUpperCase() != 'DIV' )
				                  		divAnswer = divAnswer.nextSibling;
				                                
					                  // Hide the answer
					                  divAnswer.style.display='none';
						       }
						}
					}
				}
			}
            }
            catch( expError )
		{
			// Format and display the error
			alert( BuildExceptionMessage( expError, "FAQ-Utilities-1.js", "InitializeFAQ" ) );
		}
	} // InitializeFAQ


	// -------------------------------------------------------------------------
      //  Name: ToggleFAQAnswerDisplay
	//  Abstract:  Show/Hide a given question's answer section.  The given element
	//             Should be immediately before the DIV that holds the answer.
	// -------------------------------------------------------------------------
	function ToggleFAQAnswerDisplay( h4Question )
	{
		try
		{
			var divAnswer = 0;
    				    
			// Get the questions next sibling.  ( Should be right after it )
			divAnswer = h4Question.nextSibling;
    				    
			// Is this the DIV? ( Firefox does not skip white space text nodes like IE does )
			if( divAnswer.nodeName.toUpperCase() != 'DIV' )
				divAnswer = divAnswer.nextSibling;
    				        
                  // Can we see the Answer?
                  if( divAnswer.style.display.toUpperCase() != 'BLOCK' && divAnswer.style.display.length > 0 )
                  	divAnswer.style.display='block';    // No, show it
                  else
                  	divAnswer.style.display='none';     // Yes, hide it
            }
            catch( expError )
		{
			// Format and display the error
			alert( BuildExceptionMessage( expError, "FAQ-Utilities-1.js", "ToggleFAQAnswerDisplay" ) );
		}	
                        
	} // ToggleFAQAnswerDisplay
