function addToCart(id, title, qty, price) {
		if(typeof price != 'number') {
			price = parseFloat(price);
		}
		if($('#receipt-cart').text()=='Your basket is empty.') {
			$('#cartSubmit').show();
			$('#receipt-cart').html('<div class="clearfix cart-row"><div class="quantity">QTY</div><div class="event">Event</div><div class="total">Subtotal</div></div>');
			
		}
		if($('#cart-'+id).length==0) {
			price = price.toFixed(2);
			var newItem = '<div class="clearfix cart-row" id="cart-'+id+'"><div class="quantity">'+qty+'</div><div class="event">'+title+'</div><div class="total">&pound;'+price+'</div></div>';
			addToTotal(price*qty);
			$('#receipt-cart').append(newItem);
			addToForm(id,0,qty);
			$('#buy-'+id).children('.do-remove-ticket').css('visibility','visible');
		}
		else{
			var cartID = '#cart-'+id;
			var currentQty = parseInt($(cartID).children('.quantity').text());
			var currentSubTotal = parseFloat($(cartID).children('.total').text().substr(1));
			addToForm(id,currentQty,qty);
			currentQty = currentQty+qty;
			currentSubTotal = currentSubTotal+(price*qty);
			addToTotal(price*qty);
			currentSubTotal = currentSubTotal.toFixed(2);			
			$(cartID).children('.quantity').text(currentQty);
			$(cartID).children('.total').html('&pound;'+currentSubTotal);			
		}
		$('.cart-row:odd').css('color','black');
	};
	function removeFromCart(id,price) {
		
		if(typeof price != 'number') {
			price = parseFloat(price);
		}
		var cartID = '#cart-'+id;
		var currentQty = parseInt($(cartID).children('.quantity').text());
		if(currentQty>0){
		
		
			removeFromTotal(price);
			if(currentQty==1) {
				$(cartID).remove();
				if($("#receipt-cart > .cart-row").size()==1) {
					$('#receipt-cart').html('<div class="cart-row">Your basket is empty.</div>');
					$('#cartSubmit').hide();
				}
				takeFromForm(id,1,1);	
				$('#buy-'+id).children('.do-remove-ticket').css('visibility','hidden');
			}
			else{
				takeFromForm(id,currentQty,1);
				currentQty = --currentQty;
				$(cartID).children('.quantity').text(currentQty);
				var currentPrice = parseFloat($(cartID).children('.total').text().substr(1));
				currentPrice = currentPrice-price;
				currentPrice = currentPrice.toFixed(2);
				$(cartID).children('.total').html('&pound;'+currentPrice);
			}
		}
		
	};
	function addToTotal(withPrice) {
		var currentTotal = parseFloat($('#receipt-ticket-fee').text().substr(1));
		currentTotal = currentTotal+withPrice;
		var ticketFee = currentTotal;
		bookingFee = ((currentTotal/100)*3.4)+0.20;
		currentTotal = currentTotal+bookingFee
		currentTotal = currentTotal.toFixed(2);
		bookingFee = bookingFee.toFixed(2);
		ticketFee = ticketFee.toFixed(2);
		$('#receipt-ticket-fee').html('&pound;'+ticketFee);
		$('#receipt-total').html('&pound;'+currentTotal);
		$('#receipt-booking-fee').html('&pound;'+bookingFee);
	};
	
	function removeFromTotal(withPrice) {
		var ticketFee = parseFloat($('#receipt-ticket-fee').text().substr(1));
		var bookingFee = parseFloat($('#receipt-booking-fee').text().substr(1));
		ticketFee = ticketFee-withPrice;
		var currentTotal = ticketFee;
		bookingFee = (currentTotal/100)*3.4;
		if(bookingFee != 0){
			bookingFee = bookingFee+0.20;
		}
		currentTotal = currentTotal+bookingFee
		currentTotal = currentTotal.toFixed(2);
		bookingFee = bookingFee.toFixed(2);
		ticketFee = ticketFee.toFixed(2);
		$('#receipt-ticket-fee').html('&pound;'+ticketFee);
		$('#receipt-total').html('&pound;'+currentTotal);
		$('#receipt-booking-fee').html('&pound;'+bookingFee);
	};
	
	function addToForm(id,currentQty,addQty) {
		var theForm = $('#cartHidden').val();
		if(currentQty==0) {
			var updateForm = theForm+'('+id+'='+addQty+')';
			$('#cartHidden').val(updateForm);
		}
		else{
			var currentFormat = new RegExp('\('+id+'='+currentQty+'\)');
			var newQty = currentQty+addQty;
			var newFormat  = id+'='+newQty;
			
			if(currentFormat.test(theForm)==true) {
				var updateForm = theForm.replace(currentFormat,newFormat);
				$('#cartHidden').val(updateForm);
			}
			else{
				$('#cartHidden').val(theForm);
			}
		}
		
	};
	
	function takeFromForm(id,currentQty,takeQty) {
		var theForm = $('#cartHidden').val();
		var currentFormat = new RegExp('\('+id+'='+currentQty+'\)');
		if(currentQty<=takeQty) {
			var updateForm = theForm.replace(currentFormat,'');
			$('#cartHidden').val(updateForm);
		}
		else{
			var newQty = currentQty-takeQty;
			if(newQty<0) {
				return false;
			}
			var newFormat  = id+'='+newQty;
			
			if(currentFormat.test(theForm)==true) {
				var updateForm = theForm.replace(currentFormat,newFormat);
				$('#cartHidden').val(updateForm);
			}
			else{
				$('#cartHidden').val(theForm);
			}
		}
		
	}