function getCookie(NameOfCookie){
	if (document.cookie.length > 0) 
		{ begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1) 
			{ begin += NameOfCookie.length+1; 
			var end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); } 
		}
	return null; 
}

function setCookie(NameOfCookie, value, expiredays, path) { 
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + ((path == null) ? "" : "; path=" + path);
}

function delCookie (NameOfCookie) { 
	if (getCookie(NameOfCookie)) {
		status('removing');
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";}
	else{
		alert('no cookie found');
	}
}

function clearCookie () { 
	var thecookie = document.cookie
	var cgroup = thecookie.split("&")
	for (i=0;i<cgroup.length;i++) {
		 cgroup[i] = cgroup[i].split("=")
		 document.cookie = cgroup[i][0] + "=''"
	}
}

function appendCookie(NameOfCookie,value,expiredays, path){
	var current = getCookie(NameOfCookie);
	if(current){
		// check for dups and alert if necessary;
		if(current.indexOf(value) == -1){
			setCookie(NameOfCookie, current + "," + value, expiredays, path);
			alert('This item will be added to your cart.');}
		else{
			alert("This item is already in your cart.");}
		}
	else
		{setCookie(NameOfCookie,value,expiredays, path);
		alert('This item has been added to your cart.');}
}
function addToCart(NameOfCookie, value, expiredays, path){
	appendCookie(NameOfCookie,value,expiredays, path);
	// update left navigator with cart contents;
	// update the current frame;
	document.location.reload(true);
}
function removeFromCart(NameOfCookie, value, expiredays, path){
	var current = getCookie(NameOfCookie);
	// replace the value in the string and then rewrite;
	current = current.replace(value + ",", "");    // replace with trailing comma
	current = current.replace(value, "");   // just in care, replace without as well
	setCookie(NameOfCookie, current, expiredays, path);  // replace the info in the cookie
	document.location.reload(true);
}