//=====================================================================||
//               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                                     ||
//=====================================================================||
//                     CART MANAGEMENT MODULE                          ||
//                   SHIPPING BY ZONE & Qty of Items                   ||
//       Shipment is split into packages weighing 500 lbs or less      ||
//=====================================================================||
//
OutputOrderZone = "ZONE"
// Edit Shipping Zones: 175 - 192, 210 - 217 ManageCart, 558 - 565 Checkout. 
// Formular: 300 ComputeShipping
//---------------------------------------------------------------------||
// 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.00;    //Shipping amount--set flatrate shipping here   
   	var spShipping     = 0;		// Debbie Modification for packs shipping $1 single $5 packs used as multiplier
	var fWeight        = 0;		//Weight of items for shipping calculation 
	var discount       = 1;		//0 = no discount, 1 = dicount included. 
	var reduction      = 0;
	var fItems         = 0;    // Sum of item Quantities
	var LocationSelected = 99;
	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
       strAddInfo      =	""; 
ReadCookie();

// ------------------- Cart Table Header -----------------------------------||
   if ( bDisplay )
	 		strOutput = 
"<TABLE CELLSPACING=0 CELLPADDING=0 WIDTH=100% BORDER=0 CLASS=\"nopcart\"><TR>" +			
"<TD WIDTH=1 CLASS=\"nopheader\" style=\"padding-left: 5px\"><strong>&nbsp;</strong></TD>" +	//"+strILabel+"		
"<TD ALIGN=\"LEFT\" CLASS=\"nopheader\" style=\"padding-left: 10px\"><strong>"+strDLabel+"</strong></TD>" +			
"<TD WIDTH=30 ALIGN=\"LEFT\" CLASS=\"nopheader\"><strong>"+strQLabel+"</strong></TD>" +			
"<TD WIDTH=60 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=55 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);
      fItems        += (parseInt(ItemQuantity[i]));
      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 VALIGN=MIDDLE CLASS=\"tblpadding5\"><TD CLASS=\"nopeven\" style=\"padding-left: 5px\">&nbsp;</TD>";//" + ItemId[i] + "
    strOutput += "<TD CLASS=\"nopeven\" style=\"padding-left: 10px\">"  + 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\"><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + ItemQuantity[i] + "\" onChange=\"this.value=ChangeQuantity("+i+",this.value);\"></TD>";
         strOutput += "<TD ALIGN=CENTER CLASS=\"nopeven\">"+ MonetarySymbol + moneyFormat(ItemPrice[i]) + "</TD>";

// Either display Shipping Column or extended price 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=CENTER 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 VALIGN=MIDDLE CLASS=\"tblpadding5\"><TD CLASS=\"nopentry\" style=\"padding-left: 5px\">&nbsp;</TD>";//" + ItemId[i] + "
    strOutput += "<TD CLASS=\"nopentry\" style=\"padding-left: 10px\">"  + 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\"><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + ItemQuantity[i] + "\" onChange=\"this.value=ChangeQuantity("+i+",this.value);\"></TD>";
         strOutput += "<TD ALIGN=CENTER CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(ItemPrice[i]) + "</TD>";

// Either display Shipping Column or extended price column
         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=CENTER 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 -----------------------------------||
			
//alert(fItems);
//extra = fItems%6;
//more = 6 - extra;
//confirm(extra);
//if ((fItems%6) != 0) alert("Sales can only be finalized in lots of 6 bottles. \nYou currently have " + fItems + " bottles. \nPlease adjust quantities or add " + more + " more bottles, or remove " + extra + " bottles");
   if ( bDisplay ) {
      strOutput += "<TR><TD align=\"right\" CLASS=\"ni\" COLSPAN=6><div style=\"height: 1px;\"></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\" ALIGN=CENTER width=35%><B>"+"POSTAL<BR>ZONE"+"</B></TD>"; 
strOutput += "<TD CLASS=\"nopship\" width=30%>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"0" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "TAS<br>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"1" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "VIC<br>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"2" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "NSW, ACT, SA<BR>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"3" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "QLD, WA<br>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"4" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "NT</td><td class=\"nopship\">"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"5" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "NEW ZEALALND<br>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"6" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "ASIA PACIFIC<br>"; 
strOutput += "<input type=radio name=\"ZONE\" value=\"7" + "\" onClick=\"ComputeShipping(this.value, "+fItems+")\">"; 
strOutput += "WORLDWIDE<br>"; 

strOutput += "</TD>"; 
strOutput += "</TR></TABLE></TD></TR>"; 
} 

