-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.js
More file actions
2714 lines (2476 loc) · 137 KB
/
controls.js
File metadata and controls
2714 lines (2476 loc) · 137 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ============================================================
// controls.js — Page-level logic for Controls.html
// ============================================================
//
// This file handles all form interaction, input validation, and results
// rendering for the Bin-Method RTU Comparison Calculator. It is the
// glue between the HTML form (Controls.html) and the calculation engine
// (engine/engine_module.js).
//
// Flow:
// Page load → populate dropdowns, fetch city data, run recalcVentilation()
// User edits → onChangeHandler() dispatches per-control logic
// Submit → submitToEngine() validates inputs, calls the engine,
// then buildResultsHTML() renders economics, bin tables,
// and charts (Google Charts)
//
// For a detailed description of the calculation flow, module
// communication, and ASP/JS parity notes, see ARCHITECTURE.md.
//
// Sections (search for "// ----" or "// ===="):
// Dropdown population — cmbTotalCap, cmbPLDegrFactor
// City data — loadCityData, updateCities
// Utility / validation — cFD, cFDW, problemInPowerValue,
// checkTextBoxNumber, text_notOK, countMatches
// EER / power helpers — updateEER, updateCond_kw
// Spreadsheet data — validateSpreadsheetData, parseSpreadsheetFields,
// applySpreadsheetToForm
// Ventilation — recalcVentilation, refineVentilationFromCapacity
// Fan power defaults — setFanPowerValuesAndDefaults, resetPowerDefaults
// Default-color tracking — checkForDefaults
// Change handler — onChangeHandler
// Load line lock — fetchLoadLine
// Advanced controls toggle — toggleAdvanced
// Building load models — buildingLoadModels, calcSIV, syncBuildingModelFields
// Economics helpers — UPV, NPV_calc, ROR_calc, Payback_calc, formatNumber
// Chart drawing — drawPaybackChart, drawBinLoadsChart, drawBinPerfChart
// Submit & results — submitToEngine, buildResultsHTML
// Page initialization — loadCityData → updateCities → recalcVentilation
// ============================================================
// ---- Populate Total Capacity dropdown (36..360) ----
(function() {
var sel = document.getElementById('cmbTotalCap');
for (var i = 36; i <= 360; i++) {
var opt = document.createElement('option');
var label = (i < 100 ? '0' : '') + (i < 10 ? '0' : '') + i;
opt.text = label;
opt.value = label;
if (i === 84) opt.selected = true;
sel.add(opt);
}
})();
// ---- Populate Degradation Factor dropdowns (0..50) ----
(function() {
var ids = ['cmbPLDegrFactor_C', 'cmbPLDegrFactor_S'];
for (var k = 0; k < ids.length; k++) {
var sel = document.getElementById(ids[k]);
if (!sel) continue;
for (var i = 0; i <= 50; i++) {
var opt = document.createElement('option');
opt.text = String(i);
opt.value = String(i);
if (i === 25) opt.selected = true;
sel.add(opt);
}
}
})();
// ---- City data by state (loaded from Stations.json) ----
var cityData = null;
async function loadCityData() {
try {
var resp = await fetch('data/stations.json');
var stations = await resp.json();
cityData = {};
for (var i = 0; i < stations.length; i++) {
var s = stations[i];
var st = s.state || s.State;
var ci = s.City || s.city;
if (!st || !ci) continue;
if (!cityData[st]) cityData[st] = [];
if (cityData[st].indexOf(ci) === -1) cityData[st].push(ci);
}
// Sort cities within each state
for (var st in cityData) {
cityData[st].sort();
}
} catch(e) {
console.error('Failed to load city data:', e);
}
}
function toTitleCase(s) {
return s.replace(/\w\S*/g, function(t) {
return t.charAt(0).toUpperCase() + t.substr(1).toLowerCase();
});
}
function updateCities() {
if (!cityData) return;
var stSel = document.getElementById('cmbState');
var ciSel = document.getElementById('cmbCityName2');
var st = stSel.options[stSel.selectedIndex].text;
var cities = cityData[st] || [];
ciSel.innerHTML = '';
for (var i = 0; i < cities.length; i++) {
var opt = document.createElement('option');
opt.value = cities[i];
opt.text = toTitleCase(cities[i]);
ciSel.add(opt);
}
checkForDefaults('cmbCityName2');
}
// ---- Utility functions ----
function theSelectedValueInPullDownBox(boxname) {
var el = document.forms.HECACParameters[boxname];
if (!el) return '';
for (var i = 0; i < el.length; i++) {
if (el.options[i].selected) return el.options[i].text;
}
return '';
}
function selectValueInPullDownBox(boxname, valueToSelect) {
var dB = document.forms.HECACParameters[boxname];
if (!dB) return;
for (var i = 0; i < dB.length; i++) {
if (dB.options[i].text == valueToSelect) {
dB.options[i].selected = true;
return;
}
}
}
// Color For Default — highlights the "default" column cell to show whether
// the current value differs from the factory default (dark = matches, lighter = changed).
function cFD(blnInequality, strCellName) {
var theCell = document.getElementById(strCellName);
if (!theCell) return;
theCell.style.backgroundColor = blnInequality ? '#3a3b3e' : '#707276';
}
// Color For Default (Warning variant) — yellow tint on the control cell itself
// to flag caution states (e.g. spreadsheet data active, building model edited).
function cFDW(blnInequality, strCellName) {
var theCell = document.getElementById(strCellName);
if (!theCell) return;
theCell.style.backgroundColor = blnInequality ? '#FAFAD2' : '#fff';
}
function problemInPowerValue(controlName) {
var warnings = {
'txtBFn_kw_C': 'The candidate unit Blower Fan (BFn) field must contain a number (e.g. 1.5)',
'txtBFn_kw_S': 'The standard unit Blower Fan (BFn) field must contain a number (e.g. 1.5)',
'txtAux_kw_C': 'The candidate unit Auxiliary (Aux) field must contain a number (e.g. 1.5)',
'txtAux_kw_S': 'The standard unit Auxiliary (Aux) field must contain a number (e.g. 1.5)',
'txtCond_kw_C': 'The candidate unit Compressor (Comp) field must contain a number (e.g. 1.5)',
'txtCond_kw_S': 'The standard unit Compressor (Comp) field must contain a number (e.g. 1.5)'
};
var msg = warnings[controlName];
if (!msg) { window.alert('Warning from problemInPowerValue: Cannot find that control name.'); return true; }
var val = parseFloat(document.getElementById(controlName).value);
if (!isFinite(val)) { window.alert(msg); return true; }
return false;
}
// Returns true if theText is empty or contains characters matching regExpression.
function text_notOK(theText, regExpression) {
if ((theText.length == 0) || (theText.search(regExpression) != -1)) {
return true;
} else {
return false;
}
}
// Returns the number of regex matches in theText.
function countMatches(theText, regExpression) {
if (theText.search(regExpression) == -1) {
return 0;
} else {
return theText.match(regExpression).length;
}
}
// Validates that a form text field contains a well-formed number.
// numberPeriods: 'None' = integer, 'NoneOrOne' = integer or decimal, 'One' = must have decimal point.
// Returns true if the value is INVALID (matches ASP Controls.asp checkTextBoxNumber).
function checkTextBoxNumber(textBoxName, numberPeriods) {
var theText = document.forms.HECACParameters[textBoxName].value;
if (numberPeriods == 'None') {
return (text_notOK(theText, /[^0-9\.]/) || (countMatches(theText, /\./g) != 0));
} else if (numberPeriods == 'NoneOrOne') {
return (text_notOK(theText, /[^0-9\.]/) || (countMatches(theText, /\./g) > 1));
} else if (numberPeriods == 'One') {
return (text_notOK(theText, /[^0-9\.]/) || (countMatches(theText, /\./g) != 1));
} else {
window.alert('error 1 from checkTextBoxValue');
return false;
}
}
function updateEER(strCorS) {
var myForm = document.forms.HECACParameters;
var dblCap_kbtuh = myForm['txtTotalCap'].value * 1;
var dblBFn_kw, dblAux_kw, dblCond_kw, dblEER;
if (strCorS === 'C') {
dblBFn_kw = myForm['txtBFn_kw_C'].value * 1;
dblAux_kw = myForm['txtAux_kw_C'].value * 1;
dblCond_kw = myForm['txtCond_kw_C'].value * 1;
dblEER = dblCap_kbtuh / (dblBFn_kw + dblAux_kw + dblCond_kw);
myForm['txtEER'].value = dblEER.toFixed(2);
checkForDefaults('txtEER');
} else {
dblBFn_kw = myForm['txtBFn_kw_S'].value * 1;
dblAux_kw = myForm['txtAux_kw_S'].value * 1;
dblCond_kw = myForm['txtCond_kw_S'].value * 1;
dblEER = dblCap_kbtuh / (dblBFn_kw + dblAux_kw + dblCond_kw);
myForm['txtEER_Standard'].value = dblEER.toFixed(2);
checkForDefaults('txtEER_Standard');
}
}
function updateCond_kw(strCorS) {
var myForm = document.forms.HECACParameters;
var dblCap_kbtuh = myForm['txtTotalCap'].value * 1;
var dblBFn_kw, dblAux_kw, dblCond_kw, dblEER;
if (strCorS === 'C') {
dblBFn_kw = myForm['txtBFn_kw_C'].value * 1;
dblAux_kw = myForm['txtAux_kw_C'].value * 1;
dblEER = myForm['txtEER'].value * 1;
dblCond_kw = (dblCap_kbtuh / dblEER) - (dblBFn_kw + dblAux_kw);
myForm['txtCond_kw_C'].value = dblCond_kw.toFixed(3);
document.getElementById('tdCond_kw_C_default').textContent = dblCond_kw.toFixed(3);
checkForDefaults('txtCond_kw_C');
} else {
dblBFn_kw = myForm['txtBFn_kw_S'].value * 1;
dblAux_kw = myForm['txtAux_kw_S'].value * 1;
dblEER = myForm['txtEER_Standard'].value * 1;
dblCond_kw = (dblCap_kbtuh / dblEER) - (dblBFn_kw + dblAux_kw);
myForm['txtCond_kw_S'].value = dblCond_kw.toFixed(3);
document.getElementById('tdCond_kw_S_default').textContent = dblCond_kw.toFixed(3);
checkForDefaults('txtCond_kw_S');
}
}
// Lightweight client-side parse of spreadsheet data to extract key fields.
// Validate spreadsheet data format (matches ASP classes.asp ParseAndModel lines 690-713).
// Returns an error message string if invalid, or '' if OK.
function validateSpreadsheetData(ssText, unitName) {
if (!ssText) return 'WARNING: Spreadsheet data for the ' + unitName + ' unit is empty.';
var norm = ssText.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
var rows = norm.split('\n');
if (rows.length > 1 && rows.length < 40) {
var versionRow = rows[1] || '';
if (versionRow.indexOf('V1.2') === -1) {
return 'WARNING: Spreadsheet data for the ' + unitName + ' unit is not in the correct form or the spreadsheet version is not V1.2.';
}
} else {
if (rows.length > 39) {
return 'WARNING: Spreadsheet data for the ' + unitName + ' unit is not in the correct form. It looks like maybe you pasted the data more than once. Clear out the spreadsheet cell and try again.';
} else {
return 'WARNING: Spreadsheet data for the ' + unitName + ' unit is not in the correct form. Clear out the spreadsheet cell and try again.';
}
}
return '';
}
// Matches ASP ParseSpreadsheet sub (Controls.asp line 735).
function parseSpreadsheetFields(ssText) {
var result = {};
if (!ssText) return result;
var rows = ssText.split(/\r\n|\n|\r/);
for (var j = 0; j < rows.length; j++) {
var cells = rows[j].split('\t');
var key = (cells[0] || '').trim();
if (key === 'NetCoolingCapacity') result.netCoolingCapacity = parseFloat(cells[2]);
else if (key === 'EER') result.eer = parseFloat(cells[2]);
else if (key === 'EvaporatorFanPower') result.evapFanPower = parseFloat(cells[2]);
else if (key === 'AuxilaryPower' || key === 'AuxiliaryPower') result.auxPower = parseFloat(cells[2]);
else if (key === 'CondenserPower' || key === 'CondensorPower') result.condenserPower = parseFloat(cells[2]);
else if (key === 'ST_Ratio') result.stRatio = parseFloat(cells[2]);
}
return result;
}
// Update form fields from parsed spreadsheet data (matches ASP ParseSpreadsheet).
// strCorS = 'C' for candidate, 'S' for standard.
function applySpreadsheetToForm(strCorS, ssFields) {
var form = document.forms.HECACParameters;
if (!ssFields || !isFinite(ssFields.netCoolingCapacity)) return;
// Update total capacity (common to both units)
var capKBtuh = Math.round(ssFields.netCoolingCapacity / 1000);
form['txtTotalCap'].value = capKBtuh;
selectValueInPullDownBox('cmbTotalCap', String(capKBtuh).padStart(3, '0'));
checkForDefaults('cmbTotalCap');
// Default power calculation constants (match ASP FanPower_Default / Condenser_Power_kW)
var dblBFn_slope = 0.0132;
var dblBFn_int = -0.2283;
var dblDefaultBFn = dblBFn_slope * capKBtuh + dblBFn_int;
var dblDefaultAux = 0;
// Unit-specific power fields and EER
if (strCorS === 'C') {
if (isFinite(ssFields.evapFanPower)) form['txtBFn_kw_C'].value = ssFields.evapFanPower.toFixed(3);
if (isFinite(ssFields.auxPower)) form['txtAux_kw_C'].value = ssFields.auxPower.toFixed(3);
if (isFinite(ssFields.condenserPower)) form['txtCond_kw_C'].value = ssFields.condenserPower.toFixed(3);
if (isFinite(ssFields.eer)) form['txtEER'].value = ssFields.eer.toFixed(1);
if (isFinite(ssFields.stRatio)) {
var stVal = Math.round(ssFields.stRatio * 100) / 100;
selectValueInPullDownBox('cmbST_Ratio_C', stVal.toFixed(2));
checkForDefaults('cmbST_Ratio_C');
}
// If standard unit has no spreadsheet, recalc ONLY its power from new capacity
if (!document.getElementById('chkSpreadsheetControl_S').checked) {
var eerS = parseFloat(form['txtEER_Standard'].value);
var condS = (capKBtuh / eerS) - (dblDefaultBFn + dblDefaultAux);
form['txtBFn_kw_S'].value = dblDefaultBFn.toFixed(3);
form['txtAux_kw_S'].value = dblDefaultAux.toFixed(3);
form['txtCond_kw_S'].value = condS.toFixed(3);
}
} else {
if (isFinite(ssFields.evapFanPower)) form['txtBFn_kw_S'].value = ssFields.evapFanPower.toFixed(3);
if (isFinite(ssFields.auxPower)) form['txtAux_kw_S'].value = ssFields.auxPower.toFixed(3);
if (isFinite(ssFields.condenserPower)) form['txtCond_kw_S'].value = ssFields.condenserPower.toFixed(3);
if (isFinite(ssFields.eer)) form['txtEER_Standard'].value = ssFields.eer.toFixed(1);
if (isFinite(ssFields.stRatio)) {
var stVal = Math.round(ssFields.stRatio * 100) / 100;
selectValueInPullDownBox('cmbST_Ratio_S', stVal.toFixed(2));
checkForDefaults('cmbST_Ratio_S');
}
// If candidate unit has no spreadsheet, recalc ONLY its power from new capacity
if (!document.getElementById('chkSpreadsheetControl_C').checked) {
var eerC = parseFloat(form['txtEER'].value);
var condC = (capKBtuh / eerC) - (dblDefaultBFn + dblDefaultAux);
form['txtBFn_kw_C'].value = dblDefaultBFn.toFixed(3);
form['txtAux_kw_C'].value = dblDefaultAux.toFixed(3);
form['txtCond_kw_C'].value = condC.toFixed(3);
}
}
// Update defaults display and colors
setFanPowerValuesAndDefaults(capKBtuh, 'OnlyDefaults');
checkForDefaults('txtEER');
checkForDefaults('txtEER_Standard');
checkForDefaults('txtBFn_kw_C');
checkForDefaults('txtAux_kw_C');
checkForDefaults('txtCond_kw_C');
checkForDefaults('txtBFn_kw_S');
checkForDefaults('txtAux_kw_S');
checkForDefaults('txtCond_kw_S');
}
// Recalculate ventilation rate after capacity changes (e.g. from spreadsheet data).
// Matches ASP behavior where Establish_SIV runs during InitializeControls.
async function recalcVentilation() {
try {
var form = document.forms.HECACParameters;
var psychro = await import('./engine/psychro.js');
var perf = await import('./engine/performance_module.js');
var engine = await import('./engine/engine_module.js?v=14');
if (!engine || typeof engine.exportBinCalcsJson !== 'function') return;
// Iterative Establish_SIV matching ASP Controls.asp lines 405-431:
// Run engine → extract sensibleCapacityDesign → refine ventilation → repeat
var lockWasChecked = form['chkLockLoadLine'] && form['chkLockLoadLine'].checked;
if (lockWasChecked) form['chkLockLoadLine'].checked = false;
var ranClean = false;
var bpfErrorMsg = '';
for (var iter = 0; iter < 4; iter++) {
try { await engine.exportBinCalcsJson(form, {}); } catch (ex) {
// Capture BPF/ADP error detail from the engine exception
var exMsg = ex && ex.message ? ex.message : '';
var bpfMatch = exMsg.match(/Engine error:\s*(.*)/i);
bpfErrorMsg = bpfMatch ? bpfMatch[1].trim() : exMsg;
break;
}
var ll = engine.getLastLoadLine();
if (!ll || !ll.debug || !ll.debug.capacity || !ll.debug.design) break;
var sensCapDesign = ll.debug.capacity.sensibleCapacityDesign;
if (!Number.isFinite(sensCapDesign) || sensCapDesign <= 0) break;
ranClean = true;
var prevVent = parseFloat(form['txtVentilationValue_NotAdvanced'].value);
await refineVentilationFromCapacity(psychro, perf, sensCapDesign, ll.debug.design);
var newVent = parseFloat(form['txtVentilationValue_NotAdvanced'].value);
if (Math.abs(newVent - prevVent) <= 0.1) break;
}
if (lockWasChecked) form['chkLockLoadLine'].checked = true;
// Show or clear the BPF warning area (matches ASP psychro.asp lines 368-370).
var warnArea = document.getElementById('bpfWarningArea');
if (!ranClean) {
// ASP fallback (Controls.asp lines 442-449): when BPF/ADP fails (e.g. S/T=0.80)
// Establish_SIV sets blnRanClean=False and ventilation falls back to 10%.
var ventUnits = theSelectedValueInPullDownBox('cmbVentilationUnits') || '';
var fallback;
if (ventUnits.toUpperCase().indexOf('CFM') >= 0) {
var cap = parseFloat(form['txtTotalCap'].value) || 84;
fallback = String(Math.round(0.10 * (cap / 12) * 400));
} else {
fallback = '10';
}
form['txtVentilationValue_NotAdvanced'].value = fallback;
form['txtVentilationValue'].value = fallback;
if (warnArea) {
var unitName = 'Candidate';
if (bpfErrorMsg && bpfErrorMsg.indexOf('Standard Unit') >= 0) unitName = 'Standard';
var cleanMsg = bpfErrorMsg.replace(/^(Candidate|Standard) Unit BPF:\s*/i, '');
warnArea.innerHTML = 'WARNING: Try lowering the S/T ratio for the ' + unitName + ' Unit.<br>'
+ 'ERROR Message from BPF calculation: ' + (cleanMsg || 'BPF/ADP calculation failed.');
warnArea.style.display = '';
}
} else {
if (warnArea) { warnArea.innerHTML = ''; warnArea.style.display = 'none'; }
}
// Update the default display to match the computed ventilation (ASP does this
// because the server re-renders the page with intVentilationValue in both the
// input and the default TD — see Controls.asp lines 1351 and 1355).
var ventDef = document.getElementById('tdVentilationValue_default');
if (ventDef) ventDef.textContent = form['txtVentilationValue'].value;
checkForDefaults('txtVentilationValue');
} catch (e) {
console.warn('recalcVentilation failed:', e);
}
}
// Compute default blower-fan, auxiliary, and condenser power from total capacity
// using the linear regression constants (matches ASP FanPower_Default / Condenser_Power_kW).
// strMode: 'AlsoFormValues' writes to form inputs; 'OnlyDefaults' updates only the
// default-display TDs and re-checks colors.
function setFanPowerValuesAndDefaults(dblCapacityTotal_kBtuh, strMode) {
var dblBFn_slope_kW_per_kBtuh = 0.0132;
var dblBFn_int_kW = -0.2283;
var dblBFanPower, dblAuxPower, dblCondPower_C, dblCondPower_S;
dblBFanPower = dblBFn_slope_kW_per_kBtuh * dblCapacityTotal_kBtuh + dblBFn_int_kW;
dblAuxPower = 0;
dblCondPower_C = (dblCapacityTotal_kBtuh / document.forms.HECACParameters['txtEER'].value) - (dblBFanPower + dblAuxPower);
dblCondPower_S = (dblCapacityTotal_kBtuh / document.forms.HECACParameters['txtEER_Standard'].value) - (dblBFanPower + dblAuxPower);
document.getElementById('tdBFn_kw_C_default').textContent = dblBFanPower.toFixed(3);
document.getElementById('tdAux_kw_C_default').textContent = dblAuxPower.toFixed(3);
document.getElementById('tdCond_kw_C_default').textContent = dblCondPower_C.toFixed(3);
document.getElementById('tdBFn_kw_S_default').textContent = dblBFanPower.toFixed(3);
document.getElementById('tdAux_kw_S_default').textContent = dblAuxPower.toFixed(3);
document.getElementById('tdCond_kw_S_default').textContent = dblCondPower_S.toFixed(3);
if (strMode === 'AlsoFormValues') {
document.forms.HECACParameters['txtBFn_kw_C'].value = dblBFanPower.toFixed(3);
document.forms.HECACParameters['txtAux_kw_C'].value = dblAuxPower.toFixed(3);
document.forms.HECACParameters['txtCond_kw_C'].value = dblCondPower_C.toFixed(3);
document.forms.HECACParameters['txtBFn_kw_S'].value = dblBFanPower.toFixed(3);
document.forms.HECACParameters['txtAux_kw_S'].value = dblAuxPower.toFixed(3);
document.forms.HECACParameters['txtCond_kw_S'].value = dblCondPower_S.toFixed(3);
}
checkForDefaults('txtBFn_kw_C');
checkForDefaults('txtAux_kw_C');
checkForDefaults('txtCond_kw_C');
checkForDefaults('txtBFn_kw_S');
checkForDefaults('txtAux_kw_S');
checkForDefaults('txtCond_kw_S');
}
function resetPowerDefaults() {
setFanPowerValuesAndDefaults(document.forms.HECACParameters['txtTotalCap'].value, 'AlsoFormValues');
var chkC = document.getElementById('chkSpreadsheetControl_C');
var chkS = document.getElementById('chkSpreadsheetControl_S');
if (chkC) chkC.checked = false;
if (chkS) chkS.checked = false;
}
// Compare the current value of controlName against its factory default and
// update the background color of the corresponding "default" column cell.
// Called after every control change to give the user a visual diff.
// NOTE: Default values here MUST stay in sync with getNonDefaultParams() below.
// If you change a default in one place, change it in the other.
function checkForDefaults(controlName) {
var sVPDB = theSelectedValueInPullDownBox;
var form = document.forms.HECACParameters;
if (controlName === 'cmbBuildingType') {
cFD(sVPDB(controlName) !== 'Office-Medium', 'tdBuildingType_default');
} else if (controlName === 'cmbState') {
cFD(sVPDB(controlName) !== 'MO', 'tdState_default');
} else if (controlName === 'cmbCityName2') {
cFD(sVPDB(controlName) !== 'Kansas City', 'tdCity_default');
} else if (controlName === 'cmbSchedule') {
cFD(sVPDB(controlName) !== 'M-Fri, 7 a.m. to 7 p.m.', 'tdSchedule_default');
} else if (controlName === 'cmbIDB') {
cFD(sVPDB(controlName) !== '75', 'tdIDB_default');
} else if (controlName === 'cmbIDB_SetBack') {
cFD(sVPDB(controlName) !== '5', 'tdIDB_SetBack_default');
} else if (controlName === 'cmbTotalCap') {
cFD(sVPDB(controlName) !== '084', 'tdTotalCapacity_default');
} else if (controlName === 'cmbOversizePercent') {
cFD(sVPDB(controlName) != 0, 'tdOversizePercent_default');
} else if (controlName === 'txtEER') {
cFD(form[controlName].value != 12, 'tdEER_default');
} else if (controlName === 'txtUnitCost') {
cFD(form[controlName].value != 4.5, 'tdUnitCost_default');
} else if (controlName === 'txtEER_Standard') {
cFD(form[controlName].value != 9.0, 'tdEER_Standard_default');
} else if (controlName === 'txtUnitCost_Standard') {
cFD(form[controlName].value != 4.0, 'tdUnitCost_Standard_default');
} else if (controlName === 'txtMaintenance_Standard') {
cFD(form[controlName].value != 0.0, 'tdMaintenance_Standard_default');
} else if (controlName === 'txtMaintenance_Candidate') {
cFD(form[controlName].value != 0.0, 'tdMaintenance_Candidate_default');
} else if (controlName === 'chkEconomizer_C') {
cFD(form[controlName].checked !== true, 'tdEconomizer_C_default');
} else if (controlName === 'chkEconomizer_S') {
cFD(form[controlName].checked !== true, 'tdEconomizer_S_default');
} else if (controlName === 'txtElectricityRate') {
cFD(form[controlName].value != 0.08, 'tdElectricityRate_default');
} else if (controlName === 'txtDiscountRate') {
cFD(form[controlName].value != 7.0, 'tdDiscountRate_default');
} else if (controlName === 'cmbEquipmentLife') {
cFD(sVPDB('cmbEquipmentLife') != 15, 'tdEquipmentLife_default');
} else if (controlName === 'txtNUnits') {
cFD(form[controlName].value != 1.0, 'tdNUnits_default');
} else if (controlName === 'chkChartPW') {
cFD(form[controlName].checked !== true, 'tdChartPW_default');
} else if (controlName === 'chkDetails') {
cFD(form[controlName].checked === true, 'tdDetails_default');
} else if (controlName === 'chkAdvancedControls') {
cFD(form[controlName].checked === true, 'tdAdvancedControls_default');
} else if (controlName === 'chkLockLoadLine') {
cFD(form[controlName].checked === true, 'tdLockLoadLine_default');
} else if (controlName === 'cmbST_Ratio_C') {
cFD(sVPDB(controlName) !== '0.72', 'tdST_Ratio_default_C');
} else if (controlName === 'cmbST_Ratio_S') {
cFD(sVPDB(controlName) !== '0.72', 'tdST_Ratio_default_S');
} else if (controlName === 'txtBFn_kw_C') {
var def = document.getElementById('tdBFn_kw_C_default');
if (def) cFD(form[controlName].value !== def.textContent.trim(), 'tdBFn_kw_C_default');
} else if (controlName === 'txtAux_kw_C') {
var def = document.getElementById('tdAux_kw_C_default');
if (def) cFD(form[controlName].value !== def.textContent.trim(), 'tdAux_kw_C_default');
} else if (controlName === 'txtCond_kw_C') {
var def = document.getElementById('tdCond_kw_C_default');
if (def) cFD(form[controlName].value !== def.textContent.trim(), 'tdCond_kw_C_default');
} else if (controlName === 'txtBFn_kw_S') {
var def = document.getElementById('tdBFn_kw_S_default');
if (def) cFD(form[controlName].value !== def.textContent.trim(), 'tdBFn_kw_S_default');
} else if (controlName === 'txtAux_kw_S') {
var def = document.getElementById('tdAux_kw_S_default');
if (def) cFD(form[controlName].value !== def.textContent.trim(), 'tdAux_kw_S_default');
} else if (controlName === 'txtCond_kw_S') {
var def = document.getElementById('tdCond_kw_S_default');
if (def) cFD(form[controlName].value !== def.textContent.trim(), 'tdCond_kw_S_default');
} else if (controlName === 'txtVentilationValue') {
var def = document.getElementById('tdVentilationValue_default');
if (def) cFD(form[controlName].value !== def.textContent.trim(), 'tdVentilationValue_default');
} else if (controlName === 'cmbVentilationUnits') {
cFD(sVPDB('cmbVentilationUnits') !== '% of Fan Cap.', 'tdVentilationUnits_default');
} else if (controlName === 'cmbN_Affinity') {
cFD(sVPDB(controlName) !== '2.5', 'tdN_Affinity_default');
} else if (controlName === 'txtCondFanPercent_C') {
cFD(form[controlName].value != 9.0, 'tdCondFanPercent_C');
} else if (controlName === 'txtCondFanPercent_S') {
cFD(form[controlName].value != 9.0, 'tdCondFanPercent_S');
} else if (controlName === 'chkTrackOHR') {
cFD(form[controlName].checked !== true, 'tdTrackOHR_default');
} else if (controlName === 'cmbIRH') {
cFD(sVPDB('cmbIRH') !== '60', 'tdIRH_default');
} else if (controlName === 'cmbNstages_C') {
cFD(sVPDB(controlName) !== '1', 'tdNStages_default_C');
} else if (controlName === 'cmbNstages_S') {
cFD(sVPDB(controlName) !== '1', 'tdNStages_default_S');
} else if (controlName === 'cmbFanControls_C') {
cFD(sVPDB(controlName) !== '1-Spd: Always ON', 'tdFanControls_C_default');
} else if (controlName === 'cmbFanControls_S') {
cFD(sVPDB(controlName) !== '1-Spd: Always ON', 'tdFanControls_S_default');
} else if (controlName === 'cmbPLDegrFactor_C') {
cFD(sVPDB(controlName) !== '25', 'tdPLDegrFactor_C_default');
} else if (controlName === 'cmbPLDegrFactor_S') {
cFD(sVPDB(controlName) !== '25', 'tdPLDegrFactor_S_default');
} else if (controlName === 'cmbSpecific_RTU_C') {
cFD(sVPDB(controlName) !== 'None', 'tdSpecific_RTU_C_default');
} else if (controlName === 'cmbDemandMonths') {
cFD(sVPDB(controlName) !== '0', 'tdDemandMonths_default');
} else if (controlName === 'txtDemandCostPerKW') {
cFD(form[controlName].value != 0, 'tdDemandCostPerKW_default');
} else if (controlName === 'txtSpreadsheetData_C') {
cFD((form[controlName].value !== ''), 'tdSpreadsheetData_C_default');
var ssChecked_C = document.getElementById('chkSpreadsheetControl_C').checked;
cFDW(ssChecked_C, 'tdPLDegrFactor_C_control');
cFDW(ssChecked_C, 'tdST_Ratio_C_control');
} else if (controlName === 'txtSpreadsheetData_S') {
cFD((form[controlName].value !== ''), 'tdSpreadsheetData_S_default');
var ssChecked_S = document.getElementById('chkSpreadsheetControl_S').checked;
cFDW(ssChecked_S, 'tdPLDegrFactor_S_control');
cFDW(ssChecked_S, 'tdST_Ratio_S_control');
}
}
// Collect all form parameters whose current value differs from the factory
// default. Returns a plain object { controlName: currentValue, ... }.
// NOTE: Default values here MUST stay in sync with checkForDefaults() above.
// If you change a default in one place, change it in the other.
function getNonDefaultParams() {
var sVPDB = theSelectedValueInPullDownBox;
var form = document.forms.HECACParameters;
var diff = {};
// Helpers — loose (!=) compare matches checkForDefaults behavior with numeric strings
function chk(name, defaultVal) {
var val = form[name] ? form[name].value : undefined;
if (val === undefined) return;
if (val != defaultVal) diff[name] = val;
}
function chkSel(name, defaultVal) {
var val = sVPDB(name);
if (val != defaultVal) diff[name] = val;
}
function chkChk(name, defaultChecked) {
if (!form[name]) return;
if (form[name].checked !== defaultChecked) diff[name] = form[name].checked;
}
function chkVsTd(name) {
var td = document.getElementById('td' + name.substr(3) + '_default');
if (!td) return;
if (form[name].value !== td.textContent.trim()) diff[name] = form[name].value;
}
// --- Dropdowns ---
chkSel('cmbBuildingType', 'Office-Medium');
chkSel('cmbState', 'MO');
chkSel('cmbCityName2', 'Kansas City');
chkSel('cmbSchedule', 'M-Fri, 7 a.m. to 7 p.m.');
chkSel('cmbIDB', '75');
chkSel('cmbIDB_SetBack', '5');
chkSel('cmbTotalCap', '084');
chkSel('cmbOversizePercent', '0');
chkSel('cmbEquipmentLife', '15');
chkSel('cmbST_Ratio_C', '0.72');
chkSel('cmbST_Ratio_S', '0.72');
chkSel('cmbVentilationUnits', '% of Fan Cap.');
chkSel('cmbN_Affinity', '2.5');
chkSel('cmbIRH', '60');
chkSel('cmbNstages_C', '1');
chkSel('cmbNstages_S', '1');
chkSel('cmbFanControls_C', '1-Spd: Always ON');
chkSel('cmbFanControls_S', '1-Spd: Always ON');
chkSel('cmbPLDegrFactor_C', '25');
chkSel('cmbPLDegrFactor_S', '25');
chkSel('cmbSpecific_RTU_C', 'None');
chkSel('cmbDemandMonths', '0');
// --- Text inputs ---
chk('txtEER', 12);
chk('txtUnitCost', 4.5);
chk('txtEER_Standard', 9.0);
chk('txtUnitCost_Standard', 4.0);
chk('txtMaintenance_Standard', 0.0);
chk('txtMaintenance_Candidate', 0.0);
chk('txtElectricityRate', 0.08);
chk('txtDiscountRate', 7.0);
chk('txtNUnits', 1.0);
chk('txtCondFanPercent_C', 9.0);
chk('txtCondFanPercent_S', 9.0);
chk('txtDemandCostPerKW', 0);
// --- Dynamic-default text inputs (compare against <td> default cell) ---
chkVsTd('txtBFn_kw_C');
chkVsTd('txtAux_kw_C');
chkVsTd('txtCond_kw_C');
chkVsTd('txtBFn_kw_S');
chkVsTd('txtAux_kw_S');
chkVsTd('txtCond_kw_S');
chkVsTd('txtVentilationValue');
// --- Checkboxes ---
chkChk('chkEconomizer_C', true);
chkChk('chkEconomizer_S', true);
chkChk('chkChartPW', true);
chkChk('chkDetails', false);
chkChk('chkAdvancedControls', false);
chkChk('chkLockLoadLine', false);
chkChk('chkTrackOHR', true);
// --- Spreadsheet data: log presence only (not the raw data) ---
if (form['txtSpreadsheetData_C'] && form['txtSpreadsheetData_C'].value !== '') diff['hasSpreadsheet_C'] = true;
if (form['txtSpreadsheetData_S'] && form['txtSpreadsheetData_S'].value !== '') diff['hasSpreadsheet_S'] = true;
return diff;
}
// Central dispatcher for all form-control onchange events. Each branch
// mirrors the ASP post-back handler for that control (SubmitTheFormToItself
// or GeneralChangeHandler). Keeps hidden fields, dependent controls, and
// default-column colors in sync.
function onChangeHandler(controlName) {
if (controlName === 'cmbTotalCap') {
var strTotalCap = theSelectedValueInPullDownBox('cmbTotalCap');
var intTotalCap = parseInt(strTotalCap, 10);
document.forms.HECACParameters['txtTotalCap'].value = intTotalCap;
if (document.forms.HECACParameters['chkAdvancedControls'].checked) {
setFanPowerValuesAndDefaults(intTotalCap, 'AlsoFormValues');
}
checkForDefaults('cmbTotalCap');
checkForDefaults('txtEER');
checkForDefaults('txtUnitCost');
recalcVentilation(); // ASP: SubmitTheFormToItself → Establish_SIV
} else if (controlName === 'txtDiscountRate') {
document.getElementById('txtDiscountRate_hidden').value = document.getElementById('txtDiscountRate').value;
} else if (controlName === 'chkChartPW') {
document.getElementById('txtDiscountRate').disabled = !document.getElementById('chkChartPW').checked;
} else if (controlName === 'cmbBuildingType') {
document.forms.HECACParameters['txtBuildingType_hidden'].value = theSelectedValueInPullDownBox(controlName);
checkForDefaults('cmbBuildingType');
// Repopulate BM fields if Advanced is ON
if (document.getElementById('chkAdvancedControls').checked) {
populateBMFieldsFromBuildingType();
}
recalcVentilation(); // ASP: GeneralChangeHandlerANDsubmitToSelf → Establish_SIV
} else if (controlName === 'txtBM_Slope') {
var v = parseFloat(document.getElementById('txtBM_Slope').value);
if (!isFinite(v)) {
window.alert('The Building Model slope must be a number. The slope will be reset to 0.0.');
document.getElementById('txtBM_Slope').value = 0;
}
cFDW(true, 'tdBuildingType_controlscell');
document.getElementById('txtBM_Slope_hidden').value = document.getElementById('txtBM_Slope').value;
document.getElementById('txtBM_postingstate').value = 'Pend';
} else if (controlName === 'txtBM_Intercept') {
var v = parseFloat(document.getElementById('txtBM_Intercept').value);
if (!isFinite(v)) {
window.alert('The Building Model intercept must be a number. The intercept will be reset to 0.0.');
document.getElementById('txtBM_Intercept').value = 0;
}
cFDW(true, 'tdBuildingType_controlscell');
document.getElementById('txtBM_Intercept_hidden').value = document.getElementById('txtBM_Intercept').value;
document.getElementById('txtBM_postingstate').value = 'Pend';
} else if (controlName === 'txtBM_VentSlopeFraction') {
var v = parseFloat(document.getElementById('txtBM_VentSlopeFraction').value);
if (!isFinite(v)) {
window.alert('The Building Model ventilation-slope fraction must be a number.');
document.getElementById('txtBM_VentSlopeFraction').value = 0.50;
} else if (v >= 1) {
window.alert('The Building Model ventilation-slope fraction must be less than 1.');
document.getElementById('txtBM_VentSlopeFraction').value = 0.99;
}
cFDW(true, 'tdBuildingType_controlscell');
document.getElementById('txtBM_VentSlopeFraction_hidden').value = document.getElementById('txtBM_VentSlopeFraction').value;
document.getElementById('txtBM_postingstate').value = 'Pend';
//Fan and other power related input controls (candidate unit)
} else if (controlName === 'txtBFn_kw_C' || controlName === 'txtAux_kw_C') {
if (!problemInPowerValue(controlName)) {
updateEER('C');
setFanPowerValuesAndDefaults(document.forms.HECACParameters['txtTotalCap'].value, 'OnlyDefaults');
}
} else if (controlName === 'txtCond_kw_C') {
if (!problemInPowerValue(controlName)) {
updateEER('C');
document.getElementById('tdCond_kw_C_default').textContent = document.forms.HECACParameters['txtCond_kw_C'].value;
checkForDefaults('txtCond_kw_C');
}
} else if (controlName === 'txtEER') {
updateCond_kw('C');
//Fan and other power related input controls (standard unit)
} else if (controlName === 'txtBFn_kw_S' || controlName === 'txtAux_kw_S') {
if (!problemInPowerValue(controlName)) {
updateEER('S');
setFanPowerValuesAndDefaults(document.forms.HECACParameters['txtTotalCap'].value, 'OnlyDefaults');
}
} else if (controlName === 'txtCond_kw_S') {
if (!problemInPowerValue(controlName)) {
updateEER('S');
document.getElementById('tdCond_kw_S_default').textContent = document.forms.HECACParameters['txtCond_kw_S'].value;
checkForDefaults('txtCond_kw_S');
}
} else if (controlName === 'txtEER_Standard') {
updateCond_kw('S');
// Auto humidity checkbox — toggle IRH dropdown enabled/disabled (ASP does this via SubmitTheFormToItself)
} else if (controlName === 'chkTrackOHR') {
var autoChecked = document.forms.HECACParameters['chkTrackOHR'].checked;
document.getElementById('cmbIRH').disabled = autoChecked;
recalcVentilation();
} else if (controlName === 'cmbIRH') {
// Keep hidden field in sync (ASP reads from cmbIRH or txtIRH_hidden)
document.getElementById('txtIRH_hidden').value = theSelectedValueInPullDownBox('cmbIRH');
recalcVentilation();
} else if (controlName === 'cmbST_Ratio_C' || controlName === 'cmbST_Ratio_S') {
recalcVentilation();
//These next two blocks force the degradation factor to zero when variable speed mode is selected.
} else if (controlName === 'cmbFanControls_C') {
var theSelectedValue = theSelectedValueInPullDownBox('cmbFanControls_C');
if (theSelectedValue.substring(0,1) === 'V') {
//First, save the value in the hidden field.
if (document.getElementById('cmbPLDegrFactor_C').disabled !== true) {
document.forms.HECACParameters['txtPLDegrFactor_C'].value = theSelectedValueInPullDownBox('cmbPLDegrFactor_C');
}
selectValueInPullDownBox('cmbPLDegrFactor_C', 0);
document.getElementById('cmbPLDegrFactor_C').disabled = true;
document.getElementById('txtCondFanPercent_C').disabled = false;
} else {
//Use the hidden value to reset the pull down control
selectValueInPullDownBox('cmbPLDegrFactor_C', document.forms.HECACParameters['txtPLDegrFactor_C'].value);
document.getElementById('cmbPLDegrFactor_C').disabled = false;
document.getElementById('txtCondFanPercent_C').disabled = true;
}
checkForDefaults('cmbFanControls_C');
checkForDefaults('cmbPLDegrFactor_C');
} else if (controlName === 'cmbPLDegrFactor_C') {
// stash away the selected value in the hidden field.
document.forms.HECACParameters['txtPLDegrFactor_C'].value = theSelectedValueInPullDownBox('cmbPLDegrFactor_C');
checkForDefaults(controlName);
} else if (controlName === 'cmbFanControls_S') {
if (theSelectedValueInPullDownBox('cmbFanControls_S').substring(0,1) === 'V') {
//First, save the value in the hidden field.
if (document.getElementById('cmbPLDegrFactor_S').disabled !== true) {
document.forms.HECACParameters['txtPLDegrFactor_S'].value = theSelectedValueInPullDownBox('cmbPLDegrFactor_S');
}
selectValueInPullDownBox('cmbPLDegrFactor_S', 0);
document.getElementById('cmbPLDegrFactor_S').disabled = true;
document.getElementById('txtCondFanPercent_S').disabled = false;
} else {
//Use the hidden value to reset the pull down control
selectValueInPullDownBox('cmbPLDegrFactor_S', document.forms.HECACParameters['txtPLDegrFactor_S'].value);
document.getElementById('cmbPLDegrFactor_S').disabled = false;
document.getElementById('txtCondFanPercent_S').disabled = true;
}
checkForDefaults('cmbFanControls_S');
checkForDefaults('cmbPLDegrFactor_S');
} else if (controlName === 'cmbPLDegrFactor_S') {
// stash away the selected value in the hidden field.
document.forms.HECACParameters['txtPLDegrFactor_S'].value = theSelectedValueInPullDownBox('cmbPLDegrFactor_S');
checkForDefaults(controlName);
} else if (controlName === 'txtCondFanPercent_C') {
document.forms.HECACParameters['txtCondFanPercent_C_hidden'].value = document.forms.HECACParameters['txtCondFanPercent_C'].value;
} else if (controlName === 'txtCondFanPercent_S') {
document.forms.HECACParameters['txtCondFanPercent_S_hidden'].value = document.forms.HECACParameters['txtCondFanPercent_S'].value;
} else if (controlName === 'cmbNstages_C') {
document.forms.HECACParameters['txtNstages_C'].value = theSelectedValueInPullDownBox(controlName);
checkForDefaults(controlName);
} else if (controlName === 'cmbNstages_S') {
document.forms.HECACParameters['txtNstages_S'].value = theSelectedValueInPullDownBox(controlName);
checkForDefaults(controlName);
} else if (controlName === 'cmbSpecific_RTU_C') {
if (theSelectedValueInPullDownBox(controlName) === 'Three Stages') {
//Set candidate stages control to 3.
document.forms.HECACParameters['txtNstages_C'].value = '3';
selectValueInPullDownBox('cmbNstages_C', '3');
checkForDefaults('cmbNstages_C');
//Set fan controls
selectValueInPullDownBox('cmbFanControls_C', 'N-Spd: Always ON');
checkForDefaults('cmbFanControls_C');
//Use the hidden value to reset the pull down control for the degradation factor.
selectValueInPullDownBox('cmbPLDegrFactor_C', document.forms.HECACParameters['txtPLDegrFactor_C'].value);
document.getElementById('cmbPLDegrFactor_C').disabled = false;
document.getElementById('txtCondFanPercent_C').disabled = true;
} else if (theSelectedValueInPullDownBox(controlName) === 'Advanced Controls') {
//Set candidate stages control to 2.
document.forms.HECACParameters['txtNstages_C'].value = '2';
selectValueInPullDownBox('cmbNstages_C', '2');
checkForDefaults('cmbNstages_C');
//Set fan controls
selectValueInPullDownBox('cmbFanControls_C', '1-Spd: Always ON');
checkForDefaults('cmbFanControls_C');
//Use the hidden value to reset the pull down control for the degradation factor.
selectValueInPullDownBox('cmbPLDegrFactor_C', document.forms.HECACParameters['txtPLDegrFactor_C'].value);
document.getElementById('cmbPLDegrFactor_C').disabled = false;
document.getElementById('txtCondFanPercent_C').disabled = true;
} else if (theSelectedValueInPullDownBox(controlName) === 'Variable-Speed Compressor') {
//Set candidate stages control to 1.
document.forms.HECACParameters['txtNstages_C'].value = '1';
selectValueInPullDownBox('cmbNstages_C', '1');
checkForDefaults('cmbNstages_C');
//Set fan controls
selectValueInPullDownBox('cmbFanControls_C', 'V-Spd: Always ON');
checkForDefaults('cmbFanControls_C');
//The following block is used to disable the degradation factor, but first save the current value.
if (document.getElementById('cmbPLDegrFactor_C').disabled !== true) {
document.forms.HECACParameters['txtPLDegrFactor_C'].value = theSelectedValueInPullDownBox('cmbPLDegrFactor_C');
}
selectValueInPullDownBox('cmbPLDegrFactor_C', 0);
document.getElementById('cmbPLDegrFactor_C').disabled = true;
document.getElementById('txtCondFanPercent_C').disabled = false;
} else if (theSelectedValueInPullDownBox(controlName) === 'None') {
//Set candidate stages control to 1.
document.forms.HECACParameters['txtNstages_C'].value = '1';
selectValueInPullDownBox('cmbNstages_C', '1');
checkForDefaults('cmbNstages_C');
//Set fan controls
selectValueInPullDownBox('cmbFanControls_C', '1-Spd: Always ON');
checkForDefaults('cmbFanControls_C');
//Use the hidden value to reset the pull down control for the degradation factor.
selectValueInPullDownBox('cmbPLDegrFactor_C', document.forms.HECACParameters['txtPLDegrFactor_C'].value);
document.getElementById('cmbPLDegrFactor_C').disabled = false;
document.getElementById('txtCondFanPercent_C').disabled = true;
}
checkForDefaults(controlName);
checkForDefaults('cmbPLDegrFactor_C');
// Spreadsheet data textareas — just update default colors; user must check box manually
} else if (controlName === 'txtSpreadsheetData_C') {
// If textarea is cleared, uncheck the box
if (document.getElementById('txtSpreadsheetData_C').value === '') {
document.getElementById('chkSpreadsheetControl_C').checked = false;
}
} else if (controlName === 'txtSpreadsheetData_S') {
if (document.getElementById('txtSpreadsheetData_S').value === '') {
document.getElementById('chkSpreadsheetControl_S').checked = false;
}
// Spreadsheet data checkboxes
} else if (controlName === 'chkSpreadsheetControl_C') {
var chk = document.getElementById('chkSpreadsheetControl_C');
var ta = document.getElementById('txtSpreadsheetData_C');
if (chk.checked) {
if (ta.value === '') {
chk.checked = false;
} else {
var errMsg = validateSpreadsheetData(ta.value, 'Candidate');
var wa = document.getElementById('bpfWarningArea');
if (errMsg) {
if (wa) { wa.innerHTML = errMsg; wa.style.display = ''; }
chk.checked = false;
} else {
if (wa) { wa.innerHTML = ''; wa.style.display = 'none'; }
// Parse and apply spreadsheet data to form fields
var ssFields = parseSpreadsheetFields(ta.value);
applySpreadsheetToForm('C', ssFields);
setTimeout(function() { ta.scrollTop = 0; }, 0);
recalcVentilation();
}
}
}
// Update yellow cautions based on final checkbox state
checkForDefaults('txtSpreadsheetData_C');
} else if (controlName === 'chkSpreadsheetControl_S') {
var chk = document.getElementById('chkSpreadsheetControl_S');
var ta = document.getElementById('txtSpreadsheetData_S');
if (chk.checked) {
if (ta.value === '') {
chk.checked = false;
} else {
var errMsg = validateSpreadsheetData(ta.value, 'Standard');
var wa = document.getElementById('bpfWarningArea');
if (errMsg) {
if (wa) { wa.innerHTML = errMsg; wa.style.display = ''; }
chk.checked = false;
} else {
if (wa) { wa.innerHTML = ''; wa.style.display = 'none'; }
var ssFields = parseSpreadsheetFields(ta.value);
applySpreadsheetToForm('S', ssFields);
setTimeout(function() { ta.scrollTop = 0; }, 0);
recalcVentilation();
}
}
}
// Update yellow cautions based on final checkbox state
checkForDefaults('txtSpreadsheetData_S');
}
}
// When the user checks "Lock Load Line", run the engine with the lock OFF
// to compute the normal load line, then store slope/intercept so subsequent
// submits use the locked values. Matches ASP's LockLoadLine post-back flow.
async function fetchLoadLine() {
var form = document.forms.HECACParameters;
if (form['chkLockLoadLine'] && form['chkLockLoadLine'].checked) {
try {
// Save ventilation values so we can restore them after the engine run.
// The iterative loop changes these, but we don't want fetchLoadLine to
// have side-effects on the form — submitToEngine will do its own refinement.
var savedVentNA = form['txtVentilationValue_NotAdvanced'].value;
var savedVent = form['txtVentilationValue'].value;
var savedSI = form['txtSI_Fraction_NotAdvanced'].value;
var savedSIAdv = form['txtSI_Fraction'] ? form['txtSI_Fraction'].value : '';
// Temporarily uncheck the lock so the engine computes the normal (unlocked) load line
form['chkLockLoadLine'].checked = false;
document.getElementById('txtSlope').value = '';
document.getElementById('txtIntercept').value = '';
// Sync hidden fields before running engine
document.getElementById('txtDiscountRate_hidden').value = document.getElementById('txtDiscountRate').value;
var capSel = document.getElementById('cmbTotalCap');
document.getElementById('txtTotalCap').value = parseInt(capSel.options[capSel.selectedIndex].text, 10);
syncBuildingModelFields();