/******************************************************************************

  File: tcmenu.js
  Author: Cathal Garvey
  Copyright WBT Systems, 1999-2006
  Contents:
  Version: 7.4.0
  Build: 123

******************************************************************************/
/*
   Date:          Author:  Comments:
    4th Oct 2001  eweb     #4814 Reorder top level content.
   30th Oct 2001  eweb     Edit-Managers.
   31st Oct 2001  eweb     More informative error message when can't add menu item.
   13th Nov 2001  eweb     #4713: Don't add courses to menu if user Edit units = No.
                                  Don't add import/export if user can't import/export.
   20th Nov 2001  eweb     Position in menu for Edit manager.
   28th Nov 2001  pmaher   Fix for bug no. 4829 - Incorrect menu item highlighted when
                           the import/export course menu is selected.
    8th Feb 2002  eweb     #5399 Controlling display of Database maintenance option.
                           Role variables based on TCUserRoles rather than printed user type string.
   23rd Aug 2002  des      Fix for browser version detection. Added Version5orAboveOfIE()
    7th Mar 2003  eweb     #???? If Toolbar not yet set up, wait 10 and try again.
    5th Nov 2003  eweb     #???? No longer has to be loaded after variables are set up.
    5th Dec 2003  eweb     Removed course navigation moved to tcnav.js
   10th Feb 2004  jbt      tidyup of code
   30th Mar 2004  jbt      #7302 TCArgs incorrectly set
    8th Jul 2004  eweb     #???? Menus don't work in course header frame.
   23rd Jul 2004  eweb     #7628 edit-class [List members] next loses tabs.
   24th Jan 2005  rmcn     #8630 Read Messages - adding folder causes a loss in tabs.
                           #8613 Discussion - send/delete message causes a loss in tabs.
   25th Jan 2005  rmcn     #8576 Courses list - tabs missing.
   26th Jan 2005  rmcn     #8682 Discussion - no tabs appear when delete, confirm delete or create messages.
    8th Feb 2005  eweb     #8670 Menus not working on IE 5.2 for the Mac.
    4th Mar 2005  rmcn     #8743 Search courses - navigates to courses tab rather than search.
    7th Apr 2005  nick     #8994 gave IFRAME a src (blank.html). Stop irritating popups in secure https environment.
   26th May 2005  eweb     #8147 Missing tabs for Centra schedule.
   31st May 2006  jbt      #10252 blank.html not shipped with cnr war
    3rd Jul 2006  eweb     #????? Fixing HTML, sizes in styles need units.
   20th Sep 2006  jbt      #7564  Drop-down menus - not brought to front of existing fields on form
*/

// stop total fall over if variables not set.
TCPathToTopClass = this.TCPathToTopClass ? this.TCPathToTopClass : "";

// TCLanguage - usenglish by default
TCLanguage = this.TCLanguage ? this.TCLanguage : "";
if( TCLanguage == "" ) TCLanguage="usenglish";

// Determine whether or not to show command box
TCShowCommandBox = this.TCShowCommandBox ? this.TCShowCommandBox : false;

// admin, instuctor or student?
TCUserType = this.TCUserType ? TCUserType : "";

// last issued command to TopClass
TCArgs = this.TCArgs ? TCArgs : "";

// var used to determine if TC5Style is being used - if this js file is included, then it is
this.TC5Style = true;

var TCPageTitle = "";

// set the next two vars to true for old style menus.
TCImagesForMenus = true;
TCExpandToShowPosition = true;

TCUserRoles = this.TCUserRoles ? TCUserRoles : 0;

// funcs to tell whether a user has these roles
function TCIsManager() { return TCUserRoles & 8; }
function TCIsAdmin() { return TCUserRoles & 4; }
function TCIsInstructor() { return TCUserRoles & 2; }
function TCIsStudent() { return TCUserRoles & 1; }

function TCIsCA() { return TCUserType.indexOf( "comp-CA" ) > -1 ; }

// last issued command to TopClass
TCUserRights = this.TCUserRights ? TCUserRights : 0;

function TCIsCompetenciesAdmin() { return (TCIsInstructor() && (TCUserRights & 1048576)) }  //0x100000 hex (bit 20)

// dir for non-localised TC5Style images
function getTC5ImagesSrc() { return this.TC5ImagesSrc ? this.TC5ImagesSrc : "http://207.179.167.196/ahip/icons/tc5style/common/"; }

// dir for localised TC5Style images
function getTC5MenuImagesSrc() { return this.TC5MenuImagesSrc ? this.TC5MenuImagesSrc : "http://207.179.167.196/ahip/icons/tc5style/" + TCLanguage + "/"; }

// default dimensions for parent menu image
TCDefPWidth = 120;
TCDefPHeight = 23;

