var products = []; products[475] = ["Keto", 49.99, "NuBalance Max", "", "images/prod-1.png", "1 Bottle", "By placing an order with us you will be charged $ __prc__ + $0.00 S&H for One Time for __prdqnty__ Pack of __prdname__. If you are not completely satisfied with your purchase of __prdname__ at any time, please call 877) 248-2875 or email care@nubalancemax.com, Monday - Friday, 9AM - 6PM. You will receive your package within 2-5 business days of payment via USPS First Class Mail. I agree that my credit card charge will appear as NuBalance Max." ] ; products[474] = ["Keto", 119.88, "NuBalance Max", "", "images/prod-2.png", "2 Bottles", "By placing an order with us you will be charged $ __prc__ + $0.00 S&H for One Time for __prdqnty__ Pack of __prdname__. If you are not completely satisfied with your purchase of __prdname__ at any time, please call 877) 248-2875 or email care@nubalancemax.com, Monday - Friday, 9AM - 6PM. You will receive your package within 2-5 business days of payment via USPS First Class Mail. I agree that my credit card charge will appear as NuBalance Max." ] ; products[473] = ["Keto", 159.88, "NuBalance Max", "", "images/prod-3.png", "3 Bottles", "By placing an order with us you will be charged $ __prc__ + $0.00 S&H for One Time for __prdqnty__ Pack of __prdname__. If you are not completely satisfied with your purchase of __prdname__ at any time, please call 877) 248-2875 or email care@nubalancemax.com, Monday - Friday, 9AM - 6PM. You will receive your package within 2-5 business days of payment via USPS First Class Mail. I agree that my credit card charge will appear as NuBalance Max." ] ; products[472] = ["Keto", 199.88, "NuBalance Max", "", "images/prod-4.png", "5 Bottles", "By placing an order with us you will be charged $ __prc__ + $0.00 S&H for One Time for __prdqnty__ Pack of __prdname__. If you are not completely satisfied with your purchase of __prdname__ at any time, please call 877) 248-2875 or email care@nubalancemax.com, Monday - Friday, 9AM - 6PM. You will receive your package within 2-5 business days of payment via USPS First Class Mail. I agree that my credit card charge will appear as NuBalance Max." ] ; products[476] = ["Keto", 9.99, "NuBalance Max", "", "images/prod-5.png", "8 Capsules", "By placing an order with us you will be charged $ __prc__ + $0.00 S&H for One Time for __prdqnty__ Pack of __prdname__. If you are not completely satisfied with your purchase of __prdname__ at any time, please call 877) 248-2875 or email care@nubalancemax.com, Monday - Friday, 9AM - 6PM. You will receive your package within 2-5 business days of payment via USPS First Class Mail. I agree that my credit card charge will appear as NuBalance Max." ] ; //console.log(products); var orderedItems = []; var orderedTotQty = 0; var maxQty = 10; var shipRates = false; var handling = 0; var carturl = "cart.php"; // Function to check item exists in cart var checkItemExists = function(itemId) { var order = $.cookie('order'); if (!order) { return false; } else { var itemExists = false; var items = order.split("|"); order = ""; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (order != "") { order += "|"; } if (prodId == itemId) { return true; } } } return false; } //Funtion adds Items to Cart var addItem = function(itemId, Qty, showFullCart) { if (typeof showFullCart === "undefined") { showFullCart = false; } orderedTotQty = $.cookie('orderedTotQty'); if (!orderedTotQty) { orderedTotQty = 0; } Qty = parseInt(Qty); if(Qty > maxQty) { alert("Maximum " + maxQty + " of this product can be selected in a single order"); return false; } var order = $.cookie('order'); if (!order) { order = itemId + "-" + Qty; orderedItems[itemId] = Qty; } else { var itemExists = false; var items = order.split("|"); order = ""; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (order != "") { order += "|"; } if (prodId == itemId) { alert("Product already exist in cart"); return false; if((quantity + Qty) > maxQty) { alert("Maximum " + maxQty + " of this product can be selected in a single order"); return false; } quantity += Qty; order += prodId + "-" + quantity; itemExists = true; } else { order += prodId + "-" + quantity; } orderedItems[prodId] = quantity; } if (!itemExists) { if (order != "") { order += "|"; } order += itemId + "-" + Qty; orderedItems[itemId] = Qty; } } orderedTotQty = parseInt(orderedTotQty); orderedTotQty += Qty; $('.cartqty').html(orderedTotQty); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/') + 1); if (filename == carturl) { showCart(showFullCart, 'add', itemId); } else { $(location).attr('href', carturl); } }; //Funtion decrements Items to Cart var removeItem = function(itemId, Qty) { Qty = parseInt(Qty); var order = $.cookie('order'); if (!order) { orderedItems[itemId] = 0; refreshRow(itemId); } else { var items = order.split("|"); order = ""; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId == itemId) { quantity -= Qty; if (quantity > 0) { if (order != "") { order += "|"; } order += prodId + "-" + quantity; } itemExists = true; orderedItems[prodId] = quantity; refreshRow(itemId); } else { if (order != "") { order += "|"; } order += prodId + "-" + quantity; orderedItems[prodId] = quantity; } } } orderedTotQty -= Qty; $('.cartqty').html(orderedTotQty); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/') + 1); if (filename == carturl) { showCart(false, 'remove', itemId); } else { $(location).attr('href', carturl); } }; //Funtion sets Item quantity on the Cart var setItemQty = function(itemId, Qty) { Qty = parseInt(Qty); if(Qty > maxQty || Qty < 0) { return false; } var order = $.cookie('order'); orderedTotQty = 0; if (!order) { orderedItems[itemId] = 0; } else { var items = order.split("|"); order = ""; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId == itemId) { quantity = Qty; if (order != "") { order += "|"; } order += prodId + "-" + quantity; itemExists = true; } else { if (order != "") { order += "|"; } order += prodId + "-" + quantity; } orderedItems[prodId] = quantity; orderedTotQty += quantity; } } $('.cartqty').html(orderedTotQty); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/') + 1); if (filename == carturl) { showCart(false, 'set', itemId); } else { $(location).attr('href', carturl); } }; var removeRowItem = function(itemId, showFullCart) { if (typeof showFullCart === "undefined") { showFullCart = false; } var order = $.cookie('order'); if (!order) { orderedTotQty = 0; } else { var items = order.split("|"); order = ""; orderedTotQty = 0; orderedItems = null; orderedItems = new Array(); for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId == itemId) { } else { if (order != "") { order += "|"; } order += prodId + "-" + quantity; orderedTotQty += quantity; orderedItems[prodId] = quantity; } } } if($('#prow-' + itemId).size() == 1) { $('#prow-' + itemId).remove(); } $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); showCart(true, 'removerow', itemId); }; //Emptying the cart var emptyCart = function() { var order = $.cookie('order'); order = ""; orderedTotQty = 0; orderedItems = null; orderedItems = new Array(); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); if($('[id^="prow-"]').size() > 0) { $('[id^="prow-"]').each(function(){ $(this).remove(); }); } $('.trm_1').hide(); showCart(false, 'empty'); }; //Displaying the cart items & calculations function showTotalPrice() { var cartHtml = ""; var total = 0; //var total_gbp = 0; var shipping = 0; var grand_total = 0; //var grand_total_gbp = 0; var sub_total = 0; //var sub_total_gbp = 0; var shippingType = ''; var order = $.cookie('order'); orderedTotQty = $.cookie('orderedTotQty'); if($('#shippingCountry').val() == '') { shippingType = ''; } else if($('#shippingCountry').val() == 'US') { shippingType = 'US'; } else { shippingType = 'INTERNATIONAL'; } if (!order) { orderedTotQty = 0; } else { var items = order.split("|"); if(shipRates) { shipping = shipRates * 1.0; } for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId != "" && quantity > 0) { sub_total = round((quantity * products[prodId][1]), 2); //sub_total_gbp = round((quantity * products[prodId][6]), 2); total += (quantity * products[prodId][1]); //total_gbp +=(quantity * products[prodId][6]) } } total = round(total, 2); //total_gbp = round(total_gbp, 2); } var snh = shipping + handling; //if(shipping == 0) { // snh = shipping; //} console.log(snh); grand_total = total + snh; $('#total-price').html('$ ' + total.toFixed(2)); $('#shipping-price').html('$ ' + snh.toFixed(2)); $('#grand-total').html('$ ' + grand_total.toFixed(2)); }; // Refresh row content with updated quantity / price for a product function refreshRow(pid) { pid = parseInt(pid); quantity = orderedItems[pid]; sub_total = round((quantity * products[pid][1]), 2); $('#prow-' + pid + ' .sub-total').html('$' + sub_total.toFixed(2) + ''); $('#term-' + pid + ' .sub-total').html('$' + sub_total.toFixed(2) + ''); $('#prow-' + pid + ' .qtybox').val(quantity); $('#prow-' + pid + ' .dispqty').html(quantity); } function replaceAllStr(str, find, rstr) { //return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); //return str.replace(/find/g, '\\$&'); return str.replace(new RegExp(find, "g"), rstr); } //Displaying the cart items & calculations function showCart(showFullCart, act, itm) { var cartHtml = ""; var order = $.cookie('order'); orderedTotQty = $.cookie('orderedTotQty'); if (!order) { orderedTotQty = 0; if($('[id^="prow-"]').size() == 0) { $("#cartBox").html("

