/*
   File: topclass.js
   Author: eweb
   Copyright WBT Systems, 1999-2010
   Contents:
   Version: 8.0.0
   Build: 103
   This file contains the JavaScript functions that are used throughout TopClass
   This file must be placed in the TopClass webable directory as it is referenced
   from every TopClass page. Modification to this file is at the users own risk.
*/
/*
   Date:          Author:  Comments:
   22nd Nov 1999  jbt      Added function allowSubmit to count the number of submissions of a form
   19th May 2000  jbt      Removed the calls to the doOnLoad function
   19th May 2000  jbt      Added the functions getLinkForExtRef doToolbar and TCdoCheckForFramesOff
   19th May 2000  jbt      Added the TCContainingFrame variable
   19th May 2000  jbt      Removed the function checkRelURLs added TCFindFrame, TCFindTCmain, TCFindTCtool, TCFindTCcindex, TCFindTCcmain, TCReloadContentTCFrameset
    6th Jun 2000  jbt      Added the function TCClearSubmitCount, TCEqualObjects, TCParentExists, TConLoad, TCIsPopup, TCClickedSetLocation, TCClickedSetValue, TCPopupCancelled
    7th Jun 2000  jbt      Stoped the document loaded in the index frame from updating the toolbar
   19th Jun 2000  pmaher   Added CentraHomePg function which opens a new window with the URL of the users Centra Home Page
   15th Jun 2000  jbt      Added the function TCPreviewStyleSheet and TCSelectStyle
   30th Jun 2000  jbt      The toolbar is now drawn by toolbar.html
   30th Jun 2000  jbt      Added the function TCDoCommandBoxCommand() and changes some function names
    7th Jul 2000  jbt      Fixes to get authored frames to work
    4th Jul 2000  Nick     Fixed a bug in preview functions which wouldn't work in IE 5 and mozilla.
    7th Jul 2000  pmaher   Renamed CentraHomePg() to TCCentraHomePg()
   18th Jul 2000  jbt      Added a new function TCGoBack() to deal with bug #3082
   19th Jul 2000  jbt      Fix for bug #3133
   22nd Jul 2000  jbt      You shouold be able to use the browser back button to go back to the page you just loaded.
   24th Jan 2001  jbt      Changed TCCloseOperationsWizard( ) so that submits any changes on the groups page as it closes
    1st Feb 2001  nick     Added two new small redirect commands.
   31st Jan 2001  jma      Replaced lost function TCInsertCentraEventLink().
    9th Feb 2001  jbt      Added TCPostForm to fix a bugs for cathal.
    5th Feb 2001  jbt      Added the function TCLatestNewsUpdate
   12th Apr 2001  eweb     Check for database location.
   15th May 2001  cg       Fixed TCInsertCentraEventLink so that it works
   17th Jul 2001  nick     Fix for content saving. save link doesn't prompt for loss of data.
   26th Jul 2001  pmaher   Added function for Centra One integration. Modified existing
                           Centra function to take name of plugin as a parameter.
   26th Oct 2001  eweb     Cat and Reg menu items.
   21st Nov 2001  eweb     TCClickedSetValue() to be able to 'click' PostLink buttons.
   11th Dec 2001  eweb     #5111 Set page text when it is linked to an event.
   12th Dec 2001  eweb     #???? Popup about from top menu.
   16th Jan 2002  pmaher   Need to map help files for 'Retrieve-List-submissions-XX' to
                           'retrieve-list-submissions.html'
   28th Jan 2002  pmaher   Need to map help files for 'List-students-XX' to 'list-students.html'.
    6th Feb 2002  eweb     #5431 New function DoPercentChars(), used to encode args for setting location.
   14th Feb 2002  eweb     Undo adding space on to end of fieldname.
    6th Mar 2002  eweb     #5539 New function TCPostToList.
   30th May 2002  des      Added TCPopupExpires()
   19th Jun 2002  eweb     #???? Dynamically update status in index frame.
   25th Jul 2002  eweb     #???? Handling case where frame contains content from some other site.
   26th Aug 2002  eweb     #5831 Please wait for file to upload message.
   28th Aug 2002  eweb     #5840 EnrollAs list dynamically populated.
   18th Sep 2002  eweb     #???? When setting up Frameset leave Review-Submission as is rather than convert to Retrieve-Page.
    9th Oct 2002  eweb     #6090 Typo and bad spelling.
   18th Oct 2002  eweb     #6117 Mapping of TCArgs to help file.
   25th Oct 2002  pmaher   Merging fixes from 6.0.3 Branch #5545 - allow help file for course reordering to be displayed.
    7th Mar 2003  eweb     #???? Loading immediate parent rather than root course, Reloading course index.
   11th Mar 2003  eweb     #???? Not always setting up frames.
   12th Mar 2003  eweb     #???? Reloading toolbar frame with toolbar.html (authored framesets)
   10th Apr 2003  pmaher   Fix to allow Mobile to use multiple languages for context help.
   25th Apr 2003  nickm    #6525 Javascript errors on navigation when course templates disabled.
   27th Apr 2003  nickm    switched debugAlert() and debugAlert2() so the former is now the one to call.
                           Added frame name to output, so that when frames are on it is easier to see which calls come from
                           where.
   10th Jun 2003  eweb     #???? TCMailToInstructor always specifying inPopup.
   17th Jun 2003  eweb     #6692 Refresh index frame when content has been added.
   28th Jul 2003  eweb     Use Utilities-GroupTree template.
   29th Jul 2003  eweb     #6525 TCDynamicIndex is now set in the templates.
    3rd Sep 2003  eweb     #6919 New functions to support new list management.
   16th Jan 2004  osolymosi Functions for creating and drawing tab panes and setting their states
   20th Jan 2004  eweb     #???? Mac browser dosn't like frmes.item(i)
    4th Mar 2004  eweb     #7459 TcToolbarUsername changed to TCUserName
   23rd Apr 2004  eweb     #???? Removed obsolete preview in browser code.
   19th May 2004  eweb     #???? Assumed 1st arg to edit-object would be 2 chars.
    8th Jul 2004  eweb     #8035 TCDynamicIndex = true
                           #???? Submissions and frames.
   19th Nov 2004  eweb     #???? TCOnLoadContent() if the index frame is still loading.
                           #???? TC5FrameSetup() only load tccmain which will load tccindex.
   29th Nov 2004  eweb     #???? TCOnLoadContent() handle info class loading the index frame.
   23rd Dec 2004  eweb     #8578 Can't click button by name if more that one with that name.
    7th Apr 2005  eweb     #9003 Exercise directly assigned to class, appears in both index and content frames.
   10th May 2005  eweb     #9235 Popups broken, 'Go' button not resetting list_count.
                           #8969 Barber pole not displayed while file uploading.
   23rd May 2005  mlysaght #9123 Have browser specific "TCFitWindowToSize" functions for Windows IE & Netscape (FireFox),
                           a third function covers Other browsers.
                           TCFitWindowToSize_Netcape and TCFitWindowToSize_IE will never make the window smaller.
   31st May 2005  eweb     #9368 use encodeURI instead of escape.
   15th Jun 2005  pmaher   #9389 Replacing alert message with something a little less technical but possibly a bit more user friendly...(maybe).
   22nd Jun 2005  eweb     #6635, #8132 & #9134 Now use Content-Disposition to name file.
    4th Nov 2005  eweb     #9714 Find-ULM enhancements: multiple metadata.
    2nd Dec 2005  eweb     #9790 Unrecognised Command issued by TCOnLoadContent.
   30th Mar 2006  eweb     #9873 Popup: jump and search may contradict.
    8th May 2006  eweb     #10265 Remaining formdefs
    3rd Jul 2006  eweb     #????? Fixed PressButton().
   26th Sep 2006  eweb     #????? Tidy up html and javascript.
   13th Feb 2007  eweb     #10565 Search for course by title not using value from opening form.
   12th Nov 2007  eweb     #10705 TCIsPopup() error if topclass opened from elsewhere.
    4th Jul 2008  lmcgetti #????? New function CheckAll(), checks/unchecks all checkboxes in a given section
    4th Jul 2008  lmcgetti #????? New function VerifyURL()
   13th Aug 2008  eweb     #11035 DateSelectOnclick
   14th Aug 2008  jsheil   #11039 Added YUI functionality
    4th Sep 2008  eweb     #11039 Added new what was topclass8.js
    4th Sep 2008  eweb     #11039 TcDirectory() to locate topclass.
    5th Sep 2008  lisa     #????? getFormName() gets Struts Form name
   15th Sep 2008  lisa     #11023 New ILT Functionality
   16th Sep 2008  lisa     #11023 TCErrorInfo object used to hold multiple errors returned from java
   19th Sep 2008  lisa     #11023 New ILT Functionality
   19th Sep 2008  eweb     #10225 form names
    9th Oct 2008  eweb     #11079 Fixed TCAllowSubmit
   18th Sep 2008  jsheil   #11039 Fix to YUI functionality. Tab functionality.
   16th Oct 2008  eweb     #10225 search by name if by id return null
    6th Nov 2008  eweb     #11039 Fix to YUI functionality.
    6th Nov 2008  eweb     #11122 GroupTree Setting name or id field.
   12th Nov 2008  eweb     #11122 selectGroup can now click button
    2nd Dec 2008  eweb     #00007 Moved encode_args to topclass.js
    4th Dec 2008  jsheil   #11039 TCInfoTab() to write out information section
    4th Dec 2008  jsheil   #11039 addLoadListener() to dynamically call functions for window.onload
   10th Dec 2008  eweb     #11122 Object tree is single select.
   11th Dec 2008  jsheil   #11039 TCInfoTab() to draw Page Info Paceholders
   18th Dec 2008  jsheil   #11039 preventDefault() to stop default HTML element action replaceDOMNode() to overwrite node in DOM
   18th Dec 2008  lisa     #11039
   19th Dec 2008  lisa     #11122 Object tree is single select.
   23rd Dec 2008  jsheil   #11039 added assignPathToRootTooltips
    8th Jan 2009  eweb     #11070 Rationalisation of help files
    8th Jan 2009  eweb     #10225 Invalid html
    8th Jan 2009  jsheil   #11039 added TCSetIfrmFragmentHeight
   15th Jan 2009  jsheil   #11039 Dashboard iframes resize
   16th Jan 2009  eweb     #11039 Need bits from tcmenu.js
   22nd Jan 2009  jsheil   #11039 Added changeSortCriteria used for generic sorting.
   22nd Jan 2009  jsheil   #11039 Updated Panel Headers
   29th Jan 2009  sdeehan  #11039 UI Tidy Up
   29th Jan 2009  jsheil   #11039 Added TCGoToURL( sURL )
   29th Jan 2009  jsheil   #11039 Added TCHRefAsSubmit( sURL )
    5th Feb 2009  sdeehan  #11039 jsp tidy up
   10th Feb 2009  jsheil   #11039 Add function TCResetSearchFilter
   10th Feb 2009  jsheil   #11039 Add function TCSelectRows
   12th Feb 2009  jsheil   #11039 Modify function changeSortCriteria() to allow for sorting on modal popups
   12th Feb 2009  sdeehan  #11039 jsp tidy up
   19th Feb 2009  jsheil   #11039 TCClickedSetValue: add parameter displayLabel
   19th Feb 2009  jsheil   #11039 Added function TCInitFragment
   19th Feb 2009  jsheil   #11039 Added functions TCSetFormFieldLevelHelp, TCSetFormFieldTips
   26th Feb 2009  jsheil   #11039 Added String prototype functions for Trim(), StartsWith() and EndsWith()
   26th Feb 2009  jsheil   #11039 Added param 'TCPanelActionsHTML' to TCOpnePanel()
   26th Feb 2009  jsheil   #11039 Make input type button ReadONly in function TCReadOnly()
    5th Mar 2009  joconnor #11039 Cookie for tabs
   12th Mar 2009  lisa     #11420 Edit link on Schedule tab loading TopClass in Popup
   12th Mar 2009  jsheil   #11214, #11412 Don't Use Panel headers for YUI Modal screens as this causes IE error
   26th Mar 2009  jsheil   #11039 Added new parameter to TCOpenPanel Whether to use cookie value for panel expand / collapse [OPTIONAL]
   26th Mar 2009  jsheil   #11228 Comment out all Panel Help icons
   26th Mar 2009  jsheil   #11039 Handle ILT Sesson events for Conflict Details Popup
   26th Mar 2009  jsheil   #11367 Added new function TCConfirmSubmit for Object Deletion Confirmation
   26th Mar 2009  jsheil   #11039 Added new function TCPrintFormPopup for Training History Print
   26th Mar 2009  jsheil   #11262 Added new function TCFormatAsCurrency to handle currency values on Offering Details
   26th Mar 2009  joconnor #11484 fix verify url not opening in new window in FF
   26th Mar 2009  eweb     #11497 Don't use ModalDialog for select-ulm & select-course
   31st Mar 2009  jsheil   #11039 Don't dispLay form info, if form message div is present
   31st Mar 2009  jsheil   #11039 Remove obsolete function 'TCconfirmSelection'
   31st Mar 2009  jsheil   #11039 Added functions 'TCConfirmSelectionSubmit' && 'TCShowMessages' for server-side messaging
    1st Apr 2009  lisa     #00007 Removal of old code
    2nd Apr 2009  eweb     #11487 Red N not disappearing from course.
    2nd Apr 2009  lisa     #00007
    2nd Apr 2009  jsheil   #11039 added new function VerifyURLValue to topclass.js
    3rd Apr 2009  deesy    #11089 if open report on screen defined, use openwindow
                           #11560 added helper functions to format money
   21st Apr 2009  jsheil   #11208 fixes for xhtml validation errors
    2nd Jul 2009  jsheil   #11475 Extract colour information
    2nd Jul 2009  eweb     #11709 renamed the function attendees
   28th Jul 2009  jsheil   #11733 Change reverse order rolodex sort from <= to <
   27th Aug 2009  eweb     #11597 TCConfirmDeleteObjectSubmit
    8th Dec 2009  eweb     #12100 Close button in popup on session time out doesn't work for modal windows
   28th Jan 2010  jsheil   #11147 Fix for handling resize of PoupSelect in a Popup Window
   28th Jan 2010  eweb     #12154 Help files
   28th Jan 2010  eweb     #12044 MoveGroup button support
   11th Feb 2010  jsheil   #12175 Render function drawTCTabs() obsolete. Add new function TCDrawTabs(). Add new helper function TCAddMesssageInfo()
   18th Feb 2010  jsheil   #12175 Update to TCDrawTabs(). Call client-side Validation from JSP and Formdef forms. Added new functions TCAddMessageInfo, TCDeleteChecks, TCAddMesssageError.
   22nd Feb 2010  lisa     #12205 Implement a solution to easily add a tab in java
   25th Feb 2010  jsheil   #11039 Add YUI Drag and Drop functionality for User Preferences
    1st Mar 2010  eweb     #12150 Strings now in tcmessage_*.js
    8th Mar 2010  eweb     #11497 Don't do modal popup for popup-select-ulm
   18th Mar 2010  eweb     #12031 client side strings
*/
// Global Setting to use YAHOO YUI Components

var TCUseYUI = true;
var TCModalPopupVisible=false;
var TCModalDialogVisible=false;

/*
   Should set TcDir correctly in a template, also available as a ewebScript binding.
*/

// String Prototypes
String.prototype.trim = function(){return(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
String.prototype.startsWith = function(str){return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str){return (this.match(str+"$")==str)}

function TcDirectory()
{
  if ( typeof TcDir == 'undefined' ) {
    return "";
  }
  return TcDir;
}

if(TCUseYUI)
{
  document.write("<script type='text/javascript' src='"+ TcDirectory() +"tcyui.js'></script>");
}

var allTabs = new Array();
var arrTCErrorInfo = new Array();
var tableTitle;
var tabIndex = -1;
var reportWindow = null;

TCLanguage = "usenglish";

// the frame that TopClass is contained in
var TCContainingFrame = top;
// Nicholas Murphy 01-Jul-2003  A note. If this value is true, then old style navigation will NOT work.
// the index frame will NOT update.
// if this value is false, then the nice dynamic tree will not work.
// So we default to false, and if leave it up to the templates to set it to true.
var TCDynamicIndex = true;
//Nicholas Murphy 01-Jul-2003  end

//Nicholas Murphy 03-Apr-2003  hold the position in the indexFrame
var presentPosition=null;
function WM_netscapeCssFix()
  {
    if( document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight)
      {
        document.location = document.location;
      }
  }

function WM_netscapeCssFixCheckIn()
  {
    if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4))
      {
        if (typeof document.WM == 'undefined')
          {
            document.WM = new Object;
          }

        if (typeof document.WM.WM_scaleFont == 'undefined')
          {
            document.WM.WM_netscapeCssFix = new Object;
            document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
            document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
          }

        window.onresize = WM_netscapeCssFix;
      }
  }

WM_netscapeCssFixCheckIn();


function GetPageID (pageURL)
  {
       var cstring = pageURL.toLowerCase();
       if ((cstring.indexOf ("retrieve-page") == -1) &&
           (cstring.indexOf ("edit-ulm") == -1) &&
           (cstring.indexOf ("aicc-editulm") == -1) )
             return "";
       var start = cstring.lastIndexOf("-");
       if (start == -1) return "";
       start = start+1;
       var end = cstring.length;
       return cstring.substring(start,end);
  }

function AICCLink (pageURL)
{
   var frame = TCReturnFrameRef ("TCcmain");
   if (frame == null)
        frame = TCReturnFrameRef ("TCmain");
   if (frame != null) {
      var url = frame.location;
      var pageID = GetPageID (url.href);
      if (pageID != "")
        TCCommandLink("plugin-aicc-editulm-"+pageID, "TCcmain");
      else
        TCCommandLink("plugin-aicc-toolkit", "TCmain");
   }
   else
     TCCommandLink("plugin-aicc-toolkit", "TCmain");
}

function TCPostForm( formName, fieldName, onSubmit )
  {
    var theForm = document.getElementById(formName);
    if ( !theForm )
      {
        theForm = document.forms[formName];
      }
    if ( theForm )
      {
        if ( fieldName == "reset" )
          {
            theForm.reset();
          }
        else
          {
            if ( TCAllowSubmit( theForm ) )
              {
                if ( fieldName == "" )
                  {
                    if ( TCunsavedChangesCheck( theForm ) )
                      {
                        if ( formName == "Import-Course" )
                          {
                            if ( document.getElementById('ImportForm') && document.getElementById('WaitForUpload') )
                              {
                                document.getElementById('ImportForm').style.visibility = 'hidden';
                                document.getElementById('WaitForUpload').style.visibility = '';
                              }
                          }
                        theForm.submit();
                      }
                  }
                else
                  {
                    if ( theForm.elements[1] )
                      {
                        //theForm.elements[1].name = fieldName + " ";
                        theForm.elements[1].name = fieldName;
                        if ( TCunsavedChangesCheck( theForm ) )
                          {
                            if ( formName == "Import-Course" )
                              {
                                if ( document.getElementById('ImportForm') && document.getElementById('WaitForUpload') )
                                  {
                                    document.getElementById('ImportForm').style.visibility = 'hidden';
                                    document.getElementById('WaitForUpload').style.visibility = '';
                                  }
                              }
                            theForm.submit();
                          }
                      }
                  }
              }
          }
      }
  }

// Go back to the previous page
function TCGoBack()
  {
    var tcmain = TCFindTCmain();
    if ( tcmain == null )
      {
        TCContainingFrame.history.back();
      }
    else
      {
        var tccmain = TCFindTCcmain ( tcmain );
        if ( tccmain == null )
          {
            tcmain.history.back();
          }
        else
          {
            tccmain.history.back();
          }
      }
  }
function TCDoNothing()
  {
  }
// Select a different style sheet
function TCSelectStyle( style )
  {
    if (document.Style && document.Style.StyleSheets)
      {
        document.Style.StyleSheets.value = style;
      }
  }

function TCShowSelectMeta( )
  {
    document.writeln( "<select name=\"name\" onchange=\"TCSelectMeta( this )\">" );
    document.writeln( "<option value=\"\" selected></option>" );
    document.writeln( "<option value=\"title\" >Title</option>" );
    document.writeln( "<option value=\"identifier\" >Identifier</option>" );
    document.writeln( "<option value=\"description\" >Description</option>" );
    document.writeln( "<option value=\"keywords\" >Keywords</option>" );
    document.writeln( "<option value=\"version\" >Version</option>" );
    document.writeln( "<option value=\"status\" >Status</option>" );
    document.writeln( "<option value=\"source\" >Source</option>" );
    document.writeln( "<option value=\"location\" >Location</option>" );
    document.writeln( "<option value=\"difficulty\" >Difficulty</option>" );
    document.writeln( "<option value=\"purpose\" >Purpose</option>" );
    document.writeln( "</select>" );
  }

// Select a different meta data value
function TCSelectMeta( theSelect, field )
  {
    if ( theSelect.form && theSelect.form.elements[field] )
      {
        theSelect.form.elements[field].value = theSelect.options[theSelect.selectedIndex].value ;
      }
  }

function TCGetTLOID()
  {
    var pageid = null;
    if ( TCSeparateCourseFrame )
      {
        var tccmain = TCFindTCcmain(TCContainingFrame);
        if (tccmain != null)
          {
            return tccmain.TCULMID;
          }
      }
    else
      {
        var tcmain = TCFindTCmain();
        if ( tcmain )
          {
            return tcmain.TCULMID;
          }
      }
  }
function TCURLForMessage( )
  {
    var pathtoTC = null;
    var pageurl = null;
    if ( TCSeparateCourseFrame )
      {
        var tccmain = TCFindTCcmain(TCContainingFrame);
        if ( tccmain != null )
          {
            pathtoTC = tccmain.TCPathToTopClass;
            pageurl = tccmain.document.URL;
          }
      }
    else
      {
        var tcmain = TCFindTCmain();
        if ( tcmain )
          {
            pathtoTC = tcmain.TCPathToTopClass;
            pageurl = tcmain.document.URL;
          }
          // Nicholas Murphy 21-May-2003 - fix for bug 6576, Send Message with frames off. use javascript vars from present doc.
        else
          {
            if (TCPathToTopClass)
            {
              pathtoTC = TCPathToTopClass;
            }
            pageurl = document.URL;
          }
          // Nicholas Murphy 21-May-2003  end
      }
    return escape ( "topclass:?" + TCFriendlyURL( pageurl )  );
  }

function TCMailToInstructor( popup )
  {
    var pathtoTC = null;
    if ( TCSeparateCourseFrame )
      {
        var tccmain = TCFindTCcmain(TCContainingFrame);
        if (tccmain != null)
          {
            pathtoTC = tccmain.TCPathToTopClass;
          }
      }
    else
      {
        var tcmain = TCFindTCmain();
        if ( tcmain )
          {
            pathtoTC = tcmain.TCPathToTopClass;
          }
          // Nicholas Murphy 21-May-2003 - fix for bug 6576, Send Message with frames off. use javascript vars from present doc.
          else
          {
            pathtoTC = TCPathToTopClass;
          }
          //Nicholas Murphy 21-May-2003
      }
    if ( pathtoTC != null )
      {
        if (popup == true)
        {
        //Nicholas Murphy 06-Dec-2002  open in popup
        window.open(pathtoTC + 'inPopup-Create-Message-Role-Tutor-' + TCURLForMessage(),"debugWin","resizable=yes,resizable=1,toolbar=no,scrollbars=yes,width=800, height=400");
        }
        else
        {
          window.location = pathtoTC + 'Create-Message-Role-Tutor-' + TCURLForMessage();
        }
      }
  }

function TCPostToList( list )
  {
    var pathtoTC = null;
    if ( TCSeparateCourseFrame )
      {
        var tccmain = TCFindTCcmain(TCContainingFrame);
        if (tccmain != null)
          {
            pathtoTC = tccmain.TCPathToTopClass;
          }
      }
    else
      {
        var tcmain = TCFindTCmain();
        if ( tcmain )
          {
            pathtoTC = tcmain.TCPathToTopClass;
          }
      }
    if ( pathtoTC != null )
      {
        parent.location =  pathtoTC + 'X-Posting-Create-' + list + '-0D0-' + TCURLForMessage();
      }
  }

function TCLatestNewsUpdate( select )
  {
    for (var i = 0; i < select.length; i++)
      {
        if (select.options[i].selected == true )
          {
            var selected = "lang" + select.options[i].value;
            // TODO use id rather than name
            var oldEntry = eval("document." + select.form.name + "." + TCOptCurrSel );
            var newEntry = eval("document." + select.form.name + "." + selected );
            oldEntry.value = select.form.entry.value;
            select.form.entry.value = newEntry.value;
            TCOptCurrSel = selected;
            break;
          }
      }
  }


// called from the onSubmit method of every form used in TopClass
function TCAllowSubmit( theForm )
  {
    var kDoNothing    = 10;
    var kSilentRefusal = 11;
    var kAlert    = 12;
    var kChoice = 13;

    if ( TCSubmitOption == kDoNothing )
      {
        if ( TCUseYUI && TCModalPopup && TCAllowModalSubmit && TCModalPopupVisible) {
          return ( TCPostModalPopup( theForm ) );
        }
        else {
          return true;
        }
      }

    if ( theForm.submitcount.value == 0 )
      {
        if ( TCUseYUI && TCModalPopup && TCAllowModalSubmit  && TCModalPopupVisible) {
          theForm.submitcount.value++;
          return ( TCPostModalPopup( theForm ) );
        }
        else {
          theForm.submitcount.value++;
          return true;
        }
      }
    else
      {
        if ( TCSubmitOption == kSilentRefusal )
          {
            return false;
          }
        if ( TCSubmitOption == kAlert )
          {
            alert( strAlreadyDone );
            return false;
          }
        if ( TCSubmitOption == kChoice )
          {
            if ( TCUseYUI && TCModalPopup && TCAllowModalSubmit  && TCModalPopupVisible ) {
              return ( TCPostModalPopup( theForm ) );
            }
            else {
              return confirm( strAlreadyDoneConfirm );
            }
          }
      }
  }


// Called when each TopClass page loads to clear the submit count of each form on that page
function TCClearSubmitCount()
  {
    if ( document.forms )
      {
        for ( var i = 0; i < document.forms.length; i++)
          {
            if ( document.forms[i].submitcount )
              {
                document.forms[i].submitcount.value = 0;
              }
          }
      }
  }

function TCRecursiveGetFrameRef( winobj, frameName )
  {
    if ( winobj == null )
      {
        return null;
      }
    if ( winobj.name == frameName )
      {
        return winobj;
      }
    else
      {
        for ( var i = 0; i < winobj.frames.length; i++ )
          {
            var win = TCRecursiveGetFrameRef( winobj.frames[i], frameName );
            if ( win != null )
              {
                return win;
              }
          }
        return null;
      }
  }
function TCReturnFrameRef( frameName )
  {
    if ( frameName == "self" )
      {
        return self;
      }
    if ( frameName == "parent" )
      {
        return parent;
      }
    if ( frameName == "top" )
      {
        return top;
      }
    if ( frameName == "this" )
      {
        return this;
      }
    if ( frameName == "TCmain" )
      {
        if( this.TC5Style && TCSeparateCourseFrame) return TCContainingFrame;
        else return TCContainingFrame.TCmain;
      }
    if ( frameName == "TCtool" )
      {
        return TCContainingFrame.TCtool;
      }
    if ( frameName == "TCcmain" )
      {
        if( this.TC5Style && TCSeparateCourseFrame) return TCContainingFrame.TCcmain;
        else return TCContainingFrame.TCmain.TCcmain;
      }
    if ( frameName == "TCcindex" )
      {
        if( this.TC5Style && TCSeparateCourseFrame) return TCContainingFrame.TCmain.TCcindex;
        else return TCContainingFrame.TCmain.TCcindex;
      }
    if( this.TC5Style && TCSeparateCourseFrame) return TCRecursiveGetFrameRef( TCContainingFrame.TCcmain, frameName );
    return TCRecursiveGetFrameRef( TCContainingFrame.TCmain.TCcmain, frameName );
  }

function CommandLink( url, frameName )
  {
    TCCommandLink( url, frameName );
  }

function TCCommandLink( url, frameName )
  {
    if ( typeof(TCDBLOC) != "undefined" &&
         TCDBLOC != 0 &&
         url.toLowerCase().indexOf( "retrieve-page" ) != -1 )
      {
        url1 = url.split("-");
        if ( url1[2].indexOf( "D0" ) != -1 )
          {
            // page to retrieve already has a D0 - so change the 0 to the locID
            pageno = url1[2].split("D");
            if ( TCDBLOC != null )
              {
                pageno[1] = TCDBLOC;
              }
            url1[2] = pageno.join("D");
          }
         else
          {
            // third token is either just a page number or already has a non-zero DBID
            // if the former cat on the D + the locID
            // if the latter don't replace the DBID
            if ( url1[2].indexOf( "D" ) == -1 )
              {
                url1[2] += "D";
                url1[2] += TCDBLOC;
              }
          }
        //now put the array back together again
        url = url1.join("-");
      }
    if ( TCFramesAreOn )
      {
        var win = null;
        if ( frameName != null )
          {
            win = TCReturnFrameRef( frameName );
          }
        if ( win != null )
          {
            win.location = TCPathToTopClass + url;
          }
        else
          {
            //Can't find the frame so put content into TCmain.
            var win = TCFindTCmain();
            if ( win )
              {
                win.location = TCPathToTopClass + url;
              }
            else
              {
                TCContainingFrame.location = TCPathToTopClass + url;
              }
          }
      }
    else
      {
        //frames are off ignore the frame target
        //and stick the location in the top frame
        TCContainingFrame.location = TCPathToTopClass + url;
      }
  }

// if the frame named frameName can be found in startingFrame a reference
// to that frame is returned otherwise null is returned
function TCFindFrame ( startingFrame, frameName )
  {
    var index = 0;
    if (startingFrame == null)
      {
        return null
      }
    if (startingFrame.frames)
      {
        while ( index < startingFrame.frames.length )
          {
            try
              {
                if ( startingFrame.frames[index].name == frameName )
                  {
                    return startingFrame.frames[index];
                  }
              }
            catch ( error )
              {
                //alert( "Tried to access startingFrame[" + startingFrame.name + "].frames[" + index + "]" );
              }
            index++;
          }
       }

    // if we are still here it means that we have not found the frame
    return null;

  }