// default dimensions for child menu image
TCDefCWidth = 113;
TCDefCHeight = 15;

function TCHelpUser(){
    if( TCIsStudent() ) return "student";
    if( TCIsInstructor() ) return "instructor";
    if( TCIsManager() ) return "manager";
    if( TCIsAdmin() ) return "admin";
    return "student";
  }

// To add a parent menu item use: TCAddToMenuBar( "identifier", w, h, "Alt string", 0, 0 );
// To add a sub-menu item use: TCAddToMenuBar( "identifier", w, h, "Alt string", "command link", "parent menu identifier" );

// jbt new menu stuff
TCActiveParent = this.TCActiveParent ? TCActiveParent : "";
TCActiveChild = this.TCActiveChild ? TCActiveChild : "";

MacIE = 0;
ns6   = 0;
if ( document.getElementById&&!document.all )       { ns6   = 1; }
if ( navigator.userAgent.indexOf("MSIE 5.23") > 0 ) { MacIE = 1; }


function SubItem( id, w, h, alt, command){
  this.id = id;
  this.width = w;
  this.height = h;
  this.alt = alt;
  this.command = command;
}


function Item( id, parent, w, h, alt, command){
  this.drawItemParent = drawItemParent;
  this.drawItemChildren = drawItemChildren;
  this.addToItem = addToItem;

  this.parentName = parent;

  this.id = id;
  this.width = w;
  this.height = h;
  this.alt = alt;
  this.command = command;

  this.children = new Array();

}

var commandClasses = new Object();

commandClasses['language-select'] = 'prefs';
commandClasses['plugins-qpi'] = 'prefs';
commandClasses['plugins-spi'] = 'prefs';
commandClasses['plugins-api'] = 'prefs';
commandClasses['plugins-cpi'] = 'prefs';
commandClasses['save-prefs-xml'] = 'prefs';
commandClasses['load-prefs-xml'] = 'prefs';
commandClasses['submit-user'] = 'edit-user';
commandClasses['submit-class'] = 'edit-class';
commandClasses['edit-template'] = 'prefs';
commandClasses['training-history-user'] = 'my-team';
commandClasses['learning-user'] = 'my-team';
commandClasses['skillgap-user'] = 'my-team';
commandClasses['edit-qpool'] = 'edit-ulm';
commandClasses['edit-question'] = 'edit-ulm';
commandClasses['edit-action'] = 'edit-ulm';
commandClasses['retrieve-home'] = 'learning-mine';
commandClasses['logout'] = 'login';
commandClasses['edit-group'] = 'display-group';
commandClasses['batch-user'] = 'edit-user';
commandClasses['create-message'] = 'create-message-role-tutor';
commandClasses['x-message-create'] = 'create-message-role-tutor';
commandClasses['import-course'] = 'edit-ulm';
commandClasses['export-course'] = 'edit-ulm';
commandClasses['edit-header-ulm'] = 'edit-ulm';
commandClasses['edit-rights-ulm'] = 'edit-ulm';
commandClasses['ulm-edit-template'] = 'edit-ulm';
commandClasses['edit-restriction'] = 'edit-ulm';
commandClasses['edit-rights-qpool'] = 'edit-ulm';

commandClasses['edit-object-75'] = 'edit-object-assigned26';
commandClasses['edit-object-76'] = 'edit-object-attained26';
commandClasses['x-message-retrieve'] = 'retrieve-list-in';
commandClasses['x-posting-retrieve'] = 'x-posting-list';
commandClasses['retrieve-list-submissions-mine'] = 'retrieve-list-submissions-mine';
commandClasses['retrieve-list-submissions-all'] = 'retrieve-list-submissions-unreviewed';
commandClasses['retrieve-list-submissions'] = 'retrieve-list-submissions-unreviewed';
commandClasses['plugin-report'] = 'retrieve-list-students';
commandClasses['plugin-centra-allevents'] = 'plugin-centra-curevents';
commandClasses['retrieve-profile'] = 'user-prefs';
commandClasses['edit-object-myassigns26'] = 'learning-mine';
commandClasses['edit-object-myattains26'] = 'learning-mine';
commandClasses['coursestobesigned'] = 'learning-mine';
commandClasses['edit-object-readonlyassigned68'] = 'edit-object-assigned68';
commandClasses['edit-object-readonly71'] = 'edit-object-71';
commandClasses['edit-object-readonly72'] = 'edit-object-72';
commandClasses['edit-object-readonly74'] = 'edit-object-74';
commandClasses['edit-object-readonly100'] = 'edit-object-100';
commandClasses['edit-object-readonly101'] = 'edit-object-101';
commandClasses['edit-object-readonly75'] = 'edit-object-75';
commandClasses['edit-object-readonly76'] = 'edit-object-76';
commandClasses['edit-object-iltenrollment26'] = 'edit-user';
commandClasses['review-submission'] = 'retrieve-list-students';
commandClasses['edit-object-28'] = 'edit-class';
commandClasses['groupskillprofile-user'] = 'learning-mine';

