function getQueryVar(name) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for(i=0; i<gy.length; ++i) {
        ft = gy[i].split("=");
        if(ft[0] == name)
            return ft[1];
    }
    return '';
}

g_sections = [];
g_text     = {};
g_cursec   = getQueryVar('sec');

function AddSection(id, name) {
    var section = {};
    section.id   = id;
    section.name = name;
    section.subsections = [];
    
    g_sections.push(section);

    var text = {};
    g_text[id] = text;
    text.name = name;
    text.sectionName = name;
    text.section = section;
}

function AddSubsection(id, name) {
    var subsection = {};
    subsection.id   = id;
    subsection.name = name;
    subsection.contents = [];
    
    g_sections[g_sections.length-1].subsections.push(subsection);

    var text = {};
    g_text[id] = text;
    text.name = name;
    text.sectionName    = g_sections[g_sections.length-1].name;
    text.subsectionName = name;
    text.subsection = subsection;
}

function AddContent(id, name) {
    var content = {};
    content.id    = id;
    content.name  = name;
    
    var subs = g_sections[g_sections.length-1].subsections;
    subs[subs.length-1].contents.push(content);

    var text = {};
    g_text[id] = text;
    text.name = name;
    text.sectionName    = g_sections[g_sections.length-1].name;
    text.subsectionName = subs[subs.length-1].name;
    text.contentName    = name;
}

function AddText(id, html) {
    if(id == '')
        return;
    g_text[id].html = html;
}

function LoadSection(id) {
    window.location.href = 'index.html?sec=' + id;
    return true;
}

