//=====================================================================||
//               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.5.0.draft   Feb 15, 2004                   ||
// Drop in replacement for V.4.4.0                                     ||
//=====================================================================||
//                 Australia Post CART MANAGEMENT MODULE               ||
//            Express Post Parsel  SHIPPING BY WEIGHT & ZONE           ||
//                   Flat fee + fee/Kg or part thereof.                ||
//=====================================================================||
//
OutputOrderZone = "ZONE"
//---------------------------------------------------------------------||
// Edit Shipping Zones: 
// 170 and 206 ManageCart,  
// 570 Checkout.
// Formular: 300 ComputeShipping    // Add tax to zone 291 & 295
//---------------------------------------------------------------------||
// FUNCTION:    ManageCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function ManageCart() {

	var fTotal         = 0;    		//Total cost of order
	var fprodttl       = 0; 		//Total product cost = QTY * PRICE
	var fFst           = 0;    		//FST amount
	var fTax           = 0;    		//Tax amount
	var fShipping      = 0;    		//Shipping amount--set flatrate shipping here
	var fWeight        = 0;			//Weight of items for shipping calculation 
	var LocationSelected = 8;
	var LocationLabel  = "";
	var TotWeight      = 0;
	var strTotal       = "0.00";   	//Total cost formatted as money
	var strFst         = "0.00";   	//Total FST formatted as money
	var strTax         = "0.00";   	//Total Tax formatted as money
	var strShipping    = "0.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 strProductId   = "";		//used for non-taxable item identification
	var strAddInfo     = ""; 
	
// insurance Modification
	var insure     =0
	
ReadCookie();

// ------------------- Cart Table Header -----------------------------------||
   if ( bDisplay )
	 		strOutput = 
