﻿/*******************************************************************************
 pagecontentClientID = this.PageContent_Left_TableRow_Content.ClientID
 or
 pagecontentClientID = this.PageContent_Right_TableRow_Content.ClientID
*******************************************************************************/
function adjustFontSize(pagecontentClientID, bIncrement)
{
    //var pagecontentObj = $(document.body);   // NOTE: This adjusts the font size of all text on the entire page!
    var pagecontentObj = $(pagecontentClientID);
    var currFontSize = pagecontentObj.css('font-size');
    var finalFontSize = parseFloat(currFontSize, 10);
    var stringEnding = currFontSize.slice(-2);
    if (bIncrement)
    {
        //finalFontSize *= 1.2;
        finalFontSize += 1;
    }
    else
    {
        //finalFontSize /= 1.2;
        finalFontSize -= 1;
    }
    pagecontentObj.css('font-size', finalFontSize + stringEnding);
}

/*******************************************************************************
*******************************************************************************/
function common_SyncHeight(elemId1, elemId2)
{
    // Synchronize height of left and right panels.
    var elem1_height = $(elemId1).height();
    var elem2_height = $(elemId2).height();
    if (elem1_height > elem2_height)
    {
      $(elemId2).height(elem1_height);
    }
    else if (elem1_height < elem2_height)
    {
      $(elemId1).height(elem2_height);
    }
}

