Updated code with javascript cookies. Now the only problem is retrieving the cookies to control the block:none attributes. What is the best way to read the entire collection of getElementsByName so I can use the elementName in the getCookie function?
function ShowHide(elementName) {
var HeaderElement = null;
var BodyElement = null;
if(document.getElementsByName) {
HeaderElement = document.getElementsByName(elementName+"Header");
BodyElement = document.getElementsByName(elementName+"Body");
UpImage = document.getElementsByName(elementName+"Up");
DownImage = document.getElementsByName(elementName+"Down");
if(BodyElement) {
if(BodyElement[0].style.display == "none") {
BodyElement[0].style.display = "block";
HeaderElement[0].className = "ListNuggetHeader";
DownImage[0].style.display = "none";
UpImage[0].style.display = "block";
setCookie(elementName, '1', expiration);
} else {
BodyElement[0].style.display = "none";
HeaderElement[0].className = "ListNuggetHeaderClosed";
UpImage[0].style.display = "none";
DownImage[0].style.display = "block";
setCookie(elementName, '0', expiration);
}
}
}
}
var expiration = new Date();
expiration.setTime(expiration.getTime() + 2592000000);
function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}
function setCookie(name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
((path == null) ? "" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
((secure == null) ? "" : "; secure");
}