/*---------------------------------------------------------------------------------
  PDP_Globals.js
  Copyright 2003,2004 Peter L. Blum, All Rights Reserved
  Release 1.1.7
  Part of Peter's Date Package v1.1
  No part of this file can be transmitted, reproduced, or distributed without express written consent
  of Peter Blum. Email: Contact@PeterBlum.com.
  This file provides client side scripting common to all controls in this product.
---------------------------------------------------------------------------------*/

// this detection code is taken from http://www.xs4all.nl/~ppk/js/detect.html
var detect = navigator.userAgent.toLowerCase();
var OS, browser, version, place, thestring;
var gIsOpera = false;   // v1-6
var gIsOpera7 = false;  // v7 up
var gIsIEWin = false; 
var gIsIEWin55 = false;
var gIsIEMac = false;
var gIsIEMac51 = false;
var gIsNetscapeNav = false;
var gIsNetscapeMoz = false;   //v1.1.7 also used for gecko
var gIsKonqueror = false;
var gICab = false;
var gIsSafari = false;  //!dc v1.1.4
var gSupportsInnerHTML = (document.body != null) && (document.body.innerHTML != null);
var gSupportsOnKeyPress = true;  // Opera 6 pretends to but really doesn't.
var gSupportsFocusOnTable = false;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
	gIsKonqueror = true;
}
//!dc v1.1.7 AppleWebKit is the core code for Safari and other Mac OS X browsers including OmniWeb. Use the gIsSafari switch
else if (checkIt('safari') || checkIt('applewebkit')) {browser = "Safari"; gIsSafari = true; } // !dc v1.1.4
else if (checkIt('omniweb')) browser = "OmniWeb"   // earlier versions of Omniweb
/*
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('safari')) {browser = "Safari"; gIsSafari = true; } // !dc v1.1.4
//!dc-end*/
else if (checkIt('opera')) {browser = "Opera"; gIsOpera = true; }
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) { browser = "iCab"; gICab = true; }
else if (checkIt('msie')) {browser = "Internet Explorer"; gIsIEWin = true; }
else if (checkIt('netscape')) {browser = "Netscape Mozilla"; gIsNetscapeMoz = true; }
else if (checkIt('gecko')) {browser = "Gecko"; gIsNetscapeMoz = true; } //!dc v1.1.7 gecko also uses gIsNetscapeMoz
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
	gIsNetscapeNav = true;
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}
if (gIsIEWin && (OS == "Mac"))
{
   gIsIEWin = false;
   gIsIEMac = true;
   if (detect.indexOf("msie 5.1") > -1)
     gIsIEMac51 = true;
}
else if (gIsIEWin)
{
   if ((detect.indexOf("msie 5.5") > -1) || (detect.indexOf("msie 6") > -1))
      gIsIEWin55 = true;
}
else if (gIsOpera)   //!dc v1.0.1
{
   if (parseInt(version) >= 7)
   {
     gIsOpera7 = true;
     gIsOpera = false;
   }
}
 // hopefully Opera 7 will work properly. This effect DateTextBox.js keyboard handling
 // Konqueror, ICab and Opera/Mac doesn't offer keycodes in the event
gSupportsOnKeyPress = !gIsOpera && !gIsKonqueror && !gICab; 
gSupportsFocusOnTable = gIsIEWin;

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
// end detection code

// vFormName is a global string that maintains the name of the containing form all controls on this page.
// It is only used for Netscape 4 browsers to get fields by ID.
// NOTE: If there are more than one form on this page, all PDP controls must be in the same form.
// This value must be assigned in a startup script
var gPDP_FormName = "";

//!dc v1.1.4 Used by NS4 to convert name= to id= format because 
// attributes are in local variables with don't support colons
var gPDP_NS4RegEx = new RegExp(":", "g");
//!dc-end

// PDP_SetInnerHTML sets the InnerHTML property unless its the IE Mac 5.1 browser
// That browser hangs when setting innerHTML to anything other than a blank string
// when pFld is a TD (cell of a table). On the Mac, it inserts the text into a <SPAN> tag.
// So don't expect the innerHTML to be identical to pValue.
function PDP_SetInnerHTML(pFld, pValue)
{
   if (gIsIEMac51)
   {
      pFld.innerHTML = "";
      var vNewEl = document.createElement("span");
      vNewEl.innerHTML = pValue;
      pFld.appendChild(vNewEl);
   }
   else
      pFld.innerHTML = pValue;
}  // PDP_SetInnerHTML

function PDPUtil_GetChildNodes(pParent, pNodeName, pIndex)
{
   var vFoundCount = 0;
   var vChildren = null;
   if (pParent.childNodes)
   {
      vChildren = pParent.childNodes;
   }
   else if (pParent.children)
   {
      vChildren = pParent.children;
   }
   else if (pParent.getElementsByTagName)
   {
      vChildren = pParent.getElementsByTagName(pNodeName);
   }
   else
   {
      return null;
   }
   var vLength = vChildren.length;
   for (var vCount = 0; vCount < vLength; vCount++)
      if (vChildren[vCount].nodeName == pNodeName)
      {
         vFoundCount++;
         if (vFoundCount == pIndex)
            return vChildren[vCount];
      }
   return null;
}  // PDPUtil_GetChildNodes

function PDP_GetById(pId)
{
   if (document.getElementById)
      return document.getElementById(pId);
   else if (document.all)
      return document.all[pId]
   else if (document.layers)  // NS 6, only handles one layer of nesting
   {
      var vElement = "";
//!bf v1.1.4
// use the format document.formname['name']. 'name' is NOT pID but the name= parameter.
// The server-side code must pass Control.UniqueID instead of Control.ClientID for Netscape 4
// when setting up client-side ids.
      eval("vElement=document." + gPDP_FormName + "['" + pId + "']");
/*         
      eval("if (document."+ pId + ") vElement = document."+pId+"; else vElement =document." + gPDP_FormName + "." + pId);

//!bf-end */
      return vElement;
   }
   else
      return null;   // return eval("document." + gPDP_FormName + "." + pId);
}  // PDP_GetById

//!dc 1.0.1
function PDP_ParentNode(pElement)
{
   if (pElement.parentElement != null)   //IE
      return pElement.parentElement;
   else if (pElement.parentNode != null)  // NS 6+
      return pElement.parentNode;
   else
      return null;
}
//!dc-end
//!dc v1.1.1
// When true, the field is editable. Various commands call this to prevent editing when not appropriate
// Only pass in fields that support the disabled and readonly attributes such as input type=text.
function PDP_CanEdit(pFId)
{
   var vFld = PDP_GetById(pFId);
   return !(vFld.disabled || vFld.readOnly);
}  // PDP_CanEdit
//!dc-end

//!dc v1.1.1
// Use this to detect if an associated editable field is disabled or readonly.
// The editable field's ID must be whatever precedes the last "_". For example, _ctl0_PN -> _ctl0.
// Returns true if it can edit, false if it cannot. Returns true if it cannot find any editable field.
function PDP_CanEditParent(pFId)
{
   var vPos = pFId.lastIndexOf("_");
   if (vPos > -1)
   {
      var vEFldId = pFId.substr(0, vPos);
      var vEFld = PDP_GetById(vEFldId);
      if ((vEFld != null) && 
          (((vEFld.readonly != null) && (vEFld.readonly)) || 
           ((vEFld.disabled != null) && (vEFld.disabled))))
         return false;
   }
   return true;
}  // PDP_CanEditParent
//!dc-end

