admin_module 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +2 -0
  4. data/README.md +7 -0
  5. data/admin_module.gemspec +3 -1
  6. data/{bin → exe}/admin_module +0 -0
  7. data/lib/admin_module.rb +9 -0
  8. data/lib/admin_module/command/config.rb +20 -0
  9. data/lib/admin_module/command/gdl.rb +15 -0
  10. data/lib/admin_module/guideline.rb +8 -0
  11. data/lib/admin_module/page_factory.rb +43 -2
  12. data/lib/admin_module/pages.rb +38 -81
  13. data/lib/admin_module/pages/guideline_page.rb +54 -1
  14. data/lib/admin_module/pages/guideline_page_400.rb +87 -0
  15. data/lib/admin_module/pages/guideline_version_page.rb +9 -5
  16. data/lib/admin_module/pages/guidelines_page.rb +40 -34
  17. data/lib/admin_module/pages/guidelines_page_400.rb +65 -0
  18. data/lib/admin_module/pages/guidelines_version_all_page.rb +79 -72
  19. data/lib/admin_module/pages/guidelines_version_all_page_400.rb +122 -0
  20. data/lib/admin_module/pages/login_page.rb +2 -2
  21. data/lib/admin_module/pages/login_page_400.rb +73 -0
  22. data/lib/admin_module/version.rb +1 -1
  23. data/spec/data/config/no_ams_version.admin_module +11 -0
  24. data/spec/data/html/guideline-400.html +2713 -0
  25. data/spec/data/html/guideline-400_files/BindChildren.js +852 -0
  26. data/spec/data/html/guideline-400_files/CVlogo.jpg +0 -0
  27. data/spec/data/html/guideline-400_files/Guideline.js +301 -0
  28. data/spec/data/html/guideline-400_files/OptimalOutcome.png +0 -0
  29. data/spec/data/html/guideline-400_files/WebResource(1).axd +561 -0
  30. data/spec/data/html/guideline-400_files/WebResource.axd +548 -0
  31. data/spec/data/html/guideline-400_files/styles.css +444 -0
  32. data/spec/data/html/guideline-400_files/styles2.css +115 -0
  33. data/spec/data/html/guideline-400_files/tab.css +50 -0
  34. data/spec/data/html/guideline-400_files/tabpane.js +297 -0
  35. data/spec/data/html/guideline.html +1809 -0
  36. data/spec/data/html/guideline_files/BindChildren.js +799 -0
  37. data/spec/data/html/guideline_files/Guideline.js +300 -0
  38. data/spec/data/html/guideline_files/LeftMenu.html +0 -0
  39. data/spec/data/html/guideline_files/MainFrame.html +18 -0
  40. data/spec/data/html/guideline_files/ScriptResource.axd +3725 -0
  41. data/spec/data/html/guideline_files/Stylesheet.css +1545 -0
  42. data/spec/data/html/guideline_files/WebResource(1).axd +0 -0
  43. data/spec/data/html/guideline_files/WebResource(2).axd +566 -0
  44. data/spec/data/html/guideline_files/WebResource(3).axd +219 -0
  45. data/spec/data/html/guideline_files/WebResource.axd +696 -0
  46. data/spec/data/html/guideline_files/framebar.html +0 -0
  47. data/spec/data/html/guideline_files/guideline.html +0 -0
  48. data/spec/data/html/guideline_files/home.png +0 -0
  49. data/spec/data/html/guideline_files/jquery-ui.css +578 -0
  50. data/spec/data/html/guideline_files/jquery.js +7 -0
  51. data/spec/data/html/guideline_files/slidebar.gif +29 -0
  52. data/spec/data/html/guideline_files/tab.css +49 -0
  53. data/spec/data/html/guideline_files/tabpane.js +297 -0
  54. data/spec/data/html/guidelines-400.html +368 -0
  55. data/spec/data/html/guidelines-400_files/CVlogo.jpg +0 -0
  56. data/spec/data/html/guidelines-400_files/EditListSearchHelper.js +141 -0
  57. data/spec/data/html/guidelines-400_files/OptimalOutcome.png +0 -0
  58. data/spec/data/html/guidelines-400_files/WebResource(1).axd +561 -0
  59. data/spec/data/html/guidelines-400_files/WebResource.axd +548 -0
  60. data/spec/data/html/guidelines-400_files/menu.css +29 -0
  61. data/spec/data/html/guidelines-400_files/menu.js +48 -0
  62. data/spec/data/html/guidelines-400_files/shadow.gif +0 -0
  63. data/spec/data/html/guidelines-400_files/styles.css +444 -0
  64. data/spec/data/html/guidelines-400_files/styles2.css +115 -0
  65. data/spec/data/html/guidelines.html +217 -0
  66. data/spec/data/html/guidelines_files/EditListSearchHelper.js +123 -0
  67. data/spec/data/html/guidelines_files/ScriptResource.axd +3725 -0
  68. data/spec/data/html/guidelines_files/Stylesheet.css +1545 -0
  69. data/spec/data/html/guidelines_files/jquery-ui.css +578 -0
  70. data/spec/data/html/login.aspx.html +293 -0
  71. data/spec/data/html/login.aspx_files/ScriptResource.axd +3332 -0
  72. data/spec/data/html/login.aspx_files/Stylesheet.css +1545 -0
  73. data/spec/data/html/login.aspx_files/jquery-ui.css +578 -0
  74. data/spec/data/html/login.aspx_files/jquery.js +7 -0
  75. data/spec/data/html/login400.aspx.html +191 -0
  76. data/spec/data/html/login400.aspx_files/WebResource(1).axd +561 -0
  77. data/spec/data/html/login400.aspx_files/WebResource.axd +548 -0
  78. data/spec/data/html/login400.aspx_files/styles.css +444 -0
  79. data/spec/data/html/version_all_guidelines-400.html +702 -0
  80. data/spec/data/html/version_all_guidelines-400_files/CVlogo.jpg +0 -0
  81. data/spec/data/html/version_all_guidelines-400_files/Calendar.js +521 -0
  82. data/spec/data/html/version_all_guidelines-400_files/OptimalOutcome.png +0 -0
  83. data/spec/data/html/version_all_guidelines-400_files/TwoSelects.js +300 -0
  84. data/spec/data/html/version_all_guidelines-400_files/menu.css +29 -0
  85. data/spec/data/html/version_all_guidelines-400_files/menu.js +48 -0
  86. data/spec/data/html/version_all_guidelines-400_files/shadow.gif +0 -0
  87. data/spec/data/html/version_all_guidelines-400_files/styles(1).css +134 -0
  88. data/spec/data/html/version_all_guidelines-400_files/styles.css +444 -0
  89. data/spec/data/html/version_all_guidelines-400_files/styles2.css +115 -0
  90. data/spec/data/html/version_all_guidelines.html +560 -0
  91. data/spec/data/html/version_all_guidelines_files/Calendar.js +521 -0
  92. data/spec/data/html/version_all_guidelines_files/ScriptResource.axd +3725 -0
  93. data/spec/data/html/version_all_guidelines_files/Stylesheet.css +1545 -0
  94. data/spec/data/html/version_all_guidelines_files/TwoSelects.js +304 -0
  95. data/spec/data/html/version_all_guidelines_files/jquery-ui.css +578 -0
  96. data/spec/lib/admin_module/command/config_spec.rb +27 -0
  97. data/spec/lib/admin_module/command/gdl_spec.rb +31 -0
  98. data/spec/lib/admin_module/configuration_spec.rb +47 -0
  99. data/spec/lib/admin_module/guideline_spec.rb +26 -0
  100. data/spec/lib/admin_module/page_factory_spec.rb +72 -0
  101. data/spec/lib/admin_module/pages/guideline_page_400_spec.rb +51 -0
  102. data/spec/lib/admin_module/pages/guideline_page_spec.rb +50 -0
  103. data/spec/lib/admin_module/pages/guidelines_page_400_spec.rb +92 -0
  104. data/spec/lib/admin_module/pages/guidelines_page_spec.rb +91 -0
  105. data/spec/lib/admin_module/pages/guidelines_version_all_page_400_spec.rb +102 -0
  106. data/spec/lib/admin_module/pages/guidelines_version_all_page_spec.rb +105 -0
  107. data/spec/lib/admin_module/pages/login_page_400_spec.rb +42 -0
  108. data/spec/lib/admin_module/pages/login_page_spec.rb +33 -0
  109. data/spec/support/html_spec.rb +26 -0
  110. data/spec/support/mocks.rb +23 -0
  111. metadata +191 -5
