	// Functon to Show Loading
	function show_loading($append){
		$('<div class="loading"></div>').insertAfter($append);
	}
	
	// Functon to Show Loading
	function stop_loading(){
		$('.loading').remove();
	}

$(document).ready(function() {

/*========================SUMMARY=======================*/

url = 'http://www.avalonimp.co.nz/';
//url = '/avalonci/index.php/';
/*$.ajaxSetup({
  cache: false
});*/
/*
	$('#sendordersub').click(function(){
		$('.sendo').css("display","none");
		$('.loading').show("slow");
	});
*/
	// Add inner to the order
	$('.addinn').click(function(eve){
		preventcache = new Date().getTime();
		eve.preventDefault();						
		string = $(this).attr('id');
		code = string.slice(7,14);
		show_loading('#ordqty'+code);
		$.get(url+'summary_ajax/add_inn/'+code+'/'+preventcache, function(html){
				$('#ordqty').text(html).show('slow');
				updatedisplay(code);
		});
	stop_loading('#ordqty'+code);
	});

	// Remove inner from the order
	$('.reminn').click(function(eve){
		preventcache = new Date().getTime();
		eve.preventDefault();						
		string = $(this).attr('id');
		code = string.slice(7,14);
		$.get(url+'summary_ajax/min_inn/'+code+'/'+preventcache, function(html){
				$('#ordqty').text(html).show('slow');
				updatedisplay(code);
		});
	});

	// Remove product from the order
	$('.remprod').click(function(eve){
		preventcache = new Date().getTime();
		eve.preventDefault();						
		string = $(this).attr('id');
		code = string.slice(8,15);
		$.get(url+'summary_ajax/remove_product/'+code+'/'+preventcache, function(html){
				updatedisplay(code);
		});
	});

	// Display the correct qtys and subtotals on the page
	function updatedisplay(code) {
		preventcache = new Date().getTime();
		$.get(url+'summary_ajax/display/'+code+'/'+preventcache, function(html){
				results = html.split(' | ');
				if(results[0] <= 0)
				{
					removerow(code);
				}
				$('#ordqty'+code).text(results[0]).show('slow');
				$('#subtot'+code).text(results[1]).show('slow');
				$('#total').text(results[2]).show('slow');
				$('#oostotal').text(results[3]).show('slow');
		});
		
	}
	
	// Remove the row that has the product in it.
	function removerow(code) {
		$('#row'+code).remove();
	}

/*========================BROWSING=======================*/

	// Add carton to the order	
	$('.pluctn').click(function(eve){
		preventcache = new Date().getTime();
		eve.preventDefault();						
		string = $(this).attr('id');
		code = string.slice(6,13);
		$.get(url+'products_ajax/add_ctn/'+code+'/'+preventcache, function(html){
				$('#ordqty').text(html).show('slow');
				updatedisp(code);
		});	
	});

	// Remove carton from the order
	$('.dedctn').click(function(eve){
		preventcache = new Date().getTime();
		eve.preventDefault();						
		string = $(this).attr('id');
		code = string.slice(6,13);
		$.get(url+'products_ajax/min_ctn/'+code+'/'+preventcache, function(html){
				$('#ordqty').text(html).show('slow');
				updatedisp(code);
		});
	});
	
	// Add inner to the order	
	$('.pluinn').click(function(eve){
		preventcache = new Date().getTime();
		eve.preventDefault();						
		string = $(this).attr('id');
		code = string.slice(6,13);
		$.get(url+'products_ajax/add_inn/'+code+'/'+preventcache, function(html){
				$('#ordqty').text(html).show('slow');
				updatedisp(code);
		});	
	});

	// Remove inner from the order
	$('.dedinn').click(function(eve){
		preventcache = new Date().getTime();
		eve.preventDefault();						
		string = $(this).attr('id');
		code = string.slice(6,13);
		$.get(url+'products_ajax/min_inn/'+code+'/'+preventcache, function(html){
				$('#ordqty').text(html).show('slow');
				updatedisp(code);
		});
	});
	
	// Display the correct qtys and subtotals on the page
	function updatedisp(code) {
		preventcache = new Date().getTime();
		$.get(url+'products_ajax/display/'+code+'/'+preventcache, function(html){
				results = html.split(' | ');
				$('#ordqty'+code).text(results[0]).show('slow');
		});
		
	}

});