document.write(strOutput); 
strOutput = ""; 

LocationSelected = GetCookie("ZoneSelected"); 
if (LocationSelected == null) LocationSelected = 99; 

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, SA, ACT"; 
if (LocationSelected ==  3) LocationLabel = "QLD, WA"; 
if (LocationSelected ==  4) LocationLabel = "NT";
if (LocationSelected ==  5) LocationLabel = "NZ";
if (LocationSelected ==  6) LocationLabel = "Asia Pacific";
if (LocationSelected ==  7) LocationLabel = "worldwide";

if (LocationSelected == 99) LocationLabel = '<font color="#FF0000">Select Shipping Zone</font>';

	 spShipping = fShipping;
	 fShipping = ComputeShipping(LocationSelected, fItems); // fItems swapped for total shipping
	 fFst += (fShipping * ShippingFSTaxRate);	// calculates FST for shipping charges
	 fTax += (fShipping * ShippingTaxRate);	 // calculates State Tax for shipping charges

      strTotal    = moneyFormat(fTotal);
      strFst      = moneyFormat(fFst);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);//  * fItems mod Debbie
	 
      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>";

// Don't display Weight Row if Weight is zero
      if ( fWeight > 0 ) {
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></tr>"; 
	}

// #########  DISCOUNT  #################################################################
percentage = 0;
if ( discount > 0 ) {
	if (fItems >5) percentage = 0.05;
	if (fItems >11) percentage = 0.1;
	reduction = fTotal * percentage;
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 ALIGN=RIGHT><B>DISCOUNT &nbsp; </B></TD>"; 
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + "-" + moneyFormat(reduction) + "</B></TD>"; 

strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=LEFT>&nbsp;</TD></tr>"; 
	}
//###########################################################################################

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 ( !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 - reduction)) + "</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 - reduction)) + "\">";
         strOutput += "<input type=hidden name=\"Items\" value=\""+  iNumberOrdered + "\">";
      } 
   }
   g_TotalCost = (fTotal + fShipping + fFst + fTax);

   document.write(strOutput);
   document.close();

 } 
 
//---------------------------------------------------------------------|| 
// FUNCTION: ComputeShipping                                           || 
// PARAMETERS: Zone, Total Quantity                                    || 
// RETURNS:  Shipping Cost                                             || 
// PURPOSE: Compute shipping cost total Qty and shipping zone          || 
//---------------------------------------------------------------------|| 
function ComputeShipping(Zone, NoQty) {
LocationValue = GetCookie("ZoneSelected"); 

if (LocationValue != Zone) { 
SetCookie("ZoneSelected", Zone, null, "/"); 
location.href=location.href; 
	}
	 
var ItemQty = parseInt(NoQty); //Total number of items ordered (products * Qty)
if (LocationValue == 0 ){
  var ship =  (ItemQty * 0.00);	// TAS
  return (ship);
}
if (LocationValue == 1){ // VIC
	 switch (ItemQty) {
		 case 6: return (7);
		 case 12: return (10);
		 case 18: return (17);
		 case 24: return (20);
		 default: return (ItemQty/12 * 10);
	 }
}
if (LocationValue == 2 ){ // NSW,ACT, SA
	 switch (ItemQty) {
		 case 6: return (10);
		 case 12: return (15);
		 case 18: return (25);
		 case 24: return (30);
		 default: return (ItemQty/12 * 15);
	 }
}
if (LocationValue == 3 ){ // WA, QLD
	 switch (ItemQty) {
		 case 6: return (15);
		 case 12: return (20);
		 case 18: return (35);
		 case 24: return (40);
		 default: return (ItemQty/12 * 20);
	 }
}
if (LocationValue == 4 ){	// NT
	 switch (ItemQty) {
		 case 6: return (20);
		 case 12: return (30);
		 case 18: return (45);
		 case 24: return (60);
		 default: return (ItemQty/12 * 30);
	 }
}
if (LocationValue == 5 ){
  var ship =  (ItemQty/12 * 70.00);	    // NZ
  return (ship);
}
if (LocationValue == 6 ){
  var ship =  (ItemQty/12 * 130.00);	// AP
  return (ship);
}
if (LocationValue == 7 ){
  var ship =  (ItemQty/12 * 230.00);	// WW
  return (ship);
}
if (LocationValue == 99 ) return 0.00; 
	 
}