function PDP_SetBkColor(pElement, pColor)
{
   if (gIsOpera)
   {
      if (pColor == "")
         pColor = "white";
      pElement.style.background = pColor;
   }
   else
      pElement.style.backgroundColor = pColor;
}  // PDP_SetBkColor

// PDP_GetKeyCode gets the keycode from the event
function PDP_GetKeyCode(pE)
{
   var vKeyCode = null;
   if (pE.keyCode) 
      vKeyCode = pE.keyCode;
   else if (pE.which)
      vKeyCode = pE.which;
   return vKeyCode;  // may be null
}  // PDP_GetKeyCode

// Returns true if the shift key is pressed
function PDP_IsShift(pE)
{
   var vShiftKey = false;
   if (pE.shiftKey != null)
      vShiftKey = pE.shiftKey
   else if (pE.modifiers != null)
      vShiftKey = (pE.modifiers | 4) != 0;
   return vShiftKey;
}  // PDP_IsShift

// Returns true if the ctrl key is pressed
function PDP_IsCtrl(pE)
{
   var vCtrlKey = false;
   if (pE.ctrlKey != null)
      vCtrlKey = pE.ctrlKey
   else if (pE.modifiers != null)
      vCtrlKey = (pE.modifiers | 2) != 0;
   return vCtrlKey;
}  // PDP_IsCtrl

function PDP_StopEvent(pE)
{
   if (pE.cancelBubble != null)
      pE.cancelBubble = true;
   if (pE.stopPropagation)
      pE.stopPropagation();
   if (pE.preventDefault)
      pE.preventDefault();
}  // PDP_StopEvent

// PDP_Trunc takes a decimal value and truncates the decimal portion.
// It returns an integer
function PDP_Trunc(pDecimal)
{
   var vStr = pDecimal.toString();
   var vPos = vStr.indexOf(".");
   if (vPos == -1)
      return parseInt(vStr)
   else
      return parseInt(vStr.substr(0, vPos));
}  // PDP_Trunc

// PDP_FmtDate builds a string to represent the date passed in (pYear, pMonth, pDay)
// pFormat = 0 - ShortDate (all digits) 
//           1 - Abbreviated month and week day 
//           2 - Full month and week day
// pPattern is the pattern where MMMM = month name, MM = month number with lead zero, M = month number
// ww = Day of week, dd = day with lead zero, d = day without lead zero, 
// yyyy = 4 digit year, yy = 2 digit year.
// returns a string as a result
function PDP_FmtDate(pYear, pMonth, pDay, pPattern, pFormat)
{
   if (pDay == 0) // no selection
      return "";
      
   // year is common format between the various styles
   var vResult = "";
   vResult = pPattern.replace("yyyy", pYear.toString());
   if (vResult.indexOf("yy") != -1)
   {
      var vShortYear = pYear % 100;
      if (vShortYear > 9)
         vResult = vResult.replace("yy", vShortYear.toString());
      else
         vResult = vResult.replace("yy", "0" + vShortYear.toString());
   }
   
   // day is a common format
   if (vResult.indexOf("dd") != -1)
   {
      if (pDay > 9)
         vResult = vResult.replace("dd", pDay.toString());
      else
         vResult = vResult.replace("dd", "0" + pDay.toString());
   }
   else
      vResult = vResult.replace("d", pDay.toString());
   
   // month and week day
   if (pFormat == 0) // short date
   {
      var vAdjMonth = pMonth + 1;
      if (vResult.indexOf("MM") != -1) // lead zero
      {
         if (vAdjMonth > 9)
            vResult = vResult.replace("MM", vAdjMonth.toString());
         else
            vResult = vResult.replace("MM", "0" + vAdjMonth.toString());
      }
      else
         vResult = vResult.replace("M", vAdjMonth.toString());

   }
   else if (pFormat == 1)  // abbreviated month and day of week
   {
      var vDate = new Date(pYear, pMonth, pDay);
      var vDayOfWeek = vDate.getDay();
      vResult = vResult.replace("MMMM", PDP_AbbrevMonths[pMonth]);
      vResult = vResult.replace("ww", PDP_AbbrevDaysOfWeek[vDayOfWeek]);
   }
   else   // full month and day of week
   {
      var vDate = new Date(pYear, pMonth, pDay);
      var vDayOfWeek = vDate.getDay();
      vResult = vResult.replace("MMMM", PDP_Months[pMonth]);
      vResult = vResult.replace("ww", PDP_DaysOfWeek[vDayOfWeek]);
   }

   return vResult;
}  // PDP_FmtDate

// PDP_GetCmdId parses pCmdKeys to find the CommandID represented
// by pKeyCode. It returns a positive number representing the command or 0 if none are found.
// It expects pCmdKeys to have this format:
// {<keycode>|<commandId>} (repeated for as many command keys are available)
// <keycode> is either a single character representing an ASCII character
// or has '#' + digits which represents an exact match to pKeyCode (such as ENTER, ESC, UP arrow)
// If it requires Shift or Ctrl keys, the keycode is followed by "C" and/or "S" (in that order)
function PDP_GetCmdId(pCmdKeys, pKeyCode, pCtrlKey, pShiftKey, pIsOnKeyDown)
{
   var vCommandId = "0";
   var vModifiers = pCtrlKey ? "C" : "";
   var vMod2 = pShiftKey ? "S" : "";
   vModifiers = vModifiers + vMod2;
   var vFirstToken = "{#" + pKeyCode + vModifiers;
   var vPos = pCmdKeys.indexOf(vFirstToken);
   if (vPos > -1)
   {
      var vEndPos = pCmdKeys.indexOf("}", vPos + vFirstToken.length + 1);
      if (vEndPos > -1)
         vCommandId = pCmdKeys.substring(vPos + vFirstToken.length + 1, vEndPos);
   }
   else if (!pIsOnKeyDown)
   {
      var vKeyCodeStr = String.fromCharCode(pKeyCode);
      vKeyCodeStr = vKeyCodeStr.toUpperCase();
      vFirstToken = "{" + vKeyCodeStr + vModifiers;
      vPos = pCmdKeys.indexOf(vFirstToken);
      if (vPos > -1)
      {
         var vEndPos = pCmdKeys.indexOf("}", vPos + vFirstToken.length + 1);
         if (vEndPos > -1)
            vCommandId = pCmdKeys.substring(vPos + vFirstToken.length + 1, vEndPos);
      }
   }
   return vCommandId;
}  // PDP_GetCmdId

// ButtonEffect lets you change the classname and/or image of a button
// Its called in response to a mouse down or mouse up.
function ButtonEffect(pFldWStyle, pNewStyle, pFieldID_WithImage, pImageUrl)
{
   if (!PDP_CanEditParent(pFldWStyle.id)) return;  //dc v1.1.1
   if (pFldWStyle && pFldWStyle.className)
      pFldWStyle.className = pNewStyle;
   if ((pImageUrl != "") && (pFieldID_WithImage != ""))
   {
      vFieldWithImage = PDP_GetById(pFieldID_WithImage);
      if (vFieldWithImage && vFieldWithImage.src)
         vFieldWithImage.src = pImageUrl;
   }
}  // ButtonEffect

// ---------- POPUP FUNCTIONS --------------------------------------
// Keep IDs to popup and toggle controls that are opened.
// Multiple popups can be opened so a stack is kept with gPUNPos being the count into the stack.
var gPopupCId = new Array("", "", "", "", "");
var gToggleCId = new Array("", "", "", "", "");
var gPUNPos = -1;