// returns the Topclass Main frame or null if it cannot find it
function TCFindTCmain ()
  {
    if( this.TC5Style && TCSeparateCourseFrame) {
        if( TCFramesAreOn && TCSeparateCourseFrame ) return TCContainingFrame;
        else return null;
    }
    else return TCFindFrame( TCContainingFrame, "TCmain" );
  }

// returns the Topclass Toolbar frame or null if it cannot find it
function TCFindTCtool ()
  {
    return TCFindFrame( TCContainingFrame, "TCtool" );
  }
function TCFindTCcindex (tcmain)
  {
    return TCFindFrame( tcmain, "TCcindex" );
  }
function TCFindTCcmain ( tcmain )
  {
    return TCFindFrame( tcmain, "TCcmain" );
  }

// this fuction is called to reload the content TCFrameset
// ie the frame set that contains TCcindex and TCcmain
// it is called if either of these frames cannot be found
function TCReloadContentTCFrameset ( url )
  {
    var tcmain = TCFindTCmain();
    if (tcmain == null)
      {
        // cgarvey 29May01 - revisit this!! is it always true?
        if( this.TCSeparateCourseFrame && this.TC5Style && this.TCdoFrameSetup )
          {
            tcmain = this;
          }
        else
          {
            return;
          }
      }
    var cmd = url;
    var pos = -1;
    var p = 0;
    while ( p < url.length )
      {
        if ( url.charAt(p) == "?" )
          {
            pos = p+1;
            break;
          }
            p++;
      }
    if ( pos > 0 )
      {
        cmd = url.substring(pos,url.length);
      }

    // reuse the history element of the curremt page
    // as we do not want to go back to this page
    if( this.TC5Style && this.TCSeparateCourseFrame ) {
        var curLoc = tcmain.location.pathname + tcmain.location.search;
        var indexFrmLoc = "";
        var mainFrmLoc = "";
        if( url.length ) {
            // cgarvey 11Jun01 - mainFrmLoc = url.substr( TCPathToTopClass.length );
            var tmpMainUrl = url.substr( url.indexOf( "?" ) + 1 );
            var startPoint = tmpMainUrl.toLowerCase().indexOf( "cntxt" );
            // cgarvey 15Jun01 - remove any Frame-Setup's that may be hangin around
            if( tmpMainUrl.toLowerCase().indexOf( "frame-setup", startPoint ) > startPoint ) startPoint = tmpMainUrl.toLowerCase().indexOf( "frame-setup", startPoint );
            if( tmpMainUrl.toLowerCase().indexOf( "conn", startPoint ) > startPoint ) startPoint = tmpMainUrl.toLowerCase().indexOf( "conn", startPoint );
            if( startPoint > -1 ) {
                var firstDash = tmpMainUrl.indexOf( "-", startPoint + 1 );
                var secondDash = tmpMainUrl.indexOf( "-", firstDash + 1 );
                mainFrmLoc = tmpMainUrl.substr( secondDash + 1 );
            }
            else {
                mainFrmLoc = tmpMainUrl;
            }
        }
        if( curLoc.length ) {
            // cgarvey 11Jun01 - mainFrmLoc = url.substr( TCPathToTopClass.length );
            var tmpIndUrl = curLoc.substr( curLoc.indexOf( "?" ) + 1 );
            var startPoint = tmpIndUrl.toLowerCase().indexOf( "cntxt" );
            // cgarvey 15Jun01 - remove any Frame-Setup's that may be hangin around
            if( tmpIndUrl.toLowerCase().indexOf( "frame-setup", startPoint ) > startPoint ) startPoint = tmpIndUrl.toLowerCase().indexOf( "frame-setup", startPoint );
            if( tmpIndUrl.toLowerCase().indexOf( "conn", startPoint ) > startPoint ) startPoint = tmpIndUrl.toLowerCase().indexOf( "conn", startPoint );
            if( startPoint > -1 ) {
                var firstDash = tmpIndUrl.indexOf( "-", startPoint + 1 );
                var secondDash = tmpIndUrl.indexOf( "-", firstDash + 1 );
                indexFrmLoc = tmpIndUrl.substr( secondDash + 1 );
            }
            else {
                indexFrmLoc = tmpIndUrl;
            }
            if( indexFrmLoc.toLowerCase() == "login" ) {
                // cgarvey 20Jun01 - we've got here cos we've had to log in to retrieve the requested TLO - we nee a diff way to find TLO ID
                // we can try and use TCReloadFrameURL
                if( TCReloadFrameURL ) {
                    indexFrmLoc = TCReloadFrameURL.substring( TCReloadFrameURL.toLowerCase().indexOf( "frame-setup" ) + 12 );
                }
            }
            if(  indexFrmLoc.toLowerCase() == "submit-class") {
              indexFrmLoc = mainFrmLoc;
            }

        }
        debugAlert("TCReloadContentTCFrameset","TC5FrameSetup(" + indexFrmLoc + "," + mainFrmLoc + ")" );
        TC5FrameSetup( indexFrmLoc, mainFrmLoc );
    }
    else {
        tcmain.location.replace( TCCmdSetupIndexFrame + "-" + cmd );
    }
  }
function TCEqualObjects ( url, path )
  {
    var urlIndex = url.length;
    var pathIndex = path.length;
    var match = true;

    while ( urlIndex >= 0 && pathIndex >= 0 )
      {
        if ( url.charAt(urlIndex) != path.charAt(pathIndex) )
          {
            match = false;
          }
        if ( url.charAt(urlIndex) == "-" )
          {
            return match;
          }
        urlIndex--;
        pathIndex--;
      }
     // still here
     return false;
  }

function TCParentExists ( parent )
  {
    if (parent.toLowerCase().indexOf("retrieve-page") == -1)
      {
        return true;
      }
    else
      {
        return !TCEqualObjects( parent, "-0D0" );
      }
  }

function ContainsLinkToULM( indexFrame, ulmid )
  {
  //Nicholas Murphy 03-Apr-2003  I've removed the "here" icons, so this call should always return true;
  return true;
  }

// called from the OnLoad method of every ULM that TopClass loads
function TCOnLoadContent( TCFramesetID, target, retrParent, myURL )
  {
    if ( typeof( TCRootID ) == "undefined" )
      {
        debugAlert("TCOnLoadContent","TCRootID is undefined");
      }
    else
      {
        debugAlert("TCOnLoadContent","TCRootID is " + TCRootID);
      }

    debugAlert("TCOnLoadContent", "retrParent is " + retrParent );
    debugAlert("TCOnLoadContent", "myURL is " + myURL  );
    debugAlert("TCOnLoadContent", "target is " + target );

    if ( retrParent.toLowerCase().indexOf( "retrieve-page-none" ) >= 0 )
      {
        debugAlert("TCOnLoadContent", "Parent is null so returning" );
        return;
      }

    // Get references to the TopClass frames
    var tcmain = TCFindTCmain();
    // TODO do something if tcmain is null at this point
    var tccindex = TCFindTCcindex( tcmain );
    var tccmain  = TCFindTCcmain( tcmain );

/*
    var elem = document.createElement("span");
    elem.className="frames";
    if (tccindex)
    {
      elem.innerText = "tccindex " + tccindex.title;
      tccindex.document.body.appendChild(elem);
    }
    else
    {
        alert("no tccindex");
    }

    if (tcmain)
    {
    elem.innerText = "tcmain "  + tcmain.title;
    tcmain.document.body.appendChild(elem);
    }
    else
    {
        alert("no tcmain");
    }

    if (tccmain)
    {
    elem.innerText = "tccmain " + tccmain.title;
    tccmain.document.body.appendChild(elem);
    }
    else
    {
        alert("no tccmain");
    }
*/

    // return if frames are off
    if ( !TCFramesAreOn )
      {
        debugAlert("TCOnLoadContent", "!TCFramesAreOn" );
        if ( TCArgs == "Review-Submission" && this.name == "TCcmain" )
          {
            debugAlert("TCOnLoadContent","this.name == \"TCcmain\"" );
            tccmain  = this;
            TCFramesAreOn = true;

            tcmain = TCFindTCmain();
            tccindex = TCFindTCcindex( tcmain );
          }
        else
          {
            debugAlert("TCOnLoadContent","TCFramesAreOn false so returning");
            return;
          }
      }
    else
      {
        debugAlert("TCOnLoadContent", "TCFramesAreOn" );
      }
    //Nicholas Murphy 13-Jun-2003  bug 6679. TCDynamicIndex causing warnings when previewing
    if (tccindex && tccindex.TCDynamicIndex)
    {
      debugAlert("TCOnLoadContent", "tccindex && tccindex.TCDynamicIndex" );
      //Nicholas Murphy 27-May-2003  bug 6630 - use the tcdynamicindex from main if necessary. Due to a bug 6630, with bookmarks (and explorer view) not showing the entire tree, but only the ulm and its immediate parent.
      if (tccindex.TCDynamicIndex == null && (tccmain.TCDynamicIndex!=null)|| (tccindex.TCDynamicIndex != tccmain.TCDynamicIndex))
      {
        tccindex.TCDynamicIndex=tccmain.TCDynamicIndex;
      }
    }
    else
    {
      debugAlert("TCOnLoadContent", "!tccindex || !tccindex.TCDynamicIndex" );
    }

    var TCContentFrame = tcmain;

    if ( TCSeparateCourseFrame ) // if we have a separate course frame on
      {
        debugAlert("TCOnLoadContent", "TCSeparateCourseFrame" );
        // check to see if the index frame should be updated
        if ( tccmain != null && tccindex != null ) //if both the TCcindex and TCcmain are loaded
          {
            // If there is a parent for the ULM and the index is inconsistant
            if ( TCParentExists( retrParent ) )
              {
                if ( tccindex.TCDynamicIndex && typeof( TCULMID ) != "undefined" && ContainsLinkToULM( tccindex, TCULMID ) )
                  {
                    if ( tccindex.TCULMID != TCRootID )
                      {
                        debugAlert("TCOnLoadContent","inconsistent");
                        top.TCDoNotReplace = true;
                        tccindex.location.replace( TCPathToTopClass + "Retrieve-Page-" + TCRootID );
                      }
                  }
                else if ( tccindex.TCDynamicIndex && typeof( TCULMID ) != "undefined" )
                  {
                    if ( !TCEqualObjects( "Retrieve-Page-" + TCRootID, tccindex.location.search ) )
                      {
                        debugAlert("TCOnLoadContent","retrieve-page");
                        // the the index page not to load the course info
                        top.TCDoNotReplace = true;
                        tccindex.location.replace( TCPathToTopClass + "Retrieve-Page-" + TCRootID );
                      }
                    else
                      {
                        debugAlert("TCOnLoadContent","failed TCEqualObjects");
                      }
                  }
                else if ( typeof( tccindex.TCDynamicIndex ) == "undefined" && tccmain.TCDynamicIndex )
                  {
                    if ( typeof(TCRootID) == "undefined" )
                      {
                        debugAlert("TCOnLoadContent","TCRootID is undefined");
                        if ( myURL.toLowerCase().indexOf( "info-class" ) >= 0 )
                          {
                            //debugAlert("TCOnLoadContent","tccindex.location.replace( retrParent )");
                            tccindex.location.replace( retrParent );
                          }
                        else
                          {
                            //debugAlert("TCOnLoadContent","retrParent is " + retrParent);
                            //debugAlert("TCOnLoadContent","myURL is " + myURL);
                          }
                      }
                    else if ( !TCEqualObjects( "Retrieve-Page-" + TCRootID, tccindex.location.search ) )
                      {
                        debugAlert("TCOnLoadContent","retrieve-page");
                        // the the index page not to load the course info
                        top.TCDoNotReplace = true;
                        tccindex.location.replace( TCPathToTopClass + "Retrieve-Page-" + TCRootID );
                      }
                    else
                      {
                        debugAlert("TCOnLoadContent","failed TCEqualObjects");
                      }
                  }
                else if ( !TCEqualObjects( retrParent, tccindex.location.search ) )
                  {
                    debugAlert("TCOnLoadContent","Buh? not TCEqualObjects("+retrParent+","+tccindex.location.search+")");
                    // the the index page not to load the course info
                    top.TCDoNotReplace = true;
                    tccindex.location.replace( retrParent );
                  }
              }
          }
        else
          {
            if ( this.TC5Style && this.TCSeparateCourseFrame )
              {
                var indexFrmLoc = "";
                var mainFrmLoc = "";
                if ( retrParent )
                  {
                    indexFrmLoc = retrParent;

                    var qmark = indexFrmLoc.indexOf("?");
                    if ( qmark >= 0 )
                      {
                        indexFrmLoc = indexFrmLoc.substr( qmark+1 );
                      }
                    args = indexFrmLoc.split( "-" );
                    i = 0;
                    if ( args[i].toLowerCase() == "conn" )
                      {
                        i += 2;
                      }
                    while ( args[i].toLowerCase() == "cntxt" )
                      {
                        i += 2;
                      }

                    indexFrmLoc = "";
                    for ( ; i < args.length; i++ )
                      {
                        if ( indexFrmLoc != "" )
                          {
                            indexFrmLoc = indexFrmLoc + "-";
                          }
                        indexFrmLoc = indexFrmLoc + args[i];
                      }

                    // if dynamic index then we want the root course rather than the parent course
                    if ( tccindex != null && tccindex.TCDynamicIndex && typeof( TCRootID ) != "undefined" )
                      {
                        var retrpage = "retrieve-page-";
                        var ulmidstart = indexFrmLoc.toLowerCase().indexOf( retrpage );
                        if ( ulmidstart >= 0 )
                          {
                            ulmidstart = ulmidstart + retrpage.length;
                            if ( indexFrmLoc.substr( ulmidstart ) != TCRootID )
                              {
                                indexFrmLoc = indexFrmLoc.substr( 0, ulmidstart ) + TCRootID;
                              }
                          }
                      }
                    // but what if we haven't set up the frames yet...
                    else if ( tccindex == null && TCDynamicIndex && typeof( TCRootID ) != "undefined" )
                      {
                        var retrpage = "retrieve-page-";
                        var ulmidstart = indexFrmLoc.toLowerCase().indexOf( retrpage );
                        if ( ulmidstart >= 0 )
                          {
                            ulmidstart = ulmidstart + retrpage.length;
                            if ( indexFrmLoc.substr( ulmidstart ) != TCRootID )
                              {
                                indexFrmLoc = indexFrmLoc.substr( 0, ulmidstart ) + TCRootID;
                                debugAlert("TCOnLoadContent","Setting indexFrmLoc to root ["+indexFrmLoc+"]");
                              }
                          }
                      }
                  }
                if ( myURL )
                  {
                    mainFrmLoc = myURL;
                    var qmark = mainFrmLoc.indexOf("?");
                    if ( qmark >= 0 )
                      {
                        mainFrmLoc = mainFrmLoc.substr( qmark+1 );
                      }
                    args = mainFrmLoc.split( "-" );
                    i = 0;
                    if ( args[i].toLowerCase() == "conn" )
                      {
                        i += 2;
                      }
                    while ( args[i].toLowerCase() == "cntxt" )
                      {
                        i += 2;
                      }

                    mainFrmLoc = "";
                    for ( ; i < args.length; i++ )
                      {
                        if ( mainFrmLoc != "" )
                          {
                            mainFrmLoc = mainFrmLoc + "-";
                          }
                        mainFrmLoc = mainFrmLoc + args[i];
                      }
                  }
                if ( TCArgs.indexOf( "Review-Submission" ) != -1 )
                  {
                    mainFrmLoc = TCArgs;
                  }
                debugAlert("TCOnLoadContent","TC5FrameSetup(" + indexFrmLoc + "," + mainFrmLoc + ")" );
                TC5FrameSetup( indexFrmLoc, mainFrmLoc );
              }
            else
              {
                //alert( "TCOnLoadContent: !this.TC5Style || !this.TCSeparateCourseFrame" );
                TCReloadContentTCFrameset( myURL );
              }
            return ;
          }

        if ( tcmain != null && tccmain != null) // if we have found tcmain and tccmain
          {
            TCContentFrame = tccmain;
          }
      }
    else
      {
        debugAlert("TCOnLoadContent", "!TCSeparateCourseFrame" );
      }
    if ( TCSeparateCourseFrame && tccindex.TCDynamicIndex )
      {
        debugAlert("TCOnLoadContent", "TCSeparateCourseFrame && tccindex.TCDynamicIndex" );
        if ( typeof( TCULMID ) != "undefined" && tccindex )
          {
            if ( TCOwnContext && tccindex.document.images['status'+TCULMID] )
              {
                if ( myURL && myURL.toLowerCase().indexOf( "info-course" ) >= 0 )
                  {
                  }
                else
                  {
                    tccindex.document.images['status'+TCULMID].src = 'icons/' + TCLanguage + '/ulmstatus1.gif';
                  }
              }
            if ( tccindex.TCCurrentUnit )
              {
                if ( tccindex.document.images['here' + tccindex.TCCurrentUnit] )
                 {
                   tccindex.document.images['here' + tccindex.TCCurrentUnit].src = 'icons/' + TCLanguage + '/nothere.gif';
                 }
              }
            if ( tccindex.document.images['here'+TCULMID] )
              {
                tccindex.document.images['here'+TCULMID].src = 'icons/' + TCLanguage + '/here.gif';
              }
            tccindex.TCCurrentUnit = TCULMID;
          }
      }
    else
      {
        debugAlert("TCOnLoadContent", "!TCSeparateCourseFrame || !tccindex.TCDynamicIndex" );
      }

    if ( TCSeparateCourseFrame && TCFrameSet != "" && target != "" )
      {
        debugAlert("TCOnLoadContent", "TCSeparateCourseFrame && TCFrameSet != \"\" && target != \"\"" );
        var targetFrame = TCFindFrame( TCContentFrame, target );

        // if there is no subframeid or the current subframesid has changed
        // or the the current authored TCFrameset is ok but the target frame cannot be found in it
        if ( (!top.subframeid || top.subframeid != TCFramesetID) || targetFrame == null  )
          {
            //alert ("setting up the frame set " + top.subframeid + TCFramesetID + target);
            if ( window.name != TCContentFrame.name && navigator.appName=="Netscape" )
              {
                TCContentFrame.location.replace( myURL );
                return;
              }
            top.subframeid = TCFramesetID;
            var frameset = TCFrameSet;

            // at this point the page is displayed in the wrong frame we do not want to
            // come back to here
            TCContentFrame.document.open( "text/html", "replace" );
            TCContentFrame.document.writeln( "<html><head>" );
            // we still need the javascript functions to be available for netscape
            if ( navigator.appName=="Netscape" )
              {
                TCContentFrame.document.write( '<script language="javascript" src="topclass.js"></script>');
              }

            TCContentFrame.document.writeln( "<script language=\"JavaScript\">" );
            TCContentFrame.document.writeln( "<!--" );
            TCContentFrame.document.writeln( "var TCContentFrame = \"" + target + "\";" );
            TCContentFrame.document.writeln( "//-->" );
            TCContentFrame.document.writeln( "<\/script>" );
            TCContentFrame.document.writeln( "<\/head>" );

            TCContentFrame.document.write( frameset );
            TCContentFrame.document.writeln( "<\/html>" );
            TCContentFrame.document.close();
            //alert ("Set up the Frame set");

            // try and find the target frame now
            targetFrame = TCFindFrame( TCContentFrame, target );
          }

        if ( targetFrame != null )
          {
            //alert("Target Frame " + location.href + "\nhref is " + myURL );
            if ( !TCEqualObjects ( myURL, targetFrame.location.href ) )
              {
                //alert("Target Frame " + targetFrame.name + "\nhref is " + myURL );
                targetFrame.location = myURL;
              }
            else
              {
                TCDoOnLoad();
              }
          }
      }
    else
      {
        debugAlert("TCOnLoadContent", "!TCSeparateCourseFrame || TCFrameSet == \"\" || target == \"\"" );
        TCDoOnLoad();
      }
  }

function TCIndexOfInaccessibleFrame( startingFrame )
  {
    var index = -1;
    var i = 0;
    while ( i < startingFrame.frames.length )
      {
        try
          {
            if ( startingFrame.frames[i].name == null )
              {
                return i;
              }
          }
        catch ( error )
          {
            //alert( "TCIndexOfInaccessibleFrame: error while accessing startingFrame[" + startingFrame.name + "].frames[" + index + "]" );
            index = i;
          }
        i++;
      }
    return index;
  }

// provide link to a ULM
function TCLinkForPage( frame, url )
  {
    debugAlert("TCLinkForPage","In here");
    var tcmain = TCFindTCmain();
    var tccindex = TCFindTCcindex( tcmain );
    if (tcmain == null)
      {
        if ( this.TC5Style && TCSeparateCourseFrame )
          {
            if ( !TCFramesAreOn )
              {
                // #???? set up frameset
                var qmark = url.indexOf( '?' );
                if ( qmark > 0 )
                  {
                    url = url.substr( qmark+1 );
                    // conn-
                    if ( url.substr( 0, 5 ).toLowerCase() == "conn-" )
                      {
                        url = url.substr( 5 );
                        var dash = url.indexOf( '-' );
                        if ( dash > 0 )
                          {
                            url = url.substr( dash+1 );
                          }
                      }
                  }
              //var newLoc = TCPathToTopClass + "Frame-Setup-IndFrame-Retrieve-Page-None-ContFrame-" + url;
                var newLoc = TCPathToTopClass + "Frame-Setup-ContFrame-" + url;
                debugAlert("TCLinkForPage","this.location.replace(" +  newLoc + ")");
                this.location.replace( newLoc );
                return;
              }
          }
        debugAlert("TCLinkForPage","TCContainingFrame.location =" +  url); // put the url in the content frame
        TCContainingFrame.location = url;
        return;
      }

    var TCContentFrame = tcmain;

    if ( TCSeparateCourseFrame  ) // if seperate course frame is on
      {
        debugAlert("TCLinkForPage","TCSeparateCourseFrame");
        var tccmain  = TCFindTCcmain( tcmain );
        if (tccmain == null)
          {
            //alert( "TCLinkForPage: tccmain == null" );
            var tccindex = TCFindTCcindex( tcmain );
            if ( tccindex != null )
              {
                // have index but not the content frame...
                // possibly caused by external content...
                // so get the index of the frame that we can't access
                var index = TCIndexOfInaccessibleFrame( tcmain );

                if ( index >= 0 && index < tcmain.frames.length )
                  {
                    debugAlert("TCLinkForPage","tcmain.frames[index].location.replace("+ url +")");
                    tcmain.frames[index].location.replace( url );
                    return;
                  }
              }
            // Reload the course TCFrameset
            debugAlert("TCLinkForPage","TCReloadContentTCFrameset( "+url+" )");
            TCReloadContentTCFrameset( url );
            return;
          }
        TCContentFrame = tccmain;
      }

    if ( TCSeparateCourseFrame && frame != "")  // if we need to put the url in another frame
      {
        var targetLocation = TCFindFrame(TCContentFrame, frame);
        if ( targetLocation == null )  // could not find the Target frame
          {
            //alert("Cannot find frame named " + frame );
            debugAlert("TCLinkForPage","TCContentFrame.location =" +  url); // put the url in the content frame
            TCContentFrame.location = url; // put the url in the content frame
            //Nicholas Murphy 13-Mar-2003  update the all-in-one tree
            if (tccindex.TCDynamicIndex)
            {
            objid = url.substring(eval(url.lastIndexOf("-")+"+1"),url.length);
            initialUpdateStatusGraphic(objid);
            }
            //Nicholas Murphy 13-Mar-2003  end
          }
        else  // put the url into the correct content location
          {
            debugAlert("TCLinkForPage","targetLocation.location =" +  url); // put the url in the content frame
            targetLocation.location = url;
          }
     }
    else // just put the url in the default conentent location
      {
        debugAlert("TCLinkForPage","TCContentFrame.location =" +  url); // put the url in the content frame
        TCContentFrame.location = url;
      }
  }

// Provides a link to a course folder
function TCLinkForCourse( url, pageurl )
  {
    debugAlert("TCLinkForCourse","in TCLinkForCourse");
    //Nicholas Murphy 13-Mar-2003  update the all-in-one tree
    var tcmain = TCFindTCmain();
    var tccindex = TCFindTCcindex( tcmain );
    var tccmain  = TCFindTCcmain( tcmain );
    if (tccindex != null && tccindex.TCDynamicIndex)
    {
      objid = pageurl.substring(eval(pageurl.lastIndexOf("-")+"+1"),pageurl.length);
      initialUpdateStatusGraphic(objid);
    }
    //Nicholas Murphy 13-Mar-2003  end

    if (tcmain == null)
      {
        // Reload
        TCContainingFrame.location = url;
        return;
      }

    // have found TCmain
    if ( TCSeparateCourseFrame ) // if seperate course frame is in use
      {

        if ( tccindex != null && tccmain != null )
          {
            // get course id.
            args = url.split( "-" );
            courseID = args[args.length-1];

            if ( tccindex.TCDynamicIndex && courseID && ContainsLinkToULM( tccindex, courseID ) )
              {
                debugAlert("TCLinkForCourse","tccmain.location.replace(" +  pageurl  +")");
                tccmain.location.replace( pageurl );
              }
            else
              {
                debugAlert("TCLinkForCourse","[1] url is " + url);
                tccindex.location.replace( url );
              }
          }
        else if ( tccindex != null )
          {
            debugAlert( "TCLinkForCourse","tccmain is null" );
            args = url.split( "-" );
            courseID = args[args.length-1];

            if ( tccindex.TCDynamicIndex && courseID && ContainsLinkToULM( tccindex, courseID ) )
              {
                var index = TCIndexOfInaccessibleFrame( tcmain );

                if ( index >= 0 && index < tcmain.frames.length )
                  {
                    debugAlert( "TCLinkForCourse","tcmain.frames[index].location.replace( " + pageurl +")");
                    tcmain.frames[index].location.replace( pageurl );
                  }
                else
                  {
                    TCReloadContentTCFrameset( pageurl );
                  }
              }
            else
              {
                debugAlert("TCLinkForCourse","[2] url is " + url);
                tccindex.location.replace( url );
              }
            //tccindex.location.replace( url );
          }
        else  /// we couldn't find either TCcmain or TCcindex
          {
            //alert ( "TCLinkForCourse: tccmain and tccindex are both null" );
            debugAlert("TCLinkForCourse","TCReloadContentTCFrameset( "+ pageurl +")");
            TCReloadContentTCFrameset( pageurl );
          }
      }
    else // seperate course frame is not in use
      {
        // no separate course frame so just use TCmain
        //top.loadedtarget = '';
        debugAlert("TCLinkForCourse","[3] url is " + url);
        tcmain.location = url;
      }
  }

// put curl in TCcmain
// This function is called from the onLoad method of the document loaded
// into the TCcindex page
function TCLoadContent( curl )
  {
    debugAlert("TCLoadContent",curl);
    var tcmain = TCFindTCmain();
    var replacing = true;
    if ( TCSeparateCourseFrame )
      {
        var tccmain = TCFindTCcmain(tcmain);
        if ( tccmain != null )
          {
            if ( top.TCDoNotReplace )
              {
                replacing = false;
              }
            if ( !TCEqualObjects( curl,  tccmain.location.search ) && !top.TCDoNotReplace )
              {
                debugAlert("TCLoadContent","tccmain.location="+curl);
                tccmain.location = curl;
              }
            top.TCDoNotReplace = false;
          }
        else
          {
            debugAlert( "TCLoadContent","tccmain == null" );
            var tccindex = TCFindTCcindex( tcmain );
            if ( tccindex != null )
              {
                // have index but not the content frame...
                // possibly caused by external content...
                // so get the index of the frame that we can't access
                var index = TCIndexOfInaccessibleFrame( tcmain );

                if ( index >= 0 && index < tcmain.frames.length )
                  {
                    tcmain.frames[index].location = curl;
                  }
                else
                  {
                    TCReloadContentTCFrameset( curl );
                  }
              }
            else
              {
                TCReloadContentTCFrameset( curl );
              }
          }
        var tccindex = TCFindTCcindex( tcmain );
        if ( typeof( TCULMID ) != "undefined" && tccindex && TCDynamicIndex )
          {
            if ( TCOwnContext && tccindex.document.images['status'+TCULMID] )
              {
                // Don't update status for courses.
                //tccindex.document.images['status'+TCULMID].src = 'icons/' + TCLanguage + '/ulmstatus1.gif';
              }
            if ( tccindex.TCCurrentUnit )
              {
                if ( tccindex.document.images['here' + tccindex.TCCurrentUnit] )
                  {
                    tccindex.document.images['here' + tccindex.TCCurrentUnit].src = 'icons/' + TCLanguage + '/nothere.gif';
                  }
              }
            tccindex.TCCurrentUnit = TCULMID;
            if ( !replacing )
              {
                tccindex.TCCurrentUnit = tccmain.TCULMID;
              }
            if ( tccindex.document.images['here'+tccindex.TCCurrentUnit] )
              {
                tccindex.document.images['here'+tccindex.TCCurrentUnit].src = 'icons/' + TCLanguage + '/here.gif';
              }
          }
      }
  }

// This function is used by TopClass player to display media objects
// that are contained in potentially multiple NeoAccess databases
function TCGetLinkForExtRef( cmdobjid )
  {
    var cmd = TCPathToTopClass + cmdobjid + 'D';
    if ( TCDBLOC != null )
      {
        cmd += TCDBLOC;
      }
    else
      {
        cmd += '0';
      }
    return cmd;
  }

function TCFriendlyURL( theURL )
  {
    var questionLocation = theURL.indexOf( "?" )
    if ( questionLocation != -1)
      {
        var connectionLocation = theURL.toLowerCase().indexOf( "conn-", questionLocation );
        if ( connectionLocation == -1 ) // no connid
          {
            return theURL.substr( questionLocation + 1 );
          }
        else
          {
            var start = theURL.toLowerCase().indexOf( "-", (connectionLocation + 6) );
            if ( start != -1 )
              {
                return theURL.substr( start + 1 );
              }
            else
              {
                return theURL.substr( connectionLocation + 6 )
              }
          }
     }
   return theURL;
  }

