/*

External shopping cart handler by H.Yeend (well, alex really, but I did some of it and am therefore stealing the credit...ahem..)

NOTES:
======

Not sure how this'll work with multiple colors...
oh.... bum. 11 July 2001


USAGE:
======
---------------------------------------------------
	....
	<!-- stuff in capitals needs changing, except VATrate and Oopshop -->
	<script language="Javascript1.1" src="./cart.js"></script>

	</head>
	....

	<form name="WHATEVER">

	.......

	<select name="BLAH" onChange="showme('WHATEVER.BLAH');">
	<option value="BC3412|BIG BOOBY BRA|30">BIG BOOBY BRA (£30)</option>
	<option value="BC3421|GREAT BIG BOOBY BRA|40">GREAT BIG BOOBY BRA (£40)</option>
	</select>
	.......

	<!-- stuff below this line you needn't do anything with,
		just copy these chunks for each product,
		change the form name for each
		(call the form what you want it doesn't matter as long as they're not the same) -->
	.......
	<input type=text name="quantity" size=3 maxlength="3" value="">
	<input type="hidden" name="Oopshop" value="">
	<input type="hidden" name="price">
	<input type="hidden" name="VATrate" value="0.00">
	<input type="hidden" name="desc" value="">
	<input type="hidden" name="store" value="oopshop">

	<input type="submit" onclick="javascript:addto(document.WHATEVER);">

	.......
---------------------------------------------------

*/

function showMe(formname,index)
{

	//alert(formname);
	//in the above example, formname would = whatever.blah

	splot = eval("document." + formname + "[index].value");
	//splot would = "BC3412|Big Booby Bra|30"

	//alert(splot);

	var pos = splot.indexOf("|");
	var pos2 = splot.indexOf("|",pos+1);
	//pos is where the | is

	//var size = splot.substring(pos+1,splot.length);

	//var pos = splot.indexOf("|");

	var price = splot.substring(pos2+1,splot.length);
	//price would = 30
	// (pos+1) because otherwise we get it saying that the price is "|30"

	var desc = splot.substring(pos+1,pos2);
	var ref = splot.substring(0,pos);
	//desc would = "BC3412"
	//ref would = "Big Booby Bra"
	//
	//	I know, the variable names dont make sense, I'll change em sometime.
	//
	//alert(desc + ", " + ref);

	var splinko = formname.indexOf('.');
	//splinko = (where the dot is) - so we can give 'plinko' the value of the form

	var plinko = formname.substring(0,splinko);
	//plinko becomes the form name

	//put the actual values into the form, ready to submit
	eval("document." + plinko + ".price.value = price;");
	eval("document." + plinko + ".desc.value = desc;");
	eval("document." + plinko + ".ref.value = ref;");
}

//all the stuff below is not my code. But it's modified slightly.


function addto(entry)
{ //add to cart but stay on the same page

	var description;

	// entry is the form name.

	quantity = stripNonNumbers(entry.quantity.value);

	entry.quantity.value = quantity;
		//check they haven't entered "bob" as the quantity (or 7.4)

	size = entry.desc.value;

	if(quantity && size)
	{
		ref=entry.ref.value;
			//alert ('description:'+description);
		store_name=entry.store.value;
			//alert ('store: '+store_name);
		price=entry.price.value;
			//alert('price: '+price);
		VATrate = entry.VATrate.value;
		document.cookie = "oops" + store_name + "+" + VATrate + ref + "+" + size + "=" + quantity + "++"+ price+"";
			alert(quantity + "x " + ref +" " + " " + size + ' has been added to your shopping cart--Thank you!');
			//alert("description is: "+description);
			//alert("store name is: "+store_name);
			//alert("cookie: "+document.cookie);
	 }
	 else
	 {
		alert("I'm sorry, we cannot process that order\nPlease check product and quantity have been entered.");
	 }
}


function addtocart(form,page)
{ //add to cart and go to a new page

	addto(form)
	location.href=page;
}

function setform(form,page)
{
	var formname=form;
	formname.method='GET';
	formname.action=page;
}