// PDP_TogglePopup changes the visibility state of pPUCId.
// It always toggles between "" and "hidden"
// When pOnPopup is assigned a string containing javascript, it overrides the
// onpopup property of pPUCId. It can be null/undefined.
function PDP_TogglePopup(pTglCId, pPUCId, pOnPopup)
{
   var vPUC = PDP_GetById(pPUCId);
   
   if (vPUC.style.visibility == "inherit")
   {
      PDP_ClosePopup();
   }
   else
   {
      PDP_OpenPopup(pTglCId, pPUCId, true, pOnPopup);
   }
}  // PDP_TogglePopup()

// PDP_OpenPopup opens the popup specified by the parameters.
// If pTglCId is "", there was no toggle (popped up from a mouse right click)
// and the position must be previously assigned to the popup control.
// Otherwise, it will position relative to pTglCId.
// This adds the popup to the stack.
// When pClick is true, its a mouse click and demands closing other popups out of the click position
// When pOnPopup is assigned a string containing javascript, it overrides the
// onpopup property of pPUCId. It can be null/undefined.
var gPDP_InOP = false;  //!bf v1.0.1 prevent reentrancy
function PDP_OpenPopup(pTglCId, pPUCId, pClick, pOnPopup)
{
// don't allow disabled fields to open the menu. Only works on IE browsers unless pTglCId is an input field
   var vTglC = null;
   if (pTglCId != "")
      vTglC = PDP_GetById(pTglCId); 
   if (vTglC != null)
      if (vTglC.disabled)
         return;
       
   if (pClick && window.event) // close already open popups that we're outside of
      PDP_TestCaptureNS6(window.event);
      
   if (gPUNPos >= gPopupCId.length)
      return;
            
   if (gPDP_InOP)
      return;
   gPDP_InOP = true;
     
   var vPUC = PDP_GetById(pPUCId);
   var vOnPopupFunction = "";
   if (pOnPopup != null)
      vOnPopupFunction = pOnPopup;
   else
      vOnPopupFunction = vPUC.getAttribute("onpopup");
   if ((vOnPopupFunction != null) && (vOnPopupFunction != ""))
   {
      var vResult = true;
      eval(vOnPopupFunction); // this can assign vResult to false or true if desired
      if (vResult == false)
      {
         gPDP_InOP = false;
         return;
      }
   }

   gPUNPos++;
   gPopupCId[gPUNPos] = pPUCId;
   gToggleCId[gPUNPos] = pTglCId;
   
//!bf v1.0.4
   if (vTglC != null)
      PDP_PositionPopupToToggle(vTglC, vPUC);
/*   
   if (pTglCId != "")
   {
      var vTglC = PDP_GetById(pTglCId);
      PDP_PositionPopupToToggle(vTglC, vPUC);
   }
*/
   
   PDP_MSIEFixPopupOpen(vPUC);   //!bf v1.0.1
   
   vPUC.style.visibility = "inherit";
   if (vPUC.focus)
//      vPUC.focus();
      setTimeout("javascript:var vPUC = PDP_GetById('" + pPUCId + "'); if (vPUC.style.visibility = 'inherit') vPUC.focus();", 50);   // allow the browser to catch up


/*         
   if (vPUC.setCapture) // IE 5+
   {
      vPUC.setCapture(false);
      if (vPUC.onclick == null)
         vPUC.onclick = new Function("PDP_TestCaptureIE5('" + pTglCId + "','" + pPUCId + "');");
      vPUC.onlosecapture = new Function("PDP_TogglePopup('" + pTglCId + "', '" + pPUCId + "');");
   }
*/     
   if (document.attachEvent)
   {
      if (gPUNPos == 0)
         document.attachEvent("onmousedown", PDP_TestCaptureIE5);
   } 
   else if (document.addEventListener)  // Netscape 6+
   {
      if (gPUNPos == 0)
         document.addEventListener("mousedown", PDP_TestCaptureNS6, false);
//         document.body.addEventListener("blur", PDP_ClosePopup, false);
//      vPUC.onblur = 'PDP_ClosePopup();';
   }
   else  // this will overwrite any existing onmousedown function
      document.onmousedown = PDP_TestCaptureIE5;
   gPDP_InOP = false;
}  // PDP_OpenPopup()

function PDP_OpenPopupAtMousePoint(pPUCId, pE)
{
  if ((document.body.scrollTop == null) && (window.pageXOffset))
      return;  // Neither IE or NS 6+. Context is not supported

  PDP_TestCaptureNS6(pE); // close anything else since right click avoids this test
  if (gPUNPos >= gPopupCId.length)
    return;
      
   
  var vPUC = PDP_GetById(pPUCId);
  vPUC.style.position = "absolute";
  var vClientX = PDP_GetScrolledX(vPUC, pE.clientX, true);
  var vClientY = PDP_GetScrolledY(vPUC, pE.clientY, true);
 
  if (true)
//   if (window.__smartNav != null)   // smart nav breaks PDP_RelocatePopup. This is a hack to avoid the problem
   {
//!bf 1.0.1   
      vClientX = PDP_GetOffsetX(vPUC, vClientX, -1);
      vClientY = PDP_GetOffsetY(vPUC, vClientY, -1);
/*   
      vClientX = PDP_GetOffsetX(vPUC, vClientX, -1, window.__smartNav != null);
      vClientY = PDP_GetOffsetY(vPUC, vClientY, -1, window.__smartNav != null);
      */
   }
   
   if (gIsIEMac)  // variation of IE Mac 5 fix in http://www.xs4all.nl/~ppk/js/browsers5.html#ie5mac
   {
      vClientX = vClientX + 10;
      vClientY = vClientY + 15;
   }
//!dc v1.1.4 safari adjustment
   if (gIsSafari)
   {
      vClientX = vClientX + document.body.offsetLeft;
      vClientY = vClientY + document.body.offsetTop;
   }
//!dc-end   
  PDP_SetLeftPos(vPUC, vClientX);
  PDP_SetTopPos(vPUC, vClientY);
//  vPUC.style.left = vClientX.toString() + "px";
//  vPUC.style.top = vClientY.toString() + "px";

  vPUC.style.zIndex = 30000 + gPUNPos + 1;
  
  if ((gPUNPos == -1) || (gPopupCId[gPUNPos] != pPUCId)) // its not already open
     PDP_OpenPopup("", pPUCId, true);
}  // PDP_OpenPopupAtMousePoint

// PDP_GetScrolledX applies scrolling to the pX position. Only IE 4+ and NS 6+
function PDP_GetScrolledX(pPUC, pX, pLimit)
{
//!bf 1.0.2 switched order of tests scrollLeft is first
  if (document.body.scrollLeft != null)  // IE and Netscape 6+
  {
      if (pLimit)
      {
         if (pX + pPUC.offsetWidth > document.body.offsetWidth)
            pX = pX - pPUC.offsetWidth;
         if (pX < 0)
            pX = 0;
      }
//!!bf v1.0.2 Check for being in a nested scrolled region (such as <DIV style='overflow:scollable'>)
      for (var vPar = PDP_ParentNode(pPUC);
         (vPar != document.body) && (vPar != null);
         vPar = PDP_ParentNode(vPar))
      {
         if (vPar.scrollLeft != null)  //IE Mac lacks this on some elements
            pX  = pX + vPar.scrollLeft;
      }  // for
//!!bf-end
//!bf v1.1.7 IE 6 delivers scrollLeft differently depending on document.compatMode. This fixes XHTML scrolling issues. See http://www.quirksmode.org/js/doctypes.html
      var vDE = document.documentElement; // reduce the size of the text
      if (vDE && vDE.scrollLeft)
	      pX = pX + vDE.scrollLeft;
      else
         pX = pX + document.body.scrollLeft;
/*
      pX = pX + document.body.scrollLeft;
//!bf-end */      
  }
  else if (window.pageXOffset != null)   // DOM
  {
      pX = pX + window.pageXOffset;
  }
  return pX;
}  // PDP_GetScrolledX

