function addProduct(webroot, idProduct, qty, type)

{

	$.post(webroot+"cart/addproduct", {idProduct: idProduct, quantity: qty}, function(data){

		if (type == 1) {

			updateCart(data);

		} else if (type== 2){

			updateCart(data);

			location.reload();

		} else {

			updateCartInfo(data);

		}

	});

}

function quitProduct(idProduct)

{

	$('#dialog').html('Por favor, confirma la eliminaci&oacute;n del producto');

	$("#dialog").dialog({

			bgiframe: true,

			resizable: false,

			width: 350,

			height:100,

			modal: true,

			overlay: {

				backgroundColor: '#000',

				opacity: 0.1

			},

			buttons: {

				'Eliminar': function() {

					$.post(BASEPATH+"/cart/quitproduct", {idProduct: idProduct}, function(data){location.href=BASEPATH+'/cart/view'});

				},

				'Cancelar': function() {

					$(this).dialog('close');

				}

			}

		});

}

function updateCartInfo(items)

{

	$('#cart_text').html(items + ' productos');

	if ($('#dialog').html() == '') {

		$('#dialog').html('Producto a&ntilde;adido a la cesta');

		$("#dialog").dialog({

				bgiframe: true,

				resizable: false,

				width: 350,

				height:100,

				modal: true,

				overlay: {

					backgroundColor: '#000',

					opacity: 0.1

				},

				buttons: {

					'Ir a la cesta': function() {

						location.href = BASEPATH+'/cart/view';

					},

					'Seguir comprando': function() {

						$(this).dialog('close');

					}

				}

			});

	} else {

		$("#dialog").dialog('open');

	}

}



function updateCart()

{

	$('#dialog').html('Cesta actualizada');

	$('#dialog').dialog();

}

/* 

$("#cart").ready(function(){

	$("#cart_text").mouseover(function(){ show_minicart() }); 

});

		

function show_minicart() {

	$.post(BASEPATH +"/cart/showminicart", {}, function(data){

		$("#span_cart").html(data);

		$("#span_cart").width($("#cart").width());

	});	

}

 */
