﻿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 = "";
items = 0;

product = new Array ("EFOY 600 Fuel Cell",
"EFOY 900 Fuel Cell",
"EFOY 1200 Fuel Cell",
"EFOY 1600 Fuel Cell",
"EFOY 2200 Fuel Cell",
"EFOY 5 litre fuel cartridge",
"EFOY 10 litre fuel cartridge",
"Fuel Cell Installation service")

pCount = product.length

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

price = new Array(184900, 239900, 282500, 299900, 464900, 2695, 3950,
9999)

shipping = 1499;
shipBand = new Array(0,495,1495,1995)

fitting = new Array(2,2,2,2,2,1,1,0) 

if (document.cookie != "") {
	if(cook = cookieVal("ki")) {
		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"
	}
}

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



