//=====================================================================
//					NOP Design JavaScript Shopping Cart						
//
// For more information on SmartSystems, or how NOPDesign can help you
// Please visit us on the WWW at http://www.nopdesign.com				
//
// Javascript portions of this shopping cart software are available as
// freeware from NOP Design.  You must keep this comment unchanged in
// your code.  For more information contact FreeCart@NopDesign.com.	
//
// JavaScript Shop Module, V.4.4.0												
//=====================================================================



//---------------------------------------------------------------------
//							  Global Options										
//							 ----------------										
// Shopping Cart Options, you can modify these options to change the
// the way the cart functions.													
//
// Language Packs
// ==============
// You may include any language pack before nopcart.js in your HTML	
// pages to change the language.  Simply include a language pack with
// a script src BEFORE the <SCRIPT SRC="nopcart.js">... line.			
//  For example: <SCRIPT SRC="language-en.js"></SCRIPT>					
//
// Options For Everyone:															
// =====================															
// * MonetarySymbol: string, the symbol which represents dollars/euro,
//	in your locale.
// * DisplayNotice: true/false, controls whether the user is provided
//	with a popup letting them know their product is added to the cart
// * DisplayShippingColumn: true/false, controls whether the managecart
//	and checkout pages display shipping cost column.
// * DisplayShippingRow: true/false, controls whether the managecart
//	and checkout pages display shipping cost total row.
// * DisplayTaxRow: true/false, controls whether the managecart		
//	and checkout pages display tax cost total row.						
// * TaxRate: number, your area's current tax rate, ie: if your tax	
//	rate was 7.5%, you would set TaxRate = 0.075							
// * TaxByRegion: true/false, when set to true, the user is prompted
//	with TaxablePrompt to determine if they should be charged tax.	
//	In the USA, this is useful to charge tax to those people who live
//	in a particular state, but no one else.
// * TaxPrompt: string, popup message if user has not selected either
//	taxable or nontaxable when TaxByRegion is set to true.
// * TaxablePrompt: string, the message the user is prompted with to
//	select if they are taxable.  If TaxByRegion is set to false, this
//	has no effect. Example: 'Arizona Residents'							
// * NonTaxablePrompt: string, same as above, but the choice for non-
//	taxable people.  Example: 'Other States'								
// * MinimumOrder: number, the minium dollar amount that must be		
//	purchased before a user is allowed to checkout.  Set to 0.00
//	to disable.																		
// * MinimumOrderPrompt: string, Message to prompt users with when	
//	they have not met the minimum order amount.							
//
// Payment Processor Options:
// ==========================
// * PaymentProcessor: string, the two digit payment processor code	
//	for support payment processor gateways.  Setting this field to	
//	anything other than an empty string will override your OutputItem
//	settings -- so please be careful when receiving any form data.	
//	Support payment processor gateways are:
//	 * Authorize.net (an)
//	 * Worldpay		(wp)
//	 * LinkPoint	  (lp)
//
// Options For Programmers:														
// ========================														
// * OutputItem<..>: string, the name of the pair value passed at
//	checkouttime.  Change these only if you are connecting to a CGI
//	script and need other field names, or are using a secure service
//	that requires specific field names.										
// * AppendItemNumToOutput: true/false, if set to true, the number of
//	each ordered item will be appended to the output string.  For	
//	example if OutputItemId is 'ID_' and this is set to true, the	
//	output field name will be 'ID_1', 'ID_2' ... for each item.		
// * HiddenFieldsToCheckout: true/false, if set to true, hidden fields
//	for the cart items will be passed TO the checkout page, from the
//	ManageCart page.  This is set to true for CGI/PHP/Script based	
//	checkout pages, but should be left false if you are using an
//	HTML/Javascript Checkout Page. Hidden fields will ALWAYS be		
//	passed FROM the checkout page to the Checkout CGI/PHP/ASP/Script
//---------------------------------------------------------------------

//Options for Everyone:
MonetarySymbol		  = '£';	//	pound symbol
DisplayNotice			 = true;	//	'added to cart' popup
DisplayShippingColumn = true;	//	How to show shipping - per item...
DisplayShippingRow	 = true;	//	...or per order
DisplayTaxRow			 = false;	//	total tax on order. Probably best set to 'false' if TaxRate is 0!
TaxRate					 = 0.00;	//	tax to add on. VAT would be 0.175
MinimumOrder			 = 1.00;	//	don't allow checkout below this amount
MinimumOrderPrompt	 = 'Your order is below our minimum order, please order more before checking out.';

//Options for sites charging different taxes to (non-)residents, e.g. in Arizona
TaxByRegion			  = false;
TaxPrompt				 = 'For tax purposes, please select if you are an Arizona resident before continuing';
TaxablePrompt			 = 'Arizona Residents';
NonTaxablePrompt		 = 'Other States';