// PDP_GetScrolledY applies scrolling to the pY position. Only IE 4+ and NS 6+
function PDP_GetScrolledY(pPUC, pY, pLimit)
{
//!bf 1.0.2 switched order of tests scrollTop is first
  if (document.body.scrollTop != null)
  {
      if (pLimit)
      {
         if (pY + pPUC.offsetHeight > document.body.offsetHeight)
            pY = pY - pPUC.offsetHeight;
         if (pY < 0)
            pY = 0;
      }
//!!bf v1.0.2 Check for being in a nested scrolled region (such as <DIV style='overflow:scollable'>)
      for (var vPar = PDP_ParentNode(pPUC);
         (vPar != document.body) && (vPar != null);
         vPar = PDP_ParentNode(vPar))
      {
         if (vPar.scrollTop != null)  //IE Mac lacks this on some elements
            pY  = pY + vPar.scrollTop;
      }  // for
//!!bf-end
//!bf v1.1.7 IE 6 delivers scrollTop differently depending on document.compatMode. This fixes XHTML scrolling issues. See http://www.quirksmode.org/js/doctypes.html
      var vDE = document.documentElement; // reduce the size of the text
      if (vDE && vDE.scrollTop)
	      pY = pY + vDE.scrollTop;
      else
         pY = pY + document.body.scrollTop;
/*
      pY = pY + document.body.scrollTop;
//!bf-end */      
  }
  else if (window.pageXOffset != null)
  {
      pY = pY + window.pageYOffset;
  }
  return pY;
}  // PDP_GetScrolledY

function PDP_GetOffsetX(pControl, pInitialPos, pDirection)
{
   var vLeftPos = pInitialPos;
   if (pControl.offsetParent)
      for (var vPar = pControl.offsetParent;
//!dc v1.1.4      (vPar != document.body)  && // safari sets offsetLeft in document.body
         (vPar != null);  
         vPar = vPar.offsetParent)
      {
         vLeftPos = vLeftPos + pDirection * vPar.offsetLeft;
//!dc v1.1.4         
         if (gIsSafari && (vPar.style.position == "absolute"))
            break;
//!dc-end
      }  // for
   else
   
      for (var vPar = pControl.parentNode;
         (vPar != document.body) && (vPar != null);
         vPar = vPar.parentNode)
      {
         if (vPar.style.position == "absolute")
         {
            vLeftPos = vLeftPos + pDirection * vPar.offsetLeft;
            break;
         }
      }  // for
   return vLeftPos;
}  // PDP_GetOffsetX

function PDP_GetOffsetY(pControl, pInitialPos, pDirection, pGetAbsPos)
{
   var vTopPos = pInitialPos;
   if (pControl.offsetParent)
      for (var vPar = pControl.offsetParent;
//!dc v1.1.4      (vPar != document.body)  && // safari sets offsetTop in document.body
         (vPar != null);  
         vPar = vPar.offsetParent)
      {
         vTopPos = vTopPos + pDirection * vPar.offsetTop;
//         alert("TP " + vTopPos + " IP " + pInitialPos + " OT " + vPar.offsetTop + " abs: " + (vPar.style.position == "absolute"));
//!dc v1.1.4         
         if (gIsSafari && (vPar.style.position == "absolute"))
            break;
//!dc-end
      }  // for
   else
   
      for (var vPar = pControl.parentNode;
         (vPar != document.body) && (vPar != null);
         vPar = vPar.parentNode)
      {
         if (vPar.style.position == "absolute")
         {
            vTopPos = vTopPos + pDirection * vPar.offsetTop;
            break;
         }
      }  // for
  return vTopPos;
}  // PDP_GetOffsetY

//returns true if a parent node of pPUC is absolutely positioned
function PDP_AbsParent(pPUC)
{
   if (pPUC.offsetParent)
      for (var vPar = pPUC.offsetParent;
         (vPar != document.body) && (vPar != null);
         vPar = vPar.offsetParent)
      {
         if (vPar.style.position == "absolute")
         {
            return true;
         }
      }  // for
   else
   
      for (var vPar = pPUC.parentNode;
         (vPar != document.body) && (vPar != null);
         vPar = vPar.parentNode)
      {
         if (vPar.style.position == "absolute")
         {
            return true;
         }
      }  // for
   return false;
}  // PDP_AbsParent

// PDP_ClosePopup is used by Netscape 6 to detect a focus change off this control
function PDP_ClosePopup()
{
   if (gPUNPos == -1)
      return;
   if (gPDP_InOP)
      return;
   gPDP_InOP = true;
   var vPUC = PDP_GetById(gPopupCId[gPUNPos]);

   var vOnPopdownFunction = vPUC.getAttribute("onpopdown");
   if ((vOnPopdownFunction != null) && (vOnPopdownFunction != ""))
      eval(vOnPopdownFunction);
   vPUC.style.visibility = "hidden";

   if (document.detachEvent)
   {
      if (gPUNPos == 0)
         document.detachEvent("onmousedown", PDP_TestCaptureIE5);
   }         
   else if (document.removeEventListener)  // Netscape 6+
   {
     if (gPUNPos == 0)
         document.removeEventListener("mousedown", PDP_TestCaptureNS6, false);
//         document.body.removeEventListener("blur", PDP_ClosePopup, false);
   }
   PDP_MSIEFixPopupClose(vPUC);  //!bf v1.0.1/2
   
   gPopupCId[gPUNPos] = "";
   gToggleCId[gPUNPos] = "";
   gPUNPos--;
   // restore focus on the topmost popup
   if (gPUNPos > -1)
   {
      var vLwrPC = PDP_GetById(gPopupCId[gPUNPos]);
      if ((vLwrPC.style.visibility != "hidden") && (vLwrPC.focus != null))
         vLwrPC.focus();
   }
   gPDP_InOP = false;
   
}  // PDP_ClosePopup()

// PDP_CloseAllPopups removes all popups in their stacked order
function PDP_CloseAllPopups()
{
   while (gPUNPos > -1)
      PDP_ClosePopup();
}  // PDP_CloseAllPopups