// called from the onLoad method of every page that TopClass Loads
function TCOnLoad()
  {
    TCClearSubmitCount();
    if ( typeof( TCFramesAreOn ) == "undefined" )
      {
        return;
      }
    if ( TCFramesAreOn && document.URL.toLowerCase().indexOf("create-message") != -1)
      {
        if ( document.forms )
          {
            for ( var i = 0; i < document.forms.length; i++)
              {
                if ( document.forms[i].url )
                  {
                    var toolbar = TCFindTCtool();
                    if ( toolbar != null && toolbar.document && toolbar.TCLastPage )
                      {
                        document.forms[i].url.value = "topclass:?" + TCFriendlyURL( toolbar.TCLastPage );
                      }
                  }
              }
          }
       }
    if ( TCFramesAreOn && !TCIsPopup() && ( window && window.name != "TCcindex") && !this.TCInFrameSetup )
      {
        TCDoToolbar();
      }
  }

// This function is called from the onLoad method of every document
// that is loaded in TopClass when frames are on
// It essentially just redraws the Toolbar
function TCDoToolbar()
  {
    if( this.TC5Style && this.TCSeparateCourseFrame ) {
        // cgarvey 30May01 - setting up toolbar (which is the course header frame in tc5style)
        // is handled elsewhere so return
      return;
    }

    var toolbar = TCFindTCtool();
    // if we are allowed to do a frame-setup
    if ( this.TCdoFrameSetup )
      {
        // check to see if these values have been definded
        if ( top.frameformat != null && top.pixelwidth != null && top.username != null )
          {
            // if anything has changed reload
            if ( top.frameformat != TCtoolbarFrameFormat ||
              top.pixelwidth  != TCtoolbarPixelwidth ||
              top.impl        != TCtoolbarImpl ||
              top.username    != TCUserName )
              {
                TCContainingFrame.location = TCReloadFrameURL;
                return;
              }
          }
      }
    // as long as toolbar is defined
    if ( toolbar != null )
      {
        if( typeof( this.TC5Style ) == "undefined!" || !this.TC5Style )
          {
            // don't reload toolbar unless it is not tc5style.
            if( typeof( toolbar.TC5Style ) == "undefined!" || !toolbar.TC5Style )
              {
                toolbar.location.replace( "toolbar.html" );
              }
          }
      }
    else
      {
        // only reload if the previous operation was not a post
        if ( !TCWasPosted && typeof (TCReloadFrameURL) != "undefined" )
          {
            TCContainingFrame.location.replace(TCReloadFrameURL);
          }
      }
    }


function TCDoCommandBoxCommand()
  {
    if ( document.commandbox && document.commandbox.cmd )
      {
        if ( document.commandbox.cmd.value )
          {
            TCCommandLink( document.commandbox.cmd.value, "TCmain");
          }
      }
    return false;
  }

// If the main or the toolbar frame can be found
// reload the TopClass frameset this is used to ensure that
// when frames are turned off TopClass will remove TCmain and TCtool
// if they exist called from every document when frames are turned off
function TCDoCheckForFramesOff(url)
  {
    if ( typeof( TCIgnoreFrames ) == "undefined" || !TCIgnoreFrames )
      {
        if ( TCFindTCmain() != null || TCFindTCtool() != null)
          {
            TCContainingFrame.location= url;
          }
      }
  }

// returns true if the window in question is a popup window
function TCIsPopup()
  {
    try
      {
        if ( top.opener )
          {
            // the window has been opened using the open() method
            //Nicholas Murphy 27-May-2005  this check was incorrect as the previous values were undefined.
            //if (document.location.path == top.opener.path)
            if (document.location.pathname == top.opener.location.pathname)
              {
                return true;
              }
            else
              {
                //alert ("path mismatch");
                return false;
              }
          }
        else
          {
            return false;
          }
      }
    catch ( e )
      {
        return false;
      }
  }

function TCOpenOperationsWizard( group, operation, join )
  {
    var command = TCPathToTopClass +"popup-edit-operation-" + group + "-" + operation + "-";
    if ( join )
      {
        command += "join";
      }
    else
      {
        command += "leave";
      }
    var win = window.open( command, "", "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=" + 550 + ",height=" + 600 + ",posx=" + 5 + ",posy=" + 5 );
    win.focus();
  }

function TCCloseOperationsWizard( )
  {
    if ( top.opener && top.opener.location )
      {
        top.opener.location.reload();
      }
    top.close();
  }

function TCLoadOpTools( type )
  {
    parent.frames['TCOpTools'].location.replace("optools" + type + ".html");
  }
// functions used by the select windows


function TCOpenPopup( command, title, width, height, posx, posy, TCModalParams )
{
    if ( TCUseYUI && command.indexOf("Popup-Select") != -1 &&
         command.indexOf("Popup-Select-ULM" ) == -1 &&
         command.indexOf("Popup-Select-Course") == -1 ) {
      // Select Object Popups Only
      TCOpenModalPopup( command, title, width, height, posx, posy, TCModalParams );
    }
    else if ( 0 && TCUseYUI && ( command.indexOf("Object-Tree") != -1 ) ) {
      // Select Object Popups Only
      TCOpenModalPopup( command, title, width, height, posx, posy, TCModalParams );
    }
    else {
      var win = window.open( command, title, "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=" + width + ",height=" + height + ",posx=" + posx + ",posy=" + posy );
      win.focus();
    }
  }

function ExecuteNotify( id )
  {
    var win = window.open( TCPathToTopClass + "popup-execute-" + id, "execute", "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=300,height=450,posx=5,posy=5" );
    win.focus();
  }

function TCClickedSetLocationBox( field, button )
  {

    if ( document.select && document.select.username )
      {
        if ( document.select.username.value )
          {
            TCClickedSetLocation( document.select.username.value, field, button );
          }
      }
    return false;
  }

function TCClickedSetValueBox( field, button )
  {

    if ( document.select && document.select.username )
      {
        if ( document.select.username.value )
          {
            TCClickedSetValue( document.select.username.value, field, button );
          }
      }
    return false;
  }

function TCClickedSetLocation( value, field, button )
  {
    var TCPopupType;
    if ( TCUseYUI && TCModalPopup ) {
      TCPopupType = window;
    }
    else {
      TCPopupType = window.opener
      TCAllowModalSubmit = true;
    }
    if ( window && TCPopupType && TCPopupType.document )
      {
        TCPopupType.location = TCCommandPrefix + '-' + DoPercentChars( value );
        if ( TCUseYUI && TCModalPopup ) {
          TCGetModalPopup().hide();
        }
        else {
          close();
        }
      }
    else
      {
        if ( TCUseYUI && TCModalPopup ) {
          TCGetModalPopup().hide();
        }
        else {
          close();
        }
      }
    return false;
  }

function TCSetLocation( value )
  {
    var TCPopupType;
    if ( TCUseYUI && TCModalPopup ) {
      TCPopupType = window;
    }
    else {
      TCPopupType = window.opener
      TCAllowModalSubmit = true;
    }
    if ( window && TCPopupType )
      {
        TCPopupType.location = TCCommandPrefix + '-' + value;
        if ( TCUseYUI && TCModalPopup ) {
          TCGetModalPopup().hide();
        }
        else {
          close();
        }
      }
    else
      {
        if ( TCUseYUI && TCModalPopup ) {
          TCGetModalPopup().hide();
        }
        else {
          close();
        }
      }
  }
function TCClickedSetLocationCommand( value, command )
  {
    var TCPopupType;
    if ( TCUseYUI && TCModalPopup ) {
      TCPopupType = window;
    }
    else {
      TCPopupType = window.opener
      TCAllowModalSubmit = true;
    }
    if ( window && TCPopupType && TCPopupType.document )
      {
        TCPopupType.location = command + '-' + DoPercentChars( value );
        if ( TCUseYUI && TCModalPopup ) {
          TCGetModalPopup().hide();
        }
        else {
          close();
        }
      }
    else
      {
        if ( TCUseYUI && TCModalPopup ) {
          TCGetModalPopup().hide();
        }
        else {
          close();
        }
      }
  }

function TCClickedSetValue(value,field,button,displayLabel)
  {
    //alert( "TCClickedSetValue("+value+","+field+","+button+")" );
    var TCPopupType;
    if ( TCUseYUI && TCModalPopup ) {
      TCPopupType = window;

//exclusion becuase this screen has 2 select buttons without a submit      
      if(document.location.href.indexOf("esdMergeStudents")>0)
        TCAllowModalSubmit = true;
      else
        TCAllowModalSubmit = false;
    }
    else {
      TCPopupType = window.opener;
      TCAllowModalSubmit = true;
    }

    if ( !window ||
         !TCPopupType ||
         !TCPopupType.document ||
         !TCPopupType.document.forms ||
         TCPopupType.document.forms.length == 0 ||
         !TCPopupType.document.forms[0] )
      {
        alert( "TCClickedSetValue: Can't find form" );
        close();
        return;
      }
    var found = false;

    for ( j = 0; j < TCPopupType.document.forms.length; j++ )
      {
        for ( i = 0; i < TCPopupType.document.forms[j].elements.length; i++ )
          {
            if ( TCPopupType.document.forms[j].elements[i].name == field )
              {
                found = true;
                break;
              }
          }
        if( found ) break;
      }
    if ( !found )
      {
        alert( "TCClickedSetValue: Can't find form element [" + field + "]" );
        close();
        return;
      }

    if ( found )
      {
        //alert( "Found form element [" + field + "]" );
      }

    if ( !(TCPopup_SingleSelect()) && (TCPopupType.document.forms[j].elements[field].value != "") )
      {
        //alert( "multi select and not empty so appending "+value );
        TCPopupType.document.forms[j].elements[field].value = TCPopupType.document.forms[j].elements[field].value + "," + value;
      }
    else
      {
        //alert( "setting value item named "+field+" to "+value );
        TCPopupType.document.forms[j].elements[field].value = value;
      }
      if ( displayLabel && displayLabel != "" ) {
        if ( TCPopupType.document.getElementById(field + "_displayLabel") ) {
          TCPopupType.document.getElementById(field + "_displayLabel").innerHTML = displayLabel;
        } else {
          //alert( 'no displayLabel found' );
        }
      }
    if ( button && button != '*' )
      {
        //alert( "need to press button"+button );
        if ( TCPopupType.document.forms[j].elements[button] )
          {
            //Nicholas Murphy 09-Mar-2004  remove the backlink
            bklink = TCPopupType.document.getElementById("backlink");
            if ( bklink )
              {
                bklink.value=" ";
              }
            // eweb 20th Dec 2004
            // Problem we might have two buttons with the same name...
            // in which case the following will fail.
            // but how do we know that they are all buttons?
            // or that they are buttons on the form
            buttons = TCPopupType.document.forms[j].elements[button];
            if ( buttons == null )
              {
              }
            else if ( typeof(buttons.click) != "undefined" )
              {
                buttons.click();
              }
            else if ( typeof(buttons[0].click) != "undefined" )
              {
                buttons[0].click();
              }

            //TCPopupType.document.forms[j].elements[button].click();
          }
        else
          {
            if ( TCPopupType.document.forms[j].elements['TC'] )
              {
                TCPopupType.document.forms[j].elements['TC'].name = button;
                //Nicholas Murphy 09-Mar-2004  remove the backlink
                bklink = TCPopupType.document.getElementById("backlink");
                if (bklink)
                {
                  bklink.value=" ";
                }
                TCPopupType.document.forms[j].submit();
              }
          }
      }
      if ( TCUseYUI && TCModalPopup ) {
        TCGetModalPopup().hide();
      }
      else {
        close();
      }
  }

function TcPopupSubmit()
  {
    // need to go through each check box and add it to a comma separated string and
    // then pass the whole lot back...
    var results = "";
    //theForm = document.forms['search'];
    theForm = document.getElementById('search');
    theField = theForm.elements['field'].value;
    theButton = theForm.elements['button'].value;

    if ( document.getElementsByName('list_selection') )
      {
        results = document.getElementsByName('list_selection')[0].value;
      }
    else
      {
        results = "";
      }

/*
    for ( i = 0; i < theForm.elements.length; i++ )
      {
        element = theForm.elements[i];
        if ( element && element.checked )
          {
            if ( results == '' )
              {
                results = element.value;
              }
            else
              {
                results = results + ',' + element.value;
              }
          }
      }
*/
    //alert( results );
    //alert( TcSetValueFunc );
    if ( TcSetValueFunc == "TCClickedSetValue" )
      {
        TCClickedSetValue( results, theField, theButton );
      }
    else if ( TcSetValueFunc == "TCClickedSetLocation" )
      {
        TCClickedSetLocation( results, theButton );
      }
    else
      {
        TCClickedSetValue( results, theField, theButton );
      }
  }

function TCPopupBlured()
  {
    if (navigator.appName=="Netscape")
      {
        window.focus();
      }
  }

function TCPopupCancelled()
  {
    if ( TCUseYUI && TCModalPopup )
      {
        TCGetModalPopup().hide();
      }
    else
      {
        top.close();
      }
  }
function TCNavSearch( off )
  {
    if ( document.search && document.search.offset )
      {
        document.search.offset.value = off;
        document.search.submit();
      }
  }

function TCunsavedChangesCheck(obj)
  {
    if (this.document.edit_form && this.document.edit_form.markchanges)
      {
        if (this.document.edit_form.markchanges.value != "1")
          {
            return true;
          }
        else
        if (obj)
          {
            // Nicholas Murphy, Tuesday, 17 July 2001 added obj.elements[1].name, as we're sending a form, not
            // a button. elements[1] holds the name of the anchor that submitted.
            if ((obj.name == "submit") || (obj.elements[1].name == "submit"))
              {
                return true;
              }
            else
              {
                if (confirm(unsavedChangesStr))
                  {
                    this.document.edit_form.markchanges.value="";
                    return true;
                  }
                else
                  {
                    return false;
                  }
              }
          }
      }
    else
      {
        return true;
      }
  }

function TCMarkChanges()
  {
    if (this.document.edit_form && this.document.edit_form.markchanges)
      {
        this.document.edit_form.markchanges.value = "1";
        if (navigator.appName=="Netscape")
          {
            if (this.document.layers['appear'])
              {
                this.document.layers['appear'].visibility="visible";
              }
          }
        else
          {
            if (this.document.all['appear'])
              {
                this.document.all['appear'].style.visibility="visible";
              }
          }
      }
  }

// This function opens a new window and calls the topclass plugin with the -homepg qualifier.
// The plugin function determines the URL of the users Centra homepage and redirects this url
// to the new window just opened.
// The name of the plugin must be passes in as a parameter since the user can have multiple
// versions of the same dll loaded at any given time
function TCCentraHomePg( pluginName )
  {
    var location = TCPathToTopClass + "-plugin-" + pluginName + "-homepg";
    var newWindow = window.open( location, "Centra" );
  }

function TCresetjavascript()
  {
    if (this.document.edit_form && this.document.edit_form.markchanges)
    {
        this.document.edit_form.markchanges.value = "0";
        if (navigator.appName=="Netscape")
          {
            if (this.document.layers['appear'])
              {
                this.document.layers['appear'].visibility="hide";
              }
          }
        else
          {
            if (this.document.all['appear'])
              {
                this.document.all['appear'].style.visibility="hidden";
              }
          }
    }
  }

function TCCloseWindow()
  {
    close();
  }


function TCmarkChange()
  {
    TCsavechanges = 1;
  }


function TCDoHelp()
  {
    var usertype = "student";
    if( TCIsInstructor() ) usertype = "instructor";
    if( TCIsAdmin() ) usertype = "admin";
    if( TCArgs == "" && top.frames && top.frames['TCtool'] && top.frames['TCtool'].TCArgs ) TCArgs = top.frames['TCtool'].TCArgs;

    var TCArgsLowerCase = TCArgs.toLowerCase();

    if( TCArgs.indexOf( "plugin" ) > -1 ) {
        TCArgsLowerCase = "plugin";
    }
    else {
        if( TCArgsLowerCase.indexOf( "retrieve-list-submissions-" ) > -1 ) {
            TCArgsLowerCase = "retrieve-list-submissions";
        }
        else if( TCArgsLowerCase.indexOf( "list-students-" ) > -1 ) {
            TCArgsLowerCase = "retrieve-list-students";
        }
    }
    if ( TCLanguage == "" ) {
        TCLanguage == "usenglish";
    }
    var helplang = TCLanguage;
    // Help is only available in usenglish
    helplang = "usenglish";
    var HelpUrl = TCPathToTopClass.substring( 0, 1 + TCPathToTopClass.lastIndexOf('/') ) + "chelp/" + helplang + "/" + usertype + "/" + TCArgsLowerCase + ".html";
    var TCHelpWin = window.open( HelpUrl, "TCHelpWin", "status=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes" );
    TCHelpWin.focus();
  }

function TCDoPHelp()
  {
    if ( ( TCLanguage == "ukenglish" || TCLanguage == "usenglish" ) )
      {
        var HelpUrl = TCPathToTopClass.substring( 0, 1 + TCPathToTopClass.lastIndexOf('/') ) + "phelp/index.htm";
      }
    else
      {
        var HelpUrl = TCPathToTopClass.substring( 0, 1 + TCPathToTopClass.lastIndexOf('/') ) + "phelp/" + TCLanguage + "/index.htm";
      }

    var TCHelpWin = window.open( HelpUrl, "TCHelpWin", "status=yes,menubar=yes,location=yes,resizable=yes,scrollable=yes" );
    TCHelpWin.focus();
  }

function TCShowLog()
  {
    var TCLogWin = window.open( TCPathToTopClass + "Viewlog", "TCLogWin", "menubar=yes,location=no,resizable=yes,status=yes,scrollbars=yes" );
    TCLogWin.focus();
  }

function TCPopupAbout()
  {
    var TCLogWin = window.open( TCPathToTopClass + "Popup-About", "TCLogWin", "menubar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=600,height=500" );
    TCLogWin.focus();
  }

function TCPopupExpires( NumberOfDays )
  {
    var TCExpiresWin = window.open( TCPathToTopClass + "ExpireAlert-" + NumberOfDays, "TCExpiresWin", "menubar=no,location=no,resizable=no,status=no,scrollbars=no,width=700,height=50" );
    TCExpiresWin.focus();
  }

function TCCloseWindow()
  {
    if ( top.opener && top.opener.location )
    top.close();
  }

function TCReorderFinish()
  {
    top.window.opener.document.getElementById('EditObjectForm').submit();
    top.window.close();
  }

function TCOpenOperationsWizardForDynamicOp( group, operation, join )
  {
    this.document.getElementById('EditObjectForm').hiddendynop.value = 1;
    TCOpenOperationsWizard( group, operation, join );
  }

function popupGroupTree(value)
  {
    if (value)
    {
      this.document.location = TCPathToTopClass + "-Popup-Tree-Frame-" + value;
    }
    else
    {
      this.document.location = TCPathToTopClass + "-Popup-Tree-Frame-Edit-0";
    }

  }

function ListGroups()
  {
    this.document.location = TCPathToTopClass + "-List-Group";
  }
//Added for Centra Event Integration on the Course Creation Page
//From a PopUp generated by Centra Plugin the selected event id
// & name will be passed into this function to populate the edit page
//source with a javascript link to that course.
//Added the APIVersion formal parameter so we can call a different function when we're
//using Centra One.  P.Maher 26/7/2001

function TCInsertCentraEventLink( PluginName, EventName, EventID, AttendString, APIVersion )
  {
    if( TCIsPopup() )
      {
        var Link = "";
        Link = "\n<br/>\n" + AttendString + ": \n<a href=\"javascript:";
        if( APIVersion == 1 )
          {
            Link += "TCCommandLink('plugin-" + PluginName + "-attend-" + EventID + "', '' );\" >";
          }
        else
          {
            Link += "TCCentraAttend('" + PluginName + "','" + EventID  + "' );\" >";
          }
        Link += "\n" + EventName + "\n</a><br/>\n";
        //opener.document.all.pagetext.value += Link;
        /*
        if( opener && opener.document && opener.document.forms && opener.document.forms['edit_form'] && opener.document.forms['edit_form'].elements && opener.document.forms['edit_form'].elements['pagetext'] )
          {
            opener.document.forms['edit_form'].elements['pagetext'].value += Link;
          }
        else
        */
        //Nicholas Murphy 13-May-2005  #9049 Centra event not adding to page.
        ta = opener.document.getElementById("text");
        if (ta)
        {
          ta.value = ta.value + Link;
        }
        //Nicholas Murphy 13-May-2005  end
        close(); //the Popup window
      }
  }

function TC5FrameSetup( givenIndexFrmLoc, givenMainFrmLoc )
  {
    debugAlert("TC5FrameSetup","givenIndexFrmLoc " + givenIndexFrmLoc + " givenMainFrmLoc " + givenMainFrmLoc );
    var tcmain = TCFindTCmain();
    if ( tcmain && ( typeof( TCInFrameSetup ) == "undefined" || !TCInFrameSetup ) )
    //if ( tcmain && typeof( TCInFrameSetup ) && !TCInFrameSetup )
      {
        // cgarvey 01Jun01 - if its edit ulm replace toks with retrieve page.
        var ind = givenMainFrmLoc.toLowerCase().indexOf( "edit-ulm-" );
        if( ind > -1 )
          {
            var ulmID = givenMainFrmLoc.substring( ind + 9 );
            // #5324 if previewing a newly created course
            if ( ulmID == "Course-0D0" && TCUnitToShow )
              {
                ulmID = TCUnitToShow;
              }
            givenMainFrmLoc = givenMainFrmLoc.substring( 0, ind ) + "Retrieve-Page-" + ulmID;
          }
        ind = givenIndexFrmLoc.toLowerCase().indexOf( "edit-ulm-" );
        if( ind > -1 )
          {
            var ulmID = givenIndexFrmLoc.substring( ind + 9 );
            // #5324 if previewing a newly created course
            if ( ulmID == "Course-0D0" && TCUnitToShow )
              {
                ulmID = TCUnitToShow;
              }
            givenIndexFrmLoc = givenIndexFrmLoc.substring( 0, ind ) + "Retrieve-Page-" + ulmID;
          }
        ind = givenIndexFrmLoc.toLowerCase().indexOf( "edit-object-" );
        if( ind > -1 )
          {
            var args = givenIndexFrmLoc.substring( ind + 12 );
            //args start with class e.g. '34-245D0' or 'readOnly34-245D0'
            var hyphen = args.indexOf( "-" );

            var ulmID = args.substring( hyphen );
            // #5324 if previewing a newly created course
            if ( ulmID == "Course-0D0" && TCUnitToShow )
              {
                ulmID = TCUnitToShow;
              }
            givenIndexFrmLoc = givenIndexFrmLoc.substring( 0, ind ) + "Retrieve-Page-" + ulmID;
          }
        var newLoc = TCPathToTopClass + "Frame-Setup"
                                      //+ "-IndFrame-" + givenIndexFrmLoc
                                      + "-ContFrame-" + givenMainFrmLoc;
        this.TCInFrameSetup = true;

        debugAlert("TC5FrameSetup","tcmain.location.replace(" +  newLoc + ")");
        tcmain.location.replace( newLoc );
      }
  }

function TCCentraAttend( pluginName, eventId )
  {
    var location = TCPathToTopClass + "-plugin-" + pluginName + "-attend-" + eventId;
    var newWindow = window.open( location, "Centra" );
  }

/*
   The next two functions aid the linking of ILT classes to WPages.

   TCILTLinkSubmit()
     If an event has been choosen then update the body of the page to contain a comment saying so
     If no event has been selected then remove the comment.

   TCILTLinkClose()
     Closes the popup by calling TCPopupCancelled().

*/


function TCILTLinkSubmit()
  {
    comment = "<!--Page contains a link to a Live event-->";
    var linked = true;
    if ( window.document.forms[0].elements['event'].value == '0D0' )
      {
        linked = false;
      }
    var found = false;

    for ( j = 0; j < window.opener.document.forms.length; j++ )
      {
        for ( i = 0; i < window.opener.document.forms[j].elements.length; i++ )
          {
            if ( window.opener.document.forms[j].elements[i].name == 'pagetext' )
              {
                found = true;
                break;
              }
          }
        if( found ) break;
      }
    if ( !found )
      {
        alert( "Can't find form element" );
      }
    else
      {
        var text = window.opener.document.forms[j].elements['pagetext'].value;
        var ind = text.indexOf( comment );
        if ( ind == -1 )
          {
            if ( linked )
              {
                window.opener.document.forms[j].elements['pagetext'].value=comment + '\r\n' + text;
              }
          }
        else
          {
            if ( !linked )
              {
                var newtext = "";
                if ( ind == 0 )
                  {
                    if ( text == comment + '\r\n' )
                      {
                        window.opener.document.forms[j].elements['pagetext'].value="";
                      }
                    else
                      {
                        //alert( "length of comment :" + comment.length() );
                        //newtext = text.substring( comment.length() );
                        //window.opener.document.forms[j].elements['pagetext'].value=newtext;
                      }
                  }
                else
                  {
                    //alert( "Before comment :" + text.substring( 0, ind ) );
                    //start = ind + comment.length();
                    //end = text.length();
                    //alert( "After comment :" + text.substring( start, end ) );
                    //newtext = text.substring( 0, ind ) + text.substring( ind + comment.length(), text.length() );
                    //newtext += text.substring( ind + comment.length(), text.length() );
                    //window.opener.document.forms[j].elements['pagetext'].value=newtext;
                  }
              }
          }
      }
    //this.form.submit();
  }

function TCILTLinkClose()
  {
    return TCPopupCancelled();
  }

// DoPercentChars() is similar to escape() but it also escapes hyphens
function DoPercentChars( text )
  {
    text = encodeURI( text );
    text = text.split( "-" );
    text = text.join( "%2D" );
    return text;
  }

function RefreshIndexFrame()
  {
    top.TCDoNotReplace = true;
    var tcmain = TCFindTCmain();
    var tccindex = TCFindTCcindex( tcmain );
    tccindex.location = TCPathToTopClass + "Retrieve-Page-" + TCRootID;
    //tccindex.location = tccindex.location;
  }
//#6692 Refresh index frame, called when content has been added.
function OnContentAdd()
  {
    //alert("OnContentAdd");
    top.TCDoNotReplace = true;
    var tcmain = TCFindTCmain();
    var tccindex = TCFindTCcindex( tcmain );
    if ( tccindex )
      {
        //alert("OnContentAdd calling tccindex.reload()");
        tccindex.window.location.reload();
      }
  }

// OnClickRole
// Used on Edit-User form
// Dynamically adds/removes options from EnrollAs list according to which roles have been selected.
function OnClickRole( checkbox, value, text, listname )
  {
    var list = document.getElementById(listname);
    if ( list )
      {
        var len = list.length;
        if ( checkbox.checked )
          {
            var found = false;
            var pos = -1;
            for ( i = 0; i < len; i++ )
              {
                if ( list.options[i] != null && list.options[i].value == value )
                  {
                    found = true;
                  }
                else if ( list.options[i] != null && list.options[i].value == 0 )
                  {
                    list.options[i] = null;
                    pos = i;
                  }
              }
            if ( !found )
              {
                var opt = new Option(text);
                opt.value=value;
                if ( pos == -1 ) pos = len
                list.options[pos] = opt;
              }
          }
        else
          {
            for ( i = 0; i < len; i++ )
              {
                if ( list.options[i] != null && list.options[i].value == value )
                  {
                    list.options[i] = null;
                  }
              }
          }
/*
        var items = "";
        len = list.length;
        for ( i = 0; i < len; i++ )
          {
            items = items + "options[" + i + "] ";
            if ( list.options[i] == null )
              {
                items = items + "null\n";
              }
            else //if ( list.options[i] != null )
              {
                items = items + list.options[i].value + " " + list.options[i].text + "\n";
                if ( list.options[i].value == null )
                  {
                    list.options[i] = null;
                  }
              }
          }
        alert( items );
*/
      }
  }

   function indexFrameHighlight(obj)
   {
     if (obj == presentPosition)
     {
       //obj.className="pmHoverSelect";
       obj.style.background="#EEEEEE";
     }
     else
     {
       //obj.className="pmHover";
       obj.style.background="#DFDFDF";
     }
   }

   function indexFrameUnhighlight(obj)
   {
     if (presentPosition)
     {
       //debugAlert("obj is " + obj.id + " presentPosition is " + presentPosition.id);
     }
     if (obj == presentPosition)
     {
        //debugAlert("found present position");
       //obj.className="pmSelect";
        obj.style.background="#CFCFCF";
     }
     else
     {
       obj.style.background="none";
     }
   }

   function indexFrameToggle(obj)
   {

 }
function cancelAnchorEventPropagation()
{
}
function stopEventPropagation(evt)
{
}

function updateTreeToDisplayLocation(obj)
{
  if (obj.parentNode != null)
  {
    if ((obj.parentNode.style) && (obj.parentNode.style.display="none"))
    {
      obj.parentNode.style.display="";
    }
    updateTreeToDisplayLocation(obj.parentNode);
  }
}


function initialUpdateStatusGraphic(id)
{
  debugAlert ("initialUpdateStatusGraphic", "in initialUpdateStatusGraphic with id " + id+ "\n");
  var mytcmain = TCFindTCmain();
  var mytccindex = TCFindTCcindex( mytcmain );
  if (mytccindex.document.getElementById("twister_"+id)) // we're a course
  {
    // we don't want to change status directly for a course
    //Nicholas Murphy 03-Apr-2003  set the position in the index frame
    mytccindex.markHere(mytccindex.document.getElementById('pageMarkings_'+id),false);
  }
  else if (mytccindex.document.getElementById('pageMarkings_'+id) != null)
  {
    //debugAlert("calling markHere with id " + id + "( presentPosition is " + presentPosition + ")");
    //Nicholas Murphy 03-Apr-2003  set the position in the index frame
    mytccindex.markHere(mytccindex.document.getElementById('pageMarkings_'+id),false);
    var mycheckbox= mytccindex.document.getElementById("unread_"+id);
    if (mycheckbox && mycheckbox.checked == true)
    {
      mycheckbox.checked=false;
      var myimg = mytccindex.document.getElementById("statusgraphic_"+id);
      if (myimg)
      {
         myimg.src = 'icons/' + TCLanguage + '/ulmstatus1.gif';
      }
      else
      {
        debugAlert("couldn't find image for " + "statusgraphic_" + id + "\n");
      }
      updateStatusGraphic(id);
    }
    else
    {
      if (mycheckbox)
      {
        debugAlert(mycheckbox.id + " " + mycheckbox.checked+ "\n");
      }
      else
      {
        debugAlert("couldn't find an object for id " + id+ "\n" );
      }
    }
  }
  debugAlert("-------------------\n");
}

