function dragItemCart(id,itemqty,itemname,price,desc,selector){
	row = jQuery("<div/>").addClass("itemDfCart col").attr({id:"row-"+id}).appendTo(selector);
	qty = jQuery("<div/>").addClass("qtyDfCart col").appendTo(row);
	jQuery(document.createElement("input")).attr("type","text").val(itemqty).change(updateItem).appendTo(qty);
	jQuery("<div/>").addClass("nameDfCart col").html(itemname).appendTo(row);
	jQuery("<div/>").addClass("descDfCart col").html(desc).appendTo(row);
	jQuery("<div/>").addClass("priceDfCart col").html("Q "+price).appendTo(row);
	del = jQuery("<div/>").addClass("deleteDfCart col").appendTo(row);
	jQuery("<span/>").addClass("actDelete col").click(deleteItem).appendTo(del);
}
function dragDfCart(selector){
	 jQuery.ajax({
	   type: 'POST',
	   url: 'http://latinotv.com/sfSimpleCMS/dfCart',
	   dataType: 'json',	
	   data: 'act=cart',
	   success: function(res){
		if(res.length>0){
			var totitems = 0, totpag = 0;
			for(x in res){
				totitems = parseInt(totitems+res[x].qty);
				totpag += parseFloat(res[x].qty*res[x].price);
				dragItemCart(res[x].id,res[x].qty,res[x].name,res[x].price,res[x].desc,selector);
			}
			jQuery('#totitems').html(totitems);		
			jQuery('#totpag').html(totpag.toFixed(2));	
			selector.slideDown('slow');
		}else{
			//jQuery("<div/>").html("Su carro de compras esta vacio").appendTo(selector);
		}
	   }
	 });	
}
function updateItem(val,id){
	 itemId = jQuery(this).parent().parent().attr('id').substr(4);
	 itemQty = jQuery(this).val();
	 element = jQuery(this).parent().parent();
	 jQuery.ajax({
	   type: 'POST',
	   url: 'http://latinotv.com/sfSimpleCMS/dfCart',
	   dataType: 'json',	
	   data: 'id='+itemId+'&qty='+itemQty+'&act=update',
	   success: function(res){
		jQuery('#row-'+res.id+' input').val(res.qty);
		jQuery('#totitems').html(res.totitem);		
		jQuery('#totpag').html(res.totpag);		
		element.effect("highlight", {}, 3000);
	   }
	 });
}
function deleteItem(){
	 itemId = jQuery(this).parent().parent().attr('id').substr(4);
	 element = jQuery(this).parent().parent();
	 jQuery.ajax({
	   type: 'POST',
	   url: 'http://latinotv.com/sfSimpleCMS/dfCart',
	   dataType: 'json',	
	   data: 'id='+itemId+'&act=delete',
	   success: function(res){
		//element.hide("explode", 1000);
		element.slideUp('slow');
		element.remove()
		/*element.slideUp('slow', function(){
			element.remove()
		});*/
		jQuery('#totitems').html(res.totitem);		
		jQuery('#totpag').html(res.totpag);		
	   }
	 });
}