function PDP_PositionPopupToToggle(pTglC, pPUC)
{
   var vHorizPos = "leftsidesalign";
   var vVertPos = "popupbelow";
   var vHorzOffset = 0;
   var vVertOffset = 0;
   var vTest = pTglC.getAttribute("HPos");
   if ((vTest != null) && (vTest != ""))
   {
      vHorizPos = vTest;
      vVertPos = pTglC.getAttribute("VPos");
      vHorzOffset = parseInt(pTglC.getAttribute("HPosOf"));
      vVertOffset = parseInt(pTglC.getAttribute("VPosOf"));
   }
   // if we are inside an absolutely positioned container, find its offsetleft and offsettop
   var vLeftPos = pTglC.offsetLeft;
   var vTopPos = pTglC.offsetTop;
//!bf 1.0.1 
   vLeftPos = PDP_GetOffsetX(pTglC, pTglC.offsetLeft, 1); 
   vTopPos = PDP_GetOffsetY(pTglC, pTglC.offsetTop, 1);
/*
   vLeftPos = PDP_GetOffsetX(pTglC, pTglC.offsetLeft, 1, window.__smartNav == null);
   vTopPos = PDP_GetOffsetY(pTglC, pTglC.offsetTop, 1, window.__smartNav == null);
!bf-end */   
//   alert("TP: " + vTopPos + " OT: " + pTglC.offsetTop);

   if (gIsIEMac /* && ((vTopPos != pTglC.offsetTop) || (vLeftPos != pTglC.offsetLeft)) */)  // variation of IE Mac 5 fix in http://www.xs4all.nl/~ppk/js/browsers5.html#ie5mac
   {
      vLeftPos = vLeftPos + 10;
      vTopPos = vTopPos + 15;
   }
//!dc v1.1.4 safari adjustment
   if (gIsSafari)
   {
      vLeftPos = vLeftPos + document.body.offsetLeft;
      vTopPos = vTopPos + document.body.offsetTop;
   }
//!dc-end   
   
   var vToggleWidth = pTglC.offsetWidth;
   var vPopupWidth = pPUC.offsetWidth;
   if (pPUC.clientWidth && (pPUC.clientWidth < pPUC.offsetWidth))  // IE
   {
      vHorzOffset += (pPUC.offsetWidth - pPUC.clientWidth) / 2;
   }
   switch (vHorizPos)
   {
      case "leftsidesalign":
         vLeftPos = vLeftPos;
         break;
      case "center":
         vLeftPos = vLeftPos + (vToggleWidth - vPopupWidth) / 2;
         break;
      case "rightsidesalign":
         vLeftPos = vLeftPos + vToggleWidth - vPopupWidth;
         break;
      case "popuptoright":
         vLeftPos = vLeftPos + vToggleWidth;
         break;
   }  // switch
   vLeftPos = vLeftPos + vHorzOffset;

   var vToggleHeight = pTglC.offsetHeight;
   var vPopupHeight = pPUC.offsetHeight;
   if (pPUC.clientHeight && (pPUC.clientHeight < pPUC.offsetHeight))  // IE
   {
      vVertOffset += (pPUC.offsetHeight - pPUC.clientHeight) / 2;
   }
   switch (vVertPos)
   {
      case "popupbelow":
         vTopPos = vTopPos + vToggleHeight;
         break;
      case "center":
         vTopPos = vTopPos + (vToggleHeight - vPopupHeight) / 2;
         break;
      case "popupabove":
         vTopPos = vTopPos - vPopupHeight;
         break;
      case "topsidesalign":
         vTopPos = vTopPos;
         break;
   }  // switch
   vTopPos = vTopPos + vVertOffset;
   
   //!bf 1.0.1 these positions are relative to the toggle. The popup DIV may be elsewhere such 
   // as relocated under the document.body. Thus its containers may use different offsets.
   vLeftPos = PDP_GetOffsetX(pPUC, vLeftPos, -1); 
   vTopPos = PDP_GetOffsetY(pPUC, vTopPos, -1);
   
   if (!gIsOpera7)   // !bf v1.1.1 opera returns scrolled values on the toggle way too easily
   {
      //!bf 1.0.2 if the popup is in the document.body and toggle is nested lower, the toggle
      // could be scrolled due to style:overflow. Determine both of their scrolled positions
      // and use the difference to adjust the final position
      vLeftPos = vLeftPos + PDP_GetScrolledX(pPUC, 0, false) - PDP_GetScrolledX(pTglC, 0, false);
      vTopPos = vTopPos + PDP_GetScrolledY(pPUC, 0, false) - PDP_GetScrolledY(pTglC, 0, false);
      //!bf-end
   }
   // adjust these positions further if the popup goes offscreen
   
//!bf 1.1.9 alternative !DOCTYPEs do not setup document.body with all of the correct values in IE
   var vDE = document.documentElement; // used by IE
   var vDB = document.body;
   if (!vDE)
      vDE = vDB;
/*      
   if (!vDE || gIsNetscapeMoz || ((vDE.scrollLeft == 0) && (vDE.scrollTop == 0)))
      vDE = document.body; // used by DOM and IE with the standard !DOCTYPE (HTML Transistional)
*/      
   if (vDE && (vDE.offsetWidth != null))
   {
      var vLP = vLeftPos + pPUC.offsetWidth;
      var vLDE = (vDE.scrollLeft ? vDE.scrollLeft : vDB.scrollLeft) + vDE.offsetWidth;
      if (vLP > vLDE)
         vLeftPos= vLeftPos - (vLP - vLDE);
      var vTP = vTopPos + pPUC.offsetHeight;
      var vTDE = (vDE.scrollTop ? vDE.scrollTop : vDB.scrollTop) + vDE.offsetHeight;
      if (vTP > vTDE)
         vTopPos = vTopPos - (vTP - vTDE);

/*      
      if (vLeftPos + pPUC.offsetWidth > vDE.scrollLeft + vDE.offsetWidth)
         vLeftPos= vLeftPos - ((vLeftPos + pPUC.offsetWidth) - (vDE.scrollLeft + vDE.offsetWidth));
      if (vTopPos + pPUC.offsetHeight > vDE.scrollTop + vDE.offsetHeight)
         vTopPos = vTopPos - ((vTopPos + pPUC.offsetHeight) - (vDE.scrollTop + vDE.offsetHeight));
*/
   }
/*   
   if ((document.all != null) && (document.body.offsetWidth != null))
   {

      if (vLeftPos + pPUC.offsetWidth > document.body.scrollLeft + document.body.offsetWidth)
         vLeftPos= vLeftPos - ((vLeftPos + pPUC.offsetWidth) - (document.body.scrollLeft + document.body.offsetWidth));
      if (vTopPos + pPUC.offsetHeight > document.body.scrollTop + document.body.offsetHeight)
         vTopPos = vTopPos - ((vTopPos + pPUC.offsetHeight) - (document.body.scrollTop + document.body.offsetHeight));

   }
*/   
   // Prevent overlapping left or top edge of the view area
   // When SmartNav is on, the popup control was not relocated to the body.
   // If its under another absolutely positioned element, coordinates are 
   // positioned from that elements' upper left. So vLeftPos is relative to the 
   // left and should be allowed to be negative.
   if ((window.__smartNav == null) || (!PDP_AbsParent(pPUC)))
   {
      if (vLeftPos < 0)
         vLeftPos = 0;
      if (vTopPos < 0)
         vTopPos = 0;
   }
   pPUC.style.position = "absolute";
   PDP_SetLeftPos(pPUC, vLeftPos);
   PDP_SetTopPos(pPUC, vTopPos);
   pPUC.style.zIndex = 30000 + gPUNPos;
   if (gIsIEMac)
   {
      if (pPUC.style.pixelWidth == "")
         pPUC.style.pixelWidth = pPUC.offsetWidth;
      if (pPUC.style.pixelHeight == "")
         pPUC.style.pixelHeight = pPUC.offsetHeight;
   }
   
//     DebugOffsets(pTglC, pPUC);
//   alert(pPUC.id + " " + pPUC.tagName + " " + pPUC.style.cssText + " OffsetWidth: " + pPUC.offsetWidth + " OffsetHeight: " + pPUC.offsetHeight + " left: " + vLeftPos + " top: " + vTopPos);
}  // PDP_PositionPopupToToggle