//Payment Processor Options:
PaymentProcessor		 = 'pp';	//		 *	Authorize.net (an)	 * Worldpay (wp)	 * LinkPoint (lp)	 * PayPal (pp)
YourBusiness			 = 'wightleathercraft@hotmail.com';	//	where to send the PayPal payments

//Options for Programmers:
OutputItemId		 = 'ID_';
OutputItemQuantity	 = 'QUANTITY_';
OutputItemPrice		 = 'PRICE_';
OutputItemName		 = 'NAME_';
OutputItemShipping	 = 'SHIPPING_';
OutputItemAddtlInfo	 = 'ADDTLINFO_';
OutputOrderSubtotal	 = 'SUBTOTAL';
OutputOrderShipping	 = 'SHIPPING';
OutputOrderTax		 = 'TAX';
OutputOrderTotal	 = 'TOTAL';
AppendItemNumToOutput = true;
HiddenFieldsToCheckout = true;



//=====================================================================||
//---------------------------------------------------------------------||
//	 YOU DO NOT NEED TO MAKE ANY MODIFICATIONS BELOW THIS LINE		  ||
//---------------------------------------------------------------------||
//=====================================================================||


//	indexes to 'fields' array
iID_NUM = 0;
iQUANTITY = 1;
iPRICE = 2;
iNAME = 3;
iSHIPPING = 4;	//	for first item
iADDITIONALSHIPPING = 5;	//	for other items on that line
iMAXSHIPPING = 6;	//	for that line
iLINESHIPPING = 8;	//	holds total shipping cost for line
iADDITIONALINFO = 7;



//---------------------------------------------------------------------||
//							 Language Strings										 ||
//							------------------										||
// These strings will not be used unless you have not included a		 ||
// language pack already.  You should NOT modify these, but instead	 ||
// modify the strings in language-**.js where ** is the language pack  ||
// you are using.																		||
//---------------------------------------------------------------------||

if ( !document.bLanguageDefined || !bLanguageDefined ) {
	strSorry  = "I'm Sorry, your cart is full, please proceed to checkout.";
	strAdded  = " added to your shopping cart.";
	strRemove = "Click 'Ok' to remove this product from your shopping cart.";
	strILabel = "Product Id";
	strDLabel = "Product Name/Description";
	strQLabel = "Quantity";
	strPLabel = "Price";
	strSLabel = "Shipping";
	strRLabel = "Remove From Cart";
	strRButton= "Remove";
	strSUB	 = "SUBTOTAL";
	strSHIP	 = "SHIPPING";
	strTAX	 = "TAX";
	strTOT	 = "TOTAL";
	strErrQty = "Invalid Quantity.";
	strNewQty = 'Please enter new quantity:';
	bLanguageDefined = true;
}



//---------------------------------------------------------------------||
// FUNCTION:	 CKquantity															||
// PARAMETERS:  Quantity to														  ||
// RETURNS:	  Quantity as a number, and possible alert					||
// PURPOSE:	  Make sure quantity is represented as a number			 ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
	var strNewQuantity = "";

	for ( i = 0; i < checkString.length; i++ ) {
		ch = checkString.substring(i, i+1);
		if ( (ch >= "0" && ch <= "9") || (ch == '.') )
			strNewQuantity += ch;
	}

	if ( strNewQuantity.length < 1 )
		strNewQuantity = "1";

	return(strNewQuantity);
}



