// jQuery functions: $(document).ready(function() { // Get hidden value var Price = parseFloat($('#basePrice').val()); var Shipping = ''; var num = $('#number').val(); var basePrice = 0 ; // num * Price; var gst = .05; var taxRate = 0; // Adjust price for bulk discounts if( num < 2) { // Do nothing } else if(num < 3) { Price = Price - .45; } else if (num < 21 ) { Price = Price - 1.0; } else if (num < 41 ) { Price = Price - 2.0; } else { Price = Price - 3.00; } var unitPrice = Price; unitPrice = unitPrice.toFixed(2); $('#unitPrice').html(unitPrice); // Show price after discount basePrice = Price * num; basePrice = basePrice.toFixed(2); $('#baseCost').html(basePrice); // Fall trhough shipping filter if(num < 3) { Shipping = 4.00; } else if (num < 5) { Shipping = 8.00; } else if (num < 10) { Shipping = 10.00; } else if (num < 30) { Shipping = 15.00; } else if (num < 50) { Shipping = 0.00; } else if (num < 100) { Shipping = 0.00; } else if (num < 200) { Shipping = 0.00; } else { alert('Please contact Cool Heads Publishing for orders of 200 books or more.'); num = 1; $('#number').val('1'); location.reload(); } var country = $("input[name='country']:checked").val(); if(country == 'US') { Shipping = Shipping * 1.25; } else if (country == 'Intl') { Shipping = Shipping * 1.50; } else { Shipping = Shipping * 1; } fPrice = (Price * num) + Shipping; Shipping = Shipping.toFixed(2); $('#shipping_cost').html(Shipping); if(country == 'Cdn') { taxRate = gst; } else { taxRate = 0; } var tax = taxRate * fPrice; var taxPayable = tax.toFixed(2); $('#taxPayable').html(taxPayable); fPrice = fPrice + tax; fPrice = fPrice.toFixed(2); $('#full_price').html(fPrice); // Set PayPal form var pp_Price = Price.toFixed(2); $('#amount').val(pp_Price); $('#quantity').val(num); $('#shipping').val(Shipping); $('#tax').val(taxPayable); // This section is run after a keyup in Number box $("input[name='country']").click( function() { $('#number').trigger('keyup'); }); $('#number').keyup(function(){ var num = $(this).val(); var numLen = num.length; var pattern = '/[^\d]+/'; if(numLen > 0) { if(! IsNumeric(num)) { alert('Please enter a number'); num = num.substring(0,numLen-1); $(this).val(num) ; return; } var Price = parseFloat($('#basePrice').val()); // Adjust price for bulk discounts if( num < 2) { // Do nothing } else if(num < 3) { Price = Price - .45; } else if (num < 21 ) { Price = Price - 1.0; } else if (num < 41 ) { Price = Price - 2.0; } else { Price = Price - 3.00; } var unitPrice = Price; unitPrice = unitPrice.toFixed(2); $('#unitPrice').html(unitPrice); // Fall trhough shipping filter if(num < 3) { Shipping = 4.00; } else if (num < 5) { Shipping = 8.00; } else if (num < 10) { Shipping = 10.00; } else if (num < 30) { Shipping = 15.00; } else if (num < 50) { Shipping = 0.00; } else if (num < 100) { Shipping = 0.00; } else if (num < 200) { Shipping = 0.00; } else { alert('Please contact Cool Heads Publishing for orders of 200 books or more.'); num = 1; $('#number').val('1'); location.reload(); } var country = $("input[name='country']:checked").val(); if(country == 'US') { Shipping = Shipping * 1.25; } else if (country == 'Intl') { Shipping = Shipping * 1.50; } else { Shipping = Shipping * 1; } // Before tax fPrice = (num * Price) + Shipping; // Show unit cost cost = (num * Price); cost = cost.toFixed(2); $('#baseCost').html(cost); // Shipping Shipping = Shipping.toFixed(2); $('#shipping_cost').html(Shipping); if(country == 'Cdn') { taxRate = gst; } else { taxRate = 0; } // Add tax tax = taxRate * fPrice; taxPayable = tax.toFixed(2); $('#taxPayable').html(taxPayable); // Calculate Full Price fPrice = fPrice + tax; fPrice = fPrice.toFixed(2); $('#full_price').html(fPrice); } // Set PayPal form var pp_Price = Price.toFixed(2); $('#amount').val(pp_Price); $('#quantity').val(num); $('#shipping').val(Shipping); $('#tax').val(taxPayable); }) }) // Housekeeping functions // http://www.codetoad.com/javascript/isnumeric.asp function IsNumeric(sText) { var ValidChars = "0123456789."; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; }