function OutputSubsections(subsections, contentsId, selectedContent) {
    // Output all subsections of this section
    for(var iSub = 0; iSub < subsections.length; ++iSub) {
        if(subsections[iSub].id == contentsId) {
            document.write('<div class="sidenav_subsection selected" onClick="LoadSection(\''+subsections[iSub].id+'\');">' + subsections[iSub].name + '</div>');

            // Output all contents of this subsection
            for(var iCnt = 0; iCnt < subsections[iSub].contents.length; ++iCnt) {
                if(!subsections[iSub].contents[iCnt].name)
                    continue;
                
                var clsExtra = '';
                if(subsections[iSub].contents[iCnt].id == selectedContent)
                    clsExtra = ' selected';
                
                document.write('<div class="sidenav_content' + clsExtra + '" onClick="LoadSection(\''+subsections[iSub].contents[iCnt].id+'\');">' + subsections[iSub].contents[iCnt].name + '</div>');
            }
        } else {
            document.write('<div class="sidenav_subsection" onClick="LoadSection(\''+subsections[iSub].id+'\');">' + subsections[iSub].name + '</div>');
        }
    }
}

function OutputSection(section) {
    document.write('<div class="sidenav_section" onClick="LoadSection(\''+section.id+'\');">' + section.name + '</div>');
    
    // If we're loading some content from this section, display the relevant subsections
    if(g_cursec != '') {
        if(g_cursec == section.id) {
            OutputSubsections(section.subsections);
            return;
        }
        
        for(var iSub = 0; iSub < section.subsections.length; ++iSub) {
            if(section.subsections[iSub].id == g_cursec) {
                OutputSubsections(section.subsections, section.subsections[iSub].id);
                return;
            }
            for(var iCnt = 0; iCnt < section.subsections[iSub].contents.length; ++iCnt) {
                if(section.subsections[iSub].contents[iCnt].id == g_cursec) {
                    OutputSubsections(section.subsections, section.subsections[iSub].id, g_cursec);
                    return;
                }
            }
        }
    }
}

// Output the help contents

for(var iSec = 0; iSec < g_sections.length; ++iSec) {
    OutputSection(g_sections[iSec]);
}

