Code cleanup and compress.

Thu, 05 Sep 2019 14:43:04 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 05 Sep 2019 14:43:04 +0200
changeset 462
c91175610f8a
parent 461
f147a3962775
child 463
0efdafd23753

Code cleanup and compress.

www/js/global.js file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/global.js	Mon Aug 26 16:29:30 2019 +0200
+++ b/www/js/global.js	Thu Sep 05 14:43:04 2019 +0200
@@ -712,25 +712,14 @@
 
 
 
-$(document).ready(function () {
-
-	$("#jqxMenu").jqxMenu({
-		width: 1280,
-		height: '30px',
-		autoOpen: false,
-		clickToOpen: true,
-		theme: theme
-	});
-	$("#jqxWidget").css('visibility', 'visible');
+$(document).ready(function(){
+$("#jqxMenu").jqxMenu({width:1280,height:'30px',autoOpen:false,clickToOpen:true,theme:theme});
+$("#jqxWidget").css('visibility','visible');
 });
 
 
 
-function Round(n,d) {
-var m, i;
-for (i = 0, m = 1; i < d; i++, m *= 10);
-return Math.round(n * m) / m;
-}
+function Round(n,d){for(var i=0,m=1;i<d;i++,m*=10);return Math.round(n*m)/m;}
 
 
 /*
@@ -769,55 +758,24 @@
 }
 
 
-function ebc_to_srm(ebc) {
-	var srm = -1.32303E-12 * Math.pow(ebc, 4) - 0.00000000291515 * Math.pow(ebc, 3) + 0.00000818515 * Math.pow(ebc, 2) + 0.372038 * ebc + 0.596351;
-	if ((ebc < 0) || (srm < 0))
-		console.log("ebc_to_srm("+ebc+") = "+srm);
-	return srm
+function ebc_to_srm(ebc){
+var srm = -1.32303E-12*Math.pow(ebc,4)-0.00000000291515*Math.pow(ebc,3)+0.00000818515*Math.pow(ebc,2)+0.372038*ebc+0.596351;
+if(srm<0)srm=0;return srm;
 }
-
-
-
-function srm_to_ebc(srm)
-{
-	var ebc = Math.round(0.000000000176506 * Math.pow(srm, 4) + 0.000000154529 * Math.pow(srm, 3) - 0.000159428 * Math.pow(srm, 2) + 2.68837 * srm - 1.6004);
-	if ((ebc < 0) || (srm < 0))
-		console.log("srm_to_ebc("+srm+") = "+ebc);
-	return ebc;
+function srm_to_ebc(srm){
+var ebc=Math.round(0.000000000176506*Math.pow(srm,4)+0.000000154529*Math.pow(srm,3)-0.000159428*Math.pow(srm,2)+2.68837*srm-1.6004);
+if(ebc<0)ebc=0;return ebc;
 }
 
 
 
-/*
- * Return incremented color by the boil and yeast.
- * https://www.hobbybrouwen.nl/forum/index.php/topic,19020.msg281132.html#msg281132
- */
-function get_kt(ebc) {
-
-	var kt = 1;
-	if (ebc < 3)
-		kt = 3.5;
-	else if (ebc < 6)
-		kt = 3;
-	else if (ebc < 8)
-		kt = 2.75;
-	else if (ebc < 10)
-		kt = 2.5;
-	else if (ebc < 20)
-		kt = 1.8;
-	else if (ebc < 30)
-		kt = 1.6;
-	else if (ebc < 60)
-		kt = 1.3;
-	else if (ebc < 100)
-		kt = 1.2;
-	else if (ebc < 300)
-		kt = 1.1;
-	return kt;
+/* Return incremented color by the boil and yeast.
+ * https://www.hobbybrouwen.nl/forum/index.php/topic,19020.msg281132.html#msg281132 */
+function get_kt(ebc){
+var kt=1;
+if(ebc<3)kt=3.5;else if(ebc<6)kt=3;else if(ebc<8)kt=2.75;else if(ebc<10)kt=2.5;else if(ebc<20)kt=1.8;
+else if(ebc<30)kt=1.6;else if(ebc<60)kt=1.3;else if(ebc<100)kt=1.2;else if(ebc<300)kt=1.1;return kt;
 }
-
-
-
 function abvol(og,fg){
 if(((og-fg)<0)||(fg<0.9))return 0;
 var factor=og*3157*Math.pow(10,-5)+9.716*Math.pow(10,-2);
@@ -826,10 +784,8 @@
 
 
 
-/*
- * Kleurwerking naar SRM. Niet voor Halberstadt, Naudts
- */
-function kw_to_srm(colormethod, c) {
+/* Kleurwerking naar SRM. Niet voor Halberstadt, Naudts */
+function kw_to_srm(colormethod,c){
 if(colormethod==0)return 1.4922*Math.pow(c,0.6859);//Morey
 if(colormethod==1)return 0.3*c+4.7;//Mosher
 if(colormethod==2)return 0.2*c+8.4;//Daniels
@@ -842,8 +798,7 @@
 /*
  * Berekeningen uit https://www.hobbybrouwen.nl/forum/index.php/topic,6079.msg69464.html#msg69464
  */
-function toIBU(Use, Form, SG, Volume, Amount, Boiltime, Alpha, Method)
-{
+function toIBU(Use,Form,SG,Volume,Amount,Boiltime,Alpha,Method){
 var gravity=parseFloat(SG);
 var liters=parseFloat(Volume);
 var alpha=parseFloat(Alpha)/100;
@@ -874,40 +829,39 @@
 pfactor+=my_factor_cryohop/100;
 }
 
-	if(Method==0){// Tinseth
-		/* http://realbeer.com/hops/research.html */
-		var AddedAlphaAcids = (alpha * mass * 1000) / liters;
-		var Bigness_factor = 1.65 * Math.pow( 0.000125, gravity - 1);
-		var BoilTime_factor = ((1 - Math.exp(-0.04 * time)) / 4.15);
-		var utiisation = Bigness_factor * BoilTime_factor;
-		ibu = Round(utiisation * AddedAlphaAcids * fmoment * pfactor,1);
-	}
-	if(Method==2){// Daniels
-		var boilfactor;
-		var sgfactor;
-		if (Form==2)// Leaf
-			boilfactor = -(0.0041*time*time)+(0.6162*time)+1.5779;
-		else
-			boilfactor = -(0.0051*time*time)+(0.7835*time)+1.9348;
-		if (gravity<1050)
-			sgfactor=0;
-		else
-			sgfactor=(gravity-1050)/200;
-		ibu = Round(fmoment*((mass*(alpha*100)*boilfactor* 0.1)/(liters*(1+sgfactor))),1);
-	}
-	if(Method==1){// Rager
-		var boilfactor;
-		var sgfactor;
-		boilfactor = fmoment*18.11+13.86*Math.tanh((time*31.32)/18.27);
-		if (gravity<1050)
-			sgfactor=0;
-		else
-			sgfactor=(gravity-1050)/200;
-		ibu = Round((mass*(alpha*100)*boilfactor*0.1)/(liters*(1+sgfactor)),1);
-	}
+if(Method==0){// Tinseth
+/* http://realbeer.com/hops/research.html */
+var AddedAlphaAcids=(alpha*mass*1000)/liters;
+var Bigness_factor=1.65*Math.pow(0.000125,gravity-1);
+var BoilTime_factor=((1-Math.exp(-0.04*time))/4.15);
+var utiisation=Bigness_factor*BoilTime_factor;
+ibu=Round(utiisation*AddedAlphaAcids*fmoment*pfactor,1);
+}
+if(Method==2){// Daniels
+var boilfactor;
+var sgfactor;
+if(Form==2)// Leaf
+boilfactor=-(0.0041*time*time)+(0.6162*time)+1.5779;
+else
+boilfactor=-(0.0051*time*time)+(0.7835*time)+1.9348;
+if(gravity<1050)
+sgfactor=0;
+else
+sgfactor=(gravity-1050)/200;
+ibu = Round(fmoment*((mass*(alpha*100)*boilfactor* 0.1)/(liters*(1+sgfactor))),1);
+}
+if(Method==1){// Rager
+var sgfactor;
+var boilfactor=fmoment*18.11+13.86*Math.tanh((time*31.32)/18.27);
+if(gravity<1050)
+sgfactor=0;
+else
+sgfactor=(gravity-1050)/200;
+ibu = Round((mass*(alpha*100)*boilfactor*0.1)/(liters*(1+sgfactor)),1);
+}
 
-	//console.log("toIBU("+Use+","+Form+","+SG+","+Volume+","+Amount+","+Boiltime+","+Alpha+","+Method+"):"+ibu+" fm:"+fmoment+" pf:"+pfactor);
-	return ibu;
+//console.log("toIBU("+Use+","+Form+","+SG+","+Volume+","+Amount+","+Boiltime+","+Alpha+","+Method+"):"+ibu+" fm:"+fmoment+" pf:"+pfactor);
+return ibu;
 }
 
 
@@ -915,61 +869,60 @@
 function ebc_to_color(ebc){return srm_to_color(ebc_to_srm(ebc));}
 function srm_to_color(srm){
 var i = Math.round(srm * 10);
-if(i<0){
-i=0;
-}
-if(i>299){
-i=299;
-}
+if(i<0)i=0;
+if(i>299)i=299;
 
-	/* Table copied from Brouwhulp/BrewBuddy */
-	var R = [ 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, // 0
-		  250, 250, 250, 250, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, // 2
-		  234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, // 4
-		  214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 200, 199, 199, 198, 198, // 6
-		  197, 197, 196, 196, 195, 195, 194, 194, 193, 193, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, // 8
-		  192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, // 10
-		  192, 192, 192, 192, 192, 192, 192, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, // 12
-		  179, 178, 177, 175, 174, 172, 171, 169, 168, 167, 195, 164, 162, 161, 159, 158, 157, 155, 154, 152, // 14
-		  151, 149, 148, 147, 145, 144, 142, 141, 139, 138, 137, 135, 134, 132, 131, 129, 128, 127, 125, 124, // 16
-		  122, 121, 119, 118, 117, 115, 114, 112, 111, 109, 108, 107, 105, 104, 102, 101,  99,  98,  97,  95, // 18
-		   94,  92,  91,  89,  88,  87,  85,  84,  82,  81,  79,  78,  77,  75,  74,  72,  71,  69,  68,  67, // 20
-		   65,  64,  62,  61,  59,  58,  57,  55,  54,  52,  51,  49,  48,  47,  45,  44,  43,  41,  39,  38, // 22
-		   37,  37,  36,  36,  35,  35,  34,  34,  33,  33,  32,  32,  31,  31,  30,  30,  29,  29,  28,  28, // 24
-		   27,  27,  26,  26,  25,  25,  24,  24,  23,  23,  22,  22,  21,  21,  20,  20,  19,  19,  18,  18, // 26
-		   17,  17,  16,  16,  15,  15,  14,  14,  13,  13,  12,  12,  11,  11,  10,  10,   9,   9,   8,   8 ];
+/* Table copied from Brouwhulp/BrewBuddy */
+var R=[
+250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,//0
+250,250,250,250,250,249,248,247,246,245,244,243,242,241,240,239,238,237,236,235,//2
+234,233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,218,217,216,215,//4
+214,213,212,211,210,209,208,207,206,205,204,203,202,201,200,200,199,199,198,198,//6
+197,197,196,196,195,195,194,194,193,193,192,192,192,192,192,192,192,192,192,192,//8
+192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,//10
+192,192,192,192,192,192,192,192,191,190,189,188,187,186,185,184,183,182,181,180,//12
+179,178,177,175,174,172,171,169,168,167,195,164,162,161,159,158,157,155,154,152,//14
+151,149,148,147,145,144,142,141,139,138,137,135,134,132,131,129,128,127,125,124,//16
+122,121,119,118,117,115,114,112,111,109,108,107,105,104,102,101, 99, 98, 97, 95,//18
+ 94, 92, 91, 89, 88, 87, 85, 84, 82, 81, 79, 78, 77, 75, 74, 72, 71, 69, 68, 67,//20
+ 65, 64, 62, 61, 59, 58, 57, 55, 54, 52, 51, 49, 48, 47, 45, 44, 43, 41, 39, 38,//22
+ 37, 37, 36, 36, 35, 35, 34, 34, 33, 33, 32, 32, 31, 31, 30, 30, 29, 29, 28, 28,//24
+ 27, 27, 26, 26, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18,//26
+ 17, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10,  9,  9,  8,  8];
 
-	var G = [ 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
-		  250, 250, 250, 250, 250, 250, 249, 248, 247, 246, 245, 244, 242, 240, 238, 236, 234, 232, 230, 228,
-		  226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188,
-		  186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148,
-		  146, 144, 142, 141, 140, 139, 139, 138, 137, 136, 136, 135, 134, 133, 133, 132, 131, 130, 130, 129,
-		  128, 127, 127, 126, 125, 124, 124, 123, 122, 121, 121, 120, 119, 118, 118, 117, 116, 115, 115, 114,
-		  113, 112, 112, 111, 110, 109, 109, 108, 107, 106, 106, 105, 104, 103, 103, 102, 101, 100, 100,  99,
-		   98,  97,  97,  96,  95,  94,  94,  93,  92,  91,  91,  90,  89,  88,  88,  87,  86,  85,  85,  84,
-		   83,  82,  82,  81,  80,  79,  78,  77,  76,  75,  75,  74,  73,  72,  72,  71,  70,  69,  69,  68,
-		   67,  66,  66,  65,  64,  63,  63,  62,  61,  60,  60,  59,  58,  57,  57,  56,  55,  54,  54,  53,
-		   52,  51,  51,  50,  49,  48,  48,  47,  46,  45,  45,  44,  43,  42,  42,  41,  40,  39,  39,  38,
-		   37,  36,  36,  35,  34,  33,  33,  32,  31,  30,  30,  29,  28,  27,  27,  26,  25,  24,  24,  23,
-		   22,  22,  22,  21,  21,  21,  20,  20,  20,  19,  19,  19,  18,  18,  18,  17,  17,  17,  16,  16,
-		   16,  15,  15,  15,  14,  14,  14,  13,  13,  13,  12,  12,  12,  11,  11,  11,  10,  10,  10,   9,
-		    9,   9,   8,   8,   8,   7,   7,   7,   6,   6,   6,   5,   5,   5,   4,   4,   4,   3,   3,   3 ];
+var G=[
+250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
+250,250,250,250,250,250,249,248,247,246,245,244,242,240,238,236,234,232,230,228,
+226,224,222,220,218,216,214,212,210,208,206,204,202,200,198,196,194,192,190,188,
+186,184,182,180,178,176,174,172,170,168,166,164,162,160,158,156,154,152,150,148,
+146,144,142,141,140,139,139,138,137,136,136,135,134,133,133,132,131,130,130,129,
+128,127,127,126,125,124,124,123,122,121,121,120,119,118,118,117,116,115,115,114,
+113,112,112,111,110,109,109,108,107,106,106,105,104,103,103,102,101,100,100, 99,
+ 98, 97, 97, 96, 95, 94, 94, 93, 92, 91, 91, 90, 89, 88, 88, 87, 86, 85, 85, 84,
+ 83, 82, 82, 81, 80, 79, 78, 77, 76, 75, 75, 74, 73, 72, 72, 71, 70, 69, 69, 68,
+ 67, 66, 66, 65, 64, 63, 63, 62, 61, 60, 60, 59, 58, 57, 57, 56, 55, 54, 54, 53,
+ 52, 51, 51, 50, 49, 48, 48, 47, 46, 45, 45, 44, 43, 42, 42, 41, 40, 39, 39, 38,
+ 37, 36, 36, 35, 34, 33, 33, 32, 31, 30, 30, 29, 28, 27, 27, 26, 25, 24, 24, 23,
+ 22, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 16, 16,
+ 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10,  9,
+  9,  9,  8,  8,  8,  7,  7,  7,  6,  6,  6,  5,  5,  5,  4,  4,  4,  3,  3,  3];
 
-	var B = [ 210, 204, 199, 193, 188, 182, 177, 171, 166, 160, 155, 149, 144, 138, 133, 127, 122, 116, 111, 105,
-		  100,  94,  89,  83,  78,  72,  67,  61,  56,  50,  45,  45,  45,  46,  46,  46,  46,  47,  47,  47,
-		   47,  48,  48,  48,  48,  49,  49,  49,  49,  50,  50,  50,  50,  51,  51,  51,  51,  52,  52,  52,
-		   52,  53,  53,  53,  53,  54,  54,  54,  54,  55,  55,  55,  55,  56,  56,  56,  56,  56,  56,  56,
-		   56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,
-		   56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,
-		   56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,  56,
-		   56,  56,  56,  55,  55,  55,  55,  54,  54,  54,  54,  53,  53,  53,  53,  52,  52,  52,  52,  51,
-		   51,  51,  51,  50,  50,  50,  50,  49,  49,  48,  47,  47,  46,  45,  45,  44,  43,  43,  42,  41,
-		   41,  40,  39,  39,  38,  37,  37,  36,  35,  34,  33,  32,  31,  29,  28,  27,  26,  25,  24,  23,
-		   21,  20,  19,  18,  17,  16,  15,  13,  12,  11,  10,   9,   8,   9,   9,  10,  10,  11,  11,  12,
-		   12,  13,  13,  14,  14,  15,  15,  16,  16,  17,  17,  18,  18,  19,  19,  20,  20,  21,  21,  22,
-		   21,  21,  21,  20,  20,  20,  19,  19,  19,  18,  18,  18,  17,  17,  17,  17,  16,  16,  15,  15,
-		   15,  14,  14,  14,  13,  13,  13,  12,  12,  12,  11,  11,  11,  10,  10,  10,   9,   9,   9,   8,
-		    8,   8,   7,   7,   7,   6,   6,   6,   5,   5,   5,   4,   4,   4,   3,   3,   3,   2,   2,   2 ];
+var B=[
+210,204,199,193,188,182,177,171,166,160,155,149,144,138,133,127,122,116,111,105,
+100, 94, 89, 83, 78, 72, 67, 61, 56, 50, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47,
+ 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52,
+ 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 56, 55, 55, 55, 55, 54, 54, 54, 54, 53, 53, 53, 53, 52, 52, 52, 52, 51,
+ 51, 51, 51, 50, 50, 50, 50, 49, 49, 48, 47, 47, 46, 45, 45, 44, 43, 43, 42, 41,
+ 41, 40, 39, 39, 38, 37, 37, 36, 35, 34, 33, 32, 31, 29, 28, 27, 26, 25, 24, 23,
+ 21, 20, 19, 18, 17, 16, 15, 13, 12, 11, 10,  9,  8,  9,  9, 10, 10, 11, 11, 12,
+ 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22,
+ 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 17, 16, 16, 15, 15,
+ 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10,  9,  9,  9,  8,
+  8,  8,  7,  7,  7,  6,  6,  6,  5,  5,  5,  4,  4,  4,  3,  3,  3,  2,  2,  2];
 
 var color=R[i]*65536+G[i]*256+B[i];
 var result=color.toString(16).toUpperCase();
--- a/www/js/prod_edit.js	Mon Aug 26 16:29:30 2019 +0200
+++ b/www/js/prod_edit.js	Thu Sep 05 14:43:04 2019 +0200
@@ -1764,41 +1764,33 @@
 	}
 
 function calcFermentation(){
-	if(dataRecord.brew_fermenter_sg<1.020)return;
-	var obrix=sg_to_brix(dataRecord.brew_fermenter_sg);
-	if ((dataRecord.primary_end_sg>0.990)&&(dataRecord.primary_end_sg<dataRecord.brew_fermenter_sg)){
-		var primary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.primary_end_sg)/(dataRecord.brew_fermenter_sg-1),1);
-		$("#primary_svg").val(primary_svg);
-		if((dataRecord.secondary_end_sg>0.990)&&(dataRecord.secondary_end_sg<dataRecord.brew_fermenter_sg)){
-			var secondary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.secondary_end_sg)/(dataRecord.brew_fermenter_sg-1),1);
-			$("#secondary_svg").val(secondary_svg);
-			if((dataRecord.fg>0.990)&&(dataRecord.fg<dataRecord.brew_fermenter_sg)){
-				var final_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.fg)/(dataRecord.brew_fermenter_sg-1),1);
-				$("#final_svg").val(final_svg);
-				var ABV=Round(abvol(dataRecord.brew_fermenter_sg,dataRecord.fg),2);
-				$("#final_abv").val(ABV);
-			}
-		}
-	}
+if(dataRecord.brew_fermenter_sg<1.020)return;
+var obrix=sg_to_brix(dataRecord.brew_fermenter_sg);
+if((dataRecord.primary_end_sg>0.990)&&(dataRecord.primary_end_sg<dataRecord.brew_fermenter_sg)){
+var primary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.primary_end_sg)/(dataRecord.brew_fermenter_sg-1),1);
+$("#primary_svg").val(primary_svg);
+if((dataRecord.secondary_end_sg>0.990)&&(dataRecord.secondary_end_sg<dataRecord.brew_fermenter_sg)){
+var secondary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.secondary_end_sg)/(dataRecord.brew_fermenter_sg-1),1);
+$("#secondary_svg").val(secondary_svg);
+if((dataRecord.fg>0.990)&&(dataRecord.fg<dataRecord.brew_fermenter_sg)){
+var final_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.fg)/(dataRecord.brew_fermenter_sg-1),1);
+$("#final_svg").val(final_svg);
+var ABV=Round(abvol(dataRecord.brew_fermenter_sg,dataRecord.fg),2);
+$("#final_abv").val(ABV);}}}
 }
 
