function determineVisibility() {
    var vars = getUrlVars();
    var app = vars["app"];
    var role = vars["role"];

    if (role == "fiadmin") {
        showAll();
    } else {
        hideAll();
        showSpecificSections(role, app);
    }
}

function showSpecificSections(role, app) {
    alert("role=" + role);
    alert("app=" + app);

    switch (app) {
        case "idl":
            showIdlSections();
            break;
        case "deposit":
            showDepositSections();
            break;
    }
}

function showIdlSections() {

    showById("area1");
    showById("area2");
}

function showDepositSections() {
    showById("area3");
    showById("area4");

}

function setCookies(app, role) {
    //alert("setting cookies");
    document.cookie = "app=" + app + ";";
    document.cookie = "role=" + role + ";";
    
}

function getCookies() {
    //alert("getting cookies");
    var vars = {};
    vars["app"] = getCookie("app");
    vars["role"] = getCookie("role");
    return vars;
}

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
    function (m, key, value) {
        vars[key] = value;
    });
    if (vars["app"] == null || vars["role"] == null) {
        vars = getCookies();
    } else {
        setCookies(vars["app"], vars["role"]);
    }
    return vars;
}

function hideAll() {
    var divs = document.getElementsByTagName('div');
    for (i = 0; i < divs.length; i++) {
        divs[i].style.visibility = "hidden"; 
    }
}

function showAll() {
    var divs = document.getElementsByTagName('div');
    for (i = 0; i < divs.length; i++) {
        divs[i].style.visibility = "visible";
    }
}

function getCookie(name) {
    var value = document.cookie;
    var start = value.indexOf(" " + name + "=");
    if (start == -1) {
        start = value.indexOf(name + "=");
    }
    if (start == -1) {
        value = null;
    }
    else {
        start = value.indexOf("=", start) + 1;
        var end = value.indexOf(";", start);
        if (end == -1) {
            end = value.length;
        }
        value = unescape(value.substring(start, end));
    }
    return value;
}

function showById(id) {
    var el = document.getElementById(id);
    el.style.visibility = "visible";
}