/*  Copyright (c) 2000-2002 PeopleSoft, Inc.  All Rights Reserved.
    ToolsRel: 8.42 */

if (window.showhide == null)
{
  window.showhide = function (obj, bShow)
  {
  if (obj == null)
     return;
  if (bShow)
  {
    var y = getScrollY();
    if (y != 0)
      obj.style.top = y;
    obj.style.visibility = "visible";
    obj.style.display = "block";
  }
  else
  {
    obj.style.visibility = "hidden";
    obj.style.display = "none";
  }
  }
}

function processing_win0(opt,waittime)
{
var waitobj = document.getElementById("WAIT_win0");
var saveobj = document.getElementById("SAVED_win0");

if (opt == 0)
{
  showhide(waitobj, false);
  showhide(saveobj, false);
  return;
}

if (opt == 1)
{
   showhide(waitobj, true);
   showhide(saveobj, false);
   return;
}

if (opt == 2)
{
   showhide(waitobj, false);
   showhide(saveobj, true);
   setTimeout("processing_win0(0);",waittime);
}
}

function isAltKey(evt)
{
if (!evt && window.event)
  evt = window.event;
if (!evt)
  return false;

if (evt.altKey)
  return true;
if (evt.modifiers)
  return (evt.modifiers & Event.ALT_MASK) != 0;
return false;
}

function isCtrlKey(evt)
{
if (!evt && window.event)
  evt = window.event;
if (!evt)
  return false;

if (evt.ctrlKey)
  return true;
if (evt.modifiers)
  return (evt.modifiers & Event.CONTROL_MASK) != 0;
return false;
}

function isShiftKey(evt)
{
if (!evt && window.event)
  evt = window.event;
if (!evt)
  return false;

if (evt.shiftKey)
  return true;
if (evt.modifiers)
  return (evt.modifiers & Event.SHIFT_MASK) != 0;
return false;
}

function getKeyCode(evt)
{
if (!evt && window.event)
  evt = window.event;
if (!evt)
  return 0;
if (evt.keyCode)
  return evt.keyCode;
if (evt.which)
  return evt.which;
return 0;
}

function cancelBubble(evt)
{
if (!evt && window.event)
  evt = window.event;
if (!evt)
  return;
if (typeof evt.cancelBubble != "undefined")
  evt.cancelBubble = true;
if (typeof evt.stopPropagation != "undefined" && evt.stopPropagation)  
  evt.stopPropagation();
}

function isPromptKey(evt)
{
if (isAltKey(evt) && getKeyCode(evt) == "5".charCodeAt(0))
{
  cancelBubble(evt);   
  return true;
}
return false;
}

function getEventTarget(evt)
{
if (!evt && window.event)
  evt = window.event;
if (!evt)
  return null;
if (evt.srcElement)
  return evt.srcElement;
if (evt.target)
  return evt.target;
return null;
}

function getModifiers(evt)
{
var res = "";
if (isAltKey(evt))
  res += "A";
if (isCtrlKey(evt))
  res += "C";
if (isShiftKey(evt))
  res += "S";
return res;
}

var nLastKey_win0 = 0;

function doKeyDown_win0(evt)
{
nLastKey_win0 = getKeyCode(evt);

if (nLastKey_win0 != "\t".charCodeAt(0))
  return true;

if (isCtrlKey(evt))
  return tryFocus(oFirstTab_win0);

if (isAltKey(evt) || isShiftKey(evt))
  return true;

var obj = getEventTarget(evt);

if (obj == oLastTab_win0)
{
  if (oFirstTB_win0)
  {
    if (!bTabOverTB_win0)
      return true;
  }
  if (oFirstPg_win0)
  {
    if (!bTabOverPg_win0)
       return tryFocus(oFirstPg_win0);
  }
  if (bTabOverNonPS_win0 || oFirstTB_win0 != null || oFirstPg_win0 != null)
    return tryFocus(oFirstTab_win0);
  return true;
}

if (obj == oLastTB_win0)
{
  if (oFirstPg_win0)
  {
    if (!bTabOverPg_win0)
       return tryFocus(oFirstPg_win0);
  }
  if (bTabOverNonPS_win0 || oFirstPg_win0 != null)
    return tryFocus(oFirstTab_win0);
  return true;
}

if (obj == oLastPg_win0)
{
  if (bTabOverNonPS_win0)
    return tryFocus(oFirstTab_win0);
  return true;
}
}

function getLastKey_win0()
{
var nTemp = nLastKey_win0;
nLastKey_win0 = 0;
return nTemp;
}

