var
  _webguiIsIE4 = -1;
  in_webguiSetFocus = false;
var a11yAltB = "";

function webguiIsIE4()
{
  if(_webguiIsIE4 == -1)
  {
    if (navigator.appVersion.indexOf("MSIE 4.0") != -1)
      _webguiIsIE4 = true;
    else
      _webguiIsIE4 = false;
  }

  return(_webguiIsIE4);
}

function webguiRedrawOnIE4(element)
{
    if (element && webguiIsIE4())
        element.insertAdjacentHTML("afterEnd", "");
}

var TOOLTIP_DELAY = 750;

///////////////////////////////////////////////////////////////
//  TABLE CONTROL SCROLLING FUNCTIONS /////////////////////////
///////////////////////////////////////////////////////////////
var TC_scrollingState = "";
var TC_cntrl = "";
var TC_first = "";
var TC_row = 0;
var TC_oldRow = -1;
var TC_ysoDiff = 0;
var TC_ToolTipTimerId;

// TC_checkRowToolTip
function TC_checkToolTip()
{
  if (TC_oldRow == TC_row)
  {
    var TC_ToolTip = document.getElementById(TC_cntrl + "TCToolTip");
    if (TC_ToolTip) {
      var o = document.getElementById(TC_cntrl + "TCViewContainer");
      if (o) {
        TC_ToolTip.style.top = o.style.pixelTop +
                   parseInt(document.getElementById(TC_cntrl + "scrollBarRange").style.backgroundPositionY,10) + 36;
      }
      TC_ToolTip.innerText = TC_row;
      TC_ToolTip.style.visibility = "visible";
    }
  }
  else
    TC_oldRow = TC_row;
  TC_ToolTipTimerId = setTimeout('TC_checkToolTip()',TOOLTIP_DELAY);

}
//  moveTCSlider - positions the slider after checking the scrolling range
function moveTCSlider(sliderObj, posY, sliderHeight)
{
  document.getElementById(TC_cntrl + "TCToolTip").style.visibility = "hidden";
  var range = sliderObj.clientHeight;
  if (posY <= (sliderHeight >> 1))             sliderObj.style.backgroundPositionY = 0;
  else if (posY > range - (sliderHeight >> 1)) sliderObj.style.backgroundPositionY = range - sliderHeight;
  else                                         sliderObj.style.backgroundPositionY = posY - (sliderHeight >> 1);
}

// calcTCScroll
function calcTCScroll(sliderHeight, sliderObj)
{
  var offsetY = event.screenY - TC_ysoDiff - (sliderHeight >> 1);
  var rangeHeight = sliderObj.clientHeight - sliderHeight;
  // check limits so as not to scroll under the scroll range with the slider
  offsetY = offsetY <= 0 ? 0 : (offsetY > rangeHeight ? rangeHeight : offsetY);
  return offsetY / rangeHeight;
}

//
//  checkTCScrollBar - main scrollbar function - checks for paging or scrolling
//                   note - in ITS there will be another variable when a
//                   roundtrip is called/made (called from webguiSetBusy())
//                   so that the user cannot scroll during a roundtrip
//
function checkTCScrollBar(_event, sliderHeight)
{
  if (TC_cntrl == "")
    return "break";
  var slider = document.getElementById(TC_cntrl + "scrollBarRange");
  document.getElementById(TC_cntrl + "TCToolTip").style.visibility = "hidden";
  if (TC_scrollingState != "scrolling") // if not currently scrolling, then check for paging
  {
    var sliderPosY = parseInt(slider.style.backgroundPositionY,10);
    var diff = _event.screenY - TC_ysoDiff - sliderPosY;
    /////////////// PAGE DOWN /////////////////
    if (diff > sliderHeight) { TC_scrollingState = "NextPage"; clearTimeout(TC_ToolTipTimerId); return TC_scrollingState; }
    /////////////// PAGE UP ///////////////////
    else if (diff < 0) { TC_scrollingState = "PrevPage"; clearTimeout(TC_ToolTipTimerId); return TC_scrollingState; }
    /////////////// SCROLLING //////////////
    else
    {
      TC_scrollingState = "scrolling";
      moveTCSlider(slider,_event.screenY - TC_ysoDiff, sliderHeight);
      return calcTCScroll(sliderHeight, slider);
    }

  }
  /////////////// SCROLLING //////////////
  else
  {
    TC_scrollingState = "scrolling";
    moveTCSlider(slider,_event.screenY - TC_ysoDiff, sliderHeight);
    return calcTCScroll(sliderHeight, slider);
  }
  return TC_scrollingState;
}

function doTCMouseMove(sliderHeight) // for some reason, mousedown is never called
{
  if (event.button == 1)
    return checkTCScrollBar(event,sliderHeight);
  else // if left mouse button not pressed
  {
    TC_scrollingState = "";
    return "";
  }
}

// Table Control Scroll Bar Press and Release - change the button image
function TC_ScrollBarUpPress() { event.srcElement.className = "ScrollUpPressed"; }
function TC_ScrollBarUpRelease() { event.srcElement.className = "ScrollUp"; }
function TC_ScrollBarDownPress() { event.srcElement.className = "ScrollDownPressed"; }
function TC_ScrollBarDownRelease() { event.srcElement.className = "ScrollDown"; }

//
// TC_vSBMouseUpHandler
//
function TC_vSBMouseUpHandler()
{
  clearTimeout(TC_ToolTipTimerId);
  event.srcElement.onmouseup = "";
  TC_scrollingState = "";
  if (TC_first != TC_row)
    raiseEvent(TC_cntrl,'JumpRow',TC_cntrl + '-jumprow=' + TC_row);
  else
    document.releaseCapture();
  document.getElementById(TC_cntrl + "TCToolTip").style.visibility = "hidden";
}

//
// TC_vSBMouseMoveHandler
//
function TC_vSBMouseMoveHandler(cntrl, rows, sb_size)
{
  var e = doTCMouseMove(sb_size);
  if (e!='')
  {
    if (e == "break")
      return;
    if (checkNumber(e))
    {
      event.srcElement.onmouseup = TC_vSBMouseUpHandler;
      TC_row = getTCRowNo(rows,e)
    }
    else
      raiseEvent(TC_cntrl,e);
  }
  else if (checkNumber(e))
  {
    event.srcElement.onmouseup = TC_vSBMouseUpHandler;
    TC_row = getTCRowNo(rows,e)
  }
}

//
// TC_vSBMouseDownHandler
//
function TC_vSBMouseDownHandler(cntrl,firstRow,rows, sb_size)
{
  TC_cntrl = cntrl;
  TC_ToolTipTimerId = setTimeout('TC_checkToolTip()',TOOLTIP_DELAY);
  TC_ysoDiff = event.screenY - event.offsetY;
  var e = checkTCScrollBar(event,sb_size);
  document.getElementById(cntrl + "TCToolTip").style.left = event.x - 60;

  if (e != '')
  {
    if (checkNumber(e))
    {
      TC_first = firstRow;
      TC_oldRow = TC_row = getTCRowNo(rows,e);
      event.srcElement.setCapture();
      event.srcElement.onmouseup = TC_vSBMouseUpHandler;
    }
    else
      raiseEvent(cntrl,e);
  }
  else if (checkNumber(e))
  {
    TC_first = firstRow;
    TC_oldRow = TC_row = getTCRowNo(rows,e);
    event.srcElement.setCapture();
    event.srcElement.onmouseup = TC_vSBMouseUpHandler;
  }
}


//ABP 03.08.2003 - resizeable table columns

var TCColResizeSlider = null;
var TCCellIndex = 0;
var TCCellLeftBorder = 0;
var TCResizeOffset = 0;

function TCstartColResize(tcname, hasTitle)
{
  var o = event.srcElement
  var cellWidth = 0;
  container = document.getElementById(tcname + "fixColTCDiv");

  var cntr = container.parentElement;

  TCResizeOffset = container.offsetLeft + 10;
  if ((cntr) && (typeof(cntr) == "object") && (cntr.tagName=="DIV"))
  {
      if (cntr.id == "webguictnr");
      TCResizeOffset +=  cntr.offsetLeft;
  }

  var th = o;

  while (th.tagName != "TH")
    th = th.parentElement;

  var tbl = th;
  while (tbl.tagName != "TABLE")
    tbl = tbl.parentElement;

  var cg;
  if (tbl.fixColumnTC==0)
    cg = document.getElementById(tcname + "-notfix-ColGroup");
  else
    cg = document.getElementById(tcname + "-ColGroup");

  cellWidth = th.clientWidth;

  TCCellIndex = th.TRUECELLINDEX;

  if (cellWidth != 0)
    TCCellLeftBorder = event.clientX - cellWidth;

  if (!TCColResizeSlider)
  {
    var left = event.clientX - TCResizeOffset;
    /* abp - the slider position is too far right when rendered with splitter controls
       this should be fixed for the next patch, but for now just setting the
       display style attribute to "none"
    */
    var newSlider = "<DIV id='TCColResizeSlider' STYLE='display:none;visibility:hidden;border:solid #DCE3EC 1;position:absolute;left:"+left+";top:";
    if (hasTitle)
      newSlider = newSlider + "18px;";
    else
      newSlider = newSlider + "0px;";

    newSlider = newSlider + "width:2px;height:" + container.style.height + ";'></DIV>";

    container.insertAdjacentHTML("afterBegin",newSlider);
    TCColResizeSlider = document.getElementById("TCColResizeSlider");
  }
  o.setCapture();
}

function TCColResize(tcname)
{
  if (TCColResizeSlider != null)
  {
      if ((event.clientX - TCCellLeftBorder) > 0)
        TCColResizeSlider.style.posLeft = event.clientX - TCResizeOffset;
  }
}

function TCstopColResize(tcname, webgui_font_width)
{
  if (TCColResizeSlider)
  {
    TCColResizeSlider.style.display="none";
    TCcolResizeSlider = null;
    document.releaseCapture();

    var w;
    if ((event.clientX - TCCellLeftBorder) > webgui_font_width)
      w = (event.clientX - TCCellLeftBorder) / webgui_font_width;
    else
      w = 1;

    raiseEvent(tcname,"resizecol","colindex=" + (TCCellIndex) + "&width=" + w);
  }
}


///////////////////////////////////////////////////////////////
//  LIST SCROLLING FUNCTIONS //////////////////////////////////
///////////////////////////////////////////////////////////////

var List_HscrollingState = "";
var List_VscrollingState = "";
var List_ysoDiff = 0;
var List_xsoDiff = 0;
var List_cntrl = "";
var List_first_row = 0;
var List_row  = "";
var List_first_col = 0;
var List_col  = "";
var List_oldRow = -1;
var List_RowToolTipTimerId;
var List_oldCol = -1;
var List_ColToolTipTimerId;

//
//  List_checkRowToolTip
//
function List_checkRowToolTip()
{
  if (List_oldRow == List_row)
  {
    var List_ToolTip = document.getElementById(List_cntrl + "listRowToolTip");
    if (!List_ToolTip)
      return;
    List_ToolTip.style.pixelTop = parseInt(document.getElementById(List_cntrl + "VscrollBarRange").style.backgroundPositionY,10) + 32;
    List_ToolTip.innerText = List_row;
    List_ToolTip.style.visibility = "visible";
    List_ToolTip.style.display = "block";
  }
  else
    List_oldRow = List_row;
  List_RowToolTipTimerId = setTimeout('List_checkRowToolTip()',TOOLTIP_DELAY);
}

//
//  List_checkColToolTip
//
function List_checkColToolTip()
{
  if (List_oldCol == List_col)
  {
    var List_ToolTip = document.getElementById(List_cntrl + "listColToolTip");
    if (!List_ToolTip)
      return;
    // the +75 is a hard-coded magic number, because the scrollbar size itself is hardcoded.
    List_ToolTip.style.pixelLeft = parseInt(document.getElementById(List_cntrl + "HscrollBarRange").style.backgroundPositionX,10) + 75;
    List_ToolTip.innerText = List_col;
    List_ToolTip.style.visibility = "visible";
    List_ToolTip.style.display = "block";
  }
  else
    List_oldCol = List_col;
  List_ColToolTipTimerId = setTimeout('List_checkColToolTip()',TOOLTIP_DELAY);
}

//
//  moveVListSlider - positions the vertical slider after checking the scrolling range
//
function moveVListSlider(sliderObj, posY, sb_size)
{
  document.getElementById(List_cntrl + "listRowToolTip").style.visibility = "hidden";
  var half_sb_size = (sb_size >> 1);
  if (posY < half_sb_size)              sliderObj.style.backgroundPositionY = 0;
  else if (posY > sliderObj.clientHeight - half_sb_size) sliderObj.style.backgroundPositionY = sliderObj.clientHeight - sb_size;
  else                                  sliderObj.style.backgroundPositionY = posY - half_sb_size;
}

//
//  moveHListSlider - positions the vertical slider after checking the scrolling range
//
function moveHListSlider(sliderObj, posX, sb_size)
{
  document.getElementById(List_cntrl + "listColToolTip").style.visibility = "hidden";
  var half_sb_size = sb_size >> 1;
  if (posX < half_sb_size)                              sliderObj.style.backgroundPositionX = 0;
  else if (posX > sliderObj.clientWidth - half_sb_size) sliderObj.style.backgroundPositionX = sliderObj.clientWidth - sb_size;
  else                                                  sliderObj.style.backgroundPositionX = posX - half_sb_size;
}

//
// calcVListScroll
//
function calcVListScroll(sb_size, sliderObj)
{
  var offsetY = event.screenY - List_ysoDiff - (sb_size >> 1);
  var rangeHeight = sliderObj.clientHeight - sb_size;
  // check limits so as not to scroll under the scroll range with the slider
  offsetY = offsetY <= 0 ? 0 : (offsetY > rangeHeight ? rangeHeight : offsetY);
  return offsetY / rangeHeight;
}

//
// calcHListScroll
//
function calcHListScroll(sb_size, sliderObj)
{
  var offsetX = event.screenX - List_xsoDiff - (sb_size >> 1);
  var rangeWidth = sliderObj.clientWidth - sb_size;
  // check limits so as not to scroll under the scroll range with the slider
  offsetX = offsetX <= 0 ? 0 : (offsetX > rangeWidth ? rangeWidth : offsetX);
  var percent = offsetX / rangeWidth;
  return percent;
}

//
//  checkVListScrollBar - main scrollbar function - checks for paging or scrolling
//                   note - in ITS there will be another variable when a
//                   roundtrip is called/made (called from webguiSetBusy())
//                   so that the user cannot scroll during a roundtrip
//
function checkVListScrollBar(_event, range, sb_size)
{
  if (List_cntrl == "")
    return "break";
  var slider = document.getElementById(List_cntrl + "VscrollBarRange");
  document.getElementById(List_cntrl + "listRowToolTip").style.visibility = "hidden";
  if (List_VscrollingState != "scrolling") // if not currently scrolling, then check for paging
  {
    var sliderPosY = parseInt(slider.style.backgroundPositionY,10);
    // the slider's position is originally calculated as a percent,
    // so slider.style.backgroundPositionY will be <integer>%. If the user moves the
    // scroller around and returns it to its starting position (i.e. the scrollbar
    // is moved but no event is fired), its position will then be a pixel
    // position designated by <integer>px. We must compute the user's click differently
    // for each case.
    if ((slider.style.backgroundPositionY).indexOf("%") != -1)
    {
      var sliderHeightPercent = (sb_size * 100) / slider.clientHeight;
      var clickPos = (_event.offsetY * 100) / slider.clientHeight;
      var diff = clickPos - sliderPosY;
      /////////////// PAGE DOWN /////////////////
      if (diff > sliderHeightPercent) {List_VscrollingState = "NextPage";clearTimeout(List_RowToolTipTimerId); return List_VscrollingState; }
      /////////////// PAGE UP ///////////////////
      else if (diff < -sliderHeightPercent) { List_VscrollingState = "PrevPage";clearTimeout(List_RowToolTipTimerId); return List_VscrollingState; }
      /////////////// SCROLLING //////////////
      else
      {
        List_VscrollingState = "scrolling";
        moveVListSlider(slider,_event.screenY - List_ysoDiff, sb_size);
        return calcVListScroll(sb_size, slider);
      }
    }
    else // the case after the first click, i.e. for the second time the user moves the scroller
    {
      var diff = _event.offsetY - sliderPosY;
      /////////////// PAGE DOWN /////////////////
      if (diff > sb_size) { List_VscrollingState = "NextPage";clearTimeout(List_RowToolTipTimerId); return List_VscrollingState; }
      /////////////// PAGE UP ///////////////////
      else if (diff < 0) { List_VscrollingState = "PrevPage";clearTimeout(List_RowToolTipTimerId);  return List_VscrollingState; }
      /////////////// SCROLLING //////////////
      else
      {
        List_VscrollingState = "scrolling";
        moveVListSlider(slider,_event.screenY - List_ysoDiff, sb_size);
        return calcVListScroll(sb_size, slider);
      }
    }
  }
  /////////////// SCROLLING //////////////
  else
  {
    moveVListSlider(slider,_event.screenY - List_ysoDiff, sb_size);
    return calcVListScroll(sb_size, slider);
  }
  return List_VscrollingState;
}

