function getCookie(name){
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length != 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return null;
}

function setCookie(name, value, expires) {
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; path=/; expires=" + expires.toGMTString());
}


function add_notepad(id,serv) {
  var chec_cookie = IsCookieEnabled();
  if (chec_cookie != true) {
      alert("Для работы функции необходимо включить в браузере использование cookies");
    return;
     }
//  if (serv == 'goods') var nn = "Товар в блокнот";
//  else var nn = "добавить в блокнот";
  var expiration = new Date(); expiration.setTime(expiration.getTime() + 15552000000); //6 месяцев
  var listid = getCookie("notepad_"+serv);
     if (!listid) listid = "";

   if (listid.indexOf(id)!="-1") {
      listid = listid.split(id+",").join("");
     document.getElementById("notepad_"+serv+"_"+id).innerHTML = "<img src='/img/add_notepad.gif' width='10' height='10' style='vertical-align: middle' alt='' /> <a href='javascript:add_notepad("+id+",&quot;"+serv+"&quot;)' rel='nofollow'>в блокнот</a>";
 }
   else {
      var count = listid.split(",");
      count.pop();
      count = count.length;
      if (count > 49) { alert("Максимальное количество записей в блокноте 50"); 
      return; 
     }     
     
     listid+=id+",";
     document.getElementById("notepad_"+serv+"_"+id).innerHTML = "<img src='/img/delete_notepad.gif' width='10' height='10' style='vertical-align: middle' alt='' /> <a href='javascript:add_notepad("+id+",&quot;"+serv+"&quot;)' rel='nofollow'>удалить из блокнота</a>";
   }
   setCookie("notepad_"+serv,listid,expiration);
   show_notepad(id,serv) 
   }
     
 


 

   
function mark_show(serv) {
   var mcar = getCookie("notepad_"+serv);
   if (!mcar) mcar = "";
   mrkc = mcar.split(",");
   for (i=0;i<mrkc.length;i++) {
     if (document.getElementById("notepad_"+serv+"_"+mrkc[i])) {
       document.getElementById("notepad_"+serv+"_"+mrkc[i]).innerHTML = "<img src='/img/delete_notepad.gif' width='10' height='10' style='vertical-align: middle' alt='' /> <a href='javascript:add_notepad("+mrkc[i]+",&quot;"+serv+"&quot;)' rel='nofollow'>удалить из блокнота</a>";
     }
   }
}  



function show_notepad(id,serv) {
 var listid2 = getCookie("notepad_"+serv);
   if (listid2) {
     var count_show = listid2.split(",");
     count_show.pop()
     var count_shows = count_show.length;
//<![CDATA[
     if (document.getElementById("notepad_show")) document.getElementById("notepad_show").innerHTML = '<span style="font-weight: bold"><a href="/'+serv+'/notepad/" rel="nofollow">блокнот</a> <span style="color: red">('+count_shows+')</span></span>';
//]]>
   }
else {
if (document.getElementById("notepad_show")) document.getElementById("notepad_show").innerHTML = '';
//<![CDATA[
	if (document.getElementById("notepad_id_empty")) document.getElementById("notepad_id_empty").innerHTML = "<div style='margin: 100px 0; text-align: center'><b>Ваш блокнот пуст</b></div>";
//]]>
}
     if (document.getElementById("notepad_id_"+id)) document.getElementById("notepad_id_"+id).style.display = 'none';
}

   
function DeleteCookie(strName)
{
    document.cookie = strName + "=0; expires=" + (new Date(0)).toGMTString();
}


function IsCookieEnabled()
{
    if(typeof(navigator.cookieEnabled) != "undefined")
        return navigator.cookieEnabled;
    else
    {
        // свойство navigator.cookieEnabled не поддерживается
        // установим и получим тестовую куку

        var _c = "__V_TEST_COOKIE_NAME_";

        setCookie(_c, "1");

        if(getCookie(_c) != null)
        {
            DeleteCookie(_c);
            return true;
        }

        return false;
    }
}


