////////////////////////////////////////////////////////////////////////////
//         Copyright (C) 1999 Computer Associates International, Inc
// as an unpublished work. This notice does not imply unrestricted or public
// access to these materials which are a trade secret of Computer Associates
// International or its subsidiaries or affiliates (together referred to as
// CA), and which may not be reproduced, used, sold or
// transferred to any third party without CA's prior written consent.
//
//                         All Rights Reserved.
//
//                       RESTRICTED RIGHTS LEGEND
// Use, duplication, or disclosure by the Government is subject to
// restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
// Technical Data and Computer Software clause at DFARS 252.227-7013.
////////////////////////////////////////////////////////////////////////////
// Module:  imgbutton.js
// Created: 12/28/01
////////////////////////////////////////////////////////////////////////////
// Description:
//     Script to make image buttons; supplied by Stamford and modified for CS
//
//
////////////////////////////////////////////////////////////////////////////
// $Header: /base/source/bp/freeaccess/jsdir/.RCS/imgbutton.js,v 1.75.1.5 2007/11/06 17:06:01 tuuma01 Exp $

var imgBtnArray = new Array();
var imgBtnID = 0;
var imgBtnRowCentered = true;
var imgBtnDisabledSupported = false;
var imgBtnPadding = "";
var imgBtnRowCount = 0;
var imgBtnRowActive = false;
var imgBtnDefault, imgBtnCancel, imgBtnDeferred;
var imgBtnScreenReaderHotkeys = null;
var imgBtnDefaultTabIndex;

if (typeof ahdtop == "undefined")
    ahdtop = get_ahdtop();
if ( typeof imgBtnData != "object" && typeof ahdtop == "object")
{
   var imgBtnData = ahdtop.imgBtnData;
   if (typeof imgBtnData != "object")
	imgBtnData = new Object();
}
var cancel_button_name;
var default_button_name;

if ( typeof _browser == "undefined" ) {
   var _browser = new Object();
   _browser.supportsLayers =  ! document.all;
   _browser.isIE = document.all;
}

// ImgBtnMouseOver()
//    Change cursor if button is active
function ImgBtnMouseOver( lID)
{
   var btn = imgBtnArray[lID];
   if ( typeof btn == "object" ) {
	  if ( btn.enabled )	
		window.status = btn.help;		
	  else	
		window.status = window.defaultStatus;
   }
   return true;
}

// ImgBtnExecute()
//    Run the function associated with the button
function ImgBtnExecute(lID)
{
   if ( typeof lID == "object" )
      lId = lID[0];
   var btn = imgBtnArray[lID];
   if ( btn.enabled ) {
      if ( typeof btn.innerButton == "string" )
        btn.innerButton = document.getElementById(btn.innerButton);
      try { btn.innerButton.focus(); } catch(e) {}
      eval( btn.func );
   }
   return false;
}

// ImgBtnObject()
//    Return the HTML object correspoding to a button
function ImgBtnObject(btnID)
{
  for ( var i = imgBtnArray.length - 1; i >= 0; i-- ) {
    var btn = imgBtnArray[i];
    if ( btn.id == btnID ) {
      if ( typeof btn.innerButton == "string" )
        btn.innerButton = document.getElementById(btn.innerButton);
      return btn.innerButton;
    }
  }
  return null;
}

// ImgBtnFocus()
//    Hightlight the button when it is selected (IE only)
// CA UI standards - This function will be obsolete with CA UI standards
function ImgBtnFocus(lID)
{
   var btn = imgBtnArray[lID];
   if ( btn.enabled ) {
      if ( typeof btn.obj == "string" )
        btn.obj = document.getElementById(btn.obj);
      btn.obj.style.color = imgBtnData["down_color"];
      if ( _browser.isIE ) {
         var e = window.event;
         if ( typeof e == "object" &&
              e.altKey )
            eval( btn.func );
      }
   }
}

// ImgBtnBlur()
//    Unhightlight the button when it loses focus
// CA UI standards - This function will be obsolete with CA UI standards
function ImgBtnBlur(lID)
{
   var btn = imgBtnArray[lID];
   if ( typeof btn.obj == "string" )
     btn.obj = document.getElementById(btn.obj);
   if ( btn.enabled )
      btn.obj.style.color = imgBtnData["enabled_color"];
   else
      btn.obj.style.color = imgBtnData["disabled_color"];
}

