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 addtobagall(name, value) {
    var bag = getCookie(name);
    if ((',' + bag + ',').indexOf(',' + value + ',') >= 0) //return alert('Produkt finnes allerede i listen.');
    {
    
    }
    else
    {
    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';
	if (bag == '') {
	    deletebag('produktark')
	}
	settlistlengths1();
}
function delfrombaglst(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);
    settlistlengths();
}
function deletebag(name) {

	var exp = new Date;
	exp.setTime(exp.getTime() - 1);
	document.cookie = name + "=;expires=" + exp.toGMTString()+";path=/";
	var parent = gid('ctl00_cphProductSearch_dtlproduktark');
  while(parent.childNodes[0]) {
    parent.removeChild(parent.firstChild);
}
gid('parkheader').style.display = 'none';
gid('parkfooter').style.display = 'none';
}

function deletebag1(name) {



	var exp = new Date;
	exp.setTime(exp.getTime() - 1);
	document.cookie = name + "=;expires=" + exp.toGMTString()+";path=/";
	//var parent = gid('ctl00_cphProductSearch_dtlproduktark');
  //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)+')';
}

function settlistlengths1() {
    var co = getCookie('produktark');
    gid('produktarklength').innerHTML = '(' + ((co == '') ? '0' : co.split(',').length) + ')som samlet PDF';
}
