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