﻿// JavaScript Document
var mygid;
function korzinaaaaa(){
	alert('from basket');
}

function korzina()
{
	var mygid=document.getElementById('goodsId').innerHTML;
	//alert("mygid="+mygid);

/*
stroka=" "+window.location;
alert(stroka);
k=stroka.length;
//alert("k="+k);
mygid=poisk(stroka);

*/
var tm=new Date();
tm.setDate(tm.getDate()+1);
if(ReadCookie("kaupId") == null)
	document.cookie="kaupId="+mygid+",;expires="+tm.toGMTString()+";";
	else 
	{
	curKaup=ReadCookie("kaupId");
	yest=curKaup.indexOf(mygid, 0);
	//alert("yest="+yest);
	if( yest== -1)
		{
		curKaup+=mygid+",";
		document.cookie="kaupId="+curKaup+";expires="+tm.toGMTString()+";";
		}
	}

//k=document.cookie.length;
//alert("number of cookie is "+k);
//alert(document.cookie);
//alert("kaupId="+ReadCookie("kaupId"));

//kn=ReadCookie("kaupNimi");//+"^1";
//alert("kn="+kn);

//kn=zamena(kn);

var lang=getLang();
		
if(ReadCookie("kaupLoe"+mygid) == null)	{	
	var nimi=document.getElementById('goodsName').innerHTML;
	var hind=document.getElementById('goodsPrice').innerHTML;
	var classId=document.getElementById('goodsClass').innerHTML;
	var ainult_k=document.getElementById('onlyShop').innerHTML;
	var picSource=document.getElementById('picSource').innerHTML;
kn=nimi+"^"+hind+ "^1^" + classId + "^" + ainult_k + "^" + picSource; 
//alert("kn="+kn);

//var tm=new Date();
//tm.setDate(tm.getDate()+1);

	document.cookie="kaupLoe"+mygid+"="+kn+";expires="+tm.toGMTString()+";";
//	alert('lang='+lang);
	//alert("Kaup on mдletatud"); est
	
	
	if(lang=='ee') alert("Kaup on korvis");
	if(lang=='en') alert("Goods in bascet");
	if(lang=='ru') alert("Товар в корзине");
	
	 setBasketCount();
		
	}//en
	else 	{
		if(lang=='en') alert("Goods already in bascet"); 
		if(lang=='ee')	alert("Kaup juba oli valitud"); 
		if(lang=='ru')	alert("Товар уже был выбран раньше"); 	
		}
	
	//var mesto=window.location; window.location=mesto;
}


function setGoodsInCookie(nimi, hind, classId, ainult_k, picSource){
	
	var s=nimi+"^"+hind+"^1^"+classId+"^"+ainult_k+"^"+picSource;
	alert(s);
var tm=new Date();
tm.setDate(tm.getDate()+1);
	document.cookie="kaupNimi="+s+",;expires="+tm.toGMTString()+";";	
}

