/******************************************************************************

  File: topclass.js
  Author: eweb
  Copyright WBT Systems, 1999-2007
  Contents:
  Version: 7.4.2
  Build: 025

 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
   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.
   23   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.
*/

var allTabs = new Array();
var tableTitle;
var tabIndex = -1;
var reportWindow = null;

var catregurls = new Object();
catregurls["browse"]="<plugin-catreg-L1";
catregurls["search"]="<plugin-catreg-L2";

catregurls["offerings"]="<plugin-catreg-offerings";
catregurls["categories"]="<plugin-catreg-categories";
catregurls["ilt"]="<plugin-catreg-ilt";
catregurls["locations"]="<plugin-catreg-locations";
catregurls["settings"]="<plugin-catreg-settings";

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 )
  {
    if( document.forms[formName] )
      {
        var theForm = document.forms[formName];
        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;

            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 )
      {
        return true;
      }

    if ( theForm.submitcount.value == 0 )
      {
        theForm.submitcount.value++;
        return true;
      }
    else
      {
        if ( TCSubmitOption == kSilentRefusal )
          {
            return false;
          }
        if ( TCSubmitOption == kAlert )
          {
            alert( TCAlertString );
            return false;
          }
        if ( TCSubmitOption == kChoice )
          {
            return confirm( TCConfirmString );
          }
      }
  }


// 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()
  {

    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;
      }
  }

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 )
  {
    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 )
  {
    if ( window && window.opener && window.opener.document )
      {
        window.opener.location = TCCommandPrefix + '-' + DoPercentChars( value );
        close();
      }
    else
      {
        close();
      }
    return false;
  }

function TCSetLocation( value )
  {
    if ( window && window.opener )
      {
        window.opener.location = TCCommandPrefix + '-' + value;
        close();
      }
    else
      {
        close();
      }
  }
function TCClickedSetLocationCommand( value, command )
  {
    if ( window && window.opener && window.opener.document )
      {
        window.opener.location = command + '-' + DoPercentChars( value );
        close();
      }
    else
      {
        close();
      }
  }

function TCClickedSetValue(value,field,button)
  {
    if ( !window ||
         !window.opener ||
         !window.opener.document ||
         !window.opener.document.forms ||
         window.opener.document.forms.length == 0 ||
         !window.opener.document.forms[0] )
      {
        alert( "Can't find form" );
        close();
        return;
      }
    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 == field )
              {
                found = true;
                break;
              }
          }
        if( found ) break;
      }
    if ( !found )
      {
        alert( "Can't find form element [" + field + "]" );
        close();
        return;
      }

    if ( !(TCPopup_SingleSelect()) && (window.opener.document.forms[j].elements[field].value != "") )
      {
        window.opener.document.forms[j].elements[field].value = window.opener.document.forms[j].elements[field].value + "," + value;
      }
    else
      {
        window.opener.document.forms[j].elements[field].value = value;
      }
    if ( button && button != '*' )
      {
        if ( window.opener.document.forms[j].elements[button] )
          {
            //Nicholas Murphy 09-Mar-2004  remove the backlink
            bklink = window.opener.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 = window.opener.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();
              }

            //window.opener.document.forms[j].elements[button].click();
          }
        else
          {
            if ( window.opener.document.forms[j].elements['TC'] )
              {
                window.opener.document.forms[j].elements['TC'].name = button;
                //Nicholas Murphy 09-Mar-2004  remove the backlink
                bklink = window.opener.document.getElementById("backlink");
                if (bklink)
                {
                  bklink.value=" ";
                }

                window.opener.document.forms[j].submit();
              }
          }
      }
    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'];
    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()
  {
    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";
        }
        else if( TCArgsLowerCase.indexOf( "reorder-course-" ) > -1 ) {
            TCArgsLowerCase = "reorder-course";
        }
    }
    var HelpUrl = TCPathToTopClass.substring( 0, 1 + TCPathToTopClass.lastIndexOf('/') ) + "chelp/" + TCLanguage + "/" + usertype + "/" + TCArgsLowerCase + ".htm";
    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.forms['EditObject'].submit();
    top.window.close();
  }

function TCOpenOperationsWizardForDynamicOp( group, operation, join )
  {
    this.document.forms['EditObject'].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(id),false);
  }
  else if (mytccindex.document.getElementById(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(id),false);
    var mycheckbox= mytccindex.document.getElementById(id+"_unread");
    if (mycheckbox && mycheckbox.checked == true)
    {
      mycheckbox.checked=false;
      var myimg = mytccindex.document.getElementById(id+"_statusgraphic");
      if (myimg)
      {
         myimg.src = 'icons/' + TCLanguage + '/ulmstatus1.gif';
      }
      else
      {
        debugAlert("couldn't find image for " + id + "_statusgraphic"+ "\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(id);
  var obj_unread = mytccindex.document.getElementById(id+"_unread");
  if (obj && obj_unread )
  {
    var node_id = obj.parentNode.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(eval(node_id.lastIndexOf("-")+"+1"),node_id.lastIndexOf("_"));
    objid=parenttwisterid + "_contents";
    debugAlert("updateStatusGraphic", "trying " + parenttwisterid+ "\n");
    var parent = mytccindex.document.getElementById(objid);
    if (parent)
    {
      var kids = mytccindex.document.getElementsByName(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(parenttwisterid+"_unread");
        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(parenttwisterid+"_statusgraphic");
          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(obj)
   {
     id = obj.id;
     mydiv = document.getElementById(id+"_contents");
     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 " + id + "_contents");
     }
     */
     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 + "Group-Tree";

    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;
                 }
              }
          }
        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;
                  }
              }
          }
      }
  }

// 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.SelectTreeField)
      {
        for (var form_loop = 0; form_loop < window.opener.document.forms.length; form_loop ++)
          {
            if (window.opener.document.forms[form_loop].elements[window.opener.SelectTreeField])
              {
                if (window.opener.submitForm)
                {
                  window.opener.document.forms[form_loop].elements[window.opener.SelectTreeField].value = id;
                  window.opener.submitForm(id);
                }
                else
                {
                  window.opener.document.forms[form_loop].elements[window.opener.SelectTreeField].value = shortname;
                }
                if (window.opener.CloseOnSelect)
                  {
                    window.close();
                  }
                return;
              }
          }
      }
    else
      {
        window.close();
      }
  }


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;
  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;
    }

  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 = "";
    }
  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(is.ie6 && 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( !(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();
    }
}


function EditObjectFromGroup(cmd, id)
{
  //Nicholas Murphy 15-Mar-2004  lowercase the comparisson.
  if ((indx = window.location.href.toLowerCase().indexOf("edit-object")) > -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 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;

     dest = document.getElementById(destination_id);
     if(dest && dest.value==1)
     {
        var len = reports_command.length;
        reports_command=reports_command + "&Format=PDF";
     }

     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 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 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('http://gotham:9123/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 (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) );

  // 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 "";
      }
  }
