//=====================================================================||
//       NOP Design JavaScript Shopping Cart Language Pack             ||
//                                                                     ||
//                      Language Strings                               ||
//                     ------------------                              ||
// Strings displayed to end users, in language specific encoding.      ||
// only modify these strings if you wish to change language specific   ||
// wording for your site.  If you add a new language, please send it   ||
// back to NOP Design (http://www.nopdesign.com/forum) so we can add   ||
// it to the distribution.                                             ||
//---------------------------------------------------------------------||
strSorry  = "I'm Sorry, your cart has reached the limit of 10 items.  Should you require more items for resale and want to become a certified retailer, please contact us on retail@couttsinc.biz \nThank you for your support.";
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";
strInsu   = "INSURANCE";
strTAX    = "TAX";
strTOT    = "TOTAL";
strErrQty = "Invalid Size.";
strNewQty = 'Please enter new quantity:';
iMaxOrder = 10;

Language = 'en';
bLanguageDefined = true;
//=====================================================================||
//               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        = 'R';
DisplayNotice         = false;
DisplayShippingColumn = false;
DisplayShippingRow    = true;
DisplayInsuranceRow    = true;
DisplayTaxRow         = false;
TaxRate               = 0;
TaxByRegion           = false;
//DisplayNotice         = true;
//DisplayShippingColumn = true;
//DisplayShippingRow    = true;
//DisplayTaxRow         = true;
//TaxRate               = 0.07;
//TaxByRegion           = true;
//TaxPrompt             = 'For tax purposes, please select if you are an Arizona resident before continuing';
//TaxablePrompt         = 'Arizona Residents';
//NonTaxablePrompt      = 'Other States';
MinimumOrder          = 0.00;
MinimumOrderPrompt    = 'Your order is below our minimum order, please order more before checking out.';

//Payment Processor Options:
PaymentProcessor      = '';

//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 = false;


//=====================================================================||
//---------------------------------------------------------------------||
//    YOU DO NOT NEED TO MAKE ANY MODIFICATIONS BELOW THIS LINE        ||
//---------------------------------------------------------------------||
//=====================================================================||


//---------------------------------------------------------------------||
//                      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 ( !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) {
function AddToCart(ct,thisid,thisprice,thissize,thisname,whichone) 
{
	if(thisname == "MyCopper")
	{	
		alert("MyCopper Bangles are only available for delivery in South Africa and for purchase in South African Rands.");
	}
	if(document.getElementById("sl"+thisid+whichone).selectedIndex)
		thect = document.getElementById("sl"+thisid+whichone).selectedIndex;
	else
		thect = -1;
	
	if(thect == 0)
	{
		alert("Please select a quantity.");
		document.getElementById("sl"+thisid).focus();
	}
	else
	{
		if(thect == -1)
		{
			theqty = document.getElementById("sl"+thisid).value;
			thect = 1;
		}	
		else
		{
			//theqty = document.getElementById("sl"+thisid).options[thect].value;
			theqty = document.getElementById("sl"+thisid+whichone).value;
		}	
			
	//alert(theqty);
	//alert(arMPrice[ct][thect]);
	//alert(arMPrice[ct][thect]);
	
	thisprice = arMPrice[ct][thect];
	thisshipping = arMShip[ct][thect];// shipping arr per product
	//alert(document.getElementById("sl"+thisid).selectedIndex);
	//window.location.href= "managecart.html";
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("46664NumberOrdered");
   iCurrency = GetCookie("46664Currency");
   
	if ( iNumberOrdered == null )
		iNumberOrdered = 0;
	if ( iCurrency == null )
		iCurrency = "R";
	strSHIPPING  = "0.00";
	strID_NUM = thisid;
	strPRICE  = thisprice;
	strSHIPPING  = thisshipping;
	strNAME   = thisname;
	strADDTLINFO  = "";
	strSIZE = thissize;
	strQty = theqty;
	
	
	//we always use the rand price here, 
	//we'll store it in cents
	//(paygate needs it in cents) &pound;
	
	//4 sept 08 - start storing all 4 currencies (in cents) in the cookie
   var ArrPrice = strPRICE.split(":"); 
   var ArrShipping = strSHIPPING.split(":"); 
   
   //alert(ArrPrice.length);

   for (var x=0;x<(ArrPrice.length);x++) 
   {
	  thisPrice = ArrPrice[x].replace("Price","");
	  thisPrice = thisPrice.replace(" ","");
	  thisPrice = thisPrice.replace("&#36;","");
	  thisPrice = thisPrice.replace("&pound;","");
	  thisPrice = thisPrice.replace("&euro;","");
	  thisPrice = thisPrice.replace("R","");
	  thisPrice = thisPrice.replace("#","");		  
	  thisPrice = thisPrice.replace(",","");
	  ArrPrice[x] = thisPrice; 

	  thisShip = ArrShipping[x].replace("Price","");
	  thisShip = thisShip.replace(" ","");
	  thisShip = thisShip.replace("&#36;","");
	  thisShip = thisShip.replace("&pound;","");
	  thisShip = thisShip.replace("&euro;","");		  
	  thisShip = thisShip.replace("R","");
	  thisShip = thisShip.replace("#","");
	  thisShip = thisShip.replace(",","");
	  ArrShipping[x] = thisShip;		  
   }
   
   
   thedollars 	= ArrPrice[0];
   theeuros 	= ArrPrice[1];//changed here
   thepounds 	= ArrPrice[2];
   therands 	= ArrPrice[3];
   thedollarsship 	= ArrShipping[0];
   theeurosship 	= ArrShipping[1];//changed here
   thepoundsship 	= ArrShipping[2];
   therandsship 	= ArrShipping[3];   
   //1750	233.3300	115.8900	156.2500
   thedollars 	= (Math.round(thedollars))*100;
   thepounds 	= (Math.round(thepounds))*100;
   theeuros 	= (Math.round(theeuros))*100;
   therands 	= (Math.round(therands))*100; 
	//alert(thedollars);
   thedollarsship 	= (Math.round(thedollarsship))*100;
   thepoundsship 	= (Math.round(thepoundsship))*100;
   theeurosship 	= (Math.round(theeurosship))*100;
   therandsship 	= (Math.round(therandsship))*100;
   //175000	23333.00	11589.00	15625.00
   //alert(ArrPrice[3]);
   
   //strPRICE 	= therands*100;
  //strPRICE = strPRICE*100;	//get price into cents
   strPRICE		= (therands) + "~" +(theeuros)+ "~" +(thepounds)+ "~"+(thedollars)	;
   //alert(strPRICE);
   strSHIPPING		= (therandsship) + "~" +(theeurosship)+ "~" +(thepoundsship)+ "~"+(thedollarsship)	;
	//alert(strPRICE);
	
	
   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "46664Order." + i;
      database = "";
      database = GetCookie(NewOrder);

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

	///////alert(thisname);
      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, Token5 );
      fields[6] = database.substring( Token5+1, database.length );

      if ( fields[0] == strID_NUM &&
           fields[2] == strPRICE  &&
           fields[3] == strNAME   &&
           fields[5] == strADDTLINFO
         ) {
         bAlreadyInCart = true;
         dbUpdatedOrder = strID_NUM    + "|" +
                          (parseInt(strSIZE)+parseInt(fields[1]))  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;
         strNewOrder = "46664Order." + i;
         //as of 21 aug we are adding every item as a cookie, no grouping like items together DeleteCookie(strNewOrder, "/");
         //as of 21 aug we are adding every item as a cookie, no grouping like items together SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         //notice = strSIZE + " " + strNAME + strAdded;
		 if(strSIZE >= 1){
	         notice = strSIZE + " " + strNAME + strAdded;
		 }
         break;
      }
   }

//as of 21 aug we are adding every item as a cookie, no grouping like items together
  // if ( !bAlreadyInCart ) {
   //if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > iMaxOrder )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strSIZE  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
						  strQty + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;

         strNewOrder = "46664Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("46664NumberOrdered", iNumberOrdered, null, "/");
		// if(strSIZE >= 1){
         	notice = strSIZE + " " + strNAME + strAdded;
		 //}
      }
   //}

   if ( DisplayNotice )
      alert(notice);
	  
	  
  }
}


//---------------------------------------------------------------------||
// 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 + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   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) {
   //document.cookie = "46664Order.1=thisisatest; expires=5" ;
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
					 //alert(getCookieVal("46664Currency"));
}


