// NebuCart - The JavaScript Shopping Cart
// E-Commerce YOUR way
// Originally authored by Pat Friedl pfriedl@nebulus.org
// Copyright 1999-2006 all rights reserved.

// None of this script may be redistributed or sold
// without the authors express consent.
// Violations of copyright will be prosecuted.

// If you would like to use NebuCart,
// email us at admin@javascriptcart.com
// or visit http://www.javascriptcart.com

// ********************************************
// NebuCart User Defined Settings             *
// ********************************************
// Cart variables - you edit these to taste   *
// ********************************************

// Debug Mode. Setting DEBUG to true will allow
// you to see descriptions of errors in a window.
// You should probably set this to false
// when you run the cart live
var DEBUG = false;

/*
We are testing a new mailing script in the hope we 
can use it in the very near future. Setting this
mailTest variable to true will generate two emails
using our new test mail script. Setting it to false
and using our FREE mailsender script will generate
live order data emails.

BEFORE YOU SET THIS TO FALSE, when using the FREE
NC_mailsender.asp script, set your correct email 
address in myEmail below, otherwise your customers 
will get a bounced email from GeoStore!!!!!!     */
var mailTest = false;

// set your company information here. This will all
// be generated on the printable order form
// Default settings are for GeoStore
var myName      = 'Dolce';
var mySite      = 'http://www.dolce.com.au';
var myEmail     = 'coffee@dolce.com.au';
var myPhone     = '02 9232 2938';
var myFax		= '02 9232 4789';
var myAddress   = 'SHOP 2-3, DEUTSCHE BANK PLACE<br\>126 PHILLIP STREET ';
var myCityState = 'SYDNEY';
var myZip       = '2000';
var myCountry   = 'Australia';
var myLogo      = '';
//if (location.host!=mySite)location.href='http://'+mySite;

// this is your prefix for all cookies written by your
// implementation of the cart. Do not use spaces!
var myStoreName    = 'dolce';

// set the domain values for your cookies.
// this should allow you to put catalog
// pages in different directories.
// domain values require two "."!
var unsecureDomain = '';
var secureDomain   = '';

// set the path for the cookies
// currently, we set the path as root.
var cookiePath     = '/';

// set customer Info persistence and
// cart persistence via cookies.
// usage: "setExp(S,M,H,D,W,Mo,Y)"
// S = seconds, M = minutes, H = hours
// D = days, W = weeks, Mo = months, Y = years

// You should consider that some users may be
// shopping from a shared computer and the 
// Cart data can be cleared upon a completed
// order by the final thankyou.html page.
// default times:
// customer = 2 months,
// cart: 30 mintues
// Set to ''; to have the data expire once the 
// user closes the browser.
var customerTime = 'setExp(0,0,0,0,0,2,0)';
var cartTime     = 'setExp(0,30,0,0,0,0,0)';

// set this variable to true if you don't want the
// cart page to display each time an item's added.
// if set to true, you will get a pop up instead.
var supressCart  = false;

// set the font face to whatever font you're using on your site
// Default setting is "arial,helvetica"

var fontFace = 'Verdana, Arial, Helvetica, sans-serif';

// cart look and feel
// these set the colors for the cart table
var cartHeader       = 'silver';
var cartRow1         = 'white';
var cartRow2         = '#DDDDDD';
var cartTaxRow       = '#DDDDDD';
var cartShipRow      = '#DDDDDD';
var cartSubRow       = '#DDDDDD';
var cartTotalRow     = 'silver';
var cartBorder       = '0';
var cartCellPad      = '2';
var cartCellSpace    = '2';
var cartHeaderTxt    = 'black';
var cartRowTxt       = 'black';
var cartTaxRowTxt    = 'black';
var cartShipRowTxt   = 'black';
var cartSubRowTxt    = 'black';
var cartTotalRowTxt  = 'black';

// cart button text
// these variables set the text for each button in the cart
// some are used in more places than one, so use general
// descriptions!
var backText           = 'Back';
var clearFormText      = 'Clear';
var cartUpdateText     = 'Update Cart';
var checkoutText       = 'Checkout';
var keepShopText       = 'Keep Shopping';
var deleteCartText     = 'Delete Cart';
var printFormText      = 'Fax Order';
var unsecureFormText   = 'Email Order';
var unsecureCreditText = 'Insecure Merchant Account Gateway';
var secureFormText     = 'Email Order';
var secureCreditText   = 'Secure Merchant Account Gateway';
var printMyOrderText   = 'Fax Order';
var orderFinalizeText  = 'Send Email';
var editCartText       = 'Edit Cart';