commandClasses['admin-object'] = 'admin-list';
commandClasses['admin-check'] = 'admin-list';
commandClasses['admin-delete'] = 'admin-list';
commandClasses['admin-object'] = 'admin-list';
commandClasses['admin-partmgr'] = 'admin-list';
commandClasses['admin-select'] = 'admin-list';
commandClasses['admin-swizzler'] = 'admin-list';

commandClasses['plugin-report'] = 'retrieve-list-students';
commandClasses['testeffect'] = 'retrieve-list-students';

commandClasses['edit-formdef'] = 'prefs';

commandClasses['edit-object-restrictions31'] = 'edit-ulm';
commandClasses['edit-object-33'] = 'edit-ulm';
commandClasses['edit-object-34'] = 'edit-ulm';
commandClasses['edit-object-42'] = 'edit-ulm';
commandClasses['edit-object-50'] = 'edit-ulm'; // msg action
commandClasses['edit-object-51'] = 'edit-ulm'; // add action
commandClasses['edit-object-56'] = 'edit-ulm';
commandClasses['edit-object-57'] = 'edit-ulm';
commandClasses['edit-object-63'] = 'edit-ulm';
commandClasses['edit-object-98'] = 'edit-ulm';
commandClasses['edit-object-99'] = 'edit-ulm';
commandClasses['edit-object-header33'] = 'edit-ulm';
commandClasses['edit-object-header34'] = 'edit-ulm';
commandClasses['edit-object-header42'] = 'edit-ulm';
commandClasses['x-announce-retrieve'] = 'x-announce-list';
commandClasses['x-announce-create'] = 'x-announce-list';
commandClasses['x-announce-transfer'] = 'x-announce-list';
commandClasses['x-announce-all-delete'] = 'x-announce-list';
commandClasses['x-announce-delete'] = 'x-announce-list';
commandClasses['x-announce-rights'] = 'x-announce-list';
commandClasses['x-announce-preview'] = 'x-announce-list';
commandClasses['x-announce-confirm-delete'] = 'x-announce-list';
commandClasses['x-announce-edit'] = 'x-announce-list';
commandClasses['x-announce-listedit-message'] = 'x-announce-list';
commandClasses['x-message-preview'] = 'create-message-role-tutor';
commandClasses['x-message-delete'] = 'retrieve-list-in';
commandClasses['x-message-edit'] = 'create-message-role-tutor';
commandClasses['retrieve-list-inedit-message'] = 'create-message-role-tutor';
commandClasses['x-message-confirm-delete'] = 'retrieve-list-in';

commandClasses['list-members'] = 'edit-class';
commandClasses['x-message-folder-create'] = 'retrieve-list-in';
commandClasses['x-posting-create'] = 'x-posting-list';
commandClasses['x-posting-delete'] = 'x-posting-list';
commandClasses['select-ulm'] = 'edit-ulm';
commandClasses['x-posting-confirm-delete'] = 'x-posting-list';
commandClasses['x-posting-create'] = 'x-posting-list';
commandClasses['partition-prefs'] = 'edit-partition';

var cmdList = new Object();

cmdList["Prefs"] = "utilities systemprefs";

function TCCmdMatch ( cmd ){
    var args = TCArgs.toLowerCase();
    if ( commandClasses[ args ] ){
      //alert("TCArgs is " + args + " commandClasses is " + commandClasses[args]);
      args = commandClasses[ args ];
    }
    cmd = cmd.toLowerCase();
    //alert ( args + " == " + cmd );
    var argsIndex = args.length;
    var cmdIndex = cmd.length;
    var match = true;

    while ( argsIndex >= 0 && cmdIndex >= 0 ){
      if ( args.charAt(argsIndex) != cmd.charAt(cmdIndex) )
        {
          return false;
        }
      argsIndex--;
      cmdIndex--;
    }
   return argsIndex == -1;
  }

function addToItem(id, w, h, alt, command, args){
  if ( this.parentName == "TCMenuButtons" && TCActiveChild == "" && TCArgs ) {

    // first find if any menu item is to be hightlighted
    if ( cmdList[TCArgs] ){
        var parts = new Array();
        parts = cmdList[TCArgs].split( " " );
        TCActiveParent = parts[0];
        TCActiveChild = parts[1];
    }else if ( TCCmdMatch ( command ) ){
      TCActiveParent = this.id;
      TCActiveChild = id;
    }
  }
  if ( TCPageTitle == "" && TCActiveChild == id ){
    if ( TCArgs == "Find-ULM")
      TCPageTitle = "Search";
    else
      TCPageTitle = alt;
  }
  if ( command && args ){
    command += args;
  }
  this.children[this.children.length] = new SubItem( id, w, h, alt, command );
}