// ImgBtnMouseDown()
//   Change text color when button pressed
// CA UI standards - This function will be obsolete with CA UI standards
function ImgBtnMouseDown(lID)
{
   var btn = imgBtnArray[lID];
   if ( typeof btn == "object" && btn.enabled ) {
      btn.right.src = imgBtnData["right_down"];
      btn.left.src = imgBtnData["left_down"];
      if ( typeof btn.obj == "string" )
        btn.obj = document.getElementById(btn.obj);
      btn.obj.style.color = imgBtnData["down_color"];
      btn.obj.style.background = "url(" + imgBtnData["middle_down"] + ")";
   }
}

// ImgBtnChangeCaption()
//    IE only - relabel an active button
function ImgBtnChangeCaption( btnID, sNewCaption )
{
   if ( ! _browser.supportsLayers ) {
      for ( var i=0; i < imgBtnArray.length;i++ ) {
          var btn = imgBtnArray[i];
          if ( btn.id == btnID ) {
             if ( typeof btn.actKey == "string" &&
                  btn.actKey != " " &&
                  btn.actKey.length == 1 ) {
                if ( btn.actKey == fallbackHotkey &&
                     fallbackHotkey.length > 0 )
                  sNewCaption += " (<u>" + fallbackHotkey + "</b>)";
                else {
                  var posn = sNewCaption.indexOf(btn.actKey);
                  if ( posn == -1 )
                    posn = sNewCaption.indexOf(btn.actKey.toLowerCase());
                  //SDT 36411, new caption does not contain old actKey
                  if ( posn == -1)
                  {
                      var w = getActionKeyWindow();
                      var keyCode = btn.actKey.charCodeAt(0);
                      w.actionKey[keyCode] = void(0);
                      var actKey = sNewCaption.slice(0, 1);
                      //Note that we register the button with its position in the array (i) and not btnID
                      actKey=registerActionKey(actKey,sNewCaption,ImgBtnExecute,i);
                      btn.actKey = actKey;
                      posn = sNewCaption.indexOf(btn.actKey.toLowerCase());
                  }
                  if ( posn != -1 ) {
                    var text = "";
                    if ( posn != 0 )
                        text += sNewCaption.substr(0,posn);
                    text += "<U>" + sNewCaption.substr(posn,1) + "</U>";
                    if ( posn < sNewCaption.length - 1 )
                        text += sNewCaption.substr(posn+1,sNewCaption.length-posn-1);
                    sNewCaption = text;
                  }
                }
             }             
            
             if ( typeof btn.obj == "string" )
               btn.obj = document.getElementById(btn.obj);
             if ( typeof btn.innerButton == "string" )
               btn.innerButton = document.getElementById(btn.innerButton);
             btn.obj.innerHTML = createInnerBtnHtml(i, sNewCaption, btn.enabled, btn.actKey,"",btn.innerButton.tabIndex);             
             imgBtnArray[i].innerButton = "imgBtn" + i + "_button";                     
             break;
          }
      }
   }
}

// ImgBtnChangeHelp()
function ImgBtnChangeHelp( btnID, sNewHelp )
{
	for ( var i=0; i < imgBtnArray.length;i++ )
	{
		var btn = imgBtnArray[i];
		if ( btn.id == btnID )
		{
			var elem = document.getElementById("imgBtn" + String(i));
			if (typeof elem == "object" && typeof elem.title != "undefined")
				elem.title = sNewHelp;
			btn.help = sNewHelp;
			break;
		}
	}
}

// ImgBtnSetDefaultTabIndex
//   Set the default tab index for new buttons
function ImgBtnSetDefaultTabIndex(newTabIndex)
{
  imgBtnDefaultTabIndex = newTabIndex;
}

// ImgBtnDisabled()
//    Check button status by name
function ImgBtnDisabled(btnName) {
   for ( var i=0; i < imgBtnArray.length;i++ ) {
       var btn = imgBtnArray[i];
       if ( btn.id == btnName )
          return ! btn.enabled;
   }
   return true;
}

