// submit form
function validar()
{	
	var cantidad = _getParseFloat('CarroCantidad');
	var minima = _getParseFloat('CarroCantidadMin');
	var maxima = _getParseFloat('CarroCantidadMax');
	
	var precio_unico = _getParseFloat('ProductoPrecioUnico');
	// var precio_unico = $('ProductoPrecioUnico').value;

	if (precio_unico==1)
	{
		if(cantidad<1)
		{
			return false;
		}	
	}
	else
	{
		
	 // alert( minima +' > '+ maxima + ' > ' + cantidad );
		var mensaje_max = $('CarroMensajeMax').value;
		var mensaje_min = $('CarroMensajeMin').value;
	
		if( cantidad<minima )
		{
			alert(mensaje_min.replace(/%1/, minima));
			return false;
		}
		else if( cantidad>maxima )
		{	
			alert(mensaje_max.replace(/%1/, maxima));
			return false;
		}	
	}
	$('carro_id').submit(); 
}


// onchange cantidad
function sumarCantidad()
{
	var color_cantidad = _getParseFloat('CarroColorCantidad');

	// sumar cuando hay varios colores
	if( color_cantidad>0 )
	{
		var CarroCantidad = 0;
		for( var i=1; i<=color_cantidad; i++ )
		{
			CarroCantidad += _getParseFloat('CarroColorCantidad'+i);
		}	
		
		$('CarroCantidad').value = CarroCantidad;
		$('VerCarroCantidad').innerHTML = CarroCantidad;
		
		var urlbase = $('CarroUrlBase').value;
		new Ajax.Updater('id_precio', urlbase+'/productos/calcular_precio', {asynchronous:false, evalScripts:true, parameters:$('carro_id').serialize(true)} );
	}
}		


// onchange cantidad -> calcular precio
function calcularPrecio()
{
	var urlbase = $('CarroUrlBase').value;
	new Ajax.Updater('id_precio', urlbase+'/productos/calcular_precio', {asynchronous:false, evalScripts:true, parameters:$('carro_id').serialize(true)} );
}