/*
 * Copyright (c) 2014 Robert Entrican, All Rights Reserved.
 *
 * All Rights Reserved.  Unpublished rights reserved under
 * the copyright laws of the United States.
 *
 * The software contained on this media is proprietary to
 * and embodies the confidential technology of Robert Entrican
 * Possession, use, duplication or dissemination of
 * the software and media is authorized only pursuant to
 * a valid written license from Robert Entrican.
 *
 * RESTRICTED RIGHTS LEGEND  Use, duplication, or disclosure
 * by the U.S. Government is subject to restrictions as set
 * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013,
 * or in FAR 52.227-19, as applicable.
 *
 */

/************************************************************************/
/*      Function:       fnAddLoadEvent                                  */
/*                                                                      */
/*      Summary:        Connect a load function to be invoked on load.  */
/*                      Please NOTE: This code will NOT get run if you  */
/*                      manually register a body onload function.       */
/*                                                                      */
/************************************************************************/
function fnAddLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
    window.onload =	function()
					{
						oldonload();
						func();
				    };
  }
}

/************************************************************************/
/*      Function:       fnBindHints                                     */
/*                                                                      */
/*      Summary:        Search the active document for input fields     */
/*                      and bind tooltips to them.                      */
/*                                                                      */
/************************************************************************/

function fnBindHints()
{
	var inputs = document.getElementsByTagName("input");

	for (var i=0; i<inputs.length; i++)
	{
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0])
		{
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function ()
								{
									this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
								};
								
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}

	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	
	for (var k=0; k<selects.length; k++)
	{
		if (selects[k].parentNode.getElementsByTagName("span")[0])
		{
			selects[k].onfocus =	function ()
									{
										this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
									}

			selects[k].onblur = function ()
								{
									this.parentNode.getElementsByTagName("span")[0].style.display = "none";
								}
		}
	}
}


/* Call the routine to register the event handler with a reference to the
** tooltip Binding func.
*/

	fnAddLoadEvent(fnBindHints);