// PDP_TestCaptureIE5 is an OnClick handler for the popup control.
// It is designed for IE 5+
// It is called to detect if the mouse click is outside pControlID's boundaries
// which will allow it to release capture.
function PDP_TestCaptureIE5()
{
   PDP_TestCaptureNS6(window.event);
}  // PDP_TestCaptureIE5

// PDP_TestCaptureNS6 is an OnClick handler for the popup control.
// It is designed for NS 6+
// It is called to detect if the mouse click is outside pControlID's boundaries
// which will allow it to release capture.
// Depends on gPopupCId and gToggleCId being setup
function PDP_TestCaptureNS6(e)
{
   if (gPUNPos == -1)
      return;
   if (gPDP_InOP)
      return;
      
   var vEndCaptureB = false;
   var vPUC = PDP_GetById(gPopupCId[gPUNPos]);
   var vX = gIsSafari ? e.clientX : PDP_GetScrolledX(vPUC, e.clientX, false); //!dc v1.1.4 safari prescrolls clientx and y: http://www.xs4all.nl/~ppk/js/w3c_events.html
   var vY = gIsSafari ? e.clientY : PDP_GetScrolledY(vPUC, e.clientY, false); //!dc v1.1.4
   if (gIsIEMac)  // variation of IE Mac 5 fix in http://www.xs4all.nl/~ppk/js/browsers5.html#ie5mac
   {
      vX = vX - 10;
      vY = vY - 15;
   }
//!dc v1.1.4 safari adjustment
   if (gIsSafari)
   {
      vX = vX + document.body.offsetLeft;
      vY = vY + document.body.offsetTop;
   }
//!dc-end   
   

   var vLeftPos = vPUC.offsetLeft;
   var vTopPos = vPUC.offsetTop;
//!bf 1.0.1   
   vLeftPos = PDP_GetOffsetX(vPUC, vPUC.offsetLeft, 1);
   vTopPos = PDP_GetOffsetY(vPUC, vPUC.offsetTop, 1);
/*   
   if (window.__smartNav != null)   // smart nav breaks PDP_RelocatePopup. This is a hack to avoid the problem
   {
      vLeftPos = PDP_GetOffsetX(vPUC, vPUC.offsetLeft, 1, false);
      vTopPos = PDP_GetOffsetY(vPUC, vPUC.offsetTop, 1, false);
   }
*/      

   if (vX < vLeftPos)
   {
      vEndCaptureB = true;
//   alert("Left: mouse scrolled X: " + vX + " Object Left: " + vLeftPos + " offsetWidth: " + vPUC.offsetWidth + " ClientX: " + e.clientX);
   }
   else if (vX > vLeftPos + vPUC.offsetWidth)
   {
      vEndCaptureB = true;
//   alert("Right:  mouse scrolled X: " + vX + " Object Left: " + vLeftPos + " offsetWidth: " + vPUC.offsetWidth + " ClientX: " + e.clientX);
   }
   else if (vY < vTopPos)
   {
      vEndCaptureB = true;
//   alert("Above: mouse scrolled Y: " + vY + " Object Top: " + vTopPos  + " offsetHeight: " + vPUC.offsetHeight + " ClientY: " + e.clientY);
   }
   else if (vY > vTopPos + vPUC.offsetHeight)
   {
      vEndCaptureB = true;
//   alert("Below: " + vEndCaptureB + " mouse scrolled Y: " + vY + " Object Top: " + vTopPos + " offsetHeight: " + vPUC.offsetHeight+ " ClientY: " + e.clientY);
   }
      
   if (vEndCaptureB && (gToggleCId[gPUNPos] != ""))   // if click on the toggle, its valid. Let it handle the popdown
   {
      var vTglC = PDP_GetById(gToggleCId[gPUNPos]);
      if ( (vX >= vTglC.offsetLeft) &&
           (vX <= vTglC.offsetLeft + vTglC.offsetWidth) &&
           (vY >= vTglC.offsetTop) &&
           (vY <= vTglC.offsetTop + vTglC.offsetHeight) )
         vEndCaptureB = false;
   }

   if (vEndCaptureB)
   {
      PDP_ClosePopup();
      // close any other popup that you've clicked outside of until one should stay open
      if (gPUNPos > -1)
         PDP_TestCaptureNS6(e);
   }
}  // PDP_TestCaptureNS6

//!bf 1.0.1
// PDP_MSIEFixPopup takes an absolutely positioned object and fixes a problem in IE 5.5+
// browsers where SELECT objects are shown above abs positioned objects.
// Credit goes to Coalesys, Inc.
// Design puts an empty IFrame that is sized the same as pFld. It uses a idiosyncrasy
// in IE 5.5 where an IFrame can appear above a SELECT but below an abs positioned object.
function PDP_MSIEFixPopupOpen(pFld)
{
   if (gIsIEWin55)
   {
      var vIFrNm = "PDP_ZIndexFix_"+pFld.id; //!bf v1.0.2
      if (!document.all[vIFrNm])
      {
         // create an IFrame and add it to the end of the document.
         // To avoid SmartNavigation's IFrame and others which may cause transparency through our popups,
         // be sure each popup's IFrame is lower then the one already open
         var vIFrame = "<iframe src='javascript:false;' id='" + vIFrNm +
            "' scrolling='no' frameborder='0'  " +
            "style='position:absolute;top:0x;left:0px;" + //!bf v1.0.2
            "display:none'></iframe>";
         // Add IFrame to the same parent tag as pFld so it shares
         // a common z-index base. If it was placed into document.body, there may be an absolutely
         // positioned element between pFld and document and that changes the layering system
         // and often makes the IFrame block all mouse clicks from getting through to the popup HTML
         var vElement = pFld.parentElement;
         vElement.insertAdjacentHTML('beforeEnd',vIFrame);
      }
      
      if (document.all[vIFrNm])
      {
         var vStyle = document.all[vIFrNm].style;
         
         vStyle.pixelTop = pFld.style.pixelTop;
         vStyle.pixelLeft = pFld.style.pixelLeft;
         vStyle.pixelWidth = pFld.offsetWidth + 6; // excess for borders and some filter effects
         vStyle.pixelHeight = pFld.offsetHeight + 6;
         var vZIndex = 29990 - gPUNPos;   //!bf v1.0.2
         vStyle.zIndex = vZIndex;   //!bf v1.0.2
         vStyle.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
         // show it
         vStyle.display='block';
      }
   }
}  // PDP_MSIEFixPopupOpen

// PDP_MSIEFixPopupClose reverses the effects of PopupOpen. Call before subtracting gPUNPos
function PDP_MSIEFixPopupClose(pFld)
{
   if (gIsIEWin55)
   {
      var vIFrNm = "PDP_ZIndexFix_"+pFld.id; //!bf v1.0.2
      if (document.all[vIFrNm])
      {
         document.all[vIFrNm].style.display='none';
      }
   }
}  // PDP_MSIEFixPopupClose
//!bf-end

function PDP_SetLeftPos(pFld, pLeftPos)
{
   if (pFld.style.pixelLeft)
      pFld.style.pixelLeft = pLeftPos;
   else if (pFld.style.posLeft)
      pFld.style.posLeft = pLeftPos.toString() + "px";
   else
      pFld.style.left = pLeftPos.toString() + "px";
}

