
var IS_DEBUG = false;


function Basket() {
	this.totprice = "0";
	this.totdelivery = "0";
	this.giftwrap = "0";
	this.noofitems = "0";
	this.max_fixed_discount = "0";
	this.max_percentage_discount = "0";
	this.deliveryregion = "ukpost";
};	//	object to hold summary of Basket
Basket.prototype.getDiscount = function() {
	var totdiscount = (
		(this.totprice * 
			(this.max_percentage_discount / 100.0)
		) 
		+ this.max_fixed_discount
	);
	if (totdiscount > this.totprice) {
		totdiscount = this.totprice;
	}

	return totdiscount;
};	//	end getDiscount
Basket.prototype.getTotal = function () {
	var totdiscount, fintot;

	totdiscount = this.getDiscount();

	fintot = 
		this.totprice 
		+ this.totdelivery 
		+ this.giftwrap 
		- totdiscount;

	if (fintot < 0) {
		fintot = 0;
	}

	return fintot;
};	//	end getTotal
var basket = new Basket();


// Browser detection ///////////////////////////////////////////////////////////////////////////////////////////////////
function checkIt(string, detect) {
	return detect.indexOf(string) + 1;
}


function detectBrowser() {
	var OS, place, browser, total, thestring, version = 0, detect = navigator.userAgent.toLowerCase();

	browser = "An unknown browser";
	if (checkIt('konqueror', detect)) {
		browser = "Konqueror";
		OS = "Linux";
		thestring = 'konqueror';
	} else if (checkIt('safari', detect)) { 
		browser = "Safari"; 
		thestring = 'safari'; 
	} else if (checkIt('omniweb', detect)) {
		browser = "OmniWeb"; 
		thestring = 'omniweb'; 
	} else if (checkIt('opera', detect)) { 
		browser = "Opera"; 
		thestring = 'opera';
	} else if (checkIt('webtv', detect)) { 
		browser = "WebTV"; 
		thestring = 'webtv';
	} else if (checkIt('icab', detect)) { 
		browser = "iCab"; 
		thestring = 'icab';
	} else if (checkIt('msie', detect)) { 
		browser = "Internet Explorer"; 
		thestring = 'msie';
	} else if (!checkIt('compatible', detect)) {
		browser = "Netscape Navigator";
		version = detect.charAt(8);
		thestring = 'compatible';
	}

	if (!version) {
		version = detect.charAt(place + thestring.length);
	}

	if (!OS) {
		OS = "an unknown operating system";
		if (checkIt('linux', detect)) {
			OS = "Linux";
		} else if (checkIt('x11', detect)) {
			OS = "Unix";
		} else if (checkIt('mac', detect)) {
			OS = "Mac";
		} else if (checkIt('win', detect)) {
			OS = "Windows";
		}
	}

	return(browser + ' ' + version + ' on ' + OS);
}


if (document.cookie.indexOf("Referrer") === -1) {
	document.cookie = "Browser=" + detectBrowser();
	document.cookie = "LandingPage=" + document.location.href;
	if (!document.referrer) {
		document.cookie = "Referrer=None";
	} else {
		document.cookie = "Referrer=" + document.referrer;
	}
	document.cookie = "TheBasket=.";
	document.cookie = "Postage=none";
}


// alterError - fixes a rounding bug in Netscape 4 //////////
function alterError(value) {
	return formatCurrency(value);
}
function formatCurrency(value) {
	if (typeof value != "number") {
		return value;
	}

	var newPounds = '0';
	if (value > 0.99) {
		newPounds = parseInt(value, 10);
	}

	var newPence = parseInt((value + 0.0008 - newPounds)* 100, 10);
	if (newPence <= 9) {
		newPence = '0'+ newPence;
	}

	var newString = newPounds + '.' + newPence;

	return (newString);
}



/**
 * Add an item to the shopping basket
 */
function buyItem(newProductID, newItem, newVariant, newPrice, newDelivery, newQuantity, newStock) {
	var index = document.cookie.indexOf("TheBasket");
	var countbegin = (document.cookie.indexOf("=", index) + 1);

	var countend = document.cookie.indexOf(";", index);
	if (countend == -1) {
		countend = document.cookie.length;
	}

	var fulllist = document.cookie.substring(countbegin, countend);

	var alreadyOrdered = false;

	var itemlist = 0;
	var itemstart = 0;
	var thestocklevel = 0;
	var thisitem = 0;
	var theitem = "";
	var i;
	for (i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
			thisitem = 1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thestocklevel = fulllist.substring(itemstart, itemend);
			itemlist=itemlist+1;
		} else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem==1)
				theitem = fulllist.substring(itemstart, i);
			if (thisitem==2) {
				theproductid = fulllist.substring(itemstart, i);
				if (theproductid == newProductID)
					alreadyOrdered = true;
			}
			if (thisitem==3)
				theprice = fulllist.substring(itemstart, i);
			if (thisitem==4)
				thedelivery = fulllist.substring(itemstart, i);
			if (thisitem==5)
				thequantity = fulllist.substring(itemstart, i);

			thisitem++;
			itemstart=i+1;
		}
	}

	var rc = "";
	var alertText = "";
	if (alreadyOrdered) {
  		rc = alert('You have already ordered that product!\n\nIf you want to change the quantity, please\nclick \'edit shopping cart\'.');
  	} else if (newQuantity <= 0) {
  		rc = alert('The quantity entered is incorrect.');
	} else if (newQuantity > newStock) {
		if (newStock == 0) {
			alertText = 'We\'re afraid that this item is currently out of stock.';
		} else if (newStock == 1) {
			alertText = 'There is only 1 item in stock.\nPlease revise your order.';
		} else {
			alertText = 'There are only ' + newStock + ' items in stock.\nPlease revise your order.';
		}
  		rc = alert(alertText);
	} else {
		if (newVariant == '') {
			itemDescription = newItem;
		} else {
			itemDescription = newItem + ' ' + '(' + newVariant + ')';
		}
		//index = document.cookie.indexOf("TheBasket");
		//countbegin = (document.cookie.indexOf("=", index) + 1);
		countbegin = (document.cookie.indexOf("TheBasket=") + 10);

		//countend = document.cookie.indexOf(";", index);
		countend = document.cookie.indexOf(";", countbegin);
		if (countend == -1)
			countend = document.cookie.length;
		document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+itemDescription+"|"+newProductID+"|"+newPrice+"|"+newDelivery+"|"+newQuantity+"|"+newStock+"]";
		window.location.href = window.location.href;
	}

	return true;
}