function drawItemParent(iStr, menuName){


  if( !TCExpandToShowPosition  || this.id != TCActiveParent ) { // not selected
    if( this.command == 0 ) { // no sub menu
      // function drawParent( name, id, alt, href, hName )
      if( document.all || ns6 ) drawParent( menuName + "I" + iStr, this.id , this.alt, "javascript:this.toggleMenu( '" + menuName + "', '" + iStr + "' );", menuName + "A" + iStr ); // default - toggle popup menu
      else drawParent( menuName + "I" + iStr, this.id , this.alt, "javascript:this.toggleMenu( '" + menuName + "', '" + menuName + "M" + iStr + "' );", menuName + "A" + iStr ); // default - toggle popup menu
    }else{


      drawParent( menuName + "I" + iStr, this.id , this.alt, this.command, menuName + "A" + iStr );
    }
  }else {

    drawParent( menuName + "I" + iStr, this.id, this.alt, "" );
  }
}

function drawItemChildren(iStr, menuName, halign){

if( this.children.length > 0 ) {
  var commonProps = "border-width:1;position:top; display:none;";
  if( ( document.all || ns6 ) && ( !TCExpandToShowPosition || this.id != TCActiveParent) )
  {
      divName = menuName + "D" + iStr;
      document.write("<IFRAME ID=\"" + divName + "FRM\" src=\"javascript:false;\" scrolling=\"no\"  frameborder=\"0\" style=\"position:absolute; top:0px; left:0px; display:none;\">");
      document.write("</IFRAME>");

      if( !halign )
      {
        document.write( "<DIV STYLE=\"" + commonProps + "margin-left:0px;margin-top:0px;\" ID=\"" + divName + "\">" );
      }
      else
      {
        document.write( "<DIV STYLE=\"" + commonProps + "left:0px;margin-top:" + this.height + "px;z-Index:10\" ID=\"" + divName + "\">" );
      }

      document.write( "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\" >" );
  }
  else{ /**/
      document.write( "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\" >" ); /**/
  } /**/

  for( j = 0; j < this.children.length; j++ ) {
      document.write( "<tr><td width=15px></td><td>" );  /**/
      var jStr = "" + j;
      if( j < 10 ) jStr = "0" + jStr;

      var writeLink = ( ( ( document.all || ns6 ) || ( !document.all && TCExpandToShowPosition && this.id == TCActiveParent ) ) && this.children[j] && this.children[j].command && this.children[j].command != "" );
      if ( TCImagesForMenus )
          if( TCExpandToShowPosition && this.id == TCActiveParent ) document.write( "<IMG VSPACE=\"0\" HSPACE=\"0\" BORDER=\"0\" SRC=\"" + getTC5ImagesSrc() + "spacer.gif\" WIDTH=\"0\" HEIGHT=\"1\" ALT=\"\">" );
      if( ( document.all || ns6) && ( !TCExpandToShowPosition || this.id != TCActiveParent) ) document.write( "<TR><TD class=\"tophead\" width=15px></td><td>") ;
      if( writeLink ) {
          document.write( "<A class=\"subnav\" HREF=\"" + this.children[j].command + "\"" );
          if( this.id != TCActiveParent || ( TCExpandToShowPosition && this.id == TCActiveParent && this.children[j].command != TCActiveChild ) ) {
              if ( TCImagesForMenus && TCActiveChild != this.children[j].id) {
                //document.write( "ONMOUSEOVER=\"this.style.color='#0C6EFF'\" " );
                //document.write( "ONMOUSEOUT=\"this.style.color='#FFFFFF'\" " );
              } else {
                //document.write( "ONMOUSEOVER=\"this.style.color='#FFFFFF'\" " );
                //document.write( "ONMOUSEOUT=\"this.style.color='#FFFFFF'\" " );
              }
          }
          document.write( "STYLE=\"color:#FFFFFF;font-size:11;text-decoration:none;\">" );
      }
      if( ( document.all || ns6 ) || (TCExpandToShowPosition  && this.id == TCActiveParent) ) {
          if( this.id == TCActiveParent && this.children[j].id == TCActiveChild ) {
              if ( TCImagesForMenus ) {
                document.write( "<IMG BORDER=\"0\" SRC=\"http://207.179.167.196/ahip/icons/ahip/spacer.gif\" style='vertical-align:middle'>" );
                document.write( "<IMG VSPACE=\"0\" HSPACE=\"0\" BORDER=\"0\" SRC=\"" + getTC5ImagesSrc() + "spacer.gif\" WIDTH=\"5\" HEIGHT=\"1\" ALT=\"\">" );
                document.write( "<span style='color:#80B3CF;font-weight:bold;'>" + this.children[j].alt + "</span>" );
              } else {
                document.write( this.children[j].alt + "" );
              }
          } else {
            if ( TCImagesForMenus ) {
              document.write( "<IMG BORDER=\"0\" SRC=\"http://207.179.167.196/ahip/icons/ahip/spacer.gif\" style='vertical-align:middle'>" );
              document.write( "<IMG VSPACE=\"0\" HSPACE=\"0\" BORDER=\"0\" SRC=\"" + getTC5ImagesSrc() + "http://207.179.167.196/ahip/spacer.gif\" WIDTH=\"5\" HEIGHT=\"1\" ALT=\"\">" );
              //document.write( this.children[j].alt + "" );
              document.write( "<span style='color:#93B1C1;'>" + this.children[j].alt + "</span>" );
            } else {
              document.write( this.children[j].alt + "" );
            }
          }
      }
      if( writeLink ) document.write( "</A>" );
      if( ( document.all || ns6) && (TCExpandToShowPosition && this.id != TCActiveParent) )
      {
          document.write( "</TD></TR>");
      } else {
          document.write( "</tr></td>" );  /**/
      }


  }

  if( ( document.all || ns6) && (!TCExpandToShowPosition || this.id != TCActiveParent) )
  {
      document.write( "</TABLE>" );
  } else {
      document.write( "</table>" );  /**/
  }
  if( ( document.all || ns6) && (!TCExpandToShowPosition || this.id != TCActiveParent) )
  {
    document.write( "</DIV>");
  }

}
}

