//=====================================================================||
//                 Javascript Shopping Cart                            ||
//                 (C) 2009 Mike Whelan                                ||
//=====================================================================||

// General options:
msMonetarySymbol = 'AU$ ';
mbDisplayNotice = true;
mbDisplayShippingColumn = false;
mbDisplayIdColumn = false;
mbDisplayPriceColumn = false;
mbDisplayQtyColumn = false;
mbDisplayImageColumn = true;
mbDisplayShippingRow = true;
mbDisplayInsuranceRow = true;
mbDisplayTaxRow = false;
mdTaxRate = 0.00;
mbTaxByRegion = false;
msTaxPrompt = 'For tax purposes, please select if you are an Arizona resident before continuing';
msTaxablePrompt = 'Arizona Residents';
msNonTaxablePrompt = 'Other States';
mdMinimumOrder = 10.00;
msMinimumOrderPrompt = 'Your order is below our minimum order, please order more before checking out.';
miMaxLines = 20;
miMaxItems = 50;
miDefaultMaxQuantity = 1;
msInsuranceOptions = "No;Yes".split(";");
mdKeyringRegular = 5.95;
mdLargeBoxRegular = 10.00;
mdInsuranceAUBase = 3.00;
mdInsuranceAUPer100 = 2.00;
mdInsuranceOSBase = 9.00;
mdInsuranceOSPer100 = 3;
mdDiscountAUKey = 3.95;
mdDiscountAUOther = 4.50;
mdDiscountOSKey = 9.00;
mdDiscountOSOther = 5.00;
mdLocalBase = 10.00;
mdLocalPerItem = 2.00;
mdMinAUInsurance = 200;
mdMinOSInsurance = 100;
miCartExpiresHours = 4;

