]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/WebContent/rtef/richtext.js
Salome HOME
b666b5b74c22e3310298ccce1ee88924518197e4
[tools/siman.git] / Workspace / Siman / WebContent / rtef / richtext.js
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Richtext Editor: Fork (RTEF) VERSION: 0.002
4 // Released: 8/11/2006
5 // For the latest release visit http://richtext.cabspace.com
6 // For support visit http://cabspace.com/forums/?mforum=richtext
7 //
8 ////////////////////////////////////////////////////////////////////////////////
9
10 ////////////////////////////////////////////////////////////////////////////////
11 //
12 // The MIT License
13 //
14 // Copyright (c) 2006 Timothy Bell
15 //
16 // Permission is hereby granted, free of charge, to any person obtaining a copy 
17 // of this software and associated documentation files (the "Software"), to deal
18 // in the Software without restriction, including without limitation the rights 
19 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
20 // copies of the Software, and to permit persons to whom the Software is 
21 // furnished to do so, subject to the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be included in 
24 // all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
27 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
28 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
29 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
30 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
32 // SOFTWARE.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35
36 // Constants
37 var ctxpath = "/siman/";
38 var minWidth = 400;                                     // minumum width
39 var wrapWidth = 1245;                       //width at which all icons will appear on one bar
40 var maxchar = 64000;                // maximum number of characters per save
41 var lang = "en";                                        //xhtml language
42 var lang_direction = "ltr";         //language direction : ltr = left-to-right, rtl = right-to-left 
43 var encoding = "utf-8";                     //xhtml encoding
44 var zeroBorder = "#c0c0c0";         //guideline color - see showGuidelines()
45 var btnText = "submit";                     //Button value for non-designMode() & fullsceen rte
46 var resize_fullsrcreen = true;
47 // (resize_fullsrcreen) limited in that: 1)won't auto wrap icons. 2)won't
48 // shrink to less than (wrapWidth)px if screen was initized over (wrapWidth)px;
49
50 var keep_absolute = true; // !!!Disabled - see line 456 for details!!!!!  
51 // By default IE will try to convery all hyperlinks to absolute paths. By
52 // setting this value to "false" it will retain the relative path.
53
54 // Pointers
55 var InsertChar;
56 var InsertTable;
57 var InsertLink;
58 var InsertImg;
59 var dlgReplace;
60 var dlgPasteText;
61 var dlgPasteWord;
62
63 //Init Variables & Attributes
64 var ua = navigator.userAgent.toLowerCase();
65 var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1))? true:false;
66 var isIE7 = ((isIE) && (ua.indexOf("msie 7.") != -1))? true:false;
67 var     isGecko = (ua.indexOf("gecko") != -1)? true:false;
68 var     isSafari = (ua.indexOf("safari") != -1)? true:false;
69 var safariVersion = parseFloat(ua.substring(ua.lastIndexOf("safari/") + 7));
70 var     isKonqueror = (ua.indexOf("konqueror") != -1)? true:false;
71 var rng;
72 var currentRTE;
73 var allRTEs = "";
74 var obj_width;
75 var obj_height;
76 var imagesPath;
77 var includesPath;
78 var cssFile;
79 var generateXHTML = true;
80 var isRichText = false;
81 //check to see if designMode mode is available
82 //Safari/Konqueror think they are designMode capable even though they are not
83 //if(document.getElementById && document.designMode && !isSafari && !isKonqueror){
84 if(document.getElementById && document.designMode) {
85         isRichText = true;
86 } else if ((isSafari && safariVersion >= 312) || isKonqueror) {
87         //Safari 1.3+ is capable of designMode, Safari 1.3 = webkit build 312
88         isRichText = true;
89 }
90 //for testing standard textarea, uncomment the following line
91 //isRichText = false;
92
93 var replacements = new Array (
94         new RegExp(String.fromCharCode(145),'g'), "'",
95         new RegExp(String.fromCharCode(146),'g'), "'",
96         new RegExp("'"), "'",
97         //convert all types of double quotes
98         new RegExp(String.fromCharCode(147),'g'), "\"",
99         new RegExp(String.fromCharCode(148),'g'), "\"",
100         new RegExp("\""), """,              //doesn't work
101         //replace carriage returns & line feeds
102         new RegExp("[\r\n]",'g'), " ");
103
104 function rteSafe(html) {
105         html = trim(html);
106         for (i=0; i<replacements.length; i = i+2) {
107                 html = html.replace(replacements[i], replacements[i+1]);
108         }
109         return html;
110 }
111
112 // [DBC]
113 var nbcommand     = 0;              // For not duplicating separators when no command between
114 var defaultFont   = "Times New Roman, Times, serif";
115 var defaultSize   = "13px";
116 var activeCommand = {               // Strait-forward HashMap
117         put : function(foo, bar)   {this[foo] = bar;},
118         get : function(foo) {return this[foo];}
119 }
120
121 function initTextInput() {
122     activeCommand.put("cut", lblCut);
123     activeCommand.put("copy", lblCopy);
124     activeCommand.put("paste", lblPaste);
125     activeCommand.put("undo", lblUndo);
126     activeCommand.put("redo", lblRedo);
127     activeCommand.put("bold", lblBold);
128     activeCommand.put("italic", lblItalic);
129     activeCommand.put("underline", lblUnderline);
130     activeCommand.put("list", lblUL);
131     activeCommand.put("numbered_list", lblOL);
132     activeCommand.put("indent", lblIndent);
133     activeCommand.put("outdent", lblOutdent);
134     activeCommand.put("replace", lblSearch);
135     activeCommand.put("hyperlink", lblInsertLink);
136
137     wrapWidth   = 14 * 24;
138     defaultFont = "Arial, Helvetica, sans-serif";
139     initRTE(ctxpath + "rtef/images/", ctxpath + "rtef/", "", true);
140 }
141
142 function initTextEditor() {
143     activeCommand.put("save", lblSave);
144 //  activeCommand.put("print", lblPrint);
145     activeCommand.put("cut", lblCut);
146     activeCommand.put("copy", lblCopy);
147     activeCommand.put("paste", lblPaste);
148     activeCommand.put("undo", lblUndo);
149     activeCommand.put("redo", lblRedo);
150     activeCommand.put("bold", lblBold);
151     activeCommand.put("italic", lblItalic);
152     activeCommand.put("underline", lblUnderline);
153     activeCommand.put("list", lblUL);
154     activeCommand.put("numbered_list", lblOL);
155     activeCommand.put("indent", lblIndent);
156     activeCommand.put("outdent", lblOutdent);
157     activeCommand.put("replace", lblSearch);
158     activeCommand.put("hyperlink", lblInsertLink);
159
160     wrapWidth   = 15 * 24;
161     defaultFont = "Arial, Helvetica, sans-serif";
162     initRTE(ctxpath + "rtef/images/", ctxpath + "rtef/", "", true);
163 }
164
165 function addCommand(name, action) {
166     var label = activeCommand.get(name);
167     if (label != null) {
168         insertImg(label, name + ".gif", action);
169         nbcommand += 1;
170     }
171 }
172
173 function displayTextEditor(inputname, initialtext, width, height) {
174     writeRichText(inputname, rteSafe(initialtext), '', width, height, true, false, false);
175 }
176 // [/DBC]
177
178 function initRTE(imgPath, incPath, css, genXHTML){
179         // CM 05/04/05 check args for compatibility with old RTE implementations
180         if (arguments.length == 3) {
181                 genXHTML = generateXHTML;
182         }
183         //set paths vars
184         imagesPath = imgPath;
185         includesPath = incPath;
186         cssFile = css;
187         generateXHTML = genXHTML;
188         if(isRichText){
189         document.writeln('<style type="text/css">@import "' + includesPath + 'rte.css";</style>');
190         }
191         if(!isIE){
192                 minWidth = minWidth-48;
193                 wrapWidth = wrapWidth-102;
194         }
195 }
196
197 function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscreen) {
198         currentRTE = rte;
199         if(allRTEs.length > 0){
200         allRTEs += ";";
201         }
202         allRTEs += rte;
203         // CM 06/04/05 stops single quotes from messing everything up
204         html=replaceIt(html,'\'','&apos;');
205         // CM 05/04/05 a bit of juggling for compatibility with old RTE implementations
206         if (arguments.length == 6) {
207                 fullscreen = false;
208                 readOnly = buttons;
209                 buttons = height;
210                 height = width;
211                 width = css;
212                 css = "";
213         }
214         var iconWrapWidth = wrapWidth;
215         var tablewidth;
216         if(readOnly) {
217                 buttons = false;
218         }
219         if(fullscreen) {
220                 readOnly = false; // fullscreen is not readOnly and must show buttons
221                 buttons = true;
222                 // resize rte on resize if the option resize_fullsrcreen = true.
223                 if(isRichText && resize_fullsrcreen) {
224                         window.onresize = resizeRTE;
225                 }
226                 document.body.style.margin = "0px";
227                 document.body.style.overflow = "hidden";
228                 //adjust maximum table widths
229                 findSize("");
230                 width = obj_width;
231                 if(width < iconWrapWidth) {
232                         height = (obj_height - 83);
233                 } else {
234                         height = (obj_height - 55);
235                 }
236                 if (width < minWidth) {
237                         document.body.style.overflow = "auto";
238                         if(isIE) {
239                                 height = obj_height-22;
240                         } else {
241                                 height = obj_height-24;
242                         }
243                         width = minWidth;
244                 }
245                 tablewidth = width;
246         } else {
247                 fullscreen = false;
248                 iconWrapWidth = iconWrapWidth-25;
249                 //adjust minimum table widths
250                 if(buttons && (width < minWidth)) {
251                   width = minWidth;
252           }
253           if(isIE){
254                   tablewidth = width;
255           } else {
256                   tablewidth = width + 4;
257           }
258   }
259   if(isRichText) {
260           var rte_css = "";
261           if(css.length > 0) {
262                   rte_css = css;
263           } else {
264                   rte_css = cssFile;
265           }
266           document.writeln('<span class="rteDiv">');
267           if(buttons) {
268                   document.writeln('<table class="rteBk" cellpadding=0 cellspacing=0 id="Buttons1_'+rte+'" width="' + tablewidth + '">');
269                   document.writeln('<tbody><tr>');
270                   insertBar();
271                   if(fullscreen || activeCommand.get("save") != null){
272                           document.writeln('<td><input type="image" class="rteImg" id="'+rte+'SaveButton" src="'+imagesPath+'save.gif" alt="'+lblSave+'" title="'+lblSave+'" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'" onClick="prepareSubmitEdit(currentRTE)"></td>');
273                           nbcommand += 1;
274                   }
275                   if(!isSafari && !isKonqueror) {
276                           addCommand("print","rtePrint('"+rte+"')");
277 //                        insertImg(lblPrint,"print.gif","rtePrint('"+rte+"')");
278                           insertSep();
279                           addCommand("selectall","toggleSelection('"+rte+"')");
280 //                        insertImg(lblSelectAll,"selectall.gif","toggleSelection('"+rte+"')");
281                           addCommand("unformat","rteCommand('"+rte+"','removeformat')");
282 //                        insertImg(lblUnformat,"unformat.gif","rteCommand('"+rte+"','removeformat')");
283                           insertSep();
284                   }
285                   if(false) {
286                           addCommand("cut","rteCommand('"+rte+"','cut')");
287 //                        insertImg(lblCut,"cut.gif","rteCommand('"+rte+"','cut')");
288                           addCommand("copy","rteCommand('"+rte+"','copy')");
289 //                        insertImg(lblCopy,"copy.gif","rteCommand('"+rte+"','copy')");
290                           addCommand("paste","rteCommand('"+rte+"','InsertText')");
291 //                        insertImg(lblPaste,"paste.gif","rteCommand('"+rte+"','InsertText')");
292                   }
293                   if(isIE) {
294                           addCommand("paste","rteCommand('"+rte+"','paste')");
295 //                        insertImg(lblPaste,"paste.gif","rteCommand('"+rte+"','paste')");
296                   }
297                   if(!isSafari && !isKonqueror) {
298                           addCommand("pastetext","dlgLaunch('"+rte+"','text')");
299 //                        insertImg(lblPasteText,"pastetext.gif","dlgLaunch('"+rte+"','text')");
300                           addCommand("pasteword","dlgLaunch('"+rte+"','word')");
301 //                        insertImg(lblPasteWord,"pasteword.gif","dlgLaunch('"+rte+"','word')");
302                   }
303                   insertSep();
304                   addCommand("undo","rteCommand('"+rte+"','undo')");
305 //                insertImg(lblUndo,"undo.gif","rteCommand('"+rte+"','undo')");
306                   addCommand("redo","rteCommand('"+rte+"','redo')");
307 //                insertImg(lblRedo,"redo.gif","rteCommand('"+rte+"','redo')");
308                   if(!isSafari && !isKonqueror) {
309 //                        insertSep();
310 //        document.writeln('<td>');
311 //        document.writeln('<select id="formatblock_'+rte+'" onchange="selectFont(\''+rte+'\', this.id);return false" style="font-size:14px;width:105px;height:20px;margin:1px;">');
312 //                        document.writeln(lblFormat);
313 //                        document.writeln('</select></td><td>');
314 //                        document.writeln('<select id="fontname_'+rte+'" onchange="selectFont(\''+rte+'\', this.id);return false" style="font-size:14px;width:125px;height:20px;margin:1px;">');
315 //                        document.writeln(lblFont);
316 //                        document.writeln('</select></td><td>');
317 //                        document.writeln('<select unselectable="on" id="fontsize_'+rte+'" onchange="selectFont(\''+rte+'\', this.id);return false" style="font-size:14px;width:75px;height:20px;margin:1px;">');
318 //                        document.writeln(lblSize);
319 //                        document.writeln('</select></td>');
320                   }
321                   if(tablewidth < iconWrapWidth){
322                           document.writeln('<td width="100%"></td></tr></tbody></table>');
323                           document.writeln('<table class="rteBk" cellpadding="0" cellspacing="0" id="Buttons2_'+rte+'" width="' + tablewidth + '">');
324                           document.writeln('<tbody><tr>');
325                   }
326                   insertBar();
327                   addCommand("bold","rteCommand('"+rte+"','bold')");
328 //                insertImg(lblBold,"bold.gif","rteCommand('"+rte+"','bold')");
329                   addCommand("italic","rteCommand('"+rte+"','italic')");
330 //                insertImg(lblItalic,"italic.gif","rteCommand('"+rte+"','italic')");
331                   addCommand("underline","rteCommand('"+rte+"','underline')");
332 //                insertImg(lblUnderline,"underline.gif","rteCommand('"+rte+"','underline')");
333                   //if(!isSafari && !isKonqueror) insertImg(lblStrikeThrough,"strikethrough.gif","rteCommand('"+rte+"','strikethrough')");
334                   //insertImg(lblSuperscript,"superscript.gif","rteCommand('"+rte+"','superscript')");
335                   //if(!isSafari && !isKonqueror){
336       //insertImg(lblSubscript,"subscript.gif","rteCommand('"+rte+"','subscript')");
337       //} else {
338       //insertImg(lblSubscript,"subscript.gif","rteCommand('"+rte+"','StyleChange',sub)");
339       //}
340                   insertSep();
341                   addCommand("left_just","rteCommand('"+rte+"','justifyleft')");
342 //                insertImg(lblAlgnLeft,"left_just.gif","rteCommand('"+rte+"','justifyleft')");
343                   addCommand("centre","rteCommand('"+rte+"','justifycenter')");
344 //                insertImg(lblAlgnCenter,"centre.gif","rteCommand('"+rte+"','justifycenter')");
345                   addCommand("right_just","rteCommand('"+rte+"','justifyright')");
346 //                insertImg(lblAlgnRight,"right_just.gif","rteCommand('"+rte+"','justifyright')");
347                   addCommand("justifyfull","rteCommand('"+rte+"','justifyfull')");
348 //                insertImg(lblJustifyFull,"justifyfull.gif","rteCommand('"+rte+"','justifyfull')");
349           insertSep();
350             addCommand("numbered_list","rteCommand('"+rte+"','insertorderedlist')");
351 //          insertImg(lblOL,"numbered_list.gif","rteCommand('"+rte+"','insertorderedlist')");
352             addCommand("list","rteCommand('"+rte+"','insertunorderedlist')");
353 //          insertImg(lblUL,"list.gif","rteCommand('"+rte+"','insertunorderedlist')");
354             addCommand("hyperlink","dlgLaunch('"+rte+"','link')");
355 //          insertImg(lblInsertLink,"hyperlink.gif","dlgLaunch('"+rte+"','link')");
356                   if(false) {
357                         insertSep();
358                           insertSep();
359                           addCommand("textcolor","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
360 //                        insertImg(lblTextColor,"textcolor.gif","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
361                           addCommand("bgcolor","dlgColorPalette('"+rte+"','hilitecolor')","hilitecolor_"+rte);
362 //                        insertImg(lblBgColor,"bgcolor.gif","dlgColorPalette('"+rte+"','hilitecolor')","hilitecolor_"+rte);
363                           insertSep();
364                           addCommand("hr","rteCommand('"+rte+"','inserthorizontalrule')");
365 //                        insertImg(lblHR,"hr.gif","rteCommand('"+rte+"','inserthorizontalrule')");
366                           insertSep();
367                           addCommand("special_char","dlgLaunch('"+rte+"','char')");
368 //                        insertImg(lblInsertChar,"special_char.gif","dlgLaunch('"+rte+"','char')");
369                           addCommand("image","dlgLaunch('"+rte+"','image')");
370 //                        insertImg(lblAddImage,"image.gif","dlgLaunch('"+rte+"','image')");
371                           addCommand("insert_table","dlgLaunch('"+rte+"','table')");
372 //                        insertImg(lblInsertTable,"insert_table.gif","dlgLaunch('"+rte+"','table')");
373                   }
374           addCommand("outdent","rteCommand('"+rte+"','outdent')");
375 //        insertImg(lblOutdent,"outdent.gif","rteCommand('"+rte+"','outdent')");
376           addCommand("indent","rteCommand('"+rte+"','indent')");
377 //        insertImg(lblIndent,"indent.gif","rteCommand('"+rte+"','indent')");
378                   insertSep();
379                   if(false) {
380                           addCommand("replace","dlgLaunch('"+rte+"','replace')");
381 //                        insertImg(lblSearch,"replace.gif","dlgLaunch('"+rte+"','replace')");
382                   }
383                   addCommand("word_count","countWords('"+rte+"')");
384 //                insertImg(lblWordCount,"word_count.gif","countWords('"+rte+"')");
385                   if(isIE) {
386                           addCommand("spellcheck","checkspell()");
387 //                        insertImg(lblSpellCheck,"spellcheck.gif","checkspell()");
388                   }
389                   document.writeln('<td width="100%"></td></tr></tbody></table>');
390           }
391           document.writeln('<iframe id="'+rte+'" width="' + (tablewidth - 2) + 'px" height="' + height + 'px" frameborder=0 style="border: 1px solid #d2d2d2" src="' + includesPath + 'blank.htm" onfocus="dlgCleanUp();"></iframe>');
392           if(!readOnly){
393                   document.writeln('<table id="vs'+rte+'" name="vs'+rte+'" class="rteBk" cellpadding=0 cellspacing=0 border=0 width="' + tablewidth + '"><tr>');
394                   document.writeln('<td onclick="toggleHTMLSrc(\''+rte+'\', ' + buttons + ');" nowrap><img class="rteBar" src="'+imagesPath+'bar.gif" alt="" align=absmiddle><span id="imgSrc'+rte+'"><img src="'+imagesPath+'code.gif" alt="" title="" style="margin:1px;" align=absmiddle></span><span id="_xtSrc'+rte+'" style="font-family:tahoma,sans-serif;font-size:12px;color:#0000ff;CURSOR: default;">'+lblModeHTML+'</span></td>');
395                   document.writeln('<td width="100%" nowrap>&nbsp;</td></tr></table>');
396           }
397           document.writeln('<iframe width="142" height="98" id="cp'+rte+'" src="' + includesPath + 'palette.htm" scrolling="no" frameborder=0 style="margin:0;border:0;visibility:hidden;position:absolute;border:1px solid #cdcdcd;top:-1000px;left:-1000px"></iframe>');
398           document.writeln('<input type="hidden" id="hdn'+rte+'" name="'+rte+'" value="" style="position: absolute;left:-1000px;top:-1000px;">');
399           if(!fullscreen){
400                   document.writeln('<input type="hidden" id="size'+rte+'" name="size'+rte+'" value="'+height+'" style="position: absolute;left:-1000px;top:-1000px;">');
401           }
402           document.writeln('</span>');
403           document.getElementById('hdn'+rte).value = html;
404     enableDesignMode(rte, html, rte_css, readOnly);
405         } else {
406                 buttons = false;
407                 if(fullscreen && height > 90) {
408                         height = (height - 75);tablewidth=tablewidth-30;
409                 }
410                 // CM non-designMode() UI
411                 html = parseBreaks(html);
412                 document.writeln('<div style="font:12px Verdana, Arial, Helvetica, sans-serif;width: ' + tablewidth + 'px;padding:15px;">');
413                 if(!readOnly) {
414                         document.writeln('<div style="color:gray">'+lblnon_designMode+'</div><br>');
415                         document.writeln('<input type="radio" name="' + rte + '_autobr" value="1" checked="checked" onclick="autoBRon(\'' + rte + '\');" /> '+lblAutoBR+'<input type="radio" name="' + rte + '_autobr" value="0" onclick="autoBRoff(\'' + rte + '\');" />'+lblRawHTML+'<br>');
416                         document.writeln('<textarea name="'+rte+'" id="'+rte+'" style="width: ' + tablewidth + 'px; height: ' + height + 'px;">' + html + '</textarea>');
417                 } else {
418                         document.writeln('<textarea name="'+rte+'" id="'+rte+'" style="width: ' + tablewidth + 'px; height: ' + height + 'px;" readonly=readonly>' + html + '</textarea>');
419                 }
420                 if(fullscreen) document.writeln('<br><input type="submit" value="'+btnText+'" />');
421                 document.writeln('</div>');
422         }
423 }
424
425 function insertBar() {
426         document.writeln('<td><img class="rteBar" src="'+imagesPath+'bar.gif" alt=""></td>');
427         nbcommand = 0;
428 }
429 function insertSep() {
430         if (nbcommand > 0) {
431           document.writeln('<td><img class="rteSep" src="'+imagesPath+'blackdot.gif" alt=""></td>');
432           nbcommand = 0;
433         }
434 }
435 function insertImg(name, image, command, id){
436           var td = "<td>";
437           if(id!=null){
438             td = "<td id='"+id+"'>";
439       }
440           document.writeln(td+'<img class="rteImg" src="'+imagesPath+image+'" alt="'+name+'" title="'+name+'" onClick="'+command+';return false" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'"></td>');
441 }
442
443 function enableDesignMode(rte, html, css, readOnly) {
444         var frameHtml = "<html dir='" + lang_direction + "' lang='" + lang + "' id='" + rte + "'>\n<head>\n";
445         frameHtml += "<meta http-equiv='Content-Type' content='text/html; charset=" + encoding + "'>\n";
446         frameHtml += "<meta http-equiv='Content-Language' content='" + lang + "'>\n";
447         //to reference your stylesheet, set href property below to your stylesheet path and uncomment
448         if(css.length > 0) {
449                 frameHtml += "<link media=\"all\" type=\"text/css\" href=\"" + css + "\" rel=\"stylesheet\">\n";
450         } else {
451                 frameHtml += "<style>@charset \"utf-8\"; body {background:#FFFFFF;margin:8px;padding:0px;font-family:"+defaultFont+";font-size:"+defaultSize+";}</style>\n";
452         }
453         frameHtml += "</head><body>\n"+html+"\n</body></html>";
454         if(!isSafari && !isKonqueror) var oRTE = returnRTE(rte).document;
455         if (document.all) {
456                 if(isSafari || isKonqueror) var oRTE = frames[rte].document;
457                 oRTE.open("text/html","replace");
458                 oRTE.write(frameHtml);
459                 oRTE.close();
460                 if (!readOnly) {
461                         oRTE.designMode = "On";
462                 }
463         } else {
464                 try {
465                         // Commented out the following line to confront a bug when loading multiple RTEs on one page in a MOZ browser
466                         // Fix provided by "Kings". Safari may have problems with this snytax - unable to test because I don't own a MAC.(Tim Bell)
467                         //
468                         // if(!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
469                         if(!readOnly && !isKonqueror && !isSafari) {
470                 document.getElementById(rte).contentDocument.designMode = "on"; //RKV
471                                 addLoadEvent(function() { document.getElementById(rte).contentDocument.designMode = "on"; });
472                         } else if(!readOnly) {
473                                 if (!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
474                         }
475                         try {
476                                 
477                                 if(isSafari || isKonqueror) var oRTE = document.getElementById(rte).contentWindow.document;
478                                 oRTE.open("text/html","replace");
479                                 oRTE.write(frameHtml);
480                                 oRTE.close();
481                                 if(isGecko && !readOnly) {
482                                         //attach a keyboard handler for gecko browsers to make keyboard shortcuts work
483                                         oRTE.addEventListener("keypress", geckoKeyPress, true);
484                                 }
485                         } catch(e) {
486                                 alert(lblErrorPreload);
487                         }
488                 } catch(e) {
489                         //gecko may take some time to enable design mode.
490                         //Keep looping until able to set.
491                         if(isGecko){
492                         if(!timeLeft) {
493                             timeLeft = 5000;
494                         }
495                 if(timeLeft > 0) {
496                                     setTimeout("enableDesignMode('"+rte+"', '"+html+"', '"+css+"', "+readOnly+ "','"+(timeLeft-200)+"');", 200);
497                             }
498                         }else{
499                                 return false;
500                         }
501                 }
502         }       
503         setTimeout('showGuidelines("'+rte+'")',300);
504 }
505
506 function addLoadEvent(func) {
507         var oldonload = window.onload;
508         if (typeof window.onload != 'function') {
509                 window.onload = func;
510         } else {
511                 window.onload = function() {
512                         oldonload();
513                         func();
514                 };
515         }
516 }
517
518 function returnRTE(rte) {
519         var rtn;
520         if(document.all){
521                 rtn = frames[rte];
522         } else {
523                 rtn = document.getElementById(rte).contentWindow;
524         }       
525         return rtn;
526 }
527
528 function updateRTE(rte) {
529         if(isRichText) {
530           dlgCleanUp(); //      Closes Pop-ups
531           stripGuidelines(rte); // Removes Table Guidelines
532   }
533         parseRTE(rte);
534 }
535
536 function updateRTEs(){
537         var vRTEs = allRTEs.split(";");
538         for(var i=0; i<vRTEs.length; i++){
539                 updateRTE(vRTEs[i]);
540         }
541 }
542
543 function parseRTE(rte) {
544         if (!isRichText) {
545                  autoBRoff(rte); // sorts out autoBR
546                  return false;
547         }
548         //check for readOnly mode
549         var readOnly = false;
550         var oRTE = returnRTE(rte);
551   if(document.all){
552                 if(oRTE.document.designMode != "On"){
553       readOnly = true;
554     }
555         }else{
556                 if(oRTE.document.designMode != "on"){
557       readOnly = true;
558     }
559         }
560         if(isRichText && !readOnly){
561                 //if viewing source, switch back to design view
562                 if(document.getElementById("_xtSrc"+rte).innerHTML == lblModeRichText){
563                          if(document.getElementById("Buttons1_"+rte)){
564                                  toggleHTMLSrc(rte, true);
565                          }else{
566          toggleHTMLSrc(rte, false);
567                          }
568                  stripGuidelines(rte);
569                 }
570                 setHiddenVal(rte);
571         }
572 }
573
574 function setHiddenVal(rte){
575         //set hidden form field value for current rte
576         var oHdnField = document.getElementById('hdn'+rte);
577         //convert html output to xhtml (thanks Timothy Bell and Vyacheslav Smolin!)
578         if(oHdnField.value==null){
579     oHdnField.value = "";
580         }
581   var sRTE = returnRTE(rte).document.body;
582         if(generateXHTML){
583           try{
584                   oHdnField.value = getXHTML(sRTE.innerHTML);
585           }catch(e){
586       oHdnField.value = sRTE.innerHTML;
587     }
588         }else{
589           oHdnField.value = sRTE.innerHTML;
590         }
591         // fix to replace special characters added here: 
592   oHdnField.value = replaceSpecialChars(oHdnField.value); 
593   //if there is no content (other than formatting) set value to nothing
594         if(stripHTML(oHdnField.value.replace("&nbsp;", " ")) == "" &&
595                 oHdnField.value.toLowerCase().search("<hr") == -1 &&
596                 oHdnField.value.toLowerCase().search("<img") == -1){
597     oHdnField.value = "";
598   }
599 }
600
601 function rteCommand(rte, command, option){
602         dlgCleanUp();
603   //function to perform command
604         var oRTE = returnRTE(rte);
605         try{
606                 oRTE.focus();
607                 oRTE.document.execCommand(command, false, option);
608                 oRTE.focus();
609         }catch(e){
610 //              alert(e);
611 //              setTimeout("rteCommand('" + rte + "', '" + command + "', '" + option + "');", 10);
612         }
613 }
614
615 function toggleHTMLSrc(rte, buttons){
616         dlgCleanUp();
617   //contributed by Bob Hutzel (thanks Bob!)
618   var cRTE = document.getElementById(rte);
619   var hRTE = document.getElementById('hdn'+rte);
620   var sRTE = document.getElementById("size"+rte);
621   var tRTE = document.getElementById("_xtSrc"+rte);
622   var iRTE = document.getElementById("imgSrc"+rte);
623   var oRTE = returnRTE(rte).document;
624   var htmlSrc;
625         if(sRTE){
626           obj_height = parseInt(sRTE.value);
627   }else{
628     findSize(rte);
629         }
630         if(tRTE.innerHTML == lblModeHTML){
631                 //we are checking the box
632                 tRTE.innerHTML = lblModeRichText;
633                 stripGuidelines(rte);
634                 if(buttons){
635                         showHideElement("Buttons1_" + rte, "hide", true);
636                         if(document.getElementById("Buttons2_"+rte)){
637                                 showHideElement("Buttons2_" + rte, "hide", true);
638                           cRTE.style.height = obj_height+56;
639                         }else{
640                                 cRTE.style.height = obj_height+28;
641                         }
642                 }
643                 setHiddenVal(rte);
644         if(document.all){
645                 oRTE.body.innerText = hRTE.value;
646                 }else{
647                 htmlSrc = oRTE.createTextNode(hRTE.value);
648                         oRTE.body.innerHTML = "";
649                         oRTE.body.appendChild(htmlSrc);
650                 }
651                 iRTE.innerHTML = '<img src="'+imagesPath+'design.gif" alt="Switch Mode" style="margin:1px;" align=absmiddle>';
652         }else{
653                 //we are unchecking the box
654                 obj_height = parseInt(cRTE.style.height);
655                 tRTE.innerHTML = lblModeHTML;
656                 if(buttons){
657                         showHideElement("Buttons1_" + rte, "show", true);
658                   if(document.getElementById("Buttons2_"+rte)){
659         showHideElement("Buttons2_" + rte, "show", true);
660                           cRTE.style.height = obj_height-56;
661                         }else{
662         cRTE.style.height = obj_height-28;
663       }
664                 }
665                 if(document.all){
666                         //fix for IE
667                         var output = escape(oRTE.body.innerText);
668                         output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
669                         output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
670                         oRTE.body.innerHTML = unescape(output);
671                         // Disabled due to flaw in the regular expressions, this fix 
672       // does not work with the revamped's enhanced insert link dialog window.
673       //
674       // Prevent links from changing to absolute paths
675       if(!keep_absolute){
676         var tagfix = unescape(output).match(/<a[^>]*href=(['"])([^\1>]*)\1[^>]*>/ig); 
677         var coll = oRTE.body.all.tags('A'); 
678         for(i=0; i<coll.length; i++){ 
679           // the 2 alerts below show when we hinder the links from becoming absolute                    
680           //alert(tagfix[i]); 
681           coll[i].href = tagfix[i].replace(/.*href=(['"])([^\1]*)\1.*/i,"$2"); 
682           //alert(RegExp.$1 + " " + RegExp.$2 + " " + RegExp.$3); 
683         } 
684         var imgfix = unescape(output).match(/<img[^>]*src=['"][^'"]*['"][^>]*>/ig); 
685         var coll2 = oRTE.body.all.tags('IMG'); 
686         for(i=0; i<coll2.length; i++){ 
687           coll2[i].src = imgfix[i].replace(/.*src=['"]([^'"]*)['"].*/i,"$1"); 
688         } 
689       }
690       //end path fix                    
691                 }else{
692                 htmlSrc = oRTE.body.ownerDocument.createRange();
693                         htmlSrc.selectNodeContents(oRTE.body);
694                         oRTE.body.innerHTML = htmlSrc.toString();
695                 }
696                 oRTE.body.innerHTML = replaceSpecialChars(oRTE.body.innerHTML);
697                 showGuidelines(rte);
698                 // (IE Only)This prevents an undo operation from displaying a pervious HTML mode
699                 // This resets the undo/redo buffer.
700                 if(document.all){
701                         parseRTE(rte);
702           }
703           iRTE.innerHTML = '<img src="'+imagesPath+'code.gif" alt="Switch Mode" style="margin:1px;" align=absmiddle>';
704         }
705 }
706
707 function toggleSelection(rte) {
708   var rng = setRange(rte);
709   var oRTE = returnRTE(rte).document;
710         var length1;
711   var length2;
712         if(document.all){
713                 length1 = rng.text.length;
714                 var output = escape(oRTE.body.innerText);
715                 output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
716                 output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
717                 length2 = unescape(output).length;
718         }else{
719                 length1 = rng.toString().length;
720                 var htmlSrc = oRTE.body.ownerDocument.createRange();
721                 htmlSrc.selectNodeContents(oRTE.body);
722           length2 = htmlSrc.toString().length;
723         }
724         if(length1 < length2){
725           rteCommand(rte,'selectall','');
726         } else {
727                 if(!document.all){
728                   oRTE.designMode = "off";
729                   oRTE.designMode = "on";
730                 }else{
731                   rteCommand(rte,'unselect','');
732                 }
733         }
734 }
735
736 function dlgColorPalette(rte, command) {
737         //function to display or hide color palettes
738         setRange(rte);
739         //get dialog position
740         var oDialog = document.getElementById('cp' + rte);
741         var buttonElement = document.getElementById(command+"_"+rte);
742         var iLeftPos = buttonElement.offsetLeft+5; 
743   var iTopPos = buttonElement.offsetTop+53;
744   if (!document.getElementById('Buttons2_'+rte)){
745     iTopPos = iTopPos-28;
746         }
747   oDialog.style.left = iLeftPos + "px";
748         oDialog.style.top = iTopPos + "px";
749         
750   if((command == parent.command)&&(rte == currentRTE)){
751                 //if current command dialog is currently open, close it
752                 if(oDialog.style.visibility == "hidden"){
753                         showHideElement(oDialog, 'show', false);
754                 }else{
755                         showHideElement(oDialog, 'hide', false);
756                 }
757         }else{
758                 //if opening a new dialog, close all others
759                 var vRTEs = allRTEs.split(";");
760                 for(var i = 0; i<vRTEs.length; i++){
761                         showHideElement('cp' + vRTEs[i], 'hide', false);
762                 }
763                 showHideElement(oDialog, 'show', false);
764         }
765         //save current values
766         currentRTE = rte;
767         parent.command = command;
768 }
769
770 function dlgLaunch(rte, command) {
771         var selectedText = '';
772   //save current values
773         parent.command = command;
774         currentRTE = rte;
775         switch(command){
776   case "char":
777     InsertChar = popUpWin(includesPath+'insert_char.htm', 'InsertChar', 50, 50, 'status=yes,');
778     break;
779   case "table":
780     InsertTable = popUpWin(includesPath + 'insert_table.htm', 'InsertTable', 50, 50, 'status=yes,');
781     break;
782   case "image":
783     setRange(rte);
784     parseRTE(rte);
785     InsertImg = popUpWin(includesPath + 'insert_img.htm','AddImage', 50, 50, 'status=yes,');
786     break;
787   case "link":
788     selectedText = getText(rte);
789     InsertLink = popUpWin(includesPath + 'insert_link.htm', 'InsertLink', 50, 50, 'status=yes,');
790     setFormText("0", selectedText);
791     break;
792   case "replace":
793     selectedText = getText(rte);
794     dlgReplace = popUpWin(includesPath + 'replace.htm', 'dlgReplace', 50, 50, 'status=yes,');
795     setFormText("1", selectedText);
796     break;
797   case "text":
798     dlgPasteText = popUpWin(includesPath + 'paste_text.htm', 'dlgPasteText', 50, 50, 'status=yes,');
799     break;
800   case "word":
801     dlgPasteWord = popUpWin(includesPath + 'paste_word.htm', 'dlgPasteWord', 50, 50, 'status=yes,');
802     break;
803   }
804 }
805
806 function getText(rte) {
807         //get currently highlighted text and set link text value
808   setRange(rte);
809         var rtn = '';
810         if (isIE) {
811           rtn = stripHTML(rng.htmlText);
812         } else {
813           rtn = stripHTML(rng.toString());
814         }
815         parseRTE(rte);
816         if(document.all){
817     rtn = rtn.replace("'","\\\\\\'");
818   }else{
819     rtn = rtn.replace("'","\\'");
820   }
821   return rtn;
822 }
823
824 function setFormText(popup, content, timeLeft){
825         //set link text value in dialog windows
826         if(content != "undefined")
827         {
828           try{
829                   switch(popup){
830                     case "0": InsertLink.document.getElementById("linkText").value = content; break;
831                     case "1": dlgReplace.document.getElementById("searchText").value = content; break;
832                   }
833           }catch(e){
834                   //may take some time to create dialog window.
835                   //Keep looping until able to set.
836                   if(!timeLeft) {
837                       timeLeft = 5000;
838                   }
839                   if(timeLeft > 0) {
840                       setTimeout("setFormText('"+popup+"','" + content + "','"+(timeLeft-200)+"');", 200);
841                   }
842            }
843         }
844 }
845
846 function dlgCleanUp(){
847         var vRTEs = allRTEs.split(";");
848         for(var i = 0; i < vRTEs.length; i++){
849           showHideElement('cp' + vRTEs[i], 'hide', false);
850         }
851         if(InsertChar != null){
852     InsertChar.close();
853     InsertChar=null;
854         }
855   if(InsertTable != null){
856     InsertTable.close();
857     InsertTable=null;
858         }
859   if(InsertLink != null){
860     InsertLink.close();
861     InsertLink=null;
862         }
863   if(InsertImg != null){
864     InsertImg.close();
865     InsertImg=null;
866         }
867   if(dlgReplace != null){
868     dlgReplace.close();
869     dlgReplace=null;
870         }
871   if(dlgPasteText != null){
872     dlgPasteText.close();
873     dlgPasteText=null;
874         }
875   if(dlgPasteWord != null){
876     dlgPasteWord.close();
877     dlgPasteWord=null;
878   }
879 }
880
881 function popUpWin (url, win, width, height, options) {
882   dlgCleanUp();
883         var leftPos = (screen.availWidth - width) / 2;
884         var topPos = (screen.availHeight - height) / 2;
885         options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
886         return window.open(url, win, options);
887 }
888
889 function setColor(color) {
890         //function to set color
891         var rte = currentRTE;
892         var parentCommand = parent.command;
893         if(document.all){
894                 if(parentCommand == "hilitecolor"){
895       parentCommand = "backcolor";
896     }
897                 //retrieve selected range
898                 rng.select();
899         }
900         rteCommand(rte, parentCommand, color);
901         showHideElement('cp'+rte, "hide", false);
902 }
903
904 function addImage(rte) {
905   dlgCleanUp();
906         //function to add image
907         imagePath = prompt('Enter Image URL:', 'http://');                              
908         if((imagePath != null)&&(imagePath != "")){
909                 rteCommand(rte, 'InsertImage', imagePath);
910         }
911 }
912
913 function rtePrint(rte) {
914   dlgCleanUp();
915         if(isIE){
916           document.getElementById(rte).contentWindow.document.execCommand('Print');
917   }else{
918           document.getElementById(rte).contentWindow.print();
919         }
920 }
921
922 function selectFont(rte, selectname){
923         //function to handle font changes
924         var idx = document.getElementById(selectname).selectedIndex;
925         // First one is always a label
926         if(idx != 0){
927                 var selected = document.getElementById(selectname).options[idx].value;
928                 var cmd = selectname.replace('_'+rte, '');
929                 rteCommand(rte, cmd, selected);
930                 document.getElementById(selectname).selectedIndex = 0;
931         }
932 }
933
934 function insertHTML(html){
935         //function to add HTML -- thanks dannyuk1982
936         var rte = currentRTE;
937         var oRTE = returnRTE(rte);
938         oRTE.focus();
939         if(document.all){
940                 var oRng = oRTE.document.selection.createRange();
941                 oRng.pasteHTML(html);
942                 oRng.collapse(false);
943                 oRng.select();
944         }else{
945                 oRTE.document.execCommand('insertHTML', false, html);
946         }
947 }
948
949 function replaceHTML(tmpContent, searchFor, replaceWith) {
950   var runCount = 0;
951         var intBefore = 0;
952         var intAfter = 0;
953         var tmpOutput = "";
954         while(tmpContent.toUpperCase().indexOf(searchFor.toUpperCase()) > -1) {
955     runCount = runCount+1;
956     // Get all content before the match
957     intBefore = tmpContent.toUpperCase().indexOf(searchFor.toUpperCase());
958     tmpBefore = tmpContent.substring(0, intBefore);
959     tmpOutput = tmpOutput + tmpBefore;
960     // Get the string to replace
961     tmpOutput = tmpOutput + replaceWith;
962     // Get the rest of the content after the match until
963     // the next match or the end of the content
964     intAfter = tmpContent.length - searchFor.length + 1;
965     tmpContent = tmpContent.substring(intBefore + searchFor.length);
966   }
967   return runCount+"|^|"+tmpOutput+tmpContent;
968 }
969
970 function replaceSpecialChars(html){ 
971    var specials = new Array("&cent;","&euro;","&pound;","&curren;","&yen;","&copy;","&reg;","&trade;","&divide;","&times;","&plusmn;","&frac14;","&frac12;","&frac34;","&deg;","&sup1;","&sup2;","&sup3;","&micro;","&laquo;","&raquo;","&lsquo;","&rsquo;","&lsaquo;","&rsaquo;","&sbquo;","&bdquo;","&ldquo;","&rdquo;","&iexcl;","&brvbar;","&sect;","&not;","&macr;","&para;","&middot;","&cedil;","&iquest;","&fnof;","&mdash;","&ndash;","&bull;","&hellip;","&permil;","&ordf;","&ordm;","&szlig;","&dagger;","&Dagger;","&eth;","&ETH;","&oslash;","&Oslash;","&thorn;","&THORN;","&oelig;","&OElig;","&scaron;","&Scaron;","&acute;","&circ;","&tilde;","&uml;","&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&ccedil;","&Ccedil;","&egrave;","&eacute;","&ecirc;","&euml;","&Egrave;","&Eacute;","&Ecirc;","&Euml;","&igrave;","&iacute;","&icirc;","&iuml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;","&ntilde;","&Ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&ugrave;","&uacute;","&ucirc;","&uuml;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&yacute;","&yuml;","&Yacute;","&Yuml;"); 
972    var unicodes = new Array("\u00a2","\u20ac","\u00a3","\u00a4","\u00a5","\u00a9","\u00ae","\u2122","\u00f7","\u00d7","\u00b1","\u00bc","\u00bd","\u00be","\u00b0","\u00b9","\u00b2","\u00b3","\u00b5","\u00ab","\u00bb","\u2018","\u2019","\u2039","\u203a","\u201a","\u201e","\u201c","\u201d","\u00a1","\u00a6","\u00a7","\u00ac","\u00af","\u00b6","\u00b7","\u00b8","\u00bf","\u0192","\u2014","\u2013","\u2022","\u2026","\u2030","\u00aa","\u00ba","\u00df","\u2020","\u2021","\u00f0","\u00d0","\u00f8","\u00d8","\u00fe","\u00de","\u0153","\u0152","\u0161","\u0160","\u00b4","\u02c6","\u02dc","\u00a8","\u00e0","\u00e1","\u00e2","\u00e3","\u00e4","\u00e5","\u00e6","\u00c0","\u00c1","\u00c2","\u00c3","\u00c4","\u00c5","\u00c6","\u00e7","\u00c7","\u00e8","\u00e9","\u00ea","\u00eb","\u00c8","\u00c9","\u00ca","\u00cb","\u00ec","\u00ed","\u00ee","\u00ef","\u00cc","\u00cd","\u00ce","\u00cf","\u00f1","\u00d1","\u00f2","\u00f3","\u00f4","\u00f5","\u00f6","\u00d2","\u00d3","\u00d4","\u00d5","\u00d6","\u00f9","\u00fa","\u00fb","\u00fc","\u00d9","\u00da","\u00db","\u00dc","\u00fd","\u00ff","\u00dd","\u0178"); 
973    for(var i=0; i<specials.length; i++){ 
974       html = replaceIt(html,unicodes[i],specials[i]); 
975    } 
976    return html; 
977 }
978
979 function SearchAndReplace(searchFor, replaceWith, matchCase, wholeWord) {
980    var cfrmMsg = lblSearchConfirm.replace("SF",searchFor).replace("RW",replaceWith);
981    var rte = currentRTE;
982    stripGuidelines(rte);
983    var oRTE = returnRTE(rte);
984    var tmpContent = oRTE.document.body.innerHTML.replace("'", "\'").replace('"', '\"');
985    var strRegex;
986    if (matchCase && wholeWord) {
987       strRegex = "/(?!<[^>]*)(\\b(" + searchFor + ")\\b)(?![^<]*>)/g";
988    }
989    else if (matchCase) {
990       strRegex = "/(?!<[^>]*)(" + searchFor + ")(?![^<]*>)/g";
991    }
992    else if (wholeWord) {
993       strRegex = "/(?!<[^>]*)(\\b(" + searchFor + ")\\b)(?![^<]*>)/gi";
994    } else {
995       strRegex = "/(?!<[^>]*)(" + searchFor + ")(?![^<]*>)/gi";
996    }
997    var cmpRegex=eval(strRegex);
998    var runCount = 0;
999    var tmpNext = tmpContent;
1000    var intFound = tmpNext.search(cmpRegex);
1001    while(intFound > -1) {
1002       runCount = runCount+1;
1003       tmpNext = tmpNext.substr(intFound + searchFor.length);
1004       intFound = tmpNext.search(cmpRegex);
1005    }
1006    if (runCount > 0) {
1007       cfrmMsg = cfrmMsg.replace("[RUNCOUNT]",runCount);
1008       if(confirm(cfrmMsg)) {
1009          tmpContent=tmpContent.replace(cmpRegex,replaceWith);
1010          oRTE.document.body.innerHTML = tmpContent.replace("\'", "'").replace('\"', '"');
1011       } else {
1012        alert(lblSearchAbort);
1013     }
1014       showGuidelines(rte);
1015    }
1016    else {
1017      showGuidelines(rte);
1018       alert("["+searchFor+"] "+lblSearchNotFound);
1019    }
1020 }
1021                 
1022 function showHideElement(element, showHide, rePosition){
1023         //function to show or hide elements
1024         //element variable can be string or object
1025         if(document.getElementById(element)){
1026                 element = document.getElementById(element);
1027         }
1028         if(showHide == "show"){
1029                 element.style.visibility = "visible";
1030           if(rePosition){
1031                   element.style.position = "relative";
1032             element.style.left = "auto";
1033             element.style.top = "auto";
1034     }
1035         }else if(showHide == "hide"){
1036                 element.style.visibility = "hidden";
1037     if(rePosition){
1038                         element.style.position = "absolute";
1039         element.style.left = "-1000px";
1040         element.style.top = "-1000px";
1041           }
1042   }
1043 }
1044
1045 function setRange(rte){
1046         //function to store range of current selection
1047         var oRTE = returnRTE(rte);
1048         var selection;
1049         if(document.all){  //IE
1050                 selection = oRTE.document.selection;
1051                 if(selection != null){
1052       rng = selection.createRange();
1053     }
1054         }else{
1055                 selection = oRTE.getSelection();
1056                 if(selection.rangeCount > 0) {
1057                   rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
1058                 } else {
1059                   rng = oRTE.document.createRange();
1060                 }
1061         }
1062         return rng;
1063 }
1064
1065 function stripHTML(strU) {
1066         //strip all html
1067         var strN = strU.replace(/(<([^>]+)>)/ig,"");
1068         //replace carriage returns and line feeds
1069   strN = strN.replace(/\r\n/g," ");
1070   strN = strN.replace(/\n/g," ");
1071   strN = strN.replace(/\r/g," ");
1072         strN = trim(strN);
1073         return strN;
1074 }
1075
1076 function trim(inputString) {
1077   if (typeof inputString != "string"){
1078     return inputString;
1079   }
1080   inputString = inputString.replace(/^\s+|\s+$/g, "").replace(/\s{2,}/g, "");
1081   return inputString;
1082 }
1083
1084 function showGuidelines(rte) { 
1085   if(rte.length == 0) rte = currentRTE; 
1086   var oRTE = returnRTE(rte); 
1087   var tables = oRTE.document.getElementsByTagName("table"); 
1088   var sty = "dashed 1px "+zeroBorder;
1089   for(var i=0; i<tables.length; i++){
1090     if(tables[i].getAttribute("border") == 0){
1091       if(document.all){
1092         var trs = tables[i].getElementsByTagName("tr");
1093         for(var j=0; j<trs.length; j++){
1094           var tds = trs[j].getElementsByTagName("td");
1095           for(var k=0; k<tds.length; k++){
1096                                   if(j == 0 && k == 0){
1097                                    tds[k].style.border = sty;
1098                                           }else if(j == 0 && k != 0){
1099                       tds[k].style.borderBottom = sty;
1100                                                   tds[k].style.borderTop = sty;
1101                                                   tds[k].style.borderRight = sty;
1102                   }else if(j != 0 && k == 0) {
1103                                 tds[k].style.borderBottom = sty;
1104                                             tds[k].style.borderLeft = sty;
1105                                                   tds[k].style.borderRight = sty;
1106             }else if(j != 0 && k != 0) {
1107               tds[k].style.borderBottom = sty;
1108                                             tds[k].style.borderRight = sty;
1109                         }
1110           }
1111         }  
1112       }else{  
1113         tables[i].removeAttribute("border"); 
1114         tables[i].setAttribute("style","border: " + sty); 
1115         tables[i].setAttribute("rules", "all");
1116       } 
1117     } 
1118   } 
1119
1120
1121 function stripGuidelines(rte) { 
1122   var oRTE = returnRTE(rte); 
1123   var tbls = oRTE.document.getElementsByTagName("table"); 
1124   for(var j=0; j<tbls.length; j++) { 
1125     if(tbls[j].getAttribute("border") == 0 || tbls[j].getAttribute("border") == null){
1126       if(document.all) {
1127         var tds = tbls[j].getElementsByTagName("td");
1128         for(var k=0; k<tds.length; k++) {
1129           tds[k].removeAttribute("style");
1130         }
1131       } else { 
1132         tbls[j].removeAttribute("style"); 
1133         tbls[j].removeAttribute("rules"); 
1134         tbls[j].setAttribute("border","0");
1135       } 
1136     } 
1137   } 
1138 }
1139
1140 function findSize(obj) {
1141   if(obj.length > 0 && document.all) {
1142           obj = frames[obj];
1143   } else if(obj.length > 0 && !document.all) {
1144           obj = document.getElementById(obj).contentWindow;
1145   } else {
1146     obj = this;
1147         }
1148         if ( typeof( obj.window.innerWidth ) == 'number' ) {
1149     //Non-IE
1150     obj_width = obj.window.innerWidth;
1151     obj_height = obj.window.innerHeight;
1152   } else if( obj.document.documentElement && ( obj.document.documentElement.clientWidth || obj.document.documentElement.clientHeight ) ) {
1153     //IE 6+ in 'standards compliant mode'
1154     obj_width = document.documentElement.clientWidth;
1155     obj_height = document.documentElement.clientHeight;
1156   } else if( obj.document.body && ( obj.document.body.clientWidth || obj.document.body.clientHeight ) ) {
1157     //IE 4 compatible
1158     obj_width = obj.document.body.clientWidth;
1159     obj_height = obj.document.body.clientHeight;
1160   }
1161 }
1162
1163 function resizeRTE() {
1164   document.body.style.overflow = "hidden";
1165         var rte = currentRTE;
1166   var oRTE = document.getElementById(rte);
1167   var oBut1 = document.getElementById('Buttons1_'+rte);
1168   var oBut2;
1169   var oVS = document.getElementById('vs'+rte);
1170   findSize("");
1171   width = obj_width;
1172   if (width < minWidth){
1173                 document.body.style.overflow = "auto";
1174                 width = minWidth;
1175         }
1176   var height = obj_height - 83;
1177         if (document.getElementById("_xtSrc"+rte).innerHTML == lblModeRichText){
1178           height = obj_height-28;
1179                 if (!document.getElementById('Buttons2_'+rte) && width < wrapWidth) {
1180             document.body.style.overflow = "auto";
1181                         width = wrapWidth;
1182                 }
1183                 if (document.getElementById('Buttons2_'+rte)){
1184       document.getElementById('Buttons2_'+rte).style.width = width;
1185     }
1186   } else {
1187     if (document.getElementById('Buttons2_'+rte)) {
1188                   document.getElementById('Buttons2_'+rte).style.width = width;
1189     } else {
1190                         height = obj_height - 55;
1191                         if(width < wrapWidth){
1192                           document.body.style.overflow = "auto";
1193                     width = wrapWidth;
1194                         }
1195     }
1196   }
1197   if(document.body.style.overflow == "auto" && isIE){
1198     height = height-18;
1199   } 
1200   if(document.body.style.overflow == "auto" && !isIE){
1201     height = height-24;
1202   }
1203   oBut1.style.width = width;
1204   oVS.style.width = width;
1205         oRTE.style.width = width-2;
1206   oRTE.style.height = height;
1207   if(!document.all){
1208     oRTE.contentDocument.designMode = "on";
1209   }
1210 }
1211
1212 function replaceIt(string,text,by) {
1213   // CM 19/10/04 custom replace function
1214   var strLength = string.length, _xtLength = text.length;
1215   if ((strLength == 0) || (_xtLength == 0)){
1216     return string;
1217   }
1218   var i = string.indexOf(text);
1219   if ((!i) && (text != string.substring(0,_xtLength))){
1220   return string;
1221   }
1222   if(i == -1){
1223     return string;
1224   }
1225   var newstr = string.substring(0,i) + by;
1226   if(i+_xtLength < strLength){
1227     newstr += replaceIt(string.substring(i+_xtLength,strLength),text,by);
1228   }
1229   return newstr;
1230 }
1231
1232 function countWords(rte){
1233   parseRTE(rte);
1234   var words = document.getElementById("hdn"+rte).value;
1235   var str = stripHTML(words);
1236   var chars = trim(words);
1237   chars = chars.length;
1238   chars = maxchar - chars;
1239   str = str+" a ";  // word added to avoid error
1240   str = trim(str.replace(/&nbsp;/gi,' ').replace(/([\n\r\t])/g,' ').replace(/&(.*);/g,' '));
1241   var count = 0;
1242   for(x=0;x<str.length;x++){
1243     if(str.charAt(x)==" " && str.charAt(x-1)!=" "){
1244       count++;
1245     }  
1246   }
1247   if(str.charAt(str.length-1) != " "){
1248     count++;
1249   } 
1250         count = count - 1; // extra word removed
1251         var alarm = "";
1252   if(chars<0){
1253     alarm = "\n\n"+lblCountCharWarn;
1254   }
1255   alert(lblCountTotal+": "+count+ "\n\n"+lblCountChar+": "+chars+alarm);
1256 }
1257
1258 //********************
1259 // Non-designMode() Functions
1260 //********************
1261 function autoBRon(rte) {
1262   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (and clean up other muck)
1263         var oRTE = document.forms[0].elements[rte];
1264         oRTE.value=parseBreaks(oRTE.value);
1265         oRTE.value=replaceIt(oRTE.value,'&apos;','\'');
1266 }
1267
1268 function autoBRoff(rte) {
1269   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (auto carried out when the form is submitted)
1270         var oRTE = document.forms[0].elements[rte];
1271         oRTE.value=replaceIt(oRTE.value,'\n','<br />');
1272         oRTE.value=replaceIt(oRTE.value,'\'','&apos;');
1273 }
1274
1275 function parseBreaks(argIn) {
1276   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (and clean up other muck)
1277   argIn=replaceIt(argIn,'<br>','\n');
1278         argIn=replaceIt(argIn,'<BR>','\n');
1279         argIn=replaceIt(argIn,'<br/>','\n');
1280         argIn=replaceIt(argIn,'<br />','\n');
1281         argIn=replaceIt(argIn,'\t',' ');
1282         argIn=replaceIt(argIn,'\n ','\n');
1283         argIn=replaceIt(argIn,' <p>','<p>');
1284         argIn=replaceIt(argIn,'</p><p>','\n\n');
1285         argIn=replaceIt(argIn,'&apos;','\'');
1286         argIn = trim(argIn);
1287         return argIn;
1288 }
1289
1290 //********************
1291 //Gecko-Only Functions
1292 //********************
1293 function geckoKeyPress(evt) {
1294         //function to add bold, italic, and underline shortcut commands to gecko RTEs
1295         //contributed by Anti Veeranna (thanks Anti!)
1296         var rte = evt.target.id;
1297         if (evt.ctrlKey) {
1298                 var key = String.fromCharCode(evt.charCode).toLowerCase();
1299                 var cmd = '';
1300                 switch (key) {
1301                         case 'b': cmd = "bold"; break;
1302                         case 'i': cmd = "italic"; break;
1303                         case 'u': cmd = "underline"; break;
1304                 }
1305                 if (cmd) {
1306                         rteCommand(rte, cmd, null);
1307                         // stop the event bubble
1308                         evt.preventDefault();
1309                         evt.stopPropagation();
1310                 }
1311         }
1312 }
1313
1314 //*****************
1315 //IE-Only Functions
1316 //*****************
1317 function checkspell() {
1318         dlgCleanUp();
1319         //function to perform spell check
1320         try {
1321                 var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
1322                 tmpis.CheckAllLinkedDocuments(document);
1323         }
1324         catch(exception) {
1325                 if(exception.number==-2146827859) {
1326                         if(confirm("ieSpell not detected.  Click Ok to go to download page.")){
1327         window.open("http://www.iespell.com/download.php","DownLoad");
1328       }
1329                 }else{
1330                         alert("Error Loading ieSpell: Exception " + exception.number);
1331                 }
1332         }
1333 }
1334
1335 //*****************
1336 //Validation
1337 //*****************
1338 function enableRTEvalidation(rteName) {
1339     document.getElementById(rteName+'SaveButton').onclick = function(event){
1340         updateRTEs();
1341             field = document.getElementById('hdn'+rteName);
1342             if(field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
1343                 event.preventDefault();
1344             }
1345         };
1346 }
1347