function Menu( n ){
  this.addItemToMenu = addItemToMenu;
  this.addSubItemToMenu = addSubItemToMenu;
  this.showMenu   = showMenu;
  this.closeAll  = closeAll;
  this.drawTheOptions = drawTheOptions;

  this.name = n;
  this.items = new Array();
}

function addItemToMenu(id, w, h, alt, command, args){


  if ( this.name == "TCMenuButtons" && TCActiveParent == "" && command != 0 && TCCmdMatch ( command ) ) {

    TCActiveParent = id;
  }
  if ( TCPageTitle == "" && command != 0 && TCActiveParent == id ){
    TCPageTitle = alt;
  }
  if ( command && args ){
    command += args;
  }
  this.items[this.items.length] = new Item( id, this.name, w, h, alt, command );
}

function addSubItemToMenu(parentID, id, w, h, alt, command, args){
  for( i = 0; i < this.items.length; i++ ) {
    if( this.items[i].id == parentID) {
      if( command && command.length > 1 && command.charAt(0) == '<' ) {
        command = TCPathToTopClass + command.substr(1);
      }
      this.items[i].addToItem( id, w, h, alt, command, args );
      break;
    }
  }
}

function showMenu( halign ) {
  if( !halign ) halign = 0; // default is to draw menobj vertically

  document.write( "<DIV id=\"" + this.name + "\" >");
  for( i = 0; i < this.items.length; i++ ){
    var iStr = "" + i;
    if ( i < 10 ) iStr = "0" + iStr;
    this.items[i].drawItemParent( iStr, this.name );

    //if( !halign ) document.write( "<BR>");
    this.items[i].drawItemChildren( iStr, this.name, halign );
    
    document.write( "<IMG BORDER=\"0\" SRC=\"" + getTC5ImagesSrc() + "line_brblue.gif\" WIDTH=\"170\">" );

  }
  if( !halign && TCShowCommandBox ) {
    var spaceHeight = 1;
    document.write( "<BR></TD></TR></TABLE><TABLE BORDER=\"0\" WIDTH=\"100%\" BACKGROUND=\"" + getTC5ImagesSrc() + "spacer.gif\" CELLPADDING=\"0\" CELLSPACING=\"0\">" ); // close menu bar table and open a new table for command box
    if( navigator.appName == "Netscape" ) spaceHeight = 200;
    document.write( "<TR><TD><IMG SRC=\"" + getTC5ImagesSrc() + "spacer.gif\" WIDTH=\"25\" HEIGHT=\"" + spaceHeight + "\" ALT=\"\" BORDER=\"0\" VSPACE=\"0\" HSPACE=\"0\"></TD><TD width=\"2000\"><FORM ONSUBMIT=\"return TCDoCommandBoxCommand();\" NAME=\"commandbox\">" );
    document.write( "<FONT SIZE=\"1\">Command</FONT><BR>" );
    document.write( "<INPUT SIZE=\"5\" TYPE=\"text\" NAME=\"cmd\">" );
    document.write( "<INPUT TYPE=\"IMAGE\" BORDER=\"0\" SRC=\"" + getTC5ImagesSrc() + "go.gif\" ONCLICK=\"javascript:return TCunsavedChangesCheck(this);\">" );
    document.write( "</FORM>" ); // TopClass closes the table (thinking it as the menubar table)
  }
  document.write( "</DIV>");
}
TCMenuNames = new Array( "TCMenuButtons", "TCTopMenuButtons" );

