/**
 ******************************************************************************
 *
 * Confidential Property of Documentum, Inc.
 * (c) Copyright Documentum, Inc. 2001.
 * All Rights reserved.
 * May not be used without prior written agreement
 * signed by a Documentum corporate officer.
 *
 ******************************************************************************
 *
 * Project        WDK Forms
 * File           scroll.js
 * Description    WDK Forms Visibility / Scroll Position Maintenance Mechanism
 * Created on     04 Jun 2001
 * Tab width      3
 *
 ******************************************************************************
 *
 * PVCS Maintained Data
 *
 * Revision       $Revision: 10$ 
 * Modified on    $Date: 4/3/2007 12:09:18 AM$
 *
 * Log at EOF
 * 
 ******************************************************************************
 */

/**
 * Scroll the page to the given position. Not that this will not work from
 * within a table.
 * @param Xoffset The Horizontal offset
 * @param Yoffset The Vertical offset
 */
function setScrollPosition(nXoffset, nYoffset)
{
   if (isDispatchableWindow(window) == true && (nXoffset !=0 || nYoffset !=0))
   {
      if ( typeof window.scrollTo != 'undefined' )
      {
         window.scrollTo(nXoffset, nYoffset);
      }
      else
      {
         window.scroll(nXoffset, nYoffset);
      }
   }
}
/**
 * Scroll the pane to the given position.
 * @param paneId The pane (div) tag id
 * @param Xoffset The Horizontal offset
 * @param Yoffset The Vertical offset
 */
function setPaneScrollPosition(paneId, nXoffset, nYoffset)
{
   //Check if the pane scroll position is need to be reset, if so then return from the function
   if (typeof resetScrolling != "undefined" && resetScrolling != null && resetScrolling == "true")
      return;
   if ((paneId == null) || (typeof paneId == "undefined"))
   {
      return;
   }
   var targetPane = document.getElementById(paneId);
   if (targetPane != undefined)
   {
      if (typeof targetPane.pageXOffset != 'undefined')
      {
         if(nXoffset >= 0)
         {
            targetPane.pageXOffset = nXoffset;
         }
         targetPane.pageYOffset = nYoffset;
      }
      else if (typeof targetPane.scrollTop != 'undefined')
      {
         targetPane.scrollTop = nYoffset;
         if(nXoffset >= 0)
         {
            targetPane.scrollLeft = nXoffset;
         }
      }
   }
}

/**
 * Stores the scroll position of the target window in the current window form's x and y hidden fields
 */
function storeScrollPosition(formId, propertyXId, propertyYId, target)
{
   if ((formId == null) || (typeof formId == "undefined"))
   {
      throwError("storeScrollPosition: formId is mandatory.");
      return;
   }
   if ((propertyXId == null) || (typeof propertyXId == "undefined"))
   {
      return;
   }
   if ((propertyYId == null) || (typeof propertyYId == "undefined"))
   {
      return;
   }
   if ((target == null) || (typeof target == 'undefined'))
   {
      target = window;
   }

   //Retrieve scroll position
   var nXOffset = 0;
   var nYOffset = 0;
   if ( typeof target.pageXOffset != 'undefined' )
   {
      nXOffset = target.pageXOffset;
      nYOffset = target.pageYOffset;
   }
   else
   {
      nXOffset = target.document.body.scrollLeft;
      nYOffset = target.document.body.scrollTop;
   }
   
   //Now store the scroll position in the x and y hidden fields
   document.forms[formId].elements[propertyXId].value=nXOffset;
   document.forms[formId].elements[propertyYId].value=nYOffset;
}
/**
 * Stores the scroll position of the target pane in the corresponding  pane's x and y hidden fields
 */
function storePaneScrollPosition(paneId, formId, propertyXId, propertyYId)
{
   if ((formId == null) || (typeof formId == "undefined"))
   {
      throwError("storePaneScrollPosition: formId is mandatory.");
      return;
   }
   if ((paneId == null) || (typeof paneId == "undefined"))
   {
      return;
   }
   if ((propertyXId == null) || (typeof propertyXId == "undefined"))
   {
      return;
   }
   if ((propertyYId == null) || (typeof propertyYId == "undefined"))
   {
      return;
   }
   var targetPane = document.getElementById(paneId);
   //Retrieve scroll position
   var nXOffset = 0;
   var nYOffset = 0;

   if (targetPane != undefined)
   {
      if (typeof targetPane.pageXOffset != 'undefined')
      {
         nXOffset = targetPane.pageXOffset;
         nYOffset = targetPane.pageYOffset;
      }
      else if (typeof targetPane.scrollTop != 'undefined')
      {
         nXOffset = targetPane.scrollLeft;
         nYOffset = targetPane.scrollTop;
      }
      //Now store the scroll position in the x and y hidden fields
      document.forms[formId].elements[propertyXId].value = nXOffset;
      document.forms[formId].elements[propertyYId].value = nYOffset;
   }
}
