function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}


function setCookie (name, value, expiredays, path, domain, secure) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
      document.cookie = name + "=" + escape(value) +
        ((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) +
        ((path='/') ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function checkCookie(gal,catid,kuk)
{
if(gal==true)
{
cookies = getCookie(catid);
if (cookies!=null && cookies!="")
 {
  cookies = cookies+ kuk+ '+';
  setCookie(catid,cookies,1);

  var check = cookies.split('+');
  sk = check.length-1;
  document.getElementById('count').innerHTML='('+ sk + ')';
  document.getElementById('count2').innerHTML='('+ sk + ')';
 }
else
 {
 cookies = kuk+ '+';
 if (cookies!=null && cookies!="")
   {
    setCookie(catid,cookies,1);
    var check = cookies.split('+');
    sk = check.length-1;
    document.getElementById('count').innerHTML='('+ sk + ')';
    document.getElementById('count2').innerHTML='('+ sk + ')';
   }
 }
}
if(gal==false)
{
 cookies_old = getCookie(catid);
 what = kuk+'+';
 cookies = cookies_old.replace(what,"");
 setCookie(catid,cookies,1);

  var check = cookies.split('+');
  sk = check.length-1;
  document.getElementById('count').innerHTML='('+ sk + ')';
  document.getElementById('count2').innerHTML='('+ sk + ')';

}
if(gal==3)
{ cookies = getCookie(catid);
 if (cookies!=null && cookies!="")
 {
  var check = cookies.split('+');
  sk = check.length-1;
  document.getElementById('count').innerHTML='('+ sk + ')';
  document.getElementById('count2').innerHTML='('+ sk + ')';
  for(i = 0; i < check.length; i++)
  {
   galoch = check[i];
   if(galoch!="")
   {
   test(galoch);
   }
  }
 }
}
}


function test(galoch)
{
  for(j = 1; j < 31; j++)
  {
    named = document.getElementById('chbox'+j);
    if(named!=null)
    {
        val = document.getElementById('chbox'+j).value;
    	if(val == galoch)
    	{
    	document.getElementById('chbox'+j).checked = true;
        break;
        }
    }
  }
}


function compare(tid,catid)
{
 var myString = tid.value ;
 var kuk = myString ;

 if (tid.checked)
 {
  var gal = true ;
  checkCookie(gal,catid,kuk);

 }
 else
 {
  var gal = false ;
  checkCookie(gal,catid,kuk);
 }
}

function compareall(catid)
{
	cookies = getCookie(catid);
    if (cookies!=null && cookies!="")
    {
	cookies = cookies.substring(0, cookies.length - 1);
	if (cookies.split('+').length>1) document.location.href="http://uvaga.ru/"+ catid+ "/sravnenie/"+ cookies+ "/";
	else alert("Для сравнения выберите не менее двух моделей!");
	}
    else alert("Для сравнения выберите не менее двух моделей!");
}

function del(catid,id)
{
 cookies_old = getCookie(catid);
 what = id+'+';
 cookies = cookies_old.replace(what,"");
 setCookie(catid,cookies,1);
	cookies = cookies.substring(0, cookies.length - 1);
	if (cookies!=null && cookies!="") document.location.href="http://uvaga.ru/"+ catid+ "/sravnenie/"+ cookies+ "/";
	else document.location.href="http://uvaga.ru/";

}