"<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 CLASS=\"nopcart\"><TR>" +			
"<TD WIDTH=80 CLASS=\"nopheader\" ALIGN=\"LEFT\"><strong>"+strILabel+"</strong></TD>" +			
"<TD ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strDLabel+"</strong></TD>" +			
"<TD WIDTH=50 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strQLabel+"</strong></TD>" +			
"<TD WIDTH=80 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strPLabel+"</strong></TD>";
if ( DisplayShippingColumn ) { strOutput += 
"<TD WIDTH=75 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strWLabel+"</strong></TD>";
} else { strOutput += 
"<TD WIDTH=85 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strPTLabel+"</strong></TD>";}
strOutput += "<TD  WIDTH=90 ALIGN=\"CENTER\" CLASS=\"nopheader\"><strong>"+strRLabel+"</strong></TD></TR>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR><TD COLSPAN=6 CLASS=\"nopentry\" ALIGN=\"center\"><BR><B>Your shopping cart is empty</B><BR><BR></TD></TR>";
   }else {

   for ( i = 1; i <= iNumberOrdered; i++ ) {
			even = (i & 1);

      fprodttl       = (parseInt(ItemQuantity[i])* parseFloat(ItemPrice[i]));
      fTotal        += (fprodttl);
      fShipping     += (parseInt(ItemQuantity[i])* parseFloat(ItemShipping[i]) );
			fWeight       += (parseInt(ItemQuantity[i])* parseFloat(ItemWeight[i]) );
//      fWeight        =  Math.round(fWeight * 100)/100;
     if(ItemFsTx[i] == 'true') 	fFst += (fprodttl * FstRate);
     if(ItemPsTx[i] == 'true')  fTax += (parseInt(ItemQuantity[i]) * parseFloat(ItemPrice[i])) * TaxRate; 

      strTotal    = moneyFormat(fTotal);
      strFst      = moneyFormat(fFst);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);
      strAddInfo  =	"";
	  
//	  Calculate Insurance
	  if (fTotal + fShipping + fTax <=100) insure=7;
	  else
	  	insure = parseInt((fTotal + fShipping + fTax)/100)*2+7;

// ------------------- Cart Table Body -----------------------------------||
			
if ( bDisplay ){
     if (even ^ 1 ) {
		strOutput += "<TR CLASS=\"tblpadding5\"><TD CLASS=\"nopeven\" ALIGN=\"LEFT\">" + ItemId[i] + "</TD>";
    strOutput += "<TD CLASS=\"nopeven\" ALIGN=\"LEFT\">"  + ItemName[i] ;
         if ( ItemAddtlInfo[i]  != "" ) strAddInfo  = " - <I>" + ItemAddtlInfo[i];
				 if ( ItemAddtlInfo2[i] != "" ) strAddInfo +=  ItemAddtlInfo2[i];
				 if ( ItemAddtlInfo3[i] != "" ) strAddInfo +=  ItemAddtlInfo3[i];
				 if ( ItemUserEntry[i]  != "" ) strAddInfo +=  ItemUserEntry[i];
				 if ( ItemUserEntry2[i] != "" ) strAddInfo +=  ItemUserEntry2[i];
    strOutput += strAddInfo + "</I></TD>";

         strOutput += "<TD CLASS=\"nopeven\" ALIGN=CENTER><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + ItemQuantity[i] + "\" onChange=\"this.value=ChangeQuantity("+i+",this.value);\"></TD>";
         strOutput += "<TD CLASS=\"nopeven\" ALIGN=RIGHT>"+ MonetarySymbol + moneyFormat(ItemPrice[i]) + "</TD>";

// Either display Shipping Column or extended price column
         if ( DisplayShippingColumn ) {
            if ( parseFloat(ItemWeight[i]) > 0 )
               strOutput += "<TD CLASS=\"nopeven\" ALIGN=\"RIGHT\">"+ ItemWeight[i] + "Kg/ea</TD>";
            else
               strOutput += "<TD CLASS=\"nopeven\" ALIGN=\"center\">N/A</TD>";
         }
	else {
		strOutput += "<TD ALIGN=RIGHT CLASS=\"nopeven\">"+ MonetarySymbol + moneyFormat(fprodttl) + "</TD>";
         }

    strOutput += "<TD CLASS=\"nopeven\" ALIGN=CENTER><input type=button class=\"butform\" onmousedown=\"this.className='butformy'\" onmouseup=\"this.className='butform'\" onmouseover=\"this.className='butformx'\" onmouseout=\"this.className='butform'\" value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\"></TD></TR>";
      }
else {
// repeat for odd

		strOutput += "<TR CLASS=\"tblpadding5\"><TD CLASS=\"nopentry\" ALIGN=\"LEFT\">" + ItemId[i] + "</TD>";
    strOutput += "<TD CLASS=\"nopentry\" ALIGN=\"LEFT\">"  + ItemName[i];
         if ( ItemAddtlInfo[i]  != "" ) strAddInfo  =  " - <I>" + ItemAddtlInfo[i];
				 if ( ItemAddtlInfo2[i] != "" ) strAddInfo +=  ItemAddtlInfo2[i];
				 if ( ItemAddtlInfo3[i] != "" ) strAddInfo +=  ItemAddtlInfo3[i];
				 if ( ItemUserEntry[i]  != "" ) strAddInfo +=  ItemUserEntry[i];
				 if ( ItemUserEntry2[i] != "" ) strAddInfo +=  ItemUserEntry2[i];
    strOutput += strAddInfo + "</I></TD>";

         strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + ItemQuantity[i] + "\" onChange=\"this.value=ChangeQuantity("+i+",this.value);\"></TD>";
         strOutput += "<TD CLASS=\"nopentry\" ALIGN=RIGHT>"+ MonetarySymbol + moneyFormat(ItemPrice[i]) + "</TD>";

// Either display Shipping Column or extended price column
         if ( DisplayShippingColumn ) {
            if ( parseFloat(ItemWeight[i]) > 0 )
               strOutput += "<TD CLASS=\"nopentry\" ALIGN=RIGHT>"+ ItemWeight[i] + "Kg/ea</TD>";
            else
               strOutput += "<TD CLASS=\"nopentry\" ALIGN=\"center\">N/A</TD>";
         }
	else {
		strOutput += "<TD ALIGN=RIGHT CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(fprodttl) + "</TD>";
         }

    strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER><input type=button class=\"butform\" onmousedown=\"this.className='butformy'\" onmouseup=\"this.className='butform'\" onmouseover=\"this.className='butformx'\" onmouseout=\"this.className='butform'\" value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\"></TD></TR>";
      }
}

// ------------------- End of Cart Table Body -----------------------------------||

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + ItemId[i] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + ItemQuantity[i] + "\">";
        strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + ItemPrice[i] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + ItemName[i] + "\">";
//         strOutput += "<input type=hidden name=\"" + OutputItemWeight    + strFooter + "\" value=\"" + ItemWeight[i] + "\">"; // no string "OutputItemWeight" found
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + strAddInfo + "\">";
      }

   }
}
// ------------------- Cart Table Footer -----------------------------------||
		
   if ( bDisplay ) {
      strOutput += "<TR><TD align=\"right\" CLASS=\"ni\" COLSPAN=6><div style=\"WIDTH: 3px; HEIGHT: 2px;\"></div></TD></TR>";

//this displays the shipping matrix and sets the value for each zone ||

if (( DisplayShippingRow ) && ( iNumberOrdered != 0)) {
	 		strOutput +="<TR><TD COLSPAN=6>"+ 
"<TABLE CELLSPACING=0 CELLPADDING=0 WIDTH=100% BORDER=0 CLASS=\"nopship\"><TR>"			
 
strOutput += "<TD CLASS=\"nopship\" COLSPAN=1 ALIGN=CENTER STYLE=\"TEXT-ALIGN: CENTER;\"><B>"+ strSHIP +"<BR>ZONES"+"</B></TD>"; 
strOutput += "<TD CLASS=\"nopship\" COLSPAN=1>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"0" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "TAS"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"1" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "VIC"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"2" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "NSW"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"3" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += "SA"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"4" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += "QLD/WA/NT"; 
strOutput += "</TD>"; 
strOutput += "<TD CLASS=\"nopship\" COLSPAN=1>"; 
strOutput += "INTERNATIONAL:<BR><input type=radio name=\"ZONE\" value=\"5" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "USA/CANADA"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"6" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "NZ"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"7" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "ASIA/PACIFIC"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"8" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "EUROPE"; 
strOutput += "</TD>"; 
strOutput += "</TR></TABLE></TD></TR>"; 

document.write(strOutput); 
strOutput = ""; 

LocationSelected = GetCookie("ZoneSelected"); 
if (LocationSelected == null) LocationSelected = 99; // Code to use Local Area as default checked, but not needed because want null selected at this time ||
//if (LocationSelected != null) document.all.ZONE[LocationSelected].checked = true; 

if (LocationSelected != null) {
    var cLocations = document.getElementsByName('ZONE');
    for (var iCtr = 0; iCtr < cLocations.length; iCtr++) {
         if (cLocations[iCtr].value == LocationSelected) cLocations[iCtr].checked = true;
    }
}
if (LocationSelected == 0) LocationLabel = "TAS"; 
if (LocationSelected == 1) LocationLabel = "VIC"; 
if (LocationSelected == 2) LocationLabel = "NSW"; 
if (LocationSelected == 3) LocationLabel = "SA"; 
if (LocationSelected == 4) LocationLabel = "QLD/WA/NT"; 
if (LocationSelected == 5) LocationLabel = "USA/CANADA"; 
if (LocationSelected == 6) LocationLabel = "NZ"; 
if (LocationSelected == 7) LocationLabel = "ASIA/PACIFIC";  
if (LocationSelected == 8) LocationLabel = "EUROPE"; 
if (LocationSelected == 99) LocationLabel = '<font color="#FFFF00">Select Shipping Zone</font>';

if (fWeight == 0) fShipping = 0; 
else { 
	 fShipping = ComputeShipping(LocationSelected, fWeight); 
	 fFst += (fShipping * ShippingFSTaxRate);	// calculates FST for shipping charges
	 fTax += (fShipping * ShippingTaxRate);	 // calculates State Tax for shipping charges
}

strShipping = moneyFormat(fShipping); 
      strOutput += "<TR><TD align=\"right\" CLASS=\"noptotal\" COLSPAN=4><B>" + strSUB + "  &nbsp; </B></TD>";
      strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>" + MonetarySymbol + strTotal + "</B></TD><TD CLASS=\"noptotal\"><BR></TD>";
      strOutput += "</TR>";

strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 ALIGN=RIGHT><B>"+strWTOT+" &nbsp; </B></TD>"; 
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + fWeight.toFixed(3) + "</B></TD>"; 

strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=LEFT>&nbsp;<B> "+ WeightUnits +"</B></TD>"; 

strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 ALIGN=RIGHT><B>" + LocationLabel +"&nbsp; &nbsp;" + strSHIP + " &nbsp; </B></TD>"; 

strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + strShipping +"</B></TD><TD CLASS=\"noptotal\"><BR></TD>"; 
strOutput += "</TR>"; 
} 

// Don't display Federal Sales Tax Row if FST Rate zero
      if ( FstRate > 0 ) {
            strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 align=\"right\"><B>"+strFST+" &nbsp; </B></TD>";
            strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>"+ MonetarySymbol + strFst + "</B></TD><TD CLASS=\"noptotal\"><BR></TD>";
            strOutput += "</TR>";
				}		

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=2 ROWSPAN=2 align=\"right\"><B>"+strTAX+" &nbsp; &nbsp;</B></TD>";
            strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2><B>";
            strOutput += "<input type=radio name=\""+OutputOrderTax+"\" value=\"" + strTax + "\">";
            strOutput += TaxablePrompt + ":</B></TD><TD CLASS=\"noptotal\" ALIGN=\"right\"><B> " + MonetarySymbol + strTax + "</B></TD><TD CLASS=\"noptotal\"><BR></TD></TR>";
            strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=2><B><input type=radio name=\""+OutputOrderTax+"\" value=\"0.00\">";
            strOutput += NonTaxablePrompt + ":</B></TD><TD CLASS=\"noptotal\" ALIGN=\"right\"><B> " + MonetarySymbol + "0.00";
            strOutput += "</B></TD><TD CLASS=\"noptotal\"><BR></TD>";
            strOutput += "</TR>";
         } else {
            strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 align=\"right\"><B>"+strTAX+" &nbsp; </B></TD>";
            strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>" + MonetarySymbol + strTax + "</B></TD><TD CLASS=\"noptotal\"><BR></TD>";
            strOutput += "</TR>";
         }
      }

