//---------------------------------------------------------------------------------//
// HELP LAYER                                                                      //
//---------------------------------------------------------------------------------//
// Creates a floating div from help text                                           //
//---------------------------------------------------------------------------------//

var helpLayerTimer						= 250;	// milisecond deley before the layer is displayed
var	helpLayerTimerId					= 0;
var helpLayerId								= '';
var helpLayerOffset_x					= 0;		// x position of layer relative to mouse pointer
var helpLayerOffset_y					= -10;	// y position of layer relative to mouse pointer
var mousePosition_x						= 0;		// Use a generic variable names for mouse position 		
var mousePosition_y						= 0;		// so pointerLayer events continue to function
var initialMousePosition_x		= 0;		// Use a generic variable names for mouse position 		
var initialMousePosition_y		= 0;		// so pointerLayer events continue to function
var initialPositionTolerance	= 10;		// How much the mousePosition can be from initialMousePosition

initHelpEvents ( );

//---------------------------------------------------------------------------------//
function initHelpEvents ( )
//---------------------------------------------------------------------------------//
{
	// window.onload is a fudge to disable xc2 calendar and get pointer layer working
	// when the the calendar and form2db javascript are included in the same page
	
	window.onload			= ''; 
	document.onmousemove	= getHelpMousePos;

	if ( document.captureEvents )
	{
		document.captureEvents ( Event.MOUSEMOVE );
	}
}


//---------------------------------------------------------------------------------//
function getHelpMousePos ( e )
//---------------------------------------------------------------------------------//
{
	// Get event object for IE
	if ( !e ) { e = window.event }
	
	if ( e.pageX )
	{
		// Mouse position relative to the whole document
		mousePosition_x = e.pageX;
		mousePosition_y = e.pageY;
	}
	else
	{
		mousePosition_x = document.documentElement.scrollLeft + e.clientX;
		mousePosition_y = document.documentElement.scrollTop + e.clientY;
	}
}

//---------------------------------------------------------------------------------//
function showHelpLayer ( id )
//---------------------------------------------------------------------------------//
{
	stopHelpLayerTimer ( );

	// Store the initial mouse position once we're over the
	// element that activate the helplayer
	initialMousePosition_x	= mousePosition_x;
	initialMousePosition_y	= mousePosition_y;

	helpLayerId							= id;
	helpLayerTimerId				= setTimeout ( "displayHelpLayer ( ) ", helpLayerTimer );
}

//---------------------------------------------------------------------------------//
function hideHelpLayer ( )
//---------------------------------------------------------------------------------//
{
//	if (navigator.appName != "Microsoft Internet Explorer")
		noDisplayHelpLayer ( );	
} 

//---------------------------------------------------------------------------------//
function hideHelpLayerIE ( )
//---------------------------------------------------------------------------------//
// Use with onMouseLeave to ensure IE hides the layer if onMouseOut fails
//---------------------------------------------------------------------------------//
{
	if ( navigator.appName == "Microsoft Internet Explorer" )
	{
		noDisplayHelpLayer ( );
	}
} 

//---------------------------------------------------------------------------------//
function displayHelpLayer ( )
//---------------------------------------------------------------------------------//
{
	if ( mousePosition_x > ( initialMousePosition_x - initialPositionTolerance ) &&
			 mousePosition_x < ( initialMousePosition_x + initialPositionTolerance ) &&				
			 mousePosition_y > ( initialMousePosition_y - initialPositionTolerance ) &&				
			 mousePosition_y < ( initialMousePosition_y + initialPositionTolerance )
		)
	{
		obj					= document.getElementById ( helpLayerId );
		obj.style.index			= '2';
		obj.style.position	= 'fixed';
		obj.style.display		= 'block';
		obj.style.zIndex		= '99'; /* Make sure it displays on top of any other elements */

		int_left	= mousePosition_x + helpLayerOffset_x - document.documentElement.scrollLeft - obj.offsetWidth;
		int_top		= mousePosition_y + helpLayerOffset_y - document.documentElement.scrollTop /* - obj.offsetHeight */;

		obj.style.left	= int_left + 'px';
		obj.style.top		= int_top + 'px';
/*
		alert ( 'style.left should be : ' + int_left + '\n' +
						'style.top should be : ' + int_top 
						);

		alert ( 'object : ' + helpLayerId + '\n' +
						'mousePosition_x : ' + mousePosition_x + '\n' +
						'mousePosition_y : ' + mousePosition_y + '\n' +
						'helpLayerOffset_y : ' + helpLayerOffset_y + '\n' +
						'helpLayerOffset_x : ' + helpLayerOffset_x + '\n' +
						'initialMousePosition_x : ' + initialMousePosition_x + '\n' +
						'initialMousePosition_y : ' + initialMousePosition_y + '\n' +
						'style.left : ' + obj.style.left + '\n' +
						'style.top : ' + obj.style.top + '\n' +
						'offsetWidth : ' + obj.offsetWidth + '\n' +
						'position : ' + obj.style.position   + '\n' +				  
						'offsetHeight : ' + obj.offsetHeight + '\n'
					 );
*/
	}
}

//---------------------------------------------------------------------------------//
function noDisplayHelpLayer ( )
//---------------------------------------------------------------------------------//
{
	if ( helpLayerId )
	{
		obj								= document.getElementById ( helpLayerId );
		obj.style.index		= '0';
		obj.style.display	= 'none';
	}

	stopHelpLayerTimer ( );
} 

//---------------------------------------------------------------------------------//
function stopHelpLayerTimer ( )
//---------------------------------------------------------------------------------//
{
	if ( helpLayerTimerId != 0 )
	{
		clearTimeout ( helpLayerTimerId );
		helpLayerTimerId = 0;
	}
}

//---------------------------------------------------------------------------------//
function hideShowSelectsInIE ( str_form )
//---------------------------------------------------------------------------------//
{
	if ( navigator.appName == "Microsoft Internet Explorer" )
	{
		for ( i = 0; i < document.forms.length; i++ ) 
		{
			if ( document.forms[i].id == str_form )
			{
				var selectNodeList	= document.forms[i].getElementsByTagName ( "SELECT" );
	
				for ( var j = 0; j < selectNodeList.length; j++ )
				{
					// Get an individual node
					var selectNode = selectNodeList.item ( j );				
		
					selectNode.style.visibility = ( selectNode.style.visibility == 'hidden' ? 'visible' : 'hidden' );
				}
			}
		}
	}
}

