var DOM = (document.getElementById) ? true : false;

var expands;

checkOpenSubs();

function openSubCategories(num) {
    var el = getSubs(num);
    show(el);
    
    el = getPlus(num);
    hide(el);
    
    el = getMinus(num);
    show(el);
    
    addOpened(num);
    
    return true;
}

function closeSubCategories(num) {
    var el = getSubs(num);
    hide (el);
    
    el = getPlus(num);
    show (el);
    
    el = getMinus(num);
    hide (el);
  
    removeClosed(num);
}

function show(el) {
    if (el) {
        el.style.position = "relative";
        el.style.visibility = "visible";
    }
}

function hide(el) {
    if (el) {
        el.style.position = "absolute";
        el.style.visibility = "hidden";
    }
}

function getSubs(num) {
    if (DOM) {
        return document.getElementById("sub_links_show_" + num);
    } else {
        return document.all["sub_links_show_" + num];
    }
}

function getPlus(num) {
    if (DOM) {
        return document.getElementById("plus_" + num);
    } else {
        return document.all["plus_" + num];
    }
}

function getMinus(num) {
    if (DOM) {
        return document.getElementById("minus_" + num);
    } else {
        return document.all["minus_" + num];
    }
}

function addOpened(num) {
    for (i = 0; i < parent.dlc_profile.expands.length; ++i) {
        if (parent.dlc_profile.expands[i] == num) {
            // already there!
            return;
        }
    }
    parent.dlc_profile.expands[parent.dlc_profile.expands.length] = num;
}

function removeClosed(num) {
    for (i = 0; i < parent.dlc_profile.expands.length; ++i) {
        if (parent.dlc_profile.expands[i] == num) {
            // found
            parent.dlc_profile.expands[i] = -1;  // -1 means invalid
            return;
        }
    }
}

function checkOpenSubs() {
    var newArr = new Array();
    
    if (!expands) {
        expands = new Array();
    }
    
    for (i = 0; i < expands.length; ++i) {
        if (expands[i] != -1) {
            openSubCategories(expands[i]);
            newArr[newArr.length] = expands[i];
        }
    }
    
    expands = newArr;
}
