function initSlidingContent(valone,valtwo) {return true;}	
	
	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")
		{
			ShowFeaturedProducts();
		}
	});
	
	function ClearSearchBox()
	{
		document.getElementById("qo_search").value = "";
	}
	function ClearSearchQtyBox()
	{
		document.getElementById("qo_search_qty").value = "1";
	}
	
	function SearchBoxSelected(li)
	{
		document.getElementById("qo_search").value = li.extra[0];
		ClearSearchQtyBox();
		document.getElementById("qo_search_qty").focus();
		document.getElementById("qo_search_qty").select();
	}
	
	function ShowExistingCart()
	{
		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;

					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
					});
				});
				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='1' id='qty_" + 
						product.productid + "' /> <input type='button' onclick='AddToCartFromProdList(" + 
						product.productid + ")', class='plus_button' value=' + ' />" +
						"<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'>" + product.productcode + " - " + product.productname + "</div>" + 
					"</div>";
				});
				$("#qo_product_grid").html(sHtml);
				EnableZoom();
			}
		);
	}
	
	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_manufacturer_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='1' id='qty_" + 
							product.productid + "' /> <input type='button' onclick='AddToCartFromProdList(" + 
							product.productid + ")', class='plus_button' value=' + ' />" +
							"<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'>" + 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='1' id='qty_" + 
							product.productid + "' /> <input type='button' onclick='AddToCartFromProdList(" + 
							product.productid + ")', class='plus_button' value=' + ' />" +
							"<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'>" + 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 = $("#qty_" + id).val();
		var minqty = $("#min_qty_" + id).val();
		var maxqty = $("#avail_" + id).val();
		
		if ((qty >= minqty) && (qty <= maxqty))
		{
  			AddToCart(id, qty);
		}
		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 (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 = document.getElementById("qo_search").value;
		var qty = document.getElementById("qo_search_qty").value;
		
		var page = "exm_quickorder/ajax_funcs.php?method=productid_from_productcode&productcode=" + productcode;
		$.getJSON(page, function(json){
				var id = json.productid;
				
				if (id > 0)
				{
					var maxqty = json.avail;
					var minqty = json.min_amount;
					if ((qty >= minqty) && (qty <= maxqty))
					{
  						AddToCart(id, qty);
						$("#qo_search").val(""); $("#qo_search_qty").val("");
					}
					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 (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)
	{
  		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){
			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;
						
					$.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
							});
						
							UpdateCartDisplay();
					});					
				}
			);
		}
	}
	
	function EditProductOptions(cartid)
	{
		window.open("popup_poptions.php?target=cart&id=" + cartid, "options_popup",
			"width=300, height=200");
	}
	
	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))
			{
				alert("TEST");
  				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();
				});
			}
			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();
		});
	}
	
	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"] + '<br />';
			sHtml += '(' + aItemsInCart[i]["category"] + ')</b><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]["cartid"] + ');">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;
   	}