//---------------------------------------------------------------------||
// FUNCTION:	 AddToCart															 ||
// PARAMETERS:  Form Object														  ||
// RETURNS:	  Cookie to user's browser, with prompt						||
// PURPOSE:	  Adds a product to the user's shopping cart				 ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {
	var iNumberOrdered = 0;
	var bAlreadyInCart = false;
	var notice = "";
	iNumberOrdered = GetCookie("NumberOrdered");

	if ( iNumberOrdered == null )
		iNumberOrdered = 0;

	if ( thisForm.ID_NUM == null )
		strID_NUM	 = "";
	else
		strID_NUM	 = thisForm.ID_NUM.value;

	if ( thisForm.QUANTITY == null )
		strQUANTITY  = "1";
	else
		strQUANTITY  = thisForm.QUANTITY.value;

	if ( thisForm.PRICE == null )
		strPRICE	  = "0.00";
	else
		strPRICE	  = thisForm.PRICE.value;

	if ( thisForm.NAME == null )
		strNAME		 = "";
	else
		strNAME		 = thisForm.NAME.value;

	if ( thisForm.SHIPPING == null )
		strSHIPPING  = "0.00";
	else
		strSHIPPING  = thisForm.SHIPPING.value;

	if ( thisForm.ADDITIONALSHIPPING == null )
		strADDITIONALSHIPPING  = strSHIPPING;
	else
		strADDITIONALSHIPPING  = thisForm.ADDITIONALSHIPPING.value;

	if ( thisForm.MAXSHIPPING == null )
		strMAXSHIPPING  = "0.00";
	else
		strMAXSHIPPING  = thisForm.MAXSHIPPING.value;

	if ( thisForm.ADDITIONALINFO == null ) {
		strADDTLINFO = "";
	} else {
		strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
	}
	if ( thisForm.ADDITIONALINFO2 != null ) {
		strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
	}
	if ( thisForm.ADDITIONALINFO3 != null ) {
		strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
	}
	if ( thisForm.ADDITIONALINFO4 != null ) {
		strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
	}
	if ( thisForm.ADDITIONALTEXT != null ) {
		strADDTLINFO += "; " + thisForm.ADDITIONALTEXT.value;
	}
	if ( thisForm.ADDITIONALTEXT2 != null ) {
		strADDTLINFO += "; " + thisForm.ADDITIONALTEXT2.value;
	}
	if ( thisForm.ADDITIONALTEXT3 != null ) {
		strADDTLINFO += "; " + thisForm.ADDITIONALTEXT3.value;
	}
	if ( thisForm.ADDITIONALTEXT4 != null ) {
		strADDTLINFO += "; " + thisForm.ADDITIONALTEXT4.value;
	}

	//Is this product already in the cart?  If so, increment quantity instead of adding another.
	for ( i = 1; i <= iNumberOrdered; i++ ) {
		NewOrder = "Order." + i;
		database = "";
		database = GetCookie(NewOrder);

		fields = explodeDatabase(database);

		if (
			fields[iID_NUM] == strID_NUM &&
			fields[iPRICE] == strPRICE &&
			fields[iNAME] == strNAME &&
			fields[iADDITIONALINFO] == strADDTLINFO
		) {
			bAlreadyInCart = true;
			dbUpdatedOrder = strID_NUM	 + "|" +
				(parseInt(strQUANTITY)+parseInt(fields[iQUANTITY]))  + "|" +
				strPRICE	  + "|" +
				strNAME		+ "|" +
				strSHIPPING  + "|" +
				strADDITIONALSHIPPING  + "|" +
				strMAXSHIPPING  + "|" +
				strADDTLINFO;
			strNewOrder = "Order." + i;
			DeleteCookie(strNewOrder, "/");
			SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
			notice = strQUANTITY + "x " + strNAME + strAdded;
			break;
		}
	}


	if ( !bAlreadyInCart ) {
		iNumberOrdered++;

		if ( iNumberOrdered > 12 )
			alert( strSorry );
		else {
			dbUpdatedOrder =
				strID_NUM + "|" +
				strQUANTITY + "|" +
				strPRICE + "|" +
				strNAME + "|" +
				strSHIPPING  + "|" +
				strADDITIONALSHIPPING  + "|" +
				strMAXSHIPPING  + "|" +
				strADDTLINFO;

			strNewOrder = "Order." + iNumberOrdered;
			SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
			SetCookie("NumberOrdered", iNumberOrdered, null, "/");
			notice = strQUANTITY + "x " + strNAME + strAdded;
		}
	}

	if ( DisplayNotice )
		alert(notice);
	
	if (window.drawBasket) drawBasket();	
}



//---------------------------------------------------------------------||
// FUNCTION:	 getCookieVal														 ||
// PARAMETERS:  offset																 ||
// RETURNS:	  URL unescaped Cookie Value									  ||
// PURPOSE:	  Get a specific value from a cookie							||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);

	if ( endstr == -1 )
		endstr = document.cookie.length;
	return(unescape(document.cookie.substring(offset, endstr)));
}



//---------------------------------------------------------------------||
// FUNCTION:	 FixCookieDate														||
// PARAMETERS:  date																	||
// RETURNS:	  date																	||
// PURPOSE:	  Fixes cookie date, stores back in date					  ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
	var base = new Date(0);
	var skew = base.getTime();

	date.setTime (date.getTime() - skew);
}



//---------------------------------------------------------------------||
// FUNCTION:	 GetCookie															 ||
// PARAMETERS:  Name																	||
// RETURNS:	  Value in Cookie													 ||
// PURPOSE:	  Retrieves cookie from users browser						  ||
//---------------------------------------------------------------------||
function GetCookie (name) {
	var arg = name + "=";
	//alert("name "+ name);
	var alen = arg.length;
	//alert("alen "+ alen);
	
	//alert("cookie "+ document.cookie);
	var clen = document.cookie.length;
	//alert("clen "+ clen);
	var i = 0;

	while ( i < clen ) {
		var j = i + alen;
		if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
		i = document.cookie.indexOf(" ", i) + 1;
		if ( i == 0 ) break;
	}

	return(null);
}



