function addCart(id, price, redirect){
	var v="";
	var s="";
	if (getCookie("goods")!=null) v=getCookie("goods");
	else v="";
	if (getCookie("sum")!=null) s=getCookie("sum");
	else s=0; 
	v=v.toString();
	row=v.split("_");
	f=0;
	for(i=0;i<row.length;i++){ // проверка на дублирование
		if (id==row[i])	{
			s=parseInt(s)+parseInt(price);
			setCookie("sum", s, 2);
			setCookie("kol"+id, parseInt(getCookie("kol"+id))+1, 2);
			updateBasket();
			f=1;
		}
	}
		if (f==0){
	setCookie("goods", v+"_"+id, 2);
	setCookie("kol"+id, 1, 2);
	setCookie("price"+id, price, 2);
	s=parseInt(s)+parseInt(price);
	setCookie("sum", s, 2);
	updateBasket();
		}

}


function removeFromCart(id){
	if (getCookie("goods")!=null) v=getCookie("goods");
	else v="";
	row=v.split("_");
	var nv="";
	for(i=0;i<row.length;i++){
	if (row[i]!=id) nv+=row[i]+"_";	
	else {
		setCookie("kol"+row[i], "", 0);
		setCookie("price"+row[i], "", 0);
		
	}
	
	}
	setCookie("goods", nv, 2);
	updateBasket();
	
}
function updateBasket(){
	var price;
	bas=document.getElementById("basket");
	if (bas!=null){
		var v=getCookie("goods");
		var s=getCookie("sum");
		row=v.split("_");
		var kol=0;
		var sum=0;
		var itkol=0;
		for(i=0;i<row.length;i++){
			if (row[i]!=""){
				//alert(row[i]);
				kol++;
				price=getCookie("price"+row[i]);
				//alert(price);
				itkol=getCookie("kol"+row[i]);
				if (!itkol) itkol=1;
				//alert(itkol);
				sum+=(price*itkol);
			}
			
		}
		
		if (bas.style.display=="none") bas.style.display="block";
		spans=bas.getElementsByTagName("span");
		for(i in spans){
			if (spans[i].className=="number") spans[i].innerHTML=kol;
			if (spans[i].className=="sum") spans[i].innerHTML=sum;
			
		}
		if (sum==0) window.location="/?clear";
	}
	
}


function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
	t=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : "; path=/;expires="+exdate.toGMTString())
}



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);
}