// ImgBtnEnableDeferred()
//    Enable all deferred buttons
function ImgBtnEnableDeferred()
{
   if ( typeof imgBtnDeferred == "object" ) {
      for ( var i = imgBtnDeferred.length-1; i >=0; i-- )
         ImgBtnEnableButton(imgBtnDeferred[i]);
      imgBtnDeferred = void(0);
   }
}

// ImgBtnEnableButton()
//    Enable a button
function ImgBtnEnableButton( btnName, btnEnable )
{
   if ( typeof btnEnable == "boolean" && ! btnEnable ) {
      ImgBtnDisableButton( btnName );
      return;
   }
   for ( var i=0; i < imgBtnArray.length;i++ ) {
       var btn = imgBtnArray[i];
       if ( btn.id == btnName ) {
          if ( typeof btn.obj == "string" )
            btn.obj = document.getElementById(btn.obj);
          try {
            btn.obj.style.cursor = "pointer"; 
            btn.obj.previousSibling.style.cursor = "pointer"; 
            btn.obj.nextSibling.style.cursor = "pointer"; 
          }
          catch(e) {}
          if ( typeof btn.innerButton == "string" )
            btn.innerButton = document.getElementById(btn.innerButton);
          btn.innerButton.style.cursor = "pointer";             
          btn.innerButton.style.color = imgBtnData["enabled_color"];
          btn.innerButton.disabled = false;
          btn.enabled = true;
          return;
       }
   }
}

// ImgBtnDisableButton()
//    Disable a button
function ImgBtnDisableButton( btnName )
{
   ImgBtnSupportDisabled();
   for ( var i=0; i < imgBtnArray.length;i++ ) {
       var btn = imgBtnArray[i];
       if ( btn.id == btnName ) {
          if ( typeof btn.obj == "string" )
            btn.obj = document.getElementById(btn.obj);
          try {
            btn.obj.style.cursor = "default"; 
            btn.obj.previousSibling.style.cursor = "default"; 
            btn.obj.nextSibling.style.cursor = "default"; 
          }
          catch(e) {}
          if ( typeof btn.innerButton == "string" )
            btn.innerButton = document.getElementById(btn.innerButton);
          btn.innerButton.style.cursor = "default";
          btn.innerButton.style.color = imgBtnData["disabled_color"];
          btn.innerButton.disabled = true;
          btn.enabled = false;
          return;
       }
   }
}

// ImgBtnHideButton()
//    Hide a button completely
function ImgBtnHideButton( btnName )
{
   for ( var i=0; i < imgBtnArray.length;i++ ) {
       var btn = imgBtnArray[i];
       if ( btn.id == btnName ) {
          var tbl = document.getElementById("imgBtn" + i);
          if ( tbl != null )
            tbl.style.display = "none";
          ImgBtnDisableButton( btnName );
          return;
       }
   }
}

// ImgBtnShowButton()
//    Show a previously hidden button
function ImgBtnShowButton( btnName )
{
   for ( var i=0; i < imgBtnArray.length;i++ ) {
       var btn = imgBtnArray[i];
       if ( btn.id == btnName ) {
          var tbl = document.getElementById("imgBtn" + i);
          if ( tbl != null )
            tbl.style.display = "";
          return;
       }
   }
}

// ImgBtnInExternalTable
//    Return:
//      0 - if not inside an extenal table
//      1 - if inside a detail form table
//      2 - if inside a search filter table
function ImgBtnInExternalTable()
{
  if ( typeof _dtl == "object" ) {
    if ( _dtl.tableStarted &&
         ! _dtl.doingLabelButton )
      return 1;
  }
  else if ( typeof __search_filter == "object" ) {
    if ( __search_filter.layerStarted )
      return 2;
  }
  return 0;
}

// ImgBtnNoHighlight
//    Suppress button highlighting when used as a default or cancel
function ImgBtnNoHighlight( btnName )
{
   for ( var i=0; i < imgBtnArray.length;i++ ) {
       var btn = imgBtnArray[i];
       if ( btn.id == btnName ) {
          btn.nohighlight = true;
          return;
       }
   }
}