function PostalRate(name, region) {
    this.name = name;
    this.region = region;
}
msDefaultPostalRate = "--- Choose your Country ---";
msPostalRates = new Array;
msPostalRates.push(new PostalRate(msDefaultPostalRate, ""));
msPostalRates.push(new PostalRate("Australia (Regular)", "0"));
msPostalRates.push(new PostalRate("Australia (ExpressPost)", "1"));
msPostalRates.push(new PostalRate("Australia - Brisbane (Within 50km of GPO)", "2"));
msPostalRates.push(new PostalRate("Australia - Brisbane (Local Pickup)", "3"));
msPostalRates.push(new PostalRate("------------------------------", ""));
msPostalRates.push(new PostalRate("Afghanistan", "C"));
msPostalRates.push(new PostalRate("Albania", "D"));
msPostalRates.push(new PostalRate("Algeria", "D"));
msPostalRates.push(new PostalRate("American Samoa", "B"));
msPostalRates.push(new PostalRate("Angola", "D"));
msPostalRates.push(new PostalRate("Anguilla", "D"));
msPostalRates.push(new PostalRate("Antigua And Barbuda", "D"));
msPostalRates.push(new PostalRate("Argentina", "D"));
msPostalRates.push(new PostalRate("Armenia", "D"));
msPostalRates.push(new PostalRate("Aruba", "D"));
msPostalRates.push(new PostalRate("Ascension Island", "D"));
msPostalRates.push(new PostalRate("Austria", "D"));
msPostalRates.push(new PostalRate("Azerbaijan", "D"));
msPostalRates.push(new PostalRate("Bahamas", "D"));
msPostalRates.push(new PostalRate("Bahrain", "C"));
msPostalRates.push(new PostalRate("Bangladesh", "B"));
msPostalRates.push(new PostalRate("Barbados", "D"));
msPostalRates.push(new PostalRate("Belarus", "D"));
msPostalRates.push(new PostalRate("Belgium", "D"));
msPostalRates.push(new PostalRate("Belize", "D"));
msPostalRates.push(new PostalRate("Benin", "D"));
msPostalRates.push(new PostalRate("Bermuda", "D"));
msPostalRates.push(new PostalRate("Bhutan", "B"));
msPostalRates.push(new PostalRate("Bolivia", "D"));
msPostalRates.push(new PostalRate("Bosnia And Herzegovina", "D"));
msPostalRates.push(new PostalRate("Botswana", "D"));
msPostalRates.push(new PostalRate("Brazil", "D"));
msPostalRates.push(new PostalRate("British Indian Ocean Territory", "D"));
msPostalRates.push(new PostalRate("Brunei Darussalam", "B"));
msPostalRates.push(new PostalRate("Bulgaria", "D"));
msPostalRates.push(new PostalRate("Burkina Faso", "D"));
msPostalRates.push(new PostalRate("Burundi", "D"));
msPostalRates.push(new PostalRate("Cambodia", "B"));
msPostalRates.push(new PostalRate("Cameroon", "D"));
msPostalRates.push(new PostalRate("Canada", "C"));
msPostalRates.push(new PostalRate("Cape Verde", "D"));
msPostalRates.push(new PostalRate("Cayman Islands", "D"));
msPostalRates.push(new PostalRate("Central African Republic", "D"));
msPostalRates.push(new PostalRate("Chad", "D"));
msPostalRates.push(new PostalRate("Chile", "D"));
msPostalRates.push(new PostalRate("China", "B"));
msPostalRates.push(new PostalRate("Colombia", "D"));
msPostalRates.push(new PostalRate("Comoros", "C"));
msPostalRates.push(new PostalRate("Congo", "D"));
msPostalRates.push(new PostalRate("Congo, The Democratic Republic Of The", "D"));
msPostalRates.push(new PostalRate("Cook Islands", "B"));
msPostalRates.push(new PostalRate("Costa Rica", "D"));
msPostalRates.push(new PostalRate("Cote D'ivoire", "D"));
msPostalRates.push(new PostalRate("Croatia", "D"));
msPostalRates.push(new PostalRate("Cuba", "D"));
msPostalRates.push(new PostalRate("Cyprus", "C"));
msPostalRates.push(new PostalRate("Czech Republic", "D"));
msPostalRates.push(new PostalRate("Denmark", "D"));
msPostalRates.push(new PostalRate("Djibouti", "D"));
msPostalRates.push(new PostalRate("Dominica", "D"));
msPostalRates.push(new PostalRate("Dominican Republic", "D"));
msPostalRates.push(new PostalRate("East Timor", "B"));
msPostalRates.push(new PostalRate("Ecuador", "D"));
msPostalRates.push(new PostalRate("Egypt", "D"));
msPostalRates.push(new PostalRate("El Salvador", "D"));
msPostalRates.push(new PostalRate("Equatorial Guinea", "D"));
msPostalRates.push(new PostalRate("Eritrea", "D"));
msPostalRates.push(new PostalRate("Estonia", "D"));
msPostalRates.push(new PostalRate("Ethiopia", "D"));
msPostalRates.push(new PostalRate("Falkland Islands (Malvinas)", "D"));
msPostalRates.push(new PostalRate("Fiji", "B"));
msPostalRates.push(new PostalRate("Finland", "D"));
msPostalRates.push(new PostalRate("France", "D"));
msPostalRates.push(new PostalRate("French Guiana", "D"));
msPostalRates.push(new PostalRate("French Polynesia", "B"));
msPostalRates.push(new PostalRate("Gabon", "D"));
msPostalRates.push(new PostalRate("Gambia", "D"));
msPostalRates.push(new PostalRate("Georgia", "D"));
msPostalRates.push(new PostalRate("Germany", "D"));
msPostalRates.push(new PostalRate("Ghana", "D"));
msPostalRates.push(new PostalRate("Gibraltar", "D"));
msPostalRates.push(new PostalRate("Greece", "D"));
msPostalRates.push(new PostalRate("Greenland", "D"));
msPostalRates.push(new PostalRate("Grenada", "D"));
msPostalRates.push(new PostalRate("Guadeloupe", "D"));
msPostalRates.push(new PostalRate("Guam", "B"));
msPostalRates.push(new PostalRate("Guatemala", "D"));
msPostalRates.push(new PostalRate("Guinea", "D"));
msPostalRates.push(new PostalRate("Guinea-Bissau", "D"));
msPostalRates.push(new PostalRate("Guyana", "D"));
msPostalRates.push(new PostalRate("Haiti", "D"));
msPostalRates.push(new PostalRate("Holy See (Vatican City State)", "D"));
msPostalRates.push(new PostalRate("Honduras", "D"));
msPostalRates.push(new PostalRate("Hong Kong", "B"));
msPostalRates.push(new PostalRate("Hungary", "D"));
msPostalRates.push(new PostalRate("Iceland", "D"));
msPostalRates.push(new PostalRate("India", "B"));
msPostalRates.push(new PostalRate("Indonesia", "B"));
msPostalRates.push(new PostalRate("Iran, Islamic Republic Of", "C"));
msPostalRates.push(new PostalRate("Iraq", "C"));
msPostalRates.push(new PostalRate("Ireland", "D"));
msPostalRates.push(new PostalRate("Israel", "C"));
msPostalRates.push(new PostalRate("Italy", "D"));
msPostalRates.push(new PostalRate("Jamaica", "D"));
msPostalRates.push(new PostalRate("Japan", "B"));
msPostalRates.push(new PostalRate("Jordan", "C"));
msPostalRates.push(new PostalRate("Kazakhstan", "D"));
msPostalRates.push(new PostalRate("Kenya", "D"));
msPostalRates.push(new PostalRate("Kiribati", "B"));
msPostalRates.push(new PostalRate("Korea, Democratic People's Republic Of", "B"));
msPostalRates.push(new PostalRate("Korea, Republic Of", "B"));
msPostalRates.push(new PostalRate("Kosovo, Republic Of ", "D"));
msPostalRates.push(new PostalRate("Kuwait", "C"));
msPostalRates.push(new PostalRate("Kyrgyzstan", "D"));
msPostalRates.push(new PostalRate("Lao, People's Democratic Republic", "B"));
msPostalRates.push(new PostalRate("Latvia", "D"));
msPostalRates.push(new PostalRate("Lebanon", "C"));
msPostalRates.push(new PostalRate("Lesotho", "D"));
msPostalRates.push(new PostalRate("Liberia", "D"));
msPostalRates.push(new PostalRate("Libyan Arab Jamahiriya", "D"));
msPostalRates.push(new PostalRate("Liechtenstein", "D"));
msPostalRates.push(new PostalRate("Lithuania", "D"));
msPostalRates.push(new PostalRate("Luxembourg", "D"));
msPostalRates.push(new PostalRate("Macao", "B"));
msPostalRates.push(new PostalRate("Macedonia, The Former Yugoslav Republic Of", "D"));
msPostalRates.push(new PostalRate("Madagascar", "C"));
msPostalRates.push(new PostalRate("Malawi", "D"));
msPostalRates.push(new PostalRate("Malaysia", "B"));
msPostalRates.push(new PostalRate("Maldives", "B"));
msPostalRates.push(new PostalRate("Mali", "D"));
msPostalRates.push(new PostalRate("Malta", "D"));
msPostalRates.push(new PostalRate("Marshall Islands", "B"));
msPostalRates.push(new PostalRate("Martinique", "D"));
msPostalRates.push(new PostalRate("Mauritania", "D"));
msPostalRates.push(new PostalRate("Mauritius", "C"));
msPostalRates.push(new PostalRate("Mexico", "C"));
msPostalRates.push(new PostalRate("Micronesia, Federated States Of", "B"));
msPostalRates.push(new PostalRate("Moldova, Republic Of", "D"));
msPostalRates.push(new PostalRate("Mongolia", "D"));
msPostalRates.push(new PostalRate("Montenegro", "D"));
msPostalRates.push(new PostalRate("Montserrat", "D"));
msPostalRates.push(new PostalRate("Morocco", "D"));
msPostalRates.push(new PostalRate("Mozambique", "D"));
msPostalRates.push(new PostalRate("Myanmar", "B"));
msPostalRates.push(new PostalRate("Namibia", "D"));
msPostalRates.push(new PostalRate("Nauru", "B"));
msPostalRates.push(new PostalRate("Nepal", "B"));
msPostalRates.push(new PostalRate("Netherlands", "D"));
msPostalRates.push(new PostalRate("Netherlands Antilles", "D"));
msPostalRates.push(new PostalRate("New Caledonia", "B"));
msPostalRates.push(new PostalRate("New Zealand", "A"));
msPostalRates.push(new PostalRate("Nicaragua", "D"));
msPostalRates.push(new PostalRate("Niger", "D"));
msPostalRates.push(new PostalRate("Nigeria", "D"));
msPostalRates.push(new PostalRate("Niue", "B"));
msPostalRates.push(new PostalRate("Northern Mariana Islands", "B"));
msPostalRates.push(new PostalRate("Norway", "D"));
msPostalRates.push(new PostalRate("Oman", "C"));
msPostalRates.push(new PostalRate("Pakistan", "B"));
msPostalRates.push(new PostalRate("Palau", "B"));
msPostalRates.push(new PostalRate("Panama", "D"));
msPostalRates.push(new PostalRate("Papua New Guinea", "B"));
msPostalRates.push(new PostalRate("Paraguay", "D"));
msPostalRates.push(new PostalRate("Peru", "D"));
msPostalRates.push(new PostalRate("Philippines", "B"));
msPostalRates.push(new PostalRate("Pitcairn", "B"));
msPostalRates.push(new PostalRate("Poland", "D"));
msPostalRates.push(new PostalRate("Portugal", "D"));
msPostalRates.push(new PostalRate("Puerto Rico", "D"));
msPostalRates.push(new PostalRate("Qatar", "C"));
msPostalRates.push(new PostalRate("Reunion", "C"));
msPostalRates.push(new PostalRate("Romania", "D"));
msPostalRates.push(new PostalRate("Russian Federation", "D"));
msPostalRates.push(new PostalRate("Rwanda", "D"));
msPostalRates.push(new PostalRate("Saint Kitts And Nevis", "D"));
msPostalRates.push(new PostalRate("Saint Lucia", "D"));
msPostalRates.push(new PostalRate("Saint Pierre And Miquelon", "C"));
msPostalRates.push(new PostalRate("Saint Vincent And The Grenadines", "D"));
msPostalRates.push(new PostalRate("Samoa", "B"));
msPostalRates.push(new PostalRate("Sao Tome And Principe", "D"));
msPostalRates.push(new PostalRate("Saudi Arabia", "C"));
msPostalRates.push(new PostalRate("Senegal", "D"));
msPostalRates.push(new PostalRate("Serbia", "D"));
msPostalRates.push(new PostalRate("Seychelles", "D"));
msPostalRates.push(new PostalRate("Sierra Leone", "D"));
msPostalRates.push(new PostalRate("Singapore", "B"));
msPostalRates.push(new PostalRate("Slovakia", "D"));
msPostalRates.push(new PostalRate("Slovenia", "D"));
msPostalRates.push(new PostalRate("Solomon Islands", "B"));
msPostalRates.push(new PostalRate("Somalia", "D"));
msPostalRates.push(new PostalRate("South Africa", "D"));
msPostalRates.push(new PostalRate("Spain", "D"));
msPostalRates.push(new PostalRate("Sri Lanka", "B"));
msPostalRates.push(new PostalRate("Sudan", "D"));
msPostalRates.push(new PostalRate("Suriname", "D"));
msPostalRates.push(new PostalRate("Swaziland", "D"));
msPostalRates.push(new PostalRate("Sweden", "D"));
msPostalRates.push(new PostalRate("Switzerland", "D"));
msPostalRates.push(new PostalRate("Syrian Arab Republic", "C"));
msPostalRates.push(new PostalRate("Taiwan", "B"));
msPostalRates.push(new PostalRate("Tajikistan", "D"));
msPostalRates.push(new PostalRate("Tanzania, United Republic Of", "D"));
msPostalRates.push(new PostalRate("Thailand", "B"));
msPostalRates.push(new PostalRate("Togo", "D"));
msPostalRates.push(new PostalRate("Tokelau", "B"));
msPostalRates.push(new PostalRate("Tonga", "B"));
msPostalRates.push(new PostalRate("Trinidad And Tobago", "D"));
msPostalRates.push(new PostalRate("Tristan Da Cunha", "D"));
msPostalRates.push(new PostalRate("Tunisia", "D"));
msPostalRates.push(new PostalRate("Turkey", "D"));
msPostalRates.push(new PostalRate("Turkmenistan", "D"));
msPostalRates.push(new PostalRate("Turks And Caicos Islands", "D"));
msPostalRates.push(new PostalRate("Tuvalu", "B"));
msPostalRates.push(new PostalRate("Uganda", "D"));
msPostalRates.push(new PostalRate("Ukraine", "D"));
msPostalRates.push(new PostalRate("United Arab Emirates", "C"));
msPostalRates.push(new PostalRate("United Kingdom", "D"));
msPostalRates.push(new PostalRate("United States Of America", "C"));
msPostalRates.push(new PostalRate("Uruguay", "D"));
msPostalRates.push(new PostalRate("Uzbekistan", "D"));
msPostalRates.push(new PostalRate("Vanuatu", "B"));
msPostalRates.push(new PostalRate("Venezuela", "D"));
msPostalRates.push(new PostalRate("Vietnam", "B"));
msPostalRates.push(new PostalRate("Virgin Islands", "D"));
msPostalRates.push(new PostalRate("Wallis And Futuna", "B"));
msPostalRates.push(new PostalRate("Yemen", "C"));
msPostalRates.push(new PostalRate("Zambia", "D"));
msPostalRates.push(new PostalRate("Zimbabwe", "D"));

mdPostalRates = new Array("0", "1", "2", "3", "A", "B", "C");
mdPostalRates["0"] = "6.50;8.5;14;14;17;30;30;30;30;30;30;30".split(";");
mdPostalRates["1"] = "10.50;10.50;25;25;47;100;100;100;100;100;100;100".split(";");
mdPostalRates["2"] = mdPostalRates["0"];
mdPostalRates["3"] = mdPostalRates["0"];
mdPostalRates["B"] = "11;15;20;25;30;100;100;100;100;100;100;100".split(";");
mdPostalRates["A"] = mdPostalRates["B"];
mdPostalRates["C"] = "12;18;24;30;36;100;100;100;100;100;100;100".split(";");
mdPostalRates["D"] = "13;21;29;37;44;100;100;100;100;100;100;100".split(";");
//alert(mdPostalRates["C"][2]);

// Payment Processor Options:
msPaymentProcessor      = '';