//---------------------------------------------------------------------||
// 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(g_TotalCost+ MinimumOrderPrompt );
         return false;
      }
   }

   if ( !RadioChecked(theForm.ZONE) ) {
      alert( LocationPrompt );
      return false;
   }
   
   var fItems = 0;
   var looseitems = 0;
   ReadCookie();
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      	fItems        += (parseInt(ItemQuantity[i]));
   }   
    looseItems = fItems %6;
//   alert (looseItems);
LocationValue = GetCookie("ZoneSelected");
	if ((LocationValue > 4 ) && ((fItems %12) != 0)) {
		alert('International orders must be in dozens');
		return false;
	}else{
		if (looseItems != 0){
		 alert( 'Please order in half dozen lots.\nCurrently you have ' +fItems + ' bottles.\nPlease order ' +  (6 - looseItems) + ' more bottles, \nor remove ' + looseItems + ' bottles.');
		 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 fItems         = 0;    // Sum of item Quantities
	 var LocationSelected = 99;
	 var LocationLabel  = "";
   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=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]) );
      fItems     += (parseInt(ItemQuantity[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];
         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\">" + 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];
         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\">" + 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>";
     }
  }		
}			

// ------------------- 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+ "=" + 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 ) {
      strTotal    = moneyFormat(fTotal);
      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 = "LAUNCESTON"; 
if (LocationSelected ==  1) LocationLabel = "TASMANIA"; 
if (LocationSelected ==  2) LocationLabel = "VICTORIA"; 
if (LocationSelected ==  3) LocationLabel = "NEW SOUTH WALES"; 
if (LocationSelected ==  4) LocationLabel = "QUEENSLAND"; 
if (LocationSelected ==  5) LocationLabel = "SOUTH AUSTRALIA";
if (LocationSelected ==  6) LocationLabel = "NORTHERN TERRITORY";  
if (LocationSelected ==  7) LocationLabel = "WESTERN AUSTRALIA";
 
if (LocationSelected == 99) LocationLabel = "Zone"; 


	 fShipping = ComputeShipping(LocationSelected, fItems); 
	 fFst += (fShipping * ShippingFSTaxRate);	// calculates FST for shipping charges
   if ( !TaxByRegion ) {
	 fTax += (fShipping * ShippingTaxRate);	 // calculates State Tax for shipping charges
	}		
   strShipping = moneyFormat(fShipping);

	
			strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4 ALIGN=RIGHT><B>" + LocationLabel +"&nbsp; &nbsp;" + strSHIP + " &nbsp; </B></TD>"; 

      strOutput += "<TD CLASS=\"noptotal\" ALIGN=\"right\"><B>" + MonetarySymbol + strShipping + " &nbsp; </B></TD>";
         strOutput += "</TR>";
      }


      if ( FstRate > 0 ) {
						strFst      = moneyFormat(fFst);
            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>";
      }

			
      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>";
// -----------------------End of Cart Table --------------------------------||
      
if ( PaymentProcessor == 'pp') { 
//Process this for paypal.com WebConnect 
strOutput += "<input type=hidden name=\"cmd\" value=\"_xclick\">"; 
strOutput += "<input type=hidden name=\"business\" value=\"info@partysurprise.com.au\">"; 
strOutput += "<input type=hidden name=\"currency_code\" value=\"AUD\">"; 
strOutput += "<input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">"; 
} else 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                ||
//=====================================================================||


