function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
	document.cookie = ck;
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++)
	{
		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
		return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function addToc(name,value,days) {
 		x = readCookie(name)
 	newItemlist = name
	if (x == null) {
		newItemlist += '|' +value
	} else {
		uv = x.split('|');
		for (j=0; j<uv.length; j++) {
			if (value == uv[j]) {
			alert('This image is already in the lightbox')
			return
			  }
			}
		newItemlist = x+ '|' +value
	}
	createCookie(name,newItemlist,days)
}

function showToc(name,op,page,a,s,id,slook) {
	g = readCookie(name)
	if (g == null) {
	itemlist = ""
	} else {
	itemlist = g.split('|');
	}
	h = itemlist.length-1
	ct = ""
	for (j=0; j<itemlist.length; j++) {
		if (itemlist[j] != name) {
			if (j == h) {
			ct += itemlist[j]
			} else {
		  ct += itemlist[j]+ "+"
			}
		}
	}

	tks = s.split(' ')
	nws = ''
	for (t=0; t<tks.length-1; t++) {
	nws += tks[t]+ '+'
	}
	nws += tks[t]

	if (s == 'direct') {
	checkit1="library.cds?sw=lbox1&&switch=off&&lp=" +page+ "&&page=" +a+ "&&s=" +s+ "&&g=" +ct+ "&&sord=" +op+ "&&slook=" +slook+ "&&id=" +id
	} else {
	checkit1="library.cds?sw=lbox1&&switch=off&&lp=" +page+ "&&page=" +a+ "&&s=" +nws+ "&&g=" +ct+ "&&sord=" +op+ "&&slook=" +slook+ "&&id=" +id
	}
	self.location.href=checkit1;
}

function delToc(name,value,days,op,page,a,s,id,slook) {
	//if(confirm("Really delete this image?")) {
 	x = readCookie(name)
	itemlist = x.split('|');
	newItemlist = name
	for (i=0; i<itemlist.length; i++) {
		if (itemlist[i] != value && itemlist[i] != name) {
		  newItemlist += '|' +itemlist[i]
		}
	}
	createCookie(name,newItemlist,days)
	showToc(name,op,page,a,s,id,slook)
	//} - confirm condition
}

function delCok(name,op,page,a,s,id,slook)
{
		if(confirm("Really delete this Selection?"))
		{
		createCookie(name,"",-1);
		showToc(name,op,page,a,s,id,slook)
		}
}

function callSearch(name,op,page,a,s) {
	parent.display.location.href="../inc/portf.php?switch=" +op+ "&&lp=" +page+ "&&page=" +a+ "&&s=" +s+ "&&sord=off"
}