// NOP Design JavaScript Shopping Cart (http://www.nopdesign.com)
// UPS Shipping Mod by Stefko V.1.0.0
// Modified further by Johan Van Loon 29/10/2003-2009
//=====================================================================

var delBL='2-3';
var delBLL='3';
var delET='2-3';
var delHA='2-3';
var delPM='3-4';
var delPP='2-3';
var delTP='2-3';
var delTPL='4-5';

var delPRV='2';
var delST='2';

var delPZ='5-6';
var delRE='5-6';

var levTermFR="Disponibilité habituelle, dès la réception de votre paiement.";

var levTermNL="Gebruikelijke termijn, na ontvangst van uw betaling.";

MaxArt                     = 6; // maximum number of articles

//Nopcart Options:
DisplayNotice              = false; //directly to shopping cart
DisplayShippingColumn      = true;
DisplayShippingRow         = true;
DisplayTaxRow              = false;
MinimumOrder               = 8.00;
MonetarySymbol             = '';
NonTaxablePrompt           = 'Other Branches';
TaxablePrompt              = 'Branch';
TaxByRegion                = false; //leave this a false
TaxPrompt                  = 'For tax purposes, please select if you are an * branch of * before continuing';
TaxRate                    = 0.00; //set taxable region rate

//Payment Processor Options:
PaymentProcessor = '';

//Options for Programmers:
OutputItemId               = 'ref_';
OutputItemQuantity         = 'qty_';
OutputItemPrice            = 'prc_';
OutputItemName             = 'art_';
OutputItemWeight           = 'WEIGHT_'; //Added for UPS mod
OutputItemPage             = 'page_';
OutputItemPict             = 'pict_';
OutputItemLang             = 'lang_';
OutputItemDelTime          = 'del_';
OutputItemAddtlInfo        = 'lev_';

OutputOrderShipping        = 'port';
OutputOrderSubtotal        = 'subt';
OutputOrderTax             = 'supp';
OutputOrderTotal           = 'total';
AppendItemNumToOutput      = true;
HiddenFieldsToCheckout     = true;

//Options for Shipping by Weight:
LocationLabel = 'ZONE';
LocationPrompt = 'For shipping purpose, please select the zone that your country is in.';
MaxWeightPrompt = 'Sorry, maximum weight allowable is 500 kg.';

//=====================================================================
// FUNCTION: CKquantity
// PARAMETERS: Quantity to
// RETURNS: Quantity as a number, and possible alert
// PURPOSE: Make sure quantity is represented as a number
//=====================================================================

function CKquantity(checkString) {
var strNewQuantity = "";

for ( i = 0; i < checkString.length; i++ ) {
ch = checkString.substring(i, i+1);
if ( (ch >= "0" && ch <= "9") || (ch == '.') )
strNewQuantity += ch;
}

if ( strNewQuantity.length < 1 )
strNewQuantity = "1";

return(strNewQuantity);
}

//=====================================================================
// FUNCTION: AddToCart
// PARAMETERS: Form Object
// RETURNS: Cookie to user's browser, with prompt
// PURPOSE: Adds a product to the user's shopping cart
// EXTRAS ADDED IN: USERENTRY for customer text input
//=====================================================================

