function expandTopic(topicid) {
	var topicName = getTopicText(topicid);
	var aTopicID = 0;
	var theHTML = "";
	var numQuestions = 0;
	var theDiv = getMyElementByID( "topicQuestions" );
	
	if ( theDiv ) {
		for ( var qrow=0; qrow<rsQuestions.getRowCount(); qrow++ ) {
			if ( rsQuestions.getField( qrow, "topicid" ) == topicid ) {
				numQuestions = numQuestions+1;
				theHTML +=
					"<div id=\"question" + rsQuestions.getField( qrow, "questionid" ) + "\">" +  
						"<p>" +
							"<a href=\"javascript:void(0);\" onclick=\"showAnswer( " + rsQuestions.getField( qrow, "questionid" ) + " );\">" + 
								rsQuestions.getField( qrow, "question" ) +	
							"</a>" + 
						"</p>" +
					"</div>";
			}
		}
		
		if ( numQuestions < 1 )
			theHTML = "<h2>There are no questions in the system about " + topicName + "</h2>";
		else
			theHTML = 
				"<h2 style=\"margin-top: 40px;\">Questions about " + topicName + "</h2>" +
				"<div align=\"center\" class=\"pageContent\" style=\"width: 660px;\">" + theHTML + "</div>";

		theDiv.innerHTML = theHTML;
	}
}

function showAnswer(questionid) {
	if ( questionid > 0 )
		DWREngine._execute(ajaxComponentPath + "faq.cfc", null, 'getAnswer', questionid, showAnswerResult);
	else
		clearTopicQuestions();
}

function showAnswerResult(result) {
	var questionID = 0;
	var theDiv;
	var theHTML = "";

	if ( result.getRowCount() > 0 ) {
		// Without a recordset, the div cannot be found because there's no question ID.
		// So, don't try to display anything

		questionID = result.questionid[0];
		theDiv = getMyElementByID( "question" + questionID );

		if ( theDiv ) {
			theHTML = 
				"<div style=\"border:1px solid black; background-color: white; margin: 10px; padding: 5px 10px;\">" + 
					"<p style=\"font-weight:bold;\">" + getQuestionText(questionID) +	"</p>";
	
			for ( var i=0; i<result.getRowCount(); i++ )
				theHTML += "<p>" + result.answer[i] + "</p>";
	
			theHTML +=
					"<div style=\"text-align:right;\">" +
						"<a href=\"javascript:void(0);\" onclick=\"hideAnswer( " + questionID + " );\" style=\"font-size: 3mm;\">Hide this answer</a>" +
					"</div>" + 
				"</div>";
	
			theDiv.innerHTML = theHTML;
		}
	}
}

function hideAnswer(questionID) {
	var theHTML = "";
	var theDiv = getMyElementByID( "question" + questionID );
	
	if ( theDiv ) {
		theHTML = 
			"<a href=\"javascript:void(0);\" onclick=\"showAnswer( " + questionID + " );\">" + 
				getQuestionText(questionID) +	
			"</a>";

		theDiv.innerHTML = theHTML;
	}
}

function clearTopicQuestions() {
	var myElement = getMyElementByID( "topicQuestions" );
	
	if ( myElement )
		myElement.innerHTML = "";
}

function getQuestionText(questionID) {
	var returnValue = "";

	for (var qrow=0; qrow<rsQuestions.getRowCount(); qrow++)
		if ( rsQuestions.getField( qrow, "questionid" ) == questionID ) {
			returnValue = rsQuestions.getField( qrow, "question" );
			break;
		}

	return returnValue;
}

function getTopicText(topicID) {
	var returnValue = "";

	for ( var trow=0; trow<rsTopics.getRowCount(); trow++ )
		if ( rsTopics.getField( trow, "topicid" ) == topicID ) {
			returnValue = rsTopics.getField( trow, "topic" );
			break;
		}

	return returnValue;
}

