Code cleanup using gjslint

Thu, 12 Sep 2019 15:50:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 12 Sep 2019 15:50:09 +0200
changeset 478
0a270fee6aa0
parent 477
7952f9331fd1
child 479
67dbbf301ae7

Code cleanup using gjslint

www/js/prod_edit-min.js file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/prod_edit-min.js	Wed Sep 11 15:58:32 2019 +0200
+++ b/www/js/prod_edit-min.js	Thu Sep 12 15:50:09 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 ad,l=false,ak=0,aY=0,a0=0,H=0,ab=0,aC=77,ao=0,x=0.75,Z=0,p=1,aa=1,ah=1,O=1,c=1,aX=0,U=0,C=0,aT="",af="",A=40.048,ap=24.305,ac=22.98976928,q=35.453,aH=96.0626,r=61.01684,am=172.171,S=147.015,g=100.087,aJ=246.475,aE=84.007,y=105.996,b=58.443,aI=74.06268,u=0,aK={},B=1,a=0,e={},av=0,aG={},aD=0,f={},aj=0,D={},az=4.445e-7,ax=4.68e-11,d={},E="includes/db_product.php",aQ={datatype:"json",cache:false,datafields:[{name:"record",type:"number"},{name:"uuid",type:"string"},{name:"name",type:"string"},{name:"code",type:"string"},{name:"birth",type:"string"},{name:"stage",type:"int"},{name:"notes",type:"string"},{name:"log_brew",type:"int"},{name:"log_fermentation",type:"int"},{name:"inventory_reduced",type:"int"},{name:"locked",type:"int"},{name:"eq_name",type:"string"},{name:"eq_boil_size",type:"float"},{name:"eq_batch_size",type:"float"},{name:"eq_tun_volume",type:"float"},{name:"eq_tun_weight",type:"float"},{name:"eq_tun_specific_heat",type:"float"},{name:"eq_tun_material",type:"int"},{name:"eq_tun_height",type:"float"},{name:"eq_top_up_water",type:"float"},{name:"eq_trub_chiller_loss",type:"float"},{name:"eq_evap_rate",type:"float"},{name:"eq_boil_time",type:"float"},{name:"eq_calc_boil_volume",type:"int"},{name:"eq_top_up_kettle",type:"float"},{name:"eq_hop_utilization",type:"float"},{name:"eq_notes",type:"string"},{name:"eq_lauter_volume",type:"float"},{name:"eq_lauter_height",type:"float"},{name:"eq_lauter_deadspace",type:"float"},{name:"eq_kettle_volume",type:"float"},{name:"eq_kettle_height",type:"float"},{name:"eq_mash_volume",type:"float"},{name:"eq_mash_max",type:"float"},{name:"eq_efficiency",type:"float"},{name:"brew_date_start",type:"string"},{name:"brew_mash_ph",type:"float"},{name:"brew_mash_sg",type:"float"},{name:"brew_mash_efficiency",type:"float"},{name:"brew_sparge_est",type:"float"},{name:"brew_sparge_ph",type:"float"},{name:"brew_preboil_volume",type:"float"},{name:"brew_preboil_sg",type:"float"},{name:"brew_preboil_ph",type:"float"},{name:"brew_preboil_efficiency",type:"float"},{name:"brew_aboil_volume",type:"float"},{name:"brew_aboil_sg",type:"float"},{name:"brew_aboil_ph",type:"float"},{name:"brew_aboil_efficiency",type:"float"},{name:"brew_cooling_method",type:"int"},{name:"brew_cooling_time",type:"float"},{name:"brew_cooling_to",type:"float"},{name:"brew_whirlpool9",type:"float"},{name:"brew_whirlpool7",type:"float"},{name:"brew_whirlpool6",type:"float"},{name:"brew_whirlpool2",type:"float"},{name:"brew_fermenter_volume",type:"float"},{name:"brew_fermenter_extrawater",type:"float"},{name:"brew_fermenter_tcloss",type:"float"},{name:"brew_aeration_time",type:"float"},{name:"brew_aeration_speed",type:"float"},{name:"brew_aeration_type",type:"int"},{name:"brew_fermenter_sg",type:"float"},{name:"brew_fermenter_ibu",type:"float"},{name:"brew_fermenter_color",type:"float"},{name:"brew_date_end",type:"string"},{name:"og",type:"float"},{name:"fg",type:"float"},{name:"primary_start_temp",type:"float"},{name:"primary_max_temp",type:"float"},{name:"primary_end_temp",type:"float"},{name:"primary_end_sg",type:"float"},{name:"primary_end_date",type:"string"},{name:"secondary_temp",type:"float"},{name:"secondary_end_sg",type:"float"},{name:"secondary_end_date",type:"string"},{name:"tertiary_temp",type:"float"},{name:"package_date",type:"string"},{name:"package_volume",type:"float"},{name:"package_infuse_amount",type:"float"},{name:"package_infuse_abv",type:"float"},{name:"package_infuse_notes",type:"string"},{name:"package_abv",type:"float"},{name:"package_ph",type:"float"},{name:"bottle_amount",type:"float"},{name:"bottle_carbonation",type:"float"},{name:"bottle_priming_water",type:"float"},{name:"bottle_priming_amount",type:"float"},{name:"bottle_carbonation_temp",type:"float"},{name:"keg_amount",type:"float"},{name:"keg_carbonation",type:"float"},{name:"keg_priming_water",type:"float"},{name:"keg_priming_amount",type:"float"},{name:"keg_carbonation_temp",type:"float"},{name:"keg_forced_carb",type:"int"},{name:"keg_pressure",type:"float"},{name:"taste_notes",type:"string"},{name:"taste_rate",type:"float"},{name:"taste_date",type:"string"},{name:"taste_color",type:"string"},{name:"taste_transparency",type:"string"},{name:"taste_head",type:"string"},{name:"taste_aroma",type:"string"},{name:"taste_taste",type:"string"},{name:"taste_mouthfeel",type:"string"},{name:"taste_aftertaste",type:"string"},{name:"st_name",type:"string"},{name:"st_letter",type:"string"},{name:"st_guide",type:"string"},{name:"st_category",type:"string"},{name:"st_category_number",type:"float"},{name:"st_type",type:"int"},{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:"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:"starter_enable",type:"int"},{name:"starter_type",type:"int"},{name:"starter_sg",type:"float"},{name:"starter_viability",type:"int"},{name:"prop1_type",type:"int"},{name:"prop1_volume",type:"float"},{name:"prop2_type",type:"int"},{name:"prop2_volume",type:"float"},{name:"prop3_type",type:"int"},{name:"prop3_volume",type:"float"},{name:"prop4_type",type:"int"},{name:"prop4_volume",type:"float"},{name:"fermentables",type:"array"},{name:"hops",type:"array"},{name:"miscs",type:"array"},{name:"yeasts",type:"array"},{name:"mashs",type:"array"}],id:"record",url:E+"?record="+my_record},ag=new $.jqx.dataAdapter(aQ,{loadComplete:function(){var i=ag.records;d=i[0];$("#name").val(d.name);$("#code").val(d.code);$("#birth").val(d.birth);$("#stage").val(StageData[d.stage].nl);$("#notes").val(d.notes);$("#locked").val(d.locked);$("#eq_name").val(d.eq_name);$("#eq_notes").val(d.eq_notes);$("#eq_boil_size").val(d.eq_boil_size);$("#eq_batch_size").val(d.eq_batch_size);$("#eq_tun_volume").val(d.eq_tun_volume);$("#eq_top_up_water").val(d.eq_top_up_water);$("#eq_trub_chiller_loss").val(d.eq_trub_chiller_loss);$("#eq_evap_rate").val(d.eq_evap_rate);$("#eq_boil_time").val(d.eq_boil_time);$("#eq_top_up_kettle").val(d.eq_top_up_kettle);$("#eq_hop_utilization").val(d.eq_hop_utilization);$("#eq_lauter_volume").val(d.eq_lauter_volume);$("#eq_lauter_deadspace").val(d.eq_lauter_deadspace);$("#eq_kettle_volume").val(d.eq_kettle_volume);$("#eq_mash_volume").val(d.eq_mash_volume);$("#eq_mash_max").val(d.eq_mash_max);$("#eq_efficiency").val(d.eq_efficiency);$("#brew_date_start").val(d.brew_date_start);$("#brew_mash_ph").val(d.brew_mash_ph);$("#brew_mash_sg").val(d.brew_mash_sg);$("#brew_mash_efficiency").val(d.brew_mash_efficiency);$("#brew_sparge_temperature").val(d.sparge_temp);$("#brew_sparge_volume").val(d.sparge_volume);$("#brew_sparge_est").val(d.brew_sparge_est);$("#brew_sparge_ph").val(d.brew_sparge_ph);$("#brew_aeration_type").val(d.brew_aeration_type);$("#brew_aeration_time").val(d.brew_aeration_time);$("#brew_aeration_speed").val(d.brew_aeration_speed);$("#brew_preboil_ph").val(d.brew_preboil_ph);$("#brew_preboil_sg").val(d.brew_preboil_sg);$("#brew_preboil_volume").val(d.brew_preboil_volume);$("#brew_preboil_efficiency").val(d.brew_preboil_efficiency);$("#brew_whirlpool9").val(d.brew_whirlpool9);$("#brew_whirlpool7").val(d.brew_whirlpool7);$("#brew_whirlpool6").val(d.brew_whirlpool6);$("#brew_whirlpool2").val(d.brew_whirlpool2);$("#brew_fermenter_volume").val(d.brew_fermenter_volume);$("#brew_fermenter_sg").val(d.brew_fermenter_sg);$("#brew_fermenter_sg2").val(d.brew_fermenter_sg);$("#brew_fermenter_ibu").val(d.brew_fermenter_ibu);$("#brew_fermenter_color").val(d.brew_fermenter_color);$("#brew_fermenter_extrawater").val(d.brew_fermenter_extrawater);$("#brew_fermenter_tcloss").val(d.brew_fermenter_tcloss);$("#brew_aboil_ph").val(d.brew_aboil_ph);$("#brew_aboil_sg").val(d.brew_aboil_sg);$("#brew_aboil_volume").val(d.brew_aboil_volume);$("#brew_aboil_efficiency").val(d.brew_aboil_efficiency);$("#brew_cooling_to").val(d.brew_cooling_to);$("#brew_cooling_method").val(d.brew_cooling_method);$("#brew_cooling_time").val(d.brew_cooling_time);$("#brew_date_end").val(d.brew_date_end);$("#og").val(d.og);$("#fg").val(d.fg);$("#primary_start_temp").val(d.primary_start_temp);$("#primary_max_temp").val(d.primary_max_temp);$("#primary_end_temp").val(d.primary_end_temp);$("#primary_end_sg").val(d.primary_end_sg);$("#primary_end_date").val(d.primary_end_date);$("#secondary_temp").val(d.secondary_temp);$("#secondary_end_sg").val(d.secondary_end_sg);$("#secondary_end_date").val(d.secondary_end_date);$("#tertiary_temp").val(d.tertiary_temp);$("#package_date").val(d.package_date);$("#package_volume").val(d.package_volume);$("#package_infuse_amount").val(d.package_infuse_amount);$("#package_infuse_abv").val(d.package_infuse_abv);$("#package_infuse_notes").val(d.package_infuse_notes);$("#package_abv").val(d.package_abv);$("#package_ph").val(d.package_ph);$("#bottle_amount").val(d.bottle_amount);$("#bottle_carbonation").val(d.bottle_carbonation);$("#bottle_priming_water").val(d.bottle_priming_water);$("#bottle_priming_amount").val(d.bottle_priming_amount);$("#bottle_carbonation_temp").val(d.bottle_carbonation_temp);$("#keg_amount").val(d.keg_amount);$("#keg_carbonation").val(d.keg_carbonation);$("#keg_priming_water").val(d.keg_priming_water);$("#keg_priming_amount").val(d.keg_priming_amount);$("#keg_carbonation_temp").val(d.keg_carbonation_temp);$("#keg_forced_carb").val(d.keg_forced_carb);$("#keg_pressure").val(d.keg_pressure);$("#taste_notes").val(d.taste_notes);$("#taste_rate").val(d.taste_rate);$("#taste_date").val(d.taste_date);$("#taste_color").val(d.taste_color);$("#taste_transparency").val(d.taste_transparency);$("#taste_head").val(d.taste_head);$("#taste_aroma").val(d.taste_aroma);$("#taste_taste").val(d.taste_taste);$("#taste_mouthfeel").val(d.taste_mouthfeel);$("#taste_aftertaste").val(d.taste_aftertaste);$("#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);$("#st_og_min").val(d.st_og_min);$("#st_og_max").val(d.st_og_max);$("#st_fg_min").val(d.st_fg_min);$("#st_fg_max").val(d.st_fg_max);$("#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);$("#st_ibu_min").val(d.st_ibu_min);$("#st_ibu_max").val(d.st_ibu_max);$("#st_carb_min").val(d.st_carb_min);$("#st_carb_min2").val(d.st_carb_min);$("#st_carb_max").val(d.st_carb_max);$("#st_carb_max2").val(d.st_carb_max);$("#type").val(d.type);$("#batch_size").val(d.batch_size);$("#est_a_vol").val(d.batch_size*1.04);$("#boil_size").val(d.boil_size);$("#est_pre_vol").val(d.boil_size*1.04);$("#boil_time").val(d.boil_time);$("#efficiency").val(d.efficiency);$("#est_og").val(d.est_og);$("#est_og2").val(d.est_og);$("#est_og3").val(0);$("#est_fg").val(d.est_fg);$("#est_fg2").val(d.est_fg);$("#est_fg3").val(d.est_fg);$("#est_color").val(d.est_color);$("#est_color2").val(d.est_color);$("#est_abv").val(d.est_abv);$("#color_method").val(d.color_method);$("#est_ibu").val(d.est_ibu);$("#est_ibu2").val(d.est_ibu);$("#ibu_method").val(d.ibu_method);$("#est_carb").val(d.est_carb);$("#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);$("#starter_enable").val(d.starter_enable);$("#starter_type").val(d.starter_type);$("#starter_sg").val(d.starter_sg);$("#starter_viability").val(d.starter_viability);$("#prop1_type").val(d.prop1_type);$("#prop1_volume").val(d.prop1_volume);$("#prop2_type").val(d.prop2_type);$("#prop2_volume").val(d.prop2_volume);$("#prop3_type").val(d.prop3_type);$("#prop3_volume").val(d.prop3_volume);$("#prop4_type").val(d.prop4_type);$("#prop4_volume").val(d.prop4_volume);n(d);aS(d);W(d);aL(d);au(d);aU();$("#jqxTabs").jqxTabs("select",2)},loadError:function(a3,i,a2){},beforeLoadComplete:function(i){$("#jqxLoader").jqxLoader("open")}}),n=function(a2){var i={localdata:a2.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(a5,a7,a4,a6){a6(true)},deleterow:function(a4,a5){a5(true)},updaterow:function(a4,a6,a5){a5(true)}},a3=new $.jqx.dataAdapter(i);$("#fermentableGrid").jqxGrid({width:1240,height:470,source:a3,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');a4.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",disabled:(d.stage>3),width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(a7,a6,a9){var a8=fermentablelist.records[a7];return a8.supplier+" / "+a8.name+" ("+a8.color+" EBC)"}});$("#faddrowbutton").on("select",function(a8){if(a8.args){var a6,a7,a9={},ba=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;a6=a8.args.index;a7=fermentablelist.records[a6];a9.f_name=a7.name;a9.f_origin=a7.origin;a9.f_supplier=a7.supplier;a9.f_amount=0;a9.f_cost=a7.cost;a9.f_type=a7.type;a9.f_yield=a7.yield;a9.f_color=a7.color;a9.f_coarse_fine_diff=a7.coarse_fine_diff;a9.f_moisture=a7.moisture;a9.f_diastatic_power=a7.diastatic_power;a9.f_protein=a7.protein;a9.f_max_in_batch=a7.max_in_batch;a9.f_graintype=a7.graintype;if(a7.add_after_boil){a9.f_added=2}else{if((a7.type==1)||(a7.type==4)){a9.f_added=1}else{a9.f_added=0}}a9.f_dissolved_protein=a7.dissolved_protein;a9.f_recommend_mash=a7.recommend_mash;a9.f_add_after_boil=a7.add_after_boil;if(ba==0){a9.f_adjust_to_total_100=1;a9.f_percentage=100}else{a9.f_adjust_to_total_100=0;a9.f_percentage=0}a9.f_di_ph=a7.di_ph;a9.f_acid_to_ph_57=a7.acid_to_ph_57;a9.f_inventory=a7.inventory;$("#fermentableGrid").jqxGrid("addrow",null,a9)}});$("#finstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#finstockbutton").on("change",function(a6){fermentableinstock=a6.args.checked;fermentablelist.dataBind()});$("#fdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#fdeleterowbutton").on("click",function(){var bc,bb,a9,a8,a7,ba,a6=$("#fermentableGrid").jqxGrid("getselectedrowindex");bc=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<bc){bb=$("#fermentableGrid").jqxGrid("getrowid",a6);a9=$("#fermentableGrid").jqxGrid("getcellvalue",bb,"f_percentage");a8=$("#fermentableGrid").jqxGrid("getcellvalue",bb,"f_amount");$("#fermentableGrid").jqxGrid("deleterow",bb)}bc=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(bc>1){if(l){for(a7=0;a7<bc;a7++){ba=$("#fermentableGrid").jqxGrid("getrowdata",a7);if(ba.f_adjust_to_total_100){ba.f_percentage+=a9;ba.f_amount+=a8}}}else{aV()}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}T();ar()})},ready:function(){T();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Vergistbaar ingredi&euml;nt",datafield:"f_name",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+a9.f_supplier+" / "+a9.f_name+" ("+a9.f_color+" EBC)</span>"}},{text:"Type",width:100,datafield:"f_type",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+FermentableTypeData[a8].nl+"</span>"}},{text:"Moment",width:110,datafield:"f_added",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+AddedData[a8].nl+"</span>"}},{text:"Maxinbatch",datafield:"f_max_in_batch",hidden:true},{text:"Opbrengst",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:"Voorraad Kg",datafield:"f_inventory",width:120,align:"right",cellsrenderer:function(a8,a6,a7,a4,ba,a9){var a5="#ffffff";if(((d.inventory_reduced<=2)&&(a9.f_added<=1))||((d.inventory_reduced<=3)&&(a9.f_added==2))||((d.inventory_reduced<=5)&&(a9.f_added==3))||((d.inventory_reduced<=6)&&(a9.f_added==4))||((d.inventory_reduced<=6)&&(a9.f_added==5))){if(a7<a9.f_amount){a5="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a5+';">'+a3.formatNumber(a7,"f3")+"</span>"}else{return"<span></span>"}}},{text:"Procent",datafield:"f_percentage",width:90,align:"right",cellsrenderer:function(a8,a6,a7,a4,ba,a9){if(a9.f_added>=4){return"<span></span>"}var a5="#ffffff";if(a7>a9.f_max_in_batch){a5="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a5+';">'+a3.formatNumber(a7,"p1")+"</span>"}},{text:"100%",datafield:"f_adjust_to_total_100",width:70,align:"center",cellsalign:"center",cellsrenderer:function(a5,a4,a8,a7,a6,a9){if(a8==0){return"<span></span>"}return'<span><img style="float:left; margin-left:25px; margin-top:4px;" src="images/dialog-ok-apply.png"></span>'}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){u=a4;aK=$("#fermentableGrid").jqxGrid("getrowdata",u);if(aK.f_added>=4){alert("Wijzig dit in de Verpakken tab")}else{if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{$("#wf_name").val(aK.f_name);$("#wf_amount").val(aK.f_amount);$("#wf_percentage").val(aK.f_percentage);$("#wf_max_in_batch").val(aK.f_max_in_batch);$("#wf_adjust_to_total_100").val(aK.f_adjust_to_total_100);$("#wf_added").val(aK.f_added);$("#popupFermentable").jqxWindow("open")}}}}]})},aS=function(i){var a3={localdata:i.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(a5,a7,a4,a6){console.log("hop addrow "+a5);a6(true)},deleterow:function(a4,a5){console.log("hop deleterow "+a4);a5(true)},updaterow:function(a4,a6,a5){console.log("hop updaterow "+a4);a5(true)}},a2=new $.jqx.dataAdapter(a3);$("#hopGrid").jqxGrid({width:1240,height:560,source:a2,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');a4.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,disabled:(d.stage>3),displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(a7,a6,a9){var a8=hoplist.records[a7];return a8.origin+" - "+a8.name+" / "+HopFormData[a8.form].nl+" ("+a8.alpha+"% &alpha;)"}});$("#haddrowbutton").on("select",function(a8){if(a8.args){var a7,a9={},a6=a8.args.index;a7=hoplist.records[a6];a9.h_name=a7.name;a9.h_origin=a7.origin;a9.h_amount=0;a9.h_cost=a7.cost;a9.h_type=a7.type;a9.h_form=a7.form;a9.h_useat=2;a9.h_time=0;a9.h_alpha=a7.alpha;a9.h_beta=a7.beta;a9.h_hsi=a7.hsi;a9.h_humulene=a7.humulene;a9.h_caryophyllene=a7.caryophyllene;a9.h_cohumulone=a7.cohumulone;a9.h_myrcene=a7.myrcene;a9.h_total_oil=a7.total_oil;a9.h_inventory=a7.inventory;$("#hopGrid").jqxGrid("addrow",null,a9)}$("#haddrowbutton").jqxDropDownList("clearSelection")});$("#hinstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#hinstockbutton").on("change",function(a6){hopinstock=a6.args.checked;hoplist.dataBind()});$("#hdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#hdeleterowbutton").on("click",function(){var a8,a7,a6=$("#hopGrid").jqxGrid("getselectedrowindex");a8=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<a8){a7=$("#hopGrid").jqxGrid("getrowid",a6);$("#hopGrid").jqxGrid("deleterow",a7)}ar()})},ready:function(){ar();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Hop",datafield:"h_name",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+a9.h_origin+" / "+a9.h_name+"</span>"},},{text:"Type",width:90,datafield:"h_type",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopTypeData[a8].nl+"</span>"}},{text:"Vorm",width:90,datafield:"h_form",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopFormData[a8].nl+"</span>"}},{text:"Alpha",datafield:"h_alpha",width:80,align:"right",cellsalign:"right",cellsformat:"p1"},{text:"Gebruik",width:110,datafield:"h_useat",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopUseData[a8].nl+"</span>"}},{text:"Tijdsduur",datafield:"h_time",width:90,align:"right",cellsrenderer:function(a5,a4,a8,a7,a6,ba){var a9="";if((ba.h_useat==2)||(ba.h_useat==4)){a9=ag.formatNumber(a8,"f0")+" min."}else{if(ba.h_useat==5){a9=ag.formatNumber(a8/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a9+"</span>"}},{text:"IBU",datafield:"ibu",width:80,align:"right",cellsrenderer:function(a5,a4,a8,a7,a6,ba){var a9=toIBU(ba.h_useat,ba.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(ba.h_amount),parseFloat(ba.h_time),parseFloat(ba.h_alpha),$("#ibu_method").val());return'<span style="margin: 4px; margin-top: 6px; float: right;">'+ag.formatNumber(a9,"f1")+"</span>"}},{text:"Gewicht",datafield:"h_amount",width:110,align:"right",cellsrenderer:function(a5,a4,a9,a8,a7,ba){var a6=ag.formatNumber(a9,"f1")+" kg";if(a9<1){a6=ag.formatNumber(a9*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a6+"</span>"}},{text:"Voorraad",datafield:"h_inventory",width:110,align:"right",cellsrenderer:function(a6,a5,ba,a9,a8,bb){if(((d.inventory_reduced<=2)&&(bb.h_useat<=4))||((d.inventory_reduced<=6)&&(bb.h_useat==5))){var a7,a4="#ffffff";if(ba<bb.h_amount){a4="#ff4040"}a7=ag.formatNumber(ba,"f1")+" kg";if(ba<1){a7=ag.formatNumber(ba*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a4+';">'+a7+"</span>"}else{return"<span></span>"}}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{console.log("edit button row "+a4);a=a4;e=$("#hopGrid").jqxGrid("getrowdata",a);$("#wh_name").val(e.h_name);$("#wh_amount").val(e.h_amount*1000);var a5=toIBU(e.h_useat,e.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(e.h_amount),parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(a5);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")}}}]})},W=function(a3){var a2={localdata:a3.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(a5,a7,a4,a6){console.log("misc addrow "+a5);a6(true)},deleterow:function(a4,a5){console.log("misc deleterow "+a4);a5(true)},updaterow:function(a4,a6,a5){console.log("misc updaterow "+a4);a5(true)}},i=new $.jqx.dataAdapter(a2,{beforeLoadComplete:function(a4){var a7,a5,a6=new Array();for(a5=0;a5<a4.length;a5++){a7=a4[a5];a6.push(a7);switch(a7.m_name){case"CaCl2":$("#wa_cacl2").val(a7.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(a7.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(a7.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(a7.m_amount*1000);break;case"Melkzuur":$("#wa_acid_name").val(0);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Melkzuur";break;case"Zoutzuur":$("#wa_acid_name").val(1);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Zoutzuur";break;case"Fosforzuur":$("#wa_acid_name").val(2);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Fosforzuur";break;case"Zwavelzuur":$("#wa_acid_name").val(3);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Zwavelzuur";break;case"NaHCO3":$("#wa_base_name").val(0);$("#wa_base").val(a7.m_amount*1000);aT="NaHCO3";break;case"Na2CO3":$("#wa_base_name").val(1);$("#wa_base").val(a7.m_amount*1000);aT="Na2CO3";break;case"CaCO3":$("#wa_base_name").val(2);$("#wa_base").val(a7.m_amount*1000);aT="CaCO3";break;case"Ca(OH)2":$("#wa_base_name").val(3);$("#wa_base").val(a7.m_amount*1000);aT="Ca(OH)2";break}}return a6},loadError:function(a6,a4,a5){$("#err").text(a4+" "+a5)},});$("#miscGrid").jqxGrid({width:1240,height:575,source:i,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="minstockbutton"></div>');a4.append('<input style="float: left; margin-left: 400px;" id="mdeleterowbutton" type="button" value="Verwijder ingredient" />');$("#maddrowbutton").jqxDropDownList({placeHolder:"Kies ingredi&euml;nt:",theme:theme,template:"primary",source:misclist,disabled:(d.stage>3),displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500});$("#maddrowbutton").on("select",function(a8){if(a8.args){var a7,a9={},a6=a8.args.index;a7=misclist.records[a6];a9.m_name=a7.name;a9.m_amount=0;a9.m_cost=a7.cost;a9.m_type=a7.type;a9.m_use_use=a7.use_use;a9.m_time=0;a9.m_amount_is_weight=a7.amount_is_weight;a9.m_inventory=a7.inventory;$("#miscGrid").jqxGrid("addrow",null,a9)}});$("#minstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#minstockbutton").on("change",function(a6){miscinstock=a6.args.checked;misclist.dataBind()});$("#mdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#mdeleterowbutton").on("click",function(){var a9,a7,a8,a6=$("#miscGrid").jqxGrid("getselectedrowindex");a9=$("#miscGrid").jqxGrid("getdatainformation").rowscount;a7=$("#miscGrid").jqxGrid("getcellvalue",a6,"m_type");if(a6>=0&&a6<a9&&a7!=4){a8=$("#miscGrid").jqxGrid("getrowid",a6);$("#miscGrid").jqxGrid("deleterow",a8)}})},ready:function(){aF();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Ingredient",datafield:"m_name"},{text:"Type",width:140,datafield:"m_type",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+MiscTypeData[a8].nl+"</span>"}},{text:"Gebruik",width:140,datafield:"m_use_use",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+MiscUseData[a8].nl+"</span>"}},{text:"Tijd",datafield:"m_time",width:90,align:"right",cellsrenderer:function(a5,a4,a8,a7,a6,ba){var a9="";if(ba.m_use_use==2){a9=ag.formatNumber(a8,"f0")+" min."}else{if((ba.m_use_use==3)||(ba.m_use_use==4)){a9=ag.formatNumber(a8/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a9+"</span>"},},{text:"Hoeveel",datafield:"m_amount",width:110,align:"right",cellsrenderer:function(a5,a4,a9,a7,a6,ba){var a8=ba.m_amount_is_weight?"gr":"ml";return'<span style="margin: 4px; margin-top: 6px; float: right;">'+ag.formatNumber(a9*1000,"f2")+" "+a8+"</span>"}},{text:"Voorraad",datafield:"m_inventory",width:110,align:"right",cellsrenderer:function(a8,a4,a9,bb,a5,bc){var ba,a6,a7;if(((d.inventory_reduced<=2)&&(bc.m_use_use<=2))||((d.inventory_reduced<=3)&&(bc.m_use_use==3))||((d.inventory_reduced<=5)&&(bc.m_use_use==4))||((d.inventory_reduced<=6)&&(bc.m_use_use==5))){ba=bc.m_amount_is_weight?"gr":"ml";a6="#ffffff";if(a9<bc.m_amount){a6="#ff4040"}a7=ag.formatNumber(a9*1000,"f2")+" "+ba;return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a6+';">'+a7+"</span>"}else{return"<span></span>"}}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){av=a4;aG=$("#miscGrid").jqxGrid("getrowdata",av);if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{if(aG.m_type==4){alert("Brouwzouten wijzigen in de water tab.")}else{console.log("edit button row "+a4);if(aG.m_amount_is_weight){$("#wm_pmpt_amount").html("Gewicht gram:")}else{$("#wm_pmpt_amount").html("Volume ml:")}$("#wm_name").val(aG.m_name);$("#wm_amount").val(aG.m_amount*1000);if((aG.m_use_use==3)||(aG.m_use_use==4)){$("#wm_time").val(aG.m_time/1440)}else{$("#wm_time").val(aG.m_time)}$("#wm_use_use").val(aG.m_use_use);$("#popupMisc").jqxWindow("open")}}}}]})},aL=function(a2){var i={localdata:a2.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(a5,a7,a4,a6){console.log("yeast addrow "+a5);a6(true)},deleterow:function(a4,a5){console.log("yeast deleterow "+a4);a5(true)},updaterow:function(a4,a6,a5){console.log("yeast updaterow "+a4);a5(true)}},a3=new $.jqx.dataAdapter(i);$("#yeastGrid").jqxGrid({width:1240,height:350,source:a3,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');a4.append('<input style="float: left; margin-left: 400px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');$("#yaddrowbutton").jqxDropDownList({placeHolder:"Kies gist:",theme:theme,source:yeastlist,disabled:(d.stage>3),template:"primary",displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(a7,a6,a9){var a8=yeastlist.records[a7];return a8.laboratory+" "+a8.product_id+" "+a8.name}});$("#yaddrowbutton").on("select",function(a8){if(a8.args){var a7,a9={},a6=a8.args.index;a7=yeastlist.records[a6];a9.y_name=a7.name;a9.y_laboratory=a7.laboratory;a9.y_product_id=a7.product_id;a9.y_type=a7.type;a9.y_form=a7.form;a9.y_amount=0;a9.y_cost=a7.cost;a9.y_use=0;a9.y_min_temperature=a7.min_temperature;a9.y_max_temperature=a7.max_temperature;a9.y_attenuation=a7.attenuation;a9.y_flocculation=a7.flocculation;a9.y_cells=a7.cells;a9.y_tolerance=a7.tolerance;a9.y_inventory=a7.inventory;$("#yeastGrid").jqxGrid("addrow",null,a9)}X();$("#yaddrowbutton").jqxDropDownList("clearSelection")});$("#yinstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#yinstockbutton").on("change",function(a6){yeastinstock=a6.args.checked;yeastlist.dataBind()});$("#ydeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#ydeleterowbutton").on("click",function(){var a8,a7,a6=$("#yeastGrid").jqxGrid("getselectedrowindex");a7=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<a7){a8=$("#yeastGrid").jqxGrid("getrowid",a6);$("#yeastGrid").jqxGrid("deleterow",a8);X()}})},ready:function(){T();I();X();$("#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(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastFormData[a8].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(a6,a5,ba,a9,a8,bb){var a7="",a4="#ffffff";if(ba>0){a7=ag.formatNumber(ba,"f1");if(d.est_abv>ba){a4="#ff4040"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a4+';">'+a7+"</span>"}},{text:"Attn. %",width:70,align:"right",cellsalign:"right",datafield:"y_attenuation",cellsformat:"f1"},{text:"Voor",width:120,datafield:"y_use",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastUseData[a8].nl+"</span>"}},{text:"Hoeveel",datafield:"y_amount",width:90,align:"right",cellsrenderer:function(a5,a4,a9,a8,a7,ba){var a6=ag.formatNumber(a9*1000,"f0")+" ml";if(ba.y_form==0){a6=ag.formatNumber(a9,"f0")+" pk"}else{if(ba.y_form==1){a6=ag.formatNumber(a9*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a6+"</span>"}},{text:"Voorraad",datafield:"y_inventory",width:90,align:"right",cellsrenderer:function(a6,a5,ba,a9,a8,bb){var a4,a7;if(((d.inventory_reduced<=3)&&(bb.y_use==0))||((d.inventory_reduced<=4)&&(bb.y_use==1))||((d.inventory_reduced<=5)&&(bb.y_use==2))||((d.inventory_reduced<=6)&&(bb.y_use==3))){a4="#ffffff";if(ba<bb.y_amount){a4="#ff4040"}a7=ag.formatNumber(ba*1000,"f0")+" ml";if(bb.y_form==0){a7=ag.formatNumber(ba,"f0")+" pk"}else{if(bb.y_form==1){a7=ag.formatNumber(ba*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a4+';">'+a7+"</span>"}else{return"<span></span>"}}},{text:"",datafield:"Edit",columntype:"button",width:90,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{aD=a4;f=$("#yeastGrid").jqxGrid("getrowdata",aD);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")}}}]})},au=function(a3){var a2={localdata:a3.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(a5,a7,a4,a6){a6(true)},deleterow:function(a4,a5){a5(true)}},i=new $.jqx.dataAdapter(a2,{beforeLoadComplete:function(a4){C=0;var a5,a7,a6=new Array();for(a5=0;a5<a4.length;a5++){a7=a4[a5];if(a7.step_type==0){C+=parseFloat(a7.step_infuse_amount)}a7.step_thickness=0;a6.push(a7)}},});$("#mashGrid").jqxGrid({width:1240,height:400,source:i,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');a4.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,disabled:(d.stage>3)});$("#saddrowbutton").on("click",function(){var a6={},a7=$("#mashGrid").jqxGrid("getdatainformation").rowscount;a6.step_name="Stap "+(a7+1);if(a7>0){a6.step_type=1}else{a6.step_type=0;a6.step_infuse_amount=15}a6.step_temp=62;a6.step_time=20;a6.step_thickness=0;a6.ramp_time=1;a6.end_temp=62;$("#mashGrid").jqxGrid("addrow",null,a6)});$("#sdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#sdeleterowbutton").on("click",function(){var a8,a7,a6=$("#mashGrid").jqxGrid("getselectedrowindex");a8=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<a8){a7=$("#mashGrid").jqxGrid("getrowid",a6);$("#mashGrid").jqxGrid("deleterow",a7)}})},ready:function(){aW();aN();$("#jqxLoader").jqxLoader("close");$("#jqxTabs").jqxTabs("first")},columns:[{text:"Stap naam",datafield:"step_name"},{text:"Stap type",datafield:"step_type",width:175,cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+MashStepTypeData[a8].nl+"</span>"}},{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(a4){if(d.stage>3){alert("Het maichen is al gedaan.")}else{aj=a4;D=$("#mashGrid").jqxGrid("getrowdata",aj);$("#wstep_name").val(D.step_name);$("#wstep_type").val(D.step_type);$("#wstep_infuse_amount").val(D.step_infuse_amount);$("#wstep_temp").val(D.step_temp);$("#wend_temp").val(D.end_temp);$("#wstep_time").val(D.step_time);$("#wramp_time").val(D.ramp_time);if(D.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 product ...",theme:theme});function G(){if(d.inventory_reduced>6){$("#ok_pmpt").hide();return}if(p&&aa&&ah&&O&&c){$("#ok_supplies").html("<img src='images/dialog-ok-apply.png'>")}else{$("#ok_supplies").html("<img src='images/dialog-error.png'>")}}function aV(){console.log("calcPercentages()");var a2=0,a4,i,a3=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(a3>1){for(ad=0;ad<a3;ad++){a4=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(a4.f_added<4){a2+=Round(a4.f_amount,3)}}a2=Round(a2,3);for(ad=0;ad<a3;ad++){a4=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(a4.f_added<4){i=Round(a4.f_amount/a2*100,1);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",i)}else{$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",0)}}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}}function T(){var bA=0,bs=0,bq=0,bi=0,br=0,bB=0,bb=0,bl=0,bf=0,bj=false,bo=0,ba=0,bu=0.925,bn=0.95,a9=0,bp,a8,bd,a2,bh,a3,bx,by,a6,bg=0,bw,be,bc,a5,a7,bk,a4,bm,bt,bz;H=0;ab=0;ao=0;p=1;O=1;if((bd=$("#mashGrid").jqxGrid("getrows"))){for(bp=0;bp<bd.length;bp++){a8=bd[bp];if(a8.step_type==0){bB+=parseFloat(a8.step_infuse_amount)}if(a8.step_temp<=75){bh=a8.step_time+a8.ramp_time;bo+=bh;ba+=bh*a8.step_temp}}if(bo>5){bo-=5}ba=Round(ba/bo,2)}if(!(bd=$("#fermentableGrid").jqxGrid("getrows"))){return}for(bp=0;bp<bd.length;bp++){a8=bd[bp];if(a8.f_adjust_to_total_100){bj=true}if(a8.f_type==1&&a8.f_added<4){H+=a8.f_percentage}if(a8.f_graintype==2&&a8.f_added<4){ab+=a8.f_percentage}bw=a8.f_amount*(a8.f_yield/100)*(1-a8.f_moisture/100);if(a8.f_added==0){if(bB>0){bB+=a8.f_amount*a8.f_moisture/100;bg+=bw}bw=parseFloat(d.efficiency)/100*bw;bs+=bw;ao+=parseFloat(a8.f_amount)}if(a8.f_added==0||a8.f_added==1){bA+=bw}if(a8.f_added==2||a8.f_added==3){bc=(a8.f_yield/100)*(1-a8.f_moisture/100);bi+=a8.f_amount*bc;br+=a8.f_amount;bq+=(bc*sugardensity+(1-bc)*1)*a8.f_amount}if(a8.f_added<4){bb+=a8.f_amount*ebc_to_srm(a8.f_color);bl+=a8.f_amount*a8.f_color*get_kt(a8.f_color);bf+=(a8.f_percentage/100)*a8.f_color}if(B){if(a8.f_added==4){$("#bottle_priming_total").val(a8.f_amount*1000);$("#bottle_priming_sugar").jqxDropDownList("selectItem",a8.f_name)}if(a8.f_added==5){$("#keg_priming_total").val(a8.f_amount*1000);$("#keg_priming_sugar").jqxDropDownList("selectItem",a8.f_name)}}if((((d.inventory_reduced<=2)&&(a8.f_added<=1))||((d.inventory_reduced<=3)&&(a8.f_added==2))||((d.inventory_reduced<=5)&&(a8.f_added==3))||((d.inventory_reduced<=6)&&(a8.f_added==4))||((d.inventory_reduced<=6)&&(a8.f_added==5)))&&a8.f_inventory<a8.f_amount){p=0}if(a8.f_added==0&&(a8.f_type==0||a8.f_type==4)&&a8.f_color<50){a9+=a8.f_diastatic_power*a8.f_amount}}B=0;$("#ferm_lintner").val(Math.round(parseFloat(a9/ao)));$("#mash_kg").val(ao);console.log("calcFermentables() supplies:"+p+" moutsuiker:"+bs+"/"+bA);l=bj;if(l){$("#wf_amount").jqxNumberInput({width:90,readOnly:true,spinButtons:false})}else{$("#wf_amount").jqxNumberInput({width:110,readOnly:false,spinButtons:true})}if(bB>0){be=bg/sugardensity+bB;bg=1000*bg/(be*10);a0=Round(plato_to_sg(bg),5);$("#est_mash_sg").val(a0)}d.est_og=estimate_sg(bA+bi,parseFloat(d.batch_size));$("#est_og").val(d.est_og);$("#est_og2").val(d.est_og);a2=d.est_og;aY=estimate_sg(bA,parseFloat(d.batch_size));$("#est_og3").val(aY);ak=estimate_sg(bs,parseFloat(d.boil_size));$("#est_pre_sg").val(ak);a3=parseFloat(d.batch_size);if(d.brew_aboil_volume>0){a3=d.brew_aboil_volume/1.04}if(d.brew_fermenter_tcloss==0){d.brew_fermenter_tcloss=d.eq_trub_chiller_loss;$("#brew_fermenter_tcloss").val(d.brew_fermenter_tcloss)}d.brew_fermenter_volume=a3-d.brew_fermenter_tcloss+d.brew_fermenter_extrawater;$("#brew_fermenter_volume").val(d.brew_fermenter_volume);bx=(d.boil_size-C+(ao*my_grain_absorbtion)+d.eq_lauter_deadspace)*1.03;$("#brew_sparge_est").val(bx);by=d.brew_aboil_sg;if(by<1.002){by=aY}a6=d.brew_fermenter_extrawater;if(d.brew_fermenter_volume>0){a5=sg_to_plato(by)*d.brew_fermenter_volume*by/100;a5+=bi;if((d.brew_fermenter_volume*by+br)>0){bk=100*a5/(d.brew_fermenter_volume*by+br+a6);d.brew_fermenter_sg=Round(plato_to_sg(bk),4);$("#brew_fermenter_sg").val(d.brew_fermenter_sg);if(d.color_method==4){d.brew_fermenter_color=Math.round(((bk/8.6)*bf)+(d.boil_time/60))}else{if(d.color_method==3){d.brew_fermenter_color=Math.round((4.46*bu*bn)/(a3+a6)*bl)}else{a4=bb/(a3+a6)*8.34436;d.brew_fermenter_color=kw_to_ebc(d.color_method,a4)}}$("#brew_fermenter_color").val(d.brew_fermenter_color);bt=ebc_to_color(d.brew_fermenter_color);$("#bcolorf").show();document.getElementById("bcolorf").style.background=bt}}else{d.brew_fermenter_sg=d.brew_fermenter_color=0;$("#brew_fermenter_sg").val(0);$("#brew_fermenter_color").val(0);$("#bcolorf").hide()}if(d.color_method==4){bm=Math.round(((sg_to_plato(d.est_og)/8.6)*bf)+(d.boil_time/60))}else{if(d.color_method==3){bm=Math.round((4.46*bu*bn)/parseFloat(d.batch_size)*bl)}else{a4=bb/parseFloat(d.batch_size)*8.34436;bm=kw_to_ebc(d.color_method,a4)}}d.est_color=bm;$("#est_color").val(bm);$("#est_color2").val(bm);bt=ebc_to_color(bm);document.getElementById("bcolor").style.background=bt;document.getElementById("bcolor2").style.background=bt;pmalts=ao/d.eq_mash_max*100;$("#perc_malts").jqxProgressBar("val",pmalts);$("#perc_sugars").jqxProgressBar("val",H);$("#perc_cara").jqxProgressBar("val",ab);aU();aC=0;Z=0;bd=$("#yeastGrid").jqxGrid("getrows");for(bp=0;bp<bd.length;bp++){a8=bd[bp];if(a8.y_use==0){if(parseFloat(a8.y_attenuation)>aC){aC=parseFloat(a8.y_attenuation)}if(a8.y_form==0){Z+=(parseFloat(a8.y_cells)/1000000000)*parseFloat(a8.y_amount)*(d.starter_viability/100)}else{Z+=(parseFloat(a8.y_cells)/1000000)*parseFloat(a8.y_amount)}}if((((d.inventory_reduced<=3)&&(a8.y_use==0))||((d.inventory_reduced<=4)&&(a8.y_use==1))||((d.inventory_reduced<=5)&&(a8.y_use==2))||((d.inventory_reduced<=6)&&(a8.y_use==3)))&&(a8.y_inventory<a8.y_amount)){O=0}}G();if(aC==0){aC=77}if((ao>0)&&(C>0)&&(bo>0)&&(ba>0)){d.est_fg=estimate_fg(H,ab,C/ao,bo,ba,aC,d.est_og)}else{d.est_fg=estimate_fg(H,ab,0,0,0,aC,d.est_og)}$("#est_fg").val(d.est_fg);$("#est_fg2").val(d.est_fg);$("#est_fg3").val(d.est_fg);bz=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);if((d.stage>=6)&&(d.fg>0.99)&&(d.fg<d.brew_fermenter_sg)){aC=100*(d.brew_fermenter_sg-d.fg)/(d.brew_fermenter_sg-1);a2=d.brew_fermenter_sg;bz=d.fg}$("#yeast_cells").val(Z);$("#need_cells").val(v());a7=1881.22*bz*(a2-bz)/(1.775-a2);a5=3550*bz*(0.1808*a2+0.8192*bz-1.0004);$("#kcal").val(Math.round((a7+a5)/(12*0.0295735296)))}function aN(){var a2=0,a3,a4;if(!(rows=$("#mashGrid").jqxGrid("getrows"))){return}if(ao==0){return}for(a3=0;a3<rows.length;a3++){a4=$("#mashGrid").jqxGrid("getrowdata",a3);if(a4.step_type==0){a2+=a4.step_infuse_amount}$("#mashGrid").jqxGrid("setcellvalue",a3,"step_thickness",a2/ao)}}function ae(a3){console.log("calcFermentablesFromOG("+a3+")");var a5,bb,a8,a4,ba,a7=0,a6=0,a9,a2=parseFloat($("#efficiency").jqxNumberInput("decimal"));ba=sg_to_plato(a3)*parseFloat($("#batch_size").jqxNumberInput("decimal"))*a3/100;a9=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(a4=0;a4<a9;a4++){bb=$("#fermentableGrid").jqxGrid("getrowdata",a4);if(bb.f_added<4){a8=bb.f_percentage/100*(bb.f_yield/100)*(1-bb.f_moisture/100);if(bb.f_added==0){a8=a2/100*a8}a7+=a8}}if(a7){a6=Round(ba/a7,3)}if(a6){for(a4=0;a4<a9;a4++){bb=$("#fermentableGrid").jqxGrid("getrowdata",a4);if(bb.f_added<4){a5=Math.round(bb.f_percentage*10*a6)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",a4,"f_amount",a5)}}}}function v(){var i,a3,a2=d.brew_fermenter_sg;if(a2<=1.0001&&d.fg>1){a2=d.fg}else{if(a2<=1.0001){a2=d.est_og}}i=sg_to_plato(a2);a3=d.brew_fermenter_volume;if(a3<=0){a3=d.batch_size-d.eq_trub_chiller_loss}return x*a3*i}function K(a3,a5,a2,a4){var i;if(a2==1){i=0.15}else{if(a3>50){i=0.1}else{i=15.25/(6*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((a3-21)/6,2));if(i<0.1){i=0.1}}}return(i*a4*1000)/a5}function h(a3,a5,a2,a4){var i=0;if(a2==5){i=1.33}else{if(a3>20){i=0}else{if(a3>7.5){i=10.03/(4*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((a3-7.5)/4,2))}else{if(a2==2){i=1}else{if(a2==3){i=1.2}else{if(a2==4){i=1.2}}}}}}return(i*a4*1000)/a5}function ar(){var a3=0,a2=0,a5={},a4,a6;U=aX=0;if(!(a5=$("#hopGrid").jqxGrid("getrows"))){return}aa=1;for(a4=0;a4<a5.length;a4++){a6=a5[a4];a3+=toIBU(a6.h_useat,a6.h_form,ak,parseFloat(d.batch_size),parseFloat(a6.h_amount),parseFloat(a6.h_time),parseFloat(a6.h_alpha),d.ibu_method);a2+=toIBU(a6.h_useat,a6.h_form,ak,parseFloat(d.brew_fermenter_volume)+parseFloat(d.brew_fermenter_tcloss),parseFloat(a6.h_amount),parseFloat(a6.h_time),parseFloat(a6.h_alpha),d.ibu_method);aX+=K(parseFloat(a6.h_time),parseFloat(d.batch_size),a6.h_useat,parseFloat(a6.h_amount));U+=h(parseFloat(a6.h_time),parseFloat(d.batch_size),a6.h_useat,parseFloat(a6.h_amount));if((((d.inventory_reduced<=2)&&(a6.h_useat<=4))||((d.inventory_reduced<=6)&&(a6.h_useat==5)))&&(a6.h_inventory<a6.h_amount)){aa=0}}a3=Math.round(a3*10)/10;a2=Math.round(a2*10)/10;aX=Math.round(aX*1000/5)/10;U=Math.round(U*1000/6)/10;if(aX>100){aX=100}if(U>100){U=100}console.log("calcIBUs(): "+a3+"  flavour: "+aX+"  aroma: "+U+"  fermenter:"+a2+" supplies:"+aa);d.est_ibu=a3;$("#est_ibu").val(a3);$("#est_ibu2").val(a3);$("#hop_flavour").jqxProgressBar("val",aX);$("#hop_aroma").jqxProgressBar("val",U);$("#brew_fermenter_ibu").val(a2);aU();G()}function N(a3,a4,a2){var i=a4/a2;if(i>3.5){return 0}if(a3==2){return 0.4}if(a3==1){return 0.62}if(i<=1.4){return 1.4}return 2.33-(0.67*i)}function aB(i,a3,a7){var a5=2.72715,a4=a7/i*1000,a6=Round(a4,1),a2=(d.starter_sg-1)*i*a5;grate=N(a3,a7,a2),ncells=Round(a2*grate,1),totcells=parseFloat(ncells)+a7;console.log("svol:"+i+" start:"+a7+" irate:"+a6+" egrams:"+a2+" grate:"+grate+" ncells:"+ncells);return{svol:i,irate:a6,prate:Round(a4,1),ncells:ncells,totcells:totcells,growf:Round(ncells/a7,2)}}function F(a8,a2,a9){var a7=[20,40,60,80,100,150,200,250,375,500,625,750,875,1000,1250,1500,2000,2500,3000,4000,5000],a3=a7.length,a4=0,a5=0,ba={},a6;if((parseFloat($("#prop1_volume").jqxNumberInput("decimal"))+parseFloat($("#prop2_volume").jqxNumberInput("decimal"))+parseFloat($("#prop3_volume").jqxNumberInput("decimal"))+parseFloat($("#prop4_volume").jqxNumberInput("decimal")))==0){for(a6=1;a6<5;a6++){$("#prop"+a6+"_type").hide();$("#r"+a6+"_pmpt").show();$("#prop"+a6+"_type").val(a8);$("#prop"+a6+"_volume").hide();$("#prop"+a6+"_volume").val(0);$("#prop"+a6+"_irate").hide();$("#prop"+a6+"_ncells").hide();$("#prop"+a6+"_tcells").hide();$("#prop"+a6+"_growf").hide()}if(a2>a9){return}$("#prop1_type").show();$("#r1_pmpt").hide();$("#prop1_volume").show();$("#prop1_irate").show();$("#prop1_ncells").show();$("#prop1_tcells").show();$("#prop1_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,a2);if(ba.irate<25){a5=a6-1;a4=a7[a5];ba=aB(a4,a8,a2);break}if(ba.totcells>a9||a6==a3){break}}$("#prop1_volume").val(ba.svol/1000);$("#prop1_irate").val(ba.prate);$("#prop1_ncells").val(ba.ncells);$("#prop1_tcells").val(ba.totcells);$("#prop1_growf").val(ba.growf);if(ba.totcells>a9){return}$("#r2_pmpt").hide();$("#prop2_type").val(a8);$("#prop2_type").show();$("#prop2_volume").show();$("#prop2_irate").show();$("#prop2_ncells").show();$("#prop2_tcells").show();$("#prop2_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,$("#prop1_tcells").val());if(ba.irate<25){a5=a6-1;a4=a7[a5];ba=aB(a4,a8,$("#prop1_tcells").val());break}if(ba.totcells>a9||a6==a3){break}}$("#prop2_volume").val(ba.svol/1000);$("#prop2_irate").val(ba.prate);$("#prop2_ncells").val(ba.ncells);$("#prop2_tcells").val(ba.totcells);$("#prop2_growf").val(ba.growf);if(ba.totcells>a9){return}$("#r3_pmpt").hide();$("#prop3_type").val(a8);$("#prop3_type").show();$("#prop3_volume").show();$("#prop3_irate").show();$("#prop3_ncells").show();$("#prop3_tcells").show();$("#prop3_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,$("#prop2_tcells").val());if(ba.irate<25){a5=a6-1;a4=a7[a5];ba=aB(a4,a8,$("#prop2_tcells").val());break}if(ba.totcells>a9||a6==a3){break}}$("#prop3_volume").val(ba.svol/1000);$("#prop3_irate").val(ba.prate);$("#prop3_ncells").val(ba.ncells);$("#prop3_tcells").val(ba.totcells);$("#prop3_growf").val(ba.growf);if(ba.totcells>a9){return}$("#r4_pmpt").hide();$("#prop4_type").val(a8);$("#prop4_type").show();$("#prop4_volume").show();$("#prop4_irate").show();$("#prop4_ncells").show();$("#prop4_tcells").show();$("#prop4_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,$("#prop3_tcells").val());if(ba.totcells>a9||a6==a3){$("#prop4_volume").val(ba.svol/1000);$("#prop4_irate").val(ba.prate);$("#prop4_ncells").val(ba.ncells);$("#prop4_tcells").val(ba.totcells);$("#prop4_growf").val(ba.growf);return}}}else{if(d.prop1_volume>0){$("#r1_pmpt").hide();$("#prop1_type").show();$("#prop1_volume").show();$("#prop1_irate").show();$("#prop1_ncells").show();$("#prop1_tcells").show();$("#prop1_growf").show();ba=aB($("#prop1_volume").val()*1000,d.prop1_type,a2);$("#prop1_irate").val(ba.prate);$("#prop1_ncells").val(ba.ncells);$("#prop1_tcells").val(ba.totcells);$("#prop1_growf").val(ba.growf)}if(d.prop2_volume>0){$("#r2_pmpt").hide();$("#prop2_type").show();$("#prop2_volume").show();$("#prop2_irate").show();$("#prop2_ncells").show();$("#prop2_tcells").show();$("#prop2_growf").show();ba=aB($("#prop2_volume").val()*1000,d.prop2_type,$("#prop1_tcells").val());$("#prop2_irate").val(ba.prate);$("#prop2_ncells").val(ba.ncells);$("#prop2_tcells").val(ba.totcells);$("#prop2_growf").val(ba.growf)}if(d.prop3_volume>0){$("#r3_pmpt").hide();$("#prop3_type").show();$("#prop3_volume").show();$("#prop3_irate").show();$("#prop3_ncells").show();$("#prop3_tcells").show();$("#prop3_growf").show();ba=aB($("#prop3_volume").val()*1000,d.prop3_type,$("#prop2_tcells").val());$("#prop3_irate").val(ba.prate);$("#prop3_ncells").val(ba.ncells);$("#prop3_tcells").val(ba.totcells);$("#prop3_growf").val(ba.growf)}if(d.prop4_volume>0){$("#r4_pmpt").hide();$("#prop4_type").show();$("#prop4_volume").show();$("#prop4_irate").show();$("#prop4_ncells").show();$("#prop4_tcells").show();$("#prop4_growf").show();ba=aB($("#prop4_volume").val()*1000,d.prop4_type,$("#prop3_tcells").val());$("#prop4_irate").val(ba.prate);$("#prop4_ncells").val(ba.ncells);$("#prop4_tcells").val(ba.totcells);$("#prop4_growf").val(ba.growf)}}}function X(){var ba,a3,a9,a5,a8,a2,a7,a6,a4=d.brew_fermenter_sg;if(a4<=1.0001&&d.fg>1){a4=d.fg}else{if(a4<=1.0001){a4=d.est_og}}ba=sg_to_plato(a4);a3=d.brew_fermenter_volume;if(a3>0){if(d.brew_fermenter_extrawater>0){a3+=d.brew_fermenter_extrawater}}else{a3=d.batch_size-d.eq_trub_chiller_loss}$("#yeast_cells").val(Z);if(!(a9=$("#yeastGrid").jqxGrid("getrows"))){return}a5=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(a5==0){return}for(a2=0;a2<a5;a2++){a8=$("#yeastGrid").jqxGrid("getrowdata",a2);if(a8.y_use==0){x=0.75;if(d.est_og>1.06){x=1}if(a8.y_type==0){x*=2}if(a8.y_form==1){}else{}}}a7=x*a3*ba;console.log("calcYeast() pitchrate:"+x+" start:"+Z+" needed:"+a7+" volume:"+a3);$("#need_cells").val(a7);a6=Z;if(d.starter_enable){F(d.starter_type,Z,a7);for(a2=1;a2<5;a2++){$("#r"+a2+"_irate").html("");$("#r"+a2+"_growf").html("");$("#r"+a2+"_tcells").html("");if(parseFloat($("#prop"+a2+"_volume").val())>0){if((parseFloat($("#prop"+a2+"_irate").val())<25)||(parseFloat($("#prop"+a2+"_irate").val())>100)){$("#r"+a2+"_irate").html("<img src='images/dialog-error.png'>")}else{$("#r"+a2+"_irate").html("<img src='images/dialog-ok-apply.png'>")}if(parseFloat($("#prop"+a2+"_growf").val())<1){$("#r"+a2+"_growf").html("<img src='images/dialog-error.png'>")}if(($("#prop"+a2+"_type").val()>0)&&(parseFloat($("#prop"+a2+"_growf").val())>3)){$("#r"+a2+"_growf").html("<img src='images/dialog-error.png'>")}if(parseFloat($("#prop"+a2+"_tcells").val())>a7){$("#r"+a2+"_tcells").html("<img src='images/dialog-ok-apply.png'>")}a6=parseFloat($("#prop"+a2+"_tcells").val())}else{$("#r"+a2+"_irate").html("")}}}$("#plato_cells").val(parseFloat(a6/(a3*ba)))}function ai(a4){console.log("adjustHops("+a4+")");var a5,a3,a2,a6=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}for(a3=0;a3<a6;a3++){a5=$("#hopGrid").jqxGrid("getrowdata",a3);a2=a5.h_amount*a4;$("#hopGrid").jqxGrid("setcellvalue",a3,"h_amount",a2)}}function aF(){ah=1;var a3,a2,a4=$("#miscGrid").jqxGrid("getdatainformation").rowscount;if(a4==0){return}for(a2=0;a2<a4;a2++){a3=$("#miscGrid").jqxGrid("getrowdata",a2);if((((d.inventory_reduced<=2)&&(a3.m_use_use<=2))||((d.inventory_reduced<=3)&&(a3.m_use_use==3))||((d.inventory_reduced<=5)&&(a3.m_use_use==4))||((d.inventory_reduced<=6)&&(a3.m_use_use==5)))&&(a3.m_inventory<a3.m_amount)){ah=0}}G()}function a1(a4){console.log("adjustMiscs("+a4+")");var a5,a3,a2,a6=$("#miscGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}for(a3=0;a3<a6;a3++){a5=$("#miscGrid").jqxGrid("getrowdata",a3);a2=a5.m_amount*a4;$("#miscGrid").jqxGrid("setcellvalue",a3,"m_amount",a2);switch(a5.m_name){case"CaCl2":$("#wa_cacl2").val(a5.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(a5.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(a5.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(a5.m_amount*1000);break;case"Melkzuur":case"Zoutzuur":case"Fosforzuur":case"Zwavelzuur":$("#wa_acid").val(a5.m_amount*1000);break;case"NaHCO3":case"Na2CO3":case"CaCO3":case"Ca(OH)2":$("#wa_base").val(a5.m_amount*1000);break}}}function aO(a4){console.log("adjustYeasts("+a4+")");var a5,a3,a2,a6=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}for(a3=0;a3<a6;a3++){a5=$("#yeastGrid").jqxGrid("getrowdata",a3);if(a5.y_form==1){a2=a5.y_amount*a4;$("#yeastGrid").jqxGrid("setcellvalue",a3,"y_amount",a2)}}X()}function at(a4){console.log("adjustWaters("+a4+")");var a3,a5,a2,a6=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}C=0;for(a2=0;a2<a6;a2++){a5=$("#mashGrid").jqxGrid("getrowdata",a2);if(a5.step_type==0){a3=Round(a5.step_infuse_amount*a4,1);$("#mashGrid").jqxGrid("setcellvalue",a2,"step_infuse_amount",a3);C+=a3}}if(d.w2_amount==0){d.w1_amount=C;$("#w1_amount").val(C)}else{d.w1_amount=(d.w1_amount/(d.w1_amount+d.w2_amount))*C;d.w2_amount=(d.w2_amount/(d.w1_amount+d.w2_amount))*C;$("#w1_amount").val(d.w1_amount);$("#w2_amount").val(d.w2_amount)}$("#wg_amount").val(C)}function aZ(){var a2,i;if(parseFloat($("#brew_mash_sg").jqxNumberInput("decimal"))<1.002){return}a2=sg_to_plato(a0);i=sg_to_plato(parseFloat($("#brew_mash_sg").jqxNumberInput("decimal")));if(a2>0.5){$("#brew_mash_efficiency").val(100*i/a2)}else{$("#brew_mash_efficiency").val(0)}}function w(){var a3=0,a6={},a5,a7,a4,a2=0;if(!(a6=$("#fermentableGrid").jqxGrid("getrows"))){return}for(a5=0;a5<a6.length;a5++){a7=a6[a5];if(a7.f_added==0){a3+=a7.f_amount*(a7.f_yield/100)*(1-a7.f_moisture/100)}}a4=sg_to_plato(d.brew_preboil_sg)*(d.brew_preboil_volume/1.04)*d.brew_preboil_sg*10/1000;if(a3>0){a2=Round((a4/a3*100),1)}if(a2<0){a2=0}$("#brew_preboil_efficiency").val(a2)}function R(){var a4=0,a3=0,a7={},a6,a8,a5,a2=0;if(!(a7=$("#fermentableGrid").jqxGrid("getrows"))){return}for(a6=0;a6<a7.length;a6++){a8=a7[a6];if(a8.f_added==0){a4+=a8.f_amount*(a8.f_yield/100)*(1-a8.f_moisture/100)}else{if(a8.f_added==1){a3+=a8.f_amount*(a8.f_yield/100)*(1-a8.f_moisture/100)}}}a5=sg_to_plato(d.brew_aboil_sg)*(d.brew_aboil_volume/1.04)*d.brew_aboil_sg*10/1000;a5-=a3;if(a4>0){a2=Round((a5/a4*100),1)}if(a2<0){a2=0}d.brew_aboil_efficiency=a2;$("#brew_aboil_efficiency").val(a2)}function Q(){var i=(d.est_og-1)*1000;if(i>0){return d.est_ibu/i}else{return 0.5}}function k(){var i=Q();return(-1.2*i+1.4)}function aA(a2,a4){var a8,a3,a9,a7=false,a5,a6=$("#miscGrid").jqxGrid("getrows");if(a4==0){for(a3=0;a3<a6.length;a3++){a8=a6[a3];if(a8.m_name==a2){a9=$("#miscGrid").jqxGrid("getrowid",a3);$("#miscGrid").jqxGrid("deleterow",a9)}}}else{for(a3=0;a3<a6.length;a3++){a8=a6[a3];if(a8.m_name==a2){a7=true;$("#miscGrid").jqxGrid("setcellvalue",a3,"m_amount",a4/1000);break}}if(!a7){a5=new $.jqx.dataAdapter(miscInvSource,{loadComplete:function(){var ba,bc,bd={},bb=a5.records;for(bc=0;bc<bb.length;bc++){ba=bb[bc];if(ba.name==a2){bd.m_name=ba.name;bd.m_amount=a4/1000;bd.m_cost=ba.cost;bd.m_type=ba.type;bd.m_use_use=ba.use_use;bd.m_time=0;bd.m_amount_is_weight=ba.amount_is_weight;bd.m_inventory=ba.inventory;bd.m_avail=1;$("#miscGrid").jqxGrid("addrow",null,bd)}}}});a5.dataBind();return}}}function m(a2,i){if((i=="laag")||(i=="hoog")){$("#wr_"+a2).html("<img src='images/dialog-error.png'><span style='vertical-align: top; font-size: 10px; font-style: italic;'>"+i+"</span>")}else{$("#wr_"+a2).html("<img src='images/dialog-ok-apply.png'>")}}function aP(a4,a3,a2,i){if((a4+a3)>0){return((a4*a2)+(a3*i))/(a4+a3)}return 0}function aq(a3,a2,i){return a3-(a2/1.4+i/1.7)}function z(a2){var i=Math.pow(10,-a2);return 100*az*ax/(i*i+i*az+az*ax)}function ay(a2){var i=Math.pow(10,-a2);return 100*az*i/(i*i+i*az+az*ax)}function aw(i){return(-2*z(i)-ay(i))}function J(a2){var a5=aw(4.3),a3=aw(parseFloat($("#wg_ph").jqxNumberInput("decimal"))),i=aw(a2),a7=-a5+a3,a6=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))/50/a7,a4=-i+a3;return a6*a4}function al(a2){var a3,a4,i=parseFloat($("#wg_calcium").jqxNumberInput("decimal"))/(A/2);a3=parseFloat($("#wg_magnesium").jqxNumberInput("decimal"))/(ap/2);a4=J(a2);return a4-(i/3.5+a3/7)}function L(a4){var a7,a5,a6,a3,a2,a8=al(a4)*parseFloat($("#wg_amount").jqxNumberInput("decimal"));a7=$("#fermentableGrid").jqxGrid("getrows");for(a5=0;a5<a7.length;a5++){row=a7[a5];if(row.f_added==0&&row.f_graintype!=6){a6=0;if((row.f_di_ph!=5.7)&&((row.f_acid_to_ph_57<-0.1)||(row.f_acid_to_ph_57>0.1))){a6=row.f_acid_to_ph_57/(row.f_di_ph-5.7)}else{a3=row.f_color;switch(row.f_graintype){case 0:case 3:case 5:a6=0.014*a3-34.192;break;case 2:a6=-0.0597*a3-32.457;break;case 1:a6=0.0107*a3-54.768;break;case 4:a6=-149;break}}a2=a6*(a4-row.f_di_ph);a8+=a2*row.f_amount}}return a8}function aM(){var a5=0,a3=5.4,a2=0.001,a4=0.1,i=L(a3);while(((i<-a4)||(i>a4))&&(a5<2000)){a5++;if(i<-a4){a3-=a2}else{if(i>a4){a3+=a2}}i=L(a3)}console.log("MashpH() n: "+a5+" pH: "+a3);return a3}function t(i){switch(i){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}}}function P(){console.log("calcWater()");var bj=0,by=0,a9=0,bk=0,ba=0,bv=0,bb=0,bt=0,bd=0,bm=0,bE=0,bC=0,bz=0,bx,bn,bf,a4,a3,i,be,a6,a5,bp,bh,a8,bq,bi,bw,bo,bg,br,bD,bs,bc,bA,bl,bB,a7,bu,a2;if(d.w1_name==""){return}if(d.w2_name!=""){bj=d.w1_amount+d.w2_amount;by=aP(d.w1_amount,d.w2_amount,d.w1_calcium,d.w2_calcium);a9=aP(d.w1_amount,d.w2_amount,d.w1_magnesium,d.w2_magnesium);bk=aP(d.w1_amount,d.w2_amount,d.w1_sodium,d.w2_sodium);bb=aP(d.w1_amount,d.w2_amount,d.w1_chloride,d.w2_chloride);bt=aP(d.w1_amount,d.w2_amount,d.w1_sulfate,d.w2_sulfate);ba=aP(d.w1_amount,d.w2_amount,d.w1_total_alkalinity,d.w2_total_alkalinity);bd=-Math.log10(((Math.pow(10,-d.w1_ph)*d.w1_amount)+(Math.pow(10,-d.w2_ph)*d.w2_amount))/bj)}else{bj=d.w1_amount;by=d.w1_calcium;a9=d.w1_magnesium;bk=d.w1_sodium;bb=d.w1_chloride;bt=d.w1_sulfate;ba=d.w1_total_alkalinity;bd=d.w1_ph}$("#wg_amount").val(bj);bA=by;$("#wg_calcium").val(Math.round(by*10)/10);$("#wg_magnesium").val(Math.round(a9*10)/10);bl=bk;$("#wg_sodium").val(Math.round(bk*10)/10);bB=ba;$("#wg_total_alkalinity").val(Math.round(ba*10)/10);a7=bb;$("#wg_chloride").val(Math.round(bb*10)/10);bu=bt;$("#wg_sulfate").val(Math.round(bt*10)/10);$("#wg_ph").val(Round(bd,1));$("#wb_ph").val(Round(aM(),1));$("#est_mash_ph").val(Round(aM(),1));bv=ba*1.22;a2=bv;bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am;by+=1000*bm/bj;bm=parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*ap/aJ;a9+=1000*bm/bj;bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*ac/aE;bk+=1000*bm/bj;bm=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*aH/am+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*aH/aJ;bt+=1000*bm/bj;bm=2*parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*q/S+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*q/b;bb+=1000*bm/bj;if($("#wa_acid_name").val()<0||$("#wa_acid_name").val()>3){$("#wa_acid_name").val(0);d.wa_acid_name=0}if(af==""){af=AcidTypeData[$("#wa_acid_name").val()].nl}if($("#wa_base_name").val()<0||$("#wa_base_name").val()>3){$("#wa_base_name").val(0);d.wa_base_name=0}if(aT==""){aT=BaseTypeData[$("#wa_base_name").val()].nl}bx=d.wa_acid_name;bn=d.wa_base_name;bf=t(bx);a4=bf.pK1;a3=bf.pK2;i=bf.pK3;be=bf.MolWt;a6=bf.AcidSG;a5=bf.AcidPrc;if(d.calc_acid){bC=parseFloat(d.mash_ph);bz=L(bC);console.log("calc_acid tgt: "+bC+" protonDeficit: "+bz);if(bz>0){$("#wa_base").val(0);aA(aT,0);bE=CalcFrac(bC,a4,a3,i);Acid=bz/bE;Acid*=be;Acidmg=Acid;Acid=Acid/a6;if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(a5)}Acid=Acid*a5/(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);console.log("Final ml: "+Acid);$("#wa_acid").val(Round(Acid,2));aA(AcidTypeData[bx].nl,Round(Acid,2));bv=bv-bz*bE/bj;ba=bv*50/61}else{if(bz<0){$("#wa_acid").val(0);aA(af,0);bp=Math.pow(10,(bC-6.38));bh=Math.pow(10,(bC-10.38));a8=1/(1+bp+bp*bh);bq=a8*bp;bi=bq*bh;switch(bn){case 0:bm=-bz/(a8-bi);bm=bm*aE/1000;$("#wa_base").val(Round(bm,2));aA("NaHCO3",Round(bm,2));if(bj>0){bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*ac/aE;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/aE;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 1:bm=-bz/(2*a8+bq);bm=bm*y/1000;$("#wa_base").val(Round(bm,2));aA("Na2CO3",Round(bm,2));if(bj>0){bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*ac/y;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/y;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 2:bm=-bz*(a8-bi);bm=bm*g/1000;bm=3*bm;$("#wa_base").val(Round(bm,2));aA("CaCO3",Round(bm,2));if(bj>0){bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*r/g;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am+parseFloat($("#wa_base").jqxNumberInput("decimal"))*A/g;bm=1000*bm/bj;by=bA+bm;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 3:bm=-bz/19.3;$("#wa_base").val(Round(bm,2));aA("Ca(OH)2",Round(bm,2));if(bj>0){bm=-bz/bj;ba=bB+bm;bv=ba*61/50;bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am+parseFloat($("#wa_base").jqxNumberInput("decimal"))*A/aI;bm=1000*bm/bj;by=bA+bm;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break}}}bd=bC;$("#wb_ph").val(Round(bd,1));$("#est_mash_ph").val(Round(bd,1))}else{console.log("calc_acid no");if(parseFloat($("#wa_base").jqxNumberInput("decimal"))>0){if(bj>0){switch(bn){case 0:bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*ac/aE;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/aE;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 1:bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*ac/y;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/y;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 2:bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*r/g;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium);bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am+parseFloat($("#wa_base").jqxNumberInput("decimal"))*A/g;bm=1000*bm/bj;by=bA+bm;break}}}bC=parseFloat(d.mash_ph);pHa=aM();if(parseFloat($("#wa_acid").jqxNumberInput("decimal"))>0){console.log("TpH: "+bC+" water: "+pHa);Acid=parseFloat($("#wa_acid").jqxNumberInput("decimal"));if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(a5)}Acid=Acid/a5*(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);Acid*=a6;Acid/=be;Acidmg=Acid;bE=CalcFrac(pHa,a4,a3,i);bz=Acid*bE;bw=0.001;bo=0.1;bg=L(pHa);br=0;while(((bg<(bz-bo))||(bg>(bz+bo)))&&(br<2000)){br++;if(bg<(bz-bo)){pHa-=bw}else{if(bg>(bz+bo)){pHa+=bw}}bE=CalcFrac(pHa,a4,a3,i);bz=Acid*bE;bg=L(pHa)}console.log("n: "+br+" pd: "+bg+" protonDeficit: "+bz+" frac: "+bE+" pHa: "+pHa);bm=a2-bz*bE/bj;bv=bm;ba=bm*50/61;bd=pHa;$("#wb_ph").val(Round(bd,1));$("#est_mash_ph").val(Round(bd,1))}}if((bx==3)&&(bj>0)){bm=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*aH/am+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*aH/aJ+Acidmg/1000*aH/(aH+2);bm=1000*bm/bj;bt=bu+bm}else{if((bx==1)&&(bj>0)){bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*q/S+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*q/b+Acidmg/1000*q/(q+1);bm=1000*bm/bj;bb=a7+bm}}$("#tgt_bu").val(Round(Q(),2));if(Q()<0.32){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Zeer moutig en zoet</span>")}else{if(Q()<0.43){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Moutig, zoet</span>")}else{if(Q()<0.52){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Evenwichtig</span>")}else{if(Q()<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(Round(k(),1));if(bt>0){bm=bb/bt}else{bm=10}$("#got_cl_so4").val(Round(bm,1));bD=0.8*k();bs=1.2*k();bc="normaal";if(bm<bD){bc="laag"}else{if(bm>bs){bc="hoog"}}m("cl_so4",bc);$("#wb_calcium").val(Round(by,1));$("#wb_magnesium").val(Round(a9,1));$("#wb_sodium").val(Round(bk,1));$("#wb_sulfate").val(Round(bt,1));$("#wb_chloride").val(Round(bb,1));$("#wb_total_alkalinity").val(Round(ba,1));if(by<40){m("calcium","laag")}else{if(by>150){m("calcium","hoog")}else{m("calcium","normaal")}}if(a9>=0&&a9<=30){m("magnesium","normaal")}else{m("magnesium","hoog")}if(bk<=150){m("sodium","normaal")}else{m("sodium","hoog")}if(bb<=50){m("chloride","laag")}else{if(bb<=100){m("chloride","normaal")}else{m("chloride","hoog")}}if(bt<=50){m("sulfate","laag")}else{if(bt<=350){m("sulfate","normaal")}else{m("sulfate","hoog")}}if(bd<5.2){m("ph","laag")}else{if(bd>5.6){m("ph","hoog")}else{m("ph","normaal")}}j();aF();G()}function j(){var a4,bg,be,bm,bl,bp,bj,bi,bk,a7,bu,bs,a2,a6,a9,bf,bq,bo,br,bh,a3,a8,bd,bc,bb,ba,bt,a5,i,bn;a4=d.sparge_ph;bg=d.w1_ph;be=d.w1_total_alkalinity;if(d.sparge_source==1){if(d.w2_ph>0){bg=d.w2_ph;be=d.w2_total_alkalinity}else{d.sparge_source=0;$("#sparge_source").val(0)}}else{if(d.sparge_source==2){if(d.w2_ph>0){bg=parseFloat($("#wg_ph").jqxNumberInput("decimal"));be=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))}else{d.sparge_source=0;$("#sparge_source").val(0)}}}bm=Math.pow(10,bg-6.38);bl=Math.pow(10,bg-10.373);bp=1+bm+bm*bl;bj=1/bp;bi=bm*bl/bp;bk=Math.pow(10,4.3-6.38);a7=Math.pow(10,4.3-10.373);bu=1+bk+bk*a7;bs=1/bu;a2=bk*a7/bu;a6=be/50;a9=(a6-1000*(Math.pow(10,-4.3)-Math.pow(10,-bg)))/((bs-bj)+(bi-a2));bf=Math.pow(10,a4-6.38);bq=Math.pow(10,a4-10.373);bo=1+bf+bf*bq;br=1/bo;bh=bf*bq/bo;a3=a9*((br-bj)+(bi-bh))+Math.pow(10,-a4)-Math.pow(10,-bg);a3+=0.01;if(d.sparge_acid_type<0||d.sparge_acid_type>3){d.sparge_acid_type=0;$("#sparge_acid_type").val(0)}a8=d.sparge_acid_type;bd=t(a8);bc=bd.pK1;bb=bd.pK2;ba=bd.pK3;bt=bd.MolWt;a5=bd.AcidSG;i=bd.AcidPrc;bn=CalcFrac(a4,bc,bb,ba);a3/=bn;a3*=bt;a3=a3/a5;bj=d.sparge_acid_perc;if(bj<=0.1){bj=i}a3=a3*i/(bj/100);a3*=d.sparge_volume;a3=Round(a3,2);d.sparge_acid_amount=a3/1000;$("#sparge_acid_amount").val(a3)}function M(){var a2,i,a4,a3;if(d.brew_fermenter_sg<1.02){return}if((d.primary_end_sg>0.99)&&(d.primary_end_sg<d.brew_fermenter_sg)){a2=Round(100*(d.brew_fermenter_sg-d.primary_end_sg)/(d.brew_fermenter_sg-1),1);$("#primary_svg").val(a2);if((d.secondary_end_sg>0.99)&&(d.secondary_end_sg<d.brew_fermenter_sg)){i=Round(100*(d.brew_fermenter_sg-d.secondary_end_sg)/(d.brew_fermenter_sg-1),1);$("#secondary_svg").val(i);if((d.fg>0.99)&&(d.fg<d.brew_fermenter_sg)){a4=Round(100*(d.brew_fermenter_sg-d.fg)/(d.brew_fermenter_sg-1),1);$("#final_svg").val(a4);a3=Round(abvol(d.brew_fermenter_sg,d.fg),2);$("#final_abv").val(a3)}}}}function an(a2,i){var a3=i*1.8+32;return 3.0378-0.050062*a3+0.00026555*a3*a3}function V(a2,i,a4){var a3=a4*(a2-an(a2,i))/0.286;if(a3<0){a3=0}return Round(a3,3)}function o(a2,a5,a4){var a3,i=a2-an(a2,a5);if(i<0){return 0}a3=-1.09145427669121+0.00800006989646477*a4+0.000260276315484684*a4*a4+0.0215142075945119*a4*i+0.674996600795854*i+-0.00471757220150754*i*i;if(a3<0){a3=0}a3=a3*1.01325;return Round(a3,1)}function Y(a2,i){return(a2-(-0.000005594056*Math.pow(i,4)+0.000144357886*Math.pow(i,3)+0.000362999168*i*i-0.064872987645*i+1.641145175049))/(0.00000498031*Math.pow(i,4)-0.00024358267*Math.pow(i,3)+0.00385867329*i*i-0.05671206825*i+1.53801423376)}function aR(){var a9,a6,ba,a8,a4,be,bb,a2,bg,a5,bh,bd,a3,a7,bc,bf;a9=d.secondary_temp;if(a9<1){a9=d.primary_end_temp}if(a9<1){a9=18}if(d.fg==0){a6=abvol(d.brew_fermenter_sg,parseFloat($("#est_fg").jqxNumberInput("decimal")))}else{a6=abvol(d.brew_fermenter_sg,d.fg)}ba=d.package_volume-(a6*d.package_volume)/100;a8=d.package_volume-ba;be=d.package_infuse_amount-(d.package_infuse_abv*d.package_infuse_amount)/100;bb=d.package_infuse_amount-be;bg=a8+bb;a2=ba+be;a6=Round(bg/(a2+bg)*100,2);d.package_abv=a6;$("#package_abv").val(a6);if(!(rows=$("#fermentableGrid").jqxGrid("getrows"))){return}d.bottle_priming_amount=0;d.bottle_priming_total=0;for(a5=0;a5<rows.length;a5++){bh=rows[a5];if(bh.f_added==4){bd=1/((bh.f_yield/100)*(1-bh.f_moisture/100));d.bottle_priming_amount=V(d.bottle_carbonation,a9,bd);d.bottle_priming_total=Round(d.bottle_amount*d.bottle_priming_amount,2);$("#fermentableGrid").jqxGrid("setcellvalue",a5,"f_amount",d.bottle_priming_total/1000)}}$("#bottle_priming_amount").val(Round(d.bottle_priming_amount,1));$("#bottle_priming_total").val(d.bottle_priming_total);a7=a6+d.bottle_priming_amount*0.47/7.907;a3=d.bottle_amount-(a7*d.bottle_amount)/100;bg=d.bottle_amount-a3;a2=a3+d.bottle_priming_water;a4=Round(bg/(a2+bg)*100,2);$("#bottle_abv").val(a4);$("#bottle_pressure").val(o(d.bottle_carbonation,a9,d.bottle_carbonation_temp));bc=Y(d.keg_carbonation,d.keg_carbonation_temp);if(bc<0){bc=0}d.keg_pressure=bc;$("#keg_pressure").val(Round(bc,1));d.keg_priming_amount=0;d.keg_priming_total=0;if(!d.keg_forced_carb){for(a5=0;a5<rows.length;a5++){bh=rows[a5];if(bh.f_added==5){bd=1/((bh.f_yield/100)*(1-bh.f_moisture/100));d.keg_priming_amount=V(d.keg_carbonation,a9,bd);d.keg_priming_total=Round(d.keg_amount*d.keg_priming_amount,2);$("#fermentableGrid").jqxGrid("setcellvalue",a5,"f_amount",d.keg_priming_total/1000)}}$("#keg_priming_amount").val(Round(d.keg_priming_amount,1));$("#keg_priming_total").val(d.keg_priming_total);a7=a6+d.keg_priming_amount*0.47/7.907;a3=d.keg_amount-(a7*d.keg_amount)/100;bg=d.keg_amount-a3;a2=a3+d.keg_priming_water;bf=Round(bg/(a2+bg)*100,2);$("#keg_abv").val(bf)}else{$("#keg_priming_amount").val(0);$("#keg_priming_total").val(0);$("#keg_abv").val(a6)}}function aU(){var a7=d.stage,a6,a4,a2,a8,a5,i,a3;if(a7==0&&d.est_og>1.005&&d.est_color>3&&d.est_ibu>3){a7=1}if(a7==1&&parseFloat($("#brew_date_start").val())>2000){a7=2}if(a7==2&&($("#brew_date_start").val()=="")){a7=1}if(a7==2&&parseFloat($("#brew_date_end").val())>2000){a7=3}if(a7==3&&parseFloat($("#primary_end_date").val())>2000){a7=4}if(a7==4&&parseFloat($("#secondary_end_date").val())>2000){a7=5}if(a7==5&&parseFloat($("#package_date").val())>2000){a7=6}if(a7>=6&&a7<9){a6=new Date();a2=$("#package_date").val();a2=a2.split("-");a4=new Date(a6.getFullYear(),a6.getMonth(),a6.getDate());a2=new Date(a2[0],a2[1]-1,a2[2]);a8=parseInt(a4.getTime()/1000);a5=parseInt(a2.getTime()/1000);i=a8-a5;a3=i/60/60/24;if(a3>0){if(a3>=42){a7=9}else{if(a3>=14){a7=8}else{a7=7}}}}if(a7==9&&parseFloat($("#taste_date").val())>2000){a7=10}if(a7!=d.stage){console.log("calcStage() old: "+d.stage+" new: "+a7);d.stage=a7}$("#stage").val(StageData[d.stage].nl);if(d.stage>=10){$("#locked").jqxCheckBox({disabled:false})}if(d.stage>1){$("#equipmentSelect").jqxDropDownList({disabled:true});$("#Delete").jqxButton({disabled:true})}if(d.stage<1){$("#jqxTabs").jqxTabs("disableAt",8)}else{$("#jqxTabs").jqxTabs("enableAt",8)}if(d.stage<3){$("#jqxTabs").jqxTabs("disableAt",9)}else{$("#jqxTabs").jqxTabs("enableAt",9);$("#name").jqxInput({disabled:true});$("#code").jqxInput({disabled:true});$("#batch_size").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#boil_size").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#boil_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#efficiency").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#est_og").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#type").jqxDropDownList({disabled:true});$("#styleSelect").jqxDropDownList({disabled:true});$("#color_method").jqxDropDownList({disabled:true});$("#ibu_method").jqxDropDownList({disabled:true});$("#mash_select").jqxDropDownList({disabled:true});$("#w1_name").jqxDropDownList({disabled:true});$("#w2_name").jqxDropDownList({disabled:true});$("#w2_amount").jqxNumberInput({readOnly:true});$("#pr_name").jqxDropDownList({disabled:true});$("#wa_cacl2").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_caso4").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_mgso4").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_nacl").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#mash_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#calc_acid").jqxCheckBox({disabled:true});$("#wa_base_name").jqxDropDownList({disabled:true});$("#wa_base").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_acid_name").jqxDropDownList({disabled:true});$("#wa_acid").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_acid_perc").jqxNumberInput({spinButtons:false,readOnly:true,width:70});$("#sparge_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#sparge_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#sparge_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#sparge_source").jqxDropDownList({disabled:true});$("#sparge_acid_type").jqxDropDownList({disabled:true});$("#sparge_acid_perc").jqxNumberInput({spinButtons:false,readOnly:true,width:false});$("#starter_enable").jqxCheckBox({disabled:true});$("#starter_type").jqxDropDownList({disabled:true});$("#starter_try").jqxButton({disabled:true});$("#starter_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#starter_viability").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}if(d.stage>3){$("#brew_date_start").jqxDateTimeInput({disabled:true});$("#brew_date_end").jqxDateTimeInput({disabled:true});$("#brew_mash_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_preboil_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aboil_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_mash_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_preboil_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aboil_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_preboil_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aboil_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_whirlpool9").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_cooling_to").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_whirlpool7").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_cooling_method").jqxDropDownList({disabled:true});$("#brew_whirlpool6").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_cooling_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_sparge_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_whirlpool2").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aeration_type").jqxDropDownList({disabled:true});$("#brew_fermenter_tcloss").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aeration_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_fermenter_extrawater").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aeration_speed").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}if(d.stage==5){$("#package_date").jqxDateTimeInput({disabled:false})}else{$("#package_date").jqxDateTimeInput({disabled:true})}if(d.stage>=5){$("#primary_start_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_max_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_brix").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_date").jqxDateTimeInput({disabled:true})}if(d.stage>=6){$("#secondary_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#secondary_end_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#secondary_end_date").jqxDateTimeInput({disabled:true});$("#tertiary_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#fg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#final_brix").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_date").jqxDateTimeInput({disabled:true});$("#package_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_infuse_amount").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_infuse_abv").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_infuse_notes").jqxInput({disabled:true});$("#package_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_amount").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_priming_water").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_priming_water").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_amount").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_carbonation").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_carbonation").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_priming_sugar").jqxDropDownList({disabled:true});$("#keg_priming_sugar").jqxDropDownList({disabled:true});$("#keg_forced_carb").jqxCheckBox({disabled:true});$("#bottle_carbonation_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_carbonation_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}if(d.stage<8){$("#jqxTabs").jqxTabs("disableAt",11)}else{$("#jqxTabs").jqxTabs("enableAt",11)}if(d.stage==11){$("#taste_date").jqxDateTimeInput({disabled:true});$("#taste_rate").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#taste_color").jqxInput({disabled:true});$("#taste_transparency").jqxInput({disabled:true});$("#taste_head").jqxInput({disabled:true});$("#taste_aroma").jqxInput({disabled:true});$("#taste_taste").jqxInput({disabled:true});$("#taste_aftertaste").jqxInput({disabled:true});$("#taste_mouthfeel").jqxInput({disabled:true});$("#taste_notes").jqxInput({disabled:true});$("#notes").jqxInput({disabled:true})}else{$("#notes").jqxInput({disabled:false})}}function I(){if(d.starter_enable){$("#propagator").show();$("#starter_type").jqxDropDownList({disabled:false});$("#starter_try").jqxButton({disabled:false});$("#starter_sg").jqxNumberInput({spinButtons:true,readOnly:false,width:110});$("#starter_viability").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}else{$("#propagator").hide();$("#starter_type").jqxDropDownList({disabled:true});$("#starter_try").jqxButton({disabled:true});$("#starter_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#starter_viability").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}}function aW(){console.log("calcInit()");aZ();w();R();$("#starter_enable").on("checked",function(i){d.starter_enable=1;I();X()});$("#starter_enable").on("unchecked",function(i){d.starter_enable=0;I();X()});$("#starter_try").click(function(){$("#prop1_volume").val(0);$("#prop2_volume").val(0);$("#prop3_volume").val(0);$("#prop4_volume").val(0);X()});$("#starter_type").on("change",function(a2){if(a2.args){var i=a2.args.index;d.starter_type=i;X()}});$("#starter_sg").on("change",function(i){if(i.args){d.starter_sg=i.args.value;X()}});$("#starter_viability").on("change",function(i){if(i.args){d.starter_viability=i.args.value;T();X()}});$("#prop1_type").on("change",function(a2){if(a2.args){var i=a2.args.index;d.prop1_type=i;X()}});$("#prop1_volume").on("change",function(i){if(i.args){d.prop1_volume=i.args.value;X()}});$("#prop2_type").on("change",function(a2){if(a2.args){var i=a2.args.index;d.prop2_type=i;X()}});$("#prop2_volume").on("change",function(i){if(i.args){d.prop2_volume=i.args.value;X()}});$("#prop3_type").on("change",function(a2){if(a2.args){var i=a2.args.index;d.prop3_type=i;X()}});$("#prop3_volume").on("change",function(i){if(i.args){d.prop3_volume=i.args.value;X()}});$("#prop4_type").on("change",function(a2){if(a2.args){var i=a2.args.index;d.prop4_type=i;X()}});$("#prop4_volume").on("change",function(i){if(i.args){d.prop4_volume=i.args.value;X()}});$("#calc_acid").on("checked",function(i){d.calc_acid=1;P()});$("#calc_acid").on("unchecked",function(i){d.calc_acid=0;P()});$("#w1_name").jqxDropDownList("selectItem",d.w1_name);$("#w2_name").jqxDropDownList("selectItem",d.w2_name);if(parseFloat($("#w1_amount").jqxNumberInput("decimal"))==0&&C>0){$("#w1_amount").val(C);d.w1_amount=C;$("#wg_amount").val(C);$("#w2_amount").val(0);d.w2_amount=0}P();$("#w2_amount").on("change",function(i){var a2=parseFloat(i.args.value);if(a2>C){$("#w2_amount").val(d.w2_amount);return}d.w1_amount=parseFloat($("#wg_amount").jqxNumberInput("decimal"))-a2;$("#w1_amount").val(d.w1_amount);d.w2_amount=a2;console.log("new: "+i.args.value+" w1: "+d.w1_amount+"  w2: "+d.w2_amount);P()});$("#wa_cacl2").on("change",function(i){if(i.args){aA("CaCl2",0);aA("CaCl2",i.args.value);P()}});$("#wa_caso4").on("change",function(i){if(i.args){aA("CaSO4",0);aA("CaSO4",i.args.value);P()}});$("#wa_mgso4").on("change",function(i){if(i.args){aA("MgSO4",0);aA("MgSO4",i.args.value);P()}});$("#wa_nacl").on("change",function(i){if(i.args){aA("NaCl",0);aA("NaCl",i.args.value);P()}});$("#wa_base_name").on("change",function(a2){if(a2.args){var i=a2.args.index;console.log("wa_base_name "+i);aA(aT,0);aT=BaseTypeData[i].nl;aA(aT,parseFloat($("#wa_base").jqxNumberInput("decimal")));d.wa_base_name=i;P()}});$("#wa_base").on("change",function(a2){var i=BaseTypeData[$("#wa_base_name").val()].nl;aA(i,parseFloat(a2.args.value));P()});$("#wa_acid_name").on("change",function(a2){if(a2.args){var i=a2.args.index;console.log("wa_acid_name "+i);aA(af,0);af=AcidTypeData[i].nl;aA(af,parseFloat($("#wa_acid").jqxNumberInput("decimal")));d.wa_acid_name=i;P()}});$("#wa_acid").on("change",function(a2){var i=AcidTypeData[$("#wa_acid_name").val()].nl;aA(i,parseFloat(a2.args.value));P()});$("#wa_acid_perc").on("change",function(i){P()});$("#color_method").on("change",function(i){d.color_method=i.args.index;T()});$("#ibu_method").on("change",function(i){d.ibu_method=i.args.index;T();ar()});$("#batch_size").on("change",function(a3){console.log("batch_size change:"+a3.args.value+" old:"+d.batch_size);$("#est_a_vol").val(a3.args.value*1.04);var i,a2=parseFloat(a3.args.value)+d.boil_size-d.batch_size;i=parseFloat(a3.args.value)/d.batch_size;d.boil_size=a2;$("#boil_size").val(Round(a2,2));$("#est_pre_vol").val(Round(a2*1.04,2));d.sparge_volume*=i;$("#sparge_volume").val(d.sparge_volume);$("#brew_sparge_volume").val(d.sparge_volume);d.batch_size=parseFloat(a3.args.value);ae(parseFloat($("#est_og").jqxNumberInput("decimal")));at(i);T();ai(i);a1(i);aO(i);ar();P();j();aN()});$("#boil_time").on("change",function(a3){console.log("boil_time change:"+parseFloat(a3.args.value)+" old:"+d.boil_time);var a2,i,a4=parseFloat(d.boil_size)-parseFloat(d.batch_size);i=a4*(parseFloat(a3.args.value)/d.boil_time);a2=parseFloat(d.batch_size)+i;d.boil_time=parseFloat(a3.args.value);d.boil_size=a2;$("#est_pre_vol").val(Round(a2*1.04,2));$("#boil_size").val(Round(a2,2));T();ar();X()});$("#efficiency").on("change",function(a2){var i=parseFloat($("#est_og").jqxNumberInput("decimal"));d.efficiency=parseFloat(a2.args.value);console.log("efficiency change:"+d.efficiency+" est_og:"+i);ae(i);T();ar();X()});$("#est_og").on("change",function(i){d.est_og=parseFloat(i.args.value);console.log("est_og change:"+d.est_og);$("#est_og2").val(d.est_og);ae(d.est_og);T();ar();aN();X()});$("#mash_ph").on("change",function(i){d.mash_ph=parseFloat(i.args.value);P()});$("#sparge_ph").on("change",function(i){d.sparge_ph=parseFloat(i.args.value);j()});$("#sparge_volume").on("change",function(i){d.sparge_volume=parseFloat(i.args.value);$("#brew_sparge_volume").val(d.sparge_volume);j()});$("#sparge_temp").on("change",function(i){d.sparge_temp=parseFloat(i.args.value);$("#brew_sparge_temperature").val(d.sparge_temp)});$("#sparge_source").on("change",function(a2){if(a2.args){var i=a2.args.index;d.sparge_source=i;j()}});$("#sparge_acid_type").on("change",function(a2){if(a2.args){var i=a2.args.index;d.sparge_acid_type=i;console.log("new sparge_acid_type: "+d.sparge_acid_type);j()}});$("#sparge_acid_perc").on("change",function(i){d.sparge_acid_perc=parseFloat(i.args.value);j()});M();aR();$("#package_volume").on("change",function(a2){var a3,a4,i=d.package_volume+d.package_infuse_amount;d.package_volume=parseFloat(a2.args.value);if(d.package_volume>d.brew_fermenter_volume){d.package_volume=d.brew_fermenter_volume;$("#package_volume").val(d.package_volume)}a4=d.package_volume+d.package_infuse_amount;a3=a4-i;if(i>0){d.bottle_amount+=(d.bottle_amount/i)*a3;d.keg_amount+=(d.keg_amount/i)*a3}else{d.bottle_amount=a4;d.keg_amount=0}console.log("diff:"+a3+" old:"+i+" bottle:"+d.bottle_amount+" keg:"+d.keg_amount);$("#bottle_amount").val(parseFloat(d.bottle_amount*1000)/1000);$("#keg_amount").val(parseFloat(d.keg_amount*1000)/1000);aR()});$("#package_infuse_amount").on("change",function(a2){var a3,a4,i=d.package_volume+d.package_infuse_amount;d.package_infuse_amount=parseFloat(a2.args.value);a4=d.package_volume+d.package_infuse_amount;a3=a4-i;if(i>0){d.bottle_amount+=(d.bottle_amount/i)*a3;d.keg_amount+=(d.keg_amount/i)*a3}else{d.bottle_amount=a4;d.keg_amount=0}console.log("diff:"+a3+" old:"+i+" bottle:"+d.bottle_amount+" keg:"+d.keg_amount);$("#bottle_amount").val(parseFloat(d.bottle_amount*1000)/1000);$("#keg_amount").val(parseFloat(d.keg_amount*1000)/1000);aR()});$("#package_infuse_abv").on("change",function(i){d.package_infuse_abv=parseFloat(i.args.value);aR()});$("#bottle_amount").on("change",function(a3){var i,a4,a2=parseFloat(a3.args.value);i=d.package_volume+d.package_infuse_amount;if(a2>i){a2=i}a4=d.bottle_amount-a2;d.bottle_amount=Math.round((d.bottle_amount-a4)*1000)/1000;d.keg_amount=Math.round((d.keg_amount+a4)*1000)/1000;$("#bottle_amount").val(parseFloat(d.bottle_amount));$("#keg_amount").val(parseFloat(d.keg_amount));aR()});$("#bottle_priming_water").on("change",function(i){d.bottle_priming_water=parseFloat(i.args.value);aR()});$("#keg_amount").on("change",function(a3){var a4,i,a2=parseFloat(a3.args.value);i=d.package_volume+d.package_infuse_amount;if(a2>i){a2=i}a4=d.keg_amount-a2;d.bottle_amount=Math.round((d.bottle_amount+a4)*1000)/1000;d.keg_amount=Math.round((d.keg_amount-a4)*1000)/1000;$("#bottle_amount").val(parseFloat(d.bottle_amount));$("#keg_amount").val(parseFloat(d.keg_amount));aR()});$("#keg_priming_water").on("change",function(i){d.keg_priming_water=parseFloat(i.args.value);aR()});$("#bottle_carbonation").on("change",function(i){d.bottle_carbonation=parseFloat(i.args.value);aR()});$("#bottle_carbonation_temp").on("change",function(i){d.bottle_carbonation_temp=parseFloat(i.args.value);aR()});$("#keg_carbonation").on("change",function(i){d.keg_carbonation=parseFloat(i.args.value);aR()});$("#keg_forced_carb").on("checked",function(i){d.keg_forced_carb=1;aR()});$("#keg_forced_carb").on("unchecked",function(i){d.keg_forced_carb=0;aR()});$("#keg_carbonation_temp").on("change",function(i){d.keg_carbonation_temp=parseFloat(i.args.value);aR()});$("#brew_fermenter_extrawater").on("change",function(i){d.brew_fermenter_extrawater=parseFloat(i.args.value);T();ar();X()});$("#brew_fermenter_tcloss").on("change",function(i){d.brew_fermenter_tcloss=parseFloat(i.args.value);T();ar();X()});$("#primary_end_sg").on("change",function(i){d.primary_end_sg=parseFloat(i.args.value);M()});$("#primary_end_brix").on("change",function(a2){var a3,a4,i;if(d.brew_fermenter_sg>=1.02){a3=sg_to_brix(d.brew_fermenter_sg);a4=parseFloat(a2.args.value);i=Round(1.0031-0.002318474*a3-0.000007775*(a3*a3)-3.4e-8*Math.pow(a3,3)+0.00574*(a4)+0.00003344*(a4*a4)+8.6e-8*Math.pow(a4,3),4);if(a4>0.05){$("#primary_end_sg").val(i);d.primary_end_sg=i}M()}});$("#secondary_end_sg").on("change",function(i){d.secondary_end_sg=parseFloat(i.args.value);M()});$("#secondary_end_brix").on("change",function(a2){var a3,a4,i;if(d.brew_fermenter_sg>=1.02){a3=sg_to_brix(d.brew_fermenter_sg);a4=parseFloat(a2.args.value);i=Round(1.0031-0.002318474*a3-0.000007775*(a3*a3)-3.4e-8*Math.pow(a3,3)+0.00574*(a4)+0.00003344*(a4*a4)+8.6e-8*Math.pow(a4,3),4);if(a4>0.05){$("#secondary_end_sg").val(i);d.secondary_end_sg=i}M()}});$("#final_brix").on("change",function(a2){var a3,a4,i;if(d.brew_fermenter_sg>=1.02){a3=sg_to_brix(d.brew_fermenter_sg);a4=parseFloat(a2.args.value);i=Round(1.0031-0.002318474*a3-0.000007775*(a3*a3)-3.4e-8*Math.pow(a3,3)+0.00574*(a4)+0.00003344*(a4*a4)+8.6e-8*Math.pow(a4,3),4);if(a4>0.05){$("#fg").val(i);d.fg=i}M()}});$("#fg").on("change",function(i){d.fg=parseFloat(i.args.value);M()});$("#BLog").jqxButton({disabled:(d.log_brew)?false:true});$("#FLog").jqxButton({disabled:(d.log_fermentation)?false:true})}$("#styleSelect").jqxDropDownList({placeHolder:"Kies bierstijl:",theme:theme,source:styleslist,displayMember:"name",width:180,height:23,dropDownVerticalAlignment:"top",dropDownWidth:500,dropDownHeight:380,renderer:function(a2,i,a4){var a3=styleslist.records[a2];return a3.style_guide+" "+a3.style_letter+" "+a3.name}});$("#styleSelect").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=styleslist.records[i];$("#st_name").val(a2.name);$("#st_category").val(a2.category);$("#st_category_number").val(a2.category_number);$("#st_letter").val(a2.style_letter);$("#st_guide").val(a2.style_guide);$("#st_type").val(StyleTypeData[a2.type].nl);$("#st_og_min").val(a2.og_min);$("#st_og_max").val(a2.og_max);$("#st_fg_min").val(a2.fg_min);$("#st_fg_max").val(a2.fg_max);$("#st_ibu_min").val(a2.ibu_min);$("#st_ibu_max").val(a2.ibu_max);$("#st_color_min").val(a2.color_min);$("#st_color_max").val(a2.color_max);$("#st_carb_min").val(a2.carb_min);$("#st_carb_min2").val(a2.carb_min);$("#st_carb_max").val(a2.carb_max);$("#st_carb_max2").val(a2.carb_max);$("#st_abv_min").val(a2.abv_min);$("#st_abv_max").val(a2.abv_max)}});$("#equipmentSelect").jqxDropDownList({placeHolder:"Kies apparatuur:",theme:theme,source:equipmentlist,displayMember:"name",width:170,height:23,dropDownWidth:300,renderer:function(a2,i,a4){var a3=equipmentlist.records[a2];return a3.batch_size+" liter "+a3.name}});$("#equipmentSelect").on("select",function(a4){if(a4.args){var a3,a2,i=a4.args.index;a3=equipmentlist.records[i];a2=a3.batch_size/d.batch_size;$("#eq_name").val(a3.name);$("#eq_boil_size").val(a3.boil_size);d.boil_size=a3.boil_size;$("#boil_size").val(a3.boil_size);$("#eq_batch_size").val(a3.batch_size);d.batch_size=a3.batch_size;$("#batch_size").val(a3.batch_size);$("#est_a_vol").val(a3.batch_size*1.04);$("#eq_tun_volume").val(a3.tun_volume);d.eq_tun_weight=a3.tun_weight;d.eq_tun_specific_heat=a3.tun_specific_heat;d.eq_tun_material=a3.tun_material;d.eq_tun_height=a3.tun_height/100;$("#eq_top_up_water").val(a3.top_up_water);d.eq_trub_chiller_loss=a3.trub_chiller_loss;$("#eq_trub_chiller_loss").val(a3.trub_chiller_loss);$("#eq_evap_rate").val(a3.evap_rate);$("#eq_boil_time").val(a3.boil_time);d.eq_calc_boil_volume=a3.calc_boil_volume;$("#eq_top_up_kettle").val(a3.top_up_kettle);$("#eq_hop_utilization").val(a3.hop_utilization);$("#eq_notes").val(a3.notes);$("#eq_lauter_volume").val(a3.lauter_volume);d.eq_lauter_height=a3.lauter_height/100;$("#eq_lauter_deadspace").val(a3.lauter_deadspace);$("#eq_kettle_volume").val(a3.kettle_volume);d.eq_kettle_height=a3.kettle_height/100;$("#eq_mash_volume").val(a3.mash_volume);$("#eq_mash_max").val(a3.mash_max);d.eq_mash_max=a3.mash_max;$("#mash_max").val(a3.mash_max);$("#eq_efficiency").val(a3.efficiency);d.efficiency=a3.efficiency;$("#efficiency").val(a3.efficiency);d.sparge_volume=Math.round(a3.boil_size*5)/10;$("#sparge_volume").val(d.sparge_volume);$("#brew_sparge_volume").val(d.sparge_volume);$("#est_pre_vol").val(a3.boil_size*1.04);ae(parseFloat($("#est_og").jqxNumberInput("decimal")));at(a2);T();ai(a2);a1(a2);aO(a2);ar();P();j()}});function s(){console.log("saveRecord()");var a2={record:my_record,uuid:d.uuid,name:$("#name").val(),code:$("#code").val(),birth:$("#birth").val(),stage:d.stage,notes:$("#notes").val(),log_brew:d.log_brew,log_fermentation:d.log_fermentation,inventory_reduced:d.inventory_reduced,locked:d.locked,eq_name:$("#eq_name").val(),eq_boil_size:parseFloat($("#eq_boil_size").jqxNumberInput("decimal")),eq_batch_size:parseFloat($("#eq_batch_size").jqxNumberInput("decimal")),eq_tun_volume:parseFloat($("#eq_tun_volume").jqxNumberInput("decimal")),eq_tun_weight:d.eq_tun_weight,eq_tun_specific_heat:d.eq_tun_specific_heat,eq_tun_material:d.eq_tun_material,eq_tun_height:d.eq_tun_height,eq_top_up_water:parseFloat($("#eq_top_up_water").jqxNumberInput("decimal")),eq_trub_chiller_loss:parseFloat($("#eq_trub_chiller_loss").jqxNumberInput("decimal")),eq_evap_rate:parseFloat($("#eq_evap_rate").jqxNumberInput("decimal")),eq_boil_time:parseFloat($("#eq_boil_time").jqxNumberInput("decimal")),eq_calc_boil_volume:d.eq_calc_boil_volume,eq_top_up_kettle:parseFloat($("#eq_top_up_kettle").jqxNumberInput("decimal")),eq_hop_utilization:parseFloat($("#eq_hop_utilization").jqxNumberInput("decimal")),eq_notes:$("#eq_notes").val(),eq_lauter_volume:parseFloat($("#eq_lauter_volume").jqxNumberInput("decimal")),eq_lauter_height:d.eq_lauter_height,eq_lauter_deadspace:parseFloat($("#eq_lauter_deadspace").jqxNumberInput("decimal")),eq_kettle_volume:parseFloat($("#eq_kettle_volume").jqxNumberInput("decimal")),eq_kettle_height:d.eq_kettle_height,eq_mash_volume:parseFloat($("#eq_mash_volume").jqxNumberInput("decimal")),eq_mash_max:parseFloat($("#eq_mash_max").jqxNumberInput("decimal")),eq_efficiency:parseFloat($("#eq_efficiency").jqxNumberInput("decimal")),brew_date_start:$("#brew_date_start").val(),brew_mash_ph:parseFloat($("#brew_mash_ph").jqxNumberInput("decimal")),brew_mash_sg:parseFloat($("#brew_mash_sg").jqxNumberInput("decimal")),brew_mash_efficiency:parseFloat($("#brew_mash_efficiency").jqxNumberInput("decimal")),brew_sparge_est:parseFloat($("#brew_sparge_est").jqxNumberInput("decimal")),brew_sparge_ph:parseFloat($("#brew_sparge_ph").jqxNumberInput("decimal")),brew_preboil_volume:parseFloat($("#brew_preboil_volume").jqxNumberInput("decimal")),brew_preboil_sg:parseFloat($("#brew_preboil_sg").jqxNumberInput("decimal")),brew_preboil_ph:parseFloat($("#brew_preboil_ph").jqxNumberInput("decimal")),brew_preboil_efficiency:parseFloat($("#brew_preboil_efficiency").jqxNumberInput("decimal")),brew_aboil_volume:parseFloat($("#brew_aboil_volume").jqxNumberInput("decimal")),brew_aboil_sg:parseFloat($("#brew_aboil_sg").jqxNumberInput("decimal")),brew_aboil_ph:parseFloat($("#brew_aboil_ph").jqxNumberInput("decimal")),brew_aboil_efficiency:parseFloat($("#brew_aboil_efficiency").jqxNumberInput("decimal")),brew_cooling_method:$("#brew_cooling_method").val(),brew_cooling_time:parseFloat($("#brew_cooling_time").jqxNumberInput("decimal")),brew_cooling_to:parseFloat($("#brew_cooling_to").jqxNumberInput("decimal")),brew_whirlpool9:parseFloat($("#brew_whirlpool9").jqxNumberInput("decimal")),brew_whirlpool7:parseFloat($("#brew_whirlpool7").jqxNumberInput("decimal")),brew_whirlpool6:parseFloat($("#brew_whirlpool6").jqxNumberInput("decimal")),brew_whirlpool2:parseFloat($("#brew_whirlpool2").jqxNumberInput("decimal")),brew_fermenter_volume:parseFloat($("#brew_fermenter_volume").jqxNumberInput("decimal")),brew_fermenter_extrawater:parseFloat($("#brew_fermenter_extrawater").jqxNumberInput("decimal")),brew_fermenter_tcloss:parseFloat($("#brew_fermenter_tcloss").jqxNumberInput("decimal")),brew_aeration_time:parseFloat($("#brew_aeration_time").jqxNumberInput("decimal")),brew_aeration_speed:parseFloat($("#brew_aeration_speed").jqxNumberInput("decimal")),brew_aeration_type:$("#brew_aeration_type").val(),brew_fermenter_sg:parseFloat($("#brew_fermenter_sg").jqxNumberInput("decimal")),brew_fermenter_ibu:parseFloat($("#brew_fermenter_ibu").jqxNumberInput("decimal")),brew_fermenter_color:parseFloat($("#brew_fermenter_color").jqxNumberInput("decimal")),brew_date_end:$("#brew_date_end").val(),og:d.og,fg:parseFloat($("#fg").jqxNumberInput("decimal")),primary_start_temp:parseFloat($("#primary_start_temp").jqxNumberInput("decimal")),primary_max_temp:parseFloat($("#primary_max_temp").jqxNumberInput("decimal")),primary_end_temp:parseFloat($("#primary_end_temp").jqxNumberInput("decimal")),primary_end_sg:parseFloat($("#primary_end_sg").jqxNumberInput("decimal")),primary_end_date:$("#primary_end_date").val(),secondary_temp:parseFloat($("#secondary_temp").jqxNumberInput("decimal")),secondary_end_sg:parseFloat($("#secondary_end_sg").jqxNumberInput("decimal")),secondary_end_date:$("#secondary_end_date").val(),tertiary_temp:parseFloat($("#tertiary_temp").jqxNumberInput("decimal")),package_date:$("#package_date").val(),package_volume:parseFloat($("#package_volume").jqxNumberInput("decimal")),package_infuse_amount:parseFloat($("#package_infuse_amount").jqxNumberInput("decimal")),package_infuse_abv:parseFloat($("#package_infuse_abv").jqxNumberInput("decimal")),package_infuse_notes:$("#package_infuse_notes").val(),package_abv:parseFloat($("#package_abv").jqxNumberInput("decimal")),package_ph:parseFloat($("#package_ph").jqxNumberInput("decimal")),bottle_amount:parseFloat($("#bottle_amount").jqxNumberInput("decimal")),bottle_carbonation:parseFloat($("#bottle_carbonation").jqxNumberInput("decimal")),bottle_priming_water:parseFloat($("#bottle_priming_water").jqxNumberInput("decimal")),bottle_priming_amount:parseFloat($("#bottle_priming_amount").jqxNumberInput("decimal")),bottle_carbonation_temp:parseFloat($("#bottle_carbonation_temp").jqxNumberInput("decimal")),keg_amount:parseFloat($("#keg_amount").jqxNumberInput("decimal")),keg_carbonation:parseFloat($("#keg_carbonation").jqxNumberInput("decimal")),keg_priming_water:parseFloat($("#keg_priming_water").jqxNumberInput("decimal")),keg_priming_amount:parseFloat($("#keg_priming_amount").jqxNumberInput("decimal")),keg_carbonation_temp:parseFloat($("#keg_carbonation_temp").jqxNumberInput("decimal")),keg_forced_carb:d.keg_forced_carb,keg_pressure:parseFloat($("#keg_pressure").jqxNumberInput("decimal")),taste_notes:$("#taste_notes").val(),taste_rate:parseFloat($("#taste_rate").jqxNumberInput("decimal")),taste_date:$("#taste_date").val(),taste_color:$("#taste_color").val(),taste_transparency:$("#taste_transparency").val(),taste_head:$("#taste_head").val(),taste_aroma:$("#taste_aroma").val(),taste_taste:$("#taste_taste").val(),taste_mouthfeel:$("#taste_mouthfeel").val(),taste_aftertaste:$("#taste_aftertaste").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(),starter_enable:d.starter_enable,starter_type:$("#starter_type").val(),starter_sg:parseFloat($("#starter_sg").jqxNumberInput("decimal")),starter_viability:parseFloat($("#starter_viability").jqxNumberInput("decimal")),prop1_type:$("#prop1_type").val(),prop1_volume:parseFloat($("#prop1_volume").jqxNumberInput("decimal")),prop2_type:$("#prop2_type").val(),prop2_volume:parseFloat($("#prop2_volume").jqxNumberInput("decimal")),prop3_type:$("#prop3_type").val(),prop3_volume:parseFloat($("#prop3_volume").jqxNumberInput("decimal")),prop4_type:$("#prop4_type").val(),prop4_volume:parseFloat($("#prop4_volume").jqxNumberInput("decimal")),fermentables:$("#fermentableGrid").jqxGrid("getrows"),hops:$("#hopGrid").jqxGrid("getrows"),miscs:$("#miscGrid").jqxGrid("getrows"),yeasts:$("#yeastGrid").jqxGrid("getrows"),mashs:$("#mashGrid").jqxGrid("getrows")},i="update=true&"+$.param(a2);$.ajax({dataType:"json",url:E,cache:false,data:i,async:false,type:"POST",success:function(a4,a3,a5){console.log("saveRecord() success")},error:function(a3,a5,a4){console.log("saveRecord() error")}})}ag.dataBind();$("#name").jqxTooltip({content:"De naam voor dit product."});$("#name").jqxInput({theme:theme,width:640,height:23});$("#code").jqxTooltip({content:"Product code nummer."});$("#code").jqxInput({theme:theme,width:100,height:23});$("#birth").jqxTooltip({content:"De ontwerp datum van dit product."});$("#birth").jqxInput({theme:theme,width:120,height:23});$("#stage").jqxTooltip({content:"De productie fase van dit product."});$("#stage").jqxInput({theme:theme,width:100,height:23});$("#locked").jqxCheckBox({theme:theme,width:120,height:23,disabled:true});$("#locked").on("checked",function(i){if(d.stage>=10){d.locked=1;d.stage=11;aU()}});$("#locked").on("unchecked",function(i){if(d.stage>=10){d.locked=0;d.stage=10;aU()}});$("#notes").jqxTooltip({content:"De uitgebreide opmerkingen over dit product."});$("#notes").jqxInput({theme:theme,width:960,height:100});$("#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_time").jqxTooltip({content:"De kooktijd in minuten."});$("#boil_time").jqxNumberInput(PosInt);$("#boil_time").jqxNumberInput({min:4,max:360});$("#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});$("#st_guide").jqxTooltip({content:"De bierstijl gids voor dit recept."});$("#st_guide").jqxInput({theme:theme,width:250,height:23});$("#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_type").jqxTooltip({content:"Het bierstijl type."});$("#st_type").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);$("#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 verwachte 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);$("#eq_name").jqxTooltip({content:"De naam van deze brouw apparatuur."});$("#eq_name").jqxInput({theme:theme,width:250,height:23});$("#eq_boil_size").jqxTooltip({content:"Normaal kook volume in liters"});$("#eq_boil_size").jqxNumberInput(Show1dec);$("#eq_batch_size").jqxTooltip({content:"Berekende batch grootte in liters aan het eind van de kook."});$("#eq_batch_size").jqxNumberInput(Show1dec);$("#eq_tun_volume").jqxTooltip({content:"Maisch ketel volume."});$("#eq_tun_volume").jqxNumberInput(Show1dec);$("#eq_top_up_water").jqxTooltip({content:"Extra water in het gistvat."});$("#eq_top_up_water").jqxNumberInput(Show1dec);$("#eq_trub_chiller_loss").jqxTooltip({content:"Standaard verlies bij het overbrengen naar het gistvat."});$("#eq_trub_chiller_loss").jqxNumberInput(Show1dec);$("#eq_evap_rate").jqxTooltip({content:"Verdamping in liters per uur."});$("#eq_evap_rate").jqxNumberInput(Show2dec);$("#eq_boil_time").jqxTooltip({content:"Normale kooktijd in minuten."});$("#eq_boil_time").jqxNumberInput(Show0dec);$("#eq_top_up_kettle").jqxTooltip({content:"Extra water toevoegen tijdens de kook."});$("#eq_top_up_kettle").jqxNumberInput(Show1dec);$("#eq_hop_utilization").jqxTooltip({content:"100% voor kleine installaties, hoger voor grote brouwerijen."});$("#eq_hop_utilization").jqxNumberInput(Show0dec);$("#eq_notes").jqxTooltip({content:"Opmerkingen over deze apparatuur."});$("#eq_notes").jqxInput({theme:theme,width:960,height:200});$("#eq_lauter_volume").jqxTooltip({content:"Filterkuip volume."});$("#eq_lauter_volume").jqxNumberInput(Show1dec);$("#eq_lauter_deadspace").jqxTooltip({content:"Filterkuip verlies in liters."});$("#eq_lauter_deadspace").jqxNumberInput(Show1dec);$("#eq_kettle_volume").jqxTooltip({content:"Kook ketel volume in liters."});$("#eq_kettle_volume").jqxNumberInput(Show1dec);$("#eq_mash_volume").jqxTooltip({content:"Maisch water voor de eerste stap."});$("#eq_mash_volume").jqxNumberInput(Show1dec);$("#eq_mash_max").jqxTooltip({content:"De maximale moutstort in Kg."});$("#eq_mash_max").jqxNumberInput(Show1dec);$("#eq_efficiency").jqxTooltip({content:"Gemiddeld brouwzaal rendement."});$("#eq_efficiency").jqxNumberInput(Show1dec);$("#est_color2").jqxTooltip({content:"De kleur in EBC. Dit wordt automatisch berekend."});$("#est_color2").jqxNumberInput(Show0dec);$("#est_og2").jqxTooltip({content:"Het geschatte begin SG van dit product."});$("#est_og2").jqxNumberInput(Show3dec);$("#mash_kg").jqxTooltip({content:"Het gewicht van alle mouten in de maisch."});$("#mash_kg").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(i){return(Math.round(parseInt(i)*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(i){return(Math.round(parseInt(i)*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(i){return(Math.round(parseInt(i)*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(i){return(parseInt(i)*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 a2,i=$("#fermentableGrid").jqxGrid("getrowid",u);console.log("FermentableReady row:"+u+" ID:"+i);a2={f_name:aK.f_name,f_origin:aK.f_origin,f_supplier:aK.f_supplier,f_amount:aK.f_amount,f_cost:aK.f_cost,f_type:aK.f_type,f_yield:aK.f_yield,f_color:aK.f_color,f_coarse_fine_diff:aK.f_coarse_fine_diff,f_moisture:aK.f_moisture,f_diastatic_power:aK.f_diastatic_power,f_protein:aK.f_protein,f_max_in_batch:aK.f_max_in_batch,f_graintype:aK.f_graintype,f_added:aK.f_added,f_dissolved_protein:aK.f_dissolved_protein,f_recommend_mash:aK.f_recommend_mash,f_add_after_boil:aK.f_add_after_boil,f_adjust_to_total_100:aK.f_adjust_to_total_100,f_percentage:aK.f_percentage,f_di_ph:aK.f_di_ph,f_acid_to_ph_57:aK.f_acid_to_ph_57,f_inventory:aK.f_inventory,f_avail:aK.f_avail};$("#fermentableGrid").jqxGrid("updaterow",i,a2);aV();T();ar();aN()});$("#wf_name").jqxInput({theme:theme,width:320,height:23});$("#wf_instock").jqxCheckBox({theme:theme,height:23});$("#wf_instock").on("change",function(i){fermentableinstock=i.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(a2,i,a4){var a3=fermentablelist.records[a2];return a3.supplier+" / "+a3.name+" ("+a3.color+" EBC)"}});$("#wf_select").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=fermentablelist.records[i];$("#wf_name").val(a2.name);aK.f_name=a2.name;aK.f_origin=a2.origin;aK.f_supplier=a2.supplier;aK.f_type=a2.type;aK.f_cost=a2.cost;aK.f_yield=a2.yield;aK.f_color=a2.color;aK.f_coarse_fine_diff=a2.coarse_fine_diff;aK.f_moisture=a2.moisture;aK.f_diastatic_power=a2.diastatic_power;aK.f_protein=a2.protein;aK.f_max_in_batch=a2.max_in_batch;aK.f_graintype=a2.graintype;aK.f_dissolved_protein=a2.dissolved_protein;aK.f_recommend_mash=a2.recommend_mash;aK.f_add_after_boil=a2.add_after_boil;aK.f_di_ph=a2.di_ph;aK.f_acid_to_ph_57=a2.acid_to_ph_57;aK.f_inventory=a2.inventory}});$("#wf_amount").jqxNumberInput(Spin3dec);$("#wf_amount").on("change",function(i){console.log("amount changed: "+i.args.value);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_amount",i.args.value);aK.f_amount=i.args.value;if(!l){aV();T();ar();aN()}});$("#wf_percentage").jqxNumberInput(Perc1dec);$("#wf_percentage").on("change",function(a2){var a4,a8,ba,a9,a5,a7,i,a6,bb,a3=Math.round(aK.f_percentage*10)/10;a4=a2.args.value;console.log("percentage changed: "+a4+" old: "+a3);aK.f_percent=a4;a8=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if((a3!=a4)&&(a8>1)){ba=$("#fermentableGrid").jqxGrid("getrowdata",u);if(ba.f_adjust_to_total_100){$("#wf_percentage").val(a3)}else{a9=a4-a3;a5=0;for(ad=0;ad<a8;ad++){ba=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(ba.f_added<4){a5+=Math.round(ba.f_amount*1000)/1000}}a5=Math.round(a5*1000)/1000;if(l){a7=Math.round(a5*a9*10)/1000;ba=$("#fermentableGrid").jqxGrid("getrowdata",u);i=Math.round((ba.f_amount+a7)*1000)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_amount",i);$("#wf_amount").val(i);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_percentage",ba.f_percentage+a9);for(ad=0;ad<a8;ad++){ba=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(ba.f_adjust_to_total_100){i=ba.f_amount-a7;$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",ba.f_percentage-a9);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_amount",i)}}T();ar();aN()}else{a6=a5*a9/100;for(ad=0;ad<a8;ad++){ba=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(ba.f_added<4){if(ad==u){i=Math.round((ba.f_amount+a6)*1000)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_amount",i);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",a4)}else{i=Math.round((ba.f_amount-(a6/(a8-1)))*1000)/1000;bb=Math.round((i/a5)*1000)/10;$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_amount",i);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",bb)}}else{$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",0)}}T();ar();aN()}}}});$("#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(a3){if(aK.f_adjust_to_total_100==0){if(l){var a2,a4=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(a2=0;a2<a4;a2++){if(a2!=u){$("#fermentableGrid").jqxGrid("setcellvalue",a2,"f_adjust_to_total_100",0)}}}$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_adjust_to_total_100",1);T()}});$("#wf_adjust_to_total_100").on("unchecked",function(i){if(aK.f_adjust_to_total_100!=0){$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_adjust_to_total_100",0);T()}});$("#wf_added").jqxDropDownList({theme:theme,source:AddedAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wf_added").on("select",function(a2){if(a2.args){var i=a2.args.index;$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_added",i);T();ar();aN()}});$("#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(a2){var i=parseInt(a2);if(i<20){return"Weinig"}else{if(i<40){return"Matig"}else{if(i<60){return"Redelijk"}else{if(i<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(a2){var i=parseInt(a2);if(i<20){return"Weinig"}else{if(i<40){return"Matig"}else{if(i<60){return"Redelijk"}else{if(i<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 a2,i=$("#hopGrid").jqxGrid("getrowid",a);a2={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",i,a2);ar()});$("#wh_name").jqxInput({theme:theme,width:320,height:23});$("#wh_instock").jqxCheckBox({theme:theme,height:23});$("#wh_instock").on("change",function(i){hopinstock=i.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(a2,i,a4){var a3=hoplist.records[a2];return a3.origin+" - "+a3.name+" / "+HopFormData[a3.form].nl+" ("+a3.alpha+" % &alpha;)"}});$("#wh_select").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=hoplist.records[i];$("#wh_name").val(a2.name);e.h_name=a2.name;e.h_origin=a2.origin;e.h_cost=a2.cost;e.h_type=a2.type;e.h_form=a2.form;e.h_alpha=a2.alpha;e.h_beta=a2.beta;e.h_hsi=a2.hsi;e.h_humulene=a2.humulene;e.h_caryophyllene=a2.caryophyllene;e.h_cohumulone=a2.cohumulone;e.h_myrcene=a2.myrcene;e.h_total_oil=a2.total_oil;e.h_inventory=a2.inventory}});$("#wh_amount").jqxNumberInput(Spin1dec);$("#wh_amount").on("change",function(a2){console.log("amount changed: "+a2.args.value+" time:"+e.h_time+" alpha:"+e.h_alpha);var a3,i=parseFloat(a2.args.value)/1000;a3=toIBU(e.h_useat,e.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),i,parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());e.h_amount=i;$("#wh_ibu").val(a3)});$("#wh_ibu").jqxNumberInput(Show1dec);$("#wh_time").jqxNumberInput(PosInt);$("#wh_time").on("change",function(i){var a3,a2=parseFloat(i.args.value);if(e.h_useat==2){if(a2>parseFloat($("#boil_time").jqxNumberInput("decimal"))){a2=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wh_time").val(a2)}e.h_time=a2}else{if(e.h_useat==4){if(a2>120){a2=120;$("#wh_time").val(a2)}e.h_time=a2}else{if(e.h_useat==5){if(a2>21){a2=21;$("#wh_time").val(a2)}e.h_time=a2*1440}}}a3=toIBU(e.h_useat,e.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(e.h_amount),parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(a3)});$("#wh_useat").jqxDropDownList({theme:theme,source:HopUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wh_useat").on("select",function(a2){if(a2.args){var i=a2.args.index;e.h_useat=i;if((i==0)||(i==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(i==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(i==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 a2,i=$("#miscGrid").jqxGrid("getrowid",av);console.log("MiscReady row:"+av+" ID:"+i);a2={m_name:aG.m_name,m_amount:aG.m_amount,m_cost:aG.m_cost,m_type:aG.m_type,m_use_use:aG.m_use_use,m_time:aG.m_time,m_amount_is_weight:aG.m_amount_is_weight,m_inventory:aG.m_inventory,m_avail:aG.m_avail};$("#miscGrid").jqxGrid("updaterow",i,a2);aF()});$("#wm_name").jqxInput({theme:theme,width:320,height:23});$("#wm_instock").jqxCheckBox({theme:theme,height:23});$("#wm_instock").on("change",function(i){miscinstock=i.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(a3){if(a3.args){var a2,i=a3.args.index;a2=misclist.records[i];$("#wm_name").val(a2.name);aG.m_name=a2.name;aG.m_cost=a2.cost;aG.m_type=a2.type;aG.m_use_use=a2.use_use;aG.m_amount_is_weight=a2.amount_is_weight;aG.m_inventory=a2.inventory}});$("#wm_amount").jqxNumberInput(Spin2dec);$("#wm_amount").on("change",function(i){console.log("amount changed: "+i.args.value);aG.m_amount=parseFloat(i.args.value)/1000});$("#wm_time").jqxNumberInput(PosInt);$("#wm_time").on("change",function(i){var a2=parseFloat(i.args.value);if(aG.m_use_use==2){if(a2>parseFloat($("#boil_time").jqxNumberInput("decimal"))){a2=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wm_time").val(a2)}aG.m_time=a2}else{if((aG.m_use_use==3)||(aG.m_use_use==4)){if(a2>21){a2=21;$("#wm_time").val(a2)}aG.m_time=a2*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(a2){if(a2.args){var i=a2.args.index;aG.m_use_use=i;if((i==2)||(i==3)||(i==4)){$("#wm_time").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}else{$("#wm_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wm_time").val(0);aG.m_time=0}}});$("#est_fg2").jqxTooltip({content:"Het verwachte eind SG. Dit wordt automatisch berekend."});$("#est_fg2").jqxNumberInput(Show3dec);$("#est_abv2").jqxTooltip({content:"Alcohol volume %. Dit wordt automatisch berekend."});$("#est_abv2").jqxNumberInput(Smal1dec);$("#yeast_cells").jqxNumberInput(Show1dec);$("#need_cells").jqxNumberInput(Show1dec);$("#plato_cells").jqxNumberInput(Show2dec);$("#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 a2,i=$("#yeastGrid").jqxGrid("getrowid",aD);console.log("YeastReady row:"+aD+" ID:"+i);a2={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",i,a2);T();X()});$("#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(i){yeastinstock=i.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(a2,i,a4){var a3=yeastlist.records[a2];return a3.laboratory+" "+a3.product_id+" "+a3.name}});$("#wy_select").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=yeastlist.records[i];$("#wy_name").val(a2.name);$("#wy_laboratory").val(a2.laboratory);$("#wy_product_id").val(a2.product_id);f.y_name=a2.name;f.y_cost=a2.cost;f.y_type=a2.type;f.y_form=a2.form;f.y_laboratory=a2.laboratory;f.y_product_id=a2.product_id;f.y_min_temperature=a2.min_temperature;f.y_max_temperature=a2.max_temperature;f.y_flocculation=a2.flocculation;f.y_attenuation=a2.attenuation;f.y_cells=a2.cells;f.y_inventory=a2.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:")}}T();X()}});$("#wy_amount").jqxNumberInput(Spin1dec);$("#wy_amount").on("change",function(a2){var i=parseFloat(a2.args.value);if(f.y_form!=0){i=parseFloat(a2.args.value)/1000}f.y_amount=i;T();X()});$("#wy_use").jqxDropDownList({theme:theme,source:YeastUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wy_use").on("select",function(a2){if(a2.args){var i=a2.args.index;f.y_use=i;T();X()}});for(ad=1;ad<5;ad++){$("#prop"+ad+"_type").jqxDropDownList({theme:theme,source:StarterTypeAdapter,valueMember:"id",displayMember:"nl",width:120,height:23,autoDropDownHeight:true});$("#prop"+ad+"_type").hide();$("#prop"+ad+"_volume").jqxNumberInput(Spin3dec);$("#prop"+ad+"_volume").hide();$("#prop"+ad+"_irate").jqxNumberInput(Show1dec);$("#prop"+ad+"_irate").hide();$("#prop"+ad+"_ncells").jqxNumberInput(Show1dec);$("#prop"+ad+"_ncells").hide();$("#prop"+ad+"_tcells").jqxNumberInput(Show1dec);$("#prop"+ad+"_tcells").hide();$("#prop"+ad+"_growf").jqxNumberInput(Show2dec);$("#prop"+ad+"_growf").hide()}$("#starter_enable").jqxCheckBox({theme:theme,height:23});$("#starter_type").jqxDropDownList({theme:theme,source:StarterTypeAdapter,valueMember:"id",displayMember:"nl",width:120,height:23,autoDropDownHeight:true});$("#starter_sg").jqxNumberInput(SGopts);$("#starter_viability").jqxNumberInput(Perc0);$("#starter_try").jqxButton({template:"primary",width:"100px",height:23,theme:theme});$("#mash_name").jqxTooltip({content:"De omschrijving van dit maisch profiel."});$("#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(a6){if(a6.args){var a8,a5,a2,a7,a4,a9={},a3=a6.args.index;a2=new Array();a7=$("#mashGrid").jqxGrid("getdisplayrows");for(a4=0;a4<a7.length;a4++){a9=a7[a4];a2.push(a9.uid)}$("#mashGrid").jqxGrid("deleterow",a2);a5=mashlist.records[a3];$("#mash_name").val(a5.name);for(a4=0;a4<a5.steps.length;a4++){a8=a5.steps[a4];a9.step_name=a8.step_name;a9.step_type=a8.step_type;if(C==0&&d.w1_amount>0){C=d.w1_amount}if(a4==0){a9.step_infuse_amount=C}else{a9.step_infuse_amount=0}if(ao>0){a9.step_thickness=parseFloat(C/ao)}else{a9.step_thickness=0}a9.step_temp=a8.step_temp;a9.end_temp=a8.end_temp;a9.step_time=a8.step_time;a9.ramp_time=a8.ramp_time;$("#mashGrid").jqxGrid("addrow",null,a9)}}});$("#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(){aN()});$("#wstep_name").jqxInput({theme:theme,width:320,height:23});$("#wstep_name").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.step_name=i.args.value});$("#wstep_type").jqxDropDownList({theme:theme,source:MashStepTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#wstep_type").on("select",function(a4){if(a4.args){var a7,a3,a5,a6,a2=a4.args.index;a7=$("#mashGrid").jqxGrid("getrowdata",aj);a7.step_type=a2;if(a2==0){$("#wstep_infuse_amount").show();$("#wstep_pmpt").show()}else{a7.step_infuse_amount=0;$("#wstep_infuse_amount").hide();$("#wstep_pmpt").hide()}C=0;a5=$("#mashGrid").jqxGrid("getrows");for(a3=0;a3<a5.length;a3++){a6=a5[a3];if(a6.step_type==0){C+=parseFloat(a6.step_infuse_amount)}}}});$("#wstep_temp").jqxNumberInput(Spin1dec);$("#wstep_temp").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.step_temp=parseFloat(i.args.value)});$("#wend_temp").jqxNumberInput(Spin1dec);$("#wend_temp").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.end_temp=parseFloat(i.args.value)});$("#wstep_time").jqxNumberInput(PosInt);$("#wstep_time").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.step_time=parseFloat(i.args.value)});$("#wramp_time").jqxNumberInput(PosInt);$("#wramp_time").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.ramp_time=parseFloat(i.args.value)});$("#wstep_infuse_amount").jqxNumberInput(Spin1dec);$("#wstep_infuse_amount").on("change",function(a3){var a5,a2,a4,a6=$("#mashGrid").jqxGrid("getrowdata",aj);a6.step_infuse_amount=parseFloat(a3.args.value);C=0;a4=$("#mashGrid").jqxGrid("getrows");for(a2=0;a2<a4.length;a2++){a5=a4[a2];if(a5.step_type==0){C+=parseFloat(a5.step_infuse_amount)}}if(d.w2_amount==0){d.w1_amount=C;$("#w1_amount").val(C)}else{d.w1_amount=(d.w1_amount/(d.w1_amount+d.w2_amount))*C;d.w2_amount=(d.w2_amount/(d.w1_amount+d.w2_amount))*C;$("#w1_amount").val(d.w1_amount);$("#w2_amount").val(d.w2_amount)}$("#wg_amount").val(C)});$("#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(a3){if(a3.args){var a2,i=a3.args.index;a2=waterlist.records[i];d.w1_name=a2.name;$("#w1_calcium").val(a2.calcium);d.w1_calcium=a2.calcium;$("#w1_sulfate").val(a2.sulfate);d.w1_sulfate=a2.sulfate;$("#w1_chloride").val(a2.chloride);d.w1_chloride=a2.chloride;$("#w1_sodium").val(a2.sodium);d.w1_sodium=a2.sodium;$("#w1_magnesium").val(a2.magnesium);d.w1_magnesium=a2.magnesium;$("#w1_total_alkalinity").val(a2.total_alkalinity);d.w1_total_alkalinity=a2.total_alkalinity;$("#w1_ph").val(a2.ph);d.w1_ph=a2.ph;$("#w1_cost").val(a2.cost);d.w1_cost=a2.cost;P()}});$("#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(a3){if(a3.args){var a2,i=a3.args.index;a2=waterlist.records[i];d.w2_name=a2.name;$("#w2_calcium").val(a2.calcium);d.w2_calcium=a2.calcium;$("#w2_sulfate").val(a2.sulfate);d.w2_sulfate=a2.sulfate;$("#w2_chloride").val(a2.chloride);d.w2_chloride=a2.chloride;$("#w2_sodium").val(a2.sodium);d.w2_sodium=a2.sodium;$("#w2_magnesium").val(a2.magnesium);d.w2_magnesium=a2.magnesium;$("#w2_total_alkalinity").val(a2.total_alkalinity);d.w2_total_alkalinity=a2.total_alkalinity;$("#w2_ph").val(a2.ph);d.w2_ph=a2.ph;$("#w2_cost").val(a2.cost);d.w2_cost=a2.cost;$("#w2_amount").jqxNumberInput({max:100000,readOnly:false});P()}});$("#w2_amount").jqxTooltip({content:"De verdeling van het hoofd en meng water. Het totale maisch water volume blijft gelijk."});$("#w2_amount").jqxNumberInput({inputMode:"simple",spinMode:"simple",theme:theme,width:94,height:23,min:0,max:0,decimalDigits:1,spinButtons:true,spinButtonsStep:0.5,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_total_alkalinity").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_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(a3){if(a3.args){var a2,i=a3.args.index;a2=waterprofiles.records[i];$("#pr_calcium").val(a2.calcium);$("#pr_sulfate").val(a2.sulfate);$("#pr_chloride").val(a2.chloride);$("#pr_sodium").val(a2.sodium);$("#pr_magnesium").val(a2.magnesium);$("#pr_total_alkalinity").val(a2.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"});$("#brew_date_start").jqxTooltip({content:"Brouw datum en tijd. Voor planning laat de tijd op 00:00:00 staan."});$("#brew_date_start").jqxDateTimeInput(DateTimeopts);$("#brew_date_start").on("close",function(i){aU()});$("#brew_date_end").jqxTooltip({content:"End datum en tijd van de brouw. Leeg laten als er nog niet gebrouwen is."});$("#brew_date_end").jqxDateTimeInput(DateTimeopts);$("#brew_date_end").on("close",function(i){aU()});$("#brew_mash_ph").jqxTooltip({content:"De gemeten pH tijdens het maischen eventueel na correctie."});$("#brew_mash_ph").jqxNumberInput(SpinpH);$("#est_mash_ph").jqxTooltip({content:"De gewenste pH tijdens het maischen."});$("#est_mash_ph").jqxNumberInput(Show1wat);$("#brew_preboil_ph").jqxTooltip({content:"De gemeten pH in de kookketel na het spoelen en voor de kook."});$("#brew_preboil_ph").jqxNumberInput(SpinpH);$("#brew_aboil_ph").jqxTooltip({content:"De gemeten pH na het koken."});$("#brew_aboil_ph").jqxNumberInput(SpinpH);$("#brew_mash_sg").jqxTooltip({content:"Het bereikte SG na het maischen."});$("#brew_mash_sg").jqxNumberInput(SGopts);$("#brew_mash_sg").on("valueChanged",function(){aZ()});$("#est_mash_sg").jqxTooltip({content:"Het berekende verwachte SG na het maischen."});$("#est_mash_sg").jqxNumberInput(Show3wat);$("#brew_preboil_sg").jqxTooltip({content:"Het gemeten SG in de kookketel na het spoelen en voor het koken."});$("#brew_preboil_sg").jqxNumberInput(SGopts);$("#brew_preboil_sg").on("valueChanged",function(i){d.brew_preboil_sg=i.args.value;w()});$("#est_pre_sg").jqxTooltip({content:"Het berekende SG in de kookketel na het spoelen en voor het koken."});$("#est_pre_sg").jqxNumberInput(Show3wat);$("#brew_aboil_sg").jqxTooltip({content:"Het gemeten SG in de kookketel na het koken."});$("#brew_aboil_sg").jqxNumberInput(SGopts);$("#brew_aboil_sg").on("valueChanged",function(i){d.brew_aboil_sg=i.args.value;R();T();ar()});$("#est_og3").jqxTooltip({content:"Het gewenste SG in de kookketel na het koken."});$("#est_og3").jqxNumberInput(Show3wat);$("#brew_mash_efficiency").jqxTooltip({content:"Het behaalde maisch rendement."});$("#brew_mash_efficiency").jqxNumberInput(Show1dec);$("#brew_preboil_volume").jqxTooltip({content:"Het gemeten volume van het wort voor het koken."});$("#brew_preboil_volume").jqxNumberInput(Spin1dec);$("#brew_preboil_volume").on("valueChanged",function(i){d.brew_preboil_volume=i.args.value;w()});$("#est_pre_vol").jqxTooltip({content:"Het berekende volume van het wort voor het koken."});$("#est_pre_vol").jqxNumberInput(Show1wat);$("#brew_aboil_volume").jqxTooltip({content:"Het gemeten volume van het wort na het koken."});$("#brew_aboil_volume").jqxNumberInput(Spin1dec);$("#brew_aboil_volume").on("valueChanged",function(i){d.brew_aboil_volume=i.args.value;R();T();ar()});$("#est_a_vol").jqxTooltip({content:"Het gewenste volume na het koken."});$("#est_a_vol").jqxNumberInput(Show1wat);$("#brew_preboil_efficiency").jqxTooltip({content:"Het berekende rendement voor het koken."});$("#brew_preboil_efficiency").jqxNumberInput(Show1dec);$("#brew_aboil_efficiency").jqxTooltip({content:"Het bereikte rendement na het koken."});$("#brew_aboil_efficiency").jqxNumberInput(Show1dec);$("#brew_sparge_temperature").jqxTooltip({content:"De spoelwater temperatuur, in te stellen in de Water tab."});$("#brew_sparge_temperature").jqxNumberInput(Show1dec);$("#brew_sparge_volume").jqxTooltip({content:"Het spoelwater voorraad volume, in te stellen in de Water tab."});$("#brew_sparge_volume").jqxNumberInput(Show1dec);$("#brew_sparge_est").jqxNumberInput(Show1dec);$("#brew_whirlpool9").jqxNumberInput(PosInt);$("#brew_whirlpool9").jqxNumberInput({max:120});$("#brew_cooling_to").jqxNumberInput(Spin1dec);$("#brew_sparge_ph").jqxNumberInput(SpinpH);$("#brew_whirlpool7").jqxNumberInput(PosInt);$("#brew_whirlpool7").jqxNumberInput({max:120});$("#brew_cooling_method").jqxDropDownList({theme:theme,source:CoolingTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#brew_whirlpool6").jqxNumberInput(PosInt);$("#brew_whirlpool6").jqxNumberInput({max:120});$("#brew_cooling_time").jqxNumberInput(PosInt);$("#brew_cooling_time").jqxNumberInput({max:1440});$("#brew_whirlpool2").jqxNumberInput(PosInt);$("#brew_whirlpool2").jqxNumberInput({max:120});$("#brew_aeration_type").jqxDropDownList({theme:theme,source:AerationTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#brew_aeration_time").jqxNumberInput(PosInt);$("#brew_aeration_time").jqxNumberInput({max:1440});$("#brew_aeration_speed").jqxNumberInput(PosInt);$("#brew_aeration_speed").jqxNumberInput({max:1440});$("#brew_fermenter_volume").jqxNumberInput(Show1dec);$("#brew_fermenter_extrawater").jqxNumberInput(Spin1dec);$("#brew_fermenter_sg").jqxNumberInput(Show3dec);$("#brew_fermenter_tcloss").jqxNumberInput(Spin1dec);$("#brew_fermenter_ibu").jqxNumberInput(Show0dec);$("#brew_fermenter_color").jqxNumberInput(Show0dec);$("#BLog").jqxButton({template:"info",width:"150px",theme:theme});$("#BLog").click(function(){window.open("log_brew.php?code="+d.code+"&name="+d.name)});$("#brew_fermenter_sg2").jqxTooltip({content:"Het behaalde SG in het gistvat, overgenomen van de brouwdag."});$("#brew_fermenter_sg2").jqxNumberInput(Show3dec);$("#primary_start_temp").jqxTooltip({content:"De begintemperatuur van de hoofdvergisting."});$("#primary_start_temp").jqxNumberInput(YeastT);$("#primary_max_temp").jqxTooltip({content:"De hoogst bereikte piek temperatuur tijdens de hoofgvergisting."});$("#primary_max_temp").jqxNumberInput(YeastT);$("#primary_end_temp").jqxTooltip({content:"De eind temperatuur van de hoofdvergisting."});$("#primary_end_temp").jqxNumberInput(YeastT);$("#primary_end_sg").jqxTooltip({content:"Het gemeten SG aan het eind van de hoofdvergisting."});$("#primary_end_sg").jqxNumberInput(SGopts);$("#primary_end_brix").jqxTooltip({content:"Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer."});$("#primary_end_brix").jqxNumberInput(Spin1dec);$("#primary_svg").jqxTooltip({content:"De schijnbare vergisting graad behaald na de hoofdgisting."});$("#primary_svg").jqxNumberInput(Show1dec);$("#primary_end_date").jqxTooltip({content:"De eind datum van de hoofdvergisting en eventueel overhevelen."});$("#primary_end_date").jqxDateTimeInput(Dateopts);$("#primary_end_date").on("close",function(i){aU()});$("#secondary_temp").jqxNumberInput(YeastT);$("#secondary_end_sg").jqxTooltip({content:"Het gemeten SG aan het eind van de navergisting."});$("#secondary_end_sg").jqxNumberInput(SGopts);$("#secondary_end_brix").jqxTooltip({content:"Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer."});$("#secondary_end_brix").jqxNumberInput(Spin1dec);$("#secondary_svg").jqxTooltip({content:"De schijnbare vergisting graad behaald na de nagisting."});$("#secondary_svg").jqxNumberInput(Show1dec);$("#secondary_end_date").jqxTooltip({content:"De eind datum van de navergisting en het begin van het lageren."});$("#secondary_end_date").jqxDateTimeInput(Dateopts);$("#secondary_end_date").on("close",function(i){aU()});$("#tertiary_temp").jqxNumberInput(YeastT);$("#fg").jqxNumberInput(Spin3dec);$("#est_fg3").jqxTooltip({content:"Het verwachte eind SG. Dit wordt automatisch berekend."});$("#est_fg3").jqxNumberInput(Show3dec);$("#final_brix").jqxTooltip({content:"Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer."});$("#final_brix").jqxNumberInput(Spin1dec);$("#final_abv").jqxNumberInput(Show2dec);$("#final_svg").jqxNumberInput(Show1dec);$("#FLog").jqxButton({template:"info",width:"150px",theme:theme});$("#FLog").click(function(){var i="log_fermentation.php?code="+d.code+"&name="+d.name;window.open(i)});$("#package_date").jqxTooltip({content:"De verpakkings datum van dit bier."});$("#package_date").jqxDateTimeInput(Dateopts);$("#package_date").on("close",function(i){aU()});$("#package_volume").jqxTooltip({content:"Het beschikbare volume om te bottelen of op fust te zetten."});$("#package_volume").jqxNumberInput(Spin1dec);$("#package_infuse_amount").jqxTooltip({content:"De hoeveelheid water of drank extra toe te voegen."});$("#package_infuse_amount").jqxNumberInput(Spin3dec);$("#package_infuse_abv").jqxTooltip({content:"De hoeveelheid alcohol in de drank, of 0.0 als het water is."});$("#package_infuse_abv").jqxNumberInput(Spin1dec);$("#package_infuse_notes").jqxTooltip({content:"Omschrijving van de extra toevoeging."});$("#package_infuse_notes").jqxInput({theme:theme,width:640,height:23});$("#package_abv").jqxTooltip({content:"De uiteindelijke hoeveelheid alcohol volume %."});$("#package_abv").jqxNumberInput(Show2dec);$("#package_ph").jqxTooltip({content:"De gemeten pH vlak voor het verpakken."});$("#package_ph").jqxNumberInput(SpinpH);$("#st_carb_min2").jqxTooltip({content:"Het minimum aanbevolen koolzuur volume voor deze bierstijl."});$("#st_carb_min2").jqxNumberInput(Smal1dec);$("#st_carb_max2").jqxTooltip({content:"Het maximum aamnevolen koolzuur volume voor deze bierstijl."});$("#st_carb_max2").jqxNumberInput(Smal1dec);$("#bottle_amount").jqxTooltip({content:"De totale hoeveelheid te bottelen bier."});$("#bottle_amount").jqxNumberInput(Spin1dec);$("#keg_amount").jqxTooltip({content:"De totale hoeveelheid op fust te zetten bier."});$("#keg_amount").jqxNumberInput(Spin1dec);$("#bottle_carbonation").jqxTooltip({content:"Het gewenste CO2 volume in de flessen."});$("#bottle_carbonation").jqxNumberInput(Spin2dec);$("#bottle_carbonation").jqxNumberInput({max:5});$("#keg_carbonation").jqxTooltip({content:"Het gewenste CO2 volume door de suiker in de fusten."});$("#keg_carbonation").jqxNumberInput(Spin2dec);$("#keg_carbonation").jqxNumberInput({max:5});$("#bottle_priming_sugar").jqxDropDownList({placeHolder:"Kies suiker:",theme:theme,source:fermentablesugars,displayMember:"name",width:200,height:23,dropDownWidth:300,dropDownHeight:400});$("#bottle_priming_sugar").on("select",function(a6){if(a6.args){var a8,a2,a5=-1,a4,a7,a3,a9={};a2=a6.args.index;a4=fermentablesugars.records[a2];a7=$("#fermentableGrid").jqxGrid("getrows");for(a3=0;a3<a7.length;a3++){if(a7[a3].f_added==4){a5=a3}}a9.f_name=a4.name;a9.f_origin=a4.origin;a9.f_supplier=a4.supplier;a9.f_amount=parseFloat($("#bottle_priming_total").jqxNumberInput("decimal"))/1000;a9.f_cost=a4.cost;a9.f_type=a4.type;a9.f_yield=a4.yield;a9.f_color=a4.color;a9.f_coarse_fine_diff=a4.coarse_fine_diff;a9.f_moisture=a4.moisture;a9.f_diastatic_power=a4.diastatic_power;a9.f_protein=a4.protein;a9.f_max_in_batch=a4.max_in_batch;a9.f_graintype=a4.graintype;a9.f_added=4;a9.f_dissolved_protein=a4.dissolved_protein;a9.f_recommend_mash=a4.recommend_mash;a9.f_add_after_boil=1;a9.f_adjust_to_total_100=0;a9.f_percentage=0;a9.f_di_ph=a4.di_ph;a9.f_acid_to_ph_57=a4.acid_to_ph_57;a9.f_inventory=a4.inventory;if(a5>=0){a8=$("#fermentableGrid").jqxGrid("getrowid",a5);$("#fermentableGrid").jqxGrid("updaterow",a8,a9)}else{$("#fermentableGrid").jqxGrid("addrow",null,a9)}aR()}});$("#keg_priming_sugar").jqxDropDownList({placeHolder:"Kies suiker:",theme:theme,source:fermentablesugars,displayMember:"name",width:200,height:23,dropDownWidth:300,dropDownHeight:400});$("#keg_priming_sugar").on("select",function(a6){if(a6.args){var a8,a2,a5=-1,a4,a7,a3,a9={};a2=a6.args.index;a4=fermentablesugars.records[a2];a7=$("#fermentableGrid").jqxGrid("getrows");for(a3=0;a3<a7.length;a3++){if(a7[a3].f_added==5){a5=a3}}a9.f_name=a4.name;a9.f_origin=a4.origin;a9.f_supplier=a4.supplier;a9.f_amount=parseFloat($("#keg_priming_total").jqxNumberInput("decimal"))/1000;a9.f_cost=a4.cost;a9.f_type=a4.type;a9.f_yield=a4.yield;a9.f_color=a4.color;a9.f_coarse_fine_diff=a4.coarse_fine_diff;a9.f_moisture=a4.moisture;a9.f_diastatic_power=a4.diastatic_power;a9.f_protein=a4.protein;a9.f_max_in_batch=a4.max_in_batch;a9.f_graintype=a4.graintype;a9.f_added=5;a9.f_dissolved_protein=a4.dissolved_protein;a9.f_recommend_mash=a4.recommend_mash;a9.f_add_after_boil=1;a9.f_adjust_to_total_100=0;a9.f_percentage=0;a9.f_di_ph=a4.di_ph;a9.f_acid_to_ph_57=a4.acid_to_ph_57;a9.f_inventory=a4.inventory;if(a5>=0){a8=$("#fermentableGrid").jqxGrid("getrowid",a5);$("#fermentableGrid").jqxGrid("updaterow",a8,a9)}else{$("#fermentableGrid").jqxGrid("addrow",null,a9)}aR()}});$("#bottle_priming_amount").jqxNumberInput(Show1dec);$("#bottle_priming_water").jqxTooltip({content:"De hoeveelheid water om de suiker op te lossen."});$("#bottle_priming_water").jqxNumberInput(Spin3dec);$("#keg_priming_amount").jqxNumberInput(Show1dec);$("#keg_priming_water").jqxTooltip({content:"De hoeveelheid water om de suiker op te lossen."});$("#keg_priming_water").jqxNumberInput(Spin3dec);$("#bottle_priming_total").jqxNumberInput(Show1dec);$("#bottle_pressure").jqxTooltip({content:"De maximaal te verwachten druk tijdens het hergisten."});$("#bottle_pressure").jqxNumberInput(Show1dec);$("#keg_priming_total").jqxNumberInput(Show1dec);$("#keg_forced_carb").jqxCheckBox({theme:theme,width:120,height:23});$("#keg_pressure").jqxNumberInput(Show1dec);$("#bottle_abv").jqxNumberInput(Show2dec);$("#keg_abv").jqxNumberInput(Show2dec);$("#bottle_carbonation_temp").jqxNumberInput(YeastT);$("#keg_carbonation_temp").jqxNumberInput(YeastT);$("#taste_date").jqxTooltip({content:"De proef datum van dit bier."});$("#taste_date").jqxDateTimeInput(Dateopts);$("#taste_date").on("close",function(i){aU()});$("#taste_rate").jqxTooltip({content:"Het cijfer voor dit bier van 1 tot 10."});$("#taste_rate").jqxNumberInput(Spin1dec);$("#taste_rate").jqxNumberInput({max:10});$("#taste_color").jqxTooltip({content:"De kleur van het bier."});$("#taste_color").jqxInput({theme:theme,width:320,height:23});$("#taste_transparency").jqxTooltip({content:"De helderheid van het bier."});$("#taste_transparency").jqxInput({theme:theme,width:320,height:23});$("#taste_head").jqxTooltip({content:"Het schuim op het bier."});$("#taste_head").jqxInput({theme:theme,width:320,height:23});$("#taste_aroma").jqxTooltip({content:"Het aroma van het bier."});$("#taste_aroma").jqxInput({theme:theme,width:960,height:23});$("#taste_taste").jqxTooltip({content:"De smaak van het bier."});$("#taste_taste").jqxInput({theme:theme,width:960,height:23});$("#taste_aftertaste").jqxTooltip({content:"De nasmaak van het bier."});$("#taste_aftertaste").jqxInput({theme:theme,width:960,height:23});$("#taste_mouthfeel").jqxTooltip({content:"Het mondgevoelvan het bier."});$("#taste_mouthfeel").jqxInput({theme:theme,width:960,height:23});$("#taste_notes").jqxTooltip({content:"Het oordeel en opmerkingen over dit bier."});$("#taste_notes").jqxInput({theme:theme,width:960,height:100});$("#jqxTabs").jqxTabs({theme:theme,width:1280,height:660,autoHeight:false,position:"top"});$("#Export").jqxButton({template:"info",width:"80px",theme:theme});$("#Export").bind("click",function(){s();var i="prod_export.php?record="+my_record+"&return="+my_return+"&select="+my_select+"&code="+d.code+"&name="+d.name;window.location.href=i});$("#Delete").jqxButton({template:"danger",width:"80px",theme:theme});$("#Delete").bind("click",function(){$("#eventWindow").jqxWindow("open");$("#delOk").click(function(){var i="delete=true&"+$.param({uuid:d.uuid});$.ajax({dataType:"json",url:E,cache:false,data:i,type:"POST",success:function(a3,a2,a4){window.location.href=my_return},error:function(a2,a4,a3){}})})});$("#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(){s();window.location.href=my_return});createDelElements()});
\ No newline at end of file
+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 ad,l=false,ak=0,aY=0,a0=0,H=0,ab=0,aC=77,ao=0,x=0.75,Z=0,p=1,aa=1,ah=1,O=1,c=1,aX=0,U=0,C=0,aT="",af="",A=40.048,ap=24.305,ac=22.98976928,q=35.453,aH=96.0626,r=61.01684,am=172.171,S=147.015,g=100.087,aJ=246.475,aE=84.007,y=105.996,b=58.443,aI=74.06268,u=0,aK={},B=1,a=0,e={},av=0,aG={},aD=0,f={},aj=0,D={},az=4.445e-7,ax=4.68e-11,d={},E="includes/db_product.php",aQ={datatype:"json",cache:false,datafields:[{name:"record",type:"number"},{name:"uuid",type:"string"},{name:"name",type:"string"},{name:"code",type:"string"},{name:"birth",type:"string"},{name:"stage",type:"int"},{name:"notes",type:"string"},{name:"log_brew",type:"int"},{name:"log_fermentation",type:"int"},{name:"inventory_reduced",type:"int"},{name:"locked",type:"int"},{name:"eq_name",type:"string"},{name:"eq_boil_size",type:"float"},{name:"eq_batch_size",type:"float"},{name:"eq_tun_volume",type:"float"},{name:"eq_tun_weight",type:"float"},{name:"eq_tun_specific_heat",type:"float"},{name:"eq_tun_material",type:"int"},{name:"eq_tun_height",type:"float"},{name:"eq_top_up_water",type:"float"},{name:"eq_trub_chiller_loss",type:"float"},{name:"eq_evap_rate",type:"float"},{name:"eq_boil_time",type:"float"},{name:"eq_calc_boil_volume",type:"int"},{name:"eq_top_up_kettle",type:"float"},{name:"eq_hop_utilization",type:"float"},{name:"eq_notes",type:"string"},{name:"eq_lauter_volume",type:"float"},{name:"eq_lauter_height",type:"float"},{name:"eq_lauter_deadspace",type:"float"},{name:"eq_kettle_volume",type:"float"},{name:"eq_kettle_height",type:"float"},{name:"eq_mash_volume",type:"float"},{name:"eq_mash_max",type:"float"},{name:"eq_efficiency",type:"float"},{name:"brew_date_start",type:"string"},{name:"brew_mash_ph",type:"float"},{name:"brew_mash_sg",type:"float"},{name:"brew_mash_efficiency",type:"float"},{name:"brew_sparge_est",type:"float"},{name:"brew_sparge_ph",type:"float"},{name:"brew_preboil_volume",type:"float"},{name:"brew_preboil_sg",type:"float"},{name:"brew_preboil_ph",type:"float"},{name:"brew_preboil_efficiency",type:"float"},{name:"brew_aboil_volume",type:"float"},{name:"brew_aboil_sg",type:"float"},{name:"brew_aboil_ph",type:"float"},{name:"brew_aboil_efficiency",type:"float"},{name:"brew_cooling_method",type:"int"},{name:"brew_cooling_time",type:"float"},{name:"brew_cooling_to",type:"float"},{name:"brew_whirlpool9",type:"float"},{name:"brew_whirlpool7",type:"float"},{name:"brew_whirlpool6",type:"float"},{name:"brew_whirlpool2",type:"float"},{name:"brew_fermenter_volume",type:"float"},{name:"brew_fermenter_extrawater",type:"float"},{name:"brew_fermenter_tcloss",type:"float"},{name:"brew_aeration_time",type:"float"},{name:"brew_aeration_speed",type:"float"},{name:"brew_aeration_type",type:"int"},{name:"brew_fermenter_sg",type:"float"},{name:"brew_fermenter_ibu",type:"float"},{name:"brew_fermenter_color",type:"float"},{name:"brew_date_end",type:"string"},{name:"og",type:"float"},{name:"fg",type:"float"},{name:"primary_start_temp",type:"float"},{name:"primary_max_temp",type:"float"},{name:"primary_end_temp",type:"float"},{name:"primary_end_sg",type:"float"},{name:"primary_end_date",type:"string"},{name:"secondary_temp",type:"float"},{name:"secondary_end_sg",type:"float"},{name:"secondary_end_date",type:"string"},{name:"tertiary_temp",type:"float"},{name:"package_date",type:"string"},{name:"package_volume",type:"float"},{name:"package_infuse_amount",type:"float"},{name:"package_infuse_abv",type:"float"},{name:"package_infuse_notes",type:"string"},{name:"package_abv",type:"float"},{name:"package_ph",type:"float"},{name:"bottle_amount",type:"float"},{name:"bottle_carbonation",type:"float"},{name:"bottle_priming_water",type:"float"},{name:"bottle_priming_amount",type:"float"},{name:"bottle_carbonation_temp",type:"float"},{name:"keg_amount",type:"float"},{name:"keg_carbonation",type:"float"},{name:"keg_priming_water",type:"float"},{name:"keg_priming_amount",type:"float"},{name:"keg_carbonation_temp",type:"float"},{name:"keg_forced_carb",type:"int"},{name:"keg_pressure",type:"float"},{name:"taste_notes",type:"string"},{name:"taste_rate",type:"float"},{name:"taste_date",type:"string"},{name:"taste_color",type:"string"},{name:"taste_transparency",type:"string"},{name:"taste_head",type:"string"},{name:"taste_aroma",type:"string"},{name:"taste_taste",type:"string"},{name:"taste_mouthfeel",type:"string"},{name:"taste_aftertaste",type:"string"},{name:"st_name",type:"string"},{name:"st_letter",type:"string"},{name:"st_guide",type:"string"},{name:"st_category",type:"string"},{name:"st_category_number",type:"float"},{name:"st_type",type:"int"},{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:"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:"starter_enable",type:"int"},{name:"starter_type",type:"int"},{name:"starter_sg",type:"float"},{name:"starter_viability",type:"int"},{name:"prop1_type",type:"int"},{name:"prop1_volume",type:"float"},{name:"prop2_type",type:"int"},{name:"prop2_volume",type:"float"},{name:"prop3_type",type:"int"},{name:"prop3_volume",type:"float"},{name:"prop4_type",type:"int"},{name:"prop4_volume",type:"float"},{name:"fermentables",type:"array"},{name:"hops",type:"array"},{name:"miscs",type:"array"},{name:"yeasts",type:"array"},{name:"mashs",type:"array"}],id:"record",url:E+"?record="+my_record},ag=new $.jqx.dataAdapter(aQ,{loadComplete:function(){var i=ag.records;d=i[0];$("#name").val(d.name);$("#code").val(d.code);$("#birth").val(d.birth);$("#stage").val(StageData[d.stage].nl);$("#notes").val(d.notes);$("#locked").val(d.locked);$("#eq_name").val(d.eq_name);$("#eq_notes").val(d.eq_notes);$("#eq_boil_size").val(d.eq_boil_size);$("#eq_batch_size").val(d.eq_batch_size);$("#eq_tun_volume").val(d.eq_tun_volume);$("#eq_top_up_water").val(d.eq_top_up_water);$("#eq_trub_chiller_loss").val(d.eq_trub_chiller_loss);$("#eq_evap_rate").val(d.eq_evap_rate);$("#eq_boil_time").val(d.eq_boil_time);$("#eq_top_up_kettle").val(d.eq_top_up_kettle);$("#eq_hop_utilization").val(d.eq_hop_utilization);$("#eq_lauter_volume").val(d.eq_lauter_volume);$("#eq_lauter_deadspace").val(d.eq_lauter_deadspace);$("#eq_kettle_volume").val(d.eq_kettle_volume);$("#eq_mash_volume").val(d.eq_mash_volume);$("#eq_mash_max").val(d.eq_mash_max);$("#eq_efficiency").val(d.eq_efficiency);$("#brew_date_start").val(d.brew_date_start);$("#brew_mash_ph").val(d.brew_mash_ph);$("#brew_mash_sg").val(d.brew_mash_sg);$("#brew_mash_efficiency").val(d.brew_mash_efficiency);$("#brew_sparge_temperature").val(d.sparge_temp);$("#brew_sparge_volume").val(d.sparge_volume);$("#brew_sparge_est").val(d.brew_sparge_est);$("#brew_sparge_ph").val(d.brew_sparge_ph);$("#brew_aeration_type").val(d.brew_aeration_type);$("#brew_aeration_time").val(d.brew_aeration_time);$("#brew_aeration_speed").val(d.brew_aeration_speed);$("#brew_preboil_ph").val(d.brew_preboil_ph);$("#brew_preboil_sg").val(d.brew_preboil_sg);$("#brew_preboil_volume").val(d.brew_preboil_volume);$("#brew_preboil_efficiency").val(d.brew_preboil_efficiency);$("#brew_whirlpool9").val(d.brew_whirlpool9);$("#brew_whirlpool7").val(d.brew_whirlpool7);$("#brew_whirlpool6").val(d.brew_whirlpool6);$("#brew_whirlpool2").val(d.brew_whirlpool2);$("#brew_fermenter_volume").val(d.brew_fermenter_volume);$("#brew_fermenter_sg").val(d.brew_fermenter_sg);$("#brew_fermenter_sg2").val(d.brew_fermenter_sg);$("#brew_fermenter_ibu").val(d.brew_fermenter_ibu);$("#brew_fermenter_color").val(d.brew_fermenter_color);$("#brew_fermenter_extrawater").val(d.brew_fermenter_extrawater);$("#brew_fermenter_tcloss").val(d.brew_fermenter_tcloss);$("#brew_aboil_ph").val(d.brew_aboil_ph);$("#brew_aboil_sg").val(d.brew_aboil_sg);$("#brew_aboil_volume").val(d.brew_aboil_volume);$("#brew_aboil_efficiency").val(d.brew_aboil_efficiency);$("#brew_cooling_to").val(d.brew_cooling_to);$("#brew_cooling_method").val(d.brew_cooling_method);$("#brew_cooling_time").val(d.brew_cooling_time);$("#brew_date_end").val(d.brew_date_end);$("#og").val(d.og);$("#fg").val(d.fg);$("#primary_start_temp").val(d.primary_start_temp);$("#primary_max_temp").val(d.primary_max_temp);$("#primary_end_temp").val(d.primary_end_temp);$("#primary_end_sg").val(d.primary_end_sg);$("#primary_end_date").val(d.primary_end_date);$("#secondary_temp").val(d.secondary_temp);$("#secondary_end_sg").val(d.secondary_end_sg);$("#secondary_end_date").val(d.secondary_end_date);$("#tertiary_temp").val(d.tertiary_temp);$("#package_date").val(d.package_date);$("#package_volume").val(d.package_volume);$("#package_infuse_amount").val(d.package_infuse_amount);$("#package_infuse_abv").val(d.package_infuse_abv);$("#package_infuse_notes").val(d.package_infuse_notes);$("#package_abv").val(d.package_abv);$("#package_ph").val(d.package_ph);$("#bottle_amount").val(d.bottle_amount);$("#bottle_carbonation").val(d.bottle_carbonation);$("#bottle_priming_water").val(d.bottle_priming_water);$("#bottle_priming_amount").val(d.bottle_priming_amount);$("#bottle_carbonation_temp").val(d.bottle_carbonation_temp);$("#keg_amount").val(d.keg_amount);$("#keg_carbonation").val(d.keg_carbonation);$("#keg_priming_water").val(d.keg_priming_water);$("#keg_priming_amount").val(d.keg_priming_amount);$("#keg_carbonation_temp").val(d.keg_carbonation_temp);$("#keg_forced_carb").val(d.keg_forced_carb);$("#keg_pressure").val(d.keg_pressure);$("#taste_notes").val(d.taste_notes);$("#taste_rate").val(d.taste_rate);$("#taste_date").val(d.taste_date);$("#taste_color").val(d.taste_color);$("#taste_transparency").val(d.taste_transparency);$("#taste_head").val(d.taste_head);$("#taste_aroma").val(d.taste_aroma);$("#taste_taste").val(d.taste_taste);$("#taste_mouthfeel").val(d.taste_mouthfeel);$("#taste_aftertaste").val(d.taste_aftertaste);$("#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);$("#st_og_min").val(d.st_og_min);$("#st_og_max").val(d.st_og_max);$("#st_fg_min").val(d.st_fg_min);$("#st_fg_max").val(d.st_fg_max);$("#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);$("#st_ibu_min").val(d.st_ibu_min);$("#st_ibu_max").val(d.st_ibu_max);$("#st_carb_min").val(d.st_carb_min);$("#st_carb_min2").val(d.st_carb_min);$("#st_carb_max").val(d.st_carb_max);$("#st_carb_max2").val(d.st_carb_max);$("#type").val(d.type);$("#batch_size").val(d.batch_size);$("#est_a_vol").val(d.batch_size*1.04);$("#boil_size").val(d.boil_size);$("#est_pre_vol").val(d.boil_size*1.04);$("#boil_time").val(d.boil_time);$("#efficiency").val(d.efficiency);$("#est_og").val(d.est_og);$("#est_og2").val(d.est_og);$("#est_og3").val(0);$("#est_fg").val(d.est_fg);$("#est_fg2").val(d.est_fg);$("#est_fg3").val(d.est_fg);$("#est_color").val(d.est_color);$("#est_color2").val(d.est_color);$("#est_abv").val(d.est_abv);$("#color_method").val(d.color_method);$("#est_ibu").val(d.est_ibu);$("#est_ibu2").val(d.est_ibu);$("#ibu_method").val(d.ibu_method);$("#est_carb").val(d.est_carb);$("#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);$("#starter_enable").val(d.starter_enable);$("#starter_type").val(d.starter_type);$("#starter_sg").val(d.starter_sg);$("#starter_viability").val(d.starter_viability);$("#prop1_type").val(d.prop1_type);$("#prop1_volume").val(d.prop1_volume);$("#prop2_type").val(d.prop2_type);$("#prop2_volume").val(d.prop2_volume);$("#prop3_type").val(d.prop3_type);$("#prop3_volume").val(d.prop3_volume);$("#prop4_type").val(d.prop4_type);$("#prop4_volume").val(d.prop4_volume);n(d);aS(d);W(d);aL(d);au(d);aU();$("#jqxTabs").jqxTabs("select",2)},loadError:function(a3,i,a2){},beforeLoadComplete:function(i){$("#jqxLoader").jqxLoader("open")}});var n=function(a2){var i={localdata:a2.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(a5,a7,a4,a6){a6(true)},deleterow:function(a4,a5){a5(true)},updaterow:function(a4,a6,a5){a5(true)}},a3=new $.jqx.dataAdapter(i);$("#fermentableGrid").jqxGrid({width:1240,height:470,source:a3,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');a4.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",disabled:(d.stage>3),width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(a7,a6,a9){var a8=fermentablelist.records[a7];return a8.supplier+" / "+a8.name+" ("+a8.color+" EBC)"}});$("#faddrowbutton").on("select",function(a8){if(a8.args){var a6,a7,a9={},ba=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;a6=a8.args.index;a7=fermentablelist.records[a6];a9.f_name=a7.name;a9.f_origin=a7.origin;a9.f_supplier=a7.supplier;a9.f_amount=0;a9.f_cost=a7.cost;a9.f_type=a7.type;a9.f_yield=a7.yield;a9.f_color=a7.color;a9.f_coarse_fine_diff=a7.coarse_fine_diff;a9.f_moisture=a7.moisture;a9.f_diastatic_power=a7.diastatic_power;a9.f_protein=a7.protein;a9.f_max_in_batch=a7.max_in_batch;a9.f_graintype=a7.graintype;if(a7.add_after_boil){a9.f_added=2}else{if((a7.type==1)||(a7.type==4)){a9.f_added=1}else{a9.f_added=0}}a9.f_dissolved_protein=a7.dissolved_protein;a9.f_recommend_mash=a7.recommend_mash;a9.f_add_after_boil=a7.add_after_boil;if(ba==0){a9.f_adjust_to_total_100=1;a9.f_percentage=100}else{a9.f_adjust_to_total_100=0;a9.f_percentage=0}a9.f_di_ph=a7.di_ph;a9.f_acid_to_ph_57=a7.acid_to_ph_57;a9.f_inventory=a7.inventory;$("#fermentableGrid").jqxGrid("addrow",null,a9)}});$("#finstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#finstockbutton").on("change",function(a6){fermentableinstock=a6.args.checked;fermentablelist.dataBind()});$("#fdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#fdeleterowbutton").on("click",function(){var bc,bb,a9,a8,a7,ba,a6=$("#fermentableGrid").jqxGrid("getselectedrowindex");bc=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<bc){bb=$("#fermentableGrid").jqxGrid("getrowid",a6);a9=$("#fermentableGrid").jqxGrid("getcellvalue",bb,"f_percentage");a8=$("#fermentableGrid").jqxGrid("getcellvalue",bb,"f_amount");$("#fermentableGrid").jqxGrid("deleterow",bb)}bc=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(bc>1){if(l){for(a7=0;a7<bc;a7++){ba=$("#fermentableGrid").jqxGrid("getrowdata",a7);if(ba.f_adjust_to_total_100){ba.f_percentage+=a9;ba.f_amount+=a8}}}else{aV()}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}T();ar()})},ready:function(){T();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Vergistbaar ingredi&euml;nt",datafield:"f_name",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+a9.f_supplier+" / "+a9.f_name+" ("+a9.f_color+" EBC)</span>"}},{text:"Type",width:100,datafield:"f_type",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+FermentableTypeData[a8].nl+"</span>"}},{text:"Moment",width:110,datafield:"f_added",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+AddedData[a8].nl+"</span>"}},{text:"Maxinbatch",datafield:"f_max_in_batch",hidden:true},{text:"Opbrengst",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:"Voorraad Kg",datafield:"f_inventory",width:120,align:"right",cellsrenderer:function(a8,a6,a7,a4,ba,a9){var a5="#ffffff";if(((d.inventory_reduced<=2)&&(a9.f_added<=1))||((d.inventory_reduced<=3)&&(a9.f_added==2))||((d.inventory_reduced<=5)&&(a9.f_added==3))||((d.inventory_reduced<=6)&&(a9.f_added==4))||((d.inventory_reduced<=6)&&(a9.f_added==5))){if(a7<a9.f_amount){a5="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a5+';">'+a3.formatNumber(a7,"f3")+"</span>"}else{return"<span></span>"}}},{text:"Procent",datafield:"f_percentage",width:90,align:"right",cellsrenderer:function(a8,a6,a7,a4,ba,a9){if(a9.f_added>=4){return"<span></span>"}var a5="#ffffff";if(a7>a9.f_max_in_batch){a5="#ff4040"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a5+';">'+a3.formatNumber(a7,"p1")+"</span>"}},{text:"100%",datafield:"f_adjust_to_total_100",width:70,align:"center",cellsalign:"center",cellsrenderer:function(a5,a4,a8,a7,a6,a9){if(a8==0){return"<span></span>"}return'<span><img style="float:left; margin-left:25px; margin-top:4px;" src="images/dialog-ok-apply.png"></span>'}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){u=a4;aK=$("#fermentableGrid").jqxGrid("getrowdata",u);if(aK.f_added>=4){alert("Wijzig dit in de Verpakken tab")}else{if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{$("#wf_name").val(aK.f_name);$("#wf_amount").val(aK.f_amount);$("#wf_percentage").val(aK.f_percentage);$("#wf_max_in_batch").val(aK.f_max_in_batch);$("#wf_adjust_to_total_100").val(aK.f_adjust_to_total_100);$("#wf_added").val(aK.f_added);$("#popupFermentable").jqxWindow("open")}}}}]})},aS=function(i){var a3={localdata:i.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(a5,a7,a4,a6){console.log("hop addrow "+a5);a6(true)},deleterow:function(a4,a5){console.log("hop deleterow "+a4);a5(true)},updaterow:function(a4,a6,a5){console.log("hop updaterow "+a4);a5(true)}},a2=new $.jqx.dataAdapter(a3);$("#hopGrid").jqxGrid({width:1240,height:560,source:a2,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');a4.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,disabled:(d.stage>3),displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(a7,a6,a9){var a8=hoplist.records[a7];return a8.origin+" - "+a8.name+" / "+HopFormData[a8.form].nl+" ("+a8.alpha+"% &alpha;)"}});$("#haddrowbutton").on("select",function(a8){if(a8.args){var a7,a9={},a6=a8.args.index;a7=hoplist.records[a6];a9.h_name=a7.name;a9.h_origin=a7.origin;a9.h_amount=0;a9.h_cost=a7.cost;a9.h_type=a7.type;a9.h_form=a7.form;a9.h_useat=2;a9.h_time=0;a9.h_alpha=a7.alpha;a9.h_beta=a7.beta;a9.h_hsi=a7.hsi;a9.h_humulene=a7.humulene;a9.h_caryophyllene=a7.caryophyllene;a9.h_cohumulone=a7.cohumulone;a9.h_myrcene=a7.myrcene;a9.h_total_oil=a7.total_oil;a9.h_inventory=a7.inventory;$("#hopGrid").jqxGrid("addrow",null,a9)}$("#haddrowbutton").jqxDropDownList("clearSelection")});$("#hinstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#hinstockbutton").on("change",function(a6){hopinstock=a6.args.checked;hoplist.dataBind()});$("#hdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#hdeleterowbutton").on("click",function(){var a8,a7,a6=$("#hopGrid").jqxGrid("getselectedrowindex");a8=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<a8){a7=$("#hopGrid").jqxGrid("getrowid",a6);$("#hopGrid").jqxGrid("deleterow",a7)}ar()})},ready:function(){ar();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Hop",datafield:"h_name",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+a9.h_origin+" / "+a9.h_name+"</span>"},},{text:"Type",width:90,datafield:"h_type",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopTypeData[a8].nl+"</span>"}},{text:"Vorm",width:90,datafield:"h_form",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopFormData[a8].nl+"</span>"}},{text:"Alpha",datafield:"h_alpha",width:80,align:"right",cellsalign:"right",cellsformat:"p1"},{text:"Gebruik",width:110,datafield:"h_useat",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+HopUseData[a8].nl+"</span>"}},{text:"Tijdsduur",datafield:"h_time",width:90,align:"right",cellsrenderer:function(a5,a4,a8,a7,a6,ba){var a9="";if((ba.h_useat==2)||(ba.h_useat==4)){a9=ag.formatNumber(a8,"f0")+" min."}else{if(ba.h_useat==5){a9=ag.formatNumber(a8/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a9+"</span>"}},{text:"IBU",datafield:"ibu",width:80,align:"right",cellsrenderer:function(a5,a4,a8,a7,a6,ba){var a9=toIBU(ba.h_useat,ba.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(ba.h_amount),parseFloat(ba.h_time),parseFloat(ba.h_alpha),$("#ibu_method").val());return'<span style="margin: 4px; margin-top: 6px; float: right;">'+ag.formatNumber(a9,"f1")+"</span>"}},{text:"Gewicht",datafield:"h_amount",width:110,align:"right",cellsrenderer:function(a5,a4,a9,a8,a7,ba){var a6=ag.formatNumber(a9,"f1")+" kg";if(a9<1){a6=ag.formatNumber(a9*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a6+"</span>"}},{text:"Voorraad",datafield:"h_inventory",width:110,align:"right",cellsrenderer:function(a6,a5,ba,a9,a8,bb){if(((d.inventory_reduced<=2)&&(bb.h_useat<=4))||((d.inventory_reduced<=6)&&(bb.h_useat==5))){var a7,a4="#ffffff";if(ba<bb.h_amount){a4="#ff4040"}a7=ag.formatNumber(ba,"f1")+" kg";if(ba<1){a7=ag.formatNumber(ba*1000,"f1")+" gr"}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a4+';">'+a7+"</span>"}else{return"<span></span>"}}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{console.log("edit button row "+a4);a=a4;e=$("#hopGrid").jqxGrid("getrowdata",a);$("#wh_name").val(e.h_name);$("#wh_amount").val(e.h_amount*1000);var a5=toIBU(e.h_useat,e.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(e.h_amount),parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(a5);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")}}}]})},W=function(a3){var a2={localdata:a3.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(a5,a7,a4,a6){console.log("misc addrow "+a5);a6(true)},deleterow:function(a4,a5){console.log("misc deleterow "+a4);a5(true)},updaterow:function(a4,a6,a5){console.log("misc updaterow "+a4);a5(true)}},i=new $.jqx.dataAdapter(a2,{beforeLoadComplete:function(a4){var a7,a5,a6=new Array();for(a5=0;a5<a4.length;a5++){a7=a4[a5];a6.push(a7);switch(a7.m_name){case"CaCl2":$("#wa_cacl2").val(a7.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(a7.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(a7.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(a7.m_amount*1000);break;case"Melkzuur":$("#wa_acid_name").val(0);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Melkzuur";break;case"Zoutzuur":$("#wa_acid_name").val(1);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Zoutzuur";break;case"Fosforzuur":$("#wa_acid_name").val(2);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Fosforzuur";break;case"Zwavelzuur":$("#wa_acid_name").val(3);$("#wa_acid").val(a7.m_amount*1000);$("#wa_acid_perc").val(80);af="Zwavelzuur";break;case"NaHCO3":$("#wa_base_name").val(0);$("#wa_base").val(a7.m_amount*1000);aT="NaHCO3";break;case"Na2CO3":$("#wa_base_name").val(1);$("#wa_base").val(a7.m_amount*1000);aT="Na2CO3";break;case"CaCO3":$("#wa_base_name").val(2);$("#wa_base").val(a7.m_amount*1000);aT="CaCO3";break;case"Ca(OH)2":$("#wa_base_name").val(3);$("#wa_base").val(a7.m_amount*1000);aT="Ca(OH)2";break}}return a6},loadError:function(a6,a4,a5){$("#err").text(a4+" "+a5)},});$("#miscGrid").jqxGrid({width:1240,height:575,source:i,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="minstockbutton"></div>');a4.append('<input style="float: left; margin-left: 400px;" id="mdeleterowbutton" type="button" value="Verwijder ingredient" />');$("#maddrowbutton").jqxDropDownList({placeHolder:"Kies ingredi&euml;nt:",theme:theme,template:"primary",source:misclist,disabled:(d.stage>3),displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500});$("#maddrowbutton").on("select",function(a8){if(a8.args){var a7,a9={},a6=a8.args.index;a7=misclist.records[a6];a9.m_name=a7.name;a9.m_amount=0;a9.m_cost=a7.cost;a9.m_type=a7.type;a9.m_use_use=a7.use_use;a9.m_time=0;a9.m_amount_is_weight=a7.amount_is_weight;a9.m_inventory=a7.inventory;$("#miscGrid").jqxGrid("addrow",null,a9)}});$("#minstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#minstockbutton").on("change",function(a6){miscinstock=a6.args.checked;misclist.dataBind()});$("#mdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#mdeleterowbutton").on("click",function(){var a9,a7,a8,a6=$("#miscGrid").jqxGrid("getselectedrowindex");a9=$("#miscGrid").jqxGrid("getdatainformation").rowscount;a7=$("#miscGrid").jqxGrid("getcellvalue",a6,"m_type");if(a6>=0&&a6<a9&&a7!=4){a8=$("#miscGrid").jqxGrid("getrowid",a6);$("#miscGrid").jqxGrid("deleterow",a8)}})},ready:function(){aF();$("#jqxTabs").jqxTabs("next")},columns:[{text:"Ingredient",datafield:"m_name"},{text:"Type",width:140,datafield:"m_type",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+MiscTypeData[a8].nl+"</span>"}},{text:"Gebruik",width:140,datafield:"m_use_use",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 3px; margin-top: 6px; float: left;">'+MiscUseData[a8].nl+"</span>"}},{text:"Tijd",datafield:"m_time",width:90,align:"right",cellsrenderer:function(a5,a4,a8,a7,a6,ba){var a9="";if(ba.m_use_use==2){a9=ag.formatNumber(a8,"f0")+" min."}else{if((ba.m_use_use==3)||(ba.m_use_use==4)){a9=ag.formatNumber(a8/1440,"f0")+" dagen"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a9+"</span>"}},{text:"Hoeveel",datafield:"m_amount",width:110,align:"right",cellsrenderer:function(a5,a4,a9,a7,a6,ba){var a8=ba.m_amount_is_weight?"gr":"ml";return'<span style="margin: 4px; margin-top: 6px; float: right;">'+ag.formatNumber(a9*1000,"f2")+" "+a8+"</span>"}},{text:"Voorraad",datafield:"m_inventory",width:110,align:"right",cellsrenderer:function(a8,a4,a9,bb,a5,bc){var ba,a6,a7;if(((d.inventory_reduced<=2)&&(bc.m_use_use<=2))||((d.inventory_reduced<=3)&&(bc.m_use_use==3))||((d.inventory_reduced<=5)&&(bc.m_use_use==4))||((d.inventory_reduced<=6)&&(bc.m_use_use==5))){ba=bc.m_amount_is_weight?"gr":"ml";a6="#ffffff";if(a9<bc.m_amount){a6="#ff4040"}a7=ag.formatNumber(a9*1000,"f2")+" "+ba;return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a6+';">'+a7+"</span>"}else{return"<span></span>"}}},{text:"",datafield:"Edit",columntype:"button",width:100,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){av=a4;aG=$("#miscGrid").jqxGrid("getrowdata",av);if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{if(aG.m_type==4){alert("Brouwzouten wijzigen in de water tab.")}else{console.log("edit button row "+a4);if(aG.m_amount_is_weight){$("#wm_pmpt_amount").html("Gewicht gram:")}else{$("#wm_pmpt_amount").html("Volume ml:")}$("#wm_name").val(aG.m_name);$("#wm_amount").val(aG.m_amount*1000);if((aG.m_use_use==3)||(aG.m_use_use==4)){$("#wm_time").val(aG.m_time/1440)}else{$("#wm_time").val(aG.m_time)}$("#wm_use_use").val(aG.m_use_use);$("#popupMisc").jqxWindow("open")}}}}]})},aL=function(a2){var i={localdata:a2.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(a5,a7,a4,a6){console.log("yeast addrow "+a5);a6(true)},deleterow:function(a4,a5){console.log("yeast deleterow "+a4);a5(true)},updaterow:function(a4,a6,a5){console.log("yeast updaterow "+a4);a5(true)}},a3=new $.jqx.dataAdapter(i);$("#yeastGrid").jqxGrid({width:1240,height:350,source:a3,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');a5.append(a4);a4.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');a4.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');a4.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');a4.append('<input style="float: left; margin-left: 400px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');$("#yaddrowbutton").jqxDropDownList({placeHolder:"Kies gist:",theme:theme,source:yeastlist,disabled:(d.stage>3),template:"primary",displayMember:"name",width:150,height:27,dropDownWidth:500,dropDownHeight:500,renderer:function(a7,a6,a9){var a8=yeastlist.records[a7];return a8.laboratory+" "+a8.product_id+" "+a8.name}});$("#yaddrowbutton").on("select",function(a8){if(a8.args){var a7,a9={},a6=a8.args.index;a7=yeastlist.records[a6];a9.y_name=a7.name;a9.y_laboratory=a7.laboratory;a9.y_product_id=a7.product_id;a9.y_type=a7.type;a9.y_form=a7.form;a9.y_amount=0;a9.y_cost=a7.cost;a9.y_use=0;a9.y_min_temperature=a7.min_temperature;a9.y_max_temperature=a7.max_temperature;a9.y_attenuation=a7.attenuation;a9.y_flocculation=a7.flocculation;a9.y_cells=a7.cells;a9.y_tolerance=a7.tolerance;a9.y_inventory=a7.inventory;$("#yeastGrid").jqxGrid("addrow",null,a9)}X();$("#yaddrowbutton").jqxDropDownList("clearSelection")});$("#yinstockbutton").jqxCheckBox({theme:theme,height:27,disabled:(d.stage>3)});$("#yinstockbutton").on("change",function(a6){yeastinstock=a6.args.checked;yeastlist.dataBind()});$("#ydeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#ydeleterowbutton").on("click",function(){var a8,a7,a6=$("#yeastGrid").jqxGrid("getselectedrowindex");a7=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<a7){a8=$("#yeastGrid").jqxGrid("getrowid",a6);$("#yeastGrid").jqxGrid("deleterow",a8);X()}})},ready:function(){T();I();X();$("#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(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastFormData[a8].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(a6,a5,ba,a9,a8,bb){var a7="",a4="#ffffff";if(ba>0){a7=ag.formatNumber(ba,"f1");if(d.est_abv>ba){a4="#ff4040"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a4+';">'+a7+"</span>"}},{text:"Attn. %",width:70,align:"right",cellsalign:"right",datafield:"y_attenuation",cellsformat:"f1"},{text:"Voor",width:120,datafield:"y_use",cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+YeastUseData[a8].nl+"</span>"}},{text:"Hoeveel",datafield:"y_amount",width:90,align:"right",cellsrenderer:function(a5,a4,a9,a8,a7,ba){var a6=ag.formatNumber(a9*1000,"f0")+" ml";if(ba.y_form==0){a6=ag.formatNumber(a9,"f0")+" pk"}else{if(ba.y_form==1){a6=ag.formatNumber(a9*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right;">'+a6+"</span>"}},{text:"Voorraad",datafield:"y_inventory",width:90,align:"right",cellsrenderer:function(a6,a5,ba,a9,a8,bb){var a4,a7;if(((d.inventory_reduced<=3)&&(bb.y_use==0))||((d.inventory_reduced<=4)&&(bb.y_use==1))||((d.inventory_reduced<=5)&&(bb.y_use==2))||((d.inventory_reduced<=6)&&(bb.y_use==3))){a4="#ffffff";if(ba<bb.y_amount){a4="#ff4040"}a7=ag.formatNumber(ba*1000,"f0")+" ml";if(bb.y_form==0){a7=ag.formatNumber(ba,"f0")+" pk"}else{if(bb.y_form==1){a7=ag.formatNumber(ba*1000,"f1")+" gr"}}return'<span style="margin: 4px; margin-top: 6px; float: right; color: '+a4+';">'+a7+"</span>"}else{return"<span></span>"}}},{text:"",datafield:"Edit",columntype:"button",width:90,align:"center",cellsrenderer:function(){return"Wijzig"},buttonclick:function(a4){if(d.stage>3){alert("Ingredieënt is al verwerkt.")}else{aD=a4;f=$("#yeastGrid").jqxGrid("getrowdata",aD);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")}}}]})},au=function(a3){var a2={localdata:a3.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(a5,a7,a4,a6){console.log("mash addrow "+a5);a6(true)},deleterow:function(a4,a5){console.log("mash deleterow "+a4);a5(true)}},i=new $.jqx.dataAdapter(a2,{beforeLoadComplete:function(a4){C=0;var a5,a7,a6=new Array();for(a5=0;a5<a4.length;a5++){a7=a4[a5];if(a7.step_type==0){C+=parseFloat(a7.step_infuse_amount)}a7.step_thickness=0;a6.push(a7)}},});$("#mashGrid").jqxGrid({width:1240,height:400,source:i,theme:theme,selectionmode:"singlerow",showtoolbar:true,rendertoolbar:function(a5){var a4=$('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');a5.append(a4);a4.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');a4.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,disabled:(d.stage>3)});$("#saddrowbutton").on("click",function(){var a6={},a7=$("#mashGrid").jqxGrid("getdatainformation").rowscount;a6.step_name="Stap "+(a7+1);if(a7>0){a6.step_type=1}else{a6.step_type=0;a6.step_infuse_amount=15}a6.step_temp=62;a6.step_time=20;a6.step_thickness=0;a6.ramp_time=1;a6.end_temp=62;$("#mashGrid").jqxGrid("addrow",null,a6)});$("#sdeleterowbutton").jqxButton({template:"danger",theme:theme,height:27,width:150,disabled:(d.stage>3)});$("#sdeleterowbutton").on("click",function(){var a8,a7,a6=$("#mashGrid").jqxGrid("getselectedrowindex");a8=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(a6>=0&&a6<a8){a7=$("#mashGrid").jqxGrid("getrowid",a6);$("#mashGrid").jqxGrid("deleterow",a7)}})},ready:function(){aW();aN();$("#jqxLoader").jqxLoader("close");$("#jqxTabs").jqxTabs("first")},columns:[{text:"Stap naam",datafield:"step_name"},{text:"Stap type",datafield:"step_type",width:175,cellsrenderer:function(a5,a4,a8,a7,a6,a9){return'<span style="margin: 4px; margin-top: 6px; float: left;">'+MashStepTypeData[a8].nl+"</span>"}},{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(a4){if(d.stage>3){alert("Het maichen is al gedaan.")}else{aj=a4;D=$("#mashGrid").jqxGrid("getrowdata",aj);$("#wstep_name").val(D.step_name);$("#wstep_type").val(D.step_type);$("#wstep_infuse_amount").val(D.step_infuse_amount);$("#wstep_temp").val(D.step_temp);$("#wend_temp").val(D.end_temp);$("#wstep_time").val(D.step_time);$("#wramp_time").val(D.ramp_time);if(D.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 product ...",theme:theme});function G(){if(d.inventory_reduced>6){$("#ok_pmpt").hide();return}if(p&&aa&&ah&&O&&c){$("#ok_supplies").html("<img src='images/dialog-ok-apply.png'>")}else{$("#ok_supplies").html("<img src='images/dialog-error.png'>")}}function aV(){console.log("calcPercentages()");var a2=0,a4,i,a3=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if(a3>1){for(ad=0;ad<a3;ad++){a4=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(a4.f_added<4){a2+=Round(a4.f_amount,3)}}a2=Round(a2,3);for(ad=0;ad<a3;ad++){a4=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(a4.f_added<4){i=Round(a4.f_amount/a2*100,1);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",i)}else{$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",0)}}}else{$("#fermentableGrid").jqxGrid("setcellvalue",0,"f_percentage",100)}}function T(){var bA=0,bs=0,bq=0,bi=0,br=0,bB=0,bb=0,bl=0,bf=0,bj=false,bo=0,ba=0,bu=0.925,bn=0.95,a9=0,bp,a8,bd,a2,bh,a3,bx,by,a6,bg=0,bw,be,bc,a5,a7,bk,a4,bm,bt,bz;H=0;ab=0;ao=0;p=1;O=1;if((bd=$("#mashGrid").jqxGrid("getrows"))){for(bp=0;bp<bd.length;bp++){a8=bd[bp];if(a8.step_type==0){bB+=parseFloat(a8.step_infuse_amount)}if(a8.step_temp<=75){bh=a8.step_time+a8.ramp_time;bo+=bh;ba+=bh*a8.step_temp}}if(bo>5){bo-=5}ba=Round(ba/bo,2)}if(!(bd=$("#fermentableGrid").jqxGrid("getrows"))){return}for(bp=0;bp<bd.length;bp++){a8=bd[bp];if(a8.f_adjust_to_total_100){bj=true}if(a8.f_type==1&&a8.f_added<4){H+=a8.f_percentage}if(a8.f_graintype==2&&a8.f_added<4){ab+=a8.f_percentage}bw=a8.f_amount*(a8.f_yield/100)*(1-a8.f_moisture/100);if(a8.f_added==0){if(bB>0){bB+=a8.f_amount*a8.f_moisture/100;bg+=bw}bw=parseFloat(d.efficiency)/100*bw;bs+=bw;ao+=parseFloat(a8.f_amount)}if(a8.f_added==0||a8.f_added==1){bA+=bw}if(a8.f_added==2||a8.f_added==3){bc=(a8.f_yield/100)*(1-a8.f_moisture/100);bi+=a8.f_amount*bc;br+=a8.f_amount;bq+=(bc*sugardensity+(1-bc)*1)*a8.f_amount}if(a8.f_added<4){bb+=a8.f_amount*ebc_to_srm(a8.f_color);bl+=a8.f_amount*a8.f_color*get_kt(a8.f_color);bf+=(a8.f_percentage/100)*a8.f_color}if(B){if(a8.f_added==4){$("#bottle_priming_total").val(a8.f_amount*1000);$("#bottle_priming_sugar").jqxDropDownList("selectItem",a8.f_name)}if(a8.f_added==5){$("#keg_priming_total").val(a8.f_amount*1000);$("#keg_priming_sugar").jqxDropDownList("selectItem",a8.f_name)}}if((((d.inventory_reduced<=2)&&(a8.f_added<=1))||((d.inventory_reduced<=3)&&(a8.f_added==2))||((d.inventory_reduced<=5)&&(a8.f_added==3))||((d.inventory_reduced<=6)&&(a8.f_added==4))||((d.inventory_reduced<=6)&&(a8.f_added==5)))&&a8.f_inventory<a8.f_amount){p=0}if(a8.f_added==0&&(a8.f_type==0||a8.f_type==4)&&a8.f_color<50){a9+=a8.f_diastatic_power*a8.f_amount}}B=0;$("#ferm_lintner").val(Math.round(parseFloat(a9/ao)));$("#mash_kg").val(ao);console.log("calcFermentables() supplies:"+p+" moutsuiker:"+bs+"/"+bA);l=bj;if(l){$("#wf_amount").jqxNumberInput({width:90,readOnly:true,spinButtons:false})}else{$("#wf_amount").jqxNumberInput({width:110,readOnly:false,spinButtons:true})}if(bB>0){be=bg/sugardensity+bB;bg=1000*bg/(be*10);a0=Round(plato_to_sg(bg),5);$("#est_mash_sg").val(a0)}d.est_og=estimate_sg(bA+bi,parseFloat(d.batch_size));$("#est_og").val(d.est_og);$("#est_og2").val(d.est_og);a2=d.est_og;aY=estimate_sg(bA,parseFloat(d.batch_size));$("#est_og3").val(aY);ak=estimate_sg(bs,parseFloat(d.boil_size));$("#est_pre_sg").val(ak);a3=parseFloat(d.batch_size);if(d.brew_aboil_volume>0){a3=d.brew_aboil_volume/1.04}if(d.brew_fermenter_tcloss==0){d.brew_fermenter_tcloss=d.eq_trub_chiller_loss;$("#brew_fermenter_tcloss").val(d.brew_fermenter_tcloss)}d.brew_fermenter_volume=a3-d.brew_fermenter_tcloss+d.brew_fermenter_extrawater;$("#brew_fermenter_volume").val(d.brew_fermenter_volume);bx=(d.boil_size-C+(ao*my_grain_absorbtion)+d.eq_lauter_deadspace)*1.03;$("#brew_sparge_est").val(bx);by=d.brew_aboil_sg;if(by<1.002){by=aY}a6=d.brew_fermenter_extrawater;if(d.brew_fermenter_volume>0){a5=sg_to_plato(by)*d.brew_fermenter_volume*by/100;a5+=bi;if((d.brew_fermenter_volume*by+br)>0){bk=100*a5/(d.brew_fermenter_volume*by+br+a6);d.brew_fermenter_sg=Round(plato_to_sg(bk),4);$("#brew_fermenter_sg").val(d.brew_fermenter_sg);if(d.color_method==4){d.brew_fermenter_color=Math.round(((bk/8.6)*bf)+(d.boil_time/60))}else{if(d.color_method==3){d.brew_fermenter_color=Math.round((4.46*bu*bn)/(a3+a6)*bl)}else{a4=bb/(a3+a6)*8.34436;d.brew_fermenter_color=kw_to_ebc(d.color_method,a4)}}$("#brew_fermenter_color").val(d.brew_fermenter_color);bt=ebc_to_color(d.brew_fermenter_color);$("#bcolorf").show();document.getElementById("bcolorf").style.background=bt}}else{d.brew_fermenter_sg=d.brew_fermenter_color=0;$("#brew_fermenter_sg").val(0);$("#brew_fermenter_color").val(0);$("#bcolorf").hide()}if(d.color_method==4){bm=Math.round(((sg_to_plato(d.est_og)/8.6)*bf)+(d.boil_time/60))}else{if(d.color_method==3){bm=Math.round((4.46*bu*bn)/parseFloat(d.batch_size)*bl)}else{a4=bb/parseFloat(d.batch_size)*8.34436;bm=kw_to_ebc(d.color_method,a4)}}d.est_color=bm;$("#est_color").val(bm);$("#est_color2").val(bm);bt=ebc_to_color(bm);document.getElementById("bcolor").style.background=bt;document.getElementById("bcolor2").style.background=bt;pmalts=ao/d.eq_mash_max*100;$("#perc_malts").jqxProgressBar("val",pmalts);$("#perc_sugars").jqxProgressBar("val",H);$("#perc_cara").jqxProgressBar("val",ab);aU();aC=0;Z=0;bd=$("#yeastGrid").jqxGrid("getrows");for(bp=0;bp<bd.length;bp++){a8=bd[bp];if(a8.y_use==0){if(parseFloat(a8.y_attenuation)>aC){aC=parseFloat(a8.y_attenuation)}if(a8.y_form==0){Z+=(parseFloat(a8.y_cells)/1000000000)*parseFloat(a8.y_amount)*(d.starter_viability/100)}else{Z+=(parseFloat(a8.y_cells)/1000000)*parseFloat(a8.y_amount)}}if((((d.inventory_reduced<=3)&&(a8.y_use==0))||((d.inventory_reduced<=4)&&(a8.y_use==1))||((d.inventory_reduced<=5)&&(a8.y_use==2))||((d.inventory_reduced<=6)&&(a8.y_use==3)))&&(a8.y_inventory<a8.y_amount)){O=0}}G();if(aC==0){aC=77}if((ao>0)&&(C>0)&&(bo>0)&&(ba>0)){d.est_fg=estimate_fg(H,ab,C/ao,bo,ba,aC,d.est_og)}else{d.est_fg=estimate_fg(H,ab,0,0,0,aC,d.est_og)}$("#est_fg").val(d.est_fg);$("#est_fg2").val(d.est_fg);$("#est_fg3").val(d.est_fg);bz=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);if((d.stage>=6)&&(d.fg>0.99)&&(d.fg<d.brew_fermenter_sg)){aC=100*(d.brew_fermenter_sg-d.fg)/(d.brew_fermenter_sg-1);a2=d.brew_fermenter_sg;bz=d.fg}$("#yeast_cells").val(Z);$("#need_cells").val(v());a7=1881.22*bz*(a2-bz)/(1.775-a2);a5=3550*bz*(0.1808*a2+0.8192*bz-1.0004);$("#kcal").val(Math.round((a7+a5)/(12*0.0295735296)))}function aN(){var a2=0,a3,a4;if(!(rows=$("#mashGrid").jqxGrid("getrows"))){return}if(ao==0){return}for(a3=0;a3<rows.length;a3++){a4=$("#mashGrid").jqxGrid("getrowdata",a3);if(a4.step_type==0){a2+=a4.step_infuse_amount}$("#mashGrid").jqxGrid("setcellvalue",a3,"step_thickness",a2/ao)}}function ae(a3){console.log("calcFermentablesFromOG("+a3+")");var a5,bb,a8,a4,ba,a7=0,a6=0,a9,a2=parseFloat($("#efficiency").jqxNumberInput("decimal"));ba=sg_to_plato(a3)*parseFloat($("#batch_size").jqxNumberInput("decimal"))*a3/100;a9=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(a4=0;a4<a9;a4++){bb=$("#fermentableGrid").jqxGrid("getrowdata",a4);if(bb.f_added<4){a8=bb.f_percentage/100*(bb.f_yield/100)*(1-bb.f_moisture/100);if(bb.f_added==0){a8=a2/100*a8}a7+=a8}}if(a7){a6=Round(ba/a7,3)}if(a6){for(a4=0;a4<a9;a4++){bb=$("#fermentableGrid").jqxGrid("getrowdata",a4);if(bb.f_added<4){a5=Math.round(bb.f_percentage*10*a6)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",a4,"f_amount",a5)}}}}function v(){var i,a3,a2=d.brew_fermenter_sg;if(a2<=1.0001&&d.fg>1){a2=d.fg}else{if(a2<=1.0001){a2=d.est_og}}i=sg_to_plato(a2);a3=d.brew_fermenter_volume;if(a3<=0){a3=d.batch_size-d.eq_trub_chiller_loss}return x*a3*i}function K(a3,a5,a2,a4){var i;if(a2==1){i=0.15}else{if(a3>50){i=0.1}else{i=15.25/(6*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((a3-21)/6,2));if(i<0.1){i=0.1}}}return(i*a4*1000)/a5}function h(a3,a5,a2,a4){var i=0;if(a2==5){i=1.33}else{if(a3>20){i=0}else{if(a3>7.5){i=10.03/(4*Math.sqrt(2*Math.PI))*Math.exp(-0.5*Math.pow((a3-7.5)/4,2))}else{if(a2==2){i=1}else{if(a2==3){i=1.2}else{if(a2==4){i=1.2}}}}}}return(i*a4*1000)/a5}function ar(){var a3=0,a2=0,a5={},a4,a6;U=aX=0;if(!(a5=$("#hopGrid").jqxGrid("getrows"))){return}aa=1;for(a4=0;a4<a5.length;a4++){a6=a5[a4];a3+=toIBU(a6.h_useat,a6.h_form,ak,parseFloat(d.batch_size),parseFloat(a6.h_amount),parseFloat(a6.h_time),parseFloat(a6.h_alpha),d.ibu_method);a2+=toIBU(a6.h_useat,a6.h_form,ak,parseFloat(d.brew_fermenter_volume)+parseFloat(d.brew_fermenter_tcloss),parseFloat(a6.h_amount),parseFloat(a6.h_time),parseFloat(a6.h_alpha),d.ibu_method);aX+=K(parseFloat(a6.h_time),parseFloat(d.batch_size),a6.h_useat,parseFloat(a6.h_amount));U+=h(parseFloat(a6.h_time),parseFloat(d.batch_size),a6.h_useat,parseFloat(a6.h_amount));if((((d.inventory_reduced<=2)&&(a6.h_useat<=4))||((d.inventory_reduced<=6)&&(a6.h_useat==5)))&&(a6.h_inventory<a6.h_amount)){aa=0}}a3=Math.round(a3*10)/10;a2=Math.round(a2*10)/10;aX=Math.round(aX*1000/5)/10;U=Math.round(U*1000/6)/10;if(aX>100){aX=100}if(U>100){U=100}console.log("calcIBUs(): "+a3+" flavour: "+aX+" aroma: "+U+" fermenter:"+a2+" supplies:"+aa);d.est_ibu=a3;$("#est_ibu").val(a3);$("#est_ibu2").val(a3);$("#hop_flavour").jqxProgressBar("val",aX);$("#hop_aroma").jqxProgressBar("val",U);$("#brew_fermenter_ibu").val(a2);aU();G()}function N(a3,a4,a2){var i=a4/a2;if(i>3.5){return 0}if(a3==2){return 0.4}if(a3==1){return 0.62}if(i<=1.4){return 1.4}return 2.33-(0.67*i)}function aB(a3,a8,a2){var i=2.72715,a9=a2/a3*1000,a4=Round(a9,1),a5=(d.starter_sg-1)*a3*i,a6=N(a8,a2,a5),a7=Round(a5*a6,1),ba=parseFloat(a7)+a2;console.log("svol:"+a3+" start:"+a2+" irate:"+a4+" egrams:"+a5+" grate:"+a6+" ncells:"+a7);return{svol:a3,irate:a4,prate:Round(a9,1),ncells:a7,totcells:ba,growf:Round(a7/a2,2)}}function F(a8,a2,a9){var a7=[20,40,60,80,100,150,200,250,375,500,625,750,875,1000,1250,1500,2000,2500,3000,4000,5000],a3=a7.length,a4=0,a5=0,ba={},a6;if((parseFloat($("#prop1_volume").jqxNumberInput("decimal"))+parseFloat($("#prop2_volume").jqxNumberInput("decimal"))+parseFloat($("#prop3_volume").jqxNumberInput("decimal"))+parseFloat($("#prop4_volume").jqxNumberInput("decimal")))==0){for(a6=1;a6<5;a6++){$("#prop"+a6+"_type").hide();$("#r"+a6+"_pmpt").show();$("#prop"+a6+"_type").val(a8);$("#prop"+a6+"_volume").hide();$("#prop"+a6+"_volume").val(0);$("#prop"+a6+"_irate").hide();$("#prop"+a6+"_ncells").hide();$("#prop"+a6+"_tcells").hide();$("#prop"+a6+"_growf").hide()}if(a2>a9){return}$("#prop1_type").show();$("#r1_pmpt").hide();$("#prop1_volume").show();$("#prop1_irate").show();$("#prop1_ncells").show();$("#prop1_tcells").show();$("#prop1_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,a2);if(ba.irate<25){a5=a6-1;a4=a7[a5];ba=aB(a4,a8,a2);break}if(ba.totcells>a9||a6==a3){break}}$("#prop1_volume").val(ba.svol/1000);$("#prop1_irate").val(ba.prate);$("#prop1_ncells").val(ba.ncells);$("#prop1_tcells").val(ba.totcells);$("#prop1_growf").val(ba.growf);if(ba.totcells>a9){return}$("#r2_pmpt").hide();$("#prop2_type").val(a8);$("#prop2_type").show();$("#prop2_volume").show();$("#prop2_irate").show();$("#prop2_ncells").show();$("#prop2_tcells").show();$("#prop2_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,$("#prop1_tcells").val());if(ba.irate<25){a5=a6-1;a4=a7[a5];ba=aB(a4,a8,$("#prop1_tcells").val());break}if(ba.totcells>a9||a6==a3){break}}$("#prop2_volume").val(ba.svol/1000);$("#prop2_irate").val(ba.prate);$("#prop2_ncells").val(ba.ncells);$("#prop2_tcells").val(ba.totcells);$("#prop2_growf").val(ba.growf);if(ba.totcells>a9){return}$("#r3_pmpt").hide();$("#prop3_type").val(a8);$("#prop3_type").show();$("#prop3_volume").show();$("#prop3_irate").show();$("#prop3_ncells").show();$("#prop3_tcells").show();$("#prop3_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,$("#prop2_tcells").val());if(ba.irate<25){a5=a6-1;a4=a7[a5];ba=aB(a4,a8,$("#prop2_tcells").val());break}if(ba.totcells>a9||a6==a3){break}}$("#prop3_volume").val(ba.svol/1000);$("#prop3_irate").val(ba.prate);$("#prop3_ncells").val(ba.ncells);$("#prop3_tcells").val(ba.totcells);$("#prop3_growf").val(ba.growf);if(ba.totcells>a9){return}$("#r4_pmpt").hide();$("#prop4_type").val(a8);$("#prop4_type").show();$("#prop4_volume").show();$("#prop4_irate").show();$("#prop4_ncells").show();$("#prop4_tcells").show();$("#prop4_growf").show();for(a6=a5;a6<=a3;a6++){a5=a6;a4=a7[a5];ba=aB(a4,a8,$("#prop3_tcells").val());if(ba.totcells>a9||a6==a3){$("#prop4_volume").val(ba.svol/1000);$("#prop4_irate").val(ba.prate);$("#prop4_ncells").val(ba.ncells);$("#prop4_tcells").val(ba.totcells);$("#prop4_growf").val(ba.growf);return}}}else{if(d.prop1_volume>0){$("#r1_pmpt").hide();$("#prop1_type").show();$("#prop1_volume").show();$("#prop1_irate").show();$("#prop1_ncells").show();$("#prop1_tcells").show();$("#prop1_growf").show();ba=aB($("#prop1_volume").val()*1000,d.prop1_type,a2);$("#prop1_irate").val(ba.prate);$("#prop1_ncells").val(ba.ncells);$("#prop1_tcells").val(ba.totcells);$("#prop1_growf").val(ba.growf)}if(d.prop2_volume>0){$("#r2_pmpt").hide();$("#prop2_type").show();$("#prop2_volume").show();$("#prop2_irate").show();$("#prop2_ncells").show();$("#prop2_tcells").show();$("#prop2_growf").show();ba=aB($("#prop2_volume").val()*1000,d.prop2_type,$("#prop1_tcells").val());$("#prop2_irate").val(ba.prate);$("#prop2_ncells").val(ba.ncells);$("#prop2_tcells").val(ba.totcells);$("#prop2_growf").val(ba.growf)}if(d.prop3_volume>0){$("#r3_pmpt").hide();$("#prop3_type").show();$("#prop3_volume").show();$("#prop3_irate").show();$("#prop3_ncells").show();$("#prop3_tcells").show();$("#prop3_growf").show();ba=aB($("#prop3_volume").val()*1000,d.prop3_type,$("#prop2_tcells").val());$("#prop3_irate").val(ba.prate);$("#prop3_ncells").val(ba.ncells);$("#prop3_tcells").val(ba.totcells);$("#prop3_growf").val(ba.growf)}if(d.prop4_volume>0){$("#r4_pmpt").hide();$("#prop4_type").show();$("#prop4_volume").show();$("#prop4_irate").show();$("#prop4_ncells").show();$("#prop4_tcells").show();$("#prop4_growf").show();ba=aB($("#prop4_volume").val()*1000,d.prop4_type,$("#prop3_tcells").val());$("#prop4_irate").val(ba.prate);$("#prop4_ncells").val(ba.ncells);$("#prop4_tcells").val(ba.totcells);$("#prop4_growf").val(ba.growf)}}}function X(){var ba,a3,a9,a5,a8,a2,a7,a6,a4=d.brew_fermenter_sg;if(a4<=1.0001&&d.fg>1){a4=d.fg}else{if(a4<=1.0001){a4=d.est_og}}ba=sg_to_plato(a4);a3=d.brew_fermenter_volume;if(a3>0){if(d.brew_fermenter_extrawater>0){a3+=d.brew_fermenter_extrawater}}else{a3=d.batch_size-d.eq_trub_chiller_loss}$("#yeast_cells").val(Z);if(!(a9=$("#yeastGrid").jqxGrid("getrows"))){return}a5=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(a5==0){return}for(a2=0;a2<a5;a2++){a8=$("#yeastGrid").jqxGrid("getrowdata",a2);if(a8.y_use==0){x=0.75;if(d.est_og>1.06){x=1}if(a8.y_type==0){x*=2}}}a7=x*a3*ba;console.log("calcYeast() pitchrate:"+x+" start:"+Z+" needed:"+a7+" volume:"+a3);$("#need_cells").val(a7);a6=Z;if(d.starter_enable){F(d.starter_type,Z,a7);for(a2=1;a2<5;a2++){$("#r"+a2+"_irate").html("");$("#r"+a2+"_growf").html("");$("#r"+a2+"_tcells").html("");if(parseFloat($("#prop"+a2+"_volume").val())>0){if((parseFloat($("#prop"+a2+"_irate").val())<25)||(parseFloat($("#prop"+a2+"_irate").val())>100)){$("#r"+a2+"_irate").html("<img src='images/dialog-error.png'>")}else{$("#r"+a2+"_irate").html("<img src='images/dialog-ok-apply.png'>")}if(parseFloat($("#prop"+a2+"_growf").val())<1){$("#r"+a2+"_growf").html("<img src='images/dialog-error.png'>")}if(($("#prop"+a2+"_type").val()>0)&&(parseFloat($("#prop"+a2+"_growf").val())>3)){$("#r"+a2+"_growf").html("<img src='images/dialog-error.png'>")}if(parseFloat($("#prop"+a2+"_tcells").val())>a7){$("#r"+a2+"_tcells").html("<img src='images/dialog-ok-apply.png'>")}a6=parseFloat($("#prop"+a2+"_tcells").val())}else{$("#r"+a2+"_irate").html("")}}}$("#plato_cells").val(parseFloat(a6/(a3*ba)))}function ai(a4){console.log("adjustHops("+a4+")");var a5,a3,a2,a6=$("#hopGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}for(a3=0;a3<a6;a3++){a5=$("#hopGrid").jqxGrid("getrowdata",a3);a2=a5.h_amount*a4;$("#hopGrid").jqxGrid("setcellvalue",a3,"h_amount",a2)}}function aF(){ah=1;var a3,a2,a4=$("#miscGrid").jqxGrid("getdatainformation").rowscount;if(a4==0){return}for(a2=0;a2<a4;a2++){a3=$("#miscGrid").jqxGrid("getrowdata",a2);if((((d.inventory_reduced<=2)&&(a3.m_use_use<=2))||((d.inventory_reduced<=3)&&(a3.m_use_use==3))||((d.inventory_reduced<=5)&&(a3.m_use_use==4))||((d.inventory_reduced<=6)&&(a3.m_use_use==5)))&&(a3.m_inventory<a3.m_amount)){ah=0}}G()}function a1(a4){console.log("adjustMiscs("+a4+")");var a5,a3,a2,a6=$("#miscGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}for(a3=0;a3<a6;a3++){a5=$("#miscGrid").jqxGrid("getrowdata",a3);a2=a5.m_amount*a4;$("#miscGrid").jqxGrid("setcellvalue",a3,"m_amount",a2);switch(a5.m_name){case"CaCl2":$("#wa_cacl2").val(a5.m_amount*1000);break;case"CaSO4":$("#wa_caso4").val(a5.m_amount*1000);break;case"MgSO4":$("#wa_mgso4").val(a5.m_amount*1000);break;case"NaCl":$("#wa_nacl").val(a5.m_amount*1000);break;case"Melkzuur":case"Zoutzuur":case"Fosforzuur":case"Zwavelzuur":$("#wa_acid").val(a5.m_amount*1000);break;case"NaHCO3":case"Na2CO3":case"CaCO3":case"Ca(OH)2":$("#wa_base").val(a5.m_amount*1000);break}}}function aO(a4){console.log("adjustYeasts("+a4+")");var a5,a3,a2,a6=$("#yeastGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}for(a3=0;a3<a6;a3++){a5=$("#yeastGrid").jqxGrid("getrowdata",a3);if(a5.y_form==1){a2=a5.y_amount*a4;$("#yeastGrid").jqxGrid("setcellvalue",a3,"y_amount",a2)}}X()}function at(a4){console.log("adjustWaters("+a4+")");var a3,a5,a2,a6=$("#mashGrid").jqxGrid("getdatainformation").rowscount;if(a6==0){return}C=0;for(a2=0;a2<a6;a2++){a5=$("#mashGrid").jqxGrid("getrowdata",a2);if(a5.step_type==0){a3=Round(a5.step_infuse_amount*a4,1);$("#mashGrid").jqxGrid("setcellvalue",a2,"step_infuse_amount",a3);C+=a3}}if(d.w2_amount==0){d.w1_amount=C;$("#w1_amount").val(C)}else{d.w1_amount=(d.w1_amount/(d.w1_amount+d.w2_amount))*C;d.w2_amount=(d.w2_amount/(d.w1_amount+d.w2_amount))*C;$("#w1_amount").val(d.w1_amount);$("#w2_amount").val(d.w2_amount)}$("#wg_amount").val(C)}function aZ(){var a2,i;if(parseFloat($("#brew_mash_sg").jqxNumberInput("decimal"))<1.002){return}a2=sg_to_plato(a0);i=sg_to_plato(parseFloat($("#brew_mash_sg").jqxNumberInput("decimal")));if(a2>0.5){$("#brew_mash_efficiency").val(100*i/a2)}else{$("#brew_mash_efficiency").val(0)}}function w(){var a3=0,a6={},a5,a7,a4,a2=0;if(!(a6=$("#fermentableGrid").jqxGrid("getrows"))){return}for(a5=0;a5<a6.length;a5++){a7=a6[a5];if(a7.f_added==0){a3+=a7.f_amount*(a7.f_yield/100)*(1-a7.f_moisture/100)}}a4=sg_to_plato(d.brew_preboil_sg)*(d.brew_preboil_volume/1.04)*d.brew_preboil_sg*10/1000;if(a3>0){a2=Round((a4/a3*100),1)}if(a2<0){a2=0}$("#brew_preboil_efficiency").val(a2)}function R(){var a4=0,a3=0,a7={},a6,a8,a5,a2=0;if(!(a7=$("#fermentableGrid").jqxGrid("getrows"))){return}for(a6=0;a6<a7.length;a6++){a8=a7[a6];if(a8.f_added==0){a4+=a8.f_amount*(a8.f_yield/100)*(1-a8.f_moisture/100)}else{if(a8.f_added==1){a3+=a8.f_amount*(a8.f_yield/100)*(1-a8.f_moisture/100)}}}a5=sg_to_plato(d.brew_aboil_sg)*(d.brew_aboil_volume/1.04)*d.brew_aboil_sg*10/1000;a5-=a3;if(a4>0){a2=Round((a5/a4*100),1)}if(a2<0){a2=0}d.brew_aboil_efficiency=a2;$("#brew_aboil_efficiency").val(a2)}function Q(){var i=(d.est_og-1)*1000;if(i>0){return d.est_ibu/i}else{return 0.5}}function k(){var i=Q();return(-1.2*i+1.4)}function aA(a2,a4){var a8,a3,a9,a7=false,a5,a6=$("#miscGrid").jqxGrid("getrows");if(a4==0){for(a3=0;a3<a6.length;a3++){a8=a6[a3];if(a8.m_name==a2){a9=$("#miscGrid").jqxGrid("getrowid",a3);$("#miscGrid").jqxGrid("deleterow",a9)}}}else{for(a3=0;a3<a6.length;a3++){a8=a6[a3];if(a8.m_name==a2){a7=true;$("#miscGrid").jqxGrid("setcellvalue",a3,"m_amount",a4/1000);break}}if(!a7){a5=new $.jqx.dataAdapter(miscInvSource,{loadComplete:function(){var ba,bc,bd={},bb=a5.records;for(bc=0;bc<bb.length;bc++){ba=bb[bc];if(ba.name==a2){bd.m_name=ba.name;bd.m_amount=a4/1000;bd.m_cost=ba.cost;bd.m_type=ba.type;bd.m_use_use=ba.use_use;bd.m_time=0;bd.m_amount_is_weight=ba.amount_is_weight;bd.m_inventory=ba.inventory;bd.m_avail=1;$("#miscGrid").jqxGrid("addrow",null,bd)}}}});a5.dataBind();return}}}function m(a2,i){if((i=="laag")||(i=="hoog")){$("#wr_"+a2).html("<img src='images/dialog-error.png'><span style='vertical-align: top; font-size: 10px; font-style: italic;'>"+i+"</span>")}else{$("#wr_"+a2).html("<img src='images/dialog-ok-apply.png'>")}}function aP(a4,a3,a2,i){if((a4+a3)>0){return((a4*a2)+(a3*i))/(a4+a3)}return 0}function aq(a3,a2,i){return a3-(a2/1.4+i/1.7)}function z(a2){var i=Math.pow(10,-a2);return 100*az*ax/(i*i+i*az+az*ax)}function ay(a2){var i=Math.pow(10,-a2);return 100*az*i/(i*i+i*az+az*ax)}function aw(i){return(-2*z(i)-ay(i))}function J(a2){var a5=aw(4.3),a3=aw(parseFloat($("#wg_ph").jqxNumberInput("decimal"))),i=aw(a2),a7=-a5+a3,a6=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))/50/a7,a4=-i+a3;return a6*a4}function al(a2){var a3,a4,i=parseFloat($("#wg_calcium").jqxNumberInput("decimal"))/(A/2);a3=parseFloat($("#wg_magnesium").jqxNumberInput("decimal"))/(ap/2);a4=J(a2);return a4-(i/3.5+a3/7)}function L(a4){var a7,a5,a6,a3,a2,a8=al(a4)*parseFloat($("#wg_amount").jqxNumberInput("decimal"));a7=$("#fermentableGrid").jqxGrid("getrows");for(a5=0;a5<a7.length;a5++){row=a7[a5];if(row.f_added==0&&row.f_graintype!=6){a6=0;if((row.f_di_ph!=5.7)&&((row.f_acid_to_ph_57<-0.1)||(row.f_acid_to_ph_57>0.1))){a6=row.f_acid_to_ph_57/(row.f_di_ph-5.7)}else{a3=row.f_color;switch(row.f_graintype){case 0:case 3:case 5:a6=0.014*a3-34.192;break;case 2:a6=-0.0597*a3-32.457;break;case 1:a6=0.0107*a3-54.768;break;case 4:a6=-149;break}}a2=a6*(a4-row.f_di_ph);a8+=a2*row.f_amount}}return a8}function aM(){var a5=0,a3=5.4,a2=0.001,a4=0.1,i=L(a3);while(((i<-a4)||(i>a4))&&(a5<2000)){a5++;if(i<-a4){a3-=a2}else{if(i>a4){a3+=a2}}i=L(a3)}console.log("MashpH() n: "+a5+" pH: "+a3);return a3}function t(i){switch(i){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}}}function P(){console.log("calcWater()");var bj=0,by=0,a9=0,bk=0,ba=0,bv=0,bb=0,bt=0,bd=0,bm=0,bE=0,bC=0,bz=0,bx,bn,bf,a4,a3,i,be,a6,a5,bp,bh,a8,bq,bi,bw,bo,bg,br,bD,bs,bc,bA,bl,bB,a7,bu,a2;if(d.w1_name==""){return}if(d.w2_name!=""){bj=d.w1_amount+d.w2_amount;by=aP(d.w1_amount,d.w2_amount,d.w1_calcium,d.w2_calcium);a9=aP(d.w1_amount,d.w2_amount,d.w1_magnesium,d.w2_magnesium);bk=aP(d.w1_amount,d.w2_amount,d.w1_sodium,d.w2_sodium);bb=aP(d.w1_amount,d.w2_amount,d.w1_chloride,d.w2_chloride);bt=aP(d.w1_amount,d.w2_amount,d.w1_sulfate,d.w2_sulfate);ba=aP(d.w1_amount,d.w2_amount,d.w1_total_alkalinity,d.w2_total_alkalinity);bd=-Math.log10(((Math.pow(10,-d.w1_ph)*d.w1_amount)+(Math.pow(10,-d.w2_ph)*d.w2_amount))/bj)}else{bj=d.w1_amount;by=d.w1_calcium;a9=d.w1_magnesium;bk=d.w1_sodium;bb=d.w1_chloride;bt=d.w1_sulfate;ba=d.w1_total_alkalinity;bd=d.w1_ph}$("#wg_amount").val(bj);bA=by;$("#wg_calcium").val(Math.round(by*10)/10);$("#wg_magnesium").val(Math.round(a9*10)/10);bl=bk;$("#wg_sodium").val(Math.round(bk*10)/10);bB=ba;$("#wg_total_alkalinity").val(Math.round(ba*10)/10);a7=bb;$("#wg_chloride").val(Math.round(bb*10)/10);bu=bt;$("#wg_sulfate").val(Math.round(bt*10)/10);$("#wg_ph").val(Round(bd,1));$("#wb_ph").val(Round(aM(),1));$("#est_mash_ph").val(Round(aM(),1));bv=ba*1.22;a2=bv;bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am;by+=1000*bm/bj;bm=parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*ap/aJ;a9+=1000*bm/bj;bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*ac/aE;bk+=1000*bm/bj;bm=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*aH/am+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*aH/aJ;bt+=1000*bm/bj;bm=2*parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*q/S+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*q/b;bb+=1000*bm/bj;if($("#wa_acid_name").val()<0||$("#wa_acid_name").val()>3){$("#wa_acid_name").val(0);d.wa_acid_name=0}if(af==""){af=AcidTypeData[$("#wa_acid_name").val()].nl}if($("#wa_base_name").val()<0||$("#wa_base_name").val()>3){$("#wa_base_name").val(0);d.wa_base_name=0}if(aT==""){aT=BaseTypeData[$("#wa_base_name").val()].nl}bx=d.wa_acid_name;bn=d.wa_base_name;bf=t(bx);a4=bf.pK1;a3=bf.pK2;i=bf.pK3;be=bf.MolWt;a6=bf.AcidSG;a5=bf.AcidPrc;if(d.calc_acid){bC=parseFloat(d.mash_ph);bz=L(bC);console.log("calc_acid tgt: "+bC+" protonDeficit: "+bz);if(bz>0){$("#wa_base").val(0);aA(aT,0);bE=CalcFrac(bC,a4,a3,i);Acid=bz/bE;Acid*=be;Acidmg=Acid;Acid=Acid/a6;if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(a5)}Acid=Acid*a5/(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);console.log("Final ml: "+Acid);$("#wa_acid").val(Round(Acid,2));aA(AcidTypeData[bx].nl,Round(Acid,2));bv=bv-bz*bE/bj;ba=bv*50/61}else{if(bz<0){$("#wa_acid").val(0);aA(af,0);bp=Math.pow(10,(bC-6.38));bh=Math.pow(10,(bC-10.38));a8=1/(1+bp+bp*bh);bq=a8*bp;bi=bq*bh;switch(bn){case 0:bm=-bz/(a8-bi);bm=bm*aE/1000;$("#wa_base").val(Round(bm,2));aA("NaHCO3",Round(bm,2));if(bj>0){bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*ac/aE;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/aE;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 1:bm=-bz/(2*a8+bq);bm=bm*y/1000;$("#wa_base").val(Round(bm,2));aA("Na2CO3",Round(bm,2));if(bj>0){bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*ac/y;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/y;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 2:bm=-bz*(a8-bi);bm=bm*g/1000;bm=3*bm;$("#wa_base").val(Round(bm,2));aA("CaCO3",Round(bm,2));if(bj>0){bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*r/g;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am+parseFloat($("#wa_base").jqxNumberInput("decimal"))*A/g;bm=1000*bm/bj;by=bA+bm;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break;case 3:bm=-bz/19.3;$("#wa_base").val(Round(bm,2));aA("Ca(OH)2",Round(bm,2));if(bj>0){bm=-bz/bj;ba=bB+bm;bv=ba*61/50;bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am+parseFloat($("#wa_base").jqxNumberInput("decimal"))*A/aI;bm=1000*bm/bj;by=bA+bm;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium)}break}}}bd=bC;$("#wb_ph").val(Round(bd,1));$("#est_mash_ph").val(Round(bd,1))}else{console.log("calc_acid no");if(parseFloat($("#wa_base").jqxNumberInput("decimal"))>0){if(bj>0){switch(bn){case 0:bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*ac/aE;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/aE;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 1:bm=parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*ac/b+parseFloat($("#wa_base").jqxNumberInput("decimal"))*2*ac/y;bm=1000*bm/bj;bk=bl+bm;bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))*r/y;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium);break;case 2:bm=parseFloat($("#wa_base").jqxNumberInput("decimal"))/3*r/g;bm=1000*bm/bj;bv=a2+bm;ba=bv*50/61;bm=aq(wb_total_alkalinity,wb_calcium,wb_magnesium);bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*A/S+parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*A/am+parseFloat($("#wa_base").jqxNumberInput("decimal"))*A/g;bm=1000*bm/bj;by=bA+bm;break}}}bC=parseFloat(d.mash_ph);pHa=aM();if(parseFloat($("#wa_acid").jqxNumberInput("decimal"))>0){console.log("TpH: "+bC+" water: "+pHa);Acid=parseFloat($("#wa_acid").jqxNumberInput("decimal"));if(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))==0){$("#wa_acid_perc").val(a5)}Acid=Acid/a5*(parseFloat($("#wa_acid_perc").jqxNumberInput("decimal"))/100);Acid*=a6;Acid/=be;Acidmg=Acid;bE=CalcFrac(pHa,a4,a3,i);bz=Acid*bE;bw=0.001;bo=0.1;bg=L(pHa);br=0;while(((bg<(bz-bo))||(bg>(bz+bo)))&&(br<2000)){br++;if(bg<(bz-bo)){pHa-=bw}else{if(bg>(bz+bo)){pHa+=bw}}bE=CalcFrac(pHa,a4,a3,i);bz=Acid*bE;bg=L(pHa)}console.log("n: "+br+" pd: "+bg+" protonDeficit: "+bz+" frac: "+bE+" pHa: "+pHa);bm=a2-bz*bE/bj;bv=bm;ba=bm*50/61;bd=pHa;$("#wb_ph").val(Round(bd,1));$("#est_mash_ph").val(Round(bd,1))}}if((bx==3)&&(bj>0)){bm=parseFloat($("#wa_caso4").jqxNumberInput("decimal"))*aH/am+parseFloat($("#wa_mgso4").jqxNumberInput("decimal"))*aH/aJ+Acidmg/1000*aH/(aH+2);bm=1000*bm/bj;bt=bu+bm}else{if((bx==1)&&(bj>0)){bm=parseFloat($("#wa_cacl2").jqxNumberInput("decimal"))*q/S+parseFloat($("#wa_nacl").jqxNumberInput("decimal"))*q/b+Acidmg/1000*q/(q+1);bm=1000*bm/bj;bb=a7+bm}}$("#tgt_bu").val(Round(Q(),2));if(Q()<0.32){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Zeer moutig en zoet</span>")}else{if(Q()<0.43){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Moutig, zoet</span>")}else{if(Q()<0.52){$("#wr_bu").html("<span style='vertical-align: top; font-size: 14px; font-style: italic;'>Evenwichtig</span>")}else{if(Q()<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(Round(k(),1));if(bt>0){bm=bb/bt}else{bm=10}$("#got_cl_so4").val(Round(bm,1));bD=0.8*k();bs=1.2*k();bc="normaal";if(bm<bD){bc="laag"}else{if(bm>bs){bc="hoog"}}m("cl_so4",bc);$("#wb_calcium").val(Round(by,1));$("#wb_magnesium").val(Round(a9,1));$("#wb_sodium").val(Round(bk,1));$("#wb_sulfate").val(Round(bt,1));$("#wb_chloride").val(Round(bb,1));$("#wb_total_alkalinity").val(Round(ba,1));if(by<40){m("calcium","laag")}else{if(by>150){m("calcium","hoog")}else{m("calcium","normaal")}}if(a9>=0&&a9<=30){m("magnesium","normaal")}else{m("magnesium","hoog")}if(bk<=150){m("sodium","normaal")}else{m("sodium","hoog")}if(bb<=50){m("chloride","laag")}else{if(bb<=100){m("chloride","normaal")}else{m("chloride","hoog")}}if(bt<=50){m("sulfate","laag")}else{if(bt<=350){m("sulfate","normaal")}else{m("sulfate","hoog")}}if(bd<5.2){m("ph","laag")}else{if(bd>5.6){m("ph","hoog")}else{m("ph","normaal")}}j();aF();G()}function j(){var a4,bg,be,bm,bl,bp,bj,bi,bk,a7,bu,bs,a2,a6,a9,bf,bq,bo,br,bh,a3,a8,bd,bc,bb,ba,bt,a5,i,bn;a4=d.sparge_ph;bg=d.w1_ph;be=d.w1_total_alkalinity;if(d.sparge_source==1){if(d.w2_ph>0){bg=d.w2_ph;be=d.w2_total_alkalinity}else{d.sparge_source=0;$("#sparge_source").val(0)}}else{if(d.sparge_source==2){if(d.w2_ph>0){bg=parseFloat($("#wg_ph").jqxNumberInput("decimal"));be=parseFloat($("#wg_total_alkalinity").jqxNumberInput("decimal"))}else{d.sparge_source=0;$("#sparge_source").val(0)}}}bm=Math.pow(10,bg-6.38);bl=Math.pow(10,bg-10.373);bp=1+bm+bm*bl;bj=1/bp;bi=bm*bl/bp;bk=Math.pow(10,4.3-6.38);a7=Math.pow(10,4.3-10.373);bu=1+bk+bk*a7;bs=1/bu;a2=bk*a7/bu;a6=be/50;a9=(a6-1000*(Math.pow(10,-4.3)-Math.pow(10,-bg)))/((bs-bj)+(bi-a2));bf=Math.pow(10,a4-6.38);bq=Math.pow(10,a4-10.373);bo=1+bf+bf*bq;br=1/bo;bh=bf*bq/bo;a3=a9*((br-bj)+(bi-bh))+Math.pow(10,-a4)-Math.pow(10,-bg);a3+=0.01;if(d.sparge_acid_type<0||d.sparge_acid_type>3){d.sparge_acid_type=0;$("#sparge_acid_type").val(0)}a8=d.sparge_acid_type;bd=t(a8);bc=bd.pK1;bb=bd.pK2;ba=bd.pK3;bt=bd.MolWt;a5=bd.AcidSG;i=bd.AcidPrc;bn=CalcFrac(a4,bc,bb,ba);a3/=bn;a3*=bt;a3=a3/a5;bj=d.sparge_acid_perc;if(bj<=0.1){bj=i}a3=a3*i/(bj/100);a3*=d.sparge_volume;a3=Round(a3,2);d.sparge_acid_amount=a3/1000;$("#sparge_acid_amount").val(a3)}function M(){var a2,i,a4,a3;if(d.brew_fermenter_sg<1.02){return}if((d.primary_end_sg>0.99)&&(d.primary_end_sg<d.brew_fermenter_sg)){a2=Round(100*(d.brew_fermenter_sg-d.primary_end_sg)/(d.brew_fermenter_sg-1),1);$("#primary_svg").val(a2);if((d.secondary_end_sg>0.99)&&(d.secondary_end_sg<d.brew_fermenter_sg)){i=Round(100*(d.brew_fermenter_sg-d.secondary_end_sg)/(d.brew_fermenter_sg-1),1);$("#secondary_svg").val(i);if((d.fg>0.99)&&(d.fg<d.brew_fermenter_sg)){a4=Round(100*(d.brew_fermenter_sg-d.fg)/(d.brew_fermenter_sg-1),1);$("#final_svg").val(a4);a3=Round(abvol(d.brew_fermenter_sg,d.fg),2);$("#final_abv").val(a3)}}}}function an(a2,i){var a3=i*1.8+32;return 3.0378-0.050062*a3+0.00026555*a3*a3}function V(a2,i,a4){var a3=a4*(a2-an(a2,i))/0.286;if(a3<0){a3=0}return Round(a3,3)}function o(a2,a5,a4){var a3,i=a2-an(a2,a5);if(i<0){return 0}a3=-1.09145427669121+0.00800006989646477*a4+0.000260276315484684*a4*a4+0.0215142075945119*a4*i+0.674996600795854*i+-0.00471757220150754*i*i;if(a3<0){a3=0}a3=a3*1.01325;return Round(a3,1)}function Y(a2,i){return(a2-(-0.000005594056*Math.pow(i,4)+0.000144357886*Math.pow(i,3)+0.000362999168*i*i-0.064872987645*i+1.641145175049))/(0.00000498031*Math.pow(i,4)-0.00024358267*Math.pow(i,3)+0.00385867329*i*i-0.05671206825*i+1.53801423376)}function aR(){var a9,a6,ba,a8,a4,be,bb,a2,bg,a5,bh,bd,a3,a7,bc,bf;a9=d.secondary_temp;if(a9<1){a9=d.primary_end_temp}if(a9<1){a9=18}if(d.fg==0){a6=abvol(d.brew_fermenter_sg,parseFloat($("#est_fg").jqxNumberInput("decimal")))}else{a6=abvol(d.brew_fermenter_sg,d.fg)}ba=d.package_volume-(a6*d.package_volume)/100;a8=d.package_volume-ba;be=d.package_infuse_amount-(d.package_infuse_abv*d.package_infuse_amount)/100;bb=d.package_infuse_amount-be;bg=a8+bb;a2=ba+be;a6=Round(bg/(a2+bg)*100,2);d.package_abv=a6;$("#package_abv").val(a6);if(!(rows=$("#fermentableGrid").jqxGrid("getrows"))){return}d.bottle_priming_amount=0;d.bottle_priming_total=0;for(a5=0;a5<rows.length;a5++){bh=rows[a5];if(bh.f_added==4){bd=1/((bh.f_yield/100)*(1-bh.f_moisture/100));d.bottle_priming_amount=V(d.bottle_carbonation,a9,bd);d.bottle_priming_total=Round(d.bottle_amount*d.bottle_priming_amount,2);$("#fermentableGrid").jqxGrid("setcellvalue",a5,"f_amount",d.bottle_priming_total/1000)}}$("#bottle_priming_amount").val(Round(d.bottle_priming_amount,1));$("#bottle_priming_total").val(d.bottle_priming_total);a7=a6+d.bottle_priming_amount*0.47/7.907;a3=d.bottle_amount-(a7*d.bottle_amount)/100;bg=d.bottle_amount-a3;a2=a3+d.bottle_priming_water;a4=Round(bg/(a2+bg)*100,2);$("#bottle_abv").val(a4);$("#bottle_pressure").val(o(d.bottle_carbonation,a9,d.bottle_carbonation_temp));bc=Y(d.keg_carbonation,d.keg_carbonation_temp);if(bc<0){bc=0}d.keg_pressure=bc;$("#keg_pressure").val(Round(bc,1));d.keg_priming_amount=0;d.keg_priming_total=0;if(!d.keg_forced_carb){for(a5=0;a5<rows.length;a5++){bh=rows[a5];if(bh.f_added==5){bd=1/((bh.f_yield/100)*(1-bh.f_moisture/100));d.keg_priming_amount=V(d.keg_carbonation,a9,bd);d.keg_priming_total=Round(d.keg_amount*d.keg_priming_amount,2);$("#fermentableGrid").jqxGrid("setcellvalue",a5,"f_amount",d.keg_priming_total/1000)}}$("#keg_priming_amount").val(Round(d.keg_priming_amount,1));$("#keg_priming_total").val(d.keg_priming_total);a7=a6+d.keg_priming_amount*0.47/7.907;a3=d.keg_amount-(a7*d.keg_amount)/100;bg=d.keg_amount-a3;a2=a3+d.keg_priming_water;bf=Round(bg/(a2+bg)*100,2);$("#keg_abv").val(bf)}else{$("#keg_priming_amount").val(0);$("#keg_priming_total").val(0);$("#keg_abv").val(a6)}}function aU(){var a7=d.stage,a6,a4,a2,a8,a5,i,a3;if(a7==0&&d.est_og>1.005&&d.est_color>3&&d.est_ibu>3){a7=1}if(a7==1&&parseFloat($("#brew_date_start").val())>2000){a7=2}if(a7==2&&($("#brew_date_start").val()=="")){a7=1}if(a7==2&&parseFloat($("#brew_date_end").val())>2000){a7=3}if(a7==3&&parseFloat($("#primary_end_date").val())>2000){a7=4}if(a7==4&&parseFloat($("#secondary_end_date").val())>2000){a7=5}if(a7==5&&parseFloat($("#package_date").val())>2000){a7=6}if(a7>=6&&a7<9){a6=new Date();a2=$("#package_date").val();a2=a2.split("-");a4=new Date(a6.getFullYear(),a6.getMonth(),a6.getDate());a2=new Date(a2[0],a2[1]-1,a2[2]);a8=parseInt(a4.getTime()/1000);a5=parseInt(a2.getTime()/1000);i=a8-a5;a3=i/60/60/24;if(a3>0){if(a3>=42){a7=9}else{if(a3>=14){a7=8}else{a7=7}}}}if(a7==9&&parseFloat($("#taste_date").val())>2000){a7=10}if(a7!=d.stage){console.log("calcStage() old: "+d.stage+" new: "+a7);d.stage=a7}$("#stage").val(StageData[d.stage].nl);if(d.stage>=10){$("#locked").jqxCheckBox({disabled:false})}if(d.stage>1){$("#equipmentSelect").jqxDropDownList({disabled:true});$("#Delete").jqxButton({disabled:true})}if(d.stage<1){$("#jqxTabs").jqxTabs("disableAt",8)}else{$("#jqxTabs").jqxTabs("enableAt",8)}if(d.stage<3){$("#jqxTabs").jqxTabs("disableAt",9)}else{$("#jqxTabs").jqxTabs("enableAt",9);$("#name").jqxInput({disabled:true});$("#code").jqxInput({disabled:true});$("#batch_size").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#boil_size").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#boil_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#efficiency").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#est_og").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#type").jqxDropDownList({disabled:true});$("#styleSelect").jqxDropDownList({disabled:true});$("#color_method").jqxDropDownList({disabled:true});$("#ibu_method").jqxDropDownList({disabled:true});$("#mash_select").jqxDropDownList({disabled:true});$("#w1_name").jqxDropDownList({disabled:true});$("#w2_name").jqxDropDownList({disabled:true});$("#w2_amount").jqxNumberInput({readOnly:true});$("#pr_name").jqxDropDownList({disabled:true});$("#wa_cacl2").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_caso4").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_mgso4").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_nacl").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#mash_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#calc_acid").jqxCheckBox({disabled:true});$("#wa_base_name").jqxDropDownList({disabled:true});$("#wa_base").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_acid_name").jqxDropDownList({disabled:true});$("#wa_acid").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wa_acid_perc").jqxNumberInput({spinButtons:false,readOnly:true,width:70});$("#sparge_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#sparge_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#sparge_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#sparge_source").jqxDropDownList({disabled:true});$("#sparge_acid_type").jqxDropDownList({disabled:true});$("#sparge_acid_perc").jqxNumberInput({spinButtons:false,readOnly:true,width:false});$("#starter_enable").jqxCheckBox({disabled:true});$("#starter_type").jqxDropDownList({disabled:true});$("#starter_try").jqxButton({disabled:true});$("#starter_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#starter_viability").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}if(d.stage>3){$("#brew_date_start").jqxDateTimeInput({disabled:true});$("#brew_date_end").jqxDateTimeInput({disabled:true});$("#brew_mash_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_preboil_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aboil_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_mash_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_preboil_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aboil_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_preboil_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aboil_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_whirlpool9").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_cooling_to").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_whirlpool7").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_cooling_method").jqxDropDownList({disabled:true});$("#brew_whirlpool6").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_cooling_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_sparge_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_whirlpool2").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aeration_type").jqxDropDownList({disabled:true});$("#brew_fermenter_tcloss").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aeration_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_fermenter_extrawater").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#brew_aeration_speed").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}if(d.stage==5){$("#package_date").jqxDateTimeInput({disabled:false})}else{$("#package_date").jqxDateTimeInput({disabled:true})}if(d.stage>=5){$("#primary_start_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_max_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_brix").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#primary_end_date").jqxDateTimeInput({disabled:true})}if(d.stage>=6){$("#secondary_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#secondary_end_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#secondary_end_date").jqxDateTimeInput({disabled:true});$("#tertiary_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#fg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#final_brix").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_date").jqxDateTimeInput({disabled:true});$("#package_volume").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_infuse_amount").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_infuse_abv").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#package_infuse_notes").jqxInput({disabled:true});$("#package_ph").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_amount").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_priming_water").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_priming_water").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_amount").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_carbonation").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_carbonation").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#bottle_priming_sugar").jqxDropDownList({disabled:true});$("#keg_priming_sugar").jqxDropDownList({disabled:true});$("#keg_forced_carb").jqxCheckBox({disabled:true});$("#bottle_carbonation_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#keg_carbonation_temp").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}if(d.stage<8){$("#jqxTabs").jqxTabs("disableAt",11)}else{$("#jqxTabs").jqxTabs("enableAt",11)}if(d.stage==11){$("#taste_date").jqxDateTimeInput({disabled:true});$("#taste_rate").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#taste_color").jqxInput({disabled:true});$("#taste_transparency").jqxInput({disabled:true});$("#taste_head").jqxInput({disabled:true});$("#taste_aroma").jqxInput({disabled:true});$("#taste_taste").jqxInput({disabled:true});$("#taste_aftertaste").jqxInput({disabled:true});$("#taste_mouthfeel").jqxInput({disabled:true});$("#taste_notes").jqxInput({disabled:true});$("#notes").jqxInput({disabled:true})}else{$("#notes").jqxInput({disabled:false})}}function I(){if(d.starter_enable){$("#propagator").show();$("#starter_type").jqxDropDownList({disabled:false});$("#starter_try").jqxButton({disabled:false});$("#starter_sg").jqxNumberInput({spinButtons:true,readOnly:false,width:110});$("#starter_viability").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}else{$("#propagator").hide();$("#starter_type").jqxDropDownList({disabled:true});$("#starter_try").jqxButton({disabled:true});$("#starter_sg").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#starter_viability").jqxNumberInput({spinButtons:false,readOnly:true,width:90})}}function aW(){console.log("calcInit()");aZ();w();R();$("#starter_enable").on("checked",function(i){d.starter_enable=1;I();X()});$("#starter_enable").on("unchecked",function(i){d.starter_enable=0;I();X()});$("#starter_try").click(function(){$("#prop1_volume").val(0);$("#prop2_volume").val(0);$("#prop3_volume").val(0);$("#prop4_volume").val(0);X()});$("#starter_type").on("change",function(i){if(i.args){d.starter_type=i.args.index;X()}});$("#starter_sg").on("change",function(i){if(i.args){d.starter_sg=i.args.value;X()}});$("#starter_viability").on("change",function(i){if(i.args){d.starter_viability=i.args.value;T();X()}});$("#prop1_type").on("change",function(i){if(i.args){d.prop1_type=i.args.index;X()}});$("#prop1_volume").on("change",function(i){if(i.args){d.prop1_volume=i.args.value;X()}});$("#prop2_type").on("change",function(i){if(i.args){d.prop2_type=i.args.index;X()}});$("#prop2_volume").on("change",function(i){if(i.args){d.prop2_volume=i.args.value;X()}});$("#prop3_type").on("change",function(i){if(i.args){d.prop3_type=i.args.index;X()}});$("#prop3_volume").on("change",function(i){if(i.args){d.prop3_volume=i.args.value;X()}});$("#prop4_type").on("change",function(i){if(i.args){d.prop4_type=i.args.index;X()}});$("#prop4_volume").on("change",function(i){if(i.args){d.prop4_volume=i.args.value;X()}});$("#calc_acid").on("checked",function(i){d.calc_acid=1;P()});$("#calc_acid").on("unchecked",function(i){d.calc_acid=0;P()});$("#w1_name").jqxDropDownList("selectItem",d.w1_name);$("#w2_name").jqxDropDownList("selectItem",d.w2_name);if(parseFloat($("#w1_amount").jqxNumberInput("decimal"))==0&&C>0){$("#w1_amount").val(C);d.w1_amount=C;$("#wg_amount").val(C);$("#w2_amount").val(0);d.w2_amount=0}P();$("#w2_amount").on("change",function(i){var a2=parseFloat(i.args.value);if(a2>C){$("#w2_amount").val(d.w2_amount);return}d.w1_amount=parseFloat($("#wg_amount").jqxNumberInput("decimal"))-a2;$("#w1_amount").val(d.w1_amount);d.w2_amount=a2;console.log("new: "+i.args.value+" w1: "+d.w1_amount+"  w2: "+d.w2_amount);P()});$("#wa_cacl2").on("change",function(i){if(i.args){aA("CaCl2",0);aA("CaCl2",i.args.value);P()}});$("#wa_caso4").on("change",function(i){if(i.args){aA("CaSO4",0);aA("CaSO4",i.args.value);P()}});$("#wa_mgso4").on("change",function(i){if(i.args){aA("MgSO4",0);aA("MgSO4",i.args.value);P()}});$("#wa_nacl").on("change",function(i){if(i.args){aA("NaCl",0);aA("NaCl",i.args.value);P()}});$("#wa_base_name").on("change",function(a2){if(a2.args){var i=a2.args.index;console.log("wa_base_name "+i);aA(aT,0);aT=BaseTypeData[i].nl;aA(aT,parseFloat($("#wa_base").jqxNumberInput("decimal")));d.wa_base_name=i;P()}});$("#wa_base").on("change",function(a2){var i=BaseTypeData[$("#wa_base_name").val()].nl;aA(i,parseFloat(a2.args.value));P()});$("#wa_acid_name").on("change",function(a2){if(a2.args){var i=a2.args.index;console.log("wa_acid_name "+i);aA(af,0);af=AcidTypeData[i].nl;aA(af,parseFloat($("#wa_acid").jqxNumberInput("decimal")));d.wa_acid_name=i;P()}});$("#wa_acid").on("change",function(a2){var i=AcidTypeData[$("#wa_acid_name").val()].nl;aA(i,parseFloat(a2.args.value));P()});$("#wa_acid_perc").on("change",function(i){P()});$("#color_method").on("change",function(i){d.color_method=i.args.index;T()});$("#ibu_method").on("change",function(i){d.ibu_method=i.args.index;T();ar()});$("#batch_size").on("change",function(a3){console.log("batch_size change:"+a3.args.value+" old:"+d.batch_size);$("#est_a_vol").val(a3.args.value*1.04);var i,a2=parseFloat(a3.args.value)+d.boil_size-d.batch_size;i=parseFloat(a3.args.value)/d.batch_size;d.boil_size=a2;$("#boil_size").val(Round(a2,2));$("#est_pre_vol").val(Round(a2*1.04,2));d.sparge_volume*=i;$("#sparge_volume").val(d.sparge_volume);$("#brew_sparge_volume").val(d.sparge_volume);d.batch_size=parseFloat(a3.args.value);ae(parseFloat($("#est_og").jqxNumberInput("decimal")));at(i);T();ai(i);a1(i);aO(i);ar();P();j();aN()});$("#boil_time").on("change",function(a3){console.log("boil_time change:"+parseFloat(a3.args.value)+" old:"+d.boil_time);var a2,i,a4=parseFloat(d.boil_size)-parseFloat(d.batch_size);i=a4*(parseFloat(a3.args.value)/d.boil_time);a2=parseFloat(d.batch_size)+i;d.boil_time=parseFloat(a3.args.value);d.boil_size=a2;$("#est_pre_vol").val(Round(a2*1.04,2));$("#boil_size").val(Round(a2,2));T();ar();X()});$("#efficiency").on("change",function(a2){var i=parseFloat($("#est_og").jqxNumberInput("decimal"));d.efficiency=parseFloat(a2.args.value);console.log("efficiency change:"+d.efficiency+" est_og:"+i);ae(i);T();ar();X()});$("#est_og").on("change",function(i){d.est_og=parseFloat(i.args.value);console.log("est_og change:"+d.est_og);$("#est_og2").val(d.est_og);ae(d.est_og);T();ar();aN();X()});$("#mash_ph").on("change",function(i){d.mash_ph=parseFloat(i.args.value);P()});$("#sparge_ph").on("change",function(i){d.sparge_ph=parseFloat(i.args.value);j()});$("#sparge_volume").on("change",function(i){d.sparge_volume=parseFloat(i.args.value);$("#brew_sparge_volume").val(d.sparge_volume);j()});$("#sparge_temp").on("change",function(i){d.sparge_temp=parseFloat(i.args.value);$("#brew_sparge_temperature").val(d.sparge_temp)});$("#sparge_source").on("change",function(i){if(i.args){d.sparge_source=i.args.index;j()}});$("#sparge_acid_type").on("change",function(i){if(i.args){d.sparge_acid_type=i.args.index;console.log("new sparge_acid_type: "+d.sparge_acid_type);j()}});$("#sparge_acid_perc").on("change",function(i){d.sparge_acid_perc=parseFloat(i.args.value);j()});M();aR();$("#package_volume").on("change",function(a2){var a3,a4,i=d.package_volume+d.package_infuse_amount;d.package_volume=parseFloat(a2.args.value);if(d.package_volume>d.brew_fermenter_volume){d.package_volume=d.brew_fermenter_volume;$("#package_volume").val(d.package_volume)}a4=d.package_volume+d.package_infuse_amount;a3=a4-i;if(i>0){d.bottle_amount+=(d.bottle_amount/i)*a3;d.keg_amount+=(d.keg_amount/i)*a3}else{d.bottle_amount=a4;d.keg_amount=0}console.log("diff:"+a3+" old:"+i+" bottle:"+d.bottle_amount+" keg:"+d.keg_amount);$("#bottle_amount").val(parseFloat(d.bottle_amount*1000)/1000);$("#keg_amount").val(parseFloat(d.keg_amount*1000)/1000);aR()});$("#package_infuse_amount").on("change",function(a2){var a3,a4,i=d.package_volume+d.package_infuse_amount;d.package_infuse_amount=parseFloat(a2.args.value);a4=d.package_volume+d.package_infuse_amount;a3=a4-i;if(i>0){d.bottle_amount+=(d.bottle_amount/i)*a3;d.keg_amount+=(d.keg_amount/i)*a3}else{d.bottle_amount=a4;d.keg_amount=0}console.log("diff:"+a3+" old:"+i+" bottle:"+d.bottle_amount+" keg:"+d.keg_amount);$("#bottle_amount").val(parseFloat(d.bottle_amount*1000)/1000);$("#keg_amount").val(parseFloat(d.keg_amount*1000)/1000);aR()});$("#package_infuse_abv").on("change",function(i){d.package_infuse_abv=parseFloat(i.args.value);aR()});$("#bottle_amount").on("change",function(a3){var i,a4,a2=parseFloat(a3.args.value);i=d.package_volume+d.package_infuse_amount;if(a2>i){a2=i}a4=d.bottle_amount-a2;d.bottle_amount=Math.round((d.bottle_amount-a4)*1000)/1000;d.keg_amount=Math.round((d.keg_amount+a4)*1000)/1000;$("#bottle_amount").val(parseFloat(d.bottle_amount));$("#keg_amount").val(parseFloat(d.keg_amount));aR()});$("#bottle_priming_water").on("change",function(i){d.bottle_priming_water=parseFloat(i.args.value);aR()});$("#keg_amount").on("change",function(a3){var a4,i,a2=parseFloat(a3.args.value);i=d.package_volume+d.package_infuse_amount;if(a2>i){a2=i}a4=d.keg_amount-a2;d.bottle_amount=Math.round((d.bottle_amount+a4)*1000)/1000;d.keg_amount=Math.round((d.keg_amount-a4)*1000)/1000;$("#bottle_amount").val(parseFloat(d.bottle_amount));$("#keg_amount").val(parseFloat(d.keg_amount));aR()});$("#keg_priming_water").on("change",function(i){d.keg_priming_water=parseFloat(i.args.value);aR()});$("#bottle_carbonation").on("change",function(i){d.bottle_carbonation=parseFloat(i.args.value);aR()});$("#bottle_carbonation_temp").on("change",function(i){d.bottle_carbonation_temp=parseFloat(i.args.value);aR()});$("#keg_carbonation").on("change",function(i){d.keg_carbonation=parseFloat(i.args.value);aR()});$("#keg_forced_carb").on("checked",function(i){d.keg_forced_carb=1;aR()});$("#keg_forced_carb").on("unchecked",function(i){d.keg_forced_carb=0;aR()});$("#keg_carbonation_temp").on("change",function(i){d.keg_carbonation_temp=parseFloat(i.args.value);aR()});$("#brew_fermenter_extrawater").on("change",function(i){d.brew_fermenter_extrawater=parseFloat(i.args.value);T();ar();X()});$("#brew_fermenter_tcloss").on("change",function(i){d.brew_fermenter_tcloss=parseFloat(i.args.value);T();ar();X()});$("#primary_end_sg").on("change",function(i){d.primary_end_sg=parseFloat(i.args.value);M()});$("#primary_end_brix").on("change",function(a2){var a3,a4,i;if(d.brew_fermenter_sg>=1.02){a3=sg_to_brix(d.brew_fermenter_sg);a4=parseFloat(a2.args.value);i=Round(1.0031-0.002318474*a3-0.000007775*(a3*a3)-3.4e-8*Math.pow(a3,3)+0.00574*(a4)+0.00003344*(a4*a4)+8.6e-8*Math.pow(a4,3),4);if(a4>0.05){$("#primary_end_sg").val(i);d.primary_end_sg=i}M()}});$("#secondary_end_sg").on("change",function(i){d.secondary_end_sg=parseFloat(i.args.value);M()});$("#secondary_end_brix").on("change",function(a2){var a3,a4,i;if(d.brew_fermenter_sg>=1.02){a3=sg_to_brix(d.brew_fermenter_sg);a4=parseFloat(a2.args.value);i=Round(1.0031-0.002318474*a3-0.000007775*(a3*a3)-3.4e-8*Math.pow(a3,3)+0.00574*(a4)+0.00003344*(a4*a4)+8.6e-8*Math.pow(a4,3),4);if(a4>0.05){$("#secondary_end_sg").val(i);d.secondary_end_sg=i}M()}});$("#final_brix").on("change",function(a2){var a3,a4,i;if(d.brew_fermenter_sg>=1.02){a3=sg_to_brix(d.brew_fermenter_sg);a4=parseFloat(a2.args.value);i=Round(1.0031-0.002318474*a3-0.000007775*(a3*a3)-3.4e-8*Math.pow(a3,3)+0.00574*(a4)+0.00003344*(a4*a4)+8.6e-8*Math.pow(a4,3),4);if(a4>0.05){$("#fg").val(i);d.fg=i}M()}});$("#fg").on("change",function(i){d.fg=parseFloat(i.args.value);M()});$("#BLog").jqxButton({disabled:(d.log_brew)?false:true});$("#FLog").jqxButton({disabled:(d.log_fermentation)?false:true})}$("#styleSelect").jqxDropDownList({placeHolder:"Kies bierstijl:",theme:theme,source:styleslist,displayMember:"name",width:180,height:23,dropDownVerticalAlignment:"top",dropDownWidth:500,dropDownHeight:380,renderer:function(a2,i,a4){var a3=styleslist.records[a2];return a3.style_guide+" "+a3.style_letter+" "+a3.name}});$("#styleSelect").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=styleslist.records[i];$("#st_name").val(a2.name);$("#st_category").val(a2.category);$("#st_category_number").val(a2.category_number);$("#st_letter").val(a2.style_letter);$("#st_guide").val(a2.style_guide);$("#st_type").val(StyleTypeData[a2.type].nl);$("#st_og_min").val(a2.og_min);$("#st_og_max").val(a2.og_max);$("#st_fg_min").val(a2.fg_min);$("#st_fg_max").val(a2.fg_max);$("#st_ibu_min").val(a2.ibu_min);$("#st_ibu_max").val(a2.ibu_max);$("#st_color_min").val(a2.color_min);$("#st_color_max").val(a2.color_max);$("#st_carb_min").val(a2.carb_min);$("#st_carb_min2").val(a2.carb_min);$("#st_carb_max").val(a2.carb_max);$("#st_carb_max2").val(a2.carb_max);$("#st_abv_min").val(a2.abv_min);$("#st_abv_max").val(a2.abv_max)}});$("#equipmentSelect").jqxDropDownList({placeHolder:"Kies apparatuur:",theme:theme,source:equipmentlist,displayMember:"name",width:170,height:23,dropDownWidth:300,renderer:function(a2,i,a4){var a3=equipmentlist.records[a2];return a3.batch_size+" liter "+a3.name}});$("#equipmentSelect").on("select",function(a4){if(a4.args){var a3,a2,i=a4.args.index;a3=equipmentlist.records[i];a2=a3.batch_size/d.batch_size;$("#eq_name").val(a3.name);$("#eq_boil_size").val(a3.boil_size);d.boil_size=a3.boil_size;$("#boil_size").val(a3.boil_size);$("#eq_batch_size").val(a3.batch_size);d.batch_size=a3.batch_size;$("#batch_size").val(a3.batch_size);$("#est_a_vol").val(a3.batch_size*1.04);$("#eq_tun_volume").val(a3.tun_volume);d.eq_tun_weight=a3.tun_weight;d.eq_tun_specific_heat=a3.tun_specific_heat;d.eq_tun_material=a3.tun_material;d.eq_tun_height=a3.tun_height/100;$("#eq_top_up_water").val(a3.top_up_water);d.eq_trub_chiller_loss=a3.trub_chiller_loss;$("#eq_trub_chiller_loss").val(a3.trub_chiller_loss);$("#eq_evap_rate").val(a3.evap_rate);$("#eq_boil_time").val(a3.boil_time);d.eq_calc_boil_volume=a3.calc_boil_volume;$("#eq_top_up_kettle").val(a3.top_up_kettle);$("#eq_hop_utilization").val(a3.hop_utilization);$("#eq_notes").val(a3.notes);$("#eq_lauter_volume").val(a3.lauter_volume);d.eq_lauter_height=a3.lauter_height/100;$("#eq_lauter_deadspace").val(a3.lauter_deadspace);$("#eq_kettle_volume").val(a3.kettle_volume);d.eq_kettle_height=a3.kettle_height/100;$("#eq_mash_volume").val(a3.mash_volume);$("#eq_mash_max").val(a3.mash_max);d.eq_mash_max=a3.mash_max;$("#mash_max").val(a3.mash_max);$("#eq_efficiency").val(a3.efficiency);d.efficiency=a3.efficiency;$("#efficiency").val(a3.efficiency);d.sparge_volume=Math.round(a3.boil_size*5)/10;$("#sparge_volume").val(d.sparge_volume);$("#brew_sparge_volume").val(d.sparge_volume);$("#est_pre_vol").val(a3.boil_size*1.04);ae(parseFloat($("#est_og").jqxNumberInput("decimal")));at(a2);T();ai(a2);a1(a2);aO(a2);ar();P();j()}});function s(){console.log("saveRecord()");var a2={record:my_record,uuid:d.uuid,name:$("#name").val(),code:$("#code").val(),birth:$("#birth").val(),stage:d.stage,notes:$("#notes").val(),log_brew:d.log_brew,log_fermentation:d.log_fermentation,inventory_reduced:d.inventory_reduced,locked:d.locked,eq_name:$("#eq_name").val(),eq_boil_size:parseFloat($("#eq_boil_size").jqxNumberInput("decimal")),eq_batch_size:parseFloat($("#eq_batch_size").jqxNumberInput("decimal")),eq_tun_volume:parseFloat($("#eq_tun_volume").jqxNumberInput("decimal")),eq_tun_weight:d.eq_tun_weight,eq_tun_specific_heat:d.eq_tun_specific_heat,eq_tun_material:d.eq_tun_material,eq_tun_height:d.eq_tun_height,eq_top_up_water:parseFloat($("#eq_top_up_water").jqxNumberInput("decimal")),eq_trub_chiller_loss:parseFloat($("#eq_trub_chiller_loss").jqxNumberInput("decimal")),eq_evap_rate:parseFloat($("#eq_evap_rate").jqxNumberInput("decimal")),eq_boil_time:parseFloat($("#eq_boil_time").jqxNumberInput("decimal")),eq_calc_boil_volume:d.eq_calc_boil_volume,eq_top_up_kettle:parseFloat($("#eq_top_up_kettle").jqxNumberInput("decimal")),eq_hop_utilization:parseFloat($("#eq_hop_utilization").jqxNumberInput("decimal")),eq_notes:$("#eq_notes").val(),eq_lauter_volume:parseFloat($("#eq_lauter_volume").jqxNumberInput("decimal")),eq_lauter_height:d.eq_lauter_height,eq_lauter_deadspace:parseFloat($("#eq_lauter_deadspace").jqxNumberInput("decimal")),eq_kettle_volume:parseFloat($("#eq_kettle_volume").jqxNumberInput("decimal")),eq_kettle_height:d.eq_kettle_height,eq_mash_volume:parseFloat($("#eq_mash_volume").jqxNumberInput("decimal")),eq_mash_max:parseFloat($("#eq_mash_max").jqxNumberInput("decimal")),eq_efficiency:parseFloat($("#eq_efficiency").jqxNumberInput("decimal")),brew_date_start:$("#brew_date_start").val(),brew_mash_ph:parseFloat($("#brew_mash_ph").jqxNumberInput("decimal")),brew_mash_sg:parseFloat($("#brew_mash_sg").jqxNumberInput("decimal")),brew_mash_efficiency:parseFloat($("#brew_mash_efficiency").jqxNumberInput("decimal")),brew_sparge_est:parseFloat($("#brew_sparge_est").jqxNumberInput("decimal")),brew_sparge_ph:parseFloat($("#brew_sparge_ph").jqxNumberInput("decimal")),brew_preboil_volume:parseFloat($("#brew_preboil_volume").jqxNumberInput("decimal")),brew_preboil_sg:parseFloat($("#brew_preboil_sg").jqxNumberInput("decimal")),brew_preboil_ph:parseFloat($("#brew_preboil_ph").jqxNumberInput("decimal")),brew_preboil_efficiency:parseFloat($("#brew_preboil_efficiency").jqxNumberInput("decimal")),brew_aboil_volume:parseFloat($("#brew_aboil_volume").jqxNumberInput("decimal")),brew_aboil_sg:parseFloat($("#brew_aboil_sg").jqxNumberInput("decimal")),brew_aboil_ph:parseFloat($("#brew_aboil_ph").jqxNumberInput("decimal")),brew_aboil_efficiency:parseFloat($("#brew_aboil_efficiency").jqxNumberInput("decimal")),brew_cooling_method:$("#brew_cooling_method").val(),brew_cooling_time:parseFloat($("#brew_cooling_time").jqxNumberInput("decimal")),brew_cooling_to:parseFloat($("#brew_cooling_to").jqxNumberInput("decimal")),brew_whirlpool9:parseFloat($("#brew_whirlpool9").jqxNumberInput("decimal")),brew_whirlpool7:parseFloat($("#brew_whirlpool7").jqxNumberInput("decimal")),brew_whirlpool6:parseFloat($("#brew_whirlpool6").jqxNumberInput("decimal")),brew_whirlpool2:parseFloat($("#brew_whirlpool2").jqxNumberInput("decimal")),brew_fermenter_volume:parseFloat($("#brew_fermenter_volume").jqxNumberInput("decimal")),brew_fermenter_extrawater:parseFloat($("#brew_fermenter_extrawater").jqxNumberInput("decimal")),brew_fermenter_tcloss:parseFloat($("#brew_fermenter_tcloss").jqxNumberInput("decimal")),brew_aeration_time:parseFloat($("#brew_aeration_time").jqxNumberInput("decimal")),brew_aeration_speed:parseFloat($("#brew_aeration_speed").jqxNumberInput("decimal")),brew_aeration_type:$("#brew_aeration_type").val(),brew_fermenter_sg:parseFloat($("#brew_fermenter_sg").jqxNumberInput("decimal")),brew_fermenter_ibu:parseFloat($("#brew_fermenter_ibu").jqxNumberInput("decimal")),brew_fermenter_color:parseFloat($("#brew_fermenter_color").jqxNumberInput("decimal")),brew_date_end:$("#brew_date_end").val(),og:d.og,fg:parseFloat($("#fg").jqxNumberInput("decimal")),primary_start_temp:parseFloat($("#primary_start_temp").jqxNumberInput("decimal")),primary_max_temp:parseFloat($("#primary_max_temp").jqxNumberInput("decimal")),primary_end_temp:parseFloat($("#primary_end_temp").jqxNumberInput("decimal")),primary_end_sg:parseFloat($("#primary_end_sg").jqxNumberInput("decimal")),primary_end_date:$("#primary_end_date").val(),secondary_temp:parseFloat($("#secondary_temp").jqxNumberInput("decimal")),secondary_end_sg:parseFloat($("#secondary_end_sg").jqxNumberInput("decimal")),secondary_end_date:$("#secondary_end_date").val(),tertiary_temp:parseFloat($("#tertiary_temp").jqxNumberInput("decimal")),package_date:$("#package_date").val(),package_volume:parseFloat($("#package_volume").jqxNumberInput("decimal")),package_infuse_amount:parseFloat($("#package_infuse_amount").jqxNumberInput("decimal")),package_infuse_abv:parseFloat($("#package_infuse_abv").jqxNumberInput("decimal")),package_infuse_notes:$("#package_infuse_notes").val(),package_abv:parseFloat($("#package_abv").jqxNumberInput("decimal")),package_ph:parseFloat($("#package_ph").jqxNumberInput("decimal")),bottle_amount:parseFloat($("#bottle_amount").jqxNumberInput("decimal")),bottle_carbonation:parseFloat($("#bottle_carbonation").jqxNumberInput("decimal")),bottle_priming_water:parseFloat($("#bottle_priming_water").jqxNumberInput("decimal")),bottle_priming_amount:parseFloat($("#bottle_priming_amount").jqxNumberInput("decimal")),bottle_carbonation_temp:parseFloat($("#bottle_carbonation_temp").jqxNumberInput("decimal")),keg_amount:parseFloat($("#keg_amount").jqxNumberInput("decimal")),keg_carbonation:parseFloat($("#keg_carbonation").jqxNumberInput("decimal")),keg_priming_water:parseFloat($("#keg_priming_water").jqxNumberInput("decimal")),keg_priming_amount:parseFloat($("#keg_priming_amount").jqxNumberInput("decimal")),keg_carbonation_temp:parseFloat($("#keg_carbonation_temp").jqxNumberInput("decimal")),keg_forced_carb:d.keg_forced_carb,keg_pressure:parseFloat($("#keg_pressure").jqxNumberInput("decimal")),taste_notes:$("#taste_notes").val(),taste_rate:parseFloat($("#taste_rate").jqxNumberInput("decimal")),taste_date:$("#taste_date").val(),taste_color:$("#taste_color").val(),taste_transparency:$("#taste_transparency").val(),taste_head:$("#taste_head").val(),taste_aroma:$("#taste_aroma").val(),taste_taste:$("#taste_taste").val(),taste_mouthfeel:$("#taste_mouthfeel").val(),taste_aftertaste:$("#taste_aftertaste").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(),starter_enable:d.starter_enable,starter_type:$("#starter_type").val(),starter_sg:parseFloat($("#starter_sg").jqxNumberInput("decimal")),starter_viability:parseFloat($("#starter_viability").jqxNumberInput("decimal")),prop1_type:$("#prop1_type").val(),prop1_volume:parseFloat($("#prop1_volume").jqxNumberInput("decimal")),prop2_type:$("#prop2_type").val(),prop2_volume:parseFloat($("#prop2_volume").jqxNumberInput("decimal")),prop3_type:$("#prop3_type").val(),prop3_volume:parseFloat($("#prop3_volume").jqxNumberInput("decimal")),prop4_type:$("#prop4_type").val(),prop4_volume:parseFloat($("#prop4_volume").jqxNumberInput("decimal")),fermentables:$("#fermentableGrid").jqxGrid("getrows"),hops:$("#hopGrid").jqxGrid("getrows"),miscs:$("#miscGrid").jqxGrid("getrows"),yeasts:$("#yeastGrid").jqxGrid("getrows"),mashs:$("#mashGrid").jqxGrid("getrows")},i="update=true&"+$.param(a2);$.ajax({dataType:"json",url:E,cache:false,data:i,async:false,type:"POST",success:function(a4,a3,a5){console.log("saveRecord() success")},error:function(a3,a5,a4){console.log("saveRecord() error")}})}ag.dataBind();$("#name").jqxTooltip({content:"De naam voor dit product."});$("#name").jqxInput({theme:theme,width:640,height:23});$("#code").jqxTooltip({content:"Product code nummer."});$("#code").jqxInput({theme:theme,width:100,height:23});$("#birth").jqxTooltip({content:"De ontwerp datum van dit product."});$("#birth").jqxInput({theme:theme,width:120,height:23});$("#stage").jqxTooltip({content:"De productie fase van dit product."});$("#stage").jqxInput({theme:theme,width:100,height:23});$("#locked").jqxCheckBox({theme:theme,width:120,height:23,disabled:true});$("#locked").on("checked",function(i){if(d.stage>=10){d.locked=1;d.stage=11;aU()}});$("#locked").on("unchecked",function(i){if(d.stage>=10){d.locked=0;d.stage=10;aU()}});$("#notes").jqxTooltip({content:"De uitgebreide opmerkingen over dit product."});$("#notes").jqxInput({theme:theme,width:960,height:100});$("#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_time").jqxTooltip({content:"De kooktijd in minuten."});$("#boil_time").jqxNumberInput(PosInt);$("#boil_time").jqxNumberInput({min:4,max:360});$("#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});$("#st_guide").jqxTooltip({content:"De bierstijl gids voor dit recept."});$("#st_guide").jqxInput({theme:theme,width:250,height:23});$("#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_type").jqxTooltip({content:"Het bierstijl type."});$("#st_type").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);$("#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 verwachte 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);$("#eq_name").jqxTooltip({content:"De naam van deze brouw apparatuur."});$("#eq_name").jqxInput({theme:theme,width:250,height:23});$("#eq_boil_size").jqxTooltip({content:"Normaal kook volume in liters"});$("#eq_boil_size").jqxNumberInput(Show1dec);$("#eq_batch_size").jqxTooltip({content:"Berekende batch grootte in liters aan het eind van de kook."});$("#eq_batch_size").jqxNumberInput(Show1dec);$("#eq_tun_volume").jqxTooltip({content:"Maisch ketel volume."});$("#eq_tun_volume").jqxNumberInput(Show1dec);$("#eq_top_up_water").jqxTooltip({content:"Extra water in het gistvat."});$("#eq_top_up_water").jqxNumberInput(Show1dec);$("#eq_trub_chiller_loss").jqxTooltip({content:"Standaard verlies bij het overbrengen naar het gistvat."});$("#eq_trub_chiller_loss").jqxNumberInput(Show1dec);$("#eq_evap_rate").jqxTooltip({content:"Verdamping in liters per uur."});$("#eq_evap_rate").jqxNumberInput(Show2dec);$("#eq_boil_time").jqxTooltip({content:"Normale kooktijd in minuten."});$("#eq_boil_time").jqxNumberInput(Show0dec);$("#eq_top_up_kettle").jqxTooltip({content:"Extra water toevoegen tijdens de kook."});$("#eq_top_up_kettle").jqxNumberInput(Show1dec);$("#eq_hop_utilization").jqxTooltip({content:"100% voor kleine installaties, hoger voor grote brouwerijen."});$("#eq_hop_utilization").jqxNumberInput(Show0dec);$("#eq_notes").jqxTooltip({content:"Opmerkingen over deze apparatuur."});$("#eq_notes").jqxInput({theme:theme,width:960,height:200});$("#eq_lauter_volume").jqxTooltip({content:"Filterkuip volume."});$("#eq_lauter_volume").jqxNumberInput(Show1dec);$("#eq_lauter_deadspace").jqxTooltip({content:"Filterkuip verlies in liters."});$("#eq_lauter_deadspace").jqxNumberInput(Show1dec);$("#eq_kettle_volume").jqxTooltip({content:"Kook ketel volume in liters."});$("#eq_kettle_volume").jqxNumberInput(Show1dec);$("#eq_mash_volume").jqxTooltip({content:"Maisch water voor de eerste stap."});$("#eq_mash_volume").jqxNumberInput(Show1dec);$("#eq_mash_max").jqxTooltip({content:"De maximale moutstort in Kg."});$("#eq_mash_max").jqxNumberInput(Show1dec);$("#eq_efficiency").jqxTooltip({content:"Gemiddeld brouwzaal rendement."});$("#eq_efficiency").jqxNumberInput(Show1dec);$("#est_color2").jqxTooltip({content:"De kleur in EBC. Dit wordt automatisch berekend."});$("#est_color2").jqxNumberInput(Show0dec);$("#est_og2").jqxTooltip({content:"Het geschatte begin SG van dit product."});$("#est_og2").jqxNumberInput(Show3dec);$("#mash_kg").jqxTooltip({content:"Het gewicht van alle mouten in de maisch."});$("#mash_kg").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(i){return(Math.round(parseInt(i)*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(i){return(Math.round(parseInt(i)*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(i){return(Math.round(parseInt(i)*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(i){return(parseInt(i)*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 a2,i=$("#fermentableGrid").jqxGrid("getrowid",u);console.log("FermentableReady row:"+u+" ID:"+i);a2={f_name:aK.f_name,f_origin:aK.f_origin,f_supplier:aK.f_supplier,f_amount:aK.f_amount,f_cost:aK.f_cost,f_type:aK.f_type,f_yield:aK.f_yield,f_color:aK.f_color,f_coarse_fine_diff:aK.f_coarse_fine_diff,f_moisture:aK.f_moisture,f_diastatic_power:aK.f_diastatic_power,f_protein:aK.f_protein,f_max_in_batch:aK.f_max_in_batch,f_graintype:aK.f_graintype,f_added:aK.f_added,f_dissolved_protein:aK.f_dissolved_protein,f_recommend_mash:aK.f_recommend_mash,f_add_after_boil:aK.f_add_after_boil,f_adjust_to_total_100:aK.f_adjust_to_total_100,f_percentage:aK.f_percentage,f_di_ph:aK.f_di_ph,f_acid_to_ph_57:aK.f_acid_to_ph_57,f_inventory:aK.f_inventory,f_avail:aK.f_avail};$("#fermentableGrid").jqxGrid("updaterow",i,a2);aV();T();ar();aN()});$("#wf_name").jqxInput({theme:theme,width:320,height:23});$("#wf_instock").jqxCheckBox({theme:theme,height:23});$("#wf_instock").on("change",function(i){fermentableinstock=i.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(a2,i,a4){var a3=fermentablelist.records[a2];return a3.supplier+" / "+a3.name+" ("+a3.color+" EBC)"}});$("#wf_select").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=fermentablelist.records[i];$("#wf_name").val(a2.name);aK.f_name=a2.name;aK.f_origin=a2.origin;aK.f_supplier=a2.supplier;aK.f_type=a2.type;aK.f_cost=a2.cost;aK.f_yield=a2.yield;aK.f_color=a2.color;aK.f_coarse_fine_diff=a2.coarse_fine_diff;aK.f_moisture=a2.moisture;aK.f_diastatic_power=a2.diastatic_power;aK.f_protein=a2.protein;aK.f_max_in_batch=a2.max_in_batch;aK.f_graintype=a2.graintype;aK.f_dissolved_protein=a2.dissolved_protein;aK.f_recommend_mash=a2.recommend_mash;aK.f_add_after_boil=a2.add_after_boil;aK.f_di_ph=a2.di_ph;aK.f_acid_to_ph_57=a2.acid_to_ph_57;aK.f_inventory=a2.inventory}});$("#wf_amount").jqxNumberInput(Spin3dec);$("#wf_amount").on("change",function(i){console.log("amount changed: "+i.args.value);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_amount",i.args.value);aK.f_amount=i.args.value;if(!l){aV();T();ar();aN()}});$("#wf_percentage").jqxNumberInput(Perc1dec);$("#wf_percentage").on("change",function(a2){var a4,a8,ba,a9,a5,a7,i,a6,bb,a3=Math.round(aK.f_percentage*10)/10;a4=a2.args.value;console.log("percentage changed: "+a4+" old: "+a3);aK.f_percent=a4;a8=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;if((a3!=a4)&&(a8>1)){ba=$("#fermentableGrid").jqxGrid("getrowdata",u);if(ba.f_adjust_to_total_100){$("#wf_percentage").val(a3)}else{a9=a4-a3;a5=0;for(ad=0;ad<a8;ad++){ba=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(ba.f_added<4){a5+=Math.round(ba.f_amount*1000)/1000}}a5=Math.round(a5*1000)/1000;if(l){a7=Math.round(a5*a9*10)/1000;ba=$("#fermentableGrid").jqxGrid("getrowdata",u);i=Round(ba.f_amount+a7,3);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_amount",i);$("#wf_amount").val(i);$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_percentage",ba.f_percentage+a9);for(ad=0;ad<a8;ad++){ba=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(ba.f_adjust_to_total_100){i=ba.f_amount-a7;$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",ba.f_percentage-a9);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_amount",i)}}T();ar();aN()}else{a6=a5*a9/100;for(ad=0;ad<a8;ad++){ba=$("#fermentableGrid").jqxGrid("getrowdata",ad);if(ba.f_added<4){if(ad==u){i=Math.round((ba.f_amount+a6)*1000)/1000;$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_amount",i);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",a4)}else{i=Math.round((ba.f_amount-(a6/(a8-1)))*1000)/1000;bb=Math.round((i/a5)*1000)/10;$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_amount",i);$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",bb)}}else{$("#fermentableGrid").jqxGrid("setcellvalue",ad,"f_percentage",0)}}T();ar();aN()}}}});$("#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(a3){if(aK.f_adjust_to_total_100==0){if(l){var a2,a4=$("#fermentableGrid").jqxGrid("getdatainformation").rowscount;for(a2=0;a2<a4;a2++){if(a2!=u){$("#fermentableGrid").jqxGrid("setcellvalue",a2,"f_adjust_to_total_100",0)}}}$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_adjust_to_total_100",1);T()}});$("#wf_adjust_to_total_100").on("unchecked",function(i){if(aK.f_adjust_to_total_100!=0){$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_adjust_to_total_100",0);T()}});$("#wf_added").jqxDropDownList({theme:theme,source:AddedAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wf_added").on("select",function(a2){if(a2.args){var i=a2.args.index;$("#fermentableGrid").jqxGrid("setcellvalue",u,"f_added",i);T();ar();aN()}});$("#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(a2){var i=parseInt(a2);if(i<20){return"Weinig"}else{if(i<40){return"Matig"}else{if(i<60){return"Redelijk"}else{if(i<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(a2){var i=parseInt(a2);if(i<20){return"Weinig"}else{if(i<40){return"Matig"}else{if(i<60){return"Redelijk"}else{if(i<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 a2,i=$("#hopGrid").jqxGrid("getrowid",a);a2={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",i,a2);ar()});$("#wh_name").jqxInput({theme:theme,width:320,height:23});$("#wh_instock").jqxCheckBox({theme:theme,height:23});$("#wh_instock").on("change",function(i){hopinstock=i.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(a2,i,a4){var a3=hoplist.records[a2];return a3.origin+" - "+a3.name+" / "+HopFormData[a3.form].nl+" ("+a3.alpha+" % &alpha;)"}});$("#wh_select").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=hoplist.records[i];$("#wh_name").val(a2.name);e.h_name=a2.name;e.h_origin=a2.origin;e.h_cost=a2.cost;e.h_type=a2.type;e.h_form=a2.form;e.h_alpha=a2.alpha;e.h_beta=a2.beta;e.h_hsi=a2.hsi;e.h_humulene=a2.humulene;e.h_caryophyllene=a2.caryophyllene;e.h_cohumulone=a2.cohumulone;e.h_myrcene=a2.myrcene;e.h_total_oil=a2.total_oil;e.h_inventory=a2.inventory}});$("#wh_amount").jqxNumberInput(Spin1dec);$("#wh_amount").on("change",function(a2){console.log("amount changed: "+a2.args.value+" time:"+e.h_time+" alpha:"+e.h_alpha);var a3,i=parseFloat(a2.args.value)/1000;a3=toIBU(e.h_useat,e.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),i,parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());e.h_amount=i;$("#wh_ibu").val(a3)});$("#wh_ibu").jqxNumberInput(Show1dec);$("#wh_time").jqxNumberInput(PosInt);$("#wh_time").on("change",function(i){var a3,a2=parseFloat(i.args.value);if(e.h_useat==2){if(a2>parseFloat($("#boil_time").jqxNumberInput("decimal"))){a2=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wh_time").val(a2)}e.h_time=a2}else{if(e.h_useat==4){if(a2>120){a2=120;$("#wh_time").val(a2)}e.h_time=a2}else{if(e.h_useat==5){if(a2>21){a2=21;$("#wh_time").val(a2)}e.h_time=a2*1440}}}a3=toIBU(e.h_useat,e.h_form,ak,parseFloat($("#batch_size").jqxNumberInput("decimal")),parseFloat(e.h_amount),parseFloat(e.h_time),parseFloat(e.h_alpha),$("#ibu_method").val());$("#wh_ibu").val(a3)});$("#wh_useat").jqxDropDownList({theme:theme,source:HopUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wh_useat").on("select",function(a2){if(a2.args){var i=a2.args.index;e.h_useat=i;if((i==0)||(i==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(i==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(i==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 a2,i=$("#miscGrid").jqxGrid("getrowid",av);console.log("MiscReady row:"+av+" ID:"+i);a2={m_name:aG.m_name,m_amount:aG.m_amount,m_cost:aG.m_cost,m_type:aG.m_type,m_use_use:aG.m_use_use,m_time:aG.m_time,m_amount_is_weight:aG.m_amount_is_weight,m_inventory:aG.m_inventory,m_avail:aG.m_avail};$("#miscGrid").jqxGrid("updaterow",i,a2);aF()});$("#wm_name").jqxInput({theme:theme,width:320,height:23});$("#wm_instock").jqxCheckBox({theme:theme,height:23});$("#wm_instock").on("change",function(i){miscinstock=i.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(a3){if(a3.args){var a2,i=a3.args.index;a2=misclist.records[i];$("#wm_name").val(a2.name);aG.m_name=a2.name;aG.m_cost=a2.cost;aG.m_type=a2.type;aG.m_use_use=a2.use_use;aG.m_amount_is_weight=a2.amount_is_weight;aG.m_inventory=a2.inventory}});$("#wm_amount").jqxNumberInput(Spin2dec);$("#wm_amount").on("change",function(i){console.log("amount changed: "+i.args.value);aG.m_amount=parseFloat(i.args.value)/1000});$("#wm_time").jqxNumberInput(PosInt);$("#wm_time").on("change",function(i){var a2=parseFloat(i.args.value);if(aG.m_use_use==2){if(a2>parseFloat($("#boil_time").jqxNumberInput("decimal"))){a2=parseFloat($("#boil_time").jqxNumberInput("decimal"));$("#wm_time").val(a2)}aG.m_time=a2}else{if((aG.m_use_use==3)||(aG.m_use_use==4)){if(a2>21){a2=21;$("#wm_time").val(a2)}aG.m_time=a2*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(a2){if(a2.args){var i=a2.args.index;aG.m_use_use=i;if((i==2)||(i==3)||(i==4)){$("#wm_time").jqxNumberInput({spinButtons:true,readOnly:false,width:110})}else{$("#wm_time").jqxNumberInput({spinButtons:false,readOnly:true,width:90});$("#wm_time").val(0);aG.m_time=0}}});$("#est_fg2").jqxTooltip({content:"Het verwachte eind SG. Dit wordt automatisch berekend."});$("#est_fg2").jqxNumberInput(Show3dec);$("#est_abv2").jqxTooltip({content:"Alcohol volume %. Dit wordt automatisch berekend."});$("#est_abv2").jqxNumberInput(Smal1dec);$("#yeast_cells").jqxNumberInput(Show1dec);$("#need_cells").jqxNumberInput(Show1dec);$("#plato_cells").jqxNumberInput(Show2dec);$("#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 a2,i=$("#yeastGrid").jqxGrid("getrowid",aD);console.log("YeastReady row:"+aD+" ID:"+i);a2={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",i,a2);T();X()});$("#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(i){yeastinstock=i.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(a2,i,a4){var a3=yeastlist.records[a2];return a3.laboratory+" "+a3.product_id+" "+a3.name}});$("#wy_select").on("select",function(a3){if(a3.args){var a2,i=a3.args.index;a2=yeastlist.records[i];$("#wy_name").val(a2.name);$("#wy_laboratory").val(a2.laboratory);$("#wy_product_id").val(a2.product_id);f.y_name=a2.name;f.y_cost=a2.cost;f.y_type=a2.type;f.y_form=a2.form;f.y_laboratory=a2.laboratory;f.y_product_id=a2.product_id;f.y_min_temperature=a2.min_temperature;f.y_max_temperature=a2.max_temperature;f.y_flocculation=a2.flocculation;f.y_attenuation=a2.attenuation;f.y_cells=a2.cells;f.y_inventory=a2.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:")}}T();X()}});$("#wy_amount").jqxNumberInput(Spin1dec);$("#wy_amount").on("change",function(a2){var i=parseFloat(a2.args.value);if(f.y_form!=0){i=parseFloat(a2.args.value)/1000}f.y_amount=i;T();X()});$("#wy_use").jqxDropDownList({theme:theme,source:YeastUseAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true,dropDownVerticalAlignment:"top"});$("#wy_use").on("select",function(a2){if(a2.args){var i=a2.args.index;f.y_use=i;T();X()}});for(ad=1;ad<5;ad++){$("#prop"+ad+"_type").jqxDropDownList({theme:theme,source:StarterTypeAdapter,valueMember:"id",displayMember:"nl",width:120,height:23,autoDropDownHeight:true});$("#prop"+ad+"_type").hide();$("#prop"+ad+"_volume").jqxNumberInput(Spin3dec);$("#prop"+ad+"_volume").hide();$("#prop"+ad+"_irate").jqxNumberInput(Show1dec);$("#prop"+ad+"_irate").hide();$("#prop"+ad+"_ncells").jqxNumberInput(Show1dec);$("#prop"+ad+"_ncells").hide();$("#prop"+ad+"_tcells").jqxNumberInput(Show1dec);$("#prop"+ad+"_tcells").hide();$("#prop"+ad+"_growf").jqxNumberInput(Show2dec);$("#prop"+ad+"_growf").hide()}$("#starter_enable").jqxCheckBox({theme:theme,height:23});$("#starter_type").jqxDropDownList({theme:theme,source:StarterTypeAdapter,valueMember:"id",displayMember:"nl",width:120,height:23,autoDropDownHeight:true});$("#starter_sg").jqxNumberInput(SGopts);$("#starter_viability").jqxNumberInput(Perc0);$("#starter_try").jqxButton({template:"primary",width:"100px",height:23,theme:theme});$("#mash_name").jqxTooltip({content:"De omschrijving van dit maisch profiel."});$("#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(a6){if(a6.args){var a8,a5,a2,a7,a4,a9,a3=a6.args.index;a2=new Array();a7=$("#mashGrid").jqxGrid("getdisplayrows");for(a4=0;a4<a7.length;a4++){a9=a7[a4];a2.push(a9.uid)}$("#mashGrid").jqxGrid("deleterow",a2);a5=mashlist.records[a3];$("#mash_name").val(a5.name);for(a4=0;a4<a5.steps.length;a4++){a8=a5.steps[a4];a9={};a9.step_name=a8.step_name;a9.step_type=a8.step_type;if(C==0&&d.w1_amount>0){C=d.w1_amount}if(a4==0){a9.step_infuse_amount=C}else{a9.step_infuse_amount=0}if(ao>0){a9.step_thickness=parseFloat(C/ao)}else{a9.step_thickness=0}a9.step_temp=a8.step_temp;a9.end_temp=a8.end_temp;a9.step_time=a8.step_time;a9.ramp_time=a8.ramp_time;$("#mashGrid").jqxGrid("addrow",null,a9)}}});$("#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(){aN()});$("#wstep_name").jqxInput({theme:theme,width:320,height:23});$("#wstep_name").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.step_name=i.args.value});$("#wstep_type").jqxDropDownList({theme:theme,source:MashStepTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#wstep_type").on("select",function(a4){if(a4.args){var a7,a3,a5,a6,a2=a4.args.index;a7=$("#mashGrid").jqxGrid("getrowdata",aj);a7.step_type=a2;if(a2==0){$("#wstep_infuse_amount").show();$("#wstep_pmpt").show()}else{a7.step_infuse_amount=0;$("#wstep_infuse_amount").hide();$("#wstep_pmpt").hide()}C=0;a5=$("#mashGrid").jqxGrid("getrows");for(a3=0;a3<a5.length;a3++){a6=a5[a3];if(a6.step_type==0){C+=parseFloat(a6.step_infuse_amount)}}}});$("#wstep_temp").jqxNumberInput(Spin1dec);$("#wstep_temp").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.step_temp=parseFloat(i.args.value)});$("#wend_temp").jqxNumberInput(Spin1dec);$("#wend_temp").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.end_temp=parseFloat(i.args.value)});$("#wstep_time").jqxNumberInput(PosInt);$("#wstep_time").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.step_time=parseFloat(i.args.value)});$("#wramp_time").jqxNumberInput(PosInt);$("#wramp_time").on("change",function(i){var a2=$("#mashGrid").jqxGrid("getrowdata",aj);a2.ramp_time=parseFloat(i.args.value)});$("#wstep_infuse_amount").jqxNumberInput(Spin1dec);$("#wstep_infuse_amount").on("change",function(a3){var a5,a2,a4,a6=$("#mashGrid").jqxGrid("getrowdata",aj);a6.step_infuse_amount=parseFloat(a3.args.value);C=0;a4=$("#mashGrid").jqxGrid("getrows");for(a2=0;a2<a4.length;a2++){a5=a4[a2];if(a5.step_type==0){C+=parseFloat(a5.step_infuse_amount)}}if(d.w2_amount==0){d.w1_amount=C;$("#w1_amount").val(C)}else{d.w1_amount=(d.w1_amount/(d.w1_amount+d.w2_amount))*C;d.w2_amount=(d.w2_amount/(d.w1_amount+d.w2_amount))*C;$("#w1_amount").val(d.w1_amount);$("#w2_amount").val(d.w2_amount)}$("#wg_amount").val(C)});$("#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(a3){if(a3.args){var a2,i=a3.args.index;a2=waterlist.records[i];d.w1_name=a2.name;$("#w1_calcium").val(a2.calcium);d.w1_calcium=a2.calcium;$("#w1_sulfate").val(a2.sulfate);d.w1_sulfate=a2.sulfate;$("#w1_chloride").val(a2.chloride);d.w1_chloride=a2.chloride;$("#w1_sodium").val(a2.sodium);d.w1_sodium=a2.sodium;$("#w1_magnesium").val(a2.magnesium);d.w1_magnesium=a2.magnesium;$("#w1_total_alkalinity").val(a2.total_alkalinity);d.w1_total_alkalinity=a2.total_alkalinity;$("#w1_ph").val(a2.ph);d.w1_ph=a2.ph;$("#w1_cost").val(a2.cost);d.w1_cost=a2.cost;P()}});$("#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(a3){if(a3.args){var a2,i=a3.args.index;a2=waterlist.records[i];d.w2_name=a2.name;$("#w2_calcium").val(a2.calcium);d.w2_calcium=a2.calcium;$("#w2_sulfate").val(a2.sulfate);d.w2_sulfate=a2.sulfate;$("#w2_chloride").val(a2.chloride);d.w2_chloride=a2.chloride;$("#w2_sodium").val(a2.sodium);d.w2_sodium=a2.sodium;$("#w2_magnesium").val(a2.magnesium);d.w2_magnesium=a2.magnesium;$("#w2_total_alkalinity").val(a2.total_alkalinity);d.w2_total_alkalinity=a2.total_alkalinity;$("#w2_ph").val(a2.ph);d.w2_ph=a2.ph;$("#w2_cost").val(a2.cost);d.w2_cost=a2.cost;$("#w2_amount").jqxNumberInput({max:100000,readOnly:false});P()}});$("#w2_amount").jqxTooltip({content:"De verdeling van het hoofd en meng water. Het totale maisch water volume blijft gelijk."});$("#w2_amount").jqxNumberInput({inputMode:"simple",spinMode:"simple",theme:theme,width:94,height:23,min:0,max:0,decimalDigits:1,spinButtons:true,spinButtonsStep:0.5,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_total_alkalinity").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_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(a3){if(a3.args){var a2,i=a3.args.index;a2=waterprofiles.records[i];$("#pr_calcium").val(a2.calcium);$("#pr_sulfate").val(a2.sulfate);$("#pr_chloride").val(a2.chloride);$("#pr_sodium").val(a2.sodium);$("#pr_magnesium").val(a2.magnesium);$("#pr_total_alkalinity").val(a2.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"});$("#brew_date_start").jqxTooltip({content:"Brouw datum en tijd. Voor planning laat de tijd op 00:00:00 staan."});$("#brew_date_start").jqxDateTimeInput(DateTimeopts);$("#brew_date_start").on("close",function(i){aU()});$("#brew_date_end").jqxTooltip({content:"End datum en tijd van de brouw. Leeg laten als er nog niet gebrouwen is."});$("#brew_date_end").jqxDateTimeInput(DateTimeopts);$("#brew_date_end").on("close",function(i){aU()});$("#brew_mash_ph").jqxTooltip({content:"De gemeten pH tijdens het maischen eventueel na correctie."});$("#brew_mash_ph").jqxNumberInput(SpinpH);$("#est_mash_ph").jqxTooltip({content:"De gewenste pH tijdens het maischen."});$("#est_mash_ph").jqxNumberInput(Show1wat);$("#brew_preboil_ph").jqxTooltip({content:"De gemeten pH in de kookketel na het spoelen en voor de kook."});$("#brew_preboil_ph").jqxNumberInput(SpinpH);$("#brew_aboil_ph").jqxTooltip({content:"De gemeten pH na het koken."});$("#brew_aboil_ph").jqxNumberInput(SpinpH);$("#brew_mash_sg").jqxTooltip({content:"Het bereikte SG na het maischen."});$("#brew_mash_sg").jqxNumberInput(SGopts);$("#brew_mash_sg").on("valueChanged",function(){aZ()});$("#est_mash_sg").jqxTooltip({content:"Het berekende verwachte SG na het maischen."});$("#est_mash_sg").jqxNumberInput(Show3wat);$("#brew_preboil_sg").jqxTooltip({content:"Het gemeten SG in de kookketel na het spoelen en voor het koken."});$("#brew_preboil_sg").jqxNumberInput(SGopts);$("#brew_preboil_sg").on("valueChanged",function(i){d.brew_preboil_sg=i.args.value;w()});$("#est_pre_sg").jqxTooltip({content:"Het berekende SG in de kookketel na het spoelen en voor het koken."});$("#est_pre_sg").jqxNumberInput(Show3wat);$("#brew_aboil_sg").jqxTooltip({content:"Het gemeten SG in de kookketel na het koken."});$("#brew_aboil_sg").jqxNumberInput(SGopts);$("#brew_aboil_sg").on("valueChanged",function(i){d.brew_aboil_sg=i.args.value;R();T();ar()});$("#est_og3").jqxTooltip({content:"Het gewenste SG in de kookketel na het koken."});$("#est_og3").jqxNumberInput(Show3wat);$("#brew_mash_efficiency").jqxTooltip({content:"Het behaalde maisch rendement."});$("#brew_mash_efficiency").jqxNumberInput(Show1dec);$("#brew_preboil_volume").jqxTooltip({content:"Het gemeten volume van het wort voor het koken."});$("#brew_preboil_volume").jqxNumberInput(Spin1dec);$("#brew_preboil_volume").on("valueChanged",function(i){d.brew_preboil_volume=i.args.value;w()});$("#est_pre_vol").jqxTooltip({content:"Het berekende volume van het wort voor het koken."});$("#est_pre_vol").jqxNumberInput(Show1wat);$("#brew_aboil_volume").jqxTooltip({content:"Het gemeten volume van het wort na het koken."});$("#brew_aboil_volume").jqxNumberInput(Spin1dec);$("#brew_aboil_volume").on("valueChanged",function(i){d.brew_aboil_volume=i.args.value;R();T();ar()});$("#est_a_vol").jqxTooltip({content:"Het gewenste volume na het koken."});$("#est_a_vol").jqxNumberInput(Show1wat);$("#brew_preboil_efficiency").jqxTooltip({content:"Het berekende rendement voor het koken."});$("#brew_preboil_efficiency").jqxNumberInput(Show1dec);$("#brew_aboil_efficiency").jqxTooltip({content:"Het bereikte rendement na het koken."});$("#brew_aboil_efficiency").jqxNumberInput(Show1dec);$("#brew_sparge_temperature").jqxTooltip({content:"De spoelwater temperatuur, in te stellen in de Water tab."});$("#brew_sparge_temperature").jqxNumberInput(Show1dec);$("#brew_sparge_volume").jqxTooltip({content:"Het spoelwater voorraad volume, in te stellen in de Water tab."});$("#brew_sparge_volume").jqxNumberInput(Show1dec);$("#brew_sparge_est").jqxNumberInput(Show1dec);$("#brew_whirlpool9").jqxNumberInput(PosInt);$("#brew_whirlpool9").jqxNumberInput({max:120});$("#brew_cooling_to").jqxNumberInput(Spin1dec);$("#brew_sparge_ph").jqxNumberInput(SpinpH);$("#brew_whirlpool7").jqxNumberInput(PosInt);$("#brew_whirlpool7").jqxNumberInput({max:120});$("#brew_cooling_method").jqxDropDownList({theme:theme,source:CoolingTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#brew_whirlpool6").jqxNumberInput(PosInt);$("#brew_whirlpool6").jqxNumberInput({max:120});$("#brew_cooling_time").jqxNumberInput(PosInt);$("#brew_cooling_time").jqxNumberInput({max:1440});$("#brew_whirlpool2").jqxNumberInput(PosInt);$("#brew_whirlpool2").jqxNumberInput({max:120});$("#brew_aeration_type").jqxDropDownList({theme:theme,source:AerationTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#brew_aeration_time").jqxNumberInput(PosInt);$("#brew_aeration_time").jqxNumberInput({max:1440});$("#brew_aeration_speed").jqxNumberInput(PosInt);$("#brew_aeration_speed").jqxNumberInput({max:1440});$("#brew_fermenter_volume").jqxNumberInput(Show1dec);$("#brew_fermenter_extrawater").jqxNumberInput(Spin1dec);$("#brew_fermenter_sg").jqxNumberInput(Show3dec);$("#brew_fermenter_tcloss").jqxNumberInput(Spin1dec);$("#brew_fermenter_ibu").jqxNumberInput(Show0dec);$("#brew_fermenter_color").jqxNumberInput(Show0dec);$("#BLog").jqxButton({template:"info",width:"150px",theme:theme});$("#BLog").click(function(){window.open("log_brew.php?code="+d.code+"&name="+d.name)});$("#brew_fermenter_sg2").jqxTooltip({content:"Het behaalde SG in het gistvat, overgenomen van de brouwdag."});$("#brew_fermenter_sg2").jqxNumberInput(Show3dec);$("#primary_start_temp").jqxTooltip({content:"De begintemperatuur van de hoofdvergisting."});$("#primary_start_temp").jqxNumberInput(YeastT);$("#primary_max_temp").jqxTooltip({content:"De hoogst bereikte piek temperatuur tijdens de hoofgvergisting."});$("#primary_max_temp").jqxNumberInput(YeastT);$("#primary_end_temp").jqxTooltip({content:"De eind temperatuur van de hoofdvergisting."});$("#primary_end_temp").jqxNumberInput(YeastT);$("#primary_end_sg").jqxTooltip({content:"Het gemeten SG aan het eind van de hoofdvergisting."});$("#primary_end_sg").jqxNumberInput(SGopts);$("#primary_end_brix").jqxTooltip({content:"Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer."});$("#primary_end_brix").jqxNumberInput(Spin1dec);$("#primary_svg").jqxTooltip({content:"De schijnbare vergisting graad behaald na de hoofdgisting."});$("#primary_svg").jqxNumberInput(Show1dec);$("#primary_end_date").jqxTooltip({content:"De eind datum van de hoofdvergisting en eventueel overhevelen."});$("#primary_end_date").jqxDateTimeInput(Dateopts);$("#primary_end_date").on("close",function(i){aU()});$("#secondary_temp").jqxNumberInput(YeastT);$("#secondary_end_sg").jqxTooltip({content:"Het gemeten SG aan het eind van de navergisting."});$("#secondary_end_sg").jqxNumberInput(SGopts);$("#secondary_end_brix").jqxTooltip({content:"Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer."});$("#secondary_end_brix").jqxNumberInput(Spin1dec);$("#secondary_svg").jqxTooltip({content:"De schijnbare vergisting graad behaald na de nagisting."});$("#secondary_svg").jqxNumberInput(Show1dec);$("#secondary_end_date").jqxTooltip({content:"De eind datum van de navergisting en het begin van het lageren."});$("#secondary_end_date").jqxDateTimeInput(Dateopts);$("#secondary_end_date").on("close",function(i){aU()});$("#tertiary_temp").jqxNumberInput(YeastT);$("#fg").jqxNumberInput(Spin3dec);$("#est_fg3").jqxTooltip({content:"Het verwachte eind SG. Dit wordt automatisch berekend."});$("#est_fg3").jqxNumberInput(Show3dec);$("#final_brix").jqxTooltip({content:"Hulpfinctie: de afgelezen &deg;Brix RI waarde met een refractometer."});$("#final_brix").jqxNumberInput(Spin1dec);$("#final_abv").jqxNumberInput(Show2dec);$("#final_svg").jqxNumberInput(Show1dec);$("#FLog").jqxButton({template:"info",width:"150px",theme:theme});$("#FLog").click(function(){window.open("log_fermentation.php?code="+d.code+"&name="+d.name)});$("#package_date").jqxTooltip({content:"De verpakkings datum van dit bier."});$("#package_date").jqxDateTimeInput(Dateopts);$("#package_date").on("close",function(i){aU()});$("#package_volume").jqxTooltip({content:"Het beschikbare volume om te bottelen of op fust te zetten."});$("#package_volume").jqxNumberInput(Spin1dec);$("#package_infuse_amount").jqxTooltip({content:"De hoeveelheid water of drank extra toe te voegen."});$("#package_infuse_amount").jqxNumberInput(Spin3dec);$("#package_infuse_abv").jqxTooltip({content:"De hoeveelheid alcohol in de drank, of 0.0 als het water is."});$("#package_infuse_abv").jqxNumberInput(Spin1dec);$("#package_infuse_notes").jqxTooltip({content:"Omschrijving van de extra toevoeging."});$("#package_infuse_notes").jqxInput({theme:theme,width:640,height:23});$("#package_abv").jqxTooltip({content:"De uiteindelijke hoeveelheid alcohol volume %."});$("#package_abv").jqxNumberInput(Show2dec);$("#package_ph").jqxTooltip({content:"De gemeten pH vlak voor het verpakken."});$("#package_ph").jqxNumberInput(SpinpH);$("#st_carb_min2").jqxTooltip({content:"Het minimum aanbevolen koolzuur volume voor deze bierstijl."});$("#st_carb_min2").jqxNumberInput(Smal1dec);$("#st_carb_max2").jqxTooltip({content:"Het maximum aamnevolen koolzuur volume voor deze bierstijl."});$("#st_carb_max2").jqxNumberInput(Smal1dec);$("#bottle_amount").jqxTooltip({content:"De totale hoeveelheid te bottelen bier."});$("#bottle_amount").jqxNumberInput(Spin1dec);$("#keg_amount").jqxTooltip({content:"De totale hoeveelheid op fust te zetten bier."});$("#keg_amount").jqxNumberInput(Spin1dec);$("#bottle_carbonation").jqxTooltip({content:"Het gewenste CO2 volume in de flessen."});$("#bottle_carbonation").jqxNumberInput(Spin2dec);$("#bottle_carbonation").jqxNumberInput({max:5});$("#keg_carbonation").jqxTooltip({content:"Het gewenste CO2 volume door de suiker in de fusten."});$("#keg_carbonation").jqxNumberInput(Spin2dec);$("#keg_carbonation").jqxNumberInput({max:5});$("#bottle_priming_sugar").jqxDropDownList({placeHolder:"Kies suiker:",theme:theme,source:fermentablesugars,displayMember:"name",width:200,height:23,dropDownWidth:300,dropDownHeight:400});$("#bottle_priming_sugar").on("select",function(a6){if(a6.args){var a8,a2,a5=-1,a4,a7,a3,a9={};a2=a6.args.index;a4=fermentablesugars.records[a2];a7=$("#fermentableGrid").jqxGrid("getrows");for(a3=0;a3<a7.length;a3++){if(a7[a3].f_added==4){a5=a3}}a9.f_name=a4.name;a9.f_origin=a4.origin;a9.f_supplier=a4.supplier;a9.f_amount=parseFloat($("#bottle_priming_total").jqxNumberInput("decimal"))/1000;a9.f_cost=a4.cost;a9.f_type=a4.type;a9.f_yield=a4.yield;a9.f_color=a4.color;a9.f_coarse_fine_diff=a4.coarse_fine_diff;a9.f_moisture=a4.moisture;a9.f_diastatic_power=a4.diastatic_power;a9.f_protein=a4.protein;a9.f_max_in_batch=a4.max_in_batch;a9.f_graintype=a4.graintype;a9.f_added=4;a9.f_dissolved_protein=a4.dissolved_protein;a9.f_recommend_mash=a4.recommend_mash;a9.f_add_after_boil=1;a9.f_adjust_to_total_100=0;a9.f_percentage=0;a9.f_di_ph=a4.di_ph;a9.f_acid_to_ph_57=a4.acid_to_ph_57;a9.f_inventory=a4.inventory;if(a5>=0){a8=$("#fermentableGrid").jqxGrid("getrowid",a5);$("#fermentableGrid").jqxGrid("updaterow",a8,a9)}else{$("#fermentableGrid").jqxGrid("addrow",null,a9)}aR()}});$("#keg_priming_sugar").jqxDropDownList({placeHolder:"Kies suiker:",theme:theme,source:fermentablesugars,displayMember:"name",width:200,height:23,dropDownWidth:300,dropDownHeight:400});$("#keg_priming_sugar").on("select",function(a6){if(a6.args){var a8,a2,a5=-1,a4,a7,a3,a9={};a2=a6.args.index;a4=fermentablesugars.records[a2];a7=$("#fermentableGrid").jqxGrid("getrows");for(a3=0;a3<a7.length;a3++){if(a7[a3].f_added==5){a5=a3}}a9.f_name=a4.name;a9.f_origin=a4.origin;a9.f_supplier=a4.supplier;a9.f_amount=parseFloat($("#keg_priming_total").jqxNumberInput("decimal"))/1000;a9.f_cost=a4.cost;a9.f_type=a4.type;a9.f_yield=a4.yield;a9.f_color=a4.color;a9.f_coarse_fine_diff=a4.coarse_fine_diff;a9.f_moisture=a4.moisture;a9.f_diastatic_power=a4.diastatic_power;a9.f_protein=a4.protein;a9.f_max_in_batch=a4.max_in_batch;a9.f_graintype=a4.graintype;a9.f_added=5;a9.f_dissolved_protein=a4.dissolved_protein;a9.f_recommend_mash=a4.recommend_mash;a9.f_add_after_boil=1;a9.f_adjust_to_total_100=0;a9.f_percentage=0;a9.f_di_ph=a4.di_ph;a9.f_acid_to_ph_57=a4.acid_to_ph_57;a9.f_inventory=a4.inventory;if(a5>=0){a8=$("#fermentableGrid").jqxGrid("getrowid",a5);$("#fermentableGrid").jqxGrid("updaterow",a8,a9)}else{$("#fermentableGrid").jqxGrid("addrow",null,a9)}aR()}});$("#bottle_priming_amount").jqxNumberInput(Show1dec);$("#bottle_priming_water").jqxTooltip({content:"De hoeveelheid water om de suiker op te lossen."});$("#bottle_priming_water").jqxNumberInput(Spin3dec);$("#keg_priming_amount").jqxNumberInput(Show1dec);$("#keg_priming_water").jqxTooltip({content:"De hoeveelheid water om de suiker op te lossen."});$("#keg_priming_water").jqxNumberInput(Spin3dec);$("#bottle_priming_total").jqxNumberInput(Show1dec);$("#bottle_pressure").jqxTooltip({content:"De maximaal te verwachten druk tijdens het hergisten."});$("#bottle_pressure").jqxNumberInput(Show1dec);$("#keg_priming_total").jqxNumberInput(Show1dec);$("#keg_forced_carb").jqxCheckBox({theme:theme,width:120,height:23});$("#keg_pressure").jqxNumberInput(Show1dec);$("#bottle_abv").jqxNumberInput(Show2dec);$("#keg_abv").jqxNumberInput(Show2dec);$("#bottle_carbonation_temp").jqxNumberInput(YeastT);$("#keg_carbonation_temp").jqxNumberInput(YeastT);$("#taste_date").jqxTooltip({content:"De proef datum van dit bier."});$("#taste_date").jqxDateTimeInput(Dateopts);$("#taste_date").on("close",function(i){aU()});$("#taste_rate").jqxTooltip({content:"Het cijfer voor dit bier van 1 tot 10."});$("#taste_rate").jqxNumberInput(Spin1dec);$("#taste_rate").jqxNumberInput({max:10});$("#taste_color").jqxTooltip({content:"De kleur van het bier."});$("#taste_color").jqxInput({theme:theme,width:320,height:23});$("#taste_transparency").jqxTooltip({content:"De helderheid van het bier."});$("#taste_transparency").jqxInput({theme:theme,width:320,height:23});$("#taste_head").jqxTooltip({content:"Het schuim op het bier."});$("#taste_head").jqxInput({theme:theme,width:320,height:23});$("#taste_aroma").jqxTooltip({content:"Het aroma van het bier."});$("#taste_aroma").jqxInput({theme:theme,width:960,height:23});$("#taste_taste").jqxTooltip({content:"De smaak van het bier."});$("#taste_taste").jqxInput({theme:theme,width:960,height:23});$("#taste_aftertaste").jqxTooltip({content:"De nasmaak van het bier."});$("#taste_aftertaste").jqxInput({theme:theme,width:960,height:23});$("#taste_mouthfeel").jqxTooltip({content:"Het mondgevoelvan het bier."});$("#taste_mouthfeel").jqxInput({theme:theme,width:960,height:23});$("#taste_notes").jqxTooltip({content:"Het oordeel en opmerkingen over dit bier."});$("#taste_notes").jqxInput({theme:theme,width:960,height:100});$("#jqxTabs").jqxTabs({theme:theme,width:1280,height:660,autoHeight:false,position:"top"});$("#Export").jqxButton({template:"info",width:"80px",theme:theme});$("#Export").bind("click",function(){s();window.location.href="prod_export.php?record="+my_record+"&return="+my_return+"&select="+my_select+"&code="+d.code+"&name="+d.name});$("#Delete").jqxButton({template:"danger",width:"80px",theme:theme});$("#Delete").bind("click",function(){$("#eventWindow").jqxWindow("open");$("#delOk").click(function(){var i="delete=true&"+$.param({uuid:d.uuid});$.ajax({dataType:"json",url:E,cache:false,data:i,type:"POST",success:function(a3,a2,a4){window.location.href=my_return},error:function(a2,a4,a3){}})})});$("#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(){s();window.location.href=my_return});createDelElements()});
\ No newline at end of file
--- a/www/js/prod_edit.js	Wed Sep 11 15:58:32 2019 +0200
+++ b/www/js/prod_edit.js	Thu Sep 12 15:50:09 2019 +0200
@@ -21,6018 +21,6030 @@
  *****************************************************************************/
 
 
-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 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 i,
-	to_100 = false,		// Fermentables adjust to 100%
-	preboil_sg = 0,
-	aboil_sg = 0,
-	est_mash_sg = 0,
-	psugar = 0,		// Percentage real sugars
-	pcara = 0,		// Percentage cara/crystal malts
-	svg = 77,               // Default attenuation
-        mashkg = 0,             // Malt in mash weight
-	pitchrate = 0.75,	// Yeast pitch rate default
-	initcells = 0,		// Initial yeast cell count
-
-	ok_fermentables = 1,	// Fermentables are in stock
-	ok_hops = 1,		// Hops are in stock
-	ok_miscs = 1,		// Miscs are in stock
-	ok_yeasts = 1,		// Yeasts are in stock
-	ok_waters = 1,		// Waters are in stock
-
-        hop_flavour = 0,
-        hop_aroma = 0,
-        mash_infuse = 0,
-        last_base = '',
-        last_acid = '',
-
-        MMCa = 40.048,
-        MMMg = 24.305,
-        MMNa = 22.98976928,
-        MMCl = 35.453,
-        MMSO4 = 96.0626,
-        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,
-
-	fermentableRow = 0,
-	fermentableData = {},
-	fermentableInit = 1,
-	hopRow = 0,
-	hopData = {},
-	miscRow = 0,
-	miscData = {},
-	yeastRow = 0,
-	yeastData = {},
-	mashRow = 0,
-	mashData = {},
-	Ka1 = 0.0000004445,
-	Ka2 = 0.0000000000468,
-	dataRecord = {},
-	url = "includes/db_product.php",
-
-	// Prepare the data
-	source = {
-		datatype: "json",
-		cache: false,
-		datafields: [
-			// From prod_main
-			{ name: 'record', type: 'number' },
-			{ name: 'uuid', type: 'string' },
-			{ name: 'name', type: 'string' },
-			{ name: 'code', type: 'string' },
-			{ name: 'birth', type: 'string' },
-			{ name: 'stage', type: 'int' },
-			{ name: 'notes', type: 'string' },
-			{ name: 'log_brew', type: 'int' },
-			{ name: 'log_fermentation', type: 'int' },
-			{ name: 'inventory_reduced', type: 'int' },
-			{ name: 'locked', type: 'int' },
-			{ name: 'eq_name', type: 'string' },
-			{ name: 'eq_boil_size', type: 'float' },
-			{ name: 'eq_batch_size', type: 'float' },
-			{ name: 'eq_tun_volume', type: 'float' },
-			{ name: 'eq_tun_weight', type: 'float' },
-			{ name: 'eq_tun_specific_heat', type: 'float' },
-			{ name: 'eq_tun_material', type: 'int' },
-			{ name: 'eq_tun_height', type: 'float' },
-			{ name: 'eq_top_up_water', type: 'float' },
-			{ name: 'eq_trub_chiller_loss', type: 'float' },
-			{ name: 'eq_evap_rate', type: 'float' },
-			{ name: 'eq_boil_time', type: 'float' },
-			{ name: 'eq_calc_boil_volume', type: 'int' },
-			{ name: 'eq_top_up_kettle', type: 'float' },
-			{ name: 'eq_hop_utilization', type: 'float' },
-			{ name: 'eq_notes', type: 'string' },
-			{ name: 'eq_lauter_volume', type: 'float' },
-			{ name: 'eq_lauter_height', type: 'float' },
-			{ name: 'eq_lauter_deadspace', type: 'float' },
-			{ name: 'eq_kettle_volume', type: 'float' },
-		        { name: 'eq_kettle_height', type: 'float' },
-			{ name: 'eq_mash_volume', type: 'float' },
-			{ name: 'eq_mash_max', type: 'float' },
-			{ name: 'eq_efficiency', type: 'float' },
-			{ name: 'brew_date_start', type: 'string' },
-			{ name: 'brew_mash_ph', type: 'float' },
-			{ name: 'brew_mash_sg', type: 'float' },
-			{ name: 'brew_mash_efficiency', type: 'float' },
-			{ name: 'brew_sparge_est', type: 'float' },
-			{ name: 'brew_sparge_ph', type: 'float' },
-			{ name: 'brew_preboil_volume', type: 'float' },
-			{ name: 'brew_preboil_sg', type: 'float' },
-			{ name: 'brew_preboil_ph', type: 'float' },
-			{ name: 'brew_preboil_efficiency', type: 'float' },
-			{ name: 'brew_aboil_volume', type: 'float' },
-			{ name: 'brew_aboil_sg', type: 'float' },
-			{ name: 'brew_aboil_ph', type: 'float' },
-			{ name: 'brew_aboil_efficiency', type: 'float' },
-			{ name: 'brew_cooling_method', type: 'int' },
-			{ name: 'brew_cooling_time', type: 'float' },
-			{ name: 'brew_cooling_to', type: 'float' },
-			{ name: 'brew_whirlpool9', type: 'float' },
-			{ name: 'brew_whirlpool7', type: 'float' },
-			{ name: 'brew_whirlpool6', type: 'float' },
-			{ name: 'brew_whirlpool2', type: 'float' },
-			{ name: 'brew_fermenter_volume', type: 'float' },
-			{ name: 'brew_fermenter_extrawater', type: 'float' },
-			{ name: 'brew_fermenter_tcloss', type: 'float' },
-			{ name: 'brew_aeration_time', type: 'float' },
-			{ name: 'brew_aeration_speed', type: 'float' },
-			{ name: 'brew_aeration_type', type: 'int' },
-			{ name: 'brew_fermenter_sg', type: 'float' },
-			{ name: 'brew_fermenter_ibu', type: 'float' },
-			{ name: 'brew_fermenter_color', type: 'float' },
-			{ name: 'brew_date_end', type: 'string' },
-			{ name: 'og', type: 'float' },
-			{ name: 'fg', type: 'float' },
-			{ name: 'primary_start_temp', type: 'float' },
-			{ name: 'primary_max_temp', type: 'float' },
-			{ name: 'primary_end_temp', type: 'float' },
-			{ name: 'primary_end_sg', type: 'float' },
-			{ name: 'primary_end_date', type: 'string' },
-			{ name: 'secondary_temp', type: 'float' },
-			{ name: 'secondary_end_sg', type: 'float' },
-			{ name: 'secondary_end_date', type: 'string' },
-			{ name: 'tertiary_temp', type: 'float' },
-			{ name: 'package_date', type: 'string' },
-			{ name: 'package_volume', type: 'float' },
-			{ name: 'package_infuse_amount', type: 'float' },
-			{ name: 'package_infuse_abv', type: 'float' },
-			{ name: 'package_infuse_notes', type: 'string' },
-			{ name: 'package_abv', type: 'float' },
-			{ name: 'package_ph', type: 'float' },
-			{ name: 'bottle_amount', type: 'float' },
-			{ name: 'bottle_carbonation', type: 'float' },
-			{ name: 'bottle_priming_water', type: 'float' },
-			{ name: 'bottle_priming_amount', type: 'float' },
-			{ name: 'bottle_carbonation_temp', type: 'float' },
-			{ name: 'keg_amount', type: 'float' },
-			{ name: 'keg_carbonation', type: 'float' },
-			{ name: 'keg_priming_water', type: 'float' },
-			{ name: 'keg_priming_amount', type: 'float' },
-			{ name: 'keg_carbonation_temp', type: 'float' },
-			{ name: 'keg_forced_carb', type: 'int' },
-			{ name: 'keg_pressure', type: 'float' },
-			{ name: 'taste_notes', type: 'string' },
-			{ name: 'taste_rate', type: 'float' },
-			{ name: 'taste_date', type: 'string' },
-			{ name: 'taste_color', type: 'string' },
-			{ name: 'taste_transparency', type: 'string' },
-			{ name: 'taste_head', type: 'string' },
-			{ name: 'taste_aroma', type: 'string' },
-			{ name: 'taste_taste', type: 'string' },
-			{ name: 'taste_mouthfeel', type: 'string' },
-			{ name: 'taste_aftertaste', type: 'string' },
-			{ name: 'st_name', type: 'string' },
-			{ name: 'st_letter', type: 'string' },
-			{ name: 'st_guide', type: 'string' },
-			{ name: 'st_category', type: 'string' },
-			{ name: 'st_category_number', type: 'float' },
-			{ name: 'st_type', type: 'int' },
-			{ 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: '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: 'starter_enable', type: 'int' },
-			{ name: 'starter_type', type: 'int' },
-			{ name: 'starter_sg', type: 'float' },
-			{ name: 'starter_viability', type: 'int' },
-			{ name: 'prop1_type', type: 'int' },
-			{ name: 'prop1_volume', type: 'float' },
-			{ name: 'prop2_type', type: 'int' },
-			{ name: 'prop2_volume', type: 'float' },
-			{ name: 'prop3_type', type: 'int' },
-			{ name: 'prop3_volume', type: 'float' },
-			{ name: 'prop4_type', type: 'int' },
-			{ name: 'prop4_volume', type: 'float' },
-			{ 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);
-			$("#code").val(dataRecord.code);
-			$("#birth").val(dataRecord.birth);
-			$("#stage").val(StageData[dataRecord.stage].nl);
-			$("#notes").val(dataRecord.notes);
-			$("#locked").val(dataRecord.locked);
-			$("#eq_name").val(dataRecord.eq_name);
-			$("#eq_notes").val(dataRecord.eq_notes);
-			$("#eq_boil_size").val(dataRecord.eq_boil_size);
-			$("#eq_batch_size").val(dataRecord.eq_batch_size);
-			$("#eq_tun_volume").val(dataRecord.eq_tun_volume);
-			$("#eq_top_up_water").val(dataRecord.eq_top_up_water);
-			$("#eq_trub_chiller_loss").val(dataRecord.eq_trub_chiller_loss);
-			$("#eq_evap_rate").val(dataRecord.eq_evap_rate);
-			$("#eq_boil_time").val(dataRecord.eq_boil_time);
-			$("#eq_top_up_kettle").val(dataRecord.eq_top_up_kettle);
-			$("#eq_hop_utilization").val(dataRecord.eq_hop_utilization);
-			$("#eq_lauter_volume").val(dataRecord.eq_lauter_volume);
-			$("#eq_lauter_deadspace").val(dataRecord.eq_lauter_deadspace);
-			$("#eq_kettle_volume").val(dataRecord.eq_kettle_volume);
-			$("#eq_mash_volume").val(dataRecord.eq_mash_volume);
-			$("#eq_mash_max").val(dataRecord.eq_mash_max);
-			$("#eq_efficiency").val(dataRecord.eq_efficiency);
-			// Brewdate
-			$("#brew_date_start").val(dataRecord.brew_date_start);
-			$("#brew_mash_ph").val(dataRecord.brew_mash_ph);
-			$("#brew_mash_sg").val(dataRecord.brew_mash_sg);
-			$("#brew_mash_efficiency").val(dataRecord.brew_mash_efficiency);
-			// Header Spoelen en filteren
-			$("#brew_sparge_temperature").val(dataRecord.sparge_temp);
-			$("#brew_sparge_volume").val(dataRecord.sparge_volume);
-			$("#brew_sparge_est").val(dataRecord.brew_sparge_est);
-			$("#brew_sparge_ph").val(dataRecord.brew_sparge_ph);
-			// Header Beluchten
-			$("#brew_aeration_type").val(dataRecord.brew_aeration_type);
-			$("#brew_aeration_time").val(dataRecord.brew_aeration_time);
-			$("#brew_aeration_speed").val(dataRecord.brew_aeration_speed);
-
-			$("#brew_preboil_ph").val(dataRecord.brew_preboil_ph);
-			$("#brew_preboil_sg").val(dataRecord.brew_preboil_sg);
-			$("#brew_preboil_volume").val(dataRecord.brew_preboil_volume);
-			$("#brew_preboil_efficiency").val(dataRecord.brew_preboil_efficiency);
-			// Header Koelen en whirlpoolen
-			$("#brew_whirlpool9").val(dataRecord.brew_whirlpool9);
-			$("#brew_whirlpool7").val(dataRecord.brew_whirlpool7);
-			$("#brew_whirlpool6").val(dataRecord.brew_whirlpool6);
-			$("#brew_whirlpool2").val(dataRecord.brew_whirlpool2);
-			// Header Naar gistvat
-			$("#brew_fermenter_volume").val(dataRecord.brew_fermenter_volume);
-			$("#brew_fermenter_sg").val(dataRecord.brew_fermenter_sg);
-			$("#brew_fermenter_sg2").val(dataRecord.brew_fermenter_sg);
-			$("#brew_fermenter_ibu").val(dataRecord.brew_fermenter_ibu);
-			$("#brew_fermenter_color").val(dataRecord.brew_fermenter_color);
-			$("#brew_fermenter_extrawater").val(dataRecord.brew_fermenter_extrawater);
-			$("#brew_fermenter_tcloss").val(dataRecord.brew_fermenter_tcloss);
-
-			$("#brew_aboil_ph").val(dataRecord.brew_aboil_ph);
-			$("#brew_aboil_sg").val(dataRecord.brew_aboil_sg);
-			$("#brew_aboil_volume").val(dataRecord.brew_aboil_volume);
-			$("#brew_aboil_efficiency").val(dataRecord.brew_aboil_efficiency);
-			// Header Koelen en whirlpoolen
-			$("#brew_cooling_to").val(dataRecord.brew_cooling_to);
-			$("#brew_cooling_method").val(dataRecord.brew_cooling_method);
-			$("#brew_cooling_time").val(dataRecord.brew_cooling_time);
-			// Niks
-			$("#brew_date_end").val(dataRecord.brew_date_end);
-			$("#og").val(dataRecord.og);
-			$("#fg").val(dataRecord.fg);
-			$("#primary_start_temp").val(dataRecord.primary_start_temp);
-			$("#primary_max_temp").val(dataRecord.primary_max_temp);
-			$("#primary_end_temp").val(dataRecord.primary_end_temp);
-			$("#primary_end_sg").val(dataRecord.primary_end_sg);
-			$("#primary_end_date").val(dataRecord.primary_end_date);
-			$("#secondary_temp").val(dataRecord.secondary_temp);
-			$("#secondary_end_sg").val(dataRecord.secondary_end_sg);
-			$("#secondary_end_date").val(dataRecord.secondary_end_date);
-			$("#tertiary_temp").val(dataRecord.tertiary_temp);
-			$("#package_date").val(dataRecord.package_date);
-			$("#package_volume").val(dataRecord.package_volume);
-			$("#package_infuse_amount").val(dataRecord.package_infuse_amount);
-			$("#package_infuse_abv").val(dataRecord.package_infuse_abv);
-			$("#package_infuse_notes").val(dataRecord.package_infuse_notes);
-			$("#package_abv").val(dataRecord.package_abv);
-			$("#package_ph").val(dataRecord.package_ph);
-			$("#bottle_amount").val(dataRecord.bottle_amount);
-			$("#bottle_carbonation").val(dataRecord.bottle_carbonation);
-			$("#bottle_priming_water").val(dataRecord.bottle_priming_water);
-			$("#bottle_priming_amount").val(dataRecord.bottle_priming_amount);
-			$("#bottle_carbonation_temp").val(dataRecord.bottle_carbonation_temp);
-			$("#keg_amount").val(dataRecord.keg_amount);
-			$("#keg_carbonation").val(dataRecord.keg_carbonation);
-			$("#keg_priming_water").val(dataRecord.keg_priming_water);
-			$("#keg_priming_amount").val(dataRecord.keg_priming_amount);
-			$("#keg_carbonation_temp").val(dataRecord.keg_carbonation_temp);
-			$("#keg_forced_carb").val(dataRecord.keg_forced_carb);
-			$("#keg_pressure").val(dataRecord.keg_pressure);
-			$("#taste_notes").val(dataRecord.taste_notes);
-			$("#taste_rate").val(dataRecord.taste_rate);
-			$("#taste_date").val(dataRecord.taste_date);
-			$("#taste_color").val(dataRecord.taste_color);
-			$("#taste_transparency").val(dataRecord.taste_transparency);
-			$("#taste_head").val(dataRecord.taste_head);
-			$("#taste_aroma").val(dataRecord.taste_aroma);
-			$("#taste_taste").val(dataRecord.taste_taste);
-			$("#taste_mouthfeel").val(dataRecord.taste_mouthfeel);
-			$("#taste_aftertaste").val(dataRecord.taste_aftertaste);
-
-			// Recipe
-			$("#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);
-			$("#st_og_min").val(dataRecord.st_og_min);
-			$("#st_og_max").val(dataRecord.st_og_max);
-			$("#st_fg_min").val(dataRecord.st_fg_min);
-			$("#st_fg_max").val(dataRecord.st_fg_max);
-			$("#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);
-			$("#st_ibu_min").val(dataRecord.st_ibu_min);
-			$("#st_ibu_max").val(dataRecord.st_ibu_max);
-			$("#st_carb_min").val(dataRecord.st_carb_min);
-			$("#st_carb_min2").val(dataRecord.st_carb_min);
-			$("#st_carb_max").val(dataRecord.st_carb_max);
-			$("#st_carb_max2").val(dataRecord.st_carb_max);
-			$("#type").val(dataRecord.type);
-			$("#batch_size").val(dataRecord.batch_size);
-			$("#est_a_vol").val(dataRecord.batch_size * 1.04);
-			$("#boil_size").val(dataRecord.boil_size);
-			$("#est_pre_vol").val(dataRecord.boil_size * 1.04);
-			$("#boil_time").val(dataRecord.boil_time);
-			$("#efficiency").val(dataRecord.efficiency);
-			$("#est_og").val(dataRecord.est_og);
-			$("#est_og2").val(dataRecord.est_og);
-			$("#est_og3").val(0);
-			$("#est_fg").val(dataRecord.est_fg);
-			$("#est_fg2").val(dataRecord.est_fg);
-			$("#est_fg3").val(dataRecord.est_fg);
-			$("#est_color").val(dataRecord.est_color);
-			$("#est_color2").val(dataRecord.est_color);
-			$("#est_abv").val(dataRecord.est_abv);
-			$("#color_method").val(dataRecord.color_method);
-			$("#est_ibu").val(dataRecord.est_ibu);
-			$("#est_ibu2").val(dataRecord.est_ibu);
-			$("#ibu_method").val(dataRecord.ibu_method);
-			$("#est_carb").val(dataRecord.est_carb);
-			$("#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);
-			$("#starter_enable").val(dataRecord.starter_enable);
-			$("#starter_type").val(dataRecord.starter_type);
-			$("#starter_sg").val(dataRecord.starter_sg);
-			$("#starter_viability").val(dataRecord.starter_viability);
-			$("#prop1_type").val(dataRecord.prop1_type);
-			$("#prop1_volume").val(dataRecord.prop1_volume);
-			$("#prop2_type").val(dataRecord.prop2_type);
-			$("#prop2_volume").val(dataRecord.prop2_volume);
-			$("#prop3_type").val(dataRecord.prop3_type);
-			$("#prop3_volume").val(dataRecord.prop3_volume);
-			$("#prop4_type").val(dataRecord.prop4_type);
-			$("#prop4_volume").val(dataRecord.prop4_volume);
-			editFermentable(dataRecord);
-			editHop(dataRecord);
-                        editMisc(dataRecord);
-                        editYeast(dataRecord);
-                        editMash(dataRecord);
-			calcStage();
-			$('#jqxTabs').jqxTabs('select', 2);
-		},
-		loadError: function (jqXHR, status, error) {
-		},
-                beforeLoadComplete: function (records) {
-                        $('#jqxLoader').jqxLoader('open');
-                }
-	}),
-
-        // 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);
-
-                $("#fermentableGrid").jqxGrid({
-                        width: 1240,
-                        height: 470,
-                        source: fermentableAdapter,
-                        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="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",
-					disabled: (dataRecord.stage > 3),
-                                        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["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;
-                                                $("#fermentableGrid").jqxGrid('addrow', null, row);
-                                        }
-                                });
-
-                                $("#finstockbutton").jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
-                                $("#finstockbutton").on('change', function (event) {
-                                        fermentableinstock = event.args.checked;
-                                        fermentablelist.dataBind();
-                                });
-
-                                // delete selected fermentable.
-                                $("#fdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
-                                $("#fdeleterowbutton").on('click', function () {
-					var rowscount, id, percent, amount, i, rowdata,
-                                        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, defaultvalue, 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', 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: 'Voorraad Kg', datafield: 'f_inventory', width: 120, align: 'right',
-				  cellsrenderer:  function (row, columnfield, value, defaulthtml, columnproperties, rowdata) {
-					var color = '#ffffff';
-					if (((dataRecord.inventory_reduced <= 2) && (rowdata.f_added <= 1)) ||	// Mash or boil
-					    ((dataRecord.inventory_reduced <= 3) && (rowdata.f_added == 2)) ||	// Primary
-					    ((dataRecord.inventory_reduced <= 5) && (rowdata.f_added == 3)) ||	// Secondary or Tertiary
-					    ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 4)) ||	// Bottle
-					    ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 5))) {	// Kegs
-						if (value < rowdata.f_amount)
-							color = '#ff4040';
-						return  '<span style="margin: 4px; margin-top: 6px; float: right; color: ' +
-							color + ';">' +fermentableAdapter.formatNumber(value, "f3") + '</span>';
-					} else {
-						return  '<span></span>';
-					}
-				  }
-				},
-                                { text: 'Procent', datafield: 'f_percentage', width: 90, align: 'right',
-				  cellsrenderer:  function (row, columnfield, value, defaulthtml, columnproperties, rowdata) {
-					if (rowdata.f_added >= 4)
-						return '<span></span>';
-					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%', datafield: 'f_adjust_to_total_100', width: 70, align: 'center', cellsalign: 'center',
-				  cellsrenderer:  function (index, datafield, value, defaultvalue, column, rowdata) {
-					if (value == 0)
-						return '<span></span>';
-					return  '<span><img style="float:left; margin-left:25px; margin-top:4px;" src="images/dialog-ok-apply.png"></span>';
-				  }
-				},
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-					}, buttonclick: function (row) {
-						fermentableRow = row;
-						fermentableData = $("#fermentableGrid").jqxGrid('getrowdata', fermentableRow);
-						if (fermentableData.f_added >= 4) {
-							alert("Wijzig dit in de Verpakken tab");
-						} else if (dataRecord.stage > 3) {
-							alert("Ingredieënt is al verwerkt.");
-						} else {
-							$("#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');
-						}
-					}
-				}
-                        ]
-                });
-        },
-
-        // Inline hops editor
-        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);
-
-                $("#hopGrid").jqxGrid({
-                        width: 1240,
-                        height: 560,
-                        source: hopAdapter,
-                        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="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,
-					disabled: (dataRecord.stage > 3),
-                                        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 + " / " + HopFormData[datarecord.form].nl +
-							" (" + 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');
-                                });
-
-                                $("#hinstockbutton").jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
-                                $("#hinstockbutton").on('change', function (event) {
-                                        hopinstock = event.args.checked;
-                                        hoplist.dataBind();
-                                });
-
-                                // delete selected hop.
-                                $("#hdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
-                                $("#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) {
-					if (((dataRecord.inventory_reduced <= 2) && (rowdata.h_useat <= 4)) ||  // Mash, FW, Boil, Aroma, Whirlpool
-                                            ((dataRecord.inventory_reduced <= 6) && (rowdata.h_useat == 5))) {	// Dry hop
-						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>';
-					} else {
-						return '<span></span>';
-					}
-				  }
-				},
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-					}, buttonclick: function (row) {
-						if (dataRecord.stage > 3) {
-                                                        alert("Ingredieënt is al verwerkt.");
-                                                } else {
-							console.log("edit button row "+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');
-						}
-					}
-				}
-                        ]
-                });
-        },
-
-        // Inline miscs editor
-        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 row, i, 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) {
+$(document).ready(function() {
+
+ var i,
+ to_100 = false,      // Fermentables adjust to 100%
+ preboil_sg = 0,
+ aboil_sg = 0,
+ est_mash_sg = 0,
+ psugar = 0,          // Percentage real sugars
+ pcara = 0,           // Percentage cara/crystal malts
+ svg = 77,            // Default attenuation
+ mashkg = 0,          // Malt in mash weight
+ pitchrate = 0.75,    // Yeast pitch rate default
+ initcells = 0,       // Initial yeast cell count
+
+ ok_fermentables = 1, // Fermentables are in stock
+ ok_hops = 1,         // Hops are in stock
+ ok_miscs = 1,        // Miscs are in stock
+ ok_yeasts = 1,       // Yeasts are in stock
+ ok_waters = 1,       // Waters are in stock
+
+ hop_flavour = 0,
+ hop_aroma = 0,
+ mash_infuse = 0,
+ last_base = '',
+ last_acid = '',
+
+ MMCa = 40.048,
+ MMMg = 24.305,
+ MMNa = 22.98976928,
+ MMCl = 35.453,
+ MMSO4 = 96.0626,
+ 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,
+
+ fermentableRow = 0,
+ fermentableData = {},
+ fermentableInit = 1,
+ hopRow = 0,
+ hopData = {},
+ miscRow = 0,
+ miscData = {},
+ yeastRow = 0,
+ yeastData = {},
+ mashRow = 0,
+ mashData = {},
+ Ka1 = 0.0000004445,
+ Ka2 = 0.0000000000468,
+ dataRecord = {},
+ url = 'includes/db_product.php',
+
+ // Prepare the data
+ source = {
+  datatype: 'json',
+  cache: false,
+  datafields: [
+   // From prod_main
+   { name: 'record', type: 'number' },
+   { name: 'uuid', type: 'string' },
+   { name: 'name', type: 'string' },
+   { name: 'code', type: 'string' },
+   { name: 'birth', type: 'string' },
+   { name: 'stage', type: 'int' },
+   { name: 'notes', type: 'string' },
+   { name: 'log_brew', type: 'int' },
+   { name: 'log_fermentation', type: 'int' },
+   { name: 'inventory_reduced', type: 'int' },
+   { name: 'locked', type: 'int' },
+   { name: 'eq_name', type: 'string' },
+   { name: 'eq_boil_size', type: 'float' },
+   { name: 'eq_batch_size', type: 'float' },
+   { name: 'eq_tun_volume', type: 'float' },
+   { name: 'eq_tun_weight', type: 'float' },
+   { name: 'eq_tun_specific_heat', type: 'float' },
+   { name: 'eq_tun_material', type: 'int' },
+   { name: 'eq_tun_height', type: 'float' },
+   { name: 'eq_top_up_water', type: 'float' },
+   { name: 'eq_trub_chiller_loss', type: 'float' },
+   { name: 'eq_evap_rate', type: 'float' },
+   { name: 'eq_boil_time', type: 'float' },
+   { name: 'eq_calc_boil_volume', type: 'int' },
+   { name: 'eq_top_up_kettle', type: 'float' },
+   { name: 'eq_hop_utilization', type: 'float' },
+   { name: 'eq_notes', type: 'string' },
+   { name: 'eq_lauter_volume', type: 'float' },
+   { name: 'eq_lauter_height', type: 'float' },
+   { name: 'eq_lauter_deadspace', type: 'float' },
+   { name: 'eq_kettle_volume', type: 'float' },
+   { name: 'eq_kettle_height', type: 'float' },
+   { name: 'eq_mash_volume', type: 'float' },
+   { name: 'eq_mash_max', type: 'float' },
+   { name: 'eq_efficiency', type: 'float' },
+   { name: 'brew_date_start', type: 'string' },
+   { name: 'brew_mash_ph', type: 'float' },
+   { name: 'brew_mash_sg', type: 'float' },
+   { name: 'brew_mash_efficiency', type: 'float' },
+   { name: 'brew_sparge_est', type: 'float' },
+   { name: 'brew_sparge_ph', type: 'float' },
+   { name: 'brew_preboil_volume', type: 'float' },
+   { name: 'brew_preboil_sg', type: 'float' },
+   { name: 'brew_preboil_ph', type: 'float' },
+   { name: 'brew_preboil_efficiency', type: 'float' },
+   { name: 'brew_aboil_volume', type: 'float' },
+   { name: 'brew_aboil_sg', type: 'float' },
+   { name: 'brew_aboil_ph', type: 'float' },
+   { name: 'brew_aboil_efficiency', type: 'float' },
+   { name: 'brew_cooling_method', type: 'int' },
+   { name: 'brew_cooling_time', type: 'float' },
+   { name: 'brew_cooling_to', type: 'float' },
+   { name: 'brew_whirlpool9', type: 'float' },
+   { name: 'brew_whirlpool7', type: 'float' },
+   { name: 'brew_whirlpool6', type: 'float' },
+   { name: 'brew_whirlpool2', type: 'float' },
+   { name: 'brew_fermenter_volume', type: 'float' },
+   { name: 'brew_fermenter_extrawater', type: 'float' },
+   { name: 'brew_fermenter_tcloss', type: 'float' },
+   { name: 'brew_aeration_time', type: 'float' },
+   { name: 'brew_aeration_speed', type: 'float' },
+   { name: 'brew_aeration_type', type: 'int' },
+   { name: 'brew_fermenter_sg', type: 'float' },
+   { name: 'brew_fermenter_ibu', type: 'float' },
+   { name: 'brew_fermenter_color', type: 'float' },
+   { name: 'brew_date_end', type: 'string' },
+   { name: 'og', type: 'float' },
+   { name: 'fg', type: 'float' },
+   { name: 'primary_start_temp', type: 'float' },
+   { name: 'primary_max_temp', type: 'float' },
+   { name: 'primary_end_temp', type: 'float' },
+   { name: 'primary_end_sg', type: 'float' },
+   { name: 'primary_end_date', type: 'string' },
+   { name: 'secondary_temp', type: 'float' },
+   { name: 'secondary_end_sg', type: 'float' },
+   { name: 'secondary_end_date', type: 'string' },
+   { name: 'tertiary_temp', type: 'float' },
+   { name: 'package_date', type: 'string' },
+   { name: 'package_volume', type: 'float' },
+   { name: 'package_infuse_amount', type: 'float' },
+   { name: 'package_infuse_abv', type: 'float' },
+   { name: 'package_infuse_notes', type: 'string' },
+   { name: 'package_abv', type: 'float' },
+   { name: 'package_ph', type: 'float' },
+   { name: 'bottle_amount', type: 'float' },
+   { name: 'bottle_carbonation', type: 'float' },
+   { name: 'bottle_priming_water', type: 'float' },
+   { name: 'bottle_priming_amount', type: 'float' },
+   { name: 'bottle_carbonation_temp', type: 'float' },
+   { name: 'keg_amount', type: 'float' },
+   { name: 'keg_carbonation', type: 'float' },
+   { name: 'keg_priming_water', type: 'float' },
+   { name: 'keg_priming_amount', type: 'float' },
+   { name: 'keg_carbonation_temp', type: 'float' },
+   { name: 'keg_forced_carb', type: 'int' },
+   { name: 'keg_pressure', type: 'float' },
+   { name: 'taste_notes', type: 'string' },
+   { name: 'taste_rate', type: 'float' },
+   { name: 'taste_date', type: 'string' },
+   { name: 'taste_color', type: 'string' },
+   { name: 'taste_transparency', type: 'string' },
+   { name: 'taste_head', type: 'string' },
+   { name: 'taste_aroma', type: 'string' },
+   { name: 'taste_taste', type: 'string' },
+   { name: 'taste_mouthfeel', type: 'string' },
+   { name: 'taste_aftertaste', type: 'string' },
+   { name: 'st_name', type: 'string' },
+   { name: 'st_letter', type: 'string' },
+   { name: 'st_guide', type: 'string' },
+   { name: 'st_category', type: 'string' },
+   { name: 'st_category_number', type: 'float' },
+   { name: 'st_type', type: 'int' },
+   { 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: '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: 'starter_enable', type: 'int' },
+   { name: 'starter_type', type: 'int' },
+   { name: 'starter_sg', type: 'float' },
+   { name: 'starter_viability', type: 'int' },
+   { name: 'prop1_type', type: 'int' },
+   { name: 'prop1_volume', type: 'float' },
+   { name: 'prop2_type', type: 'int' },
+   { name: 'prop2_volume', type: 'float' },
+   { name: 'prop3_type', type: 'int' },
+   { name: 'prop3_volume', type: 'float' },
+   { name: 'prop4_type', type: 'int' },
+   { name: 'prop4_volume', type: 'float' },
+   { 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);
+   $('#code').val(dataRecord.code);
+   $('#birth').val(dataRecord.birth);
+   $('#stage').val(StageData[dataRecord.stage].nl);
+   $('#notes').val(dataRecord.notes);
+   $('#locked').val(dataRecord.locked);
+   $('#eq_name').val(dataRecord.eq_name);
+   $('#eq_notes').val(dataRecord.eq_notes);
+   $('#eq_boil_size').val(dataRecord.eq_boil_size);
+   $('#eq_batch_size').val(dataRecord.eq_batch_size);
+   $('#eq_tun_volume').val(dataRecord.eq_tun_volume);
+   $('#eq_top_up_water').val(dataRecord.eq_top_up_water);
+   $('#eq_trub_chiller_loss').val(dataRecord.eq_trub_chiller_loss);
+   $('#eq_evap_rate').val(dataRecord.eq_evap_rate);
+   $('#eq_boil_time').val(dataRecord.eq_boil_time);
+   $('#eq_top_up_kettle').val(dataRecord.eq_top_up_kettle);
+   $('#eq_hop_utilization').val(dataRecord.eq_hop_utilization);
+   $('#eq_lauter_volume').val(dataRecord.eq_lauter_volume);
+   $('#eq_lauter_deadspace').val(dataRecord.eq_lauter_deadspace);
+   $('#eq_kettle_volume').val(dataRecord.eq_kettle_volume);
+   $('#eq_mash_volume').val(dataRecord.eq_mash_volume);
+   $('#eq_mash_max').val(dataRecord.eq_mash_max);
+   $('#eq_efficiency').val(dataRecord.eq_efficiency);
+   // Brewdate
+   $('#brew_date_start').val(dataRecord.brew_date_start);
+   $('#brew_mash_ph').val(dataRecord.brew_mash_ph);
+   $('#brew_mash_sg').val(dataRecord.brew_mash_sg);
+   $('#brew_mash_efficiency').val(dataRecord.brew_mash_efficiency);
+   // Header Spoelen en filteren
+   $('#brew_sparge_temperature').val(dataRecord.sparge_temp);
+   $('#brew_sparge_volume').val(dataRecord.sparge_volume);
+   $('#brew_sparge_est').val(dataRecord.brew_sparge_est);
+   $('#brew_sparge_ph').val(dataRecord.brew_sparge_ph);
+   // Header Beluchten
+   $('#brew_aeration_type').val(dataRecord.brew_aeration_type);
+   $('#brew_aeration_time').val(dataRecord.brew_aeration_time);
+   $('#brew_aeration_speed').val(dataRecord.brew_aeration_speed);
+
+   $('#brew_preboil_ph').val(dataRecord.brew_preboil_ph);
+   $('#brew_preboil_sg').val(dataRecord.brew_preboil_sg);
+   $('#brew_preboil_volume').val(dataRecord.brew_preboil_volume);
+   $('#brew_preboil_efficiency').val(dataRecord.brew_preboil_efficiency);
+   // Header Koelen en whirlpoolen
+   $('#brew_whirlpool9').val(dataRecord.brew_whirlpool9);
+   $('#brew_whirlpool7').val(dataRecord.brew_whirlpool7);
+   $('#brew_whirlpool6').val(dataRecord.brew_whirlpool6);
+   $('#brew_whirlpool2').val(dataRecord.brew_whirlpool2);
+   // Header Naar gistvat
+   $('#brew_fermenter_volume').val(dataRecord.brew_fermenter_volume);
+   $('#brew_fermenter_sg').val(dataRecord.brew_fermenter_sg);
+   $('#brew_fermenter_sg2').val(dataRecord.brew_fermenter_sg);
+   $('#brew_fermenter_ibu').val(dataRecord.brew_fermenter_ibu);
+   $('#brew_fermenter_color').val(dataRecord.brew_fermenter_color);
+   $('#brew_fermenter_extrawater').val(dataRecord.brew_fermenter_extrawater);
+   $('#brew_fermenter_tcloss').val(dataRecord.brew_fermenter_tcloss);
+
+   $('#brew_aboil_ph').val(dataRecord.brew_aboil_ph);
+   $('#brew_aboil_sg').val(dataRecord.brew_aboil_sg);
+   $('#brew_aboil_volume').val(dataRecord.brew_aboil_volume);
+   $('#brew_aboil_efficiency').val(dataRecord.brew_aboil_efficiency);
+   // Header Koelen en whirlpoolen
+   $('#brew_cooling_to').val(dataRecord.brew_cooling_to);
+   $('#brew_cooling_method').val(dataRecord.brew_cooling_method);
+   $('#brew_cooling_time').val(dataRecord.brew_cooling_time);
+   // Niks
+   $('#brew_date_end').val(dataRecord.brew_date_end);
+   $('#og').val(dataRecord.og);
+   $('#fg').val(dataRecord.fg);
+   $('#primary_start_temp').val(dataRecord.primary_start_temp);
+   $('#primary_max_temp').val(dataRecord.primary_max_temp);
+   $('#primary_end_temp').val(dataRecord.primary_end_temp);
+   $('#primary_end_sg').val(dataRecord.primary_end_sg);
+   $('#primary_end_date').val(dataRecord.primary_end_date);
+   $('#secondary_temp').val(dataRecord.secondary_temp);
+   $('#secondary_end_sg').val(dataRecord.secondary_end_sg);
+   $('#secondary_end_date').val(dataRecord.secondary_end_date);
+   $('#tertiary_temp').val(dataRecord.tertiary_temp);
+   $('#package_date').val(dataRecord.package_date);
+   $('#package_volume').val(dataRecord.package_volume);
+   $('#package_infuse_amount').val(dataRecord.package_infuse_amount);
+   $('#package_infuse_abv').val(dataRecord.package_infuse_abv);
+   $('#package_infuse_notes').val(dataRecord.package_infuse_notes);
+   $('#package_abv').val(dataRecord.package_abv);
+   $('#package_ph').val(dataRecord.package_ph);
+   $('#bottle_amount').val(dataRecord.bottle_amount);
+   $('#bottle_carbonation').val(dataRecord.bottle_carbonation);
+   $('#bottle_priming_water').val(dataRecord.bottle_priming_water);
+   $('#bottle_priming_amount').val(dataRecord.bottle_priming_amount);
+   $('#bottle_carbonation_temp').val(dataRecord.bottle_carbonation_temp);
+   $('#keg_amount').val(dataRecord.keg_amount);
+   $('#keg_carbonation').val(dataRecord.keg_carbonation);
+   $('#keg_priming_water').val(dataRecord.keg_priming_water);
+   $('#keg_priming_amount').val(dataRecord.keg_priming_amount);
+   $('#keg_carbonation_temp').val(dataRecord.keg_carbonation_temp);
+   $('#keg_forced_carb').val(dataRecord.keg_forced_carb);
+   $('#keg_pressure').val(dataRecord.keg_pressure);
+   $('#taste_notes').val(dataRecord.taste_notes);
+   $('#taste_rate').val(dataRecord.taste_rate);
+   $('#taste_date').val(dataRecord.taste_date);
+   $('#taste_color').val(dataRecord.taste_color);
+   $('#taste_transparency').val(dataRecord.taste_transparency);
+   $('#taste_head').val(dataRecord.taste_head);
+   $('#taste_aroma').val(dataRecord.taste_aroma);
+   $('#taste_taste').val(dataRecord.taste_taste);
+   $('#taste_mouthfeel').val(dataRecord.taste_mouthfeel);
+   $('#taste_aftertaste').val(dataRecord.taste_aftertaste);
+
+   // Recipe
+   $('#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);
+   $('#st_og_min').val(dataRecord.st_og_min);
+   $('#st_og_max').val(dataRecord.st_og_max);
+   $('#st_fg_min').val(dataRecord.st_fg_min);
+   $('#st_fg_max').val(dataRecord.st_fg_max);
+   $('#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);
+   $('#st_ibu_min').val(dataRecord.st_ibu_min);
+   $('#st_ibu_max').val(dataRecord.st_ibu_max);
+   $('#st_carb_min').val(dataRecord.st_carb_min);
+   $('#st_carb_min2').val(dataRecord.st_carb_min);
+   $('#st_carb_max').val(dataRecord.st_carb_max);
+   $('#st_carb_max2').val(dataRecord.st_carb_max);
+   $('#type').val(dataRecord.type);
+   $('#batch_size').val(dataRecord.batch_size);
+   $('#est_a_vol').val(dataRecord.batch_size * 1.04);
+   $('#boil_size').val(dataRecord.boil_size);
+   $('#est_pre_vol').val(dataRecord.boil_size * 1.04);
+   $('#boil_time').val(dataRecord.boil_time);
+   $('#efficiency').val(dataRecord.efficiency);
+   $('#est_og').val(dataRecord.est_og);
+   $('#est_og2').val(dataRecord.est_og);
+   $('#est_og3').val(0);
+   $('#est_fg').val(dataRecord.est_fg);
+   $('#est_fg2').val(dataRecord.est_fg);
+   $('#est_fg3').val(dataRecord.est_fg);
+   $('#est_color').val(dataRecord.est_color);
+   $('#est_color2').val(dataRecord.est_color);
+   $('#est_abv').val(dataRecord.est_abv);
+   $('#color_method').val(dataRecord.color_method);
+   $('#est_ibu').val(dataRecord.est_ibu);
+   $('#est_ibu2').val(dataRecord.est_ibu);
+   $('#ibu_method').val(dataRecord.ibu_method);
+   $('#est_carb').val(dataRecord.est_carb);
+   $('#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);
+   $('#starter_enable').val(dataRecord.starter_enable);
+   $('#starter_type').val(dataRecord.starter_type);
+   $('#starter_sg').val(dataRecord.starter_sg);
+   $('#starter_viability').val(dataRecord.starter_viability);
+   $('#prop1_type').val(dataRecord.prop1_type);
+   $('#prop1_volume').val(dataRecord.prop1_volume);
+   $('#prop2_type').val(dataRecord.prop2_type);
+   $('#prop2_volume').val(dataRecord.prop2_volume);
+   $('#prop3_type').val(dataRecord.prop3_type);
+   $('#prop3_volume').val(dataRecord.prop3_volume);
+   $('#prop4_type').val(dataRecord.prop4_type);
+   $('#prop4_volume').val(dataRecord.prop4_volume);
+   editFermentable(dataRecord);
+   editHop(dataRecord);
+   editMisc(dataRecord);
+   editYeast(dataRecord);
+   editMash(dataRecord);
+   calcStage();
+   $('#jqxTabs').jqxTabs('select', 2);
+  },
+   loadError: function(jqXHR, status, error) {
+  },
+  beforeLoadComplete: function(records) {
+   $('#jqxLoader').jqxLoader('open');
+  }
+ });
+
+ // 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);
+   }
+  },
+  fermentableAdapter = new $.jqx.dataAdapter(fermentableSource);
+
+  $('#fermentableGrid').jqxGrid({
+   width: 1240,
+   height: 470,
+   source: fermentableAdapter,
+   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="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',
+     disabled: (dataRecord.stage > 3),
+     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['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;
+      $('#fermentableGrid').jqxGrid('addrow', null, row);
+     }
+    });
+
+    $('#finstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
+    $('#finstockbutton').on('change', function(event) {
+     fermentableinstock = event.args.checked;
+     fermentablelist.dataBind();
+    });
+
+    // delete selected fermentable.
+    $('#fdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#fdeleterowbutton').on('click', function() {
+     var rowscount, id, percent, amount, i, rowdata,
+     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, defaultvalue, 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', 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: 'Voorraad Kg', datafield: 'f_inventory', width: 120, align: 'right',
+     cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) {
+      var color = '#ffffff';
+      if (((dataRecord.inventory_reduced <= 2) && (rowdata.f_added <= 1)) || // Mash or boil
+          ((dataRecord.inventory_reduced <= 3) && (rowdata.f_added == 2)) || // Primary
+          ((dataRecord.inventory_reduced <= 5) && (rowdata.f_added == 3)) || // Secondary or Tertiary
+          ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 4)) || // Bottle
+          ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 5))) { // Kegs
+       if (value < rowdata.f_amount)
+        color = '#ff4040';
+       return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + fermentableAdapter.formatNumber(value, 'f3') + '</span>';
+      } else {
+       return '<span></span>';
+      }
+     }
+    },
+    { text: 'Procent', datafield: 'f_percentage', width: 90, align: 'right',
+     cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) {
+      if (rowdata.f_added >= 4)
+       return '<span></span>';
+      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%', datafield: 'f_adjust_to_total_100', width: 70, align: 'center', cellsalign: 'center',
+     cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
+      if (value == 0)
+       return '<span></span>';
+      return '<span><img style="float:left; margin-left:25px; margin-top:4px;" src="images/dialog-ok-apply.png"></span>';
+     }
+    },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center',
+     cellsrenderer: function() {
+      return 'Wijzig';
+     }, buttonclick: function(row) {
+      fermentableRow = row;
+      fermentableData = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
+      if (fermentableData.f_added >= 4) {
+       alert('Wijzig dit in de Verpakken tab');
+      } else if (dataRecord.stage > 3) {
+       alert('Ingredieënt is al verwerkt.');
+      } else {
+       $('#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');
+      }
+     }
+    }
+   ]
+  });
+ },
+
+ // Inline hops editor
+ 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);
+
+  $('#hopGrid').jqxGrid({
+   width: 1240,
+   height: 560,
+   source: hopAdapter,
+   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="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,
+     disabled: (dataRecord.stage > 3),
+     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 + ' / ' + HopFormData[datarecord.form].nl + ' (' + 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');
+    });
+
+    $('#hinstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
+    $('#hinstockbutton').on('change', function(event) {
+     hopinstock = event.args.checked;
+     hoplist.dataBind();
+    });
+
+    // delete selected hop.
+    $('#hdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#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) {
+      if (((dataRecord.inventory_reduced <= 2) && (rowdata.h_useat <= 4)) || // Mash, FW, Boil, Aroma, Whirlpool
+          ((dataRecord.inventory_reduced <= 6) && (rowdata.h_useat == 5))) { // Dry hop
+       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>';
+      } else {
+       return '<span></span>';
+      }
+     }
+    },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center',
+     cellsrenderer: function() {
+      return 'Wijzig';
+     }, buttonclick: function(row) {
+      if (dataRecord.stage > 3) {
+       alert('Ingredieënt is al verwerkt.');
+      } else {
+       console.log('edit button row ' + 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');
+      }
+     }
+    }
+   ]
+  });
+ },
+
+ // Inline miscs editor
+ 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 row, i, 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) {
                                 $('#err').text(status + ' ' + error);
-                        },
-                });
-                $("#miscGrid").jqxGrid({
-                        width: 1240,
-                        height: 575,
-                        source: miscAdapter,
-                        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="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 ingredient" />');
-                                // add misc from dropdownlist.
-                                $("#maddrowbutton").jqxDropDownList({
-                                        placeHolder: "Kies ingredi&euml;nt:",
-                                        theme: theme,
-					template: "primary",
-                                        source: misclist,
-					disabled: (dataRecord.stage > 3),
-                                        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, disabled: (dataRecord.stage > 3) });
-                                $("#minstockbutton").on('change', function (event) {
-                                        miscinstock = event.args.checked;
-                                        misclist.dataBind();
-                                });
-                                // delete selected misc.
-                                $("#mdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
-                                $("#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() {
-				calcMiscs();
-                                $('#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, color, amount;
-					if (((dataRecord.inventory_reduced <= 2) && (rowdata.m_use_use <= 2)) ||  // Starter, Mash, Boil
-					    ((dataRecord.inventory_reduced <= 3) && (rowdata.m_use_use == 3)) ||  // Primary
-					    ((dataRecord.inventory_reduced <= 5) && (rowdata.m_use_use == 4)) ||  // Secondary, Teriary
-                                            ((dataRecord.inventory_reduced <= 6) && (rowdata.m_use_use == 5))) {  // Bottle
-						vstr = rowdata.m_amount_is_weight ? "gr":"ml";
-						color = '#ffffff';
-						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>';
-					} else {
-						return '<span></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 (dataRecord.stage > 3) {
-							alert("Ingredieënt is al verwerkt.");
-						} else if (miscData.m_type == 4) {
-							alert("Brouwzouten wijzigen in de water tab.");
-						} else {
-							console.log("edit button row "+row);
-							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');
-						}
-					}
-				}
-                        ]
-                });
-        },
-
-        // Inline yeasts editor
-        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);
-
-                $("#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,
-					disabled: (dataRecord.stage > 3),
-					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);
-                                        }
-					calcYeast();
-					$("#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);
-						calcYeast();
-                                        }
-                                });
-                        },
-                        ready: function() {
-				calcFermentables();
-				showStarter();
-				calcYeast();
-                                $('#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;
-					if (((dataRecord.inventory_reduced <= 3) && (rowdata.y_use == 0)) ||  // Primary
-                                            ((dataRecord.inventory_reduced <= 4) && (rowdata.y_use == 1)) ||  // Secondary
-                                            ((dataRecord.inventory_reduced <= 5) && (rowdata.y_use == 2)) ||  // Tertiary
-                                            ((dataRecord.inventory_reduced <= 6) && (rowdata.y_use == 3))) {  // Bottle
-						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>';
-					} else {
-						return '<span></span>';
-					}
-				  }
-				},
-				{ text: '', datafield: 'Edit', columntype: 'button', width: 90, align: 'center', cellsrenderer: function () {
-					return "Wijzig";
-					}, buttonclick: function (row) {
-						if (dataRecord.stage > 3) {
-                                                        alert("Ingredieënt is al verwerkt.");
-                                                } else {
-							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');
-						}
-					}
-				}
-                        ]
-                });
-        },
-        // inline mash editor
-        editMash = function (data) {
-                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 i, row, 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 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, disabled: (dataRecord.stage > 3) });
-                                $("#saddrowbutton").on('click', function () {
-					var row = {}, rowscount = $("#mashGrid").jqxGrid('getdatainformation').rowscount;
-					row["step_name"] = "Stap " + (rowscount + 1);
-					if (rowscount > 0) {
-						row["step_type"] = 1;
-					} else {
-						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;
-					$("#mashGrid").jqxGrid('addrow', null, row);
-                                });
-                                // delete selected step.
-                                $("#sdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
-                                $("#sdeleterowbutton").on('click', function () {
-                                        var rowscount, id, 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() {
-                                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  '<span style="margin: 4px; margin-top: 6px; float: left;">' + MashStepTypeData[value].nl + '</span>';
-                                  }
-                                },
-                                { 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) {
-						if (dataRecord.stage > 3) {
-                                                        alert("Het maichen is al gedaan.");
-                                                } else {
-							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 product ...",theme:theme});
-//	dataAdapter.dataBind();
-
-	/*
-	 * Generic functions
-	 */
-        function calcSupplies() {
-                if (dataRecord.inventory_reduced > 6) {
-                        $("#ok_pmpt").hide();
-                        return;
-                }
-                if (ok_fermentables && ok_hops && ok_miscs && ok_yeasts && ok_waters)
-                        $("#ok_supplies").html("<img src='images/dialog-ok-apply.png'>");
-                else
-                        $("#ok_supplies").html("<img src='images/dialog-error.png'>");
-        }
-
-        function calcPercentages() {
-
-                console.log("calcPercentages()");
-                var tw = 0, rowdata, percentage, rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
-                if (rowscount > 1) {
-                        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);
-                }
-        }
-
-        /* 
-         * All calculations that depend on changes in the fermentables,
-         * volumes and equipments.
-         */
-        function calcFermentables() {
-
-            var 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
-		i, row, rows, org, timem, aboil_volume, spoelw, ogx, topw, s = 0, d, v, x,
-		sug, alc, pt, cw, color, scolor, fig;
-
-		/* Init global variables */
-		psugar = 0;
-                pcara = 0;
-                mashkg = 0;
-                ok_fermentables = 1;    // All is in stock.
-                ok_yeasts = 1;
-
-               	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
-                                        timem=row.step_time+row.ramp_time;
-                                        mashtime+=timem;
-                                        mashtemp+=timem*row.step_temp;
-                                }
-                        }
-                        if(mashtime>5)
-                                mashtime-=5;//Correct last ramp > 75
-                        mashtemp=Round(mashtemp/mashtime,2);
-                }
-
-                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 += parseFloat(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 < 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.
-                        }
-                        if (fermentableInit) {
-                                if (row.f_added == 4) {
-                                        $("#bottle_priming_total").val(row.f_amount * 1000);    // Prevent clearing
-                                        $("#bottle_priming_sugar").jqxDropDownList('selectItem', row.f_name);
-                                }
-                                if (row.f_added == 5) {
-                                        $("#keg_priming_total").val(row.f_amount * 1000);
-                                        $("#keg_priming_sugar").jqxDropDownList('selectItem', row.f_name);
-                                }
-                        }
-                        // Check supplies.
-                        if ((((dataRecord.inventory_reduced <= 2) && (row.f_added <= 1)) ||  // Mash or boil
-                             ((dataRecord.inventory_reduced <= 3) && (row.f_added == 2)) ||  // Primary
-                             ((dataRecord.inventory_reduced <= 5) && (row.f_added == 3)) ||  // Secondary or Tertiary
-                             ((dataRecord.inventory_reduced <= 6) && (row.f_added == 4)) ||  // Bottle
-                             ((dataRecord.inventory_reduced <= 6) && (row.f_added == 5))) && row.f_inventory < row.f_amount) {
-                                ok_fermentables = 0;
-                        }
-                        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;
-                        }
-                }
-                fermentableInit = 0;
-                $("#ferm_lintner").val(Math.round(parseFloat(lintner / mashkg)));
-                $("#mash_kg").val(mashkg);
-                console.log("calcFermentables() supplies:"+ok_fermentables+" moutsuiker:"+sugarsm+"/"+sugarsf);
-                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 });
-                }
-
-                if (mvol > 0) {
-                        v = s / sugardensity + mvol;
-                        s = 1000 * s / (v * 10); //deg. Plato
-                        est_mash_sg = Round(plato_to_sg(s), 5);
-                        $('#est_mash_sg').val(est_mash_sg);
-                }
-
-                // 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 after boil
-                aboil_sg = estimate_sg(sugarsf, parseFloat(dataRecord.batch_size));
-                $('#est_og3').val(aboil_sg);
-
-                // Estimate SG in kettle before boil
-                preboil_sg = estimate_sg(sugarsm, parseFloat(dataRecord.boil_size));
-                $('#est_pre_sg').val(preboil_sg);
-
-                // Recalculate volumes.
-                aboil_volume = parseFloat(dataRecord.batch_size);
-                if (dataRecord.brew_aboil_volume > 0)
-                        aboil_volume = dataRecord.brew_aboil_volume / 1.04;     // volume @ 20 degrees
-                if (dataRecord.brew_fermenter_tcloss == 0) {
-                        dataRecord.brew_fermenter_tcloss = dataRecord.eq_trub_chiller_loss;
-                        $("#brew_fermenter_tcloss").val(dataRecord.brew_fermenter_tcloss);
-                }
-                dataRecord.brew_fermenter_volume = aboil_volume - dataRecord.brew_fermenter_tcloss + dataRecord.brew_fermenter_extrawater;
-                $("#brew_fermenter_volume").val(dataRecord.brew_fermenter_volume);
-                // Estimated needed sparge water corrected for the temperature.
-                spoelw = (dataRecord.boil_size - mash_infuse + (mashkg * my_grain_absorbtion) + dataRecord.eq_lauter_deadspace) * 1.03;
-                $("#brew_sparge_est").val(spoelw);
-                // Calculate SG in fermenter
-                ogx = dataRecord.brew_aboil_sg;
-                if (ogx < 1.002)
-                        ogx = aboil_sg;
-                topw = dataRecord.brew_fermenter_extrawater;
-
-                if (dataRecord.brew_fermenter_volume > 0) {
-                        sug = sg_to_plato(ogx) * dataRecord.brew_fermenter_volume * ogx / 100;  //kg of sugar in
-                        sug += addedS; //kg
-
-                        if ((dataRecord.brew_fermenter_volume * ogx + addedmass) > 0) {
-                                pt = 100 * sug / (dataRecord.brew_fermenter_volume * ogx + addedmass + topw);
-                                dataRecord.brew_fermenter_sg = Round(plato_to_sg(pt),4);
-                                $("#brew_fermenter_sg").val(dataRecord.brew_fermenter_sg);
-                                // color
-                                if (dataRecord.color_method == 4) {
-                                        dataRecord.brew_fermenter_color = Math.round(((pt / 8.6) * colorn) + (dataRecord.boil_time / 60));
-                                } else if (dataRecord.color_method == 3) {
-                                        dataRecord.brew_fermenter_color = Math.round((4.46 * bv * sr) /  (aboil_volume + topw) * colorh);
-                                } else {
-                                        cw = colort / (aboil_volume + topw) * 8.34436;
-                                        dataRecord.brew_fermenter_color = kw_to_ebc(dataRecord.color_method, cw);
-                                }
-                                $("#brew_fermenter_color").val(dataRecord.brew_fermenter_color);
-                                scolor = ebc_to_color(dataRecord.brew_fermenter_color);
-                                $("#bcolorf").show();
-                                document.getElementById("bcolorf").style.background = scolor;
-                        }
-                } else {
-                        // Negative volume
-                        dataRecord.brew_fermenter_sg = dataRecord.brew_fermenter_color = 0;
-                        $("#brew_fermenter_sg").val(0);
-                        $("#brew_fermenter_color").val(0);
-                        $("#bcolorf").hide();
-                }
-
-                // 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.eq_mash_max * 100;
-                $("#perc_malts").jqxProgressBar('val', pmalts);
-                $("#perc_sugars").jqxProgressBar('val', psugar);
-                $("#perc_cara").jqxProgressBar('val', pcara);
-                calcStage();
-
-                // Calculate estimated svg.
-                svg = 0; // default.
-                initcells = 0;
-                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.
-                                if (row.y_form == 0)
-                                        initcells += (parseFloat(row.y_cells) / 1000000000) * parseFloat(row.y_amount) * (dataRecord.starter_viability / 100);
-                                else
-                                        initcells += (parseFloat(row.y_cells) / 1000000) * parseFloat(row.y_amount);
-                        }
-                        // TODO: brett in secondary ??
-                        if ((((dataRecord.inventory_reduced <= 3) && (row.y_use == 0)) ||  // Primary
-                             ((dataRecord.inventory_reduced <= 4) && (row.y_use == 1)) ||  // Secondary
-                             ((dataRecord.inventory_reduced <= 5) && (row.y_use == 2)) ||  // Tertiary
-                             ((dataRecord.inventory_reduced <= 6) && (row.y_use == 3))) && // Bottle
-                             (row.y_inventory < row.y_amount)) {
-                                ok_yeasts = 0;
-                        }
-                }
-               	calcSupplies();
-                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);
-                $('#est_fg3').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 final svg if available use the real value.
-                if ((dataRecord.stage >= 6) && (dataRecord.fg > 0.990) && (dataRecord.fg < dataRecord.brew_fermenter_sg)) {
-                        svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.fg) / (dataRecord.brew_fermenter_sg - 1);
-                        org = dataRecord.brew_fermenter_sg;
-                        fig = dataRecord.fg;
-                }
-
-                $("#yeast_cells").val(initcells);
-                $("#need_cells").val(getNeededYeastCells());
-
-                // 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;
-
-                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);
-                }
-        }
-
-       	/*
-         * 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 = Round(sug / tot,3);
-
-                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 getNeededYeastCells() {
-
-                var plato, volume, sg = dataRecord.brew_fermenter_sg;
-                if (sg <= 1.0001 && dataRecord.fg > 1.000)
-                        sg = dataRecord.fg;
-                else if (sg <= 1.0001)
-                        sg = dataRecord.est_og;
-                plato = sg_to_plato(sg);
-
-                volume = dataRecord.brew_fermenter_volume;
-                if (volume <= 0)
-                        volume = dataRecord.batch_size - dataRecord.eq_trub_chiller_loss;
-
-                return pitchrate * volume * plato;
-        }
-
-        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 calcIBUs() {
-                var total_ibus = 0, ferm_ibus = 0, rows = {}, i, row;
-                hop_aroma = hop_flavour = 0;
-                if (!(rows = $('#hopGrid').jqxGrid('getrows'))) {
-                        return;
-                }
-                ok_hops = 1;
-                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);
-                        ferm_ibus += toIBU(row.h_useat, row.h_form, preboil_sg,
-                                        parseFloat(dataRecord.brew_fermenter_volume) + parseFloat(dataRecord.brew_fermenter_tcloss),
-                                        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),
+   },
+  });
+  $('#miscGrid').jqxGrid({
+   width: 1240,
+   height: 575,
+   source: miscAdapter,
+   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="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 ingredient" />');
+    // add misc from dropdownlist.
+    $('#maddrowbutton').jqxDropDownList({
+     placeHolder: 'Kies ingredi&euml;nt:',
+     theme: theme,
+     template: 'primary',
+     source: misclist,
+     disabled: (dataRecord.stage > 3),
+     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, disabled: (dataRecord.stage > 3) });
+    $('#minstockbutton').on('change', function(event) {
+     miscinstock = event.args.checked;
+     misclist.dataBind();
+    });
+    // delete selected misc.
+    $('#mdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#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() {
+    calcMiscs();
+    $('#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, color, amount;
+      if (((dataRecord.inventory_reduced <= 2) && (rowdata.m_use_use <= 2)) ||  // Starter, Mash, Boil
+          ((dataRecord.inventory_reduced <= 3) && (rowdata.m_use_use == 3)) ||  // Primary
+          ((dataRecord.inventory_reduced <= 5) && (rowdata.m_use_use == 4)) ||  // Secondary, Teriary
+          ((dataRecord.inventory_reduced <= 6) && (rowdata.m_use_use == 5))) {  // Bottle
+       vstr = rowdata.m_amount_is_weight ? 'gr' : 'ml';
+       color = '#ffffff';
+       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>';
+      } else {
+       return '<span></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 (dataRecord.stage > 3) {
+       alert('Ingredieënt is al verwerkt.');
+      } else if (miscData.m_type == 4) {
+       alert('Brouwzouten wijzigen in de water tab.');
+      } else {
+       console.log('edit button row ' + row);
+       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');
+      }
+     }
+    }
+   ]
+  });
+ },
+
+ // Inline yeasts editor
+ 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);
+
+  $('#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,
+     disabled: (dataRecord.stage > 3),
+     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);
+     }
+     calcYeast();
+     $('#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);
+      calcYeast();
+     }
+    });
+   },
+   ready: function() {
+    calcFermentables();
+    showStarter();
+    calcYeast();
+    $('#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;
+      if (((dataRecord.inventory_reduced <= 3) && (rowdata.y_use == 0)) ||  // Primary
+          ((dataRecord.inventory_reduced <= 4) && (rowdata.y_use == 1)) ||  // Secondary
+          ((dataRecord.inventory_reduced <= 5) && (rowdata.y_use == 2)) ||  // Tertiary
+          ((dataRecord.inventory_reduced <= 6) && (rowdata.y_use == 3))) {  // Bottle
+       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>';
+      } else {
+       return '<span></span>';
+      }
+     }
+    },
+    { text: '', datafield: 'Edit', columntype: 'button', width: 90, align: 'center',
+     cellsrenderer: function() {
+      return 'Wijzig';
+     }, buttonclick: function(row) {
+      if (dataRecord.stage > 3) {
+       alert('Ingredieënt is al verwerkt.');
+      } else {
+       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');
+      }
+     }
+    }
+   ]
+  });
+ },
+
+ // inline mash editor
+ editMash = function(data) {
+  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) {
+    console.log('mash addrow ' + rowid);
+    commit(true);
+   },
+   deleterow: function(rowid, commit) {
+    console.log('mash deleterow ' + rowid);
+    commit(true);
+   }
+  },
+  mashAdapter = new $.jqx.dataAdapter(mashSource, {
+   beforeLoadComplete: function(records) {
+    mash_infuse = 0;
+    var i, row, 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 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, disabled: (dataRecord.stage > 3) });
+    $('#saddrowbutton').on('click', function() {
+     var row = {}, rowscount = $('#mashGrid').jqxGrid('getdatainformation').rowscount;
+     row['step_name'] = 'Stap ' + (rowscount + 1);
+     if (rowscount > 0) {
+      row['step_type'] = 1;
+     } else {
+      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;
+     $('#mashGrid').jqxGrid('addrow', null, row);
+    });
+    // delete selected step.
+    $('#sdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#sdeleterowbutton').on('click', function() {
+     var rowscount, id, 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() {
+    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 '<span style="margin: 4px; margin-top: 6px; float: left;">' + MashStepTypeData[value].nl + '</span>';
+      }
+    },
+    { 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) {
+      if (dataRecord.stage > 3) {
+       alert('Het maichen is al gedaan.');
+      } else {
+       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 product ...',
+  theme: theme
+ });
+
+ /*
+  * Generic functions
+  */
+ function calcSupplies() {
+  if (dataRecord.inventory_reduced > 6) {
+   $('#ok_pmpt').hide();
+   return;
+  }
+  if (ok_fermentables && ok_hops && ok_miscs && ok_yeasts && ok_waters)
+   $('#ok_supplies').html("<img src='images/dialog-ok-apply.png'>");
+  else
+   $('#ok_supplies').html("<img src='images/dialog-error.png'>");
+ }
+
+ function calcPercentages() {
+
+  console.log('calcPercentages()');
+  var tw = 0, rowdata, percentage, rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
+  if (rowscount > 1) {
+   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);
+  }
+ }
+
+ /*
+  * All calculations that depend on changes in the fermentables,
+  * volumes and equipments.
+  */
+ function calcFermentables() {
+
+  var 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
+  i, row, rows, org, timem, aboil_volume, spoelw, ogx, topw, s = 0, d, v, x,
+  sug, alc, pt, cw, color, scolor, fig;
+
+  /* Init global variables */
+  psugar = 0;
+  pcara = 0;
+  mashkg = 0;
+  ok_fermentables = 1;    // All is in stock.
+  ok_yeasts = 1;
+
+  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
+     timem = row.step_time + row.ramp_time;
+     mashtime += timem;
+     mashtemp += timem * row.step_temp;
+    }
+   }
+   if (mashtime > 5)
+    mashtime -= 5; //Correct last ramp > 75
+   mashtemp = Round(mashtemp / mashtime, 2);
+  }
+
+  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 += parseFloat(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 < 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.
+   }
+   if (fermentableInit) {
+    if (row.f_added == 4) {
+     $('#bottle_priming_total').val(row.f_amount * 1000);    // Prevent clearing
+     $('#bottle_priming_sugar').jqxDropDownList('selectItem', row.f_name);
+    }
+    if (row.f_added == 5) {
+     $('#keg_priming_total').val(row.f_amount * 1000);
+     $('#keg_priming_sugar').jqxDropDownList('selectItem', row.f_name);
+    }
+   }
+   // Check supplies.
+   if ((((dataRecord.inventory_reduced <= 2) && (row.f_added <= 1)) ||  // Mash or boil
+        ((dataRecord.inventory_reduced <= 3) && (row.f_added == 2)) ||  // Primary
+        ((dataRecord.inventory_reduced <= 5) && (row.f_added == 3)) ||  // Secondary or Tertiary
+        ((dataRecord.inventory_reduced <= 6) && (row.f_added == 4)) ||  // Bottle
+        ((dataRecord.inventory_reduced <= 6) && (row.f_added == 5))) && row.f_inventory < row.f_amount) {
+    ok_fermentables = 0;
+   }
+   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;
+   }
+  }
+  fermentableInit = 0;
+  $('#ferm_lintner').val(Math.round(parseFloat(lintner / mashkg)));
+  $('#mash_kg').val(mashkg);
+  console.log('calcFermentables() supplies:' + ok_fermentables + ' moutsuiker:' + sugarsm + '/' + sugarsf);
+  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 });
+  }
+
+  if (mvol > 0) {
+   v = s / sugardensity + mvol;
+   s = 1000 * s / (v * 10); //deg. Plato
+   est_mash_sg = Round(plato_to_sg(s), 5);
+   $('#est_mash_sg').val(est_mash_sg);
+  }
+
+  // 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 after boil
+  aboil_sg = estimate_sg(sugarsf, parseFloat(dataRecord.batch_size));
+  $('#est_og3').val(aboil_sg);
+
+  // Estimate SG in kettle before boil
+  preboil_sg = estimate_sg(sugarsm, parseFloat(dataRecord.boil_size));
+  $('#est_pre_sg').val(preboil_sg);
+
+  // Recalculate volumes.
+  aboil_volume = parseFloat(dataRecord.batch_size);
+  if (dataRecord.brew_aboil_volume > 0)
+   aboil_volume = dataRecord.brew_aboil_volume / 1.04;     // volume @ 20 degrees
+  if (dataRecord.brew_fermenter_tcloss == 0) {
+   dataRecord.brew_fermenter_tcloss = dataRecord.eq_trub_chiller_loss;
+   $('#brew_fermenter_tcloss').val(dataRecord.brew_fermenter_tcloss);
+  }
+  dataRecord.brew_fermenter_volume = aboil_volume - dataRecord.brew_fermenter_tcloss + dataRecord.brew_fermenter_extrawater;
+  $('#brew_fermenter_volume').val(dataRecord.brew_fermenter_volume);
+  // Estimated needed sparge water corrected for the temperature.
+  spoelw = (dataRecord.boil_size - mash_infuse + (mashkg * my_grain_absorbtion) + dataRecord.eq_lauter_deadspace) * 1.03;
+  $('#brew_sparge_est').val(spoelw);
+  // Calculate SG in fermenter
+  ogx = dataRecord.brew_aboil_sg;
+  if (ogx < 1.002)
+   ogx = aboil_sg;
+  topw = dataRecord.brew_fermenter_extrawater;
+
+  if (dataRecord.brew_fermenter_volume > 0) {
+   sug = sg_to_plato(ogx) * dataRecord.brew_fermenter_volume * ogx / 100;  //kg of sugar in
+   sug += addedS; //kg
+
+   if ((dataRecord.brew_fermenter_volume * ogx + addedmass) > 0) {
+    pt = 100 * sug / (dataRecord.brew_fermenter_volume * ogx + addedmass + topw);
+    dataRecord.brew_fermenter_sg = Round(plato_to_sg(pt), 4);
+    $('#brew_fermenter_sg').val(dataRecord.brew_fermenter_sg);
+    // color
+    if (dataRecord.color_method == 4) {
+     dataRecord.brew_fermenter_color = Math.round(((pt / 8.6) * colorn) + (dataRecord.boil_time / 60));
+    } else if (dataRecord.color_method == 3) {
+     dataRecord.brew_fermenter_color = Math.round((4.46 * bv * sr) / (aboil_volume + topw) * colorh);
+    } else {
+     cw = colort / (aboil_volume + topw) * 8.34436;
+     dataRecord.brew_fermenter_color = kw_to_ebc(dataRecord.color_method, cw);
+    }
+    $('#brew_fermenter_color').val(dataRecord.brew_fermenter_color);
+    scolor = ebc_to_color(dataRecord.brew_fermenter_color);
+    $('#bcolorf').show();
+    document.getElementById('bcolorf').style.background = scolor;
+   }
+  } else {
+   // Negative volume
+   dataRecord.brew_fermenter_sg = dataRecord.brew_fermenter_color = 0;
+   $('#brew_fermenter_sg').val(0);
+   $('#brew_fermenter_color').val(0);
+   $('#bcolorf').hide();
+  }
+
+  // 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.eq_mash_max * 100;
+  $('#perc_malts').jqxProgressBar('val', pmalts);
+  $('#perc_sugars').jqxProgressBar('val', psugar);
+  $('#perc_cara').jqxProgressBar('val', pcara);
+  calcStage();
+
+  // Calculate estimated svg.
+  svg = 0; // default.
+  initcells = 0;
+  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.
+    if (row.y_form == 0)
+     initcells += (parseFloat(row.y_cells) / 1000000000) * parseFloat(row.y_amount) * (dataRecord.starter_viability / 100);
+    else
+     initcells += (parseFloat(row.y_cells) / 1000000) * parseFloat(row.y_amount);
+   }
+   // TODO: brett in secondary ??
+   if ((((dataRecord.inventory_reduced <= 3) && (row.y_use == 0)) ||  // Primary
+        ((dataRecord.inventory_reduced <= 4) && (row.y_use == 1)) ||  // Secondary
+        ((dataRecord.inventory_reduced <= 5) && (row.y_use == 2)) ||  // Tertiary
+        ((dataRecord.inventory_reduced <= 6) && (row.y_use == 3))) && // Bottle
+        (row.y_inventory < row.y_amount)) {
+    ok_yeasts = 0;
+   }
+  }
+  calcSupplies();
+  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);
+  $('#est_fg3').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 final svg if available use the real value.
+  if ((dataRecord.stage >= 6) && (dataRecord.fg > 0.990) && (dataRecord.fg < dataRecord.brew_fermenter_sg)) {
+   svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.fg) / (dataRecord.brew_fermenter_sg - 1);
+   org = dataRecord.brew_fermenter_sg;
+   fig = dataRecord.fg;
+  }
+
+  $('#yeast_cells').val(initcells);
+  $('#need_cells').val(getNeededYeastCells());
+
+  // 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;
+
+  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);
+  }
+ }
+
+ /*
+  * 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 = Round(sug / tot, 3);
+
+  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 getNeededYeastCells() {
+
+  var plato, volume, sg = dataRecord.brew_fermenter_sg;
+  if (sg <= 1.0001 && dataRecord.fg > 1.000)
+   sg = dataRecord.fg;
+  else if (sg <= 1.0001)
+   sg = dataRecord.est_og;
+  plato = sg_to_plato(sg);
+
+  volume = dataRecord.brew_fermenter_volume;
+  if (volume <= 0)
+   volume = dataRecord.batch_size - dataRecord.eq_trub_chiller_loss;
+
+  return pitchrate * volume * plato;
+ }
+
+ 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 calcIBUs() {
+  var total_ibus = 0, ferm_ibus = 0, rows = {}, i, row;
+  hop_aroma = hop_flavour = 0;
+  if (!(rows = $('#hopGrid').jqxGrid('getrows'))) {
+   return;
+  }
+  ok_hops = 1;
+  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);
+   ferm_ibus += toIBU(row.h_useat, row.h_form, preboil_sg,
+                      parseFloat(dataRecord.brew_fermenter_volume) + parseFloat(dataRecord.brew_fermenter_tcloss),
+                      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));
-                        hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
-                                        row.h_useat, parseFloat(row.h_amount));
-                        if ((((dataRecord.inventory_reduced <= 2) && (row.h_useat <= 4)) ||  // Mash, FW, Boil, Aroma, Whirlpool
-                             ((dataRecord.inventory_reduced <= 6) && (row.h_useat == 5))) && // Dry-hop
-                             (row.h_inventory < row.h_amount))
-                                ok_hops = 0;
-                }
-                total_ibus = Math.round(total_ibus * 10) / 10;
-                ferm_ibus = Math.round(ferm_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+"  fermenter:"+ferm_ibus+" supplies:"+ok_hops);
-                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);
-                $("#brew_fermenter_ibu").val(ferm_ibus);
-                calcStage();
-                calcSupplies();
-        };
-
-        /*
-         * http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
-         *
-         * stype: 0=stirred, 1=shaken, 2=simple
-         * totcells: initial cells
-         * egrams: gram extract
-         */
-        function getGrowthRate(stype, totcells, egrams){
-
-                /* Cells per grams extract (B/g) */
-                var cpe = totcells / egrams;
-
-                if (cpe > 3.5)
-                        return 0;       // no growth
-                if (stype == 2)
-                        return 0.4;     // simple starter
-                if (stype == 1)
-                        return 0.62;    // shaken starter
-                if (cpe <= 1.4)         // stirred starter
-                        return 1.4;
-                return 2.33 - (.67 * cpe );
-        };
-
-        function calcStep(svol, stype, start) {
-
-            var gperpoint = 2.72715,  //number of grams of extract per point of starter gravity per liter
-                prate = start/svol * 1000,
-                irate = Round(prate,1),
-                egrams = (dataRecord.starter_sg - 1) * svol * gperpoint;
-                grate = getGrowthRate(stype, start, egrams),
-                ncells = Round(egrams * grate, 1),
-                totcells = parseFloat(ncells) + start;
-
-                console.log("svol:"+svol+" start:"+start+" irate:"+irate+" egrams:"+egrams+" grate:"+grate+" ncells:"+ncells);
-                return {
-                        svol: svol,
-                        irate: irate,
-                        prate: Round(prate,1),
-                        ncells: ncells,
-                        totcells: totcells,
-                        growf: Round(ncells/start, 2)
-                };
-        }
-
-        /*
-         * Calculate all starter steps.
-         * stype: final starter type: 0 = stirred, 1 = shaked, 2 = simple.
-         * start: initial cells in billions
-         * needed: needed cells in billions
-         *
-         * result: all values updated.
-         */
-        function calcSteps(stype, start, needed) {
-
-            var uvols  = [ 20, 40, 60,  80, 100, 150, 200, 250, 375, 500,  625, 750, 875, 1000, 1250, 1500, 2000, 2500, 3000, 4000, 5000 ],
-                mvols  = uvols.length, svol = 0, lasti = 0, result = {}, i;
-
-                /*
-                 * If no values are set, auto calculate the starter.
-                 */
-                if ((parseFloat($("#prop1_volume").jqxNumberInput('decimal')) + parseFloat($("#prop2_volume").jqxNumberInput('decimal')) +
-                     parseFloat($("#prop3_volume").jqxNumberInput('decimal')) + parseFloat($("#prop4_volume").jqxNumberInput('decimal'))) == 0) {
-                        // clear by default
-                        for (i = 1; i < 5; i++) {
-                                $("#prop"+i+"_type").hide();
-                                $("#r"+i+"_pmpt").show();
-                                $("#prop"+i+"_type").val(stype);
-                                $("#prop"+i+"_volume").hide();
-                                $("#prop"+i+"_volume").val(0);
-                                $("#prop"+i+"_irate").hide();
-                                $("#prop"+i+"_ncells").hide();
-                                $("#prop"+i+"_tcells").hide();
-                                $("#prop"+i+"_growf").hide();
-                        }
-                        if (start > needed) {
-                                return; // no starter needed
-                        }
-                        $("#prop1_type").show();
-                        $("#r1_pmpt").hide();
-                        $("#prop1_volume").show();
-                        $("#prop1_irate").show();
-                        $("#prop1_ncells").show();
-                        $("#prop1_tcells").show();
-                        $("#prop1_growf").show();
-                        for (i = lasti; i <= mvols; i++) {
-                                lasti = i;
-                                svol = uvols[lasti];
-                                result = calcStep(svol, stype, start);
-                                if (result.irate < 25) {
-                                        // inocculation rate too low, backup one step and break out.
-                                        lasti = i - 1;
-                                        svol = uvols[lasti];
-                                        result = calcStep(svol, stype, start);
-                                        break;
-                                }
-                                if (result.totcells > needed || i == mvols) { // hit the target or loops done
-                                        break;
-                                }
-                        }
-                        $("#prop1_volume").val(result.svol / 1000); // to liters
-                        $("#prop1_irate").val(result.prate);
-                        $("#prop1_ncells").val(result.ncells);
-                        $("#prop1_tcells").val(result.totcells);
-                        $("#prop1_growf").val(result.growf);
-                        if (result.totcells > needed)
-                                return; // hit the target
-
-                        // second stage
-                        $("#r2_pmpt").hide();
-                        $("#prop2_type").val(stype);
-                        $("#prop2_type").show();
-                        $("#prop2_volume").show();
-                        $("#prop2_irate").show();
-                        $("#prop2_ncells").show();
-                        $("#prop2_tcells").show();
-                        $("#prop2_growf").show();
-                        for (i = lasti; i <= mvols; i++) {
-                                lasti = i;
-                                svol = uvols[lasti];
-                                result = calcStep(svol, stype, $("#prop1_tcells").val());
-                                if (result.irate < 25) {
-                                        lasti = i - 1;
-                                        svol = uvols[lasti];
-                                        result = calcStep(svol, stype, $("#prop1_tcells").val());
-                                        break;
-                                }
-                                if (result.totcells > needed || i == mvols) { // hit the target or loops done
-                                        break;
-                                }
-                        }
-                        $("#prop2_volume").val(result.svol / 1000); // to liters
-                        $("#prop2_irate").val(result.prate);
-                        $("#prop2_ncells").val(result.ncells);
-                        $("#prop2_tcells").val(result.totcells);
-                        $("#prop2_growf").val(result.growf);
-                        if (result.totcells > needed)
-                                return; // hit the target
-
-                        // third stage
-                        $("#r3_pmpt").hide();
-                        $("#prop3_type").val(stype);
-                        $("#prop3_type").show();
-                        $("#prop3_volume").show();
-                        $("#prop3_irate").show();
-                        $("#prop3_ncells").show();
-                        $("#prop3_tcells").show();
-                        $("#prop3_growf").show();
-                        for (i = lasti; i <= mvols; i++) {
-                                lasti = i;
-                                svol = uvols[lasti];
-                                result = calcStep(svol, stype, $("#prop2_tcells").val());
-                                if (result.irate < 25) {
-                                        lasti = i - 1;
-                                        svol = uvols[lasti];
-                                        result = calcStep(svol, stype, $("#prop2_tcells").val());
-                                        break;
-                                }
-                                if (result.totcells > needed || i == mvols) { // hit the target or loops done
-                                        break;
-                                }
-                        }
-                        $("#prop3_volume").val(result.svol / 1000); // to liters
-                        $("#prop3_irate").val(result.prate);
-                        $("#prop3_ncells").val(result.ncells);
-                        $("#prop3_tcells").val(result.totcells);
-                        $("#prop3_growf").val(result.growf);
-                        if (result.totcells > needed)
-                                return; // hit the target
-
-                        // fourth stage
-                        $("#r4_pmpt").hide();
-                        $("#prop4_type").val(stype);
-                        $("#prop4_type").show();
-                        $("#prop4_volume").show();
-                        $("#prop4_irate").show();
-                        $("#prop4_ncells").show();
-                        $("#prop4_tcells").show();
-                        $("#prop4_growf").show();
-                        for (i = lasti; i <= mvols; i++) {
-                                lasti = i;
-                                svol = uvols[lasti];
-                                result = calcStep(svol, stype, $("#prop3_tcells").val());
-                                if (result.totcells > needed || i == mvols) { // hit the target or loops done
-                                        $("#prop4_volume").val(result.svol / 1000); // to liters
-                                        $("#prop4_irate").val(result.prate);
-                                        $("#prop4_ncells").val(result.ncells);
-                                        $("#prop4_tcells").val(result.totcells);
-                                        $("#prop4_growf").val(result.growf);
-                                        return;
-                                }
-                        }
-                } else {
-                        // recalculate
-                        if (dataRecord.prop1_volume > 0) {
-                                $("#r1_pmpt").hide();
-                                $("#prop1_type").show();
-                                $("#prop1_volume").show();
-                                $("#prop1_irate").show();
-                                $("#prop1_ncells").show();
-                                $("#prop1_tcells").show();
-                                $("#prop1_growf").show();
-                                result = calcStep($("#prop1_volume").val() * 1000, dataRecord.prop1_type, start);
-                                $("#prop1_irate").val(result.prate);
-                                $("#prop1_ncells").val(result.ncells);
-                                $("#prop1_tcells").val(result.totcells);
-                                $("#prop1_growf").val(result.growf);
-                        }
-                        if (dataRecord.prop2_volume > 0) {
-                                $("#r2_pmpt").hide();
-                                $("#prop2_type").show();
-                                $("#prop2_volume").show();
-                                $("#prop2_irate").show();
-                                $("#prop2_ncells").show();
-                                $("#prop2_tcells").show();
-                                $("#prop2_growf").show();
-                                result = calcStep($("#prop2_volume").val() * 1000, dataRecord.prop2_type, $("#prop1_tcells").val());
-                                $("#prop2_irate").val(result.prate);
-                                $("#prop2_ncells").val(result.ncells);
-                                $("#prop2_tcells").val(result.totcells);
-                                $("#prop2_growf").val(result.growf);
-                        }
-                        if (dataRecord.prop3_volume > 0) {
-                                $("#r3_pmpt").hide();
-                                $("#prop3_type").show();
-                                $("#prop3_volume").show();
-                                $("#prop3_irate").show();
-                                $("#prop3_ncells").show();
-                                $("#prop3_tcells").show();
-                                $("#prop3_growf").show();
-                                result = calcStep($("#prop3_volume").val() * 1000, dataRecord.prop3_type, $("#prop2_tcells").val());
-                                $("#prop3_irate").val(result.prate);
-                                $("#prop3_ncells").val(result.ncells);
-                                $("#prop3_tcells").val(result.totcells);
-                                $("#prop3_growf").val(result.growf);
-                        }
-                        if (dataRecord.prop4_volume > 0) {
-                                $("#r4_pmpt").hide();
-                                $("#prop4_type").show();
-                                $("#prop4_volume").show();
-                                $("#prop4_irate").show();
-                                $("#prop4_ncells").show();
-                                $("#prop4_tcells").show();
-                                $("#prop4_growf").show();
-                                result = calcStep($("#prop4_volume").val() * 1000, dataRecord.prop4_type, $("#prop3_tcells").val());
-                                $("#prop4_irate").val(result.prate);
-                                $("#prop4_ncells").val(result.ncells);
-                                $("#prop4_tcells").val(result.totcells);
-                                $("#prop4_growf").val(result.growf);
-                        }
-
-                }
-        }
-
-        function calcYeast() {
-
-                // Calculate needed cells.
-		var plato, volume, rows, rowscount, row, i, needed, use_cells,
-                sg = dataRecord.brew_fermenter_sg;
-                if (sg <= 1.0001 && dataRecord.fg > 1.000)
-                        sg = dataRecord.fg;
-                else if (sg <= 1.0001)
-                        sg = dataRecord.est_og;
-                plato = sg_to_plato(sg);
-
-                volume = dataRecord.brew_fermenter_volume;
-                if (volume > 0) {
-                        if (dataRecord.brew_fermenter_extrawater > 0)
-                                volume += dataRecord.brew_fermenter_extrawater;
-                } else {
-                        volume = dataRecord.batch_size - dataRecord.eq_trub_chiller_loss;
-                }
-
-                // Also in calcFermentables()
-                $("#yeast_cells").val(initcells);
-
-                if (!(rows = $('#yeastGrid').jqxGrid('getrows'))) {
-                        return; // grid not yet loaded.
-                }
-                rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
-                if (rowscount == 0)
-                        return; // no yeast in recipe
-
-                for (i = 0; i < rowscount; i++) {
-                        row = $("#yeastGrid").jqxGrid('getrowdata', i);
-                        if (row.y_use == 0) { // primary
-                                // pitchrate see https://www.brewersfriend.com/yeast-pitch-rate-and-starter-calculator/
-                                // and http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
-                                pitchrate = 0.75;
-                                if (dataRecord.est_og > 1.060)
-                                        pitchrate = 1.0;
-//                              if (dataRecord.est_og > 1.076)
-//                                      pitchrate = 1.25;       // Wyeast labs. http://www.wyeastlab.com/hb_pitchrates.cfm
-                                if (row.y_type == 0) // lager yeast
-                                        pitchrate *= 2;
-
-                                if (row.y_form == 1) { // dry yeast
-                                } else { // possible starter needed
-                                }
-                        }
-                }
-                needed = pitchrate * volume * plato;
-                console.log("calcYeast() pitchrate:"+pitchrate+" start:"+initcells+" needed:"+needed+" volume:"+volume);
-                $("#need_cells").val(needed);
-                use_cells = initcells;
-
-                if (dataRecord.starter_enable) {
-                        calcSteps(dataRecord.starter_type, initcells, needed);
-
-                        for (i = 1; i < 5; i++) {
-                                $("#r"+i+"_irate").html("");
-                                $("#r"+i+"_growf").html("");
-                                $("#r"+i+"_tcells").html("");
-                                if (parseFloat($("#prop"+i+"_volume").val()) > 0) {
-                                        if ((parseFloat($("#prop"+i+"_irate").val()) < 25) || (parseFloat($("#prop"+i+"_irate").val()) > 100)) {
-                                                $("#r"+i+"_irate").html("<img src='images/dialog-error.png'>");
-                                        } else {
-                                                $("#r"+i+"_irate").html("<img src='images/dialog-ok-apply.png'>");
-                                        }
-                                        if (parseFloat($("#prop"+i+"_growf").val()) < 1)
-                                                $("#r"+i+"_growf").html("<img src='images/dialog-error.png'>");
-                                        if (($("#prop"+i+"_type").val() > 0) && (parseFloat($("#prop"+i+"_growf").val()) > 3))
-                                                $("#r"+i+"_growf").html("<img src='images/dialog-error.png'>");
-                                        if (parseFloat($("#prop"+i+"_tcells").val()) > needed)
-                                                $("#r"+i+"_tcells").html("<img src='images/dialog-ok-apply.png'>");
-                                        use_cells = parseFloat($("#prop"+i+"_tcells").val());
-                                } else {
-                                        $("#r"+i+"_irate").html("");
-                                }
-                        }
-                }
-                $("#plato_cells").val(parseFloat(use_cells / (volume * plato) ));
-        };
-
-        function adjustHops(factor) {
-
-                console.log("adjustHops("+factor+")");
-                var row, i, 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 calcMiscs() {
-
-                ok_miscs = 1;
-                var row, i, rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount;
-                if (rowscount == 0)
-                        return;
-                for (i = 0; i < rowscount; i++) {
-                        row = $("#miscGrid").jqxGrid('getrowdata', i);
-                        if ((((dataRecord.inventory_reduced <= 2) && (row.m_use_use <= 2)) ||  // Starter, Mash, Boil
-                             ((dataRecord.inventory_reduced <= 3) && (row.m_use_use == 3)) ||  // Primary
-                             ((dataRecord.inventory_reduced <= 5) && (row.m_use_use == 4)) ||  // Secondary, Teriary
-                             ((dataRecord.inventory_reduced <= 6) && (row.m_use_use == 5))) && // Bottle
-                             (row.m_inventory < row.m_amount)) {
-                                ok_miscs = 0;
-                        }
-                }
-                calcSupplies();
-        };
-
-        function adjustMiscs(factor) {
-
-                console.log("adjustMiscs("+factor+")");
-                var row, i, 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 row, i, 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);
-                        }
-                }
-                calcYeast();
-        };
-
-        function adjustWaters(factor) {
-
-                console.log("adjustWaters("+factor+")");
-                var amount, row, i, 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 calcMashEfficiency() {
-		var c, m;
-                if (parseFloat($("#brew_mash_sg").jqxNumberInput('decimal')) < 1.002)
-                        return;
-                c = sg_to_plato(est_mash_sg);
-                m = sg_to_plato(parseFloat($("#brew_mash_sg").jqxNumberInput('decimal')));
-                if (c > 0.5)
-                        $("#brew_mash_efficiency").val(100 * m / c);
-                else
-                        $("#brew_mash_efficiency").val(0);
-        };
-
-        function calcEfficiencyBeforeBoil() {
-                var m = 0, rows = {}, i, row, tot, result = 0;
-                if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) {
-                        return; // grid not yet loaded.
-                }
-                for (i = 0; i < rows.length; i++) {
-                        row = rows[i];
-                        if (row.f_added == 0) { // Mash
-                                m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-                        }
-                }
-                tot = sg_to_plato(dataRecord.brew_preboil_sg) * (dataRecord.brew_preboil_volume / 1.04) * dataRecord.brew_preboil_sg * 10 / 1000;
-                if (m > 0)
-                        result = Round((tot / m * 100), 1);
-                if (result < 0)
-                        result = 0;
-                $("#brew_preboil_efficiency").val(result);
-        }
-
-        function calcEfficiencyAfterBoil() {
-                var m = 0,	// Sugars added at mash
-                b = 0,		// Sugars added at boil
-                rows = {}, i, row, tot, result = 0;
-                if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) {
-                        return; // grid not yet loaded.
-                }
-                for (i = 0; i < rows.length; i++) {
-                        row = rows[i];
-                        if (row.f_added == 0) { // Mash
-                                m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-                        } else if (row.f_added == 1) { // Boil
-                                b += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-                        }
-                }
-                tot = sg_to_plato(dataRecord.brew_aboil_sg) * (dataRecord.brew_aboil_volume / 1.04) * dataRecord.brew_aboil_sg * 10 / 1000;
-                tot -= b;       // total sugars in wort  minus added sugars.
-                if (m > 0)
-                        result = Round((tot / m * 100), 1);
-                if (result < 0)
-                        result = 0;
-                dataRecord.brew_aboil_efficiency = result;
-                $("#brew_aboil_efficiency").val(result);
-
-        }
-
-        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) {
-                var row, i, id, found = false, miscs, rows = $('#miscGrid').jqxGrid('getrows');
-                if (amount == 0) {
+   if ((((dataRecord.inventory_reduced <= 2) && (row.h_useat <= 4)) ||  // Mash, FW, Boil, Aroma, Whirlpool
+        ((dataRecord.inventory_reduced <= 6) && (row.h_useat == 5))) && // Dry-hop
+        (row.h_inventory < row.h_amount))
+    ok_hops = 0;
+  }
+  total_ibus = Math.round(total_ibus * 10) / 10;
+  ferm_ibus = Math.round(ferm_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 +
+               ' fermenter:' + ferm_ibus + ' supplies:' + ok_hops);
+  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);
+  $('#brew_fermenter_ibu').val(ferm_ibus);
+  calcStage();
+  calcSupplies();
+ };
+
+ /*
+  * http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
+  *
+  * stype: 0=stirred, 1=shaken, 2=simple
+  * totcells: initial cells
+  * egrams: gram extract
+  */
+ function getGrowthRate(stype, totcells, egrams) {
+
+  /* Cells per grams extract (B/g) */
+  var cpe = totcells / egrams;
+
+  if (cpe > 3.5)
+   return 0;       // no growth
+  if (stype == 2)
+   return 0.4;     // simple starter
+  if (stype == 1)
+   return 0.62;    // shaken starter
+  if (cpe <= 1.4)  // stirred starter
+   return 1.4;
+  return 2.33 - (.67 * cpe);
+ };
+
+ function calcStep(svol, stype, start) {
+
+  var gperpoint = 2.72715,  //number of grams of extract per point of starter gravity per liter
+  prate = start / svol * 1000,
+  irate = Round(prate, 1),
+  egrams = (dataRecord.starter_sg - 1) * svol * gperpoint,
+  grate = getGrowthRate(stype, start, egrams),
+  ncells = Round(egrams * grate, 1),
+  totcells = parseFloat(ncells) + start;
+
+  console.log('svol:' + svol + ' start:' + start + ' irate:' + irate + ' egrams:' + egrams + ' grate:' + grate + ' ncells:' + ncells);
+  return {
+   svol: svol,
+   irate: irate,
+   prate: Round(prate, 1),
+   ncells: ncells,
+   totcells: totcells,
+   growf: Round(ncells / start, 2)
+  };
+ }
+
+ /*
+  * Calculate all starter steps.
+  * stype: final starter type: 0 = stirred, 1 = shaked, 2 = simple.
+  * start: initial cells in billions
+  * needed: needed cells in billions
+  *
+  * result: all values updated.
+  */
+ function calcSteps(stype, start, needed) {
+
+  var uvols = [20, 40, 60, 80, 100, 150, 200, 250, 375, 500, 625, 750, 875, 1000, 1250, 1500, 2000, 2500, 3000, 4000, 5000],
+      mvols = uvols.length, svol = 0, lasti = 0, result = {}, i;
+
+  /*
+   * If no values are set, auto calculate the starter.
+   */
+  if ((parseFloat($('#prop1_volume').jqxNumberInput('decimal')) + parseFloat($('#prop2_volume').jqxNumberInput('decimal')) +
+       parseFloat($('#prop3_volume').jqxNumberInput('decimal')) + parseFloat($('#prop4_volume').jqxNumberInput('decimal'))) == 0) {
+   // clear by default
+   for (i = 1; i < 5; i++) {
+    $('#prop' + i + '_type').hide();
+    $('#r' + i + '_pmpt').show();
+    $('#prop' + i + '_type').val(stype);
+    $('#prop' + i + '_volume').hide();
+    $('#prop' + i + '_volume').val(0);
+    $('#prop' + i + '_irate').hide();
+    $('#prop' + i + '_ncells').hide();
+    $('#prop' + i + '_tcells').hide();
+    $('#prop' + i + '_growf').hide();
+   }
+   if (start > needed) {
+    return; // no starter needed
+   }
+   $('#prop1_type').show();
+   $('#r1_pmpt').hide();
+   $('#prop1_volume').show();
+   $('#prop1_irate').show();
+   $('#prop1_ncells').show();
+   $('#prop1_tcells').show();
+   $('#prop1_growf').show();
+   for (i = lasti; i <= mvols; i++) {
+    lasti = i;
+    svol = uvols[lasti];
+    result = calcStep(svol, stype, start);
+    if (result.irate < 25) {
+     // inocculation rate too low, backup one step and break out.
+     lasti = i - 1;
+     svol = uvols[lasti];
+     result = calcStep(svol, stype, start);
+     break;
+    }
+    if (result.totcells > needed || i == mvols) { // hit the target or loops done
+     break;
+    }
+   }
+   $('#prop1_volume').val(result.svol / 1000); // to liters
+   $('#prop1_irate').val(result.prate);
+   $('#prop1_ncells').val(result.ncells);
+   $('#prop1_tcells').val(result.totcells);
+   $('#prop1_growf').val(result.growf);
+   if (result.totcells > needed)
+    return; // hit the target
+
+   // second stage
+   $('#r2_pmpt').hide();
+   $('#prop2_type').val(stype);
+   $('#prop2_type').show();
+   $('#prop2_volume').show();
+   $('#prop2_irate').show();
+   $('#prop2_ncells').show();
+   $('#prop2_tcells').show();
+   $('#prop2_growf').show();
+   for (i = lasti; i <= mvols; i++) {
+    lasti = i;
+    svol = uvols[lasti];
+    result = calcStep(svol, stype, $('#prop1_tcells').val());
+    if (result.irate < 25) {
+     lasti = i - 1;
+     svol = uvols[lasti];
+     result = calcStep(svol, stype, $('#prop1_tcells').val());
+     break;
+    }
+    if (result.totcells > needed || i == mvols) { // hit the target or loops done
+     break;
+    }
+   }
+   $('#prop2_volume').val(result.svol / 1000); // to liters
+   $('#prop2_irate').val(result.prate);
+   $('#prop2_ncells').val(result.ncells);
+   $('#prop2_tcells').val(result.totcells);
+   $('#prop2_growf').val(result.growf);
+   if (result.totcells > needed)
+    return; // hit the target
+
+   // third stage
+   $('#r3_pmpt').hide();
+   $('#prop3_type').val(stype);
+   $('#prop3_type').show();
+   $('#prop3_volume').show();
+   $('#prop3_irate').show();
+   $('#prop3_ncells').show();
+   $('#prop3_tcells').show();
+   $('#prop3_growf').show();
+   for (i = lasti; i <= mvols; i++) {
+    lasti = i;
+    svol = uvols[lasti];
+    result = calcStep(svol, stype, $('#prop2_tcells').val());
+    if (result.irate < 25) {
+     lasti = i - 1;
+     svol = uvols[lasti];
+     result = calcStep(svol, stype, $('#prop2_tcells').val());
+     break;
+    }
+    if (result.totcells > needed || i == mvols) { // hit the target or loops done
+     break;
+    }
+   }
+   $('#prop3_volume').val(result.svol / 1000); // to liters
+   $('#prop3_irate').val(result.prate);
+   $('#prop3_ncells').val(result.ncells);
+   $('#prop3_tcells').val(result.totcells);
+   $('#prop3_growf').val(result.growf);
+   if (result.totcells > needed)
+    return; // hit the target
+
+   // fourth stage
+   $('#r4_pmpt').hide();
+   $('#prop4_type').val(stype);
+   $('#prop4_type').show();
+   $('#prop4_volume').show();
+   $('#prop4_irate').show();
+   $('#prop4_ncells').show();
+   $('#prop4_tcells').show();
+   $('#prop4_growf').show();
+   for (i = lasti; i <= mvols; i++) {
+    lasti = i;
+    svol = uvols[lasti];
+    result = calcStep(svol, stype, $('#prop3_tcells').val());
+    if (result.totcells > needed || i == mvols) { // hit the target or loops done
+     $('#prop4_volume').val(result.svol / 1000); // to liters
+     $('#prop4_irate').val(result.prate);
+     $('#prop4_ncells').val(result.ncells);
+     $('#prop4_tcells').val(result.totcells);
+     $('#prop4_growf').val(result.growf);
+     return;
+    }
+   }
+  } else {
+   // recalculate
+   if (dataRecord.prop1_volume > 0) {
+    $('#r1_pmpt').hide();
+    $('#prop1_type').show();
+    $('#prop1_volume').show();
+    $('#prop1_irate').show();
+    $('#prop1_ncells').show();
+    $('#prop1_tcells').show();
+    $('#prop1_growf').show();
+    result = calcStep($('#prop1_volume').val() * 1000, dataRecord.prop1_type, start);
+    $('#prop1_irate').val(result.prate);
+    $('#prop1_ncells').val(result.ncells);
+    $('#prop1_tcells').val(result.totcells);
+    $('#prop1_growf').val(result.growf);
+   }
+   if (dataRecord.prop2_volume > 0) {
+    $('#r2_pmpt').hide();
+    $('#prop2_type').show();
+    $('#prop2_volume').show();
+    $('#prop2_irate').show();
+    $('#prop2_ncells').show();
+    $('#prop2_tcells').show();
+    $('#prop2_growf').show();
+    result = calcStep($('#prop2_volume').val() * 1000, dataRecord.prop2_type, $('#prop1_tcells').val());
+    $('#prop2_irate').val(result.prate);
+    $('#prop2_ncells').val(result.ncells);
+    $('#prop2_tcells').val(result.totcells);
+    $('#prop2_growf').val(result.growf);
+   }
+   if (dataRecord.prop3_volume > 0) {
+    $('#r3_pmpt').hide();
+    $('#prop3_type').show();
+    $('#prop3_volume').show();
+    $('#prop3_irate').show();
+    $('#prop3_ncells').show();
+    $('#prop3_tcells').show();
+    $('#prop3_growf').show();
+    result = calcStep($('#prop3_volume').val() * 1000, dataRecord.prop3_type, $('#prop2_tcells').val());
+    $('#prop3_irate').val(result.prate);
+    $('#prop3_ncells').val(result.ncells);
+    $('#prop3_tcells').val(result.totcells);
+    $('#prop3_growf').val(result.growf);
+   }
+   if (dataRecord.prop4_volume > 0) {
+    $('#r4_pmpt').hide();
+    $('#prop4_type').show();
+    $('#prop4_volume').show();
+    $('#prop4_irate').show();
+    $('#prop4_ncells').show();
+    $('#prop4_tcells').show();
+    $('#prop4_growf').show();
+    result = calcStep($('#prop4_volume').val() * 1000, dataRecord.prop4_type, $('#prop3_tcells').val());
+    $('#prop4_irate').val(result.prate);
+    $('#prop4_ncells').val(result.ncells);
+    $('#prop4_tcells').val(result.totcells);
+    $('#prop4_growf').val(result.growf);
+   }
+  }
+ }
+
+ function calcYeast() {
+
+  // Calculate needed cells.
+  var plato, volume, rows, rowscount, row, i, needed, use_cells, sg = dataRecord.brew_fermenter_sg;
+  if (sg <= 1.0001 && dataRecord.fg > 1.000)
+   sg = dataRecord.fg;
+  else if (sg <= 1.0001)
+   sg = dataRecord.est_og;
+  plato = sg_to_plato(sg);
+
+  volume = dataRecord.brew_fermenter_volume;
+  if (volume > 0) {
+   if (dataRecord.brew_fermenter_extrawater > 0)
+    volume += dataRecord.brew_fermenter_extrawater;
+  } else {
+   volume = dataRecord.batch_size - dataRecord.eq_trub_chiller_loss;
+  }
+
+  // Also in calcFermentables()
+  $('#yeast_cells').val(initcells);
+
+  if (!(rows = $('#yeastGrid').jqxGrid('getrows'))) {
+   return; // grid not yet loaded.
+  }
+  rowscount = $('#yeastGrid').jqxGrid('getdatainformation').rowscount;
+  if (rowscount == 0)
+   return; // no yeast in recipe
+
+  for (i = 0; i < rowscount; i++) {
+   row = $('#yeastGrid').jqxGrid('getrowdata', i);
+   if (row.y_use == 0) { // primary
+    // pitchrate see https://www.brewersfriend.com/yeast-pitch-rate-and-starter-calculator/
+    // and http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
+    pitchrate = 0.75;
+    if (dataRecord.est_og > 1.060)
+     pitchrate = 1.0;
+//  if (dataRecord.est_og > 1.076)
+//   pitchrate = 1.25;       // Wyeast labs. http://www.wyeastlab.com/hb_pitchrates.cfm
+    if (row.y_type == 0) // lager yeast
+     pitchrate *= 2;
+
+//    if (row.y_form == 1) { // dry yeast
+//    } else { // possible starter needed
+//    }
+   }
+  }
+  needed = pitchrate * volume * plato;
+  console.log('calcYeast() pitchrate:' + pitchrate + ' start:' + initcells + ' needed:' + needed + ' volume:' + volume);
+  $('#need_cells').val(needed);
+  use_cells = initcells;
+
+  if (dataRecord.starter_enable) {
+   calcSteps(dataRecord.starter_type, initcells, needed);
+
+   for (i = 1; i < 5; i++) {
+    $('#r' + i + '_irate').html('');
+    $('#r' + i + '_growf').html('');
+    $('#r' + i + '_tcells').html('');
+    if (parseFloat($('#prop' + i + '_volume').val()) > 0) {
+     if ((parseFloat($('#prop' + i + '_irate').val()) < 25) || (parseFloat($('#prop' + i + '_irate').val()) > 100)) {
+      $('#r' + i + '_irate').html("<img src='images/dialog-error.png'>");
+     } else {
+      $('#r' + i + '_irate').html("<img src='images/dialog-ok-apply.png'>");
+     }
+     if (parseFloat($('#prop' + i + '_growf').val()) < 1)
+      $('#r' + i + '_growf').html("<img src='images/dialog-error.png'>");
+     if (($('#prop' + i + '_type').val() > 0) && (parseFloat($('#prop' + i + '_growf').val()) > 3))
+      $('#r' + i + '_growf').html("<img src='images/dialog-error.png'>");
+     if (parseFloat($('#prop' + i + '_tcells').val()) > needed)
+      $('#r' + i + '_tcells').html("<img src='images/dialog-ok-apply.png'>");
+     use_cells = parseFloat($('#prop' + i + '_tcells').val());
+    } else {
+     $('#r' + i + '_irate').html('');
+    }
+   }
+  }
+  $('#plato_cells').val(parseFloat(use_cells / (volume * plato)));
+ };
+
+ function adjustHops(factor) {
+
+  console.log('adjustHops(' + factor + ')');
+  var row, i, 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 calcMiscs() {
+
+  ok_miscs = 1;
+  var row, i, rowscount = $('#miscGrid').jqxGrid('getdatainformation').rowscount;
+  if (rowscount == 0)
+   return;
+  for (i = 0; i < rowscount; i++) {
+   row = $('#miscGrid').jqxGrid('getrowdata', i);
+   if ((((dataRecord.inventory_reduced <= 2) && (row.m_use_use <= 2)) ||  // Starter, Mash, Boil
+        ((dataRecord.inventory_reduced <= 3) && (row.m_use_use == 3)) ||  // Primary
+        ((dataRecord.inventory_reduced <= 5) && (row.m_use_use == 4)) ||  // Secondary, Teriary
+        ((dataRecord.inventory_reduced <= 6) && (row.m_use_use == 5))) && // Bottle
+        (row.m_inventory < row.m_amount)) {
+    ok_miscs = 0;
+   }
+  }
+  calcSupplies();
+ };
+
+ function adjustMiscs(factor) {
+
+  console.log('adjustMiscs(' + factor + ')');
+  var row, i, 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 row, i, 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);
+   }
+  }
+  calcYeast();
+ };
+
+ function adjustWaters(factor) {
+
+  console.log('adjustWaters(' + factor + ')');
+  var amount, row, i, 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 calcMashEfficiency() {
+  var c, m;
+  if (parseFloat($('#brew_mash_sg').jqxNumberInput('decimal')) < 1.002)
+   return;
+  c = sg_to_plato(est_mash_sg);
+  m = sg_to_plato(parseFloat($('#brew_mash_sg').jqxNumberInput('decimal')));
+  if (c > 0.5)
+   $('#brew_mash_efficiency').val(100 * m / c);
+  else
+   $('#brew_mash_efficiency').val(0);
+ };
+
+ function calcEfficiencyBeforeBoil() {
+  var m = 0, rows = {}, i, row, tot, result = 0;
+  if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) {
+   return; // grid not yet loaded.
+  }
+  for (i = 0; i < rows.length; i++) {
+   row = rows[i];
+   if (row.f_added == 0) { // Mash
+    m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+   }
+  }
+  tot = sg_to_plato(dataRecord.brew_preboil_sg) * (dataRecord.brew_preboil_volume / 1.04) * dataRecord.brew_preboil_sg * 10 / 1000;
+  if (m > 0)
+   result = Round((tot / m * 100), 1);
+  if (result < 0)
+   result = 0;
+  $('#brew_preboil_efficiency').val(result);
+ }
+
+ function calcEfficiencyAfterBoil() {
+  var m = 0, // Sugars added at mash
+  b = 0,     // Sugars added at boil
+  rows = {}, i, row, tot, result = 0;
+  if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) {
+   return; // grid not yet loaded.
+  }
+  for (i = 0; i < rows.length; i++) {
+   row = rows[i];
+   if (row.f_added == 0) { // Mash
+    m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+   } else if (row.f_added == 1) { // Boil
+    b += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
+   }
+  }
+  tot = sg_to_plato(dataRecord.brew_aboil_sg) * (dataRecord.brew_aboil_volume / 1.04) * dataRecord.brew_aboil_sg * 10 / 1000;
+  tot -= b;       // total sugars in wort  minus added sugars.
+  if (m > 0)
+   result = Round((tot / m * 100), 1);
+  if (result < 0)
+   result = 0;
+  dataRecord.brew_aboil_efficiency = result;
+  $('#brew_aboil_efficiency').val(result);
+ }
+
+ 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) {
+  var row, i, id, found = false, miscs, 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() {
+      var record, i, row = {}, records = miscs.records;
+      for (i = 0; i < records.length; i++) {
+       record = records[i];
+       if (record.name == name) {
+        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;
+   }
+  }
+ }
+
+ 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 Magn, Z, 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 rows, i, C1, ebc, x, 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: // Melkzuur
+    return { pK1: 3.86, pK2: 20, pK3: 20, MolWt: 90.08, AcidSG: 1214, AcidPrc: 0.88 };
+   case 1: // Zoutzuur
+    return { pK1: -7, pK2: 20, pK3: 20, MolWt: 36.46, AcidSG: 1142, AcidPrc: 0.28 };
+   case 2: // Fosforzuur
+    return { pK1: 2.12, pK2: 7.20, pK3: 12.44, MolWt: 98.00, AcidSG: 1170, AcidPrc: 0.25 };
+   case 3: // Zwavelzuur
+    return { pK1: -1, pK2: 1.92, pK3: 20, MolWt: 98.07, AcidSG: 1700, AcidPrc: 0.93 };
+  }
+ }
+
+ 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;
+  }
+
+  // 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 {