-	function ResCO2(CO2, T) {
-		//var resco2 = 0.000849151 * T * T - 0.0587512 * T + 1.71137; // brouwhulp
-		var F = T * 1.8 + 32;
-                var resco2 = 3.0378 - 0.050062 * F + 0.00026555 * F * F; // most of the rest
-                //console.log("CO2: "+resco2);
-		return resco2;
-	}
-
-	function CarbCO2toS(CO2, T, SFactor) {
-		var sugar = SFactor * (CO2 - ResCO2(CO2, T)) / 0.286;
-		if (sugar < 0)
-			sugar = 0;
-		return Math.round(sugar * 1000) / 1000;
-	}
+function ResCO2(CO2,T){
+var F=T*1.8+32;
+return 3.0378-0.050062*F+0.00026555*F*F;
+}
+
+function CarbCO2toS(CO2,T,SFactor){
+var sugar=SFactor*(CO2-ResCO2(CO2,T))/0.286;
+if(sugar<0)sugar=0;
+return Round(sugar,3);
+}
 
 	function GetPressure(CO2, T1, T2) {
-		var F = T2 * 1.8 + 32;
   		var V = CO2 - ResCO2(CO2, T1);
 		if (V < 0)
 			return 0;
@@ -1808,106 +1800,91 @@
 		if (P < 0)
 			P = 0;
 		P = P * 1.01325; // atm to bar
-		P = Math.round(P * 10) / 10;
-		return P;
-	}
-
-	function CarbCO2ToPressure(CO2, T) {
-		return (CO2 - (-0.000005594056 * Math.pow(T, 4) + 0.000144357886 * Math.pow(T, 3) +
-				0.000362999168 * T * T - 0.064872987645 * T + 1.641145175049)) /
-			        (0.00000498031 * Math.pow(T, 4) - 0.00024358267 * Math.pow(T, 3) +
-				0.00385867329 * T * T - 0.05671206825 * T + 1.53801423376);
+		return Round(P,1);
 	}
 
