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,852 @@
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
+ {
140
+ targetE = jlblSal;
141
+ targetE.style.display = (value ? 'inline' : 'none');
142
+ enableValidators(targetE, value);
143
+ }
144
+ var jtxtSal;
145
+ jtxtSal = document.getElementById('txtSal')
146
+ if (jtxtSal != null)
147
+ {
148
+ targetE = jtxtSal;
149
+ targetE.style.display = (value ? 'inline' : 'none');
150
+ enableValidators(targetE, value);
151
+ }
152
+ break;
153
+ case 'b' : // background color
154
+ targetE.style.backgroundColor = (value ? args[1] : args[2]);
155
+ break;
156
+ case 'c' : // css class name
157
+ targetE.className = (value ? args[1] : args[2]);
158
+ break;
159
+ case 's' : // style
160
+ targetE.style.cssText = (value ? args[1] : args[2]);
161
+ break;
162
+ case 't' : // text value
163
+ var t = (value ? args[1] : args[2]);
164
+ if (typeof(t) != 'undefined' && t != 'IGNORE') targetE.value = t;
165
+ break;
166
+ case 'i': // include (for options of selects only)
167
+ moveOption(targetE, args[1], value);
168
+ break;
169
+ case 'k': // checKed (checkboxes and radio buttons only)
170
+ var x = (value ? args[1] : args[2]);
171
+ if (typeof(x) != 'undefined') {
172
+ switch (x.toLowerCase()) {
173
+ case 'on':
174
+ case 'check':
175
+ case 'true':
176
+ case '1':
177
+ targetE.checked = true;
178
+ break;
179
+ case 'off':
180
+ case 'uncheck':
181
+ case 'false':
182
+ case '0':
183
+ targetE.checked = false;
184
+ break;
185
+ }
186
+ }
187
+ break;
188
+ case 'f': // focus, only if true
189
+ if (value == true) targetE.focus();
190
+ break;
191
+ }
192
+ }
193
+
194
+ function enableElement(parentE, value) {
195
+ // disables object and all child nodes of the specified object
196
+ parentE.disabled = !value;
197
+ if (parentE.hasChildNodes()) {
198
+ var inputs = parentE.getElementsByTagName('INPUT');
199
+ for (var i = 0; i < inputs.length; i++) {
200
+ inputs[i].onfocus = (value ? null : inputs[i].blur);
201
+ inputs[i].disabled = !value;
202
+ }
203
+ var selects = parentE.getElementsByTagName('SELECT');
204
+ for (var i = 0; i < selects.length; i++) {
205
+ selects[i].onfocus = (value ? null : selects[i].blur);
206
+ selects[i].disabled = !value;
207
+ }
208
+ }
209
+ }
210
+
211
+ function enableValidators(parentE, value) {
212
+ // enables/disables all validator controls (spans) in the parent control
213
+ if (parentE.tagName == 'SPAN') parentE.enabled = value;
214
+ if (parentE.hasChildNodes()) {
215
+ var spans = parentE.getElementsByTagName('SPAN');
216
+ for (var i = 0; i < spans.length; i++) {
217
+ spans[i].enabled = value;
218
+ }
219
+ }
220
+ }
221
+
222
+ function moveOption(selectE, value, isIncluded) {
223
+ // move an option to/from parent.options and .options2
224
+ var index = null;
225
+
226
+ // find index in current collection
227
+ for (var i = 0; i < selectE.options.length; i++) {
228
+ if (selectE.options[i].value == value) {
229
+ index = i;
230
+ break;
231
+ }
232
+ }
233
+ if (isIncluded) {
234
+ // add to options
235
+ if (index == null && selectE.options2 != null) {
236
+ // find option text in hidden collection
237
+ if (selectE.options2[value] != null) {
238
+ var newOption = new Option(selectE.options2[value], value, false, false);
239
+ selectE.options[selectE.options.length] = newOption;
240
+ }
241
+ }
242
+ } else {
243
+ // remove from options
244
+ if (index != null) {
245
+ if (selectE.options2 == null) selectE.options2 = new Array();
246
+ selectE.options2[value] = selectE.options[index].text;
247
+ selectE.options.remove(index);
248
+ } else {
249
+ // alert('could not find option!');
250
+ }
251
+ }
252
+ }
253
+
254
+ function bindToList(parentID, childID, values, behavior) {
255
+ // bind the visiblity of a child control to a list control
256
+ boundChildren.add(bindToList.arguments);
257
+ parentE = document.getElementById(parentID);
258
+ if (parentE != null) {
259
+ // preserve prior event
260
+ attachEvent(parentE, boundList_OnChange, 'change');
261
+ if (behavior == 'i') parentE.options2 = new Array();
262
+ if (behavior != 't') boundList_OnChange(parentE);
263
+ }
264
+ }
265
+
266
+ function bindToCheck(parentID, childID, checked, behavior) {
267
+ // bind the visiblity of a child control to a checkbox or radio control
268
+ boundChildren.add(bindToCheck.arguments);
269
+ parentE = document.getElementById(parentID);
270
+ if (parentE != null) {
271
+ attachEvent(parentE, boundCheck_OnClick, 'click');
272
+ boundCheck_OnClick(parentE);
273
+ }
274
+ }
275
+
276
+ function bindToImage(parentID, childID, showSrc, hideSrc, behavior) {
277
+ // call this to bind the visiblity of a child control to an image that toggles
278
+ boundChildren.add(bindToImage.arguments);
279
+ parentE = document.getElementById(parentID);
280
+ if (parentE != null) {
281
+ parentE.style.cursor = 'hand';
282
+ attachEvent(parentE, boundImage_OnClick, 'click');
283
+ boundImage_OnClick(parentE);
284
+ }
285
+ }
286
+
287
+ function bindValueGroup(groupName, childID, sourceIDs) {
288
+ // bind the sum of all the values in the group array to the value of a control
289
+ var childE = document.getElementById(childID);
290
+ var sourceEs = new Array();
291
+ for (var i = 0; i < sourceIDs.length; i++) {
292
+ sourceE = document.getElementById(sourceIDs[i]);
293
+ if (sourceE != null ) {
294
+ sourceEs.add(sourceE);
295
+ boundChildren.add(Array(sourceIDs[i], groupName));
296
+ attachEvent(sourceE, boundGroup_OnBlur, 'change');
297
+ }
298
+ }
299
+
300
+ boundGroups[groupName] = new Array(childE, sourceEs);
301
+ boundGroup_Refresh(groupName);
302
+ }
303
+
304
+ function boundGroup_OnBlur(srcE) {
305
+ // change event of bound group members; find the group and update it
306
+ var item;
307
+ if (srcE == null) srcE = window.event.srcElement;
308
+ for (var i = 0; i < boundChildren.length; i++) {
309
+ item = boundChildren[i];
310
+ if (item != null) {
311
+ if (srcE.id == item[0]) {
312
+ boundGroup_Refresh(item[1]);
313
+ return;
314
+ }
315
+ }
316
+ }
317
+ }
318
+
319
+ function boundGroup_Refresh(groupName) {
320
+ // update all items in a group
321
+ var group = boundGroups[groupName];
322
+ var childE = group[0];
323
+ var sourceEs = group[1];
324
+ var total = 0, val = 0;
325
+
326
+ for (var i = 0; i < sourceEs.length; i++) {
327
+ val = sourceEs[i].value.replace(/[^\d\.]/g, '') * 1;
328
+ total += val;
329
+ }
330
+ // format to currency. todo: detect if it is available or not...
331
+ var num = new NumberFormat(total);
332
+ num.setCurrency(true);
333
+ childE.innerText = num.toFormatted();
334
+ }
335
+
336
+ function boundList_OnChange(srcE) {
337
+ // change event of bound list objects (select)
338
+ var item;
339
+ if (srcE == null) srcE = window.event.srcElement;
340
+ for (var i = 0; i < boundChildren.length; i++) {
341
+ item = boundChildren[i];
342
+ if (item != null) {
343
+ if (srcE.id == item[0]) {
344
+ childE = document.getElementById(item[1]);
345
+ //childE.style.display = (item[2].exists(srcE.value)) ? '' : 'none';
346
+ if (childE != null) {
347
+ changeElement(childE, item[2].exists(srcE.value), item[3]);
348
+ }
349
+ }
350
+ }
351
+ }
352
+ }
353
+
354
+ function boundCheck_OnClick(srcE) {
355
+ // change event of bound check elements (input type=checkbox)
356
+ var item;
357
+ if (srcE == null) srcE = window.event.srcElement;
358
+ for (var i = 0; i < boundChildren.length; i++) {
359
+ item = boundChildren[i];
360
+ if (item != null) {
361
+ if (srcE.id == item[0]) {
362
+ childE = document.getElementById(item[1]);
363
+ //childE.style.display = (item[2] == srcE.checked) ? '' : 'none';
364
+ if (childE != null) {
365
+ changeElement(childE, item[2] == srcE.checked, item[3]);
366
+ }
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ function boundImage_OnClick(srcE) {
373
+ // change event of bound image elements
374
+ var item, isReverse = false;
375
+ if (srcE == null) srcE = window.event.srcElement;
376
+ for (var i = 0; i < boundChildren.length; i++) {
377
+ item = boundChildren[i];
378
+ if (item != null) {
379
+ if (srcE.id == item[0]) {
380
+ var childE = document.getElementById(item[1]);
381
+ if (item[4] != null) isReverse = (item[4].substr(0, 1) == '!');
382
+
383
+ if (srcE.src == item[2]) {
384
+ srcE.title = 'Click to ' + (isReverse ? 'collapse' : 'expand');
385
+ srcE.src = item[3];
386
+ item[3] = srcE.src;
387
+ changeElement(childE, false, item[4]);
388
+ } else {
389
+ srcE.title = 'Click to ' + (isReverse ? 'expand' : 'collapse');
390
+ srcE.src = item[2];
391
+ item[2] = srcE.src;
392
+ changeElement(childE, true, item[4]);
393
+ }
394
+ }
395
+ }
396
+ }
397
+ }
398
+
399
+ // attach a new change event to an element, return the element
400
+ function attachEvent(element, newEvent, eventType) {
401
+ if (typeof(eventType) != 'string') eventType = 'change'; else eventType = eventType.toLowerCase();
402
+ if (typeof(element) == 'string') element = document.getElementById(element);
403
+ if (element == null) return;
404
+ if (typeof(element.events) != 'object') element.events = new Array();
405
+
406
+ // first time registering
407
+ if (typeof(element.events[eventType]) != 'object') {
408
+ element.events[eventType] = new Array();
409
+ if (typeof(element['on' + eventType]) == 'function') element.events[eventType][0] = element['on' + eventType];
410
+ element['on' + eventType] = doEvent;
411
+ }
412
+ var functions = element.events[eventType];
413
+ functions[functions.length] = newEvent;
414
+
415
+ return element;
416
+ }
417
+
418
+ // this event replaces everything in the 'onclick', 'onchange' etc. events
419
+ function doEvent(element, eventType) {
420
+ if (element == null) element = window.event.srcElement;
421
+ if (eventType == null) eventType = window.event.type;
422
+
423
+ if (typeof(element.events) == 'undefined') return;
424
+ var functions = element.events[eventType.toLowerCase()];
425
+ if (typeof(functions) != 'object') return;
426
+
427
+ for (var i = 0; i < functions.length; i++) {
428
+ var f = functions[i];
429
+ if (typeof(f) == 'function') {
430
+ f(element);
431
+ } else {
432
+ eval(f);
433
+ }
434
+ }
435
+ }
436
+
437
+ function setFocus(controlID) {
438
+ // puts focus on the field specified, if possible
439
+ var e = document.getElementById(controlID);
440
+ if (e != null) {
441
+ if ((!e.disabled) && (e.visible)) e.focus();
442
+ }
443
+ }
444
+
445
+ function toggleSection(span, divID) {
446
+ // old function to use plus and minus to show and hide a div
447
+ var div = document.getElementById(divID);
448
+ if (span.innerText == '-') {
449
+ span.innerText = '+';
450
+ div.style.display = 'none';
451
+ } else {
452
+ span.innerText = '-';
453
+ div.style.display = '';
454
+ }
455
+ }
456
+
457
+ function fieldFormat(source, format, arg1, arg2) {
458
+ /* --------------------------------------------------------
459
+ Formats the contents of a field, usually attached to onblur
460
+ source: the element, usually 'this'
461
+ format: format specifier; n[umeric], t[elephone], c[urrency],
462
+ s[sn]
463
+ arg[x]: format-specific arguments, see below
464
+ ex. <input type="text" onblur="fieldFormat(this, 'n', 1);">
465
+ -------------------------------------------------------- */
466
+ if (source.value.length > 0) {
467
+ if (format == null) format = 'n';
468
+ var type = format.substr(0,1).toLowerCase();
469
+ switch(type) {
470
+ case 'c': // currency
471
+ var num = new NumberFormat(source.value);
472
+ num.setCurrency(false);
473
+ num.setPlaces(2);
474
+ source.value = num.toFormatted();
475
+ break;
476
+ case 'n': // general number; arg1 = places
477
+ var num = new NumberFormat(source.value);
478
+ num.setCurrency(false);
479
+ num.setPlaces((arg1 == null ? 2 : arg1));
480
+ source.value = num.toFormatted();
481
+ break;
482
+ case 't': // telephone
483
+ var num = source.value.replace(/[^\d]/g, '').substr(0, 10);
484
+ if (num.length > 0) {
485
+ source.value = '(' + num.substr(0,3) + ') ' + num.substr(3,3) + '-' + num.substr(6,4);
486
+ } else {
487
+ source.value = '';
488
+ }
489
+ break;
490
+ case 's': // ssn
491
+ var num = source.value.replace(/[^\d]/g, '').substr(0, 9);
492
+ if (num.length > 0) {
493
+ source.value = num.substr(0,3) + '-' + num.substr(3,2) + '-' + num.substr(5,4);
494
+ } else {
495
+ source.value = '';
496
+ }
497
+ break;
498
+ }
499
+ }
500
+
501
+ if (source.onchange != null) source.onchange();
502
+ }
503
+
504
+ function fieldLimit(source, limit, max, limiter) {
505
+ /* --------------------------------------------------------
506
+ Limits the maxlength of a field based on a character, attach
507
+ to onkeyup.
508
+ source: the element, usually 'this'
509
+ limit: number of characters after limiter to allow
510
+ max: absolute max length
511
+ limiter: character to trigger limit, defaults to '.'
512
+ ex. <input type="text" onkeyup="fieldLimit(this, 3);">
513
+ -------------------------------------------------------- */
514
+ if (limiter == null) limiter = '.';
515
+ if (max == null) max = 999;
516
+ var pos = source.value.indexOf(limiter);
517
+ if (pos > -1 && caretPos(source) > pos) {
518
+ var len = (pos + limit + limiter.length);
519
+ source.maxLength = len;
520
+ if (source.value.length > len) source.value = source.value.substr(0, len);
521
+ } else {
522
+ source.maxLength = max - limit;
523
+ }
524
+ }
525
+
526
+ function caretPos(textEl) {
527
+ // returns the position of the caret within a text box
528
+ var i=textEl.value.length+1;
529
+ if (textEl.createTextRange) {
530
+ theCaret = document.selection.createRange().duplicate();
531
+ while (theCaret.parentElement()==textEl && theCaret.move("character",1)==1) --i;
532
+ return i-1;
533
+ }
534
+ else return -1;
535
+ }
536
+
537
+ function blurPhone(e) {
538
+ // backwards-compatible
539
+ fieldFormat(e, 'telephone');
540
+ }
541
+
542
+ // mredkj.com
543
+ function NumberFormat(num)
544
+ {
545
+ this.COMMA = ',';
546
+ this.PERIOD = '.';
547
+ this.DASH = '-';
548
+ this.LEFT_PAREN = '(';
549
+ this.RIGHT_PAREN = ')';
550
+ this.LEFT_OUTSIDE = 0;
551
+ this.LEFT_INSIDE = 1;
552
+ this.RIGHT_INSIDE = 2;
553
+ this.RIGHT_OUTSIDE = 3;
554
+ this.LEFT_DASH = 0;
555
+ this.RIGHT_DASH = 1;
556
+ this.PARENTHESIS = 2;
557
+ this.num;
558
+ this.numOriginal;
559
+ this.hasSeparators = false;
560
+ this.separatorValue;
561
+ this.inputDecimalValue;
562
+ this.decimalValue;
563
+ this.negativeFormat;
564
+ this.negativeRed;
565
+ this.hasCurrency;
566
+ this.currencyPosition;
567
+ this.currencyValue;
568
+ this.places;
569
+ this.setNumber = setNumberNF;
570
+ this.toUnformatted = toUnformattedNF;
571
+ this.setInputDecimal = setInputDecimalNF;
572
+ this.setSeparators = setSeparatorsNF;
573
+ this.setCommas = setCommasNF;
574
+ this.setNegativeFormat = setNegativeFormatNF;
575
+ this.setNegativeRed = setNegativeRedNF;
576
+ this.setCurrency = setCurrencyNF;
577
+ this.setCurrencyPrefix = setCurrencyPrefixNF;
578
+ this.setCurrencyValue = setCurrencyValueNF;
579
+ this.setCurrencyPosition = setCurrencyPositionNF;
580
+ this.setPlaces = setPlacesNF;
581
+ this.toFormatted = toFormattedNF;
582
+ this.toPercentage = toPercentageNF;
583
+ this.getOriginal = getOriginalNF;
584
+ this.getRounded = getRoundedNF;
585
+ this.preserveZeros = preserveZerosNF;
586
+ this.justNumber = justNumberNF;
587
+ this.setInputDecimal(this.PERIOD);
588
+ this.setNumber(num);
589
+ this.setCommas(true);
590
+ this.setNegativeFormat(this.LEFT_DASH);
591
+ this.setNegativeRed(false);
592
+ this.setCurrency(true);
593
+ this.setCurrencyPrefix('$');
594
+ this.setPlaces(2);
595
+ }
596
+ function setInputDecimalNF(val)
597
+ {
598
+ this.inputDecimalValue = val;
599
+ }
600
+ function setNumberNF(num)
601
+ {
602
+ this.numOriginal = num;
603
+ this.num = this.justNumber(num);
604
+ }
605
+ function toUnformattedNF()
606
+ {
607
+ return (this.num);
608
+ }
609
+ function getOriginalNF()
610
+ {
611
+ return (this.numOriginal);
612
+ }
613
+ function setNegativeFormatNF(format)
614
+ {
615
+ this.negativeFormat = format;
616
+ }
617
+ function setNegativeRedNF(isRed)
618
+ {
619
+ this.negativeRed = isRed;
620
+ }
621
+ function setSeparatorsNF(isC, separator, decimal)
622
+ {
623
+ this.hasSeparators = isC;
624
+ if (separator == null) separator = this.COMMA;
625
+ if (decimal == null) decimal = this.PERIOD;
626
+ if (separator == decimal)
627
+ {
628
+ this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
629
+ }
630
+ else
631
+ {
632
+ this.decimalValue = decimal;
633
+ }
634
+ this.separatorValue = separator;
635
+ }
636
+ function setCommasNF(isC)
637
+ {
638
+ this.setSeparators(isC, this.COMMA, this.PERIOD);
639
+ }
640
+ function setCurrencyNF(isC)
641
+ {
642
+ this.hasCurrency = isC;
643
+ }
644
+ function setCurrencyValueNF(val)
645
+ {
646
+ this.currencyValue = val;
647
+ }
648
+ function setCurrencyPrefixNF(cp)
649
+ {
650
+ this.setCurrencyValue(cp);
651
+ this.setCurrencyPosition(this.LEFT_OUTSIDE);
652
+ }
653
+ function setCurrencyPositionNF(cp)
654
+ {
655
+ this.currencyPosition = cp
656
+ }
657
+ function setPlacesNF(p)
658
+ {
659
+ this.places = p;
660
+ }
661
+ function toFormattedNF()
662
+ {
663
+ var pos;
664
+ var nNum = this.num;
665
+ var nStr;
666
+ var splitString = new Array(2);
667
+ nNum = this.getRounded(nNum);
668
+ nStr = this.preserveZeros(Math.abs(nNum));
669
+ if (nStr.indexOf(this.PERIOD) == -1)
670
+ {
671
+ splitString[0] = nStr;
672
+ splitString[1] = '';
673
+ }
674
+ else
675
+ {
676
+ splitString = nStr.split(this.PERIOD, 2);
677
+ }
678
+ if (this.hasSeparators)
679
+ {
680
+ pos = splitString[0].length;
681
+ while (pos > 0)
682
+ {
683
+ pos -= 3;
684
+ if (pos <= 0) break;
685
+ splitString[0] = splitString[0].substring(0,pos)
686
+ + this.separatorValue
687
+ + splitString[0].substring(pos, splitString[0].length);
688
+ }
689
+ }
690
+ if (splitString[1].length > 0)
691
+ {
692
+ nStr = splitString[0] + this.decimalValue + splitString[1];
693
+ }
694
+ else
695
+ {
696
+ nStr = splitString[0];
697
+ }
698
+ var c0 = '';
699
+ var n0 = '';
700
+ var c1 = '';
701
+ var n1 = '';
702
+ var n2 = '';
703
+ var c2 = '';
704
+ var n3 = '';
705
+ var c3 = '';
706
+ var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
707
+ var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
708
+ if (this.currencyPosition == this.LEFT_OUTSIDE)
709
+ {
710
+ if (nNum < 0)
711
+ {
712
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
713
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
714
+ }
715
+ if (this.hasCurrency) c0 = this.currencyValue;
716
+ }
717
+ else if (this.currencyPosition == this.LEFT_INSIDE)
718
+ {
719
+ if (nNum < 0)
720
+ {
721
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
722
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
723
+ }
724
+ if (this.hasCurrency) c1 = this.currencyValue;
725
+ }
726
+ else if (this.currencyPosition == this.RIGHT_INSIDE)
727
+ {
728
+ if (nNum < 0)
729
+ {
730
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
731
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
732
+ }
733
+ if (this.hasCurrency) c2 = this.currencyValue;
734
+ }
735
+ else if (this.currencyPosition == this.RIGHT_OUTSIDE)
736
+ {
737
+ if (nNum < 0)
738
+ {
739
+ if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
740
+ if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
741
+ }
742
+ if (this.hasCurrency) c3 = this.currencyValue;
743
+ }
744
+ nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
745
+ if (this.negativeRed && nNum < 0)
746
+ {
747
+ nStr = '<font color="red">' + nStr + '</font>';
748
+ }
749
+ return (nStr);
750
+ }
751
+ function toPercentageNF()
752
+ {
753
+ nNum = this.num * 100;
754
+ nNum = this.getRounded(nNum);
755
+ return nNum + '%';
756
+ }
757
+ function getRoundedNF(val)
758
+ {
759
+ var factor;
760
+ var i;
761
+ factor = 1;
762
+ for (i=0; i<this.places; i++)
763
+ { factor *= 10; }
764
+ val *= factor;
765
+ val = Math.round(val);
766
+ val /= factor;
767
+ return (val);
768
+ }
769
+ function preserveZerosNF(val)
770
+ {
771
+ var i;
772
+ val = val + '';
773
+ if (this.places <= 0) return val;
774
+ var decimalPos = val.indexOf('.');
775
+ if (decimalPos == -1)
776
+ {
777
+ val += '.';
778
+ for (i=0; i<this.places; i++)
779
+ {
780
+ val += '0';
781
+ }
782
+ }
783
+ else
784
+ {
785
+ var actualDecimals = (val.length - 1) - decimalPos;
786
+ var difference = this.places - actualDecimals;
787
+ for (i=0; i<difference; i++)
788
+ {
789
+ val += '0';
790
+ }
791
+ }
792
+ return val;
793
+ }
794
+ function justNumberNF(val)
795
+ {
796
+ val = (val==null) ? 0 : val;
797
+ var newVal = val + "";
798
+ var isPercentage = false;
799
+ var isFormattedNeg = false;
800
+ if (newVal.indexOf('%') != -1)
801
+ {
802
+ newVal = newVal.replace(/\%/g, '');
803
+ isPercentage = true;
804
+ }
805
+ if (newVal.indexOf(this.DASH) != -1
806
+ || (newVal.indexOf(this.LEFT_PAREN) != -1 && newVal.indexOf(this.RIGHT_PAREN) != -1))
807
+ {
808
+ newVal = newVal.replace(/[\-\(\)]/g, '');
809
+ isFormattedNeg = true;
810
+ }
811
+ if (this.inputDecimalValue != this.PERIOD)
812
+ {
813
+ newVal = newVal.replace(/\./g, '');
814
+ }
815
+ var itrDecimal;
816
+ var tempVal = '';
817
+ var foundDecimal = false;
818
+ for (itrDecimal=0; itrDecimal<newVal.length; itrDecimal++)
819
+ {
820
+ if (newVal.charAt(itrDecimal) == this.inputDecimalValue)
821
+ {
822
+ if (foundDecimal)
823
+ {
824
+ }
825
+ else
826
+ {
827
+ tempVal = tempVal + this.PERIOD;
828
+ foundDecimal = true;
829
+ }
830
+ }
831
+ else
832
+ {
833
+ tempVal = tempVal + newVal.charAt(itrDecimal);
834
+ }
835
+ }
836
+ newVal = tempVal;
837
+ if (isFormattedNeg) newVal = '-' + newVal;
838
+ if (isNaN(newVal))
839
+ {
840
+ newVal = parseFloat(newVal.replace(/[^\d\.\-]/g, ''));
841
+ newVal = (isNaN(newVal) ? 0 : newVal);
842
+ }
843
+ else if (!isFinite(newVal))
844
+ {
845
+ newVal = 0;
846
+ }
847
+ if (isPercentage)
848
+ {
849
+ newVal = newVal / 100;
850
+ }
851
+ return newVal;
852
+ }