function doKeyUp_win0(evt)
{
var key = getKeyCode(evt);
var keyChar = String.fromCharCode(key);

if (keyChar == "\r")
  return true;

if (!routeKeyEvent(evt))
  return false;

var bAlt = isAltKey(evt);
var bCtrl = isCtrlKey(evt);
var bNotMine = false;

if (bAlt)
{
  if (bCtrl || altKey_win0.indexOf(keyChar) < 0)
    if (keyChar == "9" || key == 220)
       
       
       return true;
   else
       bNotMine = true;
}
else if (bCtrl)
{
  keyChar = String.fromCharCode(key | 0x40);
  if (ctrlKey_win0.indexOf(keyChar) < 0)
    bNotMine = true;
}
else
{
  if (baseKey_win0.indexOf(keyChar) < 0)
    bNotMine = true;
}

if (bNotMine)
{
  
  
  
  if ((bAlt || bCtrl)) 
    {
    
    var navFrame = parent.frames["NAV"];
    if (navFrame && !isCrossDomain(navFrame) && navFrame.parentKeyHandler)
       navFrame.parentKeyHandler(window, key, bAlt, bCtrl);
    }
  
  
  return true;
}

var target = getEventTarget(evt);
var code = getModifiers(evt) + keyChar;

if (target && target.name)
  document.win0.ICFocus.value = target.name;

if (code == "A8")
   if (!doDeleteKey_win0(target))
      return false;

if (code == "A\xbf")
{
  if (window.FindString_win0
      && document.win0.ICFind
      && findScroll(target))
  {
    if (!FindString_win0(document.win0.ICFind))
      return false;
  }
  else
    return false
}

if (code == "A7")
   if (!doInsertKey_win0(target))
      return false;

submitAction_win0(document.win0, "#KEY" + code);
return false;
}

function keyHandler(keyCode, bIsAlt, bIsCtrl)
{
return keyHandler_win0(keyCode, bIsAlt, bIsCtrl);
}

function keyHandler_win0(keyCode, bIsAlt, bIsCtrl)
{
var keyChar = String.fromCharCode(keyCode);
var code = "";
if (bIsAlt)
{
  code = "A";
  if (bIsCtrl || altKey_win0.indexOf(keyChar) < 0)
    return false;
}
else if (bIsCtrl)
{
  code = "C";
  keyChar = String.fromCharCode(keyCode | 0x40);
  if (ctrlKey_win0.indexOf(keyChar) < 0)
    return false;
}
else
  return false;     

code += keyChar;

if (code  == "A8" || code == "A\xbf" || code == "A7")
  return false;

submitAction_win0(document.win0, "#KEY" + code);
return true;
}

function doDeleteKey_win0(obj)
{
if (!window.DeleteCheck2_win0)
  return false;

var scroll = findScroll(obj);
if (!scroll)
   return false;                        

var buttonid = scroll.id.replace(/\$scroll[im]?\$/,"\$fdelete\$")
if (document.getElementById(buttonid))
  return DeleteCheck2_win0();

if (obj.name.search(/\$(\d*)(\$\$\d*)?$/) < 0)
  return false;         
var row = RegExp.$1;    

if (buttonid.search(/^(.*)(\$fdelete\$)(.*)$/) < 0)
  return false;
buttonid = RegExp["$1"] + "$delete$" + row + "$$" + RegExp["$3"];

if (document.getElementById(buttonid))
  return DeleteCheck2_win0();

return false;

}

function doInsertKey_win0(obj)
{
if (!window.AddMultiple_win0)
  return false;

var scroll = findScroll(obj);
if (!scroll)
   return false;                        

if (scroll.id.match(/\$scrollm\$/))     
  return AddMultiple_win0(document.win0.ICAddCount);

if (scroll.id.match(/\$scrolli\$/))     
   return true;

return false;

}

function findScroll(obj)
{
while (obj)
{
  if (typeof obj.id  != "undefined")
     if (obj.id.match(/\$scroll/))
        return obj;
  if (typeof obj.parentNode != "undefined")
    obj = obj.parentNode;
  else   
  if (typeof obj.offsetParent != "undefined")
    obj = obj.offsetParent;
  else
    return null;
}
}