// cart title text
// these variables set the text for the cart table header
// and for other titles in the cart table
var cartIDText         = 'Item';
var cartDescText       = 'Description';
var cartOptText        = 'Special Instructions';
var cartPriceText      = 'Price';
var cartCostText       = 'Cost';
var cartQtyText        = 'Quantity';
var cartTotalText      = 'Total:';
var cartSubtotalText   = 'Subtotal:';
var cartTaxText        = 'Tax:';
var cartSnHText        = 'S &amp; H'; //Shipping & Handling
var cartDiscountText   = 'Quantity Discount:';
var cartEmptyText      = 'Your cart is currently empty.';

// billing/shipping titles
// these variables set the text for the billing and shipping
// information form.
var billBillTitleTxt   = 'Customer Delivery Details:';
var billShipTitleTxt   = 'Shipping Information:';
var billDifShipTxt     = 'different from billing';
var billFirstNameTxt   = 'First Name:';
var billLastNameTxt    = 'Last Name:';
var billEmailTxt       = 'Email:';
var billPhoneTxt       = 'Phone Number:';

var billAdd1Txt        = 'Address 1:';
var billAdd2Txt        = 'Address 2:';
var billCityTxt        = 'City:';
var billStateTxt       = 'State:';
var billZipTxt         = 'Postal Code:';
var billCountryTxt     = 'Country:';

// set wether you want to use a simple text field or a drop down
// list for billing/shipping state. Default is true (use a list)
// Note: The state list uses the ISO US state list, so for a non-US
//       list, you will need to edit the function "writeStates"
//       in the file NC_getshipping.js
var useStateSelect = false;

// set whether you want to make the customer enter their
// credit card security number (cvv2)
var useCVV2 = false;

// set the currency character
var currency = '$';//May be better to use USD, GBP, AUD, CAD etc.

// set whether you want to use the decimal in the cost or not.
// NOTE: this will concatonate values! $10.25 will become $1025
// Default is true.
var useDecimal   = true;

// set whether you want to use a thousands delimiter.
// NOTE: this will add a comma for every 3 digits. $1025 will become $1,025.
// Default is false
var useThousands = false;

// set wether you want to gather seperate shipping info
var getAltShipping = false;

// Enter the percentage of tax to charge customers if
// you need to charge tax. example - .06 is 6%, .18 is 18%
// To use only one tax rate for all transactions, just enter
// one percentage. For multiple rates, use a one-to-one relationship
// for rates to states, zipcodes, or countries.
// Default setting is for two states, Arkansas and Kansas.
// See the taxStateArray() below.
var taxRateArray = new Array(
'.07',
'.0625'
);

// Set whether you want to charge tax all the time. If so,
// you do not need to edit the taxOnCountry or taxOnState variables
// as this variable overrides all other tax flags and will use the
// first value in the taxRateArray() above.
var alwaysTax = false;

// Set whether you want to charge tax by country OR by state/province
// if you want to use either of these two variables, then make sure that
// alwaysTax = false allowing you to use the taxRateArray() values
// NOTE: the variable heirarchy is as follows:
// 1) taxOnState 2) taxOnZipCode 3) taxOnCountry
var taxOnState   = false;
var taxOnZipCode = false;
var taxOnCountry = false;

// Some states/provinces/countries require that you tax the shipping,
// set this to true if you are required to tax shipping.
var taxShipping  = false;

// Set whether you want to charge tax by the billing address
// or shipping address, if shipping address is different.
// Default is shipping address.
// Note: if no alternate shipping address is used, tax rate gets 
// calculated by the billing address.
var taxOnShipAddress = false;

// Set the state(s) you want to flag for taxing. Make sure that
// you use the common abreviation as well as the full name, all lower case!
// Only works if alwaysTax = false AND taxOnState=true and uses values from
// the taxRateArray() on a one-to-one relationship.
// View NC_getshipping.js for state values.
var taxStateArray = new Array(
'ks',
'ar'
);

// Set the zipcodes you want to flag for taxing.
// Only works if alwaysTax = false AND taxOnZipCode=true and uses values from
// the taxRateArray() on a one-to-one relationship
var taxZipCodeArray = new Array(
'66062',
'72205'
);

