var kStates;
var aState = new Array;
var sPlus;
var sMinus;
var sCookiePath;

function CLUpdate(vList) {
  var eImage, eList;
  eImage = document.getElementById("image" + vList);
  eList = document.getElementById("item" + vList);
  if (aState[vList] == 1) {
    eImage.src = sMinus;
    eList.style.display = "block";
    }
  else {
    eImage.src = sPlus;
    eList.style.display = "none";
  }
  CLResize();
}

function CLSaveState() {
  document.cookie = "show=" + aState.join("") + "; path=" + sCookiePath;
}

function CLInitialize(vLists,vPlus,vMinus,vCookiePath) {
  if (document.getElementById && navigator.cookieEnabled) {
    var s
    var i, j
    sPlus = vPlus;
    sMinus = vMinus;
    sCookiePath = vCookiePath;
    kStates = vLists;
    for (i = 1; i <= kStates; i++) {
      aState[i] = 0;
    }
    s = document.cookie;
    i = s.indexOf("show");
    if (i != -1) {
      j = s.indexOf(";",i);
      if (j == -1) {
        j = s.length;
      }
      s = s.substring(i+5,j);
      for (i = 1; i <= s.length; i++) {
        if (s.substr(i-1,1) == "1") {
          aState[i] = 1;
          }
        else {
          aState[i] = 0;
        }
      }
    }
    CLSaveState();
    window.onload=CLOnLoad;
    window.onresize=CLResize;
    return true;
    }
  else {
    return false;
  }
}

function CLOnLoad() {
  var i;
  for (i=1; i <= kStates; i++) {
    CLUpdate(i);
  }
}

function CLToggle(vList) {
  if (document.getElementById && navigator.cookieEnabled) {
    aState[vList] = (aState[vList] + 1) % 2;
    CLUpdate(vList);
    CLSaveState();
    return true;
    }
  else {
    return false;
  }
}

function CLToggleAll(vState) {
  if (document.getElementById && navigator.cookieEnabled) {
    var i;
    for (i = 1; i <= kStates; i++) {
      aState[i] = vState;
      CLUpdate(i);
    }
    CLSaveState();
    return true;
    }
  else {
    return false;
  }
}

function CLGotoURL(vURL) {
  if (document.getElementById && navigator.cookieEnabled) {
    window.location = vURL;
    return true;
    }
  else {
    return false;
  }
}

function CLResize() {
// Repositions the copyright at the bottom of the page.
// This is a work-around needed for: S203, K341, FF106, NN803, and IE550.
// This work-around is not compatible with: IE500.
// Needs to be called: On page load, when a list item is toggled, when the browser window is resized.
  var isIE500 = navigator.userAgent.indexOf("MSIE 5.0") != -1
  if (document.getElementById && !isIE500) {
    document.getElementById("copyright").style.top = "0"; // For NN610.
    var pageHeight = document.getElementById("page").offsetHeight;
    var copyrightHeight = document.getElementById("copyright").offsetHeight;
    document.getElementById("copyright").style.top = (pageHeight-copyrightHeight-1) + "px";
    // ... -1px so that text appears in exact same position as other pages in IE600.
    // Further fix Safari and Knoppix, to stop sidebar jumping down 16px ...
    var isSafari = navigator.userAgent.indexOf("Safari") != -1
    var isKonqueror = navigator.userAgent.indexOf("Konqueror") != -1
    if (isSafari || isKonqueror) {
      document.getElementById("header").style.marginBottom = "-16px";
      document.getElementById("sidebar").style.marginTop = "-16px";
    }
  }
}