//////////////////////////////////////////////////////////////////////////////////////////
// Title		: doHelp()							{JavaScript Function},				//
//				  doFindContextHelp( currentTag )	{JavaScript Function}				//
// Description	: Binds itself to the document onhelp event. It will allow a web page	//
//				  to have context-sensitive help.										//
// Dependencies	: none																	//
// Exposes		: debug_state						{true | false},						//
//				  document.myShowHelp = doShowHelp	{JavaScript Function override}		//
// Date created	: 11.12.1998															//
// Date modified: 14.12.1998															//
// Author		: Warren McCormack (WHM)												//
//////////////////////////////////////////////////////////////////////////////////////////

function doHelp()
{
	window.event.returnValue = !doFindContextHelp( window.event.srcElement );
}
	
function doFindContextHelp( currentTag )
{
	var returnState	= true;
		
	// Debug ////////////////////////////////////////////////
	if( doFindContextHelp.debug_state == true )
	{
		if( window.top != window.self )
		{
			alert( "Hi I'm " + window.name );
		}
		else
		{
			alert( "Hi I'm " + window.document.title );
		}
			
		if( currentTag[ "contexthelp" ] == null )
		{
			alert( "contexthelp = null" );
		}
		else
		{
			alert( "contexthelp = " + currentTag[ "contexthelp" ] );
		}
			
		alert( "window source element tag name = " + currentTag.tagName );
	}
	/////////////////////////////////////////////////////////
		
	if( currentTag[ "contexthelp" ] == null )
	{
		while( currentTag.parentElement != null 
			&& currentTag[ "contexthelp" ] == null )
		{
			currentTag = currentTag.parentElement;
		}
			
		if( currentTag.parentElement == null )
		{
			if( window.self != window.top 
				&& parent[ "doFindContextHelp" ] != null )
			{
				//Pass control over to parent document
				returnState = parent.doFindContextHelp( parent.document.activeElement );
			}
			else
			{
				//No contextHelp text available
				returnState = false;
			}
		}
		else
		{
			document.myShowHelp( currentTag[ "contexthelp" ] );
		}
	}
	else
	{
		document.myShowHelp( currentTag[ "contexthelp" ] );
	}
		
	return returnState;
}

function doShowHelp( contextHelpTxt )
{
	window.showHelp( contextHelpTxt + ">Base02" );
	//window.showHelp( "mk:@MSITStore:D:\\Projects\\HTML\\Experiment\\CircFM.chm" + "::/" + contextHelpTxt + ">Base02" );
}
		
//////////////////////////////////////////////////////////////////////////////////////////
// Title		: doBtnHelpClick()														//
// Description	: Binds itself to the document onclick event. It will allow a web page	//
//				  to have a 'What's this?' form of help.								//
// Dependencies	: doFindContextHelp	{JavaScript function},								//
//				  btn_help			{button}											//
// Date created	: 12.12.1998															//
// Date modified: 15.12.1998															//
// Author		: Warren McCormack (WHM)												//
//////////////////////////////////////////////////////////////////////////////////////////

function doBtnHelpClick()
{
	var event_src = window.event.srcElement;

	// Normal event bubbling structure
	
	if( event_src.btnId != null && event_src.btnId == "btn_help" )
	{
		if( doBtnHelpClick.whats_this_state == true )
		{
			doBtnHelpClick.whats_this_state = false;
			document.body.style.cursor = "auto";
		}
		else
		{
			doBtnHelpClick.whats_this_state = true;
			document.body.style.cursor = "help";
		}
	}
	else
	{
		// All event bubbling handlers that rely on a previous event bubble
		
		if( doBtnHelpClick.whats_this_state == true )
		{
			doBtnHelpClick.whats_this_state = false;
			document.body.style.cursor = "auto";
			
			var returnState = doFindContextHelp( window.event.srcElement );
			
			if( returnState != true )
			{
				alert( "No help available" );
			}
		
			window.event.cancelBubble = true;
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////////////
// Title		: initHelp( myNewShowHelp )												//
// Description	: Initialises the Help functions.										//
// Dependencies	: doFindContextHelp	{JavaScript function},								//
//				  doBtnHelpClick	{JavaScript function},								//
//				  doHelp			{JavaScript function},								//
// Date created	: 14.12.1998															//
// Date modified: -																		//
// Author		: Warren McCormack (WHM)												//
//////////////////////////////////////////////////////////////////////////////////////////
	
function initHelp( myNewShowHelp )
{
	// Create function variables
	
	doFindContextHelp.debug_state = false;
	doBtnHelpClick.whats_this_state = false;
	
	// Declare user ShowHelp or default function for showing the help
	
	if( myNewShowHelp != null )
	{
		document.myShowHelp = myNewShowHelp;
	}
	else
	{
		document.myShowHelp = doShowHelp;
	}
	
	// Declare event binding 
	
	document.onhelp = doHelp;
	document.onclick = doBtnHelpClick;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Title		: doDebug( function_name, new_state )									//
// Description	: Sets the debug mode for a specified function to either true or false	//
// Dependencies	: doFindContextHelp.debug_state	{JavaScript attribute},					//
// Date created	: 14.12.1998															//
// Date modified: -																		//
// Author		: Warren McCormack (WHM)												//
//////////////////////////////////////////////////////////////////////////////////////////

function doDebug( function_name, new_state )
{
	switch( function_name )
	{
		case "doFindContextHelp" :
		{
			doFindContextHelp.debug_state = new_state;
			break;
		}
		default :
		{
			alert( "Message to developer : pass the function name across to enable debugging" );
		}
	}
}

function getHelpState()
{
	return doBtnHelpClick.whats_this_state;
}