TCMenuButtons = new Menu ("TCMenuButtons");
TCTopMenuButtons = new Menu ("TCTopMenuButtons");

// if parentID specified the menu item will be added to the end of the submenu of that parent menu
// else a new parent menu will be created at the end
function TCAddToMenuBar( id, w, h, alt, command, parentID, menuObj, args ) {



  if( !menuObj ) {
    menuObj = TCMenuButtons;
  }
  // cgarvey 14.03.01 - check for user-type constraints on menu item
  if( id && id.length > 0 && alt && alt.length > 0 ) {
    if( id.charAt(0) == '<' ) {
      // usertype has been supplied ... check to see if we display menu or not
      var endPos = id.indexOf( '<', 1 );
      var userType = id.substr( 1, endPos - 1 );
      if( userType == "admin" && !TCIsAdmin() ) return;
      if( userType == "instructor" && !TCIsInstructor() ) return;
      if( userType == "manager" && !TCIsManager() ) return;
      if( userType == "student" && !TCIsStudent() ) return;
      id = id.substr( endPos + 1 );
    }
    if( parentID && parentID.length > 0 ) {
      menuObj.addSubItemToMenu(parentID, id, w, h, alt, command, args);
    }
    else {
      menuObj.addItemToMenu(id, w>0?w:TCDefPWidth, h>0?h:TCDefPHeight, alt, command, args);
    }
  }
  else if ( !(id && id.length > 0) ) {
    alert( "TopClass Error\n\nCould not add custom menu item [" + id + "," + parentID + "] - no id." );
  }
  else if ( !(alt && alt.length > 0) ) {
    alert( "TopClass Error\n\nCould not add custom menu item [" + id + "," + parentID + "] - no alt." );
  }
}

function drawParent( name, id, alt, href, hName ) {

  if( href ) {
    if ( TCImagesForMenus ) {
      document.write("<TABLE width=\"170\">");
      document.write("<TD style='width:20'>");
      document.write( "<IMG BORDER=\"0\" SRC=\"http://207.179.167.196/ahip/icons/ahip/blt_nav.gif\" id=\"" + 'img' + id + "\" style='vertical-align:middle;margin-top:3px;margin-bottom:3px; width:16px'" );
      document.write( "ONMOUSEOVER=\"toggleMenuImg( '" + id + "', 'on' );\" " );
      document.write( "ONMOUSEOUT=\"toggleMenuImg( '" + id + "', 'off' );\">" );
      document.write("</TD>");
      document.write("<TD>");
      document.write( "<A ID=\"" + hName + "\" HREF=\"" + href + "\" " );
      document.write( "STYLE=\"color:#FFFFFF;font-size:12;text-decoration:none;font-weight:bold;\"" );
      document.write( "ONMOUSEOVER=\"toggleMenuImg( '" + id + "', 'on' );\" " );
      document.write( "ONMOUSEOUT=\"toggleMenuImg( '" + id + "', 'off' );\">" );
      //document.write( "<IMG VSPACE=\"0\" HSPACE=\"0\" BORDER=\"0\" SRC=\"" + getTC5ImagesSrc() + "spacer.gif\" WIDTH=\"5\" HEIGHT=\"1\" ALT=\"\">");
    } else {
      document.write("<TABLE width=\"170\">");
      document.write("<TD>");
      document.write( "<A style=\"z-Index:99\" class=topHead ID=\"" + hName + "\" HREF=\"" + href + "\" " );
      document.write( "ONMOUSEOVER=\"this.style.color='#B10D0A'\" " );
      document.write( "ONMOUSEOUT=\"this.style.color='#000000'\" >" );
    }
  } else {
    // Active Parent Menu Item
    if ( TCImagesForMenus ) {
        // JS: Add link to close menu
        document.write("<TABLE width=\"170\">");
        document.write("<TD style='width:20'>");
        document.write( "<IMG BORDER=\"0\" SRC=\"http://207.179.167.196/ahip/icons/ahip/blt_nav.gif\" style='vertical-align:middle;margin-top:3px;margin-bottom:3px; width:16px;'" );
        document.write( "ONMOUSEOVER=\"toggleMenuImg( '" + id + "', 'on' );\" " );
        document.write( "ONMOUSEOUT=\"toggleMenuImg( '" + id + "', 'off' );\">" );
      	document.write("</TD>");
      	document.write("<TD>");
        document.write( "<A ID=\"" + hName + "\" HREF=\"" + href + "\" " );
        document.write( "STYLE=\"color:#FFFFFF;font-size:12;text-decoration:none;font-weight:bold\" " );
        document.write( "ONCLICK=\"CloseAllSubMenus( 'TCTopMenuButtons' );CloseAllSubMenus( 'TCMenuButtons' );return(false);\"" );
        document.write( "ONMOUSEOVER=\"toggleMenuImg( '" + id + "', 'on' );\" " );
        document.write( "ONMOUSEOUT=\"toggleMenuImg( '" + id + "', 'off' );\">" );
        document.write( "<IMG VSPACE=\"0\" HSPACE=\"0\" BORDER=\"0\" SRC=\"" + getTC5ImagesSrc() + "spacer.gif\" WIDTH=\"5\" HEIGHT=\"1\" ALT=\"\">" );

    }
  }
  if ( TCImagesForMenus ) {
    document.write( "<SPAN style='margin-top: 20px'>" + alt + "</SPAN>" );
  } else {
    document.write( alt );
  }
  if ( href ) {
    document.write( "</A>" );
  }else {
     if ( TCImagesForMenus ) {
       document.write( "</A>" );
    }
  }
  if ( !TCImagesForMenus ) {
    document.write( "&nbsp;&nbsp;&nbsp;&nbsp;" );
  }
  document.write("</TD>");
  document.write("</TABLE>");

}

