function gid(id){return document.getElementById(id)}
function addtobag(name, value) {
	var bag = getCookie(name);
	if((','+bag+',').indexOf(','+value+',')>=0) return alert('Produkt finnes allerede i listen.');
	setCookie(name,(bag=='')?value:bag+','+value);
	settlistlengths();
	alert('Produkt lagret i '+name+'.');
}
function delfrombag(name, value, aa) {
	var bag = getCookie(name);
if(bag=='') return;
else bag = bag.split(',');
for(var a=0;a<bag.length;a++) if(bag[a]==value) bag = bag.slice(0,a).concat(bag.slice(a+1,bag.length))
	setCookie(name,bag);
	gid('park'+aa).style.display='none';
}
function deletebag(name) {
	var exp = new Date;
	exp.setTime(exp.getTime() - 1);
	document.cookie = name + "=;expires=" + exp.toGMTString()+";path=/";
  var parent = gid('tablebody');
  while(parent.childNodes[0]) {
    parent.removeChild(parent.firstChild);
  }
}
function setCookie(name, value) {
	var expiry = new Date;
	expiry.setTime(expiry.getTime() + 60480000);//1week
	document.cookie = name + "=" + value + ";" + "expires=" + expiry.toGMTString() + ";path=/";
}
function getCookie(name) {
	var c = document.cookie + ";";
	c = c.match(new RegExp(name + "=([^;]*);"));
	if (c != null && c.length > 1) return c[1];
	return '';
}
function settlistlengths() {
	var co=getCookie('produktark');
	gid('produktarklength').innerHTML = '('+((co=='')?'0':co.split(',').length)+')';
	co=getCookie('smaksnotat');
	gid('smaksnotatlength').innerHTML = '('+((co=='')?'0':co.split(',').length)+')';
}
