function trim(stringToTrim)
{
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim)
{
  return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim)
{
  return stringToTrim.replace(/\s+$/,"");
}
function replaceNewline(stringToReplace)
{
  return stringToReplace.replace(/\n/g,"<br />");
}
function popEmail(pUrl)
{
  var lUrl = "/rm/email/form.do";
  if (pUrl)
    lUrl += "?url=" + escape(pUrl);
  var lWin = window.open(lUrl, 'rmemail', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=460');
  lWin.focus();
}

function popMtcEmail()
{
  var lUrl = "/rm/email/form.do?mtc=true";
  var lWin = window.open(lUrl, 'rmemail', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=520');
  lWin.focus();
}

function popEmailTo(pTo, pAdId)
{
  var lUrl = "/rm/email/form.do?to=" + escape(pTo);
  if (pAdId)
    lUrl += "&hto=true&siteId=-1&adId=" + pAdId;
  var lWin = window.open(lUrl, 'rmemail', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=460');
  lWin.focus();
}

function popWin(pUrl, pName, pWidth, pHeight)
{
  var lWin = window.open(pUrl, pName, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='+pWidth+',height='+pHeight);
  lWin.focus();
}
function popWinScroll(pUrl, pName, pWidth, pHeight)
{
  var lWin = window.open(pUrl, pName, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+pWidth+',height='+pHeight);
  lWin.focus();
}

var hRow;
var hpClassName;
function changeHighlighted(pEvent)
{
  var lTd = (pEvent) ? pEvent.target : event.srcElement;
  if ('TR' != lTd.parentNode.nodeName) { return; }
  if (hRow)
  {
    hRow.className = hpClassName;
  }
  hRow = lTd.parentNode;
  hpClassName = hRow.className;
  hRow.className = 'mover'
}
function findHighlightTable()
{
  var lTables = document.getElementsByTagName('table');
  for (i = 0; i < lTables.length; i++)
  {
    var lTable = lTables[i];
    if (lTable.className.search(/\blitable\b/) != -1)
      return lTable;
  }
  return;
} 
function registerHighlightTable()
{
  var lTable = findHighlightTable();
  if (!lTable) { return; }
  var lTrs = lTable.getElementsByTagName("TR");
  for (var i = 0; i < lTrs.length; i++)
  {
    var lTr = lTrs[i];
    if (lTr.id != 'ignoreh')
    {
      lTr.onmouseover = changeHighlighted;
    }
  }
}
function findTableForCell(pCell)
{
  var lParent = pCell.parentNode;
  if (lParent)
    if (lParent.tagName != "TABLE")
      return findTableForCell(lParent);
  return lParent;
}
function resetHighlightTableTrBg(pCell)
{
  var lTable = null;
  if (pCell)
    lTable = findTableForCell(pCell);
  else
    lTable = findHighlightTable(); //document.getElementById('htable');
  if (!lTable) { return; }
  var even = true;
  var lTrs = lTable.getElementsByTagName("TR");
  for (var i = 0; i < lTrs.length; i++)
  {
    var lTr = lTrs[i];
    if (lTr.id == 'ignoreh')
      continue;
    if (!even)
      lTr.className = 'odd';
    else
      lTr.className = 'even';
    even = !even;
  }
}
function openWindow(pName, pUrl, pWidth, pHeight)
{
  var lProps = 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1';
  if (pWidth && pHeight)
   lProps += ',width=' + pWidth + ',height=' + pHeight;
  else
   lProps += ',width=700,height=600';
  var lWin = window.open(pUrl, pName, lProps);
  lWin.focus();
}
function showHideDiv(pDivId)
{
  var lDiv = document.getElementById(pDivId);
  if (lDiv.style.display == 'block')
  {
    lDiv.style.display = "none";
  }
  else
  {
    lDiv.style.display = 'block';
  }
}
function showHideDivFlash(pDivId)
{
  var lDiv = document.getElementById(pDivId);
  if (lDiv.style.display == 'block')
  {
    lDiv.style.display = 'none';
  }
  else
  {
    lDiv.style.display = 'block';
    window.setTimeout('showHideDivFlash("'+pDivId+'")', 3000);
  }
}
function fixDivPos(pDiv, pAdjX, pAdjY, pEvent)
{
  var curleft;
  var curtop;
  var curleft = curtop = 0;
  var obj = (pEvent) ? ((pEvent.target) ? pEvent.target : pEvent.srcElement) : event.srcElement;
  if (obj.offsetParent) {
    var curleft = obj.offsetLeft;
    var curtop = obj.offsetTop;
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  pDiv.style.top=(curtop+pAdjX);
  pDiv.style.left=(curleft+pAdjY);
}