r8881@llin: dpavlin | 2005-11-14 21:11:41 +0100
[webpac2] / web / iwf / iwfcore.js
1 // =========================================================================\r
2 /// IWF - Interactive Website Framework.  Javascript library for creating\r
3 /// responsive thin client interfaces.\r
4 ///\r
5 /// Copyright (C) 2005 Brock Weaver brockweaver@users.sourceforge.net\r
6 ///\r
7 ///     This library is free software; you can redistribute it and/or modify\r
8 /// it under the terms of the GNU Lesser General Public License as published\r
9 /// by the Free Software Foundation; either version 2.1 of the License, or\r
10 /// (at your option) any later version.\r
11 ///\r
12 ///     This library is distributed in the hope that it will be useful, but\r
13 /// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
14 /// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public\r
15 /// License for more details.\r
16 ///\r
17 ///    You should have received a copy of the GNU Lesser General Public License\r
18 /// along with this library; if not, write to the Free Software Foundation,\r
19 /// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
20 ///\r
21 /// Brock Weaver\r
22 /// brockweaver@users.sourceforge.net\r
23 /// 1605 NW Maple Pl\r
24 /// Ankeny, IA 50021\r
25 ///\r
26 //! http://iwf.sourceforge.net/\r
27 // =========================================================================\r
28 //! NOTE: To minimize file size, strip all fluffy comments (except the LGPL, of course!)\r
29 //! using the following regex (global flag and multiline on):\r
30 //!            ^\t*//([^/!].*|$)\r
31 //\r
32 // This reduces file size by about 30%, give or take.\r
33 //\r
34 //!  To rip out only logging statements (commented or uncommented):\r
35 //!            ^/{0,2}iwfLog.*\r
36 // =========================================================================\r
37 \r
38 // --------------------------------------------------------------------------\r
39 //! iwfcore.js\r
40 //\r
41 // Core functions\r
42 //\r
43 //! Dependencies:\r
44 //! (none)\r
45 //\r
46 //! Brock Weaver - brockweaver@users.sourceforge.net\r
47 //! v 0.2 - 2005-11-14\r
48 //! iwfcore bug patch\r
49 //! --------------------------------------------------------------------------\r
50 //! - fixed iwfAttribute to return most current value instead of initial value\r
51 //!\r
52 //! v 0.1 - 2005-06-05\r
53 //! Initial release.\r
54 //! --------------------------------------------------------------------------\r
55 \r
56 // -----------------------------------\r
57 // Begin: Configurable variables\r
58 // -----------------------------------\r
59 \r
60 // set to true to enable logging.  Logging simply means certain values are appended to a string. nothing is written out or communicated over the wire anywhere.\r
61 var _iwfLoggingEnabled = true;\r
62 \r
63 \r
64 // -----------------------------------\r
65 // End: Configurable variables\r
66 // -----------------------------------\r
67 \r
68 \r
69 // -----------------------------------\r
70 // Begin: Element Utility Functions\r
71 // -----------------------------------\r
72 \r
73 function iwfGetById(id){\r
74         var el = null;\r
75         if (iwfIsString(id) || iwfIsNumber(id)) el = document.getElementById(id);\r
76         else if (typeof(id) == 'object') el = id;\r
77         return el;\r
78 }\r
79 \r
80 function iwfGetForm(id){\r
81         var frm = iwfGetById(id);\r
82         if (!frm){\r
83                 // or by forms collection...\r
84                 frm = document.forms ? document.forms[frm] : null;\r
85                 if (!frm){\r
86                         // or by tag elements...\r
87                         var allforms = iwfGetByTagName('form');\r
88                         for(var i=0;i<allforms.length;i++){\r
89                                 if (iwfAttribute(allforms[i], 'name') == id){\r
90                                         frm = allforms[i];\r
91                                         break;\r
92                                 }\r
93                         }\r
94                 }\r
95         }\r
96         return frm;\r
97 }\r
98 \r
99 function iwfGetByNameWithinForm(form, nm){\r
100         var frm = iwfGetForm(form);\r
101         if (!frm){\r
102                 iwfLog("IWF Core Error: Could not locate form by id, document.forms, or document[] named '" + form + "'", true);\r
103                 return null;\r
104         } else {\r
105                 // find element within this form with given id.\r
106                 var el = null;\r
107                 if (iwfIsString(nm) || iwfIsNumber(nm)) {\r
108                         for(var i=0;i<frm.elements.length;i++){\r
109                                 if (frm.elements[i].name == nm || frm.elements[i].id == nm){\r
110                                         el = frm.elements[i];\r
111                                         break;\r
112                                 }\r
113                         }\r
114                 } else {\r
115                         el = id;\r
116                 }\r
117 //iwfLog('iwfGetByNameWithinForm returning:\n\n' + iwfElementToString(el), true);\r
118                 return el;\r
119         }\r
120 }\r
121 \r
122 function iwfGetOrCreateByNameWithinForm(form, nm, tagNameOrHtml, typeAtt){\r
123         var elFrm = iwfGetForm(form);\r
124 \r
125         if (!elFrm){\r
126                 iwfLog("IWF Core Error: <form> with name or id of '" + form + "' could not be located.", true);\r
127                 return;\r
128         }\r
129 \r
130         var el = iwfGetByNameWithinForm(form, nm);\r
131         if (!el){\r
132                 // element does not exist. create it.\r
133                 el = document.createElement(tagNameOrHtml);\r
134                 iwfAttribute(el, 'name', nm);\r
135 \r
136                 if (typeAtt){\r
137                         iwfAttribute(el, 'type', typeAtt);\r
138                 }\r
139 \r
140                 elFrm.appendChild(el);\r
141         }\r
142 \r
143         return el;\r
144 }\r
145 \r
146 function iwfRemoveChild(parentId, id){\r
147         var elParent = iwfGetById(parentId);\r
148         if (elParent){\r
149                 var elChild = iwfGetById(id);\r
150                 if (elChild){\r
151                         elParent.removeChild(elChild);\r
152                 }\r
153         }\r
154         return elParent;\r
155 }\r
156 \r
157 function iwfGetOrCreateById(id, tagNameOrHtml, parentNodeId){\r
158         var el = iwfGetById(id);\r
159         if (!el){\r
160                 // element does not exist. create it.\r
161                 el = document.createElement(tagNameOrHtml);\r
162                 iwfAttribute(el, 'id', id);\r
163                 iwfAttribute(el, 'name', id);\r
164 \r
165                 if (parentNodeId){\r
166                         var elParent = iwfGetById(parentNodeId);\r
167                         if (elParent){\r
168                                 iwfAddChild(elParent, el);\r
169                         } else if (parentNodeId.toLowerCase() == 'body'){\r
170                                 iwfAddChild(document.body, el);\r
171                         }\r
172                 }\r
173 \r
174 \r
175         }\r
176         return el;\r
177 }\r
178 \r
179 function iwfAddChild(parentNodeId, childNodeId, atFront){\r
180 \r
181                 var elChild = iwfGetById(childNodeId);\r
182                 if (!elChild) return null;\r
183 \r
184                 // get the element who is to be the parent\r
185                 var elParent = iwfGetById(parentNodeId);\r
186 \r
187                 // parent not found, try by tagName\r
188                 if (!elParent) {\r
189                         var nodes = iwfGetByTagName(parentNodeId);\r
190                         if (nodes && nodes.length > 0){\r
191                                 // always use the first element with that tag name as the parent (think 'body')\r
192                                 parent = nodes[0];\r
193                         } else {\r
194                                 // couldn't find by id or tag name.  bomb out.\r
195                                 return null;\r
196                         }\r
197                 }\r
198 \r
199 \r
200 \r
201                 if (!atFront || !elParent.hasChildNodes()){\r
202                         // append as last child of elParent\r
203                         elParent.appendChild(elChild);\r
204                 } else {\r
205                         // append as first child of elParent\r
206                         elParent.insertBefore(elChild, elParent.childNodes[0]);\r
207                 }\r
208 \r
209                 return elParent;\r
210 }\r
211 \r
212 function iwfRemoveNode(id){\r
213         var el = iwfGetById(id);\r
214         if (!el) return false;\r
215         document.removeNode(el);\r
216         return true;\r
217 }\r
218 \r
219 function iwfElementToString(id){\r
220         var el = iwfGetById(id);\r
221         if (!el) return 'element ' + id + ' does not exist.';\r
222 \r
223         var s = '<' + el.tagName + ' ';\r
224         if (el.attributes){\r
225                 for(var i=0;i<el.attributes.length;i++){\r
226                         var att = el.attributes[i];\r
227                         s += ' ' + att.nodeName + '="' + att.nodeValue + '" ';\r
228                 }\r
229         }\r
230         if (el.innerHTML == ''){\r
231                 s += ' />';\r
232         } else {\r
233                 s += '>' + el.innerHTML + '</' + el.tagName + '>';\r
234         }\r
235 \r
236         return s;\r
237 }\r
238 \r
239 function iwfGetByTagName(tagName, root) {\r
240         var nodes = new Array();\r
241         tagName = tagName || '*';\r
242         root = root || document;\r
243         if (root.all){\r
244                 if (tagName == '*'){\r
245                         nodes = root.all;\r
246                 } else {\r
247                         nodes = root.all.tags(tagName);\r
248                 }\r
249         } else if (root.getElementsByTagName) {\r
250                 nodes = root.getElementsByTagName(tagName);\r
251         }\r
252         return nodes;\r
253 }\r
254 \r
255 function iwfGetByAttribute(tagName, attName, regex, callback) {\r
256         var a, list, found = new Array();\r
257         var reg = new RegExp(regex, 'i');\r
258         list = iwfGetByTagName(tagName);\r
259         for(var i=0;i<list.length;++i) {\r
260                 a = list[i].getAttribute(attName);\r
261                 if (!a) {a = list[i][attName];}\r
262                 if (typeof(a)=='string' && a.search(regex) != -1) {\r
263                         found[found.length] = list[i];\r
264                         if (callback) callback(list[i]);\r
265                 }\r
266         }\r
267         return found;\r
268 }\r
269 \r
270 function iwfAttribute(id, attName, newval){\r
271         var el = iwfGetById(id);\r
272         if (!el) return;\r
273 \r
274         var val = null;\r
275         if (iwfExists(newval)){\r
276                 if (newval == null){\r
277                         // remove it, don't set it to null.\r
278                         iwfRemoveAttribute(el, attName);\r
279                 } else {\r
280                         el.setAttribute(attName, newval);\r
281                 }\r
282         }\r
283         // 2005-11-14 Brock Weaver\r
284         // added check for attribute on el before trying getAttribute method\r
285         // (Thanks J.P. Jarolim!)\r
286         if (el[attName]){\r
287                 val = el[attName];\r
288         } else if (el.getAttribute) {\r
289                 val = el.getAttribute(attName);\r
290         }\r
291         return val;\r
292 }\r
293 \r
294 function iwfRemoveAttribute(id, attName){\r
295         var el = iwfGetById(id);\r
296         if (el){\r
297                 el.removeAttribute(attName);\r
298         }\r
299         return el;\r
300 }\r
301 \r
302 function iwfGetParent(id, useOffsetParent){\r
303         var el = iwfGetById(id);\r
304         if (!el) return null;\r
305         var cur = null;\r
306         if (useOffsetParent && iwfExists(el.offsetParent)) { cur = el.offsetParent;\r
307         } else if (iwfExists(el.parentNode)) { cur = el.parentNode;\r
308         } else if (iwfExists(el.parentElement)) { cur = el.parentElement; }\r
309         return cur;\r
310 }\r
311 \r
312 // -----------------------------------\r
313 // End: Element Utility Functions\r
314 // -----------------------------------\r
315 \r
316 \r
317 // -----------------------------------\r
318 // Begin: Encoding Utility Functions\r
319 // -----------------------------------\r
320 \r
321 function iwfXmlEncode(s){\r
322         if (!s){\r
323                 return '';\r
324         }\r
325         var ret = s.replace(/&/gi, '&amp;').replace(/>/gi,'&gt;').replace(/</gi, '&lt;').replace(/'/gi, '&apos;').replace(/"/gi, '&quot;');\r
326 //alert('after xmlencoding: \n\n\n' + ret);\r
327         return ret;\r
328 }\r
329 \r
330 function iwfXmlDecode(s){\r
331         if (!s){\r
332                 return '';\r
333         }\r
334         var ret = s.replace(/&gt;/gi, '>').replace(/&lt;/gi,'<').replace(/&apos;/gi, '\'').replace(/&quot;/gi, '"').replace(/&amp;/gi, '&');\r
335 //alert('after xmldecoding: \n\n\n' + ret);\r
336         return ret;\r
337 }\r
338 \r
339 function iwfHtmlEncode(s){\r
340         if (!s){\r
341                 return '';\r
342         }\r
343         var ret = s.replace(/&/gi, '&amp;').replace(/>/gi,'&gt;').replace(/</gi, '&lt;').replace(/'/gi, '&apos;').replace(/"/gi, '&quot;');\r
344 //alert('after xmlencoding: \n\n\n' + ret);\r
345         return ret;\r
346 }\r
347 \r
348 function iwfHtmlDecode(s){\r
349         if (!s){\r
350                 return '';\r
351         }\r
352         var ret = s.replace(/&gt;/gi, '>').replace(/&lt;/gi,'<').replace(/&apos;/gi, '\'').replace(/&quot;/gi, '"').replace(/&amp;/gi, '&');\r
353 //alert('after xmldecoding: \n\n\n' + ret);\r
354         return ret;\r
355 }\r
356 // -----------------------------------\r
357 // End: Encoding Utility Functions\r
358 // -----------------------------------\r
359 \r
360 \r
361 // -----------------------------------\r
362 // Begin: Conversion / Formatting Utility Functions\r
363 // -----------------------------------\r
364 \r
365 function iwfExists(){\r
366         for(var i=0;i<arguments.length;i++){\r
367                 if(typeof(arguments[i])=='undefined') return false;\r
368         }\r
369         return true;\r
370 }\r
371 \r
372 function iwfIsString(s){\r
373         return typeof(s) == 'string';\r
374 }\r
375 \r
376 function iwfIsNumber(n){\r
377         return typeof(n) == 'number';\r
378 }\r
379 \r
380 function iwfIsBoolean(b){\r
381         return typeof(b) == 'boolean';\r
382 }\r
383 \r
384 function iwfIsDate(val){\r
385         var dt = iwfDateFormat(val);\r
386         if(!dt){\r
387                 return false;\r
388         } else {\r
389                 // determine if the month/day makes sense.\r
390                 var mo = iwfToInt(dt.substring(0,2));\r
391                 var dy = iwfToInt(dt.substring(3,2));\r
392                 var yr = iwfToInt(dt.substring(6,4));\r
393                 var maxdy = 28;\r
394                 switch(mo){\r
395                         case 4:\r
396                         case 6:\r
397                         case 9:\r
398                         case 11:\r
399                                 maxdy = 30;\r
400                                 break;\r
401                         case 2:\r
402                                 // check leap year\r
403                                 if (yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0)){\r
404                                         maxdy = 29;\r
405                                 }\r
406                                 break;\r
407                         default:\r
408                                 // 1, 3, 5, 7, 8, 10, 12\r
409                                 maxdy = 31;\r
410                                 break;\r
411                 }\r
412                 return dy > 0 && dy <= maxdy;\r
413         }\r
414 }\r
415 \r
416 function iwfDateFormat(val){\r
417         var delim = '/';\r
418         if (val.indexOf(delim) == -1){\r
419                 delim = '-';\r
420         }\r
421 \r
422         var today = new Date();\r
423         var mo = '00' + (today.getMonth() + 1);\r
424         var dy = '00' + (today.getDate());\r
425         var yr = today.getFullYear();\r
426         var arr = val.split(delim);\r
427         switch(arr.length){\r
428                 case 2:\r
429                         //! possibles:  9/2, 9/2004, 09/06,\r
430                         //! assume first is always month\r
431                         mo = '00' + arr[0];\r
432                         if (arr[1].length == 4){\r
433                                 //! assume second is year.\r
434                                 yr = arr[1];\r
435                         } else {\r
436                                 //! assume second is date.\r
437                                 dy = '00' + arr[1];\r
438                         }\r
439                         break;\r
440                 case 3:\r
441                         //! possibles: 9/2/1, 9/02/04, 09/02/2004, 9/2/2004\r
442                         mo = '00' + arr[0];\r
443                         dy = '00' + arr[1];\r
444                         switch(arr[2].length){\r
445                                 case 1:\r
446                                         yr = '200' + arr[2];\r
447                                         break;\r
448                                 case 2:\r
449                                         if (arr[2] < 50){\r
450                                                 yr = '20' + arr[2];\r
451                                         } else {\r
452                                                 yr = '19' + arr[2];\r
453                                         }\r
454                                         break;\r
455                                 case 3:\r
456                                         //! 3 digits... assume 2000 I guess\r
457                                         yr = '2' + arr[2];\r
458                                         break;\r
459                                 case 4:\r
460                                         yr = arr[2];\r
461                                         break;\r
462                                 default:\r
463                                         break;\r
464                         }\r
465                         break;\r
466                 default:\r
467                         // invalid date.\r
468                         return null;\r
469                         break;\r
470         }\r
471         mo = mo.substring(mo.length - 2);\r
472         dy = dy.substring(dy.length - 2);\r
473         return mo + '/' + dy + '/' + yr;\r
474 \r
475 }\r
476 \r
477 function iwfToInt(val, stripFormatting){\r
478         var s = iwfIntFormat(val, stripFormatting);\r
479         return parseInt(s, 10);\r
480 }\r
481 \r
482 function iwfToFloat(val, dp, stripFormatting){\r
483         var s = iwfFloatFormat(val, dp, stripFormatting);\r
484         return parseFloat(s);\r
485 }\r
486 \r
487 function iwfIntFormat(val, stripFormatting){\r
488         return iwfFloatFormat(val, -1, stripFormatting);\r
489 }\r
490 \r
491 function iwfFloatFormat(val, dp, stripFormatting){\r
492         if (stripFormatting && iwfIsString(val)){\r
493                 val = val.replace(/[^0-9\.]/gi,'');\r
494         }\r
495         if (isNaN(val)) {\r
496                 val = 0.0;\r
497         }\r
498 \r
499         var s = '' + val;\r
500         var pos = s.indexOf('.');\r
501         if (pos == -1) {\r
502                 s += '.';\r
503                 pos += s.length;\r
504         }\r
505         s += '0000000000000000000';\r
506         s = s.substr(0,pos+dp+1);\r
507         return s;\r
508 }\r
509 \r
510 // -----------------------------------\r
511 // End: Conversion / Formatting Utility Functions\r
512 // -----------------------------------\r
513 \r
514 // -----------------------------------\r
515 // Begin: Form Submittal Utility Functions\r
516 // -----------------------------------\r
517 function iwfDoAction(act, frm, id, targetElement){\r
518         // validate the form first\r
519         if (window.iwfOnFormValidate){\r
520                 if (!iwfOnFormValidate(act)){\r
521                         return;\r
522                 }\r
523         }\r
524 \r
525         var frmId = frm;\r
526         // try by id first...\r
527         frm = iwfGetForm(frmId);\r
528 \r
529         if (!frm){\r
530                 iwfLog('IWF Core Error: Could not locate form with id or name of ' + frmId, true);\r
531                 return;\r
532         }\r
533 \r
534         // get or create the iwfId\r
535         var elId = iwfGetOrCreateById('iwfId', 'input');\r
536 \r
537         if (!elId){\r
538                 iwfLog('IWF Core Error: Could not create iwfId element!', true);\r
539                 return;\r
540         } else {\r
541                 iwfAttribute(elId, 'value', id);\r
542                 iwfRemoveAttribute(elId, 'disabled');\r
543 \r
544                 if (!iwfGetParent(elId)){\r
545                         // our element has not been added to the document yet.\r
546                         iwfAttribute(elId, 'type', 'hidden');\r
547                         if (!iwfAddChild(frm, elId)){\r
548                                 iwfLog('IWF Core Error: Created iwfId element, but could not append to form ' + frm.outerHTML, true);\r
549                                 return;\r
550                         }\r
551                 }\r
552         }\r
553 \r
554 \r
555         // get or create the iwfMode\r
556         var elMode = iwfGetOrCreateById('iwfMode', 'input');\r
557         if (!elMode){\r
558                 iwfLog('IWF Core Error: Could not create iwfMode element!', true);\r
559                 return;\r
560         } else {\r
561                 iwfAttribute(elMode, 'value', act);\r
562                 iwfRemoveAttribute(elMode, 'disabled');\r
563                 if (!iwfGetParent(elMode)){\r
564                         // our element has not been added to the document yet.\r
565                         iwfAttribute(elMode, 'type', 'hidden');\r
566                         if (!iwfAddChild(frm, elMode)){\r
567                                 iwfLog('IWF Core Error: Created iwfMode element, but could not append to form ' + frm.outerHTML, true);\r
568                                 return;\r
569                         }\r
570                 }\r
571         }\r
572 \r
573         // make our request\r
574         var elRealTarget = iwfGetById(targetElement);\r
575         if (elRealTarget){\r
576                 // use ajax because they specified a particular element to shove the results into.\r
577 \r
578                 // get or create the iwfTarget\r
579                 var elTarget = iwfGetOrCreateById('iwfTarget', 'input');\r
580                 if (!elTarget){\r
581                         iwfLog('IWF Core Error: Could not create iwfTarget element under form ' + frm.outerHTML, true);\r
582                         return;\r
583                 } else {\r
584                         iwfAttribute(elTarget, 'value', iwfAttribute(elRealTarget, 'id'));\r
585                         iwfRemoveAttribute(elTarget, 'disabled');\r
586                         if (!iwfGetParent(elTarget)){\r
587                                 // our element has not been added to the document yet.\r
588                                 iwfAttribute(elTarget, 'type', 'hidden');\r
589                                 if (!iwfAddChild(frm, elTarget)){\r
590                                         iwfLog('IWF Core Error: Created iwfTarget element, but could not append to form ' + frm.outerHTML, true);\r
591                                         return;\r
592                                 }\r
593                         }\r
594                 }\r
595 \r
596                 if (!window.iwfRequest){\r
597                         iwfLog("IWF Core Error: when using the iwfDo* functions and passing a targetElement, you must also reference the iwfajax.js file from your main html file.", true);\r
598                 } else {\r
599 //alert('calling iwfRequest(' + frm + ')');\r
600                         iwfRequest(frm);\r
601                 }\r
602         } else {\r
603                 // do a normal html submit, since they didn't specify a particular target\r
604 iwfLog('doing frm.submit()', true);\r
605                 frm.submit();\r
606         }\r
607 }\r
608 \r
609 function iwfDoEdit(formId, id, targetElement){\r
610                 iwfDoAction('edit', formId, id, targetElement);\r
611 }\r
612 function iwfDoSave(formId, id, targetElement){\r
613                 iwfDoAction('save', formId, id, targetElement);\r
614 }\r
615 function iwfDoDelete(formId, id, targetElement){\r
616                 iwfDoAction('delete', formId, id, targetElement);\r
617 }\r
618 function iwfDoAdd(formId, id, targetElement){\r
619                 iwfDoAction('add', formId, id, targetElement);\r
620 }\r
621 function iwfDoSelect(formId, id, targetElement){\r
622                 iwfDoAction('select', formId, id, targetElement);\r
623 }\r
624 function iwfDoCancel(formId, id, targetElement){\r
625                 iwfDoAction('cancel', formId, id, targetElement);\r
626 }\r
627 \r
628 function iwfMailTo(uid, host){\r
629         // this is just so an email doesn't have to be output to the browser in raw text for\r
630         // email harvesters to grab...\r
631         location.href = 'mailto:' + uid + '@' + host;\r
632 }\r
633 \r
634 function iwfClickLink(id){\r
635         var el = iwfGetById(id);\r
636         if (!el) return;\r
637 \r
638         if (el.click){\r
639                 el.click();\r
640         } else {\r
641                 location.href = el.href;\r
642         }\r
643 }\r
644 \r
645 function iwfShowMessage(msg){\r
646         var el = iwfGetById('msg');\r
647         if (!el){\r
648 //              window.status = msg;\r
649                 alert(msg + '\n\nTo supress this alert, add a tag with an id of "msg" to this page.');\r
650         } else {\r
651                 el.innerHTML = msg.replace(/\n/, '<br />');\r
652         }\r
653 }\r
654 \r
655 \r
656 // -----------------------------------\r
657 // End: Form Submittal Utility Functions\r
658 // -----------------------------------\r
659 \r
660 // -----------------------------------\r
661 // Begin: Logging Utility Functions\r
662 // -----------------------------------\r
663 \r
664 var _iwfLoggedItems = "";\r
665 function iwfLog(txt, showAlert){\r
666         if (_iwfLoggingEnabled){\r
667                 _iwfLoggedItems += txt + '\n';\r
668         } else {\r
669                 //! send to big bit bucket in the sky (/dev/null)\r
670         }\r
671         if (showAlert){\r
672                 alert(txt);\r
673         }\r
674 }\r
675 \r
676 function iwfHideLog(){\r
677         iwfGetById("iwfLog").style.display="none";\r
678 }\r
679 \r
680 function iwfClearLog(){\r
681         _iwfLoggedItems = '';\r
682         iwfRefreshLog();\r
683 }\r
684 \r
685 function iwfRefreshLog(){\r
686         iwfHideLog();\r
687         iwfShowLog();\r
688 }\r
689 \r
690 function iwfShowLog(){\r
691         if (!_iwfLoggingEnabled){\r
692                 alert("Logging for IWF has been disabled.\nSet the _iwfLoggingEnabled variable located in the iwfcore.js (or iwfconfig.js) file to true to enable logging.");\r
693         } else {\r
694                 var el = iwfGetOrCreateById('iwfLog', 'div', 'body');\r
695                 if (!el){\r
696                         alert(_iwfLoggedItems);\r
697                 } else {\r
698                         el.style.position = 'absolute';\r
699                         el.style.zIndex = '999999';\r
700                         el.style.left = '10px';\r
701                         el.style.top = '200px';\r
702                         el.style.color = 'blue';\r
703                         el.style.width = '500px';\r
704                         el.style.height = '300px';\r
705                         el.style.overflow = 'scroll';\r
706                         el.style.padding = '5px 5px 5px 5px;'\r
707                         el.style.backgroundColor = '#efefef';\r
708                         el.style.border = '1px dashed blue';\r
709                         el.style.display = 'block';\r
710                         el.style.visibility = 'visible';\r
711                         el.id = 'iwfLog';\r
712 //                      el.innerHTML = "IWF Log <span style='width:100px'>&nbsp;</span><a href='javascript:iwfRefreshLog();'>refresh</a> <a href='javascript:iwfHideLog();'>close</a> <a href='javascript:iwfClearLog();'>clear</a>:<hr />" + iwfXmlEncode(_iwfLoggedItems).replace(/\n/gi, '<br />').replace(/\t/gi,'&nbsp;&nbsp;&nbsp;&nbsp;');\r
713                         el.innerHTML = "IWF Log <span style='width:100px'>&nbsp;</span><a href='javascript:iwfRefreshLog();'>refresh</a> <a href='javascript:iwfHideLog();'>close</a> <a href='javascript:iwfClearLog();'>clear</a>:<hr /><pre>" + _iwfLoggedItems.replace(/</gi, '&lt;').replace(/>/gi, '&gt;') + "</pre>";\r
714 \r
715                 }\r
716         }\r
717 }\r
718 \r
719 \r
720 // -----------------------------------\r
721 // End: Logging Utility Functions\r
722 // -----------------------------------\r