// showItems() - displays shopping basket in a table ///////////////////////////////////////////////////////////////////
function showItems() {
	var index = document.cookie.indexOf("TheBasket");
	var countbegin = (document.cookie.indexOf("=", index) + 1);
	var countend = document.cookie.indexOf(";", index);
	if (countend == -1)
		countend = document.cookie.length;


	document.writeln('<FORM NAME="updateform">');
	document.writeln('<TABLE id="cart" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('  <TR>');
	document.writeln('		<TD class="carttopleft"><img src="./images/space.gif" width="5" height="18" border="0"></TD>');
	document.writeln('		<TD class="carttop" nowrap width="100%"><span class="gold"><b>Item</b></span></TD>');
	document.writeln('		<TD class="carttop" nowrap style="text-align: center; padding-right: 8px; padding-left: 4px;"><span class="gold"><b>Quantity</b></span></TD>');
	document.writeln('		<TD class="carttop" nowrap style="text-align: right; padding-right: 4px; padding-left: 4px;"><span class="gold"><b>Unit Price</b></span></TD>');
	document.writeln('		<TD class="carttop" nowrap style="text-align: right; padding-right: 4px; padding-left: 4px;"><span class="gold"><b>Total</b></span></TD>');
	document.writeln('		<TD class="carttop" nowrap style="text-align: right; padding-right: 4px; padding-left: 4px;"><span class="gold"><b>&nbsp;</b></span></TD>');
	document.writeln('		<TD class="carttopright"><img src="./images/space.gif" width="5" height="18" border="0"></TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleftline">&nbsp;</TD>');
	document.writeln('		<TD class="cartline" colspan="4">&nbsp;</TD>');
	document.writeln('		<TD class="cartlinespace">&nbsp;</TD>');
	document.writeln('		<TD class="cartrightlinespace">&nbsp;</TD>');
	document.writeln('	</TR>');

	var fulllist = document.cookie.substring(countbegin, countend);

	var itemlist = 0;
	var itemstart = 0;
	var itemend = 0;
	var thisitem = 0;
	var itemtotal = 0;
	var temptotal = 0;
	var theitem = 0;
	var theproductid = 0;
	var theprice = 0;
	var thedelivery = 0;
	var thequantity = 0;
	var thestocklevel = 0;
	var totprice = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
			thisitem = 1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thestocklevel = fulllist.substring(itemstart, itemend);
			itemtotal = 0;
			theprice = eval(theprice);
			itemtotal = (eval(theprice*thequantity));
			temptotal = itemtotal * 100;
			totprice = totprice + itemtotal;
			itemlist=itemlist+1;

			document.writeln('  <TR>');
			document.writeln('		<TD class="cartleft">&nbsp;</TD>');
			document.writeln('		<TD class="cartmiddle" align="left" valign="top">'+theitem+'</TD>');
			document.writeln('		<TD class="cartmiddle" valign="top" style="text-align: center; padding-right: 8px; padding-left: 4px;"><input class="quantity" name="quant'+itemlist+'" type="text" value="'+thequantity+'" size="3" maxlength="3"></TD>');
			document.writeln('		<TD class="cartmiddle" valign="top" style="text-align: right; padding-right: 4px; padding-left: 4px;">&pound;'+formatCurrency(theprice)+'</TD>');
			document.writeln('		<TD class="cartmiddle" valign="top" style="text-align: right; padding-right: 2px; padding-left: 4px;">&pound;'+formatCurrency(itemtotal)+'</TD>');
			document.writeln('		<TD class="cartmiddle" nowrap valign="top" style="text-align: center; padding-left: 6px;">[<a href="basket.php" onclick="amendItem('+ itemlist +',\''+ theitem.replace(/\'/g, '\\\'') +'\',document.updateform.quant'+ itemlist +'.value,'+ thestocklevel +','+ thequantity +'); return false;">Update Quantity</a> | <a href="basket.php" onclick="removeItem('+itemlist+',\''+theitem+'\'); return false;">Remove Item</a>]</TD>');
			document.writeln('		<TD class="cartright">&nbsp;</TD>');
			document.writeln('	</TR>');

		} else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem == 1)
				theitem = fulllist.substring(itemstart, i);
			if (thisitem == 2)
				theproductid = fulllist.substring(itemstart, i);
			if (thisitem == 3)
				theprice = fulllist.substring(itemstart, i);
			if (thisitem == 4)
				thedelivery = fulllist.substring(itemstart, i);
			if (thisitem == 5)
				thequantity = fulllist.substring(itemstart, i);

			thisitem++;
			itemstart = i+1;
		}
	}
	window.totprice = totprice;

	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleftlinespace">&nbsp;</TD>');
	document.writeln('		<TD class="cartlinespace" colspan="3">&nbsp;</TD>');
	document.writeln('		<TD class="cartline">&nbsp;</TD>');
	document.writeln('		<TD class="cartlinespace">&nbsp;</TD>');
	document.writeln('		<TD class="cartrightlinespace">&nbsp;</TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleft">&nbsp;</TD>');
	document.writeln('		<TD class="cartmiddle" valign="middle" colspan="3" style="text-align: right; padding-right: 4px; padding-left: 4px; font-size: 12px;"><span class="gold"><b>Goods Total:</b></span></TD>');
	document.writeln('		<TD class="cartmiddle" valign="middle" style="text-align: right; padding-right: 2px; padding-left: 4px; font-size: 12px;"><b>&pound;'+formatCurrency(totprice)+'</b></TD>');
	document.writeln('		<TD class="cartmiddle" valign="middle">&nbsp;</TD>');
	document.writeln('		<TD class="cartright">&nbsp;</TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartbottomleft"><img src="./images/bottomspace.gif" width="5" height="9" border="0"></TD>');
	document.writeln('		<TD class="cartbottom" colspan="5">&nbsp;</TD>');
	document.writeln('		<TD class="cartbottomright"><img src="./images/bottomspace.gif" width="5" height="9" border="0"></TD>');
	document.writeln('	</TR>');
	document.writeln('</TABLE>');

	return true;
}