//---------------------------------------------------------------------||
// FUNCTION:	 SetCookie															 ||
// PARAMETERS:  name, value, expiration date, path, domain, security	||
// RETURNS:	  Null																	||
// PURPOSE:	  Stores a cookie in the users browser						 ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
	var cookie_string =
		name + "=" + escape (value)
		+ ((expires) ? "; expires=" + expires.toGMTString() : "")
		+ ((path) ? "; path=" + path : "")
		+ ((domain) ? "; domain=" + domain : "")
		+ ((secure) ? "; secure" : "");
	//alert(cookie_string);
	document.cookie = cookie_string;
}



//---------------------------------------------------------------------||
// FUNCTION:	 DeleteCookie														 ||
// PARAMETERS:  Cookie name, path, domain										||
// RETURNS:	  null																	||
// PURPOSE:	  Removes a cookie from users browser.						 ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
	if ( GetCookie(name) ) {
		document.cookie = name + "=" +
								((path) ? "; path=" + path : "") +
								((domain) ? "; domain=" + domain : "") +
								"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}



//---------------------------------------------------------------------||
// FUNCTION:	 MoneyFormat														  ||
// PARAMETERS:  Number to be formatted											||
// RETURNS:	  Formatted Number													||
// PURPOSE:	  Reformats Dollar Amount to #.## format					  ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
	var dollars = Math.floor(input);
	var tmp = new String(input);

	for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
		if ( tmp.charAt(decimalAt)=="." )
			break;
	}

	var cents  = "" + Math.round(input * 100);
	cents = cents.substring(cents.length-2, cents.length)
			  dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

	if ( cents == "0" )
		cents = "00";

	return(dollars + "." + cents);
}



//---------------------------------------------------------------------||
// FUNCTION:	 RemoveFromCart													  ||
// PARAMETERS:  Order Number to Remove											||
// RETURNS:	  Null																	||
// PURPOSE:	  Removes an item from a users shopping cart				 ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) {
	if ( confirm( strRemove ) ) {
		NumberOrdered = GetCookie("NumberOrdered");
		for ( i=RemOrder; i < NumberOrdered; i++ ) {
			NewOrder1 = "Order." + (i+1);
			NewOrder2 = "Order." + (i);
			database = GetCookie(NewOrder1);
			SetCookie (NewOrder2, database, null, "/");
		}
		NewOrder = "Order." + NumberOrdered;
		SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
		DeleteCookie(NewOrder, "/");
		location.href=location.href;
	}
}



//---------------------------------------------------------------------||
// FUNCTION:	 ChangeQuantity													  ||
// PARAMETERS:  Order Number to Change Quantity								||
// RETURNS:	  Null																	||
// PURPOSE:	  Changes quantity of an item in the shopping cart		 ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderItem,NewQuantity) {
	if ( isNaN(NewQuantity) ) {
		alert( strErrQty );
	} else {
		NewOrder = "Order." + OrderItem;
		database = "";
		database = GetCookie(NewOrder);

		fields = explodeDatabase(database);

		dbUpdatedOrder =
			fields[iID_NUM] + "|" +
			NewQuantity + "|" +
			fields[iPRICE] + "|" +
			fields[iNAME] + "|" +
			fields[iSHIPPING] + "|" +
			fields[iADDITIONALSHIPPING] + "|" +
			fields[iMAXSHIPPING] + "|" +
			fields[iADDITIONALINFO];
		strNewOrder = "Order." + OrderItem;
		DeleteCookie(strNewOrder, "/");
		SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
		location.href=location.href;
	}
}



//---------------------------------------------------------------------||
// FUNCTION:	 GetFromCart														  ||
// PARAMETERS:  Null																	||
// RETURNS:	  Product Table Written to Document							 ||
// PURPOSE:	  Draws current cart product table on HTML page			 ||
//				  **DEPRECATED FUNCTION, USE ManageCart or Checkout**	 ||
//---------------------------------------------------------------------||
function GetFromCart( fShipping ) {
	ManageCart( );
}



//---------------------------------------------------------------------||
// FUNCTION:	 RadioChecked														 ||
// PARAMETERS:  Radio button to check											 ||
// RETURNS:	  True if a radio has been checked							  ||
// PURPOSE:	  Form fillin validation											||
//---------------------------------------------------------------------||
function RadioChecked( radiobutton ) {
	var bChecked = false;
	var rlen = radiobutton.length;
	for ( i=0; i < rlen; i++ ) {
		if ( radiobutton[i].checked )
			bChecked = true;
	}	
	return bChecked;
}