// ImgBtnOnload()
//    Netscape-only function to reposition layers after a load
function ImgBtnOnload()
{
   if ( _browser.supportsLayers ) {
      if ( typeof imgBtnOnload == "function" )
         imgBtnOnload.apply();
      ImgBtnSupportDisabled();
   }
}

// ImgBtnOnresize()
//    Netscape-only function to reposition layers after a resize
function ImgBtnOnresize(e)
{
   if ( _browser.supportsLayers ) {
      imgButtonDisabledSupported = false;
      if ( typeof imgBtnOnresize == "function" )
         imgBtnOnresize.apply();
      ImgBtnSupportDisabled();
   }
}

// ImgBtnSupportDisabled
//    Netscape-only function to support the "disabled" feature
function ImgBtnSupportDisabled()
{
   if ( _browser.supportsLayers &&
        ! imgBtnDisabledSupported ) {
      for ( i = 0; i < imgBtnArray.length; i++ ) {
	     var btn = imgBtnArray[i];
         var width = 0;
         if ( typeof btn.obj == "string" )
           btn.obj = document.getElementById(btn.obj);
         if ( typeof btn.obj == "object" && typeof btn.end == "object" )
            width = btn.end.x - btn.obj.x - 10;
         if ( width <= 0 )
            width = 100;
         var s = "<TABLE><TR>";
         s += "<A CLASS=clsButtonDisabled>" + btn.caption + "</A>"
         s += "</TD></TR></TABLE>";
         btn.disable_layer = new Layer(width);
         btn.disable_layer.document.write(s);
         btn.disable_layer.document.close();
         btn.disable_layer.moveToAbsolute(btn.obj.x, btn.obj.y);
         if ( btn.enabled )
            btn.disable_layer.visibility = "hide";
         else
            btn.disable_layer.visibility = "show";
      }
   }
   imgBtnDisabledSupported = true;
}

// ImgBtnShow()
function ImgBtnShow( btnID )
{
	for ( var i=0; i < imgBtnArray.length;i++ )
	{
		var btn = imgBtnArray[i];
		if ( btn.id == btnID )
		{
			btn = document.getElementById("imgBtn" + String(i));
			if (typeof btn == "object") {
				recursively_set_display(btn, "");
                                adjScrollDivHeight();
                        }

			break;
		}
	}
}

// ImgBtnHide()
function ImgBtnHide( btnID )
{
	for ( var i=0; i < imgBtnArray.length;i++ )
	{
		var btn = imgBtnArray[i];
		if ( btn.id == btnID )
		{
			btn = document.getElementById("imgBtn" + String(i));
			if (typeof btn == "object") {
				recursively_set_display(btn, "none");
                                adjScrollDivHeight();
                        }

			break;
		}
	}
}

// ImgBtnRow()
//    Start a row of image buttons
function ImgBtnRow(padding,centered)
{
   switch ( ImgBtnInExternalTable() ) {
     case 1: detailEndTable(); break;
     case 2: __search_filter.endLayer(); break;
   }
   var text = "";
   imgBtnRowCentered = typeof centered != "boolean" || centered;
   if ( imgBtnRowCentered )
      text += "<CENTER>";
   imgBtnPadding = "";
   var width = "";
   if ( typeof padding == "number" )
      for ( ; padding > 0; padding-- )
         imgBtnPadding += "&nbsp;";
   else if ( typeof padding == "string" &&
             padding.match(/\d+%/) )
      width = " WIDTH='" + padding + "'";
   if ( _browser.supportsLayers && imgBtnPadding.length == 0 )
      imgBtnPadding = "&nbsp;";
   text += "<TABLE border=0" + width + "><TR>\n";
   docWrite(text);
   imgBtnRowActive = true;
   imgBtnRowCount = 0;
}

// ImgBtnEndRow()
//    End a row of image buttons
function ImgBtnEndRow()
{
   if ( imgBtnRowActive ) {
      var text = "</TR></TABLE>";
      if ( imgBtnRowCentered )
         text += "</CENTER>\n";
      docWrite(text);
      imgBtnRowActive = false;
   }
}