function TCWriteMenuBar( menuObj, menuObjName, halign ) {
  menuObj.showMenu( halign );
}

function closeAll( docObj, theDivName ){
  var menuObjName = this.name;
  for( k = 0; k < this.items.length; k++ ) {
    var kStr = "" + k;
    if( k < 10 ) kStr = "0" + kStr;
    var divName = menuObjName + "D" + kStr;
    var menuDiv = document.all ? docObj[divName] : docObj.getElementById(divName);
    if( menuDiv && divName != theDivName && menuDiv.style && typeof( menuDiv.style.visibility ) != "undefined" )
    {
      menuDiv.style.visibility = "hidden";
      handleMenuSelect(docObj,divName,0);
    }
 }
}

function CloseAllSubMenus( menuObjName, divName ) {
  var docObj = ns6 ? document : this;
  if( top.frames && top.frames['TCtool'] && top.frames['TCtool'].document ){
    docObj = ns6 ? top.frames['TCtool'].document : top.frames['TCtool'];
  }
  if( top.frames && top.frames['TCtool'] ){
    menuObj = eval( "top.frames['TCtool']." + menuObjName );
  }else{
    menuObj = eval( menuObjName );
  }
  menuObj.closeAll( docObj, divName );
}

function TCDoTopMenu( link, id, w, h, x, y ) {
  // called by tthe top menu bar when logged out (i.e. Options)
  if( w || h ) {
    TCOpenPopup( link, id, w, h, x, y );
  }
  else {
    window.open( link );
  }
  // hide menubar again
  CloseAllSubMenus( "TCTopMenuButtons" );
}

function doTopMenu( ) {
  TCWriteMenuBar( TCTopMenuButtons, "TCTopMenuButtons", 1 );
}

function calculateSumTop(item){
  var totalOffset = 0;
  do{
    totalOffset += item.offsetTop;
    item = item.offsetParent
  } while (item != null);
  return totalOffset;
}

function calculateSumLeft(item){
  var totalOffset = 0;
  do{
    totalOffset += item.offsetLeft;
    item = item.offsetParent
  } while (item != null);
  return totalOffset;
}

function handleMenuSelect(docObj,divName,state)
  {
   if (ns6)
     {
       return;
     }
   if (MacIE)
     {
       return;
     }
   //theLink = document.all? docObj[menuObjName + "A" + menuNum] : docObj.getElementById( menuObjName + "A" + menuNum );
   //var DivRef = document.all? docObj[divName] : docObj.getElementById(divName );
   //var IfrRef = document.all? docObj[divName+"FRM"] : docObj.getElementById(divName+"FRM");
   var DivRef = docObj.document.getElementById(divName );
   var IfrRef = docObj.document.getElementById(divName+"FRM");
   if (docObj.document)
   {
   if (!DivRef || !IfrRef)
   {
   }
   else
   {
     if(state)
     {
      DivRef.style.display = "block";
      IfrRef.style.width = DivRef.offsetWidth;
      IfrRef.style.height = DivRef.offsetHeight -2;
      IfrRef.style.top = eval(DivRef.style.top.substr(0,DivRef.style.top.indexOf("p")) + "+25") + "px";
      IfrRef.style.left = DivRef.style.left;
      IfrRef.style.zIndex = DivRef.style.zIndex - 1;
      IfrRef.style.display = "block";
     }
     else
     {
      DivRef.style.display = "none";
      IfrRef.style.display = "none";
     }
   }
   }
  }