if (LocationSelected != 99) { //sets tax to 0.00 for all areas except 0 TAX INCLUDED. Original set to 0
fTax = 0.00;  
}
/*
if (LocationSelected == 99)  { // TAX INCLUDED. NO TAX NEEDED. Originally set to 0
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><B>"+strTAX+"</B></TD>"; 
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + strTax + strSpace +"</B></TD>"; 
strOutput += "</TR>"; 
} 
*/
      if ( !TaxByRegion ) {
         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 align=\"right\"><B>"+strTOT+" &nbsp; </B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fFst + fTax)) + "</B></TD><TD CLASS=\"noptotal\"><BR></TD>";
         strOutput += "</TR>";
// Optional Insurance
         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><B>OPTIONAL INSURANCE</B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>" + MonetarySymbol + moneyFormat(insure) + "</B></TD><TD>&nbsp;</TD>";
         strOutput += "</TR>";
      }
      strOutput += "</TABLE>";
      strOutput += "<input name=\"INSURE\" type=\"checkbox\" id=\"insurance\" value=\"included\">";
      strOutput += "Tick this box to <B>include OPTIONAL INSURANCE</B><br><BR>"; 

	 // ------------------- End of Cart 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=\""+OutputOrderFst+"\"      value=\""+ MonetarySymbol + strFst + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ moneyFormat((fTotal + fShipping + fFst + fTax)) + "\">"; //MonetarySymbol + 
         strOutput += "<input type=hidden name=\"Items\" value=\""+  iNumberOrdered + "\">";
		 strOutput += "<input type=hidden name=\"INSURANCE\" value=\""+  moneyFormat(insure) + "\">"; // OPTIONAL INSURANCE
      }
   }
   g_TotalCost = (fTotal + fShipping + fFst + fTax);

   document.write(strOutput);
   document.close();
}