// ImgBtnDoCancel()
//    Press the cancel button if defined
function ImgBtnDoCancel()
{
   if ( typeof imgBtnCancel == "object" &&
        typeof imgBtnCancel.enabled == "boolean" &&
        imgBtnCancel.enabled ) {
       if ( typeof imgBtnCancel.obj == "string" )
         imgBtnCancel.obj = document.getElementById(imgBtnCancel.obj);
       if ( imgBtnCancel.obj != null )
          imgBtnCancel.obj.style.color = imgBtnData["down_color"];
       eval( imgBtnCancel.func );
       if ( imgBtnCancel.nohighlight &&
            ! _browser.supportsLayers &&
            typeof imgBtnCancel.obj == "object" )
          imgBtnCancel.obj.style.color = imgBtnData["enabled_color"];
       return true;
   }
   return false;
}

// ImgBtnKeydownHandler
//    Activate the current button when the user presses enter
//    NOTE: This function is obsolete in USP 6.0 (Waterbury)!
//          It has been replaced with uspKeydownHandler in window_manager.js
//          It remains here for backward compatibility with CI and HT.
function ImgBtnKeydownHandler(e)
{
    var f, i, j, len;
    // No need to do anything if neither default nor cancel is enabled

    if ( ( typeof imgBtnDefault.enabled != "boolean" ||
         ! imgBtnDefault.enabled ) &&
         ( typeof imgBtnCancel.enabled != "boolean" ||
         ! imgBtnCancel.enabled ) )
       return true;

    // Find the active element 

    var key_pressed;
    var active_element;

    if ( _browser.supportsLayers )
	 {
       	key_pressed = e.which;
       	active_element = e.target;
    	 }
    else if (_browser.isIE )
	 {
	     	e = window.event;
       	key_pressed = e.keyCode;
       	active_element = document.activeElement;
	 }
	 else              // Netscape 6.x
	 {
       	key_pressed = e.keyCode;
       	active_element = e.target;
    	 }

    // Execute the default button if the user pressed enter in a form element

    if ( key_pressed == 13 &&                   // ENTER key
         typeof active_element.type == "string" &&
         active_element.type != "textarea" &&  // ENTER in textarea is newline
	 typeof imgBtnDefault == "object" &&
	 typeof imgBtnDefault.enabled == "boolean" &&
	 imgBtnDefault.enabled ) {
       if ( typeof imgBtnDefault.obj == "string" )
         imgBtnDefault.obj = document.getElementById(imgBtnDefault.obj);
       len = document.forms.length;
       for ( i = 0; i < document.forms.length; i++ ) {
          f = document.forms[i];
          for ( j = 0; j < f.length; j++ )
             if ( f.elements[j] == active_element ) {
                if ( imgBtnDefault.obj != null )
                   imgBtnDefault.obj.style.color = imgBtnData["down_color"];
                if ( typeof active_element.onchange == "function" )
                   active_element.onchange();
                if ( _browser.supportsLayers &&
                     typeof active_element.onblur == "function" )
                   active_element.onblur();
                eval( imgBtnDefault.func );
                if ( imgBtnDefault.nohighlight &&
                     imgBtnDefault.obj != null )
                   imgBtnDefault.obj.style.color = imgBtnData["enabled_color"];
                return false;
             }
       }
       if (_browser.isIE && _browser.isMAC && 
	   typeof active_element.onclick == "function")
       {
	    active_element.onclick(); 
	    return false;
       } 
    }
    // Execute the cancel button if the user pressed ESC in a form element

    if ( key_pressed == 27 &&                   // ESC key
         typeof active_element.type == "string" &&
	 typeof imgBtnCancel == "object" &&
	 typeof imgBtnCancel.enabled == "boolean" &&
	 imgBtnCancel.enabled ) {
       len = document.forms.length;
       for ( i = 0; i < document.forms.length; i++ ) {
          f = document.forms[i];
          for ( j = 0; j < f.length; j++ )
             if ( f.elements[j] == active_element ) {
                ImgBtnDoCancel();
                return true;
             }
       }
    }

    return true;
}

