-
Notifications
You must be signed in to change notification settings - Fork 0
/
Javascript Natural Gas Units
127 lines (99 loc) · 2.84 KB
/
Javascript Natural Gas Units
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
<h2>
Natural Gas Unit Conversion Tool
</h2>
<script language="JAVASCRIPT">
<!-- hide this from old browsers
function clearForm(form){
form.dTh.value ="";
form.BCf.value ="";
form.MCf.value ="";
form.MMBtu.value ="";
form.Nymex.value ="";
}
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function evalForm(form) {
var dTh = parseFloat(form.dTh.value);
var BCf = parseFloat(form.BCf.value);
var MCf = parseFloat(form.MCf.value);
var MMBtu = parseFloat(form.MMBtu.value);
var Nymex = parseFloat(form.Nymex.value);
if (isNaN(dTh)) dbool=0; else dbool=1;
if (isNaN(BCf)) bbool=0; else bbool=1;
if (isNaN(MCf)) cbool=0; else cbool=1;
if (isNaN(MMBtu)) mbool=0; else mbool=1;
if (isNaN(Nymex)) nbool=0; else nbool=1;
allVals=dbool+bbool+cbool+mbool+nbool;
if (allVals!=1){
alert("\nPlease enter one value\n");
clearForm(form);
return false;
}
if (mbool) dTh=MMBtu;
if (bbool) dTh=BCf*1000000;
if (cbool) dTh=MCf;
if (nbool) dTh=Nymex*10000;
form.dTh.value=dTh;
return true;
}
function computeForm(form) {
if (evalForm(form)) {
MMBtuValue=form.dTh.value;
BCfValue=form.dTh.value/1000000;
MCfValue=form.dTh.value;
form.dTh.value=addCommas(form.dTh.value);
form.BCf.value=addCommas(BCfValue);
form.MCf.value=addCommas(MCfValue);
form.MMBtu.value=addCommas(MMBtuValue);
Contracts=addCommas(MMBtuValue/10000);
form.Nymex.value=addCommas(Contracts);
}
form.dTh.value = form.dTh.value;
return;
}
// -- done hiding from old browsers -->
</script>
<center>
<hr size="10"/>
<a name="Calc">
Enter a number in one of the boxes<br/>
in the form below and press the "Convert" button<br/>
<form>
<table border="1">
<tr>
<td><div align="CENTER">dTh-DekaTherms</div></td>
<td><div align="CENTER">BCf-Billion Cubic Feet*</div></td>
<td><div align="CENTER">MCf-Thousand Cubic Feet*</div></td>
<td><div align="CENTER">MMBtu-Million Btu</div></td>
<td><div align="CENTER">NYMEX Contracts</div></td>
</tr>
<tr>
<td><input name="dTh" type="TEXT"/></td>
<td><input name="BCf" type="TEXT"/></td>
<td><input name="MCf" type="TEXT"/></td>
<td><input name="MMBtu" type="TEXT"/></td>
<td><input name="Nymex" type="TEXT"/></td>
</tr></table>
<p>
<input value="Convert" onclick="computeForm(this.form)" type="button"/>
<input value="Reset" onclick="clearForm(this.form)" type="button"/>
</p></form>
</a>
<hr/>
</center>
*BCf and MCf volume measurements vary with temperature and pressure (i.e. location
and time of the year).
<br/>The conversion of 1BCf=1,000,000 MMBtu is accepted by the NYMEX Conversion Table.
<p>
<hr size="10"/>
</p>