﻿logIn = 0
expireDate = new Date
expireDate.setFullYear(expireDate.getFullYear()+2)
quantityMeta = ""
realname = ""
telephone = ""
email = ""
address1 = ""
address2 = ""
address3 = ""
postcode = ""
country = "UK"
region = 0
rememberme = "yes";
total = 0;
cook = "";
orderRef = "";
items = 0;

product = new Array ("eXpress yourself tanning mist 150ml",
"eXtremely natural self tan 200ml ",
"eXtend and perfect gradual tan 200ml",
"eXquisitely soft body polish 200ml ",
"eXotically rich face and body wash 200ml",
"eXceptional radiance moisturising balm 200ml",
"eXtra sparkle gold shimmer 75ml",
"eXtra sparkle silver shimmer 75ml")

pCount = product.length

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

price = new Array(1495,
1995 ,
1495 ,
1095 ,
1095 ,
1095 ,
495 ,
495 )


shipping = 250;
shipBand = new Array(0,250,300,350,400,450,500,500,500,500,500)
shipFree=5000;
	

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 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();
}