// ImgBtnCreate()
//    Create and write an image button
function ImgBtnCreate( btnID, btnCaption, func, btnEnabled, btnWidth,
                       help, tabIndex )
{
    //alert("ImgBtnCreate(" + btnID + "," + btnCaption + "," + func + "," + btnEnabled + ")" );
    var lID;
    lID = imgBtnID;
    imgBtnID++;

    if ( typeof btnID != "string" || btnID.length == 0 ) {
       if ( lID < 10 )
          btnID = "btn00" + lID;
       else if ( lID < 100 )
          btnID = "btn0" + lID;
       else
          btnID = "btn" + lID;
    }

    if ( func.indexOf("(") == -1 )
	func = "upd_frame('" + func + "')";


    var initialval;
    var actKey;
    if (btnCaption.indexOf("[") != -1)
    {
        initialval = btnCaption.indexOf("[");
        var endval = btnCaption.lastIndexOf("]");
        var actkeylen = (endval-1)-initialval;
        actKey = btnCaption.substr(initialval+1,actkeylen);	
        btnCaption = btnCaption.substr(0,initialval);
    }
    
    if ( typeof help != "string" || help == "n/a" )
      help = "";
        
    if ( typeof actKey != "string" )
       actKey = "";
       
    if (actKey.indexOf("*")!=-1)
     {   
     	var foundindex = actKey.indexOf("*");
     	var keylength = actKey.length;
        actKey = actKey.substr(foundindex+1,keylength);
     }
     // Concanating the actionkey and caption so that characters  
     // not present in the label can also be registered for example
     // Change All btn in the edit in list registers Y as a the action key
     // and displays it as Change All(Y)
     // 2006.01.14: Commented out for fallback hotkey feature (SDT 57177)
       
     //var btnActCaption = actKey + btnCaption;        
	 actKey = registerActionKey( actKey, btnCaption, ImgBtnExecute, lID);
     if ( actKey.match(/^\s*$/) &&
          typeof ahdtop == "object" &&
          ( ahdtop.cfgUserType == "analyst" &&
            ! ahdtop.cstUsingScreenReader ) )
       actKey = fallbackHotkey;

    // Check for enable options
    //  "hide" - disable button and remove from display
    //  "defer" - disable button until page loaded 
    var hideButton = false;
    if ( typeof btnEnabled != "boolean" ) {
       if ( typeof btnEnabled == "string" ) {
          if ( btnEnabled == "hide" ) {
             btnEnabled = false;
             hideButton = true;
          }
          else if ( btnEnabled == "defer" ) {
             btnEnabled = false;
             if ( typeof imgBtnDeferred == "undefined" )
                imgBtnDeferred = new Array();
             imgBtnDeferred[imgBtnDeferred.length] = btnID;
          }
       }
       else if ( ( typeof btnEnabled != "boolean" &&
                   typeof btnEnabled != "number" ) ||
                 btnEnabled )
          btnEnabled = true;
       else
          btnEnabled = false;
    }

    var currentClass = "clsButtonEnabled";
    if ( ! btnEnabled ) {
       if ( ! _browser.supportsLayers ) {
          currentClass = "clsButtonDisabled";
       }
       else if ( typeof imgBtnOnload == "undefined" ) {
          imgBtnOnload = window.onload;
          imgBtnOnresize = window.onresize;
          window.onload = ImgBtnOnload;
          window.onresize = ImgBtnOnresize;
       }
    }
    
    var sTDWidth="";
    if (( typeof ahdtop == "object") &&	
	( typeof ahdtop.cfgSuppressImgButtonWidth == "string" ) &&
	( ahdtop.cfgSuppressImgButtonWidth == "1" )) {
	sTDWidth = " width=0";
    }
    else {
        if ( typeof btnWidth == "number"  && btnWidth > 30 )
            sTDWidth = " width=" + ( btnWidth - 28 );
        else if ( typeof btnWidth == "string" )
            sTDWidth = " width=" + btnWidth;
    }

    imgBtnArray[lID] = new Object();
    imgBtnArray[lID].id = btnID;
    imgBtnArray[lID].caption = btnCaption;
    imgBtnArray[lID].func = func;
    imgBtnArray[lID].enabled = btnEnabled;
    imgBtnArray[lID].nohighlight = false;
    imgBtnArray[lID].actKey = actKey;
    imgBtnArray[lID].help = help;
           
    var actions, actions_img, name;
    var text = "";
    if ( imgBtnRowActive ) {
       if ( imgBtnRowCount > 0 &&
            imgBtnPadding.length > 0 )
           text += "<TD>" + imgBtnPadding + "</TD>";
       text = "<TD ALIGN=center HEIGHT=21>\n";
       imgBtnRowCount++;
    }

    // CA UI standard buttons

    text += "<TABLE ID=imgBtn" + lID + " NAME=imgBtn" + lID;
    if ( hideButton )
       text += " style='display:none;'";
    text += " cellspacing=0 cellpadding=0 border=0><TR>\n";
    var action = " onClick='return ImgBtnExecute(" + lID + ");'";
    var style = " style='cursor:" + ( btnEnabled ? "pointer;" : "default;");
    text += "<TD VALIGN=middle" + action + style + "'><IMG SRC='" + 
    imgBtnData["left"]+"' ID='imgBtn"+lID+"_imgLeft' BORDER=0 alt=''"+"></TD>\n";
    text += "<TD VALIGN=middle" + sTDWidth + " ALIGN=CENTER" +
            " ID=imgBtn" + lID + "_caption CLASS=" + currentClass +
            action + style + "background: url(" + imgBtnData["middle"] +
            ");' NOWRAP>";
               
  	text += createInnerBtnHtml( lID, fmtLabelWithActkey(btnCaption,actKey),
                                btnEnabled, actKey, help, tabIndex );
                                              
    text += "</TD>\n<TD VALIGN=middle" + action + style + "'><IMG SRC='" +
             imgBtnData["right"]+"' ID='imgBtn"+lID +"_imgRight' BORDER=0 alt=''"+"></TD>\n";
    text += "</TR></TABLE>\n";
    if ( imgBtnRowActive )
       text += "</TD>";
    switch ( ImgBtnInExternalTable() ) {
       case 1: // In detail form table
         if (_dtl.edit)
           detailExternal(text);
         else
           //avoid the empty blue header in read-only mode
           detailExternal("",text);
         break;

       case 2: // In search filter table
         searchFilterExternal(text);
         break;

       default: // The normal case
         docWrite(text);    
         break;
	}
    imgBtnArray[lID].obj = "imgBtn" + lID + "_caption";
    imgBtnArray[lID].innerButton = "imgBtn" + lID + "_button";
    if ( actKey == fallbackHotkey && fallbackHotkey.length > 0 )
      registerFallbackKey("imgBtn" + lID + "_button");

    var ilen = document.images.length;
    imgBtnArray[lID].left = document.images[ilen-2];
    imgBtnArray[lID].right = document.images[ilen-1];

    // See if this is the default button

    if ( typeof default_button_name != "string" )
       default_button_name = "btndflt";
    if ( typeof cancel_button_name != "string" )
       cancel_button_name = "btncncl";
    if ( btnID == default_button_name &&
         typeof imgBtnDefault != "object" ) {
       imgBtnDefault = imgBtnArray[lID];
       if (_browser.isMAC)
       {
	    if ( typeof document.onkeypress != "function" )
		document.onkeypress = ImgBtnKeydownHandler;
       }
       else
       {
	    if ( typeof document.onkeydown != "function" )
		document.onkeydown = ImgBtnKeydownHandler;
       }
    }
    else if ( btnID == cancel_button_name &&
         typeof imgBtnCancel != "object" ) {
       imgBtnCancel = imgBtnArray[lID];
       if (_browser.isMAC)
       {
	    if ( typeof document.onkeypress != "function" )
		document.onkeypress = ImgBtnKeydownHandler;
       }
       else 
       {
	    if ( typeof document.onkeydown != "function" )
		document.onkeydown = ImgBtnKeydownHandler;
       }
    }

    return btnID;
}

