[bsa_pro_ad_space id=11]
%ABV%ABW
Kilogram(s)Pound(s)Litre(s)Gallon(s) USGallon(s) ImpOunce(s) </OPTION >Cup(s) USCup(s) ImpCup(s) MetricFl Ounce(s) USFl Ounce(s) ImpPint(s) USPint(s) ImpQuart(s) USQuart(s) Imp
SGBRIXBaume
Value #2 Volume #2 Total Volume
var theForm = document.util; // used to reference DOM elements
// // g e t S e l e c t e d V a l u e ( ) // // return the index of the selection // function getSelectedValue(xitem) { if (xitem.selectedIndex >= xitem.length) return -1; return (xitem.selectedIndex); }
// // L e f t ( ) // return the n left most chars of a string // function Left(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0,n); } // // R i g h t ( ) // return the n right most chars of a string // function Right(str, n){ if (n <= 0) { return ""; } else if (n > String(str).length) { return str; } else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } // // d i s p l a y N u m b e r ( ) // display val to sigFigures zero-filled significant figures // ie 10 becomes 10.000 if sigFigures is 3 // function displayNumber(val,sigFigures) { var neg = (Number(val) < 0) ? '-' : ''; var i = Math.floor(Math.round(Math.pow(10,sigFigures)*Number(Math.abs(val)))/Math.pow(10,sigFigures)); var x = Right(("000" + Math.round(Math.pow(10,sigFigures) * (Math.abs(Number(val)) - Math.abs(i)))), sigFigures); return (Number(neg + i + "." + x)); } // // d i s p l a y N r T r i m ( ) // display val to sigFigures significant figures if non-zero significant figures // ie 10.12345 becomes 10.123 if sigFigures is 3 // ie 10.00012 becomes 10 if sigFigures is 3 // function displayNrTrim(val,sigFigures) { v = displayNumber(val,sigFigures) - Math.floor(Number(val)); for (var j=sigFigures; j>0; j--) { if (v[j] != '0') { break; } v[j] = ''; // blank out trailing zeros } return ( Math.floor(Number(val))+Number(v) ); }
// // S G T o B a u m e ( ) // function SGToBaume(SG) { return (145-145/Number(SG)); }
// // B a u m e T o S G ( ) // function BaumeToSG(Baume) { return (145/(145-Baume)); }
// // S G T o B r i x ( ) // function SGToBrix(SG) { var x = 135.997*Math.pow(Number(SG),3)-630.272*Math.pow(Number(SG),2)+1111.14*Number(SG)-616.868; return (x); }
// // B r i x T o S G ( ) // function BrixToSG(Brix) { var x = 1.00001 + (Number(Brix)/(258.6-0.89*Number(Brix))); return (x); }
// // S G T o A B V ( ) // // Baume IS ABV (approximately, if no too many dissolved solids) // function SGToABV(SG) { return ( SGToBaume(SG) ); }
// // S G T o A B W ( ) // // SG -> ABV (Baume) -> ABW // function SGToABW(SG) { return ( ABVToABW(SGToBaume(SG)) ); }
// // A B V T o A B W ( ) // function ABVToABW(ABV) { return ( ABV * 0.8 ); }
// // A B V T o A B W ( ) // function ABWToABV(ABW) { return ( ABW / 0.8 ); }
// // A B V T o S G ( ) is baumeToSG() // function ABVToSG(ABV) { return ( BaumeToSG(ABV) ); }
// // A B W T o S G ( ) is baumeToSG() // function ABWToSG(ABW) { return ( ABVToSG(ABWToABV(ABW)) ); }
// // S G T o S u g a r C o n c ( ) // // give the g/L concentrate ratio for a given SG, using SG and Brix which is also calculated from the SG // function SGToSugarConc (SG) { return( Number( 4 + 10*SG*SGToBrix(SG) ) ); }
// // s u g a r T o S G ( ) // // uses iterative brute force solving to guess SG from g/L weight of sugars // // Accuracy is only to 3 decimal places // function sugarConcToSG(gPerL) { var i = 0; var sg = 0.992; // start at lowest and work up var loopLimit = 100000; var gpl = 0; // calculated g/L to compare with gPerL var diff = 0; // difference from calc gpl to required gpl
for (i=0;i 0.00001 diff = Math.pow(10,-1*(2 + String(Math.round(gpl,0)).length)); sg = sg*(1+diff); } return(NaN); }
// // c o n v T o S G ( ) // Potential Alc conversion: // // normalising to the SG // using the indx into sgOrigconv_s, calc the SG from the value in sgconv_t.value (val) // index=1 is BRIX to SG, index=2 is Baume to SG else SG to SG // function convToSG(val, indx) { if (indx == 1) { // BRIX -> SG return(BrixToSG(val)); } else if (indx == 2) { // Baume -> SG return(BaumeToSG(val)); } else { // SG return (Number(val)); } } // // c o n v T o A B V ( ) // Potential Alc conversion: // // normalising to the ABV // using the indx into sgOrigconv_s, calc the SG from the value in sgconv_t.value (val) // index=1 is ABW to ABV, else ABV to ABV // function convToABV(val, indx) { if (indx == 1) { // ABW -> ABV var tmp = ABWToABV(Number(val)); return(Number(tmp)); } else { // ABV return (Number(val)); } }
// // i __ u p d a t e V a l s ( ) // Potential Alc conversion: // // update the hidden values from the recently changed display value // Use these hidden values to avoid rounding errors // function i_updateVals(which) {
if (which == 1) { // Orig SG theForm.sgOrigConv_Val.value = theForm.sgOrigConv_t.value; } if (which == 2) { // Final SG theForm.sgFinConv_Val.value = theForm.sgFinConv_t.value; } if (which == 3) { // ABV/ABW theForm.sgABVConv_Val.value = theForm.paconv_t.value; } }
// // c h a n g e G r a v T e x t ( ) // Potential Alc conversion: // // change gravity text box lable to match selection // function changeGravText(which) { var x1 = document.getElementById("grav1"); var x2 = document.getElementById("grav2");
switch(which) { case 0: // SG x1.innerHTML = "Gravity:"; x2.innerHTML = "Gravity:"; break; case 1: // Brix x1.innerHTML = "BRIX:"; x2.innerHTML = "BRIX:"; break; case 2: // Baume x1.innerHTML = "Baume:"; x2.innerHTML = "Baume:"; break; } return(0); }
// // i __ t r a n s l a t e S G ( ) // Potential Alc conversion: // // when change gravity type between SG/BRIX/Baume, then change the displayed value // function i_translateSG(from) { var xt = theForm.sgOrigConv_Val; // hidden value var xs = theForm.sgOrigConv_s; var xt2 = theForm.sgFinConv_Val; // hidden value var tmp = 0; var tmp2 = 0;
// get previous gravity values as SG tmp = convToSG(xt.value, from.value); tmp2 = convToSG(xt2.value, from.value);
// now convert from SG to the new measurement type var to = xs.selectedIndex; // save the selectedIndex ready to be the "from" for next time from.value = to; changeGravText(to); if (to == 1) { // SG -> BRIX xt.value = SGToBrix(tmp); theForm.sgOrigConv_t.value = displayNumber(xt.value, 3); xt2.value = SGToBrix(tmp2); theForm.sgFinConv_t.value = displayNumber(xt2.value, 3); } else if (to == 2) { // SG -> Baume xt.value = SGToBaume(tmp); theForm.sgOrigConv_t.value = displayNumber(xt.value, 3); xt2.value = SGToBaume(tmp2); theForm.sgFinConv_t.value = displayNumber(xt2.value, 3); } else { // else SG -> SG xt.value = tmp; theForm.sgOrigConv_t.value = displayNumber(xt.value,3); xt2.value = tmp2; theForm.sgFinConv_t.value = displayNumber(xt2.value,3); } }
// // i __ c h a n g e S G ( ) // Potential Alc conversion: // // when PA changed by user, then change the displayed value of sgOrigConv_t // leaving the sgFinConv_t unchanged // function i_changeSG() { var xt = theForm.sgOrigConv_Val; var xt2 = theForm.sgFinConv_Val; var pa = theForm.sgABVConv_Val; theForm.sgOrigConv_setting.value = theForm.sgOrigConv_s.selectedIndex; var from = theForm.sgOrigConv_setting; var tmp = 0; var tmp2 = 0; var sg = 0;
// Convert PA to SG because PA is the baume, and includes ABW to ABV to SG if necessary tmp = ABVToSG(convToABV(pa.value,theForm.paconv_s.selectedIndex)); // get previous gravity values as SG tmp2 = convToSG(xt2.value, from.value); sg = Number(tmp) - Number(tmp2) + 1; // the plus 1 is: 1 + (1.xxx - 1.yyy) = 1.zzz
if (from.value == 1) { // SG to BRIX xt.value = SGToBrix(sg); theForm.sgOrigConv_t.value = displayNumber(xt.value, 3); } else if (from.value == 2) { // SG to Baume xt.value = SGToBaume(sg); theForm.sgOrigConv_t.value = displayNumber(xt.value, 3); } else { // else SG to SG xt.value = sg; theForm.sgOrigConv_t.value = displayNumber(xt.value, 3); } }
// // i __ c h a n g e P A ( ) // Potential Alc conversion: // // Update the PA if changed one of the OG or FG values (SG) // function i_changePA() { var xt = theForm.sgOrigConv_Val; // hidden field containing OrigGrav var xt2 = theForm.sgFinConv_Val; // hidden field containing FinalGrav var from = theForm.sgOrigConv_setting;
// get the Orig & Fin SG values, regardless of whether displayed as SG, Brix or Baume var tmp = convToSG(xt.value, from.value); var tmp2 = convToSG(xt2.value, from.value); var abv = SGToABV(1+Number(tmp)-Number(tmp2));
// convert to ABW if required and display the value if (theForm.paconv_s.selectedIndex == 1) { // save the accurate value to avoid rounding errors theForm.sgABVConv_Val.value = ABVToABW(abv); // update the display theForm.paconv_t.value = displayNumber(ABVToABW(abv),2); } else { // save the accurate value to avoid rounding errors theForm.sgABVConv_Val.value = abv; // update the display theForm.paconv_t.value = displayNumber(abv,2); } }
// // u p d a t e A B V o r A B W ( ) // PA Conversion Util // // convert the displayed // function i_updateABVorABW(which) { switch (which) { case 0: // ABW to ABV theForm.sgABVConv_Val.value = displayNumber(ABWToABV(theForm.sgABVConv_Val.value),3); break; case 1: // ABV to ABW theForm.sgABVConv_Val.value = displayNumber(ABVToABW(theForm.sgABVConv_Val.value),3); break; } theForm.paconv_t.value = theForm.sgABVConv_Val.value; }
//////////////////////////////////////// End of PA Conversion //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// Start of Mead Batch Util ////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // i __ u p d a t e P A ( ) // // Update the text box (tbox.value) based on the selection (post selection) od the combo box, // where selection is combobox.selectedIndex // function i_updatePA(selection,tbox) { switch (selection) { case 0: // ABW to ABV tbox.value = displayNumber(ABWToABV(tbox.value),3); break; case 1: // ABV to ABW tbox.value = displayNumber(ABVToABW(tbox.value),3); break; } // update the4 PA CALC util to match theForm.paconv_s.selectedIndex = selection; i_updateABVorABW(selection); return (tbox.value); }
// // g e t S u g a r s ( ) // returns pounds of sugar // function getSugars(which) { var i = 0;
if (which == 1) { // sugars#1 // amount * conversion to pounds * percentage sugar i = theForm.sugars1_t2.value * theForm.sugars1_s2.options[theForm.sugars1_s2.selectedIndex].value * theForm.sugars1_t3.value/100; } else if (which == 2) { // sugars#2 // amount * conversion to pounds * percentage sugar i = theForm.sugars2_t2.value * theForm.sugars2_s2.options[theForm.sugars2_s2.selectedIndex].value * theForm.sugars2_t3.value/100; } else if (which == 3) { // sugars#3 // amount * conversion to pounds * percentage sugar i = theForm.sugars3_t2.value * theForm.sugars3_s2.options[theForm.sugars3_s2.selectedIndex].value * theForm.sugars3_t3.value/100; } else if (which == 4) { // sugars#4 // amount * conversion to pounds * percentage sugar i = theForm.sugars4_t2.value * theForm.sugars4_s2.options[theForm.sugars4_s2.selectedIndex].value * theForm.sugars4_t3.value/100; } return(i); }
// // // function bit_and (p1, p2) { return eval(p1+" "+"&"+" "+p2); }
// // u p d a t e S t a t s ( ) // // determine which entries need to be computed & update them // function i_updateStats() { var vMask = 0; var vSugar = 0; var vCSg = Number(toSG(theForm.currgrav_s.selectedIndex, theForm.currgrav_s, theForm.currgrav_t)); var vCVol = Number(toVol(theForm.currvol_s.selectedIndex, theForm.currvol_s, theForm.vol_valc)); var vTSg = Number(toSG(theForm.targgrav_s.selectedIndex, theForm.targgrav_s, theForm.targgrav_t)); var vTVol = Number(toVol(theForm.targvol_s.selectedIndex, theForm.targvol_s, theForm.vol_valt));
i_updateAlc(); // // Identify which item to be updated (checkbox is unchecked) // // if (theForm.currgrav_cb.checked) { // current Gravity checked // vMask += 1; // } // if (theForm.currvol_cb.checked) { // current Volume checked // mymask += 2; // } if (theForm.targgrav_cb.checked) { // target Gravity checked vMask += 4; } if (theForm.targvol_cb.checked) { // target Volume checked vMask += 8; } if (theForm.sugars1_cb.checked) { // Sugars#1 checked vMask += 16; // Calculate the Sugars vSugar = getSugars(1); } if (theForm.sugars2_cb.checked) { // Sugars#2 checked vMask += 32; // Calculate the Sugars vSugar += getSugars(2); } if (theForm.sugars3_cb.checked) { // Sugars#3 checked vMask += 64; // Calculate the Sugars vSugar += getSugars(3); } if (theForm.sugars4_cb.checked) { // Sugars#4 checked vMask += 128; // Calculate the Sugars vSugar += getSugars(4); } // Do the Calculations here //if ( (vMask & 12) == 8) { if ( bit_and(vMask,12) == 8) { // do **Target Gravity** (targVol checked, targGrav unchecked) // (TargVol* (g/L of TargSG)) = (CurrVol * (g/L of CurrSG)) + Additional Sugars // sugars is vSugar in kilograms, so converted to grams for g/L var mygpl = (vSugar*1000 + (SGToSugarConc(vCSg - getTempCoeff())*vCVol)) / vTVol; theForm.targgrav_t.value = sugarConcToSG(mygpl) + getTempCoeff(); // convert SG to selected units theForm.targgrav_t.value = doConvertSG(0,theForm.targgrav_s.selectedIndex,theForm.targgrav_s,theForm.targgrav_t); // update the Potential Alc value i_updateAlc(); //theForm.sgOrigConv_t.value = theForm.targgrav_t.value; //i_updateVals(1); } else //if ( ((vMask & 12) == 4) && ((vMask & parseInt("0xF0",16)) > 0) ) { if ( (bit_and(vMask,12) == 4) && (bit_and(vMask,parseInt("0xF0",16)) > 0) ) { // do **Target Vol** (targVol unchecked, targGrav checked and at least one Sugars checked) // (TargVol* (g/L of TargSG)) = (CurrVol * (g/L of CurrSG)) + Additional Sugars vTVol = (vSugar*1000 + (SGToSugarConc(vCSg) * vCVol)) / SGToSugarConc(vTSg); // convert g/L to kg/L theForm.vol_valt.value = Number(vTVol / Number(theForm.targvol_s.options[theForm.targvol_s.selectedIndex].value)); theForm.targvol_t.value = displayNumber(theForm.vol_valt.value,2); // Convert to current unit selection using values of the Units Combo values } else //if (((vMask & 12) == 12) && ((vMask & parseInt("0xF0",16)) != parseInt("0xF0",16))) { if ((bit_and(vMask,12) == 12) && (bit_and(vMask,parseInt("0xF0",16)) != parseInt("0xF0",16))) { // do **Honey quantity** - targGrav & targVol checked but not all sugars checked // Grav = 1 + (targGrav-currGrav) var mySg = 1 + (vTSg-vCSg); // sugars is vSugar obtained previously via getSugars() // XtraSugar = TargSugars - AdditionalSugar - CurrSugars var myQuant = (SGToSugarConc(vTSg)*vTVol)/1000 - (SGToSugarConc(vCSg)*vCVol)/1000 - vSugar; if (!theForm.sugars1_cb.checked) { // Sugars#1 NOT checked theForm.sugars1_t2.value = Math.round(myQuant / (Number(theForm.sugars1_s2.options[theForm.sugars1_s2.selectedIndex].value) * Number(theForm.sugars1_t3.value)/100) * 1000)/1000; // Convert to selected quantity unit Scaled by %Sugar } else if (!theForm.sugars2_cb.checked) { // Sugars#2 NOT checked theForm.sugars2_t2.value = Math.round(myQuant / (Number(theForm.sugars2_s2.options[theForm.sugars2_s2.selectedIndex].value) * Number(theForm.sugars2_t3.value)/100) * 1000)/1000; // Convert to selected quantity unit Scaled by %Sugar } else if (!theForm.sugars3_cb.checked) { // Sugars#3 NOT checked theForm.sugars3_t2.value = Math.round(myQuant / (Number(theForm.sugars3_s2.options[theForm.sugars3_s2.selectedIndex].value) * Number(theForm.sugars3_t3.value)/100) * 1000)/1000; // Convert to selected quantity unit Scaled by %Sugar } else if (!theForm.sugars4_cb.checked) { // Sugars#4 NOT checked theForm.sugars4_t2.value = Math.round(myQuant / (Number(theForm.sugars4_s2.options[theForm.sugars4_s2.selectedIndex].value) * Number(theForm.sugars4_t3.value)/100) * 1000)/1000; // Convert to selected quantity unit Scaled by %Sugar } } else //if ( ((vMask & parseInt("0xF0",16)) == parseInt("0xF0",16)) && ((vMask & 12) == 12) ) { if ( (bit_and(vMask,parseInt("0xF0",16)) == parseInt("0xF0",16)) && (bit_and(vMask,12) == 12) ) { // do **CurrGrav** - all four sugars checked and tragGrav and targVol (THIS IS RARE) ; // shouldn't really be wanting to determine the CurrVol or CurrGrav } doBlend(); }
// // f i n d V a l ( ) // // For a SELECT object, find the entry containing a string, // and return the index of that selection (else -1) // function findVal(theOne, what) { var i = 0;
for (i=0; i < theOne.options.length; i++) { if (theOne.options[i].text.indexOf(what) != -1) { return(i); } } return(-1); }
// // i __ u p d a t e P r e f s ( ) // // change selections based on preference click // function i_updatePrefs(theOne) {
if (theForm.prefs[0] == theOne) { // set to Metric theForm.currvol_s.selectedIndex = findVal(theForm.currvol_s,"Litre"); theForm.targvol_s.selectedIndex = findVal(theForm.targvol_s,"Litre"); theForm.sugars1_s2.selectedIndex = findVal(theForm.sugars1_s2,"Kilogram"); //theForm.sugars1_s3.selectedIndex = findVal(theForm.sugars1_s3,"Kilogram"); theForm.sugars2_s2.selectedIndex = findVal(theForm.sugars2_s2,"Kilogram"); //theForm.sugars2_s3.selectedIndex = findVal(theForm.sugars2_s3,"Kilogram"); theForm.sugars3_s2.selectedIndex = findVal(theForm.sugars3_s2,"Kilogram"); //theForm.sugars3_s3.selectedIndex = findVal(theForm.sugars3_s3,"Kilogram"); theForm.sugars4_s2.selectedIndex = findVal(theForm.sugars4_s2,"Kilogram"); //theForm.sugars4_s3.selectedIndex = findVal(theForm.sugars4_s3,"Kilogram"); theForm.mustt_s.selectedIndex = findVal(theForm.mustt_s,"Celsius"); eval(theForm.mustt_s.options[theForm.mustt_s.selectedIndex].value); // update value i_updateQuant(1); // update first Sugars group i_updateVol(theForm.targvol_s,theForm.targvol_t,document.util.vol_settingt,document.util.vol_valt); i_updateVol(theForm.currvol_s,theForm.currvol_t,document.util.vol_settingc,document.util.vol_valc); } if (theForm.prefs[1] == theOne) { // set to US theForm.currvol_s.selectedIndex = findVal(theForm.currvol_s,"US "); theForm.targvol_s.selectedIndex = findVal(theForm.targvol_s,"US "); theForm.sugars1_s2.selectedIndex = findVal(theForm.sugars1_s2,"Pound"); //theForm.sugars1_s3.selectedIndex = findVal(theForm.sugars1_s3,"Pound"); theForm.sugars2_s2.selectedIndex = findVal(theForm.sugars2_s2,"Pound"); //theForm.sugars2_s3.selectedIndex = findVal(theForm.sugars2_s3,"Pound"); theForm.sugars3_s2.selectedIndex = findVal(theForm.sugars3_s2,"Pound"); //theForm.sugars3_s3.selectedIndex = findVal(theForm.sugars3_s3,"Pound"); theForm.sugars4_s2.selectedIndex = findVal(theForm.sugars4_s2,"Pound"); //theForm.sugars4_s3.selectedIndex = findVal(theForm.sugars4_s3,"Pound"); theForm.mustt_s.selectedIndex = findVal(theForm.mustt_s,"Fahren"); if (theForm.mustt.value < 40) { // avoid unnecessary conversion eval(theForm.mustt_s.options[theForm.mustt_s.selectedIndex].value); // update value } i_updateQuant(1); i_updateVol(theForm.targvol_s,theForm.targvol_t,document.util.vol_settingt,document.util.vol_valt); i_updateVol(theForm.currvol_s,theForm.currvol_t,document.util.vol_settingc,document.util.vol_valc); } if (theForm.prefs[2] == theOne) { // set to Imperial theForm.currvol_s.selectedIndex = findVal(theForm.currvol_s,"Imp "); theForm.targvol_s.selectedIndex = findVal(theForm.targvol_s,"Imp "); theForm.sugars1_s2.selectedIndex = findVal(theForm.sugars1_s2,"Pound"); //theForm.sugars1_s3.selectedIndex = findVal(theForm.sugars1_s3,"Pound"); theForm.sugars2_s2.selectedIndex = findVal(theForm.sugars2_s2,"Pound"); //theForm.sugars2_s3.selectedIndex = findVal(theForm.sugars2_s3,"Pound"); theForm.sugars3_s2.selectedIndex = findVal(theForm.sugars3_s2,"Pound"); //theForm.sugars3_s3.selectedIndex = findVal(theForm.sugars3_s3,"Pound"); theForm.sugars4_s2.selectedIndex = findVal(theForm.sugars4_s2,"Pound"); //theForm.sugars4_s3.selectedIndex = findVal(theForm.sugars4_s3,"Pound"); theForm.mustt_s.selectedIndex = findVal(theForm.mustt_s,"Fahren"); if (theForm.mustt.value < 40) { // avoid unnecessary conversion eval(theForm.mustt_s.options[theForm.mustt_s.selectedIndex].value); // update value } i_updateQuant(1); i_updateVol(theForm.targvol_s,theForm.targvol_t,document.util.vol_settingt,document.util.vol_valt); i_updateVol(theForm.currvol_s,theForm.currvol_t,document.util.vol_settingc,document.util.vol_valc); } } // // i __ u p d a t e A l c ( ) // Mead Batch Utility // // update the Potential Alc (ABV/ABW) due to changed SG // function i_updateAlc() { var grav = theForm.targgrav_s; var entry = theForm.targgrav_t; var abv = theForm.targpa_s; var res = theForm.targpa_t; var i = getSelectedValue(grav); // SG or BRIX ?? - want SG var k = toSG(i,grav,entry); // now have the SG -- this calc the SG from the SG field, used to determine the PA from the SG // Calc the ABV or ABW if (abv.options[abv.selectedIndex].text.indexOf("ABV") > -1) { res.value = displayNumber(SGToABV(k),2); } else if (abv.options[abv.selectedIndex].text.indexOf("ABW") > -1) { // ABW = 0.8*ABV res.value = displayNumber(SGToABW(k),2); } }
// // t o S G ( ) // function toSG(from, theOne, theVal) { var i = 0;
// Convert the FROM as SG i = theVal.value; // default is the value if (theOne.options[from].text.indexOf("BRIX") != -1) { i = BrixToSG(theVal.value); } if (theOne.options[from].text.indexOf("Baume") != -1) { i = BaumeToSG(theVal.value); } return(displayNumber(i,5)); }
// // d o C o n v e r t S G ( ) // function doConvertSG(from, to, theOne, theVal) { var i = 0; var z = 0;
// Convert the FROM to SG (using previous selection type) i = toSG(from, theOne, theVal);
// Convert the SG to the format required by TO if (theOne.options[to].text.indexOf("BRIX") != -1) { // SG -> Brix z = SGToBrix(i); return(displayNumber(z,2)); } if (theOne.options[to].text.indexOf("Baume") != -1) { // SG -> Baue z = SGToBaume(i); return(displayNumber(z,2)); } return(displayNumber(i,3)); }
// // i __ u p d a t e S G ( ) // Mead Batch Util // // Update the SG/BRIX/Baume display value based on the drop down // selection of Gravity Type // function i_updateSG(theOne, theVal) { var i = 0; var j = 0;
i = getSelectedValue(theOne); // New type (to) j = Number(theForm.sg_setting.value); // Old type (from) // Convert from old to new for BOTH select items theForm.currgrav_t.value = doConvertSG(j,i,theForm.currgrav_s,theForm.currgrav_t); theForm.targgrav_t.value = doConvertSG(j,i,theForm.targgrav_s,theForm.targgrav_t); // ensure selection pointer moves together for both Select items theForm.currgrav_s.selectedIndex = i; theForm.targgrav_s.selectedIndex = i; // remember which setting for next time theForm.sg_setting.value = i; // // adjust the type for the Potential Alcohol utility theForm.sgOrigConv_s.selectedIndex = i; i_translateSG(document.util.sgOrigConv_setting); }
// // i __ u p d a t e G r a v ( ) // Mead Batch Utility // // Update the Target Gravity displayed text // function i_updateGrav() { var pa = theForm.targpa_s; var j = Number(theForm.targpa_t.value); // ABV or ABW
if (pa.options[pa.selectedIndex].text.indexOf("ABV") > -1) { // abv is Baume, so converted by BaumeToSG which is ABVToSG theForm.targgrav_t.value = displayNumber(ABVToSG(j),3); } else if (abv.options[pa.selectedIndex].text.indexOf("ABW") > -1) { // ABW -> ABV (Baume) -> SG theForm.targgrav_t.value = displayNumber(ABWToSG(j),3); } }
// // t o V o l ( ) // Mead batch Utility // function toVol(which, theOne, theVal) { // Convert to Metric Litres (Options value is the conversion factor) return(Number(theVal.value) * Number(theOne.options[Number(which)].value)); }
// // i __ u p d a t e V o l ( ) // Mead Batch Utility // // Update the volume display text (theVal.value) // // theOne is the comboBox, theVal is the textBox, theSetting is previous selection for curr or targ volume combo box // function i_updateVol(theOne, theVal, theSetting, theSetVal) { var vTo = 0; var vFrom = 0; var vVol = 0;
// save the full significant figure value for calculations theSetVal.value = Number(theVal.value) * Number(theOne.options[Number(theSetting.value)].value)/Number(theOne.options[Number(theOne.selectedIndex)].value); // display a reduced theVal.value = displayNumber(theSetVal.value,2); theSetting.value = Number(theOne.selectedIndex); // save the new current vol selection dropdown for conversion next time as the previous theSetting }
// // i __ u p d a t e Q u a n t ( ) // Mead Batch Utility // // Update the quantities for Sugars based on "which" group of // sugars is identified // function i_updateQuant(which) { var theOne = theForm.sugars1_s2; var theVal = theForm.sugars1_t2; var i = 0; var j = 0; var k = 0;
if (which == 1) { // first group of Sugars values theOne = theForm.sugars1_s2; theVal = theForm.sugars1_t2;
i = getSelectedValue(theOne); // New quant unit (to) j = Number(theForm.quant_setting1.value); // Old quant (from)
theOne = theForm.sugars1_s2; theVal = theForm.sugars1_t2; // Convert to Pounds (Options value is the conversion factor) k = toVol(j, theOne, theVal); // Can use toVol() // Convert to new unit (Options value is the conversion factor) theVal.value = displayNumber(k / Number(theOne.options[i].value),4); theOne.selectedIndex = i;
// save new setting for next time theForm.quant_setting1.value = i; } else if (which == 2) { // second group of Sugars values theOne = theForm.sugars2_s2; theVal = theForm.sugars2_t2;
i = getSelectedValue(theOne); // New quant unit (to) j = Number(theForm.quant_setting2.value); // Old quant (from)
theOne = theForm.sugars2_s2; theVal = theForm.sugars2_t2; // Convert to Pounds (Options value is the conversion factor) k = toVol(j, theOne, theVal); // Can use toVol() // Convert to new unit (Options value is the conversion factor) theVal.value = displayNumber(k / Number(theOne.options[i].value),4); theOne.selectedIndex = i;
// save new setting for next time theForm.quant_setting2.value = i; } else if (which == 3) { // third group of Sugars values theOne = theForm.sugars3_s2; theVal = theForm.sugars3_t2;
i = getSelectedValue(theOne); // New quant unit (to) j = Number(theForm.quant_setting3.value); // Old quant (from)
theOne = theForm.sugars3_s2; theVal = theForm.sugars3_t2; // Convert to Pounds (Options value is the conversion factor) k = toVol(j, theOne, theVal); // Can use toVol() // Convert to new unit (Options value is the conversion factor) theVal.value = displayNumber(k / Number(theOne.options[i].value),4); theOne.selectedIndex = i;
// save new setting for next time theForm.quant_setting3.value = i; } else if (which == 4) { // fourth group of Sugars values theOne = theForm.sugars4_s2; theVal = theForm.sugars4_t2;
i = getSelectedValue(theOne); // New quant unit (to) j = Number(theForm.quant_setting4.value); // Old quant (from)
theOne = theForm.sugars4_s2; theVal = theForm.sugars4_t2; // Convert to Pounds (Options value is the conversion factor) k = toVol(j, theOne, theVal); // Can use toVol() // Convert to new unit (Options value is the conversion factor) theVal.value = displayNumber(k / Number(theOne.options[i].value),4); theOne.selectedIndex = i;
// save new setting for next time theForm.quant_setting4.value = i; } }
// // i __ u p d a t e T y p e ( ) // Mead Batch Utility // // Updated the Quantity settings based on the Quantity type (kilograms, pounds, ...) // the parameter "which" identifies which of the four "Additional Sugars" needs to be changed // function i_updateType(which) { var theOne = theForm.sugars1_s1; var theVal = theForm.sugars1_t3; var theQVal = theForm.sugars1_t2; var i = 0; var j = 0; var k = 0;
if (which == 1) { // Sugars#1 theOne = theForm.sugars1_s1; // Type selection theVal = theForm.sugars1_t3; // the value to change (the Sugars Content) theQVal = theForm.sugars1_t2; // the quantity to change due to sugars content } else if (which == 2) { // Sugars#2 theOne = theForm.sugars2_s1; theVal = theForm.sugars2_t3; theQVal = theForm.sugars2_t2; } else if (which == 3) { // Sugars#3 theOne = theForm.sugars3_s1; theVal = theForm.sugars3_t3; theQVal = theForm.sugars3_t2; } else if (which == 4) { // Sugars#4 theOne = theForm.sugars4_s1; theVal = theForm.sugars4_t3; theQVal = theForm.sugars4_t2; } i = getSelectedValue(theOne); // New Sug Content (to) j = Number(theVal.value); // Old Sug Content (from)
theVal.value=theOne.options[i].value; // the new sugar content
// scale the quantity back for the old sugar content, then adjust for new sugar content k = Number(theQVal.value) * j / (theOne.options[i].value); theQVal.value = displayNumber(k,3); theForm.type_setting.value = i; }
// // g e t T e m p C o e f f ( ) // function getTempCoeff() { var y = Number(theForm.mustt.value); var z = 0;
if (theForm.mustt_s.selectedIndex == 1) { y = 5*(y-32)/9; // convert to Celsius } z = -0.00469615 + 0.000377273*y - 1.17144E-05*Math.pow(y,2) + 2.29558E-07*Math.pow(y,3); return(Number(displayNumber(z,4))); } // Temp correction for 20C // -0.00469615 + 0.000377273*T - 1.17144E-05*T^2 + 2.29558E-07*T^3 // Temp Correction for 15C (59F) // 1.313454 - 0.132674*T + 2.057793e-3*T**2 - 2.627634e-6*T**3 // modified to 1.2042494.... to zero at 59F
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////// B l e n d U t i l i t y //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// // d o B l e n d ( ) // // Based on which field is blank and which Radio button is selected, calc the blend // // A C // M // B D // ----- // C+D (called vCD below) // function doBlend() { var vA = Number(theForm.blend_val1.value); var vB = Number(theForm.blend_val2.value); var vC = Number(theForm.blend_vol1.value); var vD = Number(theForm.blend_vol2.value); var vM = Number(theForm.blend_res.value); var vCD = Number(theForm.blend_totvol.value);
// ensure blen value is BETWEEN value#1 and value#2 //vM = Math.min(vM,vB); //vM = Math.max(vM,vA); //if ( vM != Number(theForm.blend_res.value) ) { // theForm.blend_res.value = displayNumber(vM,3); //}
// Calc the missing values based on what data and selections have been made if (theForm.blend_r[0].checked) { // Val1 checked - calc Val1 (vA) if ( (vB != "") && (vC != "") && (vD != "") && (vM != "")) { vA = Number(displayNrTrim((vM*vC+vM*vD-vB*vD)/vC,3)); theForm.blend_val1.value = vA; theForm.blend_r[0].checked = false; changeMsg(""); } else { changeMsg("More values rquired!"); } } else if (theForm.blend_r[1].checked) { // Vol1 checked - calc vol1 (vC) if ( (vA != "") && (vB != "") && (vD != "") && (vM != "")) { vC = Number(displayNrTrim(vD*(1-(vB/vM))/((vA/vM)-1),3)); theForm.blend_vol1.value = vC; theForm.blend_r[1].checked = false; changeMsg(""); } else if ( (vA != "") && (vB != "") && (vCD != "") && (vM != "")) { vC = Number(displayNrTrim(vCD*(vB-vM)/(vB-vA),3)); theForm.blend_vol1.value = vC; vD = Number(displayNrTrim(vCD*(vM-vA)/(vB-vA),3)); theForm.blend_vol2.value = vD; theForm.blend_r[1].checked = false; changeMsg(""); } else { changeMsg("Missing a volume"); } } else if (theForm.blend_r[2].checked) { // BlendedValue checked - calc blend (vM) if ( (vA != "") && (vB != "") && (vC != "") && (vD != "")) { vM = Number(displayNrTrim((vA*vC+vB*vD)/(vC+vD),3)); theForm.blend_res.value = vM; theForm.blend_r[2].checked = false; changeMsg(""); } else { changeMsg("More values rquired!"); } } else if (theForm.blend_r[3].checked) { // Val2 checked - calc Val2 (vB) if ( (vA != "") && (vC != "") && (vD != "") && (vM != "")) { vB = Number(displayNrTrim((vM*vC+vM*vD-vA*vC)/vD,3)); theForm.blend_val2.value = vB; theForm.blend_r[3].checked = false; changeMsg(""); } else { changeMsg("More values rquired!"); } } else if (theForm.blend_r[4].checked) { // Vol2 checked - calc vol2 (vD) if ( (vA != "") && (vB != "") && (vC != "") && (vM != "")) { vD = Number(displayNrTrim(vC*((vA/vM)-1)/(1-(vB/vM)),3)); theForm.blend_vol2.value = vD; theForm.blend_r[4].checked = false; changeMsg(""); } else if ( (vA != "") && (vB != "") && (vCD != "") && (vM != "")) { vC = Number(displayNrTrim(vCD*(vB-vM)/(vB-vA),3)); theForm.blend_vol1.value = vC; vD = Number(displayNrTrim(vCD*(vM-vA)/(vB-vA),3)); theForm.blend_vol2.value = vD; theForm.blend_r[4].checked = false; changeMsg(""); } else { changeMsg("Missing a volume"); } } else if (theForm.blend_r[5].checked) { // totvol checked - Calc vol1, vol2 and totvol if ( (vA != "") && (vB != "") && (vM != "")) { if ( (vC != "") && (vD == "") ) { // given vC, calc vD & vCD vD = Number(displayNrTrim(vC*((vA/vM)-1)/(1-(vB/vM)),3)); // same as above theForm.blend_vol2.value = vD; vCD = Number(displayNrTrim(0+vC+vD,3)); theForm.blend_totvol.value = vCD; theForm.blend_r[5].checked = false; changeMsg(''); } else if ( (vC == "") && (vD != "") ) { // given vD, calc vC & vCD vC = Number(displayNrTrim(vD*(1-vB/vM)/(vA/vM-1),3)); // same as above theForm.blend_vol1.value = vC+0; vCD = Number(displayNrTrim(0.0+vC+vD,3)); theForm.blend_totvol.value = vCD+0; theForm.blend_r[5].checked = false; changeMsg(''); } else if ( (vC == "") && (vD == "") && (vCD != "") ) { // given totvol and no vol1 or vol2, calc vC & vD vC = Number(displayNrTrim(vCD*(vB-vM)/(vB-vA),3)); theForm.blend_vol1.value = vC; vD = Number(displayNrTrim(vCD*(vM-vA)/(vB-vA),3)); theForm.blend_vol2.value = vD; theForm.blend_r[5].checked = false; changeMsg(''); } else { changeMsg("Missing a volume"); } } } if ((vCD != (vC+vD)) && (vC > 0) && (vD > 0) ) { vCD = Number(displayNrTrim(vC+vD,3)); theForm.blend_totvol.value = vCD; theForm.blend_r[5].checked = false; changeMsg(''); } return(1); }
// // i __ c h a n g e L a b e l ( ) // // Update the labels on the Blending Calc Utility // function i_changeLabel(which) { var x1 = document.getElementById('b1'); var x2 = document.getElementById('b2'); var x3 = document.getElementById('bres');
switch(which) { case 1: x1.innerHTML = "SG #1"; x2.innerHTML = "SG #2"; x3.innerHTML = "Blended SG"; break; case 2: x1.innerHTML = "BRIX #1"; x2.innerHTML = "BRIX #2"; x3.innerHTML = "Blended BRIX"; break; case 3: x1.innerHTML = "Baume #1"; x2.innerHTML = "Baume #2"; x3.innerHTML = "Blended Baume"; break; case 4: x1.innerHTML = "%ABV #1"; x2.innerHTML = "%ABV #2"; x3.innerHTML = "Blended %ABV"; break; case 5: x1.innerHTML = "%ABW #1"; x2.innerHTML = "%ABW #2"; x3.innerHTML = "Blended %ABW"; break; default: x1.innerHTML = "Value #1"; x2.innerHTML = "Value #2"; x3.innerHTML = "Blended Value"; } return (0); }
// // c h a n g e M s g ( ) // // Update the error message on the Blending Calc Utility // function changeMsg(msg) { var x1 = document.getElementById('blend_msg'); var y = " "; // default to a non-breaking space, so something displayed if (msg != "") { y = msg; } x1.innerHTML = y; return(0); }
// // i __ b l e n d C l e a r ( ) // function i_blendClear() { theForm.blend_val1.value = ''; theForm.blend_val2.value = ''; theForm.blend_res.value = ''; theForm.blend_vol1.value = ''; theForm.blend_vol2.value = ''; theForm.blend_totvol.value = ''; }
You need to enable JavaScript on your browser for the Mead Calculator to work!!
[bsa_pro_ad_space id=1]