//---------------------------------------------------------------------|| 
// FUNCTION: ComputeShipping                                           || 
// PARAMETERS: Zone, Total Weight                                      || 
// RETURNS:  Shipping Cost                                             || 
// PURPOSE: Compute shipping cost total weight and shipping zone       || 
//---------------------------------------------------------------------|| 
function ComputeShipping(Zone, TotWeight) {
	var pkg =0;
	LocationValue = GetCookie("ZoneSelected"); 
//	LocationValue = (+LocationValue); //convert LocationValue to number;
	
	if (LocationValue != Zone) { 
	SetCookie("ZoneSelected", Zone, null, "/"); 
	location.href=location.href; 
	} 
	// update to scripting for above 12kg, see below ( line 466).
	if (TotWeight >0 && TotWeight <= .025) {
		if (LocationValue >= 0 && LocationValue <= 4) return 2.5;
		if (LocationValue > 4 && LocationValue <= 8 ) return 3.5;
	}
	if (TotWeight >.025 && TotWeight <= .05) {
		if (LocationValue >= 0 && LocationValue <= 4) return 3.5;
		if (LocationValue > 4 && LocationValue <= 8 ) return 4.5;
	}
	if (TotWeight >.05 && TotWeight <= .25) {
		if (LocationValue >= 0 && LocationValue <= 4) return 5.00;
		if (LocationValue == 5 ) return 10.00;
		if (LocationValue == 6 ) return 8.00;
		if (LocationValue == 7 ) return 9.00;
		if (LocationValue == 8 ) return 12.00;
	}
	if (TotWeight >.25 && TotWeight <= .5) {
		if (LocationValue >= 0 && LocationValue <= 4) return 6.50;
		if (LocationValue == 5 ) return 17.00;
		if (LocationValue == 6 ) return 13.00;
		if (LocationValue == 7 ) return 16.00;
		if (LocationValue == 8 ) return 22.00;
	}
	if (TotWeight >.5 && TotWeight <= 1) {
		if (LocationValue == 0 ) return 9.00;
		if (LocationValue == 1 ) return 11.00;
		if (LocationValue == 2 ) return 12.00;
		if (LocationValue == 3 ) return 13.00;
		if (LocationValue == 4 ) return 14.00;
		if (LocationValue == 5 ) return 28.00;
		if (LocationValue == 6 ) return 22.00;
		if (LocationValue == 7 ) return 25.00;
		if (LocationValue == 8 ) return 35.00;
	}
	if (TotWeight >1 && TotWeight <= 1.5) {
		if (LocationValue == 0 ) return 9.50;
		if (LocationValue == 1 ) return 14.00;
		if (LocationValue == 2 ) return 16.00;
		if (LocationValue == 3 ) return 18.00;
		if (LocationValue == 4 ) return 20.00;
		if (LocationValue == 5 ) return 44.00;
		if (LocationValue == 6 ) return 30.00;
		if (LocationValue == 7 ) return 36.00;
		if (LocationValue == 8 ) return 54.00;
	}
	if (TotWeight >1.5 && TotWeight <= 2) {
		if (LocationValue == 0 ) return 10.00;
		if (LocationValue == 1 ) return 17.00;
		if (LocationValue == 2 ) return 20.00;
		if (LocationValue == 3 ) return 23.00;
		if (LocationValue == 4 ) return 26.00;
		if (LocationValue == 5 ) return 58.00;
		if (LocationValue == 6 ) return 39.00;
		if (LocationValue == 7 ) return 48.00;
		if (LocationValue == 8 ) return 73.00;
	}
	if (TotWeight >2 && TotWeight <= 3) {
		if (LocationValue == 0 ) return 11.00;
		if (LocationValue == 1 ) return 20.00;
		if (LocationValue == 2 ) return 24.00;
		if (LocationValue == 3 ) return 28.00;
		if (LocationValue == 4 ) return 32.00;
		if (LocationValue == 5 ) return 72.00;
		if (LocationValue == 6 ) return 47.00;
		if (LocationValue == 7 ) return 58.00;
		if (LocationValue == 8 ) return 89.00;
	}
	if (TotWeight >3 && TotWeight <= 4) {
		if (LocationValue == 0 ) return 12.00;
		if (LocationValue == 1 ) return 23.00;
		if (LocationValue == 2 ) return 28.00;
		if (LocationValue == 3 ) return 33.00;
		if (LocationValue == 4 ) return 38.00;
		if (LocationValue == 5 ) return 86.00;
		if (LocationValue == 6 ) return 55.00;
		if (LocationValue == 7 ) return 68.00;
		if (LocationValue == 8 ) return 107.00;
	}
	if (TotWeight >4 && TotWeight <= 5) {
		if (LocationValue == 0 ) return 13.00;
		if (LocationValue == 1 ) return 26.00;
		if (LocationValue == 2 ) return 32.00;
		if (LocationValue == 3 ) return 38.00;
		if (LocationValue == 4 ) return 44.00;
		if (LocationValue == 5 ) return 100.00;
		if (LocationValue == 6 ) return 63.00;
		if (LocationValue == 7 ) return 78.00;
		if (LocationValue == 8 ) return 125.00;
	}
	if (TotWeight >5 && TotWeight <= 6) {
		if (LocationValue == 0 ) return 14.00;
		if (LocationValue == 1 ) return 29.00;
		if (LocationValue == 2 ) return 36.00;
		if (LocationValue == 3 ) return 44.00;
		if (LocationValue == 4 ) return 50.00;
		if (LocationValue == 5 ) return 114.00;
		if (LocationValue == 6 ) return 69.00;
		if (LocationValue == 7 ) return 88.00;
		if (LocationValue == 8 ) return 143.00;
	}
	if (TotWeight >6 && TotWeight <= 7) {
		if (LocationValue == 0 ) return 15.00;
		if (LocationValue == 1 ) return 32.00;
		if (LocationValue == 2 ) return 40.00;
		if (LocationValue == 3 ) return 48.00;
		if (LocationValue == 4 ) return 56.00;
		if (LocationValue == 5 ) return 128.00;
		if (LocationValue == 6 ) return 77.00;
		if (LocationValue == 7 ) return 98.00;
		if (LocationValue == 8 ) return 161.00;
	}
	if (TotWeight >7 && TotWeight <= 8) {
		if (LocationValue == 0 ) return 16.00;
		if (LocationValue == 1 ) return 35.00;
		if (LocationValue == 2 ) return 44.00;
		if (LocationValue == 3 ) return 53.00;
		if (LocationValue == 4 ) return 62.00;
		if (LocationValue == 5 ) return 142.00;
		if (LocationValue == 6 ) return 85.00;
		if (LocationValue == 7 ) return 108.00;
		if (LocationValue == 8 ) return 179.00;
	}
	if (TotWeight >8 && TotWeight <= 9) {
		if (LocationValue == 0 ) return 17.00;
		if (LocationValue == 1 ) return 38.00;
		if (LocationValue == 2 ) return 48.00;
		if (LocationValue == 3 ) return 58.00;
		if (LocationValue == 4 ) return 68.00;
		if (LocationValue == 5 ) return 156.00;
		if (LocationValue == 6 ) return 93.00;
		if (LocationValue == 7 ) return 118.00;
		if (LocationValue == 8 ) return 197.00;
	}
	if (TotWeight >9 && TotWeight <= 10) {
		if (LocationValue == 0 ) return 18.00;
		if (LocationValue == 1 ) return 42.00;
		if (LocationValue == 2 ) return 52.00;
		if (LocationValue == 3 ) return 63.00;
		if (LocationValue == 4 ) return 74.00;
		if (LocationValue == 5 ) return 170.00;
		if (LocationValue == 6 ) return 101.00;
		if (LocationValue == 7 ) return 128.00;
		if (LocationValue == 8 ) return 215.00;
	}
	if (TotWeight >10 && TotWeight <= 11) {
		if (LocationValue == 0 ) return 19.00;
		if (LocationValue == 1 ) return 45.00;
		if (LocationValue == 2 ) return 56.00;
		if (LocationValue == 3 ) return 68.00;
		if (LocationValue == 4 ) return 80.00;
		if (LocationValue == 5 ) return 184.00;
		if (LocationValue == 6 ) return 109.00;
		if (LocationValue == 7 ) return 138.00;
		if (LocationValue == 8 ) return 233.00;
	}
	if (TotWeight >11 && TotWeight <= 12) {
		var postage = new Array(20,48,60,73,86,198,117,148,251);
		return postage[LocationValue];
	}
	if (TotWeight >12 && TotWeight <= 13) {
		var postage = new Array(21,51,64,78,92,212,125,158,269);
		return postage[LocationValue];
	}
	if (TotWeight >13 && TotWeight <= 14) {
		var postage = new Array(22,54,68,83,98,226,133,168,287);
		return postage[LocationValue];
	}
	if (TotWeight >14 && TotWeight <= 15) {
		var postage = new Array(23,57,72,88,104,240,141,178,305);
		return postage[LocationValue];
	}
	if (TotWeight >15 && TotWeight <= 16) {
		var postage = new Array(24,60,76,93,110,254,149,188,323);
		return postage[LocationValue];
	}
	if (TotWeight >16 && TotWeight <= 17) {
		var postage = new Array(25,63,80,98,116,268,157,198,341);
		return postage[LocationValue];
	} 
	if ( TotWeight > 17 ) {
		alert("Too much weight for one package, \nplease make two orders to calculate accurate postage.\n(max: 17kg)"); 
		return 350;
	}
	if (LocationValue == 99 ) return 2.50;
}
//---------------------------------------------------------------------||
// 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 ( isNaN (g_TotalCost) ) {
      alert( NoQtyPrompt );
      return false;
   }

   if ( MinimumOrder >= 0.01 ) {
      if ( g_TotalCost < MinimumOrder ) {
         alert( MinimumOrderPrompt );
         return false;
      }
   }

   if ( !RadioChecked(theForm.ZONE) ) {
      alert( LocationPrompt );
      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 fTotal         = 0;    //Total cost of order
	 var fprodttl       = 0; 		//Total product cost = QTY * PRICE
   var fFst           = 0;    //FST amount
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount  Set Flat Rate shipping cost here
	 var fWeight        = 0;		//Weight of items for shipping calculation 
	 var TotWeight      = 0;
   var strTotal       = "";   //Total cost formatted as money
   var strFst         = "";   //Total FST 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
	 var strProductId   = "";		//Used or non-taxable item identification
	     strAddInfo     = "";   // used to concatanate AdditionalInfo strings
	 
ReadCookie()

		if (iNumberOrdered  == null )
		    iNumberOrdered   = 0;
				 
// If Tax by Region get tax from checkout.html URL string
   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }

