/////////////////////////////////////////////////////////////////////////////
// Function : JOP_Sitemap
// Comments :
/////////////////////////////////////////////////////////////////////////////

var idValue = "";

function JOP_Sitemap(folderList,folderStart)
{
    //This is the list of Folders to Display
    this.Listing = folderList;

    //This is the list of Styles to Display
    this.ListStart = folderStart - 1;

    //This is the Navigation Path
    this.m_NavPath = g_navNode_Path;

    this.HTMLHeadingList = new Array();
    this.HTMLContentList = new Array();

    JOP_Sitemap.prototype.Display       = JOP_Sitemap_Display;
    JOP_Sitemap.prototype.nodeGathering = JOP_Sitemap_nodeGathering;
    JOP_Sitemap.prototype.pathInList    = JOP_Sitemap_pathInList;
}


function JOP_Sitemap_Display (node)
{
    this.nodeGathering(node);
    placeHolder = 0;
    colspan     = 0;

    if (this.HTMLContentList.length > 0) {
        document.write('<table cellspacing="0" id="sitemap" summary="Sitemap for Edward Jones\' Career Web Site">');

        for (var y = 0; y < this.HTMLHeadingList.length; y++) {

            if ( (y == 0) || ((y % 3) == 0) ) {

                document.write('<tr>');
                document.write(this.HTMLHeadingList[y]);

            } else if ((y % 3) == 2) {

                document.write(this.HTMLHeadingList[y]);
                document.write('</tr>');
                document.write('<tr>');

                for (var placeHolder=placeHolder; placeHolder <= y; placeHolder++) {
                    document.write(this.HTMLContentList[placeHolder]);
                }
                document.write('</tr>');

            } else if ( this.HTMLHeadingList.length == (y + 1) ) {

                colspan = ((y + 1) % 3);

                document.write(this.HTMLHeadingList[y]);
                document.write('<td colspan="' + colspan + '"></td>');
                
                for (var placeHolder=placeHolder; placeHolder <= y; placeHolder++) {
                    document.write(this.HTMLContentList[placeHolder]);
                }
                document.write('<td colspan="' + colspan + '"></td>');
                document.write('</tr>');

            } else {

                document.write(this.HTMLHeadingList[y]);
            }
        }
        document.write('</table>');
    }
}


function JOP_Sitemap_nodeGathering (node)
{
    if ( (this.pathInList(node.m_href) ) > -1 ) {

        this.HTMLHeadingList[this.pathInList(node.m_href)] = '<td class="sitemaphdr"><a href="' + node.m_href + '">' + node.m_label + '</a></td>';
        this.HTMLContentList[this.pathInList(node.m_href)] = '<td class="sitemapcontent">';

        if ( node.m_level > this.ListStart) {
            parentLabel = node.m_parent.m_label;
            this.HTMLContentList[this.pathInList(node.m_href)] += ('<font class="parentHeading">' + parentLabel.toUpperCase() + '</font>');
        }

        if ( node.m_subNodes.length > 0 ) {
            this.HTMLContentList[this.pathInList(node.m_href)] += '<ul>';

            for (var i = 0; i < node.m_subNodes.length ; i++) {
                this.HTMLContentList[this.pathInList(node.m_href)] += '<li><a href="' + node.m_subNodes[i].m_href + '">' + node.m_subNodes[i].m_label + '</a>';

                if ( node.m_subNodes[i].m_subNodes.length > 0 ) {
                    this.HTMLContentList[this.pathInList(node.m_href)] += '<ul>';

                    for (var j = 0; j < node.m_subNodes[i].m_subNodes.length ; j++) {
                        this.HTMLContentList[this.pathInList(node.m_href)] += '<li><a href="' + node.m_subNodes[i].m_subNodes[j].m_href + '">' + node.m_subNodes[i].m_subNodes[j].m_label + '</a></li>';
                    }
                    this.HTMLContentList[this.pathInList(node.m_href)] += '</ul>';
                }
                this.HTMLContentList[this.pathInList(node.m_href)] += '</li>';
            }
            this.HTMLContentList[this.pathInList(node.m_href)] += '</ul>';
        }
        this.HTMLContentList[this.pathInList(node.m_href)] += '</td>';
    } 

    for (var i = 0; i < node.m_subNodes.length; i++) {
       this.nodeGathering(node.m_subNodes[i]);
    }
}


function JOP_Sitemap_pathInList (folderPath)
{
    var returncode = -1;

    for (var i = 0; i < this.Listing.length; i++) {
        if (folderPath.indexOf(this.Listing[i]) > -1) {
            returncode = i;
        }
    }
    return returncode;
}