// Set the country(s) you want to flag for taxing. Make sure that
// you use the common abreviation as well as the full name, all lower case!
// Only works if alwaysTax = false AND taxOnCountry=true and uses values from
// the taxRateArray() on a one-to-one relationship.
// View NC_getshipping.js for country code values.
var taxCountryArray = new Array(
'us',
'ca'
);

// Enter shipping amount in percentage or straight charge.
// if you use a percentage, then set shipPercent = true, otherwise 
// set it to false. NEVER set shipAmt to '', see below for the reason.
// Default setting is 10
var shipAmt = '0';
var shipPercent = false;

// Set shipping cost per item.
// If set to true, shipPercent and useShipOptions below must be false, 
// the cusomter will then be charged the set shipAmt per item ordered.
var shipPerItem = false;

// Set this to true if you want to use shipping options.
// The shipOption drop-down then displays with data taken from the shipOptions 
// array() below. Setting this to true will override shipPercent and shipPerItem
// which must be set to false.
var useShipOptions = false;

// Set this to true if you want to use shipping rules.
// shipPercent, shipPerItem and shipOptions must all be set to false.
// When set to true, the data is taken from the myShipRules array() below
var useShipRules = false;

// This will define a select drop-down for your shipping options.
// The ending true/false flag is for setting whether that shipping 
// option should charge the included amount on a per item basis or not.
// Formatting:
// One option per line - "Options Description + | + option cost + | true/false",
var shipOptions = new Array(
'UPS Ground|14.95|true',
'UPS Second Day Air|32.50|false',
'FedEx Overnight|40.95|false'
);

/* 
 The following will define a set of rules for the amount to charge for 
 shipping based on order value or quantity from country to country. 
 shipPerItem, shipPercent and useShipOptions must all be set to false, 
 BUT shipAmt MUST contain a value!! Although it's not used, it's a condition 
 which forces the shipping amount to show up.

Each shipRule is defined using the following parameters:
 min value,
 max value, 
 min qty, 
 max qty, 
 ship cost, 
 As a percentage or Not, 
 UPPERCASE country list | delimited, 
 apply this rule when the user's country matches or doesn't match the country list?
* matches = true, doesn't match = false *

What you end up with is a powerful way to control shipping based
on the order value or the quantity ordered by country.

To disregard the min/max values set them to zero.
To disregard min/max quantities set them to zero.

Here's how it translates if you want to charge 5 per item to someone
in your own country. myCountry is the variable at the top of this 
file where you entered your 2 digit country code

new shipRule(0,  0,            0,        100000,             5,       false,          myCountry,         true)
from value 0 to value 0, from 0 items to 100000 items, charge 5, not as a percent, matching myCountry, if it matches charge it!

By creating a number of these shipRules, you can catch all users in
any country and apply a shipping amount based on quantity or value.

Here's another 3 which together charge UK customers 25 for an order value of 
between 0 and 49.99, 50 for an order of between 50 and 99.99 and free thereafter.
new shipRule(0,49.99,0,0,25,false,"GB",true)
new shipRule(50,99.99,0,0,50,false,"GB",true)
new shipRule(100,1000000,0,0,0,false,"GB",true)

Here's another which allows free shipping within the US and Canada
new shipRule(0,100000,0,0,0,false,"US|CA",true)

And another which charges 10% to all countries outside the US
new shipRule(0,100000,0,0,0.1,true,"US",false)

You should now be able to work out the default values for the rules
set below.

*/

var myShipRules = new Array(
new shipRule(0,   99.99,0,0,4.5,false,'US|CA',true),
new shipRule(100,100000,0,0,0.1,true, 'US|CA',true),
new shipRule(0,   49.99,0,0,9.0,false,'US|CA',false),
new shipRule(50, 100000,0,0,0.2,true, 'US|CA',false)
);

// Set whether to use discounts on your site or not.
var useDiscount = false;

// If you're using discounts, set whether you want to allow
// discounts by quantity or by a code. If set to false,
// then the discount will be by code. Default is to
// discount by quantity!
var discountByQty = true;

// Fill this array with the quantity range and the percentage discount.
// Formatting (discount by quantity):
// one discount option per line: 'Min qty | Max qty | Percent'
// Formatting (discount by code):
// one discount option per line: 'Code | Percent'
// to make things easy, discount codes will be converted to lowercase
// before matching so customers won't need to worry about it.
var discountArray = new Array(
'2|4|.05',
'5|7|.07',
'8|10|.08'
);

// Set this option for which credit cards you accept, this will
// build a select drop-down filled with card types, one per line
var cardOption = new Array(
'Visa',
'MasterCard',
'Discover',
'American Express'
);

