/*
* SCRIPT SEBASTIAN 
*/

function calculoprecio(form){
	
	// Latas
	var preciolata01, preciolata02, preciolata03, preciolata04, preciolata05 = 0;
	var cantidad01 //  cantidad de latas
	var subtotal01, subtotal02, subtotal03, subtotal04, subtotal05 = 0;
	preciolata01 = 13.90; // Jabali
	preciolata02 = 13.90; // Ciervo
	preciolata03 = 13.90;  // Ñandu
	preciolata04 = 8.90;  // Cerdo
	preciolata05 = 8.90;  // Vacuno
	
	subtotal01 = (form.lata01.value * 1) * preciolata01; 
	form.subtotal01.value = subtotal01;

	subtotal02 = (form.lata02.value * 1) * preciolata02; 
	form.subtotal02.value = subtotal02;

	subtotal03 = (form.lata03.value * 1) * preciolata03; 
	form.subtotal03.value = subtotal03;

    subtotal04 = (form.lata04.value * 1) * preciolata04; 
	form.subtotal04.value = subtotal04;

	subtotal05 = (form.lata05.value * 1) * preciolata05; 
	form.subtotal05.value = subtotal05;

	cantidad01 = (form.lata01.value * 1) + (form.lata02.value * 1) + (form.lata03.value * 1) + (form.lata04.value * 1) + (form.lata05.value * 1);
	form.cantidad01.value = cantidad01;
	
	// Estuches
	var precioestuche01, precioestuche02, precioestuche03, precioestuche04, precioestuche05, precioestuche06 = 0;
	var subtotal06, subtotal07, subtotal08, subtotal09, subtotal10, subtotal11 = 0;
	var estuche01, estuche02, estuche03, estuche04, estuche05, estuche06 = 0;
	var cantidad02 //  cantidad de Estuches

	precioestuche01 = 83; // Lata Opc 1
	precioestuche02 = 55; // Lata Opc 2
	precioestuche03 = 78;  // Estuche con Sobres Opc 1
	precioestuche04 = 165;  // Estuche con Sobres Opc 2
	precioestuche05 = 370;  // Estuche con Jamón Opc 1
	precioestuche06 = 270;  // Estuche con Jamón Opc 2
	
	subtotal06 = (form.estuche01.value * 1) * precioestuche01; 
	form.subtotal06.value = subtotal06;

	subtotal07 = (form.estuche02.value * 1) * precioestuche02; 
	form.subtotal07.value = subtotal07;

	subtotal08 = (form.estuche03.value * 1) * precioestuche03; 
	form.subtotal08.value = subtotal08;

	subtotal09 = (form.estuche04.value * 1) * precioestuche04; 
	form.subtotal09.value = subtotal09;

    subtotal10 = (form.estuche05.value * 1) * precioestuche05; 
	form.subtotal10.value = subtotal10;

	subtotal11 = (form.estuche06.value * 1) * precioestuche06; 
	form.subtotal11.value = subtotal11;
	
	cantidad02 = (form.estuche01.value * 1) + (form.estuche02.value * 1) + (form.estuche03.value * 1) + (form.estuche04.value * 1);
	form.cantidad02.value = cantidad02;
	
	cantidad03 = (form.estuche05.value * 1) + (form.estuche06.value * 1);
	form.cantidad03.value = cantidad03;
	form.total.value = subtotal01 + subtotal02 + subtotal03 + subtotal04 + subtotal05 + subtotal06 + subtotal07 + subtotal08 + subtotal09 + subtotal10 + subtotal11;
}

function validarCantidad(theForm) {
	var minimocajas = 10;
	var minimoestuches = 3;
	var cantcajas, cantestuches, cantjamones = 0;
	
	cantcajas = parseInt(theForm.cantidad01.value);
	cantestuches = parseInt(theForm.cantidad02.value);
	cantestuches = parseInt(theForm.cantidad02.value);
	
	if ((cantcajas < minimocajas) && (cantcajas > 0)) {
        alert("La compra mínima es de 10 latas");
 		theForm.cantidad01.focus();
        return false;
    }

	if ((cantestuches < minimoestuches) && (cantestuches > 0)) {
        alert("La compra mínima es de 3 Estuches.");
 		theForm.cantidad02.focus();
        return false;
    }
	if ((cantestuches == 0) && (cantcajas == 0) && (cantjamones == 0)) {
        alert("Debe realizar la compra de alguno de nuestros productos.");
 		theForm.cantidad01.focus();
        return false;
    }
    return true;
}