//---------------------------------------------------------------------||
// FUNCTION:	 QueryString														  ||
// PARAMETERS:  Key to read														  ||
// RETURNS:	  value of key														 ||
// PURPOSE:	  Read data passed in via GET mode							  ||
//---------------------------------------------------------------------||
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++) {
		if (QueryString.keys[i]==key) {
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}



//---------------------------------------------------------------------||
// FUNCTION:	 QueryString_Parse												  ||
// PARAMETERS:  (URL string)														 ||
// RETURNS:	  null																	||
// PURPOSE:	  Parses query string data, must be called before Q.S.	||
//---------------------------------------------------------------------||
function QueryString_Parse() {
	var query = window.location.search.substring(1);
	var pairs = query.split("&"); for (var i=0;i<pairs.length;i++) {
		var pos = pairs[i].indexOf('=');
		if (pos >= 0) {
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;
		}
	}
}



//---------------------------------------------------------------------||
// FUNCTION:	 ManageCart															||
// PARAMETERS:  Null																	||
// RETURNS:	  Product Table Written to Document							 ||
// PURPOSE:	  Draws current cart product table on HTML page			 ||
//---------------------------------------------------------------------||
function ManageCart( ) {
	var iNumberOrdered = 0;	 //Number of products ordered
	var fTotal			 = 0;	 //Total cost of order
	var fTax			  = 0;	 //Tax amount
	var fShipping		 = 0;	 //Shipping amount
	var strTotal		 = "";	//Total cost formatted as money
	var strTax			 = "";	//Total tax formatted as money
	var strShipping	 = "";	//Total shipping formatted as money
	var strOutput		 = "";	//String to be written to page
	var bDisplay		 = true; //Whether to write string to the page (here for programmers)

	iNumberOrdered = GetCookie("NumberOrdered");
	if ( iNumberOrdered == null )
		iNumberOrdered = 0;

	if ( bDisplay )
		strOutput = "<TABLE CLASS=\"nopcart\" border=\"0\"><tr>" +
			"<td class=\"nopheader\"><B>"+strILabel+"</B></td>" +
			"<td class=\"nopheader\"><B>"+strDLabel+"</B></td>" +
			"<td class=\"nopheader\"><B>"+strQLabel+"</B></td>" +
			"<td class=\"nopheader prices-column\"><B>"+strPLabel+"</B></td>" +
			(DisplayShippingColumn?"<td class=\"nopheader prices-column\"><B>"+strSLabel+"</B></td>":"") +
			"<td class=\"nopheader\"><B>"+strRLabel+"</B></td></TR>";

	if ( iNumberOrdered == 0 ) {
		strOutput += "<tr><TD COLSPAN=6 CLASS=\"nopentry\"><CENTER><BR><B>Your cart is empty</B><BR><BR></CENTER></td></TR>";
	}

	for ( i = 1; i <= iNumberOrdered; i++ ) {
		NewOrder = "Order." + i;
		database = "";
		database = GetCookie(NewOrder);

		fields = explodeDatabase(database);

		fTotal	  += (parseInt(fields[iQUANTITY]) * parseFloat(fields[iPRICE]) );

		var tmp = 0;
		if (parseInt(fields[iQUANTITY]) > 0) {	//	if qty > 0
			tmp = 1 * parseFloat(fields[iSHIPPING]) + (parseFloat(fields[iQUANTITY]) - 1) * parseFloat(fields[iADDITIONALSHIPPING]);
		}
		if (parseFloat(fields[iMAXSHIPPING]) > 0) {	//	if max shipping is defined
			tmp = Math.min(parseFloat(tmp), parseFloat(fields[iMAXSHIPPING]));
		}
		fields[iLINESHIPPING] = parseFloat(tmp);
		fShipping  += parseFloat(tmp);

		fTax		  = (fTotal * TaxRate);
		strTotal	 = moneyFormat(fTotal);
		strTax		 = moneyFormat(fTax);
		strShipping = moneyFormat(fShipping);

		if ( bDisplay ) {
			strOutput += "<tr><td class=\"nopentry\">"  + fields[iID_NUM] + "</td>";

			if ( fields[iADDITIONALINFO] == "" )
				strOutput += "<td class=\"nopentry\">"  + fields[iNAME] + "</td>";
			else {
				if (fields[iADDITIONALINFO].indexOf("; ") == 0) {
					fields[iADDITIONALINFO] = fields[iADDITIONALINFO].replace('; ', '');
				}
				strOutput += "<td class=\"nopentry\">"  + fields[iNAME] + "<br /><em>"+ fields[iADDITIONALINFO] + "</em></td>";
			}

			strOutput += "<td class=\"nopentry\"><INPUT TYPE=\"TEXT\" NAME=\"Q\" SIZE=\"2\" VALUE=\"" + fields[iQUANTITY] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></td>";
			strOutput += "<td class=\"nopentry prices-column\">"+ MonetarySymbol + moneyFormat(fields[iPRICE]) + "/ea</td>";

			if ( DisplayShippingColumn ) {
				if ( parseFloat(fields[iLINESHIPPING]) > 0 )
					strOutput += "<td class=\"nopentry prices-column\">"+ MonetarySymbol + moneyFormat(fields[iLINESHIPPING]) + "</td>";
				else
					strOutput += "<td class=\"nopentry prices-column\">N/A</td>";
			}

			strOutput += "<td class=\"nopentry buttons-column\"><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" class=\"nopbutton\"></td></TR>";
		}

		if ( AppendItemNumToOutput ) {
			strFooter = i;
		} else {
			strFooter = "";
		}
		if ( HiddenFieldsToCheckout ) {
			strOutput += "<input type=hidden name=\"" + OutputItemId		  + strFooter + "\" value=\"" + fields[iID_NUM] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[iQUANTITY] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemPrice	  + strFooter + "\" value=\"" + fields[iPRICE] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemName		+ strFooter + "\" value=\"" + fields[iNAME] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[iLINESHIPPING] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[iADDITIONALINFO] + "\">";
		}

	}

	if ( bDisplay ) {
		strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strSUB+"</B></td>";
		strOutput += "<td class=\"noptotal prices-column subtotal\"><B>" + MonetarySymbol + strTotal + "</B></td>";
		strOutput += "<td class=\"noptotal\" colspan='2'>&nbsp;</td>";
		strOutput += "</TR>";

		if ( DisplayShippingRow ) {
			strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strSHIP+"</B></td>";
			strOutput += "<td class=\"noptotal prices-column\"><B>" + MonetarySymbol + strShipping + "</B></td>";
			strOutput += "<td class=\"noptotal\" colspan='2'>&nbsp;</td>";
			strOutput += "</TR>";
		}

		if ( DisplayTaxRow || TaxByRegion ) {
			if ( TaxByRegion ) {
				strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strTAX+"</B></td>";
				strOutput += "<td class=\"noptotal prices-column\"><B>";
				strOutput += "<input type=radio name=\""+OutputOrderTax+"\" value=\"" + strTax + "\">";
				strOutput += TaxablePrompt + ": " + MonetarySymbol + strTax;
				strOutput += "<BR><input type=radio name=\""+OutputOrderTax+"\" value=\"0.00\">";
				strOutput += NonTaxablePrompt + ": " + MonetarySymbol + "0.00";
				strOutput += "</B></td>";
				strOutput += "<td class=\"noptotal\" colspan='2'>&nbsp;</td>";
				strOutput += "</TR>";
			} else {
				strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strTAX+"</B></td>";
				strOutput += "<td class=\"noptotal prices-column\"><B>" + MonetarySymbol + strTax + "</B></td>";
				strOutput += "<td class=\"noptotal\" colspan='2'>&nbsp;</td>";
				strOutput += "</TR>";
			}
		}

		if ( !TaxByRegion ) {
			strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strTOT+"</B></td>";
			strOutput += "<td class=\"noptotal prices-column total\"><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</B></td>";
			strOutput += "<td class=\"noptotal buttons-column\" colspan='2'></td>";
			strOutput += "</TR>";
		}
		strOutput += "</TABLE>";

		if ( HiddenFieldsToCheckout ) {
			strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
			strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
			strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"		value=\""+ MonetarySymbol + strTax + "\">";
			strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"	 value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">";
		}
	}
	g_TotalCost = (fTotal + fShipping + fTax);

	document.write(strOutput);
	document.close();
}



//---------------------------------------------------------------------||
// FUNCTION:	 ValidateCart														 ||
// PARAMETERS:  Form to validate													||
// RETURNS:	  true/false															||
// PURPOSE:	  Validates the managecart form								  ||
//---------------------------------------------------------------------||
var g_TotalCost = 0;
function ValidateCart( theForm ) {
	if ( TaxByRegion ) {
		if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
			alert( TaxPrompt );
			return false;
		}
	}

	if ( MinimumOrder >= 0.01 ) {
		if ( g_TotalCost < MinimumOrder ) {
			alert( MinimumOrderPrompt );
			return false;
		}
	}

	return true;
}