You have not selected any product...

  Browse Products"); } showTotalPrice(); return false; } else { var items = order.split("|"); var total = 0; var total_gbp = 0; var shipping = 0; var grand_total = 0; orderedTotQty = parseInt(orderedTotQty); if (typeof showFullCart === "undefined") { return false; } else if(showFullCart == false) { if ((typeof act !== "undefined") && (typeof itm !== "undefined")) { if((act == 'add' || act == 'set' || act == 'remove') && itm > 0) { refreshRow(itm); } else if(act == 'removerow' && itm > 0) { itm = parseInt(itm); } } showTotalPrice(); return false; } orderedItems = null; orderedItems = new Array(); cartHtml += "
Products QtyTotal
"; var total = 0; var term_htm =''; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId != "" && quantity > 0) { orderedItems[prodId] = quantity; var sub_total = round((quantity * products[prodId][1]), 2); //var sub_total_gbp = round((quantity * products[prodId][6]), 2); total += sub_total; //total_gbp += sub_total_gbp; termTxt = products[prodId][6]; termTxt = replaceAllStr(termTxt, ' __prc__', products[prodId][1].toFixed(2)); termTxt = replaceAllStr(termTxt, '__prdname__', products[prodId][0]); termTxt = replaceAllStr(termTxt, '__prdqnty__', products[prodId][5]); term_htm += '

' + termTxt + '

'; cartHtml += "
" + "
" + "

" + products[prodId][0] + " " + products[prodId][5] + "

" + "
" + "
" + "" + "
$" + sub_total.toFixed(2) + "
" + "
$" + sub_total.toFixed(2) + "
" + "
" } } cartHtml += "
"; cartHtml += "
Order Summary
" +"
" +"" +"
" +"
" +"Continue Shopping Empty Cart " +"
"; cartHtml += "
"; cartHtml +="
" if (cartHtml != "") { $("#cartBox").html(cartHtml); $(".trm_1").html(term_htm); } else { $("#cartBox").html(" Loading..."); } return false; } }; var round = function(value, decimals) { return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals); };