////// Define all the functions used to enhance this page.



//// Expand or colapse a topic.
function changeTopic(theParent)
    {
    if (theParent.getElementsByTagName)
        {

        // Change the link.
        var theHeaders = theParent.getElementsByTagName('th');
        for (var i = 0; i < theHeaders.length; i++)
            {
            var theLinks = theHeaders[i].getElementsByTagName('a');
            for (var j = 0; j < theLinks.length; j++)
                {
                if (theLinks[j].getAttribute)
                    {
                    var theClass = theLinks[j].getAttribute('class');

                    // Begin compensating for IE.
                    var theClassName = theLinks[j].getAttribute('className');
                    if (theClass == null) { theClass = theClassName; }
                    // End compensating for IE.

                    if (theLinks[j].setAttribute)
                        {
                        if (theClass == 'colapse')
                            {
                            // Display a link to expand a topic.
                            theLinks[j].setAttribute('class', 'expand');
                            theLinks[j].setAttribute('className', 'expand');
                            theLinks[j].setAttribute('title', 'expand');
                            }
                        else // if (theClass == 'expand')
                            {
                            // Display a link to colapse a topic.
                            theLinks[j].setAttribute('class', 'colapse');
                            theLinks[j].setAttribute('className', 'colapse');
                            theLinks[j].setAttribute('title', 'colapse');
                            }
                        }
                    }
                }
            }

        // Change the topic.
        var theDivs = theParent.getElementsByTagName('tr');
        for (var i = 0; i < theDivs.length; i++)
            {
            if (theDivs[i].getAttribute)
                {
                var theClass = theDivs[i].getAttribute('class');

                // Begin compensating for IE.
                var theClassName = theDivs[i].getAttribute('className');
                if (theClass == null) { theClass = theClassName; }
                // End compensating for IE.

                if (theDivs[i].setAttribute)
                    {
                    if (theClass == 'replace')
                        {
                        // Colapse an expanded topic.
                        theDivs[i].setAttribute('class', 'hidden');
                        theDivs[i].setAttribute('className', 'hidden');
                        }
                    else if (theClass == 'hidden')
                        {
                        // Expand a colapsed topic.
                        theDivs[i].setAttribute('class', 'replace');
                        theDivs[i].setAttribute('className', 'replace');
                        }
                    else
                        {
                        // Do nothing.
                        }
                    }
                }
            }

        }
    else
        {
        return true;
        }
    }



//// Modify a list of topics.
function setTopics()
    {
    if (document.getElementsByTagName)
        {

        //// Create a link within each topic header
        //// to expand and colapse each topic.
        var theHeaders = document.getElementsByTagName('th');
        for (var i = 0; i < theHeaders.length; i++)
            {
            var theDivs = theHeaders[i].getElementsByTagName('span');
            for (var j = 0; j < theDivs.length; j++)
                {
                //var newText = theDivs[j].textContent;
                var newText = theDivs[j].firstChild.nodeValue;
                if (theDivs[j].getAttribute)
                    {
                    var theClass = theDivs[j].getAttribute('class');

                    // Begin compensating for IE problems.
                    var theClassName = theDivs[j].getAttribute('className');
                    if (theClass == null) { theClass = theClassName; }
                    // End compensating for IE problems.

                    if ( (theClass == 'replace_link') && (document.createElement) )
                        {
                        var newLink = document.createElement('a');
                        if ( (newLink.setAttribute) && (newLink.appendChild) && (document.createTextNode) )
                            {
                            newLink.setAttribute('href', '#');
                            newLink.setAttribute('title', 'expand');
                            newLink.setAttribute('class', 'expand');
                            newLink.setAttribute('className', 'expand');
                            newLink.appendChild(document.createTextNode(newText));
                            if (theDivs[j].parentNode.replaceChild)
                                {
                                theDivs[j].parentNode.replaceChild(newLink, theDivs[j]);
                                }
                            }
                        }

                    }
                }
            }

        //// Colapse each topic.
        var theTopics = document.getElementsByTagName('tr');
        for (var k = 0; k < theTopics.length; k++)
            {
            if (theTopics[k].getAttribute)
                {
                var theClass = theTopics[k].getAttribute('class');

                // Begin compensating for IE problems.
                var theClassName = theTopics[k].getAttribute('className');
                if (theClass == null) { theClass = theClassName; }
                // End compensating for IE problems.
                
                if ( (theClass == 'replace') && (theTopics[k].setAttribute) )
                    {
                    theTopics[k].setAttribute('class', 'hidden');
                    theTopics[k].setAttribute('className', 'hidden');
                    }
                }
            }

        }
    else
        {
        return true;
        }
    }



//// Check for links that expand and colapse topics.
function setTopicLinks()
    {
    if (document.getElementsByTagName)
        {
        var theHeaders = document.getElementsByTagName('th');
        for (var i = 0; i < theHeaders.length; i++)
            {
            var theLinks = document.getElementsByTagName('a');

            for (var j = 0; j < theLinks.length; j++)
                {
                if (theLinks[j].getAttribute)
                    {
                    var theClass = theLinks[j].getAttribute('class');

                    // Begin compensating for IE.
                    var theClassName = theLinks[j].getAttribute('className');
                    if (theClass == null) { theClass = theClassName; }
                    // End compensating for IE.
                
                    // Links that expand and colapse sublists.
                     if ( (theClass == 'expand') || (theClass == 'colapse') )
                        {
                        theLinks[j].onclick = function() { changeTopic(this.parentNode.parentNode.parentNode); return false; }
                        }
                    }
                }
            }
        }
    }



//// Expand one topic.
function setFirstTopic()
    {
    if (document.getElementsByTagName)
        {
        var theImages = document.getElementsByTagName('img');
        for (var i = 0; i < theImages.length; i++)
            {
            if (theImages[i].getAttribute)
                {
                var theClass = theImages[i].getAttribute('class');

                // Begin compensating for IE.
                var theClassName = theImages[i].getAttribute('className');
                if (theClass == null) { theClass = theClassName; }
                // End compensating for IE.

                // Image with an id that hides the id of the topic to expand.
                if (theClass == 'namesake')
                    {
                    var theNamesakeID = theImages[i].getAttribute('id');
                    var theID = 'd' + theNamesakeID.substring(4);
                    var theTopic = document.getElementById(theID);
                    changeTopic(theTopic);
                    }
                }
            }
        }
    }



////// Call all the functions used to enhance this page.
addToPage(setTopics);
addToPage(setTopicLinks);
addToPage(setFirstTopic);