// showItems() - displays shopping basket in a table ///////////////////////////////////////////////////////////////////
function showBriefBasket() {
	var index = document.cookie.indexOf("TheBasket");
	var countbegin = (document.cookie.indexOf("=", index) + 1);
	var countend = document.cookie.indexOf(";", index);

	if (countend == -1)
		countend = document.cookie.length;

	document.writeln('<TABLE id="cart"  style="cursor: hand; cursor: pointer;" onclick="window.location.href=\'basket.php\';" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('  <TR>');
	document.writeln('		<TD class="carttopleft"><img src="./images/space.gif" width="5" height="18" border="0"></TD>');
	document.writeln('		<TD colspan="2" style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: .8em" class="carttop" nowrap width="100%"><span class="gold"><b>Your Shopping Basket</b></span></TD>');
	document.writeln('		<TD class="carttopright"><img src="./images/space.gif" width="5" height="18" border="0"></TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleftline">&nbsp;</TD>');
	document.writeln('		<TD colspan="2" class="cartline">&nbsp;</TD>');
	document.writeln('		<TD class="cartrightlinespace">&nbsp;</TD>');
	document.writeln('	</TR>');

	var fulllist = document.cookie.substring(countbegin, countend);

	var itemlist = 0;
	var itemstart = 0;
	var itemend = 0;
	var itemtotal = 0;
	var temptotal = 0;
	var thisitem = 0;
	var theproductid = 0;
	var thestocklevel = 0;
	var numitems = 0;
	var totprice = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
			thisitem = 1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thestocklevel = fulllist.substring(itemstart, itemend);
			itemtotal = 0;
			theprice = eval(theprice);
			itemtotal = (eval(theprice*thequantity));
			temptotal = itemtotal * 100;
			totprice = totprice + itemtotal;
			itemlist=itemlist+1;
			numitems = numitems + parseInt(thequantity, 10);
		} else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem==1)
				theitem = fulllist.substring(itemstart, i);
			if (thisitem==2)
				theproductid = fulllist.substring(itemstart, i);
			if (thisitem==3)
				theprice = fulllist.substring(itemstart, i);
			if (thisitem==4)
				thedelivery = fulllist.substring(itemstart, i);
			if (thisitem==5)
				thequantity = fulllist.substring(itemstart, i);

			thisitem++;
			itemstart=i+1;
		}
	}
	window.totprice = totprice;

	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleft">&nbsp;</TD>');

	if (itemlist > 0) {
		document.writeln('		<TD colspan="2" style="height: 3em; vertical-align: top; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: .8em" class="cartmiddle"><b>Last Added:</b><br>'+thequantity+' x '+theitem+' @ '+formatCurrency(theprice)+' each.</TD>');
	} else {
		document.writeln('		<TD colspan="2" style="height: 3em; vertical-align: middle; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: .8em; text-align: center;" class="cartmiddle">&nbsp;</TD>');
	}

	document.writeln('		<TD class="cartright">&nbsp;</TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleft">&nbsp;</TD>');
	document.writeln('		<TD style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: .8em; text-align: left; padding-bottom: 0;" class="cartmiddle"><b>Number of items: '+numitems+'</b></TD>');
	document.writeln('		<TD style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: .8em; text-align: right; padding-bottom: 0;" class="cartmiddle"><b>Subtotal: &pound;'+formatCurrency(totprice)+'</b></TD>');
	document.writeln('		<TD class="cartright">&nbsp;</TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartbottomleft"><img src="./images/bottomspace.gif" width="5" height="9" border="0"></TD>');
	document.writeln('		<TD colspan="2" class="cartbottom">&nbsp;</TD>');
	document.writeln('		<TD class="cartbottomright"><img src="./images/bottomspace.gif" width="5" height="9" border="0"></TD>');
	document.writeln('	</TR>');
	document.writeln('</TABLE>');

	return true;
}

// amendItem() - amends item in shopping basket ////////////////////////////////////////////////////////////////////////
function amendItem(itemno, itemname, newquant, stocklevel, oldquant) {
	itemno = parseInt(itemno, 10);
	if (typeof itemno != "number")
		return false;

	newquant = parseInt(newquant, 10);
	if (typeof newquant != "number")
		return false;

	stocklevel = parseInt(stocklevel, 10);
	if (typeof stocklevel != "number")
		return false;

	oldquant = parseInt(oldquant, 10);
	if (typeof oldquant != "number")
		return false;

	if (newquant == oldquant)
		return true;

	if (newquant == 0)
		return removeItem(itemno, itemname);

	if (newquant > stocklevel) {
		var alertText = 'There are only ' + stocklevel + ' items in stock.';
		if (stocklevel == 1)
			alertText = 'There is only 1 item in stock.';

		var rc = alert(alertText);
		eval("document.updateform.quant"+itemno+".value = "+oldquant+";");
		return true;
	}


	var index = document.cookie.indexOf("TheBasket");

	var countbegin = (document.cookie.indexOf("=", index) + 1);

	var countend = document.cookie.indexOf(";", index);
	if (countend == -1)
		countend = document.cookie.length;

	var fulllist = document.cookie.substring(countbegin, countend);

	var itemlist = 0;
	var itemstart = 0;
	var fullstart = 0;
	var itemend = 0;
	var itemtotal = 0;
	var temptotal = 0;
	var thisitem = 0;
	var theproductid = 0;
	var thestocklevel = 0;
	var numitems = 0;
	var totprice = 0;

	var newItemList = "";
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			thisitem = 1;
			itemstart = i+1;
			fullstart = i+1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thestocklevel = fulllist.substring(itemstart, itemend);
			itemlist=itemlist+1;
			if (itemlist != itemno) {
				newItemList = newItemList+'['+fulllist.substring(fullstart, itemend)+']';
			} else {
				newItemList = newItemList + '['+theitem+'|'+theproductid+'|'+theprice+'|'+thedelivery+'|'+newquant+'|'+thestocklevel+']';
			}
		} else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem==1)
				theitem = fulllist.substring(itemstart, i);
			if (thisitem==2)
				theproductid = fulllist.substring(itemstart, i);
			if (thisitem==3)
				theprice = fulllist.substring(itemstart, i);
			if (thisitem==4)
				thedelivery = fulllist.substring(itemstart, i);
			if (thisitem==5)
				thequantity = fulllist.substring(itemstart, i);
			thisitem++;
			itemstart=i+1;
		}
	}
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket=."+newItemList;
	self.location = "basket.php";

	return true;
}

// removeItem() - removes an item from the shopping basket /////////////////////////////////////////////////////////////
function removeItem(itemno, itemname) {
	if (!confirm('Are you sure you want to remove the ' + itemname + '\nfrom your shopping cart?'))
		return true;

	var index = document.cookie.indexOf("TheBasket");

	var countbegin = (document.cookie.indexOf("=", index) + 1);

	var countend = document.cookie.indexOf(";", index);
	if (countend == -1)
		countend = document.cookie.length;

	var fulllist = document.cookie.substring(countbegin, countend);

	var newItemList = "";
	var itemstart = 0;
	var itemend = 0;
	var itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			theitem = fulllist.substring(itemstart, itemend);
			itemlist = itemlist+1;
			if (itemlist != itemno)
				newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
		}
	}
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket=."+newItemList;
	self.location = "basket.php";

	return true;
}	//	end removeItem


