/*
 * Javascript Common
 *
 * @author David Newman
 * @version 1.0.0
 * @copyright 2007 Codegate Ltd.
 *
*/

function highlightKeyword(str, keyword)
{
  if (str) return str.replace(new RegExp(keyword, 'g'), '<span class="highlight">'+keyword+'</span>');
  else return '';
}

function mouseOver(rowID)
{
  document.getElementById(rowID).className += ' rowMouseOver';
}

function mouseOut(rowID)
{
  document.getElementById(rowID).className = document.getElementById(rowID).className.replace('rowMouseOver', '');
}

function showTooltip(tooltipID, event)
{
  var tooltip = document.getElementById(tooltipID);
  if (event.pageX && event.pageY)
  {
    // firefox
    x = event.pageX;
    y = event.pageY;
  }
  else
  {
    // internet explorer
    //x = event.offsetX + getLeft(event.srcElement);
    //y = event.offsetY + getTop(event.srcElement);
    x = event.x;
    y = event.y;
  }
  tooltip.style.display = "block";
  if (y <= getScrolledY()+(getWindowHeight()/4*3)) tooltip.style.top = y + 25 + "px";
  else tooltip.style.top = y - tooltip.clientHeight - 15 + "px";
  tooltip.style.left = x + 15 - (tooltip.clientWidth + 30) * (x / getWindowWidth()) + "px";
}

function hideTooltip(tooltipID)
{
  var tooltip = document.getElementById(tooltipID);
  tooltip.style.display = "none";
}

function getLeft(obj)
{
  if (obj == null) return 0;
  else return getLeft(obj.offsetParent) + obj.offsetLeft;
}

function getTop(obj)
{
  if (obj == null) return 0;
  else return getTop(obj.offsetParent) + obj.offsetTop;
}

function getScrolledX()
{
  if (self.pageXOffset) return self.pageXOffset;
	if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft; // Explorer 6 Strict
	if (document.body) return document.body.scrollLeft; // all other Explorers
	return null;
}

function getScrolledY()
{
	if (self.pageYOffset) return self.pageYOffset;
	if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; // Explorer 6 Strict
	if (document.body) return document.body.scrollTop; // all other Explorers
	return null;
}

function getPageWidth()
{
  if (window.innerWidth && window.scrollMaxX) return window.innerWidth + window.scrollMaxX;
  if (document.body.scrollWidth > document.body.offsetWidth)return document.body.scrollWidth; // all but Explorer Mac
  return document.body.offsetWidth; // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
}

function getPageHeight()
{
  if (window.innerHeight && window.scrollMaxY) return window.innerHeight + window.scrollMaxY;
  if (document.body.scrollHeight > document.body.offsetHeight) return document.body.scrollHeight; // all but Explorer Mac
  return document.body.offsetHeight; // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
}

function getWindowWidth()
{
	if (self.innerWidth) return self.innerWidth; // all except Explorer
  if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; // Explorer 6 Strict Mode
  if (document.body) return document.body.clientWidth; // other Explorers
  return null;
}

function getWindowHeight()
{
  if (self.innerHeight) return self.innerHeight; // all except Explorer
  if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; // Explorer 6 Strict Mode
  if (document.body) return document.body.clientHeight; // other Explorers
  return null;
}
