// JavaScript Document
function setStyleSi(id) {
	document.getElementById(id).value = "SI";
	document.getElementById(id).style.background = "#090";
}

function setStyleNo(id) {
	document.getElementById(id).value = "NO";
	document.getElementById(id).style.background = "#900";
}


function checkValue(field) { 
	if(!isNumericValue(field.value)) { 
		giveWarningAndFixValue(field); 
	} 
	ganadoCalcula (field.id);
	//alert('eo');
}

function ganadoCalcula (nombreDelCampo) {

		var resultadoString = "";

		switch (nombreDelCampo){
		//########################################
		case "ganado0" :
			document.getElementById("ganado0Out").value = FormatNumber (document.getElementById("ganado0").value * 0.36, 2, true, false);
			break;
		case "ganado1" :
			document.getElementById("ganado1Out").value = FormatNumber (document.getElementById("ganado1").value * 0.73, 2, true, false);
			break;
		case "ganado2" :
			document.getElementById("ganado2Out").value = FormatNumber (document.getElementById("ganado2").value * 1, 2, true, false);
			break;
		//########################################
		}
		//VACAS
		tempValue = parseFloat(document.getElementById("ganado0Out").value) + parseFloat(document.getElementById("ganado1Out").value) + parseFloat(document.getElementById("ganado2Out").value);
		tempValue = FormatNumber (tempValue, 2, true, false);
		tempValue = tempValue + ''; //convierte a string
		document.getElementById("ganadoOutTotal").value = tempValue;
		document.getElementById("tamUGM").value = tempValue;
		
		tempValue = parseFloat(document.getElementById("ganado0").value) + parseFloat(document.getElementById("ganado1").value) + parseFloat(document.getElementById("ganado2").value);
		tempValue = FormatNumber (tempValue, 2, true, false);
		tempValue = tempValue + ''; //convierte a string
		document.getElementById("tamGanado").value = tempValue;
		
		//CULTIVOS
		tempValue = parseFloat(document.getElementById("maizHA").value) + parseFloat(document.getElementById("forrajeraHA").value) + parseFloat(document.getElementById("naturalHA").value);
		tempValue = FormatNumber (tempValue, 2, true, false);
		tempValue = tempValue + '';
		document.getElementById("tamHA").value = tempValue;
		
		//ESTIMACIONES
		tempValue = parseFloat(4 * parseFloat(document.getElementById("tamUGM").value));
		tempValue = FormatNumber (tempValue, 2, true, false);
		tempValue = tempValue + '';
		document.getElementById("estEstercolero").value = tempValue;
		
		tempValue = parseFloat(1.5 * parseFloat(document.getElementById("tamUGM").value));
		tempValue = FormatNumber (tempValue, 2, true, false);
		tempValue = tempValue + '';
		document.getElementById("estPurines").value = tempValue;
		
		tempValue = parseFloat((parseFloat(document.getElementById("maizHA").value) * 4.5 ) + (parseFloat(document.getElementById("forrajeraHA").value) * 3) + (parseFloat(document.getElementById("naturalHA").value) * 1.5));
		tempValue = FormatNumber (tempValue, 2, true, false);
		tempValue = tempValue + '';
		document.getElementById("estUGM").value = tempValue;
}

function conclusiones () {
	if ((parseFloat(document.getElementById("depositoLixiviados").value) >=  parseFloat(document.getElementById("estPurines").value)) && (parseFloat(document.getElementById("tamUGM").value) > 0 )) {
		setStyleSi("con1");
	} else {
		setStyleNo("con1");
	}
	if ((parseFloat(document.getElementById("estercolero").value) >= parseFloat(document.getElementById("estEstercolero").value)) && (parseFloat(document.getElementById("tamUGM").value) > 0 )) {
		setStyleSi("con2");
	} else {
		setStyleNo("con2");
	}
	if ((parseFloat(document.getElementById("tamUGM").value) <  parseFloat(document.getElementById("estUGM").value)) && (parseFloat(document.getElementById("tamHA").value) > 0 ) && (parseFloat(document.getElementById("tamUGM").value) > 0 )) {
		setStyleSi("con3");
	} else {
		setStyleNo("con3");
	}
	if ((parseFloat(document.getElementById("depositoLixiviados").value) >=  parseFloat(document.getElementById("estPurines").value)) && (parseFloat(document.getElementById("tamUGM").value) <  parseFloat(document.getElementById("estUGM").value)) && (parseFloat(document.getElementById("tamUGM").value) <  parseFloat(document.getElementById("estUGM").value)) && (parseFloat(document.getElementById("tamHA").value) > 0 ) && (parseFloat(document.getElementById("tamUGM").value) > 0 )) {
		setStyleSi("con4");
	} else {
		setStyleNo("con4");
	}	
}