// clearBasket() - removes all items from the basket ///////////////////////////////////////////////////////////////////
function clearBasket() {
  if (confirm('Are you sure you wish to clear your shopping basket?')) {
	  //index = document.cookie.indexOf("TheBasket");
	  document.cookie="TheBasket=.";
	  document.cookie="Postage=none";
	  self.location = document.location.href;
  }
}

// resetShoppingBasket - resets to shopping basket to empty
//function resetShoppingBasket() {
  //index = document.cookie.indexOf("TheBasket");
  //document.cookie="TheBasket=";
//}

// Return a cookie value ///////////////////////////////////////////////////////////////////////////////////////////////
function getCookieVal(what) {
	var start, end, val

	if (document.cookie.indexOf(what + '=') == -1) {
		val = 'null';
	} else {
		start = document.cookie.indexOf(what + '=') + what.length + 1;
		val = document.cookie;
		val = val.substring(start);
		if (val.indexOf(";") == -1) {
			end = val.length;
		} else {
			end = val.indexOf(";");
		}
		val = val.substring(0, end);
	}

	return(val);
}

function PostageCountriesWrite(country_cookie) {
	var value = "";
	var allcookies = document.cookie;
	var pos = allcookies.indexOf(country_cookie + "Country=");
	if (pos != -1) {
		var start = pos + country_cookie.length + 8;
		var end = allcookies.indexOf(";", start);
		if (end == -1)
			end = allcookies.length;
		value = allcookies.substring(start,end);
		value = unescape(value);
	}

	var allcountries = new Array(1);
	var allcountrieslong = new Array(1);
	if (country_cookie == "delivery") {
		allcountries[0] = "";
		allcountrieslong[0] = "";
		allcountries.push("GB");
		allcountrieslong.push("United Kingdom");
	} else {
		allcountries[0] = ("GB");
		allcountrieslong[0] = ("United Kingdom");
	}
	allcountries.push('AL');	   allcountrieslong.push('Albania');
	allcountries.push('AD');	   allcountrieslong.push('Andorra');
	allcountries.push('AM');	   allcountrieslong.push('Armenia');
	allcountries.push('AT');	   allcountrieslong.push('Austria');
	allcountries.push('AZ');	   allcountrieslong.push('Azerbaijan');
	allcountries.push('PT');	   allcountrieslong.push('Azores');
	allcountries.push('ES');	   allcountrieslong.push('Balearic Islands');
	allcountries.push('BY');	   allcountrieslong.push('Belarus');
	allcountries.push('BE');	   allcountrieslong.push('Belgium');
	allcountries.push('BA');	   allcountrieslong.push('Bosnia And Herzegovina');
	allcountries.push('BG');	   allcountrieslong.push('Bulgaria');
	allcountries.push('ES');	   allcountrieslong.push('Canary Islands');
	allcountries.push('FR');	   allcountrieslong.push('Corsica');
	allcountries.push('HR');	   allcountrieslong.push('Croatia');
	allcountries.push('CY');	   allcountrieslong.push('Cyprus');
	allcountries.push('CZ');	   allcountrieslong.push('Czech Republic');
	allcountries.push('DK');	   allcountrieslong.push('Denmark');
	allcountries.push('EE');	   allcountrieslong.push('Estonia');
	allcountries.push('FO');	   allcountrieslong.push('Faroe Islands');
	allcountries.push('FI');	   allcountrieslong.push('Finland');
	allcountries.push('FR');	   allcountrieslong.push('France');
	allcountries.push('GE');	   allcountrieslong.push('Georgia');
	allcountries.push('DE');	   allcountrieslong.push('Germany');
	allcountries.push('GI');	   allcountrieslong.push('Gibraltar');
	allcountries.push('GR');	   allcountrieslong.push('Greece');
	allcountries.push('GL');	   allcountrieslong.push('Greenland');
	allcountries.push('HU');	   allcountrieslong.push('Hungary');
	allcountries.push('IS');	   allcountrieslong.push('Iceland');
	allcountries.push('IE');	   allcountrieslong.push('Ireland');
	allcountries.push('IT');	   allcountrieslong.push('Italy');
	allcountries.push('KZ');	   allcountrieslong.push('Kazakhstan');
	allcountries.push('CS');	   allcountrieslong.push('Kosovo');
	allcountries.push('KG');	   allcountrieslong.push('Kyrgyzstan');
	allcountries.push('LV');	   allcountrieslong.push('Latvia');
	allcountries.push('LI');	   allcountrieslong.push('Liechtenstein');
	allcountries.push('LT');	   allcountrieslong.push('Lithuania');
	allcountries.push('LU');	   allcountrieslong.push('Luxembourg');
	allcountries.push('MK');	   allcountrieslong.push('Macedonia');
	allcountries.push('PT');	   allcountrieslong.push('Madeira');
	allcountries.push('MD');	   allcountrieslong.push('Moldova');
	allcountries.push('MT');	   allcountrieslong.push('Malta');
	allcountries.push('MC');	   allcountrieslong.push('Monaco');
	allcountries.push('CS');	   allcountrieslong.push('Montenegro');
	allcountries.push('NL');	   allcountrieslong.push('Netherlands');
	allcountries.push('NZ');	   allcountrieslong.push('New Zealand');
	allcountries.push('NO');	   allcountrieslong.push('Norway');
	allcountries.push('PL');	   allcountrieslong.push('Poland');
	allcountries.push('PT');	   allcountrieslong.push('Portugal');
	allcountries.push('RO');	   allcountrieslong.push('Romania');
	allcountries.push('RU');	   allcountrieslong.push('Russian Federation');
	allcountries.push('SM');	   allcountrieslong.push('San Marino');
	allcountries.push('CS');	   allcountrieslong.push('Serbia And Montenegro');
	allcountries.push('SK');	   allcountrieslong.push('Slovakia');
	allcountries.push('SI');	   allcountrieslong.push('Slovenia');
	allcountries.push('ES');	   allcountrieslong.push('Spain');
	allcountries.push('SE');	   allcountrieslong.push('Sweden');
	allcountries.push('CH');	   allcountrieslong.push('Switzerland');
	allcountries.push('TJ');	   allcountrieslong.push('Tajikistan');
	allcountries.push('TR');	   allcountrieslong.push('Turkey');
	allcountries.push('TM');	   allcountrieslong.push('Turkmenistan');
	allcountries.push('UA');	   allcountrieslong.push('Ukraine');
	allcountries.push('UZ');	   allcountrieslong.push('Uzbekistan');
	allcountries.push('VA');	   allcountrieslong.push('Vatican City State');


	if (country_cookie == "delivery") {
		document.writeln("<select name='M_Alt_Del_Country' onChange='addPostCountries("+ window.basket.noofitems +", this)'>");
	} else {
		document.writeln("<select name='country' onChange='addPostCountries("+ window.basket.noofitems +", this)'>");
	}
	for (var i = 0; i < allcountries.length; i++) {
		if (value == allcountries[i]) {
			document.writeln("<option value='"+ allcountries[i] +"' selected='selected'>"+ allcountrieslong[i] +"</option>");
		} else {
			document.writeln("<option value='"+ allcountries[i] +"'>"+ allcountrieslong[i] +"</option>");
		}
	}
	document.writeln("</select>");

	return true;
}	//	end PostageCountriesWrite

