var iBodem = 0
var iSpec =0
var iVoor = 0
var iGroen = 0
var iOrgm = 0
var iCorr = 0
var iNTheor = 0

function SetCofHumus()
{
	if (document.Nadvies.Bodemtype.value == "L")
		{
		divCofHumus.style.display = ""
		divCofHumusL.style.display = ""
		divCofHumusH.style.display = "none"
		CalcBodem("L")
		}
	else if (document.Nadvies.Bodemtype.value == "H")
		{
		divCofHumus.style.display = ""
		divCofHumusL.style.display = "none"
		divCofHumusH.style.display = ""
		CalcBodem("H")
		}
	else
		{
		CalcBodem("")
		}
}

function CalcBodem(LeemofHumus)
{
	iBodem = 0
	if (LeemofHumus == "L")
		{
		iBodem = parseInt(document.Nadvies.CofHumusL.value)
		}
	else if (LeemofHumus == "H")
		{
		iBodem = parseInt(document.Nadvies.CofHumusH.value)
		}

	if (iBodem != 0)
		{
		document.getElementById('bodem').innerHTML = iBodem + " kg/ha"
		divSpec.style.display = ""
		CalcNTheor()
		}
	else
		{
		document.getElementById('bodem').innerHTML = ""
		divSpec.style.display = "none"
		}
}

function CalcSpec()
{
  iSpec = 0

	if (document.Nadvies.Spec1.checked) iSpec = iSpec + parseInt(document.Nadvies.Spec1.value)
	if (document.Nadvies.Spec2.checked) iSpec = iSpec + parseInt(document.Nadvies.Spec2.value)
	if (document.Nadvies.Spec3.checked) iSpec = iSpec + parseInt(document.Nadvies.Spec3.value)
	if (document.Nadvies.Spec4.checked) iSpec = iSpec + parseInt(document.Nadvies.Spec4.value)
	if (document.Nadvies.Spec5.checked) iSpec = iSpec + parseInt(document.Nadvies.Spec5.value)
	if (iSpec > 50) 
		{
		iSpec = 50
		}
	document.getElementById('spec').innerHTML = String(iSpec) + " kg/ha"
	divVoor.style.display = ""
	CalcNTheor()

}

function CalcVoor()
{
	iVoor = parseInt(document.Nadvies.voorteelt.value)
	document.getElementById('voor').innerHTML = String(iVoor) + " kg/ha"
	divGroen.style.display = ""
	CalcNTheor()
}

function CalcGroen()
{
	iGroen = parseInt(document.Nadvies.groenbemester.value)
	document.getElementById('groen').innerHTML = String(iGroen) + " kg/ha"
	divOrgm.style.display = ""

	iCorr = parseInt(document.Nadvies.corrfactor.value)
	document.getElementById('corr').innerHTML = iCorr + " kg/ha"
	divCorr.style.display = ""
	CalcNTheor()
}

function CheckOrgm(n)
{
	if (document.Nadvies.CbxOrgm[n].checked)
	{
		document.Nadvies.perorgm[n].style.display = ""
		document.Nadvies.norgm[n].style.display = ""
		document.Nadvies.dosisorgm[n].style.display = ""
	}
	else
	{
		document.Nadvies.perorgm[n].style.display = "none"
		document.Nadvies.norgm[n].style.display = "none"
		document.Nadvies.dosisorgm[n].style.display = "none"
	}
	CalcOrgm()
}

function ClickPerOrgm(n)
{
	document.Nadvies.norgm[n].value = document.Nadvies.perorgm[n].value
	CalcOrgm()
}

function CalcOrgm()
{
  iOrgm = 0
	for (i=0; i<document.Nadvies.CbxOrgm.length; i++)
	{
		if (document.Nadvies.CbxOrgm[i].checked)
		{
			iOrgm = iOrgm + (parseFloat(document.Nadvies.norgm[i].value) * parseFloat(document.Nadvies.dosisorgm[i].value)) 
		}
	}
	iOrgm = -1 * parseInt(iOrgm)
	document.getElementById('orgm').innerHTML = String(iOrgm) + " kg/ha"
	CalcNTheor()
}

function DisplayNTheor()
{
	divBereken.style.display = "none"
	divNTheor.style.display = ""
}

function CalcNTheor()
{
		iNtheor = iBodem + iSpec + iVoor + iGroen + iOrgm + iCorr
		if (iNtheor <= -50) 
			{
			iNtheor = 0
			}
		else
		  {
				if (iNtheor <= 30) 
					{
					iNtheor = 30
					}
			}
		 document.getElementById('ntheoronder').innerHTML = String(iNtheor) + " kg/ha"
}