// Set whether you'd like to allow a printable form for orders
// If you don't use a printable form, then make sure you
// have your form or gateway based ordering variables set!
// Default is true
var usePrint = true;

// Set whether you want to allow CGI or ASP form based order submission.
// Default is true. This is a payment collection page that you or your
// processor has setup to take credit card details. Best when the useSecure 
// METHOD is set to true. 
// This post MODE must be set in conjunction with a post METHOD
var useForm = true;

// Set whether you want to allow order submission through a payment gateway 
// or not. This is a payment MODE for sending order data to a Merchant Account
// Gateway for processing and must be set in conjunction with a post METHOD
var useGateway = false;

// Set wether you want to allow customers the option to use
// insecure order submission (not including printable forms)
// if useSecure is false and/or you're missing your secure
// page settings, the cart defaults to insecure ordering
// This is a post METHOD used in conjunction with a post MODE
var useUnsecure = true;

// Set whether you want to allow secure order submission.
// Default is true
// This is a post METHOD used in conjunction with a post MODE
var useSecure = false;

// If your site uses framesets, then set secureBreakFrames to true.
// This will force the post into the window.location the same as if a link
// used the _top as a target, if false, we use document.location otherwise
// we use parent.document.location, this will display the lock icon in the
// lower portion of the browser and is only used with secure ordering.
//
// if you are using frames and do not set this variable to true, the cart
// may not transfer to secure properly
var secureBreakFrames = false;

// Cart page defining variables #############################
// We define variables for our pages so we can reference them easily
// so we could now say location.href=cartPage to go to the cart page

// This is the page that displays the cart contents, if the cart script
// is on this page, it will display update/delete/continue buttons
var cartPage = 'cart.html';

// The page for gathering shipping info
var COstep1 = 'customer_data.html';

// The last step for printing out an order (verify address, etc.)
var COprintVerify = 'printverify.html';

// The printable order form page
var COprint = 'printorder.html';

// The page used for form posting. If useForm and useUnsecure are 
// both set to true, this is the page to display and the form which
// is built dynamically on this page will post to unsecurePostAction
var COform = 'formorder.html';

// The page used for gateway posting. If useGateway and useUnsecure 
// are both set to true, this is the page to display and the form which
// is built dynamically on this page will post to unsecureGatewayAction
var COgateway = 'gateway.html';

// The page used for secure form posting. If useForm and useSecure are
// both set to true, this is the page to display after concatenating 
// (joining) this variable with the securePath variable and the form which
// is built dynamically on this page will post to securePostAction.
// So this page is the one you securely host along with your js folder.
// When you click the button on the COstep1 page, you are transferred to
// your secure site for collection of card data and secure form processing.
var COsecureForm = 'secure_formorder.html';

// The page used for secure gateway posting. If useGateway and useSecure are
// both set to true, this is the page to display after concatenating 
// (joining) this variable with the securePath variable and the form which
// is built dynamically on this page will post to secureGatewayAction.
// So this page is the one you securely host along with your js folder.
// When you click the button on the COstep1 page, you are transferred to
// your secure site for onward secure posting to your Merchant Account Gateway.
var COsecureGateway = 'secure_gateway.html';
// End cart page defining variables ###############################

// Begin post ACTION variables ########################################
// We turn our URLs into variables for easy inclusion of long strings

// These post action variables are all designed to set the posting actions of
// the forms when your customers hit the finalize button.

// You can post to any script or page you desire, providing your script can 
// handle the post and redirect you according to your setup. This could be 
// a Bank defined script or one of your making. Edit the extraFormTags array() 
// below to include any data you want posted with the form.

// You may just want to log orders and contact buyers later for offline card
// collection, in which case the FREE mailsender script will email you or 
// nc.pl will take and store the order then redirect the user to another page 
// defined by you in a field called NC_Redirect.

// If you're using form posting by setting useForm and useUnsecure to true,
// this is the action of the form and is where your form will POST to. 
//var unsecurePostAction = 'http://www.javascriptcart.com/testing/cart_post.asp';
var unsecurePostAction = 'http://www.javascriptcart.com/NC_mailsender.asp';

// If you're using gateway posting by setting useGateway and useUnsecure to true,
// this is the action of the form and is where your gateway will POST to. nc.pl 
// would be the norm for this variable but can be any script or page you desire, 
// providing your script can handle the post and redirect you using the posted 
// NC_Redirect field set within the gateway script.
//var unsecureGatewayAction = 'http://www.javascriptcart.com/testing/cart_post.asp';
var unsecureGatewayAction = 'http://www.javascriptcart.com/NC_mailsender.asp';

