function nameDefined(ckie,nme){
	var splitValues
	var i
	for (i=0;i<ckie.length;++i){
		splitValues=ckie[i].split("=")
		if (splitValues[0]==nme) return true
	}
	return false
}

function delBlanks(strng){
	var result=""
	var i
	var chrn
	for (i=0;i<strng.length;++i) {
		chrn=strng.charAt(i)
		if (chrn!=" ") result += chrn
	}
	return result
}

function getCookieValue(ckie,nme){
	var splitValues
	var i
	for(i=0;i<ckie.length;++i) {
		splitValues=ckie[i].split("=")
		if(splitValues[0]==nme) return splitValues[1]
	}
	return ""
}

function testCookie(cname) {						//Tests to see if the cookie 
	var cookie=document.cookie						//with the name and value 
	var chkdCookie=delBlanks(cookie)				//are on the client computer
	var nvpair=chkdCookie.split(";")
	if(nameDefined(nvpair,cname)){					//See if the name is in any pair
		tvalue=getCookieValue(nvpair,cname)			//Gets the value of the cookie
		if (tvalue != "") return tvalue
		else return 0
	} else return 0
}

function addtocart(id) {
	lista = testCookie("shoppingcart");
	if (lista != 0) {
		var temp
		temp = lista.split("|")
		id = lista + "|" + id						//Go to the location indicating the user has been here
	}
	var futdate = new Date()						//Get the current time and date
	var expdate = futdate.getTime()					//Get the milliseconds since Jan 1, 1970
	expdate += 1209600*1000							//expires in 1 hour(milliseconds)
	futdate.setTime(expdate)
	var newCookie = "shoppingcart=" + id + "; path=/;"	//Set the new cookie values up
	newCookie += " expires=" + futdate.toGMTString()
	window.document.cookie = newCookie				//Write the cookie
}

function removefromcart(id) {
	lista = testCookie("shoppingcart");
	if (lista == 0) {
		alert("This product is not on your list");					//Go to the location indicating the user has been here
	} else {
		var temp
		temp = lista.split("|")
		for(i=0;i<temp.length;++i) {
			if(temp[i] == id) {
				temp.splice(i, 1);
				break;
			}
		}
		id = temp.join("|");	
		var futdate = new Date()						//Get the current time and date
		var expdate = futdate.getTime()					//Get the milliseconds since Jan 1, 1970
		expdate += 1209600*1000							//expires in 1 hour(milliseconds)
		futdate.setTime(expdate)
		var newCookie = "shoppingcart=" + id + "; path=/;"	//Set the new cookie values up
		newCookie += " expires=" + futdate.toGMTString()
		window.document.cookie = newCookie				//Write the cookie
		ajaxpage('getcart.php', 'cart')
	}
}

function clearcart() {
	var futdate = new Date();
	var newCookie = "shoppingcart=; path=/; expires=" + futdate.toGMTString() + ";";
	window.document.cookie = newCookie;
	ajaxpage('getcart.php', 'cart')
}