function addPostCountries(NoOfItems, select_box) {

	var country_cookie = "delivery";
	if (select_box.name == "country")
		country_cookie = "billing";

	var country = select_box.value;
	document.cookie=country_cookie+"Country="+country;

	var sc = "";
	if (NoOfItems <= 0) {
		sc = alert('You have nothing to buy!');
		return true;
	}

	//	re-calc postage region
	if (country_cookie == "delivery" || document.ORDER.M_Alt_Del_Country.value.length == 0) {
		if (country_cookie == "delivery" && document.ORDER.M_Alt_Del_Country.value.length == 0) {
			country_cookie = "billing";
			country = document.ORDER.country.value;
		}
		var delivery_region = 'world';

		var ukcountries = new Array(1);
		ukcountries[0] = "GB";

		for (x in ukcountries)
			if (ukcountries[x] == country)
				delivery_region = 'ukpost';

		if (delivery_region == 'world') {
			var europecountries = new Array(1);
			europecountries[0] = "AL";
			europecountries.push('AD');
			europecountries.push('AM');
			europecountries.push('AT');
			europecountries.push('AZ');
			europecountries.push('PT');
			europecountries.push('ES');
			europecountries.push('BY');
			europecountries.push('BE');
			europecountries.push('BA');
			europecountries.push('BG');
			europecountries.push('ES');
			europecountries.push('FR');
			europecountries.push('HR');
			europecountries.push('CY');
			europecountries.push('CZ');
			europecountries.push('DK');
			europecountries.push('EE');
			europecountries.push('FO');
			europecountries.push('FI');
			europecountries.push('FR');
			europecountries.push('GE');
			europecountries.push('DE');
			europecountries.push('GI');
			europecountries.push('GR');
			europecountries.push('GL');
			europecountries.push('HU');
			europecountries.push('IS');
			europecountries.push('IE');
			europecountries.push('IT');
			europecountries.push('KZ');
			europecountries.push('CS');
			europecountries.push('KG');
			europecountries.push('LV');
			europecountries.push('LI');
			europecountries.push('LT');
			europecountries.push('LU');
			europecountries.push('MK');
			europecountries.push('PT');
			europecountries.push('MT');
			europecountries.push('MC');
			europecountries.push('CS');
			europecountries.push('NL');
			europecountries.push('NZ');
			europecountries.push('NO');
			europecountries.push('PL');
			europecountries.push('PT');
			europecountries.push('RO');
			europecountries.push('RU');
			europecountries.push('SM');
			europecountries.push('CS');
			europecountries.push('SK');
			europecountries.push('SI');
			europecountries.push('ES');
			europecountries.push('SE');
			europecountries.push('CH');
			europecountries.push('TJ');
			europecountries.push('TR');
			europecountries.push('TM');
			europecountries.push('UA');
			europecountries.push('UZ');
			europecountries.push('VA');
			europecountries.push('MD');

			for (x in europecountries) {
				if (europecountries[x] != country)
					continue;
				
				delivery_region = 'europepost';
				break;
			}
		}

		if (delivery_region != 'world') {
			document.cookie="Postage="+delivery_region;
		}
	}

	if (calculateDelivery)
		window.basket.totdelivery = calculateDelivery();

	var totdelivery = formatCurrency(window.basket.totdelivery);
	if (document.getElementById('totdelivery'))
		document.getElementById('totdelivery').innerHTML = "&pound;"+ totdelivery;
	if (document.getElementById('m_delivery'))
		document.getElementById('m_delivery').value = totdelivery;


	var getTotal = formatCurrency(window.basket.getTotal());
	if (document.getElementById('fintot'))
		document.getElementById('fintot').innerHTML = "&pound;"+ getTotal;
	if (document.getElementById('m_final_total'))
		document.getElementById('m_final_total').value = getTotal;
	if (document.getElementById('amount'))
		document.getElementById('amount').value = getTotal;
	if (document.getElementById('m_amount'))
		document.getElementById('m_amount').value = getTotal;


	//document.location.href="buy.php";

	return true;
}	//	end function addPostCountries


function PopupPic(sPicURL) {
	window.open( "popuppic.html?"+sPicURL, "",
	"resizable=1,HEIGHT=300,WIDTH=200,TOP=0,Left=0");
}

function InfoBox(item) {
	win = window.open("info.php?item="+item, "_info",
	"resizable=0,WIDTH=525,HEIGHT=350,Left=200,TOP=150");
	win.focus();
}

function orderInfoBox(item) {
	win = window.open("order_process_info.php?item="+item, "_info",
	"resizable=0,WIDTH=525,HEIGHT=500,Left=200,TOP=50");
	win.focus();
}

function changePrice(product_id, variantid) {
	var formname = "prod" + product_id;
	var stockfield = "stock" + eval(document.forms[formname].variant_id.value);
	var newstock = eval("document.forms[formname]." + stockfield + ".value");
	document.forms[formname].stock.value = newstock;
	var buttonId = "add" + product_id;
	var button = document.getElementById(buttonId);

	if (newstock == 0) {
		//alert (buttonId);
		//alert (button.src);
		button.src = "images/awating_stock.gif";
		button.disabled = true;
	} else {
		button.src = "images/cart_add.gif";
		button.disabled = false;
	}

	return true;
}

