//CART FUNCTIONS
	
	//MAIN CART PAGE
	function Cart()
	{					//remove an item from cart
		this.remove = function( rowid )
		{
			var f = function()
			{
				location = site_url+'/public/cart/remove/'+rowid+'/0';
			};
			this.open_dialog( f, cart_remove_alert );
		}
		
		//submit cart page form for update
		this.update = function()
		{
			$.ajax(
			{
				type: 'POST',
				url: site_url+'/public/cart/update',
				data: $('#cart_form').serialize(),
				success:function(data)
				{
					location = site_url+'/public/cart';
				},
				error:function()
				{
					alert('error');
				}
			});
		}
		
		//empty the cart
		this.empty = function()
		{
			var f = function()
			{
				location = site_url+'/public/cart/empty_cart/0';
			};
			this.open_dialog( f, cart_empty_alert );
		}
		
		//dialog to confirm action
		this.open_dialog = function( action, msg )
		{
			$( "#cart_dialog" ).dialog(
			{	buttons:[{
					text: "OK",
					click: function()
					{
						$(this).dialog("close");
						action();
					}
				}]
			});
								
			$( "#cart_dialog" ).text( msg );
			$( "#cart_dialog" ).dialog("open");
		}
		
	}
	
	//CART PREVIEW FOR LEFT BAR MENU
	function CartPreview()
	{
		this.show = function()
		{			$('#cart_preview').load( site_url+'/public/cart/preview' );
		}
		
		this.add = function( pid )
		{
			var qty = $('input[name="pq_'+pid+'"]').val();
			$('#cart_preview').load( site_url+'/public/cart/add/'+pid+'/'+qty );
		}
		
		this.update = function()
		{
			$.ajax(
			{
				type: 'POST',
				url: site_url+'/public/cart/update',
				data: $('#cart_form').serialize(),
				success:function(data)
				{
					$('#cart_preview').load( site_url+'/public/cart/preview' );
				},
				error:function()
				{
					alert('error');
				}
			});
		}
		
		//remove an item from cart
		this.remove = function( rowid )
		{
			var f = function()
			{
				$('#cart_preview').load( site_url+'/public/cart/remove/'+rowid );
			};
			this.open_dialog( f, cart_remove_alert );
		}
		
		//empty the cart
		this.empty = function()
		{
			var f = function()
			{
				$('#cart_preview').load( site_url+'/public/cart/empty_cart' );
			};
			this.open_dialog( f, cart_empty_alert );
		}
		
		//dialog to confirm action
		this.open_dialog = function( action, msg )
		{
			$( "#cart_dialog" ).dialog(
			{	buttons:[{
					text: "OK",
					click: function()
					{
						$(this).dialog("close");
						action();
					}
				}]
			});
								
			$( "#cart_dialog" ).text( msg );
			$( "#cart_dialog" ).dialog("open");
		}
		
	}