//
//  checkHListScrollBar - main scrollbar function - checks for paging or scrolling
//                   note - in ITS there will be another variable when a
//                   roundtrip is called/made (called from webguiSetBusy())
//                   so that the user cannot scroll during a roundtrip
//
function checkHListScrollBar(_event, range, sb_size)
{
  if (List_cntrl == "")
    return "break";
  var slider = document.getElementById(List_cntrl + "HscrollBarRange");
  document.getElementById(List_cntrl + "listColToolTip").style.visibility = "hidden";
  if (List_HscrollingState != "scrolling") // if not currently scrolling, then check for paging
  {
    var sliderPosX = parseInt(slider.style.backgroundPositionX,10);

    // the slider's position is originally calculated as a percent,
    // so slider.style.backgroundPositionX will be <integer>%. If the user moves the
    // scroller around and returns it to its starting position (i.e. the scrollbar
    // is moved but no event is fired), its position will then be a pixel
    // position designated by <integer>px. We must compute the user's click differently
    // for each case.
    if ((slider.style.backgroundPositionX).indexOf("%") != -1)
    {
      var sliderWidthPercent = (sb_size * 100) / slider.clientWidth;
      var clickPos = (_event.offsetX * 100) / slider.clientWidth; // done with percentages
      var diff = clickPos - sliderPosX;
      /////////////// PAGE RIGHT /////////////////
      if (diff > sliderWidthPercent) {List_HscrollingState = "RightPage"; clearTimeout(List_ColToolTipTimerId); return List_HscrollingState; }
      /////////////// PAGE LEFT ///////////////////
      else if (diff < -sliderWidthPercent) { List_HscrollingState = "LeftPage";clearTimeout(List_ColToolTipTimerId); return List_HscrollingState; }
      /////////////// SCROLLING //////////////
      else
      {
        List_HscrollingState = "scrolling";
        moveHListSlider(slider,_event.screenX - List_xsoDiff, sb_size);
        return calcHListScroll(sb_size, slider);
      }
    }
    else // the case after the first click, i.e. for the second time the user moves the scroller
    {
      var diff = _event.offsetX - sliderPosX;
      /////////////// PAGE DOWN /////////////////
      if (diff > sb_size) { List_HscrollingState = "RightPage"; clearTimeout(List_ColToolTipTimerId); return List_HscrollingState; }
      /////////////// PAGE UP ///////////////////
      else if (diff < 0) { List_HscrollingState = "LeftPage"; clearTimeout(List_ColToolTipTimerId); return List_HscrollingState; }
      /////////////// SCROLLING //////////////
      else
      {
        List_HscrollingState = "scrolling";
        moveHListSlider(slider,_event.screenX - List_xsoDiff, sb_size);
        return calcHListScroll(sb_size, slider);
      }
    }
  }
  /////////////// SCROLLING //////////////
  else
  {
    List_HscrollingState = "scrolling";
    moveHListSlider(slider,_event.screenX - List_xsoDiff, sb_size);
    return calcHListScroll(sb_size, slider);
  }
  return List_HscrollingState;
}

//
// doVListMouseMove
//
function doVListMouseMove(range, sb_size)
{
  if (event.button == 1)
    return checkVListScrollBar(event,range,sb_size);
  else // if left mouse button not pressed
  {
    List_VscrollingState = "";
    return "";
  }
}

//
// doHListMouseMove
//
function doHListMouseMove(range, sb_size)
{
  if (event.button == 1)
    return checkHListScrollBar(event,range,sb_size);
  else // if left mouse button not pressed
  {
    List_HscrollingState = "";
    return "";
  }
}

// List Scroll Bar Arrow Button Clicks
function List_ScrollBarUpClick(lname) { List_VscrollingState = "rowUp"; raiseEvent(lname,"ScrollUp"); }
function List_ScrollBarDownClick(lname) {List_VscrollingState = "rowDown";raiseEvent(lname,"ScrollDown"); }
function List_ScrollBarRightClick(lname) {List_HscrollingState = "colRight";raiseEvent(lname,"ScrollRight"); }
function List_ScrollBarLeftClick(lname) {List_HscrollingState = "colLeft";raiseEvent(lname,"ScrollLeft"); }

// List Scroll Bar Press and Release - change the button image
function List_ScrollBarUpPress(){event.srcElement.className = "ScrollUpPressed";}
function List_ScrollBarUpRelease(){event.srcElement.className = "ScrollUp";}
function List_ScrollBarDownPress(){event.srcElement.className = "ScrollDownPressed";}
function List_ScrollBarDownRelease(){event.srcElement.className = "ScrollDown";}
function List_ScrollBarRightPress(){event.srcElement.className = "ScrollRightPressed";}
function List_ScrollBarRightRelease(){event.srcElement.className = "ScrollRight";}
function List_ScrollBarLeftPress(){event.srcElement.className = "ScrollLeftPressed";}
function List_ScrollBarLeftRelease(){event.srcElement.className = "ScrollLeft";}

//
// List_vSBMouseDownHandler - checks to scroll or raise and event (page)
//
function List_vSBMouseDownHandler(cntrl,firstRow,range,sb_size)
{
  List_cntrl = cntrl;
  List_RowToolTipTimerId = setTimeout('List_checkRowToolTip()',TOOLTIP_DELAY);
  List_ysoDiff = event.screenY - event.offsetY;
  var e = checkVListScrollBar(event,range, sb_size);
  if (e != '')
  {
    if (checkNumber(e))
    {
      List_first_row = firstRow;
      List_oldRow = List_row = getListRowNo(range,e);//List_row = getListRowNo(rows,e);
      event.srcElement.setCapture();
      event.srcElement.onmouseup = List_vSBMouseUpHandler;
      document.getElementById(List_cntrl + "listRowToolTip").style.pixelLeft = event.x - 48;
    }
    else
      raiseEvent(cntrl, e);
  }
  else if (checkNumber(e)) // the case when the user scrolls a second time (after moving the scroller back to the same position)
  {
    List_first_row = firstRow;
    List_oldRow = List_row = getListRowNo(range,e);
    event.srcElement.setCapture();
    event.srcElement.onmouseup = List_vSBMouseUpHandler;
    document.getElementById(List_cntrl + "listRowToolTip").style.pixelLeft = event.x - 48;
  }
}

//
// List_hSBMouseDownHandler - handles paging/scrolling
//
function List_hSBMouseDownHandler(cntrl,firstCol,range,sb_size)
{
  List_cntrl = cntrl;
  List_RowToolTipTimerId = setTimeout('List_checkColToolTip()',TOOLTIP_DELAY);
  List_xsoDiff = event.screenX - event.offsetX;
  var e = checkHListScrollBar(event,range, sb_size);
  if (e != '')
  {
    if (checkNumber(e))
    {
      List_first_col = firstCol;
      List_oldCol = List_col = getListRowNo(range,e);
      event.srcElement.setCapture();
      event.srcElement.onmouseup = List_hSBMouseUpHandler;
      document.getElementById(cntrl + "listColToolTip").style.pixelTop = event.y - 42;
    }
    else
      raiseEvent(cntrl,e);
  }
  else if (checkNumber(e)) // the case when the user scrolls a second time (after moving the scroller back to the same position)
  {
    List_first_col = firstCol;
    List_oldCol = List_col = getListRowNo(range,e);
    event.srcElement.onmouseup = List_hSBMouseUpHandler;
    event.srcElement.setCapture();
    document.getElementById(cntrl + "listColToolTip").style.pixelTop = event.y - 42;
  }
}

//
// List_vSBMouseUpHandler - this handler is dynamically set after the user scrolls
//                          oddly enough, this is called several times after a
//                          mouse up event, event though we set the onmouseup event
//                          to "" after it is called. Anyway, even though this
//                          results in multiple calls to raiseEvent(), the raiseEvent
//                          function knows only to handle the first one, so following
//                          calls are ignored.
//
function List_vSBMouseUpHandler()
{
  document.getElementById(List_cntrl + "listRowToolTip").style.visibility = "hidden";
  clearTimeout(List_RowToolTipTimerId);
  event.srcElement.onmouseup = "";
  List_VscrollingState = "";
  if (List_first_row != List_row)
    raiseEvent(List_cntrl,'jmprow', 'jmprow=' + List_row);
  else
    document.releaseCapture();

}

//
// List_hSBMouseUpHandler
//
function List_hSBMouseUpHandler()
{
  document.getElementById(List_cntrl + "listColToolTip").style.visibility = "hidden";
  clearTimeout(List_ColToolTipTimerId);
  event.srcElement.onmouseup = "";
  List_HscrollingState = "";
  if (List_first_col != List_col)
    raiseEvent(List_cntrl,'jmpcol','jmpcol=' +  List_col);
  else
    document.releaseCapture();
}

// MouseOutHandler
function List_vSBMouseOutHandler(cntrl){document.getElementById(List_cntrl + "listRowToolTip").style.visibility = "hidden";}
function List_hSBMouseOutHandler(cntrl){document.getElementById(List_cntrl + "listColToolTip").style.visibility = "hidden";}

//
// List_vSBMouseMoveHandler - checks whether to scroll or raise and event (page)
//
function List_vSBMouseMoveHandler(cntrl, range, sb_size, slider_rows)
{
  var e = doVListMouseMove(range, sb_size);
  if (e!='')
  {
    if (checkNumber(e))
    {
      event.srcElement.onmouseup = List_vSBMouseUpHandler;
      List_row = getListRowNo(range,e);
    }
    else
      raiseEvent(List_cntrl, e);
  }
  else if (checkNumber(e))
  {
    event.srcElement.onmouseup = List_vSBMouseUpHandler;
    List_row = getListRowNo(range,e);
  }
}

//
// List_hSBMouseMoveHandler - scrolls the scrollbar or pages (raises and event)
//
function List_hSBMouseMoveHandler(cntrl, range, sb_size, slider_cols)
{
//  if (List_VscrollingState) return;
  var e = doHListMouseMove(range, sb_size);
  if (e!='')
  {
    if (checkNumber(e))
    {
      event.srcElement.onmouseup = List_hSBMouseUpHandler;
      List_col = getListRowNo(range,e);
    }
    else
      raiseEvent(List_cntrl,e);
  }
  else if (checkNumber(e))
  {
    event.srcElement.onmouseup = List_hSBMouseUpHandler;
    List_col = getListRowNo(range,e);
  }
}


function webguiDoListKeyDown(event)
{
  switch (event.keyCode)
  {
    case 33:
      if (typeof(document.getElementById("~listVscrollBarRange") != "undefined"))
        raiseEvent("~list", "PrevPage");
      break;
    case 34:
      if (typeof(document.getElementById("~listVscrollBarRange") != "undefined"))
        raiseEvent("~list", "NextPage");
      break;
    default:
      break;
  }
}

///////////////////////////////////////////////////// old scroll methods (depricated, but still used by alv grids) ////////////////////////////////////
//abp/2002-18-09/scrolling - used in ALV Grid
//  cntrlIDs contains the table control id names.
//  array must be global as it's used with a timeout call which goes out of scope.
var cntrlIDs = new Array();
var _currentScrollIndex = -1;
var VScrolling = false;
var HScrolling = false;

// structure TScrollBar - used for setting the scroll position on load recursively
//                        containes the control id and the position to scroll to.

function TScrollBar(scrollBarID, scrollToID)
{
  this.scrollBarID = scrollBarID;
  this.scrollToID = scrollToID;
  this.scrollDir = "vertical";
  this.count = 0;
}


//
// setVScrollPos - sets the scroll position for the table control after loading the screen.
//                regardless of the readyState, sometimes the scroll bar position just
//                doesn't want to be set.  In such cases setVScrollPosRecursive is called.
//
// requirements:    * scrollBarID is a div defined with overflow style set to scroll and
//                    has overflowing content
//
//                  * scrollToID is the id of the element which has overflowing content within the
//                    scrollBarID
//
function setVScrollPos(scrollBarID, scrollToID)
{
  VScrolling = false;
  document.getElementById(scrollToID).scrollIntoView();
  if (document.getElementById(scrollBarID).scrollTop == 0)
  {
    for (i = 0; i < cntrlIDs.length; i++)
    {
      if (cntrlIDs[i].scrollBarID == scrollBarID)
      {
        _currentScrollIndex = i;
        break;
      }
    }
    if (cntrlIDs.length == i)
    {
      _currentScrollIndex = cntrlIDs.length;
      cntrlIDs.push(new TScrollBar(scrollBarID, scrollToID));
    }
    window.setTimeout('setVScrollPosRecursive()',10);
  }
}

//
// setHScrollPos - sets the scroll position for the table control after loading the screen.
//                regardless of the readyState, sometimes the scroll bar position just
//                doesn't want to be set.  In such cases setHScrollPosRecursive is called.
//
// requirements:    * scrollBarID is a div defined with overflow style set to scroll and
//                    has overflowing content
//
//                  * scrollToID is the id of the element which has overflowing content within the
//                    scrollBarID
//
function setHScrollPos(scrollBarID, scrollToID)
{
  HScrolling = false;
  document.getElementById(scrollToID).scrollIntoView();
  if (document.getElementById(scrollBarID).scrollWidth == 0)
  {
    for (i = 0; i < cntrlIDs.length; i++)
    {
      if (cntrlIDs[i].scrollBarID == scrollBarID)
      {
        _currentScrollIndex = i;
        break;
      }
    }
    if (cntrlIDs.length == i)
    {
      _currentScrollIndex = cntrlIDs.length;
      cntrlIDs.push(new TScrollBar(scrollBarID, scrollToID));
    }
    window.setTimeout('setHScrollPosRecursive()',10);
  }
  HScrolling = false;
}

//
// setVScrollPosRecursive -
//                  called from setVScrollPos in the case where, despite
//                  readyState (can be complete), the scroll position was not set.
//
// NOTE:            This function uses (and must use) the following global variables:
//
//                  cntrlIDs -> array containing the TScrollBar structures for all the
//                              controls with unset scroll bars
//
//                  _currentScrollIndex -> index in cntrlIDs array of the most recent
//                                         control still needed its position set
//
function setVScrollPosRecursive()
{
  VScrolling = false;
  document.getElementById(cntrlIDs[_currentScrollIndex].scrollToID).scrollIntoView(false);
  if (cntrlIDs[_currentScrollIndex].count++ < 6) // just picked 6 from the top of my head... a modest amount I thought, but will see if it works.
  {
    if (document.getElementById(cntrlIDs[_currentScrollIndex].scrollBarID).scrollTop != 0)
    {
      cntrlIDs.splice(_currentScrollIndex,1); // remove this id from the cntrlIDs array
      _currentScrollIndex = cntrlIDs.length - 1;
      if (_currentScrollIndex >= 0)
        window.setTimeout('setVScrollPosRecursive()',10); // direct recursion causes an infinite loop
    }
    else
      window.setTimeout('setVScrollPosRecursive()',10); // direct recursion causes an infinite loop
  }
}

//
// setHScrollPosRecursive -
//                  called from setHScrollPos in the case where, despite
//                  readyState (can be complete), the scroll position was not set.
//
// NOTE:            This function uses (and must use) the following global variables:
//
//                  cntrlIDs -> array containing the TScrollBar structures for all the
//                              controls with unset scroll bars
//
//                  _currentScrollIndex -> index in cntrlIDs array of the most recent
//                                         control still needed its position set
//
function setHScrollPosRecursive()
{
  HScrolling = false;
  document.getElementById(cntrlIDs[_currentScrollIndex].scrollToID).scrollIntoView(false);
  if (cntrlIDs[_currentScrollIndex].count++ < 6) // just picked 6 from the top of my head... a modest amount I thought, but will see if it works.
  {
    if (document.getElementById(cntrlIDs[_currentScrollIndex].scrollBarID).scrollWidth != 0)
    {
      cntrlIDs.splice(_currentScrollIndex,1); // remove this id from the cntrlIDs array
      _currentScrollIndex = cntrlIDs.length - 1;
      if (_currentScrollIndex >= 0)
        window.setTimeout('setHScrollPosRecursive()',10); // direct recursion causes an infinite loop
    }
    else
      window.setTimeout('setHScrollPosRecursive()',10); // direct recursion causes an infinite loop
  }
  HScrolling = false;
}

