// Cookie functions

function setcookie(c_name, value, expiredays)
{
   document.cookie=c_name+ "=" + escape(value)+ ((expiredays==null) ? "" : ";expires="+expiredays +";path=/");
} 

function getcookie(name)
{
   var dc = document.cookie;
   var prefix = name + "=";
   var begin = dc.indexOf("; " + prefix);
   
   if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0)
         return null;
   }
   else {
      begin += 2;
   }
   
   var end = document.cookie.indexOf(";", begin);
   if (end == -1) {
      end = dc.length;
   }
   
   return unescape(dc.substring(begin + prefix.length, end));
}


function FixCookieDate (date)
{
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

var lastMenuId = null;
function openMenuBlock(id)
{
   var d = document.getElementById("menu_"+ id +"").style.display;

   if(lastMenuId != null && lastMenuId != id && document.getElementById("menu_"+ lastMenuId +"")){
      var ld = document.getElementById("menu_"+ lastMenuId +"").style.display;

      document.getElementById("menu_"+ lastMenuId +"").style.display = (ld == "block") ? "none" : "block";

      var expdate = new Date();
      FixCookieDate (expdate);
      expdate.setTime (expdate.getTime() + (6 * 60 * 60 * 1000));

      setcookie("menu_"+ path0 +"_"+ path1 +"_"+ lastMenuId, ((ld == "block") ? "none" : "block"), expdate );

   }

   document.getElementById("menu_"+ id +"").style.display = (d == "block") ? "none" : "block";

   var expdate = new Date();
   FixCookieDate (expdate);
   expdate.setTime (expdate.getTime() + (6 * 60 * 60 * 1000));

   setcookie("menu_"+ path0 +"_"+ path1 +"_"+ id, ((d == "block") ? "none" : "block"), expdate );

   if(d == "block"){
      lastMenuId = null;
   }
   else{
      lastMenuId = id;
   }
}
