function setCookieMonster(){
		var now = new Date();
		var dateExpires = new Date();

		dateExpires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
		setCookie('request', 'This is a test', dateExpires, 'cookies', location.hostname, 0)

		alert("Cookie Set!\n" + location.hostname);
}

function getCookieMonster(){

	alert(getCookie("request"));
}

function appendcart(){
//	appendMe(category, brandname, model, type, description, price1, price2, quantity)
	appendMe(document.frm1.category.value, document.frm1.brandname.value, document.frm1.model.value, document.frm1.type.value, document.frm1.description.value, document.frm1.price1.value, document.frm1.price2.value, document.frm1.quantity.value);
}

function appendMe(category, brandname, model, type, description,  price1, price2, quantity) {
		var now = new Date();
		var tmpstring = getCookie("request");

		var dateExpires = new Date();
		var strtext = category + '|' + brandname + '|' + model + '|' + type + '|' + description + '|' + price1 + '|' + price2 + '|' +quantity

		dateExpires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
		if (tmpstring == null || tmpstring.length ==0){
			setCookie('request', strtext, dateExpires, 'cookies', location.hostname, 0);
		}
		else {
			setCookie('request', tmpstring + '|' + strtext, dateExpires, 'cookies', location.hostname, 0)
		}
		
		location.href = "request.php"
}

function ClearCookie(){
		var now = new Date();
		var dateExpires = new Date();

		dateExpires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
		setCookie('request', '', dateExpires, 'cookies', location.hostname, 0)
}

function showmyBasket() {

		var strBasket = getCookie("request");
		var aBasket = strBasket.split('|');
		var loopnum = 0;
		
		document.write('<table border="1" cellspacing="0" cellpadding="4" width="80%">');
		document.write('<tr>');
		document.write('<td><b>Item</b></td>');
		document.write('<td><b>Description</b></td>');
		document.write('<td><b>Quantity</b></td>');
		document.write('<td>&nbsp;</td>');
		document.write('</tr>');
		
		for (i = 0; i < aBasket.length; i++) {
			
			document.write('<tr>');
			document.write('<td valign="top">' + aBasket[i] + ' - ' + aBasket[i+1] + ' - ' + aBasket[i+2] + ' - ' + aBasket[i+3] + '</td>');
			document.write('<td valign="top">' + aBasket[i+4] + '</td>');
			document.write('<td nowrap  valign="top"><form name="frm_' + loopnum + '"><input type="text" name="quantity" value="' + aBasket[i+7] + '" size="2"><input type="button" value="Update" onclick="javascript:UpdateQuantity(' + loopnum + ', document.frm_' + loopnum + '.quantity.value)"></form></td>');
			document.write('<td valign="top"><form><input type="button" value="Remove" onclick="javascript:RemoveItem(' + loopnum + ')"></form></td>');
			document.write('</tr>');
			i = i + 7;
			loopnum = loopnum + 1;
		}
		
		document.write('</table>');
}
function UpdateQuantity(CartItemNumber, quantity){
	
	var strCart = getCookie("request");
	var aCart = strCart.split('|');

	aCart[CartItemNumber*8+7] = quantity;

	strCart = '';
	var loopnum = 0;
	for (i = 0; i < aCart.length; i++) {
			if (strCart.length == 0){
				strCart = aCart[i]
			} else {
				strCart = strCart + '|' + aCart[i]
			}
			loopnum = loopnum + 1;
		}

	var now = new Date();
	var dateExpires = new Date();
	dateExpires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
	
	setCookie('request', strCart, dateExpires, 'cookies', location.hostname, 0);
	location.reload()
}

function RemoveItem(CartItemNumber){
	
	var strCart = getCookie("request");
	var aCart = strCart.split('|');

	aCart.splice(CartItemNumber*8, 8);
	
	strCart = '';
	var loopnum = 0;
	for (i = 0; i < aCart.length; i++) {
			if (strCart.length == 0){
				strCart = aCart[i]
			} else {
				strCart = strCart + '|' + aCart[i]
			}
			loopnum = loopnum + 1;
		}

	var now = new Date();
	var dateExpires = new Date();
	dateExpires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
	
	setCookie('request', strCart, dateExpires, 'cookies', location.hostname, 0);
	location.reload()

}
function displaymyBasket() {

		var strBasket = getCookie("request");
		var aBasket = strBasket.split('|');
		var loopnum = 0;
		
		document.write('<table border="1" cellpadding="0" cellspacing="0" width="660" height="36">');
		document.write('<tr>');
		document.write('<td width="42"><b>Qty</b></td>');
		document.write('<td width="245"><b>Item</b></td>');
		document.write('<td width="245"><b>Description</b></td>');
		document.write('</tr>');		
		for (i = 0; i < aBasket.length; i++) {
			
			document.write('<tr>');
			document.write('<td valign="top">' + aBasket[i+7] + '</td>');
			document.write('<td valign="top">' + aBasket[i] + ' ' + aBasket[i+1] + ' ' + aBasket[i+2] + ' ' + aBasket[i+3] + '</td>');
			document.write('<td valign="top">' + aBasket[i+4] + '</td>');
			document.write('<td valign="top" height="36" align="right"> $' + aBasket[i+6] + '</td>');
			document.write('</tr>');
			i = i + 7;
			loopnum = loopnum + 1;
		}
		
		document.write('</table>');
}