// ------------------- Cart Table Header -----------------------------------||
   if ( bDisplay )
	 		strOutput = 	"<TABLE CELLSPACING=0 CELLPADDING=2 WIDTH=610 BORDER=5 CLASS=\"nopcart\"><TR><TD>" +
	"<TABLE CELLSPACING=0 CELLPADDING=0 WIDTH=100% BORDER=0 CLASS=\"nopcart\"><TR>" +			
"<TD WIDTH=55 CLASS=\"nopheader\"><strong>"+strILabel+"</strong></TD>" +			
"<TD ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strDLabel+"</strong></TD>" +			
"<TD WIDTH=30 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strQLabel+"</strong></TD>" +			"<TD WIDTH=55 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strPLabel+"</strong></TD>";
if ( DisplayShippingColumn ) { strOutput += 
"<TD WIDTH=60 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strSLabel+"</strong></TD>";
} else { strOutput += 
"<TD WIDTH=60 ALIGN=\"center\" CLASS=\"nopheader\"><strong>"+strPTLabel+"</strong></TD>";}
strOutput += "</TR>";

   for ( i = 1; i <= iNumberOrdered; i++ ) {
	 		even = (i & 1);

      fprodttl    = (parseInt(ItemQuantity[i]) * parseFloat(ItemPrice[i]) );
      fTotal     += (parseInt(ItemQuantity[i]) * parseFloat(ItemPrice[i]) );
      fWeight    += (parseInt(ItemQuantity[i]) * parseFloat(ItemWeight[i]) );
      fShipping  += (parseInt(ItemQuantity[i]) * parseFloat(ItemShipping[i]) );
     if(ItemFsTx[i] == 'true'){ 
      fFst       += ((fprodttl) * FstRate); }

if ( !TaxByRegion ) 
     if(ItemPsTx[i] == true){ 
         fTax += (parseInt(ItemQuantity[i]) * parseFloat(ItemPrice[i])) * TaxRate; 
      } 
      strAddInfo  =	"";
      strTotal    = moneyFormat(fTotal);
			strFst      = moneyFormat(fFst);
      if ( !TaxByRegion ) strTax = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

// ------------------- Cart Table Body -----------------------------------||

      if ( bDisplay ) {
			      if (even ^ 1 ) {
    strOutput += "<TR><TD CLASS=\"nopeven\">"  + ItemId[i] + "</TD>";

    strOutput += "<TD CLASS=\"nopeven\">"  + ItemName[i] + " - <I>";
         if ( ItemAddtlInfo[i]  != "" ) strAddInfo  =  ItemAddtlInfo[i];
				 if ( ItemAddtlInfo2[i] != "" ) strAddInfo +=  ItemAddtlInfo2[i];
				 if ( ItemAddtlInfo3[i] != "" ) strAddInfo +=  ItemAddtlInfo3[i];
				 if ( ItemUserEntry[i]  != "" ) strAddInfo +=  ItemUserEntry[i];
				 if ( ItemUserEntry2[i] != "" ) strAddInfo +=  ItemUserEntry2[i];
    strOutput += strAddInfo + "</I></TD>";

    strOutput += "<TD CLASS=\"nopeven\">" + ItemQuantity[i] + "</TD>";
    strOutput += "<TD CLASS=\"nopeven\">"+ MonetarySymbol + moneyFormat(ItemPrice[i]) + "</TD>";

// Display either shipping or extended price in this column
         if ( DisplayShippingColumn ) {
            if ( parseFloat(ItemShipping[i]) > 0 )
    strOutput += "<TD CLASS=\"nopeven\">"+ MonetarySymbol + moneyFormat(ItemShipping[i]) + "/ea</TD>";
            else
    strOutput += "<TD CLASS=\"nopeven\" ALIGN=\"center\">N/A</TD>";
         }
	else {
		strOutput += "<TD ALIGN=RIGHT CLASS=\"nopeven\">"+ MonetarySymbol + moneyFormat(fprodttl) + " &nbsp; </TD>";
         }
    strOutput += "</TR>";
      
// repeat odd
} else {			
      if ( bDisplay ) {
         strOutput += "<TR><TD CLASS=\"nopentry\">"  + ItemId[i] + "</TD>";

    strOutput += "<TD CLASS=\"nopentry\">"  + ItemName[i] + " - <I>";
         if ( ItemAddtlInfo[i]  != "" ) strAddInfo  =  ItemAddtlInfo[i];
				 if ( ItemAddtlInfo2[i] != "" ) strAddInfo +=  ItemAddtlInfo2[i];
				 if ( ItemAddtlInfo3[i] != "" ) strAddInfo +=  ItemAddtlInfo3[i];
				 if ( ItemUserEntry[i]  != "" ) strAddInfo +=  ItemUserEntry[i];
				 if ( ItemUserEntry2[i] != "" ) strAddInfo +=  ItemUserEntry2[i];
    strOutput += strAddInfo + "</I></TD>";

         strOutput += "<TD CLASS=\"nopentry\">" + ItemQuantity[i] + "</TD>";
         strOutput += "<TD CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(ItemPrice[i]) + "</TD>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(ItemShipping[i]) > 0 )
               strOutput += "<TD CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(ItemShipping[i]) + "/ea</TD>";
            else
               strOutput += "<TD CLASS=\"nopentry\" ALIGN=\"center\">N/A</TD>";
         } else {
		strOutput += "<TD ALIGN=RIGHT CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(fprodttl) + " &nbsp; </TD>";
         }
         strOutput += "</TR>";
     }
  }		
}			
// calculate Tax on Shipping
	 fFst += (fShipping * ShippingFSTaxRate);	// calculates FST for shipping charges
   if ( !TaxByRegion ) {
	 fTax += (fShipping * ShippingTaxRate);	 // calculates State Tax for shipping charges
}		

