//=====================================================================||
//               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               ||
//             Regular Post Charges SHIPPING BY WEIGHT & ZONE          ||
//                    fee/Kg or part thereof by zone.                  ||
//=====================================================================||
//
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     = ""; 
ReadCookie();

// ------------------- Cart Table Header -----------------------------------||
   if ( bDisplay )
	 		strOutput = 
"<TABLE CELLSPACING=0 CELLPADDING=0 CLASS=\"nopcart\"><TR>" +			
"<TD WIDTH=100 CLASS=\"nopheader\" ALIGN=\"center\"><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  =	"";
// ------------------- Cart Table Body -----------------------------------||
			
if ( bDisplay ){
     if (even ^ 1 ) {
		strOutput += "<TR CLASS=\"tblpadding5\"><TD CLASS=\"nopeven\" ALIGN=\"center\">" + 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] + "g/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=\"center\">" + 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] + "g/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] + "\">"; 
         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>"+"AUSTRALIA POST<BR>ZONES"+"</B><br>See below for your zone.</TD>"; 
strOutput += "<TD CLASS=\"nopship\" COLSPAN=1>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"2" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "V1 - VIC"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"3" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "V2 - VIC"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"0" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "N1 - NSW"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"1" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "N2 - NSW"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"4" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "Q1 - QLD"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"5" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "Q2 - QLD"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"6" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "Q3 - QLD"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"7" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "Q4 - QLD"; 
strOutput += "</TD>"; 
strOutput += "<TD CLASS=\"nopship\" COLSPAN=1>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"14" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "T1 - TAS"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"8" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "S1 - SA"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"9" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "S2 - SA"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"10" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "NT1 - NT"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"11" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "W1 - WA"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"12" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "W2 - WA"; 
strOutput += "<BR><input type=radio name=\"ZONE\" value=\"13" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
strOutput += "W3 - WA"; 
strOutput += "<BR>"; //<input type=radio name=\"ZONE\" value=\"15" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">"; 
//strOutput += "NF - Nolfolk Island"; 
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 = "N1"; 
if (LocationSelected == 1) LocationLabel = "N2"; 
if (LocationSelected == 2) LocationLabel = "V1"; 
if (LocationSelected == 3) LocationLabel = "V2"; 
if (LocationSelected == 4) LocationLabel = "Q1"; 
if (LocationSelected == 5) LocationLabel = "Q2"; 
if (LocationSelected == 6) LocationLabel = "Q3"; 
if (LocationSelected == 7) LocationLabel = "Q4";  
if (LocationSelected == 8) LocationLabel = "S1"; 
if (LocationSelected == 9) LocationLabel = "S2"; 
if (LocationSelected == 10) LocationLabel = "NT1"; 
if (LocationSelected == 11) LocationLabel = "W1"; 
if (LocationSelected == 12) LocationLabel = "W2"; 
if (LocationSelected == 13) LocationLabel = "W3"; 
if (LocationSelected == 14) LocationLabel = "T1"; 
if (LocationSelected == 15) LocationLabel = "NF"; 
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 + "</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>";
      }
      strOutput += "</TABLE>";

	 // ------------------- 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=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fFst + fTax)) + "\">";
		 strOutput += "<input type=hidden name=\"Items\" value=\"" + iNumberOrdered + "\">";  
      }
   }
   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 parcels =0;
	LocationValue = GetCookie("ZoneSelected"); 
	
	if (LocationValue != Zone) { 
	SetCookie("ZoneSelected", Zone, null, "/"); 
	location.href=location.href; 
	} 
	TotWeight /= 1000;
	if (TotWeight == 0) return 0.00; 
	if (TotWeight <= 0.25) return 4.2;
	if (TotWeight <= 0.5) return 5.4;
	if (TotWeight > 0.5 && TotWeight < 20) { 
		
//		parcels = Math.ceil(TotWeight/20);
		TotWeight = Math.ceil(parseFloat(TotWeight)); // Round up the weight to whole KG
//		alert(parcels);
		baseRate = 9.05;
//		alert(baseRate);
		if (LocationValue == 14 ) baseRate = 7.2; // TAS
		if (LocationValue == 15 ) baseRate = 7.95; //Norfolk Island
//		baseRate *= parcels;
// add a switch here for a variable to take the multiplier then you only need one equation. convert above to switch.
		multiplier = 2.95;
		switch(LocationValue)
		{
			case "0":	  multiplier = 1.80;	break;   //N1
			case "1":	  multiplier = 1.95;	break;   //N2
			case "2":	  multiplier = 0.75;	break;   //V1
			case "3":	  multiplier = 1.30;	break;   //V2
			case "4":	  multiplier = 2.45;	break;   //Q1
			case "5":	  multiplier = 2.85;	break;   //Q2
			case "6":	  multiplier = 2.95;	break;   //Q3
			case "7":	  multiplier = 3.05;	break;   //Q4
			case "8":	  multiplier = 1.85;	break;   //S1
			case "9":	  multiplier = 2.50;	break;   //S2
			case "10":	  multiplier = 2.90;	break;   //NT1
			case "11":	  multiplier = 2.50;	break;   //W1
			case "12":	  multiplier = 2.90;	break;   //W2
			case "13":	  multiplier = 3.00;	break;   //W3
			case "14":	  multiplier = 0.35;	break;   //T1
			case "15":	  multiplier = 3.85;	break;   //NF1
		default:
			multiplier = 3.85;
		}
//		confirm(multiplier +" | "+ LocationValue +" | "+ baseRate +" | "+  TotWeight);
		return (baseRate + (multiplier * TotWeight)); 
	} else {
		alert('Weight exceeds 20kg.\n Please make multiple orders or email for a quote!');
		return("nil");
	}
}
//---------------------------------------------------------------------||
// 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                ||
//=====================================================================||