if (window.doKeyPress_win0 == null)
{
  window.doKeyPress_win0 = function (evt)
  {
  var key = getKeyCode(evt);
  var keyChar = String.fromCharCode(key);

  
  
  if (keyChar != "\r")
    return true;

  
  if (!routeKeyEvent(evt))
    return false;

  
  
  var target = getEventTarget(evt);

  if (target)
  {
    if (typeof target.onclick == "function" || target.href)
      return true;
    if (target.type == "textarea")
      return true;
  }

  var code = getModifiers(evt) + keyChar;

  if (target && target.name)
    document.win0.ICFocus.value = target.name;

  submitAction_win0(document.win0, "#KEY" + code);
  return false;
  }
}

var oFirstTab_win0 = null;
var oLastTab_win0 = null;
var oFirstTB_win0 = null;
var oLastTB_win0 = null;
var oFirstPg_win0 = null;
var oLastPg_win0 = null;

var nFirstTBIndex = 5000;        
var nFirstPgIndex = 10000;

function checkTabIndex(obj)
{
if (obj.tabIndex && obj.tabIndex >= 0)
{
  if (obj.tabIndex < nFirstTBIndex)
  {
    if (oLastTab_win0 == null || obj.tabIndex > oLastTab_win0.tabIndex)
        oLastTab_win0 = obj;
    if (oFirstTab_win0 == null || obj.tabIndex < oFirstTab_win0.tabIndex)
        oFirstTab_win0 = obj;
  }
  else if (obj.tabIndex < nFirstPgIndex)
  {
    if (oLastTB_win0 == null || obj.tabIndex > oLastTB_win0.tabIndex)
        oLastTB_win0 = obj;
    if (oFirstTB_win0 == null || obj.tabIndex < oFirstTB_win0.tabIndex)
        oFirstTB_win0 = obj;
  }
  else
  {
    if (oLastPg_win0 == null || obj.tabIndex > oLastPg_win0.tabIndex)
        oLastPg_win0 = obj;
    if (oFirstPg_win0 == null || obj.tabIndex < oFirstPg_win0.tabIndex)
        oFirstPg_win0 = obj;
  }
}
}

function setEventHandlers_win0(sFirst, sLast, bMac)
{
var focus1, focus2;
if (bMac)
{
  focus1 = function (evt) {doFocusMac_win0(this, true, true);};
  focus2 = function (evt) {doFocusMac_win0(this, false, true);};
}
else
{
  focus1 = function (evt) {doFocus_win0(this, true, true);};
  focus2 = function (evt) {doFocus_win0(this, false, true);};
}

var i;

if (sFirst!="")
{
  for (i = 0; i < document.anchors.length; ++i)
  {
    if (document.anchors[i].name == sFirst) break;
  }
  for (++i; i < document.anchors.length; ++i)
  {
    var anc =  document.anchors[i];
    if (anc.name == sLast) break;
    checkTabIndex(anc);
    checkNSAccessKeys(anc);
    
    if  (typeof anc.onfocus != "function")
        document.anchors[i].onfocus = focus1;
  }
}
var frm = document.win0;
if (!frm) return;
for (i = 0; i < frm.length; ++i)
{
  var frmi  =  frm[i];
  if (frmi.type=="hidden") continue;
  checkTabIndex(frmi);
  checkNSAccessKeys(frmi);
  if (typeof frmi.onfocus != "function")
  {
    if (typeof frmi.onclick == "function")
      frmi.onfocus = focus1;
    else
      frmi.onfocus = focus2;
  }
}

}

if (window.setKeyEventHandler_win0 == null)
{
  window.setKeyEventHandler_win0 = function ()
    {
    if (typeof(baseKey_win0) != "undefined")
    {
      document.onkeyup = doKeyUp_win0;
      if (baseKey_win0.indexOf("\r") >= 0)
         document.onkeypress = doKeyPress_win0;
    }
    document.onkeydown = doKeyDown_win0;
    }
}

if (window.routeKeyEvent == null)
{
  window.routeKeyEvent = function(evt)
    {
    return true;
    }
}

if (window.checkNSAccessKeys == null)
{
  window.checkNSAccessKeys = function(obj)
    {
    return;
    }
}

function setFocus_win0(fldname, indx)
{
var obj = null;
if (document.win0)
{
  obj = document.win0.elements[fldname];
  if (!obj)
     obj = document.win0[fldname];
}
if (!obj)
    obj = document.getElementById(fldname);
if (!obj) return;
if (indx >= 0 && obj.length && indx < obj.length)
    obj = obj[indx];
tryFocus(obj);
}

function tryFocus(obj)
{
if (obj && typeof obj.focus != "undefined" && !obj.disabled)
{
   obj.focus();
   return false;
}
return true;
}