function updateStatusGraphic(id)
{
  debugAlert("updateStatusGraphic","in updateStatusGraphic with id " + id + "\n");
  var mytcmain = TCFindTCmain();
  var mytccindex = TCFindTCcindex( mytcmain );
  var obj = mytccindex.document.getElementById('pageMarkings_'+id);
  var obj_unread = mytccindex.document.getElementById("unread_"+id);
  if (obj && obj_unread )
  {
    //var node_id = obj.parentNode.parentNode.id;
    // #11487 only go up one level.
    var node_id = obj.parentNode.id;
    debugAlert("updateStatusGraphic", "node_id " + node_id+ "\n");
    // get the overall parent of this group of elements, which is the twister.
    parenttwisterid = node_id.substring(node_id.lastIndexOf("_")+1);
    objid="contents_"+parenttwisterid;
    debugAlert("updateStatusGraphic", "trying " + parenttwisterid+ "\n");
    var parent = mytccindex.document.getElementById(objid);
    if (parent)
    {
      //var kids = mytccindex.document.getElementsByName(parenttwisterid);
      var kids = mytccindex.getElementsByAttribute("class","JSState_"+parenttwisterid);
      var str="[" + parenttwisterid + "]["+ kids.length+"]";
      for (var i = 0; i < kids.length; i++)
      {
        str = str + kids[i].id + " :: ";
      }
      debugAlert("updateStatusGraphic", "siblings are " + str+ "\n");
      debugAlert("updateStatusGraphic", "looking at parent " + parent.id+ "\n");
      //Nicholas Murphy 21-Apr-2004  this is much easier. I've named the checkboxes after their immediate parent in the tree. If we wish to see if the ulmstatus at this level should be marked as read, we just get these children using getElementsByName(this.id) and check if any are marking an unread child.
      children = kids;
      var unread=false;
      for (var loop = 0; loop < children.length; loop ++)
      {
        if ( children[loop].tagName=="INPUT" && children[loop].type=="checkbox" )
        {
          if (children[loop].checked == true)
          {
            unread = true;
          }
        }
      }
      if (unread==false)
      {
        // there is nothing under the parent now that is unread. change the value of parentid_unread
        var parent_unread = mytccindex.document.getElementById("unread_"+parenttwisterid);
        debugAlert("updateStatusGraphic", "nothing unread. looking for " + parenttwisterid+"_unread"+"\n");
        if (parent_unread)
        {
          parent_unread.checked=false; // we're changing another ulmstatus thingy, so we have to go through this again for the parent.
          var parentimg = mytccindex.document.getElementById("statusgraphic_"+parenttwisterid);
          if (parentimg)
          {
             //debugAlert("parentImage src is " + parentimg.src);
             parentimg.src = 'icons/' + TCLanguage + '/ulmstatus1.gif';
             //debugAlert("changing parentImage src to " + parentimg.src);
          }
          else
          {
            debugAlert("updateStatusGraphic", "NOTHING Unread, but can't find the parentimage to change");
          }
          updateStatusGraphic(parenttwisterid);
        }
      }
    }
    else
    {
      debugAlert("updateStatusGraphic", obj.id + " has no parentNode\n");
    }
  }
  else
  {
    debugAlert("updateStatusGraphic", "obj_unread is "+ obj + "\n" );
    if (obj_unread)
    {
      debugAlert("updateStatusGraphic", "obj_unread checked is "+ obj_unread.checked + "\n");
    }
  }
}
function findMyFrame(doc)
{
    if (window.navigator.appName == "Microsoft Internet Explorer")
    {
      // IE specific
      frmes = top.document.frames;
      for (loop = 0; loop < frmes.length; loop ++)
      {
        if(frmes[loop].document== doc)
        {
          return(frmes[loop].name);
        }
      }
      return "";
    }
    else
    {
      frmes = top.document.getElementsByTagName("FRAME");
      for (loop = 0; loop < frmes.length; loop ++)
      {
        if(frmes[loop].src == doc.URL)
        {
          return(frmes[loop].name);
        }
      }
      return "";
    }
}

var debugwin=null;
function debugAlert(func,str)
{
  fName = findMyFrame(document);
  if (func != null && str != null)
  {
    var tcmain = TCFindTCmain();
    var tccindex = TCFindTCcindex( tcmain );
    if (fName=="TCcmain")
    {
        str = "<font color='green'><b>" + fName + "::" + func + "</b>&nbsp;</font>" + str;
    }
    else
    if (fName=="TCcIndex")
    {
        str = "<font color='red'><b>" + fName + "::" + func + "</b>&nbsp;</font>" + str;
    }
    else
    if (fName=="TCcTool")
    {
        str = "<font color='orange'><b>" + fName + "::" + func + "</b>&nbsp;</font>" + str;
    }
    else
    if (fName!="")
    {
        str = "<font color='blue'><b>" + fName + "::" + func + "</b>&nbsp;</font>" + str;
    }
    else
    {
        str = "<font color='purple'><b>" + func + "</b>&nbsp;</font>" + str;
    }
    /*
    if (tccindex != null)
    {
      if (tccindex.TCDynamicIndex == true)
      {
        str = "<font color='green'><b>" + fName + "::" + func + "</b></font>" + str;
      }
      else
      {
        str = "<font color='red'><b>" + fName + "::" + func + "</b></font>" + str;
      }
    }
    else
    {
        str = "<font color='blue'><b>" + fName + "::" + func + "</b></font>" + str;
    }
    */
    debugAlert2(str);
  }
}

function debugAlert2(str)
{
  if (0)
  {
    if (debugwin == null)
    {
      debugwin = window.open("" , "DebugWin", "menubar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=1000,height=200" );
    }
    debugwin.document.writeln(str+"<br/>");
  }
}

function indexFrameToggle(id)
   {
     mydiv = document.getElementById("contents_"+id);
     mytwister = document.getElementById("twister_"+id);
     if (mydiv && mytwister)
     {
       if (mydiv.style.display != "none")
       {
         mydiv.style.display="none";
         mytwister.src = 'icons/' + TCLanguage + '/plus.gif';
       }
       else
       {
         mydiv.style.display="";
         mytwister.src = 'icons/' + TCLanguage + '/minus.gif';
       }
     }

     /*
     else
     {
       alert("can't find element " + "contents_" + id );
     }
     */
     return false;
   }


function markHere(obj,useParent,evt)
{
  if (presentPosition != null)
  {
    presentPosition.style.background="none";
  }
  if (useParent==true)
  {
    here = obj.parentNode;
  }
  else
  {
    here = obj;
    //Nicholas Murphy 03-Apr-2003  unsure that the _contents div containing this is open
    // we shouldn't have to recurse up the tree to ensure that all displays are open, as they have to be
    // to get to this point.
    here.parentNode.parentNode.style.display="";
  }
  for (var loop = here.childNodes.length-1;  loop >= 0; loop --)
  {
    //Nicholas Murphy 31-May-2005  focus on the link to the course, so that where we are is always visible
    // in the window.
    if (here.childNodes[loop].tagName=="A")
    {
      here.childNodes[loop].focus();
      break;
    }
  }
  here.style.background="#9CCFFF";
  //debugAlert("setting presentPosition to " + here.id);
  presentPosition=here;
  if (window.navigator.appName == "Microsoft Internet Explorer")
  {
   if (window.event)
   {
     window.event.cancelBubble=true;
   }
  }
  else
  {
    if (evt)
    {
     evt.cancelBubble=true;
     }
  }
}

function stopEventPropagation(evt)
{
 var location = "";
 if (window.navigator.appName == "Microsoft Internet Explorer")
 {
  window.event.cancelBubble=true;
  location = window.event.srcElement.href;
 }
 else
 {
  evt.cancelBubble=true;
  location = evt.currentTarget.href;
 }
 objid = location.substring(eval(location.lastIndexOf("-")+"+1"),location.length-2);
 debugAlert("in stopEventPropagation with objid " + objid);
 initialUpdateStatusGraphic(objid);
}

//Nicholas Murphy 27-May-2003  update the tree if tccindex looks like its been loaded at root. Check if tccmain is displaying a page. If so,
// highlight that page. Called from template.
function CourseUpdatePositionIfNecessary()
{
  if (TCULMID == TCRootID)
  {
    debugAlert("CourseUpdatePositionIfNecessary","frames TCULMID is same as TCRootID. Gonna check tccmain to see where it is");
    var tcmain = TCFindTCmain();
    var tccmain = TCFindTCcmain(tcmain);
    if (tccmain && tccmain.TCULMID != TCULMID)
    {
      debugAlert("CourseUpdatePositionIfNecessary","updating tree with tccmain.TCULMID " + tccmain.TCULMID);
      initialUpdateStatusGraphic(tccmain.TCULMID);
    }
  }
}

// Used in the edit-object forms.
function ToggleFormSection( section )
  {
    if ( document.getElementById(section) )
      {
        if ( document.getElementById(section).style.display == 'none' )
          {
            document.getElementById(section).style.display = '';
          }
        else
          {
            document.getElementById(section).style.display = 'none';
          }
      }
  }

// #???? GroupSelectClick avoid a round trip to TopClass.
function GroupSelectClick( rootID, cmd )
  {
    CloseOnSelect = "yes"
    ExpandTreeCommand = TCPathToTopClass + "Object-Tree-68-";

    if ( cmd != "Edit" )
      {
        SelectTreeCommand = TCPathToTopClass + "Move-Group-" + cmd;
      }
    else
      {
        SelectTreeCommand = TCPathToTopClass + "Edit-Group-ID-";
      }
    InitialPointForTreeCommand = rootID;
    TCOpenPopup( ExpandTreeCommand + "-" + InitialPointForTreeCommand, "PopupCreateTreeFrame", 300, 400, 50, 50 );
  }

// Used by template based group tree
function toggleGroupContents(groupId)
  {
    contents = document.getElementById( 'contents-' + groupId);
    toggle = document.getElementById( 'toggle-' + groupId );
    if ( contents )
      {
        if ( contents.style.display == 'none' )
          {
            contents.style.display = '';
            if ( toggle )
              {
                slash = toggle.src.lastIndexOf( '/' );
                if ( slash > 0 )
                  {
                    toggle.src = toggle.src.substr( 0, slash+1 ) + 'minus.gif';
                    toggle.alt = strCollapse;
                    toggle.title = strCollapse;
                 }
              }
          }
        else
          {
            contents.style.display = 'none';
            if ( toggle )
              {
                slash = toggle.src.lastIndexOf( '/' );
                if ( slash > 0 )
                  {
                    toggle.src = toggle.src.substr( 0, slash+1 ) + 'plus.gif';
                    toggle.alt = strExpand;
                    toggle.title = strExpand;
                  }
              }
          }
      }
  }

// Used by template based group tree
function selectGroup( id, shortname )
{
  if (window.opener == null)
  {
    window.close();
  }
  else
  if (window.opener.SelectTreeCommand)
    {
      var urlstring = window.opener.SelectTreeCommand + "-" + id;
      window.opener.location= urlstring;
      if (window.opener.CloseOnSelect)
        {
          window.close();
        }
    }
  else
  if (window.opener.SelectTreeNameField || window.opener.SelectTreeIdField)
    {
      for (var form_loop = 0; form_loop < window.opener.document.forms.length; form_loop ++)
        {
          var form = window.opener.document.forms[form_loop];
          if (form.elements[window.opener.SelectTreeNameField])
            {
              form.elements[window.opener.SelectTreeNameField].value = shortname;
              if (window.opener.SelectTreeButton)
              {
                var buttons = form.elements[window.opener.SelectTreeButton];
                if ( buttons == null )
                  {
                  }
                else if ( typeof(buttons.click) != "undefined" )
                  {
                    buttons.click();
                  }
                else if ( typeof(buttons[0].click) != "undefined" )
                  {
                    buttons[0].click();
                  }
              }
              else if (window.opener.submitForm)
              {
                window.opener.submitForm(id);
              }
              if (window.opener.CloseOnSelect)
                {
                  window.close();
                }
              return;
            }
          if (form.elements[window.opener.SelectTreeIdField])
            {
              form.elements[window.opener.SelectTreeIdField].value = id;
              if (window.opener.SelectTreeButton)
              {
                var buttons = form.elements[window.opener.SelectTreeButton];
                if ( buttons == null )
                  {
                  }
                else if ( typeof(buttons.click) != "undefined" )
                  {
                    buttons.click();
                  }
                else if ( typeof(buttons[0].click) != "undefined" )
                  {
                    buttons[0].click();
                  }
              }
              else if (window.opener.submitForm)
              {
                window.opener.submitForm(id);
              }
              if (window.opener.CloseOnSelect)
                {
                  window.close();
                }
              return;
            }
        }
    }
  else
    {
      window.close();
    }
}

/*
  The group tree popup, interagates its opener to see what to do.
  Two such buttons on a page will mess up. So need to set as we
  launch. Can still go wrong, if you went back and pressed a
  different button.
*/
function selectGroupName( command, nameField, start, close )
{
  ExpandTreeCommand = command;
  SelectTreeNameField = nameField;
  InitialPointForTreeCommand = start;
  CloseOnSelect = close;
  return TCOpenPopup( command,'PopupListMembers',300,400,50,50);
}

function PopupList_SortBy( sortOn )
{
  document.getElementById("offset").value = 0;
  document.getElementById("jump").value   = "";
  var sort_field = document.getElementById("sortOn").value;

  if( sort_field == sortOn )
  {
    var reverse_field = document.getElementById("reverse").value;
    if( reverse_field == "1" )
    {
      reverse_field = "2";
    }
    else
    {
       reverse_field = "1";
    }

    document.getElementById("reverse").value = reverse_field;
  }
  else
  {
    document.getElementById("reverse").value = "1";
  }

  document.getElementById("sortOn").value = sortOn;

  if ( TCUseYUI && TCModalPopup ) {
    TCPostModalPopup( document.getElementsByName("search").item(0) )
  }
  else {
    document.getElementsByName("search").item(0).submit();
  }
  return false;
}


function Popup_SubmitJump( jump )
{
  document.getElementById("offset").value = 0;
  document.getElementById("list_count").value = -1;
  // what are we sorting on?
  var sort = document.getElementById("sortOn").value;
  if ( 0 )
    {
      if ( jump != "#" )
        {
          var find = document.getElementById("find"+sort).value;
          if ( find != "" )
            {
              document.getElementById("find"+sort).value = "";
            }
        }
      document.getElementById("jump").value   = jump;
    }
  else
    {
      // what are we sorting on?
      if ( jump == "#" )
        {
          jump = "";
        }
      else
        {
          if ( document.getElementById("reverse").value == "1" )
            {
              jump = ">=" + jump;
            }
          else
            {
              jump = "<" + String.fromCharCode(jump.charCodeAt(0)+1);
            }
        }
      document.getElementById("find"+sort).value   = jump;
    }

  if ( TCUseYUI && TCModalPopup ) {
    TCPostModalPopup( document.getElementsByName("search").item(0) )
  }
  else {
    document.getElementsByName("search").item(0).submit();
  }

  return false;
}

function PopUp_RefineSearch( theForm )
{
  document.getElementById("list_count").value = -1;
  document.getElementById("offset").value = 0;
  // what column are we sorting on?
  var sort = document.getElementById("sortOn").value;
  // have we search criteria on the sort column
  var find = document.getElementById("find"+sort).value;
  // and a jump on the sort column
  var jump = document.getElementById("jump").value;
  if ( jump != "" && find != "" )
    {
      // we should get rid of one?
      // as the user just pressed the go button we will drop
      // the jump
      document.getElementById("jump").value = "";
    }

  if ( TCUseYUI && TCModalPopup ) {
    TCPostModalPopup( document.getElementsByName("search").item(0) )
  }
  else {
    document.getElementsByName("search").item(0).submit();
  }

  return false;
}

// Start Change #9123
function TCgetNodesLowestMeasurement(node)
{
  var x = 0;
  if(node != null)
    x = node.offsetTop + node.offsetHeight;
  return x;
}

function TCgetNodesRightMostMeasurement(node)
{
  var x = 0;
  if(node != null)
    x = node.offsetLeft + node.offsetWidth;
  return x;
}

function Measure_Lowest()
{
  this.getMeasurement = TCgetNodesLowestMeasurement;
}
function Measure_RightMost()
{
  this.getMeasurement = TCgetNodesRightMostMeasurement;
}

function TCgetFurthestItem(metric, node)
{
  // Used to determine the Bottom or Right most item on the screen
  // Steps through each child item of the node passed in. Start with document.body.
  // metric object must have a "getMeasurement" method.
  var furthestPos = 0;
  var furthest = null;
  if(node != null)
  {
    furthestPos = metric.getMeasurement(node);
    furthest = node;
    var children = node.childNodes;
    var i;
    for (i = 0; i < children.length; i++)
    {
      var childsFurthest = TCgetFurthestItem(metric, children[i]);
      var childsFurthestPos = metric.getMeasurement(childsFurthest);
      if(furthestPos <= childsFurthestPos)
      {
        furthestPos = childsFurthestPos;
        furthest = childsFurthest;
      }
    }
  }
  return furthest;
}

function TCFitWindowToSize_Netscape()
{
  var rightMost = TCgetFurthestItem(new Measure_RightMost(), document.body);
  if(rightMost != null)
  {
    rightMost.scrollIntoView(false);
    if(window.pageXOffset > 0)
    {
    var deltaX = window.pageXOffset + rightMost.offsetWidth;
      window.resizeBy(deltaX, 0);
    }
  }
  var lowestItem = TCgetFurthestItem(new Measure_Lowest(), document.body);
  if(lowestItem != null)
  {
    lowestItem.scrollIntoView(false);
    if(window.pageYOffset > 0)
    {
    var deltaY = window.pageYOffset + lowestItem.offsetHeight;
      window.resizeBy(0, deltaY);
    }
  }
}

function TCFitWindowToSize_IE()
{
  var lowestItem = TCgetFurthestItem(new Measure_Lowest(), document.body);
  var rightMost = TCgetFurthestItem(new Measure_RightMost(), document.body);
  var deltaY = 0;
  var deltaX = 0;
  if(lowestItem)
  {
    deltaY = lowestItem.offsetTop + lowestItem.offsetHeight - document.body.offsetHeight ;
    if(deltaY <= 0)
      deltaY = 0;
    else
      deltaY += 20;
  }

  if(rightMost != null)
  {
    deltaX = rightMost.offsetLeft + rightMost.offsetWidth - document.body.offsetWidth ;
    if(deltaX <= 0)
      deltaX = 0;
    else
      deltaX += 20;
  }
  window.resizeBy(deltaX, deltaY);
}

function TCFitWindowToSize_Other()
{
  // Was taken from original PopUp_AdjustWindow function.
  var pp_Table = document.getElementById("PopupFrameTable");
  var pp_Frame = document.forms[0];

// IE only.
  /*
  var pp_Height = ( pp_Frame.getBoundingClientRect().bottom);
  var pp_Width  = ( pp_Table.getBoundingClientRect().right);
  */


  var width=pp_Table.offsetWidth;
  var height=pp_Frame.offsetHeight;
  window.resizeTo( width+50,height+50);

  return false;
}

function PopUp_AdjustWindow()
{
  if ( TCIsPopup() )
  {
    if(is.ie6up && is.win)
      TCFitWindowToSize_IE();
    else if( is.ns )
      TCFitWindowToSize_Netscape();
    else
      TCFitWindowToSize_Other();
    return false;
  }
}
// Finish Change #9123

function TC_AddToSelection( value )
{
  var list_selection = document.getElementById("list_selection");
  var selected = list_selection.value;
  if (selected != "")
  {
    elements = selected.split(",");
    var found = false;
    for (var loop = 0; loop < elements.length; loop ++)
    {
      if (elements[loop] == value)
      {
        found =true;
      }
    }
    if (!found)
    {
      selected = selected + "," + value;
    }
    else
    {
      return false;
    }
  } // if (selected != "")...
  else
  {
    selected = value;
  }
  list_selection.value = selected;

  return true;
}

function TC_RemoveFromSelection( value )
{
  var list_selection = document.getElementById("list_selection");
  var selected = list_selection.value;
  var newlist="";
  if (selected != "")
  {
    elements = selected.split(",");
    var found = false;
    for (var loop = 0; loop < elements.length; loop ++)
    {
      if (elements[loop] == value)
      {
        found =true;
      }
      else
      {
        if (newlist != "")
        {
          newlist = newlist+",";
        }
        newlist = newlist + elements[loop];
      }
    }
    if (!found)
    {
      return false;
    }
    else
    {
      list_selection.value = newlist;
      return true;
    }
  } // if (selected != "")...
  else
  {
    return false;
  }
}


function TC_CheckSelection( checkBoxName )
{
 var checkBox = document.getElementById(checkBoxName);

 if( checkBox.checked == true ) TC_AddToSelection( checkBox.value );
 else TC_RemoveFromSelection( checkBox.value );

 return false;
}

function TCPopup_SingleSelect()
{
  if ( typeof selection_mode != "undefined" )
    return (selection_mode == 0);
  if( !(document.getElementsByName("selection_mode")[0])
     ||(document.getElementsByName("selection_mode")[0].value != 0))
    return false;
  return true;
}

function TCAddChildrenToCondition( id )
{
  var win = window.open( TCPathToTopClass + "inpopup-condition-children-" + id, "execute", "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=300,height=450,posx=5,posy=5" );
  win.focus();
}

function TCRefreshCondition( id )
{
  top.window.close();
  var win = window.opener;
  if ( win )
    {
      win.location = TCPathToTopClass + "edit-object-98-" + id;
      win.focus();
    }
}

/*
   Not sure why we do this ths way. EditObjectFromGroup is called when we select a
   new group to edit. As a replacement for using TCClickedSetLocation.
*/
function EditObjectFromGroup(cmd, id)
{
  if ( (indx = window.location.href.toLowerCase().indexOf("edit-object")) > -1 ||
       (indx = window.location.href.toLowerCase().indexOf("display-group")) > -1 ||
       (indx = window.location.href.toLowerCase().indexOf("move-group")) > -1 )
  {
    newloc = window.location.href.substr(0,indx)+"Edit-Object-"+cmd+"-"+id;
    window.location = newloc;
  }

}

/******************************* Reports ***************************************/

var userPartition = 0;
var userLangNum   = 0;
var userID        = 0;
var TCreportRunning = "";


var reportTimeoutCheck = null;
var reportCloseTimeout = null;

function ResetReportTimeout()
{
  if (reportCloseTimeout)
  {
    clearTimeout(reportCloseTimeout);
  }
  //setTimeout("closeReportWindow()",360000);
  setTimeout("closeReportSession()",sessionTimeout);
}

function closeReportSession()
{
  if (reportWindow)
  {
    reportWindow.document.location.href="reports/logoff.asp";
  }
}

function callReport(command,destination_id,windowOptions)
{
     var reports_command = command;
     var reportFrame = window.frames['reportLoader']

     dest = document.getElementById(destination_id);
     if(dest && dest.value==1)
     {
        var len = reports_command.length;
        reports_command=reports_command + "&Format=PDF";
     }

     var pattern = new RegExp(".*creport.asp.*");
     var reportToScreen = pattern.test(reports_command);

      if(reportFrame && !reportToScreen){
        reportFrame.location.href = reports_command;
        TCreportRunning = reports_command;
      }else{
        if (windowOptions && windowOptions != "")
        {
          reportWindow = window.open(reports_command,'',windowOptions);
        }
        else
        {
          reportWindow = window.open(reports_command);
        }
      }
// don't do timeout if we're sending to email.
     if(dest && dest.value!=1)
     {
       reportTimeoutCheck = setTimeout("checkForReportWindowClose()",1000);
     }
}

function TCgotoEMail(){
  internalEMailScreen = window.open(TCPathToTopClass + "retrieve-list-in" );
}

function reportDone(){
  if("" != TCreportRunning){
    TCMessageDialog( {
      width:"360px",
      sHeader: TCreportLabelHeader,
      sBody: TCreportLabelBody,
      buttons: [ { text:TCreportLabelOk,  handler:TCSubmitYes, isDefault:true }]
    } );
    TCreportRunning = "";
  }

}

function checkForReportWindowClose()
{
  if (reportWindow)
  {
    //alert(reportWindow.closed);
    if (reportWindow.closed)
    {
      closeSessionFrame = document.getElementById("closeSessionFrame");
      if (closeSessionFrame)
      {
        try
        {
          // mozilla
          closeSessionFrame.contentDocument.location.href="reports/logoff.asp";
        }
        catch(err)
        {
          //ie
          closeSessionFrame.document.location.href="reports/logoff.asp";
        }
      }
      reportWindow = null;
      clearTimeout(reportTimeoutCheck);
      if (reportCloseTimeout)
      {
        clearTimeout(reportCloseTimeout);
      }
    }
    else
    {
      reportTimeoutCheck = setTimeout("checkForReportWindowClose()",1000);
    }
  }
}

function closeReportSessions()
{
  if (reportWindow && !reportWindow.closed)
  {
    reportWindow.document.location.href="reports/logoff.asp";
  }
  if (reportCloseTimeout)
  {
    clearTimeout(reportCloseTimeout);
  }
  reportWindow = null;
}

function selectExerciseFromClass(prefix)
{
  sel = document.getElementById(prefix+"class");
  if (sel)
  {
      window.open(this.TCPathToTopClass + "-Popup-Select-classID=42&op_code=25&field="+prefix+"exercise&attrToSend=IDID&partition=" + userPartition + "&rest="+sel.value,"PopupSelectUser", "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=300,height=400,posx=50,posy=50");
  }
  else
  {
    alert("can't find " + prefix + "class");
  }
}

function selectTutorsUser(prefix)
{
  window.open(this.TCPathToTopClass
    + "-Popup-Select-classID=26&op_code=26&field="
    +prefix
    +"student&attrToSend=IDID&partition=" + userPartition + "&rest=" + userID ,
    "PopupSelectUser",
    "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=300,height=400,posx=50,posy=50");
}

function selectUserFromClass(prefix)
{
  sel = document.getElementById(prefix+"class");
  if (sel)
  {
      window.open(this.TCPathToTopClass + "-Popup-Select-classID=26&op_code=23&field="+prefix+"student&attrToSend=usrN&partition=" + userPartition + "&rest="+sel.value,"PopupSelectUser", "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=300,height=400,posx=50,posy=50")
  }
}

