preload_image1 = new Image(25,25);
	preload_image1.src="http://www.homebrewcentregy.com/busy.gif";
preload_image2 = new Image(25,25);
preload_image2.src="http://www.homebrewcentregy.com/tick.gif";
var current_ctex = 0;
var total_ctex = 0;
var total_cost = 0;
var process_cart = true;

function addtocart(itemid,storeid,type,addname)
{
	if( ! process_cart) {
		return;
	}
	if($("#item_availablity_"+itemid).html()=='Not Currently Available')
	{
		alert('Item is not currently available');
		return false;
	}
	
	var html;
	var query = '';
	var quantity = $("#quantity_"+itemid).val();
	var cost = $("#item_cost_"+itemid).html();
	
	if( ! addname)
	{
		if(current_ctex == 0) current_ctex = parseInt(total_ctex) + parseInt(quantity);
		else current_ctex = current_ctex + parseInt(quantity);
		total_cost = total_cost + (parseFloat(cost) * parseInt(quantity));
		
		query = 'itemid='+itemid+'&storeid='+storeid+'&quantity='+quantity+'&type='+type+'&redirect='+redirect;
	} else  {
		var addname_value = $("#"+addname+'_'+itemid).val();
		if(addname_value.indexOf('{exclude}') != -1)
		{
			alert('Please choose the wine of your choice');
			return false;
		}
		
		if(current_ctex == 0) current_ctex = parseInt(total_ctex) + parseInt(quantity);
		else current_ctex = current_ctex + parseInt(quantity);
		total_cost = total_cost + (parseFloat(cost) * parseInt(quantity));
		
		query = 'itemid='+itemid+'&storeid='+storeid+'&quantity='+quantity+'&type='+type+'&addname='+addname+'&addvalue='+urlencode(addname_value)+'&redirect='+redirect;
	}
	
	process_cart = false;
	html = '<iframe style="display:none;" src ="product.php?'+query+'" width="100%" height="300">';
	html += '<p>Your browser does not support iframes.</p>';
	html += '</iframe>';
	$("#item_"+itemid).html(html);
	$("#item_display_"+itemid).css('display','inline-block');
	$("#item_display_"+itemid).css('width','20px');
	$("#item_display_"+itemid).html('<img width=17 height=17 src="/busy.gif" />');
	var t=setTimeout(function() {$("#item_display_"+itemid).html('<img src="/tick.gif" />');},1300);
	html = '<font color= #CC9360>Items in basket '+current_ctex+'</font>';
	$("#Html1").html('').delay(10000).html(html);
	$("#total_price").html('Total price £'+total_cost.toFixed(2));
	var t=setTimeout(function() {process_cart = true;},1500);
}

function urlencode(str)
{
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}