// ------------------- End of Cart Table Body -----------------------------------||

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
// ----------Concatanate items for PPs or format email using Mailto form action--|| 
      if ( PaymentProcessor != '' ) {
         //Process description field for payment processors instead of hidden values.
         //Format Description of product as:
         // ID, Name, Qty X
         strPP += ItemId[i] + ", " + ItemName[i];
         if ( strAddInfo != "" )
            strPP += " - " + strAddInfo;
         strPP += ", Qty. " + ItemQuantity[i] + "\n";
      } else {
//       	       strOutput += "<input type=hidden name=\""  + OutputItemId +  strFooter + '  PLU=' + ItemId[i] + strSpace + OutputItemQuantity  + '=' + ItemQuantity[i] + strSpace + ItemName[i] + strSpace + strAddInfo + strSpace + MonetarySymbol + ItemPrice[i] + "\n" + "\n" + "\">";
			   
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + ItemId[i] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + ItemQuantity[i] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + moneyFormat(ItemPrice[i]) + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + ItemName[i] + "\">";
//         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + ItemWeight[i] + "grams\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + strAddInfo + "\">";

      } 
   }

	 // ------------------- Cart Table Footer -----------------------------------||

			
   if ( bDisplay ) {
      strOutput += "<TR><TD align=\"right\" CLASS=\"noptotal\" COLSPAN=4><B>"+strSUB+"  &nbsp; </B></TD>";
      strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>" + MonetarySymbol + strTotal + " &nbsp; </B></TD>";
      strOutput += "</TR>";

		if ( DisplayShippingRow ) { 
LocationSelected = GetCookie("ZoneSelected"); 
if (LocationSelected == null) LocationSelected = 0; //Needed if checkout cart is empty

if (LocationSelected == 0) LocationLabel = "Zone 1"; 
if (LocationSelected == 1) LocationLabel = "Zone 2"; 
if (LocationSelected == 2) LocationLabel = "Zone 3"; 
if (LocationSelected == 3) LocationLabel = "Zone 4"; 
if (LocationSelected == 4) LocationLabel = "Zone 5"; 
if (LocationSelected == 5) LocationLabel = "Zone 6"; 
if (LocationSelected == 6) LocationLabel = "Zone 7"; 
if (LocationSelected == 7) LocationLabel = "Zone G"; 
if (LocationSelected == 8) LocationLabel = "Zone"; 

         fShipping   = ComputeShipping(LocationSelected, fWeight); 
         strShipping = moneyFormat(fShipping); 
         strOutput  += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 align=\"right\"><B>"+strSHIP+"  &nbsp; </B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>" + MonetarySymbol + strShipping + " &nbsp; </B></TD>";
         strOutput += "</TR>";
      }


      if ( FstRate > 0 ) {
            strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 align=\"right\"><B>"+strFST+" &nbsp; </B></TD>";
            strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>"+ MonetarySymbol + strFst + " &nbsp; </B></TD>";
            strOutput += "</TR>";
				}		

      if ( DisplayTaxRow || TaxByRegion ) {
         strOutput += "<TR><TD align=\"right\" CLASS=\"noptotal\" COLSPAN=4><B>"+strTAX+" &nbsp; </B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" ALIGN=RIGHT><B>" + MonetarySymbol + strTax + " &nbsp; </B></TD>";
         strOutput += "</TR>";
      }
if (LocationSelected != 0) //sets tax to 0.00 for all other areas ||
fTax = 0.00; 

if (LocationSelected == 0)  { 
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strTAX+"</B></TD>"; 
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=RIGHT><B>" + MonetarySymbol + strTax + "</B></TD>"; 
strOutput += "</TR>"; 
}
			
      strOutput += "<TR><TD align=\"right\" CLASS=\"noptotal\" COLSPAN=4><B>"+strTOT+" &nbsp; </B></TD>";
      strOutput += "<TD CLASS=\"noptotal\" ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fFst + fTax)) + " &nbsp; </B></TD>";
      strOutput += "</TR>";
      strOutput += "</TABLE> </TD></TR></TABLE>";
// -----------------------End of Cart Table --------------------------------||
      

if ( PaymentProcessor == 'an') { 
//Process this for Authorize.net WebConnect 
strOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">"; 
strOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">"; 
strOutput += "<input type=hidden name=\"x_Description\" value=\""+ strPP + "\">"; 
strOutput += "<input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">"; 
} else if ( PaymentProcessor == 'wp') { 
//Process this for WorldPay 
strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">"; 
strOutput += "<input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">"; 
} else if ( PaymentProcessor == 'lp') { 
//Process this for LinkPoint 
strOutput += "<input type=hidden name=\"mode\" value=\"fullpay\">"; 
strOutput += "<input type=hidden name=\"chargetotal\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">"; 
strOutput += "<input type=hidden name=\"tax\" value=\""+ MonetarySymbol + strTax + "\">"; 
strOutput += "<input type=hidden name=\"subtotal\" value=\""+ MonetarySymbol + strTotal + "\">"; 
strOutput += "<input type=hidden name=\"shipping\" value=\""+ MonetarySymbol + strShipping + "\">"; 
strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">"; 
} else if (LocationSelected != 0){ 
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 + "0.00" + "\">"; 
strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\" value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">"; 
strOutput += "<input type=hidden name=\""+OutputOrderZone+"\" value=\""+ LocationLabel + "\">";
strOutput += "<input type=hidden name=\"Items\" value=\"" + iNumberOrdered + "\">";  
} 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 += "<input type=hidden name=\""+OutputOrderZone+"\" value=\""+ LocationLabel + "\">"; 
   } 
}

   document.write(strOutput);
   document.close();
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||