function AddToCart(thisForm) {
var iNumberOrdered = 0;
var bAlreadyInCart = false;
var notice = "";
iNumberOrdered = GetCookie("NumberOrdered");

if ( iNumberOrdered == null )
iNumberOrdered = 0;

if ( thisForm.ID_NUM == null )
strID_NUM = "";
else
strID_NUM = thisForm.ID_NUM.value;

if ( thisForm.QUANTITY == null )
strQUANTITY = "1";
else
strQUANTITY = thisForm.QUANTITY.value;

if ( thisForm.PRICE == null )
strPRICE = "0.00";
else
strPRICE = thisForm.PRICE.value;

if ( thisForm.NAME == null )
strNAME = "";
else
strNAME = thisForm.NAME.value;

if ( thisForm.PAGE == null )
strPAGE = "";
else
strPAGE = thisForm.PAGE.value;

if ( thisForm.PICT == null )
strPICT = "";
else
strPICT = thisForm.PICT.value;

if ( thisForm.LANG== null )
strLANG = "";
else
strLANG = thisForm.LANG.value;

if ( thisForm.DELTIME== null )
strDELTIME = "";
else
strDELTIME = thisForm.DELTIME.value;

if ( thisForm.WEIGHT == null ) //Added for UPS mod ||
strSHIPPING = "0";
else
strSHIPPING = thisForm.WEIGHT.value;

if ( thisForm.ADDITIONALINFO == null ) {
       strADDTLINFO = "";
    } else {
       strADDTLINFO = thisForm.ADDITIONALINFO.value;
    }
if ( thisForm.ADDITIONALINFO2 != null ) {
strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
}
if ( thisForm.ADDITIONALINFO3 != null ) {
strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
}
if ( thisForm.ADDITIONALINFO4 != null ) {
strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
}
if ( thisForm.USERENTRY != null ) {
strADDTLINFO += "; " + thisForm.USERENTRY.value;
}
if ( thisForm.USERENTRY2 != null ) {
strADDTLINFO += "; " + thisForm.USERENTRY2.value;
}
if ( thisForm.USERENTRY3 != null ) {
strADDTLINFO += "; " + thisForm.USERENTRY3.value;
}

//Is this product already in the cart? -> procedure deleted

iNumberOrdered++;

if ( iNumberOrdered > MaxArt )
alert( strSorry );
else {
dbUpdatedOrder = strID_NUM + "|" +
strQUANTITY + "|" +
strPRICE + "|" +
strNAME + "|" +
strSHIPPING + "|" +
strPAGE + "|" +
strPICT + "|" +
strLANG + "|" +
strDELTIME + "|" +
strADDTLINFO;

strNewOrder = "Order." + iNumberOrdered;
SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
SetCookie("NumberOrdered", iNumberOrdered, null, "/");
notice = strQUANTITY + strAdded1 + strNAME + strAdded2;
}

if ( DisplayNotice && notice!=''){
alert(notice);
}else{
}
}

//=====================================================================
// FUNCTION: getCookieVal
// PARAMETERS: offset
// RETURNS: URL unescaped Cookie Value
// PURPOSE: Get a specific value from a cookie
//=====================================================================

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);

if ( endstr == -1 )
endstr = document.cookie.length;
return(unescape(document.cookie.substring(offset, endstr)));
}

//=====================================================================
// FUNCTION: FixCookieDate
// PARAMETERS: date
// RETURNS: date
// PURPOSE: Fixes cookie date, stores back in date
//=====================================================================

function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime();

date.setTime (date.getTime() - skew);
}

//=====================================================================
// FUNCTION: GetCookie
// PARAMETERS: Name
// RETURNS: Value in Cookie
// PURPOSE: Retrieves cookie from users browser
//=====================================================================

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;

while ( i < clen ) {
var j = i + alen;
if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
i = document.cookie.indexOf(" ", i) + 1;
if ( i == 0 ) break;
}

return(null);
}

//=====================================================================
// FUNCTION: SetCookie
// PARAMETERS: name, value, expiration date, path, domain, security
// RETURNS: Null
// PURPOSE: Stores a cookie in the users browser
//=====================================================================