function checkStock(product_id, variantid) {
	var formname = "prod" + product_id;
	//var stock_controlfield = "stock_control" + eval(document.forms[formname].variant.value);
	//var stock_control = eval("document.forms[formname]." + stock_controlfield + ".value");

	var stock_control = "Y";

	if (stock_control == "N") {
		return true;
	} else {
		var stockfield = "stock" + eval(document.forms[formname].variant_id.value);
		var stock = parseFloat(eval("document.forms[formname]." + stockfield + ".value"));

		var quantity = parseFloat(document.forms[formname].quantity.value);

		//alert("Stock: "+stock+", Quantity: "+quantity);
		//return false;

		if (stock == 0) {
			alert("We\'re afraid that this item is currently out of stock.");
			return false;
		} else if (quantity > stock) {
			alert("We only have "+stock+" of these items in stock.");
			return false;
		} else {
			return true;
		}
	}
}



/**
 * Gets the product's details and passes to buyItem
 */
function addItThen(product_id) {

	var formname = "prod" + product_id;

	var variant_id = document.forms[formname].variant_id.value;
	var name = document.forms[formname].name.value;
	var quantity = document.forms[formname].quantity.value;

	var variant = eval("document.forms[formname].variant" + eval(variant_id) + ".value");
	var price = eval("document.forms[formname].price" + eval(variant_id) + ".value");
	var delivery = document.forms[formname].delivery.value;
	var stock = eval("document.forms[formname].stock" + eval(variant_id) + ".value");


	/*
	var varstring = "";
	varstring += "product_id="+variant_id+"\n";
	varstring += "name="+name+"\n";
	varstring += "variant="+variant+"\n";
	varstring += "price="+price+"\n";
	varstring += "delivery="+delivery+"\n";
	varstring += "quantity="+quantity+"\n";
	varstring += "stock="+stock+"\n";
	alert(varstring);
	return false;
	*/

	return buyItem(variant_id, name, variant, price, delivery, quantity, stock);
}


function calculateDelivery() {

	//	get delivery area
	var DeliveryRegion = "ukpost";
	var postage = 0;
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("Postage=");
	if (pos != -1) {
		var start = pos + 8;
		var end = allcookies.indexOf(";", start);
		if (end == -1) end = allcookies.length;
		DeliveryRegion = allcookies.substring(start,end);
		DeliveryRegion = unescape(DeliveryRegion);
	}
	if (DeliveryRegion == "none")
		DeliveryRegion = 'ukpost';


	//	check for free-postage promotion
	if (DeliveryRegion == "ukpost") {
	}	//	end if ukpost


	//	get basket
	var index = document.cookie.indexOf("TheBasket");
	var countbegin = (document.cookie.indexOf("=", index) + 1);
	var countend = document.cookie.indexOf(";", index);
	if (countend == -1)
		countend = document.cookie.length;
	var fulllist = document.cookie.substring(countbegin, countend);


	//	get delivery
	var thisitem = 0;
	var itemstart = -1;
	var thedelivery = 0;
	var totdelivery = 0;
	var thequantity = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			thisitem = 1;
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == ']') {
			if (DeliveryRegion == "world") {
				totdelivery = totdelivery + 1000;

			} else if (DeliveryRegion == "ukpost") {
				totdelivery = totdelivery + (eval(thedelivery*thequantity));

			} else {
				if (thedelivery == "2.75") {
					totdelivery = totdelivery + (eval(7.11*thequantity));

				} else if (thedelivery == "3.50") {
					totdelivery = totdelivery + (eval(11.61*thequantity));

				} else if (thedelivery == "2.95") {
					totdelivery = totdelivery + (eval(7.11*thequantity));

				} else if (thedelivery == "2.95") {
					totdelivery = totdelivery + (eval(7.11*thequantity));
				}
			}
		} else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem==4)
				thedelivery = fulllist.substring(itemstart, i);
			if (thisitem==5)
				thequantity = fulllist.substring(itemstart, i);
			thisitem++;
			itemstart=i+1;
		}
	}	//	end foreach letter


	return totdelivery;
}	//	end function calculateDelivery