function PDP_SetTopPos(pFld, pTopPos)
{
   if (pFld.style.pixelTop)
      pFld.style.pixelTop = pTopPos;
   else if (pFld.style.posTop)
      pFld.style.posTop = pTopPos.toString() + "px";
   else
      pFld.style.top = pTopPos.toString() + "px";
}

// Microsoft supplies the hideFocus attribute to add and remove the frame for a focus.
// This is a wrapper that makes sure its present when we use it.
// pControlID is the control to change. pValue is a boolean. When true, the focus frame is hidden.
function PDP_HideFocus(pControlID, pValue)
{
   var vField = PDP_GetById(pControlID);
   if (vField.hideFocus != null)
      vField.hideFocus = pValue;
}  // PDP_HideFocus

// PDP_GetAtt is a shell for the getAttribute function that
// can assign a default when the attribute is missing.
// It handles browsers that lack getAttribute.
function PDP_GetAtt(pElement, pAttributeName, pDefaultValue) 
{
//!dc v1.1.4 Safari doesn't want underscores in the attribute names. Server side must provide a different name
   if (gIsSafari)
      pAttributeName = pAttributeName.replace("_", "");
//!dc-end   
   if (pElement.getAttribute)
   {
      var vResult = pElement.getAttribute(pAttributeName, 0);
      if (vResult == null)
         vResult = pDefaultValue; 
      else if ((vResult == "") && (!document.all))  // Netscape returns "" for empty
         vResult = pDefaultValue;
      return vResult; 
   }
   else   // NS 4. All attributes are stored in global variables
   {
//!dc v1.1.4
      var vId = pElement.name.replace(gPDP_NS4RegEx, "_");
      var vVarName = vId + "_" + pAttributeName;
/*   
      var vVarName = pElement.name + "_" + pAttributeName;
//!dc-end */      
      var vResult = eval(vVarName);
      if ((vResult == null) || (vResult == ""))
         vResult = pDefaultValue;
      return vResult;
   }
} // PDP_GetAtt()

// PDP_SetAtt sets the attribute. It handles NS 4
function PDP_SetAtt(pElement, pAttributeName, pAttributeValue)
{
   if (pElement.setAttribute) //!note v1.1.4 if we ever add an attribute that uses an "_", it must be stripped for Safari
      pElement.setAttribute(pAttributeName, pAttributeValue, 0);
   else   // NS 4. All attributes are stored in global variables
   {
      var vVarName = pElement.name + "_" + pAttributeName;
      eval("vVarName = pAttributeValue.toString();");
   }
}  // PDP_SetAtt

var gPDP_ProcessingError = false;
function PDP_ShowError(pFldId, pErrorCode, pShowAlert)
{
// if this happens during a focus movement (as onChange often does)
// IE continues moving the focus to the next field. We may need to move the focus
// back in this process. So delay the actual process for a moment while events finish.
  if (!gPDP_ProcessingError)
  {
   var vCode = "javascript:PDP_ShowErrorBody('" + pFldId + "', " + pErrorCode + "," + pShowAlert + ")";
   setTimeout(vCode, 10); 
  }
}  // PDP_ShowError()

function PDP_ShowErrorBody(pFldId, pErrorCode, pShowAlert)
{
   if (gPDP_ProcessingError)
      return;
   gPDP_ProcessingError = true;
   var vFld = PDP_GetById(pFldId);
//   var vError = eval(PDP_GetAtt(vFld, "FldError", "false"));
//   PDP_SetAtt(vFld, "FldError", true);
   
   // set the field color
   if (vFld.style)
   {
      var vForeColor = PDP_GetAtt(vFld, "ErrFC", '');
      var vBackColor = PDP_GetAtt(vFld, "ErrBC", '');
      if (vForeColor != '')
         vFld.style.color = vForeColor;
      if (vBackColor != '')
         PDP_SetBkColor(vFld, vBackColor);
   }
   else
      pShowAlert = true;   // NS 4 needs alerts since it has no other message style
   if  (!gSupportsOnKeyPress) // since we aren't filtering keys, error reporting is vital
      pShowAlert = true;

   // set the focus if desired
  if (vFld.focus && vFld.select)
  {
      var vFocusOnErrorB = eval(PDP_GetAtt(vFld, "FOErr", false));
      if (vFocusOnErrorB == true)
      {
         vFld.focus();
         vFld.select();
      }
  }
  // show the error code
  if (pShowAlert)
  {
      var vErrorMsg = "";
      switch (pErrorCode)
      {
            case 1:
               vErrorMsg = PDP_GetAtt(vFld, "InvalidMsg", false);
               break;
            case 2:
               vErrorMsg = PDP_GetAtt(vFld, "OutOfRangeMsg", false);
               break;
      }   // switch
      if (vErrorMsg != '')
         alert(vErrorMsg);
   }
   gPDP_ProcessingError = false;
}  // PDP_ShowErrorBody()

function PDP_ClearError(pFldId)
{
   var vTBFld = PDP_GetById(pFldId);
   if (vTBFld.style)
   {
      vTBFld.style.color = PDP_GetAtt(vTBFld, "OrigFC", "");
      PDP_SetBkColor(vTBFld, PDP_GetAtt(vTBFld, "OrigBC", ""));
   }
//   PDP_SetAtt(vTBFld, "FldError", false);

}  // PDP_ClearError

// PDP_ParseInt takes numeric text and strips off lead zeros.
// It returns the resulting value as an integer.
// This resolves an issue with parseInt which converts values with lead zeros as octal values.
// This is designed to return NaN when there is an illegal value.         

function PDP_ParseInt(pValue)
{
   if ((pValue == '0') || (pValue == '00'))
      return 0;
   else 
      return parseInt(pValue.replace(/^0*/, ''));
}  // PDP_ParseInt()

// PDP_MakeUTCDate creates a UTC date for pYear, pMonth, pDay, at 0 minutes in the day.
// It returns a Date object with the UTC date.
function PDP_MakeUTCDate(pYear, pMonth, pDay)
{
   var vDate = new Date(0);//!dc v1.1.9 aside from reducing the size, Safari 1-1.2.3 has a severe bug// In most time zones (GMT + 0000 through GMT + 1200 through GTM - 0800)// It returns the wrong values. In the original code, it often returns one month and one day back// This doesn't fix Safari but consistently returns better dates of one day back for those// time zones without breaking the US timezones   vDate.setUTCFullYear(pYear, pMonth, pDay);   vDate.setUTCHours(0, 0, 0, 0);/* an attempted hack. Doesn't help   if (gIsSafari)   {      var vTZO =  vDate.getTimezoneOffset();      if (vTZO < 0)      {      // safari in other time zones will not use UTC because its so unreliable that a non-UTC value is more stable      var vTime = vDate.valueOf() - vDate.getTimezoneOffset() * 1000 * 60; // vDate.getTimezoneOffset() is in seconds. Add milliseconds      vDate = new Date(vTime);      }   }*/   /*   vDate.setUTCFullYear(pYear);   vDate.setUTCMonth(pMonth);   vDate.setUTCDate(pDay);   vDate.setUTCHours(0);   vDate.setUTCMinutes(0);   vDate.setUTCSeconds(0);   vDate.setUTCMilliseconds(0);//!dc-end */   return vDate;
}  // PDP_MakeUTCDate