function instr_student_progress(prefix)
{
  studName = document.getElementById(prefix+"student");
   dest = document.getElementById(prefix+"destination");
   if (studName && studName.value)
   {
     if(dest && dest.value==0)
     {
       callReport('reports/creport.asp?pUserID='+studName.value + '&TC_REPORT_NAME=student_progress&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination");
     }
     else
     {
         callReport(this.TCPathToTopClass + '-plugin-reports-StudentProgress-'+studName.value+'-' + userLangNum + '-PDF','');
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function instr_studentcourseprogress(prefix)
{
   dest = document.getElementById(prefix+"destination");
   classid = document.getElementById(prefix+"class");
   studid = document.getElementById(prefix+"student");
   if (studid && studid.value && classid && classid.value)
   {
     if(dest && dest.value==0)
     {
       callReport('reports/creport.asp?pClassID='+classid.value+'&pUserName='+studid.value+'&TC_REPORT_NAME=student_course_progress&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination");
     }
     else
     {
       callReport(this.TCPathToTopClass + '-plugin-reports-StudentCourseProgress-' + classid.value + '-' + studid.value + '-' + userLangNum + '-PDF','');
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function instr_studenttestprogress(prefix)
{
   dest = document.getElementById(prefix+"destination");
   classid = document.getElementById(prefix+"class");
   studid = document.getElementById(prefix+"student");
   if (studid && studid.value && classid && classid.value)
   {
     if(dest && dest.value==0)
     {
       callReport('reports/creport.asp?pClassID='+classid.value+'&pUserName='+studid.value+'&TC_REPORT_NAME=Student_Test_Progress&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination");
     }
     else
     {
       callReport(this.TCPathToTopClass + '-plugin-reports-StudentTests-' +classid.value + "-" + studid.value + '-' + userLangNum + '' + '-PDF','');
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}


function instr_test_effectiveness(prefix)
{
   dest = document.getElementById(prefix+"destination");
   classid = document.getElementById(prefix+"class");
   exerid = document.getElementById(prefix+"exercise");
   if (classid && classid.value && exerid && exerid.value)
   {
     if(dest && dest.value==0)
     {

       callReport('reports/creport.asp?pClassID='+classid.value+'&TC_REPORT_NAME=Test_Effectiveness&pLangID=' + userLangNum + '&pExerciseID='+exerid.value+'&ConnID=' + this.TCConnection,prefix+"destination");
     }
     else
     {
       callReport(this.TCPathToTopClass + '-plugin-reports-TestEffectiveness-' + classid.value + '-' + exerid.value + '-' + userLangNum + '-PDF','');
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function instr_alltests(prefix)
{
   dest = document.getElementById(prefix+"destination");
   classid = document.getElementById(prefix+"class");
   if (classid && classid.value)
   {
     if(dest && dest.value==0)
     {

       callReport("reports/creport.asp?pClassID="+classid.value+"&TC_REPORT_NAME=All_tests&pLangID=" + userLangNum + "&ConnID=" + this.TCConnection,prefix+"destination");
     }
     else
     {
       callReport(this.TCPathToTopClass + "plugin-reports-AllTests-" + classid.value + "-" + userLangNum + "-PDF","");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function instr_studenttests(prefix)
{
   dest = document.getElementById(prefix+"destination");
   classid = document.getElementById(prefix+"class");
   studname = document.getElementById(prefix+"student");
   if (classid && classid.value && studname && studname.value)
   {
     if(dest && dest.value==0  )
     {

       callReport("reports/creport.asp?pClassID="+classid.value+"&TC_REPORT_NAME=Student_Test_Progress&pLangID=" + userLangNum + "&pUsername=" + studname.value + "&ConnID=" + this.TCConnection,prefix+"destination");
     }
     else
     {
       callReport(this.TCPathToTopClass + "-plugin-reports-StudentTests-" + classid.value + "-" + studname.value + "-" + userLangNum + "-PDF","");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}
function studentprogress(prefix)
{
     dest = document.getElementById(prefix+"destination");
     if(dest && dest.value==0)
     {
       callReport('reports/creport.asp?pUserID=' + userID + '&TC_REPORT_NAME=student_progress&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,dest.value);
     }
     else
     {
       callReport(this.TCPathToTopClass + '-plugin-reports-StudentProgress-' + userID + '-' + userLangNum + '' + '-PDF','');
     }
}

function class_attendees(destination_id)
{
     dest = document.getElementById(destination_id);
     if(dest && dest.value==0)
     {
     callReport('reports/creport.asp?pClassID=' + document.getElementById("attendees").value + '&TC_REPORT_NAME=ILTWBTStudents&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,destination_id);
     }
     else
     {
       callReport(this.TCPathToTopClass + '-plugin-reports-ILTWBTStudents-'+ document.getElementById("attendees").value + '-' + userLangNum + '-PDF','');
     }
}

function jsp_attendees(destination_id)
{
     dest = document.getElementById(destination_id);
     if(dest && dest.value==0)
     {
     callReport('reports/creport.jsp?pClassID=' + document.getElementById("attendees").value + '&TC_REPORT_NAME=ILTWBTStudents&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection+ '&enterprise=' + UseCrystalEnterprise + '&CMS=' + CMS + '&CE_username='+CE_UserName + '&CE_password=' + CE_Password ,destination_id);
     }
     else
     {
       callReport(this.TCPathToTopClass + '-plugin-reports-ILTWBTStudents-'+ document.getElementById("attendees").value + '-' + userLangNum + '-PDF','');
     }
}
function managedStudents(prefix)
{
     dest = document.getElementById(prefix+"destination");
     studName = document.getElementById(prefix+"name");
     if (studName && studName.value != "")
     {
       if(dest && dest.value==0)
       {
         callReport('reports/creport.asp?pUserName=' + studName.value + '&TC_REPORT_NAME=student_progress_specific_wbt&pLangID=' + userLangNum + '&ConnID='+  this.TCConnection , prefix+"destination");
       }
       else
       {
         callReport(this.TCPathToTopClass + '-plugin-reports-StudentProgressSpecificWBT-' + studName.value + '-' + userLangNum + '-' + '-PDF','');
       }
     }
    else
    {
      alert('Insufficient data to run report');
    }
}


function managedStudentsComp(prefix)
{
 dest = document.getElementById(prefix+"destination");
 studid = document.getElementById(prefix+"name");
 filter = document.getElementById(prefix+"filter");

  if (studid && studid.value != "")
  {
    if(dest && dest.value==0)
    {
     callReport('reports/creport.asp?pUserName=' + studid.value + '&TC_REPORT_NAME=Compliance_by_User&pLangID=' + userLangNum + '&pComplianceFiltered=' + filter.value + '&ConnID=' + this.TCConnection,prefix+"destination" );
    }
    else
    {
     callReport(this.TCPathToTopClass + '-plugin-reports-ComplianceByUser-' + studid.value + '-' + userLangNum + '-' + filter.value +  '-PDF','');
    }
  }
  else
  {
     alert('Insufficient data to run report');
  }
}

function managedGroups(prefix)
{
 dest = document.getElementById(prefix+"destination");
 group = document.getElementById(prefix+"groups");
 orderby = document.getElementById(prefix+"orderby");
 if (group && group.value != "")
 {
   if (orderby.value == 'Class')
   {
      if (dest.value == 0)
      {
        callReport('reports/creport.asp?pGroupID=' + group.value + '&TC_REPORT_NAME=groupprogress_byclass&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination" );
      }
      else
      {
         callReport(this.TCPathToTopClass + '-plugin-reports-GroupProgressByClass-' + group.value + '-' + userLangNum + '-' + '-PDF','');
      }
   }
   else
   {
      if (dest.value == 0)
      {
        callReport('reports/creport.asp?pGroupID=' + group.value + '&TC_REPORT_NAME=groupprogress_bystudent&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination" );
      }
      else
      {
       callReport(this.TCPathToTopClass + '-plugin-reports-GroupProgressByStudent-' + group.value + '-' + userLangNum + '-' + '-PDF','');
      }
   }
 }
 else
 {
   alert('Insufficient data to run report');
 }

}


function competencybyGroup(prefix)
{
 dest = document.getElementById(prefix+"destination");
 groups = document.getElementById(prefix+"groups");
 mode = document.getElementById(prefix+"assignments");
 members = document.getElementById(prefix+"members");
 filter = document.getElementById(prefix+"filter");
 suppress = document.getElementById(prefix+"suppress");

  if (
      groups && groups.value
      && mode && mode.value
      && members && members.value
      && filter && filter.value)
  {
    if(dest && dest.value==0)
    {
     callReport('reports/creport.asp?pGroupID=' + groups.value + '&TC_REPORT_NAME=Competencies_by_group&pLangID=' + userLangNum + '&pAssignmentMode=' + mode.value + '&pDirectMembersOnly=' + members.value + '&pComplianceFilter=' + filter.value + '&pSuppressMembers=' + suppress.value + '&ConnID=' + this.TCConnection,prefix+"destination" );
    }
    else
    {
     callReport(this.TCPathToTopClass + '-plugin-reports-CompetenciesByGroup-' + groups.value + '-' + userLangNum + '' + '-' + mode.value + '-' + members.value + '-' + filter.value  + '-' + suppress.value + '-PDF','');
    }
  }
  else
  {
    alert('Insufficient data to run report');
  }
}

function upcomingcompetencybyGroup(prefix)
{
 dest = document.getElementById(prefix+"destination");
 groups = document.getElementById(prefix+"groups");
 mode = document.getElementById(prefix+"assignments");

 members = document.getElementById(prefix+"members");
 filter = document.getElementById(prefix+"filter");

 weeks = document.getElementById(prefix+"upcomingWeeks");

  if(
     (groups && groups.value != "")
  && (mode && mode.value != "")
  && (members && members.value != "")
  && (filter && filter.value != "")
  && (weeks && weeks.value != "")
  )
  {
    if(dest && dest.value==0)
    {
     callReport('reports/creport.asp?pGroupID=' + groups.value + '&pNumWeeks=' + weeks.value + '&TC_REPORT_NAME=UpComing_Compliance_by_Group&pLangID=' + userLangNum + '&pAssignmentMode=' + mode.value + '&pDirectMembersOnly='+members.value + '&pComplianceFilter=' + filter.value + '&ConnID=' + this.TCConnection,prefix+"destination" );
     }
    else
    {
     callReport(this.TCPathToTopClass + '-plugin-reports-UpcomingComplianceByGroup-' + groups.value + '-' + userLangNum + '-' +mode.value + '-' + members.value + '-' + filter.value + '-' + weeks.value +'-PDF','');
    }
  }
  else
  {
    alert('Insufficient data to run report');
  }
}
/*
function competencybyGroup(prefix)
{
 dest = document.getElementById(prefix+"destination");
 groups = document.getElementById(prefix+"groups");

  if(dest && dest.value==0)
  {
   callReport('reports/creport.asp?pGroupID=' + groups.value + '&TC_REPORT_NAME=Competencies_by_group&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination" );
  }
  else
  {
   callReport(this.TCPathToTopClass + '-plugin-reports-CompetenciesByGroup-' + groups.value + '-' + userLangNum + '' + '-PDF','');
  }
}

function upcomingcompetencybyGroup(prefix)
{
 dest = document.getElementById(prefix+"destination");
 groups = document.getElementById(prefix+"groups");
 weeks = document.getElementById(prefix+"upcomingWeeks");
 assigns = document.getElementById(prefix+"assignments");
 members = document.getElementById(prefix+"members");
 filter = document.getElementById(prefix+"filter");

  if(dest && dest.value==0)
  {
   callReport('reports/creport.asp?pGroupID=' + groups.value + '&pWeeks=' + weeks.value + '&TC_REPORT_NAME=UpComing_Compliance_by_Group&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination" );
   }
  else
  {
   callReport(this.TCPathToTopClass + '-plugin-reports-CompetenciesByGroup-' + groups.value + '-' + userLangNum + '-' + weeks.value +'-PDF','');
  }
}
*/

function competencybyRegBody(prefix)
{
 dest = document.getElementById(prefix+"destination");
 regbody = document.getElementById(prefix+"regulatoryBody");
 if (regbody && regbody.value != "")
 {
   if (dest && dest.value==0)
   {
     callReport('reports/creport.asp?pBodyID=' + regbody.value + '&TC_REPORT_NAME=Competency_by_reg_body&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection,prefix+"destination" );
    }
    else
    {
     callReport(this.TCPathToTopClass + '-plugin-reports-CompetenciesByRegBody-' + regbody.value +  '-' + userLangNum + '-' + '-PDF','');
    }
  }
  else
  {
     alert('Insufficient data to run report');
  }
}

function complianceByCompetency(prefix)
{
 dest = document.getElementById(prefix+"destination");
 goals = document.getElementById(prefix+"goals");
 if (goals && goals.value != "")
 {
   if (dest && dest.value==0)
   {
     callReport('reports/creport.asp?pGoal_ID=' + goals.value + '&TC_REPORT_NAME=Compliance_by_Competency&pLangID=' + userLangNum + '&ConnID=' + this.TCConnection, prefix+"destination" );
    }
    else
    {
     callReport(this.TCPathToTopClass + '-plugin-reports-ComplianceByCompetency-' + goals.value +  '-' + userLangNum + '-' + '-PDF','');
    }
  }
  else
  {
     alert('Insufficient data to run report');
  }

}

////////////////////////////////////////////////////////////


function sched_managedStudentsComp(prefix,email)
{
 studid = document.getElementById(prefix+"name");
 filter = document.getElementById(prefix+"filter");
 if (studid && studid.value != "")
 {
  if (email != "" )
  {
     callReport(TCPathToTopClass + 'reportschedule-Compliance_by_User-' + this.TCConnection + "-" + email + "-numberParams-3-" + userLangNum + "-" + studid.value + '-'  + filter.value ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
  }
  else
  {
    alert("Users email address is empty. Scheduled reports require an email address");
  }
 }

}

function sched_instr_student_progress(prefix,email)
{
  studName = document.getElementById(prefix+"student");
   if (studName && studName.value)
   {
     if(email!= "")
     {
       callReport(TCPathToTopClass + 'reportschedule-student_progress-' + this.TCConnection + "-" + email + "-numberParams-2-" + studName.value + '-'  + userLangNum ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function sched_instr_studentcourseprogress(prefix,email)
{
   classid = document.getElementById(prefix+"class");
   studid = document.getElementById(prefix+"student");
   if (studid && studid.value && classid && classid.value)
   {
     if(email != "")
     {
       callReport(TCPathToTopClass + 'reportschedule-student_course_progress-' + this.TCConnection + "-" + email + "-numberParams-3-" + classid.value + "-" + userLangNum + "-" + studid.value  ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function sched_instr_studenttestprogress(prefix,email)
{
   classid = document.getElementById(prefix+"class");
   studid = document.getElementById(prefix+"student");
   if (studid && studid.value && classid && classid.value)
   {
     if(email != "")
     {
       callReport(TCPathToTopClass + 'reportschedule-Student_Test_Progress-' + this.TCConnection + "-" + email + "-numberParams-3-" + classid.value + "-" + userLangNum + "-" + studid.value  ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}


function sched_instr_test_effectiveness(prefix,email)
{
   classid = document.getElementById(prefix+"class");
   exerid = document.getElementById(prefix+"exercise");
   if (classid && classid.value && exerid && exerid.value)
   {
     if(email != "")
     {
       callReport(TCPathToTopClass + 'reportschedule-Test_Effectiveness-' + this.TCConnection + "-" + email + "-numberParams-3-" + userLangNum + "-" + classid.value + "-" + exerid.value  ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function sched_instr_alltests(prefix,email)
{
   classid = document.getElementById(prefix+"class");
   if (classid && classid.value)
   {
     if(email != "")
     {
       callReport(TCPathToTopClass + 'reportschedule-All_tests-' + this.TCConnection + "-" + email + "-numberParams-2-" + classid.value +  "-" + userLangNum ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}

function sched_instr_studenttests(prefix,email)
{
   classid = document.getElementById(prefix+"class");
   studname = document.getElementById(prefix+"student");
   if (classid && classid.value && studname && studname.value)
   {
     if(email != "")
     {
       callReport(TCPathToTopClass + 'reportschedule-Student_Test_Progress-' + this.TCConnection + "-" + email + "-numberParams-3-" + classid.value + "-" + userLangNum + "-" + studname.value ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
   }
   else
   {
     alert('Insufficient data to run report');
   }
}
function sched_studentprogress(prefix,email)
{
     if(email != "")
     {
       callReport(TCPathToTopClass + 'reportschedule-student_progress-' + this.TCConnection + "-" + email + "-numberParams-2-" + userid + '-'  + userLangNum ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");

     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
}

function sched_attendees(destination_id,email)
{
     if(email != "")
     {
     callReport(TCPathToTopClass + 'reportschedule-ILTWBTStudents-' + this.TCConnection + "-" + email + "-numberParams-2-" + document.getElementById("attendees").value  + "-" + userLangNum ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
     else
     {
       alert("Users email address is empty. Scheduled reports require an email address");
     }
}
function sched_managedStudents(prefix,email)
{
     studName = document.getElementById(prefix+"name");
     if (studName && studName.value != "")
     {
       if(email != "")
       {
         callReport(TCPathToTopClass + 'reportschedule-student_progress_specific_wbt-' + this.TCConnection + "-" + email + "-numberParams-2-" + userLangNum + "-" + studName.value  ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
       }
       else
       {
         alert("Users email address is empty. Scheduled reports require an email address");
       }
     }
    else
    {
      alert('Insufficient data to run report');
    }
}


function sched_managedGroups(prefix,email)
{
 group = document.getElementById(prefix+"groups");
 orderby = document.getElementById(prefix+"orderby");
 if (group && group.value != "")
 {
   if (orderby.value == 'Class')
   {
      if (email != "")
      {
         callReport(TCPathToTopClass + 'reportschedule-groupprogress_byclass-' + this.TCConnection + "-" + email + "-numberParams-2-" + userLangNum + "-" + group.value ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
      }
      else
      {
       alert("Users email address is empty. Scheduled reports require an email address");
      }
   }
   else
   {
      if (email != "")
      {
         callReport(TCPathToTopClass + 'reportschedule-groupprogress_bystudent-' + this.TCConnection + "-" + email + "-numberParams-2-" + userLangNum + "-" + group.value ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
      }
      else
      {
       alert("Users email address is empty. Scheduled reports require an email address");
      }
   }
 }
 else
 {
   alert('Insufficient data to run report');
 }

}


function sched_competencybyGroup(prefix,email)
{
 groups = document.getElementById(prefix+"groups");
 mode = document.getElementById(prefix+"assignments");
 members = document.getElementById(prefix+"members");
 filter = document.getElementById(prefix+"filter");
 suppress = document.getElementById(prefix+"suppress");

  if (
      groups && groups.value
      && mode && mode.value
      && members && members.value
      && filter && filter.value)
  {
    if(email != "")
    {
     callReport(TCPathToTopClass + 'reportschedule-Competencies_by_group-' + this.TCConnection + "-" + email + "-numberParams-6-" + groups.value + "-" + userLangNum + "-" + mode.value + "-" + members.value + '-'  + filter.value + "-" + suppress.value,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
    }
    else
    {
       alert("Users email address is empty. Scheduled reports require an email address");
    }
  }
  else
  {
    alert('Insufficient data to run report');
  }
}

function sched_upcomingcompetencybyGroup(prefix,email)
{
 groups = document.getElementById(prefix+"groups");
 mode = document.getElementById(prefix+"assignments");

 members = document.getElementById(prefix+"members");
 filter = document.getElementById(prefix+"filter");

 weeks = document.getElementById(prefix+"upcomingWeeks");

  if(
     (groups && groups.value != "")
  && (mode && mode.value != "")
  && (members && members.value != "")
  && (filter && filter.value != "")
  && (weeks && weeks.value != "")
  )
  {
    if(email != "")
    {
     callReport(TCPathToTopClass + 'reportschedule-UpComing_Compliance_by_Group-' + this.TCConnection + "-" + email + "-numberParams-6-" + groups.value + "-" + userLangNum + "-"  + mode.value + '-' + members.value + "-" + filter.value + "-" + weeks.value ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
     }
    else
    {
       alert("Users email address is empty. Scheduled reports require an email address");
    }
  }
  else
  {
    alert('Insufficient data to run report');
  }
}


function sched_competencybyRegBody(prefix,email)
{
 regbody = document.getElementById(prefix+"regulatoryBody");
 if (regbody && regbody.value != "")
 {
   if (email != "")
   {
     callReport(TCPathToTopClass + 'reportschedule-Competency_by_reg_body-' + this.TCConnection + "-" + email + "-numberParams-2-" + regbody.value + "-" + userLangNum ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
    }
    else
    {
       alert("Users email address is empty. Scheduled reports require an email address");
    }
  }
  else
  {
     alert('Insufficient data to run report');
  }
}

function sched_complianceByCompetency(prefix,email)
{
 goals = document.getElementById(prefix+"goals");
 if (goals && goals.value != "")
 {
   if (email != "")
   {
     callReport(TCPathToTopClass + 'reportschedule-Compliance_by_Competency-' + this.TCConnection + "-" + email + "-numberParams-2-" + userLangNum + "-" + goals.value ,"","resizable=yes,width=950,height=600,left=200,top=200,titlebar=yes");
    }
    else
    {
       alert("Users email address is empty. Scheduled reports require an email address");
    }
  }
  else
  {
     alert('Insufficient data to run report');
  }

}
////////////////////////////////////////////////////////////




function toggleSubMenu(obj)
{
  if (is.ns6 || window.event.srcElement.tagName == "LI" || window.event.srcElement.tagName=="DIV")
  {
    elem = document.getElementById(obj.id + "_details");
    if (elem)
    {
      if (elem.style.display =="")
      {
        elem.style.display = "none";
      }
      else
      {
        elem.style.display = "";
      }
    }
  }
}

function SwitchDivs( id1, id2 )
  {
    div1 = document.getElementById(id1);
    div2 = document.getElementById(id2);
    div1.style.visibility='hidden';
    div2.style.visibility='';
  }

/******************************* Reports end ***************************************/

/*
setTimeout("highlightAHREFJavascript()",2000);

function highlightAHREFJavascript()
{
  var elems = document.getElementsByTagName("A")
  for (var loop = 0; loop < elems.length; loop ++)
  {
    if (elems[loop].href.toLowerCase().indexOf("popup") != -1)
    {
        create508Warning(elems[loop],"popup","popup508");
        //elems[loop].setAttribute("popup",elems[loop].href);
    }
    else if (elems[loop].href.toLowerCase().indexOf("javascript:") != -1)
    {
        //elems[loop].setAttribute("js",elems[loop].href);
        create508Warning(elems[loop],"javascript","js508");
    }
  }
  elems = document.getElementsByTagName("IMG")
  for (var loop = 0; loop < elems.length; loop ++)
  {
    if (elems[loop].getAttribute("alt") == null)
    {
        //elems[loop].setAttribute("noalt",elems[loop].getAttribute("src") + " no alt");
        create508Warning(elems[loop],elems[loop].src + " no alt","alt508");
    }
  }
  elems = document.getElementsByTagName("INPUT")
  for (var loop = 0; loop < elems.length; loop ++)
  {
    if (elems[loop].onclick)
    //if (elems[loop].type.toLowerCase() == "button")
    {
      onclick = elems[loop].onclick.toString().toLowerCase();

      if ((onclick.indexOf('popup') != -1)  || (onclick.indexOf('window.open') != -1))
      {
        create508Warning(elems[loop],"popup","popup508");
      }
      else if (onclick != "")
      {
        create508Warning(elems[loop],"javascript","js508");
      }
    }
    if ((requiresLabel(elems[loop].type.toLowerCase())) && (!hasParent(elems[loop],"LABEL")))
    {
          // check to see if a label has a for element that points to this input.
          labels = document.getElementsByTagName("LABEL");
          var found=false;
          for (var i = 0; i < labels.length; i ++)
          {
              if (labels[i].getAttribute("for") == elems[loop].id)
              {
                found=true;
                break;
              }
          }
          if (!found)
          {
                create508Warning(elems[loop],"missing label","nolabel508" );
          }

    }
  }
  elems = document.getElementsByTagName("SELECT");
  for (loop = 0; loop < elems.length; loop ++)
  {
    if (!hasParent(elems[loop],"LABEL"))
    {
        labels = document.getElementsByTagName("LABEL");
        var found=false;
        for (var i = 0; i < labels.length; i ++)
        {
            if (labels[i].getAttribute("for") == elems[loop].id)
            {
              found=true;
              break;
            }
        }
        if (!found)
        {
          create508Warning(elems[loop],"nolabel ","nolabel508");
        }
    }
  }
  elems = document.getElementsByTagName("TH");
  for (loop = 0; loop < elems.length; loop ++)
  {
      //if (!hasParent(elems[loop],"THEAD"))
      if (!elems[loop].getAttribute("scope"))
      {
        thespan = document.createElement("SPAN");
        thespan.className="th508";
        thespan.appendChild(document.createTextNode("TH has no scope"));
        elems[loop].appendChild(thespan);
      }

  }
}

function requiresLabel(type)
{
  return ((type != "image") && (type != "submit") && (type != "button") && (type != "hidden"))
}


function hasParent(obj,type,dbg)
{
  if (!obj)
  {
    return false;
  }
  if ((obj.tagName != "BODY") || (obj.tagName!="FORM"))
  {
    if (obj.tagName==type)
    {
      return true;
    }
    else
    {
      return hasParent(obj.parentNode,type);
    }
  }
  else
  {
    return false;
  }
}

function create508Warning(element,warning,className)
{
   thediv = document.createElement("DIV");
   thediv.className="rule508";
   element.parentNode.insertBefore(thediv,element);
   thediv.appendChild(element);
   //elems[loop].parentNode.removeChild(elems[loop]);
   thespan = document.createElement("SPAN");
   thespan.className=className;
   thespan.appendChild(document.createTextNode(warning));
   thediv.appendChild(thespan);

}
*/

// Is object, moved from dragndrop.js
// Change #9123 - Extended Is object with additional logic from dhtmlnirvana.com, now gets os versions and versions of browsers
//                other than Netscape & IE
// browser sniffing functionality [http://dhtmlnirvana.com]
function Is()
{
  agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);

  //WINDOWS CHECK


  this.win = ( (agent.indexOf("win")!=-1) || (agent.indexOf("16bit")!=-1) );
  this.win95 = ((agent.indexOf("win95")!=-1) || (agent.indexOf("windows 95")!=-1));
  this.win16 = ((agent.indexOf("win16")!=-1) ||
          (agent.indexOf("16bit")!=-1) || (agent.indexOf("windows 3.1")!=-1) ||
          (agent.indexOf("windows 16-bit")!=-1) );
  this.win31 = ((agent.indexOf("windows 3.1")!=-1) || (agent.indexOf("win16")!=-1) ||
          (agent.indexOf("windows 16-bit")!=-1));
  this.win98 = ((agent.indexOf("win98")!=-1) || (agent.indexOf("windows 98")!=-1));
  this.winnt = ((agent.indexOf("winnt")!=-1) || (agent.indexOf("windows nt")!=-1));
  this.winnt4 = (agent.indexOf("windows nt 4.0")!=-1);
  this.winnt5 = (agent.indexOf("windows nt 5.0")!=-1);
  this.winnt6 = (agent.indexOf("windows nt 6.0")!=-1);
  this.win2pro = (agent.indexOf("win2000pro")!=-1);
  this.win21 = (agent.indexOf("windows 2001")!=-1);
  this.wince = (agent.indexOf("windows ce")!=-1);
  this.winxp = (agent.indexOf("windows xp")!=-1);

  // NETSCAPE SNIFFS


  this.ns = ((agent.indexOf('mozilla')!=-1) && (agent.indexOf('spoofer')==-1)
  && (agent.indexOf('compatible') == -1) && (agent.indexOf('opera')==-1)
  && (agent.indexOf('webtv')==-1));
  this.ns2 = (this.ns && (this._major == 2));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4 = (this.ns && (this.major == 4));
  this.ns40 = (this.ns && (this.major == 4) && (agent.indexOf('4.0 ')!=-1));
  this.ns401 = (this.ns && (this.major == 4) && (agent.indexOf('4.01')!=-1));
  this.ns02 = (this.ns && (this.major == 4) && (agent.indexOf('4.02')!=-1));
  this.ns03 = (this.ns && (this.major == 4) && (agent.indexOf('4.03')!=-1));
  this.ns04 = (this.ns && (this.major == 4) && (agent.indexOf('4.04')!=-1));
  this.ns05 = (this.ns && (this.major == 4) && (agent.indexOf('4.05')!=-1));
  this.ns06 = (this.ns && (this.major == 4) && (agent.indexOf('4.06')!=-1));
  this.ns07 = (this.ns && (this.major == 4) && (agent.indexOf('4.07')!=-1));
  this.ns08 = (this.ns && (this.major == 4) && (agent.indexOf('4.08')!=-1));
  this.ns450 = (this.ns && (this.major == 4) && (agent.indexOf('4.50')!=-1));
  this.ns451 = (this.ns && (this.major == 4) && (agent.indexOf('4.51')!=-1));
  this.ns46 = (this.ns && (this.major == 4) && (agent.indexOf('4.6')!=-1));
  this.ns461 = (this.ns && (this.major == 4) && (agent.indexOf('4.61')!=-1));
  this.ns47 = (this.ns && (this.major == 4) && (agent.indexOf('4.7')!=-1));
  this.ns472 = (this.ns && (this.major == 4) && (agent.indexOf('4.72')!=-1));
  this.ns473 = (this.ns && (this.major == 4) && (agent.indexOf('4.73')!=-1));
  this.ns474 = (this.ns && (this.major == 4) && (agent.indexOf('4.74')!=-1));
  this.ns475 = (this.ns && (this.major == 4) && (agent.indexOf('4.75')!=-1));
  this.ns476 = (this.ns && (this.major == 4) && (agent.indexOf('4.76')!=-1));
  this.ns48 = (this.ns && (this.major == 4) && (agent.indexOf('4.8')!=-1));
  this.ns6 = (this.ns && (this.major == 6));
  this.ns7 = (this.ns && (this.major == 7));
  this.ns7up = (this.ns && (this.major >= 6));


  //MOZILLA-SPECIFIC CHECK

  this.ns6pr1 = (this.ns && (this.major == 5)&&(agent.indexOf('6.0b1')!=-1));
  this.ns6pr2 = (this.ns && (this.major == 5)&&(agent.indexOf('6.0b2')!=-1));
  this.ns6pr3 = (this.ns && (this.major == 5)&&(agent.indexOf('6.0b3')!=-1));
  this.ns6gold = (this.ns && (this.major == 5) && (agent.indexOf('netscape')!=-1) && !this.ns6pr1 && !this.ns6pr2 && !this.ns6pr3);
  this.moz = (this.ns && (this.major >= 5) && (agent.indexOf('netscape')==-1));
  if(this.ns6)
  {
    if (agent.indexOf('; m')!=-1)
    {
      MSnumStart = agent.indexOf('; m') + 3;
      MSnumEnd = MSnumStart +2;
      MSnum = agent.substring(MSnumStart, MSnumEnd);
      mozmile = Number(MSnum);
    }
    else
    {
    mozmile = 'cannot obtain milestone number';
  }
  }
  else
  {
    mozmile = 'not a mozilla or netscape user agent';
  }
  this.mozBased = (agent.indexOf('gecko')!=-1);
  if(this.mozBased)
  {
    GeckoBuildIDStart = agent.indexOf('gecko') + 6;
    GeckoBuildIDEnd = GeckoBuildIDStart + 8;
    GeckoBuildIDnum = agent.substring(GeckoBuildIDStart, GeckoBuildIDEnd);
    GeckoBuildID = Number(GeckoBuildIDnum);
  }
  else
  {
    GeckoBuildID = 'cannot obtain gecko build #';
  }


  //MSIE CHECK


  this.ie = ((agent.indexOf("msie") != -1)&& (agent.indexOf('opera')==-1));
  this.winie = (this.win && this.ie);
  this.ie3 = (this.ie && (this.major < 4) && !this.ie6);
  this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 4")!=-1) );
  this.ie401 = (this.ie && (this.major == 4) && (agent.indexOf("msie 4.01")!=-1) );
  this.ie4up = (this.ie && (this.major >= 4));
  this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5")!=-1) );
  this.ie51 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.01")!=-1) );
  this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5")!=-1) );
  this.ie5up = (this.ie && !this.ie3 && !this.ie4);
  this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1) );
  this.ie7 = (this.ie && (agent.indexOf("msie 7.0")!=-1) );
  this.ie8 = (this.ie && (agent.indexOf("msie 8.0")!=-1) );
  this.ie6up = (this.ie && (this.ie6 || this.ie7 || this.ie8));

  // AOL CHECKS


  this.aol = (agent.indexOf("aol") != -1);
  this.aolandie3 = (this.aol && this.ie3);
  this.aolandie4 = (this.aol && this.ie4);
  this.aolandie5 = (this.aol && this.ie5);
  this.aol3 = (agent.indexOf("aol 3") != -1);
  this.aol4 = (agent.indexOf("aol 4") != -1);
  this.aol5 = (agent.indexOf("aol 5") != -1);
  this.aol6 = (agent.indexOf("aol 6") != -1);
  this.aol7 = (agent.indexOf("aol 7") != -1);
  this.aol8 = (agent.indexOf("aol 8") != -1);


  //MAC CHECK


  this.mac = (agent.indexOf("mac")!=-1);
  this.mac68k = (this.mac && ((agent.indexOf("68k")!=-1) ||
          (agent.indexOf("68000")!=-1)));
  this.macppc = (this.mac && ((agent.indexOf("ppc")!=-1) ||
          (agent.indexOf("powerpc")!=-1)));
  //MAC MSIE CHECK
  this.macie = (this.mac && this.ie);
  this.macie4 = (this.mac && (agent.indexOf("msie 4")!=-1));
  this.macie401 = (this.mac && (agent.indexOf("msie 4.01")!=-1));
  this.macie45 = (this.mac && (agent.indexOf("msie 4.5")!=-1));
  this.macie5 = (this.mac && (agent.indexOf("msie 5.0")!=-1));
  this.macie6 = (this.mac && (agent.indexOf("msie 6.0")!=-1));
  // MAC SAFARI
  this.safari = (this.mac && (agent.indexOf("safari")!=-1));


  //OPERA CHECK


  this.opera = (agent.indexOf("opera") != -1);
  this.opera3 = (this.opera && (agent.indexOf(") 3.0") != -1));
  this.opera321 = (this.opera && (agent.indexOf(") 3.21") != -1));
  this.opera351 = (this.opera && (agent.indexOf(") 3.51") != -1));
  this.opera360 = (agent.indexOf("opera 3.60") != -1);
  this.opera361 = (agent.indexOf("opera 3.61") != -1);
  this.opera362 = (agent.indexOf("opera 3.62") != -1);
  this.opera4 = (agent.indexOf("opera 4") != -1);
  this.opera5 = (agent.indexOf("opera 5") != -1);
  this.opera51 = (agent.indexOf("opera 5.1") != -1);
  this.opera52 = (agent.indexOf("opera 5.2") != -1);
  this.opera6 = (agent.indexOf("opera 6") != -1);
  this.opera7 = (agent.indexOf("opera 7") != -1);


  //WEB TV CHECK


  this.webtv = (agent.indexOf("webtv") != -1);
  this.webtv12 = this.webtv && (agent.indexOf("1.2") != -1);
  this.webtv22 = this.webtv && (agent.indexOf("2.2") != -1);

}

var is = new Is();


function removeDuplicateAttendees()
{
    //Nicholas Murphy 12-May-2005  chances are there could be duplication in the above options. So
    // go through the options and removes the copies.
elem = document.getElementById("attendees");
if (elem)
{
  var my_options = elem.childNodes;
  var len = my_options.length;
  while (len > 0)
  {
    for (var loop = len-2; loop >= 0; loop--)
    {
      if (my_options[loop].value == my_options[len-1].value)
      {
        // this one has already appeared
        elem.removeChild(my_options[len-1]);
        break;
      }
    }
    len--;
  }
}
}

function getObjectsFromObject(obj,objType,arr)
{
  for (var loop = 0; loop < obj.childNodes.length; loop ++)
  {
    if (obj.childNodes[loop].tagName && (obj.childNodes[loop].tagName.toLowerCase() == objType))
    {
      arr[arr.length] = obj.childNodes[loop];
    }
    //getObjectsFromObject(obj.childNodes[loop],objType,arr);
  }
}

function toggleTableContext(cntxt,body,selct)
{
// cntxt is the tr's we want to keep
// body is the id of the table body we want to change.
  tbdy = document.getElementById(body);
  if (tbdy)
  {
    trows = new Array();
    getObjectsFromObject(tbdy,"tr",trows);
    for (var loop = 0; loop < trows.length; loop ++)
    {
      if (trows[loop].getAttribute("name") == cntxt)
      {
        trows[loop].style.display = "";
      }
      else
      {
        trows[loop].style.display="none";
      }
  }
  //Nicholas Murphy 31-Mar-2006  ensure that the selectedIndex matches the input line being shown.
  if (selct)
  {
    sel = document.getElementById(selct);
    if (sel)
    {
      var opts = sel.options;
      for (var loop = 0; loop < opts.length; loop ++)
      {
        if (opts[loop].value == cntxt)
        {
          sel.selectedIndex = loop;
          break;
        }
      }
    }
    else
    {
      alert("didn't find select" + selct);
    }
  }
}
}

function PressButton( name )
  {
    //alert( "PressButton " + name );
    var button = document.getElementById(name);
    if ( button && typeof(button.click) != "undefined" )
      {
        button.click();
      }
    else
      {
        //alert( "No Button " + name );
      }
  }
/*
   Used to add filter criteria to a popup select.
*/
function AddLikeArgs( button, name )
  {
    if ( button.form.elements['find'+name] )
      {
        val = button.form.elements['find'+name].value;
        return "%26" + name + "op%3Dlike"
             + "%26find" + name + "%3D" + escape( val );
      }
    else
      {
        return "";
      }
  }

function CheckAll(sSection, parentCheck, childPrefix) {
  var oSection = document.getElementById(sSection);
  var bChecked = false;

  if (oSection != null)
  {
    var checks = oSection.getElementsByTagName('INPUT');
    var currentcheckid;
    var checksLen = checks.length;

    for ( var i = 0; i < checksLen; i++ )
    {
      currentcheckid = checks[i].id;
      if(currentcheckid.indexOf(parentCheck) != -1 && checks[i].type=="checkbox")
      {
       if(checks[i].checked == false)
          bChecked = false;
       else
          bChecked = true;
       break;
      }
    }

    // Check/Uncheck checkboxes in appropriate section
    for ( var i = 0; i <= checksLen-1; i++ ) {
      currentcheckid = checks[i].id;
      if((currentcheckid.indexOf(childPrefix) != -1) && (checks[i].disabled != true) && checks[i].type=="checkbox")
      {
          checks[i].checked = bChecked;
      }
    }
  }
}

function VerifyURL(urlField)
{
  var url = document.getElementById(urlField).value;
  if (url != ""){
    var has_http = url.match(/^http:\/\//) || url.match(/^https:\/\//);
    if (!has_http)
    {
      url = "http://" + url;
    }
    TCOpenPopup(url,"vurl","");
  }
  return false;
}

function VerifyURLValue(url)
{
  var has_http = url.match(/^http:\/\//) || url.match(/^https:\/\//);
  if (!has_http)
  {
    url = "http://" + url;
  }
  TCOpenPopup(url,"vurl","");
  return false;
}

function DateSelectOnclick(button,tag)
{
  if( TCUseYUI ){
    TCSetYUIDateField( button,
                       button.form.elements[tag+'day'],
                       button.form.elements[tag+'month'],
                       button.form.elements[tag+'year'] );
  }
  else {
    setDateField( button.form.elements[tag+'day'],
                  button.form.elements[tag+'month'],
                  button.form.elements[tag+'year'] );
    top.newWin = window.open('cal/calendar.html', 'cal', 'dependent=yes, width=230, height=230, screenX=200, screenY=300, titlebar=yes');
  }
}

/*
    Start of topclass 8 functions
*/

var TCUsePanels = true;
var TCUseFragments = true;
var TCPanelParams = new Object();

/***
  addClass creates a regular expression pattern containing the class to be added.
  It then uses this pattern to test the current className value.
  If the class name doesn't already exist, we check for an empty className value
  (in which case the class name is assigned to the property verbatim),
  or we append to the existing value a space and the new class name.
***/
function addClass(target, classValue)
{
 var pattern = new RegExp("(^| )" + classValue + "( |$)");

 if (!pattern.test(target.className))
 {
   if (target.className == "")
   {
     target.className = classValue;
   }
   else
   {
     target.className += " " + classValue;
   }
 }

 return true;
}

/***
  After removeClass has executed the replacement regular expression on a copy of
  the className property's value, it cleans up the resulting value by removing
  any trailing space (which is created when we remove the last class in a multiple
  class className), then assigns it back to the target's className.
***/
function removeClass(target, classValue)
{
 var removedClass = target.className;
 var pattern = new RegExp("(^| )" + classValue + "( |$)");

 removedClass = removedClass.replace(pattern, "$1");
 removedClass = removedClass.replace(/ $/, "");

 target.className = removedClass;

 return true;
}

/***
  The first two if statements deal with the standards-based and Internet Explorer
  methods respectively, but the catch-all else deals with older browsers that don't
  support either of these methods, particularly Internet Explorer 5 for Mac.
  In this last case, a DOM 0 event handler is used, but to ensure that multiple functions
  can be used to handle a single event for a particular element, a closure is used to
  execute any existing functions that are attached to the event.
***/
function attachEventListener(target, eventType, functionRef, capture)
{
 if (typeof target.addEventListener != "undefined")
 {
   target.addEventListener(eventType, functionRef, capture);
 }
 else if (typeof target.attachEvent != "undefined")
 {
   target.attachEvent("on" + eventType, functionRef);
 }
 else
 {
   eventType = "on" + eventType;

   if (typeof target[eventType] == "function")
   {
     var oldListener = target[eventType];

     target[eventType] = function()
     {
       oldListener();

       return functionRef();
     };
   }
   else
   {
     target[eventType] = functionRef;
   }
 }
}


/***
  Internet Explorer uses the detachEvent method, while the standards-compliant
  browsers instead specify a method called removeEventListener. Each of these
  methods operates fairly similarly to its listener-adding counterpart: an event
  type must be supplied along with the function that was assigned to handle that
  event type. The standard method also demands to know whether the event handler
  was registered to respond during the capture or bubble phase.
**/
function detachEventListener(target, eventType, functionRef, capture)
{
 if (typeof target.removeEventListener != "undefined")
 {
   target.removeEventListener(eventType, functionRef, capture);
 }
 else if (typeof target.detachEvent != "undefined")
 {
   target.detachEvent("on" + eventType, functionRef);
 }
 else
 {
   target["on" + eventType] = null;
 }
}


function getElementsByAttribute(attribute, attributeValue)
{
 var elementArray = new Array();
 var matchedArray = new Array();

 if (document.all)
 {
   elementArray = document.all;
 }
 else
 {
   elementArray = document.getElementsByTagName("*");
 }

 for (var i = 0; i < elementArray.length; i++)
 {
   if (attribute == "class")
   {
     var pattern = new RegExp("(^| )" +
         attributeValue + "( |$)");

     if (pattern.test(elementArray[i].className))
     {
       matchedArray[matchedArray.length] = elementArray[i];
     }
   }
   else if (attribute == "for")
   {
     if (elementArray[i].getAttribute("htmlFor") ||
         elementArray[i].getAttribute("for"))
     {
       if (elementArray[i].htmlFor == attributeValue)
       {
         matchedArray[matchedArray.length] = elementArray[i];
       }
     }
   }
   else if (elementArray[i].getAttribute(attribute) ==
       attributeValue)
   {
     matchedArray[matchedArray.length] = elementArray[i];
   }
 }

 return matchedArray;
}

function hasClass( sClassNames, sSearchName )
{
  var pattern = new RegExp("(^| )" + sSearchName + "( |$)");

  if ( pattern.test( sClassNames ) )
  {
    return ( true );
  }

  return ( false );
}

function getTCTabSeparators()
{
  return ( getElementsByAttribute("class", "JSTabSeparator") );
}

function getTCTabFormLinks()
{
  return ( getElementsByAttribute("class", "JSTabFormLink") );
}

function getTCTabSections()
{
  return ( getElementsByAttribute("class", "JSTabSection") );
}


/**
 * Generate Navigation Tabs for Forms
 *
 * param sTabsContainer: String id of container on document to show tabs
 * param sDefaultTab: String id of tab to default for display
 * param lngObjID: id of object for display
 * param sCookieID: id of cookie to use
 * param blnTCSections: Whether sections are used on a single page
 * return: None
 * NOTE: RENDERED OBSOLETE BY TCDRAWTABS() FUNCTION
 */
function drawTCTabs( sTabsContainer, sDefaultTab, lngObjID, sCookieID, blnTCSections )
{
  var TCTabSeparators = getTCTabSeparators();
  var TCTabSections = getTCTabSections();
  var nTCTabSeparators = TCTabSeparators.length;
  var nTCTabSections = TCTabSections.length;

  if ( !( nTCTabSeparators > 0 ) || ( nTCTabSeparators != nTCTabSections ) )
  {
    return ( alert( "Error generating tabs!" ) );
  }

  var sClass;
  var blnOnClick;
  var blnFormLink
  var sTCTabsHTML = "<ul>";

  try {
    for ( var i = 0; i < nTCTabSeparators; i++ )
    {
      blnOnClick = true;
      blnFormLink = false;
      sClass = "";
      // Check for disabled tabs
      if ( hasClass( TCTabSeparators[i].className, "JSTabDisabled" ) )
      {
        sClass = "TCTabDisabled";
        blnOnClick = false;
      }

      // Check for formlink tabs
      if ( hasClass( TCTabSeparators[i].className, "JSTabFormLink" ) )
      {
        blnFormLink = true;
      }

      sTCTabsHTML += "<li id=\"TCTab_" + TCTabSections[i].id + "\" class=\"" + sClass + "\" >";
      sTCTabsHTML += "<span id=\"gotoTCTab_" + TCTabSections[i].id + "\" ";
      if ( blnOnClick )
      {
        if ( blnFormLink ) {
          // Find associated FormLink button
          var sFormLinkID = TCTabSections[i].id.split( "_section" )[0];
          // Hide associated FormLink button(s)
          if ( document.getElementById("FormLink" + sFormLinkID + "_2") ) {
            // Hide associated FormLink button(s)
            var cmdFormLink = document.getElementById( "FormLink" + sFormLinkID + "_2" );
            addClass( cmdFormLink, "TCDisplayNone" );
            if ( cmdFormLink.nextSibling ) {
              var buttonSeparator = cmdFormLink.nextSibling;
              if ( hasClass( buttonSeparator.className, "TCSeparator" ) ) {
                addClass( buttonSeparator, "TCDisplayNone" );
              }
            }
          }
          sTCTabsHTML += "onclick=\"javascript:goToFormLink('" +  "FormLink" + sFormLinkID + "')\" ";
        }
        else {
          if ( !blnTCSections ) {
            sTCTabsHTML += "onclick=\"javascript:goToTab('" +  TCTabSections[i].id + "')\" ";
          }
          else {
            sTCTabsHTML += "onclick=\"javascript:showTCSection( '" + TCTabSections[i].id + "', " + lngObjID + ", '" + sCookieID + "', getTCTabSections() )\" ";
          }
        }
      }
      sTCTabsHTML += ">" + TCTabSeparators[i].innerHTML + "</span>";
      sTCTabsHTML += "</li>";
    }

    sTCTabsHTML += "</ul>";

    if ( document.getElementById(sTabsContainer) )
    {
      document.getElementById(sTabsContainer).innerHTML = sTCTabsHTML;
    }

    showTCSection( sDefaultTab, lngObjID, sCookieID, blnTCSections );


  } catch (e) {
    return ( alert( "Error generating tabs! " + e.description ) );
  }

}

// *** Supercedes use of drawTCTabs() *** //
function TCDrawTabs( TCTabsParams ) {
  /*
    Params
    TCTabsContainerID         Unique identifier of DOM element to contain tabs
    TCTabsDefault             ID of default tab, 'lk00' - 'lk99'
    TCTabsLabels              Array of Tab label strings
    TCTabsAccessRights        Array of Tab label access rights
    TCTabsRedirects           Array of Custom Tab redirects
    TCTabsForms               Array of Form names for retrieval (jsp only)
    TCTabsJSPForm             String id of Form to be submitted (jsp only)
    TCTabsSaveOnTabSwitch     Boolean whether formdef formlinks are gets or posts
    TCTabsClientSideValid     Boolean whether client-side validation
    TCTabsFormLinks           Boolean whether to use formLinks
  */

  var tabs = new Array();
  var nTabLabels = TCTabsParams.TCTabsLabels.length;
  var nTabAccessRights = TCTabsParams.TCTabsAccessRights.length;
  var nTabForms = 0;
  var nTabRedirects = 0;

  if ( typeof(TCTabsParams.TCTabsForms) != "undefined" ) {
    nTabForms = TCTabsParams.TCTabsForms.length;
  }

  if ( typeof(TCTabsParams.TCTabsSaveOnTabSwitch) == "undefined" ) {
    TCTabsParams.TCTabsSaveOnTabSwitch = true;
  }

  if ( typeof(TCTabsParams.TCTabsClientSideValid) == "undefined" ) {
    TCTabsParams.TCTabsClientSideValid = false;
  }

  if ( typeof(TCTabsParams.TCTabsRedirects) != "undefined" ) {
    nTabRedirects = TCTabsParams.TCTabsRedirects.length;
  }

  if ( nTabLabels != nTabAccessRights ) {
    debugAlert2( 'Error Generating Form Tabs!\n\nNumber of tab labels does not match tab access rights.' );
    strAlert = 'Error Generating Form Tabs!\n\nNumber of tab labels does not match tab access rights.';
  }

  if ( nTabForms > 0 ) {
    if ( nTabLabels != nTabForms ) {
      debugAlert2( 'Error Generating Form Tabs!\n\nNumber of tab labels does not match number of form names.' );
      strAlert = 'Error Generating Form Tabs!\n\nNumber of tab labels does not match number of form names.';
    }
  }

  for ( var i = 0; i < nTabLabels; i++ ) {
    var tab = new Object();
    if ( i < 10 ) {
      tab.id = "lk0" + i;
    }
    else {
      tab.id = "lk" + i;
    }
    tab.label = TCTabsParams.TCTabsLabels[i];
    if ( nTabForms > 0 ) {
      tab.form = TCTabsParams.TCTabsForms[i];
    }
    if ( nTabRedirects > 0 ) {
      tab.redirect = TCTabsParams.TCTabsRedirects[i];
    }
    tab.access = TCTabsParams.TCTabsAccessRights[i];
    tabs[tabs.length] = tab;
  }

  var sClass;
  var blnOnClick;
  var blnFormLink
  var sTCTabsHTML = "<ul>";
  var strAlert = "";

  for ( var i=0;i<tabs.length;i++ ) {
    if ( TCTabsParams.TCTabsFormLinks ) {
      var formLink_top;
      var formLink_bottom;
      if ( !document.getElementById( "FormLink" + tabs[i].id ) ) {
        debugAlert2( 'Error Generating Form Tabs!\n\nCould not find FormLink button [' + "FormLink" + tabs[i].id +']' );
        strAlert = 'Error Generating Form Tabs!\n\nCould not find FormLink button [' + "FormLink" + tabs[i].id +']';
      }
      else {
        formLink_top = document.getElementById( "FormLink" + tabs[i].id );
      }
      if ( !document.getElementById( "FormLink" + tabs[i].id + "_2" ) ) {
        debugAlert2( "Error Generating Form Tabs!\n\nCould not find FormLink button [" + "FormLink" + tabs[i].id +"_2]" );
        strAlert = "Error Generating Form Tabs!\n\nCould not find FormLink button [" + "FormLink" + tabs[i].id +"_2]";
      }
      else {
        formLink_bottom = document.getElementById( "FormLink" + tabs[i].id + "_2" );
      }
      if ( TCTabsParams.TCTabsSaveOnTabSwitch ) {
        // Formlink rendered as input
        if ( formLink_top.value != tabs[i].label ) {
          debugAlert2( "Error Generating Form Tabs!\n\nFormLink value '" + formLink_top.value + "' does not match tab label '" + tabs[i].label + "'" );
          strAlert = "Error Generating Form Tabs!\n\nFormLink value '" + formLink_top.value + "' does not match tab label '" + tabs[i].label + "'";
        }
      } else {
        // Formlink rendered as hyperlink
        if ( formLink_top.innerHTML != tabs[i].label ) {
          debugAlert2( "Error Generating Form Tabs!\n\nFormLink value '" + formLink_top.innerHTML + "' does not match tab label '" + tabs[i].label + "'" );
          strAlert = "Error Generating Form Tabs!\n\nFormLink value '" + formLink_top.innerHTML + "' does not match tab label '" + tabs[i].label + "'";
        }
      }
      if ( formLink_bottom ) {
        // Hide associated FormLink button(s)
        addClass( formLink_bottom, "TCDisplayNone" );
        if ( formLink_bottom.nextSibling ) {
          var buttonSeparator = formLink_bottom.nextSibling;
          if ( hasClass( buttonSeparator.className, "TCSeparator" ) ) {
            addClass( buttonSeparator, "TCDisplayNone" );
          }
        }
      }
    }

    try {
      blnOnClick = true;
      sClass = "";
      // Check for disabled tabs
      if ( tabs[i].access == 0 )
      {
        sClass = "TCTabDisabled";
        blnOnClick = false;
      }

      sTCTabsHTML += "<li id=\"TCTab_" + tabs[i].id + "\" class=\"" + sClass + "\" >";
      sTCTabsHTML += "<span id=\"gotoTCTab_" + tabs[i].id + "\" ";
      if ( blnOnClick )
      {
        if ( TCTabsParams.TCTabsFormLinks ) {
          if ( TCTabsParams.TCTabsSaveOnTabSwitch ) {
            sTCTabsHTML += "onclick=\"javascript:goToFormLink('" +  "FormLink" + tabs[i].id + "'," + TCTabsParams.TCTabsClientSideValid + ")\" ";
          } else {
            sTCTabsHTML += "onclick=\"javascript:goToFormHref('" +  "FormLink" + tabs[i].id + "')\" ";
          }
        } else {
          if ( nTabForms > 0 ) {
          TCTabsParams.TCTabsJSPForm
            sTCTabsHTML += "onclick=\"javascript:goToTab('" +  tabs[i].form + "', '" + TCTabsParams.TCTabsJSPForm + "', " + TCTabsParams.TCTabsClientSideValid + ", '" + tabs[i].redirect + "')\" ";
          }
        }
      }
      sTCTabsHTML += ">" + tabs[i].label + "</span>";
      sTCTabsHTML += "</li>";
    } catch (e) {
      debugAlert2( "Error Generating Form Tabs! " + e.description );
      strAlert = "Error Generating Form Tabs! " + e.description;
    }

  }

  sTCTabsHTML += "</ul>";

  if ( document.getElementById(TCTabsParams.TCTabsContainerID) )
  {
    document.getElementById(TCTabsParams.TCTabsContainerID).innerHTML = sTCTabsHTML;
  }

  if ( document.getElementById( "gotoTCTab_" + TCTabsParams.TCTabsDefault ) )
  {
    addClass(document.getElementById( "gotoTCTab_" + TCTabsParams.TCTabsDefault ), "TCActiveTab" );
  } else{
    debugAlert2( "Error Generating Form Tabs!\n\nNo default tab found!" );
    strAlert = "Error Generating Form Tabs!\n\nNo default tab found!";
  }

  if ( strAlert != "" ) {
   document.getElementById(TCTabsParams.TCTabsContainerID).innerHTML = "<!--" + strAlert + "-->";
   TCAddMesssageInfo( strAlert );
  }
}

/**
 * Go to URL specified by FormLink
 *
 * param sTabID: String id of form tab selected
 * return: none
 */
function goToFormLink( sFormLinkID, bClientSideValid ) {
//if ( fieldsObj ) {
//alert( fieldsObj.fields.length )
//}

  var bContinue = true;
  if ( bClientSideValid ) {
    bContinue = validateForm();
  }
  if ( bContinue ) {
    // Find associated FormLink button
    if ( document.getElementById( sFormLinkID ) ) {
      document.getElementById(sFormLinkID).click();
    }
    else {
      alert( "Unable to find associated FormLink: " + sFormLinkID );
    }
  }

}

/**
 * Go to URL specified by FormLink
 *
 * param sTabID: String id of form tab selected
 * return: none
 */
function goToFormHref( sFormLinkID ) {

  // Find associated FormLink href
  if ( document.getElementById( sFormLinkID ) ) {
    document.location.href = document.getElementById(sFormLinkID).href;
  }
  else {
    alert( "Unable to find associated FormLink: " + sFormLinkID );
  }

}

/**
 * Go to form specified by JSP 'Page' hidden field
 *
 * param strTab: String id of form tab selected
 * param formName: Name of jsp form being submitted
 * param bClientSideValid: Boolean whether to call client-side validation
 * param strTCRedirect: String specify redirect to TopClass
 * return: none
 */
 function goToTab(strTab, formName, bClientSideValid, strTCRedirect){
   var bContinue = true;
   if ( bClientSideValid ) {
     bContinue = validateForm();
   }
   if ( bContinue ) {
     if ( typeof(TCFormTabHelper) != "undefined" ) {
      TCFormTabHelper();
     }
     var oPage = document.getElementById("page");

     if(oPage)
       oPage.value = strTab;

     var oRedirect = document.getElementById("tcredirect");
     if( oRedirect && (strTCRedirect != "") )
       oRedirect.value = strTCRedirect;

     //Submit Form
     document.forms[formName].submit();
   }
 }


/**
 * Show Selected Navigation Tab for Forms
 *
 * param sTCActiveSection: String id of form tab section to display
 * param lngObjID: id of object for display
 * param sCookieID: id of cookie to use
 * param blnTCSections: Whether sections are used on a single page
 * return: none
 */
function showTCSection( sTCActiveSection, lngObjID, sCookieID, blnTCSections )
{
  if ( document.getElementById( sTCActiveSection ) )
  {
    document.getElementById( sTCActiveSection ).style.display = "block";
    addClass(document.getElementById( "gotoTCTab_" + sTCActiveSection), "TCActiveTab" );
  }

  var TCTabSections = getTCTabSections();
  var nTCTabSections = TCTabSections.length;

  for ( var i = 0; i < nTCTabSections; i++ )
  {
    if ( sTCActiveSection != TCTabSections[i].id )
    {
      TCTabSections[i].style.display = "none";
      if(document.getElementById('TCTab_' + TCTabSections[i].id))
      {
        removeClass(document.getElementById( "gotoTCTab_" + TCTabSections[i].id ),"TCActiveTab");
      }
    }
  }

}

function TCInitOpenPanel(TCPanelParams) {
  /*
    Params
    TCPanelPID                  Unique identifier
    TCPanelFragment             Fragment Flag [OPTIONAL]
    TCPanelIcon                 Panel Icon [OPTIONAL]
    TCPanelTitle                Panel title
    TCPanelColor                Panel color [OPTIONAL]
    TCPanelHelpURL              Help URL [OPTIONAL]
    TCPanelActionsHTML          HTML contained in Panel Actions [OPTIONAL]
    TCPanelAllowExpandCollapse  Whether the panel can expand / collapse [OPTIONAL]
    TCPanelCookieExpandCollapse Whether to use cookie value for panel expand / collapse [OPTIONAL]
    TCPanelExpanded             Initial expanded state - true: expanded [OPTIONAL]
    TCPanelPrintableURL         Print url [OPTIONAL]
    TCPanelViewAllURL           View more url [OPTIONAL]
    TCPanelViewFragmentURL      View fragment container url [OPTIONAL]
    TCPanelViewRSSURL           View link to RSS feed url [OPTIONAL]
  */
  if ( TCUsePanels ) {
    if ( YAHOO.tcmodal ) {
      // Don't Use Panel headers for YUI Modal screens as this causes IE error
      TCPanelParams.TCPanelDraw = false;
    }
    // set defaults
    if ( typeof(TCPanelParams.TCPanelDraw) == "undefined" ) {
      TCPanelParams.TCPanelDraw = true;
    }
    if ( TCModalPopupVisible ) {
      TCPanelParams.TCPanelDraw = false;
    }
    if ( typeof(TCPanelParams.TCPanelPID) == "undefined" ) {
      TCPanelParams.TCPanelPID = "TCPanelDefault";
    }
    if ( typeof(TCPanelParams.TCPanelFragment) == "undefined" ) {
      TCPanelParams.TCPanelFragment = false;
    }
    if ( typeof(TCPanelParams.TCPanelIcon) == "undefined" ) {
      //TCPanelParams.TCPanelIcon = TcDirectory() + "icons/topclass8/" + "tc" + TCArgs.toLowerCase() + ".gif";
      TCPanelParams.TCPanelIcon = TcDirectory() + "icons/topclass8/" + "tc_default.gif";
    }
    if ( typeof(TCPanelParams.TCPanelTitle) == "undefined" ) {
      TCPanelParams.TCPanelTitle = sPanelTitle;
    }
    if ( typeof(TCPanelParams.TCPanelAllowExpandCollapse) == "undefined" ) {
      TCPanelParams.TCPanelAllowExpandCollapse = false;
    }
    if ( typeof(TCPanelParams.TCPanelCookieExpandCollapse) == "undefined" ) {
      TCPanelParams.TCPanelCookieExpandCollapse = false;
    }
    if ( typeof(TCPanelParams.TCPanelActionsHTML) == "undefined" ) {
      TCPanelParams.TCPanelActionsHTML = false;
    }
    if ( typeof(TCPanelParams.TCPanelExpanded) == "undefined" ) {
      TCPanelParams.TCPanelExpanded = true;
    }
    if ( typeof(TCPanelParams.TCPanelPrintableURL) == "undefined" ) {
      TCPanelParams.TCPanelPrintableURL = "";
    }
    if ( typeof(TCPanelParams.TCPanelViewAllURL) == "undefined" ) {
      TCPanelParams.TCPanelViewAllURL = "";
    }
    if ( typeof(TCPanelParams.TCPanelViewFragmentURL) == "undefined" ) {
      TCPanelParams.TCPanelViewFragmentURL = "";
    }
    if ( typeof(TCPanelParams.TCPanelViewRSSURL) == "undefined" ) {
      TCPanelParams.TCPanelViewRSSURL = "";
    }
    if ( TCPanelParams.TCPanelDraw ) {
      TCOpenPanel({
       TCPanelPID:TCPanelParams.TCPanelPID,
       TCPanelFragment:TCPanelParams.TCPanelFragment,
       TCPanelIcon:TCPanelParams.TCPanelIcon,
       TCPanelTitle:TCPanelParams.TCPanelTitle,
       TCPanelHelpURL:TCPanelParams.TCPanelHelpURL,
       TCPanelActionsHTML:TCPanelParams.TCPanelActionsHTML,
       TCPanelAllowExpandCollapse:TCPanelParams.TCPanelAllowExpandCollapse,
       TCPanelCookieExpandCollapse:TCPanelParams.TCPanelCookieExpandCollapse,
       TCPanelExpanded:TCPanelParams.TCPanelExpanded,
       TCPanelPrintableURL:TCPanelParams.TCPanelPrintableURL,
       TCPanelViewAllURL:TCPanelParams.TCPanelViewAllURL,
       TCPanelViewFragmentURL:TCPanelParams.TCPanelViewFragmentURL,
       TCPanelViewRSSURL:TCPanelParams.TCPanelViewRSSURL
      });
    }
  }
}

function TCOpenPanel(TCPanelParams) {
  /*
    Params
    TCPanelPID                  Unique identifier
    TCPanelFragment             Fragment Flag [OPTIONAL]
    TCPanelIcon                 Panel Icon [OPTIONAL]
    TCPanelTitle                Panel title
    TCPanelColor                Panel color [OPTIONAL]
    TCPanelHelpURL              Help URL [OPTIONAL]
    TCPanelActionsHTML          HTML contained in Panel Actions [OPTIONAL]
    TCPanelAllowExpandCollapse  Whether the panel can expand / collapse [OPTIONAL]
    TCPanelCookieExpandCollapse Whether to use cookie value for panel expand / collapse [OPTIONAL]
    TCPanelExpanded             Initial expanded state - true: expanded [OPTIONAL]
    TCPanelPrintableURL         Print url [OPTIONAL]
    TCPanelViewAllURL           View more url [OPTIONAL]
    TCPanelViewFragmentURL      View fragment container url [OPTIONAL]
    TCPanelViewRSSURL           View link to RSS feed url [OPTIONAL]
  */

  if ( TCUsePanels ) {
    //open panel div
    var openPanelHTML = "<div class='TCPanel'>";

    //open panel header div
    openPanelHTML += "<div id='" + TCPanelParams.TCPanelPID + "_panelHeader' class='TCPanelHeader'";

    //if color present, override default style with inline background-color style
    if(TCPanelParams.TCPanelColor) {
      openPanelHTML += " style='background-color:" + TCPanelParams.TCPanelColor + ";'";
    }

    //Important! Close the panelheader div tag!
    openPanelHTML += " >";

    //start the panel header actions span
    openPanelHTML += "<span id='" + TCPanelParams.TCPanelPID + "_panelHeaderActions' class='TCPanelHeaderActions'>";

    if(TCPanelParams.TCPanelPrintableURL) {
      openPanelHTML += "<a href='#' id='TCPanelPrintableURL" + TCPanelParams.TCPanelPID + "' >";
      openPanelHTML += "<img src='" + TcDirectory() + "icons/topclass8/print.gif' alt='" + strPrintView + "' style='vertical-align:top'/>";
      openPanelHTML += " Print view</a>";
    }

    if ( TCPanelParams.TCPanelViewRSSURL ) {
      openPanelHTML += " <a href='#' onclick='TCPanelOpenRSSWindow(\"" + TCPanelParams.TCPanelViewRSSURL + "\")'>";
      openPanelHTML += "<img src='" + TcDirectory() + "icons/topclass8/tcrss.gif' alt='" + strRSS + "' title='" + strRSS + "' class='TCTop'/>";
      openPanelHTML += " </a>";
    }

    if(TCPanelParams.TCPanelViewAllURL) {
      openPanelHTML += " <a id='aViewAll" + TCPanelParams.TCPanelPID + " href='#' onclick='TCPanelOpenViewAllWindow(\"" + TCPanelParams.TCPanelViewAllURL + "\")'>";
      openPanelHTML += "<img src='" + TcDirectory() + "icons/topclass8/viewall.gif' alt='" + strViewAll + "' style='vertical-align:top'/>";
      openPanelHTML += " View all</a>";
    }

    if(TCPanelParams.TCPanelViewFragmentURL) {
      openPanelHTML += " <a href='#' onclick='TCPanelOpenReturnWindow(\"" + TCPanelParams.TCPanelViewFragmentURL + "\")'>";
      openPanelHTML += "<img src='" + TcDirectory() + "icons/topclass8/tc_dashboard.gif' alt='" + strReturn + "' style='vertical-align:top'/>";
      openPanelHTML += " Return</a>";
    }

    //If there's a help URL ...
    /*
    if(TCPanelParams.TCPanelHelpURL) {
      openPanelHTML += "<span id='" + TCPanelParams.TCPanelPID + "_panelHelp' class='TCPanelHelp'>";
      if ( TCPanelParams.TCPanelHelpURL == "default" )
      {
        openPanelHTML += "<a href=\"javascript:TCDoHelp();\">";
      }
      else {
        openPanelHTML += "<a href='#' onclick='TCPanelOpenHelpWindow(\"" + TCPanelParams.TCPanelHelpURL + "\");return(false);'>";
      }
      openPanelHTML += "<img src='" + TcDirectory() + "icons/topclass8/help.gif' alt='" + strHelp + "' style='vertical-align:top'/>";
      openPanelHTML += "</a></span>";
    }
    */

    //close off the panel header actions span tag
    openPanelHTML += "</span>";

    //start the title span
    openPanelHTML += "<span id='" + TCPanelParams.TCPanelPID + "_panelTitle' class='TCPanelTitle'>";

    var sDrawIcon = "";
    //if icon present
    if(TCPanelParams.TCPanelIcon) {
      sDrawIcon = "<img src=\"" + TCPanelParams.TCPanelIcon + "\" alt=\"" + TCPanelParams.TCPanelTitle + "\" title=\"" + TCPanelParams.TCPanelTitle + "\" />&nbsp;";
    }

    //if allowexpand collapse, show the icon
    if(TCPanelParams.TCPanelAllowExpandCollapse) {
      var sExpandCollapse = TCPanelDrawExpandCollapseIcon({
        TCPanelPID:TCPanelParams.TCPanelPID,
        TCPanelExpanded:TCPanelParams.TCPanelExpanded,
        TCPanelCookieExpandCollapse:TCPanelParams.TCPanelCookieExpandCollapse
      });

      openPanelHTML += sExpandCollapse + " " + sDrawIcon +  TCPanelParams.TCPanelTitle + "</a>";

    }
    else {
      openPanelHTML += " " + sDrawIcon + TCPanelParams.TCPanelTitle;
    }

    if(TCPanelParams.TCPanelActionsHTML) {
      openPanelHTML += TCPanelParams.TCPanelActionsHTML;
    }

    //close off the paneltitle span tag
    openPanelHTML += "</span>";

    //close off the panelheader div tag
    openPanelHTML += "</div>";

    //start the panelbody
    openPanelHTML += "<div id='" + TCPanelParams.TCPanelPID + "_panelBody' class='TCPanelBody'";

    var blnCookieExpand = false;
    if ( TCPanelParams.TCPanelCookieExpandCollapse ) {
      var sValue = YAHOO.util.Cookie.getSub("TCPanelDisplay", TCPanelParams.TCPanelPID);
      if ( sValue != "1" ) {
        openPanelHTML += "style='display:none;'";
      }
    } else {
    if(!TCPanelParams.TCPanelExpanded) {
      openPanelHTML += "style='display:none;'";
    }
    }

    //important: Close panelbody div tag!!
    openPanelHTML += ">";
    //write the code to the screen
    document.write(openPanelHTML);

    // attach DOM events
    if(TCPanelParams.TCPanelPrintableURL) {
      try {
        attachEventListener(document.getElementById( "TCPanelPrintableURL" + TCPanelParams.TCPanelPID ),'click',TCPanelParams.TCPanelPrintableURL, false);
      } catch (e) {
        alert( e );
      }
    }

  }

  return TCUsePanels;

}

function TCInitClosePanel(TCPanelParams) {
  /*
    Params
    TCPanelPID              Unique Identifier
  */
  if ( TCUsePanels ) {
    // set defaults
    if ( typeof(TCPanelParams.TCPanelDraw) == "undefined" ) {
      TCPanelParams.TCPanelDraw = true;
    }
    if ( TCModalPopupVisible ) {
      TCPanelParams.TCPanelDraw = false;
    }
    if ( typeof(TCPanelParams.TCPanelPID) == "undefined" ) {
      TCPanelParams.TCPanelPID = "TCPanelDefault";
    }
    if ( TCPanelParams.TCPanelDraw ) {
      TCClosePanel({
        TCPanelPID:TCPanelParams.TCPanelPID
      });
    }
  }
}

function TCClosePanel(TCPanelParams) {
  /*
    Params
    TCPanelPID              Unique Identifier
  */

  if ( TCUsePanels ) {

    //close the panelBody div tag
    var closePanelHTML = "</div>";

    //open panel footer
    closePanelHTML += "<div id='" + TCPanelParams.TCPanelPID + "_panelFooter' class='TCPanelFooter'>&nbsp;";

    //
    closePanelHTML += "<span id='" + TCPanelParams.TCPanelPID + "_panelFooterActions' class='TCPanelFooterActions'>";

    closePanelHTML += "</span>";
    closePanelHTML += "</div>";

    //close the whole panel div tag
    closePanelHTML += "</div>";

    document.write(closePanelHTML);

  }

  return TCUsePanels;
}


function TCPanelBodyShowHide( TCPanelPID ){

  if ( document.getElementById( TCPanelPID + "_panelBody" ) ){
    var obj = document.getElementById( TCPanelPID + "_panelBody");
    var imgShowHide = document.getElementById( TCPanelPID + "_imgExpandCollapse" );
    if (obj.style.display == "none"){
      obj.style.display = "";
      YAHOO.util.Cookie.setSub("TCPanelDisplay", TCPanelPID, 1);
      imgShowHide.src = TcDirectory() + "icons/topclass8/panel_up.gif";
      imgShowHide.alt = "collapse";
      // resize iframe containing fragment //
      if ( window.parent.document.getElementById( "ifrm" + TCPanelPID ) ) {
        TCSetIfrmFragmentHeight(window.parent.document.getElementById( "ifrm" + TCPanelPID ));
      }
    }
    else {
      obj.style.display = "none";
      YAHOO.util.Cookie.setSub("TCPanelDisplay", TCPanelPID, 0);
      imgShowHide.src = TcDirectory() + "icons/topclass8/panel_down.gif";
      imgShowHide.alt = "expand";
      if ( window.parent.document.getElementById( "ifrm" + TCPanelPID ) ) {
        // resize iframe containing fragment //
        TCSetIfrmFragmentHeight(window.parent.document.getElementById( "ifrm" + TCPanelPID ));
      }
    }
  }
}


function TCPanelDrawExpandCollapseIcon(iconParams) {
  /*
    Params
    TCPanelPID
    TCPanelExpanded
    TCPanelCookieExpandCollapse
  */
  var blnCookieExpand = false;
  if ( iconParams.TCPanelCookieExpandCollapse ) {
    var sValue = YAHOO.util.Cookie.getSub("TCPanelDisplay", iconParams.TCPanelPID);
    if ( sValue == 1 ) {
      blnCookieExpand = true;
    }
  }
  var iconHTML = "<a id='" + iconParams.TCPanelPID + "_panelCollapse' href='#' onclick='TCPanelBodyShowHide(\"" + iconParams.TCPanelPID + "\");return(false);'>";
  if(iconParams.TCPanelExpanded || blnCookieExpand) {
    iconHTML += "<img class='TCPanelButton' src='" + TcDirectory() + "icons/topclass8/panel_up.gif' alt='' id='" + iconParams.TCPanelPID + "_imgExpandCollapse' />";
  }
  else {
    iconHTML += "<img class='TCPanelButton' src='" + TcDirectory() + "icons/topclass8/panel_down.gif' alt='' id='" + iconParams.TCPanelPID + "_imgExpandCollapse' />";
  }

  return iconHTML;
}

function TCPanelOpenHelpWindow(url) {
  alert(url);
}


function TCPanelOpenPrintableWindow(url) {
  alert(url);
}

function TCPanelOpenViewAllWindow(url) {
  if ( window.parent ) {
    // iframe containing fragment //
    window.parent.document.location.href = url;
  } else {
    document.location.href = url;
  }
}

function TCPanelOpenReturnWindow(url) {
  if ( window.parent ) {
    // iframe containing fragment //
    window.parent.document.location.href = url;
  } else {
    document.location.href = url;
  }
}

function TCPanelOpenRSSWindow(url) {
  TCOpenPopup( url, 'RSS', 700, 400, 50, 50 );
}

function TCDashboardFragments( fragments ) {
  var bShowColumn_1 = false;
  var bShowColumn_2 = false;
  for ( var i=0; i<fragments.length; i++ ) {
    TCFragment( fragments[i] );
    if ( fragments[i].bShow && fragments[i].container.id == "TCDashboardColumn_1" ) {
      bShowColumn_1 = true;
    } else if ( fragments[i].bShow && fragments[i].container.id == "TCDashboardColumn_2" ) {
      bShowColumn_2 = true;
    }
  }
  if ( !bShowColumn_1 || !bShowColumn_2 ) {
    var TCDashboardColumn_1 = document.getElementById("TCDashboardColumn_1");
    var TCDashboardColumn_2 = document.getElementById("TCDashboardColumn_2");

    if ( !bShowColumn_1 && bShowColumn_2 ) {
      if ( TCDashboardColumn_2 ) {
        TCDashboardColumn_2.colspan = "2";
      }
      if ( TCDashboardColumn_1 ) {
        addClass( TCDashboardColumn_1, "TCDisplayNone" );
      }
    } else {
      if ( TCDashboardColumn_1 ) {
        TCDashboardColumn_1.colspan = "2";
      }
      if ( TCDashboardColumn_2 ) {
        addClass( TCDashboardColumn_2, "TCDisplayNone" );
      }
    }
  }
  if ( getElementsByAttribute( "class", "JSColumnFragment" ).length < 1 ) {
    if ( document.getElementById("TCDashboardColumn_1") ) {
      var newFragment = document.createElement("div");
      newFragment.className = "TCDashboardItem";
      newFragment.innerHTML = "<div><span class='TCEmphasis'>" + strNoMainDashboardFragments + "</span></div>";
      newFragment.id = "TCNoMainFragment";
      newFragment.name = "TCNoMainFragment";
      document.getElementById("TCDashboardColumn_1").appendChild( newFragment );
    }
  }
}

/**
 * Call to create Fragment
 *
 * return: none
 */
 /*
   Params
   fragmentID: fragment ID
   bIframe: boolean specifying whether to draw fragment as IFRAME. If false, draw DIV.
   sIframeURL: source of Iframe
   sClass: CSS class(es)
   sFragmentContentsID: id of container for fragment contents
   container: parent container layout element
   bShow: boolean specifying whether to display the fragment
 */
function TCFragment( params ) {
  if ( typeof( params.bShow ) == "undefined" ) {
    params.bShow = true;
  } else if ( params.bShow == null ) {
    params.bShow = true;
  } else {
    if ( !params.bShow ) {
      return false;
    }
  }
  if ( typeof( params.fragmentID ) == "undefined" ) {
    alert( "fragment id is undefined!" );
    return false;
  } else if ( params.fragmentID == "" ) {
    alert( "fragment id is undefined!" );
    return false;
  }
  if ( typeof( params.bIframe ) == "undefined" ) {
    params.bIframe = false;
  }
  if ( typeof( params.bIframe ) != "undefined" ) {
    if ( params.bIframe ) {
      if ( typeof( params.sIframeURL ) == "undefined" ) {
        alert( "fragment iframe url is undefined!" );
        return false;
      } else if ( params.sIframeURL == "" ) {
        alert( "fragment iframe url is undefined!" );
        return false;
      }
    }
  }
  if ( typeof( params.sClass ) == "undefined" ) {
    params.sClass = "";
  }
  if ( typeof( params.container ) == "undefined" ) {
    params.container = document.body;
  }
  if ( TCUseFragments ) {
    var oParent = params.container;
    var newFragment;
    if ( params.bIframe ) {
      newFragment = document.createElement("iframe");
      newFragment.src = params.sIframeURL;
      newFragment.width = "100%";
      newFragment.scrolling = "no";
      newFragment.marginWidth = "0";
      newFragment.frameBorder = "0";
      newFragment.className = params.sClass;
    } else {
      if ( document.getElementById( params.sFragmentContentsID ) ) {
        var fragmentNode = document.getElementById( params.sFragmentContentsID );
        newFragment = document.createElement("div");
        newFragment.className = params.sClass + " TCDashboardItem";
        newFragment.innerHTML = fragmentNode.innerHTML;
        fragmentNode.parentNode.removeChild( fragmentNode );
      } else {
        return false;
      }
    }
    newFragment.id = params.fragmentID;
    newFragment.name = params.fragmentID;
    oParent.appendChild( newFragment );
    if ( params.bIframe ) {
      attachEventListener(frames[params.fragmentID], "load", TCSetIfrmFragmentHeightShell(document.getElementById(params.fragmentID)), false);
      var spacerDiv = document.createElement("div");
      spacerDiv.className = "TCSpacerDiv";
      oParent.appendChild( spacerDiv );
    }
  }

  return TCUseFragments;

}

function addTCFormValidation( arrElems ) {
  for ( var i = 0; i < arrElems.length; i++ )
  {
    if ( document.getElementById( arrElems[i] ) )
    {
      attachEventListener(document.getElementById( arrElems[i] ),'click',validateForm, false);
    }
  }
}

function getFormName(attributeValue) {
  var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

// TODO switch to using id rather than name
  for (var i = 0; i < document.forms.length; i++ ) {
    if (pattern.test(document.forms[i].className)) {
      return document.forms[i].name;
    }
  }
}

function TCErrorInfo(id, type, success, reason) {
  this.id = id;
  this.type = type;

  if (success == "true")
    this.success = true;
  else
    this.success = false;

  this.reason = reason;
}

function addTCErrorInfo( id, type, success, reason ) {
  arrTCErrorInfo[arrTCErrorInfo.length] = new TCErrorInfo( id, type, success, reason );
}

function TCDirectoryImages( arrImages ) {
  for ( var i = 0; i < arrImages.length; i++ ) {
    if ( document.getElementById( arrImages[i] ) ) {
      var img = document.getElementById( arrImages[i] );
      img.src = TcDirectory() + img.src;
    }
  }
}

// Returns a string
function TCPadWithZeroes( val, length, blnPrefix ) {
  var tempVal = val;
  if (typeof tempVal == "string") {
    if ( tempVal.length == length ) {
      return ( tempVal );
    }
    else {
      if ( blnPrefix ) {
        tempVal = "0" + tempVal;
      }
      else {
        tempVal = tempVal + "0";
      }
      return ( TCPadWithZeroes( tempVal, length, blnPrefix ) );
    }
  }
  else if (typeof tempVal == "number") {
    tempVal = "" + tempVal;
    TCPadWithZeroes( tempVal, length, blnPrefix );
  }
  else {
    return ( tempVal );
  }
}

// For encoding args to popup-select etc.
function encode_args( args ) {
  args = args.replace( /%/g, '%25' );
  args = args.replace( /=/g, '%3D' );
  args = args.replace( /&/g, '%26' );
  args = args.replace( / /g, '%20' );
  return args;
}

function addLoadListener(fn)
{
 if (typeof window.addEventListener != 'undefined')
 {
   window.addEventListener('load', fn, false);
 }
 else if (typeof document.addEventListener != 'undefined')
 {
   document.addEventListener('load', fn, false);
 }
 else if (typeof window.attachEvent != 'undefined')
 {
   window.attachEvent('onload', fn);
 }
 else
 {
   var oldfn = window.onload;
   if (typeof window.onload != 'function')
   {
     window.onload = fn;
   }
   else
   {
     window.onload = function()
     {
       oldfn();
       fn();
     };
   }
 }
}

function TCFormElementsDisabled( oElems, blnDisabled ) {
  for ( var i = 0; i < oElems.length; i++ ) {
    if ( oElems[i].tagName.toLowerCase() == "input" ) {
      switch ( oElems[i].type.toLowerCase() ) {
        case "text" :
        case "password" :
        case "reset" :
        case "file" :
        case "hidden" :
        case "image" :
        case "checkbox" :
        case "radio" :
        case "button" :
        case "submit" :
        default:
          if (blnDisabled) {
            oElems[i].disabled = "disabled";
            addClass( oElems[i], "TCReadOnly" );
          }
          else {
            oElems[i].disabled = "";
            removeClass( oElems[i], "TCReadOnly" );
          }
          break;
      }
    }
    else if ( oElems[i].tagName.toLowerCase() == "select" ) {
      if (blnDisabled) {
        oElems[i].disabled = "disabled";
        addClass( oElems[i], "TCReadOnly" );
        oElems[i].value = "";
      }
      else {
        oElems[i].disabled = "";
        removeClass( oElems[i], "TCReadOnly" );
      }
    }
    else if ( oElems[i].tagName.toLowerCase() == "textarea" ) {
      if (blnDisabled) {
        oElems[i].disabled = "disabled";
        addClass( oElems[i], "TCReadOnly" );
        oElems[i].value = "";
      }
      else {
        oElems[i].disabled = "";
        removeClass( oElems[i], "TCReadOnly" );
      }
    }
  }
}

function TCFormElementsReadOnlyClear( oElems, blnReadOnly ) {
  TCFormElementsReadOnly( oElems, blnReadOnly );
  for ( var i = 0; i < oElems.length; i++ ) {
    if ( oElems[i].tagName.toLowerCase() == "input" ) {
      switch ( oElems[i].type.toLowerCase() ) {
        case "reset" :
        case "button" :
        case "submit" :
          break;

        default:
          if (blnReadOnly) {
            oElems[i].value = "";
            break;
          }
      }
    }
    else {
      if (blnReadOnly) {
       oElems[i].value = "";
      }
    }
  }
}

function TCFormElementsReadOnly( oElems, blnReadOnly ) {
  for ( var i = 0; i < oElems.length; i++ ) {
    if ( oElems[i] ) {
      if ( oElems[i].tagName.toLowerCase() == "input" ) {
        switch ( oElems[i].type.toLowerCase() ) {
          case "password" :
          case "reset" :
          case "file" :
          case "hidden" :
          case "checkbox" :
            if (blnReadOnly) {
              oElems[i].disabled = "disabled";
              addClass( oElems[i], "TCReadOnly" );
            }
            else {
              oElems[i].disabled = "";
              removeClass( oElems[i], "TCReadOnly" );
            }
            break;
          case "radio" :
          case "button" :
            if (blnReadOnly) {
              oElems[i].disabled = "disabled";
              addClass( oElems[i], "TCReadOnly" );
            }
            else {
              oElems[i].disabled = "";
              removeClass( oElems[i], "TCReadOnly" );
            }
          case "text" :
            if (blnReadOnly) {
              oElems[i].readOnly = "readonly";
              addClass( oElems[i], "TCReadOnly" );
            }
            else {
              oElems[i].readOnly = "";
              removeClass( oElems[i], "TCReadOnly" );
            }
            break;
          case "image" :
          case "submit" :
            if (blnReadOnly) {
              oElems[i].disabled = "disabled";
              addClass( oElems[i], "TCReadOnly" );
            }
            else {
              oElems[i].disabled = "";
              removeClass( oElems[i], "TCReadOnly" );
            }
            break;
          default:
            if (blnReadOnly) {
              oElems[i].readOnly = "readonly";
              addClass( oElems[i], "TCReadOnly" );
            }
            else {
              oElems[i].readOnly = "";
              removeClass( oElems[i], "TCReadOnly" );
            }
            break;
        }
      }
      else if ( oElems[i].tagName.toLowerCase() == "select" ) {
        if (blnReadOnly) {
          oElems[i].disabled = "disabled";
          addClass( oElems[i], "TCReadOnly" );
        }
        else {
          oElems[i].disabled = "";
          removeClass( oElems[i], "TCReadOnly" );
        }
      }
      else if ( oElems[i].tagName.toLowerCase() == "textarea" ) {
        if (blnReadOnly) {
          oElems[i].readOnly = "readonly";
          addClass( oElems[i], "TCReadOnly" );
        }
        else {
          oElems[i].readOnly = "";
          removeClass( oElems[i], "TCReadOnly" );
        }
      }
    }
  }
}

function TCInfoTab( sInfo ) {

    // * Don't dispay form info, if form message div is present *//
  var TCInfoTabHTML = "";
  TCInfoTabHTML = TCInfoTabHTML + "<div class=\"TCInfoTabWrapper\">";
  TCInfoTabHTML = TCInfoTabHTML + "<table class=\"TCInfoTab\">";
  TCInfoTabHTML = TCInfoTabHTML + "<tr>";
  TCInfoTabHTML = TCInfoTabHTML + "<td id=\"TCInfoTabBody\">";
  TCInfoTabHTML = TCInfoTabHTML + "<img src=\"" + TcDirectory() + "icons/topclass8/info.gif\" style=\"height:16px;width:16px;vertical-align:bottom;\" alt=\"\" title=\"\" />";
  TCInfoTabHTML = TCInfoTabHTML + "&nbsp;" + sInfo + "&nbsp;";
  TCInfoTabHTML = TCInfoTabHTML + "</td>";
  TCInfoTabHTML = TCInfoTabHTML + "</tr>";
  TCInfoTabHTML = TCInfoTabHTML + "</table>";
  TCInfoTabHTML = TCInfoTabHTML + "</div>";

  document.write( TCInfoTabHTML );

}

function TCAddMesssageInfo( sMessage ) {
  if ( document.getElementById("TCMessageInfo") ) {
    if ( document.getElementById("TCMessageInfo").innerHTML != "" ) {
      document.getElementById("TCMessageInfo").innerHTML = document.getElementById("TCMessageInfo").innerHTML + "<br/>" + sMessage;
    } else {
      document.getElementById("TCMessageInfo").innerHTML = sMessage;
    }
  } else {
    if ( document.getElementById("formHeader") ) {
      var newMessageDiv = document.createElement("div");
      newMessageDiv.className = "TCMessage";
      newMessageDiv.innerHTML = "<div id='TCMessageInfo' class='TCMessageInfo'>" + sMessage + "</div>";
      newMessageDiv.id = "TCMessage";
      document.getElementById("formHeader").parentNode.insertBefore( newMessageDiv, document.getElementById("formHeader") );
    } else {
      alert( 'formHeader element not found!' );
    }
  }
}

function TCAddMesssageInfo( sMessage ) {
  if ( document.getElementById("TCMessage") ) {
    if ( document.getElementById("TCMessageInfo") ) {
      if ( document.getElementById("TCMessageInfo").innerHTML != "" ) {
        document.getElementById("TCMessageInfo").innerHTML = document.getElementById("TCMessageInfo").innerHTML + "<br/>" + sMessage;
      } else {
        document.getElementById("TCMessageInfo").innerHTML = sMessage;
      }
    } else {
      document.getElementById("TCMessage").innerHTML = "<div id='TCMessageInfo' class='TCMessageInfo'>" + sMessage + "</div>";
    }
  } else {
    if ( document.getElementById("formHeader") ) {
      var newMessageDiv = document.createElement("div");
      newMessageDiv.className = "TCMessage";
      newMessageDiv.innerHTML = "<div id='TCMessageInfo' class='TCMessageInfo'>" + sMessage + "</div>";
      newMessageDiv.id = "TCMessage";
      document.getElementById("formHeader").parentNode.insertBefore( newMessageDiv, document.getElementById("formHeader").nextSibling );
    } else {
      alert( 'formHeader element not found!' );
    }
  }
}

function TCAddMesssageError( sMessage, bOverwrite ) {
  if ( document.getElementById("TCMessage") ) {
    if ( document.getElementById("TCMessageError") ) {
      if ( document.getElementById("TCMessageError").innerHTML != "" && !bOverwrite) {
        document.getElementById("TCMessageError").innerHTML = document.getElementById("TCMessageError").innerHTML + "<br/>" + sMessage;
      } else {
        document.getElementById("TCMessageError").innerHTML = sMessage;
      }
    } else {
      document.getElementById("TCMessage").innerHTML = "<div id='TCMessageError' class='TCMessageError'>" + sMessage + "</div>";
    }
  } else {
    if ( document.getElementById("formHeader") ) {
      var newMessageDiv = document.createElement("div");
      newMessageDiv.className = "TCMessage";
      newMessageDiv.innerHTML = "<div id='TCMessageError' class='TCMessageError'>" + sMessage + "</div>";
      newMessageDiv.id = "TCMessage";
      document.getElementById("formHeader").parentNode.insertBefore( newMessageDiv, document.getElementById("formHeader").nextSibling );
    } else {
      alert( 'formHeader element not found!' );
    }
  }
}

function preventDefault(evt){
  var e = evt ? evt : window.event;
  if(e.preventDefault){
      e.preventDefault();
  }
  else {
      e.returnValue = false;
  }
}

function replaceDOMNode( oNode, sReplaceHTMLNode, sClassName, sInnerHTML ) {
  if ( oNode ) {
    var oPlaceHolder;
    if ( sReplaceHTMLNode ) {
      oPlaceHolder = document.createElement(sReplaceHTMLNode);
    }
    else {
      oPlaceHolder = document.createElement("span");
    }
    if ( sClassName ) {
      if ( sClassName != "" ) {
        oPlaceHolder.className = sClassName;
      }
    }
    if ( sInnerHTML ) {
      if ( sInnerHTML != "" ) {
        oPlaceHolder.innerHTML = sInnerHTML;
      }
    }
    var parent = oNode.parentNode;
    var oNewNode;
    oNewNode = parent.replaceChild( oPlaceHolder, oNode );

    return ( oNewNode );
  }
}

function assignPathToRootTooltips() {
  var arrPathToRoot = getElementsByAttribute("class", "TCObjLocatedIn");

  for ( var i = 0; i < arrPathToRoot.length; i++ ) {
    new YAHOO.widget.Tooltip( "tt" + arrPathToRoot[i].id, { context:arrPathToRoot[i].id } );
  }
}

function TCSetIfrmFragmentHeight(oIfrmFragment)
{
  //find the height of the internal page
  var the_height= oIfrmFragment.contentWindow.document.body.scrollHeight;
  //change the height of the iframe
  oIfrmFragment.height = the_height;
}

function TCSetIfrmFragmentHeightShell(oIfrm) {
  return function(e) {
    TCSetIfrmFragmentHeight(oIfrm);
  }
}

function TCInitFragment( fragmentID )
{
  // resize fragment iframe
  if ( parent.document.getElementById( fragmentID ) ) {
    addLoadListener( TCSetIfrmFragmentHeightShell(parent.document.getElementById( fragmentID )) );
  }
  // redirect target for hyperlinks to parent window
  var links = getElementsByAttribute("class", "JSFragmentLink");
  for (var i=0;i<links.length;i++) {
    links[i].target = "_parent";
  }
  // Reset document margins for IFRAME template
  addClass( document.body, "TCFragmentBody" );
}

function changeSortCriteria(type)
{
  if ( TCUseYUI && TCModalPopup ) {
    sort_column = document.getElementById("sort_columnmodal");
    sort_direction = document.getElementById("sort_directionmodal");
  } else {
    sort_column = document.getElementById("sort_column");
    sort_direction = document.getElementById("sort_direction");
  }

  if ( type != sort_column.value)
  {
    sort_direction.value="asc";
    sort_column.value=type;
  }
  else
  {
    if (sort_direction.value == "asc")
    {
      sort_direction.value = "desc";
    }
    else
    {
      sort_direction.value = "asc";
    }
  }

  if ( TCUseYUI && TCModalPopup ) {
    TCPostModalPopup( document.getElementById("hiddenFormModal") )
  }
  else {
    document.getElementById("hiddenForm").submit();
  }

  return false;
}

function changeSortCriteria2(type)
{
  if ( TCUseYUI && TCModalPopup ) {
    sort_column2 = document.getElementById("sort_columnmodal");
    sort_direction2 = document.getElementById("sort_directionmodal");
  } else {
    sort_column2 = document.getElementById("sort_column2");
    sort_direction2 = document.getElementById("sort_direction2");
  }

  if ( type != sort_column2.value)
  {
    sort_direction2.value="asc";
    sort_column2.value=type;
  }
  else
  {
    if (sort_direction2.value == "asc")
    {
      sort_direction2.value = "desc";
    }
    else
    {
      sort_direction2.value = "asc";
    }
  }

  if ( TCUseYUI && TCModalPopup ) {
    TCPostModalPopup( document.getElementById("hiddenFormModal") )
  }
  else {
    document.getElementById("hiddenForm").submit();
  }

  return false;
}


function TCGoToURL( sURL ) {
  return function(e) {
    TCRedirect( sURL );
  }
}

function TCRedirect( sURL ) {
  if (window.opener) {
    window.opener.location.href = sURL;
    window.close();
  } else {
    document.location.href = sURL;
  }
}

function TCRedirect( sURL ) {
  if (window.opener) {
    window.opener.location.href = sURL;
    window.close();
  } else {
    document.location.href = sURL;
  }
}

function TCHrefAsSubmit( sSubmitID ) {

  if ( document.getElementById( sSubmitID ) ) {
    document.getElementById( sSubmitID ).click();
  }
  return( false );
}

function TCSelectRows( strSelectRowClass, strSwitchClass, blnSetTitle ) {
  return function(e) {
    var rows = getElementsByAttribute("class", strSelectRowClass);
    for ( var i=0; i<rows.length; i++ ) {
      if ( !hasClass( rows[i].className, "TCListing-highlighted-noPointer" ) ) {
        addClass( rows[i], "TCListing-highlighted-noPointer" );
        if ( blnSetTitle ) {
          var switchImgs = getElementsByAttribute("class", strSwitchClass);
          for ( var j=0; j<switchImgs.length; j++  ) {
            switchImgs[j].title = strDeselectRows;
          }
        }
      } else {
        removeClass( rows[i], "TCListing-highlighted-noPointer" );
        if ( blnSetTitle ) {
          var switchImgs = getElementsByAttribute("class", strSwitchClass);
          for ( var j=0; j<switchImgs.length; j++  ) {
            switchImgs[j].title = strSelectRows;
          }
        }
      }
    }
  }
}

function TCResetSearchFilter( sFrm ) {
  if ( document.forms[sFrm] ) {
    var frmInputs = document.forms[sFrm].elements;
    for ( var i=0; i < frmInputs.length; i++ ) {
      if ( frmInputs[i].tagName.toLowerCase() == "input" ) {
        switch ( frmInputs[i].type.toLowerCase() ) {
          case "password" :
            break;
          case "reset" :
            break;
          case "file" :
            break;
          case "hidden" :
            break;
          case "checkbox" :
            frmInputs[i].checked = false;
            break;
          case "radio" :
            break;
          case "button" :
            break;
          case "text" :
            if ( ( frmInputs[i].name.indexOf("day") != -1 ) || ( frmInputs[i].name.indexOf("month") != -1 ) || ( frmInputs[i].name.indexOf("year") != -1 ) ) {
              frmInputs[i].value = "0";
            } else {
              frmInputs[i].value = "";
            }
            break;
          case "image" :
            break;
          case "submit" :
            break;
          default:
            break;
        }
      }
      else if ( frmInputs[i].tagName.toLowerCase() == "select" ) {
        frmInputs[i].selectedIndex = "0";
      }
    }
  }
}

/* from tcmenu.js */

// 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 = false;
TCExpandToShowPosition = false;

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)

function TCHelpUser(){
    if( TCIsStudent() ) return "student";
    if( TCIsInstructor() ) return "instructor";
    if( TCIsManager() ) return "manager";
    if( TCIsAdmin() ) return "admin";
    return "student";
  }

// dir for non-localised TC5Style images
function getTC5ImagesSrc() { return this.TC5ImagesSrc ? this.TC5ImagesSrc : "icons/tc5style/common/"; }

// Popup for Conflict details
function TCConflictDetails(sConflictDetails) {
  return function(e) {
    var roomBookingID;
    var resourceID;
    var conflictType;
    var sConflictURL = TCPathToTopClass + "inpopup-expand-ConflictDetails";
    var arrConflictDetails;
    arrConflictDetails = sConflictDetails.split("_");
    var nConflictDetailsLength = arrConflictDetails.length;
    for ( var i=0; i<nConflictDetailsLength; i++ ) {
      if ( arrConflictDetails[i].indexOf("conflictRoomBooking") != -1 ) {
        roomBookingID = (arrConflictDetails[i]).substr("conflictRoomBooking".length);
        sConflictURL = sConflictURL + "-roomBookingID=" + roomBookingID;
      }
      if ( arrConflictDetails[i].indexOf("conflictResource") != -1 ) {
        resourceID = (arrConflictDetails[i]).substr("conflictResource".length);
        sConflictURL = sConflictURL + "-resourceID=" + resourceID;
      }
      if ( arrConflictDetails[i].indexOf("conflictEvent") != -1 ) {
        eventID = (arrConflictDetails[i]).substr("conflictEvent".length);
        sConflictURL = sConflictURL + "-eventID=" + eventID;
      }
    }
    var blnSuccess = TCDialog( {
        type: "info",
        width: "600px",
        height: "300px",
        sHeader: "head",
        sBody: "body",
        sFooter: "",
        sURL: sConflictURL,
        bDraggable: true,
        bModal: true,
        bResizable: true,
        bClose: true
       } );
  }
}

function TCSetFormFieldLevelHelp() {
  if ( !blnDisplayFormFieldLevelHelp ) {
    var arrFieldLevelHelp = getElementsByAttribute("class", "TCFormFieldLevelHelp");
    for (var i=0; i<arrFieldLevelHelp.length; i++) {
      addClass( arrFieldLevelHelp[i], "TCDisplayNone" );
    }
  }
}

function TCSetFormFieldTips() {
  if ( blnDisplayFormFieldTips ) {
    var arrFieldLevelTips = getElementsByAttribute("class", "TCFormFieldTip");
    var arrFieldLevelTipsIds = new Array();
    for (var i=0; i<arrFieldLevelTips.length; i++) {
      arrFieldLevelTipsIds[arrFieldLevelTipsIds.length] = arrFieldLevelTips[i].id;
    }
    var fieldLevelTip = new YAHOO.widget.Tooltip("fieldLevelTip", {context:arrFieldLevelTipsIds,
                                                                   showdelay:500,
                                                                   hidedelay:500,
                                                                   autodismissdelay:5000
                                                                  });
  }
}

/**************************** S H O P P I N G   C A R T *********************************/
function TCcopyElementValue(elF, elT){
  if(elF.options){
    // if elementFrom is select element - get value or text
    //and set it for another select element
    var res = elF.options[elF.selectedIndex].value;
    var valueByText = false;
    if("" == res){
      res = elF.options[elF.selectedIndex].text;
      valueByText = true;
    }
    for(var i=0;i<elT.options.length;i++){
      if(valueByText){
        if(elT.options[i].text == res ){
          elT.options[i].selected = true;
          break;
        }
      }else{
        if(elT.options[i].value == res ){
          elT.options[i].selected = true;
          break;
        }
      }
    }
  }else{
    // if elementFrom is just a text - set it for another element
    elT.value = elF.value;
  }
}


// get Elements by id, and if they are not null, call copy procedure
function TCcopyValue(elFrom, elTo){
  var elF = document.getElementById(elFrom);
  var elT = document.getElementById(elTo);
  if(elF && elT){
    TCcopyElementValue(elF, elT);
  }
}

// Deesy: compare string function, convert into string, lower it, trim it and then compare
function TCstrCompare(str1, str2){
  var result = false;
  errorshown = false;
  //Deesy: convert to string!!! otherwise rased error on numbers
  var cStr1 = "" + str1;
  var cStr2 = "" + str2;
  try{
    result = (trim(cStr1.toLowerCase()) == trim(cStr2.toLowerCase()));
  }catch(err){
    if(!errorshown){
      alert("Error " + err.description + " on *" + cStr1 + "* and *" + cStr2 + "*");
      errorshown = true;
    }
  }
  return result;
}

function trim(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
  return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
  return stringToTrim.replace(/\s+$/,"");
}

function isArray(obj) {
  if (obj.constructor.toString().indexOf("Array") == -1)
    return false;
  else
    return true;
}

function TCcopySelect(copyFrom, copyTo, selected){
  if(!copyFrom || !copyTo || !copyFrom.options || !copyTo.options){
      return;
  }
  var selectedValue = null;
  if(selected){
      selectedValue = trim(selected.toLowerCase());
  }
  var maxCount = copyFrom.options.length;
  for(i=0;i<maxCount;i++){
      copyTo[i] = new Option(copyFrom.options[i].text, copyFrom.options[i].value);
      if(selectedValue && (selectedValue == copyFrom.options[i].value.toLowerCase() || selectedValue == copyFrom.options[i].text.toLowerCase())){
          copyTo.options[i].selected = true;
      }
  }
}

//sho/hide batch of classes, eg:
//TCshowHideElements(['creditcard'],['debitacc','billme']);
function TCshowHideElements(cssClassElToShow, cssClassElToHide){
  //this function uses YUI library
  //this block parsed classes
  var elements;
  for(var j=0;j<cssClassElToShow.length;j++){
    elements = YAHOO.util.Dom.getElementsByClassName(cssClassElToShow[j]);
    if(elements.length > 0){
      for(var i=0;i<elements.length;i++){
        elements[i].style.display = '';
      }
    }
  }

  for(var j=0;j<cssClassElToHide.length;j++){
    elements = YAHOO.util.Dom.getElementsByClassName(cssClassElToHide[j]);
    if(elements.length > 0){
      for(var i=0;i<elements.length;i++){
        elements[i].style.display = 'none';
      }
    }
  }
}

function TCgetFormValue(elId){
  var el = document.getElementById(elId);
  var result = null;
  if(el){
    if(el.options){
      result = el.options[el.selectedIndex].value;
    }else{
      result = el.value;
    }
  }
  return result;
}

function TCgetOptionValue(elId){
  var result = null;
  var optionEl = document.getElementById(elId);
  if(optionEl && optionEl.options){
    result = optionEl.options[optionEl.selectedIndex].value;
  }
  else {
    result = optionEl.value;
  }
  return result;
}

function TCcheckAll(el,prefix){
  var els = document.forms.ShoppingCartForm;
  for(i = 0;i<els.length;i++){
    if(els[i].id.indexOf(prefix) == 0){
      els[i].checked = el.checked;
    }
  }
};

function TCsetElementValue(elId,elValue){
  var el = document.getElementById(elId);
  if(el){
    el.value = elValue;
    return true;
  }
  return false;
}

function TCupdateFlags( arrFields ) {
  for(var i=0; i<arrFields.length; i++) {
    if ( document.getElementById(arrFields[i]).checked )
      document.getElementById("h_" + arrFields[i]).value = "1";
    else
      document.getElementById("h_" + arrFields[i]).value = "0";
  }
}

function TCRefresh() {
  if ( window.refresh ) {
    window.refresh();
  }
}

function TCopenRoster(InstanceID){
    TCOpenPopup(TCPathToTopClass + 'expand-Roster-' + InstanceID, 'PrintRoster', 700, 400, 50, 50);
}

function TCconfirm(confirmMessage){
  if (confirm(confirmMessage)) {
      return true;
    }
    else {
     return false;
  }
}

function TCSubmitYes( sSubmitID ) {
  TCHideMessageDialog();
  if ( document.getElementById( sSubmitID ) ) {
    document.getElementById( sSubmitID ).click();
  }
}

function TCSubmitNo() {
  TCHideMessageDialog();
}

function TCConfirmSubmit( TCConfirmParams ) {
  /*
    Params
    TCConfirmWidth              Dialog width
    TCConfirmHeader             Dialog Header Title
    TCConfirmBody               Dialog Body Text
    TCConfirmYes                Yes Button Text
    TCConfirmNo                 No Button Text
    TCSubmitID                  Submit Button ID
  */
  // set defaults
  if ( typeof(TCConfirmParams.TCConfirmWidth) == "undefined" ) {
    TCConfirmParams.TCConfirmWidth = "300px";
  }
  if ( typeof(TCConfirmParams.TCConfirmHeader) == "undefined" ) {
    TCConfirmParams.TCConfirmHeader = "Warning";
  }
  if ( typeof(TCConfirmParams.TCConfirmBody) == "undefined" ) {
    alert( 'No Confirmation message specified' );
    return (false);
  }
  if ( typeof(TCConfirmParams.TCConfirmYes) == "undefined" ) {
    TCConfirmParams.TCConfirmYes = "Yes";
  }
  if ( typeof(TCConfirmParams.TCConfirmNo) == "undefined" ) {
    TCConfirmParams.TCConfirmNo = "No";
  }
  if ( typeof(TCConfirmParams.TCSubmitID) == "undefined" ) {
    alert( 'No Submit button specified' );
    return (false);
  }

  TCMessageDialog( {
    width: TCConfirmParams.TCConfirmWidth,
    sHeader: TCConfirmParams.TCConfirmHeader,
    sBody: TCConfirmParams.TCConfirmBody,
    buttons: [ { text:TCConfirmParams.TCConfirmYes, handler:function (e) { TCSubmitYes( TCConfirmParams.TCSubmitID ) }, isDefault:true }, { text:TCConfirmParams.TCConfirmNo,  handler:TCSubmitNo } ]
  } );

  return false;
}

function TCSubmitSelectionYes( sSubmitID ) {
  TCHideMessageDialog();
  if ( document.getElementById( sSubmitID ) ) {
    document.getElementById( sSubmitID ).click();
  }
}

function TCSubmitSelectionNo() {
  TCHideMessageDialog();
}

function TCConfirmSelectionSubmit( TCConfirmSelectionParams ) {
  /*
    Params
    TCConfirmSelectionWidth              Dialog width
    TCConfirmSelectionHeader             Dialog Header Title
    TCConfirmSelectionBody               Dialog Body Text
    TCConfirmSelectionSelections         Collection of Selecttion Objects
    TCConfirmSelectionYes                Yes Button Text
    TCConfirmSelectionNo                 No Button Text
    TCConfirmSelectionNone               None Selected Text
    TCConfirmSelectionID                 Submit Button ID
  */
  // set defaults
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionWidth) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionWidth = "300px";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionHeader) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionHeader = "Warning";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionBody) == "undefined" ) {
    alert( 'No Confirmation message specified' );
    return (false);
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionSelections) == "undefined" ) {
    alert( 'No Selection objects specified' );
    return (false);
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionYes) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionYes = "Yes";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionNo) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionNo = "No";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionNone) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionNone = "None selected";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionID) == "undefined" ) {
    alert( 'No Submit button specified' );
    return (false);
  }
  var selected = false;
  for(var i=0; i<TCConfirmSelectionParams.TCConfirmSelectionSelections.length; i++) {
     if(TCConfirmSelectionParams.TCConfirmSelectionSelections[i].checked){
       selected = true;
       break;
     }
  }
  if ( !selected ) {
    TCWarnDialog( TCConfirmSelectionParams.TCConfirmSelectionHeader, TCConfirmSelectionParams.TCConfirmSelectionNone, "", "200px" );
    return(false);
  }

  TCMessageDialog( {
    width: TCConfirmSelectionParams.TCConfirmSelectionWidth,
    sHeader: TCConfirmSelectionParams.TCConfirmSelectionHeader,
    sBody: TCConfirmSelectionParams.TCConfirmSelectionBody,
    buttons: [ { text:TCConfirmSelectionParams.TCConfirmSelectionYes, handler:function (e) { TCSubmitSelectionYes( TCConfirmSelectionParams.TCConfirmSelectionID ) }, isDefault:true }, { text:TCConfirmSelectionParams.TCConfirmSelectionNo,  handler:TCSubmitSelectionNo } ]
  } );

  return false;
}

function TCConfirmDeleteObjectSubmit( TCConfirmSelectionParams ) {
  /*
    Params
    TCConfirmSelectionWidth              Dialog width
    TCConfirmSelectionHeader             Dialog Header Title
    TCConfirmSelectionBody               Dialog Body Text
    TCConfirmSelectionSelections         Collection of Selecttion Objects
    TCConfirmSelectionYes                Yes Button Text
    TCConfirmSelectionNo                 No Button Text
    TCConfirmSelectionNone               None Selected Text
    TCConfirmSelectionID                 Submit Button ID
  */
  // set defaults
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionWidth) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionWidth = "300px";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionHeader) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionHeader = "Warning";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionBody) == "undefined" ) {
    alert( 'No Confirmation message specified' );
    return (false);
  }
  //if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionSelections) == "undefined" ) {
  //  alert( 'No Selection objects specified' );
  //  return (false);
  //}
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionYes) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionYes = "Yes";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionNo) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionNo = "No";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionNone) == "undefined" ) {
    TCConfirmSelectionParams.TCConfirmSelectionNone = "None selected";
  }
  if ( typeof(TCConfirmSelectionParams.TCConfirmSelectionID) == "undefined" ) {
    alert( 'No Submit button specified' );
    return (false);
  }
  /*
  var selected = false;
  for(var i=0; i<TCConfirmSelectionParams.TCConfirmSelectionSelections.length; i++) {
     if(TCConfirmSelectionParams.TCConfirmSelectionSelections[i].checked){
       selected = true;
       break;
     }
  }
  if ( !selected ) {
    TCWarnDialog( TCConfirmSelectionParams.TCConfirmSelectionHeader, TCConfirmSelectionParams.TCConfirmSelectionNone, "", "200px" );
    return(false);
  }
  */
  TCMessageDialog( {
    width: TCConfirmSelectionParams.TCConfirmSelectionWidth,
    sHeader: TCConfirmSelectionParams.TCConfirmSelectionHeader,
    sBody: TCConfirmSelectionParams.TCConfirmSelectionBody,
    buttons: [ { text:TCConfirmSelectionParams.TCConfirmSelectionYes, handler:function (e) { TCSubmitSelectionYes( TCConfirmSelectionParams.TCConfirmSelectionID ) }, isDefault:true }, { text:TCConfirmSelectionParams.TCConfirmSelectionNo,  handler:TCSubmitSelectionNo } ]
  } );

  return false;
}

function confirmDeleteObject( submitId, question ) {
  return TCConfirmDeleteObjectSubmit({
      TCConfirmSelectionWidth:"300px",
      //TCConfirmSelectionHeader:"Warning",
      TCConfirmSelectionBody: question,
      //TCConfirmSelectionSelections:getElementsByAttribute( "class", "JSSelectInstructors" ),
      //TCConfirmSelectionYes:"Yes",
      //TCConfirmSelectionNo:"No",
      //TCConfirmSelectionNone:"No objects selected",
      TCConfirmSelectionID: submitId
    });
}

function TCDeleteChecks(self, tag) {
  var dels = getElementsByAttribute( "class", 'JS' + tag + 'delet' );
  for ( var i = 0; i < dels.length; i++ ) {
    var del_id = dels[i].id;
    var check_id = del_id.replace( 'delet', 'check' );
    var check = document.getElementById( check_id );
    dels[i].checked = check.checked;
  }
}

function TCPrintFormPopup( ofrm, width, height, posx, posy ) {
  var TCPrintFormPopUpWindow = window.open( "", "TCPrintFormPopUpWindow", "toolbar=no,status=yes,scrollbars=yes,location=no,directories=no,menubar=no,resizable=yes,resizable=1,width=" + width + ",height=" + height + ",posx=" + posx + ",posy=" + posy );
  TCPrintFormPopUpWindow.focus();
  ofrm.submit();
}

function TCclick_button(sButton) {
  var oButton = document.getElementById(sButton);

  if ( typeof(oButton.click) != "undefined" ) {
    oButton.click();
  }
  else if ( typeof(oButton[0].click) != "undefined" ) {
    oButton[0].click();
  }
}

//* Copyright 2003 Bontrager Connection, LLC *//
//* Code obtained from http://WillMaster.com/ *//
function TCFormatAsCurrency(amount)
{
  var i = parseFloat(amount);
  if(isNaN(i)) { i = 0.00; }
  var minus = '';
  if(i < 0) { minus = '-'; }
  i = Math.abs(i);
  i = parseInt((i + .005) * 100);
  i = i / 100;
  s = new String(i);
  if(s.indexOf('.') < 0) { s += '.00'; }
  if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
  s = minus + s;
  return s;
}

function TCShowMessages( sHeader, sMessagesID ) {
  var blnSuccess = TCDialog( {
      replaceID: sMessagesID,
      width: "750px",
      height: "300px",
      posx: 100,
      posy: 100,
      sHeader: sHeader,
      sBody: document.getElementById(sMessagesID).innerHTML,
      sFooter: "",
      bDraggable: true,
      bModal: true,
      bClose: true
    } );
}

function TCBDtoMoney(elId){
  var el=document.getElementById(elId);
  if(el){
    var val = el.value;
    if(val.indexOf('.') == -1){
      var len = val.length;
      if(len==1){
        val = '0.0' + val;
      }else if(len==2){
        val = '0.' + val;
      }else{
        dec = val.substring(len-2);
        int = val.substring(0,len-2);
        val = int + '.' + dec;
      }
    }
    el.value=val;
  }
}



function SetIDandTitle( value,field,button ) {
  if ( arguments.length == 4 ) {
    if ( document.getElementById(field) ) {
      document.getElementById(field).value = value;
    } else {
      alert('Error Selecting Object');
      if ( TCUseYUI && TCModalPopup ) {
	TCGetModalPopup().hide();
      }
      else {
	close();
      }                
      return(0);
    }
    if ( document.getElementById(field) ) {             
      document.getElementById(field).value = arguments[3];
      document.getElementById(field + "_display").value = arguments[0];
    
    } else {
      alert('Error setting VG');
      if ( TCUseYUI && TCModalPopup ) {
	TCGetModalPopup().hide();
      }
      else {
	close();
      }                
      return(0);
    }             
  }
  if ( TCUseYUI && TCModalPopup ) {
    TCGetModalPopup().hide();
  }
  else {
    close();
  }            
}


function TCFormatMoney(elId){
  var el=document.getElementById(elId);
  if(el){
    var val = el.value;
    var len = val.length;
    if(val.indexOf('.') == -1){
      val = val + '.00';
    }else{
      var arr = val.split('.');
      arr[1] = arr[1]+'000';
      arr[1] = arr[1].substr(0,2);
      val=arr.join('.');
    }
    el.value=val;
  }
}

// Credit: by Peter-Paul Koch & Alex Tingle //
// http://www.quirksmode.org/js/findpos.html //
function TCFindPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1)
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}

function TCFindPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

function TCSortObjectArray( TCObjArray ) {
  var nLength = TCObjArray.length;
  for (var i=0; i<nLength-1; i++) {
    for (var j=i+1; j<nLength; j++) {
      if (TCObjArray[j].order < TCObjArray[i].order) {
        var dummy = TCObjArray[i];
        TCObjArray[i] = TCObjArray[j];
        TCObjArray[j] = dummy;
      }
    }
  }
  return( TCObjArray );
}

function TCOnClickShow(buttonID,visibilityID) {
  return function(e) {
    TCShowHide( buttonID,visibilityID );
    return false;
  }
}

function TCDashFragment( id, order, column, visibility, label, icon ) {
  this.id = id;
  this.order = order;
  this.column = column;
  this.visibility = visibility;
  this.label = label;
  this.icon = icon;
}

function TCUpdateDragDropOrder() {
  var dashItems = getElementsByAttribute( "class", "JSMyDashItem" );
  var oDragItemID;
  for (i=0;i<dashItems.length;i++) {
    if ( document.getElementById( "TCDragItemID_" + dashItems[i].id ) ) {
      oDragItemID = document.getElementById( "TCDragItemID_" + dashItems[i].id );
      if ( document.getElementById( oDragItemID.value + "_order" ) ) {
        document.getElementById( oDragItemID.value + "_order" ).value = i+1;
      }
      if ( document.getElementById( oDragItemID.value + "_column" ) ) {
        document.getElementById( oDragItemID.value + "_column" ).value = document.getElementById( dashItems[i].id ).parentNode.id.substr(10);
      }
    }
  }
  return(true);
}

function TCShowHide( buttonID, visibilityID ) {
  if ( hasClass( document.getElementById(buttonID).className, "yui-checkbox-button-checked" ) ) {
    document.getElementById(buttonID).getElementsByTagName("button")[0].innerHTML = strShow;
    document.getElementById(visibilityID).value = "1";
  } else {
    document.getElementById(buttonID).getElementsByTagName("button")[0].innerHTML = strHide;
    document.getElementById(visibilityID).value = "0";
  }
}

function TCDashboardDragDrop( cols, dashboardFrags, bShowDragDrop ) {
  var nRowsCol_1 = 0;
  var nRowsCol_2 = 0;
  var sDashItem;
  var showHideLabel;
  var bShow;
  var Button = YAHOO.widget.Button;
  var newButton;

  for (var c=1;c<cols+1;c++) {
    if ( document.getElementById("TCDragDropArea" + c) ) {
      var newDashList = document.createElement("ul");
      newDashList.className = "TCDragList TCYUITooltip";
      newDashList.id = "TCDragList" + c;
      if ( bShowDragDrop ) {
        newDashList.alt = strDragHere;
        newDashList.title = strDragHere;
      }
      newDashList = document.getElementById("TCDragDropArea" + c).appendChild( newDashList );
    }
  }

  for (var i=0; i<dashboardFrags.length; i++) {
    if ( document.getElementById("TCDragList" + dashboardFrags[i].column) ) {
      var newDashItem = document.createElement("li");
      newDashItem.className = "TCDragItem JSMyDashItem";
      newDashItem.id = "li" + dashboardFrags[i].column + "_" + dashboardFrags[i].order;
      sDashItem = "<table><tr><td class='TCDragItemIcon'>";
      sDashItem = sDashItem + "<img src='icons/topclass8/" + dashboardFrags[i].icon + "' title='" + dashboardFrags[i].label + "' alt='" + dashboardFrags[i].label + "'/>";
      sDashItem = sDashItem + "<\/td><td class='TCDragItemLabel'>";
      sDashItem = sDashItem + dashboardFrags[i].label;
      sDashItem = sDashItem + "<\/td><td class='TCDragItemButton'>";
      sDashItem = sDashItem + "<input type='checkbox' id='TCDDShowHideCheck" + dashboardFrags[i].column + "_" + dashboardFrags[i].order + "' value='" + strShow +"' checked='checked' />";
      sDashItem = sDashItem + "<input type='hidden' id='TCDragItemID_li" + dashboardFrags[i].column + "_" + dashboardFrags[i].order + "' name='TCDragItemID_li" + dashboardFrags[i].column + "_" + dashboardFrags[i].order + "' value='" + dashboardFrags[i].id + "' />";
      sDashItem = sDashItem + "<input type='hidden' id='" + dashboardFrags[i].id + "_order' name='" + dashboardFrags[i].id + "_order' value='" + dashboardFrags[i].order + "' />";
      sDashItem = sDashItem + "<input type='hidden' id='" + dashboardFrags[i].id + "_column' name='" + dashboardFrags[i].id + "_column' value='" + dashboardFrags[i].column + "' />";
      sDashItem = sDashItem + "<input type='hidden' id='" + dashboardFrags[i].id + "_visibility' name='" + dashboardFrags[i].id + "_visibility' value='" + dashboardFrags[i].visibility + "' />";
      sDashItem = sDashItem + "<\/td><\/tr><\/table>";
      newDashItem = document.getElementById("TCDragList" + dashboardFrags[i].column).appendChild( newDashItem );
      newDashItem.innerHTML = sDashItem;
      nRowsCol_1++;
      if ( dashboardFrags[i].visibility ) {
        showHideLabel = strShow;
      } else {
        showHideLabel = strHide;
      }
      if ( dashboardFrags[i].visibility ) {
        bShow = true;
      } else {
        bShow = false;
      }
      newButton = new Button("TCDDShowHideCheck" + dashboardFrags[i].column + "_" + dashboardFrags[i].order,
                                  { label: showHideLabel,
                                    id: "TCDDShowHideButton" + dashboardFrags[i].column + "_" + dashboardFrags[i].order,
                                    checked: bShow,
                                    onclick: { fn: TCOnClickShow("TCDDShowHideButton" + dashboardFrags[i].column + "_" + dashboardFrags[i].order, dashboardFrags[i].id + "_visibility") }
                                  });
    }
  }

  nMyDashRows = nRowsCol_1;
  if ( nRowsCol_2 > nMyDashRows ) {
    nMyDashRows = nRowsCol_2;
  }

}
