// beginning of the shopping cart implementation for the fogshop

//variables that need to be changed for unique implementations

var cartLoc = "../shopping_cart.html"; //the location of the cart page

// everything else should remain untouched

function getCookieVal (offset) {//returns the entire cookie for this domain
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) { // reads a cookie by name, returns void if named cookie doesn't exist
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg) {
	    	return getCookieVal (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break;
	}
	return null;
}

function setCookie (name,value,expires,path,domain,secure) { //writes a cookie to disk
	document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function addToCart(details) {//adds an item to the cart, items are delimited by "@"
	if (getCookie("cart") == null) {
		setCookie("cart", details,false,"/");
	} else {
		setCookie("cart", getCookie("cart") + "@" + details,false,"/");
	}
	window.location = cartLoc;
	return false;
}

// end of the shopping cart implementation for the fogshop