//abp/15-08-02 scrolling

// doVScrolling - called while the user moves (scrolls) the scroll bar.
//    it calculates the correct page (or row) of the table
//    control based on the  scroll bar position
//

function doVScrolling(percent)
{
  // propagate the event to be caught by either the mousemove or mouseout events of the div object which holds the scrollbar
  event.returnValue=true;
  event.cancelBubble=false;
  VScrolling=true;
  return (Math.round(getVScrollPos(event.srcElement, percent)));
}

// doHScrolling - called while the user moves (scrolls) the scroll bar.
//    it calculates the correct page (or row) of the table
//    control based on the  scroll bar position
//

function doHScrolling(percent)
{
  // propagate the event to be caught by either the mousemove or mouseout events of the div object which holds the scrollbar
  event.returnValue=true;
  event.cancelBubble=false;
  HScrolling=true;
  return (Math.round(getHScrollPos(event.srcElement, percent)));
}


//
// doVScrollEvent -  actually called by either a mousemove or mouseout event after the user releases
//                  the scrollbar,  These are the only two registered events we can check after the
//                  scroll bar is released to determine if it has been moved or not.
//
function doVScrollEvent(percent)
{
  if (VScrolling == true)
  {
    VScrolling = false;
    event.returnValue=false;
    event.cancelBubble=true;
    return (Math.round(getVScrollPos(event.srcElement, percent)));
  }
  return -1;
}


//
// doHScrollEvent -  actually called by either a mousemove or mouseout event after the user releases
//                  the scrollbar,  These are the only two registered events we can check after the
//                  scroll bar is released to determine if it has been moved or not.
//
function doHScrollEvent(percent)
{
  if (HScrolling == true)
  {
    HScrolling = false;
    event.returnValue=false;
    event.cancelBubble=true;
    return (Math.round(getHScrollPos(event.srcElement, percent)));
  }
  return -1;
}


//
// getHScrollPos - returns the horizontal position of the scroll bar as a percentage
//
function getHScrollPos(obj, percent)
{
  var percentScrolled = -1;
  var sliderWidth = (percent * obj.scrollWidth) / 100;
  var scrollBarRange = obj.scrollWidth - sliderWidth;

  if (obj.scrollLeft != 0)
  {
    percentScrolled = obj.scrollLeft / scrollBarRange;
    if (percentScrolled >= 0.99) percentScrolled = 1.0; // guarantee the range to be between 0 and 100
  }
  else
    percentScrolled = 0;
  return percentScrolled;
}

//
// getVScrollPos - returns the vertical position of the scroll bar as a percentage
//
function getVScrollPos(obj, percent)
{
  var percentScrolled = -1;
  var sliderHeight = (percent * obj.scrollHeight) / 100;
  var scrollBarRange = obj.scrollHeight - sliderHeight;

  if (obj.scrollTop != 0)
  {
    percentScrolled = obj.scrollTop / scrollBarRange;
  }
  else
    percentScrolled = 0;
  return percentScrolled;
 }

//abp/ 24-8-02

//===========================================================
// Table Control
// ==========================================================

function toggleTS_multiple(me,iconname_sel,iconname_desel)
{
  var statefield = me.parentElement.all(0) ;  // Parent is <TD> tag
  var parentTD = webguiTableCellGetTD(me);
  var parentTR = parentTD.parentElement;
  var TCHandle = webguiGetTC(parentTD);
  var regularexp = new RegExp();

  if (TCHandle)
    var notfixTCHandle = document.getElementById(TCHandle.id+"-notfix");

  if (notfixTCHandle)
  {
    var parentTD2 = notfixTCHandle.rows[parentTR.getAttribute("ir")].cells[parentTD.getAttribute("ic")];
    var parentTR2 = parentTD2.parentElement;
  }

  if ( statefield.value == "X" )
  {
    if (accessibility)
    {
      regularexp.compile(tableselectedtext);
      me.alt = me.alt.replace(regularexp, tableunselectedtext);
    }
    statefield.value = "" ;
    me.className = iconname_desel ;
    parentTR.selected = false;
    TCRowSelect(parentTD,"Unselect");
    if (parentTD2 && parentTR2)
    {
      parentTR2.selected = false;
      TCRowSelect(parentTD2,"Unselect");
    }
  }
  else
  {
    if (accessibility)
    {
      regularexp.compile(tableunselectedtext);
      me.alt = me.alt.replace(regularexp, tableselectedtext);
    }
    statefield.value = "X" ;
    me.className = iconname_sel ;
    parentTR.selected = true;
    TCRowSelect(parentTD,"Select");
    if (parentTD2 && parentTR2)
    {
      parentTR2.selected = true;
      TCRowSelect(parentTD2,"Select");
    }
  }

  // Set focus to first cell in row
  if (parentTR && parentTR.cells)
  {
    var element;
    // check cells in fixed table
    for (i=1; i<parentTR.cells.length; i++)
    {
      element = webguiGetFocusElement(parentTR.cells[i]);
      if (element) break;
    }

    // check cells in -notfix table
    if (!element && parentTR2 && parentTR2.cells)
    {
      for (i=0; i<parentTR2.cells.length; i++)
      {
        element = webguiGetFocusElement(parentTR2.cells[i]);
        if (element) break;
      }
    }

    if (element)
    {
      if ((element.tagName == "INPUT" && element.type != "radio" )|| element.tagName == "SELECT")
        webguiFocusField = element.name;
      else
        webguiFocusField = element.id;

      if (element.tagName == "SELECT" || element.className == "labelTableComboCtrl")
        webguiDoFocus(element);

      if (element.className=="labelTableComboCtrl")
        element.click();
      else
        webguiSetFocus();
    }
  }
  event.returnValue=false;
  event.cancelBubble=true;
}

function toggleTS_single(me,tc_name,iconname_sel,iconname_desel)
{
  toggleTS_multiple(me,iconname_sel,iconname_desel) ;
  var selectors = document.all(tc_name) ;
  var parentTD,parentTR;
  var TCHandle, parentTD2, parentTR2, notfixTCHandle;
  if ( selectors != null )
    if ( selectors.length > 0 )
      for ( i=0; i<selectors.length; i++ )
      {
        img = selectors(i).parentElement.all(1) ;
        if ( img != me && img.className == iconname_sel)
        {
          parentTD = webguiTableCellGetTD(selectors(i));
          parentTR = parentTD.parentElement;
          TCHandle = webguiGetTC(parentTD);

          if (TCHandle)
            notfixTCHandle = document.getElementById(TCHandle.id+"-notfix");

          if (notfixTCHandle)
          {
            parentTD2 = notfixTCHandle.rows[parentTR.getAttribute("ir")].cells[parentTD.getAttribute("ic")];
            parentTR2 = parentTD2.parentElement;
          }

          parentTR.selected = false;
          selectors(i).value = "" ;
          selectors(i).parentElement.all(1).className = iconname_desel ;
          TCRowSelect(parentTD,"Unselect");
          if (parentTD2 && parentTR2)
          {
            parentTR2.selected = false;
            TCRowSelect(parentTD2,"Unselect");
          }
        }
      }
  event.returnValue=false;
  event.cancelBubble=true;
}

function webguiFindComboBox(obj)
{
  while (obj && obj.id!= "ComboBox")
    obj = obj.parentElement ;
  return (obj) ;
}

function webguiTableCellGetTD(selectedElement)
{
  while (selectedElement && selectedElement.tagName!= "TD")
    selectedElement = selectedElement.parentElement ;
  return (selectedElement) ;
}

function webguiTableCellGetTR(selectedElement)
{
  while (selectedElement && selectedElement.tagName!= "TR")
    selectedElement = selectedElement.parentElement ;
  return (selectedElement) ;
}

function webguiGetTCView(selectedElement)
{
  while (selectedElement)
  {
    if (selectedElement.className && selectedElement.className == "TCViewContainer")
      return selectedElement;
    selectedElement = selectedElement.parentElement;
  }

  return null;
}

function webguiGetFixColTCDiv(selectedElement)
{
  var r, re;
  re = /fixColTCDiv$/;

  while (selectedElement)
  {

    if ((selectedElement && selectedElement.id) &&  (selectedElement.id.search(re) >= 0))
      return selectedElement;
    selectedElement = selectedElement.parentElement;
  }

  return null;
}

function webguiGetContainer(selectedElement)
{
  while (selectedElement)
  {
    if ( (selectedElement.cn && selectedElement.cn == "webguicontainer") ||
       (selectedElement.className && selectedElement.className == "webguiTSDiv") )
      return selectedElement;
    selectedElement = selectedElement.parentElement;
  }

  return null;
}

function webguiGetFocusElement(element)
{
  while (true)
  {
    if (webguiIsFocusElement(element))
      return element;

    if (element && element.all)
    {
      if (element.all(0) && (element.all(0).tagName == "SCRIPT" ||
                (element.all(0).tagName == "LABEL" && element.all(0).style.display=="none")) )
        element = element.all(1);
      else
        element = element.all(0);
    }
    else
      return null;
  }
}

function webguiGetComboHTML4Table(selectedItem,ds_name,object_name,index,okcode,special,columnwidth,sel_key,sel_value)
{
  var html = "" ;
  var ds_array ;
  var parentTD = webguiTableCellGetTD(event.srcElement);
  var temp_select;
  var option_html = "";
  var useColumnwidth = true;
  var display_key = "";

  ds_array = eval(ds_name) ;
  if (ds_array==null)
    return("") ;

  if (webguicomboboxsortbykeys)
  {
    var add_empty = false;
    var preselected = false;
    var add_empty_value = "", add_empty_key = "";

    if (ds_array.length > 0)
    {
      // according to fewdropdown.cpp
      // do not sort with empty line, add at the end afterwards
      if (ds_array[ds_array.length-1][0] == "")
      {
        add_empty_key = ds_array[ds_array.length-1][0];
        add_empty_value = ds_array[ds_array.length-1][1];
        ds_array.length -= 1;
        add_empty = true;
      }
      ds_array.sort();
    }

    for ( i=0; i<ds_array.length; i++ )
    {
      if (webguicomboboxwkeys && ds_array[i][0])
        display_key = ds_array[i][0] + "&nbsp;&nbsp;";
      else
        display_key = "";

      if ((ds_array[i][0] == sel_key) && (ds_array[i][1] == sel_value))
      {
        preselected = true;
        option_html = option_html + "<option value=\"" + ds_array[i][0] + "\"" + " selected " + ">" + display_key + ds_array[i][1] ;
      }
      else
        option_html = option_html + "<option value=\"" + ds_array[i][0] + "\">" + display_key + ds_array[i][1] ;

      if ( (ds_array[i][1].length > (columnwidth/webguiFontWidth)) && useColumnwidth )
        useColumnwidth = false;
    }

    if (add_empty)
    {
      ds_array.length += 1;
      ds_array[ds_array.length-1] = new Array(add_empty_key,add_empty_value);
      option_html = option_html + "<option ";
      if (!preselected)
        option_html = option_html + "selected ";
      option_html = option_html + "value=\"\">" + add_empty_value;
    }

    if (special == "X")
      option_html = option_html + "<option specialItem=1 selected>" + selectedItem;
  }
  else
  {
    for ( i=0,count=0; i<ds_array.length; i+=2,count++ )
    {
      if (webguicomboboxwkeys && ds_array[i])
        display_key = ds_array[i] + "&nbsp;&nbsp;";
      else
        display_key = "";

      if ( count == selectedItem )
        option_html = option_html + "<option value=\"" + ds_array[i] + "\"" + " selected " + ">" + display_key + ds_array[i+1] ;
      else
        option_html = option_html + "<option value=\"" + ds_array[i] + "\">" + display_key + ds_array[i+1] ;

      if ( (ds_array[i+1].length > (columnwidth/webguiFontWidth)) && useColumnwidth )
        useColumnwidth = false;
    }

    if (special == "X")
      option_html = option_html + "<option specialItem=1 selected>" + selectedItem;
  }

  if (parentTD.className == "TCCellInputSelected")
    cc_class = "inputTCColComboControl";
  else
    cc_class = "inputTCComboControl"

  html = "<select name=\"" + object_name + "[" + index + "]\" class=\"" + cc_class +"\" onclick=\"setOptionSelected(this);\" ";

  if (useColumnwidth)
    html = html + "style=\"width:" + parseInt(columnwidth) + "\" ";

  if (okcode!="")
    html = html + "onchange=\"setOkCode('" + okcode + "')\"";
  else
    html = html + "ondblclick=\"event.cancelBubble=true;\"";

  html = html + ">";

  html = html + option_html + "</select>";
  if (parentTD)
    parentTD.innerHTML = html;

  temp_select = document.getElementById(object_name + "[" + index + "]");
  if (temp_select && temp_select.focus)
  {
    temp_select.focus();
  }
}

function webguiGetSearchhelpButtonHTML(fieldname)
{

    var html ;
//..................................................quetzo
//      html = '<img src="' + webguiMimeURL + '/webgui/'+webguiTheme+'/images/buttons/tanicon.gif" style="width:17;height:17"\
//              onmouseout="status=\' \';"\
//              onmouseover="status=\'?\';"\
//              onclick="javascript:webguiRaiseSearchhelp(\'' + fieldname + '\')">';
    if( webguiRTL != 0 )
    {
      html = '<img src="' + webguiMimeURL + '/webgui/'+webguiTheme+'/images/buttons/tanicon.gif" style="filter:flipH(); width:17;height:17" '
           + 'onmouseout="status=\' \';" '
           + 'onmouseover="status=\'?\';" '
           + 'onclick="javascript:webguiRaiseSearchhelp(\'' + fieldname + '\')">';
    }
    else
    {
      html = '<img src="' + webguiMimeURL + '/webgui/'+webguiTheme+'/images/buttons/tanicon.gif" style="width:17;height:17" '
           + 'onmouseout="status=\' \';" '
           + 'onmouseover="status=\'?\';" '
           + 'onclick="javascript:webguiRaiseSearchhelp(\'' + fieldname + '\')">';
    }
//..................................................quetzo
    return (html) ;

}

function EnableEWTSearchHelpButton(fieldname,e,selectedElement,TCViewHandle)
{
  var topPos = 0;
  var leftPos = 0;
  var vParent;
  var TSDivHandle, ContainerHandle;
  var parentToFind;
  var sh_button;
  var combobox = webguiFindComboBox(selectedElement) ;
  if (combobox)
  {
    if (TCViewHandle)
    {
      sh_button = TCViewHandle.all('webguiTCSearchHelpButton');
      var parentTD = webguiTableCellGetTD(combobox);

      if (sh_button && parentTD)
      {
        // To enable F4-help button in webgui tablecontrol
        // in EWT, uncomment the following line
        //sh_button.innerHTML = webguiGetSearchhelpButtonHTML(fieldname);


        // abp - tables inside of tables inside of tables... ermph!
        var realTD = parentTD.parentElement;

        while (realTD && realTD.className.substr(0, 6) != "TCCell")
             realTD = realTD.parentElement;

        if (realTD)
            parentTD = realTD;

        sh_button.style.left =  parentTD.offsetLeft + parentTD.offsetWidth;
        sh_button.style.top = parentTD.offsetTop;
      }
    }
    else
      sh_button = combobox.all('EWTSH');

    if (sh_button)
    {
      sh_button.style.visibility = "visible";
      webguiSearchhelpButton = sh_button;
    }
  }

}

