﻿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 ("Purpleline Enduro, Self fit",
"Purpleline Enduro, Fitted",
"Purpleline Enduro2, Self fit",
"Purpleline Enduro2, Fitted",
"Purpleline Quattro, Self fit",
"Purpleline Quattro, Fitted",
"Hitchdrive",
"Truma Mover S, Self fit",
"Truma Mover S, fitted",
"Truma Mover SE, Self fit",
"Truma Mover SE, fitted",
"Truma Mover TE, Self fit",
"Truma Mover TE, fitted",
"Powrtouch Compact Single, self fit",
"Powrtouch Compact Single, fitted",
"Powrtouch Heavy Duty Single, self fit",
"Powrtouch Heavy Duty Single, fitted",
"Powrtouch Twin, self fit",
"Powrtouch Twin, fitted",
"Powrtouch All Wheel Drive Twin, self fit",
"Powrtouch All Wheel Drive Twin, fitted",
"Powrtouch PowrActuator, self fit",
"Powrtouch PowrActuator, fitted",
"Truma Original Mover, Self fit",
"Truma Original Mover, fitted",
"Reich Move Control, Self Fit",
"Reich Move Control, fitted",
"Reich Move Control Twin, Self Fit",
"Reich Move Control Twin, fitted",
"Reich RK Mover, Self Fit",
"Reich RK Mover, fitted",
"Reich RK Mover Twin, Self Fit",
"Reich RK Mover Twin, fitted",
"Reich Motor Drive, Single Axle",
"Reich Motor Drive, Twin Axle",
"Grove Move Control Jumbo Single, Self Fit",
"Grove Move Control Jumbo Single, fitted",
"Grove Move Control Jumbo Twin, Self Fit",
"Grove Move Control Jumbo Twin, fitted",
"Test item 1",
"Test Product 2",
"Purpleline Saracen Hitch Lock",
"Saracen Hitch Lock Special Offer",
"Purpleline AeroPlus",
"Reich Move Control Compact Single, Self Fit",
"Reich Move Control Compact Single, fitted",
"Reich Move Control Compact Twin, Self Fit",
"Reich Move Control Compact Twin, fitted",
"CombiMover Standard (manual), fitted",
"CombiMover Electronic (automatic), fitted",
"E-go Caravan Mover, self fit",
"E-go Caravan Mover, fitted",
"Royal Titan, Self Fit",
"Royal Titan, fitted",
"Royal Hercules, self fit",
"Royal Hercules, fitted",
"Royal Atlas, self fit",
"Royal Atlas, fitted",
"Motor Mover Plus Single, self fit",
"Motor Mover Plus Single, fitted",
"Motor Mover Plus twin self fit",
"Motor Mover Plus Twin, fitted",
"Motor Mover Motorglide single, self fit",
"Motor Mover Motorglide single, fitted",
"Motor Mover Motorglide twin, self fit",
"Motor Mover Motorglide twin, fitted",
"Reich Move Control Economy Single, Self Fit",
"Reich Move Control Economy Single, fitted",
"Reich Move Control Economy Twin, Self Fit",
"Reich Move Control Economy Twin, fitted",

"Powrtouch Heavy Duty Single, Electronic, self fit",	//PowrTouch + PowrActuator
"Powrtouch Heavy Duty Single, Electronic, fitted",
"Powrtouch Twin, Electronic, self fit",
"Powrtouch Twin, Electronic, fitted",
"Powrtouch All Wheel Drive Twin, Electronic, self fit",
"Powrtouch All Wheel Drive Twin, Electronic, fitted"
)

pCount = product.length

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

price = new Array(54900, 66900, 89900, 99900, 0, 0, 0,	//Purpleline
104000, 104000, 128500, 138500, 139500, 149500,				// Truma
69900, 79900, 79900, 89900, 109900, 119900, 149500, 169600, 17500, 25000,	// PowrTouch manual
64900, 73900,		// Truma
83500, 93500, 165000, 179500, 74900, 84900, 143500, 158500, 20000, 40000,	//Reich
69900, 79900, 149900, 159900,	//Grove
9,19,  //test
5999,0,9995,	//Purpleline
123500,123500,224900,224900,74900,99900,  // Reich
59900,73900, //e-go
69900, 75900, 83900, 89900, 99900, 109900,  // Royal
77500,87500,99500,109500,89500,99500,109500,119500,  //Motor Mover
69900, 79900, 149900, 159900,  // Reich Economy
99500, 109500, 129500, 139500, 187500, 207500) // Powrtouch + Powractuator


shipping = 1999;
shipBand = new Array(0,1999,1995,995)

fitting = new Array(1,0,1,0,1,0,1,
1,0,1,0,1,0,
1,0,1,0,1,0,1,0,1,0,
2,0,
1,0,1,0,1,0,1,0,1,0,
1,0,1,0,
1,0, //test
0,0,3,
1,0,1,0,
0,0,
1,0, //Ego
1,0,1,0,1,0, //Royal
1,0,1,0,1,0,1,0,  // Motor Mover
1,0,1,0,  //Reich Economy
1,0,1,0,1,0)	//Powrtouch + Actuator

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


