function buyProducto(producto, precio){
	var cantidad = document.getElementById('cantidad_'+producto).value;
	if (cantidad == ''){
		alert('Debe completar la cantidad');
	} else {
		var entero = parseInt(cantidad);
		if (isNaN(entero)){
			alert('El número ingresado no es válido');
		} else {
			if (entero <= 0){
				alert('El número ingresado debe ser mayor que cero');
			} else {
				runAddCarrito(producto, cantidad, precio);
}}}}
/*---------------------------------------------------------------------------------*/
function runAddCarrito(producto, cantidad, precio){
	document.getElementById('indicador').style.visibility = 'visible';

	var postData = "producto="  + producto +
				   	"&cantidad="+ cantidad +
				   	"&precio="  + precio;
	YAHOO.util.Connect.asyncRequest("POST", "addcarrito.php", oBackAddCarrito, postData);
}
/*---------------------------------------------------------------------------------*/
var okAddCarrito = function(o){
	document.getElementById('indicador').style.visibility = 'hidden';

	if(o.responseText !== undefined && o.responseText !== ''){
		var fixed = parseFloat(o.responseText);
		document.getElementById('total_compra').innerHTML = fixed.toFixed(2);
		document.getElementById('label_checkout').innerHTML = '<a href="checkout.php" class="finalizar">finalizar compra</a>';
	} else {
		document.getElementById('total_compra').innerHTML = 0;
		document.getElementById('label_checkout').innerHTML = '';
	}
}
var badAddCarrito = function(o){}
var oBackAddCarrito = {success:okAddCarrito, failure:badAddCarrito};