// PDP_AddMonths adds or subtracts a number of months starting at pDate
// Returns a Date object. pDate must not be null.
// Corrects for date overflow into another month
function PDP_AddMonths(pDate, pNumMonths)
{
   var vMonth = pDate.getMonth();
   var vYear = pDate.getFullYear();
   var vDay = pDate.getDate();
   
   if (pNumMonths > 0)
   {
      vMonth = vMonth + pNumMonths;
      var vIncYears = Math.round((vMonth / 12) - 0.5);
      vYear = vYear + vIncYears;
      vMonth = vMonth % 12;
   }
   else
   {
   // invert vMonth to 11 - vMonth
      vMonth = 11 - vMonth;
      vMonth = vMonth - pNumMonths;   // double negative gives a positive
      var vIncYears = Math.round((vMonth / 12) - 0.5);
      vYear = vYear - vIncYears;
      vMonth = 11 - (vMonth % 12);  // re-invert
   }
   
   do
   {
      vNewDate = new Date(vYear, vMonth, vDay);
      vDay--;
   }
   while (vNewDate.getMonth() != vMonth)
   return vNewDate;
}  // PDP_AddMonths

// PDP_GetUTCInAtt retrieves three attributes from pOwnerField
// which are pHeading+"_Year", pHeading+"_Month", and pHeading+"_Day"
// and creates a UTC date for that day.
// If the Year is unassigned, it returns null.
function PDP_GetUTCInAtt(pOwnerField, pHeading)
{
//!dc v1.1.4 for Safari, remove "_". Changes in each pHeading below
   if (!gIsSafari)
      pHeading = pHeading + "_";
   var vYear = pOwnerField.getAttribute(pHeading + "Year");
   if ((vYear != null) && (vYear != ""))
   {
      var vMonth = pOwnerField.getAttribute(pHeading + "Month");
      var vDay = pOwnerField.getAttribute(pHeading + "Day");
      return PDP_MakeUTCDate(vYear, vMonth, vDay);
   }
   else
      return null;
}  // PDP_GetUTCInAtt

// PDP_GetWeekNum returns the week number for pDate. Assumes pDate is the first date of a week.
// pRule:
// 0 = FirstDay. Whatever week contains the first day of the year
// 1 = FirstFullWeek. Whatever week contains all days from the year
// 2 = FirstFourDayWeek. Week must have at least four days in this year
// If the first day is Weds or later, its the first week.
function PDP_GetWeekNum(pDate, pRule, pFDOW)
{
   var vDate1 = PDP_GetFirstWeekNumDate(pDate.getUTCFullYear(), pRule, pFDOW);
   var vWkNum = Math.round(1 + ((pDate - vDate1) / (86400000 * 7)));
   if (vWkNum > 52)  // see if it's week 53 or 1
   {
      var vDate2 = PDP_GetFirstWeekNumDate(pDate.getUTCFullYear() + 1, pRule, pFDOW);
      if (vDate2 <= pDate)
         vWkNum = 1;
   }
   return vWkNum;
}  // PDP_GetWeekNum

// PDP_GetFirstWeekNumDate returns a Date object (UTC based) with the date of the first week number
// for a given year
function PDP_GetFirstWeekNumDate(pYear, pRule, pFDOW)
{
   var vDate = PDP_MakeUTCDate(pYear, 0, 1);
   var vDOW = vDate.getUTCDay();
   switch (pRule)
   {
      case 0:  // week with day 1
         if (vDOW == pFDOW)
            return vDate;
         else  // reverse the date to the first pFirstDayOfWeek
         {
            var vUTC = vDate.valueOf();
            if (pFDOW > vDOW)
               vUTC = vUTC - ((vDOW - pFDOW + 7) * 86400000); // 86,400,000 is number of millisecs in a day
            else
               vUTC = vUTC - ((vDOW - pFDOW) * 86400000);   
            return new Date(vUTC);  // update the first date
         }
         break;
      case 1:  // first full week
         if (vDOW == pFDOW)
            return vDate;
         else  // advance the date to the first pFirstDayOfWeek
            return PDP_MakeUTCDate(pYear, 0, 1 + (pFDOW + 7 - vDOW));
         break;
      default:
         if (pFDOW > 3)
            pFDOW = pFDOW + 4;
         if (vDOW <= pFDOW + 3)
            return PDP_GetFirstWeekNumDate(pYear, 0, pFDOW);
         else  // advance the date to the first pFirstDayOfWeek
            return PDP_MakeUTCDate(pYear, 0, 1 + (pFDOW + 7 - vDOW));
         break;     
   }  // switch
}  // PDP_GetFirstWeekNumDate

// PDP_RelocatePopup moves a popup panel from its current node to the root of the document.
// Since the popup may be nested within another absolutely positioned DIV, it will get clipped against
// that DIV. Relocate the popup menu to the root of the document
//!dc v1.1.6 changed parameter name from pPopupField to pPF
function PDP_RelocatePopup(pPF)
{
// AVOID using the opaque filter on DIVs when using smart navigation. This is only used when SmartNav is off
// because it breaks smart nav. window.__smartNav is assigned when smart nav is on
//!bf v1.1.6 IE 4 doesn't support parentNode, removeChild, or appendChild so don't move the object
    var vPN = pPF.parentNode;
    if ((vPN != null) && (vPN != document.body) && (vPN.tagName != "FORM") && (window.__smartNav == null))
/*
    if ((pPF.parentNode != document.body) && (pPF.parentNode.tagName != "FORM") && (window.__smartNav == null))
//!bf-end */    
    {
      if ((document.body.removeChild != null) && 
          ((document.body.appendChild != null) || (document.body.outerHTML != null)))
      {
         var vMoving = vPN.removeChild(pPF);      //!bf v1.1.6   pPF.parentNode -> vPN  
         if (!gIsOpera7 && (vMoving.outerHTML != null))   // IE fails with appendChild giving an alert with "Operation aborted".
         {
            document.write(vMoving.outerHTML);
         }
         else         
            document.body.appendChild(vMoving); 
      }     
    }
  
}  // PDP_RelocatePopup()
//!dc-end
/*
function DebugOffsets(pTglObj, pPUObj)
{
   var pDebugFld = document.getElementById("TEST");
   if (pDebugFld != null)
   {
      var vMsg = "";
      var vList = "";
      if (pTglObj != null)
      {
         var curleft = 0;
         var curtop = 0;
         var vObj = pTglObj;
		   while (vObj != null)
		   {
			   curleft += vObj.offsetLeft;
			   curtop += vObj.offsetTop;
			   vObj = vObj.offsetParent;
		   }
		   vMsg = "Toggle X: " + curleft + " Y: " + curtop + " Style: " + pTglObj.style.cssText;
		}
      if (pPUObj != null)
      {
         var curleft = 0;
         var curtop = 0;
         var vObj = pPUObj;
		   while (vObj != null)
		   {
			   curleft += vObj.offsetLeft;
			   curtop += vObj.offsetTop;
			   vList += vObj.tagName + " ID:" + vObj.id + " Left:" + vObj.offsetLeft + " Top: " + vObj.offsetTop +"<br>";
			   vObj = vObj.offsetParent;
		   }
		   vMsg += " Popup ID: " + pPUObj.id +" X: " + curleft + " Y: " + curtop + " Style: " + pPUObj.style.cssText;
		}

      pDebugFld.innerHTML = vMsg + "<br>" + vList;
   }
}  // DebugOffsets
*/
