// : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// :
// :	Project : ControlHelp System
// :	File	: helpControl.js
// :	Date	: 23/12/2003
// :
// :	Author	: Paul Thomas
// :
// :	Description
// :
// :	This Class manages a single help topic list. 
// :	The class requires three DIV elements:
// :				
// :				1/. Title = It places the topci title in this div.
// :				2/. TopicList = This is where it lists the available topics for display 
// :				3/. Topic Pane = The selected topic text is displayed here.
// :
// :	Each Topic Item should be stored in an Array element containing the following properties
// :
// :				ListTitle (string) = This is the text used to display the item in the element pane.
// :				Title (string) = This is the Title when the Item is displayed.
// :				Text (string) = The text of the topic item to display.
// :
// :
// :	Sample Code
// :
// :
// :	Here is a sample for creating a help panel
// :
// :
// :
// :		<script language="javascript">
// :
// :		var arrTopics = new Array();
// :
// :		arrTopics[0] = new helpTopic("", "Testing", "This text is here to help the user <b>determine</b> how usefule the help text is");
// :		arrTopics[1] = new helpTopic("", "More Help", "This text is <b>here to help</b> the user determine how usefule the help text is");
// :		arrTopics[2] = new helpTopic("", "Another Topic", "This text is here to help the user <b>determine how</b> usefule the help text is");
// :		arrTopics[3] = new helpTopic("List Test", "More Topic", "<b>This text is here to help the user determine how</b> usefule the help text is");
// :		arrTopics[4] = new helpTopic("", "Last one", "This text  <b>is here to help the user determine how</b> useful the help text is");
// :
// :		function helpTopic(sListDisplay, sTitle, sText)
// :		{
// :			this.ListTitle = (sListDisplay == "") ? sTitle : sListDisplay;
// :			this.Title = sTitle;
// :			this.Text = sText;
// :		}
// :
// :		var objHelp;
// :
// :		function initialise()
// :		{
// :			objHelp = new helpControl("objHelp", "Help1", "controltitle", "topic_pane", "topic", "my text", arrTopics);
// :		}
// :		
// :		</script>
// :		
// :
// :
// :
// : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function helpControl(sObjectName, sTopicTitle, sTopicTitlePane, sTopicListPane, sTopicPane, sDefaultText, arrTopics)
{
	// Private values
	// This is used when creating Hyperlinks etc. So the link can refer directly to the object
	var _objectName = sObjectName; 
	// The name of the help topic list
	var _topicTitle = sTopicTitle;
	// The Id of the Title DIV 
	var _topicTitlePane = sTopicTitlePane;
	// The Id of the topic list DIV
	var _topicList = sTopicListPane;
	// The Id of the Topic display DIV
	var _topicPane = sTopicPane;
	// The Array containing Topic Data
	var _topicData = arrTopics;
	// The Default Display Text
	var _defaultText = sDefaultText;
	var _activeTopic = (sDefaultText.length > 0) ? -1 : 0;
	
	// public properties
	this.objectName = _objectName;
	this.topicTitle = _topicTitle;
	this.titlePane = _topicTitlePane;
	this.topicList = _topicList;
	this.topicPane = _topicPane;
	this.topicData = _topicData;
	this.activeTopic = _activeTopic;
	
	// Functions
	this.setTopic = _setTopic;
	this.loadMenu = _loadMenu;
	this.setControlTitle = _setControlTitle;
	this.setDefaultTopicText = _setDefaultTopicText;
	
	// Init Code
	this.loadMenu();
	this.setTopic(this.activeTopic);
	this.setDefaultTopicText();
	this.setControlTitle();
	
	function _setTopic(iTopic)
	{
		if(iTopic == -1) 
		{	
			return;
		}
	
		var objTopic = document.getElementById(this.topicPane);
		
		if(objTopic != undefined)
		{
			var sOutput = "";
			
			sOutput += "<p class=\"topic_title\">" + this.topicData[iTopic].Title + "</p>";
			sOutput += "<p>" + this.topicData[iTopic].Text + "</p>";
			
			objTopic.innerHTML = sOutput;
			
			this.activeTopic = iTopic;
		}
		
		// If we have less than 100 topics we reload
		if(this.topicData.length < 100)
		{
			this.loadMenu();
		}
	}
	
	function _loadMenu()
	{
		var sOutput = "";
		
		var objTopics = document.getElementById(this.topicList);
		
		//alert("Array Length " + arrItems.length);
		
		if(objTopics != undefined)
		{
		
			for(iLoop = 0; iLoop < this.topicData.length; iLoop++)
			{
				if(iLoop != this.activeTopic)
				{
					sOutput += "<a onclick=\"Javascript:" + this.objectName + ".setTopic(" + iLoop + ")\">" + this.topicData[iLoop].ListTitle + "</a><br/>";
				}
				else
				{
					sOutput += this.topicData[iLoop].ListTitle + "<br/>";
				}
			}
			
			objTopics.innerHTML = sOutput;
		
		}	
	}
	
	function _setControlTitle()
	{
		var objTitle = document.getElementById(this.titlePane);
		
		if(objTitle != undefined)
		{
			objTitle.innerHTML = this.topicTitle;
		}
	}

	function _setDefaultTopicText()
	{
		var objTopic = document.getElementById(this.topicPane);
		
		if(objTopic != undefined)
		{
			objTopic.innerHTML = sDefaultText;	
		}
	}
	

}

