function ExpandCollapse(e, title) {
	if (e.style.display=="none") {
		SidebarWidget(e.id, false, title, true);
	} else {
		SidebarWidget(e.id, true, title, true);
	}
}

function SidebarWidget(cookie_name, collapsed, title, set_cookie) {
	if (!collapsed) {
		if (set_cookie) {
			SetCookie(cookie_name, '', null);
		}
		ChangeSidebarWidget(document.getElementById(cookie_name), false, title);
	} else {
		if (set_cookie) {
			SetCookie(cookie_name, 'none', null);
		}
		ChangeSidebarWidget(document.getElementById(cookie_name), true, title);
	}
}

function ChangeSidebarWidget(e, collapsed, title) {
	if (!collapsed) {
		e.style.display = '';
		document.getElementById(e.id + '-sign').innerHTML = '&nbsp;[-]';
		document.getElementById(e.id + '-link').setAttribute('title', 'Collapse ' + title);
	} else {
		e.style.display = 'none';
		document.getElementById(e.id + '-sign').innerHTML = '&nbsp;[+]';
		document.getElementById(e.id + '-link').setAttribute('title', 'Expand ' + title);
	}
}

function IsCollapsed (cookie_name) {
	if (GetCookie(cookie_name) == '') {
		return false;
	} else {
		return true;
	}
}

function IsCookieSet (cookie_name) {
	if ( document.cookie.length == 0 )  {
		return false;
	} else {
		cookie_start = document.cookie.indexOf(cookie_name + "=");
		if ( cookie_start == -1 ) {
			return false;
		} else {
			return true;
		}
	}
}

function GetCookie(cookie_name) {
	cookie_start=document.cookie.indexOf(cookie_name + "=");
	cookie_start=cookie_start + cookie_name.length + 1;
	cookie_end=document.cookie.indexOf(";",cookie_start);
	if (cookie_end==-1) {
		cookie_end=document.cookie.length;
	}
	return unescape(document.cookie.substring(cookie_start,cookie_end));
}

function SetCookie(cookie_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=cookie_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + "; path=/";
}