//---------------------------------------------------------------------||
// FUNCTION:	 CheckoutCart														 ||
// PARAMETERS:  Null																	||
// RETURNS:	  Product Table Written to Document							 ||
// PURPOSE:	  Draws current cart product table on HTML page for		||
//				  checkout.															 ||
//---------------------------------------------------------------------||
function CheckoutCart( ) {
	var iNumberOrdered = 0;	 //Number of products ordered
	var fTotal			 = 0;	 //Total cost of order
	var fTax			  = 0;	 //Tax amount
	var fShipping		 = 0;	 //Shipping amount
	var strTotal		 = "";	//Total cost formatted as money
	var strTax			 = "";	//Total tax formatted as money
	var strShipping	 = "";	//Total shipping formatted as money
	var strOutput		 = "";	//String to be written to page
	var bDisplay		 = true; //Whether to write string to the page (here for programmers)
	var strPP			 = "";	//Payment Processor Description Field

	iNumberOrdered = GetCookie("NumberOrdered");
	if ( iNumberOrdered == null )
		iNumberOrdered = 0;

	if ( TaxByRegion ) {
		QueryString_Parse();
		fTax = parseFloat( QueryString( OutputOrderTax ) );
		strTax = moneyFormat(fTax);
	}

	if ( bDisplay )
		strOutput = "<TABLE CLASS=\"nopcart\"><tr>" +
			"<td class=\"nopheader\"><B>"+strILabel+"</B></td>" +
			"<td class=\"nopheader\"><B>"+strDLabel+"</B></td>" +
			"<td class=\"nopheader\"><B>"+strQLabel+"</B></td>" +
			"<td class=\"nopheader\"><B>"+strPLabel+"</B></td>" +
			(DisplayShippingColumn?"<td class=\"nopheader\"><B>"+strSLabel+"</B></td>":"") +
			"</TR>";

	for ( i = 1; i <= iNumberOrdered; i++ ) {
		NewOrder = "Order." + i;
		database = "";
		database = GetCookie(NewOrder);

		fields = explodeDatabase(database);

		fTotal	  += (parseInt(fields[iQUANTITY]) * parseFloat(fields[iPRICE]) );

		var tmp = 0;
		if (parseInt(fields[iQUANTITY]) > 0) {	//	if qty > 0
			tmp = 1 * parseFloat(fields[iSHIPPING]) + (parseFloat(fields[iQUANTITY]) - 1) * parseFloat(fields[iADDITIONALSHIPPING]);
		}
		if (parseFloat(fields[iMAXSHIPPING]) > 0) {	//	if max shipping is defined
			tmp = Math.min(parseFloat(tmp), parseFloat(fields[iMAXSHIPPING]));
		}
		fields[iLINESHIPPING] = parseFloat(tmp);
		fShipping  += parseFloat(tmp);

		if ( !TaxByRegion ) fTax = (fTotal * TaxRate);
		strTotal	 = moneyFormat(fTotal);
		if ( !TaxByRegion ) strTax = moneyFormat(fTax);
		strShipping = moneyFormat(fShipping);

		if ( bDisplay ) {
			strOutput += "<tr><td class=\"nopentry\">"  + fields[iID_NUM] + "</td>";

			if ( fields[iADDITIONALINFO] == "" )
				strOutput += "<td class=\"nopentry\">"  + fields[iNAME] + "</td>";
			else {
				if (fields[iADDITIONALINFO].indexOf("; ") == 0) {
					fields[iADDITIONALINFO] = fields[iADDITIONALINFO].replace('; ', '');
				}
				strOutput += "<td class=\"nopentry\">"  + fields[iNAME] + "<br /><em>"+ fields[iADDITIONALINFO] + "</em></td>";
			}

			strOutput += "<td class=\"nopentry\">" + fields[iQUANTITY] + "</td>";
			strOutput += "<td class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[iPRICE]) + "/ea</td>";

			if ( DisplayShippingColumn ) {
				if ( parseFloat(fields[iLINESHIPPING]) > 0 ) {
					strOutput += "<td class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[iLINESHIPPING]) + "</td>";
				} else {
					strOutput += "<td class=\"nopentry\">N/A</td>";
				}
			} else {
				strOutput += "<td class=\"nopentry\"></td>";
			}

			strOutput += "</TR>";
		}

		if ( AppendItemNumToOutput ) {
			strFooter = i;
		} else {
			strFooter = "";
		}
		if ( PaymentProcessor != '' ) {
			//Process description field for payment processors instead of hidden values.
			//Format Description of product as:
			// ID, Name, Qty X
			strPP += fields[iID_NUM] + ", " + fields[iNAME];
			if ( fields[iADDITIONALINFO] != "" )
				strPP += " - " + fields[iADDITIONALINFO];
			strPP += ", Qty. " + fields[iQUANTITY] + "\n";
		} else {
			strOutput += "<input type=hidden name=\"" + OutputItemId		  + strFooter + "\" value=\"" + fields[iID_NUM] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[iQUANTITY] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemPrice	  + strFooter + "\" value=\"" + fields[iPRICE] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemName		+ strFooter + "\" value=\"" + fields[iNAME] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[iLINESHIPPING] + "\">";
			strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[iADDITIONALINFO] + "\">";
		}

	}

	if ( bDisplay ) {
		strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strSUB+"</B></td>";
		strOutput += "<td class=\"noptotal prices-column subtotal\"><B>" + MonetarySymbol + strTotal + "</B></td>";
		strOutput += "<td>&nbsp;</td>";
		strOutput += "</TR>";

		if ( DisplayShippingRow ) {
			strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strSHIP+"</B></td>";
			strOutput += "<td class=\"noptotal prices-column\"><B>" + MonetarySymbol + strShipping + "</B></td>";
			strOutput += "<td>&nbsp;</td>";
			strOutput += "</TR>";
		}

		if ( DisplayTaxRow || TaxByRegion ) {
			strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strTAX+"</B></td>";
			strOutput += "<td class=\"noptotal prices-column\"><B>" + MonetarySymbol + strTax + "</B></td>";
			strOutput += "<td>&nbsp;</td>";
			strOutput += "</TR>";
		}

		strOutput += "<tr><td class=\"noptotal\" COLSPAN=3><B>"+strTOT+"</B></td>";
		strOutput += "<td class=\"noptotal prices-column total\"><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</B></td>";
		strOutput += "<td>&nbsp;</td>";
		strOutput += "</TR>";

		strOutput += "</TABLE>";


		if ( PaymentProcessor == 'an') {
			//Process this for Authorize.net WebConnect
			strOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">";
			strOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">";
			strOutput += "<input type=hidden name=\"x_Description\" value=\""+ strPP + "\">";
			strOutput += "<input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
		} else if ( PaymentProcessor == 'wp') {
			//Process this for WorldPay
			strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
			strOutput += "<input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
		} else if ( PaymentProcessor == 'lp') {
			//Process this for LinkPoint
			strOutput += "<input type=hidden name=\"mode\" value=\"fullpay\">";
			strOutput += "<input type=hidden name=\"chargetotal\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
			strOutput += "<input type=hidden name=\"tax\" value=\""+ MonetarySymbol + strTax + "\">";
			strOutput += "<input type=hidden name=\"subtotal\" value=\""+ MonetarySymbol + strTotal + "\">";
			strOutput += "<input type=hidden name=\"shipping\" value=\""+ MonetarySymbol + strShipping + "\">";
			strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
		} else if ( PaymentProcessor == 'pp') {
			//Process this for PayPal
			if (window.InvoiceNumber) {
				var InvoiceNumber = window.InvoiceNumber;
			} else {
				var currentTime = new Date()
				var InvoiceNumber = currentTime.getFullYear() +""+ (currentTime.getMonth()+1) +""+ currentTime.getDate();
			}
			if (document.getElementById('nopcart_checkout_form')) document.getElementById('nopcart_checkout_form').action = 'https://www.paypal.com/cgi-bin/webscr';
			strOutput += "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\">";
			strOutput += "<input type=\"hidden\" name=\"business\" value=\""+ YourBusiness +"\">";
			strOutput += "<input type=\"hidden\" name=\"currency_code\" value=\"GBP\">";
			strOutput += "<input type=\"hidden\" name=\"item_name\" value=\"Order #"+ InvoiceNumber +" with WightLeatherCraft.co.uk\">";
			strOutput += "<input type=\"hidden\" name=\"amount\" value=\""+ moneyFormat((fTotal)) + "\">";
			strOutput += "<input type=\"hidden\" name=\"shipping\" value=\""+ moneyFormat((fShipping)) + "\">";
			strOutput += "<input type=\"hidden\" name=\"tax\" value=\""+ moneyFormat((fTax)) + "\">";
			strOutput += "<input type=\"hidden\" name=\"invoice\" value=\""+ InvoiceNumber +"\">";
		} else {
			strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
			strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
			strOutput += "<input type=hidden name=\""+OutputOrderTax+"\" value=\""+ MonetarySymbol + strTax + "\">";
			strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\" value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">";
		}
	}

	document.write(strOutput);
	document.close();
}



