www/js/prod_edit.js

Mon, 24 Dec 2018 23:10:52 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 24 Dec 2018 23:10:52 +0100
changeset 151
2c9cfe2f0860
parent 149
ff45488d480e
child 152
2e4249add363
permissions
-rw-r--r--

Merged prod_main and prod_recipe database tables into products. Added recipe tabs in the products editor.

/*****************************************************************************
 * Copyright (C) 2018
 *
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of BMS
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * BrewCloud is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/


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	brewstage = 0;	// Numeric value of stage
	var     preboil_sg = 0;
	var	est_mash_sg = 0;
	var     sugarsm = 0;    // Sugars after mash
	var     sugarsf = 0;    // Sugars after boil
	var     psugar = 0;     // Percentage real sugars
	var     pcara = 0;      // Percentage cara/crystal malts
	var     svg = 77;               // Default attenuation
        var     mashkg = 0;             // Malt in mash weight
        var     hop_flavour = 0;
        var     hop_aroma = 0;
        var     mash_infuse = 0;
        var     last_base = '';
        var     last_acid = '';

        var     MMCa = 40.048;
        var     MMMg = 24.305;
        var     MMNa = 22.98976928;
        var     MMCl = 35.453;
        var     MMSO4 = 96.0626;
        var     MMCO3 = 60.01684;
        var     MMHCO3 = 61.01684;
        var     MMCaSO4 = 172.171;
        var     MMCaCl2 = 147.015;
        var     MMCaCO3 = 100.087;
        var     MMMgSO4 = 246.475;
        var     MMNaHCO3 = 84.007;
        var     MMNa2CO3 = 105.996;
        var     MMNaCl = 58.443;
        var     MMCaOH2 = 74.06268;

	var	old_efficiency;
	var	old_batch_size;
	var	old_boil_time;

	console.log("record:" + my_record + "  return:" + my_return + "  theme:" + theme);
        $("#jqxLoader").jqxLoader({
                width: 250,
                height: 150,
                isModal: true,
                text: "Laden product ...",
                theme: theme
        });

	function calcFermentables() {
		console.log("calcFermentables()");
		sugarsf = 0;
		sugarsm = 0;
		psugar = 0;
		pcara = 0;
		mashkg = 0;
		var colorw = 0; // Colors working
		var my_100 = false;

                var rows = $('#fermentableGrid').jqxGrid('getrows');
                for (var i = 0; i < rows.length; i++) {
                        var row = rows[i];
                        if (row.f_adjust_to_total_100)
                                my_100 = true;
			if (row.f_type == "Sugar")
				psugar += row.f_percentage;
			if (row.f_graintype == "Crystal")
				pcara += row.f_percentage;
			var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
			if (row.f_added == "Mash") {
				d = parseFloat(dataRecord.efficiency) / 100 * d;
				sugarsm += d;
				mashkg += row.f_amount;
			}
			sugarsf += d;
			colorw += row.f_amount * ebc_to_srm(row.f_color) / parseFloat(dataRecord.batch_size) * 8.34436;
		}
		to_100 = my_100;
		var est_og = estimate_sg(sugarsf, parseFloat(dataRecord.batch_size));
                $('#est_og').val(est_og);
                $('#est_og2').val(est_og);
		preboil_sg = estimate_sg(sugarsm, parseFloat(dataRecord.boil_size));
		var color = kw_to_ebc(dataRecord.color_method, colorw);
                $('#est_color').val(color);
                $('#est_color2').val(color);
                var scolor = ebc_to_color(color);
                document.getElementById("bcolor").style.background= scolor;
                document.getElementById("bcolor2").style.background= scolor;
                pmalts = mashkg / dataRecord.eq_mash_max * 100;
                $("#perc_malts").jqxProgressBar('val', pmalts);
                $("#perc_sugars").jqxProgressBar('val', psugar);
                $("#perc_cara").jqxProgressBar('val', pcara);
	};

	function calcFermentablesFromOG(OG) {

		console.log("calcFermentablesFromOG("+OG+")");
		var     i, j, sug, d, tot, totmass;
		var     vol, vol1, vol2, sug2;
		var     mass1, mass2, efficiency;

		for (j = 1; j < 15; j++) {      // Maybe needed if there is equipment, not here.
			vol = 0;
			sug2 = 0;
			efficiency = parseFloat(dataRecord.efficiency);
			var rows = $('#fermentableGrid').jqxGrid('getrows');
			for (i = 0; i < rows.length; i++) {
				row = rows[i];
				if ((row.f_added == "Fermentation") || (row.f_added == "Lagering") || (row.f_added == "Bottle")) {
					var x = (row.f_yield / 100) * (1 - row.f_moisture / 100);
					vol += row.f_amount / (x * sugardensity + (1 - x) * 1);
					sug2 += row.f_amount * x;
				}
			}
	//              if FEquipment <> NIL then               /* Use this for prod_edit.js
	//              begin
	//              	sug:= SGToPlato(OG) * OG / 100; //kg/l
	//              	vol1:= FBatchSize.Value - FEquipment.TrubChillerLoss.Value;
	//              	vol2:= vol1 + FEquipment.TopUpWater.Value + vol;
	//              	sug:= sug * vol2; //kg in het gistvat
	//              	sug:= sug - sug2; //kg voor toevoeging in gistvat
	//              	if vol1 > 0 then
	//              		sug:= sug * FBatchSize.Value / vol1; //kg in kookketel
	//              	sug:= sug + sug2;
	//              end
	//              else
				sug = sg_to_plato(OG) * parseFloat($("#batch_size").jqxNumberInput('decimal')) * OG / 100;      //total amount of sugars in kg

			tot = 0;
			d = 0;
			for (i = 0; i < rows.length; i++) {
				row = rows[i];
				d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100);
				if (row.f_added == "Mash")
					d = efficiency / 100 * d;
				tot += d;
			}
			if (tot)
				totmass = sug / tot;
			else
				totmass = 0;

			if (totmass) {
				console.log("pass:"+j+" totmass:"+totmass);
				for (i = 0; i < rows.length; i++) {
					row = rows[i];
					row.f_amount = row.f_percentage / 100 * totmass;
					$("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", row.f_percentage / 100 * totmass);
				}
			}
		};
		//CalcWaterBalance;
	};

	function hopFlavourContribution(bt, vol, use, amount) {
		var result;

		if ((use == "First Wort") || (use == "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
		}
		result = (result * amount * 1000) / vol;
	//      console.log("hopFlavourContribution("+bt+","+vol+","+use+","+amount+"): "+result);
		return result;
	}

	function hopAromaContribution(bt, vol, use, amount) {
		var result = 0;

		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 == "Boil") {
			result = 1;
		} else if (use == "Aroma") {
			result = 1.2;
		} else if (use == "Whirlpool") {
			result = 1.2;
		} else if ((use == "Dry Hop") || (use == "Dry hop")) {
			result = 1.33;
		}
		result = (result * amount * 1000) / vol;
	//      console.log("hopAromaContribution("+bt+","+vol+","+use+","+amount+"): "+result);
		return result;
	}

	function calcIBUs() {
		var total_ibus = 0;
		hop_aroma = hop_flavour = 0;
		var rows = $('#hopGrid').jqxGrid('getrows');
		for (var i = 0; i < rows.length; i++) {
			var row = rows[i];
			total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size),
					parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method);
			hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
					row.h_useat, parseFloat(row.h_amount));
			hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
					row.h_useat, parseFloat(row.h_amount));
		}
		total_ibus = Math.round(total_ibus);
		console.log("calcIBUs(): " + total_ibus + "  flavour: " + hop_flavour + "  aroma: " + hop_aroma);
		dataRecord.est_ibu = total_ibus;
		$('#est_ibu').val(total_ibus);
		$('#est_ibu2').val(total_ibus);
		$("#hop_flavour").jqxProgressBar('val', hop_flavour * 10);
		$("#hop_aroma").jqxProgressBar('val', hop_aroma * 10);
	};

	function calcSGendMash() {
		est_mash_sg = 0;
		var	mvol = 0;	// Mash volume
		var	s = 0;
		var	gs = 0;		// Grain absorbtion
		var rows = $('#mashGrid').jqxGrid('getrows');
		for (var i = 0; i < rows.length; i++) {
			var row = rows[i];
//			console.log("step " + i + " " + row.step_name + " " + row.step_type);
			if (row.step_type == 'Infusion')
				mvol += parseFloat(row.step_infuse_amount);
		}
		if (mvol > 0) {
//			console.log("mash volume: " + mvol);
			var rows = $('#fermentableGrid').jqxGrid('getrows');
			for (var i = 0; i < rows.length; i++) {
			        var row = rows[i];
				if (row.f_added == "Mash") {
					var d = row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
					mvol += row.f_amount * row.f_moisture / 100;
					gs += my_grain_absorbtion * row.f_amount;
					s += d;
				}
			}
//			console.log("mash volume: " + mvol + "  gs: " + gs + "  s: " + s);
			var v = s / sugardensity + mvol;
			s = 1000 * s / (v * 10); //deg. Plato
			est_mash_sg = plato_to_sg(s);
		}
		console.log("calcSGendMash(): " + est_mash_sg);
		$('#est_mash_sg').val(est_mash_sg);
	};

	function calcMashEfficiency() {
//		console.log("calcMashEfficiency()");
		var c = sg_to_plato(est_mash_sg);
		var m = sg_to_plato(parseFloat($("#brew_mash_sg").jqxNumberInput('decimal')));
//		console.log("c "+ c + "  m " + m + "  in " + parseFloat($("#brew_mash_sg").jqxNumberInput('decimal')));
		if (c > 0.5)
			$("#brew_mash_efficiency").val(100 * m / c);
		else
			$("#brew_mash_efficiency").val(0);
	};

	function calcInit () {
		console.log("calc.init()");

		calcSGendMash();
		calcMashEfficiency();

	};

	// Equipemnt dropdown list
	var equipmentUrl = "includes/db_inventory_equipments.php";
	var equipmentSource = {
		datatype: "json",
		datafields: [
			{ name: 'name', type: 'string' },
			{ name: 'boil_size', type: 'float' },
			{ name: 'batch_size', type: 'float' },
			{ name: 'tun_volume', type: 'float' },
			{ name: 'tun_weight', type: 'float' },
			{ name: 'tun_specific_heat', type: 'float' },
			{ name: 'tun_material', type: 'string' },
			{ name: 'tun_height', type: 'float' },
			{ name: 'top_up_water', type: 'float' },
			{ name: 'trub_chiller_loss', type: 'float' },
			{ name: 'evap_rate', type: 'float' },
			{ name: 'boil_time', type: 'float' },
			{ name: 'calc_boil_volume', type: 'bool' },
			{ name: 'top_up_kettle', type: 'float' },
			{ name: 'hop_utilization', type: 'float' },
			{ name: 'notes', type: 'string' },
			{ name: 'lauter_volume', type: 'float' },
			{ name: 'lauter_height', type: 'float' },
			{ name: 'lauter_deadspace', type: 'float' },
			{ name: 'kettle_volume', type: 'float' },
			{ name: 'kettle_height', type: 'float' },
			{ name: 'mash_volume', type: 'float' },
			{ name: 'efficiency', type: 'float' }
		],
		url: equipmentUrl,
		async: true
	};
	var equipmentlist = new $.jqx.dataAdapter(equipmentSource);
	$("#equipmentSelect").jqxDropDownList({
		placeHolder: "Kies apparatuur:",
		theme: theme,
		source: equipmentlist,
		displayMember: "name",
		width: 150,
		height: 27,
		dropDownWidth: 300,
		renderer: function (index, label, value) {
			var datarecord = equipmentlist.records[index];
			return datarecord.batch_size + " liter " + datarecord.name;
		}
	});
	$("#equipmentSelect").on('select', function (event) {
		if (event.args) {
			var index = event.args.index;
			var datarecord = equipmentlist.records[index];
			$("#eq_name").val(datarecord.name);
			$("#eq_boil_size").val(datarecord.boil_size);
			$("#eq_batch_size").val(datarecord.batch_size);
			$("#eq_tun_volume").val(datarecord.tun_volume);
			dataRecord.eq_tun_weight = datarecord.tun_weight;
			dataRecord.eq_tun_specific_heat = datarecord.tun_specific_heat;
			dataRecord.eq_tun_material = datarecord.tun_material;
			dataRecord.eq_tun_height = datarecord.tun_height / 100.0;
			$("#eq_top_up_water").val(datarecord.top_up_water);
			$("#eq_trub_chiller_loss").val(datarecord.trub_chiller_loss);
			$("#eq_evap_rate").val(datarecord.evap_rate);
			$("#eq_boil_time").val(datarecord.boil_time);
			dataRecord.eq_calc_boil_volume = datarecord.calc_boil_volume;
			$("#eq_top_up_kettle").val(datarecord.top_up_kettle);
			$("#eq_hop_utilization").val(datarecord.hop_utilization);
			$("#eq_notes").val(datarecord.notes);
			$("#eq_lauter_volume").val(datarecord.lauter_volume);
			dataRecord.eq_lauter_height = datarecord.lauter_height / 100.0;
			$("#eq_lauter_deadspace").val(datarecord.lauter_deadspace);
			$("#eq_kettle_volume").val(datarecord.kettle_volume);
			dataRecord.eq_kettle_height = datarecord.kettle_height / 100.0;
			$("#eq_mash_volume").val(datarecord.mash_volume);
			$("#eq_mash_max").val(datarecord.mash_max);
			$("#eq_efficiency").val(datarecord.efficiency);
		}
	});

	var dataRecord = {};
	var url = "includes/db_product.php";
	// tooltips
	$("#name").jqxTooltip({ content: 'De naam voor dit product.' });
	$("#code").jqxTooltip({ content: 'Product code nummer.' });
	$("#birth").jqxTooltip({ content: 'De ontwerp datum van dit product.' });
	$("#stage").jqxTooltip({ content: 'De productie fase van dit product.' });
	$("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit product.' });
	$("#eq_name").jqxTooltip({ content: 'De naam van deze brouw apparatuur.' });
	$("#eq_notes").jqxTooltip({ content: 'Opmerkingen over deze apparatuur.' });
	$("#eq_tun_volume").jqxTooltip({ content: 'Maisch ketel volume.' });
	$("#eq_mash_volume").jqxTooltip({ content: 'Maisch water voor de eerste stap.' });
	$("#eq_mash_max").jqxTooltip({ content: 'De maximale moutstort in Kg.' });
	$("#eq_lauter_volume").jqxTooltip({ content: 'Filterkuip volume.' });
	$("#eq_lauter_deadspace").jqxTooltip({ content: 'Filterkuip verlies in liters.' });
	$("#eq_efficiency").jqxTooltip({ content: 'Gemiddeld brouwzaal rendement.' });
	$("#eq_kettle_volume").jqxTooltip({ content: 'Kook ketel volume in liters.' });
	$("#eq_boil_size").jqxTooltip({ content: 'Normaal kook volume in liters' });
	$("#eq_evap_rate").jqxTooltip({ content: 'Verdamping in liters per uur.' });
	$("#eq_boil_time").jqxTooltip({ content: 'Normale kooktijd in minuten..' });
	$("#eq_top_up_kettle").jqxTooltip({ content: 'Extra water toevoegen tijdens de kook.' });
	$("#eq_hop_utilization").jqxTooltip({ content: '100% voor kleine installaties, hoger voor grote brouwerijen.' });
	$("#eq_batch_size").jqxTooltip({ content: 'Berekende batch grootte in liters aan het eind van de kook.' });
	$("#eq_trub_chiller_loss").jqxTooltip({ content: 'Standaard verlies bij het overbrengen naar het gistvat.' });
	$("#type").jqxTooltip({ content: 'Het brouw type van dit recept.' });
	$("#batch_size").jqxTooltip({ content: 'Het volume van het gekoelde wort na het koken.' });
	$("#boil_time").jqxTooltip({ content: 'De kooktijd in minuten.' });
	$("#boil_size").jqxTooltip({ content: 'Het volume van het wort voor het koken.' });
	$("#efficiency").jqxTooltip({ content: 'Het rendement van maischen en koken.' });
	$("#est_og").jqxTooltip({ content: 'Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend.' });
	$("#est_og2").jqxTooltip({ content: 'Het begin SG wat je wilt bereiken. De moutstort wordt automatisch herberekend.' });
	$("#est_fg").jqxTooltip({ content: 'Het eind SG. Dit wordt automatisch berekend.' });
	$("#est_color").jqxTooltip({ content: 'De kleur in EBC. Dit wordt automatisch berekend.' });
	$("#est_color2").jqxTooltip({ content: 'De kleur in EBC. Dit wordt automatisch berekend.' });
	$("#est_ibu").jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
	$("#est_ibu2").jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
	$("#est_abv").jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
	$("#est_carb").jqxTooltip({ content: 'Koolzuur volume. Dit wordt automatisch berekend.' });
//	$("#st_name").jqxTooltip({ content: 'De bierstijl naam voor dit recept.'});
//	$("#st_letter").jqxTooltip({ content: 'De bierstijl letter voor dit recept.'});
//	$("#st_guide").jqxTooltip({ content: 'De bierstijl gids voor dit recept.'});
//	$("#st_category").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie.'});
//	$("#st_category_number").jqxTooltip({ content: 'De Amerikaanse bierstijl categorie sub nummer.'});
//	$("#st_type").jqxTooltip({ content: 'Het bierstijl type.'});
	$("#st_og_min").jqxTooltip({ content: 'Het minimum begin SG voor deze bierstijl.'});
	$("#st_og_max").jqxTooltip({ content: 'Het maximum begin SG voor deze bierstijl.'});
	$("#st_fg_min").jqxTooltip({ content: 'Het minimum eind SG voor deze bierstijl.'});
	$("#st_fg_max").jqxTooltip({ content: 'Het maximum eind SG voor deze bierstijl.'});
	$("#st_color_min").jqxTooltip({ content: 'De minimum kleur voor deze bierstijl.'});
	$("#st_color_max").jqxTooltip({ content: 'De maximum kleur voor deze bierstijl.'});
	$("#st_ibu_min").jqxTooltip({ content: 'De minimum bitterheid voor deze bierstijl.'});
	$("#st_ibu_max").jqxTooltip({ content: 'De maximum bitterheid voor deze bierstijl.'});
	$("#st_abv_min").jqxTooltip({ content: 'Het minimum alcohol volume % voor deze bierstijl.'});
	$("#st_abv_max").jqxTooltip({ content: 'Het maximum alcohol volume % voor deze bierstijl.'});
	$("#st_carb_min").jqxTooltip({ content: 'Het minimum koolzuur volume voor deze bierstijl.'});
	$("#st_carb_max").jqxTooltip({ content: 'Het maximum koolzuur volume voor deze bierstijl.'});
	$("#wa_cacl2").jqxTooltip({ content: 'Voor het maken van een ander waterprofiel. Voegt calcium en chloride toe. Voor het verbeteren van zoetere bieren.'});
	$("#wa_caso4").jqxTooltip({ content: 'Gips. Voor het maken van een ander waterprofiel. Voegt calcium en sulfaat toe. Voor het verbeteren van bittere bieren.'});
	$("#wa_mgso4").jqxTooltip({ content: 'Epsom zout. Voor het maken van een ander waterprofiel. Voegt magnesium en sulfaat toe. Gebruik spaarzaam!'});
	$("#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.'});
	$("#w2_amount").jqxTooltip({ content: 'De verdeling van het hoofd en meng water. Het totale maisch water volume blijft gelijk.'});
	$("#wb_calcium").jqxTooltip({ content: 'De ideale hoeveelheid Calcium is tussen 40 en 150.'});
	$("#wb_magnesium").jqxTooltip({ content: 'De ideale hoeveelheid Magnesium is lager dan 30.'});
	$("#wb_sodium").jqxTooltip({ content: 'De ideale hoeveelheid Natrium is lager dan 150.'});
	$("#wb_chloride").jqxTooltip({ content: 'De ideale hoeveelheid Chloride is lager dan 100.'});
	$("#wb_sulfate").jqxTooltip({ content: 'De ideale hoeveelheid Sulfaat is lager dan 350.'});

	// Prepare the data
	var 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: 'string' },
			{ name: 'notes', type: 'string' },
			{ name: 'log_brew', type: 'bool' },
			{ name: 'log_fermentation', type: 'bool' },
			{ name: 'inventory_reduced', type: 'bool' },
			{ name: 'locked', type: 'bool' },
			{ 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: 'string' },
			{ 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: 'bool' },
			{ 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_sparge_temperature', type: 'float' },
			{ name: 'brew_sparge_volume', 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_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: 'string' },
			{ 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_aeration_time', type: 'float' },
			{ name: 'brew_aeration_speed', type: 'float' },
			{ name: 'brew_aeration_type', type: 'string' },
			{ name: 'brew_fermenter_sg', type: 'float' },
			{ name: 'brew_fermenter_ibu', type: 'float' },
			{ name: 'brew_date_end', type: 'string' },
			{ name: 'brew_log_available', type: 'bool' },
			{ 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_date', type: 'string' },
			{ name: 'tertiary_temp', type: 'float' },
			{ name: 'package_date', type: 'string' },
			{ name: 'bottle_amount', type: 'float' },
			{ name: 'bottle_carbonation', type: 'float' },
			{ name: 'bottle_priming_sugar', type: 'string' },
			{ 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_sugar', type: 'string' },
			{ name: 'keg_priming_amount', type: 'float' },
			{ name: 'keg_carbonation_temp', type: 'float' },
			{ name: 'keg_forced_carb', type: 'bool' },
			{ name: 'keg_pressure', type: 'float' },
			{ name: 'keg_priming_factor', 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: 'string' },
			{ 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: 'string' },
			{ 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: 'string' },
			{ name: 'est_ibu', type: 'float' },
			{ name: 'ibu_method', type: 'string' },
			{ name: 'est_carb', type: 'float' },
			{ name: 'sparge_temp', type: 'float' },
			{ name: 'sparge_ph', type: 'float' },
			{ name: 'sparge_volume', type: 'float' },
			{ name: 'sparge_acid_type', type: 'string' },
			{ 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: 'bool' },
			{ 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: 'fermentables', type: 'array' },
			{ name: 'hops', type: 'string' },
			{ name: 'miscs', type: 'string' },
			{ name: 'yeasts', type: 'string' },
			{ name: 'mashs', type: 'string' }
		],
		id: 'record',
		url: url + '?record=' + my_record
	};
	// Load data and select one record.
	var dataAdapter = new $.jqx.dataAdapter(source, {
		loadComplete: function () {
			var records = dataAdapter.records;
			dataRecord = records[0];
			// Hidden record uuid
			$("#name").val(dataRecord.name);
			$("#code").val(dataRecord.code);
			$("#birth").val(dataRecord.birth);
			$("#stage").val(dataRecord.stage);
			$("#notes").val(dataRecord.notes);
			$("#log_brew").val(dataRecord.log_brew);
			$("#log_fermentation").val(dataRecord.log_fermentation);
			$("#inventory_reduced").val(dataRecord.inventory_reduced);
			$("#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 to calculate on th fly.
			// Header Spoelen en filteren
			$("#brew_sparge_temperature").val(dataRecord.brew_sparge_temperature);
			$("#brew_sparge_volume").val(dataRecord.brew_sparge_volume);
			$("#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_ibu").val(dataRecord.brew_fermenter_ibu);

			$("#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
			// Header Naar gistvat
			$("#brew_fermenter_extrawater").val(dataRecord.brew_fermenter_extrawater);
			$("#brew_fermenter_extrasugar").val(dataRecord.brew_fermenter_extrasugar);
			$("#brew_fermenter_color").val(dataRecord.brew_fermenter_color);
			$("#brew_date_end").val(dataRecord.brew_date_end);

			// 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(dataRecord.st_type);
			$("#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_max").val(dataRecord.st_carb_max);
			$("#type").val(dataRecord.type);
			$("#batch_size").val(dataRecord.batch_size);
			old_batch_size = dataRecord.batch_size;
			$("#boil_size").val(dataRecord.boil_size);
			$("#boil_time").val(dataRecord.boil_time);
			old_boil_time = dataRecord.boil_time;
			$("#efficiency").val(dataRecord.efficiency);
			old_efficiency = dataRecord.efficiency;
			$("#est_og").val(dataRecord.est_og);
			$("#est_og2").val(dataRecord.est_og);
			$("#est_fg").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);
			$("#tgt_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_acid_type").val(dataRecord.sparge_acid_type);
			$("#sparge_acid_perc").val(dataRecord.sparge_acid_perc);
			$("#sparge_acid_amount").val(dataRecord.sparge_acid_amount);
			$("#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);
			editFermentable(dataRecord);
			editHop(dataRecord);
                        editMisc(dataRecord);
                        editYeast(dataRecord);
                        editMash(dataRecord);

			switch (dataRecord.stage) {
				case 'Plan':		brewstage = 0;	break;
				case 'Wait':		brewstage = 1;	break;
				case 'Brew':		brewstage = 2;	break;
				case 'Primary':		brewstage = 3;	break;
				case 'Secondary':	brewstage = 4;	break;
				case 'Tertiary':	brewstage = 5;	break;
				case 'Package':		brewstage = 6;	break;
				case 'Carbonation':	brewstage = 7;	break;
				case 'Mature':		brewstage = 8;	break;
				case 'Taste':		brewstage = 9;	break;
				case 'Ready':		brewstage = 10;
							$("#plocked").jqxCheckBox({ disabled:false });
							break;
				case 'Closed':		brewstage = 11;
							$("#plocked").jqxCheckBox({ disabled:false });
							break;
			}
			// Enable or Disable settings depending on the stage.
			if (brewstage > 1)
				$("#equipmentSelect").jqxDropDownList({ disabled: true });
			if (brewstage > 0) {
				$("#Delete").jqxButton({ disabled: true });
				$("#birth").jqxDateTimeInput({ disabled: true });
			}
			if (brewstage < 3) {
		//		$("#brew_log").jqxButton({ disabled: true });
		//		$("#ferment_log").jqxButton({ disabled: true });
			} else {
		//		if (! dataRecord.log_brew)
		//			$("#brew_log").jqxButton({ disabled: true });
		//		if (! dataRecord.log_fermentation)
		//			$("#ferment_log").jqxButton({ disabled: true });
			}
			if (brewstage < 6)
				$("#inventory_reduced").jqxCheckBox({ disabled : true });
			else if ($('#inventory_reduced').jqxCheckBox('checked'))
				$("#inventory_reduced").jqxCheckBox({ disabled : true });

			$('#jqxTabs').jqxTabs('select', 2);
		},
		loadError: function (jqXHR, status, error) {
		},
                beforeLoadComplete: function (records) {
                        $('#jqxLoader').jqxLoader('open');
                }
	});
	dataAdapter.dataBind();

        // Inline fermentables editor
        var editFermentable = function (data) {
                var fermentableSource = {
                        localdata: data.fermentables,
                        datatype: "local",
                        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: 'string' },
                                { 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: 'string' },
                                { name: 'f_added', type: 'string' },
                                { name: 'f_dissolved_protein', type: 'float' },
                                { name: 'f_recommend_mash', type: 'bool' },
                                { name: 'f_add_after_boil', type: 'bool' },
                                { name: 'f_adjust_to_total_100', type: 'bool' },
                                { name: 'f_percentage', type: 'float' },
                                { name: 'f_di_ph', type: 'float' }
                        ],
                        addrow: function (rowid, rowdata, position, commit) {
                                commit(true);
                        },
                        deleterow: function (rowid, commit) {
                                commit(true);
                        }
                };
                var fermentableAdapter = new $.jqx.dataAdapter(fermentableSource);
                $("#fermentableGrid").jqxGrid({
                        width: 1150,
                        height: 400,
                        source: fermentableAdapter,
                        theme: theme,
                        selectionmode: 'singlerow',
                        editmode: 'selectedcell',
                        editable: true,
                        localization: getLocalization(),
                        showtoolbar: true,
                        rendertoolbar: function (toolbar) {
                                var me = this;
                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
                                toolbar.append(container);
                                container.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');
                                container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
                                container.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');
                                container.append('<input style="float: left; margin-left: 400px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');
                                // add fermentable from dropdownlist.
                                $("#faddrowbutton").jqxDropDownList({
                                        placeHolder: "Kies mout:",
                                        theme: theme,
                                        source: fermentablelist,
                                        displayMember: "name",
                                        width: 150,
                                        height: 27,
                                        dropDownWidth: 500,
                                        dropDownHeight: 500,
                                        renderer: function (index, label, value) {
                                                var datarecord = fermentablelist.records[index];
                                                return datarecord.supplier+ " / " + datarecord.name + " (" + datarecord.color + " EBC)";
                                        }
                                });
                                $("#faddrowbutton").on('select', function (event) {
                                        if (event.args) {
                                                var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
                                                var index = event.args.index;
                                                var datarecord = fermentablelist.records[index];
                                                var row = {};
                                                row["f_name"] = datarecord.name;
                                                row["f_origin"] = datarecord.origin;
                                                row["f_supplier"] = datarecord.supplier;
                                                row["f_amount"] = 0;
                                                row["f_cost"] = datarecord.cost;
                                                row["f_type"] = datarecord.type;
                                                row["f_yield"] = datarecord.yield;
                                                row["f_color"] = datarecord.color;
                                                row["f_coarse_fine_diff"] = datarecord.coarse_fine_diff;
                                                row["f_moisture"] = datarecord.moisture;
                                                row["f_diastatic_power"] = datarecord.diastatic_power;
                                                row["f_protein"] = datarecord.protein;
                                                row["f_max_in_batch"] = datarecord.max_in_batch;
                                                row["f_graintype"] = datarecord.graintype;
                                                if (datarecord.add_after_boil) {
                                                        row["f_added"] = "Primary";
                                                } else if ((datarecord.type == "Sugar") || (datarecord.type == "Adjunct")) {
                                                        row["f_added"] = "Boil";
                                                } else {
                                                        row["f_added"] = "Mash";
                                                }
                                                row["f_dissolved_protein"] = 0;
                                                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;
                                                var commit = $("#fermentableGrid").jqxGrid('addrow', null, row);
                                        }
                                });

                                $("#finstockbutton").jqxCheckBox({ theme: theme, height: 27 });
                                $("#finstockbutton").on('change', function (event) {
                                        fermentableinstock = event.args.checked;
                                        fermentablelist.dataBind();
                                });

                                // delete selected fermentable.
                                $("#fdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
                                $("#fdeleterowbutton").on('click', function () {
                                        var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex');
                                        var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                                                var id = $("#fermentableGrid").jqxGrid('getrowid', selectedrowindex);
                                                var percent = $('#fermentableGrid').jqxGrid('getcellvalue', id, "f_percentage");
                                                var amount = $('#fermentableGrid').jqxGrid('getcellvalue', id, "f_amount");
                                                var commit = $("#fermentableGrid").jqxGrid('deleterow', id);
                                        }
                                        rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
                                        if (rowscount > 1) {
                                                if (to_100) {
                                                        for (var i = 0; i < rowscount; i++) {
                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                                if (rowdata.f_adjust_to_total_100) {
                                                                        rowdata.f_percentage += percent;
                                                                        rowdata.f_amount += amount;
                                                                }
                                                        }
                                                } else {
                                                        var tw = 0;
                                                        for (i = 0; i < rowscount; i++) {
                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                                tw += rowdata.f_amount;
                                                        };
                                                        for (i = 0; i < rowscount; i++) {
                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                                var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
                                                                $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
                                                        };
                                                }
                                        } else {
                                                $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
                                        }
                                        calcFermentables();
                                        calcSVG();
                                        calcABV();
                                        calcIBUs();
                                });
                        },
                        ready: function() {
                                calcFermentables();
                                $('#jqxTabs').jqxTabs('next');
                        },
                        columns: [
                                { text: 'Vergistbaar ingredi&euml;nt', editable: false, datafield: 'f_name',
                                  cellsrenderer:  function (row, columnfield, value, defaulthtml, columnproperties) {
                                        var rowData = $("#fermentableGrid").jqxGrid('getrowdata', row);
                                        return "<span style='margin: 3px; margin-top: 6px; float: "+
                                                columnproperties.cellsalign+"'>" +rowData.f_supplier+" / "+rowData.f_name+" ("+rowData.f_color+" EBC)</span>";
                                  }
                                },
                                { text: 'Type', editable: false, align: 'center', cellsalign: 'center', width: 100, datafield: 'f_type' },
                                { text: 'Moment', width: 110, align: 'center', cellsalign: 'center', datafield: 'f_added', columntype: 'dropdownlist',
                                  createeditor: function (row, column, editor) {
                                        var srcAdded = [ "Mash", "Boil", "Fermentation", "Lagering", "Bottle" ];
                                        editor.jqxDropDownList({ autoDropDownHeight: true, source: srcAdded });
                                  }
                                },
                                { text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
                                { text: 'Gewicht Kg', datafield: 'f_amount', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f3',
                                  columntype: 'numberinput',
                                  validation: function (cell, value) {
                                        // Maximum weight is the batch_size, just a simple check.
                                        var maxmout = parseFloat($("#batch_size").jqxNumberInput('decimal'));
                                        if (value < 0 || value > maxmout) {
                                                return { result: false, message: "Gewicht moet 0-"+maxmout+" zijn" };
                                        }
                                        return true;
                                  },
                                  initeditor: function (row, cellvalue, editor) {
                                        editor.jqxNumberInput({ inputMode: 'simple', min: 0, decimalDigits: 3, spinButtons: false });
                                  },
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        if (to_100) {
                                                return oldvalue;        // When using percentages, don't allow edited results.
                                        }
                                  }
                                },
                                { text: 'Percentage', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p1',
                                  columntype: 'numberinput',
                                  validation: function (cell, value) {
                                        if (value < 0 || value > 100) {
                                                return { result: false, message: "Percentage moet 0-100 zijn" };
                                        }
                                        return true;
                                  },
                                  initeditor: function (row, cellvalue, editor) {
                                        editor.jqxNumberInput({ decimalDigits: 1, min: 0, max: 100, spinButtons: false });
                                  },
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        oldvalue = Math.round(oldvalue * 10) / 10.0;
                                        var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
                                        if ((oldvalue != newvalue) && (rowscount > 1)) {
                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', row);
                                                if (rowdata.f_adjust_to_total_100) {
                                                        return oldvalue;
                                                }
                                                var diff = newvalue - oldvalue;
                                                var tw = 0;     // total weight
                                                for (i = 0; i < rowscount; i++) {
                                                        var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                        tw += rowdata.f_amount;
                                                }
                                                if (to_100) {
                                                        // Adjust this row and the 100% row.
                                                        var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', row);
                                                        rowdata.f_amount += tw * diff / 100;
                                                        for (i = 0; i < rowscount; i++) {
                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                                if (rowdata.f_adjust_to_total_100) {
                                                                        rowdata.f_percentage -= diff;
                                                                        rowdata.f_amount -= tw * diff / 100;
                                                                }
                                                        }
                                                } else {
                                                        // Adjust all the rows.
                                                        var nw = tw * diff / 100;
                                                        for (i = 0; i < rowscount; i++) {
                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                                if (i == row) {
                                                                        rowdata.f_amount += nw;
                                                                } else {
                                                                        rowdata.f_amount -= nw / (rowscount - 1);
                                                                        rowdata.f_percentage = Math.round((rowdata.f_amount / tw) * 1000) / 10.0;
                                                                }
                                                        }
                                                }
                                        }
                                  }
                                },
                                { text: '100%', align: 'center', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 80,
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        if (to_100) {
                                                var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
                                                for (i = 0; i < rowscount; i++) {
                                                        if (i != row) {
                                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                                rowdata.f_adjust_to_total_100 = false;
                                                        }
                                                }
                                        }
                                  }
                                }
                        ]
                });
                $("#fermentableGrid").on('cellendedit', function (event) {
                        var args = event.args;
                        console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
                        // Make sure the grid itself is updated.
                        $("#fermentableGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
                        if ((args.datafield == 'f_amount') && (! to_100)) {
                                // If one of the amounts is changed, recalculate the percentages.
                                console.log("adjust percentages");
                                var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
                                if (rowscount > 1) {
                                        var tw = 0;
                                        for (i = 0; i < rowscount; i++) {
                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                tw += rowdata.f_amount;
                                        };
                                        for (i = 0; i < rowscount; i++) {
                                                var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
                                                var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
                                                $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
                                        };
                                } else {
                                        $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
                                }
                        };
                        $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc');    // TODO: not reliable
                        calcFermentables();
                        calcSVG();
                        calcABV();
                        calcIBUs();     // Depends on gravity, so recalculate.
                });
        };

        // Inline hops editor
        var editHop = function (data) {
                var hopSource = {
                        localdata: data.hops,
                        datatype: "local",
                        cache: 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: 'string' },
                                { name: 'h_form', type: 'string' },
                                { name: 'h_useat', type: 'string' },
                                { 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_carophyllene', type: 'float' },
                                { name: 'h_cohumulone', type: 'float' },
                                { name: 'h_myrcene', type: 'float' },
                                { name: 'h_total_oil', type: 'float' },
                                { name: 'h_weight', type: 'float' }
                        ],
                        addrow: function (rowid, rowdata, position, commit) {
                                commit(true);
                        },
                        deleterow: function (rowid, commit) {
                                commit(true);
                        }
                };
                var hopAdapter = new $.jqx.dataAdapter(hopSource, {
                        beforeLoadComplete: function (records) {
                                var data = new Array();
                                for (var i = 0; i < records.length; i++) {
                                        var row = records[i];
                                        row.h_weight = row.h_amount * 1000;
                                        data.push(row);
                                }
                                return data;
                        },
                        loadError: function(jqXHR, status, error) {
                                $('#err').text(status + ' ' + error);
                        },
                });
                $("#hopGrid").jqxGrid({
                        width: 1050,
                        height: 400,
                        source: hopAdapter,
                        theme: theme,
                        selectionmode: 'singlerow',
                        editmode: 'selectedcell',
                        editable: true,
                        localization: getLocalization(),
                        showtoolbar: true,
                        rendertoolbar: function (toolbar) {
                                var me = this;
                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
                                toolbar.append(container);
                                container.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');
                                container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
                                container.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');
                                container.append('<input style="float: left; margin-left: 280px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');
                                // add hop from dropdownlist.
                                $("#haddrowbutton").jqxDropDownList({
                                        placeHolder: "Kies hop:",
                                        theme: theme,
                                        source: hoplist,
                                        displayMember: "name",
                                        width: 150,
                                        height: 27,
                                        dropDownWidth: 500,
                                        dropDownHeight: 500,
                                        renderer: function (index, label, value) {
                                                var datarecord = hoplist.records[index];
                                                return datarecord.origin+ " / " + datarecord.name + " (" + datarecord.alpha + "% &alpha;)";
                                        }
                                });
                                $("#haddrowbutton").on('select', function (event) {
                                        if (event.args) {
                                                var index = event.args.index;
                                                var datarecord = hoplist.records[index];
                                                var row = {};
                                                row["h_name"] = datarecord.name;
                                                row["h_origin"] = datarecord.origin;
                                                row["h_amount"] = 0;
                                                row["h_cost"] = datarecord.cost;
                                                row["h_type"] = datarecord.type;
                                                row["h_form"] = datarecord.form;
                                                row["h_useat"] = datarecord.useat;
                                                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_carophyllene"] = datarecord.carophyllene;
                                                row["h_cohumulone"] = datarecord.cohumulone;
                                                row["h_myrcene"] = datarecord.myrcene;
                                                row["h_total_oil"] = datarecord.total_oil;
                                                row["h_weight"] = 0;
                                                var commit = $("#hopGrid").jqxGrid('addrow', null, row);
                                        }
                                });

                                $("#hinstockbutton").jqxCheckBox({ theme: theme, height: 27 });
                                $("#hinstockbutton").on('change', function (event) {
                                        hopinstock = event.args.checked;
                                        hoplist.dataBind();
                                });

                                // delete selected hop.
                                $("#hdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
                                $("#hdeleterowbutton").on('click', function () {
                                        var selectedrowindex = $("#hopGrid").jqxGrid('getselectedrowindex');
                                        var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount;
                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                                                var id = $("#hopGrid").jqxGrid('getrowid', selectedrowindex);
                                                var commit = $("#hopGrid").jqxGrid('deleterow', id);
                                        }
                                });
                        },
                        ready: function() {
                                $('#jqxTabs').jqxTabs('next');
                        },
                        columns: [
                                { text: 'Hop', editable: false, datafield: 'h_name',
                                  cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) {
                                        var rowData = $("#hopGrid").jqxGrid('getrowdata', row);
                                        return "<span style='margin: 3px; margin-top: 6px; float: "+
                                                columnproperties.cellsalign+"'>" +rowData.h_origin+" / "+rowData.h_name+"</span>";
                                  },
                                },
                                { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' },
                                { text: 'Vorm', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_form' },
                                { text: 'Alpha', editable: false, datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
                                { text: 'Amount', hidden: true, datafield: 'h_amount' },
                                { text: 'Gewicht gr', datafield: 'h_weight', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f1',
                                  columntype: 'numberinput',
                                  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
                                        return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(value, "f1") + " gr</div>";
                                  },
                                  initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
                                        editor.jqxNumberInput({
                                                inputMode: 'simple', decimalDigits: 1, min: 0, max: parseFloat(dataRecord.batch_size * 200),
                                                spinButtons: false
                                        });
                                  },
                                  validation: function (cell, value) {
                                        var maxhops = parseFloat(dataRecord.batch_size) * 200;
                                        if (value < 0 || value > maxhops ) {
                                                return { result: false, message: "Gewicht moet tussen 0 en "+maxhops+" gram zijn" };
                                        }
                                        return true;
                                  }
                                },
                                { text: 'Gebruik', width: 110, align: 'center', cellsalign: 'center', datafield: 'h_useat', columntype: 'dropdownlist',
                                  createeditor: function (row, column, editor) {
                                          var srcUse = [ "Boil", "Dry Hop", "Mash", "First Wort", "Aroma" ];
                                          editor.jqxDropDownList({ autoDropDownHeight: true, source: srcUse });
                                  },
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        if ((newvalue == "Mash") || (newvalue == "First Wort")) {
                                                $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", parseFloat(dataRecord.boil_time));
                                        } else if (newvalue == "Aroma") {
                                                $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", 0);
                                        }
                                  }
                                },
                                { text: 'Tijd', datafield: 'h_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
                                  columntype: 'numberinput',
                                  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
                                        if ((rowdata.h_useat == "Boil") || (rowdata.h_useat == "Dry Hop") || (rowdata.h_useat == "Dry hop"))
                                                return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+"</div>";
                                        else
                                                return "<div style='margin: 4px;' class='jqx-right-align'> </div>";
                                  },
                                  initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
                                        editor.jqxNumberInput({ decimalDigits: 0, digits: 3, min: 0, max: parseFloat(dataRecord.boil_time) });
                                  },
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        var use = $("#hopGrid").jqxGrid('getcellvalue', row, "h_useat");
                                        if ((use == "Mash") || (use == "First Wort") || (use == "First wort") || (use == "Aroma"))
                                                return oldvalue;
                                  },
                                  validation: function (cell, value) {
                                        var high = parseFloat(dataRecord.boil_time);
                                        if (value < 0 || value > high ) {
                                                return { result: false, message: "De tijd moet  0-"+high+" zijn" };
                                        }
                                        return true;
                                  }
                                },
                                { text: 'IBU', editable: false, 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()
                                                         );
                                        calcIBUs();
                                        return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>";
                                  }
                                }
                        ]
                });
                $("#hopGrid").on('cellendedit', function (event) {
                        var args = event.args;
                        console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
                        $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
                        if (args.datafield == 'h_weight')
                                $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, 'h_amount', args.value / 1000);
                        //$('#hopGrid').jqxGrid('sortby', 'f_amount', 'desc');
                });
        };

        // Inline miscs editor
        var editMisc = function (data) {
                var miscSource = {
                        localdata: data.miscs,
                        datatype: "local",
                        cache: false,
                        datafields: [
                                { name: 'm_name', type: 'string' },
                                { name: 'm_amount', type: 'float' },
                                { name: 'm_cost', type: 'float' },
                                { name: 'm_type', type: 'string' },
                                { name: 'm_use_use', type: 'string' },
                                { name: 'm_time', type: 'float' },
                                { name: 'm_amount_is_weight', type: 'bool' },
                                { name: 'm_weight', type: 'float' }
                        ],
                        addrow: function (rowid, rowdata, position, commit) {
                                commit(true);
                        },
                        deleterow: function (rowid, commit) {
                                commit(true);
                        }
                };
                var miscAdapter = new $.jqx.dataAdapter(miscSource, {
                        beforeLoadComplete: function (records) {
                                var data = new Array();
                                for (var i = 0; i < records.length; i++) {
                                        var row = records[i];
                                        row.m_weight = row.m_amount * 1000;
                                        data.push(row);
                                        // Initial set water agent values.
                                        switch (row.m_name) {
                                                case 'CaCl2':           $("#wa_cacl2").val(row.m_weight);
                                                                        break;
                                                case 'CaSO4':           $("#wa_caso4").val(row.m_weight);
                                                                        break;
                                                case 'MgSO4':           $("#wa_mgso4").val(row.m_weight);
                                                                        break;
                                                case 'NaCl':            $("#wa_nacl").val(row.m_weight);
                                                                        break;
                                                case 'Melkzuur':        $("#wa_acid_name").val('Melkzuur');
                                                                        $("#wa_acid").val(row.m_weight);
                                                                        $("#wa_acid_perc").val(80);
                                                                        last_acid = 'Melkzuur';
                                                                        break;
                                                case 'Zoutzuur':        $("#wa_acid_name").val('Zoutzuur');
                                                                        $("#wa_acid").val(row.m_weight);
                                                                        $("#wa_acid_perc").val(80);
                                                                        last_acid = 'Zoutzuur';
                                                                        break;
                                                case 'Fosforzuur':      $("#wa_acid_name").val('Fosforzuur');
                                                                        $("#wa_acid").val(row.m_weight);
                                                                        $("#wa_acid_perc").val(80);
                                                                        last_acid = 'Fosforzuur';
                                                                        break;
                                                case 'Zwavelzuur':      $("#wa_acid_name").val('Zwavelzuur');
                                                                        $("#wa_acid").val(row.m_weight);
                                                                        $("#wa_acid_perc").val(80);
                                                                        last_acid = 'Zwavelzuur';
                                                                        break;
                                                case 'NaHCO3':          $("#wa_base_name").val('NaHCO3');
                                                                        $("#wa_base").val(row.m_weight);
                                                                        last_base = 'NaHCO3';
                                                                        break;
                                                case 'Na2CO3':          $("#wa_base_name").val('Na2CO3');
                                                                        $("#wa_base").val(row.m_weight);
                                                                        last_base = 'Na2CO3';
                                                                        break;
                                                case 'CaCO3':           $("#wa_base_name").val('CaCO3');
                                                                        $("#wa_base").val(row.m_weight);
                                                                        last_base = 'CaCO3';
                                                                        break;
                                                case 'Ca(OH)2':         $("#wa_base_name").val('Ca(OH)2');
                                                                        $("#wa_base").val(row.m_weight);
                                                                        last_base = 'Ca(OH)2';
                                                                        break;
                                        }
                                }
                                return data;
                        },
                        loadError: function(jqXHR, status, error) {
                                $('#err').text(status + ' ' + error);
                        },
                });
                $("#miscGrid").jqxGrid({
                        width: 960,
                        height: 400,
                        source: miscAdapter,
                        theme: theme,
                        selectionmode: 'singlerow',
                        editmode: 'selectedcell',
                        editable: true,
                        localization: getLocalization(),
                        showtoolbar: true,
                        rendertoolbar: function (toolbar) {
                                var me = this;
                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
                                toolbar.append(container);
                                container.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');
                                container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
                                container.append('<div style="float: left; margin-left: 10px;" id="minstockbutton"></div>');
                                container.append('<input style="float: left; margin-left: 200px;" id="mdeleterowbutton" type="button" value="Verwijder ingredient" />');
                                // add misc from dropdownlist.
                                $("#maddrowbutton").jqxDropDownList({
                                        placeHolder: "Kies ingredient:",
                                        theme: theme,
                                        source: misclist,
                                        displayMember: "name",
                                        width: 150,
                                        height: 27,
                                        dropDownWidth: 500,
                                        dropDownHeight: 500
                                });
                                $("#maddrowbutton").on('select', function (event) {
                                        if (event.args) {
                                                var index = event.args.index;
                                                var datarecord = misclist.records[index];
                                                var row = {};
                                                row["m_name"] = datarecord.name;
                                                row["m_amount"] = 0;
                                                row["m_cost"] = datarecord.cost;
                                                row["m_type"] = datarecord.type;
                                                row["m_use_use"] = datarecord.use_use;
                                                row["m_time"] = 0;
                                                row["m_weight"] = 0;
                                                row["m_amount_is_weight"] = datarecord.amount_is_weight;
                                                var commit = $("#miscGrid").jqxGrid('addrow', null, row);
                                        }
                                });
                                $("#minstockbutton").jqxCheckBox({ theme: theme, height: 27 });
                                $("#minstockbutton").on('change', function (event) {
                                        miscinstock = event.args.checked;
                                        misclist.dataBind();
                                });
                                // delete selected misc.
                                $("#mdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
                                $("#mdeleterowbutton").on('click', function () {
                                        var selectedrowindex = $("#miscGrid").jqxGrid('getselectedrowindex');
                                        var rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount;
                                        var type = $("#miscGrid").jqxGrid('getcellvalue', selectedrowindex, "m_type");
                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount && type != "Water agent")  {
                                                var id = $("#miscGrid").jqxGrid('getrowid', selectedrowindex);
                                                var commit = $("#miscGrid").jqxGrid('deleterow', id);
                                        }
                                });
                        },
                        ready: function() {
                                $('#jqxTabs').jqxTabs('next');
                        },
                        columns: [
                                { text: 'Ingredient', editable: false, datafield: 'm_name' },
                                { text: 'Type', editable: false, width: 120, align: 'center', cellsalign: 'center', datafield: 'm_type' },
                                { text: 'Gebruik', width: 110, align: 'center', cellsalign: 'center', datafield: 'm_use_use', columntype: 'dropdownlist',
                                  createeditor: function (row, column, editor) {
                                        var srcUseUse = [ "Mash", "Boil", "Primary", "Secondary", "Bottling" ];
                                        editor.jqxDropDownList({ autoDropDownHeight: true, source: srcUseUse });
                                  },
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        var type = $("#miscGrid").jqxGrid('getcellvalue', row, "m_type");
                                        if (type == "Water agent")
                                                return oldvalue;
                                  }
                                },
                                { datafield: 'm_amount_is_weight', hidden: true },      // We need to declare this column
                                { datafield: 'm_amount', hidden: true },                // We need to declare this column
                                { text: 'Hoeveelheid', datafield: 'm_weight', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f2',
                                  columntype: 'numberinput',
                                  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
                                        var vstr = rowdata.m_amount_is_weight ? "gr":"ml";
                                        return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value,"f2")+" "+vstr+"</div>";
                                  },
                                  validation: function (cell, value) {
                                        var high = parseFloat(dataRecord.boil_size) * 1000;
                                        if (value < 0 || value > high) {
                                                return { result: false, message: "Hoeveelheid moet tussen 0 en "+high+" zijn" };
                                        }
                                        return true;
                                  },
                                  initeditor: function (row, cellvalue, editor) {
                                        editor.jqxNumberInput({
                                                inputMode: 'simple', min: 0, max: parseFloat(dataRecord.boil_size) * 1000,
                                                decimalDigits: 2, spinButtons: false
                                        });
                                  },
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        var type = $("#miscGrid").jqxGrid('getcellvalue', row, "m_type");
                                        if (type == "Water agent")
                                                return oldvalue;
                                  }
                                },
                               { text: 'Tijd', datafield: 'm_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
                                  columntype: 'numberinput',
                                  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
                                        if (rowdata.m_use_use == 'Boil') {
                                                return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" m</div>";
                                        } else if (rowdata.m_use_use == 'Secondary') {
                                                return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" d</div>";
                                        } else {
                                                var tijd = 0;
                                                return "<div style='margin: 4px;' class='jqx-right-align'> </div>";
                                        }
                                  },
                                  initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
                                        editor.jqxNumberInput({ decimalDigits: 0, digits: 3, min: 0, max: parseFloat(dataRecord.boil_time) });
                                  },
                                  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
                                        var use = $("#miscGrid").jqxGrid('getcellvalue', row, "m_use_use");
                                        if ((use != "Boil") && (use != "Secondary"))
                                                return oldvalue;
                                  },
                                  validation: function (cell, value) {
                                        var high = parseFloat(dataRecord.boil_time);
                                        if (value < 0 || value > high ) {
                                                return { result: false, message: "De tijd moet 0-"+high+" zijn" };
                                        }
                                        return true;
                                  }
                                }
                        ]
                });
                $("#miscGrid").on('cellendedit', function (event) {
                        var args = event.args;
                        console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
                        $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
                        if (args.datafield == 'm_weight') {
                                $("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_amount', parseFloat(args.value) / 1000);
                        }
                });
        };

        // Inline yeasts editor
        var editYeast = function (data) {
                var yeastSource = {
                        localdata: data.yeasts,
                        datatype: "local",
                        cache: 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: 'string' },
                                { name: 'y_form', type: 'string' },
                                { name: 'y_time', type: 'float' },
                                { name: 'y_min_temperature', type: 'float' },
                                { name: 'y_max_temperature', type: 'float' },
                                { name: 'y_attenuation', type: 'float' },
                                { name: 'y_amount_is_weight', type: 'bool' },
                                { name: 'y_use', type: 'string' },
                                { name: 'y_weight', type: 'float' }
                        ],
                        addrow: function (rowid, rowdata, position, commit) {
                                commit(true);
                        },
                        deleterow: function (rowid, commit) {
                                commit(true);
                        }
                };
                var yeastAdapter = new $.jqx.dataAdapter(yeastSource, {
                         beforeLoadComplete: function (records) {
                                var data = new Array();
                                for (var i = 0; i < records.length; i++) {
                                        var row = records[i];
                                        if (row.y_form == 'Liquid')
                                                row.y_weight = Math.round(row.y_amount * 17);
                                        else
                                                row.y_weight = row.y_amount * 1000;
                                        data.push(row);
                                }
                                return data;
                        },
                        loadError: function(jqXHR, status, error) {
                                $('#err').text(status + ' ' + error);
                        },
                });
                $("#yeastGrid").jqxGrid({
                        width: 1050,
                        height: 300,
                        source: yeastAdapter,
                        theme: theme,
                        selectionmode: 'singlerow',
                        editmode: 'selectedcell',
                        editable: true,
                        localization: getLocalization(),
                        showtoolbar: true,
                        rendertoolbar: function (toolbar) {
                                var me = this;
                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
                                toolbar.append(container);
                                container.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');
                                container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
                                container.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');
                                container.append('<input style="float: left; margin-left: 230px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');
                                // add yeast from dropdownlist.
                                $("#yaddrowbutton").jqxDropDownList({
                                        placeHolder: "Kies gist:",
                                        theme: theme,
                                        source: yeastlist,
                                        displayMember: "name",
                                        width: 150,
                                        height: 27,
                                        dropDownWidth: 500,
                                        dropDownHeight: 500,
                                        renderer: function (index, label, value) {
                                                var datarecord = yeastlist.records[index];
                                                return datarecord.laboratory+" "+datarecord.product_id+" "+datarecord.name;
                                        }
                                });
                                $("#yaddrowbutton").on('select', function (event) {
                                        if (event.args) {
                                                var index = event.args.index;
                                                var datarecord = yeastlist.records[index];
                                                var row = {};
                                                row["y_name"] = datarecord.name;
                                                row["y_laboratory"] = datarecord.laboratory;
                                                row["y_product_id"] = datarecord.product_id;
                                                row["y_type"] = datarecord.type;
                                                row["y_form"] = datarecord.form;
                                                row["y_amount"] = 0;
                                                row["y_cost"] = datarecord.cost;
                                                row["y_use"] = "Primary";
                                                row["y_time"] = 0;
                                                if (datarecord.form == "Dry") {
                                                        row["y_amount_is_weight"] = 1;
                                                } else {
                                                        row["y_amount_is_weight"] = 0;
                                                }
                                                row["y_min_temperature"] = datarecord.min_temperature;
                                                row["y_max_temperature"] = datarecord.max_temperature;
                                                row["y_attenuation"] = datarecord.attenuation;
                                                row["y_weight"] = 0;
                                                var commit = $("#yeastGrid").jqxGrid('addrow', null, row);
                                        }
                                });
                                $("#yinstockbutton").jqxCheckBox({ theme: theme, height: 27 });
                                $("#yinstockbutton").on('change', function (event) {
                                        yeastinstock = event.args.checked;
                                        yeastlist.dataBind();
                                });
                                // delete selected yeast.
                                $("#ydeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
                                $("#ydeleterowbutton").on('click', function () {
                                        var selectedrowindex = $("#yeastGrid").jqxGrid('getselectedrowindex');
                                        var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                                                var id = $("#yeastGrid").jqxGrid('getrowid', selectedrowindex);
                                                var commit = $("#yeastGrid").jqxGrid('deleterow', id);
                                        }
                                });
                        },
                        ready: function() {
//                                calcSVG();
                                $('#jqxTabs').jqxTabs('next');
                        },
                        columns: [
                                { text: 'Gist', editable: false, datafield: 'y_name' },
                                { text: 'Laboratorium', editable: false, width: 150, datafield: 'y_laboratory' },
                                { text: 'Code', editable: false, width: 90, datafield: 'y_product_id' },
                                { text: 'Soort', editable: false, width: 80, align: 'center', cellsalign: 'center', datafield: 'y_form' },
                                { text: 'Min.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_min_temperature' },
                                { text: 'Max.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_max_temperature' },
                                { text: 'Attn.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_attenuation', cellsformat: 'f1' },
                                { text: 'Voor', width: 100, align: 'center', cellsalign: 'center', datafield: 'y_use', columntype: 'dropdownlist',
                                  createeditor: function (row, column, editor) {
                                        var srcYUse = [ "Primary", "Secondary", "Bottle" ];
                                        editor.jqxDropDownList({ autoDropDownHeight: true, source: srcYUse });
                                  }
                                },
                                { datafield: 'y_amount', width: 90 },
                                { text: 'Hoeveel', datafield: 'y_weight', width: 110, align: 'right', cellsalign: 'right',
                                  cellsformat: 'f1', columntype: 'numberinput',
                                  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
                                        if (rowdata.y_form == 'Liquid') {
                                                return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" pk</div>";
                                        } else if (rowdata.y_form == 'Dry') {
                                                return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f1")+" gr</div>";
                                        } else {
                                                return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" ml</div>";
                                        }
                                  },
                                  initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
                                        var form = $("#yeastGrid").jqxGrid('getcellvalue', args.rowindex, 'y_form');
                                        if (form == 'Dry') {
                                                editor.jqxNumberInput({ decimalDigits: 1, min: 0, spinButtons: false });
                                        } else {
                                                editor.jqxNumberInput({ decimalDigits: 0, min: 0, spinButtons: false });
                                        }
                                  },
                                  validation: function (cell, value) {
                                        if (value < 0 || value > 100000000000 ) {
                                                return { result: false, message: "Hoeveelheid moet 0-~ zijn" };
                                        }
                                        return true;
                                  }
                                }
                        ]
                });
                $("#yeastGrid").on('cellendedit', function (event) {
                        var args = event.args;
                        console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
                        $("#yeastGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
                        if (args.datafield == 'y_weight') {
                                var form = $("#yeastGrid").jqxGrid('getcellvalue', args.rowindex, 'y_form');
                                if (form == 'Liquid')
                                        $("#yeastGrid").jqxGrid('setcellvalue', args.rowindex, 'y_amount', parseFloat(args.value * 0.0588));
                                else
                                        $("#yeastGrid").jqxGrid('setcellvalue', args.rowindex, 'y_amount', parseFloat(args.value / 1000));
                        }
                });
        };

        // inline mash editor
        var editMash = function (data) {
                var generaterow = function () {
                        var row = {};
                        row["step_name"] = "Stap 1";
                        row["step_type"] = "Infusion";
                        row["step_infuse_amount"] = 15;
                        row["step_temp"] = 62.0;
                        row['step_time'] = 20.0;
                        row['ramp_time'] = 1.0;
                        row['end_temp'] = 62.0;
                        return row;
                }
                var mashSource = {
                        localdata: data.mashs,
                        datatype: "local",
                        cache: false,
                        datafields: [
                                { name: 'step_name', type: 'string' },
                                { name: 'step_type', type: 'string' },
                                { name: 'step_infuse_amount', type: 'float' },
                                { name: 'step_temp', type: 'float' },
                                { name: 'step_time', type: 'float' },
                                { name: 'ramp_time', type: 'float' },
                                { name: 'end_temp', type: 'float' }
                        ],
                        addrow: function (rowid, rowdata, position, commit) {
                                commit(true);
                        },
                        deleterow: function (rowid, commit) {
                                commit(true);
                        }
                };
                var mashAdapter = new $.jqx.dataAdapter(mashSource, {
                        beforeLoadComplete: function (records) {
                                mash_infuse = 0;
                                var data = new Array();
                                for (var i = 0; i < records.length; i++) {
                                        var row = records[i];
                                        if (row.step_type == 'Infusion')
                                                mash_infuse += parseFloat(row.step_infuse_amount);
                                }
                        },
                });
                $("#mashGrid").jqxGrid({
                        width: 960,
                        height: 400,
                        source: mashAdapter,
                        theme: theme,
                        selectionmode: 'singlerow',
                        editmode: 'selectedcell',
                        editable: true,
                        localization: getLocalization(),
                        showtoolbar: true,
                        rendertoolbar: function (toolbar) {
                                var me = this;
                                var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
                                toolbar.append(container);
                                container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');
                                container.append('<input style="float: left; margin-left: 230px;" id="sdeleterowbutton" type="button" value="Verwijder stap" />');
                                $("#saddrowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
                                $("#saddrowbutton").on('click', function () {
                                        var datarow = generaterow();
                                        var commit = $("#mashGrid").jqxGrid('addrow', null, datarow);
                                });
                                // delete selected yeast.
                                $("#sdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
                                $("#sdeleterowbutton").on('click', function () {
                                        var selectedrowindex = $("#mashGrid").jqxGrid('getselectedrowindex');
                                        var rowscount = $("#mashGrid").jqxGrid('getdatainformation').rowscount;
                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                                                var id = $("#mashGrid").jqxGrid('getrowid', selectedrowindex);
                                                var commit = $("#mashGrid").jqxGrid('deleterow', id);
                                        }
                                });
                        },
                        ready: function() {
                                var fg = estimate_fg(psugar, pcara, 0, 0, 0, svg, parseFloat(parseFloat($("#est_og").jqxNumberInput('decimal'))));
                                dataRecord.est_fg = fg;
                                $('#est_fg').val(fg);
                                calcInit();
                                $('#jqxLoader').jqxLoader('close');
                                $('#jqxTabs').jqxTabs('first');
                        },
                        columns: [
                                { text: 'Stap naam', datafield: 'step_name' },
                                { text: 'Stap type', datafield: 'step_type', width: 110, columntype: 'dropdownlist',
                                  createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
                                        var dataSource = [ "Infusion", "Temperature", "Decoction" ];
                                        editor.jqxDropDownList({ source: dataSource, dropDownHeight: 105 });
                                  }
                                },
                                { text: 'Temperatuur', datafield: 'step_temp', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1',
                                  validation: function (cell, value) {
                                        if (value < 35 || value > 80) {
                                                return { result: false, message: "De temperatuur moet tussen 35 en 80 zijn." };
                                        }
                                        return true;
                                  }
                                },
                                { text: 'Eind', datafield: 'end_temp', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1',
                                  validation: function (cell, value) {
                                        if (value < 35 || value > 80) {
                                                return { result: false, message: "De temperatuur moet tussen 35 en 80 zijn." };
                                        }
                                        return true;
                                  }
                                },
                                { text: 'Tijd', datafield: 'step_time', width: 70, align: 'right', cellsalign: 'right',
                                  validation: function (cell, value) {
                                        if (value < 1 || value > 360) {
                                                return { result: false, message: "De tijd moet tussen 1 en 360 zijn." };
                                        }
                                        return true;
                                  }
                                },
                                { text: 'Stap', datafield: 'ramp_time', width: 70, align: 'right', cellsalign: 'right',
                                  validation: function (cell, value) {
                                        if (value < 1 || value > 60) {
                                                return { result: false, message: "De tijd moet tussen 1 en 60 zijn." };
                                        }
                                        return true;
                                  }
                                },
                                { text: 'Infuse', datafield: 'step_infuse_amount', width: 70, align: 'right', cellsalign: 'right',
                                  validation: function (cell, value) {
                                        if (value < 0 || value > 60) {
                                                return { result: false, message: "De waarde moet tussen 0 en 60 zijn." };
                                        }
                                        return true;
                                  }
                                }
                        ]
                });
                $("#mashGrid").on('cellendedit', function (event) {
                        $('#mashGrid').jqxGrid('sortby', 'step_temp', 'asc');
                });
        };

	// initialize the input fields.
        var srcType = [ "All Grain", "Partial Mash", "Extract" ];
        var srcColor = [ "Morey", "Mosher", "Daniels" ];
        var srcIBU = [ "Tinseth", "Rager", "Daniels" ]; // Only these are supported at this time.
        var srcBase = [ "NaHCO3", "Na2CO3", "CaCO3", "Ca(OH)2" ];
        var srcAcid = [ "Melkzuur", "Zoutzuur", "Fosforzuur", "Zwavelzuur" ];
	var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ];
	var srcAeration= [ 'None', 'Air', 'Oxygen' ];
	var srcCooling= [ '-', 'Emersion chiller', 'Counterflow chiller', 'Au bain marie', 'Natural' ];
	//                '-', 'Dompelkoeler', 'Tegenstroomkoeler', 'Au bain marie', 'Laten afkoelen'
	$("#name").jqxInput({ theme: theme, width: 640, height: 23 });
	$("#code").jqxInput({ theme: theme, width: 100, height: 23 });
	$("#birth").jqxDateTimeInput({ theme: theme, width: 150, height: 23, formatString: 'yyyy-MM-dd' });
	$("#stage").jqxInput({ theme: theme, width: 100, height: 23 });
	$("#notes").jqxInput({ theme: theme, width: 960, height: 200 });
	$("#log_brew").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$("#log_fermentation").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$("#inventory_reduced").jqxCheckBox({ theme: theme, width: 120, height: 23 });
	$('#inventory_reduced').on('checked', function (event) {
		// Call a script to do the work and block this.
		// Note that this script must set this flag too, so if the user doesn't Save it is still set.
		// Call the script with the uuid.
		$("#inventory_reduced").jqxCheckBox({ disabled : true });
	});
	$("#locked").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$('#locked').on('checked', function (event) {
		if (brewstage >= 10) {
			$("#stage").val('Closed');
			brewstage = 11;
		}
	});
	$('#locked').on('unchecked', function (event) {
		if (brewstage >= 10) {
			$("#stage").val('Ready');
			brewstage = 10;
		}
	});
	$("#eq_name").jqxInput({ theme: theme, width: 250, height: 23 });
	$("#eq_boil_size").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_batch_size").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_tun_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_top_up_water").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_trub_chiller_loss").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_evap_rate").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 2,  });
	$("#eq_boil_time").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#eq_top_up_kettle").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_hop_utilization").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#eq_notes").jqxInput({ theme: theme, width: 800, height: 100 });
	$("#eq_lauter_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_lauter_deadspace").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_kettle_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_mash_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_mash_max").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	// Brewday
	$("#brew_date_start").jqxDateTimeInput({ theme: theme, width: 230, height: 23, formatString: 'yyyy-MM-dd HH:mm:ss', showTimeButton: true });
	$("#brew_mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_mash_sg").jqxNumberInput({ inputMode: 'simple',  spinMode: 'simple', theme: theme, width: 90, height: 23, min: 1.000, max: 1.200, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
	$("#brew_mash_sg").on('valueChanged', function () { calcMashEfficiency(); });
	$("#brew_mash_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#brew_sparge_temperature").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_sparge_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_sparge_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 14, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_preboil_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_preboil_sg").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
	$("#brew_preboil_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_preboil_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#brew_aboil_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_aboil_sg").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
	$("#brew_aboil_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_aboil_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#brew_whirlpool9").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_whirlpool7").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_whirlpool6").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_whirlpool2").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 120, decimalDigits: 0, spinButtons: true });
	$("#brew_cooling_method").jqxDropDownList({ theme: theme, source: srcCooling, width: 170, height: 23, dropDownHeight: 153 });
	$("#brew_cooling_to").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_cooling_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 1440, decimalDigits: 0, spinButtons: true });
	$("#brew_aeration_type").jqxDropDownList({ theme: theme, source: srcAeration, width: 100, height: 23, dropDownHeight: 95 });
	$("#brew_aeration_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 1440, decimalDigits: 0, spinButtons: true });
	$("#brew_aeration_speed").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, max: 1440, decimalDigits: 0, spinButtons: true });
	$("#brew_fermenter_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_fermenter_extrawater").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_fermenter_extrasugar").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_fermenter_sg").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
	$("#brew_fermenter_ibu").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#brew_fermenter_color").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#brew_date_end").jqxDateTimeInput({ theme: theme, width: 230, height: 23, formatString: 'yyyy-MM-dd HH:mm:ss', showTimeButton: true });
	// Vergisting
	// Packaging
	// Tasting

	$("#batch_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: 'L', symbolPosition: 'right' });
	$("#boil_size").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 2, readOnly: true, symbol: 'L', symbolPosition: 'right' });
	$("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 360, decimalDigits: 0, spinButtons: true });
	$("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 40, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right'  });
	$("#est_og").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });
	$("#est_og2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 3, readOnly: true });
	$("#st_og_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
	$("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });

	$("#est_fg").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 3, readOnly: true });
	$("#st_fg_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
	$("#st_fg_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });

	$("#est_abv").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
	$("#st_abv_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
	$("#st_abv_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });

	$("#est_color").jqxNumberInput({ inputMode: 'simple', theme: theme, symbol: ' EBC', symbolPosition: 'right', width: 100, height: 23, decimalDigits: 0, readOnly: true });
	$("#est_color2").jqxNumberInput({ inputMode: 'simple', theme: theme, symbol: ' EBC', symbolPosition: 'right', width: 100, height: 23, decimalDigits: 0, readOnly: true });
	$("#st_color_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
	$("#st_color_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
	$("#color_method").jqxDropDownList({ theme: theme, source: srcColor, width: 125, height: 23, dropDownHeight: 95 });

	$("#est_ibu").jqxNumberInput({ inputMode: 'simple', theme: theme, symbol: ' IBU', symbolPosition: 'right', width: 100, height: 23, decimalDigits: 0, readOnly: true });
	$("#est_ibu2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
	$("#st_ibu_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
	$("#st_ibu_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
	$("#ibu_method").jqxDropDownList({ theme: theme, source: srcIBU, width: 125, height: 23, dropDownHeight: 95, dropDownVerticalAlignment: 'top' });

	$("#est_carb").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
	$("#st_carb_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
	$("#st_carb_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });

	$("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 });
	$("#mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 8, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#tgt_mash_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, readOnly: true });
	$("#sparge_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 70, max: 98, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });

	$("#est_mash_sg").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 });

        // Several gauges
        $("#hop_flavour").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true });
        $("#hop_aroma").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true });
        $("#perc_malts").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true });
        $("#perc_sugars").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true });
        $("#perc_cara").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true });

        // Water treatment
        $("#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 (event) {
                if (event.args) {
                        var index = event.args.index;
                        var datarecord = waterlist.records[index];
                        dataRecord.w1_name = datarecord.name;
                        $("#w1_calcium").val(datarecord.calcium);
                        dataRecord.w1_calcium = datarecord.calcium;
                        $("#w1_sulfate").val(datarecord.sulfate);
                        dataRecord.w1_sulfate = datarecord.sulfate;
                        $("#w1_chloride").val(datarecord.chloride);
                        dataRecord.w1_chloride = datarecord.chloride;
                        $("#w1_sodium").val(datarecord.sodium);
                        dataRecord.w1_sodium = datarecord.sodium;
                        $("#w1_magnesium").val(datarecord.magnesium);
                        dataRecord.w1_magnesium = datarecord.magnesium;
                        $("#w1_total_alkalinity").val(datarecord.total_alkalinity);
                        dataRecord.w1_total_alkalinity = datarecord.total_alkalinity;
                        $("#w1_ph").val(datarecord.ph);
                        dataRecord.w1_ph = datarecord.ph;
                        $("#w1_cost").val(datarecord.cost);
                        dataRecord.w1_cost = datarecord.cost;
                        calcWater();
                }
        });
        $("#w1_amount").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w1_calcium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w1_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w1_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w1_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w1_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w1_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w1_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });

        $("#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 (event) {
                if (event.args) {
                        var index = event.args.index;
                        var datarecord = waterlist.records[index];
                        dataRecord.w2_name = datarecord.name;
                        $("#w2_calcium").val(datarecord.calcium);
                        dataRecord.w2_calcium = datarecord.calcium;
                        $("#w2_sulfate").val(datarecord.sulfate);
                        dataRecord.w2_sulfate = datarecord.sulfate;
                        $("#w2_chloride").val(datarecord.chloride);
                        dataRecord.w2_chloride = datarecord.chloride;
                        $("#w2_sodium").val(datarecord.sodium);
                        dataRecord.w2_sodium = datarecord.sodium;
                        $("#w2_magnesium").val(datarecord.magnesium);
                        dataRecord.w2_magnesium = datarecord.magnesium;
                        $("#w2_total_alkalinity").val(datarecord.total_alkalinity);
                        dataRecord.w2_total_alkalinity = datarecord.total_alkalinity;
                        $("#w2_ph").val(datarecord.ph);
                        dataRecord.w2_ph = datarecord.ph;
                        $("#w2_cost").val(datarecord.cost);
                        dataRecord.w2_cost = datarecord.cost;
                        $("#w2_amount").jqxNumberInput({ max: 100000, readOnly: false }); // Set high max to enable the spinbuttons.
                        calcWater();
                }
        });
        $("#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({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w2_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w2_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w2_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w2_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w2_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#w2_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });

        $("#wg_amount").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wg_calcium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wg_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wg_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wg_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wg_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wg_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wg_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wb_calcium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wb_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wb_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wb_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wb_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wb_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wb_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });

        $("#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 (event) {
                if (event.args) {
                        var index = event.args.index;
                        var datarecord = waterprofiles.records[index];
                        $("#pr_calcium").val(datarecord.calcium);
                        $("#pr_sulfate").val(datarecord.sulfate);
                        $("#pr_chloride").val(datarecord.chloride);
                        $("#pr_sodium").val(datarecord.sodium);
                        $("#pr_magnesium").val(datarecord.magnesium);
                        $("#pr_total_alkalinity").val(datarecord.total_alkalinity);
                }
        });
        $("#pr_calcium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#pr_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#pr_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#pr_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#pr_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#pr_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true });
        $("#wa_cacl2").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' });
        $("#wa_caso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' });
        $("#wa_mgso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' });
        $("#wa_nacl").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' });

        $("#calc_acid").jqxCheckBox({ theme: theme, width: 120, height: 23 });
        $("#wa_base_name").jqxDropDownList({ theme: theme, source: srcBase, width: 125, height: 23, dropDownHeight: 128 });
        $("#wa_base").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05, symbol: ' gr', symbolPosition: 'right' });
        $("#wa_acid_name").jqxDropDownList({ theme: theme, source: srcAcid, width: 125, height: 23, dropDownHeight: 128 })
        $("#wa_acid").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05, symbol: ' ml', symbolPosition: 'right' });
        $("#wa_acid_perc").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 80, height: 23, min: 0, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right' });

        $("#sparge_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
        $("#sparge_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
        $("#sparge_acid_amount").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 5, readOnly: true });

	$('#jqxTabs').jqxTabs({
		theme: theme,
		width: 1280,
		height: 630,
		autoHeight: false,
		position: 'top'
	});

	// Buttons below
	$("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
	$("#Delete").click(function () {
		// Open a popup to confirm this action.
		$('#eventWindow').jqxWindow('open');
		$("#delOk").click(function () {
			var data = "delete=true&" + $.param({ uuid: dataRecord.uuid });
			$.ajax({
				dataType: 'json',
				url: url,
				cache: false,
				data: data,
				type: "POST",
				success: function (data, status, xhr) {
					// delete command is executed.
					window.location.href = my_return;
				},
				error: function (jqXHR, textStatus, errorThrown) {
				}
			});
		});
	});

	$("#Cancel").jqxButton({ template: "primary", width: '80px', theme: theme });
	$("#Cancel").click(function () {
		window.location.href = my_return;
	});

	$("#Save").jqxButton({ template: "success", width: '90px', theme: theme });
	$("#Save").click(function () {
		console.log(dataRecord.uuid);
		var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
		var hoprow = $('#hopGrid').jqxGrid('getrows');
		var miscrow = $('#miscGrid').jqxGrid('getrows');
		var yeastrow = $('#yeastGrid').jqxGrid('getrows');
		var mashrow = $('#mashGrid').jqxGrid('getrows');
		var row = {
			record: my_record,
			uuid: dataRecord.uuid,
			name: $("#name").val(),
			code: $("#code").val(),
			birth: $("#birth").val(),
			stage: $("#stage").val(),
			notes: $("#notes").val(),
			log_brew: $("#log_brew").val(),
			log_fermentation: $("#log_fermentation").val(),
			inventory_reduced: $("#inventory_reduced").val(),
			locked: $("#locked").val(),
			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: dataRecord.eq_tun_weight,
			eq_tun_specific_heat: dataRecord.eq_tun_specific_heat,
			eq_tun_material: dataRecord.eq_tun_material,
			eq_tun_height: dataRecord.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: dataRecord.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: dataRecord.eq_lauter_height,
			eq_lauter_deadspace: parseFloat($("#eq_lauter_deadspace").jqxNumberInput('decimal')),
			eq_kettle_volume: parseFloat($("#eq_kettle_volume").jqxNumberInput('decimal')),
			eq_kettle_height: dataRecord.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')),
	//		st_name: $('#st_name').val(),
	//		st_letter: $('#st_letter').val(),
	//		st_guide: $('#st_guide').val(),
	//		st_type: $('#st_type').val(),
	//		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_acid_type: $("#sparge_acid_type").val(),
		//      sparge_acid_perc: parseFloat($("#sparge_acid_perc").jqxNumberInput('decimal')),
		//      sparge_acid_amount: parseFloat($("#sparge_acid_amount").jqxNumberInput('decimal')),
			calc_acid: $("#calc_acid").val(),
			w1_name: $("#w1_name").val(),
			w1_amount: parseFloat($("#w1_amount").jqxNumberInput('decimal')),
			w1_calcium: parseFloat($("#w1_calcium").jqxNumberInput('decimal')),
			w1_sulfate: parseFloat($("#w1_sulfate").jqxNumberInput('decimal')),
			w1_chloride: parseFloat($("#w1_chloride").jqxNumberInput('decimal')),
			w1_sodium: parseFloat($("#w1_sodium").jqxNumberInput('decimal')),
			w1_magnesium: parseFloat($("#w1_magnesium").jqxNumberInput('decimal')),
			w1_total_alkalinity: parseFloat($("#w1_total_alkalinity").jqxNumberInput('decimal')),
			w1_ph: parseFloat($("#w1_ph").jqxNumberInput('decimal')),
			w1_cost: dataRecord.w1_cost,
			w2_name: $("#w2_name").val(),
			w2_amount: parseFloat($("#w2_amount").jqxNumberInput('decimal')),
			w2_calcium: parseFloat($("#w2_calcium").jqxNumberInput('decimal')),
			w2_sulfate: parseFloat($("#w2_sulfate").jqxNumberInput('decimal')),
			w2_chloride: parseFloat($("#w2_chloride").jqxNumberInput('decimal')),
			w2_sodium: parseFloat($("#w2_sodium").jqxNumberInput('decimal')),
			w2_magnesium: parseFloat($("#w2_magnesium").jqxNumberInput('decimal')),
			w2_total_alkalinity: parseFloat($("#w2_total_alkalinity").jqxNumberInput('decimal')),
			w2_ph: parseFloat($("#w2_ph").jqxNumberInput('decimal')),
			w2_cost: dataRecord.w2_cost,
			fermentables: fermentablerow,
			hops: hoprow,
			miscs: miscrow,
			yeasts: yeastrow,
			mashs: mashrow
		};
		var data = "update=true&" + $.param(row);
		$.ajax({
			dataType: 'json',
			url: url,
			cache: false,
			data: data,
			type: "POST",
			success: function (data, status, xhr) {
				// update command is executed.
				window.location.href = my_return;
			},
			error: function(jqXHR, textStatus, errorThrown) {
			}
		});
	});	
	createDelElements();
});

mercurial