// Options for Programmers:
msOutputItemId = 'item_number_'; //''; //
msOutputItemQuantity = 'quantity_';
msOutputItemPrice = 'amount_';
msOutputItemName = 'item_name_';
msOutputItemShipping = '';
msOutputItemAddtlInfo = '';
msOutputOrderSubtotal = '';
msOutputOrderShipping = 'shipping_1';
msOutputOrderTax = '';
msOutputOrderTotal = 'ORDER_TOTAL';
msOutputOrderShippingV = 'os0_#';
msOutputOrderShippingL = 'on0_#';
msOutputOrderShippingN = 'Postage Rate';
mbAppendItemNumToOutput = true;
mbHiddenFieldsToCheckout = true;

// Field order in line item:
miId             = 0;
miQty            = 1;
miPrice          = 2;
miName           = 3;
miShipping       = 4;
miAdditionalInfo = 5;
miMaxQuantity    = 6;
miMustInsure     = 7;
miWeight         = 8;
miImage          = 9;
miUrl            = 10;
miOriginalPrice  = 11;
miLargeBox       = 12;

// Language stuff
msSorry   = "I'm Sorry, your cart is full, please proceed to checkout.";
msAdded   = " has been added to your shopping cart.";
msRemove  = "Click 'Ok' to remove this item from your shopping cart.";
msClear   = "Click 'Ok' to clear all items your shopping cart.";
msGLabel  = "";
msILabel  = "";
msDLabel  = "";
msQLabel  = "";
msPLabel  = "";
msSLabel  = "";
msRLabel  = "Remove From Cart";
msRButton = " Remove ";
msSub     = "ITEM SUBTOTAL";
msShip    = "POSTAGE";
msInsure  = "INSURANCE";
msTax     = "TAX";
msTotal   = "ORDER TOTAL";
msErrQty  = "Invalid Quantity.";
msErrQtyHigh = "Quantity cannot be more than ";
msNewQty  = 'Please enter new quantity:';
mbLanguageDefined = true;

//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart(thisForm, showAlert) {
    var liNumberOrdered = 0;
    liNumberOrdered = GetCookie("NumberOrdered");
    if (liNumberOrdered == null)
        liNumberOrdered = 0;

    var liTotalOrdered = 0;
    liTotalOrdered = GetCookie("TotalOrdered");
    if (liTotalOrdered == null)
        liTotalOrdered = 0;

    if (thisForm.ID_NUM == null)
        lsIdNum = "";
    else
        lsIdNum = thisForm.ID_NUM.value;

    if (thisForm.QUANTITY == null)
        lsQuantity = "1";
    else
        lsQuantity = thisForm.QUANTITY.value;

    if (thisForm.PRICE == null)
        lsPrice = "0.00";
    else
        lsPrice = thisForm.PRICE.value;

    if (thisForm.NAME == null)
        lsName = "";
    else
        lsName = thisForm.NAME.value;

    if (thisForm.SHIPPING == null)
        lsShipping = "0.00";
    else
        lsShipping = thisForm.SHIPPING.value;

    if (thisForm.ADDITIONALINFO == null)
        lsAdditionalInfo = "";
    else
        lsAdditionalInfo = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
    if (thisForm.ADDITIONALINFO2 != null)
        lsAdditionalInfo += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
    if (thisForm.ADDITIONALINFO3 != null)
        lsAdditionalInfo += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
    if (thisForm.ADDITIONALINFO4 != null)
        lsAdditionalInfo += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;

    if (thisForm.MUST_INSURE == null)
        lsMustInsure = "";
    else
        lsMustInsure = thisForm.MUST_INSURE.value;

    if (thisForm.LARGE_BOX == null)
        lsLargeBox = "";
    else
        lsLargeBox = thisForm.LARGE_BOX.value;

    if (thisForm.MAX_QUANTITY == null)
        lsMaxQuantity = "";
    else
        lsMaxQuantity = thisForm.MAX_QUANTITY.value;

    if (thisForm.WEIGHT == null)
        lsWeight = "";
    else
        lsWeight = thisForm.WEIGHT.value;

    if (thisForm.IMAGE == null)
        lsImage = "";
    else
        lsImage = thisForm.IMAGE.value;

    if (thisForm.URL == null)
        lsUrl = "";
    else
        lsUrl = thisForm.URL.value;

    if (thisForm.ORIGINAL_PRICE == null)
        lsOriginalPrice = "";
    else
        lsOriginalPrice = thisForm.ORIGINAL_PRICE.value;

    // Add this quantity to the total and check if its still within limit
    liTotalOrdered = parseInt(liTotalOrdered) + parseInt(lsQuantity);
    if (liTotalOrdered > miMaxItems) {
        alert(msSorry);
        return(false);
    }

    // Find same item in the cart
    var lbAlreadyInCart = false;
    var liLineId = 0;
    lsFields = new Array;
    for (i = 1; i <= liNumberOrdered; i++) {
        lsFields = GetLine(i);
        if (lsFields[miId] == lsIdNum && lsFields[miPrice] == lsPrice && lsFields[miName] == lsName && lsFields[miAdditionalInfo] == lsAdditionalInfo) {
            lbAlreadyInCart = true;
            liLineId = i;
            break;
        }
    }

    // Check if item was found
    if (lbAlreadyInCart) {
        // Update the quantity
        lsFields[miQty] = parseInt(lsFields[miQty]) + parseInt(lsQuantity);
        liMaxQuantity = parseInt(lsFields[miMaxQuantity]);
        if (liMaxQuantity > 0 && lsFields[miQty] > liMaxQuantity) {
            alert("You cannot order more than " + lsFields[miMaxQuantity] + " of this item.");
            return(false);
        }
    } else {
        // Check if reached limit of items that can be ordered
        liNumberOrdered++;
        if (liNumberOrdered > miMaxLines) {
            alert(msSorry);
            return(false);
        }

        // Save the updated number of line items
        SetCookie("NumberOrdered", liNumberOrdered, miCartExpiresHours, "/");

        // Create a new line row to save
        liLineId = liNumberOrdered;
        lsFields = new Array;
        lsFields[miId] = lsIdNum;
        lsFields[miQty] = lsQuantity;
        lsFields[miPrice] = lsPrice;
        lsFields[miName] = lsName;
        lsFields[miShipping] = lsShipping;
        lsFields[miAdditionalInfo] = lsAdditionalInfo;
        lsFields[miWeight] = lsWeight;
        lsFields[miMaxQuantity] = lsMaxQuantity;
        lsFields[miMustInsure] = lsMustInsure;
        lsFields[miImage] = lsImage;
        lsFields[miUrl] = lsUrl;
        lsFields[miOriginalPrice] = lsOriginalPrice;
        lsFields[miLargeBox] = lsLargeBox;
    }

    // Save the updated total items
    SetCookie("TotalOrdered", liTotalOrdered, miCartExpiresHours, "/");

    // Save the line item
    SaveLine(liLineId, lsFields, null, "/");

    // Display prompt if required
    if (mbDisplayNotice && showAlert)
        alert(lsName + msAdded);
    else
        location.href = "cart.html#Total";

    return(true);
}