function SetCookie (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

//=====================================================================
// FUNCTION: DeleteCookie
// PARAMETERS: Cookie name, path, domain
// RETURNS: null
// PURPOSE: Removes a cookie from users browser.
//=====================================================================

function DeleteCookie (name,path,domain) {
if ( GetCookie(name) ) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

//=====================================================================
// FUNCTION: MoneyFormat
// PARAMETERS: Number to be formatted
// RETURNS: Formatted Number
// PURPOSE: Reformats Euro Amount to #.## format
//=====================================================================

function moneyFormat(input) {
var dollars = Math.floor(input);
var tmp = new String(input);

for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
if ( tmp.charAt(decimalAt)=="." )
break;
}

var cents = "" + Math.round(input * 100);
cents = cents.substring(cents.length-2, cents.length);
dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

if ( cents == "0" )
cents = "00";

return(dollars + "." + cents);
}

//=====================================================================
// FUNCTION: RemoveFromCart
// PARAMETERS: Order Number to Remove
// RETURNS: Null
// PURPOSE: Removes an item from a users shopping cart
//=====================================================================

function RemoveFromCart(RemOrder) {
if ( confirm( strRemove ) ) {
NumberOrdered = GetCookie("NumberOrdered");
for ( i=RemOrder; i < NumberOrdered; i++ ) {
NewOrder1 = "Order." + (i+1);
NewOrder2 = "Order." + (i);
database = GetCookie(NewOrder1);
SetCookie (NewOrder2, database, null, "/");
}
NewOrder = "Order." + NumberOrdered;
SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
DeleteCookie(NewOrder, "/");
location.href=location.href;
}
}

//=====================================================================
// FUNCTION: ChangeQuantity
// PARAMETERS: Order Number to Change Quantity
// RETURNS: Null
// PURPOSE: Changes quantity of an item in the shopping cart
//=====================================================================

function ChangeQuantity(OrderItem,NewQuantity) {
if ( isNaN(NewQuantity) ) {
alert( strErrQty );
} else {
NewOrder = "Order." + OrderItem;
database = "";
database = GetCookie(NewOrder);

Token0 = database.indexOf("|", 0);
Token1 = database.indexOf("|", Token0+1);
Token2 = database.indexOf("|", Token1+1);
Token3 = database.indexOf("|", Token2+1);
Token4 = database.indexOf("|", Token3+1);
Token5 = database.indexOf("|", Token4+1);
Token6 = database.indexOf("|", Token5+1);
Token7 = database.indexOf("|", Token6+1);
Token8 = database.indexOf("|", Token7+1);

fields = new Array;
fields[0] = database.substring( 0, Token0 ); // Product ID
fields[1] = database.substring( Token0+1, Token1 ); // Quantity
fields[2] = database.substring( Token1+1, Token2 ); // Price
fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description
fields[4] = database.substring( Token3+1, Token4 ); // Weight
fields[5] = database.substring( Token4+1, Token5 ); // Page
fields[6] = database.substring( Token5+1, Token6 ); // Picture
fields[7] = database.substring( Token6+1, Token7 ); // Language
fields[8] = database.substring( Token7+1, Token8 ); // Delivery time
fields[9] = database.substring( Token8+1, database.length ); //Additional Information

dbUpdatedOrder = fields[0] + "|" +
NewQuantity + "|" +
fields[2] + "|" +
fields[3] + "|" +
fields[4] + "|" +
fields[5] + "|" +
fields[6] + "|" +
fields[7] + "|" +
fields[8] + "|" +
fields[9];
strNewOrder = "Order." + OrderItem;
DeleteCookie(strNewOrder, "/");
SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
location.href=location.href;
}
}

//=====================================================================
// FUNCTION:    RadioChecked
// PARAMETERS:  Radio button to check
// RETURNS:     True if a radio has been checked
// PURPOSE:     Form fillin validation
//=====================================================================

function RadioChecked( radiobutton ) {
   var bChecked = false;
   var rlen = radiobutton.length;
   for ( i=0; i < rlen; i++ ) {
      if ( radiobutton[i].checked )
         bChecked = true;
   }
   return bChecked;
}

//=====================================================================
// FUNCTION: QueryString
// PARAMETERS: Key to read
// RETURNS: value of key
// PURPOSE: Read data passed in via GET mode
//=====================================================================

QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
var value = null;
for (var i=0;i<QueryString.keys.length;i++) {
if (QueryString.keys[i]==key) {
value = QueryString.values[i];
break;
}
}
return value;
}

//=====================================================================
// FUNCTION: QueryString_Parse
// PARAMETERS: (URL string)
// RETURNS: null
// PURPOSE: Parses query string data, must be called before Q.S.
//=====================================================================