/*******************************************************************************
*******************************************************************************/
function _common_guid_s4()
{
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function common_guid()
{
   return (_common_guid_s4()+_common_guid_s4()+'-'+_common_guid_s4()+'-'+_common_guid_s4()+'-'+_common_guid_s4()+'-'+_common_guid_s4()+_common_guid_s4()+_common_guid_s4());
}


//*****************************************************************************
// Returns a random integer between min (inclusive) and max (exclusive).
//*****************************************************************************
function common_RandBetween(min, max)
{
    var randnum = max + 1;

    while ((randnum < min) || (randnum >= max))
    {
        randnum = Math.floor(Math.random() * max);
    }

    return (randnum);
}


        
/*************************************************************************/
function common_LinkArrowImage_Left(imgId, activate)
{
    var linkarrowimage = common_ElementFromId(imgId);
    linkarrowimage.src = activate ? 'Images/linkarrow-left-anim.gif' : 'Images/linkarrow-left.gif';
    return (true);
}

/*************************************************************************/
function common_LinkArrowImage_Right(imgId, activate)
{
    var linkarrowimage = common_ElementFromId(imgId);
    linkarrowimage.src = activate ? 'Images/linkarrow-right-anim.gif' : 'Images/linkarrow-right.gif';
    return (true);
}


//*****************************************************************************
// Swap the specified columns of the specified table.
//*****************************************************************************
function common_SwapTableColumns(table, colIndex1, colIndex2)
{
  if (table && table.rows && table.insertBefore && colIndex1 != colIndex2)
  {
    colIndex1 = Number(colIndex1);
    colIndex2 = Number(colIndex2);
    if (colIndex1 == colIndex2 - 1 || colIndex1 == colIndex2 + 1)
    {
      if (colIndex1 > colIndex2)
      {
        var tempIndex = colIndex1;
        colIndex1 = colIndex2;
        colIndex2 = tempIndex;
      }
      for (var i = 0; i < table.rows.length; i++)
      {
        var row = table.rows[i];
        row.insertBefore(row.cells[colIndex2], row.cells[colIndex1]);
      }
    }
    else
    {
      for (var i = 0; i < table.rows.length; i++)
      {
        var row = table.rows[i];
        var cell1 = row.cells[colIndex1];
        var cell2 = row.cells[colIndex2];
        var siblingCell1 = row.cells[colIndex1 + 1];
        if (typeof siblingCell1 == 'undefined')
        {
          siblingCell1 = null;
        }
        row.insertBefore(cell1, cell2);
        row.insertBefore(cell2, siblingCell1);
      }
    }
  }
}


//*****************************************************************************
// Sets the visibility of the specified element object.
//*****************************************************************************
function common_SetElementVisibleById(elementId, flag)
{
  var elementObj = common_ElementFromId(elementId);

  common_SetElementVisible(elementObj, flag);

  return;
}
function common_SetElementVisible(elementObj, flag)
{
  if (elementObj)
  {
    elementObj.style.visibility = flag ? 'visible' : 'hidden';
  }

  return;
}


//*****************************************************************************
// Gets/sets the width of the specified element object.
//*****************************************************************************
function common_GetElementWidthById(elementId)
{
  var elementObj = common_ElementFromId(elementId);

  return (common_GetElementWidth(elementObj));
}
function common_GetElementWidth(elementObj)
{
  if (elementObj)
  {
    return (elementObj.style.width);
  }

  return ('0');
}
function common_SetElementWidthById(elementId, width)
{
  var elementObj = common_ElementFromId(elementId);

  common_SetElementWidth(elementObj, width);

  return;
}
function common_SetElementWidth(elementObj, width)
{
  if (elementObj)
  {
    width = (width.indexOf('px') == -1) ? (width + 'px') : width;

    elementObj.style.width = width + 'px';
  }

  return;
}


//*****************************************************************************
// Gets/sets the height of the specified element object.
//*****************************************************************************
function common_GetElementHeightById(elementId)
{
  var elementObj = common_ElementFromId(elementId);

  return (common_GetElementHeight(elementObj));
}
function common_GetElementHeight(elementObj)
{
  if (elementObj)
  {
    return (elementObj.style.height);
  }

  return ('0');
}
function common_SetElementHeightById(elementId, height)
{
  var elementObj = common_ElementFromId(elementId);

  common_SetElementHeight(elementObj, height);

  return;
}
function common_SetElementHeight(elementObj, height)
{
  if (elementObj)
  {
    height = (height.indexOf('px') == -1) ? (height + 'px') : height;

    elementObj.style.height = height + 'px';
  }

  return;
}


//*****************************************************************************
// Get the element object for the specified id.
//*****************************************************************************
function common_ElementFromId(elementId)
{
  if (document.getElementById)
  {
    return (document.getElementById(elementId));
  }
  else
  {
    return (null);
  }
}


//*****************************************************************************
// Gets whether the body content exceeds the window height (i.e., vertical
// scroll bar is active).
//*****************************************************************************
function common_IsVerticalScrollbarActive()
{
  var scrollbaractive = false;
  var windowHeight = common_WindowSize()['H'];
  var bodyHeight = parseInt(document.body.scrollHeight);
  if (windowHeight >= bodyHeight)
  {
    //alert('vertical scroll bar present - FALSE');
    scrollbaractive = false;
  }
  else
  {
    //alert('vertical scroll bar present - TRUE');
    scrollbaractive = true;
  }
  return (scrollbaractive);
}


//*****************************************************************************
// Get the inner dimensions of the window (the displayable area).
//*****************************************************************************
function common_WindowSize()
{
  var windowWidth = 0, windowHeight = 0;
  if (typeof(window.innerWidth) == 'number')
  {
    // Non-IE
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  }
  else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
  {
    // IE 6+ in 'standards compliant mode'
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  }
  else if (document.body && (document.body.clientWidth || document.body.clientHeight))
  {
    // IE 4 compatible
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  //alert('Width = ' + windowWidth);
  //alert('Height = ' + windowHeight);
  //return [ windowWidth, windowHeight ];
  var retval = new Array();
  retval['W'] = windowWidth;
  retval['w'] = windowWidth;
  retval['Width'] = windowWidth;
  retval['width'] = windowWidth;
  retval['H'] = windowHeight;
  retval['h'] = windowHeight;
  retval['Height'] = windowHeight;
  retval['height'] = windowHeight;
  return (retval);
}


//*****************************************************************************
// Get the scrolling offsets.
//*****************************************************************************
function common_GetScrollXY()
{
  var scrOfX = 0, scrOfY = 0;
  if (typeof(window.pageYOffset) == 'number')
  {
    // Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  }
  else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
  {
    // DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  }
  else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
  {
    // IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //return [ scrOfX, scrOfY ];
  var retval = new Array();
  retval['X'] = scrOfX;
  retval['x'] = scrOfX;
  retval['Y'] = scrOfY;
  retval['y'] = scrOfY;
  return (retval);
}


//*****************************************************************************
// Get the X,Y position of the element with the specified element id.
//*****************************************************************************
function common_getXY(elemId)
{
  var elemObj = common_ElementFromId(elemId);
  var curleft = 0;
  var curtop = 0;
  do
  {
    curleft += elemObj.offsetLeft;
    curtop += elemObj.offsetTop;
  }
  while (elemObj = elemObj.offsetParent);
  //return [curleft, curtop];
  var retval = new Array();
  retval['X'] = curleft;
  retval['x'] = curleft;
  retval['Y'] = curtop;
  retval['y'] = curtop;
  return (retval);
}