function EnableSearchHelpButton(fieldname,e,selectedElement,TCViewHandle)
{
  var topPos = 0;
  var leftPos = 0;
  var vParent;
  var TSDivHandle, ContainerHandle;
  var parentToFind;
  var sh_button;
  var flip_sh_button = 0;
  var tcname = "";

  if (!TCViewHandle) {
    ContainerHandle = webguiGetContainer(selectedElement);
  }

  vParent = selectedElement;

  if (TCViewHandle)
  {
    var innerTCViewHandle = webguiGetTC(selectedElement);
    var TDTag = webguiTableCellGetTD(selectedElement);

    tcname = innerTCViewHandle.tcname;

    if (innerTCViewHandle && TDTag)
    {
      if (innerTCViewHandle.webguiNumRowSelector > 0)
      {
        if (innerTCViewHandle.webguiColCount == TDTag.ic)
          flip_sh_button = 1;
      }
      else if (innerTCViewHandle.webguiColCount == (parseInt(TDTag.ic) + 1))
        flip_sh_button = 1;
    }
    if (flip_sh_button == 1 && TCViewHandle.firstChild.getAttribute("fixColumnTC") == 1)
    {
      var fixColTCDiv = webguiGetFixColTCDiv(TCViewHandle);
      if (fixColTCDiv)
        sh_button = fixColTCDiv.all["webguiTCSearchHelpButtonfixed"];
    }
    else
    {
      sh_button = TCViewHandle.all["webguiTCSearchHelpButton"];
    }
  }
  else if (ContainerHandle)
  {
    if (ContainerHandle.cn && ContainerHandle.cn == "webguicontainer")
      sh_button = ContainerHandle.all["webguiConSHButton" + ContainerHandle.sh_id];
    else if (ContainerHandle.className && ContainerHandle.className == "webguiTSDiv")
      sh_button = ContainerHandle.all["webguiTSSHButton-" + ContainerHandle.id];
  }
  else
    sh_button = document.getElementById("webguiSearchHelpButton");

  if (sh_button)
  {
    if (webguiSearchhelpButton != null)
    {
      webguiSearchhelpButton.style.visibility = "hidden" ;
      sh_button.innerHTML = "";
    }
    sh_button.innerHTML = webguiGetSearchhelpButtonHTML(fieldname) ;

    sh_button.style.visibility = "visible" ;
    sh_button.style.display = "block";

    if (!TCViewHandle)
    {
      if (ContainerHandle)
        parentToFind = ContainerHandle;
      else if (TSDivHandle)
        parentToFind = TSDivHandle;
      else
        parentToFind = webguiDynpro;

      while (vParent && vParent != parentToFind)
      {

        topPos += vParent.offsetTop;
        leftPos += vParent.offsetLeft;
        vParent = vParent.parentElement;
      }

      if (accessibility && selectedElement.parentElement.tagName == "TD")
        topPos = selectedElement.parentElement.offsetTop;

      if (ContainerHandle)
      {
        if ( (leftPos + sh_button.offsetWidth + selectedElement.offsetWidth > ContainerHandle.offsetWidth)
           && (selectedElement.offsetWidth >= (sh_button.offsetWidth * 2))
           && (fieldname && fieldname.indexOf("DDSHSELOPT-LOW") < 0)
           && (ContainerHandle.offsetWidth > 0)
           )
        { //tj/2002-06-14/Note 0528489
          if (sh_button.hasChildNodes()) {
            var imgobj = sh_button.firstChild;
            sh_button.style.pixelLeft = leftPos + selectedElement.offsetWidth - sh_button.offsetWidth;
            imgobj.setAttribute("src", webguiMimeURL + "/webgui/"+webguiTheme+"/images/buttons/tanicon_flipped.gif");
          }
          //tj/2002-06-14
        }
        else
        {
          sh_button.style.pixelLeft = leftPos + selectedElement.offsetWidth;
//.............................................................quetzo
          if( webguiRTL != 0 )
            sh_button.style.pixelLeft =  leftPos - sh_button.offsetWidth;
//.............................................................quetzo
        }
      }
      else
//.............................................................quetzo
//      sh_button.style.pixelLeft = leftPos + selectedElement.offsetWidth;
      {
        if( webguiRTL != 0 )
          sh_button.style.pixelLeft = leftPos - sh_button.offsetWidth;
        else
          sh_button.style.pixelLeft = leftPos + selectedElement.offsetWidth;
      }
//.............................................................quetzo
      sh_button.style.pixelTop = topPos;

    }
    else
    {
      // abp - tables inside of tables inside of tables... ermph!
          var TDTag = webguiTableCellGetTD(selectedElement);

      var realTD = TDTag.parentElement;
      while (realTD && realTD.className.substr(0, 6) != "TCCell")
           realTD = realTD.parentElement;

      if (realTD)
          TDTag = realTD;
      if (TDTag.remainingColWidth)
      {
        sh_button.style.left =  TDTag.offsetLeft + TDTag.offsetWidth - TCViewHandle.offsetLeft - ((TDTag.remainingColWidth) > 0 ? TDTag.remainingColWidth : 0 );

        if (TDTag.remainingColWidth < 20)
        {
          var tcTR = TDTag.parentNode;
          if (tcTR)
          {
            while (tcTR && tcTR.tagName != "TR") tcTR = tcTR.parentElement; // insurance

            if (TDTag.cellIndex == (tcTR.cells.length - 1))
            {
              TCViewHandle.scrollLeft += 20 - ((TDTag.remainingColWidth) > 0 ? TDTag.remainingColWidth : 0 );
            }
          }
        }
      }
      else
      {
//.............................................................quetzo
//      sh_button.style.left =  TDTag.offsetLeft + TDTag.offsetWidth - TCViewHandle.offsetLeft;
        if( webguiRTL != 0 )
          sh_button.style.left =  TDTag.offsetLeft + TCViewHandle.offsetLeft - sh_button.offsetWidth;
        else
          sh_button.style.left =  TDTag.offsetLeft + TDTag.offsetWidth - TCViewHandle.offsetLeft ;
//.............................................................quetzo
      }

      if (webguiIsIE4())
      { var flip_sh_button = 0;

        parentToFind = TCViewHandle;
        while (vParent && vParent != parentToFind)
        {
          topPos += vParent.offsetTop;
          leftPos += vParent.offsetLeft;
          vParent = vParent.parentElement;
        }
        sh_button.style.top = topPos;
      }
      else
      {
        if (sh_button.id == "webguiTCSearchHelpButtonfixed")
        {
          sh_button.style.top = TDTag.offsetTop + TCViewHandle.parentElement.offsetTop + 1;
          sh_button.style.left = parseInt(sh_button.style.left) + 2;

          if (tcname != "") {
            var mc = document.getElementById(tcname + "MAINCONTAINER");
            if (mc && (mc.HASTITLE != "" && mc.HASTITLE != undefined)) {
              sh_button.style.top = parseInt(sh_button.style.top) + 18;
            }
          }

        }
        else
        {
          sh_button.style.top = TDTag.offsetTop;
        }
      }

      //abp 08.10.2003 - if last cell in table, the f4 help will need to be scrolled to to be seen
      var tcTR = TDTag.parentNode;
      if (tcTR)
      {
        while (tcTR && tcTR.tagName != "TR") tcTR = tcTR.parentElement; // insurance

        if (TDTag.cellIndex == (tcTR.cells.length - 1))
        {
          if (TCViewHandle)
            TCViewHandle.scrollLeft += 20;
        }
      }
      // abp 08.10.2003

    }

    webguiSearchhelpButton = sh_button;
  }
}

function webguiEnableSearchhelpButton(fieldname, e)
{
  var TCViewHandle;

  if (e)
    selectedElement = e.srcElement;
  else
    selectedElement = event.srcElement ;

  if ( selectedElement == null )
    return ;

  if ( !selectedElement.sh )
    return ;

  TCViewHandle = webguiGetTCView(selectedElement);

  if (templatebasedEWT)
    EnableEWTSearchHelpButton(fieldname,e,selectedElement,TCViewHandle);
  else
    EnableSearchHelpButton(fieldname,e,selectedElement,TCViewHandle);
}

// ==========================================================
// Event Handlers
// ==========================================================

function webguiOnLoad()
{
  var i, j, l, par;

  //abp/2002-18-09/IE4.0 support
  if (typeof(document.getElementById) == "undefined")
    document.prototype.getElementById = document.all;

  webguiInitMenu();

  if (document.getElementById("webguiPage") != null )
  {
    document.getElementById("webguiPage").style.visibility = "visible" ;
  }

  if (webguiModalNo != 0 && !webguiFullScreenPopup)
  {
    var
      modalFrame = parent.document.getElementById(window.name);

    if (modalFrame != null)
      modalFrame.style.visibility = "visible";

    if (window.focus)
      window.focus;
  }

  webguiStartupBanner = document.getElementById("webguiStartupBanner");
  if ( webguiStartupBanner != null )
  {
    webguiStartupBanner.style.visibility = "hidden" ;
    webguiStartupBannerText = webguiStartupBanner.innerHTML ;
    webguiStartupBanner.innerHTML = "" ;
  }

  webguiUserArea = document.getElementById("webguiUserArea");
  webguiDynpro = document.getElementById("webguiDynpro");
//.................................................................quetzo
  if( webguiRTL != 0 )
    RTLwebguiDynproBorder = document.getElementById("webguiDynproBorder");
//.................................................................quetzo
  popup = document.getElementById("webguiPopup");

  // workaround for IE5, resetting height for popup box
  if (popup && isIE5())
  {
    if(webguiNoPopupMargin)
    {
      popup.style.height=0;
      popup.style.height="100%";
    }
    else
    {
      popup.style.height=0;
      popup.style.height="80%";
    }
  }

  if (webguiUserArea)
  {
    if (!webguiTableLayout)
    {
      var
        toolbar,
        container,
        statusbar;

      container = webguiUserArea.parentElement;
      toolbar = document.getElementById("webguiToolbar");
      statusbar = document.getElementById("webguiStatusbar");

      if (toolbar && container)
      {
        if (webguiIsIE4())
        {
          container.style.pixelTop += (toolbar.offsetHeight - container.offsetTop);
        }
        webguiUserArea.style.pixelWidth = toolbar.offsetWidth;

        if (popup)
        {
          webguiRedrawOnIE4(popup);
          webguiUserArea.style.pixelHeight = popup.offsetHeight - container.offsetTop;
        }
        else
          webguiUserArea.style.pixelHeight = document.body.clientHeight - container.offsetTop;

        if (statusbar)
        {
          webguiUserArea.style.pixelHeight -= statusbar.offsetHeight;
          statusbar.style.pixelWidth = toolbar.offsetWidth;
          statusbar.style.pixelTop = container.offsetTop + webguiUserArea.style.pixelHeight;
        }
        webguiRedrawOnIE4(webguiUserArea);
      }
    }
  }

  if (webguiModalNo > 0 && webguiDynpro && modalFrame && transactionType!="EWT")
  {

  //
  // resize modal window to hide scrollbars
  //
    var
      webguiDynproBorder = webguiDynpro.children[0],
      modalButtonBar = document.getElementById("WebguiModalButtonBar"),
      modalToolbarHeight = document.getElementById("WebguiModalTitleBar").offsetHeight,
      modalTooBigShrinkPx = 30,
      modalScrollBarDim = 15;
      newModalWidth = modalFrame.clientWidth,
      newModalHeight = modalFrame.offsetHeight,
      addScrollbarWidth = false,
      addScrollbarHeight = false;

    if (modalButtonBar)
      modalToolbarHeight += 30;  // 30 = height of buttonbar

    if (newModalWidth > parent.document.body.offsetWidth && parent.document.body.offsetWidth > modalTooBigShrinkPx) //tj/2002-04-18
    {
      newModalWidth = parent.document.body.offsetWidth - modalTooBigShrinkPx;
      addScrollbarHeight = true;
    }
    else if (webguiDynproBorder.offsetWidth < parent.document.body.offsetWidth)
    {
      // for width, we always add extra spaces for the modal
      // and we're checking if adding extra spaces would make
      // modal too big
      if (webguiDynproBorder.offsetWidth < newModalWidth &&
        newModalWidth + 10 < parent.document.body.offsetWidth)
        newModalWidth += 10;
      else if (webguiDynproBorder.offsetWidth + 15 < parent.document.body.offsetWidth)
        newModalWidth = webguiDynproBorder.offsetWidth + 15;
    }

    var totalModalHeight = webguiDynproBorder.offsetHeight + parseInt(modalToolbarHeight);
    if (newModalHeight> parent.document.body.offsetHeight && parent.document.body.offsetHeight > modalTooBigShrinkPx) //tj/2002-04-18
    {
      newModalHeight = parent.document.body.offsetHeight - modalTooBigShrinkPx;
      addScrollbarWidth = true;
    }
    else if (totalModalHeight > newModalHeight && totalModalHeight + 10 < parent.document.body.offsetHeight)
      newModalHeight = totalModalHeight + 10;

    // If we shrink the modal, we need to anticipate extra
    // spaces used by vert. and hori. scrollbars
    if (addScrollbarHeight)
      newModalHeight += modalScrollBarDim;

    if (addScrollbarWidth)
      newModalWidth += modalScrollBarDim;

    if (newModalWidth != modalFrame.clientWidth || newModalHeight != modalFrame.offsetHeight)
    {
      if (modalFrame.style.width.match(/%$/) == null)
        modalFrame.style.width = newModalWidth;
      if (modalFrame.style.height.match(/%$/) == null)
        modalFrame.style.height = newModalHeight;
    }

  //
  // resize oversized-containers (containers with dimensions larger
  // than modal window) to avoid scrollbars
  //
    var
      container_count = 0,
      container_resize,
      curr_container,
      parent_container,
      container_arr = document.getElementsByName("webguictnr");

    if (container_arr)
      container_count = container_arr.length;
    else
      container_count = 0;

    for (i=0; i<container_count; i++)
    {
      curr_container = container_arr[i];

      parent_container = webguiGetContainer(curr_container.parentElement);

      container_resize = true;
      if (parent_container)
      {
        curr_container.cumulative_top = curr_container.style.pixelTop + parent_container.cumulative_top;
        curr_container.cumulative_left = curr_container.style.pixelLeft + parent_container.cumulative_left;
      }
      else
      {
        curr_container.cumulative_top = curr_container.style.pixelTop;
        curr_container.cumulative_left = curr_container.style.pixelLeft;
      }

      if (curr_container.cumulative_top + curr_container.offsetHeight <= modalFrame.offsetHeight &&
        curr_container.cumulative_left + curr_container.offsetWidth <= modalFrame.offsetWidth)
        continue;

      for (j=0; j<curr_container.children.length; j++)
      {
        var
          curr_child = curr_container.children[j],
          child_absTop = curr_child.style.pixelTop + curr_container.style.pixelTop,
          child_absLeft = curr_child.style.pixelLeft + curr_container.style.pixelLeft;

        if (curr_child.tagName == "NOBR" && curr_child.children.length > 0)
          curr_child = curr_child.children[0];

        if ((curr_child.style.pixelTop + curr_container.cumulative_top > modalFrame.offsetHeight) ||
          (curr_child.style.pixelLeft + curr_container.cumulative_left > modalFrame.offsetWidth))
        {
          container_resize = false;
          break;
        }
      }
      if (container_resize)
      {
        curr_container.style.pixelHeight = webguiDynpro.offsetHeight - curr_container.cumulative_top - 10;
        curr_container.style.pixelWidth = webguiDynpro.offsetWidth - curr_container.cumulative_left - 10;
      }
    }
  }

  if (window.controlOnLoad)
    window.controlOnLoad();


  if (webguiNewWindowUrl)
  {
    if (webguiNewWindowName)
            (webguiFocusWin = window.open(webguiNewWindowUrl, webguiNewWindowName)).focus();
    else
            (webguiFocusWin = window.open(webguiNewWindowUrl, "_blank")).focus();
  }

  //Errors w/multiple channels in workplace.  Document can be hidden
  //causing infinite loop in these calculatins see customer message 136928 2001
  if(!webguiIsIE4() && document.body.clientWidth!=0)
  {
    //tj/2002-11-02/frog2002 && HCM menu
    if ( typeof( self.webguiMenusl) == "undefined") {
      webguiFitTitlebar();
      webguiFitAppButtons();
      webguiFitStdButtons();
      webguiFitMenus();
    }
    else {
      webguiFitAppMenu();
    }
  }

  //tj/2003-03-06/ toggle Menu2002 OKCode field; function defined in d_generator.html
  if ( typeof( window.toggleMenuslOKCodeFieldOnload) != "undefined")
    toggleMenuslOKCodeFieldOnload();

  /* Now, set user area parameters
  */

  // if the document is the base dynpro
  if (!webguiIsPopup)
  {
    webguiSetUserArea();
    if ((j = webguiOnLoad.a_popups) != null) {  // call webguiSetUserArea() of popups
      for (i in j)
        (j[ i].webguiSetUserArea)();
    }
  }
  // else it's a popup - save information on base dynpro
  else
  {
    par = parent;
    while (par.webguiIsPopup != false && par != par.parent)
      par = par.parent;
    if (par.webguiIsPopup == false && typeof par.webguiOnLoad != "undefined")
    {
      if (par.webguiOnLoad.a_popups == null)
        par.webguiOnLoad.a_popups = new Array();
      if (par.webguiOnLoad.a_popups != null)
      {
        l = par.webguiOnLoad.a_popups.length;
        l = (par.webguiOnLoad.a_popups[ l] = new Object());
        if ( l != null)
        {
          l.webguiSetUserArea    = webguiSetUserArea;
          l.webguiModalNo        = webguiModalNo;
          l.popupdocument        = self.document;
        }
      }
    }
  }

  // Collect performance data
  webguiPerfGetData();
  if (document.body)
    document.body.style.cursor = "";
}