function QueryString_Parse() {
var query = window.location.search.substring(1);
var pairs = query.split("&"); for (var i=0;i>pairs.length;i++) {
var pos = pairs[i].indexOf('=');
if (pos >= 0) {
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}

//=====================================================================
// FUNCTION: ManageCart
// PARAMETERS: Null
// RETURNS: Product Table Written to Document
// PURPOSE: Draws current cart product table on HTML page
// EXTRAS ADDED IN: Code to enable UPS mod.
//=====================================================================

function ManageCart( ) {
var iNumberOrdered = 0; //Number of products ordered
var fTotal = 0; //Total cost of order
var fTax = 0; //Tax amount
var fWeight = 0; //Weight
var fShipping = 0; //Shipping amount
var strTotal = ""; //Total cost formatted as money
var strTax = ""; //Total tax formatted as money
var strShipping = ""; //Total shipping formatted as money
var strOutput = ""; //String to be written to page
var bDisplay = true; //Whether to write string to the page (here for programmers)

iNumberOrdered = GetCookie("NumberOrdered");
if ( iNumberOrdered == null )
iNumberOrdered = 0;

LocationSelected = GetCookie("ZoneSelected");
if (LocationSelected == null) LocationSelected = 0; // Code to use Wichita as default checked if customer goes to Checkout with an empty Cart ||

if ( bDisplay )
strOutput = "<table width=\"100%\" class=\"nopcart\">";
strOutput += "<tr><td class=\"nopheader\" colspan=4><b>" + strCAD + "<\/b></td></tr>";

if ( iNumberOrdered == 0 ) {
strOutput += "<tr><td colspan=4 class=\"nopentry\" align=center><br><b>" + strEmpty + "<\/b><br><br></td></tr>";
}

for ( i = 1; i <= iNumberOrdered; i++ ) {
NewOrder = "Order." + i;
database = "";
database = GetCookie(NewOrder);

Token0 = database.indexOf("|", 0);
Token1 = database.indexOf("|", Token0+1);
Token2 = database.indexOf("|", Token1+1);
Token3 = database.indexOf("|", Token2+1);
Token4 = database.indexOf("|", Token3+1);
Token5 = database.indexOf("|", Token4+1);
Token6 = database.indexOf("|", Token5+1);
Token7 = database.indexOf("|", Token6+1);
Token8 = database.indexOf("|", Token7+1);

fields = new Array;
fields[0] = database.substring( 0, Token0 ); // Product ID
fields[1] = database.substring( Token0+1, Token1 ); // Quantity
fields[2] = database.substring( Token1+1, Token2 ); // Price
fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description
fields[4] = database.substring( Token3+1, Token4 ); // Weight
fields[5] = database.substring( Token4+1, Token5 ); // Page
fields[6] = database.substring( Token5+1, Token6 ); // Picture
fields[7] = database.substring( Token6+1, Token7 ); // Language
fields[8] = database.substring( Token7+1, Token8 ); // Delivery time
fields[9] = database.substring( Token8+1, database.length ); //Additional Information


fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) );
fWeight += (parseInt(fields[1]) * parseFloat(fields[4]) );
fTax = (fTotal * TaxRate);
strTotal = moneyFormat(fTotal);
strTax = moneyFormat(fTax);

// ManageCart

if ( bDisplay ) {

strOutput += "<tr><td colspan=4><hr></td></tr>";

strOutput += "<tr><td rowspan=4 align=center width=220><img src=\"../afb/" + fields[6] + "\"><\/td><td class=\"nopname\" colspan=3><p><a href=\"" + fields[5] + ".html\">" + fields[3] + "<\/a><\/p><\/td><\/tr>";

strOutput += "<tr><td class=\"nopdet\" colspan=4>" + strCLang + fields[7] + "<br>" + strCExp1 + fields[8] + strCExp2 + "<\/td><\/tr>";

strOutput += "<tr><td class=\"nopdet\">" + strCRef + "<b>" + fields[0] + "<\/b><\/td><td class=\"nopdet\">" + strCQty1 + "&nbsp;&nbsp;<b>" + fields[1] + "<\/b>&nbsp;" + strCQty2 + "<\/td><td class=\"nopdet\" align=\"right\">" + strCPrice + "&nbsp;<b>" + fields[2] + "<\/b><\/td><\/tr>";

strOutput += "<tr><td colspan=4 align=\"right\"><input type=\"button\" class=\"butCancel\" value=\"" + strRButton + "\" onClick=\"RemoveFromCart("+i+")\"><\/td><\/tr>";

//strOutput += "<td class=\"nopentry\" align=center><input type=text name=Q size=2 value=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></td>";
}


if ( AppendItemNumToOutput ) {
strFooter = i;
} else {
strFooter = "";
}
if ( HiddenFieldsToCheckout ) {
strOutput += "<input type=hidden name=\"" + OutputItemId + strFooter + "\" value=\"" + fields[0] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemQuantity + strFooter + "\" value=\"" + fields[1] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemPrice + strFooter + "\" value=\"" + fields[2] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemName + strFooter + "\" value=\"" + fields[3] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemWeight + strFooter + "\" value=\"" + fields[4] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemPage + strFooter + "\" value=\"" + fields[5] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemPict + strFooter + "\" value=\"" + fields[6] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemLang + strFooter + "\" value=\"" + fields[7] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemDelTime + strFooter + "\" value=\"" + fields[8] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[9] + "\">";
}

}

if ( bDisplay ) {
strOutput += "<tr><td colspan=4><hr></td></tr>";
strOutput += "<tr><td colspan=3 align=right>" + strSUB + "</td><td align=right><b>" + MonetarySymbol + strTotal + "<\/b></td></tr>";
strOutput += "<tr><td colspan=4><hr></td></tr>";
strOutput += "<tr><td class=\"nopbig\" colspan=4>" + strCountry + ":</td></tr>";
strOutput += "<\/table>";

//this displays the shipping matrix and sets the value for each zone ||

strOutput += "<table width=\"100%\" class=\"nopcart\">";

if (( DisplayShippingRow ) && ( iNumberOrdered != 0)) {
//strOutput += "<tr valign=\"top\"></tr><tr><td>&nbsp;</td><td ALIGN='LEFT' colspan=4>";

strOutput += "<tr><td  class=\"nopdet\" width=\"33%\" valign=\"top\"><input type=radio name=\"ZONE\" selected value=\"0" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone1l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"1" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone2l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"2" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone3l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"3" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone4l;
strOutput += "<\/td><td  class=\"nopdet\" width=\"33%\" valign=\"top\">";
strOutput += "<input type=radio name=\"ZONE\" value=\"4" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone5l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"5" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone6l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"6" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone7l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"7" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone8l;
strOutput += "<\/td><td  class=\"nopdet\" width=\"33%\" valign=\"top\">";
strOutput += "<input type=radio name=\"ZONE\" value=\"8" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone9l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"9" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone10l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"10" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone11l;
strOutput += "<br><input type=radio name=\"ZONE\" value=\"11" + "\" onClick=\"ComputeShipping(this.value, "+fWeight+")\">";
strOutput += strZone12l;
strOutput += "<\/td></tr>";
strOutput += "<tr><td align=left colspan=4 class=\"nopdet\">" + strLev + "</td></tr>";
strOutput += "<\/table>";

strOutput += "<table width=\"100%\" class=\"nopcart\">";
strOutput += "<tr><td colspan=4>&nbsp;</td></tr>";

document.write(strOutput);
strOutput = "";

LocationSelected = GetCookie("ZoneSelected");
if (LocationSelected == null) LocationSelected = 0; // Code to use Local  Area as default checked, but not needed because want null selected at this time ||
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 != 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 = strZone1;
if (LocationSelected == 1) LocationLabel = strZone2;
if (LocationSelected == 2) LocationLabel = strZone3;
if (LocationSelected == 3) LocationLabel = strZone4;
if (LocationSelected == 4) LocationLabel = strZone5;
if (LocationSelected == 5) LocationLabel = strZone6;
if (LocationSelected == 6) LocationLabel = strZone7;
if (LocationSelected == 7) LocationLabel = strZone8;
if (LocationSelected == 8) LocationLabel = strZone9;
if (LocationSelected == 9) LocationLabel = strZone10;
if (LocationSelected == 10) LocationLabel = strZone11;
if (LocationSelected == 11) LocationLabel = strZone12;

if (fWeight == 0) fShipping = 0;
else fShipping = ComputeShipping(LocationSelected, fWeight);

fShipping = ComputeShipping(LocationSelected, fWeight);

strShipping = moneyFormat(fShipping);
//strOutput += "<tr><td class=\"noptotal\"><b>"+strWTOT+"<\/b></td>";
//strOutput += "<td class=\"noptotal\" align=right><b>" + fWeight + " kg" + "<\/b></td>";

strOutput += "<tr><td class=\"noptotal\">" + strSHIP + "&nbsp;" + strDest + "&nbsp;" + LocationLabel + "</td>";
strOutput += "<td class=\"noptotal\" align=right><b>" + MonetarySymbol + strShipping + "<\/b></td></tr>";
}

if ( DisplayTaxRow || TaxByRegion ) {
if ( TaxByRegion ) {
strOutput += "<tr><td class=\"noptotal\"><b>"+strTAX+"<\/b></td>";
strOutput += "<td class=\"noptotal\"><b>";
strOutput += "<input type=radio name=\""+OutputOrderTax+"\" value=\"" + strTax + "\">";
strOutput += TaxablePrompt + ": " + MonetarySymbol + strTax;
strOutput += "<br><input type=radio name=\""+OutputOrderTax+"\" value=\"0.00\">";
strOutput += NonTaxablePrompt + ": " + MonetarySymbol + "0.00";
strOutput += "<\/b></td>";
strOutput += "<\/tr>";
} else {
strOutput += "<tr><td class=\"noptotal\"><b>"+strTAX+"<\/b></td>";
strOutput += "<td class=\"noptotal\" align=right><b>" + MonetarySymbol + strTax + "<\/b></td>";
strOutput += "<\/tr>";
}
}

//if (LocationSelected != 0) //sets tax to 0.00 for all areas except 0 ||
fTax = 0.00;

strOutput += "<tr><td colspan=4><hr></td></tr>";
strOutput += "<tr><td class=\"noptotal\"><b>"+strTOT+"<\/b></td>";
strOutput += "<td class=\"noptotal\" align=right><b>" + moneyFormat((fTotal + fShipping + fTax)) + "<\/b></td>";
strOutput += "<\/tr>";

strOutput += "<\/table>";

if ( HiddenFieldsToCheckout ) {
strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderTax+"\" value=\""+ MonetarySymbol + strTax + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\" value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">";
}
}
g_TotalCost = (fTotal + fShipping + fTax);

document.write(strOutput);
document.close();
}


