I'm still waiting for my changes to be pushed from dev to staging, so if my last changes work this will be for nothing. 
Here goes.. when the page first loads, there is no client selected so no data is displayed - no data, no categories, so nothing happens. Upon selecting a client from a drop down menu, there is an onChange event that (in addition to querying the database for client information) does the following:
onChange="document.cookie='vddstatus=\'\'; expires=Wed, 31 Dec 1980 23:59:11 UTC; path=/';"
It erases the cookie (expires it and sets it blank so the browser doesn't see it.)
When the page loads with data, a function is then automatically run:
function setDivState() {
allNames = "";
allDivs = document.getElementsByTagName('div');
b=0;
cookieValue = "vddstatus=";
for(a=0;a<allDivs.length;a++) {
if(allDivs[a].className == "input-table") { // Gets only divs that are expandable/collapsable
if(b==0) {
cookieValue += allDivs[a].id + ",1";
}
else {
cookieValue += "|" + allDivs[a].id + ",1";
}
b++;
}
}
cookieValue += "; expires=Sat, 31 Dec 2050 23:59:11 UTC; path=/";
//cookieValue looks like
// vddstatus=cat1,1|cat2,1|cat3,1.. cat9,1; expires=Sat, 31 Dec 2050 23:59:11 UTC; path=/";
// 1 means expanded, 0 means closed/hidden
cookieStart = 0;
if(document.cookie.length <= 0) { // No cookie
document.cookie = cookieValue;
}
cookieStart = document.cookie.indexOf("vmpdetdivstatus=");
if(cookieStart == -1) { // There is a cookie, but it doesn't have what we need
document.cookie = cookieValue;
}
cookieStart = document.cookie.indexOf("vmpdetdivstatus=");
vmpStart = cookieStart + 16;
vmpEnd = document.cookie.indexOf(";",vmpStart);
if(vmpEnd == -1) { vmpEnd = document.cookie.length; }
vmpValue = unescape(document.cookie.substring(vmpStart,vmpEnd));
//alert(vmpValue);
stateArray = new Array();
stateArray = vmpValue.split("|");
saLength = stateArray.length;
for(i=0;i<saLength;i++) {
nameState = stateArray[i].split(",");
thisName = nameState[0]; thisState = nameState[1]; thisLink = document.getElementById(thisName+"-display");
switch(thisState) {
case "0":
document.getElementById(thisName).style.display = "none";
thisLink.innerHTML = "[expand]";
break;
default:
break;
}
}
}
If the cookie does not exist, set it to default all expanded. Regardless, read the cookie and set the category status to what is in the array.
Now for the hide/expand links. There is a "hide/expand one", a "hide all", and an "expand all". There is also a function for setting the cookie value accordingly.
Unfortunately, this post is running out of room, so I'll continue in the next reply.
(cont'd)