@@ -0,0 +1,799 @@
1
+ /*---------------------------------------------------------
2
+ BindChildren.js
3
+ This script is used to dynamically show/hide
4
+ elements based on the value of other elements.
5
+
6
+ --- Usage ---
7
+ Include this script on the page containing the controls.
8
+ In page onload event, use the following functions:
9
+
10
+ bindToList(parentID, childID, values, [behavior])
11
+ bindToCheck(parentID, childID, checked, [behavior])
12
+ bindToImage(parentID, childID, showSrc, hideSrc, [behavior])
13
+ bindValueGroup(groupName, childID, groupIDs)
14
+ setFocus(controlID)
15
+
16
+ parentID: string containing the ID of the element that
17
+ will be the source of change events
18
+ childID: string containing the ID of the element that
19
+ will be affected by the change events
20
+ values: single value or array of values of the source
21
+ element that will trigger a change event
22
+ behavior: (optional) defines what attribute of the child
23
+ element will be changed. one of the following:
24
+ - 'v': visibility (e.style.visibility = 'visible'/'hidden')
25
+ - 'e': enabled (e.disabled = false / true)
26
+ - 'd': display (e.style.display = 'inline'/'none');
27
+ - 'b': background color
28
+ - 'c': css class
29
+ - 's': style (as in, CSS string)
30
+ - 't': text value
31
+ - 'i': include (applies only to options of selects)
32
+ - 'k': checKed (applies only to checkboxes or radio buttons)
33
+ - 'f': focus
34
+ putting a '!' in front of the element reverses
35
+ behavior, e.g. '!d' will show the child if the value
36
+ is *not* selected. 'd' is default behavior.
37
+ checked: like value, but true or false, no array
38
+ showSrc: the path to the image to display initially
39
+ hideSrc: the path to the image to display when the image
40
+ is clicked. switches with showSrc
41
+
42
+ --- Hints ---
43
+ * No error will be thrown if the parent element is not found.
44
+ This enables a static onload script block even if the
45
+ controls themselves are rendered conditionaly on the server.
46
+ However, an error will occur if the child is missing.
47
+ * To bind multiple controls to a single element, simply call
48
+ the appropriate bind function multiple times.
49
+ * The difference between visible and display is that invisible
50
+ elements still occupy the same space, while un-displayed
51
+ elements will cause surrounding objects to shrink/expand
52
+ * If something is already defined for the target event (like
53
+ onchange or onclick) then the action will only occur once
54
+
55
+ -- Samples ---
56
+ // show span1 only when list1's value = '1';
57
+ bindToList('list1', 'span1', '1');
58
+
59
+ // show span1 only when list1's value = '1' or '3' or '5';
60
+ bindToList('list1', 'span1', Array('1', '3', '5'));
61
+
62
+ // enable tbl1 only when chk1 is checked
63
+ bindToCheck('chk1', 'tbl1', true, '!e');
64
+
65
+ // same as previous example, different approach
66
+ bindToCheck('chk1', 'tbl1', false, 'e');
67
+ ---------------------------------------------------------*/
68
+
69
+ // Code executed every time -------------------------------
70
+
71
+ var boundChildren = new Array();
72
+ var boundGroups = new Array();
73
+
74
+ // functions to extend object functionality
75
+ function array_exists(val) {
76
+ var bFound = false;
77
+ for (var i = 0; i < this.length; i++) {
78
+ if (this[i] == val) {
79
+ bFound = true;
80
+ break;
81
+ }
82
+ }
83
+ return bFound;
84
+ }
85
+
86
+ function array_add(val) {
87
+ this[this.length] = val;
88
+ }
89
+
90
+ Array.prototype.exists = array_exists;
91
+ Array.prototype.add = array_add;
92
+
93
+ function string_exists(val) {
94
+ return (this == val);
95
+ }
96
+
97
+ function string_toNumber() {
98
+ return this.replace(/[^\d\.]/g, '') * 1;
99
+ }
100
+
101
+ String.prototype.exists = string_exists;
102
+ String.prototype.toNumber = string_toNumber;
103
+
104
+
105
+ // functions begin here -----------------------------------
106
+ function changeElement(targetE, value, behavior) {
107
+ /* --------------------------------------------------------
108
+ Changes an attribute of the specified element
109
+ Gets called by the change/click events of bound elements
110
+ If value = true, then show or enable.
111
+ -------------------------------------------------------- */
112
+ var args;
113
+ if (targetE == null) {
114
+ alert('target missing! check setup code');
115
+ return;
116
+ }
117
+ if (behavior == null) behavior = 'd'; // default
118
+ if (behavior.substr(0, 1) == '!') {
119
+ value = !value;
120
+ behavior = behavior.substr(1);
121
+ }
122
+ if (behavior.indexOf('|') > 0) args = behavior.split('|');
123
+
124
+ switch (behavior.substr(0, 1)) {
125
+ case 'v': // visible
126
+ targetE.style.visibility = (value ? 'visible' : 'hidden');
127
+ enableValidators(targetE, value);
128
+ break;
129
+ case 'e': // enabled
130
+ enableElement(targetE, value);
131
+ enableValidators(targetE, value);
132
+ break;
133
+ case 'd': // display
134
+ targetE.style.display = (value ? 'inline' : 'none');
135
+ enableValidators(targetE, value);
136
+ var jlblSal;
137
+ jlblSal = document.getElementById('lblSal')
138
+ if (jlblSal != null) {
139
+ targetE = jlblSal;
140
+ targetE.style.display = (value ? 'inline' : 'none');
141
+ enableValidators(targetE, value);
142
+ }
143
+ var jtxtSal;
144
+ jtxtSal = document.getElementById('txtSal')
145
+ if (jtxtSal != null) {
146
+ targetE = jtxtSal;
147
+ targetE.style.display = (value ? 'inline' : 'none');
148
+ enableValidators(targetE, value);
149
+ }
150
+ break;
151
+ case 'b': // background color
152
+ targetE.style.backgroundColor = (value ? args[1] : args[2]);
153
+ break;
154
+ case 'c': // css class name
155
+ targetE.className = (value ? args[1] : args[2]);
156
+ break;
157
+ case 's': // style
158
+ targetE.style.cssText = (value ? args[1] : args[2]);
159
+ break;
160
+ case 't': // text value
161
+ var t = (value ? args[1] : args[2]);
162
+ if (typeof (t) != 'undefined' && t != 'IGNORE') targetE.value = t;
163
+ break;
164
+ case 'i': // include (for options of selects only)
165
+ moveOption(targetE, args[1], value);
166
+ break;
167
+ case 'k': // checKed (checkboxes and radio buttons only)
168
+ var x = (value ? args[1] : args[2]);
169
+ if (typeof (x) != 'undefined') {
170
+ switch (x.toLowerCase()) {
171
+ case 'on':
172
+ case 'check':
173
+ case 'true':
174
+ case '1':
175
+ targetE.checked = true;
176
+ break;
177
+ case 'off':
178
+ case 'uncheck':
179
+ case 'false':
180
+ case '0':
181
+ targetE.checked = false;
182
+ break;
183
+ }
184
+ }
185
+ break;
186
+ case 'f': // focus, only if true
187
+ if (value == true) targetE.focus();
188
+ break;
189
+ }
190
+ }
191
+
192
+ function enableElement(parentE, value) {
193
+ // disables object and all child nodes of the specified object
194
+ parentE.disabled = !value;
195
+ if (parentE.hasChildNodes()) {
196
+ var inputs = parentE.getElementsByTagName('INPUT');
197
+ for (var i = 0; i < inputs.length; i++) {
198
+ inputs[i].onfocus = (value ? null : inputs[i].blur);
199
+ inputs[i].disabled = !value;
200
+ }
201
+ var selects = parentE.getElementsByTagName('SELECT');
202
+ for (var i = 0; i < selects.length; i++) {
203
+ selects[i].onfocus = (value ? null : selects[i].blur);
204
+ selects[i].disabled = !value;
205
+ }
206
+ }
207
+ }
208
+
209
+ function enableValidators(parentE, value) {
210
+ // enables/disables all validator controls (spans) in the parent control
211
+ if (parentE.tagName == 'SPAN') parentE.enabled = value;
212
+ if (parentE.hasChildNodes()) {
213
+ var spans = parentE.getElementsByTagName('SPAN');
214
+ for (var i = 0; i < spans.length; i++) {
215
+ spans[i].enabled = value;
216
+ }
217
+ }
218
+ }
219
+
220
+ function moveOption(selectE, value, isIncluded) {
221
+ // move an option to/from parent.options and .options2
222
+ var index = null;
223
+
224
+ // find index in current collection
225
+ for (var i = 0; i < selectE.options.length; i++) {
226
+ if (selectE.options[i].value == value) {
227
+ index = i;
228
+ break;
229
+ }
230
+ }
231
+ if (isIncluded) {
232
+ // add to options
233
+ if (index == null && selectE.options2 != null) {
234
+ // find option text in hidden collection
235
+ if (selectE.options2[value] != null) {
236
+ var newOption = new Option(selectE.options2[value], value, false, false);
237
+ selectE.options[selectE.options.length] = newOption;
238
+ }
239
+ }
240
+ } else {
241
+ // remove from options
242
+ if (index != null) {
243
+ if (selectE.options2 == null) selectE.options2 = new Array();
244
+ selectE.options2[value] = selectE.options[index].text;
245
+ selectE.options.remove(index);
246
+ } else {
247
+ // alert('could not find option!');
248
+ }
249
+ }
250
+ }
251
+
252
+ function bindToList(parentID, childID, values, behavior) {
253
+ // bind the visiblity of a child control to a list control
254
+ boundChildren.add(bindToList.arguments);
255
+ parentE = document.getElementById(parentID);
256
+ if (parentE != null) {
257
+ // preserve prior event
258
+ attachEvent(parentE, boundList_OnChange, 'change');
259
+ if (behavior == 'i') parentE.options2 = new Array();
260
+ if (behavior != 't') boundList_OnChange(parentE);
261
+ }
262
+ }
263
+
264
+ function bindToCheck(parentID, childID, checked, behavior) {
265
+ // bind the visiblity of a child control to a checkbox or radio control
266
+ boundChildren.add(bindToCheck.arguments);
267
+ parentE = document.getElementById(parentID);
268
+ if (parentE != null) {
269
+ attachEvent(parentE, boundCheck_OnClick, 'click');
270
+ boundCheck_OnClick(parentE);
271
+ }
272
+ }
273
+
274
+ function bindToImage(parentID, childID, showSrc, hideSrc, behavior) {
275
+ // call this to bind the visiblity of a child control to an image that toggles
276
+ boundChildren.add(bindToImage.arguments);
277
+ parentE = document.getElementById(parentID);
278
+ if (parentE != null) {
279
+ parentE.style.cursor = 'hand';
280
+ attachEvent(parentE, boundImage_OnClick, 'click');
281
+ boundImage_OnClick(parentE);
282
+ }
283
+ }
284
+
285
+ function bindValueGroup(groupName, childID, sourceIDs) {
286
+ // bind the sum of all the values in the group array to the value of a control
287
+ var childE = document.getElementById(childID);
288
+ var sourceEs = new Array();
289
+ for (var i = 0; i < sourceIDs.length; i++) {
290
+ sourceE = document.getElementById(sourceIDs[i]);
291
+ if (sourceE != null) {
292
+ sourceEs.add(sourceE);
293
+ boundChildren.add(Array(sourceIDs[i], groupName));
294
+ attachEvent(sourceE, boundGroup_OnBlur, 'change');
295
+ }
296
+ }
297
+
298
+ boundGroups[groupName] = new Array(childE, sourceEs);
299
+ boundGroup_Refresh(groupName);
300
+ }
301
+
302
+ function boundGroup_OnBlur(srcE) {
303
+ // change event of bound group members; find the group and update it
304
+ var item;
305
+ if (srcE == null) srcE = window.event.srcElement;
306
+ for (var i = 0; i < boundChildren.length; i++) {
307
+ item = boundChildren[i];
308
+ if (item != null) {
309
+ if (srcE.id == item[0]) {
310
+ boundGroup_Refresh(item[1]);
311
+ return;
312
+ }
313
+ }
314
+ }
315
+ }
316
+
317
+ function boundGroup_Refresh(groupName) {
318
+ // update all items in a group
319
+ var group = boundGroups[groupName];
320
+ var childE = group[0];
321
+ var sourceEs = group[1];
322
+ var total = 0, val = 0;
323
+
324
+ for (var i = 0; i < sourceEs.length; i++) {
325
+ val = sourceEs[i].value.replace(/[^\d\.]/g, '') * 1;
326
+ total += val;
327
+ }
328
+ // format to currency. todo: detect if it is available or not...
329
+ var num = new NumberFormat(total);
330
+ num.setCurrency(true);
331
+ childE.innerText = num.toFormatted();
332
+ }
333
+
334
+ function boundList_OnChange(srcE) {
335
+ // change event of bound list objects (select)
336
+ var item;
337
+ if (srcE == null) srcE = window.event.srcElement;
338
+ for (var i = 0; i < boundChildren.length; i++) {
339
+ item = boundChildren[i];
340
+ if (item != null) {
341
+ if (srcE.id == item[0]) {
342
+ childE = document.getElementById(item[1]);
343
+ //childE.style.display = (item[2].exists(srcE.value)) ? '' : 'none';
344
+ if (childE != null) {
345
+ changeElement(childE, item[2].exists(srcE.value), item[3]);
346
+ }
347
+ }
348
+ }
349
+ }
350
+ }
351
+
352
+ function boundCheck_OnClick(srcE) {
353
+ // change event of bound check elements (input type=checkbox)
354
+ var item;
355
+ if (srcE == null) srcE = window.event.srcElement;
356
+ for (var i = 0; i < boundChildren.length; i++) {
357
+ item = boundChildren[i];
358
+ if (item != null) {
359
+ if (srcE.id == item[0]) {
360
+ childE = document.getElementById(item[1]);
361
+ //childE.style.display = (item[2] == srcE.checked) ? '' : 'none';
362
+ if (childE != null) {
363
+ changeElement(childE, item[2] == srcE.checked, item[3]);
364
+ }
365
+ }
366
+ }
367
+ }
368
+ }
369
+
370
+ function boundImage_OnClick(srcE) {
371
+ // change event of bound image elements
372
+ var item, isReverse = false;
373
+ if (srcE == null) srcE = window.event.srcElement;
374
+ for (var i = 0; i < boundChildren.length; i++) {
375
+ item = boundChildren[i];
376
+ if (item != null) {
377
+ if (srcE.id == item[0]) {
378
+ var childE = document.getElementById(item[1]);
379
+ if (item[4] != null) isReverse = (item[4].substr(0, 1) == '!');
380
+
381
+ if (srcE.src == item[2]) {
382
+ srcE.title = 'Click to ' + (isReverse ? 'collapse' : 'expand');
383
+ srcE.src = item[3];
384
+ item[3] = srcE.src;
385
+ changeElement(childE, false, item[4]);
386
+ } else {
387
+ srcE.title = 'Click to ' + (isReverse ? 'expand' : 'collapse');
388
+ srcE.src = item[2];
389
+ item[2] = srcE.src;
390
+ changeElement(childE, true, item[4]);
391
+ }
392
+ }
393
+ }
394
+ }
395
+ }
396
+
397
+ // attach a new change event to an element, return the element
398
+ function attachEvent(element, newEvent, eventType) {
399
+ if (typeof (eventType) != 'string') eventType = 'change'; else eventType = eventType.toLowerCase();
400
+ if (typeof (element) == 'string') element = document.getElementById(element);
401
+ if (element == null) return;
402
+ if (typeof (element.events) != 'object') element.events = new Array();
403
+
404
+ // first time registering
405
+ if (typeof (element.events[eventType]) != 'object') {
406
+ element.events[eventType] = new Array();
407
+ if (typeof (element['on' + eventType]) == 'function') element.events[eventType][0] = element['on' + eventType];
408
+ element['on' + eventType] = doEvent;
409
+ }
410
+ var functions = element.events[eventType];
411
+ functions[functions.length] = newEvent;
412
+
413
+ return element;
414
+ }
415
+
416
+ // this event replaces everything in the 'onclick', 'onchange' etc. events
417
+ function doEvent(element, eventType) {
418
+ if (element == null) element = window.event.srcElement;
419
+ if (eventType == null) eventType = window.event.type;
420
+
421
+ if (typeof (element.events) == 'undefined') return;
422
+ var functions = element.events[eventType.toLowerCase()];
423
+ if (typeof (functions) != 'object') return;
424
+
425
+ for (var i = 0; i < functions.length; i++) {
426
+ var f = functions[i];
427
+ if (typeof (f) == 'function') {
428
+ f(element);
429
+ } else {
430
+ eval(f);
431
+ }
432
+ }
433
+ }
434
+
435
+ function setFocus(controlID) {
436
+ // puts focus on the field specified, if possible
437
+ var e = document.getElementById(controlID);
438
+ if (e != null) {
439
+ if ((!e.disabled) && (e.visible)) e.focus();
440
+ }
441
+ }
442
+
443
+ function toggleSection(span, divID) {
444
+ // old function to use plus and minus to show and hide a div
445
+ var div = document.getElementById(divID);
446
+ if (span.innerText == '-') {
447
+ span.innerText = '+';
448
+ div.style.display = 'none';
449
+ } else {
450
+ span.innerText = '-';
451
+ div.style.display = '';
452
+ }
453
+ }
454
+
455
+ function fieldFormat(source, format, arg1, arg2) {
456
+ /* --------------------------------------------------------
457
+ Formats the contents of a field, usually attached to onblur
458
+ source: the element, usually 'this'
459
+ format: format specifier; n[umeric], t[elephone], c[urrency],
460
+ s[sn]
461
+ arg[x]: format-specific arguments, see below
462
+ ex. <input type="text" onblur="fieldFormat(this, 'n', 1);">
463
+ -------------------------------------------------------- */
464
+ if (source.value.length > 0) {
465
+ if (format == null) format = 'n';
466
+ var type = format.substr(0, 1).toLowerCase();
467
+ switch (type) {
468
+ case 'c': // currency
469
+ var num = new NumberFormat(source.value);
470
+ num.setCurrency(false);
471
+ num.setPlaces(2);
472
+ source.value = num.toFormatted();
473
+ break;
474
+ case 'n': // general number; arg1 = places
475
+ var num = new NumberFormat(source.value);
476
+ num.setCurrency(false);
477
+ num.setPlaces((arg1 == null ? 2 : arg1));
478
+ source.value = num.toFormatted();
479
+ break;
480
+ case 't': // telephone
481
+ var num = source.value.replace(/[^\d]/g, '').substr(0, 10);
482
+ if (num.length > 0) {
483
+ source.value = '(' + num.substr(0, 3) + ') ' + num.substr(3, 3) + '-' + num.substr(6, 4);
484
+ } else {
485
+ source.value = '';
486
+ }
487
+ break;
488
+ case 's': // ssn
489
+ var num = source.value.replace(/[^\d]/g, '').substr(0, 9);
490
+ if (num.length > 0) {
491
+ source.value = num.substr(0, 3) + '-' + num.substr(3, 2) + '-' + num.substr(5, 4);
492
+ } else {
493
+ source.value = '';
494
+ }
495
+ break;
496
+ }
497
+ }
498
+
499
+ if (source.onchange != null) source.onchange();
500
+ }
501
+
502
+ function fieldLimit(source, limit, max, limiter) {
503
+ /* --------------------------------------------------------
504
+ Limits the maxlength of a field based on a character, attach
505
+ to onkeyup.
506
+ source: the element, usually 'this'
507
+ limit: number of characters after limiter to allow
508
+ max: absolute max length
509
+ limiter: character to trigger limit, defaults to '.'
510
+ ex. <input type="text" onkeyup="fieldLimit(this, 3);">
511
+ -------------------------------------------------------- */
512
+ if (limiter == null) limiter = '.';
513
+ if (max == null) max = 999;
514
+ var pos = source.value.indexOf(limiter);
515
+ if (pos > -1 && caretPos(source) > pos) {
516
+ var len = (pos + limit + limiter.length);
517
+ source.maxLength = len;
518
+ if (source.value.length > len) source.value = source.value.substr(0, len);
519
+ } else {
520
+ source.maxLength = max - limit;
521
+ }
522
+ }
523
+
524
+ function caretPos(textEl) {
525
+ // returns the position of the caret within a text box
526
+ var i = textEl.value.length + 1;
527
+ if (textEl.createTextRange) {
528
+ theCaret = document.selection.createRange().duplicate();
529
+ while (theCaret.parentElement() == textEl && theCaret.move("character", 1) == 1) --i;
530
+ return i - 1;
531
+ }
532
+ else return -1;
533
+ }
534
+
535
+ function blurPhone(e) {
536
+ // backwards-compatible
537
+ fieldFormat(e, 'telephone');
538
+ }
539
+
540
+ // mredkj.com
541
+ function NumberFormat(num) {
542
+ this.COMMA = ',';
543
+ this.PERIOD = '.';
544
+ this.DASH = '-';
545
+ this.LEFT_PAREN = '(';
546
+ this.RIGHT_PAREN = ')';
547
+ this.LEFT_OUTSIDE = 0;
548
+ this.LEFT_INSIDE = 1;
549
+ this.RIGHT_INSIDE = 2;
550
+ this.RIGHT_OUTSIDE = 3;
551
+ this.LEFT_DASH = 0;
552
+ this.RIGHT_DASH = 1;
553
+ this.PARENTHESIS = 2;
554
+ this.num;
555
+ this.numOriginal;
556
+ this.hasSeparators = false;
557
+ this.separatorValue;
558
+ this.inputDecimalValue;
559
+ this.decimalValue;
560
+ this.negativeFormat;
561
+ this.negativeRed;
562
+ this.hasCurrency;
563
+ this.currencyPosition;
564
+ this.currencyValue;
565
+ this.places;
566
+ this.setNumber = setNumberNF;
567
+ this.toUnformatted = toUnformattedNF;
568
+ this.setInputDecimal = setInputDecimalNF;
569
+ this.setSeparators = setSeparatorsNF;
570
+ this.setCommas = setCommasNF;
571
+ this.setNegativeFormat = setNegativeFormatNF;
572
+ this.setNegativeRed = setNegativeRedNF;
573
+ this.setCurrency = setCurrencyNF;
574
+ this.setCurrencyPrefix = setCurrencyPrefixNF;
575
+ this.setCurrencyValue = setCurrencyValueNF;
576
+ this.setCurrencyPosition = setCurrencyPositionNF;
577
+ this.setPlaces = setPlacesNF;
578
+ this.toFormatted = toFormattedNF;
579
+ this.toPercentage = toPercentageNF;
580
+ this.getOriginal = getOriginalNF;
581
+ this.getRounded = getRoundedNF;
582
+ this.preserveZeros = preserveZerosNF;
583
+ this.justNumber = justNumberNF;
584
+ this.setInputDecimal(this.PERIOD);
585
+ this.setNumber(num);
586
+ this.setCommas(true);
587
+ this.setNegativeFormat(this.LEFT_DASH);
588
+ this.setNegativeRed(false);
589
+ this.setCurrency(true);
590
+ this.setCurrencyPrefix('$');
591
+ this.setPlaces(2);
592
+ }
593
+ function setInputDecimalNF(val) {
594
+ this.inputDecimalValue = val;
595
+ }
596
+ function setNumberNF(num) {
597
+ this.numOriginal = num;
598
+ this.num = this.justNumber(num);
599
+ }
600
+ function toUnformattedNF() {
601
+ return (this.num);
602
+ }
603
+ function getOriginalNF() {
604
+ return (this.numOriginal);
605
+ }
606
+ function setNegativeFormatNF(format) {
607
+ this.negativeFormat = format;
608
+ }
609
+ function setNegativeRedNF(isRed) {
610
+ this.negativeRed = isRed;
611
+ }
612
+ function setSeparatorsNF(isC, separator, decimal) {
613
+ this.hasSeparators = isC;
614
+ if (separator == null) separator = this.COMMA;
615
+ if (decimal == null) decimal = this.PERIOD;
616
+ if (separator == decimal) {
617
+ this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
618
+ }
619
+ else {
620
+ this.decimalValue = decimal;
621
+ }
622
+ this.separatorValue = separator;
623
+ }
624
+ function setCommasNF(isC) {
625
+ this.setSeparators(isC, this.COMMA, this.PERIOD);
626
+ }
627
+ function setCurrencyNF(isC) {
628
+ this.hasCurrency = isC;
629
+ }
630
+ function setCurrencyValueNF(val) {
631
+ this.currencyValue = val;
632
+ }
633
+ function setCurrencyPrefixNF(cp) {
634
+ this.setCurrencyValue(cp);
635
+ this.setCurrencyPosition(this.LEFT_OUTSIDE);
636
+ }
637
+ function setCurrencyPositionNF(cp) {
638
+ this.currencyPosition = cp
639
+ }
640
+ function setPlacesNF(p) {
641
+ this.places = p;
642
+ }
643
+ function toFormattedNF() {
644
+ var pos;
645
+ var nNum = this.num;
646
+ var nStr;
647
+ var splitString = new Array(2);
648
+ nNum = this.getRounded(nNum);
649
+ nStr = this.preserveZeros(Math.abs(nNum));
650
+ if (nStr.indexOf(this.PERIOD) == -1) {
651
+ splitString[0] = nStr;
652
+ splitString[1] = '';
653
+ }
654
+ else {
655
+ splitString = nStr.split(this.PERIOD, 2);
656
+ }
657
+ if (this.hasSeparators) {
658
+ pos = splitString[0].length;
659
+ while (pos > 0) {
660
+ pos -= 3;
661
+ if (pos <= 0) break;
662
+ splitString[0] = splitString[0].substring(0, pos)
663
+ + this.separatorValue
664
+ + splitString[0].substring(pos, splitString[0].length);
665
+ }
666
+ }
667
+ if (splitString[1].length > 0) {
668
+ nStr = splitString[0] + this.decimalValue + splitString[1];
669
+ }
670
+ else {
671
+ nStr = splitString[0];
672
+ }
673
+ var c0 = '';
674
+ var n0 = '';
675
+ var c1 = '';
676
+ var n1 = '';
677
+ var n2 = '';
678
+ var c2 = '';
679
+ var n3 = '';
680
+ var c3 = '';
681
+ var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
682
+ var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
683
+ if (this.currencyPosition == this.LEFT_OUTSIDE) {
684
+ if (nNum < 0) {
685
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
686
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
687
+ }
688
+ if (this.hasCurrency) c0 = this.currencyValue;
689
+ }
690
+ else if (this.currencyPosition == this.LEFT_INSIDE) {
691
+ if (nNum < 0) {
692
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
693
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
694
+ }
695
+ if (this.hasCurrency) c1 = this.currencyValue;
696
+ }
697
+ else if (this.currencyPosition == this.RIGHT_INSIDE) {
698
+ if (nNum < 0) {
699
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
700
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
701
+ }
702
+ if (this.hasCurrency) c2 = this.currencyValue;
703
+ }
704
+ else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
705
+ if (nNum < 0) {
706
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
707
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
708
+ }
709
+ if (this.hasCurrency) c3 = this.currencyValue;
710
+ }
711
+ nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
712
+ if (this.negativeRed && nNum < 0) {
713
+ nStr = '<font color="red">' + nStr + '</font>';
714
+ }
715
+ return (nStr);
716
+ }
717
+ function toPercentageNF() {
718
+ nNum = this.num * 100;
719
+ nNum = this.getRounded(nNum);
720
+ return nNum + '%';
721
+ }
722
+ function getRoundedNF(val) {
723
+ var factor;
724
+ var i;
725
+ factor = 1;
726
+ for (i = 0; i < this.places; i++)
727
+ { factor *= 10; }
728
+ val *= factor;
729
+ val = Math.round(val);
730
+ val /= factor;
731
+ return (val);
732
+ }
733
+ function preserveZerosNF(val) {
734
+ var i;
735
+ val = val + '';
736
+ if (this.places <= 0) return val;
737
+ var decimalPos = val.indexOf('.');
738
+ if (decimalPos == -1) {
739
+ val += '.';
740
+ for (i = 0; i < this.places; i++) {
741
+ val += '0';
742
+ }
743
+ }
744
+ else {
745
+ var actualDecimals = (val.length - 1) - decimalPos;
746
+ var difference = this.places - actualDecimals;
747
+ for (i = 0; i < difference; i++) {
748
+ val += '0';
749
+ }
750
+ }
751
+ return val;
752
+ }
753
+ function justNumberNF(val) {
754
+ val = (val == null) ? 0 : val;
755
+ var newVal = val + "";
756
+ var isPercentage = false;
757
+ var isFormattedNeg = false;
758
+ if (newVal.indexOf('%') != -1) {
759
+ newVal = newVal.replace(/\%/g, '');
760
+ isPercentage = true;
761
+ }
762
+ if (newVal.indexOf(this.DASH) != -1
763
+ || (newVal.indexOf(this.LEFT_PAREN) != -1 && newVal.indexOf(this.RIGHT_PAREN) != -1)) {
764
+ newVal = newVal.replace(/[\-\(\)]/g, '');
765
+ isFormattedNeg = true;
766
+ }
767
+ if (this.inputDecimalValue != this.PERIOD) {
768
+ newVal = newVal.replace(/\./g, '');
769
+ }
770
+ var itrDecimal;
771
+ var tempVal = '';
772
+ var foundDecimal = false;
773
+ for (itrDecimal = 0; itrDecimal < newVal.length; itrDecimal++) {
774
+ if (newVal.charAt(itrDecimal) == this.inputDecimalValue) {
775
+ if (foundDecimal) {
776
+ }
777
+ else {
778
+ tempVal = tempVal + this.PERIOD;
779
+ foundDecimal = true;
780
+ }
781
+ }
782
+ else {
783
+ tempVal = tempVal + newVal.charAt(itrDecimal);
784
+ }
785
+ }
786
+ newVal = tempVal;
787
+ if (isFormattedNeg) newVal = '-' + newVal;
788
+ if (isNaN(newVal)) {
789
+ newVal = parseFloat(newVal.replace(/[^\d\.\-]/g, ''));
790
+ newVal = (isNaN(newVal) ? 0 : newVal);
791
+ }
792
+ else if (!isFinite(newVal)) {
793
+ newVal = 0;
794
+ }
795
+ if (isPercentage) {
796
+ newVal = newVal / 100;
797
+ }
798
+ return newVal;
799
+ }