function webguiDoClick(e, onList)
{
  var
    altTypeClicked = false;
    deleteOldSelection = true,
    selected = false,
    selectedElement = null;

  if (!webguiIsActive())
    return;

  if (e)
  {
    if (e.srcElement)
    {
      e.cancelBubble = true;
      selectedElement = e.srcElement;
    }
    else
    {
      deleteOldSelection = false;
      selectedElement = e;
    }
  }
  else
  {
    if (window.event)
    {
      window.event.cancelBubble = true;
      selectedElement = window.event.srcElement;
    }
  }

  if (!selectedElement)
    return;

  if (selectedElement.parentElement && selectedElement.parentElement.getAttribute("altType"))
  {
    selectedElement.blur();
    selectedElement = selectedElement.parentElement;
    altTypeClicked = true;
  }

  if(selectedElement == webguiSelectedElementOld)
  {
    if (selectedElement.getAttribute("altType") && !altTypeClicked)
    {
      if (selectedElement.children[0].onclick)
        selectedElement.children[0].click();

      if (selectedElement.children[0].checked == true && selectedElement.children[0].type != "radio")
        selectedElement.children[0].checked = false;
      else
        selectedElement.children[0].checked = true;
    }

    if(webguiSearchhelpButton && selectedElement.sh)
      webguiSearchhelpButton.style.visibility = "visible";
    return;
  }
    if (selectedElement.className == "SIinput"
       || selectedElement.className == "SIpulldown") // EWT
    return;

  if (webguiSearchhelpButton)
    webguiSearchhelpButton.style.visibility = "hidden" ;

  targetObject = getMainWindow().document.webguiform;

  if (onList)
  {
    // record clicked character position
    targetObject.elements[formWebguiCursorObj].value = webguiListElemId(selectedElement);
    targetObject.elements[formWebguiCursorCol].value = Math.floor(event.offsetX / webguiFontWidth);

    if(selectedElement.tagName == "IMG")
    {
      if(selectedElement.checked != null)
      {
        checked = selectedElement.checked;

        if(webguiIsIE4()) //set the selected element to the hidden field for checkboxen
          selectedElement = selectedElement.parentElement.children[0];
        else
          selectedElement = selectedElement.previousSibling;

        if(checked==1)
          selectedElement.value = "X";
        else
          selectedElement.value = " ";
      }
      else
      {
        selectedElement = selectedElement.parentElement;
        if(selectedElement == webguiSelectedElementOld)
          return;
      }
    }

    if (selectedElement.tagName == "INPUT")
    {
      if (selectedElement.type != "radio")
	    targetObject.elements[formFocusfieldIdx].value = selectedElement.name;
      else
	    targetObject.elements[formFocusfieldIdx].value = selectedElement.id;

      if( webguiSelectedElementOld != null )
        webguiSelectedElementOld.className = webguiSelectedElementOld.webguiOldClassName;

      webguiSelectedElementOld = null ;
      return ;
    }

    targetObject.elements[formFocusfieldIdx].value = selectedElement.id ;

    if ( selectedElement.tagName == "TD" )
    {
      selectedElement.webguiOldClassName = selectedElement.className;
      selectedElement.className = selectedElement.className + "Selected";

      selected = true;
    }
  }
  else
  {
    // unrecord clicked character position
    targetObject.elements[formWebguiCursorObj].value = "";
    targetObject.elements[formWebguiCursorCol].value = "";

    if (selectedElement && selectedElement.className == "TCColumnTitleText")
    {
      var depth = 5;
      while (depth-- > 0 && selectedElement && selectedElement.tagName != "TH")
        selectedElement = selectedElement.parentElement;
    }
    // Special logic for TCColTitleSelectable as it is not a focus element
    if (selectedElement && selectedElement.className == "TCColumnTitleSelectable")
    {
      if (!TCHandle)
        var TCHandle = webguiGetTC(selectedElement);

      if (TCHandle)
      {
        var colcount = TCHandle.webguiColCount;

        if (!TCHandle.selectedColumns)
        {
          webguiSyncPreSelectedColHeader(TCHandle, colcount);

          var notfixIdx = TCHandle.id.indexOf("-notfix");
          var TCHandle2;
          if (notfixIdx < 0)
            TCHandle2 = document.getElementById(TCHandle.id+"-notfix");
          else
            TCHandle2 = document.getElementById(TCHandle.id.substring(0,notfixIdx));

          if (TCHandle2)
            webguiSyncPreSelectedColHeader(TCHandle2, TCHandle2.webguiColCount);
        }

        TCHeaderClick(TCHandle, selectedElement);
      }

      if (selected && selectedElement != webguiSelectedElementOld )
      {
        if( webguiSelectedElementOld != null )
          webguiSelectedElementOld.className = webguiSelectedElementOld.webguiOldClassName;
        webguiSelectedElementOld = selectedElement ;

      }
      else if (deleteOldSelection)
      {
        if( webguiSelectedElementOld != null ) {
          webguiSelectedElementOld.className = webguiSelectedElementOld.webguiOldClassName;
        }
        webguiSelectedElementOld = null ;
      }
    }

    // Special logic for tabstrip pulldown menu as it is not a focus element
    if (selectedElement.className == "PULLDOWN-TABSTRIP")
    {
      webguiTSPulldownMenu = selectedElement;
      // Use MenuDowncheck to catch exceptions from IFRAME (e.g not fetched)
      MenuDowncheck(webguiTSPulldownMenu);
    }
    else if (webguiTSPulldownMenu)
    {
      TSMenuHide( webguiTSPulldownMenu.id.substring(0, webguiTSPulldownMenu.id.length-9) ); //substring not including '-PULLDOWN'
      webguiTSPulldownMenu = null;
    }

    if (!webguiIsFocusElement(selectedElement))
      return;

    if (selectedElement.className && selectedElement.className == "OKCodeField")
    {
      targetObject.elements[formFocusfieldIdx].value = "";
      selectedElement = null;
    }
    else
    {
      if (selectedElement.tagName == "INPUT" || selectedElement.tagName == "SELECT")
        if (selectedElement.type == "radio")
          targetObject.elements[formFocusfieldIdx].value = selectedElement.value;
        else
          targetObject.elements[formFocusfieldIdx].value = selectedElement.name;
      else
      {
        if (!selectedElement.noID)
          targetObject.elements[formFocusfieldIdx].value = selectedElement.id;
        else if (selectedElement.children[0])
        {
          if (selectedElement.children[0].tagName == "INPUT")
          {
            if (selectedElement.children[0].type == "radio")
              targetObject.elements[formFocusfieldIdx].value = selectedElement.children[0].value;
            else
              targetObject.elements[formFocusfieldIdx].value = selectedElement.children[0].name;
          }
        }
      }
      selectedElement.webguiOldClassName = selectedElement.className;
      selectedElement.className = selectedElement.className + "Selected";
    }

    // checkbox and radiobutton
    if (selectedElement && selectedElement.getAttribute("altType") && !altTypeClicked && !in_webguiSetFocus)
    {
      if (selectedElement.children[0] && (selectedElement.children[0].type=="radio" ||
        selectedElement.children[0].type == "checkbox"))
      {
        if (selectedElement.children[0].onclick)
          selectedElement.children[0].click();

        if (selectedElement.children[0].checked == true && selectedElement.children[0].type != "radio")
          selectedElement.children[0].checked = false;
        else
          selectedElement.children[0].checked = true;
      }
    }
    selected = true;
  }

  if( selected && selectedElement != webguiSelectedElementOld )
  {
    if( webguiSelectedElementOld != null ) {
      webguiSelectedElementOld.className = webguiSelectedElementOld.webguiOldClassName;
    }
    webguiSelectedElementOld = selectedElement ;
  }
  else if (deleteOldSelection)
  {
    if( webguiSelectedElementOld != null ) {
      webguiSelectedElementOld.className = webguiSelectedElementOld.webguiOldClassName;
    }

    webguiSelectedElementOld = null ;
  }

  if (selectedElement && selectedElement.sh )
  {
    if (selectedElement.webguiSearchHelpField)
      webguiEnableSearchhelpButton(selectedElement.webguiSearchHelpField, e);
    else
    {
      if (selectedElement.tagName == "INPUT")
        webguiEnableSearchhelpButton(selectedElement.name, e);
      else
        webguiEnableSearchhelpButton(selectedElement.id, e);
    }
  }
  // search help focus field
  if (selectedElement &&
      selectedElement.className == "inputSelected" &&
      selectedElement.name.substring(0,15)  == "DDSHSELOPT-LOW[")
  {
      var shFocus = document.getElementsByName("~SEARCHHELPFOCUS")[0];
      if (shFocus)
      shFocus.value = selectedElement.name;
  }
}

function webguiDoMouseDown()
{
  // Disable modal resize for now
  if (webguiModalIsResizeEvent(window.event) && 0)
  {
    webguiModalDoMouseDown(true);
  }
}


function webguiSyncPreSelectedColHeader(TCHandle, colcount)
{
  var headerHiddenInput, columnHeader;

  TCHandle.selectedColumns = new Array();

  for (var displayCol=1; displayCol<=colcount; displayCol++)
  {
    columnHeader = TCGetColumnHeader(TCHandle, displayCol);
    if (columnHeader && columnHeader.getAttribute("colselected")==1)
      TCHandle.selectedColumns[TCHandle.selectedColumns.length] = displayCol;
  }
}

function webguiGetTC(selectedElement)
{
  while (selectedElement)
  {
    if (selectedElement.className && selectedElement.className == "webguiInnerTCView")
      return selectedElement;
    selectedElement = selectedElement.parentElement;
  }

  return null;
}

function TCHeaderClick(TCHandle, selectedElement)
{
  var col = selectedElement.webguiTCCol;
  var displayCol = selectedElement.webguiDisplayCol;
  var coldiff = parseInt(TCHandle.webguiNumRowSelector,10);
  var colselecttype = TCHandle.webguiTCColSelType;
  var found = false;
  var numCols = TCHandle.selectedColumns.length;
  var startrow = TCHandle.webguiTCRowStartAt;
  var colhiddenval, TCHandle2;
  var regularexp = new RegExp();

  if (!TCHandle.selectedColumns)
    TCHandle.selectedColumns = new Array();

  for (var i=0; i<numCols; i++)
  {
    if (TCHandle.selectedColumns[i]==displayCol)
    {
      found = true;
      TCHandle.selectedColumns[i] = TCHandle.selectedColumns[numCols-1];
      TCHandle.selectedColumns.length --;
      break;
    }
  }

  if (found == true)
  {
    colhiddenval = selectedElement.children[0];

    while(colhiddenval && colhiddenval.tagName && colhiddenval.tagName != "INPUT") {
      colhiddenval = colhiddenval.firstChild;
    }

    if (colhiddenval && colhiddenval.tagName=="INPUT")
      colhiddenval.value = "";

    TCSelectColumn(TCHandle.rows, displayCol - 1 + coldiff, "UnSelect", startrow);

    if (accessibility)
    {
      var headerlabel = selectedElement.all(1);
      if (headerlabel && headerlabel.tagName == "LABEL")
      {
        regularexp = regularexp.compile(tableselectedtext);
        headerlabel.innerHTML = headerlabel.innerHTML.replace(regularexp,tableunselectedtext);
      }
    }
  }
  else
  {
    if (colselecttype != "multiple")
    {
      TCDeSelectColumns(TCHandle);

      var notfixIdx = TCHandle.id.indexOf("-notfix");
      var TCHandle2;
      if (notfixIdx < 0)
        TCHandle2 = document.getElementById(TCHandle.id+"-notfix");
      else
        TCHandle2 = document.getElementById(TCHandle.id.substring(0,notfixIdx));

      if (TCHandle2)
        TCDeSelectColumns(TCHandle2);
    }

    TCHandle.selectedColumns[TCHandle.selectedColumns.length] = displayCol;

    colhiddenval = selectedElement.children[0];

    while(colhiddenval && colhiddenval.tagName && colhiddenval.tagName != "INPUT") {
      colhiddenval = colhiddenval.firstChild;
    }

    if (colhiddenval && colhiddenval.tagName=="INPUT")
      colhiddenval.value = "X";

    // abp 17.02.04 - select a cell, then highlight its column (U9C, rsdemo02)
    TCSelectColumn(TCHandle.rows, displayCol - 1 + coldiff, "UnSelect", startrow);
    TCSelectColumn(TCHandle.rows, displayCol - 1 + coldiff, "Select", startrow);

    if (accessibility)
    {
      var headerlabel = selectedElement.all(1);
      if (headerlabel && headerlabel.tagName == "LABEL")
      {
        regularexp = regularexp.compile(tableunselectedtext);
        headerlabel.innerHTML = headerlabel.innerHTML.replace(regularexp,tableselectedtext);
      }
    }
  }

  // set focus to the first cell on the first row
  var element = webguiGetFocusElement(TCHandle.rows(parseInt(startrow)).cells(displayCol-1+coldiff));

  if (element)
  {
    if (element.tagName == "INPUT" || element.tagName == "SELECT") {
      webguiFocusField = element.name;
    }
    else {
      webguiFocusField = element.id;
    }
    webguiSetFocus( webguiFocusField);
  }
}

function TCGetColumnHeader(TCHandle, colNum)
{
  startrow = TCHandle.webguiTCRowStartAt;
  numRowSelector = TCHandle.webguiNumRowSelector;

  if (startrow > 0)
  {
    if (numRowSelector == "0")
      return TCHandle.rows[startrow-1].cells[colNum-1];
    else
      return TCHandle.rows[startrow-1].cells[colNum];
  }
  else
    return null;
}

function TCDeSelectColumns(TCHandle)
{
  if (!TCHandle.selectedColumns)
    return;

  var coldiff = parseInt(TCHandle.webguiNumRowSelector,10);
  var startrow = TCHandle.webguiTCRowStartAt;

  for (var i=0; i<TCHandle.selectedColumns.length; i++)
  {
    TCSelectColumn(TCHandle.rows, TCHandle.selectedColumns[i]-1+coldiff, "UnSelect", startrow);
    columnHeader = TCGetColumnHeader(TCHandle, TCHandle.selectedColumns[i]);
    if (columnHeader)
    {
      var colhiddenval = columnHeader.children[0];

      while(colhiddenval && colhiddenval.tagName && colhiddenval.tagName != "INPUT") {
        colhiddenval = colhiddenval.firstChild;
      }

      if (colhiddenval && colhiddenval.tagName == "INPUT")
        colhiddenval.value = "";
    }
  }

  TCHandle.selectedColumns.length = 0;
}

function TCRowSelect(row_TD, mode)
{
  var row_TR = row_TD.parentElement;
  var TCHandle = webguiGetTC(row_TD);
  var TDElement,element;
  if (row_TR)
  {
    if (mode == "Select")
    {
      row_TR.className += "Selected";
    }
    else
    {
      var oldclassname = row_TR.className;
      var newclassname = oldclassname.substring(0, (oldclassname.indexOf("Selected")));
      row_TR.className = newclassname;
    }
  }
}

////////////////////////////////////////////////////////////////////////////////
//
// TCSelectElement - used by TCSelectColumn
//
////////////////////////////////////////////////////////////////////////////////
function TCSelectElement(TDElement,mode)
{
  if (mode == "Select")
  {
    TDElement.webguiOldClassName = TDElement.className;
    TDElement.className += "Selected";

    var o = TDElement.all(0);
    if (o)
    {
      if (o.tagName=="INPUT" && o.type=="text") {
        o.webguiOldClassName = "inputTCCol"; // abp 17.02.04 - select a cell, then highlight its column (U9C, rsdemo02)
        o.className = "inputTCCol";
      } else if (o.tagName=="SELECT") {
        o.webguiOldClassName = "inputTCColComboControl";
        o.className = "inputTCColComboControl";
      } else if (o.tagName=="LABEL") {
        if (TDElement.all(1)) {
          o = TDElement.all(1);
          o.webguiOldClassName = TDElement.all(1).className;
          o.className = "inputTCCol";
        }
      } else if (o.tagName == "TABLE") {
        if (o.cells.length)
        {
          o = o.cells[0];
          if (o && o.className == "TCCellInput")
          {
            TCSelectElement(o,mode);
          }
        }
      }
    }

  }
  else if (mode == "UnSelect")
  {
    if (TDElement.webguiOldClassName)
    {
      TDElement.className = TDElement.webguiOldClassName;
      TDElement.webguiOldClassName = "";
    }

    var o = TDElement.all(0);
    if (o)
    {
      if (o.webguiOldClassName)
      {
        o.className = o.webguiOldClassName;
      }

      if(o.tagName=="INPUT" && o.type=="text")
      {
        o.className = "inputTC";
        o.webguiOldClassName = "inputTC";
      }
      else if (o.tagName=="SELECT")
      {
        o.className = "inputTCComboControl";
        o.webguiOldClassName = "inputTCComboControl";
      }
      else if (o.tagName=="LABEL")
      {
        if (TDElement.all(1)) // accessibility case
        {
          TDElement.all(1).className = "inputTC";
          TDElement.all(1).webguiOldClassName = "inputTC";
        }
      } else if (o.tagName == "TABLE") {
        if (o.cells.length)
        {
          o = o.cells[0];
          if (o && o.webguiOldClassName)
          {
            o.className = o.webguiOldClassName;
            o.webguiOldClassName = "";
            TCSelectElement(o,mode);
          }
        }
      }
    }

  }
}