-	function calcCarbonation() {
-
-		var TSec = dataRecord.secondary_temp;	// End fermentation temperature.
-		if (TSec < 1)
-			TSec = dataRecord.primary_end_temp;	// Fallback
-		if (TSec < 1)
-			TSec = 18;	// Fallback to room temperature.
-
-		if (dataRecord.fg == 0.000)
-			var ABV = abvol(dataRecord.brew_fermenter_sg, parseFloat($("#est_fg").jqxNumberInput('decimal')));
-		else
-			var ABV = abvol(dataRecord.brew_fermenter_sg, dataRecord.fg);
-
-		/*
-		 * Calculate new volume and alcohol.
-		 */
-		var bvol = dataRecord.package_volume - (ABV * dataRecord.package_volume) / 100;
-		var balc = dataRecord.package_volume - bvol;
-		var mvol = dataRecord.package_infuse_amount - (dataRecord.package_infuse_abv * dataRecord.package_infuse_amount) / 100;
-		var malc = dataRecord.package_infuse_amount - mvol;
-		var talc = balc + malc;
-		var tvol = bvol + mvol;
-		ABV = Math.round(talc / (tvol + talc) * 10000) / 100;
-		//console.log("bvol:"+bvol+" balc:"+balc+" mvol:"+mvol+" malc:"+malc+" tvol:"+tvol+" talc:"+talc+" abv:"+ABV+" vol:"+(tvol + talc));
-		dataRecord.package_abv = ABV;
-		$("#package_abv").val(ABV);
-
-		console.log("calcCarbonation() TSec:"+TSec+"  ABV:"+ABV);
-		if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) {
-			return;	// grid not yet loaded.
-		}
-
-		// Bottles
-		dataRecord.bottle_priming_amount = 0;
-		dataRecord.bottle_priming_total = 0;
-		for (var i = 0; i < rows.length; i++) {
-			var row = rows[i];
-			if (row.f_added == 4) {
-				var SFactor = 1 / ((row.f_yield / 100) * (1 - row.f_moisture / 100));
-				dataRecord.bottle_priming_amount = CarbCO2toS(dataRecord.bottle_carbonation, TSec, SFactor);
-				dataRecord.bottle_priming_total = Math.round(dataRecord.bottle_amount * dataRecord.bottle_priming_amount * 100) / 100;
-				$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', dataRecord.bottle_priming_total / 1000);
-			}
-		}
-		$("#bottle_priming_amount").val(Math.round(dataRecord.bottle_priming_amount * 10) / 10);
-                $("#bottle_priming_total").val(dataRecord.bottle_priming_total);
-		var pabv = ABV + dataRecord.bottle_priming_amount * 0.47 / 7.907;
-		var pvol = dataRecord.bottle_amount - (pabv * dataRecord.bottle_amount) / 100;
-		var talc = dataRecord.bottle_amount - pvol;
-                var tvol = pvol + dataRecord.bottle_priming_water;
-                var babv = Math.round(talc / (tvol + talc) * 10000) / 100;
-		//console.log("bottle pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.bottle_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+babv);
-                $("#bottle_abv").val(babv);
-		$("#bottle_pressure").val(GetPressure(dataRecord.bottle_carbonation, TSec, dataRecord.bottle_carbonation_temp));
-
-		// Kegs
-		var Pressure = CarbCO2ToPressure(dataRecord.keg_carbonation, dataRecord.keg_carbonation_temp);
-		if (Pressure < 0)
-			Pressure = 0;
-		dataRecord.keg_pressure = Pressure;
-		$("#keg_pressure").val(Math.round(Pressure * 10) / 10);
-
-		dataRecord.keg_priming_amount = 0;
-		dataRecord.keg_priming_total = 0;
-		if (! dataRecord.keg_forced_carb) {
-			for (var i = 0; i < rows.length; i++) {
-				var row = rows[i];
-				if (row.f_added == 5) {
-					var SFactor = 1 / ((row.f_yield / 100) * (1 - row.f_moisture / 100));
-                			dataRecord.keg_priming_amount = CarbCO2toS(dataRecord.keg_carbonation, TSec, SFactor);
-					dataRecord.keg_priming_total = Math.round(dataRecord.keg_amount * dataRecord.keg_priming_amount * 100) / 100;
-					$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', dataRecord.keg_priming_total / 1000);
-				}
-			}
-			$("#keg_priming_amount").val(Math.round(dataRecord.keg_priming_amount * 10) / 10);
-			$("#keg_priming_total").val(dataRecord.keg_priming_total);
-			var pabv = ABV + dataRecord.keg_priming_amount * 0.47 / 7.907;
-			var pvol = dataRecord.keg_amount - (pabv * dataRecord.keg_amount) / 100;
-			var talc = dataRecord.keg_amount - pvol;
-			var tvol = pvol + dataRecord.keg_priming_water;
-			var kabv = Math.round(talc / (tvol + talc) * 10000) / 100;
-			//console.log("kegs  pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.keg_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+kabv);
-			$("#keg_abv").val(kabv);
-		} else {
-			$("#keg_priming_amount").val(0);
-			$("#keg_priming_total").val(0);
-			$("#keg_abv").val(ABV);
-		}
-	}
+function CarbCO2ToPressure(CO2, T) {
+return (CO2-(-0.000005594056*Math.pow(T,4)+0.000144357886*Math.pow(T,3)+0.000362999168*T*T-0.064872987645*T+1.641145175049)) /
+ (0.00000498031*Math.pow(T,4)-0.00024358267*Math.pow(T,3)+0.00385867329*T*T-0.05671206825*T+1.53801423376);
+}
+
+function calcCarbonation() {
+var TSec=dataRecord.secondary_temp;
+if(TSec<1)TSec=dataRecord.primary_end_temp;
+if(TSec<1)TSec=18;
+if(dataRecord.fg==0.000)
+var ABV=abvol(dataRecord.brew_fermenter_sg,parseFloat($("#est_fg").jqxNumberInput('decimal')));
+else
+var ABV=abvol(dataRecord.brew_fermenter_sg,dataRecord.fg);
+/* Calculate new volume and alcohol. */
+var bvol=dataRecord.package_volume-(ABV*dataRecord.package_volume)/100;
+var balc=dataRecord.package_volume-bvol;
+var mvol=dataRecord.package_infuse_amount-(dataRecord.package_infuse_abv*dataRecord.package_infuse_amount)/100;
+var malc=dataRecord.package_infuse_amount-mvol;
+var talc=balc+malc;
+var tvol=bvol+mvol;
+ABV = Round(talc/(tvol+talc)*100,2);
+dataRecord.package_abv=ABV;
+$("#package_abv").val(ABV);
+
+//		console.log("calcCarbonation() TSec:"+TSec+"  ABV:"+ABV);
+if(!(rows = $('#fermentableGrid').jqxGrid('getrows'))){return;}
+
+// Bottles
+dataRecord.bottle_priming_amount=0;
+dataRecord.bottle_priming_total=0;
+for (var i=0;i<rows.length;i++){
+var row=rows[i];
+if(row.f_added==4){
+var SFactor=1/((row.f_yield/100)*(1-row.f_moisture/100));
+dataRecord.bottle_priming_amount=CarbCO2toS(dataRecord.bottle_carbonation,TSec,SFactor);
+dataRecord.bottle_priming_total=Round(dataRecord.bottle_amount*dataRecord.bottle_priming_amount,2);
+$("#fermentableGrid").jqxGrid('setcellvalue',i,'f_amount',dataRecord.bottle_priming_total/1000);
+}}
+$("#bottle_priming_amount").val(Round(dataRecord.bottle_priming_amount,1));
+$("#bottle_priming_total").val(dataRecord.bottle_priming_total);
+var pabv=ABV+dataRecord.bottle_priming_amount*0.47/7.907;
+var pvol=dataRecord.bottle_amount-(pabv*dataRecord.bottle_amount)/100;
+var talc=dataRecord.bottle_amount-pvol;
+var tvol=pvol+dataRecord.bottle_priming_water;
+var babv = Round(talc/(tvol+talc)*100,2);
+//console.log("bottle pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.bottle_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+babv);
+$("#bottle_abv").val(babv);
+$("#bottle_pressure").val(GetPressure(dataRecord.bottle_carbonation,TSec,dataRecord.bottle_carbonation_temp));
+
+// Kegs
+var Pressure=CarbCO2ToPressure(dataRecord.keg_carbonation,dataRecord.keg_carbonation_temp);
+if(Pressure<0)Pressure=0;
+dataRecord.keg_pressure=Pressure;
+$("#keg_pressure").val(Round(Pressure,1));
+
+dataRecord.keg_priming_amount=0;
+dataRecord.keg_priming_total=0;
+if(!dataRecord.keg_forced_carb){
+for(var i=0;i<rows.length;i++){
+var row=rows[i];
+if(row.f_added==5){
+var SFactor=1/((row.f_yield/100)*(1-row.f_moisture/100));
+dataRecord.keg_priming_amount=CarbCO2toS(dataRecord.keg_carbonation,TSec,SFactor);
+dataRecord.keg_priming_total=Round(dataRecord.keg_amount*dataRecord.keg_priming_amount,2);
+$("#fermentableGrid").jqxGrid('setcellvalue',i,'f_amount',dataRecord.keg_priming_total/1000);
+}
+}
+$("#keg_priming_amount").val(Round(dataRecord.keg_priming_amount,1));
+$("#keg_priming_total").val(dataRecord.keg_priming_total);
+var pabv=ABV+dataRecord.keg_priming_amount*0.47/7.907;
+var pvol=dataRecord.keg_amount-(pabv*dataRecord.keg_amount)/100;
+var talc=dataRecord.keg_amount-pvol;
+var tvol=pvol+dataRecord.keg_priming_water;
+var kabv=Round(talc/(tvol+talc)*100,2);
+//console.log("kegs  pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.keg_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+kabv);
+$("#keg_abv").val(kabv);
+} else {
+$("#keg_priming_amount").val(0);
+$("#keg_priming_total").val(0);
+$("#keg_abv").val(ABV);
+}
+}
 
 	function calcStage() {
 
@@ -5811,7 +5788,7 @@
 	$("#est_fg3").jqxNumberInput( Show3dec );
 	$("#final_brix").jqxTooltip({ content: 'Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer.' });
 	$("#final_brix").jqxNumberInput( Spin1dec );
-	$("#final_abv").jqxNumberInput( Show1dec );
+	$("#final_abv").jqxNumberInput( Show2dec );
 	$("#final_svg").jqxNumberInput( Show1dec );
 	$("#FLog").jqxButton({ template: "info", width: '150px', theme: theme });
 	$("#FLog").click(function () {
@@ -5834,7 +5811,7 @@
 	$('#package_infuse_notes').jqxTooltip({ content: 'Omschrijving van de extra toevoeging.' });
 	$('#package_infuse_notes').jqxInput({ theme: theme, width: 640, height: 23 });
 	$('#package_abv').jqxTooltip({ content: 'De uiteindelijke hoeveelheid alcohol volume %.' });
-	$('#package_abv').jqxNumberInput( Show1dec );
+	$('#package_abv').jqxNumberInput( Show2dec );
 	$('#package_ph').jqxTooltip({ content: 'De gemeten pH vlak voor het verpakken.' });
         $('#package_ph').jqxNumberInput( SpinpH );
 	$("#st_carb_min2").jqxTooltip({ content: 'Het minimum aanbevolen koolzuur volume voor deze bierstijl.'});
@@ -5971,8 +5948,8 @@
 	$("#keg_priming_total").jqxNumberInput( Show1dec );
 	$("#keg_forced_carb").jqxCheckBox({ theme: theme, width: 120, height: 23 });
 	$("#keg_pressure").jqxNumberInput( Show1dec );
-	$("#bottle_abv").jqxNumberInput( Show1dec );
-	$("#keg_abv").jqxNumberInput( Show1dec );
+	$("#bottle_abv").jqxNumberInput( Show2dec );
+	$("#keg_abv").jqxNumberInput( Show2dec );
 	$("#bottle_carbonation_temp").jqxNumberInput( YeastT );
 	$("#keg_carbonation_temp").jqxNumberInput( YeastT );
 

mercurial