function explodeDatabase(database) {
	Token0 = database.indexOf("|", 0);
	Token1 = database.indexOf("|", Token0+1);
	Token2 = database.indexOf("|", Token1+1);
	Token3 = database.indexOf("|", Token2+1);
	Token4 = database.indexOf("|", Token3+1);
	Token5 = database.indexOf("|", Token4+1);
	Token6 = database.indexOf("|", Token5+1);

	fields = new Array;
	fields[iID_NUM] = database.substring( 0, Token0 );					  // Product ID
	fields[iQUANTITY] = database.substring( Token0+1, Token1 );			 // Quantity
	fields[iPRICE] = database.substring( Token1+1, Token2 );			 // Price
	fields[iNAME] = database.substring( Token2+1, Token3 );			 // Product Name/Description
	fields[iSHIPPING] = database.substring( Token3+1, Token4 );			 // Shipping Cost for first item on line
	fields[iADDITIONALSHIPPING] = database.substring( Token4+1, Token5 );			 // Shipping Cost for other items on line
	fields[iMAXSHIPPING] = database.substring( Token5+1, Token6 );			 // max Shipping Cost for items on line
	fields[iADDITIONALINFO] = database.substring( Token6+1, database.length ); //Additional Information

	return fields;
}

//======================================================================||
//		END NOP Design SmartPost Shopping Cart				||
//======================================================================||