/*
<!---(INFORMATION)------------------------------------------------------
File:			          linktips.js
Author:			        Steve Walton -  Electric Edge Systems Group Inc.
Date Created:	  		February 27, 2006
Description:	      Functions related to linktips

Change History:
When		    Who	   What
-----------	-----  -----------------------------------------------------
---------------------------------------------------------------(End)--->
*/

/* Global variables */
var g_defaultTitle = "Information";
var g_objName = "popupDiv";
var g_overlayer = getObj(g_objName).style;
var g_offsetx = 10;        // the amount of space between the mouse and the linktip
var g_offsety = 10;        // the amount of space between the mouse and the linktip
var g_posx = 0;            // current mouse location
var g_posy = 0;            // current mouse location
var g_direction = "right"; // position of linktip relative to the mouse
var g_width = "200";       // max width of the linktip in pixels


// register the mouse event handler
document.onmousemove = mouseMove;
if (document.captureEvents)
  document.captureEvents(Event.MOUSEMOVE);


// **********************************************************************************
// Function: getObj
//
// Purpose: Get an object by it's id using either the web standard function
//           or older browser implementation functions
//
// Parameters: id - the id of the desired html element
//
// Returns: an html object
// *********************************************************************************
function getObj(id)
{
  var obj;
  
  // if modern browser
  if (document.getElementById)
  {
    obj = document.getElementById(id);
  }
  // try older IE function
  else if (document.all)
  {
    obj = document.all.item(id);
  }
    
  return obj;
}

// **********************************************************************************
// Function: displayElement
//
// Purpose: Set the visibility & display properties of a given object id
//          Used for cases where form elements could have same id (radio buttons, etc.)
//
// Parameters: id    - the id of the desired html element
//             state - indicate which state to set, or swap state if unspecified
//                     valid values: unspecified, 'show', or 'hide'
//             prop  - indicate which property to set, or both if unspecified
//                     valid values: unspecified, 'display', or 'visibility'
//
// Returns: nothing
// *********************************************************************************
function displayElement(id,state,prop)
{
  var element = getObj(id);

  if (element)
  {
    // if state was not specified, simply switch the state to it's opposite
    if(state==undefined || state==null)
    {
      // if property was not specified as 'display', set the visibility property
      if(prop==undefined || prop==null || prop!='display')
        element.style.visibility = (element.style.visibility == 'hidden') ? 'visible' : 'hidden';
  
      // if property was not specified as 'visibility', set the display property
      if(prop==undefined || prop==null || prop!='visibility')
        element.style.display = (element.style.display == 'none') ? 'block' : 'none';
    }
    else
    {
      // if property was not specified as 'display', set the visibility property
      if(prop==undefined || prop==null || prop!='display')
        element.style.visibility = (state == 'show') ? 'visible' : 'hidden';
  
      // if property was not specified as 'visibility', set the display property
      if(prop==undefined || prop==null || prop!='visibility')
        element.style.display = (state == 'show') ? 'block' : 'none';
    }
  }
}

// **********************************************************************************
// Function: moveIt
//
// Purpose: update the location of an object based on its calculated new top and left
//          adjust for direction and overall offset from indicated location
//
// Parameters: obj - the object we are repositioning
//             xL  - new position X
//             yL  - new position Y
//
// Written by: Steve Walton for Electric Edge Systems Group
// Date: Feb 27 2006
// *********************************************************************************
function moveIt(obj,xL,yL)
{
  var tipOffsetX = 0;
  var tipOffsetY = g_offsety;

  // determine the offset based on the direction  
  switch(g_direction)
  {
    case "center":
      tipOffsetX = g_offsetx - (g_width / 2);
      break;
    
    case "left":
      tipOffsetX = 0 - g_offsetx - g_width;
      break;
    
    case "right":
      tipOffsetX = g_offsetx;
      break;
      
    default: //no direction = no offset
      tipOffsetY = 0;
      break;
  }

  // update the objects location
  obj.left = xL + tipOffsetX;
  obj.top = yL + tipOffsetY;
}


// **********************************************************************************
// Function: mouseMove
//
// Purpose: event handler used to update positioning information
//          posX and posY will contain the mouse position relative to the document
//
// Parameters: m - mouse event object passed in by some browsers
//
// Written by: Steve Walton for Electric Edge Systems Group
// Date: Feb 27 2006
// *********************************************************************************
function mouseMove(m)
{
  // in case the event is not passed in, define it (IE)
  if (!m) var m = window.event;
	
  // use the browser supported properties
	if (m.pageX || m.pageY)
	{
		g_posx = m.pageX;
		g_posy = m.pageY;
	}
	else if (m.clientX || m.clientY)
	{
		g_posx = m.clientX + document.body.scrollLeft;
		g_posy = m.clientY + document.body.scrollTop;
	}
  
  // update the linktip location if the linktip is currently displayed
  if (g_overlayer.visibility == "visible")
    moveIt(g_overlayer, g_posx, g_posy);
}


// **********************************************************************************
// Function: showTip
//
// Purpose: show the linktip popup div
//
// Parameters: title - the title for the div
//             text  - the linktip text
//             dir   - a string indicating the direction
//
// Written by: Steve Walton for Electric Edge Systems Group
// Date: Feb 27 2006
// *********************************************************************************
function showTip(title,text,dir,width)
{
  var txt;
 
  // set the global direction
  if (arguments.length < 3)
    g_direction = "right";
  else
    g_direction = dir;
  
  // set the default width
  if (arguments.length < 4)
    width = g_width;  
  
  txt = '<div class="linktip" style="width: ' + width + 'px;"><div class="infoBody">' + text +
            '</div></div>';

  // set the position to the current mouse location
  moveIt(g_overlayer, g_posx, g_posy);
   
  // set the content into the div
  getObj(g_objName).innerHTML = txt;

  // make sure the div is visible
  displayElement(g_objName, 'show'); 

  return false;
}


// **********************************************************************************
// Function: hideTip
//
// Purpose: hide the linktip popup div
//
// Parameters: none
//
// Written by: Steve Walton for Electric Edge Systems Group
// Date: Feb 27 2006
// *********************************************************************************
function hideTip()
{
  // make sure the div is invisible
  displayElement(g_objName, 'hide');
   
  //showSelectBoxes();
  //showSelectBoxesPop();
  
  return false;
}