// createInnerBtnHtml()
//	Build the HTML for the button
//	This was created into a function so that it can be used both in ImgBtnCreate
//  and ImgBtnChangeCaption
function createInnerBtnHtml(lID, caption, enabled, actKey, titleText, tabIndex ) 
{
    // The CA UI standard class for buttons is "buttons"
    var btnClass = "buttons";
    var disabledState = "";
    if (!enabled) {
        btnClass = "disabled_buttons"; /* extension to CA UI standards for disabled buttons */
        disabledState = "disabled";
    }
    
    var actions = " onFocus='style.color=\"#336699\";'" + 
                  " onBlur='style.color=\"black\";'";
    if ( typeof ahdtop != "object" ||
         typeof ahdtop.cstUsingScreenReader == "undefined" ||
         ( ahdtop.cfgUserType == "analyst" &&
           ! ahdtop.cstUsingScreenReader ) )
      actions += " onMouseOver='return ImgBtnMouseOver(" + lID + ");'" + 
                 " onMouseOut='window.status = window.defaultStatus;return true;'";
    //Add 'name' parameter for button to avoid CGI Script error that
    //might happen with Mozilla
    var buttonHTML = "";
    buttonHTML += "<button ID=imgBtn" + lID + "_button ";
    if ( typeof tabIndex == "number" )
      buttonHTML += " tabindex=" + tabIndex;
    else if ( typeof imgBtnDefaultTabIndex == "number" )
      buttonHTML += " tabindex=" + imgBtnDefaultTabIndex;

    // Mozilla runs the onClick handler when pressing return from 
    // inside any input field. Has to provide type to avoid this. 
    if (!_browser.isIE)
       buttonHTML += " type=button";

    // Set accesskey attribute when appropriate and the screen reader user
    // preference is set.  Access keys in messages 811-829 in the form
    // xxxx[k], where xxxx is a button caption, and k is the hotkey
    // to activate when that exact caption is found.
    
    try {
      if ( ahdtop.cstUsingScreenReader ) {
        if ( ahdframe.imgBtnScreenReaderHotkeys == null ) {
          ahdframe.imgBtnScreenReaderHotkeys = new Object();
          for ( var i = 811; i < 830; i++ ) {
            var m = ahdtop.__messages[i];
            if ( typeof m == "string" &&
                m.match(/^(.*)\[(\w)\]$/) )
              ahdframe.imgBtnScreenReaderHotkeys[RegExp.$1] = RegExp.$2;
          }
        }
        var hotkey = ahdframe.imgBtnScreenReaderHotkeys[caption];
        if ( typeof hotkey == "string" && hotkey.length == 1 ) {
          buttonHTML += " accesskey=" + hotkey;
          if ( typeof ahdtop.__messages[810] == "string" &&
               ahdtop.__messages[810].length > 0 )
            caption += msgtext(810,hotkey);
          // Delete the hotkey from the table so it does not get used again
          for ( var xCaption in ahdframe.imgBtnScreenReaderHotkeys ) {
            if ( hotkey == ahdframe.imgBtnScreenReaderHotkeys[xCaption] )
              ahdframe.imgBtnScreenReaderHotkeys[xCaption] = "";
          }
        }
      }
    }
    catch(e) {}

    if ( typeof titleText == "string" &&
         titleText.length > 0 ) {
       if ( titleText.match(/^([^\[]*)\[.*\]\s*$/) )
         titleText = RegExp.$1;
       if ( titleText != caption )
         buttonHTML += " title=\"" + titleText + "\"";
    }
    
    buttonHTML += " class='" + btnClass + "' " + disabledState + " " + actions + " name=imgBtn" + lID + "_button>";
    buttonHTML += caption;
    buttonHTML += "</button>"             
    
    return buttonHTML;
}

/* SDT 26462
   The name of this routine may be a little confusing if we're IE.
   IE doesn't support the DOM spec very well.  That means that
   it has no idea what a Node is (which is an interface, hence an object/
   function). So..  if the typeof Node != function, then we really don't
   recurse.  Besides, we're only having problems with Mozilla/Netscape7,
   not IE! */
function recursively_set_display(elem, display)
{
	if (typeof Node == "function")
	{
		if (typeof elem.firstChild == "object" && elem.firstChild != null)
			recursively_set_display(elem.firstChild, display);

		if (typeof elem.nextSibling == "object" && elem.nextSibling != null)
			recursively_set_display(elem.nextSibling, display);

		if (elem.nodeType == Node.ELEMENT_NODE &&
			typeof elem.style == "object" &&
			typeof elem.style.display == "string")
			elem.style.display = display;
	}
	else
		elem.style.display = display;
}