////////////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////////////
function TCSelectColumn(rows, columnNumber, mode, startrow)
{
  var numRows = rows.length;

  for (var i=startrow; i<numRows; i++)
  {
    var TDElement = rows[i].cells[columnNumber];

    if (TDElement && TDElement.className!="TCFooter")
    {
      TCSelectElement(TDElement,mode);
    }
  }
}

function TCLabel2Input(event)
{
  var parentTD;
  var selectedElement;
  var ititle, ish, iname, iwidth, imaxlength, itextalign, ihighlighted;
  var inputHTML, newinputElement, cellClass;

  if (event && event.srcElement)
    selectedElement = event.srcElement;
  else
    return;
    //selectedElement = window.event.srcElement;

  parentTD = webguiTableCellGetTD(selectedElement);

  ititle = ""; ish = ""; iname = "";
  iwidth = ""; imaxlength = ""; itextalign = "";
  ihighlighted = "", ivalue = "";

  // retrieves attr. to be used in input
  ititle = selectedElement.title;
  ish = selectedElement.sh;
  iwidth = selectedElement.iwidth;
  imaxlength = (selectedElement.imaxlength < 0) ? null : selectedElement.imaxlength;  //tj/2003-07-21/ allow imaxlength = -1
  itextalign = selectedElement.itextalign;
  iname = selectedElement.id;
  ihighlighted = selectedElement.ihighlighted;
  imonospace = selectedElement.imonospace;
  ivalue = selectedElement.ivalue;

  if (ihighlighted) {
    cellClass = "inputTCHighlighted";
  }
  else if (parentTD.className == "TCCellInputSelected") {
    cellClass = "inputTCCol";
  }
  else {
    cellClass = "inputTC";
  }

  inputHTML = "<INPUT CLASS=\"" + cellClass + "\" TYPE=\"text\" NAME=\"" + iname + "\" ONFOCUS=\"webguiDoFocus(event);\" ";
  inputHTML = inputHTML + "VALUE=\"" + ivalue + "\" STYLE=\"width:100%;";

  if (imonospace)
    inputHTML = inputHTML + imonospace + ";";

  if (itextalign)
    inputHTML = inputHTML + "text-align:" + itextalign + ";\" ";
  else
    inputHTML = inputHTML + "\" " ;

  if (ish)
    inputHTML = inputHTML + "sh=1 ";

  if (imaxlength)
    inputHTML = inputHTML + "maxlength=\"" + imaxlength + "\" ";

  inputHTML = inputHTML + ">";
  parentTD.innerHTML = inputHTML;

  newinputElement = parentTD.all(iname);
  if (newinputElement && newinputElement.focus)
  {
    newinputElement.focus();
    newinputElement.click();
    newinputElement.focus();
  }
}

//
// abp - check to see if this is an embedded table in the last column
//
function TCCheckEmbeddedTableTD(o)
{
  var tc_checkLevel = 5;
  var realTD = o.parentNode;

  while (tc_checkLevel-- > 0 && realTD && realTD.className.substr(0, 6) != "TCCell")
       realTD = realTD.parentElement;

  if (realTD && realTD.remainingColWidth)
    o = realTD;

  return o;
}


//
// abp - check to see if this is an embedded table in the last column
//
function TCCheckEmbeddedTableTR(o)
{
  var newTD = TCCheckEmbeddedTableTD(o);
  if (o == newTD)
    return o;
  else
    return newTD.parentElement;
}

/******************************************************************************
 *
 * <webguiTCEmulateTab>
 *
 * Handle tabulator key in tablecontrols
 *
 */
function webguiTCEmulateTab(tc, element)
{
  var rowTD, rowTR;
  var currentRow, currentCol, newRow, newCol;
  var focusElement;
  var tc2;

  rowTD = TCCheckEmbeddedTableTD(webguiTableCellGetTD(element));
  rowTR = rowTD.parentElement;

  if (rowTD && rowTR)
  {
    currentRow = parseInt(rowTR.ir);
    currentCol = parseInt(rowTD.ic);

    if (event.shiftKey && element.className.indexOf("inputTCJumpRow")>=0)
    {
      currentRow = tc.rows.length - 2;
      currentCol = tc.rows[tc.webguiTCRowStartAt].cells.length;
    }
    newRow = currentRow;
    newCol = currentCol;

    if (isNaN(currentCol) || isNaN(currentRow))
    {
      event.cancelBubble = false;
      event.returnValue = true;
      return;
    }

    do
    {
      if (currentRow < 0 || currentCol < 0)
      {
        event.cancelBubble = false;
        event.returnValue = true;
        return;
      }
      if (event.shiftKey)
      {
        if (tc.webguiNumRowSelector && currentCol == 0)
        {
          var notfixIdx = tc.id.indexOf("-notfix");
          if (notfixIdx < 0)
            tc2 = document.getElementById(tc.id+"-notfix");
          else
            tc2 = document.getElementById(tc.id.substring(0,notfixIdx));

          if (currentRow == tc.webguiTCRowStartAt && notfixIdx < 0)
          {
            event.cancelBubble = false;
            event.returnValue = true;
            return;
          }
          else
          {
            if (tc2)
            {
              tc = tc2;
              newCol = tc.rows[currentRow].cells.length - 1;
              if (notfixIdx < 0)
                newRow = currentRow - 1;
            }
            else
            {
              newRow = currentRow - 1;
              newCol = tc.rows[currentRow].cells.length - 1;
            }
          }
        }
        else
        {
          newCol = parseInt(currentCol) - 1;
        }
      }
      else
      {
        if (currentCol == tc.rows[currentRow].cells.length - 1)
        {
          var notfixIdx = tc.id.indexOf("-notfix");
          if (notfixIdx < 0)
            tc2 = document.getElementById(tc.id+"-notfix");
          else
            tc2 = document.getElementById(tc.id.substring(0,notfixIdx));

          if (currentRow >= tc.rows.length - 1 && ((notfixIdx < 0 && !tc2) || notfixIdx > 0))
          {
            event.cancelBubble = false;
            event.returnValue = true;
            return;
          }
          else
          {
            if (tc2)
            {
              tc = tc2;
              newCol = tc.webguiNumRowSelector; //0
              if (notfixIdx >= 0)
              {
                newRow = parseInt(currentRow) + 1;
              }
            }
            else
            {
              newRow = parseInt(currentRow) + 1;
              newCol = tc.webguiNumRowSelector;
            }
          }
        }
        else
        {
          newCol = parseInt(currentCol) + 1;
        }
      }

      if (newRow >= 0 && newRow < tc.rows.length)
      {
        try
        {
          focusElement = webguiGetFocusElement(tc.rows[newRow].cells[newCol]);
        }
        catch(exception)
        {
          status = "caught exception in webguiEmulateTab: " + exception.message;
        }
      }

      currentCol = newCol;
      currentRow = newRow;
    }
    while (!focusElement || (tc.rows[newRow].cells[newCol].className == "TCCellText"))
    if (focusElement)
    {
      var focusId = getAttributeRecursive(focusElement,"id");

      if (focusId)
      {
        webguiSetFocus(focusId.id);
      }
      else
      {
        focusId = getAttributeRecursive(focusElement,"name");
        if (focusId)
        {
          webguiSetFocus(focusId.name);
        }
      }
    }
  }
}
// </webguiTCEmulateTab>

function webguiDoDblClick(e)
{
  if (!webguiIsActive())
    return;

  if(e)
    selectedElement = e.srcElement;
  else
  {
    selectedElement = window.event.srcElement;
    e = window.event;
  }

  if ( selectedElement == null )
    return ;

  if (selectedElement.className == "PULLDOWN-TABSTRIP")
  {
    webguiDoClick(e);
    e.cancelBubble = true;
    e.returnValue = false;
    return;
  }

  e.cancelBubble = true;
  e.returnValue = false;

  if ( selectedElement.tagName == "INPUT" && selectedElement.type != "radio" )
  {
    targetObject = getMainWindow().document.webguiform;
    targetObject.elements[formFocusfieldIdx].value = selectedElement.name;
  }
  else
  {
    targetObject = getMainWindow().document.webguiform;

    if(selectedElement.id=="")
      selectedElement = selectedElement.parentElement;

    targetObject.elements[formFocusfieldIdx].value = selectedElement.id ;
  }

  webguiRaiseFKey(2);
}

function webguiDoFocus(e)
{
  webguiDoClick(e);
}

function webguiDoTabKey(eventHandler)
{
  if (eventHandler && eventHandler.srcElement)
    if (tc = webguiGetTC(eventHandler.srcElement))
    {
      eventHandler.cancelBubble = true;
      eventHandler.returnValue = false;
      webguiTCEmulateTab(tc, eventHandler.srcElement);
    }
}

function webguiSetDynproScrollPos(x,y)
{
  if (webguiDynpro)
  {
    if (x) webguiDynpro.scrollLeft = x;
    if (y) webguiDynpro.scrollTop = y;
  }
}

function webguiGetDynproScrollPos()
{
  var scrollleft, scrolltop;

  scrollleft = document.getElementById("~dynproscrollx");
  if (scrollleft)
    scrollleft.value = webguiDynpro.scrollLeft;

  scrolltop = document.getElementById("~dynproscrolly");
  if (scrolltop)
    scrolltop.value = webguiDynpro.scrollTop;
}

function webguiSetFocus(localfocusfield)
{
  //Errors w/multiple channels in workplace.  Document can be
  //hidden causing .focus() to fail see customer message 136928 2001

  if(isIE55_up() && document.body.clientWidth==0)
    return;

  var focusElement, inputRadioElement;

  if (!webguiIsActive())
    return;

  if (typeof(webgui_donot_set_focus) != "undefined") // abp 25.03.2003
  {
    if (webgui_donot_set_focus)
    {
      webgui_donot_set_focus = false;
      return;
    }
  }
  else
    webgui_donot_set_focus = false; // abp 25.03.2003

  in_webguiSetFocus = true;

  if (localfocusfield && localfocusfield != "")
    webguiFocusField = localfocusfield;
  else if(accessibility && webgui_ts_first_field && webgui_ts_first_field!="")
    webguiFocusField = webgui_ts_first_field;

  if (webguiFocusField && webguiFocusField != "")
  {
    if (webguiFocusField == "ControlFocusElement")
    {
      focusElement = document.getElementsByName(webguiFocusField);
      if (focusElement && focusElement.length)
      {
        focusElement = getAttributeRecursive(focusElement[0], "tabIndex");
        if (focusElement)
        {
          // for some reason .focus() doesn't work, and if we do a
          // .click(), it might be a hotspot (link) and go into an infinite
          // loop (thanks Tobias), so we fire an onmousedown event, which
          // works fine in setting the focus, and it should have
          // much less of a chance to cause a roundtrip...

          focusElement.fireEvent("onmousedown");
          focusElement.focus();
/* the problem here was that the focusElement's parent (or parent's parent) had
   an onclick handler, so this test didn't work
          if (focusElement.onclick == null) // okay to click
            focusElement.click();
          else if (focusElement.onmousedown == null) // okay to fire onmousedown event
            focusElement.fireEvent("onmousedown");
          else // what else can we do?
            focusElement.focus();
*/
        }
        return;
      }
    }
    else
    {
      focusElement = document.getElementById(webguiFocusField);

      if (!focusElement) {
        focusElement = document.getElementsByName(webguiFocusField);
        if (focusElement.length) {
          focusElement = focusElement[0];
        }
        else
          focusElement = null;
      }
    }
    if (focusElement && focusElement.length > 1 && focusElement.tagName != "SELECT")
    {
        // checkbox only - hidden value with same name
        for (i=0; i<focusElement.length; i++)
      if (focusElement[i].tagName == "INPUT" && (focusElement[i].type == "checkbox" || focusElement[i].type == "radio")
        && focusElement[i].disabled == false )
      {
          if (focusElement[i].parentElement && focusElement[i].parentElement.getAttribute("altType"))
        focusElement[i].parentElement.click();
          else
        focusElement[i].focus();

          break;
      }
    }
    else
    {
      if (focusElement && focusElement.tagName != "INPUT" && focusElement.tagName != "SELECT")
      {
        focusElement.click();
        if (focusElement && focusElement.parentNode)
          focusElement.focus();
      }
      else
      {
        if (focusElement && focusElement.focus && focusElement.disabled == false)
        {
          if (focusElement.parentElement && focusElement.parentElement.getAttribute("altType"))
          {
            focusElement.parentElement.click();
          }
          else if (focusElement.type == "hidden")
          {
            while (focusElement && focusElement.type != "checkbox")
              focusElement = focusElement.nextSibling;
            if (focusElement)
              focusElement.focus();
          }
          else
          {
            focusElement.focus();
          }
        }
      }
    }
  }
  else
  {
    // default focus on OKCodefield
    focusElement = document.all("~ToolbarOkCode");
    if (focusElement && focusElement.focus && focusElement.type != "hidden")
        focusElement.focus();
  }

  if (webguiFocusWin)
    if (typeof webguiFocusWin == "object") {
      webguiFocusWin.focus();
  }
    else if(webguiFocusWin != "") {
      window.open( "", webguiFocusWin).focus();
  }

  in_webguiSetFocus = false;
}

function webguiDoResize (immediate)
{
    if (!immediate)
    {
        // Workaround for IE4: Resizing a window with a complex page
        // is to slow. We install a timeout that triggers the actual
        // resizing after the mouse button is released in this case.
        if (webguiIsIE4())
        {
            statusbar = document.all["webguiStatusbar"];

            if (statusbar)
                statusbar.style.visibility = "hidden";

            clearTimeout(webguiTimeoutId);
            webguiTimeoutId = setTimeout("webguiDoResize(true);", WEBGUI_RESIZE_TIMEOUT);
            return;
        }
    }

    //Errors w/multiple channels in workplace.  Document can be hidden
    //causing infinite loop in these calculatins see customer message 136928 2001
    if(!webguiIsIE4() && document.body.clientWidth!=0)
    {
        webguiFitTitlebar();
    if ( typeof( self.webguiMenusl) == "undefined") {
          webguiFitAppButtons();
          webguiFitStdButtons();
          webguiFitMenus();
    }
    else {
      webguiFitAppMenu();
    }
    }

    if (webguiUserArea)
    {
        if (!webguiTableLayout)
        {
          var
                toolbar,
                container,
                statusbar;

            container = webguiUserArea.parentElement;
            toolbar = document.all["webguiToolbar"];
            statusbar = document.all["webguiStatusbar"];
            popup = document.all["webguiPopup"];

            if (toolbar && container)
            {
                webguiUserArea.style.pixelWidth = toolbar.offsetWidth;
                if (popup)
                {
                    webguiRedrawOnIE4(popup);
                    webguiUserArea.style.pixelHeight = popup.offsetHeight - container.offsetTop;
                }
                else
                    webguiUserArea.style.pixelHeight = document.body.clientHeight - container.offsetTop;

                webguiRedrawOnIE4(webguiUserArea);

                if (statusbar)
                {
                    statusbar.style.visibility = "visible";
                    webguiUserArea.style.pixelHeight -= statusbar.offsetHeight;
                    statusbar.style.pixelWidth = toolbar.offsetWidth;
                    statusbar.style.pixelTop = container.offsetTop + webguiUserArea.style.pixelHeight;
                }
            }
        }
    }

    if (window.controlDoResize)
        window.controlDoResize();

  webguiSetUserArea();
}

var garr_controlClasses = new Array(
  "ColumnTree", "Docking", "gridview", "htmlviewer", "image", "splitter", "TCViewContainer", "TextEdit"
);

