// JavaScript Document

$(document).ready(function() {  
     
    //var link = ""; 
  
    $("ul.products form").submit(function() {  
        
		// Get the product ID and the quantity  
        var id = $(this).find('input[name=product_id]').val();  
        var qty = $(this).find('input[name=quantity]').val(); 
		
		//alert('ID:' + id + '\n\rQTY:' + qty);   
  
		$.post(link + "add_cart_item", {product_id: id, quantity: qty, ajax: '1'},
			function(data) {
				
				if(data == 'true') {
					
					$.get(link + "blog/show_cart", function(cart)
					{
						$("#cart_content").html(cart);
						//location.reload();
					});
				
				} else {
					alert("Record does not exist");
				}
			
			});
		  
        return false;   
    });  
	
	$("table.checkout form").submit(function() {
		
		alert("Click");
		
		$(".checkout_view").show();
		//$("submit[name=checkout]").click;
		
		
		$.post(link + "blog/checkout", {ajax: '1'}, function(data) {
				
				if(data == 'true') {
				
					$.get(link + "blog/show_checkout", function(cart)
					{
						
						$("#checkout_content").html(cart);
					});
				} else {
					alert("Is not working");
				}
			});
		
		return false;
	});
	
  
});  


$(".empty").live("click", function() {
	$.get(link + "blog/empty_cart", function() {
		$.get(link + "blog/show_cart", function(cart) {
			$("#cart_content").html(cart);
		});
	});
	
	return false;
});


