////// Define all the functions used to enhance the page "index.php".



//// Expand or colapse a sublist.
function changeList(theParent)
    {
    if (theParent.getElementsByTagName)
        {
        var theDivs = theParent.getElementsByTagName('div');
        for (var i = 0; i < theDivs.length; i++)
            {
            if (theDivs[i].getAttribute)
                {
                var theDivsClass = theDivs[i].getAttribute('class');

                // Begin compensating for IE.
                var theDivsClassName = theDivs[i].getAttribute('className');
                if (theDivsClass == null) { theDivsClass = theDivsClassName; }
                // End compensating for IE.

                if (theDivs[i].setAttribute)
                    {
                    if (theDivsClass == 'hidden')
                        {
                        // Expand a colapsed sublist.
                        theDivs[i].setAttribute('class', 'replace');
                        theDivs[i].setAttribute('className', 'replace');
                        }
                    else if (theDivsClass == 'replace')
                        {
                        // Colapse an expanded sublist.
                        theDivs[i].setAttribute('class', 'hidden');
                        theDivs[i].setAttribute('className', 'hidden');
                        }


                    // Change the look of the link that triggers this function.
                    var theHeaders = theDivs[i].parentNode.getElementsByTagName('h3');
                    for (var j = 0; j < theHeaders.length; j++)
                        {
                        var theLinks = theHeaders[j].getElementsByTagName('a');
                        for (var k = 0; k < theLinks.length; k++)
                            {
                            if (theLinks[k].getAttribute)
                                {
                                var theLinksClass = theLinks[k].getAttribute('class');

                                // Begin compensating for IE.
                                var theLinksClassName = theLinks[k].getAttribute('className');
                                if (theLinksClass == null) { theLinksClass = theLinksClassName; }
                                // End compensating for IE.

                                if ( (theLinks[k].setAttribute) && (theLinks[k].removeChild) && (theLinks[k].appendChild) && (document.createTextNode) )
                                    {
                                    if (theLinksClass == 'plus')
                                        {
                                        // Change a link to open into a link to close.
                                        theLinks[k].setAttribute('class', 'minus');
                                        theLinks[k].setAttribute('className', 'minus');
                                        theLinks[k].setAttribute('title', 'close this list');
                                        theLinks[k].removeChild(theLinks[k].firstChild);
                                        theLinks[k].appendChild(document.createTextNode('- close'));
                                        }
                                    else if (theLinksClass == 'minus')
                                        {
                                        // Change a link to close into a link to open.
                                        theLinks[k].setAttribute('class', 'plus');
                                        theLinks[k].setAttribute('className', 'plus');
                                        theLinks[k].setAttribute('title', 'open this list');
                                        theLinks[k].removeChild(theLinks[k].firstChild);
                                        theLinks[k].appendChild(document.createTextNode('+ open'));
                                        }
                                    }
                                }
                            }
                        }

                    }
                }
            }
        }
    }



//// Modify a list:
////     Colapse each sublist.
////     Create links to expand and colapse each sublist.
function setLists()
    {
    if (document.getElementsByTagName)
        {

        var theDivs = document.getElementsByTagName('div');

        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.

                // Create links to expand and colapse each sublist.
                if ( (theClass == 'replace_link') && (document.createElement) )
                    {
                    var newLink = document.createElement('a');
                    if ( (newLink.setAttribute) && (newLink.appendChild) && (document.createTextNode) )
                        {
                        newLink.setAttribute('href', '#');
                        newLink.setAttribute('title', 'open this list');
                        newLink.setAttribute('class', 'plus');
                        newLink.setAttribute('className', 'plus');
                        newLink.appendChild(document.createTextNode('+ open'));
                        if (theDivs[i].parentNode.replaceChild)
                            {
                            theDivs[i].parentNode.replaceChild(newLink, theDivs[i]);
                            }
                        }
                    }

                // Colapse each sublist.
                if (theClass == 'replace_holding')
                    {
                    theSubDivs = theDivs[i].getElementsByTagName('div');

                    for (var j = 0; j < theSubDivs.length; j++)
                        {
                        var theSubClass = theSubDivs[j].getAttribute('class');

                        // Begin compensating for IE.
                        var theSubClassName = theSubDivs[j].getAttribute('className');
                        if (theSubClass == null) { theSubClass = theSubClassName; }
                        // End compensating for IE.

                        if (theSubClass == 'replace')
                            {
                            theSubDivs[j].setAttribute('class', 'hidden');
                            theSubDivs[j].setAttribute('className', 'hidden');
                            }
                        }
                    }


                }
            }

        }
    }



//// Check for links that require special behaviors.
function setListLinks()
    {
    if (document.getElementsByTagName)
        {
        var theLinks = document.getElementsByTagName('a');

        for (var i = 0; i < theLinks.length; i++)
            {
            if (theLinks[i].getAttribute)
                {
                var theClass = theLinks[i].getAttribute('class');

                // Begin compensating for IE.
                var theClassName = theLinks[i].getAttribute('className');
                if (theClass == null) { theClass = theClassName; }
                // End compensating for IE.
                
                // Links that expand and colapse sublists.
                if ( (theClass == 'plus') || (theClass == 'minus') )
                    {
                    theLinks[i].onclick = function() { changeList(this.parentNode.parentNode); return false; }
                    }
                }
            }
        }
    }



////// Call all the functions used to enhance this page.
addToPage(setLists);
addToPage(setListLinks);