function showItems2() {

	//	get basket
	var index = document.cookie.indexOf("TheBasket");
	var countbegin = (document.cookie.indexOf("=", index) + 1);
	var countend = document.cookie.indexOf(";", index);
	if (countend == -1)
		countend = document.cookie.length;
	var fulllist = document.cookie.substring(countbegin, countend);
	//alert("showItems2::fulllist "+ fulllist);


	//	get delivery area
	var DeliveryRegion = "ukpost";
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("Postage=");
	if (pos != -1) {
		var start = pos + 8;
		var end = allcookies.indexOf(";", start);
		if (end == -1) end = allcookies.length;
		DeliveryRegion = allcookies.substring(start,end);
		DeliveryRegion = unescape(DeliveryRegion);
	}
	if (DeliveryRegion == "none")
		DeliveryRegion = 'ukpost';

	document.writeln('<FORM action="thanks.html" target="_top">');
	document.writeln('<TABLE id="cart" border="0" cellspacing="0" cellpadding="0" style="width: 100%; height: 100%">');

	document.writeln('  <TR>');
	document.writeln('		<TD class="carttopleft"><img src="./images/space.gif" width="5" height="18" border="0"></TD>');
	document.writeln('		<TD class="carttop" nowrap width="130"><span class="gold"><b>Item</b></span></TD>');
	document.writeln('		<TD class="carttop" nowrap style="text-align: center" style="padding-right: 8px; padding-left: 4px;"><span class="gold"><b>Quantity</b></span></TD>');
	document.writeln('		<TD class="carttop" nowrap style="text-align: right" style="padding-right: 4px; padding-left: 4px;"><span class="gold"><b>Unit Price</b></span></TD>');
	document.writeln('		<TD class="carttop" nowrap style="text-align: right" style="padding-right: 2px; padding-left: 2px;"><span class="gold"><b>Total</b></span></TD>');
	document.writeln('		<TD class="carttopright"><img src="./images/space.gif" width="5" height="18" border="0"></TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleftline">&nbsp;</TD>');
	document.writeln('		<TD class="cartline" colspan="4">&nbsp;</TD>');
	document.writeln('		<TD class="cartrightlinespace">&nbsp;</TD>');
	document.writeln('	</TR>');

	var totprice = 0;
	var itemlist = 0;
	var NoOfItems = 0; // total count of items variable
	var WorldPayDescription = "";
	var thisitem = 0;
	var itemstart = -1;
	var itemend = -1;
	var thestocklevel = 0;
	var itemtotal = 0;
	var theitem = 0;
	var theproductid = 0;
	var theprice = 0;
	var thedelivery = 0;
	var thequantity = 0;
	var temptotal = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		//alert("substring "+ fulllist.substring(i,i+1));

		if (fulllist.substring(i,i+1) == '[') {
			thisitem = 1;
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thestocklevel = fulllist.substring(itemstart, itemend);
			NoOfItems += (eval(thequantity)); // adds amount of items together
			itemtotal = 0;
			itemtotal = (eval(theprice*thequantity));
			theprice = eval(theprice);
			temptotal = itemtotal * 100;
			totprice = totprice + itemtotal;
			itemlist=itemlist+1;
			WorldPayDescription = WorldPayDescription + thequantity + " " + theitem + ", ";

			document.writeln('  <TR>');
			document.writeln('		<TD class="cartleft">&nbsp;</TD>');
			document.writeln('		<TD class="cartmiddle" valign="top">'+theitem+'</TD>');
			document.writeln('		<TD class="cartmiddle" style="text-align: center" valign="top">'+thequantity+'</TD>');
			document.writeln('		<TD class="cartmiddle" style="text-align: right" valign="top" style="padding-right: 4px; padding-left: 4px;">&pound;'+formatCurrency(theprice)+'</TD>');
			document.writeln('		<TD class="cartmiddle" style="text-align: right" valign="top" style="padding-right: 2px; padding-left: 2px;">&pound;'+formatCurrency(itemtotal)+'</TD>');
			document.writeln('		<TD class="cartright">&nbsp;</TD>');
			document.writeln('	</TR>');

			document.writeln('<INPUT TYPE="hidden" NAME="M_item['+itemlist+']" VALUE="'+theitem+'" SIZE="40">');
			document.writeln('<INPUT TYPE="hidden" NAME="M_quantity['+itemlist+']" VALUE="'+thequantity+'" SIZE="40">');
			document.writeln('<INPUT TYPE="hidden" NAME="M_productid['+itemlist+']" VALUE="'+theproductid+'" SIZE="40">');
			document.writeln('<INPUT TYPE="hidden" NAME="M_price each['+itemlist+']" VALUE="'+theprice+'" SIZE="40">');
			document.writeln('<INPUT TYPE="hidden" NAME="M_total cost['+itemlist+']" VALUE="'+formatCurrency(itemtotal)+'" SIZE="40">');
		} else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem==1) theitem = fulllist.substring(itemstart, i);
			if (thisitem==2) theproductid = fulllist.substring(itemstart, i);
			if (thisitem==3) theprice = fulllist.substring(itemstart, i);
			if (thisitem==4) thedelivery = fulllist.substring(itemstart, i);
			if (thisitem==5) thequantity = fulllist.substring(itemstart, i);
			thisitem++;
			itemstart=i+1;
		}	//	end if char =
	}	//	end foreach char
	//alert("showItems2::totprice "+ totprice);
	//alert("showItems2::NoOfItems "+ NoOfItems);
	window.basket.totprice = totprice;
	window.basket.noofitems = NoOfItems;


	var GiftWrap = 0;
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("GiftWrap=");
	if (pos != -1) {
		var start = pos + 9;
		var end = allcookies.indexOf(";", start);
		if (end == -1) end = allcookies.length;
		var GiftValue = allcookies.substring(start,end);
		GiftValue = unescape(GiftValue);
		GiftWrap = 0;
		if (GiftValue == "YES")
			GiftWrap = 1.50;
	}
	window.basket.giftwrap = GiftWrap;
	//alert("showItems2::GiftWrap "+ GiftWrap);


	var max_fixed_discount = 0;
	var max_percentage_discount = 0;
	window.basket.max_fixed_discount = max_fixed_discount;
	window.basket.max_percentage_discount = max_percentage_discount;



	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleftlinespace">&nbsp;</TD>');
	document.writeln('		<TD class="cartlinespace" colspan="3">&nbsp;</TD>');
	document.writeln('		<TD class="cartline">&nbsp;</TD>');
	document.writeln('		<TD class="cartrightlinespace">&nbsp;</TD>');
	document.writeln('	</TR>');

	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleft">&nbsp;</TD>');
	document.writeln('		<TD class="cartmiddle" style="text-align: right" valign="middle" colspan="3" style="padding-right: 4px; padding-left: 4px;"><b>Goods Total:</b></TD>');
	document.writeln('		<TD class="cartmiddle" style="text-align: right" valign="middle" id="totprice" style="padding-right: 2px; padding-left: 2px;"><b>&pound;'+formatCurrency(totprice)+'</b></TD>');
	document.writeln('		<TD class="cartright">&nbsp;</TD>');
	document.writeln('	</TR>');

	var totdiscount = window.basket.getDiscount();
	if(totdiscount > 0) {
		document.writeln('  <TR>');
		document.writeln('		<TD class="cartleft">&nbsp;</TD>');
		document.writeln('		<TD class="cartmiddle" style="text-align: right" valign="middle" colspan="3" style="padding-right: 4px; padding-left: 4px;">Discount:</TD>');
		document.writeln('		<TD class="cartmiddle" style="text-align: right" id="totdiscount" valign="middle" style="padding-right: 2px; padding-left: 2px;">&pound;'+formatCurrency(totdiscount)+'</TD>');
		document.writeln('		<TD class="cartright">&nbsp;</TD>');
		document.writeln('	</TR>');
	}

	window.basket.totdelivery = calculateDelivery();
	var totdelivery = formatCurrency(window.basket.totdelivery);
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleft">&nbsp;</TD>');
	document.writeln('		<TD class="cartmiddle" style="text-align: right" valign="middle" colspan="3" style="padding-right: 4px; padding-left: 4px;">Packing &amp; Delivery:</TD>');
	document.writeln('		<TD class="cartmiddle" style="text-align: right" id="totdelivery" valign="middle" style="padding-right: 2px; padding-left: 2px;">&pound;'+ totdelivery +'</TD>');
	document.writeln('		<TD class="cartright">&nbsp;</TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleftlinespace">&nbsp;</TD>');
	document.writeln('		<TD class="cartlinespace" colspan="3">&nbsp;</TD>');
	document.writeln('		<TD class="cartline">&nbsp;</TD>');
	document.writeln('		<TD class="cartrightlinespace">&nbsp;</TD>');
	document.writeln('	</TR>');

	var fintot = formatCurrency(window.basket.getTotal());
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleft">&nbsp;</TD>');
	document.writeln('		<TD class="cartmiddle" style="text-align: right" valign="middle" colspan="3" style="padding-right: 4px; padding-left: 4px;"><span class="gold" style="font-size: 12px;"><b><b>Total Due:</b></span></TD>');
	document.writeln('		<TD class="cartmiddle" style="text-align: right" id="fintot" valign="middle" style="padding-right: 2px; padding-left: 2px; font-size: 12px; font-weight: bold;"><span>&pound;'+ fintot +'</span></TD>');
	document.writeln('		<TD class="cartright">&nbsp;</TD>');
	document.writeln('	</TR>');


	document.writeln('  <tr>');
	document.writeln('  <td class="cartleft">&nbsp;</td>');
	document.writeln('   <td colspan="4" class="cartmiddle" align="left" valign="middle">&nbsp;</td>');
	document.writeln('  <td class="cartright">&nbsp;</td>');
	document.writeln('	</TR>');
	document.writeln('  <tr>');
	document.writeln('   <td class="cartleft">&nbsp;</td>');
	document.writeln('   <td colspan="4" class="cartmiddle" nowrap align="left"><b><span class="gold" style="font-size: 12px;">For our information:</span></b></td>');
	document.writeln('   <td class="cartright" style="font-size: 12px;">&nbsp;</td>');
	document.writeln('	</TR>');
	document.writeln('  <tr>');
	document.writeln('   <td class="cartleftline">&nbsp;</td>');
	document.writeln('   <td colspan="4" class="cartline">&nbsp;</td>');
	document.writeln('   <td class="cartrightlinespace">&nbsp;</td>');
	document.writeln('   </tr>');
	document.writeln('  <tr>');
	document.writeln('   <td class="cartleft">&nbsp;</td>');
	document.writeln('   <td colspan="4" class="cartmiddle">');
	document.writeln('	<table border="0" cellspacing="0" cellpadding="0" width="100%">');
	document.writeln('	  <tr>');
	document.writeln('		<td class="cartmiddle" align="left" valign="middle" style="font-size: 12px; padding-right: 4px;" nowrap> <span style="font-size: 12px;">Where did you hear about <strong>ukhandbags</strong></span><strong><span class="gold" style="font-size: 12px;">.com</span></strong>?:</td>');
	document.writeln('		<td class="cartmiddle" align="left" valign="middle" style="font-size: 12px; width: 100%" nowrap>');
	document.writeln('		 <input class="cartinput" type="TEXT" name="M_where_heard2" style="width: 50%">');
	document.writeln('		</td>');
	document.writeln('	  </tr>');
	document.writeln('	</table>');
	document.writeln('   </td>');
	document.writeln('   <td class="cartright">&nbsp;</td>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartleftpad">&nbsp;</TD>');
	document.writeln('		<TD class="cartmiddlepad" colspan="4">&nbsp;</TD>');
	document.writeln('		<TD class="cartrightpad">&nbsp;</TD>');
	document.writeln('	</TR>');
	document.writeln('  <TR>');
	document.writeln('		<TD class="cartbottomleft"><img  src="./images/bottomspace.gif" width="5" height="9" border="0"></TD>');
	document.writeln('		<TD class="cartbottom" align="right" colspan="4">&nbsp;</TD>');
	document.writeln('		<TD class="cartbottomright"><img  src="./images/bottomspace.gif" width="5" height="9" border="0"></TD>');
	document.writeln('	</TR>');
	document.writeln('</TABLE>');

	document.writeln('<INPUT TYPE="hidden" NAME="M_Goods Total" VALUE="'+formatCurrency(totprice)+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" NAME="M_Discount" VALUE="'+formatCurrency(totdiscount)+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" id="m_delivery" NAME="M_Pack & Del" VALUE="'+formatCurrency(totdelivery)+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" NAME="M_Gift Wrap" VALUE="'+formatCurrency(GiftWrap)+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" id="m_final_total" NAME="M_Final Total" VALUE="'+formatCurrency(fintot)+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" id="amount" NAME="amount" VALUE="'+formatCurrency(fintot)+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" id="m_amount" NAME="M_amount" VALUE="'+formatCurrency(fintot)+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" NAME="M_Delivery Region" VALUE="'+DeliveryRegion+'" SIZE="40">');
	document.writeln('<INPUT TYPE="hidden" NAME="instId" VALUE="80900">');
	document.writeln('<INPUT TYPE="hidden" NAME="M_instId" VALUE="80900">');
	var date = new Date();
	var day = date.getDate();
	var month = date.getMonth() + 1.0;
	var year = date.getFullYear();
	var hours = date.getHours();
	var minutes = date.getMinutes();
	if (month < 10)
		month = "0" + month;
	if (minutes < 10)
		minutes = "0" + minutes;
	if (day < 10)
		day = "0" + day;
	if (hours < 10)
		hours = "0" + hours;
	document.writeln('<INPUT TYPE="hidden" NAME="cartId" VALUE="'+"UKH",year,month,day,"-",hours,minutes+'">');
	document.writeln('<INPUT TYPE="hidden" NAME="M_cartId" VALUE="'+"UKH",year,month,day,"-",hours,minutes+'">');
	document.writeln('<INPUT TYPE="hidden" NAME="testMode" VALUE="0">');
	document.writeln('<INPUT TYPE="hidden" NAME="currency" VALUE="GBP">');
	WorldPayDescription = WorldPayDescription.substr(0, WorldPayDescription.length-2);
	if (GiftWrap > 0)
		WorldPayDescription = WorldPayDescription+", Gift Wrapping";
	document.writeln('<INPUT TYPE="hidden" NAME="desc" VALUE="'+WorldPayDescription+'">');
	document.writeln('<INPUT TYPE="hidden" NAME="M_desc" VALUE="'+WorldPayDescription+'">');
	//document.writeln('</FORM>');


	return true;
}


// global variable for error flag
var errfound = false;


// function to validate by length
function ValidLength(item, len) {
	return (item.length >= len);
}


// function to validate an email address
function ValidEmail(item)
{
	if (!ValidLength(item, 5))
		return false;
	if (item.indexOf ('@', 0) == -1)
		return false;

	return true;
}	//	end ValidEmail


// display an error alert
function error(elem, text)
{
	// abort if we already found an error
	if (window.errfound)
		return true;

	window.alert(text);
	//	elem.select();// commented out enabling select box focusing
	//	elem.focus();
	window.errfound = true;

	return true;
}	//	end error


// main validation function
function Validate() {
	if (typeof window.error != "function")
		return true;

	var totprice = window.totprice;
	if (typeof window.alterError == "function")
		totprice = formatCurrency(totprice);

	if (totprice == 0) {
		error(document.ORDER.CCImage,"You have nothing to buy as yet!");
		window.errfound = true;
	} else if (totprice >= 250.01) {
		error(document.ORDER.CCImage,"You have exceeded the order limit!");
		window.errfound = true;
	}


	return !window.errfound; /* true if there are no errors */
}	//	end Validate

