// a class to track which section of the page needs updating.
// page that needs section reload should implement the update method to specify how each section should reload
function SectionReload(sectArray, reloadAll) {
    // reloadAll indicates whether the section should reload b4 user's interaction w/ the page, if null, default to false which means the data is loaded on page load
    this.sectionArray = sectArray;
    this.reload = new Array();

    for (var i = 0; i < sectArray.length; i++) {
        if (reloadAll != null && reloadAll)
            this.reload[i] = true;
        else
            this.reload[i] = false;
    }
    this.currentSection = 0;
}
SectionReload.prototype.currentSectionName = function() {
    return this.sectionArray[this.currentSection];
}
SectionReload.prototype.reloadCurrent = function() {
    this.reload[this.currentSection] = true;
    this.update(this.currentSection);
//    this.reload[this.currentSection] = false;
}
SectionReload.prototype.reloadOther = function() {
    for (var i = 0; i < this.reload.length; i++) {
        if (i != this.currentSection)
            this.reload[i] = true;
    }
}
SectionReload.prototype.reloadAll = function() {
    this.reloadCurrent();
    this.reloadOther();
}
SectionReload.prototype.reloadAllExcept = function(name) {
    var targetSection = null;
    for (var i = 0; i < this.sectionArray.length; i++) {
        if (this.sectionArray[i] == name)
            targetSection = i;
    }
    if (targetSection == null) return;
    
    if (this.currentSection == targetSection)
        this.reloadOther();
    else {
        for (var i = 0; i < this.reload.length; i++) {
            if (i != targetSection)
                this.reload[i] = true;
        }
        this.reloadCurrent();
    }
}
SectionReload.prototype.reloadByNameArray = function(nameArray) {
    for (var i = 0; i < nameArray.length; i++)
        this.setReloadByName(nameArray[i]);
    this.update(this.currentSection);
}
SectionReload.prototype.setReloadByName = function(name) {
    for (var i = 0; i < this.sectionArray.length; i++) {
        if (this.sectionArray[i] == name)
            this.reload[i] = true;
    }
}
SectionReload.prototype.update = function () {}
