Code check and cleanup using gjslint

Mon, 09 Sep 2019 20:03:50 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 09 Sep 2019 20:03:50 +0200
changeset 474
7b7df475e67d
parent 473
5c7566f6d42a
child 475
c34d71572023

Code check and cleanup using gjslint

www/js/rec_edit-min.js file | annotate | diff | comparison | revisions
www/js/rec_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/rec_edit-min.js	Sat Sep 07 20:27:06 2019 +0200
+++ b/www/js/rec_edit-min.js	Mon Sep 09 20:03:50 2019 +0200
@@ -1,1 +1,1 @@
-function createDelElements(){$("#eventWindow").jqxWindow({theme:theme,position:{x:490,y:210},width:300,height:175,resizable:false,isModal:true,modalOpacity:0.4,okButton:$("#delOk"),cancelButton:$("#delCancel"),initContent:function(){$("#delOk").jqxButton({template:"danger",width:"65px",theme:theme});$("#delCancel").jqxButton({template:"success",width:"65px",theme:theme});$("#delCancel").focus()}});$("#eventWindow").jqxWindow("hide")}$(document).ready(function(){var k=false;var S=0;var A=0;var L=0;var ah=77;var V=0;var aA=0;var J=0;var w=0;var ax="";var O="";var v=40.048;var W=24.305;var M=22.98976928;var o=35.453;var al=96.0626;var E=60.01684;var p=61.01684;var U=172.171;var H=147.015;var g=100.087;var an=246.475;var aj=84.007;var t=105.996;var c=58.443;var am=74.06268;var r=0;var ao={};var b=0;var e={};var ab=0;var ak={};var ai=0;var f={};var R=0;var y={};$("#jqxMenu").jqxMenu("destroy");console.log("record:"+my_record+"  return:"+my_return+"  theme:"+theme);$("#jqxLoader").jqxLoader({width:250,height:150,isModal:true,text:"Laden recept ...",theme:theme});function a(aE){var aF=!aE;var aC=110;var aD=80;if(aE){aC=90;aD=60}$("#batch_size").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#boil_size").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#boil_time").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#efficiency").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#est_og").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#type").jqxDropDownList({disabled:aE});$("#styleSelect").jqxDropDownList({disabled:aE});$("#color_method").jqxDropDownList({disabled:aE});$("#ibu_method").jqxDropDownList({disabled:aE});$("#Delete").jqxButton({disabled:aE});$("#fermentableGrid").jqxGrid({editable:aF});$("#faddrowbutton").jqxDropDownList({disabled:aE});$("#finstockbutton").jqxCheckBox({disabled:aE});$("#fdeleterowbutton").jqxButton({disabled:aE});$("#hopGrid").jqxGrid({editable:aF});$("#haddrowbutton").jqxDropDownList({disabled:aE});$("#hinstockbutton").jqxCheckBox({disabled:aE});$("#hdeleterowbutton").jqxButton({disabled:aE});$("#miscGrid").jqxGrid({editable:aF});$("#maddrowbutton").jqxDropDownList({disabled:aE});$("#minstockbutton").jqxCheckBox({disabled:aE});$("#mdeleterowbutton").jqxButton({disabled:aE});$("#yeastGrid").jqxGrid({editable:aF});$("#yaddrowbutton").jqxDropDownList({disabled:aE});$("#yinstockbutton").jqxCheckBox({disabled:aE});$("#ydeleterowbutton").jqxButton({disabled:aE});$("#mashGrid").jqxGrid({editable:aF});$("#saddrowbutton").jqxButton({disabled:aE});$("#sdeleterowbutton").jqxButton({disabled:aE});$("#w1_name").jqxDropDownList({disabled:aE});$("#w2_name").jqxDropDownList({disabled:aE});$("#pr_name").jqxDropDownList({disabled:aE});$("#wa_cacl2").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#wa_caso4").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#wa_mgso4").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#wa_nacl").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#mash_ph").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#calc_acid").jqxCheckBox({disabled:aE});$("#wa_base_name").jqxDropDownList({disabled:aE});$("#wa_base").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#wa_acid_name").jqxDropDownList({disabled:aE});$("#wa_acid").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#wa_acid_perc").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aD});$("#sparge_temp").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#sparge_volume").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#sparge_ph").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC});$("#sparge_source").jqxDropDownList({disabled:aE});$("#sparge_acid_type").jqxDropDownList({disabled:aE});$("#sparge_acid_perc").jqxNumberInput({spinButtons:aF,readOnly:aE,width:aC})}function ay(){console.log("calcPercentages()");var aF=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(aF>1){var aD=0;for(i=0;i<aF;i++){var aE=$("#fermentableGrid").jqxGrid("getrowdata",i);if(aE.f_added<4){aD+=Math.round(aE.f_amount*1000)/1000}}aD=Math.round(aD*1000)/1000;for(i=0;i<aF;i++){var aE=$("#fermentableGrid").jqxGrid("getrowdata",i);if(aE.f_added<4){var aC=Math.round(aE.f_amount/aD*1000)/10;$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_percentage",aC)}else{$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_percentage",0)}}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}}function I(){console.log("calcFermentables()");sugarsf=0;sugarsm=0;A=0;L=0;V=0;var aV=0;var aO=0;var aW=0;var a1=0;var aJ=0;var aQ=0;var aM=0;var aP=false;var aT=0;var aI=0;var aY=0.925;var aS=0.95;var aH=0;if((aK=$("#mashGrid").jqxGrid("getrows"))){for(var aU=0;aU<aK.length;aU++){var aG=aK[aU];if(aG.step_type==0){a1+=parseFloat(aG.step_infuse_amount)}if(aG.step_temp<=75){aT+=aG.step_time;aI+=aG.step_time*aG.step_temp}}aI=aI/aT}if(!(aK=$("#fermentableGrid").jqxGrid("getrows"))){return}var aN=0;for(var aU=0;aU<aK.length;aU++){var aG=aK[aU];if(aG.f_adjust_to_total_100){aP=true}if(aG.f_type==1&&aG.f_added<4){A+=aG.f_percentage}if(aG.f_graintype==2&&aG.f_added<4){L+=aG.f_percentage}var aZ=aG.f_amount*(aG.f_yield/100)*(1-aG.f_moisture/100);if(aG.f_added==0){if(a1>0){a1+=aG.f_amount*aG.f_moisture/100;aN+=aZ}aZ=parseFloat(d.efficiency)/100*aZ;sugarsm+=aZ;V+=aG.f_amount}if(aG.f_added==0||aG.f_added==1){sugarsf+=aZ}if(aG.f_added==2||aG.f_added==3){var aL=(aG.f_yield/100)*(1-aG.f_moisture/100);aO+=aG.f_amount*aL;aW+=aG.f_amount;aV+=(aL*sugardensity+(1-aL)*1)*aG.f_amount}if(aG.f_added==0&&(aG.f_type==0||aG.f_type==4)&&aG.f_color<50){aH+=aG.f_diastatic_power*aG.f_amount}if(aG.f_added<4){aJ+=aG.f_amount*ebc_to_srm(aG.f_color);aQ+=aG.f_amount*aG.f_color*get_kt(aG.f_color);aM+=(aG.f_percentage/100)*aG.f_color}}$("#ferm_lintner").val(Math.round(parseFloat(aH/V)));console.log("lintner:"+aH+" kg:"+V);k=aP;if(k){$("#wf_amount").jqxNumberInput({width:90,readOnly:true,spinButtons:false})}else{$("#wf_amount").jqxNumberInput({width:110,readOnly:false,spinButtons:true})}d.est_og=estimate_sg(sugarsf+aO,parseFloat(d.batch_size));$("#est_og").val(d.est_og);$("#est_og2").val(d.est_og);var aC=d.est_og;S=estimate_sg(sugarsm,parseFloat(d.boil_size));if(d.color_method==4){var aR=Math.round(((sg_to_plato(d.est_og)/8.6)*aM)+(d.boil_time/60))}else{if(d.color_method==3){var aR=Math.round((4.46*aY*aS)/parseFloat(d.batch_size)*aQ)}else{var aD=aJ/parseFloat(d.batch_size)*8.34436;var aR=kw_to_ebc(d.color_method,aD)}}d.est_color=aR;$("#est_color").val(aR);$("#est_color2").val(aR);var aX=ebc_to_color(aR);document.getElementById("bcolor").style.background=aX;document.getElementById("bcolor2").style.background=aX;pmalts=V/(d.boil_size/3)*100;$("#perc_malts").jqxProgressBar("val",pmalts);$("#perc_sugars").jqxProgressBar("val",A);$("#perc_cara").jqxProgressBar("val",L);ah=0;var aK=$("#yeastGrid").jqxGrid("getrows");for(var aU=0;aU<aK.length;aU++){var aG=aK[aU];if(aG.y_use==0){if(parseFloat(aG.y_attenuation)>ah){ah=parseFloat(aG.y_attenuation)}}}if(ah==0){ah=77}if((V>0)&&(w>0)&&(aT>0)&&(aI>0)){d.est_fg=estimate_fg(A,L,w/V,aT,aI,ah,d.est_og)}else{d.est_fg=estimate_fg(A,L,0,0,0,ah,d.est_og)}$("#est_fg").val(d.est_fg);$("#est_fg2").val(d.est_fg);var a0=d.est_fg;d.est_abv=abvol(d.est_og,d.est_fg);$("#est_abv").val(d.est_abv);$("#est_abv2").val(d.est_abv);var aF=1881.22*a0*(aC-a0)/(1.775-aC);var aE=3550*a0*(0.1808*aC+0.8192*a0-1.0004);$("#kcal").val(Math.round((aF+aE)/(12*0.0295735296)))}function B(aE,aG,aD,aF){var aC;if(aD==1){aC=0.15}else{if(aE>50){aC=0.1}else{aC=15.25/(6*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((aE-21)/6,2));if(aC<0.1){aC=0.1}}}return(aC*aF*1000)/aG}function h(aE,aG,aD,aF){var aC=0;if(aD==5){aC=1.33}else{if(aE>20){aC=0}else{if(aE>7.5){aC=10.03/(4*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((aE-7.5)/4,2))}else{if(aD==2){aC=1}else{if(aD==3){aC=1.2}else{if(aD==4){aC=1.2}}}}}}return(aC*aF*1000)/aG}function ar(){if(!(rows=$("#mashGrid").jqxGrid("getrows"))){return}if(V==0){return}var aC=0;for(var aD=0;aD<rows.length;aD++){var aE=$("#mashGrid").jqxGrid("getrowdata",aD);if(aE.step_type==0){aC+=aE.step_infuse_amount}$("#mashGrid").jqxGrid("setcellvalue",aD,"step_thickness",aC/V)}}function X(){var aC=0;J=aA=0;var aE={};if(!(aE=$("#hopGrid").jqxGrid("getrows"))){return}for(var aD=0;aD<aE.length;aD++){var aF=aE[aD];aC+=toIBU(aF.h_useat,aF.h_form,S,parseFloat(d.batch_size),parseFloat(aF.h_amount),parseFloat(aF.h_time),parseFloat(aF.h_alpha),d.ibu_method);aA+=B(parseFloat(aF.h_time),parseFloat(d.batch_size),aF.h_useat,parseFloat(aF.h_amount));J+=h(parseFloat(aF.h_time),parseFloat(d.batch_size),aF.h_useat,parseFloat(aF.h_amount))}aC=Math.round(aC*10)/10;aA=Math.round(aA*1000/5)/10;J=Math.round(J*1000/6)/10;if(aA>100){aA=100}if(J>100){J=100}console.log("calcIBUs(): "+aC+"  flavour: "+aA+"  aroma: "+J);d.est_ibu=aC;$("#est_ibu").val(aC);$("#est_ibu2").val(aC);$("#hop_flavour").jqxProgressBar("val",aA);$("#hop_aroma").jqxProgressBar("val",J)}function Q(aE){console.log("adjustHops("+aE+")");var aG=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(aG==0){return}for(var aD=0;aD<aG;aD++){var aF=$("#hopGrid").jqxGrid("getrowdata",aD);var aC=aF.h_amount*aE;$("#hopGrid").jqxGrid("setcellvalue",aD,"h_amount",aC)}}function aB(aE){console.log("adjustMiscs("+aE+")");var aG=$("#miscGrid").jqxGrid("getdatainformation").rowscount;if(aG==0){return}for(var aD=0;aD<aG;aD++){var aF=$("#miscGrid").jqxGrid("getrowdata",aD);var aC=aF.m_amount*aE;$("#miscGrid").jqxGrid("setcellvalue",aD,"m_amount",aC);switch(aF.m_name){case"CaCl2":$("#wa_cacl2").val(aF.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(aF.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(aF.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(aF.m_amount*1000);break;case"Melkzuur":case"Zoutzuur":case"Fosforzuur":case"Zwavelzuur":$("#wa_acid").val(aF.m_amount*1000);break;case"NaHCO3":case"Na2CO3":case"CaCO3":case"Ca(OH)2":$("#wa_base").val(aF.m_amount*1000);break}}}function at(aE){console.log("adjustYeasts("+aE+")");var aG=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(aG==0){return}for(var aD=0;aD<aG;aD++){var aF=$("#yeastGrid").jqxGrid("getrowdata",aD);if(aF.y_form==1){var aC=aF.y_amount*aE;$("#yeastGrid").jqxGrid("setcellvalue",aD,"y_amount",aC)}}}function aa(aE){console.log("adjustWaters("+aE+")");var aG=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(aG==0){return}w=0;for(var aD=0;aD<aG;aD++){var aF=$("#mashGrid").jqxGrid("getrowdata",aD);if(aF.step_type==0){var aC=Math.round(aF.step_infuse_amount*aE*10)/10;$("#mashGrid").jqxGrid("setcellvalue",aD,"step_infuse_amount",aC);w+=aC}}if(d.w2_amount==0){d.w1_amount=w;$("#w1_amount").val(w)}else{d.w1_amount=(d.w1_amount/(d.w1_amount+d.w2_amount))*w;d.w2_amount=(d.w2_amount/(d.w1_amount+d.w2_amount))*w;$("#w1_amount").val(d.w1_amount);$("#w2_amount").val(d.w2_amount)}$("#wg_amount").val(w)}function F(){var aC=(d.est_og-1)*1000;if(aC>0){return d.est_ibu/aC}else{return 0.5}}function l(){var aC=F();return(-1.2*aC+1.4)}function ag(aC,aG){var aJ=$("#miscGrid").jqxGrid("getrows");if(aG==0){for(var aF=0;aF<aJ.length;aF++){var aI=aJ[aF];if(aI.m_name==aC){var aD=$("#miscGrid").jqxGrid("getrowid",aF);var aE=$("#miscGrid").jqxGrid("deleterow",aD)}}}else{var aK=false;for(var aF=0;aF<aJ.length;aF++){var aI=aJ[aF];if(aI.m_name==aC){aK=true;$("#miscGrid").jqxGrid("setcellvalue",aF,"m_amount",aG/1000);break}}if(!aK){var aH=new $.jqx.dataAdapter(miscInvSource,{loadComplete:function(){var aM=aH.records;for(var aN=0;aN<aM.length;aN++){var aL=aM[aN];if(aL.name==aC){var aP={};aP.m_name=aL.name;aP.m_amount=aG/1000;aP.m_cost=aL.cost;aP.m_type=aL.type;aP.m_use_use=aL.use_use;aP.m_time=0;aP.m_amount_is_weight=aL.amount_is_weight;aP.m_inventory=aL.inventory;aP.m_avail=1;var aO=$("#miscGrid").jqxGrid("addrow",null,aP)}}}});aH.dataBind();return}}}function m(aD,aC){if((aC=="laag")||(aC=="hoog")){$("#wr_"+aD).html("<img src='images/dialog-error.png'><span style='vertical-align: top; font-size: 10px; font-style: italic;'>"+aC+"</span>")}else{$("#wr_"+aD).html("<img src='images/dialog-ok-apply.png'>")}}function au(aF,aE,aD,aC){if((aF+aE)>0){return((aF*aD)+(aE*aC))/(aF+aE)}return 0}function Y(aE,aD,aC){return aE-(aD/1.4+aC/1.7)}var ae=4.445e-7;var ad=4.68e-11;function u(aD){var aC=Math.pow(10,-aD);return 100*ae*ad/(aC*aC+aC*ae+ae*ad)}function af(aD){var aC=Math.pow(10,-aD);return 100*ae*aC/(aC*aC+aC*ae+ae*ad)}function ac(aC){return(-2*u(aC)-af(aC))}function C(aD){var aG=ac(4.3);var aE=ac(parseFloat($("#wg_ph").jqxNumberInput("decimal")));var aC=ac(aD);var aI=-aG+aE;var aH=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))/50/aI;var aF=-aC+aE;return aH*aF}function T(aD){var aC=parseFloat($("#wg_calcium").jqxNumberInput("decimal"))/(v/2);var aE=parseFloat($("#wg_magnesium").jqxNumberInput("decimal"))/(W/2);var aF=C(aD);return aF-(aC/3.5+aE/7)}function D(aD){var aI=T(aD)*parseFloat($("#wg_amount").jqxNumberInput("decimal"));var aG=$("#fermentableGrid").jqxGrid("getrows");for(var aE=0;aE<aG.length;aE++){var aH=aG[aE];if(aH.f_added==0&&aH.f_graintype!=6){var aF=0;if((aH.f_di_ph!=5.7)&&((aH.f_acid_to_ph_57<-0.1)||(aH.f_acid_to_ph_57>0.1))){aF=aH.f_acid_to_ph_57/(aH.f_di_ph-5.7)}else{var aC=aH.f_color;switch(aH.f_graintype){case 0:case 3:case 5:aF=0.014*aC-34.192;break;case 2:aF=-0.0597*aC-32.457;break;case 1:aF=0.0107*aC-54.768;break;case 4:aF=-149;break}}x=aF*(aD-aH.f_di_ph);aI+=x*aH.f_amount}}return aI}function aq(){var aG=0;var aE=5.4;var aD=0.001;var aF=0.1;var aC=D(aE);while(((aC<-aF)||(aC>aF))&&(aG<2000)){aG++;if(aC<-aF){aE-=aD}else{if(aC>aF){aE+=aD}}aC=D(aE)}console.log("MashpH() n: "+aG+" pH: "+aE);return aE}function s(aC){switch(aC){case 0:return{pK1:3.86,pK2:20,pK3:20,MolWt:90.08,AcidSG:1214,AcidPrc:0.88};case 1:return{pK1:-7,pK2:20,pK3:20,MolWt:36.46,AcidSG:1142,AcidPrc:0.28};case 2:return{pK1:2.12,pK2:7.2,pK3:12.44,MolWt:98,AcidSG:1170,AcidPrc:0.25};case 3:return{pK1:-1,pK2:1.92,pK3:20,MolWt:98.07,AcidSG:1700,AcidPrc:0.93}}console.log("Bummer, AT is "+aC)}function G(){console.log("calcWater()");var aW=0;var bb=0;var aM=0;var aX=0;var aN=0;var a8=0;var aO=0;var a6=0;var aQ=0;var aZ=0;var aF=0;var bi=0;var bg=0;var bc=0;if(d.w1_name==""){return}if(d.w2_name!=""){aW=d.w1_amount+d.w2_amount;bb=au(d.w1_amount,d.w2_amount,d.w1_calcium,d.w2_calcium);aM=au(d.w1_amount,d.w2_amount,d.w1_magnesium,d.w2_magnesium);aX=au(d.w1_amount,d.w2_amount,d.w1_sodium,d.w2_sodium);aO=au(d.w1_amount,d.w2_amount,d.w1_chloride,d.w2_chloride);a6=au(d.w1_amount,d.w2_amount,d.w1_sulfate,d.w2_sulfate);aN=au(d.w1_amount,d.w2_amount,d.w1_total_alkalinity,d.w2_total_alkalinity);aQ=-Math.log10(((Math.pow(10,-d.w1_ph)*d.w1_amount)+(Math.pow(10,-d.w2_ph)*d.w2_amount))/aW)}else{aW=d.w1_amount;bb=d.w1_calcium;aM=d.w1_magnesium;aX=d.w1_sodium;aO=d.w1_chloride;a6=d.w1_sulfate;aN=d.w1_total_alkalinity;aQ=d.w1_ph}$("#wg_amount").val(aW);var bd=bb;$("#wg_calcium").val(Math.round(bb*10)/10);var bf=aM;$("#wg_magnesium").val(Math.round(aM*10)/10);var aY=aX;$("#wg_sodium").val(Math.round(aX*10)/10);var be=aN;$("#wg_total_alkalinity").val(Math.round(aN*10)/10);var aK=aO;$("#wg_chloride").val(Math.round(aO*10)/10);var a7=a6;$("#wg_sulfate").val(Math.round(a6*10)/10);var aH=aQ;$("#wg_ph").val(Math.round(aQ*10)/10);$("#wb_ph").val(Math.round(aq()*10)/10);a8=aN*1.22;var aE=a8;aZ=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*v/H+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*v/U;bb+=1000*aZ/aW;aZ=parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*W/an;aM+=1000*aZ/aW;aZ=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*M/c;aX+=1000*aZ/aW;aZ=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*al/U+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*al/an;a6+=1000*aZ/aW;aZ=2*parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*o/H+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*o/c;aO+=1000*aZ/aW;if($("#wa_acid_name").val()<0||$("#wa_acid_name").val()>3){console.log("fix wa_acid_name");$("#wa_acid_name").val(0);d.wa_acid_name=0}if(O==""){O=AcidTypeData[$("#wa_acid_name").val()].nl}if($("#wa_base_name").val()<0||$("#wa_base_name").val()>3){console.log("fix wa_base_name");$("#wa_base_name").val(0);d.wa_base_name=0}if(ax==""){ax=BaseTypeData[$("#wa_base_name").val()].nl}var ba=d.wa_acid_name;var a0=d.wa_base_name;var aS=s(ba);var aG=aS.pK1;var aD=aS.pK2;var aC=aS.pK3;var aR=aS.MolWt;var aJ=aS.AcidSG;var aI=aS.AcidPrc;if(d.calc_acid){bg=parseFloat(d.mash_ph);bc=D(bg);console.log("calc_acid tgt: "+bg+" protonDeficit: "+bc);if(bc>0){$("#wa_base").val(0);ag(ax,0);bi=CalcFrac(bg,aG,aD,aC);Acid=bc/bi;Acid*=aR;Acidmg=Acid;Acid=Acid/aJ;if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(aI)}Acid=Acid*aI/(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);console.log("Final ml: "+Acid);$("#wa_acid").val(Math.round(Acid*100)/100);ag(AcidTypeData[ba].nl,Math.round(Acid*100)/100);a8=a8-bc*bi/aW;aN=a8*50/61}else{if(bc<0){$("#wa_acid").val(0);ag(O,0);var a2=Math.pow(10,(bg-6.38));var aU=Math.pow(10,(bg-10.38));var aL=1/(1+a2+a2*aU);var a3=aL*a2;var aV=a3*aU;switch(a0){case 0:aZ=-bc/(aL-aV);aZ=aZ*aj/1000;$("#wa_base").val(Math.round(aZ*100)/100);ag("NaHCO3",Math.round(aZ*100)/100);if(aW>0){aZ=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*M/c+parseFloat($("#wa_base").jqxNumberInput("decimal"))*M/aj;aZ=1000*aZ/aW;aX=aY+aZ;aZ=parseFloat($("#wa_base").jqxNumberInput("decimal"))*p/aj;aZ=1000*aZ/aW;a8=aE+aZ;aN=a8*50/61;aZ=Y(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 1:aZ=-bc/(2*aL+a3);aZ=aZ*t/1000;$("#wa_base").val(Math.round(aZ*100)/100);ag("Na2CO3",Math.round(aZ*100)/100);if(aW>0){aZ=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*M/c+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*M/t;aZ=1000*aZ/aW;aX=aY+aZ;aZ=parseFloat($("#wa_base").jqxNumberInput("decimal"))*p/t;aZ=1000*aZ/aW;a8=aE+aZ;aN=a8*50/61;aZ=Y(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 2:aZ=-bc*(aL-aV);aZ=aZ*g/1000;aZ=3*aZ;$("#wa_base").val(Math.round(aZ*100)/100);ag("CaCO3",Math.round(aZ*100)/100);if(aW>0){aZ=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*p/g;aZ=1000*aZ/aW;a8=aE+aZ;aN=a8*50/61;aZ=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*v/H+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*v/U+parseFloat($("#wa_base").jqxNumberInput("decimal"))*v/g;aZ=1000*aZ/aW;bb=bd+aZ;aZ=Y(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 3:aZ=-bc/19.3;$("#wa_base").val(Math.round(aZ*100)/100);ag("Ca(OH)2",Math.round(aZ*100)/100);if(aW>0){aZ=-bc/aW;aN=be+aZ;a8=aN*61/50;aZ=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*v/H+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*v/U+parseFloat($("#wa_base").jqxNumberInput("decimal"))*v/am;aZ=1000*aZ/aW;bb=bd+aZ;aZ=Y(wb_total_alkalinity,wb_calcium,wb_magnesium)}break}}}aQ=bg;$("#wb_ph").val(Math.round(aQ*10)/10)}else{console.log("calc_acid no");if(parseFloat($("#wa_base").jqxNumberInput("decimal"))>0){if(aW>0){switch(a0){case 0:aZ=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*M/c+parseFloat($("#wa_base").jqxNumberInput("decimal"))*M/aj;aZ=1000*aZ/aW;aX=aY+aZ;aZ=parseFloat($("#wa_base").jqxNumberInput("decimal"))*p/aj;aZ=1000*aZ/aW;a8=aE+aZ;aN=a8*50/61;aZ=Y(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 1:aZ=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*M/c+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*M/t;aZ=1000*aZ/aW;aX=aY+aZ;aZ=parseFloat($("#wa_base").jqxNumberInput("decimal"))*p/t;aZ=1000*aZ/aW;a8=aE+aZ;aN=a8*50/61;aZ=Y(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 2:aZ=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*p/g;aZ=1000*aZ/aW;a8=aE+aZ;aN=a8*50/61;aZ=Y(wb_total_alkalinity,wb_calcium,wb_magnesium);aZ=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*v/H+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*v/U+parseFloat($("#wa_base").jqxNumberInput("decimal"))*v/g;aZ=1000*aZ/aW;bb=bd+aZ;break}}}bg=parseFloat(d.mash_ph);pHa=aq();if(parseFloat($("#wa_acid").jqxNumberInput("decimal"))>0){console.log("TpH: "+bg+" water: "+pHa);Acid=parseFloat($("#wa_acid").jqxNumberInput("decimal"));if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(aI)}Acid=Acid/aI*(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);Acid*=aJ;Acid/=aR;Acidmg=Acid;bi=CalcFrac(pHa,aG,aD,aC);bc=Acid*bi;var a9=0.001;var a1=0.1;var aT=D(pHa);var a5=0;while(((aT<(bc-a1))||(aT>(bc+a1)))&&(a5<2000)){a5++;if(aT<(bc-a1)){pHa-=a9}else{if(aT>(bc+a1)){pHa+=a9}}bi=CalcFrac(pHa,aG,aD,aC);bc=Acid*bi;aT=D(pHa)}console.log("n: "+a5+" pd: "+aT+" protonDeficit: "+bc+" frac: "+bi+" pHa: "+pHa);aZ=aE-bc*bi/aW;a8=aZ;aN=aZ*50/61;aQ=pHa;$("#wb_ph").val(Math.round(aQ*10)/10)}}if((ba==3)&&(aW>0)){aZ=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*al/U+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*al/an+Acidmg/1000*al/(al+2);aZ=1000*aZ/aW;a6=a7+aZ}else{if((ba==1)&&(aW>0)){aZ=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*o/H+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*o/c+Acidmg/1000*o/(o+1);aZ=1000*aZ/aW;aO=aK+aZ}}$("#tgt_bu").val(Math.round(F()*100)/100);if(F()<0.32){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Zeer moutig en zoet</span>")}else{if(F()<0.43){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Moutig, zoet</span>")}else{if(F()<0.52){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Evenwichtig</span>")}else{if(F()<0.63){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Licht hoppig, bitter</span>")}else{$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Extra hoppig, zeer bitter</span>")}}}}$("#tgt_cl_so4").val(Math.round(l()*10)/10);if(a6>0){aZ=aO/a6}else{aZ=10}$("#got_cl_so4").val(Math.round(aZ*10)/10);var bh=0.8*l();var a4=1.2*l();var aP="normaal";if(aZ<bh){aP="laag"}else{if(aZ>a4){aP="hoog"}}m("cl_so4",aP);$("#wb_calcium").val(Math.round(bb*10)/10);$("#wb_magnesium").val(Math.round(aM*10)/10);$("#wb_sodium").val(Math.round(aX*10)/10);$("#wb_sulfate").val(Math.round(a6*10)/10);$("#wb_chloride").val(Math.round(aO*10)/10);$("#wb_total_alkalinity").val(Math.round(aN*10)/10);if(bb<40){m("calcium","laag")}else{if(bb>150){m("calcium","hoog")}else{m("calcium","normaal")}}if(aM>=0&&aM<=30){m("magnesium","normaal")}else{m("magnesium","hoog")}if(aX<=150){m("sodium","normaal")}else{m("sodium","hoog")}if(aO<=50){m("chloride","laag")}else{if(aO<=100){m("chloride","normaal")}else{m("chloride","hoog")}}if(a6<=50){m("sulfate","laag")}else{if(a6<=350){m("sulfate","normaal")}else{m("sulfate","hoog")}}if(aQ<5.2){m("ph","laag")}else{if(aQ>5.6){m("ph","hoog")}else{m("ph","normaal")}}j()}function j(){var aF=d.sparge_ph;var aT=d.w1_ph;var aR=d.w1_total_alkalinity;if(d.sparge_source==1){if(d.w2_ph>0){aT=d.w2_ph;aR=d.w2_total_alkalinity}else{d.sparge_source=0;$("#sparge_source").val(0)}}else{if(d.sparge_source==2){if(d.w2_ph>0){aT=parseFloat($("#wg_ph").jqxNumberInput("decimal"));aR=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))}else{d.sparge_source=0;$("#sparge_source").val(0)}}}var a0=Math.pow(10,aT-6.38);var aZ=Math.pow(10,aT-10.373);var a3=1+a0+a0*aZ;var aX=1/a3;var aW=a0/a3;var aV=a0*aZ/a3;var aY=Math.pow(10,4.3-6.38);var aJ=Math.pow(10,4.3-10.373);var a8=1+aY+aY*aJ;var a6=1/a8;var aQ=aY/a8;var aD=aY*aJ/a8;var aH=aR/50;var aL=(aH-1000*(Math.pow(10,-4.3)-Math.pow(10,-aT)))/((a6-aX)+(aV-aD));var aS=Math.pow(10,aF-6.38);var a4=Math.pow(10,aF-10.373);var a2=1+aS+aS*a4;var a5=1/a2;var aI=aS/a2;var aU=aS*a4/a2;var aE=aL*((a5-aX)+(aV-aU))+Math.pow(10,-aF)-Math.pow(10,-aT);aE+=0.01;if(d.sparge_acid_type<0||d.sparge_acid_type>3){d.sparge_acid_type=0;$("#sparge_acid_type").val(0)}var aK=d.sparge_acid_type;var aP=s(aK);var aO=aP.pK1;var aN=aP.pK2;var aM=aP.pK3;var a7=aP.MolWt;var aG=aP.AcidSG;var aC=aP.AcidPrc;var a1=CalcFrac(aF,aO,aN,aM);aE/=a1;aE*=a7;aE=aE/aG;var aX=d.sparge_acid_perc;if(aX<=0.1){aX=aC}aE=aE*aC/(aX/100);aE*=d.sparge_volume;aE=Math.round(aE*100)/100;d.sparge_acid_amount=aE/1000;$("#sparge_acid_amount").val(aE)}function N(aD){console.log("calcFermentablesFromOG("+aD+")");var aC=parseFloat($("#efficiency").jqxNumberInput("decimal"));var aK=sg_to_plato(aD)*parseFloat($("#batch_size").jqxNumberInput("decimal"))*aD/100;var aH=0;var aJ=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(var aE=0;aE<aJ;aE++){var aL=$("#fermentableGrid").jqxGrid("getrowdata",aE);if(aL.f_added<4){var aI=aL.f_percentage/100*(aL.f_yield/100)*(1-aL.f_moisture/100);if(aL.f_added==0){aI=aC/100*aI}aH+=aI}}var aG=0;if(aH){aG=Math.round((aK/aH)*1000)/1000}if(aG){for(aE=0;aE<aJ;aE++){var aL=$("#fermentableGrid").jqxGrid("getrowdata",aE);if(aL.f_added<4){var aF=Math.round(aL.f_percentage*10*aG)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",aE,"f_amount",aF)}}}}function az(){console.log("calc.init()");$("#calc_acid").on("checked",function(aC){d.calc_acid=1;G()});$("#calc_acid").on("unchecked",function(aC){d.calc_acid=0;G()});$("#w1_name").jqxDropDownList("selectItem",d.w1_name);$("#w2_name").jqxDropDownList("selectItem",d.w2_name);if(parseFloat($("#w1_amount").jqxNumberInput("decimal"))==0&&w>0){$("#w1_amount").val(w);d.w1_amount=w;$("#wg_amount").val(w);$("#w2_amount").val(0);d.w2_amount=0}G();$("#w2_amount").on("change",function(aC){var aD=parseFloat(aC.args.value);if(aD>w){$("#w2_amount").val(d.w2_amount);return}d.w1_amount=parseFloat($("#wg_amount").jqxNumberInput("decimal"))-aD;$("#w1_amount").val(d.w1_amount);d.w2_amount=aD;console.log("new: "+aC.args.value+" w1: "+d.w1_amount+"  w2: "+d.w2_amount);G()});$("#wa_cacl2").on("change",function(aC){if(aC.args){ag("CaCl2",0);ag("CaCl2",aC.args.value);G()}});$("#wa_caso4").on("change",function(aC){if(aC.args){ag("CaSO4",0);ag("CaSO4",aC.args.value);G()}});$("#wa_mgso4").on("change",function(aC){if(aC.args){ag("MgSO4",0);ag("MgSO4",aC.args.value);G()}});$("#wa_nacl").on("change",function(aC){if(aC.args){ag("NaCl",0);ag("NaCl",aC.args.value);G()}});$("#wa_base_name").on("change",function(aD){if(aD.args){var aC=aD.args.index;console.log("wa_base_name "+aC);ag(ax,0);ax=BaseTypeData[aC].nl;ag(ax,parseFloat($("#wa_base").jqxNumberInput("decimal")));d.wa_base_name=aC;G()}});$("#wa_base").on("change",function(aD){var aC=BaseTypeData[$("#wa_base_name").val()].nl;ag(aC,parseFloat(aD.args.value));G()});$("#wa_acid_name").on("change",function(aD){if(aD.args){var aC=aD.args.index;console.log("wa_acid_name "+aC);ag(O,0);O=AcidTypeData[aC].nl;ag(O,parseFloat($("#wa_acid").jqxNumberInput("decimal")));d.wa_acid_name=aC;G()}});$("#wa_acid").on("change",function(aD){var aC=AcidTypeData[$("#wa_acid_name").val()].nl;ag(aC,parseFloat(aD.args.value));G()});$("#wa_acid_perc").on("change",function(aC){G()});$("#color_method").on("change",function(aC){d.color_method=aC.args.index;I()});$("#ibu_method").on("change",function(aC){d.ibu_method=aC.args.index;I();X()});$("#batch_size").on("change",function(aE){console.log("batch_size change:"+aE.args.value+" old:"+d.batch_size);var aD=parseFloat(aE.args.value)+d.boil_size-d.batch_size;var aC=parseFloat(aE.args.value)/d.batch_size;d.boil_size=aD;$("#boil_size").val(Math.round(aD*100)/100);d.sparge_volume*=aC;$("#sparge_volume").val(d.sparge_volume);d.batch_size=parseFloat(aE.args.value);N(parseFloat($("#est_og").jqxNumberInput("decimal")));aa(aC);I();Q(aC);aB(aC);at(aC);X();G();j();ar()});$("#boil_time").on("change",function(aE){console.log("boil_time change:"+parseFloat(aE.args.value)+" old:"+d.boil_time);var aF=parseFloat(d.boil_size)-parseFloat(d.batch_size);var aC=aF*(parseFloat(aE.args.value)/d.boil_time);var aD=parseFloat(d.batch_size)+aC;d.boil_time=parseFloat(aE.args.value);d.boil_size=aD;$("#boil_size").val(Math.round(aD*100)/100);I();X()});$("#efficiency").on("change",function(aD){var aC=parseFloat($("#est_og").jqxNumberInput("decimal"));d.efficiency=parseFloat(aD.args.value);console.log("efficiency change:"+d.efficiency);N(aC);I();X()});$("#est_og").on("change",function(aC){d.est_og=parseFloat(aC.args.value);console.log("est_og change:"+d.est_og);N(d.est_og);I();X();ar()});$("#mash_ph").on("change",function(aC){d.mash_ph=parseFloat(aC.args.value);G()});$("#sparge_ph").on("change",function(aC){d.sparge_ph=parseFloat(aC.args.value);j()});$("#sparge_volume").on("change",function(aC){d.sparge_volume=parseFloat(aC.args.value);j()});$("#sparge_source").on("change",function(aD){if(aD.args){var aC=aD.args.index;d.sparge_source=aC;j()}});$("#sparge_acid_type").on("change",function(aD){if(aD.args){var aC=aD.args.index;d.sparge_acid_type=aC;console.log("new sparge_acid_type: "+d.sparge_acid_type);j()}});$("#sparge_acid_perc").on("change",function(aC){d.sparge_acid_perc=parseFloat(aC.args.value);j()});$("#locked").on("checked",function(aC){d.locked=1;a(true)});$("#locked").on("unchecked",function(aC){d.locked=0;a(false)})}$("#styleSelect").jqxDropDownList({placeHolder:"Kies bierstijl:",theme:theme,source:styleslist,displayMember:"name",width:180,height:23,dropDownVerticalAlignment:"top",dropDownWidth:500,dropDownHeight:380,renderer:function(aD,aC,aF){var aE=styleslist.records[aD];return aE.style_guide+" "+aE.style_letter+" "+aE.name}});$("#styleSelect").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=styleslist.records[aC];$("#st_name").val(aD.name);$("#st_category").val(aD.category);$("#st_category_number").val(aD.category_number);$("#st_letter").val(aD.style_letter);$("#st_guide").val(aD.style_guide);$("#st_type").val(StyleTypeData[aD.type].nl);$("#st_og_min").val(aD.og_min);$("#st_og_max").val(aD.og_max);$("#st_fg_min").val(aD.fg_min);$("#st_fg_max").val(aD.fg_max);$("#st_ibu_min").val(aD.ibu_min);$("#st_ibu_max").val(aD.ibu_max);$("#st_color_min").val(aD.color_min);$("#st_color_max").val(aD.color_max);$("#st_carb_min").val(aD.carb_min);$("#st_carb_max").val(aD.carb_max);$("#st_abv_min").val(aD.abv_min);$("#st_abv_max").val(aD.abv_max)}});function q(){var aD=$("#fermentableGrid").jqxGrid("getrows");var aG=$("#hopGrid").jqxGrid("getrows");var aE=$("#miscGrid").jqxGrid("getrows");var aC=$("#yeastGrid").jqxGrid("getrows");var aF=$("#mashGrid").jqxGrid("getrows");var aI={record:my_record,uuid:d.uuid,name:$("#name").val(),locked:d.locked,notes:$("#notes").val(),st_name:$("#st_name").val(),st_letter:$("#st_letter").val(),st_guide:$("#st_guide").val(),st_type:d.st_type,st_category:$("#st_category").val(),st_category_number:parseFloat($("#st_category_number").jqxNumberInput("decimal")),st_og_min:parseFloat($("#st_og_min").jqxNumberInput("decimal")),st_og_max:parseFloat($("#st_og_max").jqxNumberInput("decimal")),st_fg_min:parseFloat($("#st_fg_min").jqxNumberInput("decimal")),st_fg_max:parseFloat($("#st_fg_max").jqxNumberInput("decimal")),st_ibu_min:parseFloat($("#st_ibu_min").jqxNumberInput("decimal")),st_ibu_max:parseFloat($("#st_ibu_max").jqxNumberInput("decimal")),st_color_min:parseFloat($("#st_color_min").jqxNumberInput("decimal")),st_color_max:parseFloat($("#st_color_max").jqxNumberInput("decimal")),st_carb_min:parseFloat($("#st_carb_min").jqxNumberInput("decimal")),st_carb_max:parseFloat($("#st_carb_max").jqxNumberInput("decimal")),st_abv_min:parseFloat($("#st_abv_min").jqxNumberInput("decimal")),st_abv_max:parseFloat($("#st_abv_max").jqxNumberInput("decimal")),type:$("#type").val(),batch_size:parseFloat($("#batch_size").jqxNumberInput("decimal")),boil_size:parseFloat($("#boil_size").jqxNumberInput("decimal")),boil_time:parseFloat($("#boil_time").jqxNumberInput("decimal")),efficiency:parseFloat($("#efficiency").jqxNumberInput("decimal")),est_og:parseFloat($("#est_og").jqxNumberInput("decimal")),est_fg:parseFloat($("#est_fg").jqxNumberInput("decimal")),est_abv:parseFloat($("#est_abv").jqxNumberInput("decimal")),est_color:parseFloat($("#est_color").jqxNumberInput("decimal")),color_method:$("#color_method").val(),est_ibu:parseFloat($("#est_ibu").jqxNumberInput("decimal")),ibu_method:$("#ibu_method").val(),est_carb:parseFloat($("#est_carb").jqxNumberInput("decimal")),mash_name:$("#mash_name").val(),mash_ph:parseFloat($("#mash_ph").jqxNumberInput("decimal")),sparge_temp:parseFloat($("#sparge_temp").jqxNumberInput("decimal")),sparge_ph:parseFloat($("#sparge_ph").jqxNumberInput("decimal")),sparge_volume:parseFloat($("#sparge_volume").jqxNumberInput("decimal")),sparge_source:$("#sparge_source").val(),sparge_acid_type:$("#sparge_acid_type").val(),sparge_acid_perc:parseFloat($("#sparge_acid_perc").jqxNumberInput("decimal")),sparge_acid_amount:d.sparge_acid_amount,calc_acid:d.calc_acid,w1_name:$("#w1_name").val(),w1_amount:parseFloat($("#w1_amount").jqxNumberInput("decimal")),w1_calcium:parseFloat($("#w1_calcium").jqxNumberInput("decimal")),w1_sulfate:parseFloat($("#w1_sulfate").jqxNumberInput("decimal")),w1_chloride:parseFloat($("#w1_chloride").jqxNumberInput("decimal")),w1_sodium:parseFloat($("#w1_sodium").jqxNumberInput("decimal")),w1_magnesium:parseFloat($("#w1_magnesium").jqxNumberInput("decimal")),w1_total_alkalinity:parseFloat($("#w1_total_alkalinity").jqxNumberInput("decimal")),w1_ph:parseFloat($("#w1_ph").jqxNumberInput("decimal")),w1_cost:d.w1_cost,w2_name:$("#w2_name").val(),w2_amount:parseFloat($("#w2_amount").jqxNumberInput("decimal")),w2_calcium:parseFloat($("#w2_calcium").jqxNumberInput("decimal")),w2_sulfate:parseFloat($("#w2_sulfate").jqxNumberInput("decimal")),w2_chloride:parseFloat($("#w2_chloride").jqxNumberInput("decimal")),w2_sodium:parseFloat($("#w2_sodium").jqxNumberInput("decimal")),w2_magnesium:parseFloat($("#w2_magnesium").jqxNumberInput("decimal")),w2_total_alkalinity:parseFloat($("#w2_total_alkalinity").jqxNumberInput("decimal")),w2_ph:parseFloat($("#w2_ph").jqxNumberInput("decimal")),w2_cost:d.w2_cost,wg_amount:parseFloat($("#wg_amount").jqxNumberInput("decimal")),wg_calcium:parseFloat($("#wg_calcium").jqxNumberInput("decimal")),wg_sulfate:parseFloat($("#wg_sulfate").jqxNumberInput("decimal")),wg_chloride:parseFloat($("#wg_chloride").jqxNumberInput("decimal")),wg_sodium:parseFloat($("#wg_sodium").jqxNumberInput("decimal")),wg_magnesium:parseFloat($("#wg_magnesium").jqxNumberInput("decimal")),wg_total_alkalinity:parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal")),wg_ph:parseFloat($("#wg_ph").jqxNumberInput("decimal")),wb_calcium:parseFloat($("#wb_calcium").jqxNumberInput("decimal")),wb_sulfate:parseFloat($("#wb_sulfate").jqxNumberInput("decimal")),wb_chloride:parseFloat($("#wb_chloride").jqxNumberInput("decimal")),wb_sodium:parseFloat($("#wb_sodium").jqxNumberInput("decimal")),wb_magnesium:parseFloat($("#wb_magnesium").jqxNumberInput("decimal")),wb_total_alkalinity:parseFloat($("#wb_total_alkalinity").jqxNumberInput("decimal")),wb_ph:parseFloat($("#wb_ph").jqxNumberInput("decimal")),wa_acid_name:$("#wa_acid_name").val(),wa_acid_perc:parseFloat($("#wa_acid_perc").jqxNumberInput("decimal")),wa_base_name:$("#wa_base_name").val(),fermentables:aD,hops:aG,miscs:aE,yeasts:aC,mashs:aF};var aH="update=true&"+$.param(aI);$.ajax({dataType:"json",url:z,cache:false,async:false,data:aH,type:"POST",success:function(aK,aJ,aL){console.log("saveRecord() success")},error:function(aJ,aL,aK){console.log("saveRecord() error")}})}var d={};var z="includes/db_recipes.php";var av={datatype:"json",cache:false,datafields:[{name:"record",type:"number"},{name:"uuid",type:"string"},{name:"locked",type:"int"},{name:"st_name",type:"string"},{name:"st_letter",type:"string"},{name:"st_guide",type:"string"},{name:"st_type",type:"int"},{name:"st_category",type:"string"},{name:"st_category_number",type:"float"},{name:"st_og_min",type:"float"},{name:"st_og_max",type:"float"},{name:"st_fg_min",type:"float"},{name:"st_fg_max",type:"float"},{name:"st_ibu_min",type:"float"},{name:"st_ibu_max",type:"float"},{name:"st_color_min",type:"float"},{name:"st_color_max",type:"float"},{name:"st_carb_min",type:"float"},{name:"st_carb_max",type:"float"},{name:"st_abv_min",type:"float"},{name:"st_abv_max",type:"float"},{name:"name",type:"string"},{name:"notes",type:"string"},{name:"type",type:"int"},{name:"batch_size",type:"float"},{name:"boil_size",type:"float"},{name:"boil_time",type:"float"},{name:"efficiency",type:"float"},{name:"est_og",type:"float"},{name:"est_fg",type:"float"},{name:"est_abv",type:"float"},{name:"est_color",type:"float"},{name:"color_method",type:"int"},{name:"est_ibu",type:"float"},{name:"ibu_method",type:"int"},{name:"est_carb",type:"float"},{name:"sparge_temp",type:"float"},{name:"sparge_ph",type:"float"},{name:"sparge_volume",type:"float"},{name:"sparge_source",type:"int"},{name:"sparge_acid_type",type:"int"},{name:"sparge_acid_perc",type:"float"},{name:"sparge_acid_amount",type:"float"},{name:"mash_ph",type:"float"},{name:"mash_name",type:"string"},{name:"calc_acid",type:"int"},{name:"w1_name",type:"string"},{name:"w1_amount",type:"float"},{name:"w1_calcium",type:"float"},{name:"w1_sulfate",type:"float"},{name:"w1_chloride",type:"float"},{name:"w1_sodium",type:"float"},{name:"w1_magnesium",type:"float"},{name:"w1_total_alkalinity",type:"float"},{name:"w1_ph",type:"float"},{name:"w1_cost",type:"float"},{name:"w2_name",type:"string"},{name:"w2_amount",type:"float"},{name:"w2_calcium",type:"float"},{name:"w2_sulfate",type:"float"},{name:"w2_chloride",type:"float"},{name:"w2_sodium",type:"float"},{name:"w2_magnesium",type:"float"},{name:"w2_total_alkalinity",type:"float"},{name:"w2_ph",type:"float"},{name:"w2_cost",type:"float"},{name:"wg_amount",type:"float"},{name:"wg_calcium",type:"float"},{name:"wg_sulfate",type:"float"},{name:"wg_chloride",type:"float"},{name:"wg_sodium",type:"float"},{name:"wg_magnesium",type:"float"},{name:"wg_total_alkalinity",type:"float"},{name:"wg_ph",type:"float"},{name:"wb_calcium",type:"float"},{name:"wb_sulfate",type:"float"},{name:"wb_chloride",type:"float"},{name:"wb_sodium",type:"float"},{name:"wb_magnesium",type:"float"},{name:"wb_total_alkalinity",type:"float"},{name:"wb_ph",type:"float"},{name:"wa_acid_name",type:"int"},{name:"wa_acid_perc",type:"int"},{name:"wa_base_name",type:"int"},{name:"fermentables",type:"array"},{name:"hops",type:"array"},{name:"miscs",type:"array"},{name:"yeasts",type:"array"},{name:"mashs",type:"array"}],id:"record",url:z+"?record="+my_record};var P=new $.jqx.dataAdapter(av,{loadComplete:function(){var aC=P.records;d=aC[0];$("#name").val(d.name);$("#notes").val(d.notes);$("#locked").val(d.locked);$("#st_name").val(d.st_name);$("#st_letter").val(d.st_letter);$("#st_guide").val(d.st_guide);$("#st_category").val(d.st_category);$("#st_category_number").val(d.st_category_number);$("#st_type").val(StyleTypeData[d.st_type].nl);$("#type").val(d.type);$("#batch_size").val(d.batch_size);$("#boil_size").val(d.boil_size);$("#boil_time").val(d.boil_time);$("#efficiency").val(d.efficiency);$("#est_og").val(d.est_og);$("#est_og2").val(d.est_og);$("#st_og_min").val(d.st_og_min);$("#st_og_max").val(d.st_og_max);$("#est_fg").val(d.est_fg);$("#est_fg2").val(d.est_fg);$("#st_fg_min").val(d.st_fg_min);$("#st_fg_max").val(d.st_fg_max);$("#est_color").val(d.est_color);$("#est_color2").val(d.est_color);$("#est_abv").val(d.est_abv);$("#est_abv2").val(d.est_abv);$("#st_abv_min").val(d.st_abv_min);$("#st_abv_max").val(d.st_abv_max);$("#st_color_min").val(d.st_color_min);$("#st_color_max").val(d.st_color_max);$("#color_method").val(d.color_method);$("#est_ibu").val(d.est_ibu);$("#est_ibu2").val(d.est_ibu);$("#st_ibu_min").val(d.st_ibu_min);$("#st_ibu_max").val(d.st_ibu_max);$("#ibu_method").val(d.ibu_method);$("#est_carb").val(d.est_carb);$("#st_carb_min").val(d.st_carb_min);$("#st_carb_max").val(d.st_carb_max);$("#mash_name").val(d.mash_name);$("#mash_ph").val(d.mash_ph);$("#sparge_temp").val(d.sparge_temp);$("#sparge_ph").val(d.sparge_ph);$("#sparge_volume").val(d.sparge_volume);$("#sparge_source").val(d.sparge_source);$("#sparge_acid_type").val(d.sparge_acid_type);$("#sparge_acid_perc").val(d.sparge_acid_perc);$("#sparge_acid_amount").val(d.sparge_acid_amount*1000);$("#calc_acid").val(d.calc_acid);$("#w1_name").val(d.w1_name);$("#w1_amount").val(d.w1_amount);$("#w1_calcium").val(d.w1_calcium);$("#w1_sulfate").val(d.w1_sulfate);$("#w1_chloride").val(d.w1_chloride);$("#w1_sodium").val(d.w1_sodium);$("#w1_magnesium").val(d.w1_magnesium);$("#w1_total_alkalinity").val(d.w1_total_alkalinity);$("#w1_ph").val(d.w1_ph);$("#w1_cost").val(d.w1_cost);$("#w2_name").val(d.w2_name);$("#w2_amount").val(d.w2_amount);$("#w2_calcium").val(d.w2_calcium);$("#w2_sulfate").val(d.w2_sulfate);$("#w2_chloride").val(d.w2_chloride);$("#w2_sodium").val(d.w2_sodium);$("#w2_magnesium").val(d.w2_magnesium);$("#w2_total_alkalinity").val(d.w2_total_alkalinity);$("#w2_ph").val(d.w2_ph);$("#w2_cost").val(d.w2_cost);$("#wg_amount").val(d.wg_amount);$("#wg_calcium").val(d.wg_calcium);$("#wg_sulfate").val(d.wg_sulfate);$("#wg_chloride").val(d.wg_chloride);$("#wg_sodium").val(d.wg_sodium);$("#wg_magnesium").val(d.wg_magnesium);$("#wg_total_alkalinity").val(d.wg_total_alkalinity);$("#wg_ph").val(d.wg_ph);$("#wb_calcium").val(d.wb_calcium);$("#wb_sulfate").val(d.wb_sulfate);$("#wb_chloride").val(d.wb_chloride);$("#wb_sodium").val(d.wb_sodium);$("#wb_magnesium").val(d.wb_magnesium);$("#wb_total_alkalinity").val(d.wb_total_alkalinity);$("#wb_ph").val(d.wb_ph);$("#wa_acid_name").val(d.wa_acid_name);$("#wa_acid_perc").val(d.wa_acid_perc);$("#wa_base_name").val(d.wa_base_name);n(d);aw(d);K(d);ap(d);Z(d);$("#jqxTabs").jqxTabs("next")},loadError:function(aE,aC,aD){},beforeLoadComplete:function(aC){$("#jqxLoader").jqxLoader("open")}});P.dataBind();var n=function(aD){var aC={localdata:aD.fermentables,datatype:"local",cache:false,async:false,datafields:[{name:"f_name",type:"string"},{name:"f_origin",type:"string"},{name:"f_supplier",type:"string"},{name:"f_amount",type:"float"},{name:"f_cost",type:"float"},{name:"f_type",type:"int"},{name:"f_yield",type:"float"},{name:"f_color",type:"float"},{name:"f_coarse_fine_diff",type:"float"},{name:"f_moisture",type:"float"},{name:"f_diastatic_power",type:"float"},{name:"f_protein",type:"float"},{name:"f_max_in_batch",type:"float"},{name:"f_graintype",type:"int"},{name:"f_added",type:"int"},{name:"f_dissolved_protein",type:"float"},{name:"f_recommend_mash",type:"int"},{name:"f_add_after_boil",type:"int"},{name:"f_adjust_to_total_100",type:"int"},{name:"f_percentage",type:"float"},{name:"f_di_ph",type:"float"},{name:"f_acid_to_ph_57",type:"float"},{name:"f_inventory",type:"float"},{name:"f_avail",type:"int"}],addrow:function(aG,aI,aF,aH){aH(true)},deleterow:function(aF,aG){aG(true)},updaterow:function(aF,aH,aG){aG(true)}};var aE=new $.jqx.dataAdapter(aC);$("#fermentableGrid").jqxGrid({width:1240,height:470,source:aE,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(aH){var aG=this;var aF=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");aH.append(aF);aF.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');aF.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');aF.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');aF.append('<input style="float: left; margin-left: 400px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');$("#faddrowbutton").jqxDropDownList({placeHolder:"Kies mout:",theme:theme,template:"primary",source:fermentablelist,displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(aJ,aI,aL){var aK=fermentablelist.records[aJ];return aK.supplier+" / "+aK.name+" ("+aK.color+" EBC)"}});$("#faddrowbutton").on("select",function(aK){if(aK.args){var aN=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;var aI=aK.args.index;var aJ=fermentablelist.records[aI];var aM={};aM.f_name=aJ.name;aM.f_origin=aJ.origin;aM.f_supplier=aJ.supplier;aM.f_amount=0;aM.f_cost=aJ.cost;aM.f_type=aJ.type;aM.f_yield=aJ.yield;aM.f_color=aJ.color;aM.f_coarse_fine_diff=aJ.coarse_fine_diff;aM.f_moisture=aJ.moisture;aM.f_diastatic_power=aJ.diastatic_power;aM.f_protein=aJ.protein;aM.f_max_in_batch=aJ.max_in_batch;aM.f_graintype=aJ.graintype;if(aJ.add_after_boil){aM.f_added=2}else{if((aJ.type==1)||(aJ.type==4)){aM.f_added=1}else{aM.f_added=0}}aM.f_dissolved_protein=aJ.dissolved_protein;aM.f_recommend_mash=aJ.recommend_mash;aM.f_add_after_boil=aJ.add_after_boil;if(aN==0){aM.f_adjust_to_total_100=1;aM.f_percentage=100}else{aM.f_adjust_to_total_100=0;aM.f_percentage=0}aM.f_di_ph=aJ.di_ph;aM.f_acid_to_ph_57=aJ.acid_to_ph_57;aM.f_inventory=aJ.inventory;var aL=$("#fermentableGrid").jqxGrid("addrow",null,aM)}});$("#finstockbutton").jqxCheckBox({theme:theme,height:27});$("#finstockbutton").on("change",function(aI){fermentableinstock=aI.args.checked;fermentablelist.dataBind()});$("#fdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#fdeleterowbutton").on("click",function(){var aK=$("#fermentableGrid").jqxGrid("getselectedrowindex");var aP=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(aK>=0&&aK<aP){var aO=$("#fermentableGrid").jqxGrid("getrowid",aK);var aL=$("#fermentableGrid").jqxGrid("getcellvalue",aO,"f_percentage");var aJ=$("#fermentableGrid").jqxGrid("getcellvalue",aO,"f_amount");var aM=$("#fermentableGrid").jqxGrid("deleterow",aO)}aP=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(aP>1){if(k){for(var aI=0;aI<aP;aI++){var aN=$("#fermentableGrid").jqxGrid("getrowdata",aI);if(aN.f_adjust_to_total_100){aN.f_percentage+=aL;aN.f_amount+=aJ}}}else{ay()}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}I();X()})},ready:function(){I();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Vergistbaar ingredi&euml;nt",datafield:"f_name",cellsrenderer:function(aH,aG,aJ,aF,aI,aK){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+aK.f_supplier+" / "+aK.f_name+" ("+aK.f_color+" EBC)</span>"}},{text:"Type",width:100,datafield:"f_type",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+FermentableTypeData[aJ].nl+"</span>"}},{text:"Moment",width:110,datafield:"f_added",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+AddedData[aJ].nl+"</span>"}},{text:"Maxinbatch",datafield:"f_max_in_batch",hidden:true},{text:"Opbrengst",editable:false,datafield:"f_yield",width:90,align:"right",cellsalign:"right",cellsformat:"p1"},{text:"Gewicht Kg",datafield:"f_amount",width:120,align:"right",cellsalign:"right",cellsformat:"f3"},{text:"Voorr. Kg",datafield:"f_inventory",width:120,align:"right",cellsrenderer:function(aJ,aH,aI,aF,aL,aK){var aG="#ffffff";if(aI<aK.f_amount){aG="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+aG+';">'+aE.formatNumber(aI,"f3")+"</span>"}},{text:"Procent",datafield:"f_percentage",width:90,align:"right",cellsrenderer:function(aJ,aH,aI,aF,aL,aK){var aG="#ffffff";if(aI>aK.f_max_in_batch){aG="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+aG+';">'+aE.formatNumber(aI,"p1")+"</span>"}},{text:"100%",align:"center",datafield:"f_adjust_to_total_100",columntype:"checkbox",width:70},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(aF){r=aF;ao=$("#fermentableGrid").jqxGrid("getrowdata",r);$("#wf_name").val(ao.f_name);$("#wf_amount").val(ao.f_amount);$("#wf_percentage").val(ao.f_percentage);$("#wf_max_in_batch").val(ao.f_max_in_batch);$("#wf_adjust_to_total_100").val(ao.f_adjust_to_total_100);$("#wf_added").val(ao.f_added);$("#popupFermentable").jqxWindow("open")}}]})};var aw=function(aC){var aE={localdata:aC.hops,datatype:"local",cache:false,async:false,datafields:[{name:"h_name",type:"string"},{name:"h_origin",type:"string"},{name:"h_amount",type:"float"},{name:"h_cost",type:"float"},{name:"h_type",type:"int"},{name:"h_form",type:"int"},{name:"h_useat",type:"int"},{name:"h_time",type:"float"},{name:"h_alpha",type:"float"},{name:"h_beta",type:"float"},{name:"h_hsi",type:"float"},{name:"h_humulene",type:"float"},{name:"h_caryophyllene",type:"float"},{name:"h_cohumulone",type:"float"},{name:"h_myrcene",type:"float"},{name:"h_total_oil",type:"float"},{name:"h_inventory",type:"float"},{name:"h_avail",type:"int"}],addrow:function(aG,aI,aF,aH){console.log("hop addrow "+aG);aH(true)},deleterow:function(aF,aG){console.log("hop deleterow "+aF);aG(true)},updaterow:function(aF,aH,aG){console.log("hop updaterow "+aF);aG(true)}};var aD=new $.jqx.dataAdapter(aE);$("#hopGrid").jqxGrid({width:1240,height:560,source:aD,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(aH){var aG=this;var aF=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");aH.append(aF);aF.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');aF.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');aF.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');aF.append('<input style="float: left; margin-left: 400px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');$("#haddrowbutton").jqxDropDownList({placeHolder:"Kies hop:",theme:theme,template:"primary",source:hoplist,displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(aJ,aI,aL){var aK=hoplist.records[aJ];return aK.origin+" / "+aK.name+" ("+aK.alpha+"% &alpha;)"}});$("#haddrowbutton").on("select",function(aK){if(aK.args){var aI=aK.args.index;var aJ=hoplist.records[aI];var aM={};aM.h_name=aJ.name;aM.h_origin=aJ.origin;aM.h_amount=0;aM.h_cost=aJ.cost;aM.h_type=aJ.type;aM.h_form=aJ.form;aM.h_useat=2;aM.h_time=0;aM.h_alpha=aJ.alpha;aM.h_beta=aJ.beta;aM.h_hsi=aJ.hsi;aM.h_humulene=aJ.humulene;aM.h_caryophyllene=aJ.caryophyllene;aM.h_cohumulone=aJ.cohumulone;aM.h_myrcene=aJ.myrcene;aM.h_total_oil=aJ.total_oil;aM.h_inventory=aJ.inventory;var aL=$("#hopGrid").jqxGrid("addrow",null,aM)}$("#haddrowbutton").jqxDropDownList("clearSelection")});$("#hinstockbutton").jqxCheckBox({theme:theme,height:27});$("#hinstockbutton").on("change",function(aI){hopinstock=aI.args.checked;hoplist.dataBind()});$("#hdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#hdeleterowbutton").on("click",function(){var aI=$("#hopGrid").jqxGrid("getselectedrowindex");var aL=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(aI>=0&&aI<aL){var aK=$("#hopGrid").jqxGrid("getrowid",aI);var aJ=$("#hopGrid").jqxGrid("deleterow",aK)}X()})},ready:function(){X();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Hop",datafield:"h_name",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+aK.h_origin+" / "+aK.h_name+"</span>"},},{text:"Type",width:90,datafield:"h_type",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopTypeData[aJ].nl+"</span>"}},{text:"Vorm",width:90,datafield:"h_form",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopFormData[aJ].nl+"</span>"}},{text:"Alpha",datafield:"h_alpha",width:80,align:"right",cellsalign:"right",cellsformat:"p1"},{text:"Gebruik",width:110,datafield:"h_useat",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopUseData[aJ].nl+"</span>"}},{text:"Tijdsduur",datafield:"h_time",width:90,align:"right",cellsrenderer:function(aG,aF,aJ,aI,aH,aL){var aK="";if((aL.h_useat==2)||(aL.h_useat==4)){aK=P.formatNumber(aJ,"f0")+" min."}else{if(aL.h_useat==5){aK=P.formatNumber(aJ/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+aK+"</span>"}},{text:"IBU",datafield:"ibu",width:80,align:"right",cellsrenderer:function(aG,aF,aJ,aI,aH,aL){var aK=toIBU(aL.h_useat,aL.h_form,S,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(aL.h_amount),parseFloat(aL.h_time),parseFloat(aL.h_alpha),$("#ibu_method").val());return'<span style="margin: 4px; margin-top: 6px; float: right;">'+P.formatNumber(aK,"f1")+"</span>"}},{text:"Gewicht",datafield:"h_amount",width:110,align:"right",cellsrenderer:function(aG,aF,aK,aJ,aI,aL){var aH=P.formatNumber(aK,"f1")+" kg";if(aK<1){aH=P.formatNumber(aK*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+aH+"</span>"}},{text:"Voorraad",datafield:"h_inventory",width:110,align:"right",cellsrenderer:function(aH,aG,aL,aK,aJ,aM){var aF="#ffffff";if(aL<aM.h_amount){aF="#ff4040"}var aI=P.formatNumber(aL,"f1")+" kg";if(aL<1){aI=P.formatNumber(aL*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+aF+';">'+aI+"</span>"}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(aF){b=aF;e=$("#hopGrid").jqxGrid("getrowdata",b);$("#wh_name").val(e.h_name);$("#wh_amount").val(e.h_amount*1000);var aG=toIBU(e.h_useat,e.h_form,S,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(e.h_amount),parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(aG);if(e.h_useat==5){$("#wh_time").val(e.h_time/1440)}else{$("#wh_time").val(e.h_time)}$("#wh_useat").val(e.h_useat);$("#popupHop").jqxWindow("open")}}]})};var K=function(aE){var aD={localdata:aE.miscs,datatype:"local",cache:false,async:false,datafields:[{name:"m_name",type:"string"},{name:"m_amount",type:"float"},{name:"m_cost",type:"float"},{name:"m_type",type:"int"},{name:"m_use_use",type:"int"},{name:"m_time",type:"float"},{name:"m_amount_is_weight",type:"int"},{name:"m_inventory",type:"float"},{name:"m_avail",type:"int"}],addrow:function(aG,aI,aF,aH){console.log("misc addrow "+aG);aH(true)},deleterow:function(aF,aG){console.log("misc deleterow "+aF);aG(true)},updaterow:function(aF,aH,aG){console.log("misc updaterow "+aF);aG(true)}};var aC=new $.jqx.dataAdapter(aD,{beforeLoadComplete:function(aF){var aH=new Array();for(var aG=0;aG<aF.length;aG++){var aI=aF[aG];aH.push(aI);switch(aI.m_name){case"CaCl2":$("#wa_cacl2").val(aI.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(aI.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(aI.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(aI.m_amount*1000);break;case"Melkzuur":$("#wa_acid_name").val(0);$("#wa_acid").val(aI.m_amount*1000);$("#wa_acid_perc").val(80);O="Melkzuur";break;case"Zoutzuur":$("#wa_acid_name").val(1);$("#wa_acid").val(aI.m_amount*1000);$("#wa_acid_perc").val(80);O="Zoutzuur";break;case"Fosforzuur":$("#wa_acid_name").val(2);$("#wa_acid").val(aI.m_amount*1000);$("#wa_acid_perc").val(80);O="Fosforzuur";break;case"Zwavelzuur":$("#wa_acid_name").val(3);$("#wa_acid").val(aI.m_amount*1000);$("#wa_acid_perc").val(80);O="Zwavelzuur";break;case"NaHCO3":$("#wa_base_name").val(0);$("#wa_base").val(aI.m_amount*1000);ax="NaHCO3";break;case"Na2CO3":$("#wa_base_name").val(1);$("#wa_base").val(aI.m_amount*1000);ax="Na2CO3";break;case"CaCO3":$("#wa_base_name").val(2);$("#wa_base").val(aI.m_amount*1000);ax="CaCO3";break;case"Ca(OH)2":$("#wa_base_name").val(3);$("#wa_base").val(aI.m_amount*1000);ax="Ca(OH)2";break}}return aH},loadError:function(aH,aF,aG){$("#err").text(aF+" "+aG)},});$("#miscGrid").jqxGrid({width:1240,height:575,source:aC,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(aH){var aG=this;var aF=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");aH.append(aF);aF.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');aF.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');aF.append('<div style="float: left; margin-left: 10px;" id="minstockbutton"></div>');aF.append('<input style="float: left; margin-left: 400px;" id="mdeleterowbutton" type="button" value="Verwijder ingredi&euml;nt" />');$("#maddrowbutton").jqxDropDownList({placeHolder:"Kies ingredi&euml;nt:",theme:theme,template:"primary",source:misclist,displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500});$("#maddrowbutton").on("select",function(aK){if(aK.args){var aI=aK.args.index;var aJ=misclist.records[aI];var aM={};aM.m_name=aJ.name;aM.m_amount=0;aM.m_cost=aJ.cost;aM.m_type=aJ.type;aM.m_use_use=aJ.use_use;aM.m_time=0;aM.m_amount_is_weight=aJ.amount_is_weight;aM.m_inventory=aJ.inventory;var aL=$("#miscGrid").jqxGrid("addrow",null,aM)}});$("#minstockbutton").jqxCheckBox({theme:theme,height:27});$("#minstockbutton").on("change",function(aI){miscinstock=aI.args.checked;misclist.dataBind()});$("#mdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#mdeleterowbutton").on("click",function(){var aI=$("#miscGrid").jqxGrid("getselectedrowindex");var aM=$("#miscGrid").jqxGrid("getdatainformation").rowscount;var aJ=$("#miscGrid").jqxGrid("getcellvalue",aI,"m_type");if(aI>=0&&aI<aM&&aJ!=4){var aL=$("#miscGrid").jqxGrid("getrowid",aI);var aK=$("#miscGrid").jqxGrid("deleterow",aL)}})},ready:function(){$("#jqxTabs").jqxTabs("next")},columns:[{text:"Ingredient",datafield:"m_name"},{text:"Type",width:140,datafield:"m_type",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+MiscTypeData[aJ].nl+"</span>"}},{text:"Gebruik",width:140,datafield:"m_use_use",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+MiscUseData[aJ].nl+"</span>"}},{text:"Tijd",datafield:"m_time",width:90,align:"right",cellsrenderer:function(aG,aF,aJ,aI,aH,aL){var aK="";if(aL.m_use_use==2){aK=P.formatNumber(aJ,"f0")+" min."}else{if((aL.m_use_use==3)||(aL.m_use_use==4)){aK=P.formatNumber(aJ/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+aK+"</span>"},},{text:"Hoeveel",datafield:"m_amount",width:110,align:"right",cellsrenderer:function(aG,aF,aK,aI,aH,aL){var aJ=aL.m_amount_is_weight?"gr":"ml";return'<span style="margin: 4px; margin-top: 6px; float: right;">'+P.formatNumber(aK*1000,"f2")+" "+aJ+"</span>"},},{text:"Voorraad",datafield:"m_inventory",width:110,align:"right",cellsrenderer:function(aJ,aF,aK,aM,aG,aN){var aL=aN.m_amount_is_weight?"gr":"ml";var aH="#ffffff";if(aK<aN.m_amount){aH="#ff4040"}var aI=P.formatNumber(aK*1000,"f2")+" "+aL;return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+aH+';">'+aI+"</span>"},},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(aF){ab=aF;ak=$("#miscGrid").jqxGrid("getrowdata",ab);if(ak.m_type==4){alert("Brouwzouten wijzigen in de water tab.")}else{if(ak.m_amount_is_weight){$("#wm_pmpt_amount").html("Gewicht gram:")}else{$("#wm_pmpt_amount").html("Volume ml:")}$("#wm_name").val(ak.m_name);$("#wm_amount").val(ak.m_amount*1000);if((ak.m_use_use==3)||(ak.m_use_use==4)){$("#wm_time").val(ak.m_time/1440)}else{$("#wm_time").val(ak.m_time)}$("#wm_use_use").val(ak.m_use_use);$("#popupMisc").jqxWindow("open")}}}]})};var ap=function(aD){var aC={localdata:aD.yeasts,datatype:"local",cache:false,async:false,datafields:[{name:"y_name",type:"string"},{name:"y_laboratory",type:"string"},{name:"y_product_id",type:"string"},{name:"y_amount",type:"float"},{name:"y_cost",type:"float"},{name:"y_type",type:"int"},{name:"y_form",type:"int"},{name:"y_flocculation",type:"int"},{name:"y_min_temperature",type:"float"},{name:"y_max_temperature",type:"float"},{name:"y_attenuation",type:"float"},{name:"y_use",type:"int"},{name:"y_cells",type:"float"},{name:"y_tolerance",type:"float"},{name:"y_inventory",type:"float"},{name:"y_avail",type:"int"}],addrow:function(aG,aI,aF,aH){console.log("yeast addrow "+aG);aH(true)},deleterow:function(aF,aG){console.log("yeast deleterow "+aF);aG(true)},updaterow:function(aF,aH,aG){console.log("yeast updaterow "+aF);aG(true)}};var aE=new $.jqx.dataAdapter(aC);$("#yeastGrid").jqxGrid({width:1240,height:350,source:aE,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(aH){var aG=this;var aF=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");aH.append(aF);aF.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');aF.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');aF.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');aF.append('<input style="float: left; margin-left: 400px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');$("#yaddrowbutton").jqxDropDownList({placeHolder:"Kies gist:",theme:theme,template:"primary",source:yeastlist,displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(aJ,aI,aL){var aK=yeastlist.records[aJ];return aK.laboratory+" "+aK.product_id+" "+aK.name}});$("#yaddrowbutton").on("select",function(aK){if(aK.args){var aI=aK.args.index;var aJ=yeastlist.records[aI];var aM={};aM.y_name=aJ.name;aM.y_laboratory=aJ.laboratory;aM.y_product_id=aJ.product_id;aM.y_type=aJ.type;aM.y_form=aJ.form;aM.y_amount=0;aM.y_cost=aJ.cost;aM.y_use=0;aM.y_min_temperature=aJ.min_temperature;aM.y_max_temperature=aJ.max_temperature;aM.y_attenuation=aJ.attenuation;aM.y_flocculation=aJ.flocculation;aM.y_cells=aJ.cells;aM.y_tolerance=aJ.tolerance;aM.y_inventory=aJ.inventory;var aL=$("#yeastGrid").jqxGrid("addrow",null,aM)}$("#yaddrowbutton").jqxDropDownList("clearSelection")});$("#yinstockbutton").jqxCheckBox({theme:theme,height:27});$("#yinstockbutton").on("change",function(aI){yeastinstock=aI.args.checked;yeastlist.dataBind()});$("#ydeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#ydeleterowbutton").on("click",function(){var aI=$("#yeastGrid").jqxGrid("getselectedrowindex");var aL=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(aI>=0&&aI<aL){var aK=$("#yeastGrid").jqxGrid("getrowid",aI);var aJ=$("#yeastGrid").jqxGrid("deleterow",aK)}})},ready:function(){I();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Gist",datafield:"y_name"},{text:"Laboratorium",width:150,datafield:"y_laboratory"},{text:"Code",width:90,datafield:"y_product_id"},{text:"Soort",width:100,datafield:"y_form",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastFormData[aJ].nl+"</span>"}},{text:"Min. &deg;C",width:70,align:"right",cellsalign:"right",datafield:"y_min_temperature"},{text:"Max. &deg;C",width:70,align:"right",cellsalign:"right",datafield:"y_max_temperature"},{text:"Tol. %",width:60,align:"right",cellsalign:"right",datafield:"y_tolerance",cellsrenderer:function(aH,aG,aL,aK,aJ,aM){var aF="#ffffff";var aI="";if(aL>0){aI=P.formatNumber(aL,"f1");if(d.est_abv>aL){aF="#ff4040"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+aF+';">'+aI+"</span>"}},{text:"Attn. %",width:70,align:"right",cellsalign:"right",datafield:"y_attenuation",cellsformat:"f1"},{text:"Voor",width:120,datafield:"y_use",cellsrenderer:function(aG,aF,aJ,aI,aH,aK){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastUseData[aJ].nl+"</span>"}},{text:"Hoeveel",datafield:"y_amount",width:90,align:"right",cellsrenderer:function(aG,aF,aK,aJ,aI,aL){var aH=P.formatNumber(aK*1000,"f0")+" ml";if(aL.y_form==0){aH=P.formatNumber(aK,"f0")+" pk"}else{if(aL.y_form==1){aH=P.formatNumber(aK*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+aH+"</span>"}},{text:"Voorraad",datafield:"y_inventory",width:90,align:"right",cellsrenderer:function(aH,aG,aL,aK,aJ,aM){var aF="#ffffff";if(aL<aM.y_amount){aF="#ff4040"}var aI=P.formatNumber(aL*1000,"f0")+" ml";if(aM.y_form==0){aI=P.formatNumber(aL,"f0")+" pk"}else{if(aM.y_form==1){aI=P.formatNumber(aL*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+aF+';">'+aI+"</span>"}},{text:"",datafield:"Edit",columntype:"button",width:90,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(aF){ai=aF;f=$("#yeastGrid").jqxGrid("getrowdata",ai);if(f.y_form==0){$("#wy_pmpt_amount").html("Pak(ken):");$("#wy_amount").val(f.y_amount);$("#wy_amount").jqxNumberInput({decimalDigits:0})}else{if(f.y_form==1){$("#wy_pmpt_amount").html("Gewicht gram:");$("#wy_amount").val(f.y_amount*1000);$("#wy_amount").jqxNumberInput({decimalDigits:1})}else{$("#wy_pmpt_amount").html("Volume ml:");$("#wy_amount").val(f.y_amount*1000);$("#wy_amount").jqxNumberInput({decimalDigits:0})}}$("#wy_name").val(f.y_name);$("#wy_laboratory").val(f.y_laboratory);$("#wy_product_id").val(f.y_product_id);$("#wy_use").val(f.y_use);$("#popupYeast").jqxWindow("open")}}]})};var Z=function(aF){var aE=function(){var aG={};aG.step_name="Stap 1";aG.step_type=0;aG.step_infuse_amount=15;aG.step_temp=62;aG.step_time=20;aG.step_thickness=0;aG.ramp_time=1;aG.end_temp=62;return aG};var aD={localdata:aF.mashs,datatype:"local",cache:false,async:false,datafields:[{name:"step_name",type:"string"},{name:"step_type",type:"int"},{name:"step_infuse_amount",type:"float"},{name:"step_temp",type:"float"},{name:"step_time",type:"float"},{name:"step_thickness",type:"float"},{name:"ramp_time",type:"float"},{name:"end_temp",type:"float"}],addrow:function(aH,aJ,aG,aI){aI(true)},deleterow:function(aG,aH){aH(true)}};var aC=new $.jqx.dataAdapter(aD,{beforeLoadComplete:function(aG){w=0;var aI=new Array();for(var aH=0;aH<aG.length;aH++){var aJ=aG[aH];if(aJ.step_type==0){w+=parseFloat(aJ.step_infuse_amount)}aJ.step_thickness=0;aI.push(aJ)}},});$("#mashGrid").jqxGrid({width:1240,height:400,source:aC,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(aI){var aH=this;var aG=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");aI.append(aG);aG.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');aG.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder stap" />');$("#saddrowbutton").jqxButton({template:"primary",theme:theme,height:27,width:150});$("#saddrowbutton").on("click",function(){var aJ=aE();var aK=$("#mashGrid").jqxGrid("addrow",null,aJ)});$("#sdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#sdeleterowbutton").on("click",function(){var aJ=$("#mashGrid").jqxGrid("getselectedrowindex");var aM=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(aJ>=0&&aJ<aM){var aL=$("#mashGrid").jqxGrid("getrowid",aJ);var aK=$("#mashGrid").jqxGrid("deleterow",aL)}})},ready:function(){I();az();ar();$("#jqxLoader").jqxLoader("close");$("#jqxTabs").jqxTabs("first")},columns:[{text:"Stap naam",datafield:"step_name"},{text:"Stap type",datafield:"step_type",width:175,cellsrenderer:function(aH,aG,aK,aJ,aI,aL){return"<div style='margin: 4px;'>"+MashStepTypeData[aK].nl+"</div>"}},{text:"Start &deg;C",datafield:"step_temp",width:90,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Eind &deg;C",datafield:"end_temp",width:90,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Rust min.",datafield:"step_time",width:90,align:"right",cellsalign:"right"},{text:"Stap min.",datafield:"ramp_time",width:90,align:"right",cellsalign:"right"},{text:"Infuse L.",datafield:"step_infuse_amount",width:90,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"L/Kg.",datafield:"step_thickness",width:90,align:"right",cellsalign:"right",cellsformat:"f2"},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(aG){R=aG;y=$("#mashGrid").jqxGrid("getrowdata",R);$("#wstep_name").val(y.step_name);$("#wstep_type").val(y.step_type);$("#wstep_infuse_amount").val(y.step_infuse_amount);$("#wstep_temp").val(y.step_temp);$("#wend_temp").val(y.end_temp);$("#wstep_time").val(y.step_time);$("#wramp_time").val(y.ramp_time);if(y.step_type==0){$("#wstep_infuse_amount").show();$("#wstep_pmpt").show()}else{$("#wstep_infuse_amount").hide();$("#wstep_pmpt").hide()}$("#popupMash").jqxWindow("open")}}]})};$("#name").jqxTooltip({content:"De naam voor dit recept."});$("#name").jqxInput({theme:theme,width:640,height:23});$("#locked").jqxCheckBox({theme:theme,width:120,height:23});$("#notes").jqxTooltip({content:"De uitgebreide opmerkingen over dit recept."});$("#notes").jqxInput({theme:theme,width:960,height:200});$("#type").jqxTooltip({content:"Het brouw type van dit recept."});$("#type").jqxDropDownList({theme:theme,source:RecipeTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#efficiency").jqxTooltip({content:"Het rendement van maischen en koken."});$("#efficiency").jqxNumberInput(Perc1dec);$("#batch_size").jqxTooltip({content:"Het volume van het gekoelde wort na het koken."});$("#batch_size").jqxNumberInput(Spin1dec);$("#batch_size").jqxNumberInput({min:4});$("#boil_size").jqxTooltip({content:"Het volume van het wort voor het koken."});$("#boil_size").jqxNumberInput({inputMode:"simple",theme:theme,width:90,height:23,decimalDigits:2,readOnly:true});$("#boil_time").jqxTooltip({content:"De kooktijd in minuten."});$("#boil_time").jqxNumberInput(PosInt);$("#boil_time").jqxNumberInput({min:4,max:360});$("#st_name").jqxTooltip({content:"De bierstijl naam voor dit recept."});$("#st_name").jqxInput({theme:theme,width:250,height:23});$("#st_letter").jqxTooltip({content:"De bierstijl letter voor dit recept."});$("#st_letter").jqxInput({theme:theme,width:90,height:23});$("#st_guide").jqxTooltip({content:"De bierstijl gids voor dit recept."});$("#st_guide").jqxInput({theme:theme,width:250,height:23});$("#st_category").jqxTooltip({content:"De Amerikaanse bierstijl categorie."});$("#st_category").jqxInput({theme:theme,width:250,height:23});$("#st_category_number").jqxTooltip({content:"De Amerikaanse bierstijl categorie sub nummer."});$("#st_category_number").jqxNumberInput(Smal0dec);$("#st_type").jqxTooltip({content:"Het bierstijl type."});$("#st_type").jqxInput({theme:theme,width:250,height:23});$("#est_og").jqxTooltip({content:"Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend."});$("#est_og").jqxNumberInput(SGopts);$("#st_og_min").jqxTooltip({content:"Het minimum begin SG voor deze bierstijl."});$("#st_og_min").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#st_og_max").jqxTooltip({content:"Het maximum begin SG voor deze bierstijl."});$("#st_og_max").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#est_fg").jqxTooltip({content:"Het eind SG. Dit wordt automatisch berekend."});$("#est_fg").jqxNumberInput(Show3dec);$("#st_fg_min").jqxTooltip({content:"Het minimum eind SG voor deze bierstijl."});$("#st_fg_min").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#st_fg_max").jqxTooltip({content:"Het maximum eind SG voor deze bierstijl."});$("#st_fg_max").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#est_abv").jqxTooltip({content:"Alcohol volume %. Dit wordt automatisch berekend."});$("#est_abv").jqxNumberInput(Smal1dec);$("#st_abv_min").jqxTooltip({content:"Het minimum alcohol volume % voor deze bierstijl."});$("#st_abv_min").jqxNumberInput(Smal1dec);$("#st_abv_max").jqxTooltip({content:"Het maximum alcohol volume % voor deze bierstijl."});$("#st_abv_max").jqxNumberInput(Smal1dec);$("#est_color").jqxTooltip({content:"De kleur in EBC. Dit wordt automatisch berekend."});$("#est_color").jqxNumberInput(Show0dec);$("#st_color_min").jqxTooltip({content:"De minimum kleur voor deze bierstijl."});$("#st_color_min").jqxNumberInput(Smal0dec);$("#st_color_max").jqxTooltip({content:"De maximum kleur voor deze bierstijl."});$("#st_color_max").jqxNumberInput(Smal0dec);$("#color_method").jqxDropDownList({theme:theme,source:ColorMethodAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#est_ibu").jqxTooltip({content:"De bitterheid in IBU. Dit wordt automatisch berekend."});$("#est_ibu").jqxNumberInput(Show0dec);$("#st_ibu_min").jqxTooltip({content:"De minimum bitterheid voor deze bierstijl."});$("#st_ibu_min").jqxNumberInput(Smal0dec);$("#st_ibu_max").jqxTooltip({content:"De maximum bitterheid voor deze bierstijl."});$("#st_ibu_max").jqxNumberInput(Smal0dec);$("#ibu_method").jqxDropDownList({theme:theme,source:IBUmethodAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#kcal").jqxTooltip({content:"Energie-inhoud in kcal/liter."});$("#kcal").jqxNumberInput(Smal0dec);$("#est_carb").jqxTooltip({content:"Koolzuur volume. Dit wordt automatisch berekend."});$("#est_carb").jqxNumberInput(Smal1dec);$("#st_carb_min").jqxTooltip({content:"Het minimum koolzuur volume voor deze bierstijl."});$("#st_carb_min").jqxNumberInput(Smal1dec);$("#st_carb_max").jqxTooltip({content:"Het maximum koolzuur volume voor deze bierstijl."});$("#st_carb_max").jqxNumberInput(Smal1dec);$("#est_color2").jqxTooltip({content:"De kleur in EBC. Dit wordt automatisch berekend."});$("#est_color2").jqxNumberInput(Show0dec);$("#est_og2").jqxTooltip({content:"Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend."});$("#est_og2").jqxNumberInput(Show3dec);$("#perc_malts").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:120,animationDuration:0,colorRanges:[{stop:90,color:"#008C00"},{stop:100,color:"#EB7331"},{stop:120,color:"#FF0000"}],renderText:function(aC){return(Math.round(parseInt(aC)*1.2))+"%"}});$("#perc_sugars").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:50,animationDuration:0,colorRanges:[{stop:20,color:"#008C00"},{stop:50,color:"#FF0000"}],renderText:function(aC){return(Math.round(parseInt(aC)*5)/10)+"%"}});$("#perc_cara").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:50,animationDuration:0,colorRanges:[{stop:25,color:"#008C00"},{stop:50,color:"#FF0000"}],renderText:function(aC){return(Math.round(parseInt(aC)*5)/10)+"%"}});$("#ferm_lintner").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:200,animationDuration:0,colorRanges:[{stop:30,color:"#FF0000"},{stop:40,color:"#EB7331"},{stop:200,color:"#008C00"}],renderText:function(aC){return(parseInt(aC)*2)+" lintner"}});$("#popupFermentable").jqxWindow({width:800,height:300,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#FermentableReady"),modalOpacity:0.4});$("#FermentableReady").jqxButton({template:"success",width:"90px",theme:theme});$("#FermentableReady").click(function(){var aC=$("#fermentableGrid").jqxGrid("getrowid",r);console.log("FermentableReady row:"+r+" ID:"+aC);var aD={f_name:ao.f_name,f_origin:ao.f_origin,f_supplier:ao.f_supplier,f_amount:ao.f_amount,f_cost:ao.f_cost,f_type:ao.f_type,f_yield:ao.f_yield,f_color:ao.f_color,f_coarse_fine_diff:ao.f_coarse_fine_diff,f_moisture:ao.f_moisture,f_diastatic_power:ao.f_diastatic_power,f_protein:ao.f_protein,f_max_in_batch:ao.f_max_in_batch,f_graintype:ao.f_graintype,f_added:ao.f_added,f_dissolved_protein:ao.f_dissolved_protein,f_recommend_mash:ao.f_recommend_mash,f_add_after_boil:ao.f_add_after_boil,f_adjust_to_total_100:ao.f_adjust_to_total_100,f_percentage:ao.f_percentage,f_di_ph:ao.f_di_ph,f_acid_to_ph_57:ao.f_acid_to_ph_57,f_inventory:ao.f_inventory,f_avail:ao.f_avail};$("#fermentableGrid").jqxGrid("updaterow",aC,aD);ay();I();X();ar()});$("#wf_name").jqxInput({theme:theme,width:320,height:23});$("#wf_instock").jqxCheckBox({theme:theme,height:23});$("#wf_instock").on("change",function(aC){fermentableinstock=aC.args.checked;fermentablelist.dataBind()});$("#wf_select").jqxDropDownList({placeHolder:"Kies mout:",theme:theme,source:fermentablelist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500,renderer:function(aD,aC,aF){var aE=fermentablelist.records[aD];return aE.supplier+" / "+aE.name+" ("+aE.color+" EBC)"}});$("#wf_select").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=fermentablelist.records[aC];$("#wf_name").val(aD.name);ao.f_name=aD.name;ao.f_origin=aD.origin;ao.f_supplier=aD.supplier;ao.f_type=aD.type;ao.f_cost=aD.cost;ao.f_yield=aD.yield;ao.f_color=aD.color;ao.f_coarse_fine_diff=aD.coarse_fine_diff;ao.f_moisture=aD.moisture;ao.f_diastatic_power=aD.diastatic_power;ao.f_protein=aD.protein;ao.f_max_in_batch=aD.max_in_batch;ao.f_graintype=aD.graintype;ao.f_dissolved_protein=aD.dissolved_protein;ao.f_recommend_mash=aD.recommend_mash;ao.f_add_after_boil=aD.add_after_boil;ao.f_di_ph=aD.di_ph;ao.f_acid_to_ph_57=aD.acid_to_ph_57;ao.f_inventory=aD.inventory}});$("#wf_amount").jqxNumberInput(Spin3dec);$("#wf_amount").on("change",function(aC){console.log("amount changed: "+aC.args.value);$("#fermentableGrid").jqxGrid("setcellvalue",r,"f_amount",aC.args.value);ao.f_amount=aC.args.value;if(!k){ay();I();ar()}});$("#wf_percentage").jqxNumberInput(Perc1dec);$("#wf_percentage").on("change",function(aD){var aE=Math.round(ao.f_percentage*10)/10;var aF=aD.args.value;console.log("percentage changed: "+aF+" old: "+aE);ao.f_percent=aF;var aJ=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if((aE!=aF)&&(aJ>1)){var aL=$("#fermentableGrid").jqxGrid("getrowdata",r);if(aL.f_adjust_to_total_100){$("#wf_percentage").val(aE)}else{var aK=aF-aE;var aG=0;for(i=0;i<aJ;i++){var aL=$("#fermentableGrid").jqxGrid("getrowdata",i);if(aL.f_added<4){aG+=Math.round(aL.f_amount*1000)/1000}}aG=Math.round(aG*1000)/1000;if(k){var aI=Math.round(aG*aK*10)/1000;var aL=$("#fermentableGrid").jqxGrid("getrowdata",r);var aC=Math.round((aL.f_amount+aI)*1000)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",r,"f_amount",aC);$("#wf_amount").val(aC);$("#fermentableGrid").jqxGrid("setcellvalue",r,"f_percentage",aL.f_percentage+aK);for(i=0;i<aJ;i++){var aL=$("#fermentableGrid").jqxGrid("getrowdata",i);if(aL.f_adjust_to_total_100){aC=aL.f_amount-aI;$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_percentage",aL.f_percentage-aK);$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_amount",aC)}}I();cacMash()}else{var aH=aG*aK/100;for(i=0;i<aJ;i++){var aL=$("#fermentableGrid").jqxGrid("getrowdata",i);if(aL.f_added<4){if(i==r){var aC=Math.round((aL.f_amount+aH)*1000)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_amount",aC);$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_percentage",aF)}else{var aC=Math.round((aL.f_amount-(aH/(aJ-1)))*1000)/1000;var aM=Math.round((aC/aG)*1000)/10;$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_amount",aC);$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_percentage",aM)}}else{$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_percentage",0)}}I();ar()}}}});$("#wf_max_in_batch").jqxNumberInput(Show1dec);$("#wf_adjust_to_total_100").jqxCheckBox({theme:theme,width:120,height:23});$("#wf_adjust_to_total_100").on("checked",function(aD){if(ao.f_adjust_to_total_100==0){if(k){var aE=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(var aC=0;aC<aE;aC++){if(aC!=r){$("#fermentableGrid").jqxGrid("setcellvalue",aC,"f_adjust_to_total_100",0)}}}$("#fermentableGrid").jqxGrid("setcellvalue",r,"f_adjust_to_total_100",1);I()}});$("#wf_adjust_to_total_100").on("unchecked",function(aC){if(ao.f_adjust_to_total_100!=0){$("#fermentableGrid").jqxGrid("setcellvalue",r,"f_adjust_to_total_100",0);I()}});$("#wf_added").jqxDropDownList({theme:theme,source:AddedAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wf_added").on("select",function(aD){if(aD.args){var aC=aD.args.index;$("#fermentableGrid").jqxGrid("setcellvalue",r,"f_added",aC);I();X();ar()}});$("#est_ibu2").jqxTooltip({content:"De bitterheid in IBU. Dit wordt automatisch berekend."});$("#est_ibu2").jqxNumberInput(Smal0dec);$("#hop_flavour").jqxProgressBar({width:300,height:23,theme:theme,showText:true,animationDuration:0,colorRanges:[{stop:20,color:"#004D00"},{stop:40,color:"#008C00"},{stop:60,color:"#00BF00"},{stop:80,color:"#00FF00"},{stop:100,color:"#80FF80"}],renderText:function(aD){var aC=parseInt(aD);if(aC<20){return"Weinig"}else{if(aC<40){return"Matig"}else{if(aC<60){return"Redelijk"}else{if(aC<80){return"Veel"}else{return"Zeer veel"}}}}}});$("#hop_aroma").jqxProgressBar({width:300,height:23,theme:theme,showText:true,animationDuration:0,colorRanges:[{stop:20,color:"#004D00"},{stop:40,color:"#008C00"},{stop:60,color:"#00BF00"},{stop:80,color:"#00FF00"},{stop:100,color:"#80FF80"}],renderText:function(aD){var aC=parseInt(aD);if(aC<20){return"Weinig"}else{if(aC<40){return"Matig"}else{if(aC<60){return"Redelijk"}else{if(aC<80){return"Veel"}else{return"Zeer veel"}}}}}});$("#popupHop").jqxWindow({width:800,height:300,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#HopReady"),modalOpacity:0.4});$("#HopReady").jqxButton({template:"success",width:"90px",theme:theme});$("#HopReady").click(function(){var aC=$("#hopGrid").jqxGrid("getrowid",b);console.log("HopReady row:"+b+" ID:"+aC);var aD={h_name:$("#wh_name").val(),h_origin:e.h_origin,h_amount:parseFloat($("#wh_amount").jqxNumberInput("decimal"))/1000,h_cost:e.h_cost,h_type:e.h_type,h_form:e.h_form,h_useat:$("#wh_useat").val(),h_time:e.h_time,h_alpha:e.h_alpha,h_beta:e.h_beta,h_hsi:e.h_hsi,h_humulene:e.h_humulene,h_caryophyllene:e.h_caryophyllene,h_cohumulone:e.h_cohumulone,h_myrcene:e.h_myrcene,h_total_oil:e.h_total_oil,h_inventory:e.h_inventory,h_avail:e.h_avail};$("#hopGrid").jqxGrid("updaterow",aC,aD);X()});$("#wh_name").jqxInput({theme:theme,width:320,height:23});$("#wh_instock").jqxCheckBox({theme:theme,height:23});$("#wh_instock").on("change",function(aC){hopinstock=aC.args.checked;hoplist.dataBind()});$("#wh_select").jqxDropDownList({placeHolder:"Kies hop:",theme:theme,source:hoplist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500,renderer:function(aD,aC,aF){var aE=hoplist.records[aD];return aE.origin+" / "+aE.name+" ("+aE.alpha+" % &alpha;)"}});$("#wh_select").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=hoplist.records[aC];$("#wh_name").val(aD.name);e.h_name=aD.name;e.h_origin=aD.origin;e.h_cost=aD.cost;e.h_type=aD.type;e.h_form=aD.form;e.h_alpha=aD.alpha;e.h_beta=aD.beta;e.h_hsi=aD.hsi;e.h_humulene=aD.humulene;e.h_caryophyllene=aD.caryophyllene;e.h_cohumulone=aD.cohumulone;e.h_myrcene=aD.myrcene;e.h_total_oil=aD.total_oil;e.h_inventory=aD.inventory}});$("#wh_amount").jqxNumberInput(Spin1dec);$("#wh_amount").on("change",function(aD){console.log("amount changed: "+aD.args.value+" time:"+e.h_time+" alpha:"+e.h_alpha);var aC=parseFloat(aD.args.value)/1000;var aE=toIBU(e.h_useat,e.h_form,S,parseFloat($("#batch_size").jqxNumberInput("decimal")),aC,parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());e.h_amount=aC;$("#wh_ibu").val(aE)});$("#wh_ibu").jqxNumberInput(Show1dec);$("#wh_time").jqxNumberInput(PosInt);$("#wh_time").on("change",function(aC){var aD=parseFloat(aC.args.value);if(e.h_useat==2){if(aD>parseFloat($("#boil_time").jqxNumberInput("decimal"))){aD=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wh_time").val(aD)}e.h_time=aD}else{if(e.h_useat==4){if(aD>120){aD=120;$("#wh_time").val(aD)}e.h_time=aD}else{if(e.h_useat==5){if(aD>21){aD=21;$("#wh_time").val(aD)}e.h_time=aD*1440}}}var aE=toIBU(e.h_useat,e.h_form,S,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(e.h_amount),parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(aE)});$("#wh_useat").jqxDropDownList({theme:theme,source:HopUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wh_useat").on("select",function(aD){if(aD.args){var aC=aD.args.index;e.h_useat=aC;if((aC==0)||(aC==1)){e.h_time=parseFloat(d.boil_time);$("#wh_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wh_time").val(e.h_time)}else{if(aC==3){e.h_time=0;$("#wh_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wh_time").val(0)}else{$("#wh_time").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}}if(aC==5){$("#wh_pmpt_time").html("Tijd in dagen")}else{$("#wh_pmpt_time").html("Tijd in minuten")}}});$("#popupMisc").jqxWindow({width:800,height:275,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#MiscReady"),modalOpacity:0.4});$("#MiscReady").jqxButton({template:"success",width:"90px",theme:theme});$("#MiscReady").click(function(){var aC=$("#miscGrid").jqxGrid("getrowid",ab);console.log("MiscReady row:"+ab+" ID:"+aC);var aD={m_name:ak.m_name,m_amount:ak.m_amount,m_cost:ak.m_cost,m_type:ak.m_type,m_use_use:ak.m_use_use,m_time:ak.m_time,m_amount_is_weight:ak.m_amount_is_weight,m_inventory:ak.m_inventory,m_avail:ak.m_avail};$("#miscGrid").jqxGrid("updaterow",aC,aD)});$("#wm_name").jqxInput({theme:theme,width:320,height:23});$("#wm_instock").jqxCheckBox({theme:theme,height:23});$("#wm_instock").on("change",function(aC){miscinstock=aC.args.checked;misclist.dataBind()});$("#wm_select").jqxDropDownList({placeHolder:"Kies ingredi&euml;nt:",theme:theme,source:misclist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500});$("#wm_select").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=misclist.records[aC];$("#wm_name").val(aD.name);ak.m_name=aD.name;ak.m_cost=aD.cost;ak.m_type=aD.type;ak.m_use_use=aD.use_use;ak.m_amount_is_weight=aD.amount_is_weight;ak.m_inventory=aD.inventory}});$("#wm_amount").jqxNumberInput(Spin1dec);$("#wm_amount").on("change",function(aC){console.log("amount changed: "+aC.args.value);ak.m_amount=parseFloat(aC.args.value)/1000});$("#wm_time").jqxNumberInput(PosInt);$("#wm_time").on("change",function(aC){console.log("time changed: "+aC.args.value);var aD=parseFloat(aC.args.value);if(ak.m_use_use==2){if(aD>parseFloat($("#boil_time").jqxNumberInput("decimal"))){aD=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wm_time").val(aD)}ak.m_time=aD}else{if((ak.m_use_use==3)||(ak.m_use_use==4)){if(aD>21){aD=21;$("#wm_time").val(aD)}ak.m_time=aD*1440}}});$("#wm_use_use").jqxDropDownList({theme:theme,source:MiscUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wm_use_use").on("select",function(aD){if(aD.args){var aC=aD.args.index;ak.m_use_use=aC;if((aC==2)||(aC==3)||(aC==4)){$("#wm_time").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}else{ak.m_time=0;$("#wm_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wm_time").val(0)}}});$("#est_fg2").jqxTooltip({content:"Het eind SG. Dit wordt automatisch berekend."});$("#est_fg2").jqxNumberInput(Show3dec);$("#est_abv2").jqxTooltip({content:"Alcohol volume %. Dit wordt automatisch berekend."});$("#est_abv2").jqxNumberInput(Smal1dec);$("#popupYeast").jqxWindow({width:800,height:300,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#YeastReady"),modalOpacity:0.4});$("#YeastReady").jqxButton({template:"success",width:"90px",theme:theme});$("#YeastReady").click(function(){var aC=$("#yeastGrid").jqxGrid("getrowid",ai);console.log("YeastReady row:"+ai+" ID:"+aC);var aD={y_name:f.y_name,y_laboratory:f.y_laboratory,y_product_id:f.y_product_id,y_amount:f.y_amount,y_cost:f.y_cost,y_type:f.y_type,y_form:f.y_form,y_flocculation:f.y_flocculation,y_min_temperature:f.y_min_temperature,y_max_temperature:f.y_max_temperature,y_attenuation:f.y_attenuation,y_use:f.y_use,y_cells:f.y_cells,y_tolerance:f.y_tolerance,y_inventory:f.y_inventory,y_avail:f.y_avail};$("#yeastGrid").jqxGrid("updaterow",aC,aD);I()});$("#wy_name").jqxInput({theme:theme,width:320,height:23});$("#wy_laboratory").jqxInput({theme:theme,width:320,height:23});$("#wy_product_id").jqxInput({theme:theme,width:320,height:23});$("#wy_instock").jqxCheckBox({theme:theme,height:23});$("#wy_instock").on("change",function(aC){yeastinstock=aC.args.checked;yeastlist.dataBind()});$("#wy_select").jqxDropDownList({placeHolder:"Kies gist:",theme:theme,source:yeastlist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500,renderer:function(aD,aC,aF){var aE=yeastlist.records[aD];return aE.laboratory+" "+aE.product_id+" "+aE.name}});$("#wy_select").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=yeastlist.records[aC];$("#wy_name").val(aD.name);$("#wy_laboratory").val(aD.laboratory);$("#wy_product_id").val(aD.product_id);f.y_name=aD.name;f.y_cost=aD.cost;f.y_type=aD.type;f.y_form=aD.form;f.y_laboratory=aD.laboratory;f.y_product_id=aD.product_id;f.y_min_temperature=aD.min_temperature;f.y_max_temperature=aD.max_temperature;f.y_flocculation=aD.flocculation;f.y_attenuation=aD.attenuation;f.y_cells=aD.cells;f.y_inventory=aD.inventory;if(f.y_form==0){$("#wy_pmpt_amount").html("Pak(ken):")}else{if(f.y_form==1){$("#wy_pmpt_amount").html("Gewicht gram:")}else{$("#wy_pmpt_amount").html("Volume ml:")}}I()}});$("#wy_amount").jqxNumberInput(Spin1dec);$("#wy_amount").on("change",function(aD){console.log("amount changed: "+aD.args.value);if(f.y_form==0){var aC=parseFloat(aD.args.value)}else{var aC=parseFloat(aD.args.value)/1000}f.y_amount=aC;I()});$("#wy_use").jqxDropDownList({theme:theme,source:YeastUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wy_use").on("select",function(aD){if(aD.args){var aC=aD.args.index;f.y_use=aC;calcFermentabes()}});$("#mash_name").jqxInput({theme:theme,width:320,height:23});$("#mash_select").jqxDropDownList({placeHolder:"Kies schema:",theme:theme,source:mashlist,displayMember:"name",width:250,height:23,dropDownWidth:500,dropDownHeight:500,dropDownHorizontalAlignment:"right"});$("#mash_select").on("select",function(aC){if(aC.args){var aI=aC.args.index;var aH=new Array();var aK=$("#mashGrid").jqxGrid("getdisplayrows");for(var aF=0;aF<aK.length;aF++){var aJ=aK[aF];aH.push(aJ.uid)}$("#mashGrid").jqxGrid("deleterow",aH);var aG=mashlist.records[aI];$("#mash_name").val(aG.name);for(var aF=0;aF<aG.steps.length;aF++){var aE=aG.steps[aF];var aJ={};aJ.step_name=aE.step_name;aJ.step_type=aE.step_type;if(w==0&&d.w1_amount>0){w=d.w1_amount}if(aF==0){aJ.step_infuse_amount=w}else{aJ.step_infuse_amount=0}aJ.step_temp=aE.step_temp;if(V>0){aJ.step_thickness=parseFloat(w/V)}else{aJ.step_thickness=0}aJ.end_temp=aE.end_temp;aJ.step_time=aE.step_time;aJ.ramp_time=aE.ramp_time;var aD=$("#mashGrid").jqxGrid("addrow",null,aJ)}}});$("#popupMash").jqxWindow({width:800,height:350,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#MashReady"),modalOpacity:0.4});$("#MashReady").jqxButton({template:"success",width:"90px",theme:theme});$("#MashReady").click(function(){ar()});$("#wstep_name").jqxInput({theme:theme,width:320,height:23});$("#wstep_name").on("change",function(aC){var aD=$("#mashGrid").jqxGrid("getrowdata",R);aD.step_name=aC.args.value});$("#wstep_type").jqxDropDownList({theme:theme,source:MashStepTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#wstep_type").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aH=$("#mashGrid").jqxGrid("getrowdata",R);aH.step_type=aC;if(aC==0){$("#wstep_infuse_amount").show();$("#wstep_pmpt").show()}else{aH.step_infuse_amount=0;$("#wstep_infuse_amount").hide();$("#wstep_pmpt").hide()}w=0;var aF=$("#mashGrid").jqxGrid("getrows");for(var aD=0;aD<aF.length;aD++){var aG=aF[aD];if(aG.step_type==0){w+=parseFloat(aG.step_infuse_amount)}}}});$("#wstep_temp").jqxNumberInput(Spin1dec);$("#wstep_temp").on("change",function(aC){var aD=$("#mashGrid").jqxGrid("getrowdata",R);aD.step_temp=parseFloat(aC.args.value)});$("#wend_temp").jqxNumberInput(Spin1dec);$("#wend_temp").on("change",function(aC){var aD=$("#mashGrid").jqxGrid("getrowdata",R);aD.end_temp=parseFloat(aC.args.value)});$("#wstep_time").jqxNumberInput(PosInt);$("#wstep_time").on("change",function(aC){var aD=$("#mashGrid").jqxGrid("getrowdata",R);aD.step_time=parseFloat(aC.args.value)});$("#wramp_time").jqxNumberInput(PosInt);$("#wramp_time").on("change",function(aC){var aD=$("#mashGrid").jqxGrid("getrowdata",R);aD.ramp_time=parseFloat(aC.args.value)});$("#wstep_infuse_amount").jqxNumberInput(Spin1dec);$("#wstep_infuse_amount").on("change",function(aD){var aG=$("#mashGrid").jqxGrid("getrowdata",R);aG.step_infuse_amount=parseFloat(aD.args.value);w=0;var aE=$("#mashGrid").jqxGrid("getrows");for(var aC=0;aC<aE.length;aC++){var aF=aE[aC];if(aF.step_type==0){w+=parseFloat(aF.step_infuse_amount)}}if(d.w2_amount==0){d.w1_amount=w;$("#w1_amount").val(w)}else{d.w1_amount=(d.w1_amount/(d.w1_amount+d.w2_amount))*w;d.w2_amount=(d.w2_amount/(d.w1_amount+d.w2_amount))*w;$("#w1_amount").val(d.w1_amount);$("#w2_amount").val(d.w2_amount)}$("#wg_amount").val(w)});$("#tgt_bu").jqxNumberInput(Show2wat);$("#tgt_cl_so4").jqxNumberInput(Show1wat);$("#got_cl_so4").jqxNumberInput(Show1wat);$("#w1_name").jqxDropDownList({placeHolder:"Kies hoofd water:",theme:theme,source:waterlist,displayMember:"name",width:250,height:27,dropDownWidth:400,dropDownHeight:400});$("#w1_name").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=waterlist.records[aC];d.w1_name=aD.name;$("#w1_calcium").val(aD.calcium);d.w1_calcium=aD.calcium;$("#w1_sulfate").val(aD.sulfate);d.w1_sulfate=aD.sulfate;$("#w1_chloride").val(aD.chloride);d.w1_chloride=aD.chloride;$("#w1_sodium").val(aD.sodium);d.w1_sodium=aD.sodium;$("#w1_magnesium").val(aD.magnesium);d.w1_magnesium=aD.magnesium;$("#w1_total_alkalinity").val(aD.total_alkalinity);d.w1_total_alkalinity=aD.total_alkalinity;$("#w1_ph").val(aD.ph);d.w1_ph=aD.ph;$("#w1_cost").val(aD.cost);d.w1_cost=aD.cost;G()}});$("#w1_amount").jqxNumberInput(Show1wat);$("#w1_calcium").jqxNumberInput(Show1wat);$("#w1_magnesium").jqxNumberInput(Show1wat);$("#w1_sodium").jqxNumberInput(Show1wat);$("#w1_total_alkalinity").jqxNumberInput(Show1wat);$("#w1_chloride").jqxNumberInput(Show1wat);$("#w1_sulfate").jqxNumberInput(Show1wat);$("#w1_ph").jqxNumberInput(Show1wat);$("#w2_name").jqxDropDownList({placeHolder:"Kies meng water:",theme:theme,source:waterlist,displayMember:"name",width:250,height:27,dropDownWidth:400,dropDownHeight:400});$("#w2_name").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=waterlist.records[aC];d.w2_name=aD.name;$("#w2_calcium").val(aD.calcium);d.w2_calcium=aD.calcium;$("#w2_sulfate").val(aD.sulfate);d.w2_sulfate=aD.sulfate;$("#w2_chloride").val(aD.chloride);d.w2_chloride=aD.chloride;$("#w2_sodium").val(aD.sodium);d.w2_sodium=aD.sodium;$("#w2_magnesium").val(aD.magnesium);d.w2_magnesium=aD.magnesium;$("#w2_total_alkalinity").val(aD.total_alkalinity);d.w2_total_alkalinity=aD.total_alkalinity;$("#w2_ph").val(aD.ph);d.w2_ph=aD.ph;$("#w2_cost").val(aD.cost);d.w2_cost=aD.cost;$("#w2_amount").jqxNumberInput({max:100000,readOnly:false});G()}});$("#w2_amount").jqxTooltip({content:"De verdeling van het hoofd en meng water. Het totale maisch water volume blijft gelijk."});$("#w2_amount").jqxNumberInput({inputMode:"simple",theme:theme,width:94,height:23,min:0,max:0,decimalDigits:1,spinButtons:true,readOnly:true});$("#w2_calcium").jqxNumberInput(Show1wat);$("#w2_magnesium").jqxNumberInput(Show1wat);$("#w2_sodium").jqxNumberInput(Show1wat);$("#w2_total_alkalinity").jqxNumberInput(Show1wat);$("#w2_chloride").jqxNumberInput(Show1wat);$("#w2_sulfate").jqxNumberInput(Show1wat);$("#w2_ph").jqxNumberInput(Show1wat);$("#wg_amount").jqxNumberInput(Show1wat);$("#wg_calcium").jqxNumberInput(Show1wat);$("#wg_magnesium").jqxNumberInput(Show1wat);$("#wg_sodium").jqxNumberInput(Show1wat);$("#wg_total_alkalinity").jqxNumberInput(Show1wat);$("#wg_chloride").jqxNumberInput(Show1wat);$("#wg_sulfate").jqxNumberInput(Show1wat);$("#wg_ph").jqxNumberInput(Show1wat);$("#wb_calcium").jqxTooltip({content:"De ideale hoeveelheid Calcium is tussen 40 en 150."});$("#wb_calcium").jqxNumberInput(Show1wat);$("#wb_magnesium").jqxTooltip({content:"De ideale hoeveelheid Magnesium is lager dan 30."});$("#wb_magnesium").jqxNumberInput(Show1wat);$("#wb_sodium").jqxTooltip({content:"De ideale hoeveelheid Natrium is lager dan 150."});$("#wb_sodium").jqxNumberInput(Show1wat);$("#wb_chloride").jqxTooltip({content:"De ideale hoeveelheid Chloride is tussen 50 en 100."});$("#wb_chloride").jqxNumberInput(Show1wat);$("#wb_sulfate").jqxTooltip({content:"De ideale hoeveelheid Sulfaat is tussen 50 en 350."});$("#wb_sulfate").jqxNumberInput(Show1wat);$("#wb_total_alkalinity").jqxNumberInput(Show1wat);$("#wb_ph").jqxNumberInput(Show1wat);$("#pr_name").jqxDropDownList({placeHolder:"Kies doel profiel:",theme:theme,source:waterprofiles,displayMember:"name",width:250,height:27,dropDownWidth:400,dropDownHeight:300});$("#pr_name").on("select",function(aE){if(aE.args){var aC=aE.args.index;var aD=waterprofiles.records[aC];$("#pr_calcium").val(aD.calcium);$("#pr_sulfate").val(aD.sulfate);$("#pr_chloride").val(aD.chloride);$("#pr_sodium").val(aD.sodium);$("#pr_magnesium").val(aD.magnesium);$("#pr_total_alkalinity").val(aD.total_alkalinity)}});$("#pr_calcium").jqxNumberInput(Show1wat);$("#pr_magnesium").jqxNumberInput(Show1wat);$("#pr_sodium").jqxNumberInput(Show1wat);$("#pr_total_alkalinity").jqxNumberInput(Show1wat);$("#pr_chloride").jqxNumberInput(Show1wat);$("#pr_sulfate").jqxNumberInput(Show1wat);$("#wa_cacl2").jqxTooltip({content:"Voor het maken van een ander waterprofiel. Voegt calcium en chloride toe. Voor het verbeteren van zoetere bieren."});$("#wa_cacl2").jqxNumberInput(Spin1dec);$("#wa_caso4").jqxTooltip({content:"Gips. Voor het maken van een ander waterprofiel. Voegt calcium en sulfaat toe. Voor het verbeteren van bittere bieren."});$("#wa_caso4").jqxNumberInput(Spin1dec);$("#wa_mgso4").jqxTooltip({content:"Epsom zout. Voor het maken van een ander waterprofiel. Voegt magnesium en sulfaat toe. Gebruik spaarzaam!"});$("#wa_mgso4").jqxNumberInput(Spin1dec);$("#wa_nacl").jqxTooltip({content:"Keukenzout. Voor het maken van een ander waterprofiel. Voegt natrium en chloride toe. Voor het accentueren van zoetheid. Bij hoge dosering wordt het bier ziltig."});$("#wa_nacl").jqxNumberInput(Spin1dec);$("#mash_ph").jqxTooltip({content:"Maisch pH tussen 5.2 en 5.6. Gebruik 5.2 voor lichte en 5.5 voor donkere bieren."});$("#mash_ph").jqxNumberInput(SpinpH);$("#calc_acid").jqxCheckBox({theme:theme,width:120,height:23});$("#wa_base_name").jqxDropDownList({theme:theme,source:BaseTypeAdapter,valueMember:"id",displayMember:"nl",width:170,height:23,autoDropDownHeight:true});$("#wa_base").jqxNumberInput(Spin2dec);$("#wa_base").jqxNumberInput({symbol:" gr",symbolPosition:"right"});$("#wa_acid_name").jqxDropDownList({theme:theme,source:AcidTypeAdapter,valueMember:"id",displayMember:"nl",width:170,height:23,autoDropDownHeight:true});$("#wa_acid").jqxNumberInput(Spin2dec);$("#wa_acid").jqxNumberInput({symbol:" ml",symbolPosition:"right"});$("#wa_acid_perc").jqxNumberInput(Perc0);$("#wa_acid_perc").jqxNumberInput({width:70,symbol:"%",symbolPosition:"right"});$("#sparge_temp").jqxNumberInput(Spin1dec);$("#sparge_volume").jqxNumberInput(Spin1dec);$("#sparge_ph").jqxNumberInput(SpinpH);$("#sparge_source").jqxDropDownList({theme:theme,source:SpargeSourceAdapter,valueMember:"id",displayMember:"nl",width:110,height:23,autoDropDownHeight:true});$("#sparge_acid_amount").jqxNumberInput(Spin2dec);$("#sparge_acid_amount").jqxNumberInput({spinButtons:false,readOnly:true,symbol:" ml",symbolPosition:"right"});$("#sparge_acid_type").jqxDropDownList({theme:theme,source:AcidTypeAdapter,valueMember:"id",displayMember:"nl",width:110,height:23,autoDropDownHeight:true});$("#sparge_acid_perc").jqxNumberInput(Perc0);$("#sparge_acid_perc").jqxNumberInput({symbol:"%",symbolPosition:"right"});$("#jqxTabs").jqxTabs({theme:theme,width:1280,height:660,autoHeight:false,position:"top"});$("#Export").jqxButton({template:"info",width:"80px",theme:theme});$("#Export").bind("click",function(){q();var aC="rec_export.php?record="+my_record+"&return="+my_return+"&name="+d.name;window.location.href=aC});$("#Delete").jqxButton({template:"danger",width:"80px",theme:theme});$("#Delete").bind("click",function(){$("#eventWindow").jqxWindow("open");$("#delOk").click(function(){var aC="delete=true&"+$.param({record:my_record});$.ajax({dataType:"json",url:z,cache:false,data:aC,type:"POST",success:function(aE,aD,aF){window.location.href=my_return},error:function(aD,aF,aE){}})})});$("#Cancel").jqxButton({template:"primary",width:"80px",theme:theme});$("#Cancel").bind("click",function(){window.location.href=my_return});$("#Save").jqxButton({template:"success",width:"80px",theme:theme});$("#Save").bind("click",function(){q();window.location.href=my_return});createDelElements()});
\ No newline at end of file
+var psugar=0,pcara=0,svg=77,mashkg=0,mash_infuse=0,dataRecord={},hop_flavour=0,hop_aroma=0,preboil_sg=0,last_base="",last_acid="",Ka1=4.445e-7,Ka2=4.68e-11,MMCa=40.048,MMMg=24.305,MMNa=22.98976928,MMCl=35.453,MMSO4=96.0626,MMCO3=60.01684,MMHCO3=61.01684,MMCaSO4=172.171,MMCaCl2=147.015,MMCaCO3=100.087,MMMgSO4=246.475,MMNaHCO3=84.007,MMNa2CO3=105.996,MMNaCl=58.443,MMCaOH2=74.06268;function createDelElements(){$("#eventWindow").jqxWindow({theme:theme,position:{x:490,y:210},width:300,height:175,resizable:false,isModal:true,modalOpacity:0.4,okButton:$("#delOk"),cancelButton:$("#delCancel"),initContent:function(){$("#delOk").jqxButton({template:"danger",width:"65px",theme:theme});$("#delCancel").jqxButton({template:"success",width:"65px",theme:theme});$("#delCancel").focus()}});$("#eventWindow").jqxWindow("hide")}function hopFlavourContribution(c,e,b,d){var a;if(b==1){a=0.15}else{if(c>50){a=0.1}else{a=15.25/(6*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((c-21)/6,2));if(a<0.1){a=0.1}}}return(a*d*1000)/e}function hopAromaContribution(c,e,b,d){var a=0;if(b==5){a=1.33}else{if(c>20){a=0}else{if(c>7.5){a=10.03/(4*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((c-7.5)/4,2))}else{if(b==2){a=1}else{if(b==3){a=1.2}else{if(b==4){a=1.2}}}}}}return(a*d*1000)/e}function setReadonly(c){var d=!c,a=110,b=80;if(c){a=90;b=60}$("#batch_size").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#boil_size").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#boil_time").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#efficiency").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#est_og").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#type").jqxDropDownList({disabled:c});$("#styleSelect").jqxDropDownList({disabled:c});$("#color_method").jqxDropDownList({disabled:c});$("#ibu_method").jqxDropDownList({disabled:c});$("#Delete").jqxButton({disabled:c});$("#fermentableGrid").jqxGrid({editable:d});$("#faddrowbutton").jqxDropDownList({disabled:c});$("#finstockbutton").jqxCheckBox({disabled:c});$("#fdeleterowbutton").jqxButton({disabled:c});$("#hopGrid").jqxGrid({editable:d});$("#haddrowbutton").jqxDropDownList({disabled:c});$("#hinstockbutton").jqxCheckBox({disabled:c});$("#hdeleterowbutton").jqxButton({disabled:c});$("#miscGrid").jqxGrid({editable:d});$("#maddrowbutton").jqxDropDownList({disabled:c});$("#minstockbutton").jqxCheckBox({disabled:c});$("#mdeleterowbutton").jqxButton({disabled:c});$("#yeastGrid").jqxGrid({editable:d});$("#yaddrowbutton").jqxDropDownList({disabled:c});$("#yinstockbutton").jqxCheckBox({disabled:c});$("#ydeleterowbutton").jqxButton({disabled:c});$("#mashGrid").jqxGrid({editable:d});$("#saddrowbutton").jqxButton({disabled:c});$("#sdeleterowbutton").jqxButton({disabled:c});$("#w1_name").jqxDropDownList({disabled:c});$("#w2_name").jqxDropDownList({disabled:c});$("#pr_name").jqxDropDownList({disabled:c});$("#wa_cacl2").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#wa_caso4").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#wa_mgso4").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#wa_nacl").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#mash_ph").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#calc_acid").jqxCheckBox({disabled:c});$("#wa_base_name").jqxDropDownList({disabled:c});$("#wa_base").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#wa_acid_name").jqxDropDownList({disabled:c});$("#wa_acid").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#wa_acid_perc").jqxNumberInput({spinButtons:d,readOnly:c,width:b});$("#sparge_temp").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#sparge_volume").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#sparge_ph").jqxNumberInput({spinButtons:d,readOnly:c,width:a});$("#sparge_source").jqxDropDownList({disabled:c});$("#sparge_acid_type").jqxDropDownList({disabled:c});$("#sparge_acid_perc").jqxNumberInput({spinButtons:d,readOnly:c,width:a})}function calcPercentages(){console.log("calcPercentages()");var b,e,a,c,d=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(d>1){b=0;for(c=0;c<d;c++){e=$("#fermentableGrid").jqxGrid("getrowdata",c);if(e.f_added<4){b+=Round(e.f_amount,3)}}b=Round(b,3);for(c=0;c<d;c++){e=$("#fermentableGrid").jqxGrid("getrowdata",c);if(e.f_added<4){a=Round(e.f_amount/b*100,1);$("#fermentableGrid").jqxGrid("setcellvalue",c,"f_percentage",a)}else{$("#fermentableGrid").jqxGrid("setcellvalue",c,"f_percentage",0)}}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}}function calcFermentables(){console.log("calcFermentables()");var g,o,p,n,q=0,k,l,m,c,f,e,j,b,h=0,a=0;vol=0,addedS=0,addedmass=0,mvol=0,colort=0,colorh=0,colorn=0,my_100=false,mashtime=0,mashtemp=0,bv=0.925,sr=0.95,lintner=0;psugar=0;pcara=0;mashkg=0;if((p=$("#mashGrid").jqxGrid("getrows"))){for(g=0;g<p.length;g++){o=p[g];if(o.step_type==0){mvol+=parseFloat(o.step_infuse_amount)}if(o.step_temp<=75){mashtime+=o.step_time;mashtemp+=o.step_time*o.step_temp}}mashtemp=mashtemp/mashtime}if(!(p=$("#fermentableGrid").jqxGrid("getrows"))){return}for(g=0;g<p.length;g++){o=p[g];if(o.f_adjust_to_total_100){my_100=true}if(o.f_type==1&&o.f_added<4){psugar+=o.f_percentage}if(o.f_graintype==2&&o.f_added<4){pcara+=o.f_percentage}k=o.f_amount*(o.f_yield/100)*(1-o.f_moisture/100);if(o.f_added==0){if(mvol>0){mvol+=o.f_amount*o.f_moisture/100;q+=k}k=parseFloat(dataRecord.efficiency)/100*k;a+=k;mashkg+=o.f_amount}if(o.f_added==0||o.f_added==1){h+=k}if(o.f_added==2||o.f_added==3){l=(o.f_yield/100)*(1-o.f_moisture/100);addedS+=o.f_amount*l;addedmass+=o.f_amount;vol+=(l*sugardensity+(1-l)*1)*o.f_amount}if(o.f_added==0&&(o.f_type==0||o.f_type==4)&&o.f_color<50){lintner+=o.f_diastatic_power*o.f_amount}if(o.f_added<4){colort+=o.f_amount*ebc_to_srm(o.f_color);colorh+=o.f_amount*o.f_color*get_kt(o.f_color);colorn+=(o.f_percentage/100)*o.f_color}}$("#ferm_lintner").val(Math.round(parseFloat(lintner/mashkg)));to_100=my_100;if(to_100){$("#wf_amount").jqxNumberInput({width:90,readOnly:true,spinButtons:false})}else{$("#wf_amount").jqxNumberInput({width:110,readOnly:false,spinButtons:true})}dataRecord.est_og=estimate_sg(h+addedS,parseFloat(dataRecord.batch_size));$("#est_og").val(dataRecord.est_og);$("#est_og2").val(dataRecord.est_og);n=dataRecord.est_og;preboil_sg=estimate_sg(a,parseFloat(dataRecord.boil_size));if(dataRecord.color_method==4){e=Math.round(((sg_to_plato(dataRecord.est_og)/8.6)*colorn)+(dataRecord.boil_time/60))}else{if(dataRecord.color_method==3){e=Math.round((4.46*bv*sr)/parseFloat(dataRecord.batch_size)*colorh)}else{f=colort/parseFloat(dataRecord.batch_size)*8.34436;e=kw_to_ebc(dataRecord.color_method,f)}}dataRecord.est_color=e;$("#est_color").val(e);$("#est_color2").val(e);j=ebc_to_color(e);document.getElementById("bcolor").style.background=j;document.getElementById("bcolor2").style.background=j;pmalts=mashkg/(dataRecord.boil_size/3)*100;$("#perc_malts").jqxProgressBar("val",pmalts);$("#perc_sugars").jqxProgressBar("val",psugar);$("#perc_cara").jqxProgressBar("val",pcara);svg=0;p=$("#yeastGrid").jqxGrid("getrows");for(g=0;g<p.length;g++){o=p[g];if(o.y_use==0){if(parseFloat(o.y_attenuation)>svg){svg=parseFloat(o.y_attenuation)}}}if(svg==0){svg=77}if((mashkg>0)&&(mash_infuse>0)&&(mashtime>0)&&(mashtemp>0)){dataRecord.est_fg=estimate_fg(psugar,pcara,mash_infuse/mashkg,mashtime,mashtemp,svg,dataRecord.est_og)}else{dataRecord.est_fg=estimate_fg(psugar,pcara,0,0,0,svg,dataRecord.est_og)}$("#est_fg").val(dataRecord.est_fg);$("#est_fg2").val(dataRecord.est_fg);b=dataRecord.est_fg;dataRecord.est_abv=abvol(dataRecord.est_og,dataRecord.est_fg);$("#est_abv").val(dataRecord.est_abv);$("#est_abv2").val(dataRecord.est_abv);c=1881.22*b*(n-b)/(1.775-n);m=3550*b*(0.1808*n+0.8192*b-1.0004);$("#kcal").val(Math.round((c+m)/(12*0.0295735296)))}function calcMash(){var a=0,b,d,c;if(!(c=$("#mashGrid").jqxGrid("getrows"))){return}if(mashkg==0){return}for(b=0;b<c.length;b++){d=$("#mashGrid").jqxGrid("getrowdata",b);if(d.step_type==0){a+=d.step_infuse_amount}$("#mashGrid").jqxGrid("setcellvalue",b,"step_thickness",a/mashkg)}}function calcIBUs(){var a=0,c={},b,d;hop_aroma=hop_flavour=0;if(!(c=$("#hopGrid").jqxGrid("getrows"))){return}for(b=0;b<c.length;b++){d=c[b];a+=toIBU(d.h_useat,d.h_form,preboil_sg,parseFloat(dataRecord.batch_size),parseFloat(d.h_amount),parseFloat(d.h_time),parseFloat(d.h_alpha),dataRecord.ibu_method);hop_flavour+=hopFlavourContribution(parseFloat(d.h_time),parseFloat(dataRecord.batch_size),d.h_useat,parseFloat(d.h_amount));hop_aroma+=hopAromaContribution(parseFloat(d.h_time),parseFloat(dataRecord.batch_size),d.h_useat,parseFloat(d.h_amount))}a=Round(a,1);hop_flavour=Round(hop_flavour*100/5,1);hop_aroma=Round(hop_aroma*100/6,1);if(hop_flavour>100){hop_flavour=100}if(hop_aroma>100){hop_aroma=100}console.log("calcIBUs(): "+a+"  flavour: "+hop_flavour+"  aroma: "+hop_aroma);dataRecord.est_ibu=a;$("#est_ibu").val(a);$("#est_ibu2").val(a);$("#hop_flavour").jqxProgressBar("val",hop_flavour);$("#hop_aroma").jqxProgressBar("val",hop_aroma)}function adjustHops(c){var b,d,a,e=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(e==0){return}for(b=0;b<e;b++){d=$("#hopGrid").jqxGrid("getrowdata",b);a=d.h_amount*c;$("#hopGrid").jqxGrid("setcellvalue",b,"h_amount",a)}}function adjustMiscs(c){var b,d,a,e=$("#miscGrid").jqxGrid("getdatainformation").rowscount;if(e==0){return}for(b=0;b<e;b++){d=$("#miscGrid").jqxGrid("getrowdata",b);a=d.m_amount*c;$("#miscGrid").jqxGrid("setcellvalue",b,"m_amount",a);switch(d.m_name){case"CaCl2":$("#wa_cacl2").val(d.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(d.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(d.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(d.m_amount*1000);break;case"Melkzuur":case"Zoutzuur":case"Fosforzuur":case"Zwavelzuur":$("#wa_acid").val(d.m_amount*1000);break;case"NaHCO3":case"Na2CO3":case"CaCO3":case"Ca(OH)2":$("#wa_base").val(d.m_amount*1000);break}}}function adjustYeasts(c){var b,d,a,e=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(e==0){return}for(b=0;b<e;b++){d=$("#yeastGrid").jqxGrid("getrowdata",b);if(d.y_form==1){a=d.y_amount*c;$("#yeastGrid").jqxGrid("setcellvalue",b,"y_amount",a)}}}function adjustWaters(c){var b,d,a,e=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(e==0){return}mash_infuse=0;for(b=0;b<e;b++){d=$("#mashGrid").jqxGrid("getrowdata",b);if(d.step_type==0){a=Round(d.step_infuse_amount*c,1);$("#mashGrid").jqxGrid("setcellvalue",b,"step_infuse_amount",a);mash_infuse+=a}}if(dataRecord.w2_amount==0){dataRecord.w1_amount=mash_infuse;$("#w1_amount").val(mash_infuse)}else{dataRecord.w1_amount=(dataRecord.w1_amount/(dataRecord.w1_amount+dataRecord.w2_amount))*mash_infuse;dataRecord.w2_amount=(dataRecord.w2_amount/(dataRecord.w1_amount+dataRecord.w2_amount))*mash_infuse;$("#w1_amount").val(dataRecord.w1_amount);$("#w2_amount").val(dataRecord.w2_amount)}$("#wg_amount").val(mash_infuse)}function GetBUGU(){var a=(dataRecord.est_og-1)*1000;if(a>0){return dataRecord.est_ibu/a}else{return 0.5}}function GetOptClSO4ratio(){var a=GetBUGU();return(-1.2*a+1.4)}function setRangeIndicator(b,a){if((a=="laag")||(a=="hoog")){$("#wr_"+b).html('<img src="images/dialog-error.png"><span style="vertical-align: top; font-size: 10px; font-style: italic;">'+a+"</span>")}else{$("#wr_"+b).html('<img src="images/dialog-ok-apply.png">')}}function mix(d,c,b,a){if((d+c)>0){return((d*b)+(c*a))/(d+c)}return 0}function ResidualAlkalinity(c,b,a){return c-(b/1.4+a/1.7)}function PartCO3(b){var a=Math.pow(10,-b);return 100*Ka1*Ka2/(a*a+a*Ka1+Ka1*Ka2)}function PartHCO3(b){var a=Math.pow(10,-b);return 100*Ka1*a/(a*a+a*Ka1+Ka1*Ka2)}function Charge(a){return(-2*PartCO3(a)-PartHCO3(a))}function ZAlkalinity(b){var e=Charge(4.3),c=Charge(parseFloat($("#wg_ph").jqxNumberInput("decimal"))),a=Charge(b),g=-e+c,f=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))/50/g,d=-a+c;return f*d}function ZRA(b){var a=parseFloat($("#wg_calcium").jqxNumberInput("decimal"))/(MMCa/2),c=parseFloat($("#wg_magnesium").jqxNumberInput("decimal"))/(MMMg/2),d=ZAlkalinity(b);return d-(a/3.5+c/7)}function ProtonDeficit(b){var a,e,c,d,f,g=ZRA(b)*parseFloat($("#wg_amount").jqxNumberInput("decimal"));d=$("#fermentableGrid").jqxGrid("getrows");for(c=0;c<d.length;c++){f=d[c];if(f.f_added==0&&f.f_graintype!=6){e=0;if((f.f_di_ph!=5.7)&&((f.f_acid_to_ph_57<-0.1)||(f.f_acid_to_ph_57>0.1))){e=f.f_acid_to_ph_57/(f.f_di_ph-5.7)}else{a=f.f_color;switch(f.f_graintype){case 0:case 3:case 5:e=0.014*a-34.192;break;case 2:e=-0.0597*a-32.457;break;case 1:e=0.0107*a-54.768;break;case 4:e=-149;break}}x=e*(b-f.f_di_ph);g+=x*f.f_amount}}return g}function MashpH(){var e=0,c=5.4,b=0.001,d=0.1,a=ProtonDeficit(c);while(((a<-d)||(a>d))&&(e<2000)){e++;if(a<-d){c-=b}else{if(a>d){c+=b}}a=ProtonDeficit(c)}return c}function GetAcidSpecs(a){switch(a){case 0:return{pK1:3.86,pK2:20,pK3:20,MolWt:90.08,AcidSG:1214,AcidPrc:0.88};case 1:return{pK1:-7,pK2:20,pK3:20,MolWt:36.46,AcidSG:1142,AcidPrc:0.28};case 2:return{pK1:2.12,pK2:7.2,pK3:12.44,MolWt:98,AcidSG:1170,AcidPrc:0.25};case 3:return{pK1:-1,pK2:1.92,pK3:20,MolWt:98.07,AcidSG:1700,AcidPrc:0.93}}}$(document).ready(function(){var h=false,u=0,e={},o=0,t={},q=0,p={},c=0,g={},l=0,r={},f="includes/db_recipes.php",s={datatype:"json",cache:false,datafields:[{name:"record",type:"number"},{name:"uuid",type:"string"},{name:"locked",type:"int"},{name:"st_name",type:"string"},{name:"st_letter",type:"string"},{name:"st_guide",type:"string"},{name:"st_type",type:"int"},{name:"st_category",type:"string"},{name:"st_category_number",type:"float"},{name:"st_og_min",type:"float"},{name:"st_og_max",type:"float"},{name:"st_fg_min",type:"float"},{name:"st_fg_max",type:"float"},{name:"st_ibu_min",type:"float"},{name:"st_ibu_max",type:"float"},{name:"st_color_min",type:"float"},{name:"st_color_max",type:"float"},{name:"st_carb_min",type:"float"},{name:"st_carb_max",type:"float"},{name:"st_abv_min",type:"float"},{name:"st_abv_max",type:"float"},{name:"name",type:"string"},{name:"notes",type:"string"},{name:"type",type:"int"},{name:"batch_size",type:"float"},{name:"boil_size",type:"float"},{name:"boil_time",type:"float"},{name:"efficiency",type:"float"},{name:"est_og",type:"float"},{name:"est_fg",type:"float"},{name:"est_abv",type:"float"},{name:"est_color",type:"float"},{name:"color_method",type:"int"},{name:"est_ibu",type:"float"},{name:"ibu_method",type:"int"},{name:"est_carb",type:"float"},{name:"sparge_temp",type:"float"},{name:"sparge_ph",type:"float"},{name:"sparge_volume",type:"float"},{name:"sparge_source",type:"int"},{name:"sparge_acid_type",type:"int"},{name:"sparge_acid_perc",type:"float"},{name:"sparge_acid_amount",type:"float"},{name:"mash_ph",type:"float"},{name:"mash_name",type:"string"},{name:"calc_acid",type:"int"},{name:"w1_name",type:"string"},{name:"w1_amount",type:"float"},{name:"w1_calcium",type:"float"},{name:"w1_sulfate",type:"float"},{name:"w1_chloride",type:"float"},{name:"w1_sodium",type:"float"},{name:"w1_magnesium",type:"float"},{name:"w1_total_alkalinity",type:"float"},{name:"w1_ph",type:"float"},{name:"w1_cost",type:"float"},{name:"w2_name",type:"string"},{name:"w2_amount",type:"float"},{name:"w2_calcium",type:"float"},{name:"w2_sulfate",type:"float"},{name:"w2_chloride",type:"float"},{name:"w2_sodium",type:"float"},{name:"w2_magnesium",type:"float"},{name:"w2_total_alkalinity",type:"float"},{name:"w2_ph",type:"float"},{name:"w2_cost",type:"float"},{name:"wg_amount",type:"float"},{name:"wg_calcium",type:"float"},{name:"wg_sulfate",type:"float"},{name:"wg_chloride",type:"float"},{name:"wg_sodium",type:"float"},{name:"wg_magnesium",type:"float"},{name:"wg_total_alkalinity",type:"float"},{name:"wg_ph",type:"float"},{name:"wb_calcium",type:"float"},{name:"wb_sulfate",type:"float"},{name:"wb_chloride",type:"float"},{name:"wb_sodium",type:"float"},{name:"wb_magnesium",type:"float"},{name:"wb_total_alkalinity",type:"float"},{name:"wb_ph",type:"float"},{name:"wa_acid_name",type:"int"},{name:"wa_acid_perc",type:"int"},{name:"wa_base_name",type:"int"},{name:"fermentables",type:"array"},{name:"hops",type:"array"},{name:"miscs",type:"array"},{name:"yeasts",type:"array"},{name:"mashs",type:"array"}],id:"record",url:f+"?record="+my_record},y=new $.jqx.dataAdapter(s,{loadComplete:function(){var B=y.records;dataRecord=B[0];$("#name").val(dataRecord.name);$("#notes").val(dataRecord.notes);$("#locked").val(dataRecord.locked);$("#st_name").val(dataRecord.st_name);$("#st_letter").val(dataRecord.st_letter);$("#st_guide").val(dataRecord.st_guide);$("#st_category").val(dataRecord.st_category);$("#st_category_number").val(dataRecord.st_category_number);$("#st_type").val(StyleTypeData[dataRecord.st_type].nl);$("#type").val(dataRecord.type);$("#batch_size").val(dataRecord.batch_size);$("#boil_size").val(dataRecord.boil_size);$("#boil_time").val(dataRecord.boil_time);$("#efficiency").val(dataRecord.efficiency);$("#est_og").val(dataRecord.est_og);$("#est_og2").val(dataRecord.est_og);$("#st_og_min").val(dataRecord.st_og_min);$("#st_og_max").val(dataRecord.st_og_max);$("#est_fg").val(dataRecord.est_fg);$("#est_fg2").val(dataRecord.est_fg);$("#st_fg_min").val(dataRecord.st_fg_min);$("#st_fg_max").val(dataRecord.st_fg_max);$("#est_fg").val(dataRecord.est_fg);$("#est_fg2").val(dataRecord.est_fg);$("#st_fg_min").val(dataRecord.st_fg_min);$("#st_fg_max").val(dataRecord.st_fg_max);$("#est_color").val(dataRecord.est_color);$("#est_color2").val(dataRecord.est_color);$("#est_abv").val(dataRecord.est_abv);$("#est_abv2").val(dataRecord.est_abv);$("#st_abv_min").val(dataRecord.st_abv_min);$("#st_abv_max").val(dataRecord.st_abv_max);$("#st_color_min").val(dataRecord.st_color_min);$("#st_color_max").val(dataRecord.st_color_max);$("#color_method").val(dataRecord.color_method);$("#est_ibu").val(dataRecord.est_ibu);$("#est_ibu2").val(dataRecord.est_ibu);$("#st_ibu_min").val(dataRecord.st_ibu_min);$("#st_ibu_max").val(dataRecord.st_ibu_max);$("#ibu_method").val(dataRecord.ibu_method);$("#est_carb").val(dataRecord.est_carb);$("#st_carb_min").val(dataRecord.st_carb_min);$("#st_carb_max").val(dataRecord.st_carb_max);$("#mash_name").val(dataRecord.mash_name);$("#mash_ph").val(dataRecord.mash_ph);$("#sparge_temp").val(dataRecord.sparge_temp);$("#sparge_ph").val(dataRecord.sparge_ph);$("#sparge_volume").val(dataRecord.sparge_volume);$("#sparge_source").val(dataRecord.sparge_source);$("#sparge_acid_type").val(dataRecord.sparge_acid_type);$("#sparge_acid_perc").val(dataRecord.sparge_acid_perc);$("#sparge_acid_amount").val(dataRecord.sparge_acid_amount*1000);$("#calc_acid").val(dataRecord.calc_acid);$("#w1_name").val(dataRecord.w1_name);$("#w1_amount").val(dataRecord.w1_amount);$("#w1_calcium").val(dataRecord.w1_calcium);$("#w1_sulfate").val(dataRecord.w1_sulfate);$("#w1_chloride").val(dataRecord.w1_chloride);$("#w1_sodium").val(dataRecord.w1_sodium);$("#w1_magnesium").val(dataRecord.w1_magnesium);$("#w1_total_alkalinity").val(dataRecord.w1_total_alkalinity);$("#w1_ph").val(dataRecord.w1_ph);$("#w1_cost").val(dataRecord.w1_cost);$("#w2_name").val(dataRecord.w2_name);$("#w2_amount").val(dataRecord.w2_amount);$("#w2_calcium").val(dataRecord.w2_calcium);$("#w2_sulfate").val(dataRecord.w2_sulfate);$("#w2_chloride").val(dataRecord.w2_chloride);$("#w2_sodium").val(dataRecord.w2_sodium);$("#w2_magnesium").val(dataRecord.w2_magnesium);$("#w2_total_alkalinity").val(dataRecord.w2_total_alkalinity);$("#w2_ph").val(dataRecord.w2_ph);$("#w2_cost").val(dataRecord.w2_cost);$("#wg_amount").val(dataRecord.wg_amount);$("#wg_calcium").val(dataRecord.wg_calcium);$("#wg_sulfate").val(dataRecord.wg_sulfate);$("#wg_chloride").val(dataRecord.wg_chloride);$("#wg_sodium").val(dataRecord.wg_sodium);$("#wg_magnesium").val(dataRecord.wg_magnesium);$("#wg_total_alkalinity").val(dataRecord.wg_total_alkalinity);$("#wg_ph").val(dataRecord.wg_ph);$("#wb_calcium").val(dataRecord.wb_calcium);$("#wb_sulfate").val(dataRecord.wb_sulfate);$("#wb_chloride").val(dataRecord.wb_chloride);$("#wb_sodium").val(dataRecord.wb_sodium);$("#wb_magnesium").val(dataRecord.wb_magnesium);$("#wb_total_alkalinity").val(dataRecord.wb_total_alkalinity);$("#wb_ph").val(dataRecord.wb_ph);$("#wa_acid_name").val(dataRecord.wa_acid_name);$("#wa_acid_perc").val(dataRecord.wa_acid_perc);$("#wa_base_name").val(dataRecord.wa_base_name);j(dataRecord);A(dataRecord);b(dataRecord);w(dataRecord);n(dataRecord);$("#jqxTabs").jqxTabs("next")},loadError:function(D,B,C){},beforeLoadComplete:function(B){$("#jqxLoader").jqxLoader("open")}}),j=function(C){var B={localdata:C.fermentables,datatype:"local",cache:false,async:false,datafields:[{name:"f_name",type:"string"},{name:"f_origin",type:"string"},{name:"f_supplier",type:"string"},{name:"f_amount",type:"float"},{name:"f_cost",type:"float"},{name:"f_type",type:"int"},{name:"f_yield",type:"float"},{name:"f_color",type:"float"},{name:"f_coarse_fine_diff",type:"float"},{name:"f_moisture",type:"float"},{name:"f_diastatic_power",type:"float"},{name:"f_protein",type:"float"},{name:"f_max_in_batch",type:"float"},{name:"f_graintype",type:"int"},{name:"f_added",type:"int"},{name:"f_dissolved_protein",type:"float"},{name:"f_recommend_mash",type:"int"},{name:"f_add_after_boil",type:"int"},{name:"f_adjust_to_total_100",type:"int"},{name:"f_percentage",type:"float"},{name:"f_di_ph",type:"float"},{name:"f_acid_to_ph_57",type:"float"},{name:"f_inventory",type:"float"},{name:"f_avail",type:"int"}],addrow:function(F,H,E,G){G(true)},deleterow:function(E,F){F(true)},updaterow:function(E,G,F){F(true)}},D=new $.jqx.dataAdapter(B);$("#fermentableGrid").jqxGrid({width:1240,height:470,source:D,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(F){var E=$('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');F.append(E);E.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');E.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');E.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');E.append('<input style="float: left; margin-left: 400px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');$("#faddrowbutton").jqxDropDownList({placeHolder:"Kies mout:",theme:theme,template:"primary",source:fermentablelist,displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(H,G,J){var I=fermentablelist.records[H];return I.supplier+" / "+I.name+" ("+I.color+" EBC)"}});$("#faddrowbutton").on("select",function(I){if(I.args){var G,H,J={},K=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;G=I.args.index;H=fermentablelist.records[G];J.f_name=H.name;J.f_origin=H.origin;J.f_supplier=H.supplier;J.f_amount=0;J["[_cost"]=H.cost;J.f_type=H.type;J.f_yield=H.yield;J.f_color=H.color;J.f_coarse_fine_diff=H.coarse_fine_diff;J.f_moisture=H.moisture;J.f_diastatic_power=H.diastatic_power;J.f_protein=H.protein;J.f_max_in_batch=H.max_in_batch;J.f_graintype=H.graintype;if(H.add_after_boil){J.f_added=2}else{if((H.type==1)||(H.type==4)){J.f_added=1}else{J.f_added=0}}J.f_dissolved_protein=H.dissolved_protein;J.f_recommend_mash=H.recommend_mash;J.f_add_after_boil=H.add_after_boil;if(K==0){J.f_adjust_to_total_100=1;J.f_percentage=100}else{J.f_adjust_to_total_100=0;J.f_percentage=0}J.f_di_ph=H.di_ph;J.f_acid_to_ph_57=H.acid_to_ph_57;J.f_inventory=H.inventory;$("#fermentableGrid").jqxGrid("addrow",null,J)}});$("#finstockbutton").jqxCheckBox({theme:theme,height:27});$("#finstockbutton").on("change",function(G){fermentableinstock=G.args.checked;fermentablelist.dataBind()});$("#fdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#fdeleterowbutton").on("click",function(){var M,J,I,H,L,K,G=$("#fermentableGrid").jqxGrid("getselectedrowindex");K=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(G>=0&&G<K){M=$("#fermentableGrid").jqxGrid("getrowid",G);J=$("#fermentableGrid").jqxGrid("getcellvalue",M,"f_percentage");I=$("#fermentableGrid").jqxGrid("getcellvalue",M,"f_amount");$("#fermentableGrid").jqxGrid("deleterow",M)}K=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(K>1){if(h){for(H=0;H<K;H++){L=$("#fermentableGrid").jqxGrid("getrowdata",H);if(L.f_adjust_to_total_100){L.f_percentage+=J;L.f_amount+=I}}}else{calcPercentages()}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}calcFermentables();calcIBUs()})},ready:function(){calcFermentables();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Vergistbaar ingredi&euml;nt",datafield:"f_name",cellsrenderer:function(G,F,I,E,H,J){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+J.f_supplier+" / "+J.f_name+" ("+J.f_color+" EBC)</span>"}},{text:"Type",width:100,datafield:"f_type",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+FermentableTypeData[I].nl+"</span>"}},{text:"Moment",width:110,datafield:"f_added",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+AddedData[I].nl+"</span>"}},{text:"Maxinbatch",datafield:"f_max_in_batch",hidden:true},{text:"Opbrengst",editable:false,datafield:"f_yield",width:90,align:"right",cellsalign:"right",cellsformat:"p1"},{text:"Gewicht Kg",datafield:"f_amount",width:120,align:"right",cellsalign:"right",cellsformat:"f3"},{text:"Voorr. Kg",datafield:"f_inventory",width:120,align:"right",cellsrenderer:function(I,G,H,E,K,J){var F="#ffffff";if(H<J.f_amount){F="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+F+';">'+D.formatNumber(H,"f3")+"</span>"}},{text:"Procent",datafield:"f_percentage",width:90,align:"right",cellsrenderer:function(I,G,H,E,K,J){var F="#ffffff";if(H>J.f_max_in_batch){F="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+F+';">'+D.formatNumber(H,"p1")+"</span>"}},{text:"100%",align:"center",datafield:"f_adjust_to_total_100",columntype:"checkbox",width:70},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(E){u=E;e=$("#fermentableGrid").jqxGrid("getrowdata",u);$("#wf_name").val(e.f_name);$("#wf_amount").val(e.f_amount);$("#wf_percentage").val(e.f_percentage);$("#wf_max_in_batch").val(e.f_max_in_batch);$("#wf_adjust_to_total_100").val(e.f_adjust_to_total_100);$("#wf_added").val(e.f_added);$("#popupFermentable").jqxWindow("open")}}]})};var A=function(B){var D={localdata:B.hops,datatype:"local",cache:false,async:false,datafields:[{name:"h_name",type:"string"},{name:"h_origin",type:"string"},{name:"h_amount",type:"float"},{name:"h_cost",type:"float"},{name:"h_type",type:"int"},{name:"h_form",type:"int"},{name:"h_useat",type:"int"},{name:"h_time",type:"float"},{name:"h_alpha",type:"float"},{name:"h_beta",type:"float"},{name:"h_hsi",type:"float"},{name:"h_humulene",type:"float"},{name:"h_caryophyllene",type:"float"},{name:"h_cohumulone",type:"float"},{name:"h_myrcene",type:"float"},{name:"h_total_oil",type:"float"},{name:"h_inventory",type:"float"},{name:"h_avail",type:"int"}],addrow:function(F,H,E,G){G(true)},deleterow:function(E,F){F(true)},updaterow:function(E,G,F){F(true)}},C=new $.jqx.dataAdapter(D);$("#hopGrid").jqxGrid({width:1240,height:560,source:C,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(F){var E=$('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');F.append(E);E.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');E.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');E.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');E.append('<input style="float: left; margin-left: 400px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');$("#haddrowbutton").jqxDropDownList({placeHolder:"Kies hop:",theme:theme,template:"primary",source:hoplist,displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(H,G,J){var I=hoplist.records[H];return I.origin+" / "+I.name+" ("+I.alpha+"% &alpha;)"}});$("#haddrowbutton").on("select",function(I){if(I.args){var H,J={},G=I.args.index;H=hoplist.records[G];J.h_name=H.name;J.h_origin=H.origin;J.h_amount=0;J.h_cost=H.cost;J.h_type=H.type;J.h_form=H.form;J.h_useat=2;J.h_time=0;J.h_alpha=H.alpha;J.h_beta=H.beta;J.h_hsi=H.hsi;J.h_humulene=H.humulene;J.h_caryophyllene=H.caryophyllene;J.h_cohumulone=H.cohumulone;J.h_myrcene=H.myrcene;J.h_total_oil=H.total_oil;J.h_inventory=H.inventory;$("#hopGrid").jqxGrid("addrow",null,J)}$("#haddrowbutton").jqxDropDownList("clearSelection")});$("#hinstockbutton").jqxCheckBox({theme:theme,height:27});$("#hinstockbutton").on("change",function(G){hopinstock=G.args.checked;hoplist.dataBind()});$("#hdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#hdeleterowbutton").on("click",function(){var I,H,G=$("#hopGrid").jqxGrid("getselectedrowindex");I=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(G>=0&&G<I){H=$("#hopGrid").jqxGrid("getrowid",G);$("#hopGrid").jqxGrid("deleterow",H)}calcIBUs()})},ready:function(){calcIBUs();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Hop",datafield:"h_name",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+J.h_origin+" / "+J.h_name+"</span>"}},{text:"Type",width:90,datafield:"h_type",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopTypeData[I].nl+"</span>"}},{text:"Vorm",width:90,datafield:"h_form",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopFormData[I].nl+"</span>"}},{text:"Alpha",datafield:"h_alpha",width:80,align:"right",cellsalign:"right",cellsformat:"p1"},{text:"Gebruik",width:110,datafield:"h_useat",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopUseData[I].nl+"</span>"}},{text:"Tijdsduur",datafield:"h_time",width:90,align:"right",cellsrenderer:function(F,E,I,H,G,K){var J="";if((K.h_useat==2)||(K.h_useat==4)){J=y.formatNumber(I,"f0")+" min."}else{if(K.h_useat==5){J=y.formatNumber(I/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+J+"</span>"}},{text:"IBU",datafield:"ibu",width:80,align:"right",cellsrenderer:function(F,E,I,H,G,K){var J=toIBU(K.h_useat,K.h_form,preboil_sg,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(K.h_amount),parseFloat(K.h_time),parseFloat(K.h_alpha),$("#ibu_method").val());return'<span style="margin: 4px; margin-top: 6px; float: right;">'+y.formatNumber(J,"f1")+"</span>"}},{text:"Gewicht",datafield:"h_amount",width:110,align:"right",cellsrenderer:function(F,E,J,I,H,K){var G=y.formatNumber(J,"f1")+" kg";if(J<1){G=y.formatNumber(J*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+G+"</span>"}},{text:"Voorraad",datafield:"h_inventory",width:110,align:"right",cellsrenderer:function(G,F,K,J,I,L){var H,E="#ffffff";if(K<L.h_amount){E="#ff4040"}H=y.formatNumber(K,"f1")+" kg";if(K<1){H=y.formatNumber(K*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+E+';">'+H+"</span>"}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(E){o=E;t=$("#hopGrid").jqxGrid("getrowdata",o);$("#wh_name").val(t.h_name);$("#wh_amount").val(t.h_amount*1000);var F=toIBU(t.h_useat,t.h_form,preboil_sg,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(t.h_amount),parseFloat(t.h_time),parseFloat(t.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(F);if(t.h_useat==5){$("#wh_time").val(t.h_time/1440)}else{$("#wh_time").val(t.h_time)}$("#wh_useat").val(t.h_useat);$("#popupHop").jqxWindow("open")}}]})};var b=function(D){var C={localdata:D.miscs,datatype:"local",cache:false,async:false,datafields:[{name:"m_name",type:"string"},{name:"m_amount",type:"float"},{name:"m_cost",type:"float"},{name:"m_type",type:"int"},{name:"m_use_use",type:"int"},{name:"m_time",type:"float"},{name:"m_amount_is_weight",type:"int"},{name:"m_inventory",type:"float"},{name:"m_avail",type:"int"}],addrow:function(F,H,E,G){G(true)},deleterow:function(E,F){F(true)},updaterow:function(E,G,F){F(true)}},B=new $.jqx.dataAdapter(C,{beforeLoadComplete:function(E){var F,H,G=new Array();for(F=0;F<E.length;F++){H=E[F];G.push(H);switch(H.m_name){case"CaCl2":$("#wa_cacl2").val(H.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(H.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(H.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(H.m_amount*1000);break;case"Melkzuur":$("#wa_acid_name").val(0);$("#wa_acid").val(H.m_amount*1000);$("#wa_acid_perc").val(80);last_acid="Melkzuur";break;case"Zoutzuur":$("#wa_acid_name").val(1);$("#wa_acid").val(H.m_amount*1000);$("#wa_acid_perc").val(80);last_acid="Zoutzuur";break;case"Fosforzuur":$("#wa_acid_name").val(2);$("#wa_acid").val(H.m_amount*1000);$("#wa_acid_perc").val(80);last_acid="Fosforzuur";break;case"Zwavelzuur":$("#wa_acid_name").val(3);$("#wa_acid").val(H.m_amount*1000);$("#wa_acid_perc").val(80);last_acid="Zwavelzuur";break;case"NaHCO3":$("#wa_base_name").val(0);$("#wa_base").val(H.m_amount*1000);last_base="NaHCO3";break;case"Na2CO3":$("#wa_base_name").val(1);$("#wa_base").val(H.m_amount*1000);last_base="Na2CO3";break;case"CaCO3":$("#wa_base_name").val(2);$("#wa_base").val(H.m_amount*1000);last_base="CaCO3";break;case"Ca(OH)2":$("#wa_base_name").val(3);$("#wa_base").val(H.m_amount*1000);last_base="Ca(OH)2";break}}return G},loadError:function(G,E,F){}});$("#miscGrid").jqxGrid({width:1240,height:575,source:B,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(F){var E=$('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');F.append(E);E.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');E.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');E.append('<div style="float: left; margin-left: 10px;" id="minstockbutton"></div>');E.append('<input style="float: left; margin-left: 400px;" id="mdeleterowbutton" type="button" value="Verwijder ingredi&euml;nt" />');$("#maddrowbutton").jqxDropDownList({placeHolder:"Kies ingredi&euml;nt:",theme:theme,template:"primary",source:misclist,displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500});$("#maddrowbutton").on("select",function(I){if(I.args){var H,J={},G=I.args.index;H=misclist.records[G];J.m_name=H.name;J.m_amount=0;J.m_cost=H.cost;J.m_type=H.type;J.m_use_use=H.use_use;J.m_time=0;J.m_amount_is_weight=H.amount_is_weight;J.m_inventory=H.inventory;$("#miscGrid").jqxGrid("addrow",null,J)}});$("#minstockbutton").jqxCheckBox({theme:theme,height:27});$("#minstockbutton").on("change",function(G){miscinstock=G.args.checked;misclist.dataBind()});$("#mdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#mdeleterowbutton").on("click",function(){var J,H,I,G=$("#miscGrid").jqxGrid("getselectedrowindex");J=$("#miscGrid").jqxGrid("getdatainformation").rowscount;H=$("#miscGrid").jqxGrid("getcellvalue",G,"m_type");if(G>=0&&G<J&&H!=4){I=$("#miscGrid").jqxGrid("getrowid",G);$("#miscGrid").jqxGrid("deleterow",I)}})},ready:function(){$("#jqxTabs").jqxTabs("next")},columns:[{text:"Ingredient",datafield:"m_name"},{text:"Type",width:140,datafield:"m_type",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+MiscTypeData[I].nl+"</span>"}},{text:"Gebruik",width:140,datafield:"m_use_use",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+MiscUseData[I].nl+"</span>"}},{text:"Tijd",datafield:"m_time",width:90,align:"right",cellsrenderer:function(F,E,I,H,G,K){var J="";if(K.m_use_use==2){J=y.formatNumber(I,"f0")+" min."}else{if((K.m_use_use==3)||(K.m_use_use==4)){J=y.formatNumber(I/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+J+"</span>"}},{text:"Hoeveel",datafield:"m_amount",width:110,align:"right",cellsrenderer:function(F,E,J,H,G,K){var I=K.m_amount_is_weight?"gr":"ml";return'<span style="margin: 4px; margin-top: 6px; float: right;">'+y.formatNumber(J*1000,"f2")+" "+I+"</span>"}},{text:"Voorraad",datafield:"m_inventory",width:110,align:"right",cellsrenderer:function(I,E,J,L,F,M){var H,G="#ffffff",K=M.m_amount_is_weight?"gr":"ml";if(J<M.m_amount){G="#ff4040"}H=y.formatNumber(J*1000,"f2")+" "+K;return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+G+';">'+H+"</span>"},},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(E){q=E;p=$("#miscGrid").jqxGrid("getrowdata",q);if(p.m_type==4){alert("Brouwzouten wijzigen in de water tab.")}else{if(p.m_amount_is_weight){$("#wm_pmpt_amount").html("Gewicht gram:")}else{$("#wm_pmpt_amount").html("Volume ml:")}$("#wm_name").val(p.m_name);$("#wm_amount").val(p.m_amount*1000);if((p.m_use_use==3)||(p.m_use_use==4)){$("#wm_time").val(p.m_time/1440)}else{$("#wm_time").val(p.m_time)}$("#wm_use_use").val(p.m_use_use);$("#popupMisc").jqxWindow("open")}}}]})};var w=function(C){var B={localdata:C.yeasts,datatype:"local",cache:false,async:false,datafields:[{name:"y_name",type:"string"},{name:"y_laboratory",type:"string"},{name:"y_product_id",type:"string"},{name:"y_amount",type:"float"},{name:"y_cost",type:"float"},{name:"y_type",type:"int"},{name:"y_form",type:"int"},{name:"y_flocculation",type:"int"},{name:"y_min_temperature",type:"float"},{name:"y_max_temperature",type:"float"},{name:"y_attenuation",type:"float"},{name:"y_use",type:"int"},{name:"y_cells",type:"float"},{name:"y_tolerance",type:"float"},{name:"y_inventory",type:"float"},{name:"y_avail",type:"int"}],addrow:function(F,H,E,G){G(true)},deleterow:function(E,F){F(true)},updaterow:function(E,G,F){F(true)}},D=new $.jqx.dataAdapter(B);$("#yeastGrid").jqxGrid({width:1240,height:350,source:D,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(F){var E=$('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');F.append(E);E.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');E.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');E.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');E.append('<input style="float: left; margin-left: 400px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');$("#yaddrowbutton").jqxDropDownList({placeHolder:"Kies gist:",theme:theme,source:yeastlist,template:"primary",displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(H,G,J){var I=yeastlist.records[H];return I.laboratory+" "+I.product_id+" "+I.name}});$("#yaddrowbutton").on("select",function(I){if(I.args){var H,J={},G=I.args.index;H=yeastlist.records[G];J.y_name=H.name;J.y_laboratory=H.laboratory;J.y_product_id=H.product_id;J.y_type=H.type;J.y_form=H.form;J.y_amount=0;J.y_cost=H.cost;J.y_use=0;J.y_min_temperature=H.min_temperature;J.y_max_temperature=H.max_temperature;J.y_attenuation=H.attenuation;J.y_flocculation=H.flocculation;J.y_cells=H.cells;J.y_tolerance=H.tolerance;J.y_inventory=H.inventory;$("#yeastGrid").jqxGrid("addrow",null,J)}$("#yaddrowbutton").jqxDropDownList("clearSelection")});$("#yinstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(dataRecord.stage>3)});$("#yinstockbutton").on("change",function(G){yeastinstock=G.args.checked;yeastlist.dataBind()});$("#ydeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(dataRecord.stage>3)});$("#ydeleterowbutton").on("click",function(){var I,H,G=$("#yeastGrid").jqxGrid("getselectedrowindex");H=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(G>=0&&G<H){I=$("#yeastGrid").jqxGrid("getrowid",G);$("#yeastGrid").jqxGrid("deleterow",I)}})},ready:function(){calcFermentables();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Gist",datafield:"y_name"},{text:"Laboratorium",width:150,datafield:"y_laboratory"},{text:"Code",width:90,datafield:"y_product_id"},{text:"Soort",width:100,datafield:"y_form",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastFormData[I].nl+"</span>"}},{text:"Min. &deg;C",width:70,align:"right",cellsalign:"right",datafield:"y_min_temperature"},{text:"Max. &deg;C",width:70,align:"right",cellsalign:"right",datafield:"y_max_temperature"},{text:"Tol. %",width:60,align:"right",cellsalign:"right",datafield:"y_tolerance",cellsrenderer:function(G,F,K,J,I,L){var H="",E="#ffffff";if(K>0){H=y.formatNumber(K,"f1");if(dataRecord.est_abv>K){E="#ff4040"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+E+';">'+H+"</span>"}},{text:"Attn. %",width:70,align:"right",cellsalign:"right",datafield:"y_attenuation",cellsformat:"f1"},{text:"Voor",width:120,datafield:"y_use",cellsrenderer:function(F,E,I,H,G,J){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastUseData[I].nl+"</span>"}},{text:"Hoeveel",datafield:"y_amount",width:90,align:"right",cellsrenderer:function(F,E,J,I,H,K){var G=y.formatNumber(J*1000,"f0")+" ml";if(K.y_form==0){G=y.formatNumber(J,"f0")+" pk"}else{if(K.y_form==1){G=y.formatNumber(J*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+G+"</span>"}},{text:"Voorraad",datafield:"y_inventory",width:90,align:"right",cellsrenderer:function(G,F,K,J,I,L){var E,H;E="#ffffff";if(K<L.y_amount){E="#ff4040"}H=y.formatNumber(K*1000,"f0")+" ml";if(L.y_form==0){H=y.formatNumber(K,"f0")+" pk"}else{if(L.y_form==1){H=y.formatNumber(K*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+E+';">'+H+"</span>"}},{text:"",datafield:"Edit",columntype:"button",width:90,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(E){c=E;g=$("#yeastGrid").jqxGrid("getrowdata",c);if(g.y_form==0){$("#wy_pmpt_amount").html("Pak(ken):");$("#wy_amount").val(g.y_amount);$("#wy_amount").jqxNumberInput({decimalDigits:0})}else{if(g.y_form==1){$("#wy_pmpt_amount").html("Gewicht gram:");$("#wy_amount").val(g.y_amount*1000);$("#wy_amount").jqxNumberInput({decimalDigits:1})}else{$("#wy_pmpt_amount").html("Volume ml:");$("#wy_amount").val(g.y_amount*1000);$("#wy_amount").jqxNumberInput({decimalDigits:0})}}$("#wy_name").val(g.y_name);$("#wy_laboratory").val(g.y_laboratory);$("#wy_product_id").val(g.y_product_id);$("#wy_use").val(g.y_use);$("#popupYeast").jqxWindow("open")}}]})};var n=function(E){var D=function(){var F={};F.step_name="Stap 1";F.step_type=0;F.step_infuse_amount=15;F.step_temp=62;F.step_time=20;F.step_thickness=0;F.ramp_time=1;F.end_temp=62;return F};var C={localdata:E.mashs,datatype:"local",cache:false,async:false,datafields:[{name:"step_name",type:"string"},{name:"step_type",type:"int"},{name:"step_infuse_amount",type:"float"},{name:"step_temp",type:"float"},{name:"step_time",type:"float"},{name:"step_thickness",type:"float"},{name:"ramp_time",type:"float"},{name:"end_temp",type:"float"}],addrow:function(G,I,F,H){H(true)},deleterow:function(F,G){G(true)}},B=new $.jqx.dataAdapter(C,{beforeLoadComplete:function(F){mash_infuse=0;var I,G,H=new Array();for(G=0;G<F.length;G++){I=F[G];if(I.step_type==0){mash_infuse+=parseFloat(I.step_infuse_amount)}I.step_thickness=0;H.push(I)}},});$("#mashGrid").jqxGrid({width:1240,height:400,source:B,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(G){var F=$('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');G.append(F);F.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');F.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder stap" />');$("#saddrowbutton").jqxButton({template:"primary",theme:theme,height:27,width:150});$("#saddrowbutton").on("click",function(){var H=D();$("#mashGrid").jqxGrid("addrow",null,H)});$("#sdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150});$("#sdeleterowbutton").on("click",function(){var J,I,H=$("#mashGrid").jqxGrid("getselectedrowindex");I=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(H>=0&&H<I){J=$("#mashGrid").jqxGrid("getrowid",H);$("#mashGrid").jqxGrid("deleterow",J)}})},ready:function(){calcFermentables();a();calcMash();$("#jqxLoader").jqxLoader("close");$("#jqxTabs").jqxTabs("first")},columns:[{text:"Stap naam",datafield:"step_name"},{text:"Stap type",datafield:"step_type",width:175,cellsrenderer:function(G,F,J,I,H,K){return'<div style="margin: 4px;">'+MashStepTypeData[J].nl+"</div>"}},{text:"Start &deg;C",datafield:"step_temp",width:90,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Eind &deg;C",datafield:"end_temp",width:90,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Rust min.",datafield:"step_time",width:90,align:"right",cellsalign:"right"},{text:"Stap min.",datafield:"ramp_time",width:90,align:"right",cellsalign:"right"},{text:"Infuse L.",datafield:"step_infuse_amount",width:90,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"L/Kg.",datafield:"step_thickness",width:90,align:"right",cellsalign:"right",cellsformat:"f2"},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(F){l=F;r=$("#mashGrid").jqxGrid("getrowdata",l);$("#wstep_name").val(r.step_name);$("#wstep_type").val(r.step_type);$("#wstep_infuse_amount").val(r.step_infuse_amount);$("#wstep_temp").val(r.step_temp);$("#wend_temp").val(r.end_temp);$("#wstep_time").val(r.step_time);$("#wramp_time").val(r.ramp_time);if(r.step_type==0){$("#wstep_infuse_amount").show();$("#wstep_pmpt").show()}else{$("#wstep_infuse_amount").hide();$("#wstep_pmpt").hide()}$("#popupMash").jqxWindow("open")}}]})};$("#jqxMenu").jqxMenu("destroy");console.log("record:"+my_record+"  return:"+my_return+"  theme:"+theme);$("#jqxLoader").jqxLoader({width:250,height:150,isModal:true,text:"Laden recept ...",theme:theme});function z(B,F){var G,D,H,E,C,K,J=false,I=$("#miscGrid").jqxGrid("getrows");if(F==0){for(E=0;E<I.length;E++){K=I[E];if(K.m_name==B){C=$("#miscGrid").jqxGrid("getrowid",E);$("#miscGrid").jqxGrid("deleterow",C)}}}else{for(E=0;E<I.length;E++){K=I[E];if(K.m_name==B){J=true;$("#miscGrid").jqxGrid("setcellvalue",E,"m_amount",F/1000);break}}if(!J){H=new $.jqx.dataAdapter(miscInvSource,{loadComplete:function(){D=H.records;for(E=0;E<D.length;E++){G=D[E];if(G.name==B){K={};K.m_name=G.name;K.m_amount=F/1000;K.m_cost=G.cost;K.m_type=G.type;K.m_use_use=G.use_use;K.m_time=0;K.m_amount_is_weight=G.amount_is_weight;K.m_inventory=G.inventory;K.m_avail=1;$("#miscGrid").jqxGrid("addrow",null,K)}}}});H.dataBind();return}}}function m(){console.log("calcWater()");var T=0,ai=0,J=0,U=0,K=0,af=0,L=0,ad=0,N=0,W=0,ao=0,am=0,aj=0,ah,X,P,E,D,B,O,G,F,Z,R,I,aa,S,ag,Y,Q,ab,an,ac,M,ak,V,al,H,ae,C;if(dataRecord.w1_name==""){return}if(dataRecord.w2_name!=""){T=dataRecord.w1_amount+dataRecord.w2_amount;ai=mix(dataRecord.w1_amount,dataRecord.w2_amount,dataRecord.w1_calcium,dataRecord.w2_calcium);J=mix(dataRecord.w1_amount,dataRecord.w2_amount,dataRecord.w1_magnesium,dataRecord.w2_magnesium);U=mix(dataRecord.w1_amount,dataRecord.w2_amount,dataRecord.w1_sodium,dataRecord.w2_sodium);L=mix(dataRecord.w1_amount,dataRecord.w2_amount,dataRecord.w1_chloride,dataRecord.w2_chloride);ad=mix(dataRecord.w1_amount,dataRecord.w2_amount,dataRecord.w1_sulfate,dataRecord.w2_sulfate);K=mix(dataRecord.w1_amount,dataRecord.w2_amount,dataRecord.w1_total_alkalinity,dataRecord.w2_total_alkalinity);N=-Math.log10(((Math.pow(10,-dataRecord.w1_ph)*dataRecord.w1_amount)+(Math.pow(10,-dataRecord.w2_ph)*dataRecord.w2_amount))/T)}else{T=dataRecord.w1_amount;ai=dataRecord.w1_calcium;J=dataRecord.w1_magnesium;U=dataRecord.w1_sodium;L=dataRecord.w1_chloride;ad=dataRecord.w1_sulfate;K=dataRecord.w1_total_alkalinity;N=dataRecord.w1_ph}$("#wg_amount").val(T);ak=ai;$("#wg_calcium").val(Math.round(ai*10)/10);$("#wg_magnesium").val(Math.round(J*10)/10);V=U;$("#wg_sodium").val(Math.round(U*10)/10);al=K;$("#wg_total_alkalinity").val(Math.round(K*10)/10);H=L;$("#wg_chloride").val(Math.round(L*10)/10);ae=ad;$("#wg_sulfate").val(Math.round(ad*10)/10);$("#wg_ph").val(Round(N,1));$("#wb_ph").val(Round(MashpH(),1));af=K*1.22;C=af;W=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*MMCa/MMCaCl2+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*MMCa/MMCaSO4;ai+=1000*W/T;W=parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*MMMg/MMMgSO4;J+=1000*W/T;W=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*MMNa/MMNaCl;U+=1000*W/T;W=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*MMSO4/MMCaSO4+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*MMSO4/MMMgSO4;ad+=1000*W/T;W=2*parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*MMCl/MMCaCl2+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*MMCl/MMNaCl;L+=1000*W/T;if($("#wa_acid_name").val()<0||$("#wa_acid_name").val()>3){$("#wa_acid_name").val(0);dataRecord.wa_acid_name=0}if(last_acid==""){last_acid=AcidTypeData[$("#wa_acid_name").val()].nl}if($("#wa_base_name").val()<0||$("#wa_base_name").val()>3){$("#wa_base_name").val(0);dataRecord.wa_base_name=0}if(last_base==""){last_base=BaseTypeData[$("#wa_base_name").val()].nl}ah=dataRecord.wa_acid_name;X=dataRecord.wa_base_name;P=GetAcidSpecs(ah);E=P.pK1;D=P.pK2;B=P.pK3;O=P.MolWt;G=P.AcidSG;F=P.AcidPrc;if(dataRecord.calc_acid){am=parseFloat(dataRecord.mash_ph);aj=ProtonDeficit(am);console.log("calc_acid tgt: "+am+" protonDeficit: "+aj);if(aj>0){$("#wa_base").val(0);z(last_base,0);ao=CalcFrac(am,E,D,B);Acid=aj/ao;Acid*=O;Acidmg=Acid;Acid=Acid/G;if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(F)}Acid=Acid*F/(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);console.log("Final ml: "+Acid);$("#wa_acid").val(Math.round(Acid*100)/100);z(AcidTypeData[ah].nl,Math.round(Acid*100)/100);af=af-aj*ao/T;K=af*50/61}else{if(aj<0){$("#wa_acid").val(0);z(last_acid,0);Z=Math.pow(10,(am-6.38));R=Math.pow(10,(am-10.38));I=1/(1+Z+Z*R);aa=I*Z;S=aa*R;switch(X){case 0:W=-aj/(I-S);W=W*MMNaHCO3/1000;$("#wa_base").val(Round(W,2));z("NaHCO3",Round(W,2));if(T>0){W=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*MMNa/MMNaCl+parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMNa/MMNaHCO3;W=1000*W/T;U=V+W;W=parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMHCO3/MMNaHCO3;W=1000*W/T;af=C+W;K=af*50/61;W=ResidualAlkalinity(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 1:W=-aj/(2*I+aa);W=W*MMNa2CO3/1000;$("#wa_base").val(Round(W,2));z("Na2CO3",Round(W,2));if(T>0){W=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*MMNa/MMNaCl+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*MMNa/MMNa2CO3;W=1000*W/T;U=V+W;W=parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMHCO3/MMNa2CO3;W=1000*W/T;af=C+W;K=af*50/61;W=ResidualAlkalinity(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 2:W=-aj*(I-S);W=W*MMCaCO3/1000;W=3*W;$("#wa_base").val(Round(W,2));z("CaCO3",Round(W,2));if(T>0){W=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*MMHCO3/MMCaCO3;W=1000*W/T;af=C+W;K=af*50/61;W=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*MMCa/MMCaCl2+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*MMCa/MMCaSO4+parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMCa/MMCaCO3;W=1000*W/T;ai=ak+W;W=ResidualAlkalinity(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 3:W=-aj/19.3;$("#wa_base").val(Round(W,2));z("Ca(OH)2",Round(W,2));if(T>0){W=-aj/T;K=al+W;af=K*61/50;W=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*MMCa/MMCaCl2+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*MMCa/MMCaSO4+parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMCa/MMCaOH2;W=1000*W/T;ai=ak+W;W=ResidualAlkalinity(wb_total_alkalinity,wb_calcium,wb_magnesium)}break}}}N=am;$("#wb_ph").val(Math.round(N*10)/10)}else{console.log("calc_acid no");if(parseFloat($("#wa_base").jqxNumberInput("decimal"))>0){if(T>0){switch(X){case 0:W=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*MMNa/MMNaCl+parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMNa/MMNaHCO3;W=1000*W/T;U=V+W;W=parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMHCO3/MMNaHCO3;W=1000*W/T;af=C+W;K=af*50/61;W=ResidualAlkalinity(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 1:W=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*MMNa/MMNaCl+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*MMNa/MMNa2CO3;W=1000*W/T;U=V+W;W=parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMHCO3/MMNa2CO3;W=1000*W/T;af=C+W;K=af*50/61;W=ResidualAlkalinity(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 2:W=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*MMHCO3/MMCaCO3;W=1000*W/T;af=C+W;K=af*50/61;W=ResidualAlkalinity(wb_total_alkalinity,wb_calcium,wb_magnesium);W=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*MMCa/MMCaCl2+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*MMCa/MMCaSO4+parseFloat($("#wa_base").jqxNumberInput("decimal"))*MMCa/MMCaCO3;W=1000*W/T;ai=ak+W;break}}}am=parseFloat(dataRecord.mash_ph);pHa=MashpH();if(parseFloat($("#wa_acid").jqxNumberInput("decimal"))>0){console.log("TpH: "+am+" water: "+pHa);Acid=parseFloat($("#wa_acid").jqxNumberInput("decimal"));if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(F)}Acid=Acid/F*(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);Acid*=G;Acid/=O;Acidmg=Acid;ao=CalcFrac(pHa,E,D,B);aj=Acid*ao;ag=0.001;Y=0.1;Q=ProtonDeficit(pHa);ab=0;while(((Q<(aj-Y))||(Q>(aj+Y)))&&(ab<2000)){ab++;if(Q<(aj-Y)){pHa-=ag}else{if(Q>(aj+Y)){pHa+=ag}}ao=CalcFrac(pHa,E,D,B);aj=Acid*ao;Q=ProtonDeficit(pHa)}console.log("n: "+ab+" pd: "+Q+" protonDeficit: "+aj+" frac: "+ao+" pHa: "+pHa);W=C-aj*ao/T;af=W;K=W*50/61;N=pHa;$("#wb_ph").val(Round(N,1))}}if((ah==3)&&(T>0)){W=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*MMSO4/MMCaSO4+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*MMSO4/MMMgSO4+Acidmg/1000*MMSO4/(MMSO4+2);W=1000*W/T;ad=ae+W}else{if((ah==1)&&(T>0)){W=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*MMCl/MMCaCl2+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*MMCl/MMNaCl+Acidmg/1000*MMCl/(MMCl+1);W=1000*W/T;L=H+W}}$("#tgt_bu").val(Math.round(GetBUGU()*100)/100);if(GetBUGU()<0.32){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Zeer moutig en zoet</span>")}else{if(GetBUGU()<0.43){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Moutig, zoet</span>")}else{if(GetBUGU()<0.52){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Evenwichtig</span>")}else{if(GetBUGU()<0.63){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Licht hoppig, bitter</span>")}else{$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Extra hoppig, zeer bitter</span>")}}}}$("#tgt_cl_so4").val(Math.round(GetOptClSO4ratio()*10)/10);if(ad>0){W=L/ad}else{W=10}$("#got_cl_so4").val(Math.round(W*10)/10);an=0.8*GetOptClSO4ratio();ac=1.2*GetOptClSO4ratio();M="normaal";if(W<an){M="laag"}else{if(W>ac){M="hoog"}}setRangeIndicator("cl_so4",M);$("#wb_calcium").val(Round(ai,1));$("#wb_magnesium").val(Round(J,1));$("#wb_sodium").val(Round(U,1));$("#wb_sulfate").val(Round(ad,1));$("#wb_chloride").val(Round(L,1));$("#wb_total_alkalinity").val(Round(K,1));if(ai<40){setRangeIndicator("calcium","laag")}else{if(ai>150){setRangeIndicator("calcium","hoog")}else{setRangeIndicator("calcium","normaal")}}if(J>=0&&J<=30){setRangeIndicator("magnesium","normaal")}else{setRangeIndicator("magnesium","hoog")}if(U<=150){setRangeIndicator("sodium","normaal")}else{setRangeIndicator("sodium","hoog")}if(L<=50){setRangeIndicator("chloride","laag")}else{if(L<=100){setRangeIndicator("chloride","normaal")}else{setRangeIndicator("chloride","hoog")}}if(ad<=50){setRangeIndicator("sulfate","laag")}else{if(ad<=350){setRangeIndicator("sulfate","normaal")}else{setRangeIndicator("sulfate","hoog")}}if(N<5.2){setRangeIndicator("ph","laag")}else{if(N>5.6){setRangeIndicator("ph","hoog")}else{setRangeIndicator("ph","normaal")}}v()}function v(){var E,Q,O,W,V,Z,T,S,U,H,ae,ac,C,G,J,P,aa,Y,ab,R,D,I,N,M,L,K,ad,F,B,X;E=dataRecord.sparge_ph;Q=dataRecord.w1_ph;O=dataRecord.w1_total_alkalinity;if(dataRecord.sparge_source==1){if(dataRecord.w2_ph>0){Q=dataRecord.w2_ph;O=dataRecord.w2_total_alkalinity}else{dataRecord.sparge_source=0;$("#sparge_source").val(0)}}else{if(dataRecord.sparge_source==2){if(dataRecord.w2_ph>0){Q=parseFloat($("#wg_ph").jqxNumberInput("decimal"));O=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))}else{dataRecord.sparge_source=0;$("#sparge_source").val(0)}}}W=Math.pow(10,Q-6.38);V=Math.pow(10,Q-10.373);Z=1+W+W*V;T=1/Z;S=W*V/Z;U=Math.pow(10,4.3-6.38);H=Math.pow(10,4.3-10.373);ae=1+U+U*H;ac=1/ae;C=U*H/ae;G=O/50;J=(G-1000*(Math.pow(10,-4.3)-Math.pow(10,-Q)))/((ac-T)+(S-C));P=Math.pow(10,E-6.38);aa=Math.pow(10,E-10.373);Y=1+P+P*aa;ab=1/Y;R=P*aa/Y;D=J*((ab-T)+(S-R))+Math.pow(10,-E)-Math.pow(10,-Q);D+=0.01;if(dataRecord.sparge_acid_type<0||dataRecord.sparge_acid_type>3){dataRecord.sparge_acid_type=0;$("#sparge_acid_type").val(0)}I=dataRecord.sparge_acid_type;N=GetAcidSpecs(I);M=N.pK1;L=N.pK2;K=N.pK3;ad=N.MolWt;F=N.AcidSG;B=N.AcidPrc;X=CalcFrac(E,M,L,K);D/=X;D*=ad;D=D/F;T=dataRecord.sparge_acid_perc;if(T<=0.1){T=B}D=D*B/(T/100);D*=dataRecord.sparge_volume;D=Round(D,2);dataRecord.sparge_acid_amount=D/1000;$("#sparge_acid_amount").val(D)}function k(C){console.log("calcFermentablesFromOG("+C+")");var E,K,H,D,J,G=0,F=0,I,B=parseFloat($("#efficiency").jqxNumberInput("decimal"));J=sg_to_plato(C)*parseFloat($("#batch_size").jqxNumberInput("decimal"))*C/100;I=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(D=0;D<I;D++){K=$("#fermentableGrid").jqxGrid("getrowdata",D);if(K.f_added<4){H=K.f_percentage/100*(K.f_yield/100)*(1-K.f_moisture/100);if(K.f_added==0){H=B/100*H}G+=H}}if(G){F=Math.round((J/G)*1000)/1000}if(F){for(D=0;D<I;D++){K=$("#fermentableGrid").jqxGrid("getrowdata",D);if(K.f_added<4){E=Math.round(K.f_percentage*10*F)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",D,"f_amount",E)}}}}function a(){console.log("calc.init()");$("#calc_acid").on("checked",function(B){dataRecord.calc_acid=1;m()});$("#calc_acid").on("unchecked",function(B){dataRecord.calc_acid=0;m()});$("#w1_name").jqxDropDownList("selectItem",dataRecord.w1_name);$("#w2_name").jqxDropDownList("selectItem",dataRecord.w2_name);if(parseFloat($("#w1_amount").jqxNumberInput("decimal"))==0&&mash_infuse>0){$("#w1_amount").val(mash_infuse);dataRecord.w1_amount=mash_infuse;$("#wg_amount").val(mash_infuse);$("#w2_amount").val(0);dataRecord.w2_amount=0}m();$("#w2_amount").on("change",function(B){var C=parseFloat(B.args.value);if(C>mash_infuse){$("#w2_amount").val(dataRecord.w2_amount);return}dataRecord.w1_amount=parseFloat($("#wg_amount").jqxNumberInput("decimal"))-C;$("#w1_amount").val(dataRecord.w1_amount);dataRecord.w2_amount=C;console.log("new: "+B.args.value+" w1: "+dataRecord.w1_amount+"  w2: "+dataRecord.w2_amount);m()});$("#wa_cacl2").on("change",function(B){if(B.args){z("CaCl2",0);z("CaCl2",B.args.value);m()}});$("#wa_caso4").on("change",function(B){if(B.args){z("CaSO4",0);z("CaSO4",B.args.value);m()}});$("#wa_mgso4").on("change",function(B){if(B.args){z("MgSO4",0);z("MgSO4",B.args.value);m()}});$("#wa_nacl").on("change",function(B){if(B.args){z("NaCl",0);z("NaCl",B.args.value);m()}});$("#wa_base_name").on("change",function(C){if(C.args){var B=C.args.index;z(last_base,0);last_base=BaseTypeData[B].nl;z(last_base,parseFloat($("#wa_base").jqxNumberInput("decimal")));dataRecord.wa_base_name=B;m()}});$("#wa_base").on("change",function(C){var B=BaseTypeData[$("#wa_base_name").val()].nl;z(B,parseFloat(C.args.value));m()});$("#wa_acid_name").on("change",function(C){if(C.args){var B=C.args.index;z(last_acid,0);last_acid=AcidTypeData[B].nl;z(last_acid,parseFloat($("#wa_acid").jqxNumberInput("decimal")));dataRecord.wa_acid_name=B;m()}});$("#wa_acid").on("change",function(C){var B=AcidTypeData[$("#wa_acid_name").val()].nl;z(B,parseFloat(C.args.value));m()});$("#wa_acid_perc").on("change",function(B){m()});$("#color_method").on("change",function(B){dataRecord.color_method=B.args.index;calcFermentables()});$("#ibu_method").on("change",function(B){dataRecord.ibu_method=B.args.index;calcFermentables();calcIBUs()});$("#batch_size").on("change",function(D){console.log("batch_size change:"+D.args.value+" old:"+dataRecord.batch_size);var B,C=parseFloat(D.args.value)+dataRecord.boil_size-dataRecord.batch_size;B=parseFloat(D.args.value)/dataRecord.batch_size;dataRecord.boil_size=C;$("#boil_size").val(Round(C,2));dataRecord.sparge_volume*=B;$("#sparge_volume").val(dataRecord.sparge_volume);dataRecord.batch_size=parseFloat(D.args.value);k(parseFloat($("#est_og").jqxNumberInput("decimal")));adjustWaters(B);calcFermentables();adjustHops(B);adjustMiscs(B);adjustYeasts(B);calcIBUs();m();v();calcMash()});$("#boil_time").on("change",function(D){console.log("boil_time change:"+parseFloat(D.args.value)+" old:"+dataRecord.boil_time);var C,B,E=parseFloat(dataRecord.boil_size)-parseFloat(dataRecord.batch_size);B=E*(parseFloat(D.args.value)/dataRecord.boil_time);C=parseFloat(dataRecord.batch_size)+B;dataRecord.boil_time=parseFloat(D.args.value);dataRecord.boil_size=C;$("#boil_size").val(Round(C,2));calcFermentables();calcIBUs()});$("#efficiency").on("change",function(C){var B=parseFloat($("#est_og").jqxNumberInput("decimal"));dataRecord.efficiency=parseFloat(C.args.value);console.log("efficiency change:"+dataRecord.efficiency);k(B);calcFermentables();calcIBUs()});$("#est_og").on("change",function(B){dataRecord.est_og=parseFloat(B.args.value);console.log("est_og change:"+dataRecord.est_og);k(dataRecord.est_og);calcFermentables();calcIBUs();calcMash()});$("#mash_ph").on("change",function(B){dataRecord.mash_ph=parseFloat(B.args.value);m()});$("#sparge_ph").on("change",function(B){dataRecord.sparge_ph=parseFloat(B.args.value);v()});$("#sparge_volume").on("change",function(B){dataRecord.sparge_volume=parseFloat(B.args.value);v()});$("#sparge_source").on("change",function(C){if(C.args){var B=C.args.index;dataRecord.sparge_source=B;v()}});$("#sparge_acid_type").on("change",function(C){if(C.args){var B=C.args.index;dataRecord.sparge_acid_type=B;console.log("new sparge_acid_type: "+dataRecord.sparge_acid_type);v()}});$("#sparge_acid_perc").on("change",function(B){dataRecord.sparge_acid_perc=parseFloat(B.args.value);v()});$("#locked").on("checked",function(B){dataRecord.locked=1;setReadonly(true)});$("#locked").on("unchecked",function(B){dataRecord.locked=0;setReadonly(false)})}$("#styleSelect").jqxDropDownList({placeHolder:"Kies bierstijl:",theme:theme,source:styleslist,displayMember:"name",width:180,height:23,dropDownVerticalAlignment:"top",dropDownWidth:500,dropDownHeight:350,renderer:function(C,B,E){var D=styleslist.records[C];return D.style_guide+" "+D.style_letter+" "+D.name}});$("#styleSelect").on("select",function(D){if(D.args){var C,B=D.args.index;C=styleslist.records[B];$("#st_name").val(C.name);$("#st_category").val(C.category);$("#st_category_number").val(C.category_number);$("#st_letter").val(C.style_letter);$("#st_guide").val(C.style_guide);$("#st_type").val(StyleTypeData[C.type].nl);$("#st_og_min").val(C.og_min);$("#st_og_max").val(C.og_max);$("#st_fg_min").val(C.fg_min);$("#st_fg_max").val(C.fg_max);$("#st_ibu_min").val(C.ibu_min);$("#st_ibu_max").val(C.ibu_max);$("#st_color_min").val(C.color_min);$("#st_color_max").val(C.color_max);$("#st_carb_min").val(C.carb_min);$("#st_carb_max").val(C.carb_max);$("#st_abv_min").val(C.abv_min);$("#st_abv_max").val(C.abv_max)}});function d(){var C={record:my_record,uuid:dataRecord.uuid,name:$("#name").val(),locked:dataRecord.locked,notes:$("#notes").val(),st_name:$("#st_name").val(),st_letter:$("#st_letter").val(),st_guide:$("#st_guide").val(),st_type:dataRecord.st_type,st_category:$("#st_category").val(),st_category_number:parseFloat($("#st_category_number").jqxNumberInput("decimal")),st_og_min:parseFloat($("#st_og_min").jqxNumberInput("decimal")),st_og_max:parseFloat($("#st_og_max").jqxNumberInput("decimal")),st_fg_min:parseFloat($("#st_fg_min").jqxNumberInput("decimal")),st_fg_max:parseFloat($("#st_fg_max").jqxNumberInput("decimal")),st_ibu_min:parseFloat($("#st_ibu_min").jqxNumberInput("decimal")),st_ibu_max:parseFloat($("#st_ibu_max").jqxNumberInput("decimal")),st_color_min:parseFloat($("#st_color_min").jqxNumberInput("decimal")),st_color_max:parseFloat($("#st_color_max").jqxNumberInput("decimal")),st_carb_min:parseFloat($("#st_carb_min").jqxNumberInput("decimal")),st_carb_max:parseFloat($("#st_carb_max").jqxNumberInput("decimal")),st_abv_min:parseFloat($("#st_abv_min").jqxNumberInput("decimal")),st_abv_max:parseFloat($("#st_abv_max").jqxNumberInput("decimal")),type:$("#type").val(),batch_size:parseFloat($("#batch_size").jqxNumberInput("decimal")),boil_size:parseFloat($("#boil_size").jqxNumberInput("decimal")),boil_time:parseFloat($("#boil_time").jqxNumberInput("decimal")),efficiency:parseFloat($("#efficiency").jqxNumberInput("decimal")),est_og:parseFloat($("#est_og").jqxNumberInput("decimal")),est_fg:parseFloat($("#est_fg").jqxNumberInput("decimal")),est_abv:parseFloat($("#est_abv").jqxNumberInput("decimal")),est_color:parseFloat($("#est_color").jqxNumberInput("decimal")),color_method:$("#color_method").val(),est_ibu:parseFloat($("#est_ibu").jqxNumberInput("decimal")),ibu_method:$("#ibu_method").val(),est_carb:parseFloat($("#est_carb").jqxNumberInput("decimal")),mash_name:$("#mash_name").val(),mash_ph:parseFloat($("#mash_ph").jqxNumberInput("decimal")),sparge_temp:parseFloat($("#sparge_temp").jqxNumberInput("decimal")),sparge_ph:parseFloat($("#sparge_ph").jqxNumberInput("decimal")),sparge_volume:parseFloat($("#sparge_volume").jqxNumberInput("decimal")),sparge_source:$("#sparge_source").val(),sparge_acid_type:$("#sparge_acid_type").val(),sparge_acid_perc:parseFloat($("#sparge_acid_perc").jqxNumberInput("decimal")),sparge_acid_amount:dataRecord.sparge_acid_amount,calc_acid:dataRecord.calc_acid,w1_name:$("#w1_name").val(),w1_amount:parseFloat($("#w1_amount").jqxNumberInput("decimal")),w1_calcium:parseFloat($("#w1_calcium").jqxNumberInput("decimal")),w1_sulfate:parseFloat($("#w1_sulfate").jqxNumberInput("decimal")),w1_chloride:parseFloat($("#w1_chloride").jqxNumberInput("decimal")),w1_sodium:parseFloat($("#w1_sodium").jqxNumberInput("decimal")),w1_magnesium:parseFloat($("#w1_magnesium").jqxNumberInput("decimal")),w1_total_alkalinity:parseFloat($("#w1_total_alkalinity").jqxNumberInput("decimal")),w1_ph:parseFloat($("#w1_ph").jqxNumberInput("decimal")),w1_cost:dataRecord.w1_cost,w2_name:$("#w2_name").val(),w2_amount:parseFloat($("#w2_amount").jqxNumberInput("decimal")),w2_calcium:parseFloat($("#w2_calcium").jqxNumberInput("decimal")),w2_sulfate:parseFloat($("#w2_sulfate").jqxNumberInput("decimal")),w2_chloride:parseFloat($("#w2_chloride").jqxNumberInput("decimal")),w2_sodium:parseFloat($("#w2_sodium").jqxNumberInput("decimal")),w2_magnesium:parseFloat($("#w2_magnesium").jqxNumberInput("decimal")),w2_total_alkalinity:parseFloat($("#w2_total_alkalinity").jqxNumberInput("decimal")),w2_ph:parseFloat($("#w2_ph").jqxNumberInput("decimal")),w2_cost:dataRecord.w2_cost,wg_amount:parseFloat($("#wg_amount").jqxNumberInput("decimal")),wg_calcium:parseFloat($("#wg_calcium").jqxNumberInput("decimal")),wg_sulfate:parseFloat($("#wg_sulfate").jqxNumberInput("decimal")),wg_chloride:parseFloat($("#wg_chloride").jqxNumberInput("decimal")),wg_sodium:parseFloat($("#wg_sodium").jqxNumberInput("decimal")),wg_magnesium:parseFloat($("#wg_magnesium").jqxNumberInput("decimal")),wg_total_alkalinity:parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal")),wg_ph:parseFloat($("#wg_ph").jqxNumberInput("decimal")),wb_calcium:parseFloat($("#wb_calcium").jqxNumberInput("decimal")),wb_sulfate:parseFloat($("#wb_sulfate").jqxNumberInput("decimal")),wb_chloride:parseFloat($("#wb_chloride").jqxNumberInput("decimal")),wb_sodium:parseFloat($("#wb_sodium").jqxNumberInput("decimal")),wb_magnesium:parseFloat($("#wb_magnesium").jqxNumberInput("decimal")),wb_total_alkalinity:parseFloat($("#wb_total_alkalinity").jqxNumberInput("decimal")),wb_ph:parseFloat($("#wb_ph").jqxNumberInput("decimal")),wa_acid_name:$("#wa_acid_name").val(),wa_acid_perc:parseFloat($("#wa_acid_perc").jqxNumberInput("decimal")),wa_base_name:$("#wa_base_name").val(),fermentables:$("#fermentableGrid").jqxGrid("getrows"),hops:$("#hopGrid").jqxGrid("getrows"),miscs:$("#miscGrid").jqxGrid("getrows"),yeasts:$("#yeastGrid").jqxGrid("getrows"),mashs:$("#mashGrid").jqxGrid("getrows")},B="update=true&"+$.param(C);$.ajax({dataType:"json",url:f,cache:false,async:false,data:B,type:"POST",success:function(E,D,F){console.log("saveRecord() success")},error:function(D,F,E){console.log("saveRecord() error")}})}y.dataBind();$("#name").jqxTooltip({content:"De naam voor dit recept."});$("#name").jqxInput({theme:theme,width:640,height:23});$("#locked").jqxCheckBox({theme:theme,width:120,height:23});$("#notes").jqxTooltip({content:"De uitgebreide opmerkingen over dit recept."});$("#notes").jqxInput({theme:theme,width:960,height:200});$("#type").jqxTooltip({content:"Het brouw type van dit recept."});$("#type").jqxDropDownList({theme:theme,source:RecipeTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#efficiency").jqxTooltip({content:"Het rendement van maischen en koken."});$("#efficiency").jqxNumberInput(Perc1dec);$("#batch_size").jqxTooltip({content:"Het volume van het gekoelde wort na het koken."});$("#batch_size").jqxNumberInput(Spin1dec);$("#batch_size").jqxNumberInput({min:4});$("#boil_size").jqxTooltip({content:"Het volume van het wort voor het koken."});$("#boil_size").jqxNumberInput({inputMode:"simple",theme:theme,width:90,height:23,decimalDigits:2,readOnly:true});$("#boil_time").jqxTooltip({content:"De kooktijd in minuten."});$("#boil_time").jqxNumberInput(PosInt);$("#boil_time").jqxNumberInput({min:4,max:360});$("#st_name").jqxTooltip({content:"De bierstijl naam voor dit recept."});$("#st_name").jqxInput({theme:theme,width:250,height:23});$("#st_letter").jqxTooltip({content:"De bierstijl letter voor dit recept."});$("#st_letter").jqxInput({theme:theme,width:90,height:23});$("#st_guide").jqxTooltip({content:"De bierstijl gids voor dit recept."});$("#st_guide").jqxInput({theme:theme,width:250,height:23});$("#st_category").jqxTooltip({content:"De Amerikaanse bierstijl categorie."});$("#st_category").jqxInput({theme:theme,width:250,height:23});$("#st_category_number").jqxTooltip({content:"De Amerikaanse bierstijl categorie sub nummer."});$("#st_category_number").jqxNumberInput(Smal0dec);$("#st_type").jqxTooltip({content:"Het bierstijl type."});$("#st_type").jqxInput({theme:theme,width:250,height:23});$("#est_og").jqxTooltip({content:"Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend."});$("#est_og").jqxNumberInput(SGopts);$("#st_og_min").jqxTooltip({content:"Het minimum begin SG voor deze bierstijl."});$("#st_og_min").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#st_og_max").jqxTooltip({content:"Het maximum begin SG voor deze bierstijl."});$("#st_og_max").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#est_fg").jqxTooltip({content:"Het eind SG. Dit wordt automatisch berekend."});$("#est_fg").jqxNumberInput(Show3dec);$("#st_fg_min").jqxTooltip({content:"Het minimum eind SG voor deze bierstijl."});$("#st_fg_min").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#st_fg_max").jqxTooltip({content:"Het maximum eind SG voor deze bierstijl."});$("#st_fg_max").jqxNumberInput({inputMode:"simple",theme:theme,width:50,height:23,decimalDigits:3,readOnly:true});$("#est_abv").jqxTooltip({content:"Alcohol volume %. Dit wordt automatisch berekend."});$("#est_abv").jqxNumberInput(Smal1dec);$("#st_abv_min").jqxTooltip({content:"Het minimum alcohol volume % voor deze bierstijl."});$("#st_abv_min").jqxNumberInput(Smal1dec);$("#st_abv_max").jqxTooltip({content:"Het maximum alcohol volume % voor deze bierstijl."});$("#st_abv_max").jqxNumberInput(Smal1dec);$("#est_color").jqxTooltip({content:"De kleur in EBC. Dit wordt automatisch berekend."});$("#est_color").jqxNumberInput(Show0dec);$("#st_color_min").jqxTooltip({content:"De minimum kleur voor deze bierstijl."});$("#st_color_min").jqxNumberInput(Smal0dec);$("#st_color_max").jqxTooltip({content:"De maximum kleur voor deze bierstijl."});$("#st_color_max").jqxNumberInput(Smal0dec);$("#color_method").jqxDropDownList({theme:theme,source:ColorMethodAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#est_ibu").jqxTooltip({content:"De bitterheid in IBU. Dit wordt automatisch berekend."});$("#est_ibu").jqxNumberInput(Show0dec);$("#st_ibu_min").jqxTooltip({content:"De minimum bitterheid voor deze bierstijl."});$("#st_ibu_min").jqxNumberInput(Smal0dec);$("#st_ibu_max").jqxTooltip({content:"De maximum bitterheid voor deze bierstijl."});$("#st_ibu_max").jqxNumberInput(Smal0dec);$("#ibu_method").jqxDropDownList({theme:theme,source:IBUmethodAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#kcal").jqxTooltip({content:"Energie-inhoud in kcal/liter."});$("#kcal").jqxNumberInput(Smal0dec);$("#est_carb").jqxTooltip({content:"Koolzuur volume. Dit wordt automatisch berekend."});$("#est_carb").jqxNumberInput(Smal1dec);$("#st_carb_min").jqxTooltip({content:"Het minimum koolzuur volume voor deze bierstijl."});$("#st_carb_min").jqxNumberInput(Smal1dec);$("#st_carb_max").jqxTooltip({content:"Het maximum koolzuur volume voor deze bierstijl."});$("#st_carb_max").jqxNumberInput(Smal1dec);$("#est_color2").jqxTooltip({content:"De kleur in EBC. Dit wordt automatisch berekend."});$("#est_color2").jqxNumberInput(Show0dec);$("#est_og2").jqxTooltip({content:"Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend."});$("#est_og2").jqxNumberInput(Show3dec);$("#perc_malts").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:120,animationDuration:0,colorRanges:[{stop:90,color:"#008C00"},{stop:100,color:"#EB7331"},{stop:120,color:"#FF0000"}],renderText:function(B){return(Math.round(parseInt(B)*1.2))+"%"}});$("#perc_sugars").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:50,animationDuration:0,colorRanges:[{stop:20,color:"#008C00"},{stop:50,color:"#FF0000"}],renderText:function(B){return(Math.round(parseInt(B)*5)/10)+"%"}});$("#perc_cara").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:50,animationDuration:0,colorRanges:[{stop:25,color:"#008C00"},{stop:50,color:"#FF0000"}],renderText:function(B){return(Math.round(parseInt(B)*5)/10)+"%"}});$("#ferm_lintner").jqxProgressBar({width:300,height:23,theme:theme,showText:true,max:200,animationDuration:0,colorRanges:[{stop:30,color:"#FF0000"},{stop:40,color:"#EB7331"},{stop:200,color:"#008C00"}],renderText:function(B){return(parseInt(B)*2)+" lintner"}});$("#popupFermentable").jqxWindow({width:800,height:300,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#FermentableReady"),modalOpacity:0.4});$("#FermentableReady").jqxButton({template:"success",width:"90px",theme:theme});$("#FermentableReady").click(function(){var C,B=$("#fermentableGrid").jqxGrid("getrowid",u);console.log("FermentableReady row:"+u+" ID:"+B);C={f_name:e.f_name,f_origin:e.f_origin,f_supplier:e.f_supplier,f_amount:e.f_amount,f_cost:e.f_cost,f_type:e.f_type,f_yield:e.f_yield,f_color:e.f_color,f_coarse_fine_diff:e.f_coarse_fine_diff,f_moisture:e.f_moisture,f_diastatic_power:e.f_diastatic_power,f_protein:e.f_protein,f_max_in_batch:e.f_max_in_batch,f_graintype:e.f_graintype,f_added:e.f_added,f_dissolved_protein:e.f_dissolved_protein,f_recommend_mash:e.f_recommend_mash,f_add_after_boil:e.f_add_after_boil,f_adjust_to_total_100:e.f_adjust_to_total_100,f_percentage:e.f_percentage,f_di_ph:e.f_di_ph,f_acid_to_ph_57:e.f_acid_to_ph_57,f_inventory:e.f_inventory,f_avail:e.f_avail};$("#fermentableGrid").jqxGrid("updaterow",B,C);calcPercentages();calcFermentables();calcIBUs();calcMash()});$("#wf_name").jqxInput({theme:theme,width:320,height:23});$("#wf_instock").jqxCheckBox({theme:theme,height:23});$("#wf_instock").on("change",function(B){fermentableinstock=B.args.checked;fermentablelist.dataBind()});$("#wf_select").jqxDropDownList({placeHolder:"Kies mout:",theme:theme,source:fermentablelist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500,renderer:function(C,B,E){var D=fermentablelist.records[C];return D.supplier+" / "+D.name+" ("+D.color+" EBC)"}});$("#wf_select").on("select",function(D){if(D.args){var C,B=D.args.index;C=fermentablelist.records[B];$("#wf_name").val(C.name);e.f_name=C.name;e.f_origin=C.origin;e.f_supplier=C.supplier;e.f_type=C.type;e.f_cost=C.cost;e.f_yield=C.yield;e.f_color=C.color;e.f_coarse_fine_diff=C.coarse_fine_diff;e.f_moisture=C.moisture;e.f_diastatic_power=C.diastatic_power;e.f_protein=C.protein;e.f_max_in_batch=C.max_in_batch;e.f_graintype=C.graintype;e.f_dissolved_protein=C.dissolved_protein;e.f_recommend_mash=C.recommend_mash;e.f_add_after_boil=C.add_after_boil;e.f_di_ph=C.di_ph;e.f_acid_to_ph_57=C.acid_to_ph_57;e.f_inventory=C.inventory}});$("#wf_amount").jqxNumberInput(Spin3dec);$("#wf_amount").on("change",function(B){console.log("amount changed: "+B.args.value);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_amount",B.args.value);e.f_amount=B.args.value;if(!h){calcPercentages();calcFermentables();calcMash()}});$("#wf_percentage").jqxNumberInput(Perc1dec);$("#wf_percentage").on("change",function(C){var M,H,I,B,J,L,K,G,F,E,D=Round(e.f_percentage,1);E=C.args.value;console.log("percentage changed: "+E+" old: "+D);e.f_percent=E;J=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if((D!=E)&&(J>1)){L=$("#fermentableGrid").jqxGrid("getrowdata",u);if(L.f_adjust_to_total_100){$("#wf_percentage").val(D)}else{K=E-D;G=0;for(F=0;F<J;F++){L=$("#fermentableGrid").jqxGrid("getrowdata",F);if(L.f_added<4){G+=Round(L.f_amount,3)}}G=Round(G,3);if(h){I=Math.round(G*K*10)/1000;L=$("#fermentableGrid").jqxGrid("getrowdata",u);B=Round((L.f_amount+I),3);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_amount",B);$("#wf_amount").val(B);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_percentage",L.f_percentage+K);for(F=0;F<J;F++){L=$("#fermentableGrid").jqxGrid("getrowdata",F);if(L.f_adjust_to_total_100){B=L.f_amount-I;$("#fermentableGrid").jqxGrid("setcellvalue",F,"f_percentage",L.f_percentage-K);$("#fermentableGrid").jqxGrid("setcellvalue",F,"f_amount",B)}}calcFermentables();calcMash()}else{H=G*K/100;for(F=0;F<J;F++){L=$("#fermentableGrid").jqxGrid("getrowdata",F);if(L.f_added<4){if(F==u){B=Math.round((L.f_amount+H)*1000)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",F,"f_amount",B);$("#fermentableGrid").jqxGrid("setcellvalue",F,"f_percentage",E)}else{B=Round((L.f_amount-(H/(J-1))),3);M=Round((B/G)*100,1);$("#fermentableGrid").jqxGrid("setcellvalue",F,"f_amount",B);$("#fermentableGrid").jqxGrid("setcellvalue",F,"f_percentage",M)}}else{$("#fermentableGrid").jqxGrid("setcellvalue",F,"f_percentage",0)}}calcFermentables();calcMash()}}}});$("#wf_max_in_batch").jqxNumberInput(Show1dec);$("#wf_adjust_to_total_100").jqxCheckBox({theme:theme,width:120,height:23});$("#wf_adjust_to_total_100").on("checked",function(B){if(e.f_adjust_to_total_100==0){if(h){rowscount=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(i=0;i<rowscount;i++){if(i!=u){$("#fermentableGrid").jqxGrid("setcellvalue",i,"f_adjust_to_total_100",0)}}}$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_adjust_to_total_100",1);calcFermentables()}});$("#wf_adjust_to_total_100").on("unchecked",function(B){if(e.f_adjust_to_total_100!=0){$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_adjust_to_total_100",0);calcFermentables()}});$("#wf_added").jqxDropDownList({theme:theme,source:AddedAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wf_added").on("select",function(C){if(C.args){var B=C.args.index;$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_added",B);calcFermentables();calcIBUs();calcMash()}});$("#est_ibu2").jqxTooltip({content:"De bitterheid in IBU. Dit wordt automatisch berekend."});$("#est_ibu2").jqxNumberInput(Smal0dec);$("#hop_flavour").jqxProgressBar({width:300,height:23,theme:theme,showText:true,animationDuration:0,colorRanges:[{stop:20,color:"#004D00"},{stop:40,color:"#008C00"},{stop:60,color:"#00BF00"},{stop:80,color:"#00FF00"},{stop:100,color:"#80FF80"}],renderText:function(C){var B=parseInt(C);if(B<20){return"Weinig"}else{if(B<40){return"Matig"}else{if(B<60){return"Redelijk"}else{if(B<80){return"Veel"}else{return"Zeer veel"}}}}}});$("#hop_aroma").jqxProgressBar({width:300,height:23,theme:theme,showText:true,animationDuration:0,colorRanges:[{stop:20,color:"#004D00"},{stop:40,color:"#008C00"},{stop:60,color:"#00BF00"},{stop:80,color:"#00FF00"},{stop:100,color:"#80FF80"}],renderText:function(C){var B=parseInt(C);if(B<20){return"Weinig"}else{if(B<40){return"Matig"}else{if(B<60){return"Redelijk"}else{if(B<80){return"Veel"}else{return"Zeer veel"}}}}}});$("#popupHop").jqxWindow({width:800,height:300,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#HopReady"),modalOpacity:0.4});$("#HopReady").jqxButton({template:"success",width:"90px",theme:theme});$("#HopReady").click(function(){var C,B=$("#hopGrid").jqxGrid("getrowid",o);console.log("HopReady row:"+o+" ID:"+B);C={h_name:$("#wh_name").val(),h_origin:t.h_origin,h_amount:parseFloat($("#wh_amount").jqxNumberInput("decimal"))/1000,h_cost:t.h_cost,h_type:t.h_type,h_form:t.h_form,h_useat:$("#wh_useat").val(),h_time:t.h_time,h_alpha:t.h_alpha,h_beta:t.h_beta,h_hsi:t.h_hsi,h_humulene:t.h_humulene,h_caryophyllene:t.h_caryophyllene,h_cohumulone:t.h_cohumulone,h_myrcene:t.h_myrcene,h_total_oil:t.h_total_oil,h_inventory:t.h_inventory,h_avail:t.h_avail};$("#hopGrid").jqxGrid("updaterow",B,C);calcIBUs()});$("#wh_name").jqxInput({theme:theme,width:320,height:23});$("#wh_instock").jqxCheckBox({theme:theme,height:23});$("#wh_instock").on("change",function(B){hopinstock=B.args.checked;hoplist.dataBind()});$("#wh_select").jqxDropDownList({placeHolder:"Kies hop:",theme:theme,source:hoplist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500,renderer:function(C,B,E){var D=hoplist.records[C];return D.origin+" / "+D.name+" ("+D.alpha+" % &alpha;)"}});$("#wh_select").on("select",function(D){if(D.args){var C,B=D.args.index;C=hoplist.records[B];$("#wh_name").val(C.name);t.h_name=C.name;t.h_origin=C.origin;t.h_cost=C.cost;t.h_type=C.type;t.h_form=C.form;t.h_alpha=C.alpha;t.h_beta=C.beta;t.h_hsi=C.hsi;t.h_humulene=C.humulene;t.h_caryophyllene=C.caryophyllene;t.h_cohumulone=C.cohumulone;t.h_myrcene=C.myrcene;t.h_total_oil=C.total_oil;t.h_inventory=C.inventory}});$("#wh_amount").jqxNumberInput(Spin1dec);$("#wh_amount").on("change",function(C){var D,B=parseFloat(C.args.value)/1000;D=toIBU(t.h_useat,t.h_form,preboil_sg,parseFloat($("#batch_size").jqxNumberInput("decimal")),B,parseFloat(t.h_time),parseFloat(t.h_alpha),$("#ibu_method").val());t.h_amount=B;console.log("amount changed: "+C.args.value+" time:"+t.h_time+" alpha:"+t.h_alpha+" IBU:"+D);$("#wh_ibu").val(D)});$("#wh_ibu").jqxNumberInput(Show1dec);$("#wh_time").jqxNumberInput(PosInt);$("#wh_time").on("change",function(B){var D,C=parseFloat(B.args.value);if(t.h_useat==2){if(C>parseFloat($("#boil_time").jqxNumberInput("decimal"))){C=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wh_time").val(C)}t.h_time=C}else{if(t.h_useat==4){if(C>120){C=120;$("#wh_time").val(C)}t.h_time=C}else{if(t.h_useat==5){if(C>21){C=21;$("#wh_time").val(C)}t.h_time=C*1440}}}D=toIBU(t.h_useat,t.h_form,preboil_sg,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(t.h_amount),parseFloat(t.h_time),parseFloat(t.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(D)});$("#wh_useat").jqxDropDownList({theme:theme,source:HopUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wh_useat").on("select",function(C){if(C.args){var B=C.args.index;t.h_useat=B;if((B==0)||(B==1)){t.h_time=parseFloat(dataRecord.boil_time);$("#wh_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wh_time").val(t.h_time)}else{if(B==3){t.h_time=0;$("#wh_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wh_time").val(0)}else{$("#wh_time").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}}if(B==5){$("#wh_pmpt_time").html("Tijd in dagen")}else{$("#wh_pmpt_time").html("Tijd in minuten")}}});$("#popupMisc").jqxWindow({width:800,height:275,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#MiscReady"),modalOpacity:0.4});$("#MiscReady").jqxButton({template:"success",width:"90px",theme:theme});$("#MiscReady").click(function(){var C,B=$("#miscGrid").jqxGrid("getrowid",q);console.log("MiscReady row:"+q+" ID:"+B);C={m_name:p.m_name,m_amount:p.m_amount,m_cost:p.m_cost,m_type:p.m_type,m_use_use:p.m_use_use,m_time:p.m_time,m_amount_is_weight:p.m_amount_is_weight,m_inventory:p.m_inventory,m_avail:p.m_avail};$("#miscGrid").jqxGrid("updaterow",B,C)});$("#wm_name").jqxInput({theme:theme,width:320,height:23});$("#wm_instock").jqxCheckBox({theme:theme,height:23});$("#wm_instock").on("change",function(B){miscinstock=B.args.checked;misclist.dataBind()});$("#wm_select").jqxDropDownList({placeHolder:"Kies ingredi&euml;nt:",theme:theme,source:misclist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500});$("#wm_select").on("select",function(D){if(D.args){var C,B=D.args.index;C=misclist.records[B];$("#wm_name").val(C.name);p.m_name=C.name;p.m_cost=C.cost;p.m_type=C.type;p.m_use_use=C.use_use;p.m_amount_is_weight=C.amount_is_weight;p.m_inventory=C.inventory}});$("#wm_amount").jqxNumberInput(Spin1dec);$("#wm_amount").on("change",function(B){console.log("amount changed: "+B.args.value);p.m_amount=parseFloat(B.args.value)/1000});$("#wm_time").jqxNumberInput(PosInt);$("#wm_time").on("change",function(B){console.log("time changed: "+B.args.value);var C=parseFloat(B.args.value);if(p.m_use_use==2){if(C>parseFloat($("#boil_time").jqxNumberInput("decimal"))){C=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wm_time").val(C)}p.m_time=C}else{if((p.m_use_use==3)||(p.m_use_use==4)){if(C>21){C=21;$("#wm_time").val(C)}p.m_time=C*1440}}});$("#wm_use_use").jqxDropDownList({theme:theme,source:MiscUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wm_use_use").on("select",function(C){if(C.args){var B=C.args.index;p.m_use_use=B;if((B==2)||(B==3)||(B==4)){$("#wm_time").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}else{p.m_time=0;$("#wm_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wm_time").val(0)}}});$("#est_fg2").jqxTooltip({content:"Het eind SG. Dit wordt automatisch berekend."});$("#est_fg2").jqxNumberInput(Show3dec);$("#est_abv2").jqxTooltip({content:"Alcohol volume %. Dit wordt automatisch berekend."});$("#est_abv2").jqxNumberInput(Smal1dec);$("#popupYeast").jqxWindow({width:800,height:300,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#YeastReady"),modalOpacity:0.4});$("#YeastReady").jqxButton({template:"success",width:"90px",theme:theme});$("#YeastReady").click(function(){var C,B=$("#yeastGrid").jqxGrid("getrowid",c);console.log("YeastReady row:"+c+" ID:"+B);C={y_name:g.y_name,y_laboratory:g.y_laboratory,y_product_id:g.y_product_id,y_amount:g.y_amount,y_cost:g.y_cost,y_type:g.y_type,y_form:g.y_form,y_flocculation:g.y_flocculation,y_min_temperature:g.y_min_temperature,y_max_temperature:g.y_max_temperature,y_attenuation:g.y_attenuation,y_use:g.y_use,y_cells:g.y_cells,y_tolerance:g.y_tolerance,y_inventory:g.y_inventory,y_avail:g.y_avail};$("#yeastGrid").jqxGrid("updaterow",B,C);calcFermentables()});$("#wy_name").jqxInput({theme:theme,width:320,height:23});$("#wy_laboratory").jqxInput({theme:theme,width:320,height:23});$("#wy_product_id").jqxInput({theme:theme,width:320,height:23});$("#wy_instock").jqxCheckBox({theme:theme,height:23});$("#wy_instock").on("change",function(B){yeastinstock=B.args.checked;yeastlist.dataBind()});$("#wy_select").jqxDropDownList({placeHolder:"Kies gist:",theme:theme,source:yeastlist,displayMember:"name",width:150,height:23,dropDownWidth:500,dropDownHeight:500,renderer:function(C,B,E){var D=yeastlist.records[C];return D.laboratory+" "+D.product_id+" "+D.name}});$("#wy_select").on("select",function(D){if(D.args){var C,B=D.args.index;C=yeastlist.records[B];$("#wy_name").val(C.name);$("#wy_laboratory").val(C.laboratory);$("#wy_product_id").val(C.product_id);g.y_name=C.name;g.y_cost=C.cost;g.y_type=C.type;g.y_form=C.form;g.y_laboratory=C.laboratory;g.y_product_id=C.product_id;g.y_min_temperature=C.min_temperature;g.y_max_temperature=C.max_temperature;g.y_flocculation=C.flocculation;g.y_attenuation=C.attenuation;g.y_cells=C.cells;g.y_inventory=C.inventory;if(g.y_form==0){$("#wy_pmpt_amount").html("Pak(ken):")}else{if(g.y_form==1){$("#wy_pmpt_amount").html("Gewicht gram:")}else{$("#wy_pmpt_amount").html("Volume ml:")}}calcFermentables()}});$("#wy_amount").jqxNumberInput(Spin1dec);$("#wy_amount").on("change",function(C){console.log("amount changed: "+C.args.value);var B;if(g.y_form==0){B=parseFloat(C.args.value)}else{B=parseFloat(C.args.value)/1000}g.y_amount=B;calcFermentables()});$("#wy_use").jqxDropDownList({theme:theme,source:YeastUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wy_use").on("select",function(C){if(C.args){var B=C.args.index;g.y_use=B;calcFermentabes()}});$("#mash_name").jqxInput({theme:theme,width:320,height:23});$("#mash_select").jqxDropDownList({placeHolder:"Kies schema:",theme:theme,source:mashlist,displayMember:"name",width:250,height:23,dropDownWidth:500,dropDownHeight:500,dropDownHorizontalAlignment:"right"});$("#mash_select").on("select",function(F){if(F.args){var H,E,D,I,G,B,C=F.args.index;B=new Array();G=$("#mashGrid").jqxGrid("getdisplayrows");for(D=0;D<G.length;D++){I=G[D];B.push(I.uid)}$("#mashGrid").jqxGrid("deleterow",B);E=mashlist.records[C];$("#mash_name").val(E.name);for(D=0;D<E.steps.length;D++){H=E.steps[D];I={};I.step_name=H.step_name;I.step_type=H.step_type;if(mash_infuse==0&&dataRecord.w1_amount>0){mash_infuse=dataRecord.w1_amount}if(D==0){I.step_infuse_amount=mash_infuse}else{I.step_infuse_amount=0}I.step_temp=H.step_temp;if(mashkg>0){I.step_thickness=parseFloat(mash_infuse/mashkg)}else{I.step_thickness=0}I.end_temp=H.end_temp;I.step_time=H.step_time;I.ramp_time=H.ramp_time;$("#mashGrid").jqxGrid("addrow",null,I)}}});$("#popupMash").jqxWindow({width:800,height:350,position:{x:230,y:100},resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#MashReady"),modalOpacity:0.4});$("#MashReady").jqxButton({template:"success",width:"90px",theme:theme});$("#MashReady").click(function(){calcMash()});$("#wstep_name").jqxInput({theme:theme,width:320,height:23});$("#wstep_name").on("change",function(B){var C=$("#mashGrid").jqxGrid("getrowdata",l);C.step_name=B.args.value});$("#wstep_type").jqxDropDownList({theme:theme,source:MashStepTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#wstep_type").on("select",function(D){if(D.args){var G,E,C,F,B=D.args.index;G=$("#mashGrid").jqxGrid("getrowdata",l);G.step_type=B;if(B==0){$("#wstep_infuse_amount").show();$("#wstep_pmpt").show()}else{G.step_infuse_amount=0;$("#wstep_infuse_amount").hide();$("#wstep_pmpt").hide()}mash_infuse=0;E=$("#mashGrid").jqxGrid("getrows");for(C=0;C<E.length;C++){F=E[C];if(F.step_type==0){mash_infuse+=parseFloat(F.step_infuse_amount)}}}});$("#wstep_temp").jqxNumberInput(Spin1dec);$("#wstep_temp").on("change",function(B){var C=$("#mashGrid").jqxGrid("getrowdata",l);C.step_temp=parseFloat(B.args.value)});$("#wend_temp").jqxNumberInput(Spin1dec);$("#wend_temp").on("change",function(B){var C=$("#mashGrid").jqxGrid("getrowdata",l);C.end_temp=parseFloat(B.args.value)});$("#wstep_time").jqxNumberInput(PosInt);$("#wstep_time").on("change",function(B){var C=$("#mashGrid").jqxGrid("getrowdata",l);C.step_time=parseFloat(B.args.value)});$("#wramp_time").jqxNumberInput(PosInt);$("#wramp_time").on("change",function(B){var C=$("#mashGrid").jqxGrid("getrowdata",l);C.ramp_time=parseFloat(B.args.value)});$("#wstep_infuse_amount").jqxNumberInput(Spin1dec);$("#wstep_infuse_amount").on("change",function(C){var B,D,E,F=$("#mashGrid").jqxGrid("getrowdata",l);F.step_infuse_amount=parseFloat(C.args.value);mash_infuse=0;D=$("#mashGrid").jqxGrid("getrows");for(B=0;B<D.length;B++){E=D[B];if(E.step_type==0){mash_infuse+=parseFloat(E.step_infuse_amount)}}if(dataRecord.w2_amount==0){dataRecord.w1_amount=mash_infuse;$("#w1_amount").val(mash_infuse)}else{dataRecord.w1_amount=(dataRecord.w1_amount/(dataRecord.w1_amount+dataRecord.w2_amount))*mash_infuse;dataRecord.w2_amount=(dataRecord.w2_amount/(dataRecord.w1_amount+dataRecord.w2_amount))*mash_infuse;$("#w1_amount").val(dataRecord.w1_amount);$("#w2_amount").val(dataRecord.w2_amount)}$("#wg_amount").val(mash_infuse)});$("#tgt_bu").jqxNumberInput(Show2wat);$("#tgt_cl_so4").jqxNumberInput(Show1wat);$("#got_cl_so4").jqxNumberInput(Show1wat);$("#w1_name").jqxDropDownList({placeHolder:"Kies hoofd water:",theme:theme,source:waterlist,displayMember:"name",width:250,height:27,dropDownWidth:400,dropDownHeight:400});$("#w1_name").on("select",function(D){if(D.args){var C,B=D.args.index;C=waterlist.records[B];dataRecord.w1_name=C.name;$("#w1_calcium").val(C.calcium);dataRecord.w1_calcium=C.calcium;$("#w1_sulfate").val(C.sulfate);dataRecord.w1_sulfate=C.sulfate;$("#w1_chloride").val(C.chloride);dataRecord.w1_chloride=C.chloride;$("#w1_sodium").val(C.sodium);dataRecord.w1_sodium=C.sodium;$("#w1_magnesium").val(C.magnesium);dataRecord.w1_magnesium=C.magnesium;$("#w1_total_alkalinity").val(C.total_alkalinity);dataRecord.w1_total_alkalinity=C.total_alkalinity;$("#w1_ph").val(C.ph);dataRecord.w1_ph=C.ph;$("#w1_cost").val(C.cost);dataRecord.w1_cost=C.cost;m()}});$("#w1_amount").jqxNumberInput(Show1wat);$("#w1_calcium").jqxNumberInput(Show1wat);$("#w1_magnesium").jqxNumberInput(Show1wat);$("#w1_sodium").jqxNumberInput(Show1wat);$("#w1_total_alkalinity").jqxNumberInput(Show1wat);$("#w1_chloride").jqxNumberInput(Show1wat);$("#w1_sulfate").jqxNumberInput(Show1wat);$("#w1_ph").jqxNumberInput(Show1wat);$("#w2_name").jqxDropDownList({placeHolder:"Kies meng water:",theme:theme,source:waterlist,displayMember:"name",width:250,height:27,dropDownWidth:400,dropDownHeight:400});$("#w2_name").on("select",function(D){if(D.args){var C,B=D.args.index;C=waterlist.records[B];dataRecord.w2_name=C.name;$("#w2_calcium").val(C.calcium);dataRecord.w2_calcium=C.calcium;$("#w2_sulfate").val(C.sulfate);dataRecord.w2_sulfate=C.sulfate;$("#w2_chloride").val(C.chloride);dataRecord.w2_chloride=C.chloride;$("#w2_sodium").val(C.sodium);dataRecord.w2_sodium=C.sodium;$("#w2_magnesium").val(C.magnesium);dataRecord.w2_magnesium=C.magnesium;$("#w2_total_alkalinity").val(C.total_alkalinity);dataRecord.w2_total_alkalinity=C.total_alkalinity;$("#w2_ph").val(C.ph);dataRecord.w2_ph=C.ph;$("#w2_cost").val(C.cost);dataRecord.w2_cost=C.cost;$("#w2_amount").jqxNumberInput({max:100000,readOnly:false});m()}});$("#w2_amount").jqxTooltip({content:"De verdeling van het hoofd en meng water. Het totale maisch water volume blijft gelijk."});$("#w2_amount").jqxNumberInput({inputMode:"simple",theme:theme,width:94,height:23,min:0,decimalDigits:1,spinButtons:true,readOnly:true});$("#w2_calcium").jqxNumberInput(Show1wat);$("#w2_magnesium").jqxNumberInput(Show1wat);$("#w2_sodium").jqxNumberInput(Show1wat);$("#w2_total_alkalinity").jqxNumberInput(Show1wat);$("#w2_chloride").jqxNumberInput(Show1wat);$("#w2_sulfate").jqxNumberInput(Show1wat);$("#w2_ph").jqxNumberInput(Show1wat);$("#wg_amount").jqxNumberInput(Show1wat);$("#wg_calcium").jqxNumberInput(Show1wat);$("#wg_magnesium").jqxNumberInput(Show1wat);$("#wg_sodium").jqxNumberInput(Show1wat);$("#wg_total_alkalinity").jqxNumberInput(Show1wat);$("#wg_chloride").jqxNumberInput(Show1wat);$("#wg_sulfate").jqxNumberInput(Show1wat);$("#wg_ph").jqxNumberInput(Show1wat);$("#wb_calcium").jqxTooltip({content:"De ideale hoeveelheid Calcium is tussen 40 en 150."});$("#wb_calcium").jqxNumberInput(Show1wat);$("#wb_magnesium").jqxTooltip({content:"De ideale hoeveelheid Magnesium is lager dan 30."});$("#wb_magnesium").jqxNumberInput(Show1wat);$("#wb_sodium").jqxTooltip({content:"De ideale hoeveelheid Natrium is lager dan 150."});$("#wb_sodium").jqxNumberInput(Show1wat);$("#wb_chloride").jqxTooltip({content:"De ideale hoeveelheid Chloride is tussen 50 en 100."});$("#wb_chloride").jqxNumberInput(Show1wat);$("#wb_sulfate").jqxTooltip({content:"De ideale hoeveelheid Sulfaat is tussen 50 en 350."});$("#wb_sulfate").jqxNumberInput(Show1wat);$("#wb_total_alkalinity").jqxNumberInput(Show1wat);$("#wb_ph").jqxNumberInput(Show1wat);$("#pr_name").jqxDropDownList({placeHolder:"Kies doel profiel:",theme:theme,source:waterprofiles,displayMember:"name",width:250,height:27,dropDownWidth:400,dropDownHeight:300});$("#pr_name").on("select",function(D){if(D.args){var C,B=D.args.index;C=waterprofiles.records[B];$("#pr_calcium").val(C.calcium);$("#pr_sulfate").val(C.sulfate);$("#pr_chloride").val(C.chloride);$("#pr_sodium").val(C.sodium);$("#pr_magnesium").val(C.magnesium);$("#pr_total_alkalinity").val(C.total_alkalinity)}});$("#pr_calcium").jqxNumberInput(Show1wat);$("#pr_magnesium").jqxNumberInput(Show1wat);$("#pr_sodium").jqxNumberInput(Show1wat);$("#pr_total_alkalinity").jqxNumberInput(Show1wat);$("#pr_chloride").jqxNumberInput(Show1wat);$("#pr_sulfate").jqxNumberInput(Show1wat);$("#wa_cacl2").jqxTooltip({content:"Voor het maken van een ander waterprofiel. Voegt calcium en chloride toe. Voor het verbeteren van zoetere bieren."});$("#wa_cacl2").jqxNumberInput(Spin1dec);$("#wa_caso4").jqxTooltip({content:"Gips. Voor het maken van een ander waterprofiel. Voegt calcium en sulfaat toe. Voor het verbeteren van bittere bieren."});$("#wa_caso4").jqxNumberInput(Spin1dec);$("#wa_mgso4").jqxTooltip({content:"Epsom zout. Voor het maken van een ander waterprofiel. Voegt magnesium en sulfaat toe. Gebruik spaarzaam!"});$("#wa_mgso4").jqxNumberInput(Spin1dec);$("#wa_nacl").jqxTooltip({content:"Keukenzout. Voor het maken van een ander waterprofiel. Voegt natrium en chloride toe. Voor het accentueren van zoetheid. Bij hoge dosering wordt het bier ziltig."});$("#wa_nacl").jqxNumberInput(Spin1dec);$("#mash_ph").jqxTooltip({content:"Maisch pH tussen 5.2 en 5.6. Gebruik 5.2 voor lichte en 5.5 voor donkere bieren."});$("#mash_ph").jqxNumberInput(SpinpH);$("#calc_acid").jqxCheckBox({theme:theme,width:120,height:23});$("#wa_base_name").jqxDropDownList({theme:theme,source:BaseTypeAdapter,valueMember:"id",displayMember:"nl",width:170,height:23,autoDropDownHeight:true});$("#wa_base").jqxNumberInput(Spin2dec);$("#wa_base").jqxNumberInput({symbol:" gr",symbolPosition:"right"});$("#wa_acid_name").jqxDropDownList({theme:theme,source:AcidTypeAdapter,valueMember:"id",displayMember:"nl",width:170,height:23,autoDropDownHeight:true});$("#wa_acid").jqxNumberInput(Spin2dec);$("#wa_acid").jqxNumberInput({symbol:" ml",symbolPosition:"right"});$("#wa_acid_perc").jqxNumberInput(Perc0);$("#wa_acid_perc").jqxNumberInput({width:70,symbol:"%",symbolPosition:"right"});$("#sparge_temp").jqxNumberInput(Spin1dec);$("#sparge_volume").jqxNumberInput(Spin1dec);$("#sparge_ph").jqxNumberInput(SpinpH);$("#sparge_source").jqxDropDownList({theme:theme,source:SpargeSourceAdapter,valueMember:"id",displayMember:"nl",width:110,height:23,autoDropDownHeight:true});$("#sparge_acid_amount").jqxNumberInput(Spin2dec);$("#sparge_acid_amount").jqxNumberInput({spinButtons:false,readOnly:true,symbol:" ml",symbolPosition:"right"});$("#sparge_acid_type").jqxDropDownList({theme:theme,source:AcidTypeAdapter,valueMember:"id",displayMember:"nl",width:110,height:23,autoDropDownHeight:true});$("#sparge_acid_perc").jqxNumberInput(Perc0);$("#sparge_acid_perc").jqxNumberInput({symbol:"%",symbolPosition:"right"});$("#jqxTabs").jqxTabs({theme:theme,width:1280,height:660,autoHeight:false,position:"top"});$("#Export").jqxButton({template:"info",width:"80px",theme:theme});$("#Export").bind("click",function(){d();window.location.href="rec_export.php?record="+my_record+"&return="+my_return+"&name="+dataRecord.name});$("#Delete").jqxButton({template:"danger",width:"80px",theme:theme});$("#Delete").bind("click",function(){$("#eventWindow").jqxWindow("open");$("#delOk").click(function(){var B="delete=true&"+$.param({record:my_record});$.ajax({dataType:"json",url:f,cache:false,data:B,type:"POST",success:function(D,C,E){window.location.href=my_return},error:function(C,E,D){}})})});$("#Cancel").jqxButton({template:"primary",width:"80px",theme:theme});$("#Cancel").bind("click",function(){window.location.href=my_return});$("#Save").jqxButton({template:"success",width:"80px",theme:theme});$("#Save").bind("click",function(){d();window.location.href=my_return});createDelElements()});
\ No newline at end of file
--- a/www/js/rec_edit.js	Sat Sep 07 20:27:06 2019 +0200
+++ b/www/js/rec_edit.js	Mon Sep 09 20:03:50 2019 +0200
@@ -20,3991 +20,3977 @@
  * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  *****************************************************************************/
 
+ var psugar = 0,     // Percentage real sugars
+ pcara = 0,          // Percentage cara/crystal malts
+ svg = 77,           // Default attenuation
+ mashkg = 0,         // Malt in mash weight
+ mash_infuse = 0,
+ dataRecord = {},    // Main recipe record
+ hop_flavour = 0,
+ hop_aroma = 0,
+ preboil_sg = 0,
+ last_base = '',
+ last_acid = '',
+ Ka1 = 0.0000004445,
+ Ka2 = 0.0000000000468,
+ MMCa = 40.048,
+ MMMg = 24.305,
+ MMNa = 22.98976928,
+ MMCl = 35.453,
+ MMSO4 = 96.0626,
+ MMCO3 = 60.01684,
+ MMHCO3 = 61.01684,
+ MMCaSO4 = 172.171,
+ MMCaCl2 = 147.015,
+ MMCaCO3 = 100.087,
+ MMMgSO4 = 246.475,
+ MMNaHCO3 = 84.007,
+ MMNa2CO3 = 105.996,
+ MMNaCl = 58.443,
+ MMCaOH2 = 74.06268;
+
 
 function createDelElements() {
-	$('#eventWindow').jqxWindow({
-		theme: theme,
-		position: { x: 490, y: 210 },
-		width: 300,
-		height: 175,
-		resizable: false,
-		isModal: true,
-		modalOpacity: 0.4,
-		okButton: $('#delOk'),
-		cancelButton: $('#delCancel'),
-		initContent: function () {
-			$('#delOk').jqxButton({ template: "danger", width: '65px', theme: theme });
-			$('#delCancel').jqxButton({ template: "success", width: '65px', theme: theme });
-			$('#delCancel').focus();
-		}
-	});
-	$('#eventWindow').jqxWindow('hide');
+ $('#eventWindow').jqxWindow({
+  theme: theme,
+  position: { x: 490, y: 210 },
+  width: 300,
+  height: 175,
+  resizable: false,
+  isModal: true,
+  modalOpacity: 0.4,
+  okButton: $('#delOk'),
+  cancelButton: $('#delCancel'),
+  initContent: function() {
+   $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme });
+   $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme });
+   $('#delCancel').focus();
+  }
+ });
+ $('#eventWindow').jqxWindow('hide');
+}
+
+
+function hopFlavourContribution(bt, vol, use, amount) {
+ var result;
+
+ if (use == 1) {   // First wort
+  result = 0.15;   // assume 15% flavourcontribution for fwh
+ } else if (bt > 50) {
+  result = 0.10;   // assume 10% flavourcontribution as a minimum
+ } else {
+  result = 15.25 / (6 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 21) / 6, 2));
+  if (result < 0.10)
+   result = 0.10;  // assume 10% flavourcontribution as a minimum
+ }
+ return (result * amount * 1000) / vol;
+}
+
+
+function hopAromaContribution(bt, vol, use, amount) {
+ var result = 0;
+
+ if (use == 5) {         // Dry hop
+  result = 1.33;
+ } else if (bt > 20) {
+  result = 0;
+ } else if (bt > 7.5) {
+  result = 10.03 / (4 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 7.5) / 4, 2));
+ } else if (use == 2) {  // Boil
+  result = 1;
+ } else if (use == 3) {  // Aroma
+  result = 1.2;
+ } else if (use == 4) {  // Whirlpool
+  result = 1.2;
+ }
+ return (result * amount * 1000) / vol;
+}
+
+
+function setReadonly(ro) {
+ var rw = ! ro, w100 = 110, w80 = 80;
+ if (ro) { // jqxNumberInput width -20 for no spinbuttons
+  w100 = 90;
+  w80 = 60;
+ }
+ $('#batch_size').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#boil_size').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#boil_time').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#efficiency').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#est_og').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ // id="st_fg_min" margin-left 15/35 maken
+ $('#type').jqxDropDownList({ disabled: ro });
+ $('#styleSelect').jqxDropDownList({ disabled: ro });
+ $('#color_method').jqxDropDownList({ disabled: ro });
+ $('#ibu_method').jqxDropDownList({ disabled: ro });
+ $('#Delete').jqxButton({ disabled: ro });
+ $('#fermentableGrid').jqxGrid({ editable: rw });
+ $('#faddrowbutton').jqxDropDownList({ disabled: ro });
+ $('#finstockbutton').jqxCheckBox({ disabled: ro });
+ $('#fdeleterowbutton').jqxButton({ disabled: ro });
+ $('#hopGrid').jqxGrid({ editable: rw });
+ $('#haddrowbutton').jqxDropDownList({ disabled: ro });
+ $('#hinstockbutton').jqxCheckBox({ disabled: ro });
+ $('#hdeleterowbutton').jqxButton({ disabled: ro });
+ $('#miscGrid').jqxGrid({ editable: rw });
+ $('#maddrowbutton').jqxDropDownList({ disabled: ro });
+ $('#minstockbutton').jqxCheckBox({ disabled: ro });
+ $('#mdeleterowbutton').jqxButton({ disabled: ro });
+ $('#yeastGrid').jqxGrid({ editable: rw });
+ $('#yaddrowbutton').jqxDropDownList({ disabled: ro });
+ $('#yinstockbutton').jqxCheckBox({ disabled: ro });
+ $('#ydeleterowbutton').jqxButton({ disabled: ro });
+ $('#mashGrid').jqxGrid({ editable: rw });
+ $('#saddrowbutton').jqxButton({ disabled: ro });
+ $('#sdeleterowbutton').jqxButton({ disabled: ro });
+ $('#w1_name').jqxDropDownList({ disabled: ro });
+ $('#w2_name').jqxDropDownList({ disabled: ro });
+ $('#pr_name').jqxDropDownList({ disabled: ro });
+ $('#wa_cacl2').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#wa_caso4').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#wa_mgso4').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#wa_nacl').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#mash_ph').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#calc_acid').jqxCheckBox({ disabled: ro });
+ $('#wa_base_name').jqxDropDownList({ disabled: ro });
+ $('#wa_base').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#wa_acid_name').jqxDropDownList({ disabled: ro });
+ $('#wa_acid').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#wa_acid_perc').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w80 });
+ $('#sparge_temp').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#sparge_volume').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#sparge_ph').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+ $('#sparge_source').jqxDropDownList({ disabled: ro });
+ $('#sparge_acid_type').jqxDropDownList({ disabled: ro });
+ $('#sparge_acid_perc').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
+}
+
+
+function calcPercentages() {
+
+ console.log('calcPercentages()');
+ var tw, rowdata, percentage, i, rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+ if (rowscount > 1) {
+  tw = 0;
+  for (i = 0; i < rowscount; i++) {
+   rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
+   if (rowdata.f_added < 4)
+    tw += Round(rowdata.f_amount, 3);
+  }
+  tw = Round(tw, 3);
+
+  for (i = 0; i < rowscount; i++) {
+   rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
+   if (rowdata.f_added < 4) {
+    percentage = Round(rowdata.f_amount / tw * 100, 1);
+    $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', percentage);
+   } else {
+    $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', 0);
+   }
+  }
+ } else {
+  $('#fermentableGrid').jqxGrid('setcellvalue', 0, 'f_percentage', 100);
+ }
+}
+
+
+function calcFermentables() {
+ console.log('calcFermentables()');
+ var i, row, rows, org, s = 0, d, x,
+ sug, alc, cw, color, scolor, fig,
+ sugarsf = 0,    // fermentable sugars mash + boil
+ sugarsm = 0;        // fermentable sugars in mash
+ vol = 0,            // Volume sugars after boil
+ addedS = 0,         // Added sugars after boil
+ addedmass = 0,      // Added mass after boil
+ mvol = 0,           // mash volume
+ colort = 0,         // Colors srm * vol totals
+ colorh = 0,         // Colors ebc * vol * kt
+ colorn = 0,         // Colors ebc * pt * pct
+ my_100 = false,
+ mashtime = 0,       // Total mash time
+ mashtemp = 0,       // Average mash temperature
+ bv = 0.925,         // Bierverlies rendement
+ sr = 0.95,          // Mash en spoel rendement
+ lintner = 0;        // Total recipe lintner
+ /* Init global variables */
+ psugar = 0;
+ pcara = 0;
+ mashkg = 0;
+
+ if ((rows = $('#mashGrid').jqxGrid('getrows'))) {
+  for (i = 0; i < rows.length; i++) {
+   row = rows[i];
+   if (row.step_type == 0) // Infusion
+    mvol += parseFloat(row.step_infuse_amount);
+   if (row.step_temp <= 75) { // Ignore mashout
+    mashtime += row.step_time;
+    mashtemp += row.step_time * row.step_temp;
+   }
+  }
+  mashtemp = mashtemp / mashtime;
+ }
+
+ if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) {
+  return; // grid not yet loaded.
+ }
+
+ for (i = 0; i < rows.length; i++) {
+  row = rows[i];
+  if (row.f_adjust_to_total_100)
+   my_100 = true;
+  if (row.f_type == 1 && row.f_added < 4)      // Sugar
+   psugar += row.f_percentage;
+  if (row.f_graintype == 2 && row.f_added < 4) // Crystal
+   pcara += row.f_percentage;
+  d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+  if (row.f_added == 0) {                      // Mash
+   if (mvol > 0) {                             // Only if mash already known
+    mvol += row.f_amount * row.f_moisture / 100;
+    s += d;
+   }
+   d = parseFloat(dataRecord.efficiency) / 100 * d;
+   sugarsm += d;
+   mashkg += row.f_amount;
+  }
+  if (row.f_added == 0 || row.f_added == 1)    // Mash or Boil
+   sugarsf += d;
+  if (row.f_added == 2 || row.f_added == 3) {  // Fermentation or lagering
+   x = (row.f_yield / 100) * (1 - row.f_moisture / 100);
+   addedS += row.f_amount * x;
+   addedmass += row.f_amount;
+   vol += (x * sugardensity + (1 - x) * 1) * row.f_amount;
+  }
+  if (row.f_added == 0 && (row.f_type == 0 || row.f_type == 4) && row.f_color < 50) { // Mash and Grain/Adjunct and Color < 50
+   lintner += row.f_diastatic_power * row.f_amount;
+  }
+  if (row.f_added < 4) {
+   colort += row.f_amount * ebc_to_srm(row.f_color);
+   colorh += row.f_amount * row.f_color * get_kt(row.f_color);
+   colorn += (row.f_percentage / 100) * row.f_color;       // For 8.6 Pt wort.
+  }
+ }
+ $('#ferm_lintner').val(Math.round(parseFloat(lintner / mashkg)));
+ //console.log('lintner:' + lintner + ' kg:' + mashkg);
+ to_100 = my_100;
+ if (to_100) {
+  $('#wf_amount').jqxNumberInput({ width: 90, readOnly: true, spinButtons: false });
+ } else {
+  $('#wf_amount').jqxNumberInput({ width: 110, readOnly: false, spinButtons: true });
+ }
+
+ // Estimate total recipe OG.
+ dataRecord.est_og = estimate_sg(sugarsf + addedS, parseFloat(dataRecord.batch_size));
+ $('#est_og').val(dataRecord.est_og);
+ $('#est_og2').val(dataRecord.est_og);
+ org = dataRecord.est_og;
+
+ // Estimate SG in kettle before boil
+ preboil_sg = estimate_sg(sugarsm, parseFloat(dataRecord.boil_size));
+
+ // Color of the wort
+ if (dataRecord.color_method == 4) {
+  color = Math.round(((sg_to_plato(dataRecord.est_og) / 8.6) * colorn) + (dataRecord.boil_time / 60));
+ } else if (dataRecord.color_method == 3) {     // Hans Halberstadt
+  color = Math.round((4.46 * bv * sr) / parseFloat(dataRecord.batch_size) * colorh);
+ } else {
+  cw = colort / parseFloat(dataRecord.batch_size) * 8.34436;
+  color = kw_to_ebc(dataRecord.color_method, cw);
+ }
+ dataRecord.est_color = color;
+ $('#est_color').val(color);
+ $('#est_color2').val(color);
+ scolor = ebc_to_color(color);
+ document.getElementById('bcolor').style.background = scolor;
+ document.getElementById('bcolor2').style.background = scolor;
+
+ // Progress bars
+ pmalts = mashkg / (dataRecord.boil_size / 3) * 100;
+ $('#perc_malts').jqxProgressBar('val', pmalts);
+ $('#perc_sugars').jqxProgressBar('val', psugar);
+ $('#perc_cara').jqxProgressBar('val', pcara);
+
+ // Calculate estimated svg.
+ svg = 0; // default.
+ rows = $('#yeastGrid').jqxGrid('getrows');
+ for (i = 0; i < rows.length; i++) {
+  row = rows[i];
+  if (row.y_use == 0) {   // Primary
+   if (parseFloat(row.y_attenuation) > svg)
+    svg = parseFloat(row.y_attenuation);    // Take the highest if multiple yeasts.
+  }
+  // TODO: brett in secondary ??
+ }
+ if (svg == 0)
+  svg = 77;
+
+ if ((mashkg > 0) && (mash_infuse > 0) && (mashtime > 0) && (mashtemp > 0)) {
+  dataRecord.est_fg = estimate_fg(psugar, pcara, mash_infuse / mashkg, mashtime, mashtemp, svg, dataRecord.est_og);
+ } else {
+  dataRecord.est_fg = estimate_fg(psugar, pcara, 0, 0, 0, svg, dataRecord.est_og);
+ }
+ $('#est_fg').val(dataRecord.est_fg);
+ $('#est_fg2').val(dataRecord.est_fg);
+ fig = dataRecord.est_fg;
+
+ dataRecord.est_abv = abvol(dataRecord.est_og, dataRecord.est_fg);
+ $('#est_abv').val(dataRecord.est_abv);
+ $('#est_abv2').val(dataRecord.est_abv);
+
+ // Calculate the calories in kcal/l (from brouwhulp)
+ alc = 1881.22 * fig * (org - fig) / (1.775 - org);
+ sug = 3550 * fig * (0.1808 * org + 0.8192 * fig - 1.0004);
+ $('#kcal').val(Math.round((alc + sug) / (12 * 0.0295735296)));
+}
+
+
+function calcMash() {
+ var infused = 0, i, row, rows;
+ if (!(rows = $('#mashGrid').jqxGrid('getrows')))
+  return;
+ if (mashkg == 0)
+  return;
+
+ for (i = 0; i < rows.length; i++) {
+  row = $('#mashGrid').jqxGrid('getrowdata', i);
+  if (row.step_type == 0) // Infusion
+   infused += row.step_infuse_amount;
+  $('#mashGrid').jqxGrid('setcellvalue', i, 'step_thickness', infused / mashkg);
+ }
+}
+
+
+function calcIBUs() {
+ var total_ibus = 0,
+ rows = {},
+ i, row;
+
+ hop_aroma = hop_flavour = 0;
+ if (!(rows = $('#hopGrid').jqxGrid('getrows'))) {
+  return;
+ }
+ for (i = 0; i < rows.length; i++) {
+  row = rows[i];
+  total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size),
+   parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method);
+  hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size), row.h_useat, parseFloat(row.h_amount));
+  hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size), row.h_useat, parseFloat(row.h_amount));
+ }
+ total_ibus = Round(total_ibus, 1);
+ hop_flavour = Round(hop_flavour * 100 / 5, 1);
+ hop_aroma = Round(hop_aroma * 100 / 6, 1);
+ if (hop_flavour > 100)
+  hop_flavour = 100;
+ if (hop_aroma > 100)
+  hop_aroma = 100;
+ console.log('calcIBUs(): ' + total_ibus + '  flavour: ' + hop_flavour + '  aroma: ' + hop_aroma);
+ dataRecord.est_ibu = total_ibus;
+ $('#est_ibu').val(total_ibus);
+ $('#est_ibu2').val(total_ibus);
+ $('#hop_flavour').jqxProgressBar('val', hop_flavour);
+ $('#hop_aroma').jqxProgressBar('val', hop_aroma);
+}
+
+
+function adjustHops(factor) {
+
+ //console.log('adjustHops(' + factor + ')');
+ var i, row, amount, rowscount = $('#hopGrid').jqxGrid('getdatainformation').rowscount;
+ if (rowscount == 0)
+  return;
+
+ for (i = 0; i < rowscount; i++) {
+  row = $('#hopGrid').jqxGrid('getrowdata', i);
+  amount = row.h_amount * factor;
+  $('#hopGrid').jqxGrid('setcellvalue', i, 'h_amount', amount);
+ }
+}
+
+
+function adjustMiscs(factor) {
+
+ //console.log('adjustMiscs(' + factor + ')');
+ var i, row, amount, rowscount = $('#miscGrid').jqxGrid('getdatainformation').rowscount;
+ if (rowscount == 0)
+  return;
+
+ for (i = 0; i < rowscount; i++) {
+  row = $('#miscGrid').jqxGrid('getrowdata', i);
+  amount = row.m_amount * factor;
+  $('#miscGrid').jqxGrid('setcellvalue', i, 'm_amount', amount);
+  switch (row.m_name) {
+   case 'CaCl2': $('#wa_cacl2').val(row.m_amount * 1000); break;
+   case 'CaSO4': $('#wa_caso4').val(row.m_amount * 1000); break;
+   case 'MgSO4': $('#wa_mgso4').val(row.m_amount * 1000); break;
+   case 'NaCl': $('#wa_nacl').val(row.m_amount * 1000); break;
+   case 'Melkzuur':
+   case 'Zoutzuur':
+   case 'Fosforzuur':
+   case 'Zwavelzuur': $('#wa_acid').val(row.m_amount * 1000); break;
+   case 'NaHCO3':
+   case 'Na2CO3':
+   case 'CaCO3':
+   case 'Ca(OH)2': $('#wa_base').val(row.m_amount * 1000); break;
+  }
+ }
+}
+
+
+function adjustYeasts(factor) {
+
+ //console.log('adjustYeasts(' + factor + ')');
+ var i, row, amount, rowscount = $('#yeastGrid').jqxGrid('getdatainformation').rowscount;
+ if (rowscount == 0)
+  return;
+
+ for (i = 0; i < rowscount; i++) {
+  row = $('#yeastGrid').jqxGrid('getrowdata', i);
+  if (row.y_form == 1) { // Only adjust dry yeast
+   amount = row.y_amount * factor;
+   $('#yeastGrid').jqxGrid('setcellvalue', i, 'y_amount', amount);
+  }
+ }
+}
+
+
+function adjustWaters(factor) {
+
+ //console.log('adjustWaters(' + factor + ')');
+ var i, row, amount, rowscount = $('#mashGrid').jqxGrid('getdatainformation').rowscount;
+ if (rowscount == 0)
+  return;
+ mash_infuse = 0;
+ for (i = 0; i < rowscount; i++) {
+  row = $('#mashGrid').jqxGrid('getrowdata', i);
+  if (row.step_type == 0) { // Infusion
+   amount = Round(row.step_infuse_amount * factor, 1);
+   $('#mashGrid').jqxGrid('setcellvalue', i, 'step_infuse_amount', amount);
+   mash_infuse += amount;
+  }
+ }
+ if (dataRecord.w2_amount == 0) {
+  dataRecord.w1_amount = mash_infuse;
+  $('#w1_amount').val(mash_infuse);
+ } else {
+  dataRecord.w1_amount = (dataRecord.w1_amount / (dataRecord.w1_amount + dataRecord.w2_amount)) * mash_infuse;
+  dataRecord.w2_amount = (dataRecord.w2_amount / (dataRecord.w1_amount + dataRecord.w2_amount)) * mash_infuse;
+  $('#w1_amount').val(dataRecord.w1_amount);
+  $('#w2_amount').val(dataRecord.w2_amount);
+ }
+ $('#wg_amount').val(mash_infuse);
+}
+
+
+function GetBUGU() {
+ var gu = (dataRecord.est_og - 1) * 1000;
+ if (gu > 0)
+  return dataRecord.est_ibu / gu;
+ else
+  return 0.5;
+}
+
+
+function GetOptClSO4ratio() {
+ var BUGU = GetBUGU();
+ return (-1.2 * BUGU + 1.4);
+}
+
+
+
+function setRangeIndicator(ion, rangeCode) {
+ if ((rangeCode == 'laag') || (rangeCode == 'hoog'))
+  $('#wr_' + ion).html('<img src="images/dialog-error.png"><span style="vertical-align: top; font-size: 10px; font-style: italic;">' + rangeCode + '</span>');
+ else
+  $('#wr_' + ion).html('<img src="images/dialog-ok-apply.png">');
+}
+
+
+function mix(v1, v2, c1, c2) {
+ if ((v1 + v2) > 0) {
+  return ((v1 * c1) + (v2 * c2)) / (v1 + v2);
+ }
+ return 0;
+}
+
+
+// mg/l as CaCO3
+function ResidualAlkalinity(total_alkalinity, calcium, magnesium) {
+ return total_alkalinity - (calcium / 1.4 + magnesium / 1.7);
+}
+
+
+function PartCO3(pH) {
+ var H = Math.pow(10, -pH);
+ return 100 * Ka1 * Ka2 / (H * H + H * Ka1 + Ka1 * Ka2);
+}
+
+
+function PartHCO3(pH) {
+ var H = Math.pow(10, -pH);
+ return 100 * Ka1 * H / (H * H + H * Ka1 + Ka1 * Ka2);
+}
+
+
+function Charge(pH) {
+ return (-2 * PartCO3(pH) - PartHCO3(pH));
+}
+
+
+//Z alkalinity is the amount of acid (in mEq/l) needed to bring water to the target pH (Z pH)
+function ZAlkalinity(pHZ) {
+ var C43 = Charge(4.3),
+ Cw = Charge(parseFloat($('#wg_ph').jqxNumberInput('decimal'))),
+ Cz = Charge(pHZ),
+ DeltaCNaught = -C43 + Cw,
+ CT = parseFloat($('#wg_total_alkalinity').jqxNumberInput('decimal')) / 50 / DeltaCNaught,
+ DeltaCZ = -Cz + Cw;
+ return CT * DeltaCZ;
+}
+
+
+//Z Residual alkalinity is the amount of acid (in mEq/l) needed to bring the water in the mash to the target pH (Z pH)
+function ZRA(pHZ) {
+ var Calc = parseFloat($('#wg_calcium').jqxNumberInput('decimal')) / (MMCa / 2),
+ Magn = parseFloat($('#wg_magnesium').jqxNumberInput('decimal')) / (MMMg / 2),
+ Z = ZAlkalinity(pHZ);
+ return Z - (Calc / 3.5 + Magn / 7);
+}
+
+
+function ProtonDeficit(pHZ) {
+ var ebc, C1, i, rows, row, Result = ZRA(pHZ) * parseFloat($('#wg_amount').jqxNumberInput('decimal'));
+ // proton deficit for the grist
+ rows = $('#fermentableGrid').jqxGrid('getrows');
+ for (i = 0; i < rows.length; i++) {
+  row = rows[i];
+  if (row.f_added == 0 && row.f_graintype != 6) { // Added == Mash && graintype != No Malt
+   // Check if acid is required
+   C1 = 0;
+   if ((row.f_di_ph != 5.7) && ((row.f_acid_to_ph_57 < - 0.1) || (row.f_acid_to_ph_57 > 0.1))) {
+    C1 = row.f_acid_to_ph_57 / (row.f_di_ph - 5.7);
+   } else {
+    // If the acid_to_ph_5.7 is unknown from the maltster, guess the required acid.
+    ebc = row.f_color;
+    switch (row.f_graintype) {
+     case 0:                              // Base, Special, Kilned
+     case 3:
+     case 5: C1 = 0.014 * ebc - 34.192;
+             break;
+     case 2: C1 = -0.0597 * ebc - 32.457; // Crystal
+             break;
+     case 1: C1 = 0.0107 * ebc - 54.768;  // Roast
+             break;
+     case 4: C1 = -149;                   // Sour malt
+             break;
+    }
+   }
+   x = C1 * (pHZ - row.f_di_ph);   // AcidRequired(ZpH)
+   Result += x * row.f_amount;
+  }
+ }
+ return Result;
+}
+
+
+function MashpH() {
+ var n = 0,
+ pH = 5.4,
+ deltapH = 0.001,
+ deltapd = 0.1,
+ pd = ProtonDeficit(pH);
+ while (((pd < -deltapd) || (pd > deltapd)) && (n < 2000)) {
+  n++;
+  if (pd < -deltapd)
+   pH -= deltapH;
+  else if (pd > deltapd)
+   pH += deltapH;
+  pd = ProtonDeficit(pH);
+ }
+ //console.log('MashpH() n: ' + n + ' pH: ' + pH);
+ return pH;
+}
+
+
+function GetAcidSpecs(AT) {
+ switch (AT) {
+  case 0: return { pK1: 3.86, pK2: 20, pK3: 20, MolWt: 90.08, AcidSG: 1214, AcidPrc: 0.88 }; // Melkzuur
+  case 1: return { pK1: -7, pK2: 20, pK3: 20, MolWt: 36.46, AcidSG: 1142, AcidPrc: 0.28 }; // Zoutzuur
+  case 2: return { pK1: 2.12, pK2: 7.20, pK3: 12.44, MolWt: 98.00, AcidSG: 1170, AcidPrc: 0.25 }; // Fosforzuur
+  case 3: return { pK1: -1, pK2: 1.92, pK3: 20, MolWt: 98.07, AcidSG: 1700, AcidPrc: 0.93 }; // Zwavelzuur
+ }
 }
 
 
-$(document).ready(function () {
 
-	var	to_100 = false;		// Fermentables adjust to 100%
-	var	preboil_sg = 0;
-	var     psugar = 0;     	// Percentage real sugars
-	var     pcara = 0;      	// Percentage cara/crystal malts
-	var	svg = 77;		// Default attenuation
-	var	mashkg = 0;		// Malt in mash weight
-	var	hop_flavour = 0;
-	var	hop_aroma = 0;
-	var	mash_infuse = 0;
-	var	last_base = '';
-	var	last_acid = '';
 
-	var     MMCa = 40.048;
-	var     MMMg = 24.305;
-	var     MMNa = 22.98976928;
-	var     MMCl = 35.453;
-	var     MMSO4 = 96.0626;
-	var     MMCO3 = 60.01684;
-	var     MMHCO3 = 61.01684;
-	var     MMCaSO4 = 172.171;
-	var     MMCaCl2 = 147.015;
-	var     MMCaCO3 = 100.087;
-	var     MMMgSO4 = 246.475;
-	var     MMNaHCO3 = 84.007;
-	var     MMNa2CO3 = 105.996;
-	var     MMNaCl = 58.443;
-	var     MMCaOH2 = 74.06268;
 
-	var	fermentableRow = 0;
-	var	fermentableData = {};
-	var	hopRow = 0;
-	var	hopData = {};
-	var	miscRow = 0;
-	var	miscData = {};
-	var	yeastRow = 0;
-	var	yeastData = {};
-	var	mashRow = 0;
-	var	mashData = {};
-
-	/*
-	 * Remove the top menu so that we MUST use the buttons to leave the editor.
-	 */
-	$('#jqxMenu').jqxMenu('destroy');
-
-	console.log("record:" + my_record + "  return:" + my_return + "  theme:" + theme);
-	$("#jqxLoader").jqxLoader({
-		width: 250,
-		height: 150,
-		isModal: true,
-		text: "Laden recept ...",
-		theme: theme
-	});
 
-	function setReadonly(ro) {
-		var rw = ! ro;
-		var w100 = 110;
-		var w80 = 80;
-		if (ro) { // jqxNumberInput width -20 for no spinbuttons
-			w100 = 90;
-			w80 = 60;
-		}
-		$("#batch_size").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#boil_size").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#boil_time").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#efficiency").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#est_og").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		// id="st_fg_min" margin-left 15/35 maken
-		$("#type").jqxDropDownList({ disabled: ro });
-		$("#styleSelect").jqxDropDownList({ disabled: ro });
-		$("#color_method").jqxDropDownList({ disabled: ro });
-		$("#ibu_method").jqxDropDownList({ disabled: ro });
-		$("#Delete").jqxButton({ disabled: ro });
-		$("#fermentableGrid").jqxGrid({ editable: rw });
-		$("#faddrowbutton").jqxDropDownList({ disabled: ro });
-		$("#finstockbutton").jqxCheckBox({ disabled: ro });
-		$("#fdeleterowbutton").jqxButton({ disabled: ro });
-		$("#hopGrid").jqxGrid({ editable: rw });
-		$("#haddrowbutton").jqxDropDownList({ disabled: ro });
-		$("#hinstockbutton").jqxCheckBox({ disabled: ro });
-		$("#hdeleterowbutton").jqxButton({ disabled: ro });
-		$("#miscGrid").jqxGrid({ editable: rw });
-		$("#maddrowbutton").jqxDropDownList({ disabled: ro });
-		$("#minstockbutton").jqxCheckBox({ disabled: ro });
-		$("#mdeleterowbutton").jqxButton({ disabled: ro });
-		$("#yeastGrid").jqxGrid({ editable: rw });
-		$("#yaddrowbutton").jqxDropDownList({ disabled: ro });
-		$("#yinstockbutton").jqxCheckBox({ disabled: ro });
-		$("#ydeleterowbutton").jqxButton({ disabled: ro });
-		$("#mashGrid").jqxGrid({ editable: rw });
-		$("#saddrowbutton").jqxButton({ disabled: ro });
-		$("#sdeleterowbutton").jqxButton({ disabled: ro });
-		$("#w1_name").jqxDropDownList({ disabled: ro });
-		$("#w2_name").jqxDropDownList({ disabled: ro });
-		$("#pr_name").jqxDropDownList({ disabled: ro });
-		$("#wa_cacl2").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#wa_caso4").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#wa_mgso4").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#wa_nacl").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#mash_ph").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#calc_acid").jqxCheckBox({ disabled: ro });
-		$("#wa_base_name").jqxDropDownList({ disabled: ro });
-		$("#wa_base").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#wa_acid_name").jqxDropDownList({ disabled: ro });
-		$("#wa_acid").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#wa_acid_perc").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w80 });
-		$("#sparge_temp").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#sparge_volume").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#sparge_ph").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-		$("#sparge_source").jqxDropDownList({ disabled: ro });
-		$("#sparge_acid_type").jqxDropDownList({ disabled: ro });
-		$("#sparge_acid_perc").jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
-	};
+
+$(document).ready(function() {
+
+ var to_100 = false, // Fermentables adjust to 100%
 
-	function calcPercentages() {
-
-		console.log("calcPercentages()");
-		var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-		if (rowscount > 1) {
-			var tw = 0;
-			for (i = 0; i < rowscount; i++) {
-				var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-				if (rowdata.f_added < 4)
-					tw += Math.round(rowdata.f_amount * 1000) / 1000;
-			};
-			tw = Math.round(tw * 1000) / 1000;
-
-			for (i = 0; i < rowscount; i++) {
-				var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-				if (rowdata.f_added < 4) {
-					var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
-					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
-				} else {
-					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", 0);
-				}
-			};
-		} else {
-			$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
-		}
-	}
-
-	function calcFermentables() {
-		console.log("calcFermentables()");
-		sugarsf = 0;		// fermentable sugars mash + boil
-		sugarsm = 0;		// fermentable sugars in mash
-		psugar = 0;
-		pcara = 0;
-		mashkg = 0;
-		var vol = 0;		// Volume sugars after boil
-		var addedS = 0;		// Added sugars after boil
-		var addedmass = 0;	// Added mass after boil
-		var mvol = 0;		// mash volume
-		var colort = 0;		// Colors srm * vol totals
-		var colorh = 0;         // Colors ebc * vol * kt
-		var colorn = 0;		// Colors ebc * pt * pct
-		var my_100 = false;
-		var mashtime = 0;       // Total mash time
-		var mashtemp = 0;       // Average mash temperature
-		var bv = 0.925;         // Bierverlies rendement
-                var sr = 0.95;          // Mash en spoel rendement
-		var lintner = 0;	// Total recipe lintner
-
-		if ((rows = $('#mashGrid').jqxGrid('getrows'))) {
-			for (var i = 0; i < rows.length; i++) {
-				var row = rows[i];
-				if (row.step_type == 0) // Infusion
-					mvol += parseFloat(row.step_infuse_amount);
-				if (row.step_temp <= 75) { // Ignore mashout
-					mashtime += row.step_time;
-					mashtemp += row.step_time * row.step_temp;
-				}
-			}
-			mashtemp = mashtemp / mashtime;
-		}
-
-		if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) {
-			return; // grid not yet loaded.
-		}
-
-		var s = 0;
-		for (var i = 0; i < rows.length; i++) {
-			var row = rows[i];
-			if (row.f_adjust_to_total_100)
-				my_100 = true;
-			if (row.f_type == 1 && row.f_added < 4)		// Sugar
-				psugar += row.f_percentage;
-			if (row.f_graintype == 2 && row.f_added < 4)	// Crystal
-				pcara += row.f_percentage;
-			var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-			if (row.f_added == 0) {		// Mash
-				if (mvol > 0) { 	// Only if mash already known
-					mvol += row.f_amount * row.f_moisture / 100;
-					s += d;
-				}
-				d = parseFloat(dataRecord.efficiency) / 100 * d;
-				sugarsm += d;
-				mashkg += row.f_amount;
-			}
-			if (row.f_added == 0 || row.f_added == 1)	// Mash or Boil
-				sugarsf += d;
-			if (row.f_added == 2 || row.f_added == 3) {	// Fermentation or lagering
-				var x = (row.f_yield / 100) * (1 - row.f_moisture / 100);
-				addedS += row.f_amount * x;
-				addedmass += row.f_amount;
-				vol += (x * sugardensity + (1 - x) * 1) * row.f_amount;
-			}
-			if (row.f_added == 0 && (row.f_type == 0 || row.f_type == 4) && row.f_color < 50) { // Mash and Grain/Adjunct and Color < 50
-				lintner += row.f_diastatic_power * row.f_amount;
-			}
-			if (row.f_added < 4) {
-				colort += row.f_amount * ebc_to_srm(row.f_color);
-				colorh += row.f_amount * row.f_color * get_kt(row.f_color);
-				colorn += (row.f_percentage / 100) * row.f_color;	// For 8.6 Pt wort.
-			}
-		}
-		$("#ferm_lintner").val(Math.round(parseFloat(lintner / mashkg)));
-		console.log("lintner:"+lintner+" kg:"+mashkg);
-		to_100 = my_100;
-		if (to_100) {
-			$("#wf_amount").jqxNumberInput({ width: 90, readOnly: true, spinButtons: false  });
-		} else {
-			$("#wf_amount").jqxNumberInput({ width: 110, readOnly: false, spinButtons: true });
-		}
-
-		// Estimate total recipe OG.
-		dataRecord.est_og = estimate_sg(sugarsf + addedS, parseFloat(dataRecord.batch_size));
-		$('#est_og').val(dataRecord.est_og);
-		$('#est_og2').val(dataRecord.est_og);
-		var org = dataRecord.est_og;
+ fermentableRow = 0,
+ fermentableData = {},
+ hopRow = 0,
+ hopData = {},
+ miscRow = 0,
+ miscData = {},
+ yeastRow = 0,
+ yeastData = {},
+ mashRow = 0,
+ mashData = {},
 
-		// Estimate SG in kettle before boil
-		preboil_sg = estimate_sg(sugarsm, parseFloat(dataRecord.boil_size));
-
-		// Color of the wort
-		if (dataRecord.color_method == 4) {
-			var color = Math.round(((sg_to_plato(dataRecord.est_og) / 8.6) * colorn) + (dataRecord.boil_time / 60));
-		} else if (dataRecord.color_method == 3) {     // Hans Halberstadt
-                        var color = Math.round((4.46 * bv * sr) /  parseFloat(dataRecord.batch_size) * colorh);
-                } else {
-			var cw = colort / parseFloat(dataRecord.batch_size) * 8.34436;
-			var color = kw_to_ebc(dataRecord.color_method, cw);
-		}
-		dataRecord.est_color = color;
-		$('#est_color').val(color);
-		$('#est_color2').val(color);
-		var scolor = ebc_to_color(color);
-		document.getElementById("bcolor").style.background= scolor;
-		document.getElementById("bcolor2").style.background= scolor;
-
-		// Progress bars
-		pmalts = mashkg / (dataRecord.boil_size / 3) * 100;
-		$("#perc_malts").jqxProgressBar('val', pmalts);
-		$("#perc_sugars").jqxProgressBar('val', psugar);
-		$("#perc_cara").jqxProgressBar('val', pcara);
-
-		// Calculate estimated svg.
-		svg = 0; // default.
-		var rows = $('#yeastGrid').jqxGrid('getrows');
-		for (var i = 0; i < rows.length; i++) {
-			var row = rows[i];
-			if (row.y_use == 0) {   // Primary
-				if (parseFloat(row.y_attenuation) > svg)
-					svg = parseFloat(row.y_attenuation);    // Take the highest if multiple yeasts.
-			}
-			// TODO: brett in secondary ??
-		}
-		if (svg == 0)
-			svg = 77;
-
-		if ((mashkg > 0) && (mash_infuse > 0) && (mashtime > 0) && (mashtemp > 0)) {
-			dataRecord.est_fg = estimate_fg(psugar, pcara, mash_infuse / mashkg, mashtime, mashtemp, svg, dataRecord.est_og);
-		} else {
-			dataRecord.est_fg = estimate_fg(psugar, pcara, 0, 0, 0, svg, dataRecord.est_og);
-		}
-		$('#est_fg').val(dataRecord.est_fg);
-		$('#est_fg2').val(dataRecord.est_fg);
-		var fig = dataRecord.est_fg;
-
-		dataRecord.est_abv = abvol(dataRecord.est_og, dataRecord.est_fg);
-		$("#est_abv").val(dataRecord.est_abv);
-		$("#est_abv2").val(dataRecord.est_abv);
-
-		// Calculate the calories in kcal/l (from brouwhulp)
-		var alc = 1881.22 * fig * (org - fig) / (1.775 - org);
-		var sug = 3550 * fig * (0.1808 * org + 0.8192 * fig - 1.0004);
-		$("#kcal").val(Math.round((alc + sug) / (12 * 0.0295735296)));
-	};
-
-	function hopFlavourContribution(bt, vol, use, amount) {
-		var result;
-
-		if (use == 1) {	// First wort
-			result = 0.15;		// assume 15% flavourcontribution for fwh
-		} else if (bt > 50) {
-			result = 0.10;		// assume 10% flavourcontribution as a minimum
-		} else {
-			result = 15.25 / (6 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 21) /6, 2));
-			if (result < 0.10)
-				result = 0.10;	// assume 10% flavourcontribution as a minimum
-		}
-		return (result * amount * 1000) / vol;
-	}
-
-	function hopAromaContribution(bt, vol, use, amount) {
-		var result = 0;
-
-		if (use == 5) {         // Dry hop
-                        result = 1.33;
-                } else if (bt > 20) {
-			result = 0;
-		} else if (bt > 7.5) {
-			result = 10.03 / (4 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 7.5) /4, 2));
-		} else if (use == 2) {	// Boil
-			result = 1;
-		} else if (use == 3) {	// Aroma / vlamuit
-			result = 1.2;
-		} else if (use == 4) { // Whirlpool
-			result = 1.2;
-		}
-		return (result * amount * 1000) / vol;
-	}
-
-	function calcMash() {
-
-		if (!(rows = $('#mashGrid').jqxGrid('getrows')))
-                        return;
-		if (mashkg == 0)
-			return;
-
-		var infused = 0;
-		for (var i = 0; i < rows.length; i++) {
-			var row = $("#mashGrid").jqxGrid('getrowdata', i);
-			if (row.step_type == 0) // Infusion
-				infused += row.step_infuse_amount;
-                        $("#mashGrid").jqxGrid('setcellvalue', i, "step_thickness", infused / mashkg);
-		}
-	}
+ url = 'includes/db_recipes.php',
+ // prepare the data
+ source = {
+  datatype: 'json',
+  cache: false,
+  datafields: [
+   { name: 'record', type: 'number' },
+   { name: 'uuid', type: 'string' },
+   { name: 'locked', type: 'int' },
+   { name: 'st_name', type: 'string' },
+   { name: 'st_letter', type: 'string' },
+   { name: 'st_guide', type: 'string' },
+   { name: 'st_type', type: 'int' },
+   { name: 'st_category', type: 'string' },
+   { name: 'st_category_number', type: 'float' },
+   { name: 'st_og_min', type: 'float' },
+   { name: 'st_og_max', type: 'float' },
+   { name: 'st_fg_min', type: 'float' },
+   { name: 'st_fg_max', type: 'float' },
+   { name: 'st_ibu_min', type: 'float' },
+   { name: 'st_ibu_max', type: 'float' },
+   { name: 'st_color_min', type: 'float' },
+   { name: 'st_color_max', type: 'float' },
+   { name: 'st_carb_min', type: 'float' },
+   { name: 'st_carb_max', type: 'float' },
+   { name: 'st_abv_min', type: 'float' },
+   { name: 'st_abv_max', type: 'float' },
+   { name: 'name', type: 'string' },
+   { name: 'notes', type: 'string' },
+   { name: 'type', type: 'int' },
+   { name: 'batch_size', type: 'float' },
+   { name: 'boil_size', type: 'float' },
+   { name: 'boil_time', type: 'float' },
+   { name: 'efficiency', type: 'float' },
+   { name: 'est_og', type: 'float' },
+   { name: 'est_fg', type: 'float' },
+   { name: 'est_abv', type: 'float' },
+   { name: 'est_color', type: 'float' },
+   { name: 'color_method', type: 'int' },
+   { name: 'est_ibu', type: 'float' },
+   { name: 'ibu_method', type: 'int' },
+   { name: 'est_carb', type: 'float' },
+   { name: 'sparge_temp', type: 'float' },
+   { name: 'sparge_ph', type: 'float' },
+   { name: 'sparge_volume', type: 'float' },
+   { name: 'sparge_source', type: 'int' },
+   { name: 'sparge_acid_type', type: 'int' },
+   { name: 'sparge_acid_perc', type: 'float' },
+   { name: 'sparge_acid_amount', type: 'float' },
+   { name: 'mash_ph', type: 'float' },
+   { name: 'mash_name', type: 'string' },
+   { name: 'calc_acid', type: 'int' },
+   { name: 'w1_name', type: 'string' },
+   { name: 'w1_amount', type: 'float' },
+   { name: 'w1_calcium', type: 'float' },
+   { name: 'w1_sulfate', type: 'float' },
+   { name: 'w1_chloride', type: 'float' },
+   { name: 'w1_sodium', type: 'float' },
+   { name: 'w1_magnesium', type: 'float' },
+   { name: 'w1_total_alkalinity', type: 'float' },
+   { name: 'w1_ph', type: 'float' },
+   { name: 'w1_cost', type: 'float' },
+   { name: 'w2_name', type: 'string' },
+   { name: 'w2_amount', type: 'float' },
+   { name: 'w2_calcium', type: 'float' },
+   { name: 'w2_sulfate', type: 'float' },
+   { name: 'w2_chloride', type: 'float' },
+   { name: 'w2_sodium', type: 'float' },
+   { name: 'w2_magnesium', type: 'float' },
+   { name: 'w2_total_alkalinity', type: 'float' },
+   { name: 'w2_ph', type: 'float' },
+   { name: 'w2_cost', type: 'float' },
+   { name: 'wg_amount', type: 'float' },
+   { name: 'wg_calcium', type: 'float' },
+   { name: 'wg_sulfate', type: 'float' },
+   { name: 'wg_chloride', type: 'float' },
+   { name: 'wg_sodium', type: 'float' },
+   { name: 'wg_magnesium', type: 'float' },
+   { name: 'wg_total_alkalinity', type: 'float' },
+   { name: 'wg_ph', type: 'float' },
+   { name: 'wb_calcium', type: 'float' },
+   { name: 'wb_sulfate', type: 'float' },
+   { name: 'wb_chloride', type: 'float' },
+   { name: 'wb_sodium', type: 'float' },
+   { name: 'wb_magnesium', type: 'float' },
+   { name: 'wb_total_alkalinity', type: 'float' },
+   { name: 'wb_ph', type: 'float' },
+   { name: 'wa_acid_name', type: 'int' },
+   { name: 'wa_acid_perc', type: 'int' },
+   { name: 'wa_base_name', type: 'int' },
+   { name: 'fermentables', type: 'array' },
+   { name: 'hops', type: 'array' },
+   { name: 'miscs', type: 'array' },
+   { name: 'yeasts', type: 'array' },
+   { name: 'mashs', type: 'array' }
+  ],
+  id: 'record',
+  url: url + '?record=' + my_record
+ },
+ // Load data and select one record.
+ dataAdapter = new $.jqx.dataAdapter(source, {
+  loadComplete: function() {
+   var records = dataAdapter.records;
+   dataRecord = records[0];
+   // Hidden record uuid
+   $('#name').val(dataRecord.name);
+   $('#notes').val(dataRecord.notes);
+   $('#locked').val(dataRecord.locked);
+   $('#st_name').val(dataRecord.st_name);
+   $('#st_letter').val(dataRecord.st_letter);
+   $('#st_guide').val(dataRecord.st_guide);
+   $('#st_category').val(dataRecord.st_category);
+   $('#st_category_number').val(dataRecord.st_category_number);
+   $('#st_type').val(StyleTypeData[dataRecord.st_type].nl);
+   $('#type').val(dataRecord.type);
+   $('#batch_size').val(dataRecord.batch_size);
+   $('#boil_size').val(dataRecord.boil_size);
+   $('#boil_time').val(dataRecord.boil_time);
+   $('#efficiency').val(dataRecord.efficiency);
+   $('#est_og').val(dataRecord.est_og);
+   $('#est_og2').val(dataRecord.est_og);
+   $('#st_og_min').val(dataRecord.st_og_min);
+   $('#st_og_max').val(dataRecord.st_og_max);
+   $('#est_fg').val(dataRecord.est_fg);
+   $('#est_fg2').val(dataRecord.est_fg);
+   $('#st_fg_min').val(dataRecord.st_fg_min);
+   $('#st_fg_max').val(dataRecord.st_fg_max);
+   $('#est_fg').val(dataRecord.est_fg);
+   $('#est_fg2').val(dataRecord.est_fg);
+   $('#st_fg_min').val(dataRecord.st_fg_min);
+   $('#st_fg_max').val(dataRecord.st_fg_max);
+   $('#est_color').val(dataRecord.est_color);
+   $('#est_color2').val(dataRecord.est_color);
+   $('#est_abv').val(dataRecord.est_abv);
+   $('#est_abv2').val(dataRecord.est_abv);
+   $('#st_abv_min').val(dataRecord.st_abv_min);
+   $('#st_abv_max').val(dataRecord.st_abv_max);
+   $('#st_color_min').val(dataRecord.st_color_min);
+   $('#st_color_max').val(dataRecord.st_color_max);
+   $('#color_method').val(dataRecord.color_method);
+   $('#est_ibu').val(dataRecord.est_ibu);
+   $('#est_ibu2').val(dataRecord.est_ibu);
+   $('#st_ibu_min').val(dataRecord.st_ibu_min);
+   $('#st_ibu_max').val(dataRecord.st_ibu_max);
+   $('#ibu_method').val(dataRecord.ibu_method);
+   $('#est_carb').val(dataRecord.est_carb);
+   $('#st_carb_min').val(dataRecord.st_carb_min);
+   $('#st_carb_max').val(dataRecord.st_carb_max);
+   $('#mash_name').val(dataRecord.mash_name);
+   $('#mash_ph').val(dataRecord.mash_ph);
+   $('#sparge_temp').val(dataRecord.sparge_temp);
+   $('#sparge_ph').val(dataRecord.sparge_ph);
+   $('#sparge_volume').val(dataRecord.sparge_volume);
+   $('#sparge_source').val(dataRecord.sparge_source);
+   $('#sparge_acid_type').val(dataRecord.sparge_acid_type);
+   $('#sparge_acid_perc').val(dataRecord.sparge_acid_perc);
+   $('#sparge_acid_amount').val(dataRecord.sparge_acid_amount * 1000);
+   $('#calc_acid').val(dataRecord.calc_acid);
+   $('#w1_name').val(dataRecord.w1_name);
+   $('#w1_amount').val(dataRecord.w1_amount);
+   $('#w1_calcium').val(dataRecord.w1_calcium);
+   $('#w1_sulfate').val(dataRecord.w1_sulfate);
+   $('#w1_chloride').val(dataRecord.w1_chloride);
+   $('#w1_sodium').val(dataRecord.w1_sodium);
+   $('#w1_magnesium').val(dataRecord.w1_magnesium);
+   $('#w1_total_alkalinity').val(dataRecord.w1_total_alkalinity);
+   $('#w1_ph').val(dataRecord.w1_ph);
+   $('#w1_cost').val(dataRecord.w1_cost);
+   $('#w2_name').val(dataRecord.w2_name);
+   $('#w2_amount').val(dataRecord.w2_amount);
+   $('#w2_calcium').val(dataRecord.w2_calcium);
+   $('#w2_sulfate').val(dataRecord.w2_sulfate);
+   $('#w2_chloride').val(dataRecord.w2_chloride);
+   $('#w2_sodium').val(dataRecord.w2_sodium);
+   $('#w2_magnesium').val(dataRecord.w2_magnesium);
+   $('#w2_total_alkalinity').val(dataRecord.w2_total_alkalinity);
+   $('#w2_ph').val(dataRecord.w2_ph);
+   $('#w2_cost').val(dataRecord.w2_cost);
+   $('#wg_amount').val(dataRecord.wg_amount);
+   $('#wg_calcium').val(dataRecord.wg_calcium);
+   $('#wg_sulfate').val(dataRecord.wg_sulfate);
+   $('#wg_chloride').val(dataRecord.wg_chloride);
+   $('#wg_sodium').val(dataRecord.wg_sodium);
+   $('#wg_magnesium').val(dataRecord.wg_magnesium);
+   $('#wg_total_alkalinity').val(dataRecord.wg_total_alkalinity);
+   $('#wg_ph').val(dataRecord.wg_ph);
+   $('#wb_calcium').val(dataRecord.wb_calcium);
+   $('#wb_sulfate').val(dataRecord.wb_sulfate);
+   $('#wb_chloride').val(dataRecord.wb_chloride);
+   $('#wb_sodium').val(dataRecord.wb_sodium);
+   $('#wb_magnesium').val(dataRecord.wb_magnesium);
+   $('#wb_total_alkalinity').val(dataRecord.wb_total_alkalinity);
+   $('#wb_ph').val(dataRecord.wb_ph);
+   $('#wa_acid_name').val(dataRecord.wa_acid_name);
+   $('#wa_acid_perc').val(dataRecord.wa_acid_perc);
+   $('#wa_base_name').val(dataRecord.wa_base_name);
+   editFermentable(dataRecord);
+   editHop(dataRecord);
+   editMisc(dataRecord);
+   editYeast(dataRecord);
+   editMash(dataRecord);
+   $('#jqxTabs').jqxTabs('next');
+  },
+  loadError: function(jqXHR, status, error) {},
+  beforeLoadComplete: function(records) { $('#jqxLoader').jqxLoader('open'); }
+ }),
 
-	function calcIBUs() {
-		var total_ibus = 0;
-		hop_aroma = hop_flavour = 0;
-		var rows = {};
-		if (!(rows = $('#hopGrid').jqxGrid('getrows'))) {
-                        return;
-                }
-		for (var i = 0; i < rows.length; i++) {
-			var row = rows[i];
-			total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size),
-					parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method);
-			hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
-						row.h_useat, parseFloat(row.h_amount));
-			hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
-					        row.h_useat, parseFloat(row.h_amount));
-		}
-		total_ibus = Math.round(total_ibus * 10) / 10;
-		hop_flavour = Math.round(hop_flavour * 1000 / 5) / 10;
-                hop_aroma = Math.round(hop_aroma * 1000 / 6) / 10;
-		if (hop_flavour > 100)
-                        hop_flavour = 100;
-                if (hop_aroma > 100)
-                        hop_aroma = 100;
-		console.log("calcIBUs(): " + total_ibus + "  flavour: " + hop_flavour + "  aroma: " + hop_aroma);
-		dataRecord.est_ibu = total_ibus;
-		$('#est_ibu').val(total_ibus);
-		$('#est_ibu2').val(total_ibus);
-		$("#hop_flavour").jqxProgressBar('val', hop_flavour);
-		$("#hop_aroma").jqxProgressBar('val', hop_aroma);
-	};
-
-	function adjustHops(factor) {
-
-		console.log("adjustHops("+factor+")");
-
-		var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount;
-		if (rowscount == 0)
-			return;
-
-		for (var i = 0; i < rowscount; i++) {
-			var row = $("#hopGrid").jqxGrid('getrowdata', i);
-			var amount = row.h_amount * factor;
-			$("#hopGrid").jqxGrid('setcellvalue', i, "h_amount", amount);
-		}
-	};
-
-	function adjustMiscs(factor) {
-
-		console.log("adjustMiscs("+factor+")");
-
-		var rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount;
-		if (rowscount == 0)
-			return;
-
-		for (var i = 0; i < rowscount; i++) {
-			var row = $("#miscGrid").jqxGrid('getrowdata', i);
-			var amount = row.m_amount * factor;
-			$("#miscGrid").jqxGrid('setcellvalue', i, "m_amount", amount);
-			switch (row.m_name) {
-				case 'CaCl2':           $("#wa_cacl2").val(row.m_amount * 1000);
-							break;
-				case 'CaSO4':           $("#wa_caso4").val(row.m_amount * 1000);
-							break;
-				case 'MgSO4':           $("#wa_mgso4").val(row.m_amount * 1000);
-							break;
-				case 'NaCl':            $("#wa_nacl").val(row.m_amount * 1000);
-							break;
-				case 'Melkzuur':
-				case 'Zoutzuur':
-				case 'Fosforzuur':
-				case 'Zwavelzuur':      $("#wa_acid").val(row.m_amount * 1000);
-							break;
-				case 'NaHCO3':
-				case 'Na2CO3':
-				case 'CaCO3':
-				case 'Ca(OH)2':         $("#wa_base").val(row.m_amount * 1000);
-							break;
-			}
-		}
-	};
-
-	function adjustYeasts(factor) {
-
-		console.log("adjustYeasts("+factor+")");
-
-		var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
-		if (rowscount == 0)
-			return;
-
-		for (var i = 0; i < rowscount; i++) {
-			var row = $("#yeastGrid").jqxGrid('getrowdata', i);
-			if (row.y_form == 1) { // Only adjust dry yeast
-				var amount = row.y_amount * factor;
-				$("#yeastGrid").jqxGrid('setcellvalue', i, "y_amount", amount);
-			}
-		}
-	};
-
-	function adjustWaters(factor) {
-
-		console.log("adjustWaters("+factor+")");
-
-		var rowscount = $("#mashGrid").jqxGrid('getdatainformation').rowscount;
-		if (rowscount == 0)
-			return;
-
-		mash_infuse = 0;
-		for (var i = 0; i < rowscount; i++) {
-			var row = $("#mashGrid").jqxGrid('getrowdata', i);
-			if (row.step_type == 0) { // Infusion
-				var amount = Math.round(row.step_infuse_amount * factor * 10) / 10;
-				$("#mashGrid").jqxGrid('setcellvalue', i, "step_infuse_amount", amount);
-				mash_infuse += amount;
-			}
-		}
-		if (dataRecord.w2_amount == 0) {
-			dataRecord.w1_amount = mash_infuse;
-			$("#w1_amount").val(mash_infuse);
-		} else {
-			dataRecord.w1_amount = (dataRecord.w1_amount / (dataRecord.w1_amount + dataRecord.w2_amount)) * mash_infuse;
-			dataRecord.w2_amount = (dataRecord.w2_amount / (dataRecord.w1_amount + dataRecord.w2_amount)) * mash_infuse;
-			$("#w1_amount").val(dataRecord.w1_amount);
-			$("#w2_amount").val(dataRecord.w2_amount);
-		}
-		$('#wg_amount').val(mash_infuse);
-	};
+ // Inline fermentables editor
+ editFermentable = function(data) {
+  var fermentableSource = {
+   localdata: data.fermentables,
+   datatype: 'local',
+   cache: false,
+   async: false,
+   datafields: [
+    { name: 'f_name', type: 'string' },
+    { name: 'f_origin', type: 'string' },
+    { name: 'f_supplier', type: 'string' },
+    { name: 'f_amount', type: 'float' },
+    { name: 'f_cost', type: 'float' },
+    { name: 'f_type', type: 'int' },
+    { name: 'f_yield', type: 'float' },
+    { name: 'f_color', type: 'float' },
+    { name: 'f_coarse_fine_diff', type: 'float' },
+    { name: 'f_moisture', type: 'float' },
+    { name: 'f_diastatic_power', type: 'float' },
+    { name: 'f_protein', type: 'float' },
+    { name: 'f_max_in_batch', type: 'float' },
+    { name: 'f_graintype', type: 'int' },
+    { name: 'f_added', type: 'int' },
+    { name: 'f_dissolved_protein', type: 'float' },
+    { name: 'f_recommend_mash', type: 'int' },
+    { name: 'f_add_after_boil', type: 'int' },
+    { name: 'f_adjust_to_total_100', type: 'int' },
+    { name: 'f_percentage', type: 'float' },
+    { name: 'f_di_ph', type: 'float' },
+    { name: 'f_acid_to_ph_57', type: 'float' },
+    { name: 'f_inventory', type: 'float' },
+    { name: 'f_avail', type: 'int' }
+   ],
+   addrow: function(rowid, rowdata, position, commit) {
+    //console.log("fermentable addrow "+rowid);
+    commit(true);
+   },
+   deleterow: function(rowid, commit) {
+    //console.log("fermentable deleterow "+rowid);
+    commit(true);
+   },
+   updaterow: function(rowid, rowdata, commit) {
+    //console.log("fermentable updaterow "+rowid);
+    commit(true);
+   }
+  },
+  fermentableAdapter = new $.jqx.dataAdapter(fermentableSource);
 
-	function GetBUGU() {
-		var gu = (dataRecord.est_og - 1) * 1000;
-		if (gu > 0)
-			return dataRecord.est_ibu / gu;
-		else
-			return 0.5;
-	}
-
-	function GetOptClSO4ratio() {
-		var BUGU = GetBUGU();
-		return (-1.2 * BUGU + 1.4);
-	}
-
-	function setWaterAgent(name, amount) {
-		//console.log("setWaterAgent(" + name + ", " + amount + ")");
-		var rows = $('#miscGrid').jqxGrid('getrows');
-		if (amount == 0) {
-			for (var i = 0; i < rows.length; i++) {
-				var row = rows[i];
-				if (row.m_name == name) {
-					var id = $("#miscGrid").jqxGrid('getrowid', i);
-					var commit = $("#miscGrid").jqxGrid('deleterow', id);
-				}
-			}
-		} else {
-			var found = false;
-			for (var i = 0; i < rows.length; i++) {
-				var row = rows[i];
-				if (row.m_name == name) {
-					found = true;
-					$("#miscGrid").jqxGrid('setcellvalue', i, 'm_amount', amount / 1000);
-					break;
-				}
-			}
-			if (! found) {
-				var miscs = new $.jqx.dataAdapter(miscInvSource, {
-					loadComplete: function () {
-						var records = miscs.records;
-						for (var i = 0; i < records.length; i++) {
-							var record = records[i];
-							if (record.name == name) {
-								var row = {};
-								row["m_name"] = record.name;
-								row["m_amount"] = amount / 1000;
-								row["m_cost"] = record.cost;
-								row["m_type"] = record.type;
-								row["m_use_use"] = record.use_use;
-								row["m_time"] = 0;
-								row["m_amount_is_weight"] = record.amount_is_weight;
-								row["m_inventory"] = record.inventory;
-								row["m_avail"] = 1;
-								var commit = $("#miscGrid").jqxGrid('addrow', null, row);
-							}
-						}
-					}
-				});
-				miscs.dataBind();
-				return;
-			}
-		}
-	}
-
-	function setRangeIndicator(ion, rangeCode) {
-		if ((rangeCode == "laag") || (rangeCode == "hoog"))
-			$("#wr_"+ion).html("<img src='images/dialog-error.png'><span style='vertical-align: top; font-size: 10px; font-style: italic;'>"+rangeCode + "</span>");
-		else
-			$("#wr_"+ion).html("<img src='images/dialog-ok-apply.png'>");
-	}
-
-	function mix(v1, v2, c1, c2) {
-		if ((v1 + v2) > 0) {
-			return ((v1 * c1) + (v2 * c2)) / (v1 + v2);
-		}
-		return 0;
-	}
-
-	// mg/l as CaCO3
-	function ResidualAlkalinity(total_alkalinity, calcium, magnesium) {
-		return total_alkalinity - (calcium / 1.4 + magnesium / 1.7);
-	}
-
-	var Ka1 = 0.0000004445;
-	var Ka2 = 0.0000000000468;
-
-	function PartCO3(pH) {
-		var H = Math.pow(10, -pH);
-		return 100 * Ka1 * Ka2 / (H*H + H * Ka1 + Ka1 * Ka2);
-	}
-
-	function PartHCO3(pH) {
-		var H = Math.pow(10, -pH);
-		return 100 * Ka1 * H / (H*H + H * Ka1 + Ka1 * Ka2);
-	}
-
-	function Charge(pH) {
-		return (-2 * PartCO3(pH) - PartHCO3(pH));
-	}
-
-	//Z alkalinity is the amount of acid (in mEq/l) needed to bring water to the target pH (Z pH)
-	function ZAlkalinity(pHZ) {
-		var C43 = Charge(4.3);
-		var Cw = Charge(parseFloat($("#wg_ph").jqxNumberInput('decimal')));
-		var Cz = Charge(pHZ);
-		var DeltaCNaught = -C43+Cw;
-		var CT = parseFloat($("#wg_total_alkalinity").jqxNumberInput('decimal')) / 50 / DeltaCNaught;
-		var DeltaCZ = -Cz+Cw;
-		return CT * DeltaCZ;
-	}
-
-	//Z Residual alkalinity is the amount of acid (in mEq/l) needed to bring the water in the mash to the target pH (Z pH)
-	function ZRA(pHZ) {
+  $('#fermentableGrid').jqxGrid({
+   width: 1240,
+   height: 470,
+   source: fermentableAdapter,
+   theme: theme,
+   selectionmode: 'singlerow',
+   showtoolbar: true,
+   rendertoolbar: function(toolbar) {
+    //var me = this;
+    var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
+    toolbar.append(container);
+    container.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');
+    container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
+    container.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');
+    container.append('<input style="float: left; margin-left: 400px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');
+    // add fermentable from dropdownlist.
+    $('#faddrowbutton').jqxDropDownList({
+     placeHolder: 'Kies mout:',
+     theme: theme,
+     template: 'primary',
+     source: fermentablelist,
+     displayMember: 'name',
+     width: 150,
+     height: 27,
+     dropDownWidth: 500,
+     dropDownHeight: 500,
+     renderer: function(index, label, value) {
+      var datarecord = fermentablelist.records[index];
+      return datarecord.supplier + ' / ' + datarecord.name + ' (' + datarecord.color + ' EBC)';
+     }
+    });
+    $('#faddrowbutton').on('select', function(event) {
+     if (event.args) {
+      var index, datarecord, row = {}, rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+      index = event.args.index;
+      datarecord = fermentablelist.records[index];
+      row['f_name'] = datarecord.name;
+      row['f_origin'] = datarecord.origin;
+      row['f_supplier'] = datarecord.supplier;
+      row['f_amount'] = 0;
+      row['[_cost'] = datarecord.cost;
+      row['f_type'] = datarecord.type;
+      row['f_yield'] = datarecord.yield;
+      row['f_color'] = datarecord.color;
+      row['f_coarse_fine_diff'] = datarecord.coarse_fine_diff;
+      row['f_moisture'] = datarecord.moisture;
+      row['f_diastatic_power'] = datarecord.diastatic_power;
+      row['f_protein'] = datarecord.protein;
+      row['f_max_in_batch'] = datarecord.max_in_batch;
+      row['f_graintype'] = datarecord.graintype;
+      if (datarecord.add_after_boil) {
+       row['f_added'] = 2;     // Fermentation
+      } else if ((datarecord.type == 1) || (datarecord.type == 4)) {  // Sugar or Adjunct
+       row['f_added'] = 1;     // Boil
+      } else {
+       row['f_added'] = 0;     // Mash
+      }
+      row['f_dissolved_protein'] = datarecord.dissolved_protein;
+      row['f_recommend_mash'] = datarecord.recommend_mash;
+      row['f_add_after_boil'] = datarecord.add_after_boil;
+      if (rowscount == 0) {
+       // The first fermentable
+       row['f_adjust_to_total_100'] = 1;
+       row['f_percentage'] = 100;
+      } else {
+       row['f_adjust_to_total_100'] = 0;
+       row['f_percentage'] = 0;
+      }
+      row['f_di_ph'] = datarecord.di_ph;
+      row['f_acid_to_ph_57'] = datarecord.acid_to_ph_57;
+      row['f_inventory'] = datarecord.inventory;
+      $('#fermentableGrid').jqxGrid('addrow', null, row);
+     }
+    });
+    $('#finstockbutton').jqxCheckBox({ theme: theme, height: 27 });
+    $('#finstockbutton').on('change', function(event) {
+     fermentableinstock = event.args.checked;
+     fermentablelist.dataBind();
+    });
 
-		var Calc = parseFloat($("#wg_calcium").jqxNumberInput('decimal')) / (MMCa / 2);
-		var Magn = parseFloat($("#wg_magnesium").jqxNumberInput('decimal')) / (MMMg / 2);
-		var Z = ZAlkalinity(pHZ);
-		return Z - (Calc / 3.5 + Magn / 7);
-	}
-
-	function ProtonDeficit(pHZ) {
-
-		var Result = ZRA(pHZ) * parseFloat($("#wg_amount").jqxNumberInput('decimal'));
-		// proton deficit for the grist
-		var rows = $('#fermentableGrid').jqxGrid('getrows');
-		for (var i = 0; i < rows.length; i++) {
-			var row = rows[i];
-			if (row.f_added == 0 && row.f_graintype != 6) {	// Added == Mash && graintype != No Malt
-				// Check if acid is required
-				var C1 = 0;
-				if ((row.f_di_ph != 5.7) && ((row.f_acid_to_ph_57 < - 0.1) || (row.f_acid_to_ph_57 > 0.1))) {
-					C1 = row.f_acid_to_ph_57 / (row.f_di_ph - 5.7);
-				} else {
-					// If the acid_to_ph_5.7 is unknown from the maltster, guess the required acid.
-					var ebc = row.f_color;
-					switch (row.f_graintype) {
-						case 0:					// Base, Special, Kilned
-						case 3:
-						case 5:	C1 = 0.014 * ebc - 34.192;
-							break;
-						case 2:	C1 = -0.0597 * ebc - 32.457;	// Crystal
-							break;
-						case 1:	C1 = 0.0107 * ebc - 54.768;	// Roast
-							break;
-						case 4:	C1 = -149;			// Sour malt
-							break;
-					}
-				}
-				x = C1 * (pHZ - row.f_di_ph);	// AcidRequired(ZpH)
-				Result += x * row.f_amount;
-			}
-		}
-		return Result;
-	}
-
-	function MashpH() {
-		var n = 0;
-		var pH = 5.4;
-		var deltapH = 0.001;
-		var deltapd = 0.1;
-		var pd = ProtonDeficit(pH);
-		while (((pd < -deltapd) || (pd > deltapd)) && (n < 2000)) {
-			n++;
-			if (pd < -deltapd)
-				pH -= deltapH;
-			else if (pd > deltapd)
-				pH += deltapH;
-			pd = ProtonDeficit(pH);
-		}
-		console.log("MashpH() n: "+n+" pH: "+pH);
-		return pH;
-	}
-
-	function GetAcidSpecs(AT) {
-		switch(AT) {
-			case 0:	return {	// Melkzuur
-					pK1: 3.86,
-					pK2: 20,
-					pK3: 20,
-					MolWt: 90.08,
-					AcidSG: 1214,
-					AcidPrc: 0.88
-				};
-			case 1:	return {	// Zoutzuur
-					pK1: -7,
-					pK2: 20,
-					pK3: 20,
-					MolWt: 36.46,
-					AcidSG: 1142,
-					AcidPrc: 0.28
-				};
-			case 2:	return {	// Fosforzuur
-					pK1: 2.12,
-					pK2: 7.20,
-					pK3: 12.44,
-					MolWt: 98.00,
-					AcidSG: 1170,
-					AcidPrc: 0.25
-				};
-			case 3:	return {	// Zwavelzuur
-					pK1: -1,
-					pK2: 1.92,
-					pK3: 20,
-					MolWt: 98.07,
-					AcidSG: 1700,
-					AcidPrc: 0.93
-				};
-		}
-		console.log("Bummer, AT is " + AT);
-	}
-
-	// Procedure TFrmWaterAdjustment.CalcWater2;
-	function calcWater() {
-
-		console.log("calcWater()");
-		var liters = 0;
-		var calcium = 0;
-		var magnesium = 0;
-		var sodium = 0;
-		var total_alkalinity = 0;
-		var bicarbonate = 0;
-		var chloride = 0;
-		var sulfate = 0;
-		var ph = 0;
-		var RA = 0;
-		var acid = 0;
-		var frac = 0;
-		var TpH = 0;
-		var protonDeficit = 0;
-
-		if (dataRecord.w1_name == "") {
-			return;
-		}
-		// Check for a recipe too. Fermentables, Mash schedule?
+    // delete selected fermentable.
+    $('#fdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150 });
+    $('#fdeleterowbutton').on('click', function() {
+     var id, percent, amount, i, rowdata, rowscount, selectedrowindex = $('#fermentableGrid').jqxGrid('getselectedrowindex');
+     rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+     if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+      id = $('#fermentableGrid').jqxGrid('getrowid', selectedrowindex);
+      percent = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_percentage');
+      amount = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_amount');
+      $('#fermentableGrid').jqxGrid('deleterow', id);
+     }
+     rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+     if (rowscount > 1) {
+      if (to_100) {
+       for (i = 0; i < rowscount; i++) {
+        rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
+        if (rowdata.f_adjust_to_total_100) {
+         rowdata.f_percentage += percent;
+         rowdata.f_amount += amount;
+        }
+       }
+      } else {
+       calcPercentages();
+      }
+     } else {
+      $('#fermentableGrid').jqxGrid('setcellvalue', 0, 'f_percentage', 100);
+     }
+     calcFermentables();
+     calcIBUs();
+    });
+   },
+   ready: function() {
+    calcFermentables();
+    $('#jqxTabs').jqxTabs('next');
+   },
+   columns: [
+    { text: 'Vergistbaar ingredi&euml;nt', datafield: 'f_name',
+     cellsrenderer: function(index, datafield, value, defaulvalue, column, rowdata) {
+      return '<span style="margin: 3px; margin-top: 6px; float: left;">' +
+      rowdata.f_supplier + ' / ' + rowdata.f_name + ' (' + rowdata.f_color + ' EBC)</span>';
+     }
+    },
+    { text: 'Type', width: 100, datafield: 'f_type',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 3px; margin-top: 6px; float: left;">' + FermentableTypeData[value].nl + '</span>';
+     }
+    },
+    { text: 'Moment', width: 110, datafield: 'f_added',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 3px; margin-top: 6px; float: left;">' + AddedData[value].nl + '</span>';
+     }
+    },
+    { text: 'Maxinbatch', datafield: 'f_max_in_batch', hidden: true },
+    { text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
+    { text: 'Gewicht Kg', datafield: 'f_amount', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f3' },
+    { text: 'Voorr. Kg', datafield: 'f_inventory', width: 120, align: 'right',
+     cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) {
+      var color = '#ffffff';
+      if (value < rowdata.f_amount)
+       color = '#ff4040';
+      return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' +
+             color + ';">' + fermentableAdapter.formatNumber(value, 'f3') + '</span>';
+     }
+    },
+    { text: 'Procent', datafield: 'f_percentage', width: 90, align: 'right',
+     cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) {
+      var color = '#ffffff';
+      if (value > rowdata.f_max_in_batch)
+       color = '#ff4040';
+      return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' +
+             color + ';">' + fermentableAdapter.formatNumber(value, 'p1') + '</span>';
+     }
+    },
+    { text: '100%', align: 'center', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 70 },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function() {
+     return 'Wijzig';
+     }, buttonclick: function(row) {
+      fermentableRow = row;
+      fermentableData = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
+      $('#wf_name').val(fermentableData.f_name);
+      $('#wf_amount').val(fermentableData.f_amount);
+      $('#wf_percentage').val(fermentableData.f_percentage);
+      $('#wf_max_in_batch').val(fermentableData.f_max_in_batch);
+      $('#wf_adjust_to_total_100').val(fermentableData.f_adjust_to_total_100);
+      $('#wf_added').val(fermentableData.f_added);
+      // show the popup window.
+      $('#popupFermentable').jqxWindow('open');
+     }
+    }
+   ]
+  });
+ };
 
-		// If there is a dillute water source, mix the waters.
-		if (dataRecord.w2_name != "") {
-			liters = dataRecord.w1_amount + dataRecord.w2_amount;
-			calcium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_calcium, dataRecord.w2_calcium);
-			magnesium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_magnesium, dataRecord.w2_magnesium);
-			sodium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sodium, dataRecord.w2_sodium);
-			chloride = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_chloride, dataRecord.w2_chloride);
-			sulfate = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sulfate, dataRecord.w2_sulfate);
-			total_alkalinity = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_total_alkalinity, dataRecord.w2_total_alkalinity);
-			ph = -Math.log10(((Math.pow(10, -dataRecord.w1_ph) * dataRecord.w1_amount) + (Math.pow(10, -dataRecord.w2_ph) * dataRecord.w2_amount))  / liters);
-		} else {
-			liters = dataRecord.w1_amount;
-			calcium = dataRecord.w1_calcium;
-			magnesium = dataRecord.w1_magnesium;
-			sodium = dataRecord.w1_sodium;
-			chloride = dataRecord.w1_chloride;
-			sulfate = dataRecord.w1_sulfate;
-			total_alkalinity = dataRecord.w1_total_alkalinity;
-			ph = dataRecord.w1_ph;
-		}
-		$('#wg_amount').val(liters);
-		var wg_calcium = calcium;
-		$('#wg_calcium').val(Math.round(calcium * 10) / 10);
-		var wg_magnesium = magnesium;
-		$('#wg_magnesium').val(Math.round(magnesium * 10) / 10);
-		var wg_sodium = sodium;
-		$('#wg_sodium').val(Math.round(sodium * 10) / 10);
-		var wg_total_alkalinity = total_alkalinity;
-		$('#wg_total_alkalinity').val(Math.round(total_alkalinity * 10) / 10);
-		var wg_chloride = chloride;
-		$('#wg_chloride').val(Math.round(chloride * 10) / 10);
-		var wg_sulfate = sulfate;
-		$('#wg_sulfate').val(Math.round(sulfate * 10) / 10);
-		// Note: brouwhulp has the malts included here in the result.
-		var wg_ph = ph;
-		$('#wg_ph').val(Math.round(ph * 10) / 10);
-		$('#wb_ph').val(Math.round(MashpH() * 10) / 10);
-		bicarbonate = total_alkalinity * 1.22;
-		var wg_bicarbonate = bicarbonate;
-
-		// Noot: de volgende berekeningen geven bijna gelijke resultaten in Brun'water.
-		// Calculate Ca
-		RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
-		     parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4;
-		calcium += 1000 * RA / liters;
-
-		// Calculate Mg
-		RA = parseFloat($("#wa_mgso4").jqxNumberInput('decimal')) * MMMg / MMMgSO4;
-		magnesium += 1000 * RA / liters;
-
-		// Calculate Na
-		RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl;
-		sodium += 1000 * RA / liters;
+ // Inline hops editor
+ var editHop = function(data) {
+  var hopSource = {
+   localdata: data.hops,
+   datatype: 'local',
+   cache: false,
+   async: false,
+   datafields: [
+    { name: 'h_name', type: 'string' },
+    { name: 'h_origin', type: 'string' },
+    { name: 'h_amount', type: 'float' },
+    { name: 'h_cost', type: 'float' },
+    { name: 'h_type', type: 'int' },
+    { name: 'h_form', type: 'int' },
+    { name: 'h_useat', type: 'int' },
+    { name: 'h_time', type: 'float' },
+    { name: 'h_alpha', type: 'float' },
+    { name: 'h_beta', type: 'float' },
+    { name: 'h_hsi', type: 'float' },
+    { name: 'h_humulene', type: 'float' },
+    { name: 'h_caryophyllene', type: 'float' },
+    { name: 'h_cohumulone', type: 'float' },
+    { name: 'h_myrcene', type: 'float' },
+    { name: 'h_total_oil', type: 'float' },
+    { name: 'h_inventory', type: 'float' },
+    { name: 'h_avail', type: 'int' }
+   ],
+   addrow: function(rowid, rowdata, position, commit) {
+    //console.log("hop addrow "+rowid);
+    commit(true);
+   },
+   deleterow: function(rowid, commit) {
+    //console.log("hop deleterow "+rowid);
+    commit(true);
+   },
+   updaterow: function(rowid, rowdata, commit) {
+    //console.log("hop updaterow "+rowid);
+    commit(true);
+   }
+  },
+  hopAdapter = new $.jqx.dataAdapter(hopSource);
 
-		// Calculate SO4
-		RA = parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMSO4 / MMCaSO4 +
-		     parseFloat($("#wa_mgso4").jqxNumberInput('decimal')) * MMSO4 / MMMgSO4;
-		sulfate += 1000 * RA / liters;
-
-		// Calculate Cl
-		RA = 2 * parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCl / MMCaCl2 +
-		     parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMCl / MMNaCl;
-		chloride += 1000 * RA / liters;
-		// Einde noot.
-
-		if ($("#wa_acid_name").val() < 0 || $("#wa_acid_name").val() > 3) {
-			console.log("fix wa_acid_name");
-			$("#wa_acid_name").val(0);
-			dataRecord.wa_acid_name = 0;
-		}
-		if (last_acid == '')
-			last_acid = AcidTypeData[$("#wa_acid_name").val()].nl;
-
-		if ($("#wa_base_name").val() < 0 || $("#wa_base_name").val() > 3) {
-			console.log("fix wa_base_name");
-			$("#wa_base_name").val(0);
-			dataRecord.wa_base_name = 0;
-		}
-		if (last_base == '')
-			last_base = BaseTypeData[$("#wa_base_name").val()].nl;
-
-		var AT = dataRecord.wa_acid_name;
-		var BT = dataRecord.wa_base_name;
-
-		var result = GetAcidSpecs(AT);
-		var pK1 = result.pK1;
-		var pK2 = result.pK2;
-		var pK3 = result.pK3;
-		var MolWt = result.MolWt;
-		var AcidSG = result.AcidSG;
-		var AcidPrc = result.AcidPrc;
-
-		if (dataRecord.calc_acid) {
-			TpH = parseFloat(dataRecord.mash_ph);
-			protonDeficit = ProtonDeficit(TpH);
-			console.log("calc_acid tgt: "+TpH+" protonDeficit: "+protonDeficit);
-			if (protonDeficit > 0) { // Add acid
-				$("#wa_base").val(0);
-				setWaterAgent(last_base, 0);
-				frac = CalcFrac(TpH, pK1, pK2, pK3);
-				Acid = protonDeficit / frac;
-				Acid *= MolWt; // mg
-				Acidmg = Acid;
-				Acid = Acid / AcidSG; // ml
-
-				if (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) == 0)
-					$("#wa_acid_perc").val(AcidPrc);
-				Acid = Acid * AcidPrc / (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) / 100); // ml
-				console.log("Final ml: "+Acid);
-				$("#wa_acid").val(Math.round(Acid * 100) / 100);
-				setWaterAgent(AcidTypeData[AT].nl, Math.round(Acid * 100) / 100);
+  $('#hopGrid').jqxGrid({
+   width: 1240,
+   height: 560,
+   source: hopAdapter,
+   theme: theme,
+   selectionmode: 'singlerow',
+   showtoolbar: true,
+   rendertoolbar: function(toolbar) {
+    //var me = this;
+    var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
+    toolbar.append(container);
+    container.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');
+    container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
+    container.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');
+    container.append('<input style="float: left; margin-left: 400px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');
+    // add hop from dropdownlist.
+    $('#haddrowbutton').jqxDropDownList({
+     placeHolder: 'Kies hop:',
+     theme: theme,
+     template: 'primary',
+     source: hoplist,
+     displayMember: 'name',
+     width: 150,
+     height: 27,
+     dropDownWidth: 500,
+     dropDownHeight: 500,
+     renderer: function(index, label, value) {
+      var datarecord = hoplist.records[index];
+      return datarecord.origin + ' / ' + datarecord.name + ' (' + datarecord.alpha + '% &alpha;)';
+     }
+    });
+    $('#haddrowbutton').on('select', function(event) {
+     if (event.args) {
+      var datarecord, row = {}, index = event.args.index;
+      datarecord = hoplist.records[index];
+      row['h_name'] = datarecord.name;
+      row['h_origin'] = datarecord.origin;
+      row['h_amount'] = 0;
+      row['h_cost'] = datarecord.cost;
+      row['h_type'] = datarecord.type;
+      row['h_form'] = datarecord.form;
+      row['h_useat'] = 2;     // Boil
+      row['h_time'] = 0;
+      row['h_alpha'] = datarecord.alpha;
+      row['h_beta'] = datarecord.beta;
+      row['h_hsi'] = datarecord.hsi;
+      row['h_humulene'] = datarecord.humulene;
+      row['h_caryophyllene'] = datarecord.caryophyllene;
+      row['h_cohumulone'] = datarecord.cohumulone;
+      row['h_myrcene'] = datarecord.myrcene;
+      row['h_total_oil'] = datarecord.total_oil;
+      row['h_inventory'] = datarecord.inventory;
+      $('#hopGrid').jqxGrid('addrow', null, row);
+     }
+     $('#haddrowbutton').jqxDropDownList('clearSelection');
+    });
 
-				bicarbonate = bicarbonate - protonDeficit * frac / liters;
-				total_alkalinity = bicarbonate * 50 / 61;
-			} else if (protonDeficit < 0) { //Add base
-				$("#wa_acid").val(0);
-				setWaterAgent(last_acid, 0);
-				var r1d = Math.pow(10, (TpH - 6.38));
-				var r2d = Math.pow(10, (TpH - 10.38));
-				var f1d = 1 / (1 + r1d + r1d * r2d);
-				var f2d = f1d * r1d;
-				var f3d = f2d * r2d;
-				switch (BT) {
-					case 0:	RA = -protonDeficit / (f1d - f3d); //Sodiumbicarbonate, mmol totaal
-						RA = RA * MMNaHCO3/1000; //gram
-						$("#wa_base").val(Math.round(RA * 100) / 100);
-						setWaterAgent('NaHCO3', Math.round(RA * 100) / 100);
-						if (liters > 0) {
-							// Na
-							RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl +
-							     parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMNa / MMNaHCO3;
-							RA = 1000 * RA / liters;
-							sodium = wg_sodium + RA;
-							// HCO3
-							RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMHCO3 / MMNaHCO3;
-							RA = 1000 * RA / liters;
-							bicarbonate = wg_bicarbonate + RA;
-							total_alkalinity = bicarbonate * 50 / 61;
-							RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
-						}
-						break;
-					case 1:	RA = -protonDeficit / (2 * f1d + f2d); // Sodiumcarbonate, mmol totaal
-						RA = RA * MMNa2CO3/1000; //gram
-						$("#wa_base").val(Math.round(RA * 100) / 100);
-						setWaterAgent('Na2CO3', Math.round(RA * 100) / 100);
-						if (liters > 0) {
-							RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl +
-							     parseFloat($("#wa_base").jqxNumberInput('decimal')) * 2 * MMNa / MMNa2CO3;
-							RA = 1000 * RA / liters;
-							sodium = wg_sodium + RA;
-							// HCO3
-							RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMHCO3 / MMNa2CO3;
-							RA = 1000 * RA / liters;
-							bicarbonate = wg_bicarbonate + RA;
-							total_alkalinity = bicarbonate * 50 / 61;
-							RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
-						}
-						break;
-					case 2:	RA = -protonDeficit * (f1d - f3d); // Calciumcarbonate, mmol totaal
-						RA = RA * MMCaCO3/1000; //gram
-						//but only 1/3 is effective, so add 3 times as much
-						RA = 3 * RA;
-						$("#wa_base").val(Math.round(RA * 100) / 100);
-						setWaterAgent('CaCO3', Math.round(RA * 100) / 100);
-						if (liters > 0) {
-							//Bicarbonate
-							RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) / 3 * MMHCO3 / MMCaCO3;
-							RA = 1000 * RA / liters;
-							bicarbonate = wg_bicarbonate + RA;
-							total_alkalinity = bicarbonate * 50 / 61;
-							//Ca precipitates out as Ca10(PO4)6(OH)2
-							RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
-							     parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4 +
-							     parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMCa / MMCaCO3;
-							RA = 1000 * RA / liters;
-							calcium = wg_calcium + RA;
-							RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
-						}
-						break;
-					case 3:	RA = -protonDeficit / 19.3; // Calciumhydroxide
-						$("#wa_base").val(Math.round(RA * 100) / 100);
-						setWaterAgent('Ca(OH)2', Math.round(RA * 100) / 100);
-						if (liters > 0) {
-							// Bicarbonate
-							RA = -protonDeficit / liters;
-							total_alkalinity = wg_total_alkalinity + RA;
-							bicarbonate = total_alkalinity * 61 / 50;
-							// Calcium
-							RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
-							     parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4 +
-							     parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMCa / MMCaOH2;
-							RA = 1000 * RA / liters;
-							calcium = wg_calcium + RA;
-							RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
-						}
-						break;
-				}
-			}
-			ph = TpH;
-			$('#wb_ph').val(Math.round(ph * 10) / 10);
-		} else { // Manual
-			console.log("calc_acid no");
-			// First add base salts
-			if (parseFloat($("#wa_base").jqxNumberInput('decimal')) > 0) {
-				if (liters > 0) {
-					switch (BT) {
-						case 0:	// Sodiumbicarbonate, Na
-							RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl +
-							     parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMNa / MMNaHCO3;
-							RA = 1000 * RA / liters;
-							sodium = wg_sodium + RA;
-							// HCO3
-							RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMHCO3 / MMNaHCO3;
-							RA = 1000 * RA / liters;
-							bicarbonate = wg_bicarbonate + RA;
-							total_alkalinity = bicarbonate * 50 / 61;
-							RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
-							break;
-						case 1:	// Sodiumcarbonate
-							RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl +
-							     parseFloat($("#wa_base").jqxNumberInput('decimal')) * 2 * MMNa / MMNa2CO3;
-							RA = 1000 * RA / liters;
-							sodium = wg_sodium + RA;
-							// HCO3
-							RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMHCO3 / MMNa2CO3;
-							RA = 1000 * RA / liters;
-							bicarbonate = wg_bicarbonate + RA;
-							total_alkalinity = bicarbonate * 50 / 61;
-							RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
-							break;
-						case 2:	// Calciumcarbonate: Bicarbonate
-							RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) / 3 * MMHCO3 / MMCaCO3;
-							RA = 1000 * RA / liters;
-							bicarbonate = wg_bicarbonate + RA;
-							total_alkalinity = bicarbonate * 50 / 61;
-							RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
-							// Ca
-							RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
-							     parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMCa / MMCaSO4 +
-							     parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMCa / MMCaCO3;
-							RA = 1000 * RA / liters;
-							calcium = wg_calcium + RA;
-							break;
-					}
-				}
-			}
+    $('#hinstockbutton').jqxCheckBox({ theme: theme, height: 27 });
+    $('#hinstockbutton').on('change', function(event) {
+     hopinstock = event.args.checked;
+     hoplist.dataBind();
+    });
+
+    // delete selected hop.
+    $('#hdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150 });
+    $('#hdeleterowbutton').on('click', function() {
+     var rowscount, id, selectedrowindex = $('#hopGrid').jqxGrid('getselectedrowindex');
+     rowscount = $('#hopGrid').jqxGrid('getdatainformation').rowscount;
+     if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+      id = $('#hopGrid').jqxGrid('getrowid', selectedrowindex);
+      $('#hopGrid').jqxGrid('deleterow', id);
+     }
+     calcIBUs();
+    });
+   },
+   ready: function() {
+    calcIBUs();
+    $('#jqxTabs').jqxTabs('next');
+   },
+   columns: [
+    { text: 'Hop', datafield: 'h_name',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 3px; margin-top: 6px; float: left;">' + rowdata.h_origin + ' / ' + rowdata.h_name + '</span>';
+     }
+    },
+    { text: 'Type', width: 90, datafield: 'h_type',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 4px; margin-top: 6px; float: left;">' + HopTypeData[value].nl + '</span>';
+     }
+    },
+    { text: 'Vorm', width: 90, datafield: 'h_form',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 4px; margin-top: 6px; float: left;">' + HopFormData[value].nl + '</span>';
+     }
+    },
+    { text: 'Alpha', datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
+    { text: 'Gebruik', width: 110, datafield: 'h_useat',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 4px; margin-top: 6px; float: left;">' + HopUseData[value].nl + '</span>';
+     }
+    },
+    { text: 'Tijdsduur', datafield: 'h_time', width: 90, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var duration = '';
+      if ((rowdata.h_useat == 2) || (rowdata.h_useat == 4))   // Boil, Whirlpool
+       duration = dataAdapter.formatNumber(value, 'f0') + ' min.';
+      else if (rowdata.h_useat == 5)       // Dry hop
+       duration = dataAdapter.formatNumber(value / 1440, 'f0') + ' dagen';
+      return '<span style="margin: 4px; margin-top: 6px; float: right;">' + duration + '</span>';
+     }
+    },
+    { text: 'IBU', datafield: 'ibu', width: 80, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var ibu = toIBU(rowdata.h_useat, rowdata.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
+                      parseFloat(rowdata.h_amount), parseFloat(rowdata.h_time),
+                      parseFloat(rowdata.h_alpha), $('#ibu_method').val());
+      return '<span style="margin: 4px; margin-top: 6px; float: right;">' + dataAdapter.formatNumber(ibu, 'f1') + '</span>';
+     }
+    },
+    { text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var amount = dataAdapter.formatNumber(value, 'f1') + ' kg';
+      if (value < 1)
+       amount = dataAdapter.formatNumber(value * 1000, 'f1') + ' gr';
+      return '<span style="margin: 4px; margin-top: 6px; float: right;">' + amount + '</span>';
+     }
+    },
+    { text: 'Voorraad', datafield: 'h_inventory', width: 110, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var amount, color = '#ffffff';
+      if (value < rowdata.h_amount)
+       color = '#ff4040';
+      amount = dataAdapter.formatNumber(value, 'f1') + ' kg';
+      if (value < 1)
+       amount = dataAdapter.formatNumber(value * 1000, 'f1') + ' gr';
+      return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
+     }
+    },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center',
+     cellsrenderer: function() {
+      return 'Wijzig';
+     }, buttonclick: function(row) {
+      hopRow = row;
+      hopData = $('#hopGrid').jqxGrid('getrowdata', hopRow);
+      $('#wh_name').val(hopData.h_name);
+      $('#wh_amount').val(hopData.h_amount * 1000);
+      var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg,
+                parseFloat($('#batch_size').jqxNumberInput('decimal')),
+                parseFloat(hopData.h_amount), parseFloat(hopData.h_time),
+                parseFloat(hopData.h_alpha), $('#ibu_method').val()
+      );
+      $('#wh_ibu').val(ibu);
+      if (hopData.h_useat == 5)       // Dry hop
+       $('#wh_time').val(hopData.h_time / 1440);
+      else
+       $('#wh_time').val(hopData.h_time);
+      $('#wh_useat').val(hopData.h_useat);
+      // show the popup window.
+      $('#popupHop').jqxWindow('open');
+     }
+    }
+   ]
+  });
+ };
 
-			TpH = parseFloat(dataRecord.mash_ph);
-			pHa = MashpH();	// This one is in demi water, should be in adjusted water???
-			// Then calculate the new pH with added acids
-			if (parseFloat($("#wa_acid").jqxNumberInput('decimal')) > 0) {
-				console.log("TpH: "+TpH+" water: "+pHa);
-				Acid = parseFloat($("#wa_acid").jqxNumberInput('decimal'));
-				if (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) == 0)
-					$("#wa_acid_perc").val(AcidPrc);
-				Acid = Acid / AcidPrc * (parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')) / 100); // ml
-				Acid *= AcidSG; // ml
-				Acid /= MolWt;  // mg
-				Acidmg = Acid;
-
-				//find the pH where the protondeficit = protondeficit by the acid
-				frac = CalcFrac(pHa, pK1, pK2, pK3);
-				protonDeficit = Acid * frac;
-
-				var deltapH = 0.001;
-				var deltapd = 0.1;
-				var pd = ProtonDeficit(pHa);
-				var n = 0;
-				while (((pd < (protonDeficit - deltapd)) || (pd > (protonDeficit + deltapd))) && (n < 2000)) {
-					n++;
-					if (pd < (protonDeficit-deltapd))
-						pHa -= deltapH;
-					else if (pd > (protonDeficit+deltapd))
-						pHa += deltapH;
-					frac = CalcFrac(pHa, pK1, pK2, pK3);
-					protonDeficit = Acid * frac;
-					pd = ProtonDeficit(pHa);
-				}
-				console.log("n: "+n+" pd: "+pd+" protonDeficit: "+protonDeficit+" frac: "+frac+" pHa: "+pHa);
-				RA = wg_bicarbonate - protonDeficit * frac / liters;
-				bicarbonate = RA;
-				total_alkalinity = RA * 50 / 61;
-				ph = pHa;
-				$('#wb_ph').val(Math.round(ph * 10) / 10);
-			}
-		}
-
-		if ((AT == 3) && (liters > 0)) {	// Sulfuctic / Zwavelzuur
-			RA = parseFloat($("#wa_caso4").jqxNumberInput('decimal')) * MMSO4 / MMCaSO4 +
-			     parseFloat($("#wa_mgso4").jqxNumberInput('decimal')) * MMSO4 / MMMgSO4 +
-			     Acidmg / 1000 * MMSO4 / (MMSO4 + 2);
-			RA = 1000 * RA / liters;
-			sulfate = wg_sulfate + RA;	// Not add to sulfate??
-		} else if ((AT == 1) && (liters > 0)) {	// Hydrochloric, Zoutzuur
-			RA = parseFloat($("#wa_cacl2").jqxNumberInput('decimal')) * MMCl / MMCaCl2 +
-			     parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMCl / MMNaCl +
-			     Acidmg / 1000 * MMCl / (MMCl + 1);
-			RA = 1000 * RA / liters;
-			chloride = wg_chloride + RA;
-		}
-
-		// 2:1 Sulfate to Chroride IPA's, Pale Ales.
-		// 1:1 Sulfate to Chloride Balanced
-		// 1:2 Sulfate to Chloride Malty
-		// Note, values below are the other way, cl to so4!
-		// So: 0.5 is IPA's, Pale Ales.
-		//       1 Balanced
-		//       2 Malty.
-		$('#tgt_bu').val(Math.round(GetBUGU() * 100) / 100);
-		// From brouwhulp.
-		if (GetBUGU() < 0.32)
-			$('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Zeer moutig en zoet</span>");
-		else if (GetBUGU() < 0.43)
-			$('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Moutig, zoet</span>");
-		else if (GetBUGU() < 0.52)
-			$('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Evenwichtig</span>");
-		else if (GetBUGU() < 0.63)
-			$('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Licht hoppig, bitter</span>");
-		else
-			$('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Extra hoppig, zeer bitter</span>");
-		$('#tgt_cl_so4').val(Math.round(GetOptClSO4ratio() * 10) / 10);
-		if (sulfate > 0)
-			RA = chloride / sulfate;
-		else
-			RA = 10;
-		$('#got_cl_so4').val(Math.round(RA * 10) / 10);
-		var piCLSO4_low = 0.8 * GetOptClSO4ratio();
-		var piCLSO4_high = 1.2 * GetOptClSO4ratio();
-		var Res = 'normaal';
-		if (RA < piCLSO4_low)
-			Res = 'laag';
-		else if (RA > piCLSO4_high)
-			Res = 'hoog';
-		setRangeIndicator('cl_so4', Res);
-
-                $('#wb_calcium').val(Math.round(calcium * 10) / 10);
-                $('#wb_magnesium').val(Math.round(magnesium * 10) / 10);
-                $('#wb_sodium').val(Math.round(sodium * 10) / 10);
-                $('#wb_sulfate').val(Math.round(sulfate * 10) / 10);
-                $('#wb_chloride').val(Math.round(chloride * 10) / 10);
-		$('#wb_total_alkalinity').val(Math.round(total_alkalinity * 10) / 10);
-
-                if (calcium < 40) {
-			setRangeIndicator("calcium", "laag");
-		} else if (calcium > 150) {
-			setRangeIndicator("calcium", "hoog");
-		} else {
-			setRangeIndicator("calcium", "normaal");
-		}
-                if (magnesium >= 0 && magnesium <= 30) {
-			setRangeIndicator("magnesium", "normaal");
-		} else {
-			setRangeIndicator("magnesium", "hoog");
-		}
-                if (sodium <= 150) {
-			setRangeIndicator("sodium", "normaal");
-		} else {
-			setRangeIndicator("sodium", "hoog");
-		}
-		// Both chloride and sulfate should be above 50 according to
-		// John Palmer. So the Cl/SO4 ratio calculation will work.
-		if (chloride <= 50) {
-			setRangeIndicator("chloride", "laag");
-		} else if (chloride <= 100) {
-			setRangeIndicator("chloride", "normaal");
-		} else {
-			setRangeIndicator("chloride", "hoog");
-		}
-		if (sulfate <= 50) {
-			setRangeIndicator("sulfate", "laag");
-                } else if (sulfate <= 350) {
-			setRangeIndicator("sulfate", "normaal");
-		} else {
-			setRangeIndicator("sulfate", "hoog");
-		}
-		if (ph < 5.2) {
-			setRangeIndicator("ph", "laag");
-		} else if (ph > 5.6) {
-			setRangeIndicator("ph", "hoog");
-		} else {
-			setRangeIndicator("ph", "normaal");
-		}
-		calcSparge();
-	}
-
-	function calcSparge() {
-
-		// Code from BrewBuddy/Brouwhulp, who got it from http://www.brewery.org/brewery/library/Acidi0,00fWaterAJD0497.html
-		var TargetpH = dataRecord.sparge_ph;
-		var Source_pH = dataRecord.w1_ph;
-		var Source_alkalinity = dataRecord.w1_total_alkalinity;
-		// Select watersource or fallback to the first source.
-		if (dataRecord.sparge_source == 1) {	// Source 2
-			if (dataRecord.w2_ph > 0.0) {
-				Source_pH = dataRecord.w2_ph;
-				Source_alkalinity = dataRecord.w2_total_alkalinity;
-			} else {
-				dataRecord.sparge_source = 0;	// Source 1
-				$("#sparge_source").val(0);
-			}
-		} else if (dataRecord.sparge_source == 2) {	// Mixed
-			if (dataRecord.w2_ph > 0.0) {
-				Source_pH = parseFloat($("#wg_ph").jqxNumberInput('decimal'));
-				Source_alkalinity = parseFloat($("#wg_total_alkalinity").jqxNumberInput('decimal'));
-			} else {
-				dataRecord.sparge_source = 0;
-				$("#sparge_source").val(0);
-			}
-		}
-
-		//console.log("calcSparge() target pH: "+TargetpH+" Source: "+Source_pH+" alkalinity: "+Source_alkalinity);
-
-		// Step 1: Compute the mole fractions of carbonic (f1o), bicarbonate (f2o) and carbonate(f3o) at the water pH
-		var r1 = Math.pow(10, Source_pH - 6.38);
-		var r2 = Math.pow(10, Source_pH - 10.373);
-		var d = 1 + r1 + r1*r2;
-		var f1 = 1/d;
-		var f2 = r1/d;
-		var f3 = r1 * r2 / d;
-
-		//Step 2. Compute the mole fractions at pH = 4.3 (the pH which defines alkalinity)
-		var r143 = Math.pow(10, 4.3 - 6.38);
-		var r243 = Math.pow(10, 4.3 - 10.373);
-		var d43 = 1 + r143 + r143*r243;
-		var f143 = 1/d43;
-		var f243 = r143 / d43;
-		var f343 = r143 * r243 / d43;
-
-		//Step 3. Convert the sample alkalinity to milliequivalents/L
-		var alkalinity = Source_alkalinity / 50;
-		//Step 4. Solve
-		var Ct = (alkalinity - 1000 * (Math.pow(10, -4.3) - Math.pow(10, -Source_pH))) / ((f143-f1)+(f3-f343));
-
-		//Step 5. Compute mole fractions at desired pH
-		var r1g = Math.pow(10, TargetpH - 6.38);
-		var r2g = Math.pow(10, TargetpH - 10.373);
-		var dg = 1 + r1g + r1g*r2g;
-		var f1g = 1/dg;
-		var f2g = r1g / dg;
-		var f3g = r1g * r2g / dg;
-
-		//Step 6. Use these to compute the milliequivalents acid required per liter (mEq/L)
-		var Acid = Ct * ((f1g-f1)+(f3-f3g)) + Math.pow(10, -TargetpH) - Math.pow(10, -Source_pH);  //mEq/l
-                Acid += 0.01;   // Add acid that would be required for distilled water.
-		if (dataRecord.sparge_acid_type < 0 || dataRecord.sparge_acid_type > 3) {
-			dataRecord.sparge_acid_type = 0;
-			$("#sparge_acid_type").val(0);
-		}
-
-		//Step 8. Get the acid data.
-		var AT = dataRecord.sparge_acid_type;
-		var result = GetAcidSpecs(AT);
-		var pK1 = result.pK1;
-		var pK2 = result.pK2;
-		var pK3 = result.pK3;
-		var MolWt = result.MolWt;
-		var AcidSG = result.AcidSG;
-		var AcidPrc = result.AcidPrc;
-		var fract = CalcFrac(TargetpH, pK1, pK2, pK3);
-
-		//Step 9. Now divide the mEq required by the "fraction". This is the required number of moles of acid.
-		Acid /= fract;
-
-		//Step 10. Multiply by molecular weight of the acid
-		Acid *= MolWt; //mg
-
-		Acid = Acid / AcidSG; //ml ; 88% lactic solution
-		var f1 = dataRecord.sparge_acid_perc;
-		if (f1 <= 0.1)
-			f1 = AcidPrc;
-		Acid = Acid * AcidPrc / (f1 / 100);
-
-		Acid *= dataRecord.sparge_volume; //ml lactic acid total
-		Acid = Math.round(Acid * 100) / 100;
-		dataRecord.sparge_acid_amount = Acid / 1000;
-		$("#sparge_acid_amount").val(Acid);
-	}
+ // Inline miscs editor
+ var editMisc = function(data) {
+  var miscSource = {
+   localdata: data.miscs,
+   datatype: 'local',
+   cache: false,
+   async: false,
+   datafields: [
+    { name: 'm_name', type: 'string' },
+    { name: 'm_amount', type: 'float' },
+    { name: 'm_cost', type: 'float' },
+    { name: 'm_type', type: 'int' },
+    { name: 'm_use_use', type: 'int' },
+    { name: 'm_time', type: 'float' },
+    { name: 'm_amount_is_weight', type: 'int' },
+    { name: 'm_inventory', type: 'float' },
+    { name: 'm_avail', type: 'int' }
+   ],
+   addrow: function(rowid, rowdata, position, commit) {
+    //console.log("misc addrow "+rowid);
+    commit(true);
+   },
+   deleterow: function(rowid, commit) {
+    //console.log("misc deleterow "+rowid);
+    commit(true);
+   },
+   updaterow: function(rowid, rowdata, commit) {
+    //console.log("misc updaterow "+rowid);
+    commit(true);
+   }
+  },
+  miscAdapter = new $.jqx.dataAdapter(miscSource, {
+   beforeLoadComplete: function(records) {
+    var i, row, data = new Array();
+    for (i = 0; i < records.length; i++) {
+     row = records[i];
+     data.push(row);
+     // Initial set water agent values.
+     switch (row.m_name) {
+      case 'CaCl2':
+       $('#wa_cacl2').val(row.m_amount * 1000);
+       break;
+      case 'CaSO4':
+       $('#wa_caso4').val(row.m_amount * 1000);
+       break;
+      case 'MgSO4':
+       $('#wa_mgso4').val(row.m_amount * 1000);
+       break;
+      case 'NaCl':
+       $('#wa_nacl').val(row.m_amount * 1000);
+       break;
+      case 'Melkzuur':
+       $('#wa_acid_name').val(0);
+       $('#wa_acid').val(row.m_amount * 1000);
+       $('#wa_acid_perc').val(80);
+       last_acid = 'Melkzuur';
+       break;
+      case 'Zoutzuur':
+       $('#wa_acid_name').val(1);
+       $('#wa_acid').val(row.m_amount * 1000);
+       $('#wa_acid_perc').val(80);
+       last_acid = 'Zoutzuur';
+       break;
+      case 'Fosforzuur':
+       $('#wa_acid_name').val(2);
+       $('#wa_acid').val(row.m_amount * 1000);
+       $('#wa_acid_perc').val(80);
+       last_acid = 'Fosforzuur';
+       break;
+      case 'Zwavelzuur':
+       $('#wa_acid_name').val(3);
+       $('#wa_acid').val(row.m_amount * 1000);
+       $('#wa_acid_perc').val(80);
+       last_acid = 'Zwavelzuur';
+       break;
+      case 'NaHCO3':
+       $('#wa_base_name').val(0);
+       $('#wa_base').val(row.m_amount * 1000);
+       last_base = 'NaHCO3';
+       break;
+      case 'Na2CO3':
+       $('#wa_base_name').val(1);
+       $('#wa_base').val(row.m_amount * 1000);
+       last_base = 'Na2CO3';
+       break;
+      case 'CaCO3':
+       $('#wa_base_name').val(2);
+       $('#wa_base').val(row.m_amount * 1000);
+       last_base = 'CaCO3';
+       break;
+      case 'Ca(OH)2':
+       $('#wa_base_name').val(3);
+       $('#wa_base').val(row.m_amount * 1000);
+       last_base = 'Ca(OH)2';
+       break;
+     }
+    }
+    return data;
+   },
+   loadError: function(jqXHR, status, error) {}
+  });
+  $('#miscGrid').jqxGrid({
+   width: 1240,
+   height: 575,
+   source: miscAdapter,
+   theme: theme,
+   selectionmode: 'singlerow',
+   showtoolbar: true,
+   rendertoolbar: function(toolbar) {
+    //var me = this;
+    var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
+    toolbar.append(container);
+    container.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');
+    container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
+    container.append('<div style="float: left; margin-left: 10px;" id="minstockbutton"></div>');
+    container.append('<input style="float: left; margin-left: 400px;" id="mdeleterowbutton" type="button" value="Verwijder ingredi&euml;nt" />');
+    // add misc from dropdownlist.
+    $('#maddrowbutton').jqxDropDownList({
+     placeHolder: 'Kies ingredi&euml;nt:',
+     theme: theme,
+     template: 'primary',
+     source: misclist,
+     displayMember: 'name',
+     width: 150,
+     height: 27,
+     dropDownWidth: 500,
+     dropDownHeight: 500
+    });
+    $('#maddrowbutton').on('select', function(event) {
+     if (event.args) {
+      var datarecord, row = {}, index = event.args.index;
+      datarecord = misclist.records[index];
+      row['m_name'] = datarecord.name;
+      row['m_amount'] = 0;
+      row['m_cost'] = datarecord.cost;
+      row['m_type'] = datarecord.type;
+      row['m_use_use'] = datarecord.use_use;
+      row['m_time'] = 0;
+      row['m_amount_is_weight'] = datarecord.amount_is_weight;
+      row['m_inventory'] = datarecord.inventory;
+      $('#miscGrid').jqxGrid('addrow', null, row);
+     }
+    });
+    $('#minstockbutton').jqxCheckBox({ theme: theme, height: 27 });
+    $('#minstockbutton').on('change', function(event) {
+     miscinstock = event.args.checked;
+     misclist.dataBind();
+    });
+    // delete selected misc.
+    $('#mdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150 });
+    $('#mdeleterowbutton').on('click', function() {
+     var rowscount, type, id, selectedrowindex = $('#miscGrid').jqxGrid('getselectedrowindex');
+     rowscount = $('#miscGrid').jqxGrid('getdatainformation').rowscount;
+     type = $('#miscGrid').jqxGrid('getcellvalue', selectedrowindex, 'm_type');
+     if (selectedrowindex >= 0 && selectedrowindex < rowscount && type != 4) {       // Water agent
+      id = $('#miscGrid').jqxGrid('getrowid', selectedrowindex);
+      $('#miscGrid').jqxGrid('deleterow', id);
+     }
+    });
+   },
+   ready: function() {
+    $('#jqxTabs').jqxTabs('next');
+   },
+   columns: [
+    { text: 'Ingredient', datafield: 'm_name' },
+    { text: 'Type', width: 140, datafield: 'm_type',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 3px; margin-top: 6px; float: left;">' + MiscTypeData[value].nl + '</span>';
+     }
+    },
+    { text: 'Gebruik', width: 140, datafield: 'm_use_use',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 3px; margin-top: 6px; float: left;">' + MiscUseData[value].nl + '</span>';
+     }
+    },
+    { text: 'Tijd', datafield: 'm_time', width: 90, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var duration = '';
+      if (rowdata.m_use_use == 2)     // Boil
+       duration = dataAdapter.formatNumber(value, 'f0') + ' min.';
+      else if ((rowdata.m_use_use == 3) || (rowdata.m_use_use == 4))  // Primary or Secondary
+       duration = dataAdapter.formatNumber(value / 1440, 'f0') + ' dagen';
+      return '<span style="margin: 4px; margin-top: 6px; float: right;">' + duration + '</span>';
+     }
+    },
+    { text: 'Hoeveel', datafield: 'm_amount', width: 110, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var vstr = rowdata.m_amount_is_weight ? 'gr' : 'ml';
+      return '<span style="margin: 4px; margin-top: 6px; float: right;">' +
+             dataAdapter.formatNumber(value * 1000, 'f2') + ' ' + vstr + '</span>';
+     }
+    },
+    { text: 'Voorraad', datafield: 'm_inventory', width: 110, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var amount, color = '#ffffff', vstr = rowdata.m_amount_is_weight ? 'gr' : 'ml';
+      if (value < rowdata.m_amount)
+       color = '#ff4040';
+      amount = dataAdapter.formatNumber(value * 1000, 'f2') + ' ' + vstr;
+      return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
+     },
+    },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center',
+     cellsrenderer: function() {
+      return 'Wijzig';
+     }, buttonclick: function(row) {
+      miscRow = row;
+      miscData = $('#miscGrid').jqxGrid('getrowdata', miscRow);
+      if (miscData.m_type == 4) {
+       alert('Brouwzouten wijzigen in de water tab.');
+      } else {
+       if (miscData.m_amount_is_weight)
+        $('#wm_pmpt_amount').html('Gewicht gram:');
+       else
+        $('#wm_pmpt_amount').html('Volume ml:');
+       $('#wm_name').val(miscData.m_name);
+       $('#wm_amount').val(miscData.m_amount * 1000);
+       if ((miscData.m_use_use == 3) || (miscData.m_use_use == 4))     // Primary or Secondary
+        $('#wm_time').val(miscData.m_time / 1440);
+       else
+        $('#wm_time').val(miscData.m_time);
+       $('#wm_use_use').val(miscData.m_use_use);
+       // show the popup window.
+       $('#popupMisc').jqxWindow('open');
+      }
+     }
+    }
+   ]
+  });
+ };
 
-	/*
-	 * Change OG of recipe but keep the water volumes.
-	 */
-	function calcFermentablesFromOG(OG) {
-
-		console.log("calcFermentablesFromOG("+OG+")");
-		var efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal'));
-		var sug = sg_to_plato(OG) * parseFloat($("#batch_size").jqxNumberInput('decimal')) * OG / 100;	//total amount of sugars in kg
-		var tot = 0;
-		var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-
-		for (var i = 0; i < rowscount; i++) {
-			var row = $("#fermentableGrid").jqxGrid('getrowdata', i);
-			if (row.f_added < 4) {
-				var d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-				if (row.f_added == 0)	// Mash
-					d = efficiency / 100 * d;
-				tot += d;
-			}
-		}
-		var	totmass = 0;
-		if (tot)
-			totmass = Math.round((sug / tot) * 1000) / 1000;
-
-		if (totmass) {
-			for (i = 0; i < rowscount; i++) {
-				var row = $("#fermentableGrid").jqxGrid('getrowdata', i);
-				if (row.f_added < 4) {
-					var amount = Math.round(row.f_percentage * 10 * totmass) / 1000;
-					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount);
-				}
-			}
-		}
-	};
-
-	function calcInit () {
-		console.log("calc.init()");
-
-		$("#calc_acid").on('checked', function (event) {
-			dataRecord.calc_acid = 1;
-			calcWater();
-		});
-		$("#calc_acid").on('unchecked', function (event) {
-			dataRecord.calc_acid = 0;
-			calcWater();
-		});
-		$("#w1_name").jqxDropDownList('selectItem', dataRecord.w1_name);
-		$("#w2_name").jqxDropDownList('selectItem', dataRecord.w2_name);
-		// Fix tap water if zero using mash infuse amount.
-		if (parseFloat($("#w1_amount").jqxNumberInput('decimal')) == 0 && mash_infuse > 0) {
-			$("#w1_amount").val(mash_infuse);
-			dataRecord.w1_amount = mash_infuse;
-			$("#wg_amount").val(mash_infuse);
-			$("#w2_amount").val(0);
-			dataRecord.w2_amount = 0;
-		}
-		calcWater();
-		$("#w2_amount").on('change', function (event) {
-			var newval = parseFloat(event.args.value);
+ // Inline yeasts editor
+ var editYeast = function(data) {
+  var yeastSource = {
+   localdata: data.yeasts,
+   datatype: 'local',
+   cache: false,
+   async: false,
+   datafields: [
+    { name: 'y_name', type: 'string' },
+    { name: 'y_laboratory', type: 'string' },
+    { name: 'y_product_id', type: 'string' },
+    { name: 'y_amount', type: 'float' },
+    { name: 'y_cost', type: 'float' },
+    { name: 'y_type', type: 'int' },
+    { name: 'y_form', type: 'int' },
+    { name: 'y_flocculation', type: 'int' },
+    { name: 'y_min_temperature', type: 'float' },
+    { name: 'y_max_temperature', type: 'float' },
+    { name: 'y_attenuation', type: 'float' },
+    { name: 'y_use', type: 'int' },
+    { name: 'y_cells', type: 'float' },
+    { name: 'y_tolerance', type: 'float' },
+    { name: 'y_inventory', type: 'float' },
+    { name: 'y_avail', type: 'int' }
+   ],
+   addrow: function(rowid, rowdata, position, commit) {
+    //console.log("yeast addrow "+rowid);
+    commit(true);
+   },
+   deleterow: function(rowid, commit) {
+    //console.log("yeast deleterow "+rowid);
+    commit(true);
+   },
+   updaterow: function(rowid, rowdata, commit) {
+    //console.log("yeast updaterow "+rowid);
+    commit(true);
+   }
+  },
+  yeastAdapter = new $.jqx.dataAdapter(yeastSource);
 
-			if (newval > mash_infuse) {
-				$("#w2_amount").val(dataRecord.w2_amount);
-				return;
-			}
-			dataRecord.w1_amount = parseFloat($("#wg_amount").jqxNumberInput('decimal')) - newval;
-			$("#w1_amount").val(dataRecord.w1_amount);
-			dataRecord.w2_amount = newval;
-			console.log("new: "+event.args.value+" w1: "+dataRecord.w1_amount+"  w2: "+dataRecord.w2_amount);
-			calcWater();
-		});
-		$('#wa_cacl2').on('change', function (event) {
-			if (event.args) {
-				setWaterAgent('CaCl2', 0);	// This can prevent double entries.
-				setWaterAgent('CaCl2', event.args.value);
-				calcWater();
-			}
-		});
-		$('#wa_caso4').on('change', function (event) {
-			if (event.args) {
-				setWaterAgent('CaSO4', 0);
-				setWaterAgent('CaSO4', event.args.value);
-				calcWater();
-			}
-		});
-		$('#wa_mgso4').on('change', function (event) {
-			if (event.args) {
-				setWaterAgent('MgSO4', 0);
-				setWaterAgent('MgSO4', event.args.value);
-				calcWater();
-			}
-		});
-		$('#wa_nacl').on('change', function (event) {
-			if (event.args) {
-				setWaterAgent('NaCl', 0);
-				setWaterAgent('NaCl', event.args.value);
-				calcWater();
-			}
-		});
-		$('#wa_base_name').on('change', function (event) {
-			if (event.args) {
-				var index = event.args.index;
-				console.log("wa_base_name "+index);
-				setWaterAgent(last_base, 0);
-				last_base = BaseTypeData[index].nl;
-				setWaterAgent(last_base, parseFloat($("#wa_base").jqxNumberInput('decimal')));
-				dataRecord.wa_base_name = index;
-				calcWater();
-			}
-		});
-		$('#wa_base').on('change', function (event) {
-			var name = BaseTypeData[$("#wa_base_name").val()].nl;
-			setWaterAgent(name, parseFloat(event.args.value));
-			calcWater();
-		});
-		$('#wa_acid_name').on('change', function (event) {
-			if (event.args) {
-				var index = event.args.index;
-				console.log("wa_acid_name "+index);
-				setWaterAgent(last_acid, 0);
-				last_acid = AcidTypeData[index].nl;
-				setWaterAgent(last_acid, parseFloat($("#wa_acid").jqxNumberInput('decimal')));
-				dataRecord.wa_acid_name = index;
-				calcWater();
-			}
-		});
-		$('#wa_acid').on('change', function (event) {
-			var name = AcidTypeData[$("#wa_acid_name").val()].nl;
-			setWaterAgent(name, parseFloat(event.args.value));
-			calcWater();
-		});
-		$('#wa_acid_perc').on('change', function (event) { calcWater(); });
-
-		$('#color_method').on('change', function (event) {
-			dataRecord.color_method = event.args.index;
-			calcFermentables();
-		});
-		$('#ibu_method').on('change', function (event) {
-			dataRecord.ibu_method = event.args.index;
-			calcFermentables();
-			calcIBUs(); 
-		});
-		$('#batch_size').on('change', function (event) {
-			console.log("batch_size change:"+event.args.value+" old:"+dataRecord.batch_size);
-			var new_boil = parseFloat(event.args.value) + dataRecord.boil_size - dataRecord.batch_size;
-			var factor = parseFloat(event.args.value) / dataRecord.batch_size;
-			dataRecord.boil_size = new_boil;
-			$("#boil_size").val(Math.round(new_boil * 100) / 100);
-			dataRecord.sparge_volume *= factor;
-			$("#sparge_volume").val(dataRecord.sparge_volume);
-			dataRecord.batch_size = parseFloat(event.args.value);
-			calcFermentablesFromOG(parseFloat($("#est_og").jqxNumberInput('decimal')));     // Keep the OG
-			adjustWaters(factor);
-			calcFermentables();
-			adjustHops(factor);
-			adjustMiscs(factor);
-			adjustYeasts(factor);
-			calcIBUs();
-			calcWater();
-			calcSparge();
-			calcMash();
-		});
-		$('#boil_time').on('change', function (event) {
-			console.log("boil_time change:"+parseFloat(event.args.value)+" old:"+dataRecord.boil_time);
-			var old_evap = parseFloat(dataRecord.boil_size) - parseFloat(dataRecord.batch_size);
-			var new_evap = old_evap * (parseFloat(event.args.value) / dataRecord.boil_time);
-			var new_boil = parseFloat(dataRecord.batch_size) + new_evap;
-	//		console.log("old_evap:"+old_evap+" new_evap:"+new_evap+" new_boil:"+new_boil);
-			dataRecord.boil_time = parseFloat(event.args.value);
-			dataRecord.boil_size = new_boil;
-			$("#boil_size").val(Math.round(new_boil * 100) / 100);
-			calcFermentables();
-			// TODO: adjust the hops, miscs, yeast, water.
-			calcIBUs();
-		});
-		$('#efficiency').on('change', function (event) {
-			var estog = parseFloat($("#est_og").jqxNumberInput('decimal'));
-			dataRecord.efficiency = parseFloat(event.args.value);
-			console.log("efficiency change:"+dataRecord.efficiency);
-			calcFermentablesFromOG(estog);     // Keep the OG
-			calcFermentables();
-			calcIBUs();
-		});
-		$('#est_og').on('change', function (event) {
-			dataRecord.est_og = parseFloat(event.args.value);
-			console.log("est_og change:"+dataRecord.est_og);
-			calcFermentablesFromOG(dataRecord.est_og);      // Adjust fermentables amounts
-			calcFermentables();                             // Update the recipe details
-			calcIBUs();                                     // and the IBU's.
-			calcMash();
-		});
-		$('#mash_ph').on('change', function (event) {
-			dataRecord.mash_ph = parseFloat(event.args.value);
-			calcWater();
-		});
-
-		$('#sparge_ph').on('change', function (event) {
-			dataRecord.sparge_ph = parseFloat(event.args.value);
-			calcSparge();
-		});
-		$('#sparge_volume').on('change', function (event) {
-			dataRecord.sparge_volume = parseFloat(event.args.value);
-			calcSparge();
-		});
-		$('#sparge_source').on('change', function (event) {
-			if (event.args) {
-				var index = event.args.index;
-				dataRecord.sparge_source= index;
-				calcSparge();
-			}
-		});
-		$('#sparge_acid_type').on('change', function (event) {
-			if (event.args) {
-				var index = event.args.index;
-				dataRecord.sparge_acid_type = index;
-				console.log("new sparge_acid_type: "+dataRecord.sparge_acid_type);
-				calcSparge();
-			}
-		});
-		$('#sparge_acid_perc').on('change', function (event) {
-			dataRecord.sparge_acid_perc = parseFloat(event.args.value);
-			calcSparge();
-		});
-		$('#locked').on('checked', function (event) {
-			dataRecord.locked = 1;
-			setReadonly(true);
-		});
-		$('#locked').on('unchecked', function (event) {
-			dataRecord.locked = 0;
-			setReadonly(false);
-		});
-//		setReadonly(false);
-	};
+  $('#yeastGrid').jqxGrid({
+   width: 1240,
+   height: 350,
+   source: yeastAdapter,
+   theme: theme,
+   selectionmode: 'singlerow',
+   showtoolbar: true,
+   rendertoolbar: function(toolbar) {
+    var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
+    toolbar.append(container);
+    container.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');
+    container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
+    container.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');
+    container.append('<input style="float: left; margin-left: 400px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');
+    // add yeast from dropdownlist.
+    $('#yaddrowbutton').jqxDropDownList({
+     placeHolder: 'Kies gist:',
+     theme: theme,
+     source: yeastlist,
+     template: 'primary',
+     displayMember: 'name',
+     width: 150,
+     height: 27,
+     dropDownWidth: 500,
+     dropDownHeight: 500,
+     renderer: function(index, label, value) {
+      var datarecord = yeastlist.records[index];
+      return datarecord.laboratory + ' ' + datarecord.product_id + ' ' + datarecord.name;
+     }
+    });
+    $('#yaddrowbutton').on('select', function(event) {
+     if (event.args) {
+      var datarecord, row = {}, index = event.args.index;
+      datarecord = yeastlist.records[index];
+      row['y_name'] = datarecord.name;
+      row['y_laboratory'] = datarecord.laboratory;
+      row['y_product_id'] = datarecord.product_id;
+      row['y_type'] = datarecord.type;
+      row['y_form'] = datarecord.form;
+      row['y_amount'] = 0;
+      row['y_cost'] = datarecord.cost;
+      row['y_use'] = 0;
+      row['y_min_temperature'] = datarecord.min_temperature;
+      row['y_max_temperature'] = datarecord.max_temperature;
+      row['y_attenuation'] = datarecord.attenuation;
+      row['y_flocculation'] = datarecord.flocculation;
+      row['y_cells'] = datarecord.cells;
+      row['y_tolerance'] = datarecord.tolerance;
+      row['y_inventory'] = datarecord.inventory;
+      $('#yeastGrid').jqxGrid('addrow', null, row);
+     }
+     $('#yaddrowbutton').jqxDropDownList('clearSelection');
+    });
+    $('#yinstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
+    $('#yinstockbutton').on('change', function(event) {
+     yeastinstock = event.args.checked;
+     yeastlist.dataBind();
+    });
+    // delete selected yeast.
+    $('#ydeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#ydeleterowbutton').on('click', function() {
+     var id, rowscount, selectedrowindex = $('#yeastGrid').jqxGrid('getselectedrowindex');
+     rowscount = $('#yeastGrid').jqxGrid('getdatainformation').rowscount;
+     if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+      id = $('#yeastGrid').jqxGrid('getrowid', selectedrowindex);
+      $('#yeastGrid').jqxGrid('deleterow', id);
+     }
+    });
+   },
+   ready: function() {
+    calcFermentables();
+    $('#jqxTabs').jqxTabs('next');
+   },
+   columns: [
+    { text: 'Gist', datafield: 'y_name' },
+    { text: 'Laboratorium', width: 150, datafield: 'y_laboratory' },
+    { text: 'Code', width: 90, datafield: 'y_product_id' },
+    { text: 'Soort', width: 100, datafield: 'y_form',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 4px; margin-top: 6px; float: left;">' + YeastFormData[value].nl + '</span>';
+     }
+    },
+    { text: 'Min. &deg;C', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_min_temperature' },
+    { text: 'Max. &deg;C', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_max_temperature' },
+    { text: 'Tol. %', width: 60, align: 'right', cellsalign: 'right', datafield: 'y_tolerance',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var amount = '', color = '#ffffff';
+      if (value > 0) {
+       amount = dataAdapter.formatNumber(value, 'f1');
+       if (dataRecord.est_abv > value)
+        color = '#ff4040';
+      }
+      return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
+     }
+    },
+    { text: 'Attn. %', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_attenuation', cellsformat: 'f1' },
+    { text: 'Voor', width: 120, datafield: 'y_use',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<span style="margin: 4px; margin-top: 6px; float: left;">' + YeastUseData[value].nl + '</span>';
+     }
+    },
+    { text: 'Hoeveel', datafield: 'y_amount', width: 90, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var amount = dataAdapter.formatNumber(value * 1000, 'f0') + ' ml';
+      if (rowdata.y_form == 0)        // Liquid
+       amount = dataAdapter.formatNumber(value, 'f0') + ' pk';
+      else if (rowdata.y_form == 1)   // Dry
+       amount = dataAdapter.formatNumber(value * 1000, 'f1') + ' gr';
+      return '<span style="margin: 4px; margin-top: 6px; float: right;">' + amount + '</span>';
+     }
+    },
+    { text: 'Voorraad', datafield: 'y_inventory', width: 90, align: 'right',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      var color, amount;
+      color = '#ffffff';
+      if (value < rowdata.y_amount)
+       color = '#ff4040';
+      amount = dataAdapter.formatNumber(value * 1000, 'f0') + ' ml';
+      if (rowdata.y_form == 0)        // Liquid
+       amount = dataAdapter.formatNumber(value, 'f0') + ' pk';
+      else if (rowdata.y_form == 1)   // Dry
+       amount = dataAdapter.formatNumber(value * 1000, 'f1') + ' gr';
+      return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
+     }
+    },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 90, align: 'center',
+     cellsrenderer: function() {
+      return 'Wijzig';
+     }, buttonclick: function(row) {
+      yeastRow = row;
+      yeastData = $('#yeastGrid').jqxGrid('getrowdata', yeastRow);
+      if (yeastData.y_form == 0) {
+       $('#wy_pmpt_amount').html('Pak(ken):');
+       $('#wy_amount').val(yeastData.y_amount);
+       $('#wy_amount').jqxNumberInput({ decimalDigits: 0 });
+      } else if (yeastData.y_form == 1) {
+       $('#wy_pmpt_amount').html('Gewicht gram:');
+       $('#wy_amount').val(yeastData.y_amount * 1000);
+       $('#wy_amount').jqxNumberInput({ decimalDigits: 1 });
+      } else {
+       $('#wy_pmpt_amount').html('Volume ml:');
+       $('#wy_amount').val(yeastData.y_amount * 1000);
+       $('#wy_amount').jqxNumberInput({ decimalDigits: 0 });
+      }
+      $('#wy_name').val(yeastData.y_name);
+      $('#wy_laboratory').val(yeastData.y_laboratory);
+      $('#wy_product_id').val(yeastData.y_product_id);
+      $('#wy_use').val(yeastData.y_use);
+      // show the popup window.
+      $('#popupYeast').jqxWindow('open');
+     }
+    }
+   ]
+  });
+ };
 
-	$("#styleSelect").jqxDropDownList({
-		placeHolder: "Kies bierstijl:",
-		theme: theme,
-		source: styleslist,
-		displayMember: "name",
-		width: 180,
-		height: 23,
-		dropDownVerticalAlignment: 'top',
-		dropDownWidth: 500,
-		dropDownHeight: 380,
-		renderer: function (index, label, value) {
-			var datarecord = styleslist.records[index];
-			return datarecord.style_guide + " " + datarecord.style_letter+ " " + datarecord.name;
-		}
-	});
-	$("#styleSelect").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			var datarecord = styleslist.records[index];
-			$("#st_name").val(datarecord.name);
-			$("#st_category").val(datarecord.category);
-			$("#st_category_number").val(datarecord.category_number);
-			$("#st_letter").val(datarecord.style_letter);
-			$("#st_guide").val(datarecord.style_guide);
-			$("#st_type").val(StyleTypeData[datarecord.type].nl);
-			$("#st_og_min").val(datarecord.og_min);
-			$("#st_og_max").val(datarecord.og_max);
-			$("#st_fg_min").val(datarecord.fg_min);
-			$("#st_fg_max").val(datarecord.fg_max);
-			$("#st_ibu_min").val(datarecord.ibu_min);
-			$("#st_ibu_max").val(datarecord.ibu_max);
-			$("#st_color_min").val(datarecord.color_min);
-			$("#st_color_max").val(datarecord.color_max);
-			$("#st_carb_min").val(datarecord.carb_min);
-			$("#st_carb_max").val(datarecord.carb_max);
-			$("#st_abv_min").val(datarecord.abv_min);
-			$("#st_abv_max").val(datarecord.abv_max);
-		}
-	});
+ // inline mash editor
+ var editMash = function(data) {
+  var generaterow = function() {
+   var row = {};
+   row['step_name'] = 'Stap 1';
+   row['step_type'] = 0;
+   row['step_infuse_amount'] = 15;
+   row['step_temp'] = 62.0;
+   row['step_time'] = 20.0;
+   row['step_thickness'] = 0;
+   row['ramp_time'] = 1.0;
+   row['end_temp'] = 62.0;
+   return row;
+  };
+  var mashSource = {
+   localdata: data.mashs,
+   datatype: 'local',
+   cache: false,
+   async: false,
+   datafields: [
+    { name: 'step_name', type: 'string' },
+    { name: 'step_type', type: 'int' },
+    { name: 'step_infuse_amount', type: 'float' },
+    { name: 'step_temp', type: 'float' },
+    { name: 'step_time', type: 'float' },
+    { name: 'step_thickness', type: 'float' },
+    { name: 'ramp_time', type: 'float' },
+    { name: 'end_temp', type: 'float' }
+   ],
+   addrow: function(rowid, rowdata, position, commit) {
+    commit(true);
+   },
+   deleterow: function(rowid, commit) {
+    commit(true);
+   }
+  },
+  mashAdapter = new $.jqx.dataAdapter(mashSource, {
+   beforeLoadComplete: function(records) {
+    mash_infuse = 0;
+    var row, i, data = new Array();
+    for (i = 0; i < records.length; i++) {
+     row = records[i];
+     if (row.step_type == 0) // Infusion
+      mash_infuse += parseFloat(row.step_infuse_amount);
+     row.step_thickness = 0; // Init this field.
+     data.push(row);
+    }
+   },
+  });
+  $('#mashGrid').jqxGrid({
+   width: 1240,
+   height: 400,
+   source: mashAdapter,
+   theme: theme,
+   selectionmode: 'singlerow',
+   showtoolbar: true,
+   rendertoolbar: function(toolbar) {
+    //var me = this;
+    var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
+    toolbar.append(container);
+    container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');
+    container.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder stap" />');
+    $('#saddrowbutton').jqxButton({ template: 'primary', theme: theme, height: 27, width: 150 });
+    $('#saddrowbutton').on('click', function() {
+     var datarow = generaterow();
+     $('#mashGrid').jqxGrid('addrow', null, datarow);
+    });
+    // delete selected yeast.
+    $('#sdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150 });
+    $('#sdeleterowbutton').on('click', function() {
+     var id, rowscount, selectedrowindex = $('#mashGrid').jqxGrid('getselectedrowindex');
+     rowscount = $('#mashGrid').jqxGrid('getdatainformation').rowscount;
+     if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+      id = $('#mashGrid').jqxGrid('getrowid', selectedrowindex);
+      $('#mashGrid').jqxGrid('deleterow', id);
+     }
+    });
+   },
+   ready: function() {
+    calcFermentables();
+    calcInit();
+    calcMash();
+    $('#jqxLoader').jqxLoader('close');
+    $('#jqxTabs').jqxTabs('first');
+   },
+   columns: [
+    { text: 'Stap naam', datafield: 'step_name' },
+    { text: 'Stap type', datafield: 'step_type', width: 175,
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      return '<div style="margin: 4px;">' + MashStepTypeData[value].nl + '</div>';
+     }
+    },
+    { text: 'Start &deg;C', datafield: 'step_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
+    { text: 'Eind &deg;C', datafield: 'end_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
+    { text: 'Rust min.', datafield: 'step_time', width: 90, align: 'right', cellsalign: 'right' },
+    { text: 'Stap min.', datafield: 'ramp_time', width: 90, align: 'right', cellsalign: 'right' },
+    { text: 'Infuse L.', datafield: 'step_infuse_amount', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
+    { text: 'L/Kg.', datafield: 'step_thickness', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f2' },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center',
+     cellsrenderer: function() {
+      return 'Wijzig';
+     }, buttonclick: function(row) {
+      mashRow = row;
+      mashData = $('#mashGrid').jqxGrid('getrowdata', mashRow);
+      $('#wstep_name').val(mashData.step_name);
+      $('#wstep_type').val(mashData.step_type);
+      $('#wstep_infuse_amount').val(mashData.step_infuse_amount);
+      $('#wstep_temp').val(mashData.step_temp);
+      $('#wend_temp').val(mashData.end_temp);
+      $('#wstep_time').val(mashData.step_time);
+      $('#wramp_time').val(mashData.ramp_time);
+      if (mashData.step_type == 0) {
+       $('#wstep_infuse_amount').show();
+       $('#wstep_pmpt').show();
+      } else {
+       $('#wstep_infuse_amount').hide();
+       $('#wstep_pmpt').hide();
+      }
+      // show the popup window.
+      $('#popupMash').jqxWindow('open');
+     }
+    }
+   ]
+  });
+ };
+
+
+
+
+ /*
+  * Remove the top menu so that we MUST use the buttons to leave the editor.
+  */
+ $('#jqxMenu').jqxMenu('destroy');
+
+ console.log('record:' + my_record + '  return:' + my_return + '  theme:' + theme);
+ $('#jqxLoader').jqxLoader({
+  width: 250,
+  height: 150,
+  isModal: true,
+  text: 'Laden recept ...',
+  theme: theme
+ });
+
+
+ function setWaterAgent(name, amount) {
 
-	function saveRecord() {
-		var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
-		var hoprow = $('#hopGrid').jqxGrid('getrows');
-		var miscrow = $('#miscGrid').jqxGrid('getrows');
-		var yeastrow = $('#yeastGrid').jqxGrid('getrows');
-		var mashrow = $('#mashGrid').jqxGrid('getrows');
-		var row = {
-			record: my_record,
-			uuid: dataRecord.uuid,
-			name: $("#name").val(),
-			locked: dataRecord.locked,
-			notes: $("#notes").val(),
-			st_name: $('#st_name').val(),
-			st_letter: $('#st_letter').val(),
-			st_guide: $('#st_guide').val(),
-			st_type: dataRecord.st_type,
-			st_category: $('#st_category').val(),
-			st_category_number: parseFloat($("#st_category_number").jqxNumberInput('decimal')),
-			st_og_min: parseFloat($("#st_og_min").jqxNumberInput('decimal')),
-			st_og_max: parseFloat($("#st_og_max").jqxNumberInput('decimal')),
-			st_fg_min: parseFloat($("#st_fg_min").jqxNumberInput('decimal')),
-			st_fg_max: parseFloat($("#st_fg_max").jqxNumberInput('decimal')),
-			st_ibu_min: parseFloat($("#st_ibu_min").jqxNumberInput('decimal')),
-			st_ibu_max: parseFloat($("#st_ibu_max").jqxNumberInput('decimal')),
-			st_color_min: parseFloat($("#st_color_min").jqxNumberInput('decimal')),
-			st_color_max: parseFloat($("#st_color_max").jqxNumberInput('decimal')),
-			st_carb_min: parseFloat($("#st_carb_min").jqxNumberInput('decimal')),
-			st_carb_max: parseFloat($("#st_carb_max").jqxNumberInput('decimal')),
-			st_abv_min: parseFloat($("#st_abv_min").jqxNumberInput('decimal')),
-			st_abv_max: parseFloat($("#st_abv_max").jqxNumberInput('decimal')),
-			type: $("#type").val(),
-			batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')),
-			boil_size: parseFloat($("#boil_size").jqxNumberInput('decimal')),
-			boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')),
-			efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')),
-			est_og: parseFloat($("#est_og").jqxNumberInput('decimal')),
-			est_fg: parseFloat($("#est_fg").jqxNumberInput('decimal')),
-			est_abv: parseFloat($("#est_abv").jqxNumberInput('decimal')),
-			est_color: parseFloat($("#est_color").jqxNumberInput('decimal')),
-			color_method: $("#color_method").val(),
-			est_ibu: parseFloat($("#est_ibu").jqxNumberInput('decimal')),
-			ibu_method: $("#ibu_method").val(),
-			est_carb: parseFloat($("#est_carb").jqxNumberInput('decimal')),
-			mash_name: $("#mash_name").val(),
-			mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
-			sparge_temp: parseFloat($("#sparge_temp").jqxNumberInput('decimal')),
-			sparge_ph: parseFloat($("#sparge_ph").jqxNumberInput('decimal')),
-			sparge_volume: parseFloat($("#sparge_volume").jqxNumberInput('decimal')),
-			sparge_source: $("#sparge_source").val(),
-			sparge_acid_type: $("#sparge_acid_type").val(),
-			sparge_acid_perc: parseFloat($("#sparge_acid_perc").jqxNumberInput('decimal')),
-			sparge_acid_amount: dataRecord.sparge_acid_amount,
-			calc_acid: dataRecord.calc_acid,
-			w1_name: $("#w1_name").val(),
-			w1_amount: parseFloat($("#w1_amount").jqxNumberInput('decimal')),
-			w1_calcium: parseFloat($("#w1_calcium").jqxNumberInput('decimal')),
-			w1_sulfate: parseFloat($("#w1_sulfate").jqxNumberInput('decimal')),
-			w1_chloride: parseFloat($("#w1_chloride").jqxNumberInput('decimal')),
-			w1_sodium: parseFloat($("#w1_sodium").jqxNumberInput('decimal')),
-			w1_magnesium: parseFloat($("#w1_magnesium").jqxNumberInput('decimal')),
-			w1_total_alkalinity: parseFloat($("#w1_total_alkalinity").jqxNumberInput('decimal')),
-			w1_ph: parseFloat($("#w1_ph").jqxNumberInput('decimal')),
-			w1_cost: dataRecord.w1_cost,
-			w2_name: $("#w2_name").val(),
-			w2_amount: parseFloat($("#w2_amount").jqxNumberInput('decimal')),
-			w2_calcium: parseFloat($("#w2_calcium").jqxNumberInput('decimal')),
-			w2_sulfate: parseFloat($("#w2_sulfate").jqxNumberInput('decimal')),
-			w2_chloride: parseFloat($("#w2_chloride").jqxNumberInput('decimal')),
-			w2_sodium: parseFloat($("#w2_sodium").jqxNumberInput('decimal')),
-			w2_magnesium: parseFloat($("#w2_magnesium").jqxNumberInput('decimal')),
-			w2_total_alkalinity: parseFloat($("#w2_total_alkalinity").jqxNumberInput('decimal')),
-			w2_ph: parseFloat($("#w2_ph").jqxNumberInput('decimal')),
-			w2_cost: dataRecord.w2_cost,
-			wg_amount: parseFloat($("#wg_amount").jqxNumberInput('decimal')),
-			wg_calcium: parseFloat($("#wg_calcium").jqxNumberInput('decimal')),
-			wg_sulfate: parseFloat($("#wg_sulfate").jqxNumberInput('decimal')),
-			wg_chloride: parseFloat($("#wg_chloride").jqxNumberInput('decimal')),
-			wg_sodium: parseFloat($("#wg_sodium").jqxNumberInput('decimal')),
-			wg_magnesium: parseFloat($("#wg_magnesium").jqxNumberInput('decimal')),
-			wg_total_alkalinity: parseFloat($("#wg_total_alkalinity").jqxNumberInput('decimal')),
-			wg_ph: parseFloat($("#wg_ph").jqxNumberInput('decimal')),
-			wb_calcium: parseFloat($("#wb_calcium").jqxNumberInput('decimal')),
-			wb_sulfate: parseFloat($("#wb_sulfate").jqxNumberInput('decimal')),
-			wb_chloride: parseFloat($("#wb_chloride").jqxNumberInput('decimal')),
-			wb_sodium: parseFloat($("#wb_sodium").jqxNumberInput('decimal')),
-			wb_magnesium: parseFloat($("#wb_magnesium").jqxNumberInput('decimal')),
-			wb_total_alkalinity: parseFloat($("#wb_total_alkalinity").jqxNumberInput('decimal')),
-			wb_ph: parseFloat($("#wb_ph").jqxNumberInput('decimal')),
-			wa_acid_name: $("#wa_acid_name").val(),
-			wa_acid_perc: parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')),
-			wa_base_name: $("#wa_base_name").val(),
-			fermentables: fermentablerow,
-			hops: hoprow,
-			miscs: miscrow,
-			yeasts: yeastrow,
-			mashs: mashrow
-		};
-		var data = "update=true&" + $.param(row);
-		$.ajax({
-			dataType: 'json',
-			url: url,
-			cache: false,
-			async: false,
-			data: data,
-			type: "POST",
-			success: function (data, status, xhr) {
-				console.log("saveRecord() success");
-			},
-			error: function(jqXHR, textStatus, errorThrown) {
-				console.log("saveRecord() error");
-			}
-		});
-	};
+  var record, records, miscs, i, id, row, found = false, rows = $('#miscGrid').jqxGrid('getrows');
+  if (amount == 0) {
+   for (i = 0; i < rows.length; i++) {
+    row = rows[i];
+    if (row.m_name == name) {
+     id = $('#miscGrid').jqxGrid('getrowid', i);
+     $('#miscGrid').jqxGrid('deleterow', id);
+    }
+   }
+  } else {
+   for (i = 0; i < rows.length; i++) {
+    row = rows[i];
+    if (row.m_name == name) {
+     found = true;
+     $('#miscGrid').jqxGrid('setcellvalue', i, 'm_amount', amount / 1000);
+     break;
+    }
+   }
+   if (! found) {
+    miscs = new $.jqx.dataAdapter(miscInvSource, {
+     loadComplete: function() {
+      records = miscs.records;
+      for (i = 0; i < records.length; i++) {
+       record = records[i];
+       if (record.name == name) {
+        row = {};
+        row['m_name'] = record.name;
+        row['m_amount'] = amount / 1000;
+        row['m_cost'] = record.cost;
+        row['m_type'] = record.type;
+        row['m_use_use'] = record.use_use;
+        row['m_time'] = 0;
+        row['m_amount_is_weight'] = record.amount_is_weight;
+        row['m_inventory'] = record.inventory;
+        row['m_avail'] = 1;
+        $('#miscGrid').jqxGrid('addrow', null, row);
+       }
+      }
+     }
+    });
+    miscs.dataBind();
+    return;
+   }
+  }
+ }
+
+
+ // Procedure TFrmWaterAdjustment.CalcWater2;
+ function calcWater() {
+
+  console.log('calcWater()');
+  var liters = 0,
+  calcium = 0,
+  magnesium = 0,
+  sodium = 0,
+  total_alkalinity = 0,
+  bicarbonate = 0,
+  chloride = 0,
+  sulfate = 0,
+  ph = 0,
+  RA = 0,
+  frac = 0,
+  TpH = 0,
+  protonDeficit = 0,
+  AT, BT, result, pK1, pK2, pK3, MolWt, AcidSG, AcidPrc,
+  r1d, r2d, f1d, f2d, f3d,
+  deltapH, deltapd, pd, n,
+  piCLSO4_low, piCLSO4_high, Res,
+  wg_calcium, wg_sodium, wg_total_alkalinity, wg_chloride, wg_sulfate, wg_bicarbonate;
+
+  if (dataRecord.w1_name == '') {
+   return;
+  }
 
-	var dataRecord = {};
-	var url = "includes/db_recipes.php";
+  // If there is a dillute water source, mix the waters.
+  if (dataRecord.w2_name != '') {
+   liters = dataRecord.w1_amount + dataRecord.w2_amount;
+   calcium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_calcium, dataRecord.w2_calcium);
+   magnesium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_magnesium, dataRecord.w2_magnesium);
+   sodium = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sodium, dataRecord.w2_sodium);
+   chloride = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_chloride, dataRecord.w2_chloride);
+   sulfate = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_sulfate, dataRecord.w2_sulfate);
+   total_alkalinity = mix(dataRecord.w1_amount, dataRecord.w2_amount, dataRecord.w1_total_alkalinity, dataRecord.w2_total_alkalinity);
+   ph = -Math.log10(((Math.pow(10, -dataRecord.w1_ph) * dataRecord.w1_amount) + (Math.pow(10, -dataRecord.w2_ph) * dataRecord.w2_amount)) / liters);
+  } else {
+   liters = dataRecord.w1_amount;
+   calcium = dataRecord.w1_calcium;
+   magnesium = dataRecord.w1_magnesium;
+   sodium = dataRecord.w1_sodium;
+   chloride = dataRecord.w1_chloride;
+   sulfate = dataRecord.w1_sulfate;
+   total_alkalinity = dataRecord.w1_total_alkalinity;
+   ph = dataRecord.w1_ph;
+  }
+  $('#wg_amount').val(liters);
+  wg_calcium = calcium;
+  $('#wg_calcium').val(Math.round(calcium * 10) / 10);
+  //wg_magnesium = magnesium;
+  $('#wg_magnesium').val(Math.round(magnesium * 10) / 10);
+  wg_sodium = sodium;
+  $('#wg_sodium').val(Math.round(sodium * 10) / 10);
+  wg_total_alkalinity = total_alkalinity;
+  $('#wg_total_alkalinity').val(Math.round(total_alkalinity * 10) / 10);
+  wg_chloride = chloride;
+  $('#wg_chloride').val(Math.round(chloride * 10) / 10);
+  wg_sulfate = sulfate;
+  $('#wg_sulfate').val(Math.round(sulfate * 10) / 10);
+  // Note: brouwhulp has the malts included here in the result.
+  //wg_ph = ph;
+  $('#wg_ph').val(Round(ph, 1));
+  $('#wb_ph').val(Round(MashpH(), 1));
+  bicarbonate = total_alkalinity * 1.22;
+  wg_bicarbonate = bicarbonate;
+
+  // Noot: de volgende berekeningen geven bijna gelijke resultaten in Brun'water.
+  // Calculate Ca
+  RA = parseFloat($('#wa_cacl2').jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
+       parseFloat($('#wa_caso4').jqxNumberInput('decimal')) * MMCa / MMCaSO4;
+  calcium += 1000 * RA / liters;
+
+  // Calculate Mg
+  RA = parseFloat($('#wa_mgso4').jqxNumberInput('decimal')) * MMMg / MMMgSO4;
+  magnesium += 1000 * RA / liters;
+
+  // Calculate Na
+  RA = parseFloat($('#wa_nacl').jqxNumberInput('decimal')) * MMNa / MMNaCl;
+  sodium += 1000 * RA / liters;
+
+  // Calculate SO4
+  RA = parseFloat($('#wa_caso4').jqxNumberInput('decimal')) * MMSO4 / MMCaSO4 +
+       parseFloat($('#wa_mgso4').jqxNumberInput('decimal')) * MMSO4 / MMMgSO4;
+  sulfate += 1000 * RA / liters;
+
+  // Calculate Cl
+  RA = 2 * parseFloat($('#wa_cacl2').jqxNumberInput('decimal')) * MMCl / MMCaCl2 +
+           parseFloat($('#wa_nacl').jqxNumberInput('decimal')) * MMCl / MMNaCl;
+  chloride += 1000 * RA / liters;
+  // Einde noot.
+
+  if ($('#wa_acid_name').val() < 0 || $('#wa_acid_name').val() > 3) {
+   $('#wa_acid_name').val(0);
+   dataRecord.wa_acid_name = 0;
+  }
+  if (last_acid == '')
+   last_acid = AcidTypeData[$('#wa_acid_name').val()].nl;
+
+  if ($('#wa_base_name').val() < 0 || $('#wa_base_name').val() > 3) {
+   $('#wa_base_name').val(0);
+   dataRecord.wa_base_name = 0;
+  }
+  if (last_base == '')
+   last_base = BaseTypeData[$('#wa_base_name').val()].nl;
+
+  AT = dataRecord.wa_acid_name;
+  BT = dataRecord.wa_base_name;
 
-	// prepare the data
-	var source = {
-		datatype: "json",
-		cache: false,
-		datafields: [
-			{ name: 'record', type: 'number' },
-			{ name: 'uuid', type: 'string' },
-			{ name: 'locked', type: 'int' },
-			{ name: 'st_name', type: 'string' },
-			{ name: 'st_letter', type: 'string' },
-			{ name: 'st_guide', type: 'string' },
-			{ name: 'st_type', type: 'int' },
-			{ name: 'st_category', type: 'string' },
-			{ name: 'st_category_number', type: 'float' },
-			{ name: 'st_og_min', type: 'float' },
-			{ name: 'st_og_max', type: 'float' },
-			{ name: 'st_fg_min', type: 'float' },
-			{ name: 'st_fg_max', type: 'float' },
-			{ name: 'st_ibu_min', type: 'float' },
-			{ name: 'st_ibu_max', type: 'float' },
-			{ name: 'st_color_min', type: 'float' },
-			{ name: 'st_color_max', type: 'float' },
-			{ name: 'st_carb_min', type: 'float' },
-			{ name: 'st_carb_max', type: 'float' },
-			{ name: 'st_abv_min', type: 'float' },
-			{ name: 'st_abv_max', type: 'float' },
-			{ name: 'name', type: 'string' },
-			{ name: 'notes', type: 'string' },
-			{ name: 'type', type: 'int' },
-			{ name: 'batch_size', type: 'float' },
-			{ name: 'boil_size', type: 'float' },
-			{ name: 'boil_time', type: 'float' },
-			{ name: 'efficiency', type: 'float' },
-			{ name: 'est_og', type: 'float' },
-			{ name: 'est_fg', type: 'float' },
-			{ name: 'est_abv', type: 'float' },
-			{ name: 'est_color', type: 'float' },
-			{ name: 'color_method', type: 'int' },
-			{ name: 'est_ibu', type: 'float' },
-			{ name: 'ibu_method', type: 'int' },
-			{ name: 'est_carb', type: 'float' },
-			{ name: 'sparge_temp', type: 'float' },
-			{ name: 'sparge_ph', type: 'float' },
-			{ name: 'sparge_volume', type: 'float' },
-			{ name: 'sparge_source', type: 'int' },
-			{ name: 'sparge_acid_type', type: 'int' },
-			{ name: 'sparge_acid_perc', type: 'float' },
-			{ name: 'sparge_acid_amount', type: 'float' },
-			{ name: 'mash_ph', type: 'float' },
-			{ name: 'mash_name', type: 'string' },
-			{ name: 'calc_acid', type: 'int' },
-			{ name: 'w1_name', type: 'string' },
-			{ name: 'w1_amount', type: 'float' },
-			{ name: 'w1_calcium', type: 'float' },
-			{ name: 'w1_sulfate', type: 'float' },
-			{ name: 'w1_chloride', type: 'float' },
-			{ name: 'w1_sodium', type: 'float' },
-			{ name: 'w1_magnesium', type: 'float' },
-			{ name: 'w1_total_alkalinity', type: 'float' },
-			{ name: 'w1_ph', type: 'float' },
-			{ name: 'w1_cost', type: 'float' },
-			{ name: 'w2_name', type: 'string' },
-			{ name: 'w2_amount', type: 'float' },
-			{ name: 'w2_calcium', type: 'float' },
-			{ name: 'w2_sulfate', type: 'float' },
-			{ name: 'w2_chloride', type: 'float' },
-			{ name: 'w2_sodium', type: 'float' },
-			{ name: 'w2_magnesium', type: 'float' },
-			{ name: 'w2_total_alkalinity', type: 'float' },
-			{ name: 'w2_ph', type: 'float' },
-			{ name: 'w2_cost', type: 'float' },
-			{ name: 'wg_amount', type: 'float' },
-			{ name: 'wg_calcium', type: 'float' },
-			{ name: 'wg_sulfate', type: 'float' },
-			{ name: 'wg_chloride', type: 'float' },
-			{ name: 'wg_sodium', type: 'float' },
-			{ name: 'wg_magnesium', type: 'float' },
-			{ name: 'wg_total_alkalinity', type: 'float' },
-			{ name: 'wg_ph', type: 'float' },
-			{ name: 'wb_calcium', type: 'float' },
-			{ name: 'wb_sulfate', type: 'float' },
-			{ name: 'wb_chloride', type: 'float' },
-			{ name: 'wb_sodium', type: 'float' },
-			{ name: 'wb_magnesium', type: 'float' },
-			{ name: 'wb_total_alkalinity', type: 'float' },
-			{ name: 'wb_ph', type: 'float' },
-			{ name: 'wa_acid_name', type: 'int' },
-			{ name: 'wa_acid_perc', type: 'int' },
-			{ name: 'wa_base_name', type: 'int' },
-			{ name: 'fermentables', type: 'array' },
-			{ name: 'hops', type: 'array' },
-			{ name: 'miscs', type: 'array' },
-			{ name: 'yeasts', type: 'array' },
-			{ name: 'mashs', type: 'array' }
-		],
-		id: 'record',
-		url: url + '?record=' + my_record
-	};
-	// Load data and select one record.
-	var dataAdapter = new $.jqx.dataAdapter(source, {
-		loadComplete: function () {
-			var records = dataAdapter.records;
-			dataRecord = records[0];
-			// Hidden record uuid
-			$("#name").val(dataRecord.name);
-			$("#notes").val(dataRecord.notes);
-			$("#locked").val(dataRecord.locked);
-			$("#st_name").val(dataRecord.st_name);
-			$("#st_letter").val(dataRecord.st_letter);
-			$("#st_guide").val(dataRecord.st_guide);
-			$("#st_category").val(dataRecord.st_category);
-			$("#st_category_number").val(dataRecord.st_category_number);
-			$("#st_type").val(StyleTypeData[dataRecord.st_type].nl);
-			$("#type").val(dataRecord.type);
-			$("#batch_size").val(dataRecord.batch_size);
-			$("#boil_size").val(dataRecord.boil_size);
-			$("#boil_time").val(dataRecord.boil_time);
-			$("#efficiency").val(dataRecord.efficiency);
-			$("#est_og").val(dataRecord.est_og);
-			$("#est_og2").val(dataRecord.est_og);
-			$("#st_og_min").val(dataRecord.st_og_min);
-			$("#st_og_max").val(dataRecord.st_og_max);
-			$("#est_fg").val(dataRecord.est_fg);
-			$("#est_fg2").val(dataRecord.est_fg);
-			$("#st_fg_min").val(dataRecord.st_fg_min);
-			$("#st_fg_max").val(dataRecord.st_fg_max);
-			$("#est_color").val(dataRecord.est_color);
-			$("#est_color2").val(dataRecord.est_color);
-			$("#est_abv").val(dataRecord.est_abv);
-			$("#est_abv2").val(dataRecord.est_abv);
-			$("#st_abv_min").val(dataRecord.st_abv_min);
-			$("#st_abv_max").val(dataRecord.st_abv_max);
-			$("#st_color_min").val(dataRecord.st_color_min);
-			$("#st_color_max").val(dataRecord.st_color_max);
-			$("#color_method").val(dataRecord.color_method);
-			$("#est_ibu").val(dataRecord.est_ibu);
-			$("#est_ibu2").val(dataRecord.est_ibu);
-			$("#st_ibu_min").val(dataRecord.st_ibu_min);
-			$("#st_ibu_max").val(dataRecord.st_ibu_max);
-			$("#ibu_method").val(dataRecord.ibu_method);
-			$("#est_carb").val(dataRecord.est_carb);
-			$("#st_carb_min").val(dataRecord.st_carb_min);
-			$("#st_carb_max").val(dataRecord.st_carb_max);
-			$("#mash_name").val(dataRecord.mash_name);
-			$("#mash_ph").val(dataRecord.mash_ph);
-			$("#sparge_temp").val(dataRecord.sparge_temp);
-			$("#sparge_ph").val(dataRecord.sparge_ph);
-			$("#sparge_volume").val(dataRecord.sparge_volume);
-			$("#sparge_source").val(dataRecord.sparge_source);
-			$("#sparge_acid_type").val(dataRecord.sparge_acid_type);
-			$("#sparge_acid_perc").val(dataRecord.sparge_acid_perc);
-			$("#sparge_acid_amount").val(dataRecord.sparge_acid_amount * 1000);
-			$("#calc_acid").val(dataRecord.calc_acid);
-			$("#w1_name").val(dataRecord.w1_name);
-			$("#w1_amount").val(dataRecord.w1_amount);
-			$("#w1_calcium").val(dataRecord.w1_calcium);
-			$("#w1_sulfate").val(dataRecord.w1_sulfate);
-			$("#w1_chloride").val(dataRecord.w1_chloride);
-			$("#w1_sodium").val(dataRecord.w1_sodium);
-			$("#w1_magnesium").val(dataRecord.w1_magnesium);
-			$("#w1_total_alkalinity").val(dataRecord.w1_total_alkalinity);
-			$("#w1_ph").val(dataRecord.w1_ph);
-			$("#w1_cost").val(dataRecord.w1_cost);
-			$("#w2_name").val(dataRecord.w2_name);
-			$("#w2_amount").val(dataRecord.w2_amount);
-			$("#w2_calcium").val(dataRecord.w2_calcium);
-			$("#w2_sulfate").val(dataRecord.w2_sulfate);
-			$("#w2_chloride").val(dataRecord.w2_chloride);
-			$("#w2_sodium").val(dataRecord.w2_sodium);
-			$("#w2_magnesium").val(dataRecord.w2_magnesium);
-			$("#w2_total_alkalinity").val(dataRecord.w2_total_alkalinity);
-			$("#w2_ph").val(dataRecord.w2_ph);
-			$("#w2_cost").val(dataRecord.w2_cost);
-			$("#wg_amount").val(dataRecord.wg_amount);
-			$("#wg_calcium").val(dataRecord.wg_calcium);
-			$("#wg_sulfate").val(dataRecord.wg_sulfate);
-			$("#wg_chloride").val(dataRecord.wg_chloride);
-			$("#wg_sodium").val(dataRecord.wg_sodium);
-			$("#wg_magnesium").val(dataRecord.wg_magnesium);
-			$("#wg_total_alkalinity").val(dataRecord.wg_total_alkalinity);
-			$("#wg_ph").val(dataRecord.wg_ph);
-			$("#wb_calcium").val(dataRecord.wb_calcium);
-			$("#wb_sulfate").val(dataRecord.wb_sulfate);
-			$("#wb_chloride").val(dataRecord.wb_chloride);
-			$("#wb_sodium").val(dataRecord.wb_sodium);
-			$("#wb_magnesium").val(dataRecord.wb_magnesium);
-			$("#wb_total_alkalinity").val(dataRecord.wb_total_alkalinity);
-			$("#wb_ph").val(dataRecord.wb_ph);
-			$("#wa_acid_name").val(dataRecord.wa_acid_name);
-			$("#wa_acid_perc").val(dataRecord.wa_acid_perc);
-			$("#wa_base_name").val(dataRecord.wa_base_name);
-			editFermentable(dataRecord);
-			editHop(dataRecord);
-			editMisc(dataRecord);
-			editYeast(dataRecord);
-			editMash(dataRecord);
-			$('#jqxTabs').jqxTabs('next');
-		},
-		loadError: function (jqXHR, status, error) {
-		},
-		beforeLoadComplete: function (records) {
-			$('#jqxLoader').jqxLoader('open');
-		}
-	});
-	dataAdapter.dataBind();
+  result = GetAcidSpecs(AT);
+  pK1 = result.pK1;
+  pK2 = result.pK2;
+  pK3 = result.pK3;
+  MolWt = result.MolWt;
+  AcidSG = result.AcidSG;
+  AcidPrc = result.AcidPrc;
+
+  if (dataRecord.calc_acid) {
+   TpH = parseFloat(dataRecord.mash_ph);
+   protonDeficit = ProtonDeficit(TpH);
+   console.log('calc_acid tgt: ' + TpH + ' protonDeficit: ' + protonDeficit);
+   if (protonDeficit > 0) { // Add acid
+    $('#wa_base').val(0);
+    setWaterAgent(last_base, 0);
+    frac = CalcFrac(TpH, pK1, pK2, pK3);
+    Acid = protonDeficit / frac;
+    Acid *= MolWt; // mg
+    Acidmg = Acid;
+    Acid = Acid / AcidSG; // ml
+
+    if (parseFloat($('#wa_acid_perc').jqxNumberInput('decimal')) == 0)
+     $('#wa_acid_perc').val(AcidPrc);
+    Acid = Acid * AcidPrc / (parseFloat($('#wa_acid_perc').jqxNumberInput('decimal')) / 100); // ml
+    console.log('Final ml: ' + Acid);
+    $('#wa_acid').val(Math.round(Acid * 100) / 100);
+    setWaterAgent(AcidTypeData[AT].nl, Math.round(Acid * 100) / 100);
 
-	// Inline fermentables editor
-	var editFermentable = function (data) {
-		var fermentableSource = {
-			localdata: data.fermentables,
-			datatype: "local",
-			cache: false,
-			async: false,
-			datafields: [
-				{ name: 'f_name', type: 'string' },
-				{ name: 'f_origin', type: 'string' },
-				{ name: 'f_supplier', type: 'string' },
-				{ name: 'f_amount', type: 'float' },
-				{ name: 'f_cost', type: 'float' },
-				{ name: 'f_type', type: 'int' },
-				{ name: 'f_yield', type: 'float' },
-				{ name: 'f_color', type: 'float' },
-				{ name: 'f_coarse_fine_diff', type: 'float' },
-				{ name: 'f_moisture', type: 'float' },
-				{ name: 'f_diastatic_power', type: 'float' },
-				{ name: 'f_protein', type: 'float' },
-				{ name: 'f_max_in_batch', type: 'float' },
-				{ name: 'f_graintype', type: 'int' },
-				{ name: 'f_added', type: 'int' },
-				{ name: 'f_dissolved_protein', type: 'float' },
-				{ name: 'f_recommend_mash', type: 'int' },
-				{ name: 'f_add_after_boil', type: 'int' },
-				{ name: 'f_adjust_to_total_100', type: 'int' },
-				{ name: 'f_percentage', type: 'float' },
-				{ name: 'f_di_ph', type: 'float' },
-				{ name: 'f_acid_to_ph_57', type: 'float' },
-				{ name: 'f_inventory', type: 'float' },
-				{ name: 'f_avail', type: 'int' }
-			],
-			addrow: function (rowid, rowdata, position, commit) {
-				//console.log("fermentable addrow "+rowid);
-				commit(true);
-			},
-			deleterow: function (rowid, commit) {
-				//console.log("fermentable deleterow "+rowid);
-				commit(true);
-			},
-			updaterow: function (rowid, rowdata, commit) {
-				//console.log("fermentable updaterow "+rowid);
-				commit(true);
-			}
-		};
-		var fermentableAdapter = new $.jqx.dataAdapter(fermentableSource);
-		$("#fermentableGrid").jqxGrid({
-			width: 1240,
-			height: 470,
-			source: fermentableAdapter,
-			theme: theme,
-			selectionmode: 'singlerow',
-			showtoolbar: true,
-			rendertoolbar: function (toolbar) {
-				var me = this;
-				var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
-				toolbar.append(container);
-				container.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');
-				container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
-				container.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');
-				container.append('<input style="float: left; margin-left: 400px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');
-				// add fermentable from dropdownlist.
-				$("#faddrowbutton").jqxDropDownList({
-					placeHolder: "Kies mout:",
-					theme: theme,
-					template: "primary",
-					source: fermentablelist,
-					displayMember: "name",
-					width: 150,
-					height: 27,
-					dropDownWidth: 500,
-					dropDownHeight: 500,
-					renderer: function (index, label, value) {
-						var datarecord = fermentablelist.records[index];
-						return datarecord.supplier+ " / " + datarecord.name + " (" + datarecord.color + " EBC)";
-					}
-				});
-				$("#faddrowbutton").on('select', function (event) {
-					if (event.args) {
-						var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-						var index = event.args.index;
-						var datarecord = fermentablelist.records[index];
-						var row = {};
-						row["f_name"] = datarecord.name;
-						row["f_origin"] = datarecord.origin;
-						row["f_supplier"] = datarecord.supplier;
-						row["f_amount"] = 0;
-						row["f_cost"] = datarecord.cost;
-						row["f_type"] = datarecord.type;
-						row["f_yield"] = datarecord.yield;
-						row["f_color"] = datarecord.color;
-						row["f_coarse_fine_diff"] = datarecord.coarse_fine_diff;
-						row["f_moisture"] = datarecord.moisture;
-						row["f_diastatic_power"] = datarecord.diastatic_power;
-						row["f_protein"] = datarecord.protein;
-						row["f_max_in_batch"] = datarecord.max_in_batch;
-						row["f_graintype"] = datarecord.graintype;
-						if (datarecord.add_after_boil) {
-							row["f_added"] = 2;	// Fermentation
-						} else if ((datarecord.type == 1) || (datarecord.type == 4)) {	// Sugar or Adjunct
-							row["f_added"] = 1;	// Boil
-						} else {
-							row["f_added"] = 0;	// Mash
-						}
-						row["f_dissolved_protein"] = datarecord.dissolved_protein;
-						row["f_recommend_mash"] = datarecord.recommend_mash;
-						row["f_add_after_boil"] = datarecord.add_after_boil;
-						if (rowscount == 0) {
-							// The first fermentable
-							row["f_adjust_to_total_100"] = 1;
-							row["f_percentage"] = 100;
-						} else {
-							row["f_adjust_to_total_100"] = 0;
-							row["f_percentage"] = 0;
-						}
-						row["f_di_ph"] = datarecord.di_ph;
-						row["f_acid_to_ph_57"] = datarecord.acid_to_ph_57;
-						row["f_inventory"] = datarecord.inventory;
-						var commit = $("#fermentableGrid").jqxGrid('addrow', null, row);
-					}
-				});
+    bicarbonate = bicarbonate - protonDeficit * frac / liters;
+    total_alkalinity = bicarbonate * 50 / 61;
+   } else if (protonDeficit < 0) { //Add base
+    $('#wa_acid').val(0);
+    setWaterAgent(last_acid, 0);
+    r1d = Math.pow(10, (TpH - 6.38));
+    r2d = Math.pow(10, (TpH - 10.38));
+    f1d = 1 / (1 + r1d + r1d * r2d);
+    f2d = f1d * r1d;
+    f3d = f2d * r2d;
+    switch (BT) {
+     case 0: RA = -protonDeficit / (f1d - f3d); //Sodiumbicarbonate, mmol totaal
+             RA = RA * MMNaHCO3 / 1000; //gram
+             $('#wa_base').val(Round(RA, 2));
+             setWaterAgent('NaHCO3', Round(RA, 2));
+             if (liters > 0) {
+              // Na
+              RA = parseFloat($('#wa_nacl').jqxNumberInput('decimal')) * MMNa / MMNaCl +
+                   parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMNa / MMNaHCO3;
+              RA = 1000 * RA / liters;
+              sodium = wg_sodium + RA;
+              // HCO3
+              RA = parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMHCO3 / MMNaHCO3;
+              RA = 1000 * RA / liters;
+              bicarbonate = wg_bicarbonate + RA;
+              total_alkalinity = bicarbonate * 50 / 61;
+              RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
+             }
+             break;
+     case 1: RA = -protonDeficit / (2 * f1d + f2d); // Sodiumcarbonate, mmol totaal
+             RA = RA * MMNa2CO3 / 1000; //gram
+             $('#wa_base').val(Round(RA, 2));
+             setWaterAgent('Na2CO3', Round(RA, 2));
+             if (liters > 0) {
+              RA = parseFloat($('#wa_nacl').jqxNumberInput('decimal')) * MMNa / MMNaCl +
+                   parseFloat($('#wa_base').jqxNumberInput('decimal')) * 2 * MMNa / MMNa2CO3;
+              RA = 1000 * RA / liters;
+              sodium = wg_sodium + RA;
+              // HCO3
+              RA = parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMHCO3 / MMNa2CO3;
+              RA = 1000 * RA / liters;
+              bicarbonate = wg_bicarbonate + RA;
+              total_alkalinity = bicarbonate * 50 / 61;
+              RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
+             }
+             break;
+     case 2: RA = -protonDeficit * (f1d - f3d); // Calciumcarbonate, mmol totaal
+             RA = RA * MMCaCO3 / 1000; //gram
+             //but only 1/3 is effective, so add 3 times as much
+             RA = 3 * RA;
+             $('#wa_base').val(Round(RA, 2));
+             setWaterAgent('CaCO3', Round(RA, 2));
+             if (liters > 0) {
+              //Bicarbonate
+              RA = parseFloat($('#wa_base').jqxNumberInput('decimal')) / 3 * MMHCO3 / MMCaCO3;
+              RA = 1000 * RA / liters;
+              bicarbonate = wg_bicarbonate + RA;
+              total_alkalinity = bicarbonate * 50 / 61;
+              //Ca precipitates out as Ca10(PO4)6(OH)2
+              RA = parseFloat($('#wa_cacl2').jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
+                   parseFloat($('#wa_caso4').jqxNumberInput('decimal')) * MMCa / MMCaSO4 +
+                   parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMCa / MMCaCO3;
+              RA = 1000 * RA / liters;
+              calcium = wg_calcium + RA;
+              RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
+             }
+             break;
+     case 3: RA = -protonDeficit / 19.3; // Calciumhydroxide
+             $('#wa_base').val(Round(RA, 2));
+             setWaterAgent('Ca(OH)2', Round(RA, 2));
+             if (liters > 0) {
+              // Bicarbonate
+              RA = -protonDeficit / liters;
+              total_alkalinity = wg_total_alkalinity + RA;
+              bicarbonate = total_alkalinity * 61 / 50;
+              // Calcium
+              RA = parseFloat($('#wa_cacl2').jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
+                   parseFloat($('#wa_caso4').jqxNumberInput('decimal')) * MMCa / MMCaSO4 +
+                   parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMCa / MMCaOH2;
+              RA = 1000 * RA / liters;
+              calcium = wg_calcium + RA;
+              RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
+             }
+             break;
+    }
+   }
+   ph = TpH;
+   $('#wb_ph').val(Math.round(ph * 10) / 10);
+  } else { // Manual
+   console.log('calc_acid no');
+   // First add base salts
+   if (parseFloat($('#wa_base').jqxNumberInput('decimal')) > 0) {
+    if (liters > 0) {
+     switch (BT) {
+      case 0: // Sodiumbicarbonate, Na
+       RA = parseFloat($('#wa_nacl').jqxNumberInput('decimal')) * MMNa / MMNaCl +
+            parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMNa / MMNaHCO3;
+       RA = 1000 * RA / liters;
+       sodium = wg_sodium + RA;
+       // HCO3
+       RA = parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMHCO3 / MMNaHCO3;
+       RA = 1000 * RA / liters;
+       bicarbonate = wg_bicarbonate + RA;
+       total_alkalinity = bicarbonate * 50 / 61;
+       RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
+       break;
+      case 1: // Sodiumcarbonate
+       RA = parseFloat($('#wa_nacl').jqxNumberInput('decimal')) * MMNa / MMNaCl +
+            parseFloat($('#wa_base').jqxNumberInput('decimal')) * 2 * MMNa / MMNa2CO3;
+       RA = 1000 * RA / liters;
+       sodium = wg_sodium + RA;
+       // HCO3
+       RA = parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMHCO3 / MMNa2CO3;
+       RA = 1000 * RA / liters;
+       bicarbonate = wg_bicarbonate + RA;
+       total_alkalinity = bicarbonate * 50 / 61;
+       RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
+       break;
+      case 2: // Calciumcarbonate: Bicarbonate
+       RA = parseFloat($('#wa_base').jqxNumberInput('decimal')) / 3 * MMHCO3 / MMCaCO3;
+       RA = 1000 * RA / liters;
+       bicarbonate = wg_bicarbonate + RA;
+       total_alkalinity = bicarbonate * 50 / 61;
+       RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium);
+       // Ca
+       RA = parseFloat($('#wa_cacl2').jqxNumberInput('decimal')) * MMCa / MMCaCl2 +
+            parseFloat($('#wa_caso4').jqxNumberInput('decimal')) * MMCa / MMCaSO4 +
+            parseFloat($('#wa_base').jqxNumberInput('decimal')) * MMCa / MMCaCO3;
+       RA = 1000 * RA / liters;
+       calcium = wg_calcium + RA;
+       break;
+     }
+    }
+   }
 
-				$("#finstockbutton").jqxCheckBox({ theme: theme, height: 27 });
-				$("#finstockbutton").on('change', function (event) {
-					fermentableinstock = event.args.checked;
-					fermentablelist.dataBind();
-				});
+   TpH = parseFloat(dataRecord.mash_ph);
+   pHa = MashpH(); // This one is in demi water, should be in adjusted water???
+   // Then calculate the new pH with added acids
+   if (parseFloat($('#wa_acid').jqxNumberInput('decimal')) > 0) {
+    console.log('TpH: ' + TpH + ' water: ' + pHa);
+    Acid = parseFloat($('#wa_acid').jqxNumberInput('decimal'));
+    if (parseFloat($('#wa_acid_perc').jqxNumberInput('decimal')) == 0)
+     $('#wa_acid_perc').val(AcidPrc);
+    Acid = Acid / AcidPrc * (parseFloat($('#wa_acid_perc').jqxNumberInput('decimal')) / 100); // ml
+    Acid *= AcidSG; // ml
+    Acid /= MolWt;  // mg
+    Acidmg = Acid;
+
+    //find the pH where the protondeficit = protondeficit by the acid
+    frac = CalcFrac(pHa, pK1, pK2, pK3);
+    protonDeficit = Acid * frac;
+
+    deltapH = 0.001;
+    deltapd = 0.1;
+    pd = ProtonDeficit(pHa);
+    n = 0;
+    while (((pd < (protonDeficit - deltapd)) || (pd > (protonDeficit + deltapd))) && (n < 2000)) {
+     n++;
+     if (pd < (protonDeficit - deltapd))
+      pHa -= deltapH;
+     else if (pd > (protonDeficit + deltapd))
+      pHa += deltapH;
+     frac = CalcFrac(pHa, pK1, pK2, pK3);
+     protonDeficit = Acid * frac;
+     pd = ProtonDeficit(pHa);
+    }
+    console.log('n: ' + n + ' pd: ' + pd + ' protonDeficit: ' + protonDeficit + ' frac: ' + frac + ' pHa: ' + pHa);
+    RA = wg_bicarbonate - protonDeficit * frac / liters;
+    bicarbonate = RA;
+    total_alkalinity = RA * 50 / 61;
+    ph = pHa;
+    $('#wb_ph').val(Round(ph, 1));
+   }
+  }
+
+  if ((AT == 3) && (liters > 0)) {        // Sulfuctic / Zwavelzuur
+   RA = parseFloat($('#wa_caso4').jqxNumberInput('decimal')) * MMSO4 / MMCaSO4 +
+        parseFloat($('#wa_mgso4').jqxNumberInput('decimal')) * MMSO4 / MMMgSO4 +
+        Acidmg / 1000 * MMSO4 / (MMSO4 + 2);
+   RA = 1000 * RA / liters;
+   sulfate = wg_sulfate + RA;      // Not add to sulfate??
+  } else if ((AT == 1) && (liters > 0)) { // Hydrochloric, Zoutzuur
+   RA = parseFloat($('#wa_cacl2').jqxNumberInput('decimal')) * MMCl / MMCaCl2 +
+        parseFloat($('#wa_nacl').jqxNumberInput('decimal')) * MMCl / MMNaCl +
+        Acidmg / 1000 * MMCl / (MMCl + 1);
+   RA = 1000 * RA / liters;
+   chloride = wg_chloride + RA;
+  }
+
+  // 2:1 Sulfate to Chroride IPA's, Pale Ales.
+  // 1:1 Sulfate to Chloride Balanced
+  // 1:2 Sulfate to Chloride Malty
+  // Note, values below are the other way, cl to so4!
+  // So: 0.5 is IPA's, Pale Ales.
+  //       1 Balanced
+  //       2 Malty.
+  $('#tgt_bu').val(Math.round(GetBUGU() * 100) / 100);
+  // From brouwhulp.
+  if (GetBUGU() < 0.32)
+   $('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Zeer moutig en zoet</span>");
+  else if (GetBUGU() < 0.43)
+   $('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Moutig, zoet</span>");
+  else if (GetBUGU() < 0.52)
+   $('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Evenwichtig</span>");
+  else if (GetBUGU() < 0.63)
+   $('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Licht hoppig, bitter</span>");
+  else
+   $('#wr_bu').html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Extra hoppig, zeer bitter</span>");
+  $('#tgt_cl_so4').val(Math.round(GetOptClSO4ratio() * 10) / 10);
+  if (sulfate > 0)
+   RA = chloride / sulfate;
+  else
+   RA = 10;
+  $('#got_cl_so4').val(Math.round(RA * 10) / 10);
+  piCLSO4_low = 0.8 * GetOptClSO4ratio();
+  piCLSO4_high = 1.2 * GetOptClSO4ratio();
+  Res = 'normaal';
+  if (RA < piCLSO4_low)
+   Res = 'laag';
+  else if (RA > piCLSO4_high)
+   Res = 'hoog';
+  setRangeIndicator('cl_so4', Res);
+
+  $('#wb_calcium').val(Round(calcium, 1));
+  $('#wb_magnesium').val(Round(magnesium, 1));
+  $('#wb_sodium').val(Round(sodium, 1));
+  $('#wb_sulfate').val(Round(sulfate, 1));
+  $('#wb_chloride').val(Round(chloride, 1));
+  $('#wb_total_alkalinity').val(Round(total_alkalinity, 1));
+
+  if (calcium < 40) {
+   setRangeIndicator('calcium', 'laag');
+  } else if (calcium > 150) {
+   setRangeIndicator('calcium', 'hoog');
+  } else {
+   setRangeIndicator('calcium', 'normaal');
+  }
+  if (magnesium >= 0 && magnesium <= 30) {
+   setRangeIndicator('magnesium', 'normaal');
+  } else {
+   setRangeIndicator('magnesium', 'hoog');
+  }
+  if (sodium <= 150) {
+   setRangeIndicator('sodium', 'normaal');
+  } else {
+   setRangeIndicator('sodium', 'hoog');
+  }
+  // Both chloride and sulfate should be above 50 according to
+  // John Palmer. So the Cl/SO4 ratio calculation will work.
+  if (chloride <= 50) {
+   setRangeIndicator('chloride', 'laag');
+  } else if (chloride <= 100) {
+   setRangeIndicator('chloride', 'normaal');
+  } else {
+   setRangeIndicator('chloride', 'hoog');
+  }
+  if (sulfate <= 50) {
+   setRangeIndicator('sulfate', 'laag');
+  } else if (sulfate <= 350) {
+   setRangeIndicator('sulfate', 'normaal');
+  } else {
+   setRangeIndicator('sulfate', 'hoog');
+  }
+  if (ph < 5.2) {
+   setRangeIndicator('ph', 'laag');
+  } else if (ph > 5.6) {
+   setRangeIndicator('ph', 'hoog');
+  } else {
+   setRangeIndicator('ph', 'normaal');
+  }
+  calcSparge();
+ }
+
 
-				// delete selected fermentable.
-				$("#fdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150 });
-				$("#fdeleterowbutton").on('click', function () {
-					var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex');
-					var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-					if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
-						var id = $("#fermentableGrid").jqxGrid('getrowid', selectedrowindex);
-						var percent = $('#fermentableGrid').jqxGrid('getcellvalue', id, "f_percentage");
-						var amount = $('#fermentableGrid').jqxGrid('getcellvalue', id, "f_amount");
-						var commit = $("#fermentableGrid").jqxGrid('deleterow', id);
-					}
-					rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-					if (rowscount > 1) {
-						if (to_100) {
-							for (var i = 0; i < rowscount; i++) {
-								var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-								if (rowdata.f_adjust_to_total_100) {
-									rowdata.f_percentage += percent;
-									rowdata.f_amount += amount;
-								}
-							}
-						} else {
-							calcPercentages();
-						}
-					} else {
-						$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
-					}
-					calcFermentables();
-					calcIBUs();
-				});
-			},
-			ready: function() {
-				calcFermentables();
-				$('#jqxTabs').jqxTabs('next');
-			},
-			columns: [
-				{ text: 'Vergistbaar ingredi&euml;nt', datafield: 'f_name',
-				  cellsrenderer:  function (index, datafield, value, defaulvalue, column, rowdata) {
-					return "<span style='margin: 3px; margin-top: 6px; float: left;'>" +
-						rowdata.f_supplier+" / "+rowdata.f_name+" ("+rowdata.f_color+" EBC)</span>";
-				  }
-			       	},
-				{ text: 'Type', width: 100, datafield: 'f_type',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return "<span style='margin: 3px; margin-top: 6px; float: left;'>" + FermentableTypeData[value].nl + "</span>";
-				  }
-				},
-				{ text: 'Moment', width: 110, datafield: 'f_added',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return "<span style='margin: 3px; margin-top: 6px; float: left;'>" + AddedData[value].nl + "</span>";
-				  }
-				},
-				{ text:'Maxinbatch', datafield: 'f_max_in_batch', hidden: true },
-				{ text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
-				{ text: 'Gewicht Kg', datafield: 'f_amount', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f3' },
-				{ text: 'Voorr. Kg', datafield: 'f_inventory', width: 120, align: 'right',
-				  cellsrenderer:  function (row, columnfield, value, defaulthtml, columnproperties, rowdata) {
-					var color = '#ffffff';
-					if (value < rowdata.f_amount)
-						color = '#ff4040';
-					return  '<span style="margin: 4px; margin-top: 6px; float: right; color: ' +
-						color + ';">' +fermentableAdapter.formatNumber(value, "f3") + '</span>';
-				  }
-				},
-				{ text: 'Procent', datafield: 'f_percentage', width: 90, align: 'right',
-				  cellsrenderer:  function (row, columnfield, value, defaulthtml, columnproperties, rowdata) {
-					var color = '#ffffff';
-					if (value > rowdata.f_max_in_batch)
-						color = '#ff4040';
-					return  '<span style="margin: 4px; margin-top: 6px; float: right; color: ' +
-						color + ';">' +fermentableAdapter.formatNumber(value, "p1") + '</span>';
-				  }
-				},
-				{ text: '100%', align: 'center', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 70 },
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-				        }, buttonclick: function (row) {
-						fermentableRow = row;
-						fermentableData = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
-						$("#wf_name").val(fermentableData.f_name);
-						$("#wf_amount").val(fermentableData.f_amount);
-						$("#wf_percentage").val(fermentableData.f_percentage);
-						$("#wf_max_in_batch").val(fermentableData.f_max_in_batch);
-						$("#wf_adjust_to_total_100").val(fermentableData.f_adjust_to_total_100);
-						$("#wf_added").val(fermentableData.f_added);
-						// show the popup window.
-						$("#popupFermentable").jqxWindow('open');
-					}
-				}
-			]
-		});
-	};
+ function calcSparge() {
+  var TargetpH, Source_pH, Source_alkalinity, r1, r2, d, f1, f3,
+  r143, r243, d43, f143, f343, alkalinity, Ct, r1g, r2g, dg, f1g, f3g,
+  Acid, AT, result, pK1, pK2, pK3, MolWt, AcidSG, AcidPrc, fract;
+
+  // Code from BrewBuddy/Brouwhulp, who got it from http://www.brewery.org/brewery/library/Acidi0,00fWaterAJD0497.html
+  TargetpH = dataRecord.sparge_ph;
+  Source_pH = dataRecord.w1_ph;
+  Source_alkalinity = dataRecord.w1_total_alkalinity;
+  // Select watersource or fallback to the first source.
+  if (dataRecord.sparge_source == 1) { // Source 2
+   if (dataRecord.w2_ph > 0.0) {
+    Source_pH = dataRecord.w2_ph;
+    Source_alkalinity = dataRecord.w2_total_alkalinity;
+   } else {
+    dataRecord.sparge_source = 0; // Source 1
+    $('#sparge_source').val(0);
+   }
+  } else if (dataRecord.sparge_source == 2) { // Mixed
+   if (dataRecord.w2_ph > 0.0) {
+    Source_pH = parseFloat($('#wg_ph').jqxNumberInput('decimal'));
+    Source_alkalinity = parseFloat($('#wg_total_alkalinity').jqxNumberInput('decimal'));
+   } else {
+    dataRecord.sparge_source = 0;
+    $('#sparge_source').val(0);
+   }
+  }
+
+  // Step 1: Compute the mole fractions of carbonic (f1o), bicarbonate (f2o) and carbonate(f3o) at the water pH
+  r1 = Math.pow(10, Source_pH - 6.38);
+  r2 = Math.pow(10, Source_pH - 10.373);
+  d = 1 + r1 + r1 * r2;
+  f1 = 1 / d;
+  f3 = r1 * r2 / d;
+
+  //Step 2. Compute the mole fractions at pH = 4.3 (the pH which defines alkalinity)
+  r143 = Math.pow(10, 4.3 - 6.38);
+  r243 = Math.pow(10, 4.3 - 10.373);
+  d43 = 1 + r143 + r143 * r243;
+  f143 = 1 / d43;
+  f343 = r143 * r243 / d43;
+
+  //Step 3. Convert the sample alkalinity to milliequivalents/L
+  alkalinity = Source_alkalinity / 50;
+  //Step 4. Solve
+  Ct = (alkalinity - 1000 * (Math.pow(10, -4.3) - Math.pow(10, -Source_pH))) / ((f143 - f1) + (f3 - f343));
+
+  //Step 5. Compute mole fractions at desired pH
+  r1g = Math.pow(10, TargetpH - 6.38);
+  r2g = Math.pow(10, TargetpH - 10.373);
+  dg = 1 + r1g + r1g * r2g;
+  f1g = 1 / dg;
+  f3g = r1g * r2g / dg;
+
+  //Step 6. Use these to compute the milliequivalents acid required per liter (mEq/L)
+  Acid = Ct * ((f1g - f1) + (f3 - f3g)) + Math.pow(10, -TargetpH) - Math.pow(10, -Source_pH);  //mEq/l
+  Acid += 0.01;   // Add acid that would be required for distilled water.
+  if (dataRecord.sparge_acid_type < 0 || dataRecord.sparge_acid_type > 3) {
+   dataRecord.sparge_acid_type = 0;
+   $('#sparge_acid_type').val(0);
+  }
+
+  //Step 8. Get the acid data.
+  AT = dataRecord.sparge_acid_type;
+  result = GetAcidSpecs(AT);
+  pK1 = result.pK1;
+  pK2 = result.pK2;
+  pK3 = result.pK3;
+  MolWt = result.MolWt;
+  AcidSG = result.AcidSG;
+  AcidPrc = result.AcidPrc;
+  fract = CalcFrac(TargetpH, pK1, pK2, pK3);
+
+  //Step 9. Now divide the mEq required by the "fraction". This is the required number of moles of acid.
+  Acid /= fract;
+
+  //Step 10. Multiply by molecular weight of the acid
+  Acid *= MolWt; //mg
+
+  Acid = Acid / AcidSG; //ml ; 88% lactic solution
+  f1 = dataRecord.sparge_acid_perc;
+  if (f1 <= 0.1)
+   f1 = AcidPrc;
+  Acid = Acid * AcidPrc / (f1 / 100);
+
+  Acid *= dataRecord.sparge_volume; //ml lactic acid total
+  Acid = Round(Acid, 2);
+  dataRecord.sparge_acid_amount = Acid / 1000;
+  $('#sparge_acid_amount').val(Acid);
+ }
+
+ /*
+  * Change OG of recipe but keep the water volumes.
+  */
+ function calcFermentablesFromOG(OG) {
+
+  console.log('calcFermentablesFromOG(' + OG + ')');
+  var amount, row, d, i, sug, tot = 0, totmass = 0, rowscount, efficiency = parseFloat($('#efficiency').jqxNumberInput('decimal'));
+  sug = sg_to_plato(OG) * parseFloat($('#batch_size').jqxNumberInput('decimal')) * OG / 100; //total amount of sugars in kg
+  rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+
+  for (i = 0; i < rowscount; i++) {
+   row = $('#fermentableGrid').jqxGrid('getrowdata', i);
+   if (row.f_added < 4) {
+    d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+    if (row.f_added == 0) // Mash
+     d = efficiency / 100 * d;
+    tot += d;
+   }
+  }
+  if (tot)
+   totmass = Math.round((sug / tot) * 1000) / 1000;
+
+  if (totmass) {
+   for (i = 0; i < rowscount; i++) {
+    row = $('#fermentableGrid').jqxGrid('getrowdata', i);
+    if (row.f_added < 4) {
+     amount = Math.round(row.f_percentage * 10 * totmass) / 1000;
+     $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', amount);
+    }
+   }
+  }
+ };
+
+ function calcInit() {
+  console.log('calc.init()');
 
-	// Inline hops editor
-        var editHop = function (data) {
-                var hopSource = {
-                        localdata: data.hops,
-                        datatype: "local",
-			cache: false,
-			async: false,
-                        datafields: [
-                                { name: 'h_name', type: 'string' },
-                                { name: 'h_origin', type: 'string' },
-                                { name: 'h_amount', type: 'float' },
-                                { name: 'h_cost', type: 'float' },
-				{ name: 'h_type', type: 'int' },
-				{ name: 'h_form', type: 'int' },
-				{ name: 'h_useat', type: 'int' },
-                                { name: 'h_time', type: 'float' },
-				{ name: 'h_alpha', type: 'float' },
-				{ name: 'h_beta', type: 'float' },
-				{ name: 'h_hsi', type: 'float' },
-				{ name: 'h_humulene', type: 'float' },
-				{ name: 'h_caryophyllene', type: 'float' },
-				{ name: 'h_cohumulone', type: 'float' },
-				{ name: 'h_myrcene', type: 'float' },
-				{ name: 'h_total_oil', type: 'float' },
-				{ name: 'h_inventory', type: 'float' },
-				{ name: 'h_avail', type: 'int' }
-                        ],
-                        addrow: function (rowid, rowdata, position, commit) {
-				console.log("hop addrow "+rowid);
-                                commit(true);
-                        },
-                        deleterow: function (rowid, commit) {
-				console.log("hop deleterow "+rowid);
-                                commit(true);
-                        },
-			updaterow: function (rowid, rowdata, commit) {
-				console.log("hop updaterow "+rowid);
-				commit(true);
-			}
-                };
-                var hopAdapter = new $.jqx.dataAdapter(hopSource);
-                $("#hopGrid").jqxGrid({
-                        width: 1240,
-                        height: 560,
-                        source: hopAdapter,
-                        theme: theme,
-                        selectionmode: 'singlerow',
-                        showtoolbar: true,
-                        rendertoolbar: function (toolbar) {
-                                var me = this;
-                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
-                                toolbar.append(container);
-                                container.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');
-				container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
-				container.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');
-                                container.append('<input style="float: left; margin-left: 400px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');
-                                // add hop from dropdownlist.
-                                $("#haddrowbutton").jqxDropDownList({
-                                        placeHolder: "Kies hop:",
-                                        theme: theme,
-					template: "primary",
-                                        source: hoplist,
-                                        displayMember: "name",
-                                        width: 150,
-                                        height: 27,
-                                        dropDownWidth: 500,
-					dropDownHeight: 500,
-					renderer: function (index, label, value) {
-						var datarecord = hoplist.records[index];
-						return datarecord.origin+ " / " + datarecord.name + " (" + datarecord.alpha + "% &alpha;)";
-					}
-                                });
-                                $("#haddrowbutton").on('select', function (event) {
-                                        if (event.args) {
-                                                var index = event.args.index;
-                                                var datarecord = hoplist.records[index];
-                                                var row = {};
-                                                row["h_name"] = datarecord.name;
-                                                row["h_origin"] = datarecord.origin;
-                                                row["h_amount"] = 0;
-                                                row["h_cost"] = datarecord.cost;
-                                                row["h_type"] = datarecord.type;
-						row["h_form"] = datarecord.form;
-						row["h_useat"] = 2;	// Boil
-						row["h_time"] = 0;
-						row["h_alpha"] = datarecord.alpha;
-						row["h_beta"] = datarecord.beta;
-						row["h_hsi"] = datarecord.hsi;
-						row["h_humulene"] = datarecord.humulene;
-						row["h_caryophyllene"] = datarecord.caryophyllene;
-						row["h_cohumulone"] = datarecord.cohumulone;
-						row["h_myrcene"] = datarecord.myrcene;
-						row["h_total_oil"] = datarecord.total_oil;
-						row["h_inventory"] = datarecord.inventory;
-                                                var commit = $("#hopGrid").jqxGrid('addrow', null, row);
-                                        }
-					$("#haddrowbutton").jqxDropDownList('clearSelection');
-                                });
+  $('#calc_acid').on('checked', function(event) {
+   dataRecord.calc_acid = 1;
+   calcWater();
+  });
+  $('#calc_acid').on('unchecked', function(event) {
+   dataRecord.calc_acid = 0;
+   calcWater();
+  });
+  $('#w1_name').jqxDropDownList('selectItem', dataRecord.w1_name);
+  $('#w2_name').jqxDropDownList('selectItem', dataRecord.w2_name);
+  // Fix tap water if zero using mash infuse amount.
+  if (parseFloat($('#w1_amount').jqxNumberInput('decimal')) == 0 && mash_infuse > 0) {
+   $('#w1_amount').val(mash_infuse);
+   dataRecord.w1_amount = mash_infuse;
+   $('#wg_amount').val(mash_infuse);
+   $('#w2_amount').val(0);
+   dataRecord.w2_amount = 0;
+  }
+  calcWater();
+  $('#w2_amount').on('change', function(event) {
+   var newval = parseFloat(event.args.value);
 
-				$("#hinstockbutton").jqxCheckBox({ theme: theme, height: 27 });
-				$("#hinstockbutton").on('change', function (event) {
-					hopinstock = event.args.checked;
-					hoplist.dataBind();
-				});
+   if (newval > mash_infuse) {
+    $('#w2_amount').val(dataRecord.w2_amount);
+    return;
+   }
+   dataRecord.w1_amount = parseFloat($('#wg_amount').jqxNumberInput('decimal')) - newval;
+   $('#w1_amount').val(dataRecord.w1_amount);
+   dataRecord.w2_amount = newval;
+   console.log('new: ' + event.args.value + ' w1: ' + dataRecord.w1_amount + '  w2: ' + dataRecord.w2_amount);
+   calcWater();
+  });
+  $('#wa_cacl2').on('change', function(event) {
+   if (event.args) {
+    setWaterAgent('CaCl2', 0); // This can prevent double entries.
+    setWaterAgent('CaCl2', event.args.value);
+    calcWater();
+   }
+  });
+  $('#wa_caso4').on('change', function(event) {
+   if (event.args) {
+    setWaterAgent('CaSO4', 0);
+    setWaterAgent('CaSO4', event.args.value);
+    calcWater();
+   }
+  });
+  $('#wa_mgso4').on('change', function(event) {
+   if (event.args) {
+    setWaterAgent('MgSO4', 0);
+    setWaterAgent('MgSO4', event.args.value);
+    calcWater();
+   }
+  });
+  $('#wa_nacl').on('change', function(event) {
+   if (event.args) {
+    setWaterAgent('NaCl', 0);
+    setWaterAgent('NaCl', event.args.value);
+    calcWater();
+   }
+  });
+  $('#wa_base_name').on('change', function(event) {
+   if (event.args) {
+    var index = event.args.index;
+    setWaterAgent(last_base, 0);
+    last_base = BaseTypeData[index].nl;
+    setWaterAgent(last_base, parseFloat($('#wa_base').jqxNumberInput('decimal')));
+    dataRecord.wa_base_name = index;
+    calcWater();
+   }
+  });
+  $('#wa_base').on('change', function(event) {
+   var name = BaseTypeData[$('#wa_base_name').val()].nl;
+   setWaterAgent(name, parseFloat(event.args.value));
+   calcWater();
+  });
+  $('#wa_acid_name').on('change', function(event) {
+   if (event.args) {
+    var index = event.args.index;
+    setWaterAgent(last_acid, 0);
+    last_acid = AcidTypeData[index].nl;
+    setWaterAgent(last_acid, parseFloat($('#wa_acid').jqxNumberInput('decimal')));
+    dataRecord.wa_acid_name = index;
+    calcWater();
+   }
+  });
+  $('#wa_acid').on('change', function(event) {
+   var name = AcidTypeData[$('#wa_acid_name').val()].nl;
+   setWaterAgent(name, parseFloat(event.args.value));
+   calcWater();
+  });
+  $('#wa_acid_perc').on('change', function(event) { calcWater(); });
 
-                                // delete selected hop.
-                                $("#hdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150 });
-                                $("#hdeleterowbutton").on('click', function () {
-                                        var selectedrowindex = $("#hopGrid").jqxGrid('getselectedrowindex');
-                                        var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount;
-                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
-                                                var id = $("#hopGrid").jqxGrid('getrowid', selectedrowindex);
-                                                var commit = $("#hopGrid").jqxGrid('deleterow', id);
-                                        }
-					calcIBUs();
-                                });
-                        },
-			ready: function() {
-				calcIBUs();
-				$('#jqxTabs').jqxTabs('next');
-			},
-                        columns: [
-                                { text: 'Hop', datafield: 'h_name',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return "<span style='margin: 3px; margin-top: 6px; float: left;'>" +rowdata.h_origin+" / "+rowdata.h_name+"</span>";
-				  },
-			       	},
-                                { text: 'Type', width: 90, datafield: 'h_type',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return  '<span style="margin: 4px; margin-top: 6px; float: left;">' + HopTypeData[value].nl + '</span>';
-				  }
-			       	},
-				{ text: 'Vorm', width: 90, datafield: 'h_form',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return  '<span style="margin: 4px; margin-top: 6px; float: left;">' + HopFormData[value].nl + '</span>';
-				  }
-			       	},
-                                { text: 'Alpha', datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
-				{ text: 'Gebruik', width: 110, datafield: 'h_useat',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return  '<span style="margin: 4px; margin-top: 6px; float: left;">' + HopUseData[value].nl + '</span>';
-				  }
-				},
-				{ text: 'Tijdsduur', datafield: 'h_time', width: 90, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var duration = '';
-					if ((rowdata.h_useat == 2) || (rowdata.h_useat == 4))   // Boil, Whirlpool
-						duration = dataAdapter.formatNumber(value, "f0")+" min.";
-					else if (rowdata.h_useat == 5)       // Dry hop
-						duration = dataAdapter.formatNumber(value/1440, "f0")+" dagen";
-					return  '<span style="margin: 4px; margin-top: 6px; float: right;">' + duration + '</span>';
-				  }
-				},
-				{ text: 'IBU', datafield: 'ibu', width: 80, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var ibu = toIBU(rowdata.h_useat, rowdata.h_form, preboil_sg, parseFloat($("#batch_size").jqxNumberInput('decimal')),
-							  parseFloat(rowdata.h_amount), parseFloat(rowdata.h_time),
-							  parseFloat(rowdata.h_alpha), $("#ibu_method").val());
-					return  '<span style="margin: 4px; margin-top: 6px; float: right;">' + dataAdapter.formatNumber(ibu, "f1") + '</span>';
-				  }
-				},
-				{ text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var amount = dataAdapter.formatNumber(value, "f1") + ' kg';
-					if (value < 1)
-						amount = dataAdapter.formatNumber(value * 1000, "f1") + ' gr';
-					return  '<span style="margin: 4px; margin-top: 6px; float: right;">' + amount + '</span>';
-				  }
-				},
-				{ text: 'Voorraad', datafield: 'h_inventory', width: 110, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var color = '#ffffff';
-					if (value < rowdata.h_amount)
-						color = '#ff4040';
-					var amount = dataAdapter.formatNumber(value, "f1") + ' kg';
-					if (value < 1)
-						amount = dataAdapter.formatNumber(value * 1000, "f1") + ' gr';
-					return  '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
-				  }
-				},
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-					}, buttonclick: function (row) {
-						hopRow = row;
-						hopData = $("#hopGrid").jqxGrid('getrowdata', hopRow);
-						$("#wh_name").val(hopData.h_name);
-						$("#wh_amount").val(hopData.h_amount * 1000);
-						var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg,
-							parseFloat($("#batch_size").jqxNumberInput('decimal')),
-							parseFloat(hopData.h_amount), parseFloat(hopData.h_time),
-							parseFloat(hopData.h_alpha), $("#ibu_method").val()
-						);
-						$("#wh_ibu").val(ibu);
-						if (hopData.h_useat == 5)	// Dry hop
-							$("#wh_time").val(hopData.h_time / 1440);
-						else
-							$("#wh_time").val(hopData.h_time);
-						$("#wh_useat").val(hopData.h_useat);
-						// show the popup window.
-						$("#popupHop").jqxWindow('open');
-					}
-				}
-                        ]
-                });
-        };
+  $('#color_method').on('change', function(event) {
+   dataRecord.color_method = event.args.index;
+   calcFermentables();
+  });
+  $('#ibu_method').on('change', function(event) {
+   dataRecord.ibu_method = event.args.index;
+   calcFermentables();
+   calcIBUs();
+  });
+  $('#batch_size').on('change', function(event) {
+   console.log('batch_size change:' + event.args.value + ' old:' + dataRecord.batch_size);
+   var factor, new_boil = parseFloat(event.args.value) + dataRecord.boil_size - dataRecord.batch_size;
+   factor = parseFloat(event.args.value) / dataRecord.batch_size;
+   dataRecord.boil_size = new_boil;
+   $('#boil_size').val(Round(new_boil, 2));
+   dataRecord.sparge_volume *= factor;
+   $('#sparge_volume').val(dataRecord.sparge_volume);
+   dataRecord.batch_size = parseFloat(event.args.value);
+   calcFermentablesFromOG(parseFloat($('#est_og').jqxNumberInput('decimal')));     // Keep the OG
+   adjustWaters(factor);
+   calcFermentables();
+   adjustHops(factor);
+   adjustMiscs(factor);
+   adjustYeasts(factor);
+   calcIBUs();
+   calcWater();
+   calcSparge();
+   calcMash();
+  });
+  $('#boil_time').on('change', function(event) {
+   console.log('boil_time change:' + parseFloat(event.args.value) + ' old:' + dataRecord.boil_time);
+   var new_boil, new_evap, old_evap = parseFloat(dataRecord.boil_size) - parseFloat(dataRecord.batch_size);
+   new_evap = old_evap * (parseFloat(event.args.value) / dataRecord.boil_time);
+   new_boil = parseFloat(dataRecord.batch_size) + new_evap;
+   dataRecord.boil_time = parseFloat(event.args.value);
+   dataRecord.boil_size = new_boil;
+   $('#boil_size').val(Round(new_boil, 2));
+   calcFermentables();
+   // TODO: adjust the hops, miscs, yeast, water.
+   calcIBUs();
+  });
+  $('#efficiency').on('change', function(event) {
+   var estog = parseFloat($('#est_og').jqxNumberInput('decimal'));
+   dataRecord.efficiency = parseFloat(event.args.value);
+   console.log('efficiency change:' + dataRecord.efficiency);
+   calcFermentablesFromOG(estog);     // Keep the OG
+   calcFermentables();
+   calcIBUs();
+  });
+  $('#est_og').on('change', function(event) {
+   dataRecord.est_og = parseFloat(event.args.value);
+   console.log('est_og change:' + dataRecord.est_og);
+   calcFermentablesFromOG(dataRecord.est_og); // Adjust fermentables amounts
+   calcFermentables(); // Update the recipe details
+   calcIBUs();
+   calcMash();
+  });
+  $('#mash_ph').on('change', function(event) {
+   dataRecord.mash_ph = parseFloat(event.args.value);
+   calcWater();
+  });
 
-	// Inline miscs editor
-        var editMisc = function (data) {
-                var miscSource = {
-                        localdata: data.miscs,
-                        datatype: "local",
-                        cache: false,
-			async: false,
-                        datafields: [
-                                { name: 'm_name', type: 'string' },
-                                { name: 'm_amount', type: 'float' },
-                                { name: 'm_cost', type: 'float' },
-                                { name: 'm_type', type: 'int' },
-                                { name: 'm_use_use', type: 'int' },
-                                { name: 'm_time', type: 'float' },
-                                { name: 'm_amount_is_weight', type: 'int' },
-				{ name: 'm_inventory', type: 'float' },
-				{ name: 'm_avail', type: 'int' }
-                        ],
-                        addrow: function (rowid, rowdata, position, commit) {
-				console.log("misc addrow "+rowid);
-                                commit(true);
-                        },
-                        deleterow: function (rowid, commit) {
-				console.log("misc deleterow "+rowid);
-                                commit(true);
-                        },
-			updaterow: function (rowid, rowdata, commit) {
-				console.log("misc updaterow "+rowid);
-				commit(true);
-			}
-                };
-                var miscAdapter = new $.jqx.dataAdapter(miscSource, {
-			beforeLoadComplete: function (records) {
-				var data = new Array();
-				for (var i = 0; i < records.length; i++) {
-					var row = records[i];
-					data.push(row);
-					// Initial set water agent values.
-					switch (row.m_name) {
-						case 'CaCl2':		$("#wa_cacl2").val(row.m_amount * 1000);
-									break;
-						case 'CaSO4':		$("#wa_caso4").val(row.m_amount * 1000);
-									break;
-						case 'MgSO4':		$("#wa_mgso4").val(row.m_amount * 1000);
-									break;
-						case 'NaCl':		$("#wa_nacl").val(row.m_amount * 1000);
-									break;
-						case 'Melkzuur':	$("#wa_acid_name").val(0);
-									$("#wa_acid").val(row.m_amount * 1000);
-									$("#wa_acid_perc").val(80);
-									last_acid = 'Melkzuur';
-									break;
-						case 'Zoutzuur':	$("#wa_acid_name").val(1);
-									$("#wa_acid").val(row.m_amount * 1000);
-									$("#wa_acid_perc").val(80);
-									last_acid = 'Zoutzuur';
-									break;
-						case 'Fosforzuur':	$("#wa_acid_name").val(2);
-									$("#wa_acid").val(row.m_amount * 1000);
-									$("#wa_acid_perc").val(80);
-									last_acid = 'Fosforzuur';
-									break;
-						case 'Zwavelzuur':	$("#wa_acid_name").val(3);
-									$("#wa_acid").val(row.m_amount * 1000);
-									$("#wa_acid_perc").val(80);
-									last_acid = 'Zwavelzuur';
-									break;
-						case 'NaHCO3':		$("#wa_base_name").val(0);
-									$("#wa_base").val(row.m_amount * 1000);
-									last_base = 'NaHCO3';
-									break;
-						case 'Na2CO3':		$("#wa_base_name").val(1);
-									$("#wa_base").val(row.m_amount * 1000);
-									last_base = 'Na2CO3';
-									break;
-						case 'CaCO3':		$("#wa_base_name").val(2);
-									$("#wa_base").val(row.m_amount * 1000);
-									last_base = 'CaCO3';
-									break;
-						case 'Ca(OH)2':		$("#wa_base_name").val(3);
-									$("#wa_base").val(row.m_amount * 1000);
-									last_base = 'Ca(OH)2';
-									break;
-					}
-				}
-				return data;
-			},
-			loadError: function(jqXHR, status, error) {
-				$('#err').text(status + ' ' + error);
-			},
-		});
-                $("#miscGrid").jqxGrid({
-                        width: 1240,
-                        height: 575,
-                        source: miscAdapter,
-                        theme: theme,
-                        selectionmode: 'singlerow',
-                        showtoolbar: true,
-                        rendertoolbar: function (toolbar) {
-                                var me = this;
-                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
-                                toolbar.append(container);
-                                container.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');
-				container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
-				container.append('<div style="float: left; margin-left: 10px;" id="minstockbutton"></div>');
-                                container.append('<input style="float: left; margin-left: 400px;" id="mdeleterowbutton" type="button" value="Verwijder ingredi&euml;nt" />');
-                                // add misc from dropdownlist.
-                                $("#maddrowbutton").jqxDropDownList({
-                                        placeHolder: "Kies ingredi&euml;nt:",
-                                        theme: theme,
-					template: "primary",
-                                        source: misclist,
-                                        displayMember: "name",
-                                        width: 150,
-                                        height: 27,
-                                        dropDownWidth: 500,
-					dropDownHeight: 500
-                                });
-                                $("#maddrowbutton").on('select', function (event) {
-                                        if (event.args) {
-                                                var index = event.args.index;
-                                                var datarecord = misclist.records[index];
-                                                var row = {};
-                                                row["m_name"] = datarecord.name;
-                                                row["m_amount"] = 0;
-                                                row["m_cost"] = datarecord.cost;
-                                                row["m_type"] = datarecord.type;
-                                                row["m_use_use"] = datarecord.use_use;
-                                                row["m_time"] = 0;
-                                                row["m_amount_is_weight"] = datarecord.amount_is_weight;
-						row["m_inventory"] = datarecord.inventory;
-                                                var commit = $("#miscGrid").jqxGrid('addrow', null, row);
-                                        }
-                                });
-				$("#minstockbutton").jqxCheckBox({ theme: theme, height: 27 });
-				$("#minstockbutton").on('change', function (event) {
-					miscinstock = event.args.checked;
-					misclist.dataBind();
-				});
-                                // delete selected misc.
-                                $("#mdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150 });
-                                $("#mdeleterowbutton").on('click', function () {
-                                        var selectedrowindex = $("#miscGrid").jqxGrid('getselectedrowindex');
-                                        var rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount;
-					var type = $("#miscGrid").jqxGrid('getcellvalue', selectedrowindex, "m_type");
-                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount && type != 4) {	// Water agent
-                                                var id = $("#miscGrid").jqxGrid('getrowid', selectedrowindex);
-                                                var commit = $("#miscGrid").jqxGrid('deleterow', id);
-                                        }
-                                });
-                        },
-			ready: function() {
-				$('#jqxTabs').jqxTabs('next');
-			},
-			columns: [
-                                { text: 'Ingredient', datafield: 'm_name' },
-                                { text: 'Type', width: 140, datafield: 'm_type',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return "<span style='margin: 3px; margin-top: 6px; float: left;'>" + MiscTypeData[value].nl + "</span>";
-				  }
-			       	},
-                                { text: 'Gebruik', width: 140, datafield: 'm_use_use',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return "<span style='margin: 3px; margin-top: 6px; float: left;'>" + MiscUseData[value].nl + "</span>";
-				  }
-			       	},
-                                { text: 'Tijd', datafield: 'm_time', width: 90, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var duration = '';
-					if (rowdata.m_use_use == 2)     // Boil
-						duration = dataAdapter.formatNumber(value, "f0")+" min.";
-					else if ((rowdata.m_use_use == 3) || (rowdata.m_use_use == 4))  // Primary or Secondary
-						duration = dataAdapter.formatNumber(value/1440, "f0")+" dagen";
-					return  '<span style="margin: 4px; margin-top: 6px; float: right;">' + duration + '</span>';
-				  },
-                                },
-				{ text: 'Hoeveel', datafield: 'm_amount', width: 110, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var vstr = rowdata.m_amount_is_weight ? "gr":"ml";
-					return  '<span style="margin: 4px; margin-top: 6px; float: right;">' +
-						dataAdapter.formatNumber(value * 1000,"f2")+" "+vstr + '</span>';
-				  },
-				},
-				{ text: 'Voorraad', datafield: 'm_inventory', width: 110, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var vstr = rowdata.m_amount_is_weight ? "gr":"ml";
-					var color = '#ffffff';
-					if (value < rowdata.m_amount)
-						color = '#ff4040';
-					var amount = dataAdapter.formatNumber(value * 1000,"f2")+" "+vstr;
-					return  '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
-				  },
-				},
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-					}, buttonclick: function (row) {
-						miscRow = row;
-						miscData = $("#miscGrid").jqxGrid('getrowdata', miscRow);
-						if (miscData.m_type == 4) {
-							alert("Brouwzouten wijzigen in de water tab.");
-						} else {
-							if (miscData.m_amount_is_weight)
-								$("#wm_pmpt_amount").html("Gewicht gram:");
-							else
-								$("#wm_pmpt_amount").html("Volume ml:");
-							$("#wm_name").val(miscData.m_name);
-							$("#wm_amount").val(miscData.m_amount * 1000);
-							if ((miscData.m_use_use == 3) || (miscData.m_use_use == 4))	// Primary or Secondary
-								$("#wm_time").val(miscData.m_time / 1440);
-							else
-								$("#wm_time").val(miscData.m_time);
-							$("#wm_use_use").val(miscData.m_use_use);
-							// show the popup window.
-							$("#popupMisc").jqxWindow('open');
-						}
-					}
-				}
-                        ]
-                });
-        };
+  $('#sparge_ph').on('change', function(event) {
+   dataRecord.sparge_ph = parseFloat(event.args.value);
+   calcSparge();
+  });
+  $('#sparge_volume').on('change', function(event) {
+   dataRecord.sparge_volume = parseFloat(event.args.value);
+   calcSparge();
+  });
+  $('#sparge_source').on('change', function(event) {
+   if (event.args) {
+    var index = event.args.index;
+    dataRecord.sparge_source = index;
+    calcSparge();
+   }
+  });
+  $('#sparge_acid_type').on('change', function(event) {
+   if (event.args) {
+    var index = event.args.index;
+    dataRecord.sparge_acid_type = index;
+    console.log('new sparge_acid_type: ' + dataRecord.sparge_acid_type);
+    calcSparge();
+   }
+  });
+  $('#sparge_acid_perc').on('change', function(event) {
+   dataRecord.sparge_acid_perc = parseFloat(event.args.value);
+   calcSparge();
+  });
+  $('#locked').on('checked', function(event) {
+   dataRecord.locked = 1;
+   setReadonly(true);
+  });
+  $('#locked').on('unchecked', function(event) {
+   dataRecord.locked = 0;
+   setReadonly(false);
+  });
+ };
+
+ $('#styleSelect').jqxDropDownList({
+  placeHolder: 'Kies bierstijl:',
+  theme: theme,
+  source: styleslist,
+  displayMember: 'name',
+  width: 180,
+  height: 23,
+  dropDownVerticalAlignment: 'top',
+  dropDownWidth: 500,
+  dropDownHeight: 350,
+  renderer: function(index, label, value) {
+   var datarecord = styleslist.records[index];
+   return datarecord.style_guide + ' ' + datarecord.style_letter + ' ' + datarecord.name;
+  }
+ });
+ $('#styleSelect').on('select', function(event) {
+  if (event.args) {
+   var datarecord, index = event.args.index;
+   datarecord = styleslist.records[index];
+   $('#st_name').val(datarecord.name);
+   $('#st_category').val(datarecord.category);
+   $('#st_category_number').val(datarecord.category_number);
+   $('#st_letter').val(datarecord.style_letter);
+   $('#st_guide').val(datarecord.style_guide);
+   $('#st_type').val(StyleTypeData[datarecord.type].nl);
+   $('#st_og_min').val(datarecord.og_min);
+   $('#st_og_max').val(datarecord.og_max);
+   $('#st_fg_min').val(datarecord.fg_min);
+   $('#st_fg_max').val(datarecord.fg_max);
+   $('#st_ibu_min').val(datarecord.ibu_min);
+   $('#st_ibu_max').val(datarecord.ibu_max);
+   $('#st_color_min').val(datarecord.color_min);
+   $('#st_color_max').val(datarecord.color_max);
+   $('#st_carb_min').val(datarecord.carb_min);
+   $('#st_carb_max').val(datarecord.carb_max);
+   $('#st_abv_min').val(datarecord.abv_min);
+   $('#st_abv_max').val(datarecord.abv_max);
+  }
+ });
 
-	// Inline yeasts editor
-        var editYeast = function (data) {
-                var yeastSource = {
-                        localdata: data.yeasts,
-                        datatype: "local",
-                        cache: false,
-			async: false,
-                        datafields: [
-                                { name: 'y_name', type: 'string' },
-				{ name: 'y_laboratory', type: 'string' },
-				{ name: 'y_product_id', type: 'string' },
-                                { name: 'y_amount', type: 'float' },
-                                { name: 'y_cost', type: 'float' },
-                                { name: 'y_type', type: 'int' },
-                                { name: 'y_form', type: 'int' },
-				{ name: 'y_flocculation', type: 'int' },
-				{ name: 'y_min_temperature', type: 'float' },
-				{ name: 'y_max_temperature', type: 'float' },
-				{ name: 'y_attenuation', type: 'float' },
-				{ name: 'y_use', type: 'int' },
-				{ name: 'y_cells', type: 'float' },
-				{ name: 'y_tolerance', type: 'float' },
-				{ name: 'y_inventory', type: 'float' },
-				{ name: 'y_avail', type: 'int' }
-                        ],
-                        addrow: function (rowid, rowdata, position, commit) {
-				console.log("yeast addrow "+rowid);
-                                commit(true);
-                        },
-                        deleterow: function (rowid, commit) {
-				console.log("yeast deleterow "+rowid);
-                                commit(true);
-                        },
-			updaterow: function (rowid, rowdata, commit) {
-				console.log("yeast updaterow "+rowid);
-				commit(true);
-			}
-                };
-                var yeastAdapter = new $.jqx.dataAdapter(yeastSource);
-                $("#yeastGrid").jqxGrid({
-                        width: 1240,
-                        height: 350,
-                        source: yeastAdapter,
-                        theme: theme,
-                        selectionmode: 'singlerow',
-                        showtoolbar: true,
-                        rendertoolbar: function (toolbar) {
-                                var me = this;
-                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
-                                toolbar.append(container);
-                                container.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');
-				container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
-				container.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');
-                                container.append('<input style="float: left; margin-left: 400px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');
-                                // add yeast from dropdownlist.
-                                $("#yaddrowbutton").jqxDropDownList({
-                                        placeHolder: "Kies gist:",
-                                        theme: theme,
-					template: "primary",
-                                        source: yeastlist,
-                                        displayMember: "name",
-                                        width: 150,
-                                        height: 27,
-                                        dropDownWidth: 500,
-					dropDownHeight: 500,
-					renderer: function (index, label, value) {
-						var datarecord = yeastlist.records[index];
-						return datarecord.laboratory+" "+datarecord.product_id+" "+datarecord.name;
-					}
-                                });
-                                $("#yaddrowbutton").on('select', function (event) {
-                                        if (event.args) {
-                                                var index = event.args.index;
-                                                var datarecord = yeastlist.records[index];
-                                                var row = {};
-                                                row["y_name"] = datarecord.name;
-						row["y_laboratory"] = datarecord.laboratory;
-						row["y_product_id"] = datarecord.product_id;
-						row["y_type"] = datarecord.type;
-						row["y_form"] = datarecord.form;
-                                                row["y_amount"] = 0;
-                                                row["y_cost"] = datarecord.cost;
-                                                row["y_use"] = 0;
-						row["y_min_temperature"] = datarecord.min_temperature;
-						row["y_max_temperature"] = datarecord.max_temperature;
-						row["y_attenuation"] = datarecord.attenuation;
-						row["y_flocculation"] = datarecord.flocculation;
-						row["y_cells"] = datarecord.cells;
-						row["y_tolerance"] = datarecord.tolerance;
-						row["y_inventory"] = datarecord.inventory;
-                                                var commit = $("#yeastGrid").jqxGrid('addrow', null, row);
-                                        }
-					$("#yaddrowbutton").jqxDropDownList('clearSelection');
-                                });
-				$("#yinstockbutton").jqxCheckBox({ theme: theme, height: 27 });
-				$("#yinstockbutton").on('change', function (event) {
-					yeastinstock = event.args.checked;
-					yeastlist.dataBind();
-				});
-                                // delete selected yeast.
-                                $("#ydeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150 });
-                                $("#ydeleterowbutton").on('click', function () {
-                                        var selectedrowindex = $("#yeastGrid").jqxGrid('getselectedrowindex');
-                                        var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
-                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
-                                                var id = $("#yeastGrid").jqxGrid('getrowid', selectedrowindex);
-                                                var commit = $("#yeastGrid").jqxGrid('deleterow', id);
-                                        }
-                                });
-                        },
-			ready: function() {
-				calcFermentables();
-				$('#jqxTabs').jqxTabs('next');
-			},
-                        columns: [
-                                { text: 'Gist', datafield: 'y_name' },
-				{ text: 'Laboratorium', width: 150, datafield: 'y_laboratory' },
-				{ text: 'Code', width: 90, datafield: 'y_product_id' },
-                                { text: 'Soort', width: 100, datafield: 'y_form',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return  '<span style="margin: 4px; margin-top: 6px; float: left;">' + YeastFormData[value].nl + '</span>';
-				  }
-				},
-				{ text: 'Min. &deg;C', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_min_temperature' },
-				{ text: 'Max. &deg;C', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_max_temperature' },
-				{ text: 'Tol. %', width: 60, align: 'right', cellsalign: 'right', datafield: 'y_tolerance',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var color = '#ffffff';
-					var amount = "";
-					if (value > 0) {
-						amount = dataAdapter.formatNumber(value, "f1");
-						if (dataRecord.est_abv > value)
-							color = '#ff4040';
-					}
-					return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
-				  }
-				},
-				{ text: 'Attn. %', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_attenuation', cellsformat: 'f1' },
-				{ text: 'Voor', width: 120, datafield: 'y_use',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return  '<span style="margin: 4px; margin-top: 6px; float: left;">' + YeastUseData[value].nl + '</span>';
-				  }
-				},
-				{ text: 'Hoeveel', datafield: 'y_amount', width: 90, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var amount = dataAdapter.formatNumber(value*1000, "f0")+" ml";
-					if (rowdata.y_form == 0)        // Liquid
-						amount = dataAdapter.formatNumber(value, "f0")+" pk";
-					else if (rowdata.y_form == 1)   // Dry
-						amount = dataAdapter.formatNumber(value*1000, "f1")+" gr";
-					return  '<span style="margin: 4px; margin-top: 6px; float: right;">' + amount + '</span>';
-                                  }
-                                },
-				{ text: 'Voorraad', datafield: 'y_inventory', width: 90, align: 'right',
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var color = '#ffffff';
-					if (value < rowdata.y_amount)
-						color = '#ff4040';
-					var amount = dataAdapter.formatNumber(value*1000, "f0")+" ml";
-					if (rowdata.y_form == 0)        // Liquid
-						amount = dataAdapter.formatNumber(value, "f0")+" pk";
-					else if (rowdata.y_form == 1)   // Dry
-						amount = dataAdapter.formatNumber(value*1000, "f1")+" gr";
-					return  '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + amount + '</span>';
-				  }
-				},
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 90, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-					}, buttonclick: function (row) {
-						yeastRow = row;
-						yeastData = $("#yeastGrid").jqxGrid('getrowdata', yeastRow);
-						if (yeastData.y_form == 0) {
-							$("#wy_pmpt_amount").html("Pak(ken):");
-							$("#wy_amount").val(yeastData.y_amount);
-							$("#wy_amount").jqxNumberInput({ decimalDigits: 0 });
-						} else if (yeastData.y_form == 1) {
-							$("#wy_pmpt_amount").html("Gewicht gram:");
-							$("#wy_amount").val(yeastData.y_amount * 1000);
-							$("#wy_amount").jqxNumberInput({ decimalDigits: 1 });
-						} else {
-							$("#wy_pmpt_amount").html("Volume ml:");
-							$("#wy_amount").val(yeastData.y_amount * 1000);
-							$("#wy_amount").jqxNumberInput({ decimalDigits: 0 });
-						}
-						$("#wy_name").val(yeastData.y_name);
-						$("#wy_laboratory").val(yeastData.y_laboratory);
-						$("#wy_product_id").val(yeastData.y_product_id);
-						$("#wy_use").val(yeastData.y_use);
-						// show the popup window.
-						$("#popupYeast").jqxWindow('open');
-					}
-				}
-                        ]
-                });
-        };
+ function saveRecord() {
+  var row = {
+   record: my_record,
+   uuid: dataRecord.uuid,
+   name: $('#name').val(),
+   locked: dataRecord.locked,
+   notes: $('#notes').val(),
+   st_name: $('#st_name').val(),
+   st_letter: $('#st_letter').val(),
+   st_guide: $('#st_guide').val(),
+   st_type: dataRecord.st_type,
+   st_category: $('#st_category').val(),
+   st_category_number: parseFloat($('#st_category_number').jqxNumberInput('decimal')),
+   st_og_min: parseFloat($('#st_og_min').jqxNumberInput('decimal')),
+   st_og_max: parseFloat($('#st_og_max').jqxNumberInput('decimal')),
+   st_fg_min: parseFloat($('#st_fg_min').jqxNumberInput('decimal')),
+   st_fg_max: parseFloat($('#st_fg_max').jqxNumberInput('decimal')),
+   st_ibu_min: parseFloat($('#st_ibu_min').jqxNumberInput('decimal')),
+   st_ibu_max: parseFloat($('#st_ibu_max').jqxNumberInput('decimal')),
+   st_color_min: parseFloat($('#st_color_min').jqxNumberInput('decimal')),
+   st_color_max: parseFloat($('#st_color_max').jqxNumberInput('decimal')),
+   st_carb_min: parseFloat($('#st_carb_min').jqxNumberInput('decimal')),
+   st_carb_max: parseFloat($('#st_carb_max').jqxNumberInput('decimal')),
+   st_abv_min: parseFloat($('#st_abv_min').jqxNumberInput('decimal')),
+   st_abv_max: parseFloat($('#st_abv_max').jqxNumberInput('decimal')),
+   type: $('#type').val(),
+   batch_size: parseFloat($('#batch_size').jqxNumberInput('decimal')),
+   boil_size: parseFloat($('#boil_size').jqxNumberInput('decimal')),
+   boil_time: parseFloat($('#boil_time').jqxNumberInput('decimal')),
+   efficiency: parseFloat($('#efficiency').jqxNumberInput('decimal')),
+   est_og: parseFloat($('#est_og').jqxNumberInput('decimal')),
+   est_fg: parseFloat($('#est_fg').jqxNumberInput('decimal')),
+   est_abv: parseFloat($('#est_abv').jqxNumberInput('decimal')),
+   est_color: parseFloat($('#est_color').jqxNumberInput('decimal')),
+   color_method: $('#color_method').val(),
+   est_ibu: parseFloat($('#est_ibu').jqxNumberInput('decimal')),
+   ibu_method: $('#ibu_method').val(),
+   est_carb: parseFloat($('#est_carb').jqxNumberInput('decimal')),
+   mash_name: $('#mash_name').val(),
+   mash_ph: parseFloat($('#mash_ph').jqxNumberInput('decimal')),
+   sparge_temp: parseFloat($('#sparge_temp').jqxNumberInput('decimal')),
+   sparge_ph: parseFloat($('#sparge_ph').jqxNumberInput('decimal')),
+   sparge_volume: parseFloat($('#sparge_volume').jqxNumberInput('decimal')),
+   sparge_source: $('#sparge_source').val(),
+   sparge_acid_type: $('#sparge_acid_type').val(),
+   sparge_acid_perc: parseFloat($('#sparge_acid_perc').jqxNumberInput('decimal')),
+   sparge_acid_amount: dataRecord.sparge_acid_amount,
+   calc_acid: dataRecord.calc_acid,
+   w1_name: $('#w1_name').val(),
+   w1_amount: parseFloat($('#w1_amount').jqxNumberInput('decimal')),
+   w1_calcium: parseFloat($('#w1_calcium').jqxNumberInput('decimal')),
+   w1_sulfate: parseFloat($('#w1_sulfate').jqxNumberInput('decimal')),
+   w1_chloride: parseFloat($('#w1_chloride').jqxNumberInput('decimal')),
+   w1_sodium: parseFloat($('#w1_sodium').jqxNumberInput('decimal')),
+   w1_magnesium: parseFloat($('#w1_magnesium').jqxNumberInput('decimal')),
+   w1_total_alkalinity: parseFloat($('#w1_total_alkalinity').jqxNumberInput('decimal')),
+   w1_ph: parseFloat($('#w1_ph').jqxNumberInput('decimal')),
+   w1_cost: dataRecord.w1_cost,
+   w2_name: $('#w2_name').val(),
+   w2_amount: parseFloat($('#w2_amount').jqxNumberInput('decimal')),
+   w2_calcium: parseFloat($('#w2_calcium').jqxNumberInput('decimal')),
+   w2_sulfate: parseFloat($('#w2_sulfate').jqxNumberInput('decimal')),
+   w2_chloride: parseFloat($('#w2_chloride').jqxNumberInput('decimal')),
+   w2_sodium: parseFloat($('#w2_sodium').jqxNumberInput('decimal')),
+   w2_magnesium: parseFloat($('#w2_magnesium').jqxNumberInput('decimal')),
+   w2_total_alkalinity: parseFloat($('#w2_total_alkalinity').jqxNumberInput('decimal')),
+   w2_ph: parseFloat($('#w2_ph').jqxNumberInput('decimal')),
+   w2_cost: dataRecord.w2_cost,
+   wg_amount: parseFloat($('#wg_amount').jqxNumberInput('decimal')),
+   wg_calcium: parseFloat($('#wg_calcium').jqxNumberInput('decimal')),
+   wg_sulfate: parseFloat($('#wg_sulfate').jqxNumberInput('decimal')),
+   wg_chloride: parseFloat($('#wg_chloride').jqxNumberInput('decimal')),
+   wg_sodium: parseFloat($('#wg_sodium').jqxNumberInput('decimal')),
+   wg_magnesium: parseFloat($('#wg_magnesium').jqxNumberInput('decimal')),
+   wg_total_alkalinity: parseFloat($('#wg_total_alkalinity').jqxNumberInput('decimal')),
+   wg_ph: parseFloat($('#wg_ph').jqxNumberInput('decimal')),
+   wb_calcium: parseFloat($('#wb_calcium').jqxNumberInput('decimal')),
+   wb_sulfate: parseFloat($('#wb_sulfate').jqxNumberInput('decimal')),
+   wb_chloride: parseFloat($('#wb_chloride').jqxNumberInput('decimal')),
+   wb_sodium: parseFloat($('#wb_sodium').jqxNumberInput('decimal')),
+   wb_magnesium: parseFloat($('#wb_magnesium').jqxNumberInput('decimal')),
+   wb_total_alkalinity: parseFloat($('#wb_total_alkalinity').jqxNumberInput('decimal')),
+   wb_ph: parseFloat($('#wb_ph').jqxNumberInput('decimal')),
+   wa_acid_name: $('#wa_acid_name').val(),
+   wa_acid_perc: parseFloat($('#wa_acid_perc').jqxNumberInput('decimal')),
+   wa_base_name: $('#wa_base_name').val(),
+   fermentables: $('#fermentableGrid').jqxGrid('getrows'),
+   hops: $('#hopGrid').jqxGrid('getrows'),
+   miscs: $('#miscGrid').jqxGrid('getrows'),
+   yeasts: $('#yeastGrid').jqxGrid('getrows'),
+   mashs: $('#mashGrid').jqxGrid('getrows')
+  },
+  data = 'update=true&' + $.param(row);
+  $.ajax({
+   dataType: 'json',
+   url: url,
+   cache: false,
+   async: false,
+   data: data,
+   type: 'POST',
+   success: function(data, status, xhr) {
+    console.log('saveRecord() success');
+   },
+   error: function(jqXHR, textStatus, errorThrown) {
+    console.log('saveRecord() error');
+   }
+  });
+ };
 
-	// inline mash editor
-        var editMash = function (data) {
-		var generaterow = function () {
-			var row = {};
-			row["step_name"] = "Stap 1";
-			row["step_type"] = 0;
-			row["step_infuse_amount"] = 15;
-			row["step_temp"] = 62.0;
-			row['step_time'] = 20.0;
-			row['step_thickness'] = 0;
-			row['ramp_time'] = 1.0;
-			row['end_temp'] = 62.0;
-			return row;
-		}
-                var mashSource = {
-                        localdata: data.mashs,
-                        datatype: "local",
-                        cache: false,
-			async: false,
-                        datafields: [
-                                { name: 'step_name', type: 'string' },
-                                { name: 'step_type', type: 'int' },
-				{ name: 'step_infuse_amount', type: 'float' },
-				{ name: 'step_temp', type: 'float' },
-				{ name: 'step_time', type: 'float' },
-				{ name: 'step_thickness', type: 'float' },
-				{ name: 'ramp_time', type: 'float' },
-				{ name: 'end_temp', type: 'float' }
-                        ],
-                        addrow: function (rowid, rowdata, position, commit) {
-                                commit(true);
-                        },
-                        deleterow: function (rowid, commit) {
-                                commit(true);
-                        }
-                };
-                var mashAdapter = new $.jqx.dataAdapter(mashSource, {
-			beforeLoadComplete: function (records) {
-				mash_infuse = 0;
-				var data = new Array();
-				for (var i = 0; i < records.length; i++) {
-					var row = records[i];
-					if (row.step_type == 0)	// Infusion
-						mash_infuse += parseFloat(row.step_infuse_amount);
-					row.step_thickness = 0;	// Init this field.
-					data.push(row);
-				}
-			},	
-		});
-                $("#mashGrid").jqxGrid({
-                        width: 1240,
-                        height: 400,
-                        source: mashAdapter,
-                        theme: theme,
-                        selectionmode: 'singlerow',
-                        showtoolbar: true,
-                        rendertoolbar: function (toolbar) {
-                                var me = this;
-                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
-                                toolbar.append(container);
-                                container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');
-                                container.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder stap" />');
-				$("#saddrowbutton").jqxButton({ template: "primary", theme: theme, height: 27, width: 150 });
-				$("#saddrowbutton").on('click', function () {
-					var datarow = generaterow();
-					var commit = $("#mashGrid").jqxGrid('addrow', null, datarow);
-				});
-                                // delete selected yeast.
-                                $("#sdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150 });
-                                $("#sdeleterowbutton").on('click', function () {
-                                        var selectedrowindex = $("#mashGrid").jqxGrid('getselectedrowindex');
-                                        var rowscount = $("#mashGrid").jqxGrid('getdatainformation').rowscount;
-                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
-                                                var id = $("#mashGrid").jqxGrid('getrowid', selectedrowindex);
-                                                var commit = $("#mashGrid").jqxGrid('deleterow', id);
-                                        }
-                                });
-                        },
-			ready: function() {
-				calcFermentables();
-				calcInit();
-				calcMash();
-				$('#jqxLoader').jqxLoader('close');
-				$('#jqxTabs').jqxTabs('first');
-			},
-                        columns: [
-				{ text: 'Stap naam', datafield: 'step_name' },
-			        { text: 'Stap type', datafield: 'step_type', width: 175,
-				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					return "<div style='margin: 4px;'>" + MashStepTypeData[value].nl + "</div>";
-				  }
-				},
-				{ text: 'Start &deg;C', datafield: 'step_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
-				{ text: 'Eind &deg;C', datafield: 'end_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
-				{ text: 'Rust min.', datafield: 'step_time', width: 90, align: 'right', cellsalign: 'right' },
-				{ text: 'Stap min.', datafield: 'ramp_time', width: 90, align: 'right', cellsalign: 'right' },
-				{ text: 'Infuse L.', datafield: 'step_infuse_amount', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
-				{ text: 'L/Kg.', datafield: 'step_thickness', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f2' },
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-					}, buttonclick: function (row) {
-						mashRow = row;
-						mashData = $("#mashGrid").jqxGrid('getrowdata', mashRow);
-						$("#wstep_name").val(mashData.step_name);
-						$("#wstep_type").val(mashData.step_type);
-						$("#wstep_infuse_amount").val(mashData.step_infuse_amount);
-						$("#wstep_temp").val(mashData.step_temp);
-						$("#wend_temp").val(mashData.end_temp);
-						$("#wstep_time").val(mashData.step_time);
-						$("#wramp_time").val(mashData.ramp_time);
-						if (mashData.step_type == 0) {
-							$("#wstep_infuse_amount").show();
-							$("#wstep_pmpt").show();
-						} else {
-							$("#wstep_infuse_amount").hide();
-							$("#wstep_pmpt").hide();
-						}
-						// show the popup window.
-						$("#popupMash").jqxWindow('open');
-					}
-				}
-                        ]
-                });
-        };
+ dataAdapter.dataBind();
+
+ // initialize the input fields.
+ // Tab 1, Algemeen
+ $('#name').jqxTooltip({ content: 'De naam voor dit recept.' });
+ $('#name').jqxInput({ theme: theme, width: 640, height: 23 });
+ $('#locked').jqxCheckBox({ theme: theme, width: 120, height: 23 });
+ $('#notes').jqxTooltip({ content: 'De uitgebreide opmerkingen over dit recept.' });
+ $('#notes').jqxInput({ theme: theme, width: 960, height: 200 });
+ $('#type').jqxTooltip({ content: 'Het brouw type van dit recept.' });
+ $('#type').jqxDropDownList({
+  theme: theme,
+  source: RecipeTypeAdapter,
+  valueMember: 'id',
+  displayMember: 'nl',
+  width: 180,
+  height: 23,
+  autoDropDownHeight: true
+ });
+ $('#efficiency').jqxTooltip({ content: 'Het rendement van maischen en koken.' });
+ $('#efficiency').jqxNumberInput(Perc1dec);
+ $('#batch_size').jqxTooltip({ content: 'Het volume van het gekoelde wort na het koken.' });
+ $('#batch_size').jqxNumberInput(Spin1dec);
+ $('#batch_size').jqxNumberInput({ min: 4 });
+ $('#boil_size').jqxTooltip({ content: 'Het volume van het wort voor het koken.' });
+ $('#boil_size').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 90, height: 23, decimalDigits: 2, readOnly: true });
+ $('#boil_time').jqxTooltip({ content: 'De kooktijd in minuten.' });
+ $('#boil_time').jqxNumberInput(PosInt);
+ $('#boil_time').jqxNumberInput({ min: 4, max: 360 });
+
+ $('#st_name').jqxTooltip({ content: 'De bierstijl naam voor dit recept.'});
+ $('#st_name').jqxInput({ theme: theme, width: 250, height: 23 });
+ $('#st_letter').jqxTooltip({ content: 'De bierstijl letter voor dit recept.'});
+ $('#st_letter').jqxInput({ theme: theme, width: 90, height: 23 });
+ $('#st_guide').jqxTooltip({ content: 'De bierstijl gids voor dit recept.'});
+ $('#st_guide').jqxInput({ theme: theme, width: 250, height: 23 });
+ $('#st_category').jqxTooltip({ content: 'De Amerikaanse bierstijl categorie.'});
+ $('#st_category').jqxInput({ theme: theme, width: 250, height: 23 });
+ $('#st_category_number').jqxTooltip({ content: 'De Amerikaanse bierstijl categorie sub nummer.'});
+ $('#st_category_number').jqxNumberInput(Smal0dec);
+ $('#st_type').jqxTooltip({ content: 'Het bierstijl type.'});
+ $('#st_type').jqxInput({ theme: theme, width: 250, height: 23 });
+
+ $('#est_og').jqxTooltip({ content: 'Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend.' });
+ $('#est_og').jqxNumberInput(SGopts);
+ $('#st_og_min').jqxTooltip({ content: 'Het minimum begin SG voor deze bierstijl.'});
+ $('#st_og_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
+ $('#st_og_max').jqxTooltip({ content: 'Het maximum begin SG voor deze bierstijl.'});
+ $('#st_og_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
 
-	// initialize the input fields.
-	// Tab 1, Algemeen
-	$("#name").jqxTooltip({ content: 'De naam voor dit recept.' });
-	$("#name").jqxInput({ theme: theme, width: 640, height: 23 });
-	$("#locked").jqxCheckBox({ theme: theme, width: 120, height: 23 });
-	$("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit recept.' });
-	$("#notes").jqxInput({ theme: theme, width: 960, height: 200 });
-	$("#type").jqxTooltip({ content: 'Het brouw type van dit recept.' });
-	$("#type").jqxDropDownList({
-		theme: theme,
-		source: RecipeTypeAdapter,
-		valueMember: 'id',
-		displayMember: 'nl',
-		width: 180,
-		height: 23,
-		autoDropDownHeight: true
-	});
-	$("#efficiency").jqxTooltip({ content: 'Het rendement van maischen en koken.' });
-	$("#efficiency").jqxNumberInput( Perc1dec );
-	$("#batch_size").jqxTooltip({ content: 'Het volume van het gekoelde wort na het koken.' });
-	$("#batch_size").jqxNumberInput( Spin1dec );
-	$("#batch_size").jqxNumberInput({ min: 4 });
-	$("#boil_size").jqxTooltip({ content: 'Het volume van het wort voor het koken.' });
-	$("#boil_size").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 90, height: 23, decimalDigits: 2, readOnly: true });
-	$("#boil_time").jqxTooltip({ content: 'De kooktijd in minuten.' });
-	$("#boil_time").jqxNumberInput( PosInt );
-	$("#boil_time").jqxNumberInput({ min: 4, max: 360 });
+ $('#est_fg').jqxTooltip({ content: 'Het eind SG. Dit wordt automatisch berekend.' });
+ $('#est_fg').jqxNumberInput(Show3dec);
+ $('#st_fg_min').jqxTooltip({ content: 'Het minimum eind SG voor deze bierstijl.'});
+ $('#st_fg_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
+ $('#st_fg_max').jqxTooltip({ content: 'Het maximum eind SG voor deze bierstijl.'});
+ $('#st_fg_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
 
-	$("#st_name").jqxTooltip({ content: 'De bierstijl naam voor dit recept.'});
-	$("#st_name").jqxInput({ theme: theme, width: 250, height: 23 });
-	$("#st_letter").jqxTooltip({ content: 'De bierstijl letter voor dit recept.'});
-	$("#st_letter").jqxInput({ theme: theme, width: 90, height: 23 });
-	$("#st_guide").jqxTooltip({ content: 'De bierstijl gids voor dit recept.'});
-	$("#st_guide").jqxInput({ theme: theme, width: 250, height: 23 });
-	$("#st_category").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie.'});
-	$("#st_category").jqxInput({ theme: theme, width: 250, height: 23 });
-	$("#st_category_number").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie sub nummer.'});
-	$("#st_category_number").jqxNumberInput( Smal0dec );
-	$("#st_type").jqxTooltip({ content: 'Het bierstijl type.'});
-	$("#st_type").jqxInput({ theme: theme, width: 250, height: 23 });
-
-	$("#est_og").jqxTooltip({ content: 'Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend.' });
-	$("#est_og").jqxNumberInput( SGopts );
-	$("#st_og_min").jqxTooltip({ content: 'Het minimum begin SG voor deze bierstijl.'});
-	$("#st_og_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
-	$("#st_og_max").jqxTooltip({ content: 'Het maximum begin SG voor deze bierstijl.'});
-	$("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
+ $('#est_abv').jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
+ $('#est_abv').jqxNumberInput(Smal1dec);
+ $('#st_abv_min').jqxTooltip({ content: 'Het minimum alcohol volume % voor deze bierstijl.'});
+ $('#st_abv_min').jqxNumberInput(Smal1dec);
+ $('#st_abv_max').jqxTooltip({ content: 'Het maximum alcohol volume % voor deze bierstijl.'});
+ $('#st_abv_max').jqxNumberInput(Smal1dec);
 
-	$("#est_fg").jqxTooltip({ content: 'Het eind SG. Dit wordt automatisch berekend.' });
-	$("#est_fg").jqxNumberInput( Show3dec );
-	$("#st_fg_min").jqxTooltip({ content: 'Het minimum eind SG voor deze bierstijl.'});
-	$("#st_fg_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
-	$("#st_fg_max").jqxTooltip({ content: 'Het maximum eind SG voor deze bierstijl.'});
-	$("#st_fg_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
-
-	$("#est_abv").jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
-	$("#est_abv").jqxNumberInput( Smal1dec );
-	$("#st_abv_min").jqxTooltip({ content: 'Het minimum alcohol volume % voor deze bierstijl.'});
-	$("#st_abv_min").jqxNumberInput( Smal1dec );
-	$("#st_abv_max").jqxTooltip({ content: 'Het maximum alcohol volume % voor deze bierstijl.'});
-	$("#st_abv_max").jqxNumberInput( Smal1dec );
-
-	$("#est_color").jqxTooltip({ content: 'De kleur in EBC. Dit wordt automatisch berekend.' });
-	$("#est_color").jqxNumberInput( Show0dec );
-	$("#st_color_min").jqxTooltip({ content: 'De minimum kleur voor deze bierstijl.'});
-	$("#st_color_min").jqxNumberInput( Smal0dec );
-	$("#st_color_max").jqxTooltip({ content: 'De maximum kleur voor deze bierstijl.'});
-	$("#st_color_max").jqxNumberInput( Smal0dec );
-	$("#color_method").jqxDropDownList({
-		theme: theme,
-		source: ColorMethodAdapter,
-		valueMember: 'id',
-		displayMember: 'nl',
-		width: 180,
-		height: 23,
-		autoDropDownHeight: true
-	});
-	$("#est_ibu").jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
-	$("#est_ibu").jqxNumberInput( Show0dec );
-	$("#st_ibu_min").jqxTooltip({ content: 'De minimum bitterheid voor deze bierstijl.'});
-	$("#st_ibu_min").jqxNumberInput( Smal0dec );
-	$("#st_ibu_max").jqxTooltip({ content: 'De maximum bitterheid voor deze bierstijl.'});
-	$("#st_ibu_max").jqxNumberInput( Smal0dec );
-	$("#ibu_method").jqxDropDownList({
-		theme: theme,
-		source: IBUmethodAdapter,
-		valueMember: 'id',
-		displayMember: 'nl',
-		width: 180,
-		height: 23,
-		autoDropDownHeight: true,
-		dropDownVerticalAlignment: 'top'
-	});
-	$("#kcal").jqxTooltip({ content: 'Energie-inhoud in kcal/liter.' });
-	$("#kcal").jqxNumberInput( Smal0dec );
-	$("#est_carb").jqxTooltip({ content: 'Koolzuur volume. Dit wordt automatisch berekend.' });
-	$("#est_carb").jqxNumberInput( Smal1dec );
-	$("#st_carb_min").jqxTooltip({ content: 'Het minimum koolzuur volume voor deze bierstijl.'});
-	$("#st_carb_min").jqxNumberInput( Smal1dec );
-	$("#st_carb_max").jqxTooltip({ content: 'Het maximum koolzuur volume voor deze bierstijl.'});
-	$("#st_carb_max").jqxNumberInput( Smal1dec );
+ $('#est_color').jqxTooltip({ content: 'De kleur in EBC. Dit wordt automatisch berekend.' });
+ $('#est_color').jqxNumberInput(Show0dec);
+ $('#st_color_min').jqxTooltip({ content: 'De minimum kleur voor deze bierstijl.'});
+ $('#st_color_min').jqxNumberInput(Smal0dec);
+ $('#st_color_max').jqxTooltip({ content: 'De maximum kleur voor deze bierstijl.'});
+ $('#st_color_max').jqxNumberInput(Smal0dec);
+ $('#color_method').jqxDropDownList({
+  theme: theme,
+  source: ColorMethodAdapter,
+  valueMember: 'id',
+  displayMember: 'nl',
+  width: 180,
+  height: 23,
+  autoDropDownHeight: true
+ });
+ $('#est_ibu').jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
+ $('#est_ibu').jqxNumberInput(Show0dec);
+ $('#st_ibu_min').jqxTooltip({ content: 'De minimum bitterheid voor deze bierstijl.'});
+ $('#st_ibu_min').jqxNumberInput(Smal0dec);
+ $('#st_ibu_max').jqxTooltip({ content: 'De maximum bitterheid voor deze bierstijl.'});
+ $('#st_ibu_max').jqxNumberInput(Smal0dec);
+ $('#ibu_method').jqxDropDownList({
+  theme: theme,
+  source: IBUmethodAdapter,
+  valueMember: 'id',
+  displayMember: 'nl',
+  width: 180,
+  height: 23,
+  autoDropDownHeight: true,
+  dropDownVerticalAlignment: 'top'
+ });
+ $('#kcal').jqxTooltip({ content: 'Energie-inhoud in kcal/liter.' });
+ $('#kcal').jqxNumberInput(Smal0dec);
+ $('#est_carb').jqxTooltip({ content: 'Koolzuur volume. Dit wordt automatisch berekend.' });
+ $('#est_carb').jqxNumberInput(Smal1dec);
+ $('#st_carb_min').jqxTooltip({ content: 'Het minimum koolzuur volume voor deze bierstijl.'});
+ $('#st_carb_min').jqxNumberInput(Smal1dec);
+ $('#st_carb_max').jqxTooltip({ content: 'Het maximum koolzuur volume voor deze bierstijl.'});
+ $('#st_carb_max').jqxNumberInput(Smal1dec);
 
-	// Tab 2, Vergistbaar
-	$("#est_color2").jqxTooltip({ content: 'De kleur in EBC. Dit wordt automatisch berekend.' });
-	$("#est_color2").jqxNumberInput( Show0dec );
-	$("#est_og2").jqxTooltip({ content: 'Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend.' });
-	$("#est_og2").jqxNumberInput( Show3dec );
-	$("#perc_malts").jqxProgressBar({
-		width: 300,
-		height: 23,
-		theme: theme,
-		showText: true,
-		max: 120,
-		animationDuration: 0,
-		colorRanges: [
-			{ stop:  90, color: '#008C00' },
-			{ stop: 100, color: '#EB7331' },
-			{ stop: 120, color: '#FF0000' }
-		],
-		renderText: function (text) {
-			return (Math.round(parseInt(text) * 1.2)) + '%';
-		}
-	});
-	$("#perc_sugars").jqxProgressBar({
-		width: 300,
-		height: 23,
-		theme: theme,
-		showText: true,
-		max: 50,
-		animationDuration: 0,
-		colorRanges: [
-			{ stop: 20, color: '#008C00' },
-			{ stop: 50, color: '#FF0000' }
-		],
-		renderText: function (text) {
-			return (Math.round(parseInt(text) * 5) / 10) + '%';
-		}
-	});
-	$("#perc_cara").jqxProgressBar({
-		width: 300,
-		height: 23,
-		theme: theme,
-		showText: true,
-		max: 50,
-		animationDuration: 0,
-		colorRanges: [
-			{ stop: 25, color: '#008C00' },
-			{ stop: 50, color: '#FF0000' }
-		],
-		renderText: function (text) {
-			return (Math.round(parseInt(text) * 5) / 10) + '%';
-		}
-	});
-        $("#ferm_lintner").jqxProgressBar({
-                width: 300,
-                height: 23,
-                theme: theme,
-                showText: true,
-                max: 200,
-                animationDuration: 0,
-                colorRanges: [
-                        { stop:  30, color: '#FF0000' },
-                        { stop:  40, color: '#EB7331' },
-                        { stop: 200, color: '#008C00' }
-                ],
-                renderText: function (text) {
-                        return (parseInt(text) * 2) + ' lintner';
-                }
-        });
-	$("#popupFermentable").jqxWindow({
-		width: 800,
-		height: 300,
-		position: { x: 230, y: 100 },
-		resizable: false,
-		theme: theme,
-		isModal: true,
-		autoOpen: false,
-		cancelButton: $("#FermentableReady"),
-		modalOpacity: 0.40
-	});
-	$("#FermentableReady").jqxButton({ template: "success", width: '90px', theme: theme });
-	$("#FermentableReady").click(function () {
-		var rowID = $("#fermentableGrid").jqxGrid('getrowid', fermentableRow);
-		console.log("FermentableReady row:"+fermentableRow+" ID:"+rowID);
-		var row = {
-			f_name: fermentableData.f_name,
-			f_origin: fermentableData.f_origin,
-			f_supplier: fermentableData.f_supplier,
-			f_amount: fermentableData.f_amount,
-			f_cost: fermentableData.f_cost,
-			f_type: fermentableData.f_type,
-			f_yield: fermentableData.f_yield,
-			f_color: fermentableData.f_color,
-			f_coarse_fine_diff: fermentableData.f_coarse_fine_diff,
-			f_moisture: fermentableData.f_moisture,
-			f_diastatic_power: fermentableData.f_diastatic_power,
-			f_protein: fermentableData.f_protein,
-			f_max_in_batch: fermentableData.f_max_in_batch,
-			f_graintype: fermentableData.f_graintype,
-			f_added: fermentableData.f_added,
-			f_dissolved_protein: fermentableData.f_dissolved_protein,
-			f_recommend_mash: fermentableData.f_recommend_mash,
-			f_add_after_boil: fermentableData.f_add_after_boil,
-			f_adjust_to_total_100: fermentableData.f_adjust_to_total_100,
-			f_percentage: fermentableData.f_percentage,
-			f_di_ph: fermentableData.f_di_ph,
-			f_acid_to_ph_57: fermentableData.f_acid_to_ph_57,
-			f_inventory: fermentableData.f_inventory,
-			f_avail: fermentableData.f_avail
-		};
-		$("#fermentableGrid").jqxGrid('updaterow', rowID, row);
-		calcPercentages();
-		calcFermentables();
-		calcIBUs();
-		calcMash();
-		// Waters: yes there is impact.
-	});
-	$("#wf_name").jqxInput({ theme: theme, width: 320, height: 23 });
-	$("#wf_instock").jqxCheckBox({ theme: theme, height: 23 });
-	$("#wf_instock").on('change', function (event) {
-		fermentableinstock = event.args.checked;
-		fermentablelist.dataBind();
-	});
-	$("#wf_select").jqxDropDownList({
-		placeHolder: "Kies mout:",
-		theme: theme,
-		source: fermentablelist,
-		displayMember: "name",
-		width: 150,
-		height: 23,
-		dropDownWidth: 500,
-		dropDownHeight: 500,
-		renderer: function (index, label, value) {
-			var datarecord = fermentablelist.records[index];
-			return datarecord.supplier+ " / " + datarecord.name + " (" + datarecord.color + " EBC)";
-		}
-	});
-	$("#wf_select").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			var datarecord = fermentablelist.records[index];
-			$("#wf_name").val(datarecord.name);
-			fermentableData.f_name = datarecord.name;
-			fermentableData.f_origin = datarecord.origin;
-			fermentableData.f_supplier = datarecord.supplier;
-			fermentableData.f_type = datarecord.type;
-			fermentableData.f_cost = datarecord.cost;
-			fermentableData.f_yield = datarecord.yield;
-			fermentableData.f_color = datarecord.color;
-			fermentableData.f_coarse_fine_diff = datarecord.coarse_fine_diff;
-			fermentableData.f_moisture = datarecord.moisture;
-			fermentableData.f_diastatic_power = datarecord.diastatic_power;
-			fermentableData.f_protein = datarecord.protein;
-			fermentableData.f_max_in_batch = datarecord.max_in_batch;
-			fermentableData.f_graintype = datarecord.graintype;
-			fermentableData.f_dissolved_protein = datarecord.dissolved_protein;
-			fermentableData.f_recommend_mash = datarecord.recommend_mash;
-			fermentableData.f_add_after_boil = datarecord.add_after_boil;
-			fermentableData.f_di_ph = datarecord.di_ph;
-			fermentableData.f_acid_to_ph_57 = datarecord.acid_to_ph_57;
-			fermentableData.f_inventory = datarecord.inventory;
-		}
-	});
-	$("#wf_amount").jqxNumberInput( Spin3dec );
-	$('#wf_amount').on('change', function (event) {
-		console.log("amount changed: "+event.args.value);
-		$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value);
-		fermentableData.f_amount = event.args.value;
-		if (! to_100) {
-			calcPercentages();
-			calcFermentables();
-			calcMash();
-		};
-	});
-	$("#wf_percentage").jqxNumberInput( Perc1dec );
-	$("#wf_percentage").on('change', function (event) {
-		var oldvalue = Math.round(fermentableData.f_percentage * 10) / 10.0;
-		var newvalue = event.args.value;
-		console.log("percentage changed: "+newvalue+" old: "+oldvalue);
-		fermentableData.f_percent = newvalue;
-		var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-		if ((oldvalue != newvalue) && (rowscount > 1)) {
-			var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
-			if (rowdata.f_adjust_to_total_100) {
-				$("#wf_percentage").val(oldvalue);
-			} else {
-				var diff = newvalue - oldvalue;
-				var tw = 0;     // total weight
-				for (i = 0; i < rowscount; i++) {
-					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-					if (rowdata.f_added < 4)
-						tw += Math.round(rowdata.f_amount * 1000) / 1000;
-				}
-				tw = Math.round(tw * 1000) / 1000;
-				if (to_100) {
-					// Adjust this row and the 100% row.
-					var damount = Math.round(tw * diff *10) / 1000;
-					var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
-					var namount = Math.round((rowdata.f_amount + damount) * 1000) / 1000;					
-					$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount);
-					$("#wf_amount").val(namount);
-					$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff);
-					for (i = 0; i < rowscount; i++) {
-						var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-						if (rowdata.f_adjust_to_total_100) {
-							namount = rowdata.f_amount - damount;
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', rowdata.f_percentage - diff);
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
-						}
-					}
-					calcFermentables();
-					cacMash();
-				} else {
-					// Adjust all the rows.
-					var nw = tw * diff / 100;
-					for (i = 0; i < rowscount; i++) {
-						var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
-						if (rowdata.f_added < 4) {
-							if (i == fermentableRow) {
-								var namount = Math.round((rowdata.f_amount + nw) * 1000) / 1000;
-								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
-		//						$("#wf_amount").val(namount); // Will crash the script.
-								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newvalue);
-							} else {
-								var namount = Math.round((rowdata.f_amount - (nw / (rowscount - 1))) * 1000) / 1000;
-								var newperc = Math.round((namount / tw) * 1000) / 10.0;
-								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', namount);
-								$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', newperc);
-							}
-						} else {
-							$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_percentage', 0);
-						}
-					}
-					calcFermentables();
-					calcMash();
-				}
-			}
-		}
+ // Tab 2, Vergistbaar
+ $('#est_color2').jqxTooltip({ content: 'De kleur in EBC. Dit wordt automatisch berekend.' });
+ $('#est_color2').jqxNumberInput(Show0dec);
+ $('#est_og2').jqxTooltip({ content: 'Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend.' });
+ $('#est_og2').jqxNumberInput(Show3dec);
+ $('#perc_malts').jqxProgressBar({
+  width: 300,
+  height: 23,
+  theme: theme,
+  showText: true,
+  max: 120,
+  animationDuration: 0,
+  colorRanges: [
+   { stop: 90, color: '#008C00' },
+   { stop: 100, color: '#EB7331' },
+   { stop: 120, color: '#FF0000' }
+  ],
+  renderText: function(text) {
+   return (Math.round(parseInt(text) * 1.2)) + '%';
+  }
+ });
+ $('#perc_sugars').jqxProgressBar({
+  width: 300,
+  height: 23,
+  theme: theme,
+  showText: true,
+  max: 50,
+  animationDuration: 0,
+  colorRanges: [
+   { stop: 20, color: '#008C00' },
+   { stop: 50, color: '#FF0000' }
+  ],
+  renderText: function(text) {
+   return (Math.round(parseInt(text) * 5) / 10) + '%';
+  }
+ });
+ $('#perc_cara').jqxProgressBar({
+  width: 300,
+  height: 23,
+  theme: theme,
+  showText: true,
+  max: 50,
+  animationDuration: 0,
+  colorRanges: [
+   { stop: 25, color: '#008C00' },
+   { stop: 50, color: '#FF0000' }
+  ],
+  renderText: function(text) {
+   return (Math.round(parseInt(text) * 5) / 10) + '%';
+  }
+ });
+ $('#ferm_lintner').jqxProgressBar({
+  width: 300,
+  height: 23,
+  theme: theme,
+  showText: true,
+  max: 200,
+  animationDuration: 0,
+  colorRanges: [
+   { stop: 30, color: '#FF0000' },
+   { stop: 40, color: '#EB7331' },
+   { stop: 200, color: '#008C00' }
+  ],
+  renderText: function(text) {
+   return (parseInt(text) * 2) + ' lintner';
+  }
+ });
+ $('#popupFermentable').jqxWindow({
+  width: 800,
+  height: 300,
+  position: { x: 230, y: 100 },
+  resizable: false,
+  theme: theme,
+  isModal: true,
+  autoOpen: false,
+  cancelButton: $('#FermentableReady'),
+  modalOpacity: 0.40
+ });
+ $('#FermentableReady').jqxButton({ template: 'success', width: '90px', theme: theme });
+ $('#FermentableReady').click(function() {
+  var row, rowID = $('#fermentableGrid').jqxGrid('getrowid', fermentableRow);
+  console.log('FermentableReady row:' + fermentableRow + ' ID:' + rowID);
+  row = {
+   f_name: fermentableData.f_name,
+   f_origin: fermentableData.f_origin,
+   f_supplier: fermentableData.f_supplier,
+   f_amount: fermentableData.f_amount,
+   f_cost: fermentableData.f_cost,
+   f_type: fermentableData.f_type,
+   f_yield: fermentableData.f_yield,
+   f_color: fermentableData.f_color,
+   f_coarse_fine_diff: fermentableData.f_coarse_fine_diff,
+   f_moisture: fermentableData.f_moisture,
+   f_diastatic_power: fermentableData.f_diastatic_power,
+   f_protein: fermentableData.f_protein,
+   f_max_in_batch: fermentableData.f_max_in_batch,
+   f_graintype: fermentableData.f_graintype,
+   f_added: fermentableData.f_added,
+   f_dissolved_protein: fermentableData.f_dissolved_protein,
+   f_recommend_mash: fermentableData.f_recommend_mash,
+   f_add_after_boil: fermentableData.f_add_after_boil,
+   f_adjust_to_total_100: fermentableData.f_adjust_to_total_100,
+   f_percentage: fermentableData.f_percentage,
+   f_di_ph: fermentableData.f_di_ph,
+   f_acid_to_ph_57: fermentableData.f_acid_to_ph_57,
+   f_inventory: fermentableData.f_inventory,
+   f_avail: fermentableData.f_avail
+  };
+  $('#fermentableGrid').jqxGrid('updaterow', rowID, row);
+  calcPercentages();
+  calcFermentables();
+  calcIBUs();
+  calcMash();
+  // Waters: yes there is impact.
+ });
+ $('#wf_name').jqxInput({ theme: theme, width: 320, height: 23 });
+ $('#wf_instock').jqxCheckBox({ theme: theme, height: 23 });
+ $('#wf_instock').on('change', function(event) {
+  fermentableinstock = event.args.checked;
+  fermentablelist.dataBind();
+ });
+ $('#wf_select').jqxDropDownList({
+  placeHolder: 'Kies mout:',
+  theme: theme,
+  source: fermentablelist,
+  displayMember: 'name',
+  width: 150,
+  height: 23,
+  dropDownWidth: 500,
+  dropDownHeight: 500,
+  renderer: function(index, label, value) {
+   var datarecord = fermentablelist.records[index];
+   return datarecord.supplier + ' / ' + datarecord.name + ' (' + datarecord.color + ' EBC)';
+  }
+ });
+ $('#wf_select').on('select', function(event) {
+  if (event.args) {
+   var datarecord, index = event.args.index;
+   datarecord = fermentablelist.records[index];
+   $('#wf_name').val(datarecord.name);
+   fermentableData.f_name = datarecord.name;
+   fermentableData.f_origin = datarecord.origin;
+   fermentableData.f_supplier = datarecord.supplier;
+   fermentableData.f_type = datarecord.type;
+   fermentableData.f_cost = datarecord.cost;
+   fermentableData.f_yield = datarecord.yield;
+   fermentableData.f_color = datarecord.color;
+   fermentableData.f_coarse_fine_diff = datarecord.coarse_fine_diff;
+   fermentableData.f_moisture = datarecord.moisture;
+   fermentableData.f_diastatic_power = datarecord.diastatic_power;
+   fermentableData.f_protein = datarecord.protein;
+   fermentableData.f_max_in_batch = datarecord.max_in_batch;
+   fermentableData.f_graintype = datarecord.graintype;
+   fermentableData.f_dissolved_protein = datarecord.dissolved_protein;
+   fermentableData.f_recommend_mash = datarecord.recommend_mash;
+   fermentableData.f_add_after_boil = datarecord.add_after_boil;
+   fermentableData.f_di_ph = datarecord.di_ph;
+   fermentableData.f_acid_to_ph_57 = datarecord.acid_to_ph_57;
+   fermentableData.f_inventory = datarecord.inventory;
+  }
+ });
+ $('#wf_amount').jqxNumberInput(Spin3dec);
+ $('#wf_amount').on('change', function(event) {
+  console.log('amount changed: ' + event.args.value);
+  $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value);
+  fermentableData.f_amount = event.args.value;
+  if (! to_100) {
+   calcPercentages();
+   calcFermentables();
+   calcMash();
+  }
+ });
+ $('#wf_percentage').jqxNumberInput(Perc1dec);
+ $('#wf_percentage').on('change', function(event) {
+  var newperc, nw, damount, namount, rowscount, rowdata, diff, tw, i, newvalue,
+  oldvalue = Round(fermentableData.f_percentage, 1);
+  newvalue = event.args.value;
+  console.log('percentage changed: ' + newvalue + ' old: ' + oldvalue);
+  fermentableData.f_percent = newvalue;
+  rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+  if ((oldvalue != newvalue) && (rowscount > 1)) {
+   rowdata = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
+   if (rowdata.f_adjust_to_total_100) {
+    $('#wf_percentage').val(oldvalue);
+   } else {
+    diff = newvalue - oldvalue;
+    tw = 0; // total weight
+    for (i = 0; i < rowscount; i++) {
+     rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
+     if (rowdata.f_added < 4)
+      tw += Round(rowdata.f_amount, 3);
+    }
+    tw = Round(tw, 3);
+    if (to_100) {
+     // Adjust this row and the 100% row.
+     damount = Math.round(tw * diff * 10) / 1000;
+     rowdata = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
+     namount = Round((rowdata.f_amount + damount), 3);
+     $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount);
+     $('#wf_amount').val(namount);
+     $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff);
+     for (i = 0; i < rowscount; i++) {
+      rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
+      if (rowdata.f_adjust_to_total_100) {
+       namount = rowdata.f_amount - damount;
+       $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', rowdata.f_percentage - diff);
+       $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount);
+      }
+     }
+     calcFermentables();
+     calcMash();
+    } else {
+     // Adjust all the rows.
+     nw = tw * diff / 100;
+     for (i = 0; i < rowscount; i++) {
+      rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
+      if (rowdata.f_added < 4) {
+       if (i == fermentableRow) {
+        namount = Math.round((rowdata.f_amount + nw) * 1000) / 1000;
+        $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount);
+  //    $('#wf_amount').val(namount); // Will crash the script.
+        $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', newvalue);
+       } else {
+        namount = Round((rowdata.f_amount - (nw / (rowscount - 1))), 3);
+        newperc = Round((namount / tw) * 100, 1);
+        $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount);
+        $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', newperc);
+       }
+      } else {
+       $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', 0);
+      }
+     }
+     calcFermentables();
+     calcMash();
+    }
+   }
+  }
+ });
+ $('#wf_max_in_batch').jqxNumberInput(Show1dec);
+ $('#wf_adjust_to_total_100').jqxCheckBox({ theme: theme, width: 120, height: 23 });
+ $('#wf_adjust_to_total_100').on('checked', function(event) {
+  if (fermentableData.f_adjust_to_total_100 == 0) {
+   if (to_100) {
+    // Reset other flag first.
+    rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+    for (i = 0; i < rowscount; i++) {
+     if (i != fermentableRow) {
+      $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_adjust_to_total_100', 0);
+     }
+    }
+   }
+   $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 1);
+   calcFermentables();
+  }
+ });
+ $('#wf_adjust_to_total_100').on('unchecked', function(event) {
+  if (fermentableData.f_adjust_to_total_100 != 0) {
+   $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 0);
+   calcFermentables();
+  }
+ });
+ $('#wf_added').jqxDropDownList({
+  theme: theme,
+  source: AddedAdapter,
+  valueMember: 'id',
+  displayMember: 'nl',
+  width: 180,
+  height: 23,
+  autoDropDownHeight: true,
+  dropDownVerticalAlignment: 'top'
+ });
+ $('#wf_added').on('select', function(event) {
+  if (event.args) {
+   var index = event.args.index;
+   $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_added', index);
+   calcFermentables();
+   calcIBUs();
+   calcMash();
+  }
+ });
 
-	});
-	$("#wf_max_in_batch").jqxNumberInput( Show1dec );
-	$("#wf_adjust_to_total_100").jqxCheckBox({ theme: theme, width: 120, height: 23 });
-	$("#wf_adjust_to_total_100").on('checked', function (event) {
-		if (fermentableData.f_adjust_to_total_100 == 0) {
-			if (to_100) {
-				// Reset other flag first.
-				var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-				for (var i = 0; i < rowscount; i++) {
-					if (i != fermentableRow) {
-						$("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_adjust_to_total_100', 0);
-					}
-				}
-			}
-			$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 1);
-			calcFermentables();
-		}
-	});
-	$("#wf_adjust_to_total_100").on('unchecked', function (event) {
-		if (fermentableData.f_adjust_to_total_100 != 0) {
-			$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 0);
-			calcFermentables();
-		}
-	});
-	$("#wf_added").jqxDropDownList({
-		theme: theme,
-		source: AddedAdapter,
-		valueMember: 'id',
-		displayMember: 'nl',
-		width: 180,
-		height: 23,
-		autoDropDownHeight: true,
-		dropDownVerticalAlignment: 'top'
-	});
-	$("#wf_added").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_added', index);
-			calcFermentables();
-			calcIBUs();
-			calcMash();
-		}
-	});
+ // Tab 3, Hoppen
+ $('#est_ibu2').jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
+ $('#est_ibu2').jqxNumberInput(Smal0dec);
+ $('#hop_flavour').jqxProgressBar({
+  width: 300,
+  height: 23,
+  theme: theme,
+  showText: true,
+  animationDuration: 0,
+  colorRanges: [
+   { stop: 20, color: '#004D00' },
+   { stop: 40, color: '#008C00' },
+   { stop: 60, color: '#00BF00' },
+   { stop: 80, color: '#00FF00' },
+   { stop: 100, color: '#80FF80' }
+  ],
+  renderText: function(text) {
+   var val = parseInt(text);
+   if (val < 20)
+    return 'Weinig';
+   else if (val < 40)
+    return 'Matig';
+   else if (val < 60)
+    return 'Redelijk';
+   else if (val < 80)
+    return 'Veel';
+   else
+    return 'Zeer veel';
+  }
+ });
+ $('#hop_aroma').jqxProgressBar({
+  width: 300,
+  height: 23,
+  theme: theme,
+  showText: true,
+  animationDuration: 0,
+  colorRanges: [
+   { stop: 20, color: '#004D00' },
+   { stop: 40, color: '#008C00' },
+   { stop: 60, color: '#00BF00' },
+   { stop: 80, color: '#00FF00' },
+   { stop: 100, color: '#80FF80' }
+  ],
+  renderText: function(text) {
+   var val = parseInt(text);
+   if (val < 20)
+    return 'Weinig';
+   else if (val < 40)
+    return 'Matig';
+   else if (val < 60)
+    return 'Redelijk';
+   else if (val < 80)
+    return 'Veel';
+   else
+    return 'Zeer veel';
+  }
+ });
+ $('#popupHop').jqxWindow({
+  width: 800,
+  height: 300,
+  position: { x: 230, y: 100 },
+  resizable: false,
+  theme: theme,
+  isModal: true,
+  autoOpen: false,
+  cancelButton: $('#HopReady'),
+  modalOpacity: 0.40
+ });
+ $('#HopReady').jqxButton({ template: 'success', width: '90px', theme: theme });
+ $('#HopReady').click(function() {
+  var row, rowID = $('#hopGrid').jqxGrid('getrowid', hopRow);
+  console.log('HopReady row:' + hopRow + ' ID:' + rowID);
+  row = {
+   h_name: $('#wh_name').val(),
+   h_origin: hopData.h_origin,
+   h_amount: parseFloat($('#wh_amount').jqxNumberInput('decimal')) / 1000,
+   h_cost: hopData.h_cost,
+   h_type: hopData.h_type,
+   h_form: hopData.h_form,
+   h_useat: $('#wh_useat').val(),
+   h_time: hopData.h_time,
+   h_alpha: hopData.h_alpha,
+   h_beta: hopData.h_beta,
+   h_hsi: hopData.h_hsi,
+   h_humulene: hopData.h_humulene,
+   h_caryophyllene: hopData.h_caryophyllene,
+   h_cohumulone: hopData.h_cohumulone,
+   h_myrcene: hopData.h_myrcene,
+   h_total_oil: hopData.h_total_oil,
+   h_inventory: hopData.h_inventory,
+   h_avail: hopData.h_avail
+  };
+  $('#hopGrid').jqxGrid('updaterow', rowID, row);
+  calcIBUs();
+ });
+ $('#wh_name').jqxInput({ theme: theme, width: 320, height: 23 });
+ $('#wh_instock').jqxCheckBox({ theme: theme, height: 23 });
+ $('#wh_instock').on('change', function(event) {
+  hopinstock = event.args.checked;
+  hoplist.dataBind();
+ });
+ $('#wh_select').jqxDropDownList({
+  placeHolder: 'Kies hop:',
+  theme: theme,
+  source: hoplist,
+  displayMember: 'name',
+  width: 150,
+  height: 23,
+  dropDownWidth: 500,
+  dropDownHeight: 500,
+  renderer: function(index, label, value) {
+   var datarecord = hoplist.records[index];
+   return datarecord.origin + ' / ' + datarecord.name + ' (' + datarecord.alpha + ' % &alpha;)';
+  }
+ });
+ $('#wh_select').on('select', function(event) {
+  if (event.args) {
+   var datarecord, index = event.args.index;
+   datarecord = hoplist.records[index];
+   $('#wh_name').val(datarecord.name);
+   hopData.h_name = datarecord.name;
+   hopData.h_origin = datarecord.origin;
+   hopData.h_cost = datarecord.cost;
+   hopData.h_type = datarecord.type;
+   hopData.h_form = datarecord.form;
+   hopData.h_alpha = datarecord.alpha;
+   hopData.h_beta = datarecord.beta;
+   hopData.h_hsi = datarecord.hsi;
+   hopData.h_humulene = datarecord.humulene;
+   hopData.h_caryophyllene = datarecord.caryophyllene;
+   hopData.h_cohumulone = datarecord.cohumulone;
+   hopData.h_myrcene = datarecord.myrcene;
+   hopData.h_total_oil = datarecord.total_oil;
+   hopData.h_inventory = datarecord.inventory;
+  }
+ });
+ $('#wh_amount').jqxNumberInput(Spin1dec);
+ $('#wh_amount').on('change', function(event) {
+  var ibu, amount = parseFloat(event.args.value) / 1000;
+  ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
+   amount, parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val());
+  hopData.h_amount = amount;
+  console.log('amount changed: ' + event.args.value + ' time:' + hopData.h_time + ' alpha:' + hopData.h_alpha + ' IBU:' + ibu);
+  $('#wh_ibu').val(ibu);
+ });
+ $('#wh_ibu').jqxNumberInput(Show1dec);
+ $('#wh_time').jqxNumberInput(PosInt);
+ $('#wh_time').on('change', function(event) {
+  var ibu, newtime = parseFloat(event.args.value);
+  // Check limits and correct
+  if (hopData.h_useat == 2) { // Boil
+   if (newtime > parseFloat($('#boil_time').jqxNumberInput('decimal'))) {
+    newtime = parseFloat($('#boil_time').jqxNumberInput('decimal'));
+    $('#wh_time').val(newtime);
+   }
+   hopData.h_time = newtime;
+  } else if (hopData.h_useat == 4) { // Whirlpool
+   if (newtime > 120) {
+    newtime = 120;
+    $('#wh_time').val(newtime);
+   }
+   hopData.h_time = newtime;
+  } else if (hopData.h_useat == 5) { // Dry hop
+   if (newtime > 21) {
+    newtime = 21;
+    $('#wh_time').val(newtime);
+   }
+   hopData.h_time = newtime * 1440;
+  }
+  ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
+   parseFloat(hopData.h_amount), parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $('#ibu_method').val());
+  $('#wh_ibu').val(ibu);
+ });
+ $('#wh_useat').jqxDropDownList({
+  theme: theme,
+  source: HopUseAdapter,
+  valueMember: 'id',
+  displayMember: 'nl',
+  width: 180,
+  height: 23,
+  autoDropDownHeight: true,
+  dropDownVerticalAlignment: 'top'
+ });
+ $('#wh_useat').on('select', function(event) {
+  if (event.args) {
+   var index = event.args.index;
+   hopData.h_useat = index;
+   if ((index == 0) || (index == 1)) { // Mashhop or First wort hop
+    hopData.h_time = parseFloat(dataRecord.boil_time);
+    $('#wh_time').jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
+    $('#wh_time').val(hopData.h_time);
+   } else if (index == 3) { // Aroma
+    hopData.h_time = 0;
+    $('#wh_time').jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
+    $('#wh_time').val(0);
+   } else { // Boil, Whirlpool or Dry hop
+    $('#wh_time').jqxNumberInput({ spinButtons: true, readOnly: false, width: 110 });
+   }
+   if (index == 5) // Dry hop
+    $('#wh_pmpt_time').html('Tijd in dagen');
+   else
+    $('#wh_pmpt_time').html('Tijd in minuten');
+  }
+ });
 
-	// Tab 3, Hoppen
-	$("#est_ibu2").jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
-	$("#est_ibu2").jqxNumberInput( Smal0dec );
-	$("#hop_flavour").jqxProgressBar({
-		width: 300,
-		height: 23,
-		theme: theme,
-		showText: true,
-		animationDuration: 0,
-		colorRanges: [
-			{ stop:  20, color: '#004D00' },
-			{ stop:  40, color: '#008C00' },
-			{ stop:  60, color: '#00BF00' },
-			{ stop:  80, color: '#00FF00' },
-			{ stop: 100, color: '#80FF80' }
-		],
-                renderText: function (text) {
-                        var val = parseInt(text);
-                        if (val < 20)
-                                return 'Weinig';
-                        else if (val < 40)
-                                return 'Matig';
-                        else if (val < 60)
-                                return 'Redelijk';
-                        else if (val < 80)
-                                return 'Veel';
-                        else
-                                return 'Zeer veel';
-                }
-	});
-	$("#hop_aroma").jqxProgressBar({
-		width: 300,
-		height: 23,
-		theme: theme,
-		showText: true,
-		animationDuration: 0,
-		colorRanges: [
-			{ stop:  20, color: '#004D00' },
-			{ stop:  40, color: '#008C00' },
-			{ stop:  60, color: '#00BF00' },
-			{ stop:  80, color: '#00FF00' },
-			{ stop: 100, color: '#80FF80' }
-		],
-                renderText: function (text) {
-                        var val = parseInt(text);
-                        if (val < 20)
-                                return 'Weinig';
-                        else if (val < 40)
-                                return 'Matig';
-                        else if (val < 60)
-                                return 'Redelijk';
-                        else if (val < 80)
-                                return 'Veel';
-                        else
-                                return 'Zeer veel';
-                }
-	});
-	$("#popupHop").jqxWindow({
-		width: 800,
-		height: 300,
-		position: { x: 230, y: 100 },
-		resizable: false,
-		theme: theme,
-		isModal: true,
-		autoOpen: false,
-		cancelButton: $("#HopReady"),
-		modalOpacity: 0.40
-	});
-	$("#HopReady").jqxButton({ template: "success", width: '90px', theme: theme });
-	$("#HopReady").click(function () {
-		var rowID = $("#hopGrid").jqxGrid('getrowid', hopRow);
-		console.log("HopReady row:"+hopRow+" ID:"+rowID);
-		var row = {
-			h_name: $("#wh_name").val(),
-			h_origin: hopData.h_origin,
-			h_amount: parseFloat($("#wh_amount").jqxNumberInput('decimal')) / 1000,
-			h_cost: hopData.h_cost,
-			h_type: hopData.h_type,
-			h_form: hopData.h_form,
-			h_useat: $("#wh_useat").val(),
-			h_time: hopData.h_time,
-			h_alpha: hopData.h_alpha,
-			h_beta: hopData.h_beta,
-			h_hsi: hopData.h_hsi,
-			h_humulene: hopData.h_humulene,
-			h_caryophyllene: hopData.h_caryophyllene,
-			h_cohumulone: hopData.h_cohumulone,
-			h_myrcene: hopData.h_myrcene,
-			h_total_oil: hopData.h_total_oil,
-			h_inventory: hopData.h_inventory,
-			h_avail: hopData.h_avail
-		};
-		$("#hopGrid").jqxGrid('updaterow', rowID, row);
-		calcIBUs();
-	});
-	$("#wh_name").jqxInput({ theme: theme, width: 320, height: 23 });
-	$("#wh_instock").jqxCheckBox({ theme: theme, height: 23 });
-	$("#wh_instock").on('change', function (event) {
-		hopinstock = event.args.checked;
-		hoplist.dataBind();
-	});
-	$("#wh_select").jqxDropDownList({
-		placeHolder: "Kies hop:",
-		theme: theme,
-		source: hoplist,
-		displayMember: "name",
-		width: 150,
-		height: 23,
-		dropDownWidth: 500,
-		dropDownHeight: 500,
-		renderer: function (index, label, value) {
-			var datarecord = hoplist.records[index];
-			return datarecord.origin+ " / " + datarecord.name + " (" + datarecord.alpha + " % &alpha;)";
-		}
-	});
-	$("#wh_select").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			var datarecord = hoplist.records[index];
-			$("#wh_name").val(datarecord.name);
-			hopData.h_name = datarecord.name;
-			hopData.h_origin = datarecord.origin;
-			hopData.h_cost = datarecord.cost;
-			hopData.h_type = datarecord.type;
-			hopData.h_form = datarecord.form;
-			hopData.h_alpha = datarecord.alpha;
-			hopData.h_beta = datarecord.beta;
-			hopData.h_hsi = datarecord.hsi;
-			hopData.h_humulene = datarecord.humulene;
-			hopData.h_caryophyllene = datarecord.caryophyllene;
-			hopData.h_cohumulone = datarecord.cohumulone;
-			hopData.h_myrcene = datarecord.myrcene;
-			hopData.h_total_oil = datarecord.total_oil;
-			hopData.h_inventory = datarecord.inventory;
-		}
-	});
-	$("#wh_amount").jqxNumberInput( Spin1dec );
-	$('#wh_amount').on('change', function (event) {
-		console.log("amount changed: "+event.args.value+" time:"+hopData.h_time+" alpha:"+hopData.h_alpha);
-		var amount = parseFloat(event.args.value) / 1000;
-
-		var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg,
-			parseFloat($("#batch_size").jqxNumberInput('decimal')),
-			amount, parseFloat(hopData.h_time),
-			parseFloat(hopData.h_alpha), $("#ibu_method").val()
-		);
-		hopData.h_amount = amount;
-		$("#wh_ibu").val(ibu);
-	});
-	$("#wh_ibu").jqxNumberInput( Show1dec );
-	$("#wh_time").jqxNumberInput( PosInt );
-	$("#wh_time").on('change', function (event) {
-		var newtime = parseFloat(event.args.value);
-		// Check limits and correct
-		if (hopData.h_useat == 2) {	// Boil
-			if (newtime > parseFloat($("#boil_time").jqxNumberInput('decimal'))) {
-				newtime = parseFloat($("#boil_time").jqxNumberInput('decimal'));
-				$("#wh_time").val(newtime);
-			}
-			hopData.h_time = newtime;
-		} else if (hopData.h_useat == 4) {	// Whirlpool
-			if (newtime > 120) {
-				newtime = 120;
-				$("#wh_time").val(newtime);
-			}
-			hopData.h_time = newtime;
-		} else if (hopData.h_useat == 5) {	// Dry hop
-			if (newtime > 21) {
-				newtime = 21;
-				$("#wh_time").val(newtime);
-			}
-			hopData.h_time = newtime * 1440;
-		}
-		var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($("#batch_size").jqxNumberInput('decimal')),
-			parseFloat(hopData.h_amount), parseFloat(hopData.h_time), parseFloat(hopData.h_alpha), $("#ibu_method").val());
-		$("#wh_ibu").val(ibu);
-	});
-	$("#wh_useat").jqxDropDownList({
-		theme: theme,
-		source: HopUseAdapter,
-		valueMember: 'id',
-		displayMember: 'nl',
-		width: 180,
-		height: 23,
-		autoDropDownHeight: true,
-		dropDownVerticalAlignment: 'top'
-	});
-	$("#wh_useat").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			hopData.h_useat = index;
-			if ((index == 0) || (index == 1)) {	// Mashhop or First wort hop
-				hopData.h_time = parseFloat(dataRecord.boil_time);
-				$("#wh_time").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
-				$("#wh_time").val(hopData.h_time);
-			} else if (index == 3) {	// Aroma
-				hopData.h_time = 0;
-				$("#wh_time").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
-				$("#wh_time").val(0);
-			} else {	// Boil, Whirlpool or Dry hop
-				$("#wh_time").jqxNumberInput({ spinButtons: true, readOnly: false, width: 110 });
-			}
-			if (index == 5)	// Dry hop
-				$("#wh_pmpt_time").html("Tijd in dagen");
-			else
-				$("#wh_pmpt_time").html("Tijd in minuten");
-		}
-	});
-
-	// Tab 4, Diversen
-	$("#popupMisc").jqxWindow({
-		width: 800,
-		height: 275,
-		position: { x: 230, y: 100 },
-		resizable: false,
-		theme: theme,
-		isModal: true,
-		autoOpen: false,
-		cancelButton: $("#MiscReady"),
-		modalOpacity: 0.40
-	});
-	$("#MiscReady").jqxButton({ template: "success", width: '90px', theme: theme });
-	$("#MiscReady").click(function () {
-		var rowID = $("#miscGrid").jqxGrid('getrowid', miscRow);
-		console.log("MiscReady row:"+miscRow+" ID:"+rowID);
-		var row = {
-			m_name: miscData.m_name,
-			m_amount: miscData.m_amount,
-			m_cost: miscData.m_cost,
-			m_type: miscData.m_type,
-			m_use_use: miscData.m_use_use,
-			m_time: miscData.m_time,
-			m_amount_is_weight: miscData.m_amount_is_weight,
-			m_inventory: miscData.m_inventory,
-			m_avail:  miscData.m_avail
-		};
-		$("#miscGrid").jqxGrid('updaterow', rowID, row);
-        });
-	$("#wm_name").jqxInput({ theme: theme, width: 320, height: 23 });
-	$("#wm_instock").jqxCheckBox({ theme: theme, height: 23 });
-	$("#wm_instock").on('change', function (event) {
-		miscinstock = event.args.checked;
-		misclist.dataBind();
-	});
-	$("#wm_select").jqxDropDownList({
-		placeHolder: "Kies ingredi&euml;nt:",
-		theme: theme,
-		source: misclist,
-		displayMember: "name",
-		width: 150,
-		height: 23,
-		dropDownWidth: 500,
-		dropDownHeight: 500
-	});
-	$("#wm_select").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			var datarecord = misclist.records[index];
-			$("#wm_name").val(datarecord.name);
-			miscData.m_name = datarecord.name;
-			miscData.m_cost = datarecord.cost;
-			miscData.m_type = datarecord.type;
-			miscData.m_use_use = datarecord.use_use;
-			miscData.m_amount_is_weight = datarecord.amount_is_weight;
-			miscData.m_inventory = datarecord.inventory;
-		}
-	});
-	$("#wm_amount").jqxNumberInput( Spin1dec );
-	$('#wm_amount').on('change', function (event) {
-		console.log("amount changed: "+event.args.value);
-		miscData.m_amount = parseFloat(event.args.value) / 1000;
-	});
-	$("#wm_time").jqxNumberInput( PosInt );
-	$("#wm_time").on('change', function (event) {
-		console.log("time changed: "+event.args.value);
-		var newtime = parseFloat(event.args.value);
+ // Tab 4, Diversen
+ $('#popupMisc').jqxWindow({
+  width: 800,
+  height: 275,
+  position: { x: 230, y: 100 },
+  resizable: false,
+  theme: theme,
+  isModal: true,
+  autoOpen: false,
+  cancelButton: $('#MiscReady'),
+  modalOpacity: 0.40
+ });
+ $('#MiscReady').jqxButton({ template: 'success', width: '90px', theme: theme });
+ $('#MiscReady').click(function() {
+  var row, rowID = $('#miscGrid').jqxGrid('getrowid', miscRow);
+  console.log('MiscReady row:' + miscRow + ' ID:' + rowID);
+  row = {
+   m_name: miscData.m_name,
+   m_amount: miscData.m_amount,
+   m_cost: miscData.m_cost,
+   m_type: miscData.m_type,
+   m_use_use: miscData.m_use_use,
+   m_time: miscData.m_time,
+   m_amount_is_weight: miscData.m_amount_is_weight,
+   m_inventory: miscData.m_inventory,
+   m_avail: miscData.m_avail
+  };
+  $('#miscGrid').jqxGrid('updaterow', rowID, row);
+ });
+ $('#wm_name').jqxInput({ theme: theme, width: 320, height: 23 });
+ $('#wm_instock').jqxCheckBox({ theme: theme, height: 23 });
+ $('#wm_instock').on('change', function(event) {
+  miscinstock = event.args.checked;
+  misclist.dataBind();
+ });
+ $('#wm_select').jqxDropDownList({
+  placeHolder: 'Kies ingredi&euml;nt:',
+  theme: theme,
+  source: misclist,
+  displayMember: 'name',
+  width: 150,
+  height: 23,
+  dropDownWidth: 500,
+  dropDownHeight: 500
+ });
+ $('#wm_select').on('select', function(event) {
+  if (event.args) {
+   var datarecord, index = event.args.index;
+   datarecord = misclist.records[index];
+   $('#wm_name').val(datarecord.name);
+   miscData.m_name = datarecord.name;
+   miscData.m_cost = datarecord.cost;
+   miscData.m_type = datarecord.type;
+   miscData.m_use_use = datarecord.use_use;
+   miscData.m_amount_is_weight = datarecord.amount_is_weight;
+   miscData.m_inventory = datarecord.inventory;
+  }
+ });
+ $('#wm_amount').jqxNumberInput(Spin1dec);
+ $('#wm_amount').on('change', function(event) {
+  console.log('amount changed: ' + event.args.value);
+  miscData.m_amount = parseFloat(event.args.value) / 1000;
+ });
+ $('#wm_time').jqxNumberInput(PosInt);
+ $('#wm_time').on('change', function(event) {
+  console.log('time changed: ' + event.args.value);
+  var newtime = parseFloat(event.args.value);
 
-		if (miscData.m_use_use == 2) {	// Boil
-			if (newtime > parseFloat($("#boil_time").jqxNumberInput('decimal'))) {
-				newtime = parseFloat($("#boil_time").jqxNumberInput('decimal'));
-				$("#wm_time").val(newtime);
-			}
-		        miscData.m_time = newtime;
-		} else if ((miscData.m_use_use == 3) || (miscData.m_use_use == 4)) {	// Primary or Secondary
-			if (newtime > 21) {
-				newtime = 21;
-				$("#wm_time").val(newtime);
-			}
-			miscData.m_time = newtime * 1440;
-		}
-	});
-	$("#wm_use_use").jqxDropDownList({
-		theme: theme,
-		source: MiscUseAdapter,
-		valueMember: 'id',
-		displayMember: 'nl',
-		width: 180,
-		height: 23,
-		autoDropDownHeight: true,
-		dropDownVerticalAlignment: 'top'
-	});
-	$("#wm_use_use").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			miscData.m_use_use = index;
-			if ((index == 2) || (index == 3) || (index == 4)) {	// Boil, Primary or Secondary
-				$("#wm_time").jqxNumberInput({ spinButtons: true, readOnly: false, width: 110 });
-			} else {
-				miscData.m_time = 0;
-				$("#wm_time").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
-				$("#wm_time").val(0);
-			}
-		}
-	});
+  if (miscData.m_use_use == 2) { // Boil
+   if (newtime > parseFloat($('#boil_time').jqxNumberInput('decimal'))) {
+    newtime = parseFloat($('#boil_time').jqxNumberInput('decimal'));
+    $('#wm_time').val(newtime);
+   }
+   miscData.m_time = newtime;
+  } else if ((miscData.m_use_use == 3) || (miscData.m_use_use == 4)) { // Primary or Secondary
+   if (newtime > 21) {
+    newtime = 21;
+    $('#wm_time').val(newtime);
+   }
+   miscData.m_time = newtime * 1440;
+  }
+ });
+ $('#wm_use_use').jqxDropDownList({
+  theme: theme,
+  source: MiscUseAdapter,
+  valueMember: 'id',
+  displayMember: 'nl',
+  width: 180,
+  height: 23,
+  autoDropDownHeight: true,
+  dropDownVerticalAlignment: 'top'
+ });
+ $('#wm_use_use').on('select', function(event) {
+  if (event.args) {
+   var index = event.args.index;
+   miscData.m_use_use = index;
+   if ((index == 2) || (index == 3) || (index == 4)) { // Boil, Primary or Secondary
+    $('#wm_time').jqxNumberInput({ spinButtons: true, readOnly: false, width: 110 });
+   } else {
+    miscData.m_time = 0;
+    $('#wm_time').jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
+    $('#wm_time').val(0);
+   }
+  }
+ });
 
-	// Tab 5, Gist
-	$("#est_fg2").jqxTooltip({ content: 'Het eind SG. Dit wordt automatisch berekend.' });
-	$("#est_fg2").jqxNumberInput( Show3dec );
-	$("#est_abv2").jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
-	$("#est_abv2").jqxNumberInput( Smal1dec );
-	$("#popupYeast").jqxWindow({
-		width: 800,
-		height: 300,
-		position: { x: 230, y: 100 },
-		resizable: false,
-		theme: theme,
-		isModal: true,
-		autoOpen: false,
-		cancelButton: $("#YeastReady"),
-		modalOpacity: 0.40
-	});
-	$("#YeastReady").jqxButton({ template: "success", width: '90px', theme: theme });
-	$("#YeastReady").click(function () {
-		var rowID = $("#yeastGrid").jqxGrid('getrowid', yeastRow);
-		console.log("YeastReady row:"+yeastRow+" ID:"+rowID);
-		var row = {
-			y_name: yeastData.y_name,
-			y_laboratory: yeastData.y_laboratory,
-			y_product_id: yeastData.y_product_id,
-			y_amount: yeastData.y_amount,
-			y_cost: yeastData.y_cost,
-			y_type: yeastData.y_type,
-			y_form: yeastData.y_form,
-			y_flocculation: yeastData.y_flocculation,
-			y_min_temperature: yeastData.y_min_temperature,
-			y_max_temperature: yeastData.y_max_temperature,
-			y_attenuation: yeastData.y_attenuation,
-			y_use: yeastData.y_use,
-			y_cells: yeastData.y_cells,
-			y_tolerance: yeastData.y_tolerance,
-			y_inventory: yeastData.y_inventory,
-			y_avail: yeastData.y_avail
-		};
-		$("#yeastGrid").jqxGrid('updaterow', rowID, row);
-		calcFermentables();
-	});
-	$("#wy_name").jqxInput({ theme: theme, width: 320, height: 23 });
-	$("#wy_laboratory").jqxInput({ theme: theme, width: 320, height: 23 });
-	$("#wy_product_id").jqxInput({ theme: theme, width: 320, height: 23 });
-	$("#wy_instock").jqxCheckBox({ theme: theme, height: 23 });
-	$("#wy_instock").on('change', function (event) {
-		yeastinstock = event.args.checked;
-		yeastlist.dataBind();
-	});
-	$("#wy_select").jqxDropDownList({
-		placeHolder: "Kies gist:",
-		theme: theme,
-		source: yeastlist,
-		displayMember: "name",
-		width: 150,
-		height: 23,
-		dropDownWidth: 500,
-		dropDownHeight: 500,
-		renderer: function (index, label, value) {
-			var datarecord = yeastlist.records[index];
-			return datarecord.laboratory+" "+datarecord.product_id+" "+datarecord.name;
-		}
-	});
-	$("#wy_select").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			var datarecord = yeastlist.records[index];
-			$("#wy_name").val(datarecord.name);
-			$("#wy_laboratory").val(datarecord.laboratory);
-			$("#wy_product_id").val(datarecord.product_id);
-			yeastData.y_name = datarecord.name;
-			yeastData.y_cost = datarecord.cost;
-			yeastData.y_type = datarecord.type;
-			yeastData.y_form = datarecord.form;
-			yeastData.y_laboratory = datarecord.laboratory;
-			yeastData.y_product_id = datarecord.product_id;
-			yeastData.y_min_temperature = datarecord.min_temperature;
-			yeastData.y_max_temperature = datarecord.max_temperature;
-			yeastData.y_flocculation = datarecord.flocculation;
-			yeastData.y_attenuation = datarecord.attenuation;
-			yeastData.y_cells = datarecord.cells;
-			yeastData.y_inventory = datarecord.inventory;
-			if (yeastData.y_form == 0) {
-				$("#wy_pmpt_amount").html("Pak(ken):");
-			} else if (yeastData.y_form == 1) {
-				$("#wy_pmpt_amount").html("Gewicht gram:");
-			} else {
-				$("#wy_pmpt_amount").html("Volume ml:");
-			}
-			calcFermentables();
-		}
-	});
-	$("#wy_amount").jqxNumberInput( Spin1dec );
-	$('#wy_amount').on('change', function (event) {
-		console.log("amount changed: "+event.args.value);
-		if (yeastData.y_form == 0)	// Liquid
-			var amount = parseFloat(event.args.value);
-		else
-			var amount = parseFloat(event.args.value) / 1000;
-		yeastData.y_amount = amount;
-		calcFermentables();
-	});
-	$("#wy_use").jqxDropDownList({
-		theme: theme,
-		source: YeastUseAdapter,
-		valueMember: 'id',
-		displayMember: 'nl',
-		width: 180,
-		height: 23,
-		autoDropDownHeight: true,
-		dropDownVerticalAlignment: 'top'
-	});
-	$("#wy_use").on('select', function (event) {
-		if (event.args) {
-			var index = event.args.index;
-			yeastData.y_use = index;
-			calcFermentabes();
-		}
-	});
+ // Tab 5, Gist
+ $('#est_fg2').jqxTooltip({ content: 'Het eind SG. Dit wordt automatisch berekend.' });
+ $('#est_fg2').jqxNumberInput(Show3dec);
+ $('#est_abv2').jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
+ $('#est_abv2').jqxNumberInput(Smal1dec);
+ $('#popupYeast').jqxWindow({
+  width: 800,
+  height: 300,
+  position: { x: 230, y: 100 },
+  resizable: false,
+  theme: theme,
+  isModal: true,
+  autoOpen: false,
+  cancelButton: $('#YeastReady'),
+  modalOpacity: 0.40
+ });
+ $('#YeastReady').jqxButton({ template: 'success', width: '90px', theme: theme });
+ $('#YeastReady').click(function() {
+  var row, rowID = $('#yeastGrid').jqxGrid('getrowid', yeastRow);
+  console.log('YeastReady row:' + yeastRow + ' ID:' + rowID);
+  row = {
+   y_name: yeastData.y_name,
+   y_laboratory: yeastData.y_laboratory,
+   y_product_id: yeastData.y_product_id,
+   y_amount: yeastData.y_amount,
+   y_cost: yeastData.y_cost,
+   y_type: yeastData.y_type,
+   y_form: yeastData.y_form,
+   y_flocculation: yeastData.y_flocculation,
+   y_min_temperature: yeastData.y_min_temperature,
+   y_max_temperature: yeastData.y_max_temperature,