
var items = new Array("CHIS", "CHIS10MG", "CHIS10MX", "CHIS10WG", "CHIS10WX", "CHIS18G", "CHIS18X", "CHIS8NG", "CHIS8NX", "CHISG", "GEO16TS", "GEO20SF", "GEO24WS", "GEO32LUMP", "GEO8SS", "HLDRSL", "PRY30", "SAFEV", "TYV35X25", "TYV46X25", "TYV57X25", "TYV69X24", "TYV810X25", "TYVASS", "TYVBAG");
var names = new Array("Splitting chisel", "19&times;250mm splitting chisel + guard", "19&times;250mm splitting chisel", "25&times;250mm splitting chisel + guard", "25&times;250mm splitting chisel", "25&times;450mm splitting chisel + guard", "25&times;450mm splitting chisel", "12&times;200mm splitting chisel + guard", "12&times;200mm splitting chisel", "Splitting chisel with hand guard", "16oz Tubular Shaft Hammer", "Solid Forged Hammer", "24oz Wooden Shaft Hammer", "Lump Hammer", "Small Chipping Hammer", "Hammer Holder", "Pry bar", "High Visibility Jackets", "3×5in TYVEK™ specimen bag (×24)", "4×6in TYVEK™ specimen bag (×24)", "5×7in TYVEK™ specimen bag (×24)", "6x9in TYVEK specimen bag (x24)", "8×10in TYVEK™ specimen bag (×24)", "Tyvek specimen bag selection", "Tyvek™ Specimen bags");
var prices = new Array("5.99", "5.99", "4.49", "7.99", "6.49", "11.49", "9.99", "4.49", "2.99", "0.00", "14.99", "23.95", "12.99", "6.99", "9.99", "3.99", "7.29", "3.49", "4.59", "5.49", "6.79", "8.79", "11.49", "9.49", "5.49");
var discountable = new Array("0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00");
var blurb = new Array("The ultimate splitting tool", "The ultimate splitting tool", "The ultimate splitting tool", "The ultimate splitting tool", "The ultimate splitting tool", "The ultimate splitting tool", "The ultimate splitting tool", "The ultimate splitting tool", "The ultimate splitting tool", "For a safer split", "with a lightweight tubular shaft", "One piece, robust construction", "with an elegant wooden shaft", "for a firm blow", "sprung shaft, lightly built", "keeping your hammer to hand", "perfect for splitting shales", "vital safety equipment", "Keeping your specimens safe", "Keeping your specimens safe", "Keeping your specimens safe", "Keeping your specimens safe", "Keeping your specimens safe", "For specimens of all shapes and sizes", "safe storage for specimens. Pack of 24.");
var qt = new Array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
var sessQt = new Array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); // this variable takes note of what the server thinks is in the basket.
var shippingcharge = 1 * 4.99;	
var discountAmount = 1 * 2.50;
var root = "/";
var MultiSave = 2.50*-1; //Saving

//Define indexOf for IE
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
				if(this[i]==obj){
						return i;
				}
		}
		return -1;
	}
}


function addIfEnter(e, id) {
	if (e.keyCode == 13) AddToBasket(id);
}

function AddToBasket(item) {
	var InNow = qt[items.indexOf(item)];
	var ToAdd = document.getElementById("Quantity_" + item).value;
	InNow = 1 * InNow;
	ToAdd = 1 * ToAdd;
	if (!isNaN(ToAdd)) InNow += ToAdd;
	if (InNow<0) InNow = 0;
	qt[items.indexOf(item)] = Math.round(InNow);
	if (document.getElementById("removePic_" + item)) {
		if (InNow == 0) {	
			document.getElementById("removePic_" + item).src = RemoveGrey.src;
		} else {	
			document.getElementById("removePic_" + item).src = RemoveBlack.src;
		}
	}
	UpdateBasket();
}

function quickAdd(item) {
	var InNow = qt[items.indexOf(item)];
	InNow = 1 * InNow;
	InNow += 1;
	qt[items.indexOf(item)] = Math.round(InNow);
	if (document.getElementById("removePic_" + item)) document.getElementById("removePic_" + item).src = RemoveBlack.src;
	UpdateBasket();
}

function Remove(item) {
	qt[items.indexOf(item)] = 0;
	if (document.getElementById("removePic_" + item)) document.getElementById("removePic_" + item).src = RemoveGrey.src;
	UpdateBasket();
}

function BuyNow(){
	UpdateBasket();
	window.location.href = "/checkout-page.html";
}
	
function UpdateBasket() {
	var ListOfContents = "<table>";
	var discounts = -1;
	var orderValue = 0;
	var cost = Array();
	
	//Update session data and product boxes
	for (i=0; i<items.length; i++) {
		//Session data
		quant = qt[i];
		id = items[i];
		cost[i] = quant * prices[i];
		orderValue += cost[i];
		discounts += quant * discountable[i];
		if (quant > 0) {
			ListOfContents+= "<tr><td class=basket-item>" 
				+ quant + " &times; <a href='/product-" + id + ".html' title='More about this item'>" + names[i] + "</a>"
				+ "</font></td><td class=basket-cost>£" + num2cash(quant*prices[i]) +"</td><td onclick='Remove(\"" + id + "\")' class=basket-remove title='Remove this item from your basket by clicking here'>[X]</td></tr>";
		} 	
		if (quant != sessQt[i]) {
			//Add item to belt
			
			ajax("additemtobelt&id=" + id + "&quantity=" + quant);
			sessQt[i] = quant;
		}
		//Product boxes
		if (document.getElementById("currentBox_" + items[i])) document.getElementById("currentBox_" + items[i]).innerHTML=(quant>0)?quant:"0";
	}
	
	//Postage and packing
	var PnP = "<span class=PnP title='Postage and packaging is free for orders over £15'>" + ((orderValue<15)?" + £2.99 P&P<br><em>Free postage for orders over £15</em>":"Free P&P") + "</span><br><br style='line-height:0.5'>";
	if (discounts > 0) {
		PnP += "<br><font size=1> Including <b>£" + num2cash(discounts * discountAmount) + "</b> discount</font>";
		setSaving(discounts * discountAmount);
	} else discounts = 0;
	//Display contents to user
	if (orderValue == 0) {
	 	document.getElementById("BasketContents").innerHTML = "<i>Your basket is currently empty.</i>";
	 	if (document.getElementById("payExpl")) document.getElementById("payExpl").style.display = 'none';
	} else {
	 	if (document.getElementById("payExpl")) document.getElementById("payExpl").style.display = 'block';
		document.getElementById("BasketContents").innerHTML = ListOfContents
			+ "<tr><td colspan=3 style='padding:8 0 0 0;' align=center><span class=basket-total title='The total amount payable. For a breakdown, go to the checkout.'>Total: £"
			+ num2cash(orderValue - (discounts * discountAmount))
			+ "</span><br" + ">"
			+ PnP
			+ "</td></tr></table>"
			+ "<p class=buynow onclick='BuyNow();''><img src='" + root + "images/ProceedToPayment.PNG' title='Review your order at the checkout stage by clicking here' onmouseover='this.src=\"" + root + "images/ProceedToPaymentHover.PNG\";' onMouseOut='this.src=\"" + root + "images/ProceedToPayment.PNG\";' height=37 width=109></p>";
	}
}

function setSaving(saving) {
	ajax("setsaving&saving="+saving);
}