var products = [];
products[501] = ["Canned Mixed Vegetables (Pack of 12)", 12.99, "Everyday Essentials Surplus", "A 12-pack of 15oz cans of mixed vegetables, perfect for stocking up on pantry essentials.", "", 0,"", ""];
products[502] = ["Gourmet Coffee Variety Pack", 24.99, "Everyday Essentials Surplus", "Assorted gourmet coffee grounds with 6 unique flavors, 12 oz bags each. Great for coffee lovers.", "
", 0,"", ""];
products[503] = ["Organic Cereal Pack (6 Boxes)", 19.99, "Everyday Essentials Surplus", "Variety pack of organic cereal, 6 boxes with different flavors for a healthy breakfast option.", "
", 0,"", ""];
products[504] = ["Assorted Herbal Teas (15-Count)", 9.99, "Everyday Essentials Surplus", "Box of 15 assorted herbal tea bags for relaxation and wellness. No caffeine.", "
", 0,"", ""];
products[505] = ["Frozen French Fries (3 lb bag)", 4.49, "Everyday Essentials Surplus", "3 lb bag of frozen French fries, ready to bake or fry. Perfect side for any meal.", "
", 0,"", ""];
products[506] = ["Box of Spaghetti", 1.99, "Everyday Essentials Surplus", "1 lb box of spaghetti pasta, ideal for making classic Italian dishes.", "
", 0,"", ""];
products[507] = ["Canned Tomato Soup Pack", 7.99, "Everyday Essentials Surplus", "4-pack of tomato canned soups, ideal for quick and easy meals.", "
", 0,"", ""];
products[508] = ["Cooking Oil (Vegetable)", 3.99, "Everyday Essentials Surplus", "32 oz bottle of vegetable cooking oil, perfect for frying, baking, and sautéing.", "
", 0,"", ""];
products[509] = ["Luxury Towels Set (8-Piece)", 39.99, "Everyday Essentials Surplus", "8-piece luxury bath towel set, soft and absorbent. Ideal for a premium bathroom experience.", "
", 0,"", ""];
products[510] = ["Paper Towels (24 Rolls)", 19.99, "Everyday Essentials Surplus", "24 rolls of thick and absorbent paper towels, suitable for kitchen and general use.", "
", 0,"", ""];
products[511] = ["Household Essentials Cleaning Kit", 29.99, "Everyday Essentials Surplus", "Complete cleaning kit with multi-surface cleaner, dish soap, sponges, and microfiber cloths.", "
", 0,"", ""];
products[512] = ["Natural Soy Candles Set (4-Pack)", 14.99, "Everyday Essentials Surplus", "4-pack of natural soy candles with soothing scents, ideal for relaxation at home.", "
", 0,"", ""];
products[513] = ["Reusable Grocery Bags (Set of 12)", 14.99, "Everyday Essentials Surplus", "Eco-friendly reusable grocery bags with reinforced handles, washable and durable.", "
", 0,"", ""];
products[514] = ["Complete Kitchen Essentials Set", 59.99, "Everyday Essentials Surplus", "Complete set of kitchen essentials, including utensils, cutting board, measuring cups, and storage containers, ideal for any household.", "
", 0,"", ""];
products[515] = ["Instant Rice", 1.75, "Everyday Essentials Surplus", "8.5 oz box of instant white rice, ready in minutes for easy meal prep.", "
", 0,"", ""];
products[516] = ["Assorted Greeting Card Pack", 9.99, "Everyday Essentials Surplus", "A beautifully designed pack of 24 assorted greeting cards, perfect for birthdays, holidays, thank-yous, and more.", "
", 0,"", ""];
products[517] = ["Microwave Oven", 89.99, "Everyday Essentials Surplus", "Compact countertop microwave oven with 700 watts of power and easy-to-use controls.", "
", 0,"", ""];
products[518] = ["Electric Toothbrush Kit", 29.99, "Everyday Essentials Surplus", "Rechargeable electric toothbrush kit with 4 brush heads and travel case.", "
", 0,"", ""];
products[519] = ["Reusable Hand Warmers (Set of 2)", 9.99, "Everyday Essentials Surplus", "Set of two reusable hand warmers, perfect for winter outdoor activities.", "
", 0,"", ""];
products[520] = ["Portable Cooler Bag", 19.99, "Everyday Essentials Surplus", "Insulated cooler bag, ideal for keeping drinks and snacks cold during travel.", "
", 0,"", ""];
products[521] = ["Household First Aid Kit", 24.99, "Everyday Essentials Surplus", "Comprehensive first aid kit for home use, with essentials for treating minor injuries.", "
", 0,"", ""];
products[522] = ["Keto Supplement", 129.99, "Everyday Essentials Surplus", "Keto dietary supplement to support energy and metabolism, 1-month supply.", "
", 0,"", "1 Bottle"];
products[523] = ["Keto Supplement - 2 Bottles", 159.99, "Everyday Essentials Surplus", "Keto dietary supplement to support energy and metabolism, 2-month supply.", "
", 0,"", "2 Bottles"];
products[524] = ["Keto Supplement - 3 Bottles", 189.99, "Everyday Essentials Surplus", "Keto dietary supplement to support energy and metabolism, 3-month supply.", "
", 0,"", "3 Bottles"];
products[525] = ["Keto Supplement - 4 Bottles", 199.99, "Everyday Essentials Surplus", "Keto dietary supplement to support energy and metabolism, 4-month supply.", "
", 0,"", "4 Bottles"];
products[526] = ["Keto Supplement - 5 Bottles", 239.99, "Everyday Essentials Surplus", "Keto dietary supplement to support energy and metabolism, 5-month supply.", "
", 0,"", "5 Bottles"];
products[527] = ["Glyco Supplement", 129.99, "Everyday Essentials Surplus", "Glyco support supplement to help regulate blood sugar, 1-month supply.", "
", 0,"", "1 Bottle"];
products[528] = ["Glyco Supplement - 2 Bottles", 159.99, "Everyday Essentials Surplus", "Glyco support supplement to help regulate blood sugar, 2-month supply.", "
", 0,"", "2 Bottles"];
products[529] = ["Glyco Supplement - 3 Bottles", 189.99, "Everyday Essentials Surplus", "Glyco support supplement to help regulate blood sugar, 3-month supply.", "
", 0,"", "3 Bottles"];
products[530] = ["Glyco Supplement - 4 Bottles", 199.99, "Everyday Essentials Surplus", "Glyco support supplement to help regulate blood sugar, 4-month supply.", "
", 0,"", "4 Bottles"];
products[531] = ["Glyco Supplement - 5 Bottles", 239.99, "Everyday Essentials Surplus", "Glyco support supplement to help regulate blood sugar, 5-month supply.", "
", 0,"", "5 Bottles"];
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).length == 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-"]').length > 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 shipping = 0;
var grand_total = 0;
var sub_total = 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);
total += (quantity * products[prodId][1]);
}
}
total = round(total, 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 + ' .tot-price').html('$' + sub_total.toFixed(2) + ' USD');
$('#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-"]').length == 0) {
$("#cartBox").html("
You have not selected any product...
  Browse Products"); } showTotalPrice(); return false; } else { var items = order.split("|"); var total = 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[prodId][4] + " " + products[prodId][0] + " " + products[prodId][7] + "
" + "