<!--
/*****************************************************************************
*        File: events.js
* Description: Code to manage the display of the various events
*****************************************************************************/
var sizeExtra = 60;
var PDFStdHeight = 1100;
var baseHeight = 100;

/*****************************************************************************
*       Class: Event
* Description: Class to hold table of contents information about an event
*  Parameters: eventPage - Web page where the content is located
*              eventDesc - The description/title that will be displayed in
*                          the table of events
*              tagName - The short name of the event.  Used for linking.
*              local -  True if the the page to display is local to the
*                       website
*****************************************************************************/
function Event(eventPage, eventDesc, tagName, local) {

    this.page = eventPage;
    this.title = eventDesc;
    this.tagName = tagName;
    this.getTOEEntry = makeTOEEntry;

    if (local == undefined)
        this.local = true;
    else
        this.local = local;

}

/*****************************************************************************
*      Method: makeTOEEntry
* Description: Generate the entry for the Table of Contents
*  Parameters: list - The varable that holds the event list
*     Returns: String
*****************************************************************************/
function makeTOEEntry(list) {
    var resolve;

    if (browserIE())
        resolve = 'false';
    else
        resolve = 'true';

    return '<a href=\'javascript: parent.' + list + '.gotoPage("' +
           this.tagName + '", ' + resolve + ');\'>' + this.title + '</a><br>';

}

/*****************************************************************************
*       Class: Events
* Description: Class to hold a list of events
*  Parameters: None
*****************************************************************************/
function Events() {

    this.table = new Array();
    this.current = 0;
    this.getLength = toeLen;
    this.add = toeAdd;
    this.next = toeNext;
    this.previous = toePrev;
    this.gotoPage = toeGoto;
    this.toe = toeShowTable;
    this.frame = null;
    this.frameID = '';
    this.framePos = 0;
    this.prevButton = null;
    this.nextButton = null;
    this.setButtons = toeSetButtons;
    this.setSize = toeSetSize;
    this.makeTOE = buildTOE;
    this.fixPath = toeFixPath;

}

/*****************************************************************************
*      Method: toeLen
* Description: Method to return the number of items in the event list
*  Parameters: None
*     Returns: Integer - The number of events in the event list
*****************************************************************************/
function toeLen() {

    return this.table.length;

}

/*****************************************************************************
*      Method: toeAdd
* Description: Method to add an event to the list
*  Parameters: event - An Event object
*     Returns: Nothing
*****************************************************************************/
function toeAdd(event) {

    this.table.push(event);

}

/*****************************************************************************
*      Method: toeNext
* Description: Method to move to the next event
*  Parameters: None
*     Returns: The next event in the list
*****************************************************************************/
function toeNext() {

    if (this.current + 1 < this.table.length)
        this.current++;

    this.frame.location.href = this.table[this.current].page;
    this.setButtons();

    return this.table[this.current].page;

}

/*****************************************************************************
*      Method: toePrev
* Description: Method to move to the previous event
*  Parameters: None
*     Returns: The previous event in the list
*****************************************************************************/
function toePrev() {

    if (this.current > 0)
        this.current--;

    this.frame.location.href = this.table[this.current].page;
    this.setButtons();

    return this.table[this.current].page;

}

/*****************************************************************************
*      Method: toeGoto
* Description: Method to go to a selected event
*  Parameters: tag - The tag of the page to goto
*              resolve - True if the page path needs to be resolved
*     Returns: Boolean - True if a match for the tag was found
*****************************************************************************/
function toeGoto(tag, resolve) {
    var found = false;
    var i;

    for (i = 0; i < this.table.length && !found; i++)
        if (this.table[i].tagName.toUpperCase() == tag.toUpperCase()) {
            this.current = i;

            if (resolve)
                this.frame.location.href = this.fixPath(this.table[i].page);
            else
                this.frame.location.href = this.table[i].page;

            this.setButtons();

            found = true;
        }

    return found;

}

/*****************************************************************************
*      Method: toeShowTable
* Description: Method to display the table of events
*  Parameters: None
*     Returns: The Table of Events event
*****************************************************************************/
function toeShowTable() {

    this.current = 0;

    this.frame.location.href = this.table[0].page;
    this.setButtons();

    return this.table[0].page;

}

/*****************************************************************************
*      Method: toeSetButtons
* Description: Turn the buttons on or off
*  Parameters: None
*     Returns: Nothing
*****************************************************************************/
function toeSetButtons() {

    this.nextButton.disabled = (this.current + 1 >= this.table.length);
    this.prevButton.disabled = (this.current <= 0);

}

/*****************************************************************************
*      Method: toeSetSize
* Description: Sets the height of the iFrame
*  Parameters: None
*     Returns: Nothing
*****************************************************************************/
function toeSetSize() {
    var pdf = '.pdf';
    var iframe = document.getElementById(this.frameID);
    var pageHref = this.table[this.current].page.toLowerCase();

    // Determine the index of the frame in the frame list
    if (pageHref.lastIndexOf(pdf) == pageHref.length - pdf.length)
        iframe.height = PDFStdHeight + sizeExtra;
    else {
        // Reset the frame height.  This is required for FireFox
        if (!browserIE())
            iframe.height = baseHeight;

        try {
            iframe.height = window.frames[this.frameID].scrollMaxY +
                            parseInt(iframe.height) + sizeExtra;
        }
        catch (e) {
            iframe.height = PDFStdHeight + sizeExtra;
        }

        try {
            window.frames[this.frameID].document.body.style.backgroundColor = iframe.style.backgroundColor;
        }
        catch (e) {
        }

    }

}

/*****************************************************************************
*      Method: buildTOE
* Description: Generate a table of coents
*  Parameters: list - The variable that holds the event list
*     Returns: String
*****************************************************************************/
function buildTOE(list) {
    var toe = '';
    var i;

    // Start with 1 because the TOC should not be shown in the TOC
    for (i = 1; i < this.getLength(); i++)
        toe += this.table[i].getTOEEntry(list);

    return toe;

}

/*****************************************************************************
*      Method: buildTOE
* Description: Generate a table of coents
*  Parameters: path - The path to fix
*     Returns: String
*****************************************************************************/
function toeFixPath(list) {
    var resolved = list;
    var i;

    // If the path contains a colon, assume it is a full path
    if (resolved.indexOf(':') < 0) {
        i = resolved.lastIndexOf('/');

        if (i >= 0)
            resolved = resolved.substr(i + 1);

    }

    return resolved;

}
//-->