function webguiEventOnControl( in_evt )
{
  function _isControl( in_obj )
  { var rc = false;
    var objclass;
    if (in_obj) {
      objclass = in_obj.className;
      if (objclass != null) {
        //alert("webguiEventOnControl()._isControl(): Object(" + in_obj.tagName + ") class = " + objclass);
        for (var cl in garr_controlClasses) {
          if (garr_controlClasses[ cl] == objclass) {
            rc = true;
            break;
          }
        } // for
      }
    }
    return rc;
  } // _isControl()

  var rval = obj;
  var evt;
  var obj,
      parobj,
      rootobj = document.getElementsByTagName("body")[0];
  var isSearch = true;

  evt = in_evt ? in_evt : ((window.event) ? window.event : "");
  if (evt) {
    // look for control
    obj = event.srcElement;
    while (obj != rootobj) {
      if (_isControl( obj)) {
        //alert("webguiEventOnControl(): Object " + obj.tagName + "(" + obj.className + ") is a control");
        rval = obj;
        break;
      }
      obj = obj.parentNode;
    }
  }
  return rval;
} // webguiEventOnControl()


function webguiDoContextMenu ()
{
  var obj;
  if (webguiContextMenu && arrMenu_FM!="")
  {
    if (webguiIsActive())
    {
      // check if legal object for context menu
      obj = webguiEventOnControl();
      //alert("webguiDoContextMenu(): Event on control: " + (obj ? "yes" : "no") + (obj ? "\n Show context menu: " + (obj.oncontextmenu != null ? "yes" : "no") : "") );
      if (!obj || obj.oncontextmenu != null) {
        contextMenuException = false;
        OpenContextMenu();
      }
    }

    event.returnValue = false;
    event.cancelBubble = true;
  }
}

// BEGIN @@ JB 8.3.2002
function webguiDoControlContextMenu (controlId, myevent, local)
{
  if (webguiIsActive())
  {
    //contextMenuException = false;
    OpenControlContextMenu(controlId, myevent, local);
  }

  event.returnValue = false;
  event.cancelBubble = true;
}
// END OF @@ JB 8.3.2002


function webguiListDoDblClick(e)
{
  if (!webguiIsActive() || in_webguiSetFocus)
    return;

  if (e)
    elem = e.srcElement;
  else
    elem = window.event.srcElement;

  id = webguiListElemId(elem);

  targetObject = getMainWindow().document.webguiform;
  targetObject.elements[formControlIdx].value = "~list" ;
  targetObject.elements[formEventIdx].value = "DblClick";
  targetObject.elements[formEventPrmIdx].name = "~objid" ;
  targetObject.elements[formEventPrmIdx].value = id ;
  submitForm();
}

function webguiListElemId(element)
{
  var
    id;

  if(element && element.tagName == "IMG")
  {
    if(webguiIsIE4() && element.parentElement.children[0]) //set the selected element to the hidden field for checkboxen
      element = element.parentElement.children[0];
    else if(element.previousSibling)
      element = element.previousSibling;

    if(element.tagName == "INPUT")
      id = element.name;
    else
    {
      if(element.tagName=="IMG" && element.id=="")
        id = element.parentElement.id;
      else
        id = element.id;
    }
  }
  else
    id = element.id;

  return(id);
}

function webguiSetUserArea()
{
	//convert back to SAP metric
	var targetObject, parentTargetObject;
	var webguibody;
	var h, w;

	if (webguiIsPopup)
	{

		webguibody = document.getElementsByTagName("body")[0];
		if (webguibody && webguibody.id.substr(0, 10) == "webguiBody")
		{
			for (var par = parent; par.webguiIsPopup && par != par.parent; par = par.parent)
			;
			if (par && par.webguiIsPopup == false)
			{
				parentTargetObject = par.document.webguiform;
				targetObject = document.webguiform;
				targetObject.elements[ formWebguiUserAreaHeight].value = parentTargetObject.elements[ formWebguiUserAreaHeight].value;
				targetObject.elements[ formWebguiUserAreaWidth].value  = parentTargetObject.elements[ formWebguiUserAreaWidth].value;
			}
		}


	}

	//fontHeight = document.getElementById("FontWidthTester").offsetHeight;
	//fontWidth = document.getElementById("FontWidthTester").offsetWidth;
	//fontListHeight = document.getElementById("FontListTester").offsetHeight;
	//fontListWidth = document.getElementById("FontListTester").offsetWidth;

	//alert(fontHeight + " - " + fontWidth + "    " + fontListHeight + " - " + fontListWidth);

	targetObject = document.webguiform;
	webguibody = document.getElementById("webguiBody");

	var statusbarHeight = 0;

	if(webguiUserArea && targetObject && !webguiIsPopup)
	{
		if(targetObject.elements[formWebguiUserAreaHeight] &&
		    targetObject.elements[formWebguiUserAreaHeight].name.indexOf("~webgui")==0)
		{
		    newAreaHeight = document.getElementById("WebguiUserArea").offsetHeight - 20;
		    if (newAreaHeight<0)
			newAreaHeight = 0;
		    targetObject.elements[formWebguiUserAreaHeight].value = newAreaHeight;
		}

		if(targetObject.elements[formWebguiUserAreaWidth] &&
		    targetObject.elements[formWebguiUserAreaWidth].name.indexOf("~webgui")==0)
		{
		    newAreaWidth = (document.getElementById("WebguiUserArea").offsetWidth - 20) ;
		    if (newAreaWidth<0)
			newAreaWidth = 0;
		    targetObject.elements[formWebguiUserAreaWidth].value = newAreaWidth;
		}
	}
}

// ==========================================================
// Modal Windows
// ==========================================================

function webguiModalLoad(modalNo)
{
  return document.all["webguiModalWindow" + modalNo].innerHTML;
}

function webguiModalDoMouseMove()
{
  var
    webguiMoveModal = window.webguiMoveModal,
    webguiModalElement;

  if (webguiMoveModal != null)
  {
    var
      pixelLeft,
      pixelTop,
      pixelWidth,
      pixelHeight;

    webguiModalElement = webguiMoveModal.element;

    if (webguiMoveModal.resize)
    {
    pixelWidth = webguiMoveModal.windowWidth + event.screenX - webguiMoveModal.startX;
    pixelHeight = webguiMoveModal.windowHeight + event.screenY - webguiMoveModal.startY;

      webguiModalElement.style.pixelWidth = pixelWidth;
      webguiModalElement.style.pixelHeight = pixelHeight;
    }
    else
    {
      pixelLeft = webguiMoveModal.windowX + event.screenX - webguiMoveModal.startX;
      pixelTop = webguiMoveModal.windowY + event.screenY - webguiMoveModal.startY;

      if(webguiMoveModal.boundCursor)
      {
        cursorLeft = webguiModalElement.offsetLeft + event.clientX;
        cursorTop = webguiModalElement.offsetTop + event.clientY;
        if(cursorLeft > 0 && cursorLeft < webguiModalElement.document.parentWindow.document.body.offsetWidth - 5 &&
          cursorTop > 0 && cursorTop < webguiModalElement.document.parentWindow.document.body.offsetHeight - 5)
        {
          webguiModalElement.style.pixelLeft = pixelLeft;
          webguiModalElement.style.pixelTop = pixelTop;
        }
    }
    else
    {
      webguiModalElement.style.pixelLeft = pixelLeft;
      webguiModalElement.style.pixelTop = pixelTop;
      }
    }
    event.cancelBubble = true;
    event.returnValue = false;
  }
}

function webguiModalDoMouseUp()
{
  if (window.webguiMoveModal != null)
  {
    var
      webguiModalElement = window.webguiMoveModal.element;

    if (window.webguiMoveModal.resize)
    {
      document.body.innerHTML = window.webguiMoveModal.innerHTML;
    }

    document.body.onmousemove = window.webguiMoveModal.oldonmousemove;
    document.body.onmouseup = window.webguiMoveModal.oldonmouseup;
    event.cancelBubble = true;
    event.returnValue = false;

    if (document.webguiform && webguiModalElement)
    {
      if (document.webguiform.elements[formWebguiModalLeft])
      {
        document.webguiform.elements[formWebguiModalLeft].value = webguiModalElement.style.pixelLeft;
      }
      if (document.webguiform.elements[formWebguiModalTop])
      {
        document.webguiform.elements[formWebguiModalTop].value = webguiModalElement.style.pixelTop;
      }
    }

    window.webguiMoveModal = null;
  }
}

function webguiModalDoMouseDown(resize)
{
  var
    webguiMoveModal,
    webguiModalElement;

  webguiModalElement = parent.document.getElementById(window.name);
  if (webguiModalElement)
  {
    webguiMoveModal = new Object;
    webguiMoveModal.startX = event.screenX;
    webguiMoveModal.startY = event.screenY;
    webguiMoveModal.windowX = webguiModalElement.style.pixelLeft;
    webguiMoveModal.windowY = webguiModalElement.style.pixelTop;
    webguiMoveModal.windowWidth = webguiModalElement.style.pixelWidth;
    webguiMoveModal.windowHeight = webguiModalElement.style.pixelHeight;
    webguiMoveModal.oldonmousemove = document.body.onmousemove;
    webguiMoveModal.oldonmouseup = document.body.onmouseup;
    webguiMoveModal.oldonmouseout = document.body.onmouseout;
    webguiMoveModal.element = webguiModalElement;
    if (resize)
    {
      webguiMoveModal.resize = true;
      webguiMoveModal.innerHTML = document.body.innerHTML;
      document.body.innerHTML = "";
    }
    window.webguiMoveModal = webguiMoveModal;
    document.body.onmousemove = webguiModalDoMouseMove;
    document.body.onmouseup = webguiModalDoMouseUp;

//tj/2001-10-02
    if(isIE55_up())
//tj/
    {
      document.body.onmouseout = webguiModalDoMouseMove;
      webguiMoveModal.boundCursor = 1;
    }
  }
}

function webguiModalIsResizeEvent(event)
{
  if (webguiIsPopup && webguiIsResizable)
  {
    if (event && event.srcElement && event.type == "mousedown")
    {
      if ((event.x >= event.srcElement.offsetWidth - WEBGUI_RESIZE_WIDTH)
       && (event.x <= event.srcElement.offsetWidth)
       && (event.y >= event.srcElement.offsetHeight - WEBGUI_RESIZE_WIDTH)
       && (event.y <= event.srcElement.offsetHeight))
      {
        return true;
      }
    }
  }

  return false;
}


// ==========================================================
// Misc
// ==========================================================

function webguiGetAbsScreenPos(element)
{
  var vParent,parentToFind,scrolledTop,scrolledLeft,topPos,leftPos,insidewebguiDynpro;
  var webguiToolbar = document.getElementById("webguiToolbar");

  if (webguiDynpro)
  {
    parentToFind = webguiDynpro;
    vParent = element;
  }
  else
    return;

  topPos = 0;
  leftPos = 0;
  scrolledLeft = 0;
  scrolledTop = 0;
  element.absTop = 0;
  element.absLeft = 0;
  insidewebguiDynpro = false;

  while (vParent)
  {
    topPos = topPos + vParent.offsetTop;
    leftPos = leftPos + vParent.offsetLeft;
    if (vParent.scrollTop)
      topPos = topPos - vParent.scrollTop;
    if (vParent.scrollLeft)
      leftPos = leftPos - vParent.scrollLeft;
    if (vParent==webguiDynpro)
    {
      insidewebguiDynpro = true;
      break;
    }

    vParent = vParent.offsetParent;
  }

  element.absTop = topPos;
  element.absLeft = leftPos;

        if (webguiToolbar && insidewebguiDynpro)
  {
    topPos = topPos + webguiToolbar.offsetHeight;
    element.absTop = topPos + 10; // +10 webguidynproborder
    element.absLeft = leftPos + 10;
  }
}

function webguiLoadEmpty()
{
  return "<html><head><script language='Javascript' src='" + document.webguiMimeURL + "/webgui/2002/scripts/wgu_winframe.js'></script> <script>wgu_TrySetDocumentDomainParentDependend();</script></head><body></body></html>";
}

function shResultTableSelect(useGlobalVar)
{
  var TRRow, controlid;

  if (useGlobalVar)
  {
    if (shResultFieldRowIdx != null)
    {
      var shResultTable = document.getElementById("searchHelpResultBody")

      if (shResultTable)
        TRRow = shResultTable.rows[shResultFieldRowIdx];
    }
    else
      submitForm();
  }
  else if (event.srcElement)
    TRRow = webguiTableCellGetTR(event.srcElement);

  if (TRRow && TRRow.param)
  {
    controlid = TRRow.controlid;
    webguiRaiseEvent(controlid,"ResultTableSelect",TRRow.param, "_parent");
  }
}

function redirect_TCLabel2Input(TCHandle)
{
  var firstCell, firstCellChild;

  if (TCHandle && TCHandle.rows[0])
    firstCell = TCHandle.rows[0].cells[0];

  for (i=0; i < firstCell.children.length; i++)
  {
    firstCellChild = firstCell.children[i];
    while (firstCellChild)
    {
      if (firstCellChild.className.indexOf("labelTable") >= 0)
      {
        firstCellChild.click();
        return;
      }
      firstCellChild = firstCellChild.children[0];
    }
  }
}

var webguiAppButtonBar=0;

function webguiFitAppButtons()
{
  if(webguiAppButtonBar==0)
  {
    webguiAppButtonBar = document.getElementById("webguiAppButtonBar");
    if(!webguiAppButtonBar)
      return;

    webguiAppButtonBar.lastVisible = webguiAppButtonBar.rows[0].cells.length - 1;
    webguiAppButtonBar.totalCells = webguiAppButtonBar.lastVisible;
    webguiAppButtonBar.widthVisible = 0;
    webguiAppButtonBar.firstVisible = 1;

    cells = webguiAppButtonBar.rows[0].cells;

    for(i=0; i<webguiAppButtonBar.totalCells; i++)
    {
      webguiAppButtonBar.widthVisible += cells[i].offsetWidth;
    }
  }

  if(!webguiAppButtonBar ||
    (document.body.clientWidth >= webguiAppButtonBar.widthVisible &&
    webguiAppButtonBar.totalCells == webguiAppButtonBar.lastVisible))
    return;

  if(document.body.clientWidth < webguiAppButtonBar.widthVisible)
    webguiHideBar(webguiAppButtonBar);
  else
    webguiShowBar(webguiAppButtonBar);
}

var webguiStdButtonBar=0;

function webguiFitStdButtons()
{
  if(webguiStdButtonBar==0)
  {
    webguiStdButtonBar = document.getElementById("webguiStdButtonBar");
    if(!webguiStdButtonBar)
      return;

    webguiStdButtonBar.lastVisible = webguiStdButtonBar.rows[0].cells.length - 1;
    webguiStdButtonBar.totalCells = webguiStdButtonBar.lastVisible;
    webguiStdButtonBar.widthVisible = 0;
    webguiStdButtonBar.firstVisible = 5;

    cells = webguiStdButtonBar.rows[0].cells;

    for(i=0; i<webguiStdButtonBar.totalCells; i++)
    {
      webguiStdButtonBar.widthVisible += cells[i].offsetWidth;
    }

    // don't forget to add the meta standard button menu
    webguiStdButtonBar.widthVisible += cells[i].offsetWidth;

    // must take into account the width of the toolbar's logo.
    webguiLogo = document.getElementById("webguiToolbarLogo");
    if(webguiLogo)
      webguiStdButtonBar.widthVisible += webguiLogo.offsetWidth;

    // some buffer space
    webguiStdButtonBar.widthVisible += 24;
  }

  if(!webguiStdButtonBar ||
    (document.body.clientWidth > webguiStdButtonBar.widthVisible &&
    webguiStdButtonBar.totalCells == webguiStdButtonBar.lastVisible))
    return;

  if(document.body.clientWidth < webguiStdButtonBar.widthVisible)
    webguiHideBar(webguiStdButtonBar);
  else
    webguiShowBar(webguiStdButtonBar);

  metaStdButton = document.getElementById("webguiMetaStdButton");
  if(webguiStdButtonBar.totalCells == webguiStdButtonBar.lastVisible)
    metaStdButton.style.visibility = "hidden";
  else
    metaStdButton.style.visibility = "visible";
}

var webguiMenuBar=0;

