//------------------------------------
// QuickOrder v1.1 - 4 May 2009
//------------------------------------
// Copyright 2009 ElegantXMods.com
// Please note that this file and
// all QuickOrder files are licenced
// on a per-site basis.
// contact enquiries@elegantxmods.com
// for details or visit our website
// at http://www.elegantxmods.com
//------------------------------------

	
	
	var aItemsInCart = new Array();

	$(document).ready(function() {
		document.getElementById("quickorder_container").style.visibility = "visible";
		ShowTab("category");
		$("#qo_search").autocomplete("exm_quickorder/autocomplete_fill.php", 
			{maxItemsToShow:10, width:300, onItemSelect:SearchBoxSelected}
		);
		ShowExistingCart();
		ShowCatsAndManufacturers();
		if ((cfg_show_featured_products == "Y") && (!search_results))
		{
			ShowFeaturedProducts();
		}
		
		if (search_results)
		{
			ShowSearchResults();
		}
	});
	
	function ClearSearchBox()
	{
		$("#qo_search").addClass("searchbox_selected");
		$("#qo_search").val("");
	}
	function ClearSearchQtyBox()
	{
		$("#qo_search_qty").addClass("searchbox_selected");
		$("#qo_search_qty").val("1");
	}
	
	function SearchBoxSelected(li)
	{
		if (cfg_searchbox_filter == "SKU")
		{
			$("#hdn_qo_searchboxselected").val(li.extra[0]);
			ClearSearchQtyBox();
			document.getElementById("qo_search_qty").focus();
			document.getElementById("qo_search_qty").select();
		}
		else
		{
			$("#hdn_qo_searchboxselected").val(li.extra[0]);
			$("#qo_search").val($("#qo_search").val().replace("<span class='optavail'>(options available)</span>", ""));
			ClearSearchQtyBox();
			document.getElementById("qo_search_qty").focus();
			document.getElementById("qo_search_qty").select();
		}
	}
	
	function ShowExistingCart()
	{
		aItemsInCart.length = 0;
		ShowLoadingPanel("Loading your cart...");
		$.getJSON("exm_quickorder/ajax_funcs.php?method=current_cart_contents",
			function(json) {
				$.each(json.cart, function(i,item)
				{
					var productid = item.productid;
					var productcode = item.productcode;
					var productname = item.productname;
					var price = item.price;
					var manufacturer = item.manufacturer;
					var category = item.category;
					var categoryid = item.categoryid;
					var quantity = item.qty;
					var thumbnail = item.thumbnail;
					var option_count = item.option_count;
					var main_image = item.main_image;
					var cartid = item.cartid;
					var min_amount = item.min_amount;
					var avail = item.avail;
					var product_options = item.product_options;

					aItemsInCart.push({
						"productid": productid,
						"productcode": productcode,
						"productname": productname,
						"price": price,
						"manufacturer": manufacturer,
						"category": category,
						"categoryid": categoryid,
						"quantity": quantity,
						"thumbnail": thumbnail,
						"option_count": option_count,
						"main_image": main_image,
						"cartid": cartid,
						"min_amount": min_amount,
						"avail": avail,
						"product_options": product_options
					});
				});
				UpdateCartDisplay();
				HideLoadingPanel();
			}
		);
	}
	
	function ShowCatsAndManufacturers()
	{
		$.getJSON("exm_quickorder/ajax_funcs.php?method=categories_and_manufacturers",
			function(json) {
				sHtml = "";
				$.each(json.categories, function(i,item){
					var sAlt = "";
					if (i % 2 == 0) {sAlt = "class='alt'";}
					sHtml = sHtml + "<li><a id='ll_category_" + item.categoryid + 
						"' href='javascript:ShowCategory(" + item.categoryid + 
						");' " + sAlt + ">" + item.categoryname + "</a></li>";
				});
				$("#qo_category_list").html(sHtml);
				
				sHtml = "";
				if (cfg_use_manufacturers == "Y")
				{
					$.each(json.manufacturers, function(i,item){
						var sAlt = "";
						if (i % 2 == 0) {sAlt = "class='alt'";}
						sHtml = sHtml + "<li><a id='ll_manufacturer_" + item.manufacturerid + 
							"' href='javascript:ShowManufacturer(" + item.manufacturerid + 
							");' " + sAlt + ">" + item.manufacturer_name + "</a></li>";
					});
					$("#qo_manufacturer_list").html(sHtml);
				}
			}
		);
	}
	
	function ShowFeaturedProducts()
	{
		$.getJSON("exm_quickorder/ajax_funcs.php?method=featured_products",
			function(json) {
				var sHtml = "";
				sHtml = sHtml + "<div class='qopg_catheading'>Featured Products</div>";
				
				$.each(json.featured_products, function(i,product)
				{
					var sAlt = "";
					if (i % 2 == 1)
						sAlt = " qogr_alt";
					
					sHtml = sHtml + 
					"<div class='qo_product_gridrow" + sAlt + "'>" +
					"<div class='qogr_qty'><input type='text' size='3' maxlength='4' value='" + product.min_amount + "' id='qty_" + 
						product.productid + "' /> <input type='button' onclick='AddToCartFromProdList(" + 
						product.productid + ")', class='plus_button' value=' + ' />" +
						"<input type='hidden' id='optcount_" + product.productid + "' value='" + product.option_count + "' />" +
						"<input type='hidden' id='min_qty_" + product.productid + "' value='" + product.min_amount + "' />" +
						"<input type='hidden' id='avail_" + product.productid + "' value='" + product.avail + "' /></div>" +
					"<div class='qogr_price'>" + product.price + "</div>" + 
					"<div class='qogr_img'>" + Thumbnail(product.thumbnail, product.main_image, 25, 25) + "</div>" +
					"<div class='qogr_prodname'>" + FormatProduct(product.productcode, product.productname) + "</div>" + 
					"</div>";
				});
				$("#qo_product_grid").html(sHtml);
				EnableZoom();
			}
		);
	}
	
	function ShowSearchResults()
	{
		var url = "exm_quickorder/ajax_funcs.php?method=search_results_list&products=";
		for (var i = 0; i < aSearchResults.length; i++)
		{
			if (i > 0)
				url += ",";
			
			url += aSearchResults[i];
		}
		
		$.getJSON(url, function(json) {
			var sHtml = "";
			sHtml = sHtml + "<div class='qopg_catheading'>Search Results</div>";
				
			$.each(json.search_results, function(i,product)
			{
				var sAlt = "";
				if (i % 2 == 1)
					sAlt = " qogr_alt";
				
				sHtml = sHtml + 
				"<div class='qo_product_gridrow" + sAlt + "'>" +
				"<div class='qogr_qty'><input type='text' size='3' maxlength='4' value='" + product.min_amount + "' id='qty_" + 
					product.productid + "' /> <input type='button' onclick='AddToCartFromProdList(" + 
					product.productid + ")', class='plus_button' value=' + ' />" +
					"<input type='hidden' id='optcount_" + product.productid + "' value='" + product.option_count + "' />" +
					"<input type='hidden' id='min_qty_" + product.productid + "' value='" + product.min_amount + "' />" +
					"<input type='hidden' id='avail_" + product.productid + "' value='" + product.avail + "' /></div>" +
				"<div class='qogr_price'>" + product.price + "</div>" + 
				"<div class='qogr_img'>" + Thumbnail(product.thumbnail, product.main_image, 25, 25) + "</div>" +
				"<div class='qogr_prodname'>" + FormatProduct(product.productcode, product.productname) + "</div>" + 
				"</div>";
			});
			$("#qo_product_grid").html(sHtml);
			EnableZoom();
		});
	}
	
	function FormatProduct(pcode, pname)
	{
		if (cfg_display_sku == "Y")
			return pcode + " - " + pname;
		else
			return pname;
		
	}
	
	function ShowTab(list_type)
	{
		var id = "";
		switch(list_type)
		{
			case "manufacturer":
				$("#qo_manufacturer_list").show();
				$("#qo_category_list").hide();
				$("#qo_manulist_link").addClass("active");
				$("#qo_catlist_link").removeClass("active");
				$("#hdn_list_type").value = "manufacturer";
				break;
			case "category":
				$("#qo_manufacturer_list").hide();
				$("#qo_category_list").show();
				$("#qo_manulist_link").removeClass("active");
				$("#qo_catlist_link").addClass("active");
				$("#hdn_list_type").value = "category";
				break;
		}
	}
	
	function ShowManufacturer(id)
	{
		$("#qo_category_list a").removeClass("selected");
		$("#ll_manufacturer_" + id).addClass("selected");
		$.getJSON("exm_quickorder/ajax_funcs.php?method=products_by_manufacturer&manufacturer_id=" + id,
			function(json) {
				var sHtml = "";
				$.each(json.categories, function(i,subcat)
				{
					// writing HTML for subcategory headings
					sHtml = sHtml + "<div class='qopg_catheading'>" +
						subcat.category_name + " - (" + subcat.product_count + " products)</div>";
					
					// writing HTML for product listings
					$.each(subcat.products, function(j,product)
					{
						var sAlt = "";
						if (j % 2 == 1)
							sAlt = " qogr_alt";
					
						sHtml = sHtml + 
						"<div class='qo_product_gridrow" + sAlt + "'>" +
						"<div class='qogr_qty'><input type='text' size='3' maxlength='4' value='" + product.min_amount + "' id='qty_" + 
							product.productid + "' /> <input type='button' onclick='AddToCartFromProdList(" + 
							product.productid + ")', class='plus_button' value=' + ' />" +
							"<input type='hidden' id='optcount_" + product.productid + "' value='" + product.option_count + "' />" +
							"<input type='hidden' id='min_qty_" + product.productid + "' value='" + product.min_amount + "' />" +
							"<input type='hidden' id='avail_" + product.productid + "' value='" + product.avail + "' /></div>" +
						"<div class='qogr_price'>" + product.price + "</div>" + 
						"<div class='qogr_img'>" + Thumbnail(product.thumbnail, product.main_image, 25, 25) + "</div>" +
						"<div class='qogr_prodname'>" + FormatProduct(product.productcode, product.productname) + "</div>" + 
						"</div>";
					});
				});
				$("#qo_product_grid").html(sHtml);
				EnableZoom();
			}
		);
	}
	
	function ShowCategory(id)
	{
		$("#qo_category_list a").removeClass("selected");
		$("#ll_category_" + id).addClass("selected");
		$.getJSON("exm_quickorder/ajax_funcs.php?method=products_by_category&cat_id=" + id,
			function(json) {
				var sHtml = "";
				$.each(json.categories, function(i,subcat)
				{
					// writing HTML for subcategory headings
					sHtml = sHtml + "<div class='qopg_catheading'>" +
						subcat.category_name + " - (" + subcat.product_count + " products)</div>";
					
					// writing HTML for product listings
					$.each(subcat.products, function(j,product)
					{
						var sAlt = "";
						if (j % 2 == 1)
							sAlt = " qogr_alt";
					
						sHtml = sHtml + 
						"<div class='qo_product_gridrow" + sAlt + "'>" +
						"<div class='qogr_qty'><input type='text' size='3' maxlength='4' value='" + product.min_amount + "' id='qty_" + 
							product.productid + "' /> <input type='button' onclick='AddToCartFromProdList(" + 
							product.productid + ")', class='plus_button' value=' + ' />" +
							"<input type='hidden' id='optcount_" + product.productid + "' value='" + product.option_count + "' />" +
							"<input type='hidden' id='min_qty_" + product.productid + "' value='" + product.min_amount + "' />" +
							"<input type='hidden' id='avail_" + product.productid + "' value='" + product.avail + "' /></div>" +
						"<div class='qogr_price'>" + product.price + "</div>" + 
						"<div class='qogr_img'>" + Thumbnail(product.thumbnail, product.main_image, 25, 25) + "</div>" +
						"<div class='qogr_prodname'>" + FormatProduct(product.productcode, product.productname) + "</div>" + 
						"</div>";
					});
				});
				$("#qo_product_grid").html(sHtml);
				EnableZoom();
			}
		);
	}
		
	function ShowLoadingPanel(message)
	{
		$(".plus_button").each( function() { this.disabled = true } );
		$("#loading_message").html(message);
		$("#loading_panel").fadeIn('fast');
	}
	
	function HideLoadingPanel()
	{
		UpdateCartDisplay();
		$("#loading_panel").fadeOut('normal');
		$(".plus_button").each( function() { this.disabled = false } );
	}
	
	function AddToCartFromProdList(id)
	{
		var qty = parseInt($("#qty_" + id).val());
		var minqty = parseInt($("#min_qty_" + id).val());
		var maxqty = parseInt($("#avail_" + id).val());
		var optcount = parseInt($("#optcount_" + id).val());
		var tot_qty = qty;
		
		// we need to check that this won't go over maximum quantity...
		for (var i = 0; i < aItemsInCart.length; i++)
		{
			if (id == aItemsInCart[i]["productid"])
			{
				tot_qty = qty + parseInt(aItemsInCart[i]["quantity"]);
			}
		}

		if ((qty >= minqty) && (tot_qty <= maxqty))
		{
  			AddToCart(id, qty, optcount);
		}
		else
		{
			if (qty < minqty)
			{
				alert("Sorry, you must order at least " + minqty + " of this product");
				$("#qty_" + id).val(minqty); document.getElementById("qty_" + id).focus();
			}
			else if (tot_qty > maxqty)
			{
				alert("Sorry, there is not enough in stock. At present, we only have a maximum of " + maxqty + " to sell.");
				$("#qty_" + id).val(maxqty); document.getElementById("qty_" + id).focus();
			}
		}	
	}
	
	function AddToCartFromSearchBar()
	{
		var productcode = $("#hdn_qo_searchboxselected").val();
		var qty = parseInt($("#qo_search_qty").val());
		var tot_qty = qty;

		var page = "exm_quickorder/ajax_funcs.php?method=productid_from_productcode&productcode=" + productcode;
		$.getJSON(page, function(json)
		{
			var id = json.productid;
			
			// we need to check that this won't go over maximum quantity...
			for (var i = 0; i < aItemsInCart.length; i++)
			{
				if (id == aItemsInCart[i]["productid"])
				{
					tot_qty = qty + parseInt(aItemsInCart[i]["quantity"]);
				}
			}
				
			if (id > 0)
			{
				var maxqty = parseInt(json.avail);
				var minqty = parseInt(json.min_amount);
				var optcount = parseInt(json.option_count);

				if ((qty >= minqty) && (tot_qty <= maxqty))
				{
					AddToCart(id, qty, optcount);
					$("#qo_search, #qo_search_qty").removeClass("searchbox_selected");
					if (cfg_searchbox_filter == "SKU")
						$("#qo_search").val(lbl_sku);
					else
						$("#qo_search").val(lbl_product_name);
					
					$("#qo_search_qty").val(lbl_qty);
				}
				else
				{
					if (qty < minqty)
					{
						alert("Sorry, you must order at least " + minqty + " of this product");
						$("#qo_search").val(""); $("#qo_search_qty").val(""); document.getElementById("qo_search").focus();
					}
					else if (tot_qty > maxqty)
					{
						alert("Sorry, there is not enough in stock. At present, we only have a maximum of " + maxqty + " to sell.");
						$("#qo_search").val(""); $("#qo_search_qty").val(""); document.getElementById("qo_search").focus();
					}
				}
			}
			else
			{
				alert("Sorry, we could not find that product. Please try again.");
				$("#qo_search").val(""); $("#qo_search_qty").val(""); document.getElementById("qo_search").focus();
			}
		});
	}
	
	function AddToCart(id, qty, optcount)
	{
		ShowLoadingPanel("Adding to cart...");
		var page="exm_quickorder/ajax_funcs.php?method=set_cart_contents&productid="+id+"&qty="+qty+"&mode=add";	
		$.get(page, function(data){
			if (parseInt(optcount) > 0)
			{
				$.get("cart.php?mode=checkout");
				EditProductOptions(id);
			}
			else
			{
  				UpdateCart(id, qty);
  				HideLoadingPanel();
			}
		});
	}
	
	function UpdateCart(id, qty)
	{
		// does the product already exist in the cart? if so, update its quantity
		var isnewproduct = 1;
		for (var i = 0; i < aItemsInCart.length; i++)
		{
			if (aItemsInCart[i]["productid"] == id)
			{
				isnewproduct = 0;
				
				// update product's quantity
				aItemsInCart[i]["quantity"] = parseInt(aItemsInCart[i]["quantity"]) + parseInt(qty);
				UpdateCartDisplay();
			}
		}
						
		if (isnewproduct == 1) // product is new
		{
			$.getJSON("exm_quickorder/ajax_funcs.php?method=product_from_id&productid=" + id,
				function(json) {
					var productid = json.product.productid;
					var productcode = json.product.productcode;
					var productname = json.product.productname;
					var price = json.product.price;
					var manufacturer = json.product.manufacturer;
					var category = json.product.category;
					var categoryid = json.product.categoryid;
					var quantity = qty;
					var thumbnail = json.product.thumbnail;
					var min_amount = json.product.min_amount;
					var avail = json.product.avail;
					var low_stock = json.product.low_stock;
					var option_count = json.product.option_count;
					var main_image = json.product.main_image;
					var product_options = json.product.product_options;
						
					$.getJSON("exm_quickorder/ajax_funcs.php?method=get_cart_id&productid="+id, 
						function(data) {

							aItemsInCart.push({
								"productid": productid,
								"productcode": productcode,
								"productname": productname,
								"price": price,
								"manufacturer": manufacturer,
								"category": category,
								"categoryid": categoryid,
								"quantity": quantity,
								"thumbnail": thumbnail,
								"min_amount": min_amount,
								"avail": avail,
								"option_count": option_count,
								"main_image": main_image,
								"cartid": data.cartid,
								"product_options": product_options
							});
						
							UpdateCartDisplay();
							$.get("cart.php?mode=checkout", function(data){});
					});					
				}
			);
		}
	}
	
	function EditProductOptions(productid)
	{
		$.getJSON("exm_quickorder/ajax_funcs.php?method=product_options&productid="+productid, 
			function(data) {
				
				// first get default / chosen options
				var aDefOpts = new Array();
				for (var i = 0; i < data.default_options.length; i++)
				{
					aDefOpts.push ({
						"classid":data.default_options[i].classid,
						"optionvalue":data.default_options[i].optionvalue
					});
				}

				// build options dropdowns and text boxes
				var sHtml = "<h1 class='popopt_header'>Choose Options</h1>";
				sHtml += "<table>";
				for (var i = 0; i < data.product_options.length; i++)
				{
					var opt = data.product_options[i];
					
					// find the corresponding default/selected option
					var def_option = "";
					for (var d = 0; d < aDefOpts.length; d++)
					{
						if (aDefOpts[d]["classid"] == opt.classid)
							def_option = aDefOpts[d]["optionvalue"];
					}
					
					if (((opt.classtype == "variant") || (opt.classtype == "price_modifier"))
						&& (opt.option_types.length > 1))
					{
						sHtml += "<tr><td><label>" + opt.classtext + "</label></td><td>";
						sHtml += "<select id='product_options[" + opt.classid + "]'>";
						for (var j = 0; j < opt.option_types.length; j++)
						{
							var opttype = opt.option_types[j];
							var sSelected = "";
							
							if (opttype.optionid == def_option)
								sSelected = " selected='selected'";
							
							sHtml += "<option value='" + opttype.optionid + "'" + sSelected +
							">" + opttype.option_name + "</option>";
						}
						sHtml += "</select>";
					}
					else if (opt.classtype == "text_field")
					{
						sHtml += "<tr><td width='50%'><label>" + opt.classtext + "</label></td><td width='50%'>";
						sHtml += "<input type='text' value='" + def_option + "' id='product_options[" + opt.classid + "]' />"
					}
					
					sHtml += "</td></tr>";
				}
				sHtml += "</table><div><input type='button' value='Continue' onclick='SaveProductOptions(" + productid + ")' /></div>";
            	
				HideLoadingPanel();

				$("#qo_canvas").fadeIn("fast");
            	var nLeft = ($("#qo_canvas").width() - 300) / 2;
            	document.getElementById("qo_optionspopup").style.marginLeft = nLeft + "px";
            	$("#qo_optionspopup").html(sHtml); 
				$("#qo_optionspopup").show();
		});		
	}
	
	function SaveProductOptions(productid)
	{
		var cart_id = 0;
		$.getJSON("exm_quickorder/ajax_funcs.php?method=get_cart_id&productid="+productid, 
			function(data) {
				var cart_id = data.cartid;
				var sData = "mode=update&id=" + cart_id + "&target=cart&eventid=0";
				
				var aClasses = $("#qo_optionspopup select, #qo_optionspopup input");
				for (var i = 0; i < aClasses.length; i++)
				{
					var selId = aClasses[i].id;
					var selOption = $(aClasses[i]).val();
					sData += "&" + selId + "=" + selOption;
				}

				$.ajax({
   					type: "POST",
   					url: "popup_poptions.php",
   					data: sData,
   					success: function(msg){
   						$("#qo_optionspopup").hide();
   						$("#qo_optionspopup").html("");
   						$("#qo_canvas").hide();
     					ShowExistingCart();
   					}
 				});
			});
	}
	
	function EditQuantity(productid)
	{
		var quantity = 0;
		for (var i = 0; i < aItemsInCart.length; i++)
		{
			if (aItemsInCart[i]["productid"] == productid)
			{
				quantity = aItemsInCart[i]["quantity"];
			}
		}
		sHtml = lbl_qty + ": <input type='text' value='" + quantity + "' id='txtQtyEdit_" + productid + "' class='txtEditQty' /> - <a href='javascript:SaveEdit(" + productid + ");'>Save</a>";
		$("#lblQuantityBox_" + productid).html(sHtml);
	}
	
	function SaveEdit(productid)
	{
		var qty = parseInt($("#txtQtyEdit_" + productid).val());
		if (qty > 0)
		{
			var minqty = parseInt($("#cart_minqty_" + productid).val());
			var maxqty = parseInt($("#cart_maxqty_" + productid).val());

			if ((qty >= minqty) && (qty <= maxqty))
			{
  				for (var i = 0; i < aItemsInCart.length; i++)
				{
					if (aItemsInCart[i]["productid"] == productid)
					{
						aItemsInCart[i]["quantity"] = qty;
					}
				}
				ShowLoadingPanel("Updating cart...");
				var page="exm_quickorder/ajax_funcs.php?method=set_cart_contents&productid="+productid+"&qty="+qty+"&mode=modify";	
				$.get(page, function(data){
					HideLoadingPanel();
					$.get("cart.php?mode=checkout", function(data){});
				});
			}
			else
			{
				if (qty < minqty)
				{
					alert("Sorry, you must order at least " + minqty + " of this product");
					$("#txtQtyEdit_" + productid).val(minqty); document.getElementById("txtQtyEdit_" + productid).focus();
				}
				else if (qty > maxqty)
				{
					alert("Sorry, there is not enough in stock. At present, we only have a maximum of " + maxqty + " to sell.");
					$("#txtQtyEdit_" + productid).val(maxqty); document.getElementById("txtQtyEdit_" + productid).focus();
				}
			}			
		} else {
			alert("You must enter a quantity higher than zero.");
		}
	}
	
	function DeleteItem(productid)
	{
		for (var i = 0; i < aItemsInCart.length; i++)
		{
			if (aItemsInCart[i]["productid"] == productid)
			{
				aItemsInCart.splice(i, 1);
			}
		}
		ShowLoadingPanel("Updating cart...");
		var page="exm_quickorder/ajax_funcs.php?method=set_cart_contents&productid="+productid+"&mode=delete";	
		$.get(page, function(data){
  			HideLoadingPanel();
  			$.get("cart.php?mode=checkout", function(data){});
		});
	}
	
	function ClearBasket()
	{
		aItemsInCart.splice(0, aItemsInCart.length);
		ShowLoadingPanel("Clearing cart...");
		$.get("cart.php?mode=clear_cart", function(data){
  			HideLoadingPanel();
		});
	}
	
	function UpdateCartDisplay()
	{
		var total_price = 0;
		var sHtml = "";
		for (i=0; i<aItemsInCart.length; i++)
		{
			total_price = total_price + (parseFloat(aItemsInCart[i]["price"]) * parseInt(aItemsInCart[i]["quantity"]));

			sHtml += '<div class="productinfo">';
			sHtml += Thumbnail(aItemsInCart[i]["thumbnail"], aItemsInCart[i]["main_image"], 60, 60);
			sHtml += '<p><b>' + aItemsInCart[i]["productname"] + '</b><br />';
			if (aItemsInCart[i]["product_options"].length > 4)
			{
				sHtml += "<i>" + aItemsInCart[i]["product_options"] + "</i><br />";
			}
			sHtml += '<input type="hidden" id="cart_minqty_' + aItemsInCart[i]["productid"] + '" value="' + aItemsInCart[i]["min_amount"] + '" />';
			sHtml += '<input type="hidden" id="cart_maxqty_' + aItemsInCart[i]["productid"] + '" value="' + aItemsInCart[i]["avail"] + '" />';
			sHtml += '<span id="lblQuantityBox_' + aItemsInCart[i]["productid"] + '">Qty: <b>' + aItemsInCart[i]["quantity"] + '</b> - ';
			sHtml += '<a href="javascript:EditQuantity(' + aItemsInCart[i]["productid"] + ');">' + lbl_edit + '</a> - ';
			sHtml += '<a href="javascript:DeleteItem(' + aItemsInCart[i]["productid"] + ');">' + lbl_delete + '</a>';
			if (aItemsInCart[i]["option_count"] > 0)
			{
				sHtml += ' - <a href="javascript:EditProductOptions(' + aItemsInCart[i]["productid"] + ');">Options</a>';
			}
			sHtml += '</span><br />Subtotal: <b>' + currency_symbol + (parseFloat(aItemsInCart[i]["price"]) * parseInt(aItemsInCart[i]["quantity"])).toFixed(2) + '</b></p>';
			sHtml += '</div>';
		}
		$("#qo_col_right_cart").html(sHtml);
		EnableZoom();
		
		// populate summary panel	
		$("#lblNoItemsBasket").html(aItemsInCart.length);
		$("#lblTotal").html(total_price.toFixed(2));
		
		document.getElementById("qo_col_right_cart").scrollTop = document.getElementById("qo_col_right_cart").scrollHeight;
	}
	
	var cart_count = 0;
	
	function Checkout()
	{
		ShowLoadingPanel("Checking out...");
		window.location.href = "cart.php?mode=checkout";
	}
	
	function CloseQO()
	{
		ShowLoadingPanel("Exiting...");
		window.location.href = "home.php";
	}
	
	function Thumbnail(sThumb, sMain, nWidth, nHeight)
	{
		if (cfg_use_phpthumb == "Y")
			return "<a href='" + sMain + "' class='zoom'><img src='exm_quickorder/thumbnail/phpThumb.php?src=" + sThumb + "&q=80&w=" + nWidth + "&h=" + nHeight + "' /></a>";
		else
			return "<a href='" + sMain + "' class='zoom'><img src='" + sThumb + "' width='" + nWidth + "' height='" + nHeight + "' /></a>";
	}
	
	function EnableZoom()
	{
		$("a.zoom").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true }); 
	}

	function isInteger(myNum)
   	{
    	if(typeof(myNum)=='number' && /^\d*$/.test(myNum.toString(10)))
			return true;
		else
			return false;
   	}