function toggleMenu( menuObjName, menuNum ) {
  var docObj = this;
  if ( ns6 ){ docObj = document; }
  divName = menuObjName + "D" + menuNum;

  if( top.frames && top.frames['TCtool'] ) {
    docObj = ns6 ? top.frames['TCtool'].document : top.frames['TCtool'];
  }

  if( TCMenuNames && TCMenuNames.length ) {
    for( i = 0; i < TCMenuNames.length; i ++ ) {
      CloseAllSubMenus( TCMenuNames[i], "" );
    }
  }
  theLink = document.all? docObj[menuObjName + "A" + menuNum] : docObj.getElementById( menuObjName + "A" + menuNum );
  theMenu = document.all? docObj[divName] : docObj.getElementById(divName);
  if( theMenu && theMenu.style && typeof( theMenu.style.visibility ) != "undefined" ) {

    if( theMenu.style.visibility == "hidden"  ){
      theMenu.style.left = calculateSumLeft(theLink) + "px";
      theMenu.style.top = calculateSumTop(theLink) + "px";
      theMenu.style.visibility = "visible";
      handleMenuSelect(docObj,divName,1);
    }
    else
    {
      theMenu.style.visibility = "hidden";
      handleMenuSelect(docObj,divName,0);
    }
  }
}



function toggleMenuImg( imgName, status, layer, x ) {
  try {
    if( status == "on" ) {
      document.getElementById( "img" + imgName ).src = "http://207.179.167.196/ahip/icons/ahip/blt_nav_over.gif"
      //document.images[imgName].src = eval ("document.images[imgName].src.substr( 0, document.images[imgName].src.length - 5 )") + "1.gif";
    }else if( status == "off" ) {
      document.getElementById( "img" + imgName ).src = "http://207.179.167.196/ahip/icons/ahip/blt_nav.gif"
    }
  } catch (e) {

  }
}

if ( document.all || ns6 ){
  document.onclick = function( ) {
    CloseAllSubMenus( "TCTopMenuButtons" );
    CloseAllSubMenus( "TCMenuButtons" );
  }
}

/*  Functions for creating setting and drawing the tab panes */

//Orsolya 16.01.2004


//var allTabs = new Array();
var tao = getTC5ImagesSrc() + 'tab_active_open.gif';
var tac = getTC5ImagesSrc() + 'tab_active_close.gif';
var tio = getTC5ImagesSrc() + 'tab_inactive_open.gif';
var tic = getTC5ImagesSrc() + 'tab_inactive_close.gif';
var imgOpen = tao;
var imgClose = tac;
var activeClass='TCTabActive';
var inactiveClass='TCTabInactive';
var tabActive;

/* Draws the tab panes and set the first tab pane to the active one */
function drawOptions() {
  TCMenuButtons.drawTheOptions()
}

function drawTheOptions() {
  var selected;
  for( i = 0; i < this.items.length; i++ ) {
    if( this.items[i].id == TCActiveParent) {
      selected = this.items[i];
      break;
    }
  }
  if ( selected ){
    document.write('<tr> \n');
    for (var i = 0; i< selected.children.length; i++){
      if ( selected.children[i].id == TCActiveChild ) {
        activeClass = 'TCTabActive';
        imgOpen=tao;
        imgClose=tac;
      } else {
        activeClass = 'TCTabInactive';
        imgOpen=tio;
        imgClose=tic;
      }
      document.write('<td align="right"><img src="'+imgOpen+'" name="o'+i+'" ></td>');
      document.write('<td id="tab'+i+'" class="'+activeClass+'" nowrap><a id="a'+i+'" class="'+activeClass+'" href="' + selected.children[i].command + '">'+ selected.children[i].alt +'</a></td>');
      document.write('<td><img src="'+imgClose+'" name="c'+i+'" ></td>');
      imgOpen=tio;
      imgClose=tic;
    }
    document.write('<td class="TCTabSpHolder">&nbsp; </td>');
    document.write('</tr> \n');

    activeClass='TCTabActive';
  }
}

function drawTableTitle() {
  if ( TCPageTitle != "" ) {
    document.write(TCPageTitle);
  }
  else if ( typeof(TCTitle) != "undefined" && TCTitle != "" ) {
    document.write(TCTitle);
  }
}