//---------------------------------------------------------------------||
// 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 displaymoneyFormat(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";
	  
	 //space for thousands
	dollars = "" + dollars;
	if(dollars.length >= 4){
		dollars = dollars.substring(0,(dollars.length-3)) + "," + dollars.substring((dollars.length-3),(dollars.length));
	}

   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("46664NumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "46664Order." + (i+1);
         NewOrder2 = "46664Order." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, null, "/");
      }
      NewOrder = "46664Order." + NumberOrdered;
      SetCookie ("46664NumberOrdered", 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 ChangeSize(OrderItem,NewSize) {
   if ( isNaN(NewSize) ) {
      NewOrder = "46664Order." + OrderItem;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );

      dbUpdatedOrder = fields[0] + "|" +
                       NewSize + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" +
                       fields[5];
      strNewOrder = "46664Order." + OrderItem;
      DeleteCookie(strNewOrder, "/");
	  SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
		//alert(NewQuantity);
      document.location.href=document.location.href;   
   } else {   
      alert( strErrQty );
   }
}


//---------------------------------------------------------------------||
// 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 iCurrency	  = "";
   //var MonetarySymbol = "R";
   var MonetarySymbol = "$";//Default to dollars
   var fTotal         = 0;    //Total cost of order
   var rTotal         = 0;    //Total cost of order in rands
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount
   var tShipping		= 0;
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var fQty				= 0;    //quantity
   //var strShipping    = "250";   //Total shipping formatted as money
   var strShipping    = "";   //shipping now storred in cookie - per product
   var strShippingCurrencyofChoice    = "0";   //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 strInsurance	  =	"";
   var rInsurance	  =	"";
   var isfirst = 0;
   var isMyCopper = 0;
		rShipping = "250";	  
	  strrTotal		= 0;

   iNumberOrdered = GetCookie("46664NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
	  
	  
	  

   var strCurrencyShipping    = "0";   //Total shipping in currency of coice
   //shipping:
   //Rand invoices 		R250 per 2 bangles
   //Dollar invoices  	$23 per two bangles
   //Euro Invoices  	€16 per two bangles
   //Pounds Invoice  	£9 per two bangles
   shipRand = 250;
   shipDollar = 23;
   shipEuro = 16;
   shipPounds = 9;
   iCurrency = GetCookie("46664Currency");
   if ( iCurrency == null )
   {
      iCurrency = "dollar";//default to dollars  
	  SetCookie("46664Currency", "dollar", null, "/");
   }
   
	if(iCurrency == "rand")
	{		
		MonetarySymbol = "R";	
		strShippingCurrencyofChoice = shipRand;
	}
	if(iCurrency == "euro")
	{		
		MonetarySymbol = "&euro;";	
		strShippingCurrencyofChoice = shipEuro;
	}
	if(iCurrency == "pound")
	{		
		MonetarySymbol = "&pound;";	
		strShippingCurrencyofChoice = shipPounds;
	}
	if(iCurrency == "dollar")
	{	
		MonetarySymbol = "$";	
		strShippingCurrencyofChoice = shipDollar;  
	}
	//work out 2 values for shipping	
	if(iNumberOrdered >= 0)
	{
		noofships = Math.round(iNumberOrdered/2);
		pershipcostinrands = strShipping*noofships;
		pershipcostincurrencyofchoice = strShippingCurrencyofChoice*noofships;
		//alert(pershipcostinrands);
		var rShipping = pershipcostinrands;
		var strShipping = pershipcostincurrencyofchoice;
	}




	  

   if ( bDisplay )
      strOutput = "<TABLE  width='473' border='0' cellpadding='0' cellspacing='0' class='tblretailersheading' ><TR height='39'><td width='15'>&nbsp;</td><td  align='left' class='whitetext'><img src='../images/cart/cart.gif'>&nbsp;&nbsp;<b>YOUR SHOPPING CART</b></td>" +
                  "<TD align='right' ></TD><td width='20'>&nbsp;</td>" +
		"</TR></table>";
		


strOutput +=  "<TABLE width='473' border='0' cellpadding='3' cellspacing='0' class='tblretailers'>";

strOutput += "<tr><td colspan='10' valign='top' style='padding:10px;'><div style='border-bottom:dotted 2px #D7D8DA;padding-bottom:5px'><table width='100%' cellspacing='0' cellpadding='0'><tr><td><span class='orangetext'>Change currency</span></td><td align='right'><a href='javascript:changeCurrency(\"rand\")'><img src=\"../images/cart/cur_zar.gif\" border=\"0\">R</a> <a href='javascript:changeCurrency(\"euro\")'><img src=\"../images/cart/cur_eu.gif\" border=\"0\">&euro;</a> <a href='javascript:changeCurrency(\"pound\")'><img src=\"../images/cart/cur_gbp.gif\" border=\"0\">&pound;</a> <a href='javascript:changeCurrency(\"dollar\")'><img src=\"../images/cart/cur_usd.gif\" border=\"0\">$</a></td></tr></table></div></td></tr>";

strOutput +=  "<tr height='23px' width=20>"+
		"<TD align='left' width='5'></TD>" +
		"<TD align='left'  width='62'>&nbsp;</TD>" +	
		"<TD align='left' width=100 class='orangecopymid'><b>ITEM</b></TD>" +
		"<TD align='left'  width=60 class='orangecopymid'><b>QTY</b></TD>" +
		"<TD align='left' colspan=2 width=100 class='orangecopymid'><b>SIZE</b></TD>" +
		"<TD align='right' colspan=2 class='orangecopymid' width=120><b>SHIPPING</b></TD>" + 
		"<TD align='right' class='orangecopymid' width=120><b>PRICE "+MonetarySymbol+"</b></TD>" + 
		"<TD align='left' width='20'>&nbsp;</TD>" +
		"<TD align='right'>&nbsp;</TD>"+
	       "</tr>";
  
  

   if ( iNumberOrdered == 0 ) 
   {
      strOutput += "<TR height='22px' ><TD COLSPAN=11><CENTER><BR>Your cart is empty<BR><BR></CENTER></TD></TR>";	  
   }
   for ( i = 1; i <= iNumberOrdered; i++ ) 
   {
	  therands 		= 0;
	  theeuros 		= 0;
	  thepounds 	= 0;
	  thedollars	= 0;
	NewOrder = "46664Order." + i;
	database = "";
	database = GetCookie(NewOrder);

	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[0] 	= database.substring( 0, Token0 );                 // Product ID
	fields[1] 	= database.substring( Token0+1, Token1 );          // Size
      
	//price array

	fields[2] 	= database.substring( Token1+1, Token2 );          // Price Array
	arrPrice 	= fields[2].split("~");
	therands 	= arrPrice[0];
	theeuros 	= arrPrice[1];
	thepounds 	= arrPrice[2];
	thedollars	= arrPrice[3];
	fields[3] 	= database.substring( Token2+1, Token3 );          // Product Name/Description
	fields[4] 	= database.substring( Token3+1, Token4 ); 			//Quantity
	fields[5] 	= database.substring( Token4+1, Token5 );          // SHipping Price Array

      
	  arrShip 		= fields[5].split("~");
	  therandsship 		= arrShip[0];
	  theeurosship 		= arrShip[1];
	  thepoundsship 	= arrShip[2];
	  thedollarsship	= arrShip[3];
	 
	  if( fields[3] == "MyCopper"){	 isMyCopper = 1;	}
   
	  //quantity always 1
	  thisQuant = 1;
	  //display correct currency
	  thelineitem = 0;
	  if(iCurrency == "rand"){	thelineitem = therands;	thelineitemship = therandsship; 	}
	  if(iCurrency == "euro"){	thelineitem = theeuros;	thelineitemship = theeurosship; 	}
	  if(iCurrency == "pound"){	thelineitem = thepounds; thelineitemship = thepoundsship;	}
	  if(iCurrency == "dollar"){	thelineitem = thedollars; thelineitemship = thedollarsship; 	}

	//keep track of rand value for paygate
	rTotal     += (parseInt(thisQuant) * parseFloat(therands) );
	fTotal     += (parseInt(thisQuant) * parseFloat(thelineitem) );

	fQty  		= (parseInt(thisQuant) * parseFloat(fields[4]) );

	fTax        = (fTotal * TaxRate);
	strTotal    = moneyFormat(fTotal);
	strrTotal    = moneyFormat(rTotal);
	strTax      = moneyFormat(fTax);

	strInsurance = moneyFormat(strInsurance);
	
	  //shipping charge for individual bangles: one rate per 2 bangles
	  if(fQty == 1){	isfirst++;	}
		//alert(isfirst);
		if(isfirst == 2)
		{
			//do nothing
			fShipping = 0
			strShipping = 0;
			isfirst = 0;
		}
		else
		{
			fShipping  = (parseInt(thisQuant) * parseFloat(thelineitemship) );
			strShipping    = moneyFormat(fShipping/100);
			tShipping = tShipping + fShipping;
		}
	strSIZE =  fields[1];
	if(1 == 1)
	{
			
      if ( bDisplay ) 
      {

	strOutput += "<TR height='23px'>";
	strOutput += "  <TD align='left'></TD>" ;	
	strOutput += "  <TD align='left'></TD>" ;
         

         
         if ( fQty == "1" )
            strOutput += "<TD align='left'>"  + fields[3] + "</td><td><I>"  + fQty + "</I></TD>";
         else
            strOutput += "<TD align='left'>"  + fields[3] + "</td><td><I>"+ fQty + "</I></TD>";

         
         
		 strOutput +=  "<TD align='left'>";
		 if(fields[4] == 1){
			 strOutput += "<select class='slqty'  name='slsize' onChange=\"ChangeSize("+i+", this.value)\">" ;
			 //strOutput += "<option value='0'>select a size</option>" ;
			 if( fields[1] == "small"){
				strOutput += "<option value='small' selected>small</option>" ;
			 }else{
				strOutput += "<option value='small'>small</option>" ;
			 }
			 if( fields[1] == "large"){
				strOutput += "<option value='large' selected>large</option></select>";
			 }else{
				strOutput += "<option value='large'>large</option></select>";
			 }
		 }else{
			 strOutput += "<input name='slsize' id='slsize' value='large' type='hidden'>";
		}
		 strOutput += "</TD>";
            strOutput += "       <TD align='left' width='5'>&nbsp;</TD>" ;
         
		 thisSubTotal = thelineitem * thisQuant;
		 //thisSubTotal = (thelineitem * thisQuant) +(thelineitemship * thisQuant);
		 thisSubTotal = thisSubTotal/100; // display in rands
		 strOutput += "<TD align='right' colspan=2>"+ MonetarySymbol + displaymoneyFormat(strShipping) + "</TD>";//shipping col
		 strOutput += "<TD align='right'>"+ MonetarySymbol + displaymoneyFormat(thisSubTotal) +"</TD>";

         if ( DisplayShippingColumn ) 
         {
            if ( parseFloat(fields[5]) > 0 )              
               strOutput += "<TD>"+ MonetarySymbol + moneyFormat(thisSubTotal) + "</TD>";
            else
               strOutput += "<TD>N/A</TD>";
         }
         strOutput += "  <TD ><a href='#' onClick=\"RemoveFromCart("+i+")\" class='copyblack'><img src='../images/cart/remove.gif' border='0'></a></TD>";
		 strOutput += "<TD align='right'>&nbsp;</TD>";
		         
		 strOutput += "</TR>";
      }
      if ( AppendItemNumToOutput ) 
      {
         strFooter = i;
      } 
      else 
      {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) 
      {
         strOutput += "<input type=hiden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"1\">";
         strOutput += "<input type=hiden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + thelineitem + "\">";
         strOutput += "<input type=hiden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hiden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[5] + "\">";
         strOutput += "<input type=hiden name=\"" + OutputItemQty  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hiden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[6] + "\">";
      }
	}
   }
   strSubTotal = strTotal/100;
  rSubTotal = strrTotal/100;
  
  if((isMyCopper == 1)&&(iCurrency != 'rand'))
  {
	strOutput += "<TR ><TD COLSPAN=11 align='center' class='FormErrors'><b>The MyCopper Bangles in your cart are only available<br>for delivery in South Africa and for purchase in South African Rands.<br>Please remove any MyCopper Bangles before checking out.</b></TD></tr>";
  }
  
   strOutput += "<TR ><TD COLSPAN=11><img src='images/shim.gif' height='1'></TD></tr></table><TABLE width='473' border='0' cellpadding='3' cellspacing='0' class='tblretailers'>";
   if ( bDisplay ) 
   {
      
	strOutput += "<TR height='22px' ><TD COLSPAN=8 align='right' class='' width='310'>&nbsp;</TD>";
	strOutput += "  <TD align='left' width='5'>&nbsp;</TD>" ;
	strOutput += "	<TD  align='right' class=''>" + MonetarySymbol + displaymoneyFormat(strSubTotal) + "</TD>";
	strOutput += "	<TD align='right'>&nbsp;</TD>";
	strOutput += "</TR>";
	strInsurance = (strSubTotal*.55)/100;
	rInsurance = (rSubTotal*.55)/100;
	
	//apply minimums to insurance amount per currency (mins are per bangle)
	//euro 1
	//pound 1
	//dolar 1.5
	//rand 10	
	var themin = 0;
	if(iCurrency == "rand"){		themin = iNumberOrdered*10;}
	if(iCurrency == "euro"){		themin = iNumberOrdered*1;	}
	if(iCurrency == "pound"){		themin = iNumberOrdered*1;	}
	if(iCurrency == "dollar"){		themin = iNumberOrdered*1.5;	}
	if(strInsurance <= themin){		strInsurance = themin;	}
	
	strInsuranceCents = parseInt(moneyFormat(strInsurance)*100);	
	strShippingCents = tShipping*100;
	rtrShippingCents = tShipping*100;
	////////////////////////////

	rShippingCents = tShipping;
	strDisplayTotal = parseInt(strTotal) + parseInt(fShipping);

	strRealTotal = parseInt(strTotal) + parseInt(tShipping);
	rSubTotal = parseInt(tShipping) + parseInt(rSubTotal);
	rTotal = parseInt(rTotal) + parseInt(tShipping);

	strDisplayTotal = strDisplayTotal/100;//show in rands
	strDisplayShipping = tShipping/100;
	
      if ( DisplayInsuranceRow ) 
      {
         strOutput += "<TR   height='22px' ><TD COLSPAN=8 align='right' class=''>"+strInsu+"</TD>";
         strOutput += " <TD align='left' width='5'><input class='chktiny' checked type='checkbox' id='ckInsurance' name='ckInsurance' OnClick='docheckinsturance("+rSubTotal+","+rInsurance+","+moneyFormat(strInsurance)+","+strSubTotal+","+strDisplayShipping+",\""+MonetarySymbol+"\")'></TD>" ;
         strOutput += "	<TD align='right' class=''>" + MonetarySymbol + displaymoneyFormat(strInsurance) + "</TD>";
	 strOutput += "	<TD align='right'>&nbsp;</TD>";
         strOutput += "</TR>";
      }
	  
	  

      if ( DisplayShippingRow ) 
      {
	strOutput += "<TR  height='22px' ><TD COLSPAN=8 align='right' class=''>"+strSHIP+"</TD>";
	strOutput += "  <TD align='left' width='5'>&nbsp;</TD>" ;
	strOutput += "	<TD align='right' class=''>" + MonetarySymbol + displaymoneyFormat(strDisplayShipping) + "</TD>";
	strOutput += "	<TD align='right'>&nbsp;</TD>";
	strOutput += "</TR>";
      }

      if ( DisplayTaxRow || TaxByRegion ) 
      {
	if ( TaxByRegion ) 
	{
		strOutput += "<TR height='22px' ><TD COLSPAN=8 align='right' class=''>"+strTAX+"</TD>";
		strOutput += "	<TD align='left' width='5'>&nbsp;</TD>" ;
		strOutput += "	<TD >";
		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 += "	</TD>";
		strOutput += "	<TD align='right'>&nbsp;</TD>";
		strOutput += "</TR>";
	} 
	else 
	{
		strOutput += "<TR bgcolor='#ffffff' height='22px' ><TD COLSPAN=8 align='right' class=''>"+strTAX+"</TD>";
		strOutput += "       <TD align='left' width='5'>&nbsp;</TD>" ;
		strOutput += "	<TD align='right' class=''>" + MonetarySymbol + strTax + "</TD>";
		strOutput += "	<TD align='right'>&nbsp;</TD>";
		strOutput += "</TR>";
	}
      }
      strOutput += "<TR ><TD COLSPAN=11><img src='images/shim.gif' height='1'></TD></tr>";
      if ( !TaxByRegion ) 
      {        
         strOutput += "<TR  height='22px' valign='top'><TD COLSPAN=8 align='right' class=''><b>SUBTOTAL</b></TD>";
         strOutput += "<TD align='left' width='5'>&nbsp;</TD>" ;
         strOutput += "<TD align='right' class=''><div name='thisTotal' id='thisTotal' class=''><b>" + MonetarySymbol + displaymoneyFormat((strDisplayTotal)) + "</b></div></TD>";
	 strOutput += "<TD align='right'>&nbsp;</TD>";
         strOutput += "</TR>";
      }
      strOutput += "<TR ><TD COLSPAN=10 align='right'>Prices exclude local Sales Tax / VAT</TD><td><img src='images/shim.gif' height='1'></td></tr>";
      strOutput += "<TR ><TD COLSPAN=11><img src='images/shim.gif' height='1'></TD></tr>";

      strOutput += "<input type=hidden name='theTot' id='theTot' value='"+strRealTotal+"'>";
      strOutput += "<input type=hidden name='theRandTot' id='theRandTot' value='"+rSubTotal+"'>";
      strOutput += "<input type=hidden name='strInsurance' id='strInsurance' value='"+strInsuranceCents+"'>";
      strOutput += "<input type=hidden name='strCurrencyOfChoice' id='strCurrencyOfChoice' value='"+iCurrency+"'>";
      strOutput += "<input type=hidden name='strShipping' id='strShipping' value='"+strDisplayShipping+"'>";
      strOutput += "<input type=hidden name='strShippingOfChoice' id='strShippingOfChoice' value='"+strDisplayShipping+"'>";
      strOutput += "<input type=hidden name='isMyCopper' id='isMyCopper' value='"+isMyCopper+"'>";
	  
  
	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);
      
  	strOutput += "<TR height='35'><TD COLSPAN=8 align='right'>";
    
	strOutput += "";

	strOutput += "<table width='54' height='23' border=0 cellpadding=0 cellspacing=0><tr><TD align='center' style='background-position:center;background-repeat:no-repeat;background-image:url(../images/addbuy.jpg)'><a href='buynow.php'><b>BACK</b></a></td></tr></table>";

	strOutput += "</TD><TD align='left'>&nbsp;</TD><TD align='right'>";
	strOutput += "<table width='80' height='23' border='0' cellpadding=0 cellspacing=0><tr><TD align='center' style='background-position:center;background-repeat:no-repeat;background-image:url(../images/addbuywide.jpg)'><a href='#' onClick='doTestForEmpty("+iNumberOrdered+")'><b>CHECK OUT</b></a></td></tr></table>";

	strOutput += "</TD><TD align='left'>&nbsp;</TD></tr>";

	strOutput += "<TR class='tblretailersfoot'><TD COLSPAN=11><img src='../images/spacer.gif' height='2'></TD></tr>";
	strOutput += "</TABLE>";
	strOutput += "<script language='javascript'>";
	strOutput += "docheckinsturance("+rSubTotal+","+rInsurance+","+moneyFormat(strInsurance)+","+strSubTotal+","+strDisplayShipping+",'"+MonetarySymbol+"');";
	strOutput += "</script>";
	document.write(strOutput);

	document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    ManageCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function ManageBackUpCart( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var iCurrency	  = "";
   //var MonetarySymbol = "R";
   var MonetarySymbol = "$";//Default to dollars
   var fTotal         = 0;    //Total cost of order
   var rTotal         = 0;    //Total cost of order in rands
   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    = "250";   //Total shipping formatted as money
   var strShippingCurrencyofChoice    = "0";   //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 strInsurance	  =	"";
   var rInsurance	  =	"";
		rShipping = "250";	  
	  strrTotal		= 0;

   iNumberOrdered = GetCookie("46664NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
	  
	  
	  

   var strCurrencyShipping    = "0";   //Total shipping in currency of coice
   //shipping:
   //Rand invoices 		R250 per 2 bangles
   //Dollar invoices  	$23 per two bangles
   //Euro Invoices  	€16 per two bangles
   //Pounds Invoice  	£9 per two bangles
   shipRand = 250;
   shipDollar = 23;
   shipEuro = 16;
   shipPounds = 9;
   iCurrency = GetCookie("46664Currency");
   if ( iCurrency == null ){
      iCurrency = "dollar";//default to dollars  
	  SetCookie("46664Currency", "dollar", null, "/");
   }
	  
	if(iCurrency == "rand"){		
		MonetarySymbol = "R";	
		strShippingCurrencyofChoice = shipRand;
	}
	if(iCurrency == "euro"){		
		MonetarySymbol = "&euro;";	
		strShippingCurrencyofChoice = shipEuro;
	}
	if(iCurrency == "pound"){		
		MonetarySymbol = "&pound;";	
		strShippingCurrencyofChoice = shipPounds;
	}
	if(iCurrency == "dollar"){	
		MonetarySymbol = "$";	
		strShippingCurrencyofChoice = shipDollar;  
	}
	//work out 2 values for shipping
	if(iNumberOrdered >= 0){
		noofships = Math.round(iNumberOrdered/2);
		pershipcostinrands = strShipping*noofships;
		pershipcostincurrencyofchoice = strShippingCurrencyofChoice*noofships;
		//alert(pershipcostinrands);
		var rShipping = pershipcostinrands;
		var strShipping = pershipcostincurrencyofchoice;
		}




	  

   if ( bDisplay )
      strOutput = "<TABLE  width='100%' border='0' cellpadding='0' cellspacing='0'><TR height='25'>" +
                  "<TD align='right' class='basketnotbold'>Change currency: <a href='javascript:changeCurrency(\"rand\",1)'>R</a> <a href='javascript:changeCurrency(\"euro\",1)'>&euro;</a> <a href='javascript:changeCurrency(\"pound\",1)'>&pound;</a> <a href='javascript:changeCurrency(\"dollar\",1)'>$</a></TD>" +
				  "</TR></table>" +
				  "<TABLE style='background-repeat:no-repeat;background-image:url(images/purchasepath/yourbasketpages/brown_header.gif)' width='100%' border='0' cellpadding='0' cellspacing='0' class='basketfont'><tr height='22px' class='basketheaderfont'><TD align='left' width='5'></TD>" +
                  "<TD align='left'>&nbsp;</TD>" +
                  "<TD align='left' colspan=2 width=100>Item</TD>" +
                  "<TD align='left' colspan=2>Size</TD>" +
                  "<TD align='right'>Price "+MonetarySymbol+"</TD>" + 
				  "<TD align='right'>&nbsp;</TD></tr>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR height='22px' ><TD COLSPAN=9 bgcolor='#f9f4d7'><CENTER><BR>Your cart is empty<BR><BR></CENTER></TD></TR>";	  
   }
   for ( i = 1; i <= iNumberOrdered; i++ ) {
	  therands 		= 0;
	  theeuros 		= 0;
	  thepounds 	= 0;
	  thedollars	= 0;
      NewOrder = "46664Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] 	= database.substring( 0, Token0 );                 // Product ID
      fields[1] 	= database.substring( Token0+1, Token1 );          // Size
      //fields[1] = 1;          // Quantity
      //fields[2] = database.substring( Token1+1, Token2 );          // Price  
	  //price array
	  //strPRICE		= (therands) + "~" +(theeuros)+ "~" +(thepounds)+ "~"+(thedollars)	
      fields[2] 	= database.substring( Token1+1, Token2 );          // Price Array
	  arrPrice 		= fields[2].split("~");
	  therands 		= arrPrice[0];
	  theeuros 		= arrPrice[1];
	  thepounds 	= arrPrice[2];
	  thedollars	= arrPrice[3];
      fields[3] 	= database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] 	= database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] 	= database.substring( Token4+1, database.length ); //Additional Information
	  //quantity always 1
	  thisQuant = 1;
	  //display correct currency
	  thelineitem = 0;
	  if(iCurrency == "rand"){		thelineitem = therands;	}
	  if(iCurrency == "euro"){		thelineitem = theeuros;	}
	  if(iCurrency == "pound"){		thelineitem = thepounds;	}
	  if(iCurrency == "dollar"){	thelineitem = thedollars;	}
//   alert(arrPrice);
	  //keep track of rand value for paygate
      rTotal     += (parseInt(thisQuant) * parseFloat(therands) );
      fTotal     += (parseInt(thisQuant) * parseFloat(thelineitem) );
      fShipping  += (parseInt(thisQuant) * parseFloat(fields[4]) );
      fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strrTotal    = moneyFormat(rTotal);
      strTax      = moneyFormat(fTax);
      //strShipping = moneyFormat(fShipping);
      strInsurance = moneyFormat(strInsurance);
	
	strSIZE =  fields[1];
	if(1 == 1){
			
      if ( bDisplay ) {

         strOutput += "<TR bgcolor='#f9f4d7' height='35px'>";
            strOutput += "       <TD align='left' width='5'></TD>" ;
			 //strOutput += "	  <TD align='left'><INPUT TYPE=checkbox NAME='Confirm" + OutputItemId + "' checked class='txtqty' ></TD>";
         	 strOutput += "	  <TD align='left'><input type=button value=\"remove\" onClick=\"RemoveFromCart("+i+")\"></TD>";
         //strOutput += "<TD>"  + fields[0] + "</TD>";

         if ( fields[5] == "" )
            strOutput += "<TD align='left'>"  + fields[3] + "</TD>";
         else
            strOutput += "<TD align='left'>"  + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

         //strOutput += "<TD align='left'><INPUT TYPE=TEXT NAME=Q class='txtqty' VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></TD>";
         //strOutput += "<TD align='center'><INPUT TYPE=hidden NAME=Q class='txtqty' VALUE=\"1\" >" + fields[1] + "</TD>";
         strOutput += "<TD align='center'>&nbsp;</TD>";
         
		 strOutput +=  "<TD align='left'>";
		 strOutput += "<select class='slsize'  name='slsize' onChange=\"ChangeSize("+i+", this.value)\">" ;
		 //strOutput += "<option value='0'>select a size</option>" ;
		 if( fields[1] == "small"){
		 	strOutput += "<option value='small' selected>small</option>" ;
		 }else{
		 	strOutput += "<option value='small'>small</option>" ;
		 }
		 if( fields[1] == "large"){
		 	strOutput += "<option value='large' selected>large</option></select>";
		 }else{
		 	strOutput += "<option value='large'>large</option></select>";
		 }
		 strOutput += "</TD>";
            strOutput += "       <TD align='left' width='5'>&nbsp;</TD>" ;
         
		 thisSubTotal = thelineitem * thisQuant;
		 thisSubTotal = thisSubTotal/100; // display in rands
		 strOutput += "<TD align='right'>"+ MonetarySymbol + displaymoneyFormat(thisSubTotal) + "</TD>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               //strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</TD>";
               strOutput += "<TD>"+ MonetarySymbol + moneyFormat(thisSubTotal) + "</TD>";
            else
               strOutput += "<TD>N/A</TD>";
         }
		 strOutput += "<TD align='right'>&nbsp;</TD>";
		 

         //strOutput += "<TD ALIGN=CENTER><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\"></TD>";
		 strOutput += "</TR>";
      }
      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"1\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + thelineitem + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      }
	}
   }
   strSubTotal = strTotal/100;
  rSubTotal = strrTotal/100;

      strOutput += "<TR bgcolor='#b0afa9' ><TD COLSPAN=8><img src='images/shim.gif' height='1'></TD></tr>";
   if ( bDisplay ) {
      //strOutput += "<TR bgcolor='#dedede' height='22px' ><TD COLSPAN=5 align='right' >"+strSUB+"</TD>";
      strOutput += "<TR bgcolor='#dedede' height='22px' ><TD COLSPAN=5 align='right' >&nbsp;</TD>";
            strOutput += "       <TD align='left' width='5'>&nbsp;</TD>" ;
      strOutput += "<TD  align='right' class='basketnotbold'>" + MonetarySymbol + displaymoneyFormat(strSubTotal) + "</TD>";
		 strOutput += "<TD align='right'>&nbsp;</TD>";
      strOutput += "</TR>";
	strInsurance = (strSubTotal*.55)/100;
	rInsurance = (rSubTotal*.55)/100;
	
	//apply minimums to insurance amount per currency (mins are per bangle)
	//euro 1
	//pound 1
	//dolar 1.5
	//rand 10	
	var themin = 0;
	if(iCurrency == "rand"){		themin = iNumberOrdered*10;}
	if(iCurrency == "euro"){		themin = iNumberOrdered*1;	}
	if(iCurrency == "pound"){		themin = iNumberOrdered*1;	}
	if(iCurrency == "dollar"){		themin = iNumberOrdered*1.5;	}
	if(strInsurance <= themin){		strInsurance = themin;	}
	
	strInsuranceCents = parseInt(moneyFormat(strInsurance)*100);
	//rInsuranceCents = parseInt(moneyFormat(rInsurance)*100);
	   // strShippingCents = strShipping.replace(".","");
	    strShippingCents = strShipping*100;
		rtrShippingCents = strShipping*100;
		////////////////////////////
		
		rShippingCents = rShipping;
	  	strDisplayTotal = parseInt(strTotal) + parseInt(strShippingCents);
	  	strRealTotal = parseInt(strTotal) + parseInt(strShippingCents);
		rSubTotal = parseInt(rShippingCents) + parseInt(rSubTotal);
	  	rTotal = parseInt(rTotal) + parseInt(rShippingCents);
	  	//strDisplayTotal = strShippingCents;// + fTax ;
		strDisplayTotal = strDisplayTotal/100;//show in rands
	
	//strInsuranceCents = moneyFormat(strInsurance).ToInt;
      if ( DisplayInsuranceRow ) {
         strOutput += "<TR bgcolor='#dedede' height='22px' ><TD COLSPAN=5 align='right' >"+strInsu+"</TD>";
            strOutput += "       <TD align='left' width='5'><input type='checkbox' id='ckInsurance' name='ckInsurance' OnClick='docheckinsturance("+rSubTotal+","+rInsurance+","+moneyFormat(strInsurance)+","+strSubTotal+","+strShipping+",\""+MonetarySymbol+"\")'></TD>" ;
         strOutput += "<TD align='right' class='basketnotbold'>" + MonetarySymbol + displaymoneyFormat(strInsurance) + "</TD>";
		 strOutput += "<TD align='right'>&nbsp;</TD>";
         strOutput += "</TR>";
      }
	  
	
	  

      if ( DisplayShippingRow ) {
         strOutput += "<TR bgcolor='#dedede' height='22px' ><TD COLSPAN=5 align='right' >"+strSHIP+"</TD>";
            strOutput += "       <TD align='left' width='5'>&nbsp;</TD>" ;
         strOutput += "<TD align='right' class='basketnotbold'>" + MonetarySymbol + displaymoneyFormat(strShipping) + "</TD>";
		 strOutput += "<TD align='right'>&nbsp;</TD>";
         strOutput += "</TR>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<TR bgcolor='#dedede' height='22px' ><TD COLSPAN=5 align='right' >"+strTAX+"</TD>";
            strOutput += "       <TD align='left' width='5'>&nbsp;</TD>" ;
            strOutput += "<TD >";
            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 += "</TD>";
		 strOutput += "<TD align='right'>&nbsp;</TD>";
            strOutput += "</TR>";
         } else {
            strOutput += "<TR bgcolor='#dedede' height='22px' ><TD COLSPAN=5 align='right' >"+strTAX+"</TD>";
            strOutput += "       <TD align='left' width='5'>&nbsp;</TD>" ;
            strOutput += "<TD align='right' class='basketnotbold'>" + MonetarySymbol + strTax + "</TD>";
		 strOutput += "<TD align='right'>&nbsp;</TD>";
            strOutput += "</TR>";
         }
      }
      strOutput += "<TR bgcolor='#ffffff'><TD COLSPAN=8><img src='images/shim.gif' height='1'></TD></tr>";
      if ( !TaxByRegion ) {
        // strOutput += "<TR bgcolor='#dedede' height='22px' ><TD COLSPAN=5 align='right' >"+strTOT+"</TD>";
         strOutput += "<TR bgcolor='#dedede' height='22px' valign='top'><TD COLSPAN=5 align='right' >SUBTOTAL</TD>";
         strOutput += "<TD align='left' width='5'>&nbsp;</TD>" ;
         strOutput += "<TD align='right' class='basketnotbold'><div name='thisTotal' id='thisTotal' >" + MonetarySymbol + displaymoneyFormat((strDisplayTotal)) + "</div>(excluding VAT)</TD>";
		 strOutput += "<TD align='right'>&nbsp;</TD>";
         strOutput += "</TR>";
      }
      strOutput += "<TR bgcolor='#b0afa9'><TD COLSPAN=9><img src='images/shim.gif' height='1'></TD></tr>";

      strOutput += "<input type=hidden name='theTot' id='theTot' value='"+strRealTotal+"'>";
      strOutput += "<input type=hidden name='theRandTot' id='theRandTot' value='"+rSubTotal+"'>";
      strOutput += "<input type=hidden name='strInsurance' id='strInsurance' value='"+strInsuranceCents+"'>";
      strOutput += "<input type=hidden name='strCurrencyOfChoice' id='strCurrencyOfChoice' value='"+iCurrency+"'>";
      strOutput += "<input type=hidden name='strShipping' id='strShipping' value='"+rShipping+"'>";
      strOutput += "<input type=hidden name='strShippingOfChoice' id='strShippingOfChoice' value='"+strShipping+"'>";
	  
  /*
   */
      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);
   
   
      strOutput += "<TR bgcolor='#ffffff' height='35'><TD COLSPAN=7 valign='bottom' align='right'>";
	strOutput += "<a href='BuyNow.html'><img hspace='10' border='0' src='images/purchasepath/yourbasketpages/buttons/back_to_bangles_off.gif' onmouseover='this.src=\"../../images/purchasepath/yourbasketpages/buttons/back_to_bangles_on.gif\"' onmouseout='this.src=\"../../images/purchasepath/yourbasketpages/buttons/back_to_bangles_off.gif\"'></a>";
   //strOutput += "<a href='checkout.html'><img border='0' src='images/purchasepath/yourbasketpages/buttons/cgeckOut_off.gif' onmouseover='this.src=\"../../images/purchasepath/yourbasketpages/buttons/cgeckOut_on.gif\"' onmouseout='this.src=\"../../images/purchasepath/yourbasketpages/buttons/cgeckOut_off.gif\"'></a>";
  
  strOutput += "<img onClick='doTestForEmpty("+iNumberOrdered+")' border='0' src='images/purchasepath/yourbasketpages/buttons/cgeckOut_off.gif' onmouseover='this.src=\"../../images/purchasepath/yourbasketpages/buttons/cgeckOut_on.gif\"' onmouseout='this.src=\"../../images/purchasepath/yourbasketpages/buttons/cgeckOut_off.gif\"'>";
  //strOutput += "<input type='image' border='0' src='images/purchasepath/yourbasketpages/buttons/cgeckOut_off.gif' onmouseover='this.src=\"../../images/purchasepath/yourbasketpages/buttons/cgeckOut_on.gif\"' onmouseout='this.src=\"../../images/purchasepath/yourbasketpages/buttons/cgeckOut_off.gif\"'>";
   
      strOutput += "</TD>  <TD align='left' width='5'>&nbsp;</TD></tr>";
      strOutput += "</TABLE>";
      strOutput += "<script language='javascript'>";
	  strOutput += "docheckinsturance("+rSubTotal+","+rInsurance+","+moneyFormat(strInsurance)+","+strSubTotal+","+strShipping+",'"+MonetarySymbol+"');";
	  strOutput += "</script>";
	  document.write(strOutput);
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    MiniCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function MiniCart( ) {
   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 totalQty = 0;
   iNumberOrdered = GetCookie("46664NumberOrdered");
   //alert(iNumberOrdered);
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( bDisplay )
      strOutput = "<TABLE><TR>" +
                  "<TD>"+strILabel+"</TD>" +
                  "<TD>"+strDLabel+"</TD>" +
                  "<TD>"+strQLabel+"</TD>" +
                  "<TD>"+strPLabel+"</TD>" +
                  (DisplayShippingColumn?"<TD>"+strSLabel+"</TD>":"") +
                  "<TD>"+strRLabel+"</TD></TR>";
				  

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR><TD COLSPAN=6><CENTER><BR>Your cart is empty<BR><BR></CENTER></TD></TR>";
   }

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "46664Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      //fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[1] = 1;          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information

      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) {
         strOutput += "<TR><TD>"  + fields[0] + "</TD>";

         if ( fields[5] == "" )
            strOutput += "<TD>"  + fields[3] + "</TD>";
         else
            strOutput += "<TD>"  + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

         strOutput += "<TD><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></TD>";
         strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</TD>";
		totalQty = totalQty + parseInt(fields[1]);
         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</TD>";
            else
               strOutput += "<TD>N/A</TD>";
         }

         strOutput += "<TD ALIGN=CENTER><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\"></TD></TR>";
      }

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"1\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      }

   }

   if ( bDisplay ) {
      strOutput += "<TR><TD COLSPAN=4>"+strSUB+"</TD>";
      strOutput += "<TD COLSPAN=2>" + MonetarySymbol + strTotal + "</TD>";
      strOutput += "</TR>";

      if ( DisplayShippingRow ) {
         strOutput += "<TR><TD COLSPAN=4>"+strSHIP+"</TD>";
         strOutput += "<TD COLSPAN=2>" + MonetarySymbol + strShipping + "</TD>";
         strOutput += "</TR>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<TR><TD COLSPAN=4>"+strTAX+"</TD>";
            strOutput += "<TD COLSPAN=2>";
            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 += "</TD>";
            strOutput += "</TR>";
         } else {
            strOutput += "<TR><TD COLSPAN=4>"+strTAX+"</TD>";
            strOutput += "<TD COLSPAN=2>" + MonetarySymbol + strTax + "</TD>";
            strOutput += "</TR>";
         }
      }

      if ( !TaxByRegion ) {
         strOutput += "<TR><TD COLSPAN=4>"+strTOT+"</TD>";
         strOutput += "<TD COLSPAN=2>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</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)) + "\">";
      }
	  theinc = " items";
	  if(totalQty == 1){	theinc = " item";	}
	 strOutputMini = "You have " + totalQty + theinc +" in your basket.";
   }
   
   g_TotalCost = (fTotal + fShipping + fTax);
	//strOutput = "<div style='visibility:visible;width:100px;height:100px;'>" + strOutput + "</div>";
	if(totalQty >= 1 ){
		strOutput = "<div class='minibasket'><table cellpadding='0' cellspacing='0' border='0' height='55'><tr><td width='380' class='minibasketfont'>" + strOutputMini + "</td><td valign='middle'><a href='managecart.php'><img style='float:right' src='../images/checkout_btn.jpg' border='0'></a></td></tr></table><br></div>";
   		document.write(strOutput);
	}
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    MiniCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function MiniBKCart( ) {
   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 totalQty = 0;
   iNumberOrdered = GetCookie("46664NumberOrdered");
   //alert(iNumberOrdered);
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( bDisplay )
      strOutput = "<TABLE><TR>" +
                  "<TD>"+strILabel+"</TD>" +
                  "<TD>"+strDLabel+"</TD>" +
                  "<TD>"+strQLabel+"</TD>" +
                  "<TD>"+strPLabel+"</TD>" +
                  (DisplayShippingColumn?"<TD>"+strSLabel+"</TD>":"") +
                  "<TD>"+strRLabel+"</TD></TR>";
				  

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR><TD COLSPAN=6><CENTER><BR>Your cart is empty<BR><BR></CENTER></TD></TR>";
   }

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "46664Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      //fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[1] = 1;          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information

      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) {
         strOutput += "<TR><TD>"  + fields[0] + "</TD>";

         if ( fields[5] == "" )
            strOutput += "<TD>"  + fields[3] + "</TD>";
         else
            strOutput += "<TD>"  + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

         strOutput += "<TD><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></TD>";
         strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</TD>";
		totalQty = totalQty + parseInt(fields[1]);
         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</TD>";
            else
               strOutput += "<TD>N/A</TD>";
         }

         strOutput += "<TD ALIGN=CENTER><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\"></TD></TR>";
      }

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"1\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      }

   }

   if ( bDisplay ) {
      strOutput += "<TR><TD COLSPAN=4>"+strSUB+"</TD>";
      strOutput += "<TD COLSPAN=2>" + MonetarySymbol + strTotal + "</TD>";
      strOutput += "</TR>";

      if ( DisplayShippingRow ) {
         strOutput += "<TR><TD COLSPAN=4>"+strSHIP+"</TD>";
         strOutput += "<TD COLSPAN=2>" + MonetarySymbol + strShipping + "</TD>";
         strOutput += "</TR>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<TR><TD COLSPAN=4>"+strTAX+"</TD>";
            strOutput += "<TD COLSPAN=2>";
            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 += "</TD>";
            strOutput += "</TR>";
         } else {
            strOutput += "<TR><TD COLSPAN=4>"+strTAX+"</TD>";
            strOutput += "<TD COLSPAN=2>" + MonetarySymbol + strTax + "</TD>";
            strOutput += "</TR>";
         }
      }

      if ( !TaxByRegion ) {
         strOutput += "<TR><TD COLSPAN=4>"+strTOT+"</TD>";
         strOutput += "<TD COLSPAN=2>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</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)) + "\">";
      }
	  theinc = " items";
	  if(totalQty == 1){	theinc = " item";	}
	 strOutputMini = "You have " + totalQty + theinc +" in your basket.";
   }
   
   g_TotalCost = (fTotal + fShipping + fTax);
	//strOutput = "<div style='visibility:visible;width:100px;height:100px;'>" + strOutput + "</div>";
	if(totalQty >= 1 ){
		strOutput = "<div class='minibasket'><table cellpadding='0' cellspacing='0' border='0'><tr><td width='380' class='minibasketfont'>" + strOutputMini + "</td><td valign='top'><a href='managecart.php'>checkout<!--img style='float:right' src='images/purchasepath/minibasket/top_right_button_no_rollover.gif' border='0'--></a></td></tr></table></div>";
   		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    = "250.00";   //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
   var strInsurance	  =	"0";
   //alert(request.form( "ckInsurance")

   iNumberOrdered = GetCookie("46664NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
	  
      iCurrency = GetCookie("46664Currency");
	if(iCurrency == "rand"){				MonetarySymbol = "R";		}
	if(iCurrency == "euro"){				MonetarySymbol = "&euro;";		}
	if(iCurrency == "pound"){				MonetarySymbol = "&pound;";		}
	if(iCurrency == "dollar"){				MonetarySymbol = "$";		}
	
   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }
if ( bDisplay )
	  strOutput = "<TR height='22px' class=''>" +
                  //"<TD>"+strILabel+"</TD>" +
                  //"<TD>"+strDLabel+"</TD>" +
                  //"<TD>"+strQLabel+"</TD>" +
                  //"<TD>"+strPLabel+"</TD>" +
                  "<TD align='left' width='19'></TD>" +
                  "<TD align='left' width='150'><b>Item</b></TD>" +
                  "<TD align='left'colspan=2><b>Size</b></TD>" +
                  "<TD align='left' width='5'></TD>" +
//                  (DisplayShippingColumn?"<TD>"+strSLabel+"</TD>":"") +
                  //"<TD>"+strRLabel+"</TD>" +
				  "</TR>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR height='22px' ><TD COLSPAN=7><CENTER><BR>Your cart is empty<BR><BR></CENTER></TD></TR>";
   }

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "46664Order." + i;
      database = "";
      database = GetCookie(NewOrder);

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

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Size
      //fields[1] = 1;          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price Array
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // qty
      fields[5] = database.substring( Token4+1, Token5 );          // Shipping Cost
      fields[6] = database.substring( Token5+1, database.length ); //Additional Information
	  
      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[5]) );
      fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      //strShipping = moneyFormat(fShipping);
      strInsurance = moneyFormat(strInsurance);


	thisSize = fields[1]	;
	//if(thisQty >= 1){
      if ( bDisplay ) {
         strOutput += "<TR height='35px'>";
            strOutput += "       <TD align='left' width='5'></TD>" ;
         //strOutput += "<TD>"  + fields[0] + "</TD>";

        // if ( fields[4] == "" )
         if ( fields[4] == "" )
            strOutput += "<TD align='left'>"  + fields[3] + "</TD>";
         else
            strOutput += "<TD align='left'>"  + fields[3] + " - <I>"+ fields[4] + "</I></TD>";

         strOutput += "<TD align='left' colspan=2>";
         if ( fields[4] == "1" ){		 strOutput += thisSize;	  	}
		 strOutput += "</TD>";
            strOutput += "       <TD align='left' width='5'></TD>" ;
         
		 
		 //strOutput += "<TD align='left'>"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</TD>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[5]) > 0 )
               strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[5]) + "/ea</TD>";
            else
               strOutput += "<TD>N/A</TD>";
         }
		 

         //strOutput += "<TD ALIGN=CENTER><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\"></TD>";
		 strOutput += "</TR>";
      }

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"1\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[5] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[4] + "\">";
      }


   
   //}
   }
      strOutput += "<TR ><TD COLSPAN=7><img src='images/shim.gif' height='1'></TD></tr>";
		//add first row now to include total
	    strShippingCents = strShipping.replace(".","");
	  	var allinall = ((fTotal) + (strShippingCents)+(strInsurance))/100;
		//var allinall = (parseInt(fTotal) + parseInt(strShippingCents)+parseInt(strInsurance))/100;
		//var allinall = fTotal + txtShipping + fTax;
		//firstrow ="<TABLE  width='460' border='0' cellpadding='0' cellspacing='0' class='basketfont'><TR height='32px' class='checkoutheader'><TD COLSPAN=3 align='left'><span class='checkoutfont'>&nbsp;&nbsp;&nbsp;Your order</span></TD><TD COLSPAN=3 align='center'><span >&nbsp;&nbsp;&nbsp;"+ MonetarySymbol + moneyFormat(allinall)+"</span></TD></TR>";
		firstrow ="<TABLE class='tblretailersheading'  width='473' border='0' cellpadding='0' cellspacing='0'><TR height='39'>" +
                  "<TD align='center' class=''><a href='managecart.php'>&lt;&lt;&nbsp;To change currency, return to shopping basket</a></TD>" +
				  "</TR></table><TABLE class='tblretailers' width='473' border='0' cellpadding='0' cellspacing='0' class=''>";
		firstrow +=  "			<TR height='32px' class=''>";
		firstrow +=  "				<TD COLSPAN=3 align='left' valign='middle'><span class=''>&nbsp;&nbsp;&nbsp;Your order</span></TD>";
		firstrow +=  "				<TD align='right' class=''>&nbsp;</td>";
		firstrow +=  "				<TD align='right' width='100'><span class='' id='theTot' name='theTot'></span></TD>";
		firstrow +=  "			</TR>";
		firstrow +=  " <TR height='21px'  >";
		firstrow +=  "<TD COLSPAN=3 align='left' valign='top'>&nbsp;</TD>";
		firstrow +=  "<TD align='right' class=''>VAT:</td>";
		firstrow +=  "<TD align='right' width='100' nowrap><div  id='divvat' name='divvat'></div></TD>";
		firstrow +=  "</TR>";
		firstrow +=  " <TR height='21px' >";
		firstrow +=  " <TD COLSPAN=3 align='left' valign='top'>&nbsp;</TD>";
		firstrow +=  " <TD align='right' class=''>Total:</td>";
		firstrow +=  " <TD align='right'  nowrap><div  id='divgrandtot' name='divgrandtot'></div></TD>";
		firstrow +=  " </TR>";
		firstrow +=  " <TR height='21px' >";
		firstrow +=  " <TD COLSPAN=5 align='right' valign='top'>&nbsp;Prices exclude local Sales Tax / VAT&nbsp;&nbsp;<br>The recipient is responsible for the Sales Tax in each receiving country&nbsp;&nbsp;</TD>";
		firstrow +=  " </TR>";
		
		
		
		
		strOutput =  firstrow + strOutput;
	  

      strOutput += "</TABLE>";

      
      

   document.write(strOutput);
   //document.form1.AMOUNT.value = fTotal + fShipping + fTax;
   ////document.form1.AMOUNT.value = allinall;
   var TotalForDisplay = displaymoneyFormat(document.form1.CURRENCYAMOUNT.value/100);
   document.getElementById('theTot').innerHTML =  MonetarySymbol + TotalForDisplay + "&nbsp;&nbsp;";
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    CheckoutCart                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page for      ||
//              checkout.                                              ||
//---------------------------------------------------------------------||
function CheckoutBKCart( ) {
   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    = "250.00";   //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
   var strInsurance	  =	"0";
   //alert(request.form( "ckInsurance")

   iNumberOrdered = GetCookie("46664NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
	  
      iCurrency = GetCookie("46664Currency");
	if(iCurrency == "rand"){				MonetarySymbol = "R";		}
	if(iCurrency == "euro"){				MonetarySymbol = "&euro;";		}
	if(iCurrency == "pound"){				MonetarySymbol = "&pound;";		}
	if(iCurrency == "dollar"){				MonetarySymbol = "$";		}
	
   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }
if ( bDisplay )
	  strOutput = "<TR bgcolor='#f9f4d7'  height='22px' class='checkoutheaderfont'>" +
                  
                  "<TD align='left' width='19'></TD>" +
                  "<TD align='left'><b>Item</b></TD>" +
                  "<TD align='left'colspan=2><b>Size</b></TD>" +
                  "<TD align='left' width='5'></TD>" +


				  "</TR>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR height='22px' ><TD COLSPAN=7 bgcolor='#f9f4d7'><CENTER><BR>Your cart is empty<BR><BR></CENTER></TD></TR>";
   }

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "46664Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Size
      //fields[1] = 1;          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price Array
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information
	  
      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      //strShipping = moneyFormat(fShipping);
      strInsurance = moneyFormat(strInsurance);


	thisSize = fields[1]	;
	//if(thisQty >= 1){
      if ( bDisplay ) {
         strOutput += "<TR bgcolor='#f9f4d7' height='35px'>";
            strOutput += "       <TD align='left' width='5'></TD>" ;
         //strOutput += "<TD>"  + fields[0] + "</TD>";

         if ( fields[5] == "" )
            strOutput += "<TD align='left'>"  + fields[3] + "</TD>";
         else
            strOutput += "<TD align='left'>"  + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

         strOutput += "<TD align='left' colspan=2>";
		 strOutput += thisSize+"</select>"
		 strOutput += "</TD>";
            strOutput += "       <TD align='left' width='5'></TD>" ;
         
		 
		 //strOutput += "<TD align='left'>"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</TD>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</TD>";
            else
               strOutput += "<TD>N/A</TD>";
         }
		 

         //strOutput += "<TD ALIGN=CENTER><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\"></TD>";
		 strOutput += "</TR>";
      }

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"1\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      }


   
   
   }
      strOutput += "<TR bgcolor='#b0afa9' ><TD COLSPAN=7><img src='images/shim.gif' height='1'></TD></tr>";
		//add first row now to include total
	    strShippingCents = strShipping.replace(".","");
	  	var allinall = ((fTotal) + (strShippingCents)+(strInsurance))/100;
		//var allinall = (parseInt(fTotal) + parseInt(strShippingCents)+parseInt(strInsurance))/100;
		//var allinall = fTotal + txtShipping + fTax;
		//firstrow ="<TABLE  width='460' border='0' cellpadding='0' cellspacing='0' class='basketfont'><TR height='32px' class='checkoutheader'><TD COLSPAN=3 align='left'><span class='checkoutfont'>&nbsp;&nbsp;&nbsp;Your order</span></TD><TD COLSPAN=3 align='center'><span >&nbsp;&nbsp;&nbsp;"+ MonetarySymbol + moneyFormat(allinall)+"</span></TD></TR>";
		firstrow ="<TABLE  width='455' border='0' cellpadding='0' cellspacing='0'><TR height='25'>" +
                  "<TD align='right' class='basketnotbold'><a href='managecart.html'>&lt;&lt;&nbsp;To change currency, return to shopping basket</a></TD>" +
				  "</TR></table><TABLE  width='460' border='0' cellpadding='0' cellspacing='0' class='basketfont'>";
		firstrow +=  "			<TR height='32px' class='checkoutheader'>";
		firstrow +=  "				<TD COLSPAN=3 align='left' valign='middle'><span class='checkoutfont'>&nbsp;&nbsp;&nbsp;Your order</span></TD>";
		firstrow +=  "				<TD align='right' >&nbsp;</td>";
		firstrow +=  "				<TD align='right' width='100'><span  id='theTot' name='theTot'></span></TD>";
		firstrow +=  "			</TR>";
		firstrow +=  " <TR height='21px'  bgcolor='#f9f4d7' >";
		firstrow +=  "<TD COLSPAN=3 align='left' valign='top'>&nbsp;</TD>";
		firstrow +=  "<TD align='right' >VAT:</td>";
		firstrow +=  "<TD align='right' width='100' nowrap><div  id='divvat' name='divvat'></div></TD>";
		firstrow +=  "</TR>";
		firstrow +=  " <TR height='21px'  bgcolor='#f9f4d7' >";
		firstrow +=  " <TD COLSPAN=3 align='left' valign='top'>&nbsp;</TD>";
		firstrow +=  " <TD align='right' >Total:</td>";
		firstrow +=  " <TD align='right'  nowrap><div  id='divgrandtot' name='divgrandtot'></div></TD>";
		firstrow +=  " </TR>";
		
		
		
		
		strOutput =  firstrow + strOutput;
	  

      strOutput += "</TABLE>";

      
      

   document.write(strOutput);
   //document.form1.AMOUNT.value = fTotal + fShipping + fTax;
   ////document.form1.AMOUNT.value = allinall;
   var TotalForDisplay = displaymoneyFormat(document.form1.CURRENCYAMOUNT.value/100);
   document.getElementById('theTot').innerHTML =  MonetarySymbol + TotalForDisplay + "&nbsp;&nbsp;";
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    CheckoutConfirm                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page for      ||
//              checkout.                                              ||
//---------------------------------------------------------------------||
function CheckoutConfirm( ) {
   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("46664NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }

   if ( bDisplay )
      strOutput = "<TABLE><TR>" +
                  "<TD>"+strILabel+"</TD>" +
                  "<TD>"+strDLabel+"</TD>" +
                  "<TD>"+strQLabel+"</TD>" +
                  "<TD>"+strPLabel+"</TD>" +
                  (DisplayShippingColumn?"<TD>"+strSLabel+"</TD>":"") +
                  "</TR>";

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "46664Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      //fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[1] = 1;          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information

      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      if ( !TaxByRegion ) fTax = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      if ( !TaxByRegion ) strTax = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) {
         strOutput += "<TR><TD>"  + fields[0] + "</TD>";

         if ( fields[5] == "" )
            strOutput += "<TD>"  + fields[3] + "</TD>";
         else
            strOutput += "<TD>"  + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

         strOutput += "<TD>" + fields[1] + "</TD>";
         strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</TD>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               strOutput += "<TD>"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</TD>";
            else
               strOutput += "<TD>N/A</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[0] + ", " + fields[3];
         if ( fields[5] != "" )
            strPP += " - " + fields[5];
         strPP += ", Qty. " + fields[1] + "\n";
      } else {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"1\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      } 

   }

   if ( bDisplay ) {
      strOutput += "<TR><TD COLSPAN=3>"+strSUB+"</TD>";
      strOutput += "<TD COLSPAN=2 ALIGN=RIGHT>" + MonetarySymbol + strTotal + "</TD>";
      strOutput += "</TR>";

      if ( DisplayShippingRow ) {
         strOutput += "<TR><TD COLSPAN=3>"+strSHIP+"</TD>";
         strOutput += "<TD COLSPAN=2 ALIGN=RIGHT>" + MonetarySymbol + strShipping + "</TD>";
         strOutput += "</TR>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         strOutput += "<TR><TD COLSPAN=3>"+strTAX+"</TD>";
         strOutput += "<TD COLSPAN=2 ALIGN=RIGHT>" + MonetarySymbol + strTax + "</TD>";
         strOutput += "</TR>";
      }

      strOutput += "<TR><TD COLSPAN=3>"+strTOT+"</TD>";
      strOutput += "<TD COLSPAN=2 ALIGN=RIGHT>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</TD>";
      strOutput += "</TR>";
	  var allinall = fTotal + fShipping + fTax;
      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 {
         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)) + "\">";
      }
   }
	strOutput = "<p>Please click submit to process the transaction for: "+MonetarySymbol + moneyFormat((fTotal + fShipping + fTax))+"</p>";
   //document.write(strOutput);
   document.forms[0].AMOUNT.value = fTotal + fShipping + fTax;
   document.close();
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||

  
function docheckinsturance(rTotal,rInsurance,strInsurance,strSubTotal,strShipping,MonetarySymbol){
	if(document.getElementById("ckInsurance").checked == true){
		var addup = parseFloat(strInsurance)+parseFloat(strSubTotal)+parseFloat(strShipping);
		var Raddup = parseFloat(rTotal)+parseFloat(rInsurance);
		var thisTotal = moneyFormat(addup);
		var thisRandTotal = moneyFormat(Raddup);
		document.getElementById("thisTotal").innerHTML = MonetarySymbol + displaymoneyFormat(thisTotal);
	}else{
		var addup = parseFloat(strSubTotal)+parseFloat(strShipping);
		var Raddup = parseFloat(rTotal);
		var thisRandTotal = moneyFormat(Raddup);
		var thisTotal = moneyFormat(addup);
		document.getElementById("thisTotal").innerHTML = MonetarySymbol + displaymoneyFormat(thisTotal);
	}
	document.getElementById("theTot").value = (thisTotal*100);
	document.getElementById("theRandTot").value = (thisRandTotal*100);
}

