]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/WebContent/rtef/richtext.js
Salome HOME
3dada53abc36cea1123b0866b021f3c833006638
[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 = 450;                                     // 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" 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="submitEdit()"></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(isIE || isSafari || isKonqueror) {
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                   }
291                   if(isSafari || isKonqueror) {
292                           addCommand("paste","rteCommand('"+rte+"','InsertText')");
293 //                        insertImg(lblPaste,"paste.gif","rteCommand('"+rte+"','InsertText')");
294                   }
295                   if(isIE) {
296                           addCommand("paste","rteCommand('"+rte+"','paste')");
297 //                        insertImg(lblPaste,"paste.gif","rteCommand('"+rte+"','paste')");
298                   }
299                   if(!isSafari && !isKonqueror) {
300                           addCommand("pastetext","dlgLaunch('"+rte+"','text')");
301 //                        insertImg(lblPasteText,"pastetext.gif","dlgLaunch('"+rte+"','text')");
302                           addCommand("pasteword","dlgLaunch('"+rte+"','word')");
303 //                        insertImg(lblPasteWord,"pasteword.gif","dlgLaunch('"+rte+"','word')");
304                   }
305                   insertSep();
306                   addCommand("undo","rteCommand('"+rte+"','undo')");
307 //                insertImg(lblUndo,"undo.gif","rteCommand('"+rte+"','undo')");
308                   addCommand("redo","rteCommand('"+rte+"','redo')");
309 //                insertImg(lblRedo,"redo.gif","rteCommand('"+rte+"','redo')");
310                   if(!isSafari && !isKonqueror) {
311 //                        insertSep();
312 //        document.writeln('<td>');
313 //        document.writeln('<select id="formatblock_'+rte+'" onchange="selectFont(\''+rte+'\', this.id);return false" style="font-size:14px;width:105px;height:20px;margin:1px;">');
314 //                        document.writeln(lblFormat);
315 //                        document.writeln('</select></td><td>');
316 //                        document.writeln('<select id="fontname_'+rte+'" onchange="selectFont(\''+rte+'\', this.id);return false" style="font-size:14px;width:125px;height:20px;margin:1px;">');
317 //                        document.writeln(lblFont);
318 //                        document.writeln('</select></td><td>');
319 //                        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;">');
320 //                        document.writeln(lblSize);
321 //                        document.writeln('</select></td>');
322                   }
323                   if(tablewidth < iconWrapWidth){
324                           document.writeln('<td width="100%"></td></tr></tbody></table>');
325                           document.writeln('<table class="rteBk" cellpadding="0" cellspacing="0" id="Buttons2_'+rte+'" width="' + tablewidth + '">');
326                           document.writeln('<tbody><tr>');
327                   }
328                   insertBar();
329                   addCommand("bold","rteCommand('"+rte+"','bold')");
330 //                insertImg(lblBold,"bold.gif","rteCommand('"+rte+"','bold')");
331                   addCommand("italic","rteCommand('"+rte+"','italic')");
332 //                insertImg(lblItalic,"italic.gif","rteCommand('"+rte+"','italic')");
333                   addCommand("underline","rteCommand('"+rte+"','underline')");
334 //                insertImg(lblUnderline,"underline.gif","rteCommand('"+rte+"','underline')");
335                   //if(!isSafari && !isKonqueror) insertImg(lblStrikeThrough,"strikethrough.gif","rteCommand('"+rte+"','strikethrough')");
336                   //insertImg(lblSuperscript,"superscript.gif","rteCommand('"+rte+"','superscript')");
337                   //if(!isSafari && !isKonqueror){
338       //insertImg(lblSubscript,"subscript.gif","rteCommand('"+rte+"','subscript')");
339       //} else {
340       //insertImg(lblSubscript,"subscript.gif","rteCommand('"+rte+"','StyleChange',sub)");
341       //}
342                   insertSep();
343                   addCommand("left_just","rteCommand('"+rte+"','justifyleft')");
344 //                insertImg(lblAlgnLeft,"left_just.gif","rteCommand('"+rte+"','justifyleft')");
345                   addCommand("centre","rteCommand('"+rte+"','justifycenter')");
346 //                insertImg(lblAlgnCenter,"centre.gif","rteCommand('"+rte+"','justifycenter')");
347                   addCommand("right_just","rteCommand('"+rte+"','justifyright')");
348 //                insertImg(lblAlgnRight,"right_just.gif","rteCommand('"+rte+"','justifyright')");
349                   addCommand("justifyfull","rteCommand('"+rte+"','justifyfull')");
350 //                insertImg(lblJustifyFull,"justifyfull.gif","rteCommand('"+rte+"','justifyfull')");
351                   if(!isSafari && !isKonqueror) {
352                         insertSep();
353                           addCommand("numbered_list","rteCommand('"+rte+"','insertorderedlist')");
354 //                        insertImg(lblOL,"numbered_list.gif","rteCommand('"+rte+"','insertorderedlist')");
355                           addCommand("list","rteCommand('"+rte+"','insertunorderedlist')");
356 //                        insertImg(lblUL,"list.gif","rteCommand('"+rte+"','insertunorderedlist')");
357                           addCommand("outdent","rteCommand('"+rte+"','outdent')");
358 //                        insertImg(lblOutdent,"outdent.gif","rteCommand('"+rte+"','outdent')");
359                           addCommand("indent","rteCommand('"+rte+"','indent')");
360 //                        insertImg(lblIndent,"indent.gif","rteCommand('"+rte+"','indent')");
361                           insertSep();
362                           addCommand("textcolor","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
363 //                        insertImg(lblTextColor,"textcolor.gif","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
364                           addCommand("bgcolor","dlgColorPalette('"+rte+"','hilitecolor')","hilitecolor_"+rte);
365 //                        insertImg(lblBgColor,"bgcolor.gif","dlgColorPalette('"+rte+"','hilitecolor')","hilitecolor_"+rte);
366                           insertSep();
367                           addCommand("hr","rteCommand('"+rte+"','inserthorizontalrule')");
368 //                        insertImg(lblHR,"hr.gif","rteCommand('"+rte+"','inserthorizontalrule')");
369                           insertSep();
370                           addCommand("special_char","dlgLaunch('"+rte+"','char')");
371 //                        insertImg(lblInsertChar,"special_char.gif","dlgLaunch('"+rte+"','char')");
372                           addCommand("hyperlink","dlgLaunch('"+rte+"','link')");
373 //                        insertImg(lblInsertLink,"hyperlink.gif","dlgLaunch('"+rte+"','link')");
374                           addCommand("image","dlgLaunch('"+rte+"','image')");
375 //                        insertImg(lblAddImage,"image.gif","dlgLaunch('"+rte+"','image')");
376                           addCommand("insert_table","dlgLaunch('"+rte+"','table')");
377 //                        insertImg(lblInsertTable,"insert_table.gif","dlgLaunch('"+rte+"','table')");
378                   }
379                   insertSep();
380                   if(!isSafari && !isKonqueror) {
381                           addCommand("replace","dlgLaunch('"+rte+"','replace')");
382 //                        insertImg(lblSearch,"replace.gif","dlgLaunch('"+rte+"','replace')");
383                   }
384                   addCommand("word_count","countWords('"+rte+"')");
385 //                insertImg(lblWordCount,"word_count.gif","countWords('"+rte+"')");
386                   if(isIE) {
387                           addCommand("spellcheck","checkspell()");
388 //                        insertImg(lblSpellCheck,"spellcheck.gif","checkspell()");
389                   }
390                   document.writeln('<td width="100%"></td></tr></tbody></table>');
391           }
392           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>');
393           if(!readOnly){
394                   document.writeln('<table id="vs'+rte+'" name="vs'+rte+'" class="rteBk" cellpadding=0 cellspacing=0 border=0 width="' + tablewidth + '"><tr>');
395                   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>');
396                   document.writeln('<td width="100%" nowrap>&nbsp;</td></tr></table>');
397           }
398           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>');
399           document.writeln('<input type="hidden" id="hdn'+rte+'" name="'+rte+'" value="" style="position: absolute;left:-1000px;top:-1000px;">');
400           if(!fullscreen){
401                   document.writeln('<input type="hidden" id="size'+rte+'" name="size'+rte+'" value="'+height+'" style="position: absolute;left:-1000px;top:-1000px;">');
402           }
403           document.writeln('</span>');
404           document.getElementById('hdn'+rte).value = html;
405     enableDesignMode(rte, html, rte_css, readOnly);
406         } else {
407                 buttons = false;
408                 if(fullscreen && height > 90) {
409                         height = (height - 75);tablewidth=tablewidth-30;
410                 }
411                 // CM non-designMode() UI
412                 html = parseBreaks(html);
413                 document.writeln('<div style="font:12px Verdana, Arial, Helvetica, sans-serif;width: ' + tablewidth + 'px;padding:15px;">');
414                 if(!readOnly) {
415                         document.writeln('<div style="color:gray">'+lblnon_designMode+'</div><br>');
416                         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>');
417                         document.writeln('<textarea name="'+rte+'" id="'+rte+'" style="width: ' + tablewidth + 'px; height: ' + height + 'px;">' + html + '</textarea>');
418                 } else {
419                         document.writeln('<textarea name="'+rte+'" id="'+rte+'" style="width: ' + tablewidth + 'px; height: ' + height + 'px;" readonly=readonly>' + html + '</textarea>');
420                 }
421                 if(fullscreen) document.writeln('<br><input type="submit" value="'+btnText+'" />');
422                 document.writeln('</div>');
423         }
424 }
425
426 function insertBar() {
427         document.writeln('<td><img class="rteBar" src="'+imagesPath+'bar.gif" alt=""></td>');
428         nbcommand = 0;
429 }
430 function insertSep() {
431         if (nbcommand > 0) {
432           document.writeln('<td><img class="rteSep" src="'+imagesPath+'blackdot.gif" alt=""></td>');
433           nbcommand = 0;
434         }
435 }
436 function insertImg(name, image, command, id){
437           var td = "<td>";
438           if(id!=null){
439             td = "<td id='"+id+"'>";
440       }
441           document.writeln(td+'<img class="rteImg" src="'+imagesPath+image+'" alt="'+name+'" title="'+name+'" onMouseDown="'+command+';return false" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'"></td>');
442 }
443
444 function enableDesignMode(rte, html, css, readOnly) {
445         var frameHtml = "<html dir='" + lang_direction + "' lang='" + lang + "' id='" + rte + "'>\n<head>\n";
446         frameHtml += "<meta http-equiv='Content-Type' content='text/html; charset=" + encoding + "'>\n";
447         frameHtml += "<meta http-equiv='Content-Language' content='" + lang + "'>\n";
448         //to reference your stylesheet, set href property below to your stylesheet path and uncomment
449         if(css.length > 0) {
450                 frameHtml += "<link media=\"all\" type=\"text/css\" href=\"" + css + "\" rel=\"stylesheet\">\n";
451         } else {
452                 frameHtml += "<style>@charset \"utf-8\"; body {background:#FFFFFF;margin:8px;padding:0px;font-family:"+defaultFont+";font-size:"+defaultSize+";}</style>\n";
453         }
454         frameHtml += "</head><body>\n"+html+"\n</body></html>";
455         if(!isSafari && !isKonqueror) var oRTE = returnRTE(rte).document;
456         if (document.all) {
457                 if(isSafari || isKonqueror) var oRTE = frames[rte].document;
458                 oRTE.open("text/html","replace");
459                 oRTE.write(frameHtml);
460                 oRTE.close();
461                 if (!readOnly) {
462                         oRTE.designMode = "On";
463                 }
464         } else {
465                 try {
466                         // Commented out the following line to confront a bug when loading multiple RTEs on one page in a MOZ browser
467                         // Fix provided by "Kings". Safari may have problems with this snytax - unable to test because I don't own a MAC.(Tim Bell)
468                         //
469                         // if(!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
470                         if(!readOnly && !isKonqueror && !isSafari) {
471                 document.getElementById(rte).contentDocument.designMode = "on"; //RKV
472                                 addLoadEvent(function() { document.getElementById(rte).contentDocument.designMode = "on"; });
473                         } else if(!readOnly) {
474                                 if (!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
475                         }
476                         try {
477                                 
478                                 if(isSafari || isKonqueror) var oRTE = document.getElementById(rte).contentWindow.document;
479                                 oRTE.open("text/html","replace");
480                                 oRTE.write(frameHtml);
481                                 oRTE.close();
482                                 if(isGecko && !readOnly) {
483                                         //attach a keyboard handler for gecko browsers to make keyboard shortcuts work
484                                         oRTE.addEventListener("keypress", geckoKeyPress, true);
485                                         oRTE.addEventListener("focus", function (){dlgCleanUp();}, false);
486                                 }
487                         } catch(e) {
488                                 alert(lblErrorPreload);
489                         }
490                 } catch(e) {
491                         //gecko may take some time to enable design mode.
492                         //Keep looping until able to set.
493                         if(isGecko){
494                                 setTimeout("enableDesignMode('"+rte+"', '"+html+"', '"+css+"', "+readOnly+");", 200);
495                         }else{
496                                 return false;
497                         }
498                 }
499         }       
500         setTimeout('showGuidelines("'+rte+'")',300);
501 }
502
503 function addLoadEvent(func) {
504         var oldonload = window.onload;
505         if (typeof window.onload != 'function') {
506                 window.onload = func;
507         } else {
508                 window.onload = function() {
509                         oldonload();
510                         func();
511                 };
512         }
513 }
514
515 function returnRTE(rte) {
516         var rtn;
517         if(document.all){
518                 rtn = frames[rte];
519         } else {
520                 rtn = document.getElementById(rte).contentWindow;
521         }       
522         return rtn;
523 }
524
525 function updateRTE(rte) {
526         if(isRichText) {
527           dlgCleanUp(); //      Closes Pop-ups
528           stripGuidelines(rte); // Removes Table Guidelines
529   }
530         parseRTE(rte);
531 }
532
533 function updateRTEs(){
534         var vRTEs = allRTEs.split(";");
535         for(var i=0; i<vRTEs.length; i++){
536                 updateRTE(vRTEs[i]);
537         }
538 }
539
540 function parseRTE(rte) {
541         if (!isRichText) {
542                  autoBRoff(rte); // sorts out autoBR
543                  return false;
544         }
545         //check for readOnly mode
546         var readOnly = false;
547         var oRTE = returnRTE(rte);
548   if(document.all){
549                 if(oRTE.document.designMode != "On"){
550       readOnly = true;
551     }
552         }else{
553                 if(oRTE.document.designMode != "on"){
554       readOnly = true;
555     }
556         }
557         if(isRichText && !readOnly){
558                 //if viewing source, switch back to design view
559                 if(document.getElementById("_xtSrc"+rte).innerHTML == lblModeRichText){
560                          if(document.getElementById("Buttons1_"+rte)){
561                                  toggleHTMLSrc(rte, true);
562                          }else{
563          toggleHTMLSrc(rte, false);
564                          }
565                  stripGuidelines(rte);
566                 }
567                 setHiddenVal(rte);
568         }
569 }
570
571 function setHiddenVal(rte){
572         //set hidden form field value for current rte
573         var oHdnField = document.getElementById('hdn'+rte);
574         //convert html output to xhtml (thanks Timothy Bell and Vyacheslav Smolin!)
575         if(oHdnField.value==null){
576     oHdnField.value = "";
577         }
578   var sRTE = returnRTE(rte).document.body;
579         if(generateXHTML){
580           try{
581                   oHdnField.value = getXHTML(sRTE.innerHTML);
582           }catch(e){
583       oHdnField.value = sRTE.innerHTML;
584     }
585         }else{
586           oHdnField.value = sRTE.innerHTML;
587         }
588         // fix to replace special characters added here: 
589   oHdnField.value = replaceSpecialChars(oHdnField.value); 
590   //if there is no content (other than formatting) set value to nothing
591         if(stripHTML(oHdnField.value.replace("&nbsp;", " ")) == "" &&
592                 oHdnField.value.toLowerCase().search("<hr") == -1 &&
593                 oHdnField.value.toLowerCase().search("<img") == -1){
594     oHdnField.value = "";
595   }
596 }
597
598 function rteCommand(rte, command, option){
599         dlgCleanUp();
600   //function to perform command
601         var oRTE = returnRTE(rte);
602         try{
603                 oRTE.focus();
604                 oRTE.document.execCommand(command, false, option);
605                 oRTE.focus();
606         }catch(e){
607 //              alert(e);
608 //              setTimeout("rteCommand('" + rte + "', '" + command + "', '" + option + "');", 10);
609         }
610 }
611
612 function toggleHTMLSrc(rte, buttons){
613         dlgCleanUp();
614   //contributed by Bob Hutzel (thanks Bob!)
615   var cRTE = document.getElementById(rte);
616   var hRTE = document.getElementById('hdn'+rte);
617   var sRTE = document.getElementById("size"+rte);
618   var tRTE = document.getElementById("_xtSrc"+rte);
619   var iRTE = document.getElementById("imgSrc"+rte);
620   var oRTE = returnRTE(rte).document;
621   var htmlSrc;
622         if(sRTE){
623           obj_height = parseInt(sRTE.value);
624   }else{
625     findSize(rte);
626         }
627         if(tRTE.innerHTML == lblModeHTML){
628                 //we are checking the box
629                 tRTE.innerHTML = lblModeRichText;
630                 stripGuidelines(rte);
631                 if(buttons){
632                         showHideElement("Buttons1_" + rte, "hide", true);
633                         if(document.getElementById("Buttons2_"+rte)){
634                                 showHideElement("Buttons2_" + rte, "hide", true);
635                           cRTE.style.height = obj_height+56;
636                         }else{
637                                 cRTE.style.height = obj_height+28;
638                         }
639                 }
640                 setHiddenVal(rte);
641         if(document.all){
642                 oRTE.body.innerText = hRTE.value;
643                 }else{
644                 htmlSrc = oRTE.createTextNode(hRTE.value);
645                         oRTE.body.innerHTML = "";
646                         oRTE.body.appendChild(htmlSrc);
647                 }
648                 iRTE.innerHTML = '<img src="'+imagesPath+'design.gif" alt="Switch Mode" style="margin:1px;" align=absmiddle>';
649         }else{
650                 //we are unchecking the box
651                 obj_height = parseInt(cRTE.style.height);
652                 tRTE.innerHTML = lblModeHTML;
653                 if(buttons){
654                         showHideElement("Buttons1_" + rte, "show", true);
655                   if(document.getElementById("Buttons2_"+rte)){
656         showHideElement("Buttons2_" + rte, "show", true);
657                           cRTE.style.height = obj_height-56;
658                         }else{
659         cRTE.style.height = obj_height-28;
660       }
661                 }
662                 if(document.all){
663                         //fix for IE
664                         var output = escape(oRTE.body.innerText);
665                         output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
666                         output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
667                         oRTE.body.innerHTML = unescape(output);
668                         // Disabled due to flaw in the regular expressions, this fix 
669       // does not work with the revamped's enhanced insert link dialog window.
670       //
671       // Prevent links from changing to absolute paths
672       if(!keep_absolute){
673         var tagfix = unescape(output).match(/<a[^>]*href=(['"])([^\1>]*)\1[^>]*>/ig); 
674         var coll = oRTE.body.all.tags('A'); 
675         for(i=0; i<coll.length; i++){ 
676           // the 2 alerts below show when we hinder the links from becoming absolute                    
677           //alert(tagfix[i]); 
678           coll[i].href = tagfix[i].replace(/.*href=(['"])([^\1]*)\1.*/i,"$2"); 
679           //alert(RegExp.$1 + " " + RegExp.$2 + " " + RegExp.$3); 
680         } 
681         var imgfix = unescape(output).match(/<img[^>]*src=['"][^'"]*['"][^>]*>/ig); 
682         var coll2 = oRTE.body.all.tags('IMG'); 
683         for(i=0; i<coll2.length; i++){ 
684           coll2[i].src = imgfix[i].replace(/.*src=['"]([^'"]*)['"].*/i,"$1"); 
685         } 
686       }
687       //end path fix                    
688                 }else{
689                 htmlSrc = oRTE.body.ownerDocument.createRange();
690                         htmlSrc.selectNodeContents(oRTE.body);
691                         oRTE.body.innerHTML = htmlSrc.toString();
692                 }
693                 oRTE.body.innerHTML = replaceSpecialChars(oRTE.body.innerHTML);
694                 showGuidelines(rte);
695                 // (IE Only)This prevents an undo operation from displaying a pervious HTML mode
696                 // This resets the undo/redo buffer.
697                 if(document.all){
698                         parseRTE(rte);
699           }
700           iRTE.innerHTML = '<img src="'+imagesPath+'code.gif" alt="Switch Mode" style="margin:1px;" align=absmiddle>';
701         }
702 }
703
704 function toggleSelection(rte) {
705   var rng = setRange(rte);
706   var oRTE = returnRTE(rte).document;
707         var length1;
708   var length2;
709         if(document.all){
710                 length1 = rng.text.length;
711                 var output = escape(oRTE.body.innerText);
712                 output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
713                 output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
714                 length2 = unescape(output).length;
715         }else{
716                 length1 = rng.toString().length;
717                 var htmlSrc = oRTE.body.ownerDocument.createRange();
718                 htmlSrc.selectNodeContents(oRTE.body);
719           length2 = htmlSrc.toString().length;
720         }
721         if(length1 < length2){
722           rteCommand(rte,'selectall','');
723         } else {
724                 if(!document.all){
725                   oRTE.designMode = "off";
726                   oRTE.designMode = "on";
727                 }else{
728                   rteCommand(rte,'unselect','');
729                 }
730         }
731 }
732
733 function dlgColorPalette(rte, command) {
734         //function to display or hide color palettes
735         setRange(rte);
736         //get dialog position
737         var oDialog = document.getElementById('cp' + rte);
738         var buttonElement = document.getElementById(command+"_"+rte);
739         var iLeftPos = buttonElement.offsetLeft+5; 
740   var iTopPos = buttonElement.offsetTop+53;
741   if (!document.getElementById('Buttons2_'+rte)){
742     iTopPos = iTopPos-28;
743         }
744   oDialog.style.left = iLeftPos + "px";
745         oDialog.style.top = iTopPos + "px";
746         
747   if((command == parent.command)&&(rte == currentRTE)){
748                 //if current command dialog is currently open, close it
749                 if(oDialog.style.visibility == "hidden"){
750                         showHideElement(oDialog, 'show', false);
751                 }else{
752                         showHideElement(oDialog, 'hide', false);
753                 }
754         }else{
755                 //if opening a new dialog, close all others
756                 var vRTEs = allRTEs.split(";");
757                 for(var i = 0; i<vRTEs.length; i++){
758                         showHideElement('cp' + vRTEs[i], 'hide', false);
759                 }
760                 showHideElement(oDialog, 'show', false);
761         }
762         //save current values
763         currentRTE = rte;
764         parent.command = command;
765 }
766
767 function dlgLaunch(rte, command) {
768         var selectedText = '';
769   //save current values
770         parent.command = command;
771         currentRTE = rte;
772         switch(command){
773   case "char":
774     InsertChar = popUpWin(includesPath+'insert_char.htm', 'InsertChar', 50, 50, 'status=yes,');
775     break;
776   case "table":
777     InsertTable = popUpWin(includesPath + 'insert_table.htm', 'InsertTable', 50, 50, 'status=yes,');
778     break;
779   case "image":
780     setRange(rte);
781     parseRTE(rte);
782     InsertImg = popUpWin(includesPath + 'insert_img.htm','AddImage', 50, 50, 'status=yes,');
783     break;
784   case "link":
785     selectedText = getText(rte);
786     InsertLink = popUpWin(includesPath + 'insert_link.htm', 'InsertLink', 50, 50, 'status=yes,');
787     setFormText("0", selectedText);
788     break;
789   case "replace":
790     selectedText = getText(rte);
791     dlgReplace = popUpWin(includesPath + 'replace.htm', 'dlgReplace', 50, 50, 'status=yes,');
792     setFormText("1", selectedText);
793     break;
794   case "text":
795     dlgPasteText = popUpWin(includesPath + 'paste_text.htm', 'dlgPasteText', 50, 50, 'status=yes,');
796     break;
797   case "word":
798     dlgPasteWord = popUpWin(includesPath + 'paste_word.htm', 'dlgPasteWord', 50, 50, 'status=yes,');
799     break;
800   }
801 }
802
803 function getText(rte) {
804         //get currently highlighted text and set link text value
805   setRange(rte);
806         var rtn = '';
807         if (isIE) {
808           rtn = stripHTML(rng.htmlText);
809         } else {
810           rtn = stripHTML(rng.toString());
811         }
812         parseRTE(rte);
813         if(document.all){
814     rtn = rtn.replace("'","\\\\\\'");
815   }else{
816     rtn = rtn.replace("'","\\'");
817   }
818   return rtn;
819 }
820
821 function setFormText(popup, content){
822         //set link text value in dialog windows
823         if(content != "undefined")
824         {
825           try{
826                   switch(popup){
827                     case "0": InsertLink.document.getElementById("linkText").value = content; break;
828                     case "1": dlgReplace.document.getElementById("searchText").value = content; break;
829                   }
830           }catch(e){
831                   //may take some time to create dialog window.
832                   //Keep looping until able to set.
833                   setTimeout("setFormText('"+popup+"','" + content + "');", 10);
834           }
835         }
836 }
837
838 function dlgCleanUp(){
839         var vRTEs = allRTEs.split(";");
840         for(var i = 0; i < vRTEs.length; i++){
841           showHideElement('cp' + vRTEs[i], 'hide', false);
842         }
843         if(InsertChar != null){
844     InsertChar.close();
845     InsertChar=null;
846         }
847   if(InsertTable != null){
848     InsertTable.close();
849     InsertTable=null;
850         }
851   if(InsertLink != null){
852     InsertLink.close();
853     InsertLink=null;
854         }
855   if(InsertImg != null){
856     InsertImg.close();
857     InsertImg=null;
858         }
859   if(dlgReplace != null){
860     dlgReplace.close();
861     dlgReplace=null;
862         }
863   if(dlgPasteText != null){
864     dlgPasteText.close();
865     dlgPasteText=null;
866         }
867   if(dlgPasteWord != null){
868     dlgPasteWord.close();
869     dlgPasteWord=null;
870   }
871 }
872
873 function popUpWin (url, win, width, height, options) {
874   dlgCleanUp();
875         var leftPos = (screen.availWidth - width) / 2;
876         var topPos = (screen.availHeight - height) / 2;
877         options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
878         return window.open(url, win, options);
879 }
880
881 function setColor(color) {
882         //function to set color
883         var rte = currentRTE;
884         var parentCommand = parent.command;
885         if(document.all){
886                 if(parentCommand == "hilitecolor"){
887       parentCommand = "backcolor";
888     }
889                 //retrieve selected range
890                 rng.select();
891         }
892         rteCommand(rte, parentCommand, color);
893         showHideElement('cp'+rte, "hide", false);
894 }
895
896 function addImage(rte) {
897   dlgCleanUp();
898         //function to add image
899         imagePath = prompt('Enter Image URL:', 'http://');                              
900         if((imagePath != null)&&(imagePath != "")){
901                 rteCommand(rte, 'InsertImage', imagePath);
902         }
903 }
904
905 function rtePrint(rte) {
906   dlgCleanUp();
907         if(isIE){
908           document.getElementById(rte).contentWindow.document.execCommand('Print');
909   }else{
910           document.getElementById(rte).contentWindow.print();
911         }
912 }
913
914 function selectFont(rte, selectname){
915         //function to handle font changes
916         var idx = document.getElementById(selectname).selectedIndex;
917         // First one is always a label
918         if(idx != 0){
919                 var selected = document.getElementById(selectname).options[idx].value;
920                 var cmd = selectname.replace('_'+rte, '');
921                 rteCommand(rte, cmd, selected);
922                 document.getElementById(selectname).selectedIndex = 0;
923         }
924 }
925
926 function insertHTML(html){
927         //function to add HTML -- thanks dannyuk1982
928         var rte = currentRTE;
929         var oRTE = returnRTE(rte);
930         oRTE.focus();
931         if(document.all){
932                 var oRng = oRTE.document.selection.createRange();
933                 oRng.pasteHTML(html);
934                 oRng.collapse(false);
935                 oRng.select();
936         }else{
937                 oRTE.document.execCommand('insertHTML', false, html);
938         }
939 }
940
941 function replaceHTML(tmpContent, searchFor, replaceWith) {
942   var runCount = 0;
943         var intBefore = 0;
944         var intAfter = 0;
945         var tmpOutput = "";
946         while(tmpContent.toUpperCase().indexOf(searchFor.toUpperCase()) > -1) {
947     runCount = runCount+1;
948     // Get all content before the match
949     intBefore = tmpContent.toUpperCase().indexOf(searchFor.toUpperCase());
950     tmpBefore = tmpContent.substring(0, intBefore);
951     tmpOutput = tmpOutput + tmpBefore;
952     // Get the string to replace
953     tmpOutput = tmpOutput + replaceWith;
954     // Get the rest of the content after the match until
955     // the next match or the end of the content
956     intAfter = tmpContent.length - searchFor.length + 1;
957     tmpContent = tmpContent.substring(intBefore + searchFor.length);
958   }
959   return runCount+"|^|"+tmpOutput+tmpContent;
960 }
961
962 function replaceSpecialChars(html){ 
963    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;"); 
964    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"); 
965    for(var i=0; i<specials.length; i++){ 
966       html = replaceIt(html,unicodes[i],specials[i]); 
967    } 
968    return html; 
969 }
970
971 function SearchAndReplace(searchFor, replaceWith, matchCase, wholeWord) {
972    var cfrmMsg = lblSearchConfirm.replace("SF",searchFor).replace("RW",replaceWith);
973    var rte = currentRTE;
974    stripGuidelines(rte);
975    var oRTE = returnRTE(rte);
976    var tmpContent = oRTE.document.body.innerHTML.replace("'", "\'").replace('"', '\"');
977    var strRegex;
978    if (matchCase && wholeWord) {
979       strRegex = "/(?!<[^>]*)(\\b(" + searchFor + ")\\b)(?![^<]*>)/g";
980    }
981    else if (matchCase) {
982       strRegex = "/(?!<[^>]*)(" + searchFor + ")(?![^<]*>)/g";
983    }
984    else if (wholeWord) {
985       strRegex = "/(?!<[^>]*)(\\b(" + searchFor + ")\\b)(?![^<]*>)/gi";
986    } else {
987       strRegex = "/(?!<[^>]*)(" + searchFor + ")(?![^<]*>)/gi";
988    }
989    var cmpRegex=eval(strRegex);
990    var runCount = 0;
991    var tmpNext = tmpContent;
992    var intFound = tmpNext.search(cmpRegex);
993    while(intFound > -1) {
994       runCount = runCount+1;
995       tmpNext = tmpNext.substr(intFound + searchFor.length);
996       intFound = tmpNext.search(cmpRegex);
997    }
998    if (runCount > 0) {
999       cfrmMsg = cfrmMsg.replace("[RUNCOUNT]",runCount);
1000       if(confirm(cfrmMsg)) {
1001          tmpContent=tmpContent.replace(cmpRegex,replaceWith);
1002          oRTE.document.body.innerHTML = tmpContent.replace("\'", "'").replace('\"', '"');
1003       } else {
1004        alert(lblSearchAbort);
1005     }
1006       showGuidelines(rte);
1007    }
1008    else {
1009      showGuidelines(rte);
1010       alert("["+searchFor+"] "+lblSearchNotFound);
1011    }
1012 }
1013                 
1014 function showHideElement(element, showHide, rePosition){
1015         //function to show or hide elements
1016         //element variable can be string or object
1017         if(document.getElementById(element)){
1018                 element = document.getElementById(element);
1019         }
1020         if(showHide == "show"){
1021                 element.style.visibility = "visible";
1022           if(rePosition){
1023                   element.style.position = "relative";
1024             element.style.left = "auto";
1025             element.style.top = "auto";
1026     }
1027         }else if(showHide == "hide"){
1028                 element.style.visibility = "hidden";
1029     if(rePosition){
1030                         element.style.position = "absolute";
1031         element.style.left = "-1000px";
1032         element.style.top = "-1000px";
1033           }
1034   }
1035 }
1036
1037 function setRange(rte){
1038         //function to store range of current selection
1039         var oRTE = returnRTE(rte);
1040         var selection;
1041         if(document.all){
1042                 selection = oRTE.document.selection;
1043                 if(selection != null){
1044       rng = selection.createRange();
1045     }
1046         }else{
1047                 selection = oRTE.getSelection();
1048                 rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
1049         }
1050         return rng;
1051 }
1052
1053 function stripHTML(strU) {
1054         //strip all html
1055         var strN = strU.replace(/(<([^>]+)>)/ig,"");
1056         //replace carriage returns and line feeds
1057   strN = strN.replace(/\r\n/g," ");
1058   strN = strN.replace(/\n/g," ");
1059   strN = strN.replace(/\r/g," ");
1060         strN = trim(strN);
1061         return strN;
1062 }
1063
1064 function trim(inputString) {
1065   if (typeof inputString != "string"){
1066     return inputString;
1067   }
1068   inputString = inputString.replace(/^\s+|\s+$/g, "").replace(/\s{2,}/g, "");
1069   return inputString;
1070 }
1071
1072 function showGuidelines(rte) { 
1073   if(rte.length == 0) rte = currentRTE; 
1074   var oRTE = returnRTE(rte); 
1075   var tables = oRTE.document.getElementsByTagName("table"); 
1076   var sty = "dashed 1px "+zeroBorder;
1077   for(var i=0; i<tables.length; i++){
1078     if(tables[i].getAttribute("border") == 0){
1079       if(document.all){
1080         var trs = tables[i].getElementsByTagName("tr");
1081         for(var j=0; j<trs.length; j++){
1082           var tds = trs[j].getElementsByTagName("td");
1083           for(var k=0; k<tds.length; k++){
1084                                   if(j == 0 && k == 0){
1085                                    tds[k].style.border = sty;
1086                                           }else if(j == 0 && k != 0){
1087                       tds[k].style.borderBottom = sty;
1088                                                   tds[k].style.borderTop = sty;
1089                                                   tds[k].style.borderRight = sty;
1090                   }else if(j != 0 && k == 0) {
1091                                 tds[k].style.borderBottom = sty;
1092                                             tds[k].style.borderLeft = sty;
1093                                                   tds[k].style.borderRight = sty;
1094             }else if(j != 0 && k != 0) {
1095               tds[k].style.borderBottom = sty;
1096                                             tds[k].style.borderRight = sty;
1097                         }
1098           }
1099         }  
1100       }else{  
1101         tables[i].removeAttribute("border"); 
1102         tables[i].setAttribute("style","border: " + sty); 
1103         tables[i].setAttribute("rules", "all");
1104       } 
1105     } 
1106   } 
1107
1108
1109 function stripGuidelines(rte) { 
1110   var oRTE = returnRTE(rte); 
1111   var tbls = oRTE.document.getElementsByTagName("table"); 
1112   for(var j=0; j<tbls.length; j++) { 
1113     if(tbls[j].getAttribute("border") == 0 || tbls[j].getAttribute("border") == null){
1114       if(document.all) {
1115         var tds = tbls[j].getElementsByTagName("td");
1116         for(var k=0; k<tds.length; k++) {
1117           tds[k].removeAttribute("style");
1118         }
1119       } else { 
1120         tbls[j].removeAttribute("style"); 
1121         tbls[j].removeAttribute("rules"); 
1122         tbls[j].setAttribute("border","0");
1123       } 
1124     } 
1125   } 
1126 }
1127
1128 function findSize(obj) {
1129   if(obj.length > 0 && document.all) {
1130           obj = frames[obj];
1131   } else if(obj.length > 0 && !document.all) {
1132           obj = document.getElementById(obj).contentWindow;
1133   } else {
1134     obj = this;
1135         }
1136         if ( typeof( obj.window.innerWidth ) == 'number' ) {
1137     //Non-IE
1138     obj_width = obj.window.innerWidth;
1139     obj_height = obj.window.innerHeight;
1140   } else if( obj.document.documentElement && ( obj.document.documentElement.clientWidth || obj.document.documentElement.clientHeight ) ) {
1141     //IE 6+ in 'standards compliant mode'
1142     obj_width = document.documentElement.clientWidth;
1143     obj_height = document.documentElement.clientHeight;
1144   } else if( obj.document.body && ( obj.document.body.clientWidth || obj.document.body.clientHeight ) ) {
1145     //IE 4 compatible
1146     obj_width = obj.document.body.clientWidth;
1147     obj_height = obj.document.body.clientHeight;
1148   }
1149 }
1150
1151 function resizeRTE() {
1152   document.body.style.overflow = "hidden";
1153         var rte = currentRTE;
1154   var oRTE = document.getElementById(rte);
1155   var oBut1 = document.getElementById('Buttons1_'+rte);
1156   var oBut2;
1157   var oVS = document.getElementById('vs'+rte);
1158   findSize("");
1159   width = obj_width;
1160   if (width < minWidth){
1161                 document.body.style.overflow = "auto";
1162                 width = minWidth;
1163         }
1164   var height = obj_height - 83;
1165         if (document.getElementById("_xtSrc"+rte).innerHTML == lblModeRichText){
1166           height = obj_height-28;
1167                 if (!document.getElementById('Buttons2_'+rte) && width < wrapWidth) {
1168             document.body.style.overflow = "auto";
1169                         width = wrapWidth;
1170                 }
1171                 if (document.getElementById('Buttons2_'+rte)){
1172       document.getElementById('Buttons2_'+rte).style.width = width;
1173     }
1174   } else {
1175     if (document.getElementById('Buttons2_'+rte)) {
1176                   document.getElementById('Buttons2_'+rte).style.width = width;
1177     } else {
1178                         height = obj_height - 55;
1179                         if(width < wrapWidth){
1180                           document.body.style.overflow = "auto";
1181                     width = wrapWidth;
1182                         }
1183     }
1184   }
1185   if(document.body.style.overflow == "auto" && isIE){
1186     height = height-18;
1187   } 
1188   if(document.body.style.overflow == "auto" && !isIE){
1189     height = height-24;
1190   }
1191   oBut1.style.width = width;
1192   oVS.style.width = width;
1193         oRTE.style.width = width-2;
1194   oRTE.style.height = height;
1195   if(!document.all){
1196     oRTE.contentDocument.designMode = "on";
1197   }
1198 }
1199
1200 function replaceIt(string,text,by) {
1201   // CM 19/10/04 custom replace function
1202   var strLength = string.length, _xtLength = text.length;
1203   if ((strLength == 0) || (_xtLength == 0)){
1204     return string;
1205   }
1206   var i = string.indexOf(text);
1207   if ((!i) && (text != string.substring(0,_xtLength))){
1208   return string;
1209   }
1210   if(i == -1){
1211     return string;
1212   }
1213   var newstr = string.substring(0,i) + by;
1214   if(i+_xtLength < strLength){
1215     newstr += replaceIt(string.substring(i+_xtLength,strLength),text,by);
1216   }
1217   return newstr;
1218 }
1219
1220 function countWords(rte){
1221   parseRTE(rte);
1222   var words = document.getElementById("hdn"+rte).value;
1223   var str = stripHTML(words);
1224   var chars = trim(words);
1225   chars = chars.length;
1226   chars = maxchar - chars;
1227   str = str+" a ";  // word added to avoid error
1228   str = trim(str.replace(/&nbsp;/gi,' ').replace(/([\n\r\t])/g,' ').replace(/&(.*);/g,' '));
1229   var count = 0;
1230   for(x=0;x<str.length;x++){
1231     if(str.charAt(x)==" " && str.charAt(x-1)!=" "){
1232       count++;
1233     }  
1234   }
1235   if(str.charAt(str.length-1) != " "){
1236     count++;
1237   } 
1238         count = count - 1; // extra word removed
1239         var alarm = "";
1240   if(chars<0){
1241     alarm = "\n\n"+lblCountCharWarn;
1242   }
1243   alert(lblCountTotal+": "+count+ "\n\n"+lblCountChar+": "+chars+alarm);
1244 }
1245
1246 //********************
1247 // Non-designMode() Functions
1248 //********************
1249 function autoBRon(rte) {
1250   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (and clean up other muck)
1251         var oRTE = document.forms[0].elements[rte];
1252         oRTE.value=parseBreaks(oRTE.value);
1253         oRTE.value=replaceIt(oRTE.value,'&apos;','\'');
1254 }
1255
1256 function autoBRoff(rte) {
1257   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (auto carried out when the form is submitted)
1258         var oRTE = document.forms[0].elements[rte];
1259         oRTE.value=replaceIt(oRTE.value,'\n','<br />');
1260         oRTE.value=replaceIt(oRTE.value,'\'','&apos;');
1261 }
1262
1263 function parseBreaks(argIn) {
1264   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (and clean up other muck)
1265   argIn=replaceIt(argIn,'<br>','\n');
1266         argIn=replaceIt(argIn,'<BR>','\n');
1267         argIn=replaceIt(argIn,'<br/>','\n');
1268         argIn=replaceIt(argIn,'<br />','\n');
1269         argIn=replaceIt(argIn,'\t',' ');
1270         argIn=replaceIt(argIn,'\n ','\n');
1271         argIn=replaceIt(argIn,' <p>','<p>');
1272         argIn=replaceIt(argIn,'</p><p>','\n\n');
1273         argIn=replaceIt(argIn,'&apos;','\'');
1274         argIn = trim(argIn);
1275         return argIn;
1276 }
1277
1278 //********************
1279 //Gecko-Only Functions
1280 //********************
1281 function geckoKeyPress(evt) {
1282         //function to add bold, italic, and underline shortcut commands to gecko RTEs
1283         //contributed by Anti Veeranna (thanks Anti!)
1284         var rte = evt.target.id;
1285         if (evt.ctrlKey) {
1286                 var key = String.fromCharCode(evt.charCode).toLowerCase();
1287                 var cmd = '';
1288                 switch (key) {
1289                         case 'b': cmd = "bold"; break;
1290                         case 'i': cmd = "italic"; break;
1291                         case 'u': cmd = "underline"; break;
1292                 }
1293                 if (cmd) {
1294                         rteCommand(rte, cmd, null);
1295                         // stop the event bubble
1296                         evt.preventDefault();
1297                         evt.stopPropagation();
1298                 }
1299         }
1300 }
1301
1302 //*****************
1303 //IE-Only Functions
1304 //*****************
1305 function checkspell() {
1306         dlgCleanUp();
1307         //function to perform spell check
1308         try {
1309                 var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
1310                 tmpis.CheckAllLinkedDocuments(document);
1311         }
1312         catch(exception) {
1313                 if(exception.number==-2146827859) {
1314                         if(confirm("ieSpell not detected.  Click Ok to go to download page.")){
1315         window.open("http://www.iespell.com/download.php","DownLoad");
1316       }
1317                 }else{
1318                         alert("Error Loading ieSpell: Exception " + exception.number);
1319                 }
1320         }
1321 }