function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) {
		var begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}

function setCookie(NameOfCookie, value, expiredays)
{
	var ExpireDate = new Date();
	if (expiredays == null) expiredays = 365; // keep the settings for a year
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) +
		"; path=/catalog/";
}

function delCookie(NameOfCookie)
{
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +
		"; path=/catalog/";
	}
}

function saveBoxState(boxId, state)
{
	setCookie('boxState_' + boxId, state, null);
}

function restoreBoxState(boxId)
{
	var state = getCookie('boxState_' + boxId);
	if (state == null || state == 'closed') toggleBoxState(boxId);
}

function toggleBoxState(boxId)
{
  if (document.getElementById) {
    var title = document.getElementById(boxId + 'Head');
  } else {
    var title = document.all[boxId + 'Head'];
  }

  var box = document.getElementById ? document.getElementById(boxId) : document.all[boxId];

  // switch box header icon
  if (box.style.display == '') {
    title.className = 'maximize';
	saveBoxState(boxId, 'closed');
  } else {
    title.className = '';
	saveBoxState(boxId, 'open');
  }

  // switch box visibility state
  if (box.style.display == '') {
      box.style.display = 'none';
  } else {
      box.style.display = '';
  }
}
