<!-- 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);
currentacid=form.currentacid.value;
desiredacid=form.desiredacid.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 (currentacid == "")
window.alert("Please enter the current acid level in the must, juice or wine");
if (desiredacid == "")
window.alert("Please enter the desired acid level in the must, juice or wine");

if (desiredacid < 5)
window.alert("Most commercial red wines have an acid level between five and seven tenths of a percent while commercial white wines typically have between six and eight tenths of a percent titratable acid");
if (desiredacid > 8)
window.alert("Most commercial red wines have an acid level between five and seven tenths of a percent while commercial white wines typically have between six and eight tenths of a percent titratable acid");
calculate(form)
}





function calculate(form) {
var gallons=form.gallons.value;

var tartaricgrams=((desiredacid-currentacid)*(gallons*3.7));
var tartaricgramsround=Math.round(tartaricgrams);
var tartaricounces=(tartaricgrams*.0353)
var tartaricouncesround=Math.round(tartaricounces*10)/10;
var tartarictsps=(tartaricgrams/5);
var tartarictspsfull=Math.floor(tartarictsps);
var tartarictspsdec=(tartarictsps-tartarictspsfull);
var tartaricmilliliters=(tartarictsps*4.93)
var tartaricmillilitersround=Math.round(tartaricmilliliters*10)/10

var malicgrams=((desiredacid-currentacid)*(gallons*3.6));
var malicgramsround=Math.round(malicgrams);
var malicounces=(malicgrams*.0353)
var malicouncesround=Math.round(malicounces*10)/10;
var malictsps=(malicgrams/4.5);
var malictspsfull=Math.floor(malictsps);
var malictspsdec=(malictsps-malictspsfull);
var malicmilliliters=(malictsps*4.93)
var malicmillilitersround=Math.round(malicmilliliters*10)/10


var acidblendgrams=((desiredacid-currentacid)*(gallons*3.6));
var acidblendgramsround=Math.round(acidblendgrams);
var acidblendounces=(acidblendgrams*.0353)
var acidblendouncesround=Math.round(acidblendounces*10)/10;
var acidblendtsps=(acidblendgrams/4.9);
var acidblendtspsfull=Math.floor(acidblendtsps);
var acidblendtspsdec=(acidblendtsps-acidblendtspsfull);
var acidblendmilliliters=(acidblendtsps*4.93)
var acidblendmillilitersround=Math.round(acidblendmilliliters*10)/10

var chalkgrams=((currentacid-desiredacid)*(gallons*3.5));
var chalkgramsround=Math.round(chalkgrams);
var chalkounces=(chalkgrams*.0353)
var chalkouncesround=Math.round(chalkounces*10)/10;
var chalktsps=(chalkgrams/2.6);
var chalktspsfull=Math.floor(chalktsps);
var chalktspsdec=(chalktsps-chalktspsfull);
var chalkmilliliters=(chalktsps*4.93)
var chalkmillilitersround=Math.round(chalkmilliliters*10)/10

if (tartaricgramsround >0)  
form.tartaricgramsround.value=tartaricgramsround;
else
form.tartaricgramsround.value=0;

if (tartaricouncesround >0)  
form.tartaricouncesround.value=tartaricouncesround;
else
form.tartaricouncesround.value=0;

if (tartaricmillilitersround >0)  
form.tartaricmillilitersround.value=tartaricmillilitersround;
else
form.tartaricmillilitersround.value=0;

if (tartarictspsfull <1)
tartarictspsfull=""
if (tartarictspsdec >.9)
form.tartarictspsfraction.value=tartarictspsfull+1;
else if (tartarictspsdec >.65)
form.tartarictspsfraction.value=tartarictspsfull+"  3/4";
else if (tartarictspsdec >.4)
form.tartarictspsfraction.value=tartarictspsfull+"  1/2";
else if (tartarictspsdec >.2)
form.tartarictspsfraction.value=tartarictspsfull+"  1/4";
else if (tartarictspsdec >.1)
form.tartarictspsfraction.value=tartarictspsfull+"  1/8";
else
form.tartarictspsfraction.value=tartarictspsfull;
if (tartaricgramsround <1)
form.tartarictspsfraction.value=0;

if (malicgramsround >0)  
form.malicgramsround.value=malicgramsround;
else
form.malicgramsround.value=0;

if (malicouncesround >0)  
form.malicouncesround.value=malicouncesround;
else
form.malicouncesround.value=0;

if (malicmillilitersround >0)  
form.malicmillilitersround.value=malicmillilitersround;
else
form.malicmillilitersround.value=0;

if (malictspsfull <1)
malictspsfull=""
if (malictspsdec >.9)
form.malictspsfraction.value=malictspsfull+1;
else if (malictspsdec >.65)
form.malictspsfraction.value=malictspsfull+"  3/4";
else if (malictspsdec >.4)
form.malictspsfraction.value=malictspsfull+"  1/2";
else if (malictspsdec >.2)
form.malictspsfraction.value=malictspsfull+"  1/4";
else if (malictspsdec >.1)
form.malictspsfraction.value=malictspsfull+"  1/8";
else
form.malictspsfraction.value=malictspsfull;
if (malicgramsround <1)
form.malictspsfraction.value=0;

if (malicmillilitersround >0)  
form.malicmillilitersround.value=malicmillilitersround;
else
form.malicmillilitersround.value=0;


if (acidblendgramsround >0)  
form.acidblendgramsround.value=acidblendgramsround;
else
form.acidblendgramsround.value=0;

if (acidblendouncesround >0)  
form.acidblendouncesround.value=acidblendouncesround;
else
form.acidblendouncesround.value=0;

if (acidblendmillilitersround >0)  
form.acidblendmillilitersround.value=acidblendmillilitersround;
else
form.acidblendmillilitersround.value=0;

if (acidblendtspsfull <1)
acidblendtspsfull=""
if (acidblendtspsdec >.9)
form.acidblendtspsfraction.value=acidblendtspsfull+1;
else if (acidblendtspsdec >.65)
form.acidblendtspsfraction.value=acidblendtspsfull+"  3/4";
else if (acidblendtspsdec >.4)
form.acidblendtspsfraction.value=acidblendtspsfull+"  1/2";
else if (acidblendtspsdec >.2)
form.acidblendtspsfraction.value=acidblendtspsfull+"  1/4";
else if (acidblendtspsdec >.1)
form.acidblendtspsfraction.value=acidblendtspsfull+"  1/8";
else
form.acidblendtspsfraction.value=acidblendtspsfull;
if (acidblendgramsround <1)
form.acidblendtspsfraction.value=0;

if (acidblendgramsround >0)  
form.acidblendgramsround.value=acidblendgramsround;
else
form.acidblendgramsround.value=0;

if (chalkgramsround >0)  
form.chalkgramsround.value=chalkgramsround;
else
form.chalkgramsround.value=0;

if (chalkouncesround >0)  
form.chalkouncesround.value=chalkouncesround;
else
form.chalkouncesround.value=0;

if (chalkmillilitersround >0)  
form.chalkmillilitersround.value=chalkmillilitersround;
else
form.chalkmillilitersround.value=0;

if (chalktspsfull <1)
chalktspsfull=""
if (chalktspsdec >.9)
form.chalktspsfraction.value=chalktspsfull+1;
else if (chalktspsdec >.65)
form.chalktspsfraction.value=chalktspsfull+"  3/4";
else if (chalktspsdec >.4)
form.chalktspsfraction.value=chalktspsfull+"  1/2";
else if (chalktspsdec >.2)
form.chalktspsfraction.value=chalktspsfull+"  1/4";
else if (chalktspsdec >.1)
form.chalktspsfraction.value=chalktspsfull+"  1/8";
else
form.chalktspsfraction.value=chalktspsfull;
if (chalkgramsround <1)
form.chalktspsfraction.value=0;




}