function AddInsuranceCookie(isInsured,insValue){	
		if(isInsured == "on"){
         	SetCookie("46664Insured", insValue, null, "/");
		}else{
         	SetCookie("46664Insured", "0", null, "/");
		}
	}
function doTestForEmpty(iNumberOrdered){	
	if(iNumberOrdered == 0){
		alert("Your cart is empty. Please add at least one item before checking out.")	
        exit;		
	}else{
		isMyCopper = document.getElementById("isMyCopper").value;
		iCurrency = GetCookie("46664Currency");
		//alert(iCurrency);
		if((iCurrency != 'rand')&&(isMyCopper == 1)){
			ok = confirm("MyCopper Bangles are only available for delivery in South Africa and for purchase in South African Rands.\n\nPlease remove any MyCopper Bangles from your cart before checking out\nor change the currency to South AFrican Rands.");
		}else{
			document.forms[0].action = "checkout.php";
			document.forms[0].submit();
		}
	}
}
function changeCurrency(strcurrency){
	isMyCopper = document.getElementById("isMyCopper").value;
	//alert(document.getElementById("isMyCopper").value);
	if((strcurrency != 'rand')&&(isMyCopper == 1)){
		ok = alert("MyCopper Bangles are only available for delivery in South Africa and for purchase in South African Rands.\n\nPlease remove any MyCopper Bangles from your cart before changing your currency.");
	}else{
		SetCookie("46664Currency", strcurrency, null, "/");
		window.location.href = window.location.href;			
	}
}