//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal(offset) {
    var liEndStr = document.cookie.indexOf(";", offset);

    if (liEndStr == -1)
        liEndStr = document.cookie.length;
    return(unescape(document.cookie.substring(offset, liEndStr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate(date) {
    var ldtBase = new Date(0);
    var liSkew = ldtBase.getTime();

    date.setTime(date.getTime() - liSkew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie(name) {
    var lsArg = name + "=";
    var liArgLen = lsArg.length;
    var liCookieLen = document.cookie.length;
    var i = 0;

    while (i < liCookieLen) {
        var j = i + liArgLen;
        if (document.cookie.substring(i, j) == lsArg) 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) {
    var exdate = new Date();
    if (expires) {
        exdate.setHours(exdate.getHours() + expires);
        //alert("name=" + name + "\nExpires=" + exdate);
    }
    document.cookie = name + "=" + escape(value) +
                      ((expires) ? "; expires=" + exdate.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 Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
    var liDollars = Math.floor(input);
    var lsTmp = new String(input);

    for (var liDecimalAt = 0; liDecimalAt < lsTmp.length; liDecimalAt++) {
        if (lsTmp.charAt(liDecimalAt) == ".")
            break;
    }

    var lsCents  = "" + Math.round(input * 100);
    lsCents = lsCents.substring(lsCents.length - 2, lsCents.length);
    liDollars += ((lsTmp.charAt(liDecimalAt + 2) == "9")&&(lsCents == "00"))? 1 : 0;

    if (lsCents == "0")
        lsCents = "00";

    return(liDollars + "." + lsCents);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetLine                                                ||
// PARAMETERS:  Order line to get                                      ||
// RETURNS:     array containing details of line item                  ||
// PURPOSE:     Gets the values for specified line item                ||
//---------------------------------------------------------------------||
function GetLine(lineNo) {
    var lsId = "Order." + lineNo;
    var lsLine = GetCookie(lsId);
    return lsLine.split("|");
}

//---------------------------------------------------------------------||
// FUNCTION:    SaveLine                                               ||
// PARAMETERS:  Order line to save, values of line item                ||
// RETURNS:     null                                                   ||
// PURPOSE:     Saves the values for the specified line item           ||
//---------------------------------------------------------------------||
function SaveLine(lineNo, fields) {
    var lsId = "Order." + lineNo;
    var lsLine = fields.join("|");
    DeleteCookie(lsId, "/");
    SetCookie(lsId, lsLine, miCartExpiresHours, "/");
}

//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) {
    // Check if its ok to proceed
    if (! confirm(msRemove))
        return(false);

    // Get the number of items in the cart
    liNumberOrdered = GetCookie("NumberOrdered");

    // Subtract the removed item from the total count
    lsFields = GetLine(RemOrder);
    liTotalOrdered = GetCookie("TotalOrdered");
    if (liTotalOrdered == null)
        liTotalOrdered = 0;
    liTotalOrdered = parseInt(liTotalOrdered) - parseInt(lsFields[miQty]);
    if (liTotalOrdered < 0)
        liTotalOrdered = 0;
    SetCookie("TotalOrdered", liTotalOrdered, miCartExpiresHours, "/");

    // Move all the remaining orders up 1 number
    for (i=RemOrder; i < liNumberOrdered; i++) {
        lsLine = GetCookie("Order." + (i+1));
        SetCookie("Order." + i, lsLine, miCartExpiresHours, "/");
    }

    // Remove the last entry
    DeleteCookie("Order." + liNumberOrdered, "/");

    // Update the number of items in the cart
    SetCookie ("NumberOrdered", liNumberOrdered - 1, miCartExpiresHours, "/");

    // Refresh the page
    RefreshPage();
    return(true);
}

//---------------------------------------------------------------------||
// FUNCTION:    IsCartEmpty                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     True if the cart is empty, otherwise false.            ||
// PURPOSE:     Checks if the cart is empty                            ||
//---------------------------------------------------------------------||
function IsCartEmpty() {
    return GetTotalOrdered() == 0;
}


//---------------------------------------------------------------------||
// FUNCTION:    ClearCart                                              ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes all items from a users shopping cart           ||
//---------------------------------------------------------------------||
function ClearCartDetails() {
    // Get the number of items in the cart
    var liNumberOrdered = GetCookie("NumberOrdered");
    if (liNumberOrdered == null)
         liNumberOrdered = 0;

    // Delete each line
    for (i=0; i < liNumberOrdered; i++) {
        DeleteCookie("Order." + (i), "/");
    }

    // Delete the cookies containing the number of items in the cart
    DeleteCookie("NumberOrdered", "/");
    DeleteCookie("TotalOrdered", "/");
    DeleteCookie("Insurance", "/");

    return true;
}

//---------------------------------------------------------------------||
// FUNCTION:    ClearCart                                              ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes all items from a users shopping cart           ||
//---------------------------------------------------------------------||
function ClearCart() {
    // Check if its ok to proceed
    if (! confirm(msClear))
    return(false);

    ClearCartDetails();

    // Refresh the page
    RefreshPage();
    return(true);
}


//---------------------------------------------------------------------||
// FUNCTION:    ChangeQuantity                                         ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Changes quantity of an item in the shopping cart       ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderItem,NewQuantity) {
    // Get the current row
    var lsFields = GetLine(OrderItem);

    // Validate the quantity
    if (isNaN(NewQuantity)) {
        alert(msErrQty);
        return(lsFields[miQty]);
    }

    // Make sure its at least 1
    var liNewQuantity = parseInt(NewQuantity);
    if (liNewQuantity < 1) {
        alert(msErrQty);
        return(lsFields[miQty]);
    }

    // Check that maximum has not been exceeded
    var liMaxQuantity = parseInt(lsFields[miMaxQuantity]);
    if (liMaxQuantity > 0 && liNewQuantity > liMaxQuantity) {
        alert("You cannot order more than " + lsFields[miMaxQuantity] + " of this item.");
        return(lsFields[miQty]);
    }

    // Update total count with the difference
    var liTotalOrdered = 0;
    liTotalOrdered = GetCookie("TotalOrdered");
    if (liTotalOrdered == null)
        liTotalOrdered = 0;
    liTotalOrdered = parseInt(liTotalOrdered) - parseInt(lsFields[miQty]) + liNewQuantity;
    if (liTotalOrdered < 0)
        liTotalOrdered = 0;
    SetCookie("TotalOrdered", liTotalOrdered, miCartExpiresHours, "/");

    // Update the quantity and save
    lsFields[miQty] = liNewQuantity;
    SaveLine(OrderItem, lsFields);

    // Refresh the page
    RefreshPage();
    return(true);
}


//---------------------------------------------------------------------||
// FUNCTION:    RadioChecked                                           ||
// PARAMETERS:  Radio button to check                                  ||
// RETURNS:     True if a radio has been checked                       ||
// PURPOSE:     Form fillin validation                                 ||
//---------------------------------------------------------------------||
function RadioChecked(radiobutton) {
    var lbChecked = false;
    var liLen = radiobutton.length;
    for (i=0; i < liLen; i++) {
        if (radiobutton[i].checked)
            lbChecked = true;
    }
    return lbChecked;
}


//---------------------------------------------------------------------||
// 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 lsValue = null;
    for (var i=0; i < QueryString.keys.length; i++) {
        if (QueryString.keys[i] == key) {
            lsValue = QueryString.values[i];
            break;
        }
    }
    return lsValue;
}


//---------------------------------------------------------------------||
// FUNCTION:    QueryString_Parse                                      ||
// PARAMETERS:  (URL string)                                           ||
// RETURNS:     null                                                   ||
// PURPOSE:     Parses query string data, must be called before Q.S.   ||
//---------------------------------------------------------------------||
function QueryString_Parse() {
    var lsQuery = window.location.search.substring(1);
    var lsPairs = lsQuery.split("&");
    for (var i = 0; i < lsPairs.length; i++) {
        var pos = lsPairs[i].indexOf('=');
        if (pos >= 0) {
            var argname = lsPairs[i].substring(0,pos);
            var lsValue = lsPairs[i].substring(pos+1);
            QueryString.keys[QueryString.keys.length] = argname;
            QueryString.values[QueryString.values.length] = lsValue;
        }
    }
}


//---------------------------------------------------------------------||
// FUNCTION:    CartStatus                                             ||
// PARAMETERS:  null                                                   ||
// RETURNS:     number of items in cart                                ||
// PURPOSE:     Returns a status message about how many items in cart  ||
//---------------------------------------------------------------------||
function CartStatus() {
    var liTotalOrdered = GetCookie("TotalOrdered");
    if (liTotalOrdered == null)
        liTotalOrdered = 0;

    if (liTotalOrdered == 1)
        return(liTotalOrdered + " item in cart")
    else
        return(liTotalOrdered + " items in cart")
}

//---------------------------------------------------------------------||
// FUNCTION:    GetTotalOrdered                                        ||
// PARAMETERS:  null                                                   ||
// RETURNS:     total number of items in cart                          ||
// PURPOSE:     Returns the total number of items in the cart          ||
//---------------------------------------------------------------------||
function GetTotalOrdered() {
    var liTotalOrdered = GetCookie("TotalOrdered");
    if (liTotalOrdered == null)
        liTotalOrdered = 0;

    return(liTotalOrdered)
}


//---------------------------------------------------------------------||
// FUNCTION:    GetPostalRate                                          ||
// PARAMETERS:  null                                                   ||
// RETURNS:     The selected postal rate                               ||
// PURPOSE:     Returns the selected postal rate                       ||
//---------------------------------------------------------------------||
function GetPostalRate() {
    var lsPostalRate = GetCookie("PostalRate");
    if (lsPostalRate == null) {
        lsPostalRate = msDefaultPostalRate;
    }

    return lsPostalRate;
}

//---------------------------------------------------------------------||
// FUNCTION:    SavePostalRate                                         ||
// PARAMETERS:  The selected postal rate                               ||
// RETURNS:     null                                                   ||
// PURPOSE:     Saves the selected postal rate and refreshes the page  ||
//---------------------------------------------------------------------||
function SavePostalRate(postalRate) {
    //alert("SavePostalRate started");
    //var loCombo = document.getElementById("POSTAL_REGION");
    //alert("SavePostalRate loCombo=" + loCombo);
    //var lsPostalRate = loCombo.options[loCombo.selectedIndex].text;
    //var lsPostalRate = form.text
    //alert("SavePostalRate PostalRate=" + lsPostalRate);

    // Check if the value is different
    var lsOldRate = GetPostalRate();
    if (lsOldRate == postalRate) {
        return;
    }
    //alert("SavePostalRate Now PostalRate=" + postalRate);

    // Save the new region
    SetCookie("PostalRate", postalRate, null, "/");

    // Refresh the page
    RefreshPage();
}

//---------------------------------------------------------------------||
// FUNCTION:    GetPostalRegion                                        ||
// PARAMETERS:  null                                                   ||
// RETURNS:     The selected postal region                             ||
// PURPOSE:     Returns the selected postal region                     ||
//---------------------------------------------------------------------||
function GetPostalRegion(postalRate) {
    //alert("GetPostalRegion looking for '" + postalRate + "'");
    for (i = 0; i < msPostalRates.length; i++) {
        if (msPostalRates[i].name == postalRate) {
            //alert("GetPostalRegion Found rate");
            return msPostalRates[i].region;
        }
    }

    //alert("GetPostalRegion Not Found rate");
    return null;
}

//---------------------------------------------------------------------||
// FUNCTION:    GetInsurance                                           ||
// PARAMETERS:  null                                                   ||
// RETURNS:     The selected Insurance                                 ||
// PURPOSE:     Returns selected Insurance value                       ||
//---------------------------------------------------------------------||
function GetInsurance() {
    var lsInsurance = GetCookie("Insurance");
    if (lsInsurance == null)
        lsInsurance = "0";

    return(parseInt(lsInsurance))
}

//---------------------------------------------------------------------||
// FUNCTION:    SaveInsurance                                          ||
// PARAMETERS:  The selected insurance option                          ||
// RETURNS:     null                                                   ||
// PURPOSE:     Saves selected insurance option and refreshes the page ||
//---------------------------------------------------------------------||
function SaveInsurance(Insurance) {
    // Check if the value is different
    if (GetInsurance() == Insurance)
        return;

    // Save the new region
    SetCookie("Insurance", Insurance, null, "/");

    // Refresh the page
    RefreshPage();
}

function RefreshPage() {
    location.href="cart.html";
}

//---------------------------------------------------------------------||
// FUNCTION:    OutputHiddenLineItemDetails                            ||
// PARAMETERS:  Line no, fields to output                              ||
// RETURNS:     string containing the hidden input values              ||
// PURPOSE:     Returns the hidden fields for the line item            ||
//---------------------------------------------------------------------||
function OutputHiddenLineItemDetails(lineNo, fields) {
    var lsOutput = "";

    if (mbAppendItemNumToOutput) {
        lsSuffix = lineNo;
    } else {
        lsSuffix = "";
    }
    if (msOutputItemId != "") lsOutput += "<input type=hidden name=\"" + msOutputItemId + lsSuffix + "\" value=\"" + fields[miId] + "\">\n";
    if (msOutputItemQuantity != "") lsOutput += "<input type=hidden name=\"" + msOutputItemQuantity + lsSuffix + "\" value=\"" + fields[miQty] + "\">\n";
    if (msOutputItemPrice != "") lsOutput += "<input type=hidden name=\"" + msOutputItemPrice + lsSuffix + "\" value=\"" + fields[miPrice] + "\">\n";
    if (msOutputItemName != "") {
        if (msOutputItemAddtlInfo == "" && fields[miAdditionalInfo] != "")
            lsOutput += "<input type=hidden name=\"" + msOutputItemName + lsSuffix + "\" value=\"" + fields[miName] + " - " + fields[miAdditionalInfo] & "\">\n";
        else
            lsOutput += "<input type=hidden name=\"" + msOutputItemName + lsSuffix + "\" value=\"" + fields[miName] + "\">\n";
    }
    if (msOutputItemShipping != "") lsOutput += "<input type=hidden name=\"" + msOutputItemShipping  + lsSuffix + "\" value=\"" + fields[miShipping] + "\">\n";
    if (msOutputItemAddtlInfo != "") lsOutput += "<input type=hidden name=\"" + msOutputItemAddtlInfo + lsSuffix + "\" value=\"" + fields[miAdditionalInfo] + "\">\n";

    return lsOutput;
}

//---------------------------------------------------------------------||
// FUNCTION:    UpdateLinkText                                         ||
// PARAMETERS:  Text to identify link, and text to replace it with     ||
// RETURNS:     number of items in cart                                ||
// PURPOSE:     Returns a status message about how many items in cart  ||
//---------------------------------------------------------------------||
function UpdateLinkText(currentText, newText) {
    for (i = 0; i < document.links.length; i++) {
        if (document.links[i].innerText.indexOf(currentText) != -1) {
            document.links[i].innerText = newText;
            break;
        }
    }
}


//---------------------------------------------------------------------||
// FUNCTION:    ManageCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function ManageCart() {
    var liNumberOrdered = 0;    //Number of products ordered
    var ldTotal         = 0;    //Total cost of order
    var ldTax           = 0;    //Tax amount
    var ldShipping      = 0;    //Shipping amount
    var lsTotal         = "";   //Total cost formatted as money
    var lsTax           = "";   //Total tax formatted as money
    var lsShipping      = "";   //Total shipping formatted as money
    var lsOutput        = "";   //String to be written to page
    var lbDisplay       = true; //Whether to write string to the page (here for programmers)
    var liKeyringCount  = 0;
    var liOtherCount    = 0;
    var liLargeCount    = 0;
    var lbMustInsure    = false;

    // Get the number of line items
    liNumberOrdered = GetCookie("NumberOrdered");
    if (liNumberOrdered == null)
        liNumberOrdered = 0;

    var liCols = 6;
    if (! mbDisplayShippingColumn) liCols--;
    if (! mbDisplayIdColumn) liCols--;
    if (! mbDisplayQtyColumn) liCols--;
    if (! mbDisplayPriceColumn) liCols--;
    if (! mbDisplayImageColumn) liCols--;
    var liTotalCols = 2 + liCols;

    // Display table headings
    if (lbDisplay) {
        if (liNumberOrdered == 0) {
            lsOutput = "<TABLE CELLSPACING=10 CELLPADDING=0 BORDER=0 CLASS=\"Cart\"><TR>" +
                        (mbDisplayImageColumn ? "<TD CLASS=\"Image\"></TD>" : "") +
                        (mbDisplayIdColumn ? "<TD CLASS=\"Id\"></TD>" : "") +
                        "<TD CLASS=\"Empty\"><CENTER>Your cart is empty</CENTER></TD>" +
                        (mbDisplayQtyColumn ? "<TD CLASS=\"Qty\"></TD>" : "") +
                        (mbDisplayPriceColumn ? "<TD CLASS=\"Price\"></TD>" : "") +
                        (mbDisplayShippingColumn ? "<TD CLASS=\"Shipping\"></TD>" : "") +
                        "<TD CLASS=\"Button\"></TD></TR>\n";
        } else
            lsOutput = "<TABLE CELLSPACING=10 CELLPADDING=0 BORDER=0 CLASS=\"Cart\">";
/*
            lsOutput = "<TR>" +
                        (mbDisplayImageColumn ? "<TH CLASS=\"Image\">" + msGLabel + "</TD>" : "") +
                        (mbDisplayIdColumn ? "<TH CLASS=\"Id\">" + msILabel + "</TD>" : "") +
                        "<TH CLASS=\"Descr\">" + msDLabel + "</TD>" +
                        (mbDisplayQtyColumn ? "<TH CLASS=\"Qty\">" + msQLabel + "</TD>" : "") +
                        (mbDisplayPriceColumn ? "<TH CLASS=\"Price\">" + msPLabel + "</TD>" : "") +
                        (mbDisplayShippingColumn ? "<TH CLASS=\"Shipping\">" + msSLabel + "</TD>" : "") +
                        "<TD CLASS=\"Button\"></TD><TD CLASS=\"Button\" ALIGN=RIGHT><INPUT TYPE=IMAGE SRC="images/clearcart.gif" WIDTH=80 HEIGHT=24 ALT=\"Clear Cart\" onClick=\"ClearCart();return false\"></TD>" +
                        "</TR>\n";
*/
    }

    // Go through each line item
    ldItemSavings = 0.00;
    lsPostalRate = GetPostalRate();
    //alert("ManageCart lsPostalRate=" + lsPostalRate);
    lsPostalRegion = GetPostalRegion(lsPostalRate);
    //alert("ManageCart lsPostalRegion=" + lsPostalRegion);
    for (i = 1; i <= liNumberOrdered; i++) {
        // Get the line details
        lsFields = GetLine(i);

        // Get the item shipping amount etc
        ldItemShipping = parseFloat(lsFields[miShipping]);
        liQuantity = parseInt(lsFields[miQty]);

        // Update counts for combined postage calculations
        lbKeyring = false;
        lbLargeBox = false;
        if (lsFields[miId].indexOf("KEY") < 0) {
            liOtherCount += liQuantity;
            //alert("LARGE_BOX=" + lsFields[miLargeBox]);
            if (lsFields[miLargeBox] == "Y") {
                liLargeCount += liQuantity;
                lbLargeBox = true;
            }
        } else {
            liKeyringCount += liQuantity;
            lbKeyring = true;
        }

        // Check if must insure shipment
        if (lsFields[miMustInsure] == "Y")
            lbMustInsure = true;

        // See if shipping needs to be determined.
        liWeight = parseInt(lsFields[miWeight]);
        if (ldItemShipping == 0.0 && liWeight > 0) {
            //alert("lsPostalRegion=" + lsPostalRegion + " liWeight=" + liWeight);
            liIndex = Math.floor((liWeight + 249) / 250) - 1;
            //alert("liIndex=" + liIndex + " liWeight=" + liWeight + " lsPostalRegion=" + lsPostalRegion);
            if (lbKeyring && (lsPostalRegion == "0" || lsPostalRegion == "2")) {
                ldItemShipping = mdKeyringRegular
            } else if (lbLargeBox && (lsPostalRegion == "0" || lsPostalRegion == "2" || lsPostalRegion == "3")) {
                ldItemShipping = mdLargeBoxRegular
            } else if (lsPostalRegion) {
                ldItemShipping = mdPostalRates[lsPostalRegion][liIndex];
            }
        }

        lsOrigPrice = lsFields[miOriginalPrice];
        if (lsOrigPrice == null) lsOrigPrice = "";

        // Update the totals
        ldPrice = parseFloat(lsFields[miPrice]);
        ldTotal     += (liQuantity * ldPrice);
        ldShipping  += (liQuantity * ldItemShipping);
        ldTax        = (ldTotal * mdTaxRate);
        if (lsOrigPrice != "") {
            ldItemSavings += liQuantity * (parseFloat(lsOrigPrice) - ldPrice);
        }

        // Output the line details
        if (lbDisplay) {
            lsOutput += "<TR>";
            if (mbDisplayImageColumn) {
                lsOutput += "<TD CLASS=\"Image\">"
                if (i == liNumberOrdered) lsOutput +="<A NAME=Total>";
                lsImage = lsFields[miImage];
                if (lsImage != "") {
                    lsOutput += "<DIV CLASS=\"img2\">";
                    if (lsFields[miUrl] != "")
                        lsOutput += "<A HREF=\"" + lsFields[miUrl] + "\">";
                    lsOutput += "<IMG SRC=\"" + lsImage + "\">";
                    if (lsFields[miUrl] != "")
                        lsOutput += "</A>";
                    lsOutput += "</DIV>";
                }
                lsOutput += "</TD>\n";
            }
            if (mbDisplayIdColumn)
                lsOutput += "<TD CLASS=\"Id\">"  + lsFields[miId] + "</TD>\n";

            lsOutput += "<TD CLASS=\"Descr\">";
            if (i == liNumberOrdered && (! mbDisplayImageColumn)) lsOutput +="<A NAME=Total>";
            if (! mbDisplayQtyColumn)
                lsOutput += "<INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + lsFields[miQty] + "\" onChange=\"this.value=ChangeQuantity(" + i + ", this.value);\"> &nbsp; ";
            lsOutput += lsFields[miName];
            if (lsFields[miAdditionalInfo] != "")
                lsOutput += " - <I>" +  lsFields[miAdditionalInfo] + "</I>";
            if (lsFields[miMustInsure] == "Y")
                lsOutput += " (*)";
            if (! mbDisplayPriceColumn) {
                lsOutput += "<BR><BR>\n";
                lsOutput += msMonetarySymbol + moneyFormat(lsFields[miPrice]) + " each\n";
                if (lsOrigPrice != "") lsOutput += "<BR><DIV CLASS=\"OldPrice\">" + msMonetarySymbol + lsOrigPrice + " each</DIV>";
            }
            lsOutput += "</TD>\n";

            if (mbDisplayQtyColumn)
                lsOutput += "<TD CLASS=\"Qty\"><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + lsFields[miQty] + "\" onChange=\"this.value=ChangeQuantity(" + i + ", this.value);\"></TD>\n";

            if (mbDisplayPriceColumn) {
                lsOutput += "<TD CLASS=\"Price\">";
                if (lsOrigPrice != "") lsOutput += "<DIV CLASS=\"OldPrice\">" + msMonetarySymbol + lsOrigPrice + " each</DIV><BR>";
                lsOutput += msMonetarySymbol + moneyFormat(lsFields[miPrice]) + " each</TD>\n";
            }
            if (mbDisplayShippingColumn) {
                if (ldItemShipping > 0)
                    lsOutput += "<TD CLASS=\"Shipping\">" +  msMonetarySymbol + moneyFormat(ldItemShipping) + " each</TD>\n";
                else
                    lsOutput += "<TD CLASS=\"Shipping\">N/A</TD>\n";
            }

            lsOutput += "<TD CLASS=\"Button\" ALIGN=RIGHT><input TYPE=IMAGE SRC=\"images/removecart.gif\" WIDTH=70 HEIGHT=24 ALT=\"Remove From Cart\" onClick=\"RemoveFromCart(" + i + ")\" CLASS=\"Button\"></TD>";
            if (i == 1)
                lsOutput += "<TD CLASS=\"Button\" ALIGN=RIGHT><INPUT TYPE=IMAGE SRC=\"images/clearcart.gif\" WIDTH=80 HEIGHT=24 ALT=\"\Clear Cart\" onClick=\"ClearCart();return false\"></TD>"
            lsOutput += "</TR>\n";
        }

        if (mbHiddenFieldsToCheckout) {
            lsOutput += OutputHiddenLineItemDetails(i, lsFields);
        }
    }

    // Determine Combined Postage
    //alert("liOtherCount=" + liOtherCount + " liKeyringCount=" + liKeyringCount);
    liTotalOrdered = GetTotalOrdered();
    ldPostageSavings = 0.00;

    if (lsPostalRegion < "A") {
        lbIsAU = true;
        ldMinInsurance = mdMinAUInsurance;
        ldDiscount = mdDiscountAUOther;
        ldDiscountKey = mdDiscountAUKey;
    } else {
        lbIsAU = false;
        ldMinInsurance = mdMinOSInsurance;
        ldDiscount = mdDiscountOSOther;
        ldDiscountKey = mdDiscountOSKey;
    }

    liCombinableItems = liOtherCount - liLargeCount + liKeyringCount;
    if (liCombinableItems > 1) {
        if (liCombinableItems == liKeyringCount)
            ldPostageSavings = (liKeyringCount - 1) * ldDiscountKey
        else
            ldPostageSavings = (liOtherCount - liLargeCount - 1) * ldDiscount + liKeyringCount * ldDiscountKey;
        ldShipping = ldShipping - ldPostageSavings;
    }
    if (lsPostalRegion == "2") {
        ldLocalShipping = mdLocalBase + (liKeyringCount + liOtherCount - 1) * mdLocalPerItem;
        if (ldLocalShipping < ldShipping) {
            ldPostageSavings = ldPostageSavings + (ldShipping - ldLocalShipping);
            ldShipping = ldLocalShipping;
        }
    } else if (lsPostalRegion == "3") {
            ldPostageSavings = ldPostageSavings + ldShipping;
            ldShipping = 0.0;
    }

    // If an item must be insured then set the option
    liInsurance = GetInsurance();
    lsMustInsureReason = "";
    if (lbMustInsure) {
        liInsurance = 1;
        lsMustInsureReason = "(*) This item requires insurance.";
    } else {
        if (ldTotal >= ldMinInsurance && ldMinInsurance > 0) {
            lsMustInsureReason = "Orders totalling " + msMonetarySymbol + moneyFormat(ldMinInsurance) + " or more must be insured.";
            liInsurance = 1;
            lbMustInsure = true;
        }
    }
    if (liInsurance == 0)
        lsMustInsureReason = "I cannot take responsibility for orders<BR>that are lost or damaged if insurance is not taken.";

    lbInsuranceDisabled = lbMustInsure;

    // Handle ExpressPost
    if (lsPostalRegion == "1") {
        lbInsuranceDisabled = true;
        lsMustInsureReason = "ExpressPost packages cannot be insured.";
        liInsurance = 0;
    }

    // Handle Local Pickup
    if (lsPostalRegion == "3") {
        lbInsuranceDisabled = true;
        lsMustInsureReason = "";
        liInsurance = 0;
    }

    ldInsuranceSavings = 0.00;
    ldInsurance = 0.00;
    if (mbDisplayInsuranceRow && liInsurance == 1 && liTotalOrdered > 0) {
        if (lbIsAU)
            ldInsurance = mdInsuranceAUBase + mdInsuranceAUPer100 * Math.floor(ldTotal / 100);
        else
            ldInsurance = mdInsuranceOSBase + mdInsuranceOSPer100 * Math.floor(ldTotal / 100);
    }

    mdTotalCost = (ldTotal + ldShipping + ldTax + ldInsurance);
    ldTotalSavings = (ldItemSavings + ldPostageSavings + ldInsuranceSavings);
    lsTotal = moneyFormat(ldTotal);
    lsTax = moneyFormat(ldTax);
    lsShipping = moneyFormat(ldShipping);
    lsInsurance = moneyFormat(ldInsurance);

    // Output the totals
    if (lbDisplay) {
        lsOutput += "<TR><TD COLSPAN=" + liCols + ">&nbsp;</TD><TD CLASS=\"Total\">Subtotals</TD>";
        if (ldTotalSavings > 0) lsOutput += "<TD CLASS=\"Saving\">Savings</TD>";
        lsOutput += "</TR>";
        lsOutput += "<TR><TD CLASS=\"TotalHead\" COLSPAN=" + liCols + ">" + msSub + "</TD>";
        lsOutput += "<TD CLASS=\"Total\">" + msMonetarySymbol + lsTotal + "</TD>";
        if (ldItemSavings > 0) lsOutput += "<TD CLASS=\"Saving\">" + msMonetarySymbol + moneyFormat(ldItemSavings) + "</TD>";
        lsOutput += "</TR>\n";

        if (mbDisplayShippingRow) {
            lsOutput += "<TR><TD CLASS=\"TotalHead\">"
            if (ldPostageSavings > 0) lsOutput += "COMBINED ";
            lsOutput += msShip + "</TD>";
            lsOutput += "<TD CLASS=\"TotalLeft\" COLSPAN=" + (liCols - 1) + "><SELECT NAME=\"POSTAL_REGION\" onChange=\"SavePostalRate(this.value);\">\n";
            for (i = 0; i < msPostalRates.length; i++) {
                lsOutput += "<OPTION ";
                if (msPostalRates[i].name == lsPostalRate)
                    lsOutput += " SELECTED=\"SELECTED\""
                lsOutput += " VALUE=\"" + msPostalRates[i].name + "\">" + msPostalRates[i].name + "</OPTION>\n";
                //lsOutput += " >" + msPostalRates[i].name + "</OPTION>\n";
            }
            lsOutput += "</SELECT></TD>";
            lsOutput += "<TD CLASS=\"Total\">";
            if (lsPostalRegion)
                lsOutput += msMonetarySymbol + lsShipping;
            lsOutput += "</TD>";
            if (ldPostageSavings > 0) lsOutput += "<TD CLASS=\"Saving\">" + msMonetarySymbol + moneyFormat(ldPostageSavings) + "</TD>";
            lsOutput += "</TR>\n";
        }
        // Handle Local Pickup
        if (lsPostalRegion == "3") {
            lsOutput += "<TR><TD></TD><TD COLSPAN=3 CLASS=\"TotalHead\">You must pre-arrange the local pickup before proceeding with this order.<BR>Click <A TARGET=\"LocalPickup\" HREF=\"localpickup.html\">here</A> for more information.</TD></TR>";
        }

        if (mbDisplayInsuranceRow && lsPostalRegion != "3") {
            lsOutput += "<TR><TD CLASS=\"TotalHead\">" + msInsure + "</TD>";
            lsOutput += "<TD CLASS=\"TotalLeft\" COLSPAN=" + (liCols - 1) + "><SELECT NAME=\"INSURANCE\" onChange=\"SaveInsurance(this.value);\"";
            if (lbInsuranceDisabled)
                lsOutput += " DISABLED=\"DISABLED\""
            lsOutput += ">\n"
            for (i = 0; i < msInsuranceOptions.length; i++) {
                lsOutput += "<OPTION VALUE=\"" + i + "\"";
                if (i == liInsurance)
                    lsOutput += " SELECTED=\"SELECTED\""
                lsOutput += ">" + msInsuranceOptions[i] + "</OPTION>\n";
            }
            lsOutput += "</SELECT>";
            if (lsMustInsureReason != "")
                lsOutput += " &nbsp; " + lsMustInsureReason;
            lsOutput += "</TD>";

            lsOutput += "<TD CLASS=\"Total\">" + msMonetarySymbol + lsInsurance + "</TD>";
            if (ldInsuranceSavings > 0) lsOutput += "<TD CLASS=\"Saving\">" + msMonetarySymbol + moneyFormat(ldInsuranceSavings) + "</TD>";
            lsOutput += "</TR>\n";
        }

        if (mbDisplayTaxRow || mbTaxByRegion) {
            if (mbTaxByRegion) {
                lsOutput += "<TR><TD CLASS=\"Total\" COLSPAN=" + liCols + ">" + lsTax + "</TD>";
                lsOutput += "<TD CLASS=\"Total\">";
                lsOutput += "<input type=radio name=\"" + msOutputOrderTax + "\" value=\"" + lsTax + "\">";
                lsOutput += msTaxablePrompt + ": " + msMonetarySymbol + lsTax;
                lsOutput += "<BR><input type=radio name=\"" + msOutputOrderTax + "\" value=\"0.00\">";
                lsOutput += msNonTaxablePrompt + ": " + msMonetarySymbol + "0.00";
                lsOutput += "</TD>";
                lsOutput += "</TR>\n";
            } else {
                lsOutput += "<TR><TD CLASS=\"TotalHead\" COLSPAN=" + liCols + ">" + lsTax + "</TD>";
                lsOutput += "<TD CLASS=\"Total\">" + msMonetarySymbol + lsTax + "</TD>";
                lsOutput += "</TR>\n";
            }
        }

        if (! mbTaxByRegion) {
            lsOutput += "<TR><TD CLASS=\"GrandTotalHead\" COLSPAN=" + liCols + ">" + msTotal + "</A></TD>";
            lsOutput += "<TD CLASS=\"GrandTotal\">" + msMonetarySymbol + moneyFormat(mdTotalCost) + "</TD>";
            if (ldTotalSavings > 0) lsOutput += "<TD CLASS=\"SavingTotal\">" + msMonetarySymbol + moneyFormat(ldTotalSavings) + "</TD>";
            lsOutput += "</TR>\n";
        }
//        if (liNumberOrdered > 0)
//            lsOutput += "<TR><TD CLASS=\"TotalHead\" COLSPAN=" + liCols + "></TD><TD CLASS=\"Button\" ALIGN=RIGHT><BR><BR><INPUT TYPE=IMAGE NAME=SUBMIT src=\"images/paypalcheckout.gif\"></TD></TR>";


        if (! lbIsAU)
            lsOutput += "<TR><TD COLSPAN=" + liTotalCols + " ALIGN=CENTER>Go to a currency converter such as the <A TARGET=UCC HREF=\"http://www.xe.com/ucc/\">Universal Currency Converter</A> to get an idea of these amounts in your local currency.<BR>The exact amount will be slightly different when you checkout through PayPal.</TD></TR>";

        lsOutput += "<TR><TD COLSPAN=" + liTotalCols + " ALIGN=CENTER><B>Make sure you have chosen the correct postage options before proceeding.</B></TD></TR>";
        lsOutput += "</TABLE>\n";

        if (mbHiddenFieldsToCheckout) {
            if (ldInsurance > 0) {
                lsFields = new Array;
                lsFields[miId] = "";
                lsFields[miQty] = "1";
                lsFields[miPrice] = ldInsurance;
                lsFields[miName] = "Insurance";
                lsFields[miShipping] = "";
                lsFields[miAdditionalInfo] = "";
                lsFields[miWeight] = "";
                lsFields[miMaxQuantity] = "";
                lsFields[miMustInsure] = "";
                lsFields[miImage] = "";
                lsFields[miUrl] = "";
                lsFields[miOriginalPrice] = "";
                lsFields[miLargeBox] = "";
                liNumberOrdered = parseInt(liNumberOrdered) + 1
                lsOutput += OutputHiddenLineItemDetails(liNumberOrdered, lsFields);
            }

            if (msOutputOrderSubtotal != "") lsOutput += "<input type=hidden name=\"" + msOutputOrderSubtotal + "\" value=\"" +  lsTotal + "\">\n";
            if (msOutputOrderShipping != "") lsOutput += "<input type=hidden name=\"" + msOutputOrderShipping + "\" value=\"" +  lsShipping + "\">\n";
            if (msOutputOrderTax != "") lsOutput += "<input type=hidden name=\"" + msOutputOrderTax + "\"      value=\"" +  lsTax + "\">\n";
            if (msOutputOrderTotal != "") lsOutput += "<input type=hidden name=\"" + msOutputOrderTotal + "\"    value=\"" +  moneyFormat((ldTotal + ldShipping + ldInsurance + ldTax)) + "\">\n";
            if (msOutputOrderShippingV != "") lsOutput += "<input type=hidden name=\"" + msOutputOrderShippingV.replace("#", liNumberOrdered) + "\" value=\"" + lsPostalRate + "\">\n";
            if (msOutputOrderShippingL != "") lsOutput += "<input type=hidden name=\"" + msOutputOrderShippingL.replace("#", liNumberOrdered) + "\" value=\"" + msOutputOrderShippingN + "\">\n";
            lsOutput += "<input type=hidden name=\"ITEM_COUNT\" value=\"" +  liNumberOrdered + "\">\n";
        }
    }

    //lsOutput += "<textarea rows=10 cols=80>" + lsOutput + "</textarea>";
    //alert(lsOutput);
    document.write(lsOutput);
    document.close();
    return true;
}


//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
var mdTotalCost = 0;
function ValidateCart(theForm) {
    if (mbTaxByRegion) {
        if (! RadioChecked(eval("theForm." + msOutputOrderTax))) {
           alert(msTaxPrompt);
           return false;
        }
    }

    if (mdMinimumOrder >= 0.01) {
        if (mdTotalCost < mdMinimumOrder) {
            alert(msMinimumOrderPrompt);
            return false;
        }
    }

    if (! GetPostalRegion(GetPostalRate())) {
        alert("You must choose the destination country before proceeding");
        return false;
    }
    return true;
}


//---------------------------------------------------------------------||
// FUNCTION:    ValidateBank                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the bank form                                ||
//---------------------------------------------------------------------||
function ValidateBank(theForm) {
    if (mdMinimumOrder >= 0.01) {
        if (mdTotalCost < mdMinimumOrder) {
            alert(msMinimumOrderPrompt);
            return false;
        }
    }
    if (theForm.EMAIL_ADDRESS.value == null)
        lsEmailAddress = ""
    else
        lsEmailAddress = theForm.EMAIL_ADDRESS.value;
    if (theForm.POSTAL_ADDRESS.value == null)
        lsPostalAddress = ""
    else
        lsPostalAddress = theForm.POSTAL_ADDRESS.value;
    if (theForm.SAVE_SETTINGS.value == null)
        lbSettings = false
    else
        lbSettings = theForm.SAVE_SETTINGS.checked;

    if (lbSettings) {
        SetCookie("EmailAddress", lsEmailAddress, null, "/");
        SetCookie("PostalAddress", lsPostalAddress, null, "/");
    }

    if (lsEmailAddress == "") {
        alert("Please enter your email address.");
        return false;
    } else {
        var lsFilter = /^.+@.+\..{2,3}$/
        if (! lsFilter.test(lsEmailAddress)) {
            alert("Please enter a valid email address.");
            return false;
        }
    }
    if (lsPostalAddress == "") {
        alert("Please enter your postal address.");
        return false;
    }

    lsPostalRate = GetPostalRate();
    lsPostalRegion = GetPostalRegion(lsPostalRate);
    if (lsPostalRegion >= "A") {
        alert("You have chosen an overseas postal region - Direct Deposit is only available to Australian Customers.");
        return false;
    }
    return true;
}



function SubmitForm() {
    if (document.CartForm.onsubmit()) {
        ClearCartDetails();
        document.CartForm.action = 'https://www.paypal.com/cgi-bin/webscr';
        //document.CartForm.target = "paypal";
        document.CartForm.submit();
    }
}

function SendEmail() {
    if (ValidateBank(document.CartForm)) {
        ClearCartDetails();
        document.CartForm.action = 'http://newfarm.mine.nu:8080/bos/cgibin/bosweb.exe';
        document.CartForm.submit();
    }
}

function CheckSearch(theForm) {
    if (theForm.Text.value == null)
        lsText = ""
    else
        lsText = theForm.Text.value;

    if (lsText == "")
        return false;

    return true;
}

function DoSearch() {
    if (CheckSearch(document.Search)) {
        document.Search.submit();
    }
}


function GetEmailAddress() {
    lsValue = GetCookie("EmailAddress");
    if (lsValue == null) lsValue = "";
    document.write("<INPUT NAME=\"EMAIL_ADDRESS\" VALUE=\"" + lsValue + "\" SIZE=40>");

}

function GetPostalAddress() {
    lsValue = GetCookie("PostalAddress");
    if (lsValue == null) lsValue = "";
    document.write("<TEXTAREA NAME=POSTAL_ADDRESS COLS=40 ROWS=4>" + lsValue + "</TEXTAREA>");
}


//---------------------------------------------------------------------||
// FUNCTION:    CheckoutCart                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page for      ||
//              checkout.                                              ||
//---------------------------------------------------------------------||
function CheckoutCart() {
    var liNumberOrdered = 0;    //Number of products ordered
    var ldTotal         = 0;    //Total cost of order
    var ldTax           = 0;    //Tax amount
    var ldShipping      = 0;    //Shipping amount
    var lsTotal       = "";   //Total cost formatted as money
    var lsTax         = "";   //Total tax formatted as money
    var lsShipping    = "";   //Total shipping formatted as money
    var lsOutput      = "";   //String to be written to page
    var lbDisplay       = true; //Whether to write string to the page (here for programmers)
    var lsPPDescr          = "";   //Payment Processor Description Field

    liNumberOrdered = GetCookie("NumberOrdered");
    if (liNumberOrdered == null)
        liNumberOrdered = 0;

    if (mbTaxByRegion) {
        QueryString_Parse();
        ldTax = parseFloat(QueryString(msOutputOrderTax));
        lsTax = moneyFormat(ldTax);
    }

    if (lbDisplay)
        lsOutput = "<TABLE CLASS=\"Cart\"><TR>" +
                    "<TH CLASS=\"Id\">" + msILabel + "</TD>" +
                    "<TH CLASS=\"Descr\">" + msDLabel + "</TD>" +
                    "<TH CLASS=\"Qty\">" + msQLabel + "</TD>" +
                    "<TH CLASS=\"Price\">" + msPLabel + "</TD>" +
                    (mbDisplayShippingColumn?"<TH CLASS=\"Shipping\">" + msSLabel + "</TD>":"") +
                    "</TR>";

    for (i = 1; i <= liNumberOrdered; i++) {
        lsFields = GetLine(i);

        ldTotal     += (parseInt(lsFields[miQty]) * parseFloat(lsFields[miPrice]));
        ldShipping  += (parseInt(lsFields[miQty]) * parseFloat(lsFields[miShipping]));
        if (! mbTaxByRegion) ldTax = (ldTotal * mdTaxRate);

        if (lbDisplay) {
            lsOutput += "<TR><TD CLASS=\"Id\">"  + lsFields[miId] + "</TD>";

            if (lsFields[miAdditionalInfo] == "")
                lsOutput += "<TD CLASS=\"Descr\">"  + lsFields[miName] + "</TD>";
            else
                lsOutput += "<TD CLASS=\"Descr\">"  + lsFields[miName] + " - <I>" +  lsFields[miAdditionalInfo] + "</I></TD>";

            lsOutput += "<TD CLASS=\"Qty\">" + lsFields[miQty] + "</TD>";
            lsOutput += "<TD CLASS=\"Price\">" +  msMonetarySymbol + moneyFormat(lsFields[miPrice]) + "/ea</TD>";

            if (mbDisplayShippingColumn) {
                if (parseFloat(lsFields[miShipping]) > 0)
                    lsOutput += "<TD CLASS=\"Shipping\">" +  msMonetarySymbol + moneyFormat(lsFields[miShipping]) + "/ea</TD>";
                else
                    lsOutput += "<TD CLASS=\"Shipping\">N/A</TD>";
            }

            lsOutput += "</TR>";
        }

        if (msPaymentProcessor != '') {
            //Process description field for payment processors instead of hidden values.
            //Format Description of product as:
            // ID, Name, Qty X
            lsPPDescr += lsFields[miId] + ", " + lsFields[miName];
            if (lsFields[miAdditionalInfo] != "")
                lsPPDescr += " - " + lsFields[miAdditionalInfo];
            lsPPDescr += ", Qty. " + lsFields[miQty] + "\n";
        } else {
            if (mbAppendItemNumToOutput) {
                lsSuffix = i;
            } else {
                lsSuffix = "";
            }
            lsOutput += "<input type=hidden name=\"" + msOutputItemId        + lsSuffix + "\" value=\"" + lsFields[miId] + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputItemQuantity  + lsSuffix + "\" value=\"" + lsFields[miQty] + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputItemPrice     + lsSuffix + "\" value=\"" + lsFields[miPrice] + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputItemName      + lsSuffix + "\" value=\"" + lsFields[miName] + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputItemShipping  + lsSuffix + "\" value=\"" + lsFields[miShipping] + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputItemAddtlInfo + lsSuffix + "\" value=\"" + lsFields[miAdditionalInfo] + "\">";
        }

    }
    lsTotal = moneyFormat(ldTotal);
    lsTax = moneyFormat(ldTax);
    lsShipping = moneyFormat(ldShipping);

    if (lbDisplay) {
        lsOutput += "<TR><TD CLASS=\"Total\" COLSPAN=3>" + msSub + "</TD>";
        lsOutput += "<TD CLASS=\"Total\" COLSPAN=2 ALIGN=RIGHT>" + msMonetarySymbol + lsTotal + "</TD>";
        lsOutput += "</TR>";

        if (mbDisplayShippingRow) {
            lsOutput += "<TR><TD CLASS=\"Total\" COLSPAN=3>" + msShip + "</TD>";
            lsOutput += "<TD CLASS=\"Total\" COLSPAN=2 ALIGN=RIGHT>" + msMonetarySymbol + lsShipping + "</TD>";
            lsOutput += "</TR>";
        }

        if (mbDisplayTaxRow || mbTaxByRegion) {
            lsOutput += "<TR><TD CLASS=\"Total\" COLSPAN=3>" + lsTax + "</TD>";
            lsOutput += "<TD CLASS=\"Total\" COLSPAN=2 ALIGN=RIGHT>" + msMonetarySymbol + lsTax + "</TD>";
            lsOutput += "</TR>";
        }

        lsOutput += "<TR><TD CLASS=\"Total\" COLSPAN=3>" + msTotal + "</TD>";
        lsOutput += "<TD CLASS=\"Total\" COLSPAN=2 ALIGN=RIGHT>" + msMonetarySymbol + moneyFormat((ldTotal + ldShipping + ldTax)) + "</TD>";
        lsOutput += "</TR>";

        lsOutput += "</TABLE>";


        if (msPaymentProcessor == 'an') {
            //Process this for Authorize.net WebConnect
            lsOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">";
            lsOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">";
            lsOutput += "<input type=hidden name=\"x_Description\" value=\"" +  lsPPDescr + "\">";
            lsOutput += "<input type=hidden name=\"x_Amount\" value=\"" +  moneyFormat((ldTotal + ldShipping + ldTax)) + "\">";
        } else if (msPaymentProcessor == 'wp') {
            //Process this for WorldPay
            lsOutput += "<input type=hidden name=\"desc\" value=\"" +  lsPPDescr + "\">";
            lsOutput += "<input type=hidden name=\"amount\" value=\"" +  moneyFormat((ldTotal + ldShipping + ldTax)) + "\">";
        } else if (msPaymentProcessor == 'lp') {
            //Process this for LinkPoint
            lsOutput += "<input type=hidden name=\"mode\" value=\"fullpay\">";
            lsOutput += "<input type=hidden name=\"chargetotal\" value=\"" +  moneyFormat((ldTotal + ldShipping + ldTax)) + "\">";
            lsOutput += "<input type=hidden name=\"tax\" value=\"" +  msMonetarySymbol + lsTax + "\">";
            lsOutput += "<input type=hidden name=\"subtotal\" value=\"" +  msMonetarySymbol + lsTotal + "\">";
            lsOutput += "<input type=hidden name=\"shipping\" value=\"" +  msMonetarySymbol + lsShipping + "\">";
            lsOutput += "<input type=hidden name=\"desc\" value=\"" +  lsPPDescr + "\">";
        } else {
            lsOutput += "<input type=hidden name=\"" + msOutputOrderSubtotal + "\" value=\"" +  lsTotal + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputOrderShipping + "\" value=\"" +  lsShipping + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputOrderTax + "\"      value=\"" +  lsTax + "\">";
            lsOutput += "<input type=hidden name=\"" + msOutputOrderTotal + "\"    value=\"" +  moneyFormat((ldTotal + ldShipping + ldTax)) + "\">";
        }
    }

    document.write(lsOutput);
    document.close();
}

//=====================================================================||
//               END Shopping Cart                                     ||
//=====================================================================||

