var signP="images/plus.gif";
var signM="images/minus.gif";

function GetCookie(name) {
  var arg=name+"=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i  = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i,j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
     if (endstr == 1)
       endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie (name, value, expires) {
  var exp = new Date();
  var expiro = (exp.getTime() + (24 * 60 * 60 * 1000 * expires));
  exp.setTime(expiro);
  var expstr = "; expires=" + exp.toGMTString();
  document.cookie = name + "=" + escape(value) + expstr;
}

function DeleteCookie(name){
  if (GetCookie(name)) {
    document.cookie = name + "=" + "; expires = Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function xswitch(listID) {
  if(listID.style.display=="none") {
    listID.style.display="";
  } else {
    listID.style.display="none";
  }
}

function icoswitch(bid) {
  icoID = document.getElementById('pic'+bid);
  if(icoID.src.indexOf("minus") != -1) {
    icoID.src = signP;
	icoID.title='Покажи';
    SetCookie('block'+bid,'yes',365);
  } else {
    icoID.src = signM;
	icoID.title='Скрий';
    DeleteCookie('block'+bid);
  }
}

function xyzswitch(bid) {
    xswitch(document.getElementById('pe'+bid));
    icoswitch(bid);
}

function writeImg(id) {
var isP=GetCookie("block"+id);
  document.write('<img align="right" id="pic'+id+'" src="'+(isP?signP:signM)+'" onclick="xyzswitch(\''+id+'\');" style="cursor:pointer" title="'+(isP?'Покажи':'Скрий')+'">&nbsp;');
}

function writeDiv(id) {
  document.write('<div id="pe'+id+'" style="display:'+(GetCookie("block"+id)?"none":"")+';">');
}
