﻿logIn = 0
expireDate = new Date
expireDate.setFullYear(expireDate.getFullYear()+2)
quantityMeta = ""

country = "UK"
region = 0
rememberme = "yes";
total = 0;
cook = "";
orderRef = "";
items = 0;

product = new Array ("Slate Place Mats - Box of 4",
"Slate Place Mats - Box of 6",
"Slate Coasters - Box of 4",
"Slate Coasters - Box of 6",
"Slate Cheeseboard / Canape Tray",
"Slate Trivet - Large",
"Slate Trivet Small",
"Slate Tableware Gift Set",
"Printed Photo Slates",
"Slate Plant Markers - Set of 6",
"Shabby Chic Fruit Bowl, Blue",
"Shabby Chic Fruit Bowl, Cream",
"Shabby Chic Fruit Bowl, Silver Green",
"Lusso Leather Place Mats, plain black - Box of 4",
"Lusso Leather Place Mats, plain brown - Box of 4",
"Lusso Leather Place Mats, plain claret - Box of 4",
"Lusso Leather Place Mats, embossed line black - Box of 4",
"Lusso Leather Place Mats, embossed line brown - Box of 4",
"Lusso Leather Place Mats, embossed line claret - Box of 4",
"Lusso Leather Coasters, plain black - Box of 4",
"Lusso Leather Coasters, plain brown - Box of 4",
"Lusso Leather Coasters, plain claret - Box of 4",
"Lusso Leather Coasters, embossed line black - Box of 4",
"Lusso Leather Coasters, embossed line brown - Box of 4",
"Lusso Leather Coasters, embossed line claret - Box of 4",
"Large Leather Centre Trivet",
"Slate Starter Platter",
"Slate Serving Platter",
"Large Slate Platter",
"Gastro Platter",
"Gourmet Platter",
"Gastro Cheese Board",
"Round Cheese board",
"Sparrow Bird Seed Holder",
"Picket fence planters - set of 3",
"Rustic gecko with white stones",
"Cast iron boot scraper and brush",
"Cast iron sign: A Cat and its staff live here",
"Bronze sign: Save water drink Beer",
"Green cast iron chicken 12 egg holder",
"Snail door wedge - cast iron",
"Pair of Square Serving Platters",
"Square Slate Trivet - medium"
)

pCount = product.length

quantity = new Array(pCount)
for(i=0; i<pCount; i++) {
	quantity[i] = 0;
	}

price = new Array(2995,
3999,
1995,
2695,
1695,
1995,
695,
13665,
2999,
1495,
7995,
7995,
7995,
4671,
4671,
4671,
4671,
4671,
4671,
2291,
2291,
2291,
2291,
2291,
2291,
5995,
495,
595,
999,
325,
399,
695,
1995,
999,
3495,
1299,
1495,
999,
699,
999,
699,
699,
1299)

sWeight = new Array(4300, 6300, 700, 900, 1200, 1900, 800, 15000, 1000, 1200, 5100, 5100, 5100, 2000, 2000, 2000, 2000, 2000, 2000, 700, 700, 700, 700, 700, 700, 600, 800, 1000, 1800, 500, 500,600, 1200,1000,4600,250,2250,1450,250,1100,500,500,500)

shipBand = new Array(0,900,1800)  // Englad wales - Scotland up to 25kg

discount = 0.0;	// Percentage discount
discountAmount = 0;

if (document.cookie != "") {
	if(cook = cookieVal("sst")) {
		cook = unenc(cook)
		realname = cook.split("^")[0]
		telephone = cook.split("^")[1]
		email = cook.split("^")[2]
		address1 = cook.split("^")[3]
		address2 = cook.split("^")[4]
		address3 = cook.split("^")[5]
		postcode = cook.split("^")[6]
		country = cook.split("^")[7]
		rememberme = cook.split("^")[8]
	}
	if(!rememberme) {
		rememberme = "no"
	}
}
orderRef = cookieVal("orderRef")

logIn = cookieVal("logIn")
if(logIn == false) {	/* First Page - clear basket */
	logIn = true
	setQuantity(quantity)
	setLogin(logIn)

} else{					/* Load basket values */
	quantityMeta = cookieVal("quantity")
	for(i=0; i<pCount; i++) {
		quantity[i] = parseInt(quantityMeta.split(",")[i])
		if(isNaN(quantity[i])){quantity[i]=0}
	}
	if(cookieVal("region")) {
		region = cookieVal("region")
	}
}
/* quantity = new Array (1,0,1,1,1,2,2) */
/* quantity[0] = 1; /* TEST DATA ONLY */

for( i=0; i<pCount; i++) { items+=quantity[i] }

/* Functions below */

function cookieVal(cookieName) {
	thisCookie = document.cookie.split("; ")
	for (i=0; i<thisCookie.length; i++) {
       	if (cookieName == thisCookie[i].split("=")[0]) {
        	return thisCookie[i].split("=")[1]
        }
    }
return 0
}

function unenc(enc_str) {
	plain = ""
	if(enc_str != "") {
		for(i = 0; i < enc_str.length; i += 2) {
			meta = parseInt(enc_str.substr(i,[2])) + 23
			num_in = unescape('%' + meta.toString(16))
			plain += num_in
		}
	plain = unescape(plain)
 	}
return(plain)
}

function enc(plain) {
	enc_str = "";
	if(plain == "") {
		alert("No string")
	}
	else {
		pl_str = escape(plain);
		for(i = 0; i < pl_str.length; i++) {
			enc_str += pl_str.charCodeAt(i) - 23;
		}
	}
return(enc_str)
}

function setLogin(logIn) {
	document.cookie="logIn="+logIn+";;path=/"
	return true
}

function setQuantity(quantity) {
	document.cookie="quantity="+quantity+";;path=/"
	return true
}

function setRegion(region) {
	document.cookie="region="+region+";;path=/"
	return true
}

var re2 = /^\d+$/

function addItem2(i,count,finish) {
//	alert(size+" "+finish+" "+p3)
	if(re2.test(count) != true) {
		alert("Please enter only numbers");
		window.location.reload();
		return false;
	}
	i += parseInt(finish);
//	alert("Adding "+product[i])
	quantity[i] += parseInt(count);
	if(quantity[i] < 0) {
		quantity[i] = 0
	}
	setQuantity(quantity);
//	window.location.reload();
	window.location = "../basket.html";
	return true;
}


function addItem(i,count) {
	if(re2.test(count) != true) {
		alert("Please enter only numbers");
		window.location.reload();
		return false;
	}
	if(parseInt(count) > 9){
		alert("Please call for quote on quantities of 10 and over")
		window.location.reload();
		return false;
	}
	quantity[i] += parseInt(count);
	if(quantity[i] < 0) {
		quantity[i] = 0
	}
	setQuantity(quantity);
//	window.location.reload();
	window.location = "../basket.html";
	return true;
}
re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

function clearBasket() {
	for(i=0; i<quantity.length; i++){
		quantity[i]=0;
	}
	setQuantity(quantity)
	window.location.reload();
}

function clearItem(i) {
	quantity[i]=0;
	setQuantity(quantity);
	window.location.reload();
}