//=====================================================================
// FUNCTION: ComputeShipping
// PARAMETERS:
// RETURNS:
// PURPOSE: Compute shipping cost due to total weight
//=====================================================================

function ComputeShipping(Zone, TotWeight) {
LocationValue = GetCookie("ZoneSelected");

if (LocationValue != Zone) {
SetCookie("ZoneSelected", Zone, null, "/");
location.href=location.href;
}

//if (TotWeight == 0) return 0.00;

if (LocationValue == 0) {
return 0.00;
}
if (LocationValue == 1 ) {
return 8.00;
}
if (LocationValue == 2 ) {
return 8.00;
}
if (LocationValue == 3 ) {
return 8.00;
}
if (LocationValue == 4) {
return 8.00;
}
if (LocationValue == 5 ) {
return 8.00;
}
if (LocationValue == 6 ) {
return 8.00;
}
if (LocationValue == 7 ) {
return 8.00;
}
if (LocationValue == 8) {
return 0.00;
}
if (LocationValue == 9 ) {
return 8.00;
}
if (LocationValue == 10 ) {
return 8.00;
}
if (LocationValue == 11 ) {
return 8.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( 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 iNumberOrdered = 0; //Number of products ordered
var fTotal = 0; //Total cost of order
var fTax = 0; //Tax amount
var fWeight = 0; //Weight
var fShipping = 0; //Shipping amount
var strTotal = ""; //Total cost formatted as money
var strTax = ""; //Total tax formatted as money
var strShipping = ""; //Total shipping formatted as money
var strOutput = ""; //String to be written to page
var bDisplay = true; //Whether to write string to the page (here for programmers)
var strPP = ""; //Payment Processor Description Field

iNumberOrdered = GetCookie("NumberOrdered");
if ( iNumberOrdered == null )
iNumberOrdered = 0;

if ( TaxByRegion ) {
QueryString_Parse();
fTax = parseFloat( QueryString( OutputOrderTax ) );
strTax = moneyFormat(fTax);
}

if ( bDisplay )

strOutput = "<table width=\"100%\" class=\"nopcart\">";
strOutput += "<tr><td class=\"nopheader\" colspan=5><b>" + strCAD + "<\/b></td></tr>";

for ( i = 1; i <= iNumberOrdered; i++ ) {
NewOrder = "Order." + i;
database = "";
database = GetCookie(NewOrder);

Token0 = database.indexOf("|", 0);
Token1 = database.indexOf("|", Token0+1);
Token2 = database.indexOf("|", Token1+1);
Token3 = database.indexOf("|", Token2+1);
Token4 = database.indexOf("|", Token3+1);
Token5 = database.indexOf("|", Token4+1);
Token6 = database.indexOf("|", Token5+1);
Token7 = database.indexOf("|", Token6+1);
Token8 = database.indexOf("|", Token7+1);

fields = new Array;
fields[0] = database.substring( 0, Token0 ); // Product ID
fields[1] = database.substring( Token0+1, Token1 ); // Quantity
fields[2] = database.substring( Token1+1, Token2 ); // Price
fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description
fields[4] = database.substring( Token3+1, Token4 ); // Weight
fields[5] = database.substring( Token4+1, Token5 ); // Page
fields[6] = database.substring( Token5+1, Token6 ); // Picture
fields[7] = database.substring( Token6+1, Token7 ); // Language
fields[8] = database.substring( Token7+1, Token8 ); // Delivery time
fields[9] = database.substring( Token8+1, database.length ); //Additional Information

fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) );
fWeight += (parseInt(fields[1]) * parseFloat(fields[4]) );
fWeight = Math.round(fWeight * 1000)/1000;
if ( !TaxByRegion ) fTax = (fTotal * TaxRate);
strTotal = moneyFormat(fTotal);
if ( !TaxByRegion ) strTax = moneyFormat(fTax);

// CheckoutCart

if ( bDisplay ) {

strOutput += "<tr><td colspan=4><hr></td></tr>";

strOutput += "<tr><td rowspan=4 align=center width=220><img src=\"../afb/" + fields[6] + "\"><\/td><td class=\"nopname\" colspan=3><p><a href=\"" + fields[5] + ".html\">" + fields[3] + "<\/a><\/p><\/td><\/tr>";

strOutput += "<tr><td class=\"nopdet\" colspan=4>" + strCLang + fields[7] + "<br>" + strCExp1 + fields[8] + strCExp2 + "<\/td><\/tr>";

strOutput += "<tr><td class=\"nopdet\">" + strCRef + "<b>" + fields[0] + "<\/b><\/td><td class=\"nopdet\">" + strCQty1 + "&nbsp;&nbsp;<b>" + fields[1] + "<\/b>&nbsp;" + strCQty2 + "<\/td><td class=\"nopdet\" align=\"right\">" + strCPrice + "&nbsp;<b>" + fields[2] + "<\/b><\/td><\/tr>";

strOutput += "<tr><td colspan=4>&nbsp;<\/td><\/tr>";

//strOutput += "<tr><td colspan=4 align=\"right\"><input type=\"button\" class=\"butCancel\" value=\"" + strRButton + "\" onClick=\"RemoveFromCart("+i+")\"><\/td><\/tr>";

//strOutput += "<td class=\"nopentry\" align=center><input type=text name=Q size=2 value=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></td>";
}


if ( AppendItemNumToOutput ) {
strFooter = i;
} else {
strFooter = "";
}

strOutput += "<input type=hidden name=\"" + OutputItemId + strFooter + "\" value=\"" + fields[0] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemQuantity + strFooter + "\" value=\"" + fields[1] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemPrice + strFooter + "\" value=\"" + fields[2] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemName + strFooter + "\" value=\"" + fields[3] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemWeight + strFooter + "\" value=\"" + fields[4] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemPage + strFooter + "\" value=\"" + fields[5] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemPict + strFooter + "\" value=\"" + fields[6] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemLang + strFooter + "\" value=\"" + fields[7] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemDelTime + strFooter + "\" value=\"" + fields[8] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[9] + "\">";

}

if ( bDisplay ) {
strOutput += "<tr><td colspan=5><hr></td></tr>";
strOutput += "<tr><td class=\"noptotal\" colspan=3>"+strSUB+"</td>";
strOutput += "<td class=\"noptotal\" colspan=2 align=right><b>" + strTotal + "<\/b></td>";
strOutput += "<\/tr>";

if ( DisplayShippingRow ) {
LocationSelected = GetCookie("ZoneSelected");
if (LocationSelected == null) LocationSelected = 0; //Needed if checkout cart is empty

if (LocationSelected == 0) LocationLabel = strZone1;
if (LocationSelected == 1) LocationLabel = strZone2;
if (LocationSelected == 2) LocationLabel = strZone3;
if (LocationSelected == 3) LocationLabel = strZone4;
if (LocationSelected == 4) LocationLabel = strZone5;
if (LocationSelected == 5) LocationLabel = strZone6;
if (LocationSelected == 6) LocationLabel = strZone7;
if (LocationSelected == 7) LocationLabel = strZone8;
if (LocationSelected == 8) LocationLabel = strZone9;
if (LocationSelected == 9) LocationLabel = strZone10;
if (LocationSelected == 10) LocationLabel = strZone11;
if (LocationSelected == 11) LocationLabel = strZone12;


fShipping = ComputeShipping(LocationSelected, fWeight);
strShipping = moneyFormat(fShipping);

//strOutput += "<tr><td class=\"noptotal\" colspan=2><b>"+strWTOT+"<\/b></td>";
//strOutput += "<td class=\"noptotal\" colspan=3 align=right><b>" + fWeight + " kg" + "<\/b></td>";

strOutput += "<tr><td class=\"noptotal\" colspan=3>" + strSHIP + "&nbsp;<b>" + strDest + "&nbsp;" + LocationLabel + "<\/b></td>";
strOutput += "<td class=\"noptotal\" colspan=2 align=right><b>" + strShipping + "<\/b></td>";
strOutput += "<\/tr>";
}

if ( DisplayTaxRow || TaxByRegion ) {
strOutput += "<tr><td class=\"noptotal\" colspan=3><b>"+strTAX+"<\/b></td>";
strOutput += "<td class=\"noptotal\" colspan=2 align=right><b>" + strTax + "<\/b></td>";
strOutput += "<\/tr>";
}

//if (LocationSelected != 0) //sets tax to 0.00 for all other areas ||
fTax = 0.00;

strOutput += "<tr><td colspan=6><hr></td></tr>";
strOutput += "<tr><td class=\"noptotal\" colspan=3><b>"+strTOT+"<\/b></td>";
strOutput += "<td class=\"noptotal\" colspan=2 align=right><b>" + moneyFormat((fTotal + fShipping + fTax)) + "<\/b></td>";
strOutput += "<\/tr>";

strOutput += "<\/table>";

strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderTax+"\" value=\""+ MonetarySymbol + strTax + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\" value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">";

}
document.write(strOutput);
document.close();
}

//=====================================================================
// FUNCTIONS: coBevestigen, coVerzenden
// PURPOSE: Check-out buttons
//=====================================================================

function coBevestigen()
{
if (ValidateCart(document.cart))
{
document.cart.submit();
}
}

function coVerzenden()
{
document.tmbform.submit();
}