// Set the Post action for your secure form. If you've just taken card details and
// you're posting to a secure form handler, here's where you put the URL.
// Don't be confused by thinking that securePostAction needs to be a secure post, 
// it just means that this is the post action used BY your secure page. nc.pl will
// take this data as will an ASP back-end found within the cgi-bin then redirect.
var securePostAction = 'https://gazza.readyhosting.com/testing/cart_post.asp';

// Set the Post action for your secure gateway. If you want to securely transfer your
// customer to the gateway or to another back-end you have configured, then do it here.
// Don't be confused by thinking that secureGatewayAction needs to be a secure post, it
// just means that this is the post action used BY your secure gateway page. nc.pl will
// take this data as will an ASP back-end found within the cgi-bin then redirect.
var secureGatewayAction = 'https://gazza.readyhosting.com/testing/cart_post.asp';
// End posting variables ############################################


// Set the path to your SSL here. If you're not using a secure server, then
// this variable isn't necessary, otherwise it's used in conjunction with the
// COsecureForm and COsecureGateway variables to load the relevant secure page
var securePath = 'https://gazza.readyhosting.com/secure/';

// Set up an array of tags for your specific form handling CGI script see your
// form script help file for required or optional tags. By default, these tags
// are specifically coded for use with the FREE NC_mailsender script 
// http://www.javascriptcart.com/NC_mailsender.asp which can take the post, email
// you and the customer the order, then redirect to the page defined by NC_Redirect
// You could use this script in place of nc.pl and have orders emailed to you.
// To use this script instead of nc.pl, just point the post action of the form you're 
// using to the NC_mailsender.asp script and let us do the rest.
var extraFormTags = new Array(
/*These fields post data to the FREE NC_mailsender.asp script details available here:*/
//http://www.javascriptcart.com/forum/topic.asp?TOPIC_ID=356
'<input type="hidden" name="mailTest" value="'+mailTest+'">',//This will send you the new test emails, delete when ready
'<input type="hidden" name="NC_FromCart"      value="1">',
'<input type="hidden" name="NC_Merchant_Name" value="Dolce">',//Merchant name
'<input type="hidden" name="NC_Email" value="'+myEmail+'">',//Merchant email
//Replace with your merchant email address, "yourEmail@yourdomain.com" NC_Email is the Merchant address
'<input type="hidden" name="NC_Subject"       value="Dolce Coffee Order">',
'<input type="hidden" name="NC_Header"        value="Thank you for your recent Dolce Coffee Order">',
'<input type="hidden" name="NC_Footer"        value="NebuCart - www.javascriptcart.com">',
'<input type="hidden" name="NC_Message"       value="">',
'<input type="hidden" name="NC_Redirect2"     value="http://www.dolce.com.au/html/store/thankyou.html">',
'<input type="hidden" name="NC_EmailCustomer" value="1">'//A zero will not send it or you can delete it alltogether
//'<input type="hidden" name="NC_SilentPost" value="www.your_order_capture_script.com/cgi-bin/formorder.cgi">'
//'<input type="hidden" name="NC_MerchantOnly" value="whatever you want in here to be passed in your email">'
);

// Set the name of the field that designates the mail recipient for
// your form handling CGI or ASP. This gets used to add the customer's email
// to this field so that they get a copy of the order as well.
// In other words, if you were using a generic formMail script like Matt's formMail,
// then his form contains a field specific for the recipient and if that was called
// recipient, then type recipient in the cgiMailField and we'll look for a value and add
// the customer's email address to it so they also get a copy.
var cgiMailField = '';

// Shipping Rule Object - Do not edit
function shipRule(amtLbound,amtUbound,qtyLbound,qtyUbound,shipCost,percent,countries,applyDomestic){
 this.amtLbound     = amtLbound;
 this.amtUbound     = amtUbound;
 this.qtyLbound     = qtyLbound;
 this.qtyUbound     = qtyUbound;
 this.shipCost      = shipCost;
 this.percent       = percent;
 this.countries     = countries;
 this.applyDomestic = applyDomestic
}

// TEST CREDIT CARD NUMBERS
// 370000000000002  American Express
// 6011000000000012 Discover
// 5424000000000015 MasterCard
// 4007000000027    Visa