function webguiFitMenus()
{
  if(webguiMenuBar==0)
  {
    webguiMenuBar = document.getElementById("_sapMenu_");
    if(!webguiMenuBar)
      return;

    //subtract one for the function menu (it is not counted).

    if(!webguiContextMenu)
      webguiMenuBar.lastVisible = webguiMenuBar.rows[0].cells.length - 1 - 2;
    else
      webguiMenuBar.lastVisible = webguiMenuBar.rows[0].cells.length - 1 - 1;

    webguiMenuBar.totalCells = webguiMenuBar.lastVisible;
    webguiMenuBar.widthVisible = 0;
    webguiMenuBar.firstVisible = 1;

    cells = webguiMenuBar.rows[0].cells;

    for(i=0; i<webguiMenuBar.totalCells; i++)
    {
      webguiMenuBar.widthVisible += cells[i].offsetWidth;
    }
    //skip over the cell which makes everything align left.

    // don't forget to add the function menu & the meta menu button
    webguiMenuBar.widthVisible += cells[i+1].offsetWidth;

    if(!webguiContextMenu)
      webguiMenuBar.widthVisible += cells[i+2].offsetWidth;

    // must take into account the width of the toolbar's logo.
    webguiLogo = document.getElementById("webguiToolbarLogo");
    if(webguiLogo)
      webguiMenuBar.widthVisible += webguiLogo.offsetWidth;

    // some buffer space
    webguiMenuBar.widthVisible += 20;
  }

  if(!webguiMenuBar ||
    (document.body.clientWidth > webguiMenuBar.widthVisible &&
    webguiMenuBar.totalCells == webguiMenuBar.lastVisible))
    return;

  if(document.body.clientWidth < webguiMenuBar.widthVisible)
    webguiHideBar(webguiMenuBar);
  else
    webguiShowBar(webguiMenuBar);

  metaMenu = document.getElementById("webguiMetaMenu");
  if(webguiMenuBar.totalCells == webguiMenuBar.lastVisible)
    metaMenu.style.visibility = "hidden";
  else
    metaMenu.style.visibility = "visible";
}


//tj/2002-11-02/ frog2002 && HCM menu
//

function webguiRebuildAppButtonMenu( webguiAppMenuBar, webguiAppMetaButton )
{ var i, j, k, l;
  if (arrMenu_appBarFul && arrMenu_appBarCur) {
    arrMenu_appBarCur = new Array();
    for (i = webguiAppMenuBar.lastVisible; i < webguiAppMenuBar.totalCells; i++) {
      k = i * 5; l = (i - webguiAppMenuBar.lastVisible) * 5;
      for (j = 0; j < 5; j++)
        arrMenu_appBarCur[ l + j] = arrMenu_appBarFul[ k + j];
    }
  } // if (arrMenu_...)
} // webguiRebuildAppButtonMenu ()


var webguiAppMenuBar = 0;
var webguiAppMetaButton = 0;
var webguiAppMetaButtonLV = 0;

function webguiFitAppMenu( reset )
{
  if (reset) {
    webguiAppMenuBar = 0;
    webguiAppMetaButton = 0;
  }

  if(!webguiAppMenuBar || !webguiAppMetaButton)
  {
    webguiAppMenuBar = document.getElementById( "webguiAppButtonBar");
    webguiAppMetaButton = document.getElementById("webguiMetaAppButton");

    if(!webguiAppMenuBar || !webguiAppMetaButton)
      return;

    webguiAppMenuBar.lastVisible = webguiAppMenuBar.rows[0].cells.length - 2;
    webguiAppMenuBar.totalCells = webguiAppMenuBar.lastVisible;
    webguiAppMenuBar.widthVisible = 0;
    webguiAppMenuBar.firstVisible = 0;

    cells = webguiAppMenuBar.rows[0].cells;

    for(i = 0; i < webguiAppMenuBar.totalCells + 1; i++) {
      var olddis = cells[i].style.display;
      cells[i].style.display = "block";
      webguiAppMenuBar.widthVisible += cells[i].offsetWidth;
      if (cells[ i] == webguiAppMetaButton)
        webguiAppMetaButton.style.display = "none";
      else {
        if (!reset)
          cells[i].style.display = olddis;
      }
    }

    var mb = document.getElementById("_sapMenu_");
    var tb = document.getElementById("webguiStdButtonBar");
    var l;
    if (mb != null && tb != null) {
      l = mb.offsetWidth + tb.offsetWidth;
      webguiAppMenuBar.widthVisible = l + webguiAppMenuBar.widthVisible + 12;
    }
  }

  if (webguiAppMenuBar) {
    if (document.body.clientWidth > webguiAppMenuBar.widthVisible && webguiAppMenuBar.totalCells == webguiAppMenuBar.lastVisible) {
      if (reset) webguiShowBar(webguiAppMenuBar);
    }
    else {
      if(document.body.clientWidth < webguiAppMenuBar.widthVisible)
        webguiHideBar(webguiAppMenuBar);
      else
        webguiShowBar(webguiAppMenuBar);

      if(webguiAppMenuBar.totalCells == webguiAppMenuBar.lastVisible)
        webguiAppMetaButton.style.display = "none";
      else
        webguiAppMetaButton.style.display = "block";

      if (self.webguiMenuslDynAppMenu && webguiAppMetaButtonLV != webguiAppMenuBar.lastVisible) {
        webguiAppMetaButtonLV = webguiAppMenuBar.lastVisible;
        webguiRebuildAppButtonMenu(webguiAppMenuBar, webguiAppMetaButton);
      }
    }
  } // if (webguiAppMenuBar)
} // webguiFitAppMenu()


var webguiTitlebar = 0;

function webguiFitTitlebar()
{
  if(webguiTitlebar==0)
  {
    webguiTitlebar = document.getElementById("webguiTitleBar");
    if(!webguiTitlebar)
      return;

    webguiTitlebar.textObj = document.getElementById("webguiTitleBarText");
    if(!webguiTitlebar.textObj)
      return;

    webguiTitlebar.textObj.origText = webguiTitlebar.textObj.innerHTML;
  }

  if(!webguiTitlebar || !webguiTitlebar.textObj)
    return;

  while(webguiTitlebar.textObj.offsetWidth + 40 > document.body.clientWidth)
  {
    webguiTitlebar.textObj.innerHTML = webguiTitlebar.textObj.innerHTML.substring(0, webguiTitlebar.textObj.innerHTML.length-2);
  }

  while(webguiTitlebar.textObj.offsetWidth + 60 < document.body.clientWidth &&
    webguiTitlebar.textObj.innerHTML.length < webguiTitlebar.textObj.origText.length)
  {
    webguiTitlebar.textObj.innerHTML = webguiTitlebar.textObj.origText.substring(0, webguiTitlebar.textObj.innerHTML.length+1);
  }
}

function webguiHideBar(bar)
{
  cells = bar.rows[0].cells;

  //document.body.clientWidth is the visible (not including hidden parts that are reachable with
  // the use of the scroll bar) screen area of the body.
  for(i=bar.lastVisible; i>bar.firstVisible && i >= 0 && document.body.clientWidth < bar.widthVisible; i--)
  {
    bar.widthVisible -= cells[i-1].offsetWidth;
    cells[i-1].style.display = "none";
  }

  bar.lastVisible = i;
}

function webguiShowBar(bar)
{
  cells = bar.rows[0].cells;

  for(i=bar.lastVisible; i<bar.totalCells && i >= 0 && document.body.clientWidth > bar.widthVisible; i++)
  {
    cells[i].style.display = "block";
    bar.widthVisible += cells[i].offsetWidth;
  }

  if(document.body.clientWidth <= bar.widthVisible && i >= 0)
  {
    i--;
    bar.widthVisible -= cells[i].offsetWidth;
    cells[i].style.display = "none";
  }

  bar.lastVisible = ((i < 0) ? 0 : i);
}

function labelImageClick(event)
{
  var selectedElement;

  if (event && (selectedElement = event.srcElement))
  {
    if (selectedElement.parentElement)
      selectedElement.parentElement.click();
  }
}

// checkNumber - returns true if the string is a valid number, false otherwise.
//               ignores leading and ending spaces.
//
function checkNumber(string)
{
//  var re = /^\s*\d+(\.\d+)?\s*$/;
//  return (string.match(re) == null ? 0 : 1);
  return (String(string.constructor).indexOf("Number") != -1);
}

function adjustRange(fromId, toId, range, max)
{
  if ((checkNumber(from.value)) && ((from.value - range) > 0) && (from.value < max))
    to.value = from.value + range;
}

function fireVScroll(obj, percentScrolled, rowNumber)
{
  var e = document.createEventObject();
  e.setAttribute("percentScrolled",percentScrolled);
  e.setAttribute("rowNumber",rowNumber);

  if (obj)
    obj.fireEvent("onscroll",e);

}

function getTCRowNo(noRows, percent)
{
  var rowNo = Math.round(noRows * percent);
  return (rowNo == 0 ? 1 : rowNo);
}

function getListRowNo(noRows, percent)
{
  var rowNo = Math.round(noRows * percent);
  return (rowNo == 0 ? 1 : rowNo);
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////// ACCESSIBILITY ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////


//
// a11y_resetTab(
//
function a11y_resetTab()
{
  var first = document.getElementsByName("firstFocusElement");

  if (first && first.length)
    first[0].focus();
}

//
// a11y_checkAltControlTab(
//
function a11y_checkAltControlTab()
{

}

//
// A11YSETALBBID(id)
//
function a11ySetAltBId(id)
{
  a11yAltB = id;
}

//
// A11YGETALTBID()
//
function a11yGetAltBId()
{
  return a11yAltB;
}

//
// DO AREA END ON KEY DOWN
//
function doAreaEndOnKeyDown()
{
  a11yLastKey=event.keyCode;
}

//
// DO AREA BEGIN ON KEY DOWN
//
function doAreaBeginOnKeyDown(id)
{
  var myId = event.srcElement.id;
  a11yLastKey=event.keyCode;

  if (a11yLastKey == 9) // tab
  {
    if (event.shiftKey==true) // backward
        a11ySetAltBId("");
    else                      // forward
        a11ySetAltBId(myId);
  }
  else if (event.altKey && a11yLastKey == 66) // Alt + b
  {
    a11ySetAltBId("");
  }
  else if ((event.keyCode == 83) && (id != ""))
  {
    var next = document.getElementById(id);

    if (next)
    {
      webguiSetFocus(id);
    }
    else
    {
      alert("couldn't get " + id);
    }
  }
}

//
// DO AREA BEGIN ON FOCUS
//
function doAreaBeginOnFocus(id)
{
  var altB = a11yGetAltBId();
  var myId = event.srcElement.id;

  window.status=event.srcElement.alt;
  if (altB) // id already set
  {
    if (altB == myId)
    {
      if (event.altKey && a11yLastKey == 90) // Alt + z
      {
        a11ySetAltBId(myId);
      }
      else if (event.altKey && a11yLastKey == 66) // Alt + b
      {
        a11ySetAltBId("");
      }
      else if (a11yLastKey == 9) // tab
      {
        if (event.shiftKey==true) // backward
          a11ySetAltBId("");
        else                      // forward
          a11ySetAltBId(myId);
      }
    }
    else // Id set, not this one
    {
      if (event.altKey) // can't check event.keyCode unfortunately, as it's always 0 here
      {
        var a11y_b = document.getElementById(altB);
        if (a11y_b)
          a11y_b.focus();
      }
    }
  }
}

//
// DO AREA END ON BLUR
//
function doAreaEndOnBlur(id)
{
  window.status="";
  if (a11yLastKey == 9) // tab
    a11ySetAltBId("");
}

//
// A11Y_CHECK() - checks for arrow navigation
//
function a11y_Check()
{
  if (event.srcElement.tagName != "SELECT") // don't do it on drop down boxes
  {
    if (event.keyCode==40) // down
    {
      return a11y_check_DownArrow();
    }
    else if (event.keyCode==38) // up
    {
      return a11y_check_UpArrow();
    }
  }
  return "";
}

//
// A11Y_CHECK_GETPARENTINFO
//
function a11y_check_getParentInfo(obj,params)
{
  var o = obj;
  while (o.tagName != "TD")
    o = o.parentElement;
  params[0] = o.cellIndex;
  params[1] = o.parentElement.rowIndex;
  var tbl = o;
  while (tbl.tagName != "TABLE")
    tbl = tbl.parentElement;
  params[2]=tbl;
}

//
// A11Y_REMOVE_ROWLABEL
//
function a11y_remove_rowLabel()
{
  var labelText, i = 0;
  var o = event.srcElement;
  o.onblur="";
  while (o.tagName != "TD")
    o = o.parentElement;
  var kids = o.children;
  for (i=0;i < kids.length; i++)
  {
    if (kids(i).tagName == "LABEL")
    {
      labelText = kids(i).innerText.split(a11y_firstRow);
      kids(i).innerText = (labelText.length == 1) ? labelText[0].split(a11y_lastRow)[1] : labelText[1];
      return;
/*    if (labelText.indexOf(a11y_lastRow) != -1) labelText = labelText.slice(a11y_lastRow.length);
    else if (labelText.indexOf(a11y_firstRow) != -1) labelText = labelText.slice(a11y_firstRow.length); */
    }
  }
  if (kids.length == 0)
  {
    labelText = o.title.split(a11y_firstRow);
    o.title= (labelText.length == 1) ? labelText[0].split(a11y_lastRow)[1] : labelText[1];
  }
}


//
// A11Y_CHECK_DOWNARROW_LASTTD
//
function a11y_check_DownArrow_LastTD(lastTD,numRows)
{
  var child;
  for (i = 0; i < lastTD.children.length; i++)
  {
    child = lastTD.children(i);
    if (child.tagName == "LABEL")
    {
      if (child.innerText.indexOf(a11y_lastRow) == -1)
        child.innerText = a11y_lastRow + " " + child.innerText;
    }
    else if (child.tagName == "INPUT")
      child.onblur=a11y_remove_rowLabel;
  } // end for
  if (lastTD.children.length == 0) // just the TD mam
  {
    lastTD.title = a11y_lastRow + " " + lastTD.title;
    lastTD.onblur= a11y_remove_rowLabel;
  }
}

//
// A11Y_CHECK_UPARROW_FIRSTTD
//
function a11y_check_UpArrow_FirstTD(firstTD,numRows)
{
  var child;
  for (i = 0; i < firstTD.children.length; i++)
  {
    child = firstTD.children(i);
    if (child.tagName == "LABEL")
    {
      if (child.innerText.indexOf(a11y_firstRow) == -1)
        child.innerText = a11y_firstRow + " " + child.innerText;
    }
    else if (child.tagName == "INPUT")
      child.onblur=a11y_remove_rowLabel;
  } // end for
  if (firstTD.children.length == 0) //if label found
  {
    firstTD.title = a11y_firstRow + " " + firstTD.title;
    firstTD.onblur= a11y_remove_rowLabel;
  }

}

//
// A11Y_CHECK_SETFOCUS
//
function a11y_check_SetFocus(nextTD)
{
  if (nextTD == null)
    return;
  var i;
  for (i = 0; i < nextTD.children.length; i++)
  {
    if (nextTD.children(i).tagName == "INPUT" || nextTD.children(i).tagName == "SELECT")
    {
      if ((nextTD.children(i).type != "checkbox") && (nextTD.children(i).type != "hidden"))
      {
        nextTD.children(i).focus();
        break;
      }
      else
        nextTD.click();
    }
  }
  if (i == nextTD.children.length)
  {
    try { // might get a "cannot move focus to... error
      nextTD.focus(); // firstChild.click() raised an error with non-editable ALV Grids (?)
    } catch(err) {
      nextTD.click();
    }
  }
}

//
// A11Y_CHECK_DOWNARROW
//
function a11y_check_DownArrow()
{
  var cI,rI,tbl,nextTD,lastTD;
  var params = new Array(3);
  a11y_check_getParentInfo(event.srcElement,params);
  cI = params[0];
  rI = params[1];
  tbl = params[2];

  if (rI != tbl.rows.length - 1)
  {
    nextTD = tbl.rows(rI + 1).cells(cI);
    // test for 2nd row from bottom to change its label to read "last row"
    if (rI == tbl.rows.length - (((tbl.className == "webguiInnerTCView") ? 3 : 2))) /* -3 for [table] controls with footers */
    {
      lastTD = tbl.rows(tbl.rows.length - (((tbl.className == "webguiInnerTCView") ? 2 : 1))).cells(cI);
      a11y_check_DownArrow_LastTD(lastTD,tbl.rows.length);
    }
    a11y_check_SetFocus(nextTD);
  }
  else //     event.cancelBubble =true; event.returnValue = false;
    return "down"; // nextTD = tbl.rows(1).cells(cI); // would be for looping, but probably not the best idea
}

//
// A11Y_CHECK_UPARROW
//
function a11y_check_UpArrow()
{
  var cI,rI,tbl,nextTD,firstTD;
  var params = new Array(3);
  a11y_check_getParentInfo(event.srcElement,params);
  cI = params[0];
  rI = params[1];
  tbl = params[2];

  if (rI != 0)
  {
    prevTD = tbl.rows(rI - 1).cells(cI);
    // test for 2nd row from top (second row) to change its lable to read "first row"
    // test for HEADER ROW!!!!!!
    if (rI == 2) // if second row
    {
      firstTD = tbl.rows(1).cells(cI);
      a11y_check_UpArrow_FirstTD(firstTD,tbl.rows.length);
    }
    a11y_check_SetFocus(prevTD);
  }
  else
    return "up";
}
