function boxOver(id) 
{
    var Item = document.getElementById(id);
    if (Item.className == "box1") 
    {
        Item.className = "box1-hover";
    }
}

function boxOut(id) 
{
    var Item = document.getElementById(id);
    if (Item.className == "box1-hover") 
    {
        Item.className = "box1";
    }
}

function boxClick(id) {
    var Item = document.getElementById(id);
    var sectionItem = document.getElementById('section-' + id.toString().substring(4, id.toString().length));

    if (sectionItem.style.display != "block") {
        CloseAll(Item.parentNode);
        sectionItem.style.display = "block";
        Item.className = "box1-open";

        CreateCookie("openbox", id, 1);
    }
    else 
    {
        sectionItem.style.display = "none";
        Item.className = "box1";
    }
}

function CloseAll(Menu) 
{
  for (var i = 0; i < Menu.childNodes.length; i++) 
  {
      var item = Menu.childNodes[i];
      if (item.className == "box1-open") 
      {
          boxClick(item.id);
      }
  }
}

function CreateCookie(name, value, days) {
    if (value == "") {
        return;
    }
    if (days) 
    {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function Readcookie(name) 
{
    myString = document.cookie
    myRE = new RegExp(name + '=box-[0-9]?[0-9]')
    results = myString.match(myRE);

    if (results)
    {
        boxClick(results[results.length-1].split('=')[1]);
    }
    else
        return null;
}

window.onload = function() 
{
    Readcookie("openbox");
}