function Section_Choice_Init(sid)
{
    h = fetch_object('sections_select_div');
    h.innerHTML = '';
    
    cta = new Array();
    i = 0;
    
    if (PHP_Emulator_array_key_exists(sid, Sections)){
        cta[0] = Section_Choice_Load_Select(sid, 0);
    } else {
        cta[0] = Section_Choice_Load_Btn(sid);
    }
    
    if (sid != 0){
        do {
            u_sid = sid;
            
            for (key in Sections){
                if (PHP_Emulator_in_array(sid, Sections[key]))
                {
                    sid = key;
                    break;
                }
            }
            i ++;
            if (PHP_Emulator_array_key_exists(sid, Sections)){
                cta[i] = Section_Choice_Load_Select(sid, u_sid);
            }
        } while (!PHP_Emulator_in_array(u_sid, Sections[0]));
    }
    
    for (i = cta.length - 1; i >=0; i --){
        h.innerHTML += cta[i];
    }
}

function Section_Choice_Load_Select(sid, ssid)
{
    ss = '<select onChange="(Section_Choice_Init(this.options[this.selectedIndex].value));">';
    ss += '<option value=0></option>';
    for (key in Sections[sid]){
        isid = Sections[sid][key];
        ss += '<option value="' + isid + '"';
        if (isid == ssid){
            ss += ' selected';
        }
        ss += '>' + SectionTitles[isid] + '</option>';
    }
    
    ss += '</select>';
    ss += '<br>';
    
    return ss;
}

function Section_Choice_Load_Btn(sid)
{   
    var b;
    b = '<input type="button" value="' + section_choise_btn + '" onClick="location.replace(\'' + SectionPaths[sid] + 'add.php\')">';
    
    return b;
}

function sections__last_select(sid, uid)
{
    h = fetch_object('last_select_div');

    ss = '<select onChange="location.replace(SectionPaths[this.options[this.selectedIndex].value]);">';
    for (key in Sections[uid]){
        isid = Sections[uid][key];
        ss += '<option value="' + isid + '"';
        if (isid == sid){
            ss += ' selected';
        }
        ss += '>' + SectionTitles[isid] + '</option>';
    }
    
    ss += '</select>';
    
    h.innerHTML = ss;
}