<!-- Copywrite iWinemaker.com All rights reserved -->

function quantity(form) {
gallons=form.gallons.value;
liters=form.liters.value;
if (gallons == "")
form.gallons.value=(liters*.26);

if (liters == "")
form.liters.value=(gallons*3.79);
currentso2=form.currentso2.value;
desiredso2=form.desiredso2.value;
validate(form)

}

function validate(form) {
var gallons=form.gallons.value
var liters=form.liters.value
if (gallons == "")
window.alert("Please enter the quantity of must, juice or wine");
if (liters == "")
window.alert("Please enter the quanitity of must, juice or wine");
if (currentso2 == "")
window.alert("Please enter the current sulfite level in the must, juice or wine");
if (desiredso2 == "")
window.alert("Please enter the desired sulfite level in the must, juice or wine");

if (desiredso2 < 25)
window.alert("To mimimize the chance of spoilage and oxidation, at least 25ppm of Sulfur Dioxide is recommended");
if (desiredso2 > 150)
window.alert("Sulfur Dioxide levels greater than 150ppm can impact the taste of your finished wine and lead to adverse reactions in some people");
if (currentso2 > desiredso2)
window.alert("Your current free sulfite level you entered is greater than the desired sulfite level you entered. If this is correct, you do not need to add any additional sulfite");
calculate(form)
}



function calculate(form) {
var gallons=form.gallons.value
var liters=form.liters.value
var so2grams=((desiredso2-currentso2)*(gallons/150));
var so2gramsround=Math.round(so2grams);
var so2ounces=(so2grams*.0353)
var so2ouncesround=Math.round(so2ounces*10)/10;
so2tsps=(so2grams/6.2);
so2tspsfull=Math.floor(so2tsps);
so2tspsdec=(so2tsps-so2tspsfull);
so2milliliters=(so2tsps*4.93)
so2millilitersround=Math.round(so2milliliters*10)/10
campden=((desiredso2-currentso2)*(gallons/75));
campdenfull=Math.floor(campden);
campdendec=(campden-campdenfull);


if (so2gramsround >0)  
form.so2gramsround.value=so2gramsround;
else
form.so2gramsround.value=0;

if (so2ouncesround >0)
form.so2ouncesround.value=so2ouncesround;
else
form.so2ouncesround.value=0

if (so2millilitersround >0)
form.so2millilitersround.value=so2millilitersround;
else
form.so2millilitersround.value=0



if (so2tspsfull <1)
so2tspsfull=""

if (so2tspsdec >.9)
form.so2tspsfraction.value=so2tspsfull+1;
else if (so2tspsdec >.65)
form.so2tspsfraction.value=so2tspsfull+"  3/4";
else if (so2tspsdec >.4)
form.so2tspsfraction.value=so2tspsfull+"  1/2";
else if (so2tspsdec >.2)
form.so2tspsfraction.value=so2tspsfull+"  1/4";
else if (so2tspsdec >.1)
form.so2tspsfraction.value=so2tspsfull+"  1/8";
else
form.so2tspsfraction.value=so2tspsfull;
if (so2gramsround <1)
form.so2tspsfraction.value=0;

if (campdendec >.75)
form.campdenfraction.value=campdenfull+1;
else if (campdendec >.25)
form.campdenfraction.value=campdenfull+" 1/2";
else
form.campdenfraction.value=campdenfull;

if (campdenfull <1)
campdenfull="0"


}









