//////////////////////deleting whole cart at once//////////////////////////
function emptyCart()
{
	$.ajax({
     type: "POST",
     url: controllerPath+'/carts/emptycart',
     dataType: "json",
     success: function(data){
		 var items=data.fileName;
		 var pre=data.pre;
	 deleteCart(items,pre);
     setNumItemsDisplay();
     }
   });
	
	
	
	}
	
	
	function deleteCart(items,pre)
	{
	$("#cartItems").empty();
	$("#cartItems").append('<li>There is no item in your cart!...</li>');
	for(var i in items)
		 {
		  if(items.hasOwnProperty(i))
			{
				$('#checkOutId'+pre[i]+items[i]).attr('disabled','');
				//$('#checkOutId'+pre[i]+items[i]).css({'cursor' : 'pointer'});
				$('#checkOutId'+pre[i]+items[i]).removeClass('added_to_cart').addClass('checkoutButton');
				$('#checkOutId'+pre[i]+items[i]).attr('value','Add to Cart');
				//alert(items[i]);checkoutButton
			}
		}
	}
	
	
	
	
///////////////////deleting one element at a time///////////////////////	
	
	
	function deleteOne(id)
	{
		$.ajax({
     type: "POST",
     url: controllerPath+"/carts/emptyone/"+id,
     dataType: "json",
     success: function(data){
	 var items=data.items;
	 var path=data.path;
	 var button=data.button;
	 var pre=data.pre;
	 showCart(items,path,button,pre);

     }
   });	
	}
	
	
	function showCart(items,pth,button,pre)
	{
		$('#checkOutId'+pre+button).attr('disabled','');
		//$('#checkOutId'+pre+button).css({'cursor' : 'pointer'});
		$('#checkOutId'+pre+button).attr('value','Add to Cart');
		$('#checkOutId'+pre+button).removeClass('added_to_cart').addClass('checkoutButton');
		//alert(button);
        $("#cartItems").empty();
        var path = pth;
        for(var i in items){
                    if(items.hasOwnProperty(i)){

                    $("#cartItems")
                        .append(
                            '<li class="cartItem"><span><img class="item" src="'
                            + path +
                            '/uploads/thumb/'
                            + items[i][2] +
                            '"></span><img style="display:none;" class="delete" src="'
                            + path +
                            '/cartdia-delete-item.jpg" alt="delete this item" onclick="deleteOne('
                            + i +
                            ');" style="cursor:pointer;"/></li>'
                        );
                    }
        }

        if(!$('#cartItems').children().length){
              $('#cartItems').append('<li>No items in Cart</li>');
          }
        
        $('.cartItem').hover(function(){
            $(this).children('.delete').css('display', 'block');
        },function(){
            $(this).children('.delete').css('display', 'none');
        });
        setNumItemsDisplay();
	}
	