function getQuantity() 
{
	var size = document.getElementById("terrain_size").value;
	var water = document.getElementById("water").value;
	var concentration = document.getElementById("concentration").value;
	var sprayer = document.getElementById("sprayer").value;
	
	
	size = size.replace(",", ".");
	water = water.replace(",", ".");
	concentration = concentration.replace(",", ".");
	sprayer = sprayer.replace(",", ".");
	
	size = size.replace(/[^0-9$.,]/g, '');
	water = water.replace(/[^0-9$.,]/g, '');
	concentration = concentration.replace(/[^0-9$.,]/g, '');
	sprayer = sprayer.replace(/[^0-9$.,]/g, '');
	
	terrain_unit = $( "#terrain_unit option:selected" ).text();
	concentration_unit = $( "#concentration_unit option:selected" ).text();
	
	$("#result").text("");
	$("#result-text").text("");
	$("#result-sprayer").text("");
	$("#result-sprayer-text").text("");
	
	
	var concentrationProc;
	var unit = "kg";
	
	if (!size)
		size = 1;

	if (terrain_unit == "a")
		size /= 100;
	else if (terrain_unit == "m2")
		size /= 10000;

	
	if (concentration_unit == "%")
		concentrationProc = concentration*1000/water;
	else if (concentration_unit == "kg/ha")
	{	
		concentrationProc = concentration*100/water;
		unit = "kg";
	}
	else if (concentration_unit == "l/ha")
	{	
		concentrationProc = concentration*100/water;
		unit = "l";
	}
	else if (concentration_unit == "dl/ha")
	{	
		concentrationProc = concentration*100/water/10;
		unit = "l";
	}
	else if (concentration_unit == "dag/ha")
	{
		concentrationProc = concentration*100/water/100;
		unit = "kg";
	}
	else if (concentration_unit == "cl/ha")
	{
		concentrationProc = concentration*100/water/100;
		unit = "l";
	}
	else if (concentration_unit == "g/ha")
	{	
		concentrationProc = concentration*100/water/1000;
		unit = "kg";
	}
	else if (concentration_unit == "ml/ha")
	{	
		concentrationProc = concentration*100/water/1000
		unit = "l";
	}
	
	
	if (size && concentration && water)
	{
		if (concentration_unit == '%')
			quant = 10*concentration*size
		else
			quant = water*concentrationProc*size/100;
		
		if (quant < 0.01)
		{
			quant *= 1000;
			if (unit == "kg")
				unit = "g";
			else
				unit = "ml";
			
		}
		if (sprayer)
		{
			divider = water*size/sprayer
			response = quant/divider;
			sprayerUnit = unit;
			
			if (response < 0.01)
			{	
				if (unit == "kg")
				{
					sprayerUnit = "g"
					response *= 1000;
				}
				else if (unit == "l")
				{	
					sprayerUnit = "ml"
					response *= 1000;
				}
			}
			$("#result-sprayer-text").text("For a single sprayer, use ");
			$("#result-sprayer").text(response.toFixed(2)+sprayerUnit+" of plant protector.");
		}
		
		$("#result-text").text("Based on the entered data, we advise you to use ");
		$("#result").text(quant.toFixed(2)+unit+" of plant protector.");
	}
	else
		$("#result-text").text("To calculate the amount of plant protector, you should minimally enter the amount of water, hectares, and requested concentration.");
}

$("input[type=number]").keydown(function (e) {
var key = e.which ? e.which : event.keyCode;
if (key == 110 || key == 188) {
    e.preventDefault();
    var value = $(this).val();
    //console.log(value);
    $(this).val(value);
}
});