]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/WebContent/rtef/richtext.js
Salome HOME
1acd7a9fab570613095b7e22995a407b21b53adf
[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 minWidth = 450;                                     // minumum width
38 var wrapWidth = 1245;                       //width at which all icons will appear on one bar
39 var maxchar = 64000;                // maximum number of characters per save
40 var lang = "en";                                        //xhtml language
41 var lang_direction = "ltr";         //language direction : ltr = left-to-right, rtl = right-to-left 
42 var encoding = "utf-8";                     //xhtml encoding
43 var zeroBorder = "#c0c0c0";         //guideline color - see showGuidelines()
44 var btnText = "submit";                     //Button value for non-designMode() & fullsceen rte
45 var resize_fullsrcreen = true;
46 // (resize_fullsrcreen) limited in that: 1)won't auto wrap icons. 2)won't
47 // shrink to less than (wrapWidth)px if screen was initized over (wrapWidth)px;
48
49 var keep_absolute = true; // !!!Disabled - see line 456 for details!!!!!  
50 // By default IE will try to convery all hyperlinks to absolute paths. By
51 // setting this value to "false" it will retain the relative path.
52
53 // Pointers
54 var InsertChar;
55 var InsertTable;
56 var InsertLink;
57 var InsertImg;
58 var dlgReplace;
59 var dlgPasteText;
60 var dlgPasteWord;
61
62 //Init Variables & Attributes
63 var ua = navigator.userAgent.toLowerCase();
64 var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1))? true:false;
65 var isIE7 = ((isIE) && (ua.indexOf("msie 7.") != -1))? true:false;
66 var     isGecko = (ua.indexOf("gecko") != -1)? true:false;
67 var     isSafari = (ua.indexOf("safari") != -1)? true:false;
68 var safariVersion = parseFloat(ua.substring(ua.lastIndexOf("safari/") + 7));
69 var     isKonqueror = (ua.indexOf("konqueror") != -1)? true:false;
70 var rng;
71 var currentRTE;
72 var allRTEs = "";
73 var obj_width;
74 var obj_height;
75 var imagesPath;
76 var includesPath;
77 var cssFile;
78 var generateXHTML = true;
79 var isRichText = false;
80 //check to see if designMode mode is available
81 //Safari/Konqueror think they are designMode capable even though they are not
82 //if(document.getElementById && document.designMode && !isSafari && !isKonqueror){
83 if(document.getElementById && document.designMode) {
84         isRichText = true;
85 } else if ((isSafari && safariVersion >= 312) || isKonqueror) {
86         //Safari 1.3+ is capable of designMode, Safari 1.3 = webkit build 312
87         isRichText = true;
88 }
89 //for testing standard textarea, uncomment the following line
90 //isRichText = false;
91
92 var replacements = new Array (
93         new RegExp(String.fromCharCode(145),'g'), "'",
94         new RegExp(String.fromCharCode(146),'g'), "'",
95         new RegExp("'"), "'",
96         //convert all types of double quotes
97         new RegExp(String.fromCharCode(147),'g'), "\"",
98         new RegExp(String.fromCharCode(148),'g'), "\"",
99         new RegExp("\""), """,              //doesn't work
100         //replace carriage returns & line feeds
101         new RegExp("[\r\n]",'g'), " ");
102
103 function rteSafe(html) {
104         html = trim(html);
105         for (i=0; i<replacements.length; i = i+2) {
106                 html = html.replace(replacements[i], replacements[i+1]);
107         }
108         return html;
109 }
110
111 // [DBC]
112 var nbcommand     = 0;              // For not duplicating separators when no command between
113 var defaultFont   = "Times New Roman, Times, serif";
114 var defaultSize   = "13px";
115 var activeCommand = {               // Strait-forward HashMap
116         put : function(foo, bar)   {this[foo] = bar;},
117         get : function(foo) {return this[foo];}
118 }
119
120 function initTextInput() {
121     activeCommand.put("cut", lblCut);
122     activeCommand.put("copy", lblCopy);
123     activeCommand.put("paste", lblPaste);
124     activeCommand.put("undo", lblUndo);
125     activeCommand.put("redo", lblRedo);
126     activeCommand.put("bold", lblBold);
127     activeCommand.put("italic", lblItalic);
128     activeCommand.put("underline", lblUnderline);
129     activeCommand.put("list", lblUL);
130     activeCommand.put("numbered_list", lblOL);
131     activeCommand.put("indent", lblIndent);
132     activeCommand.put("outdent", lblOutdent);
133     activeCommand.put("replace", lblSearch);
134     activeCommand.put("hyperlink", lblInsertLink);
135
136     wrapWidth   = 14 * 24;
137     defaultFont = "Arial, Helvetica, sans-serif";
138     initRTE("../rtef/images/", "../rtef/", "", true);
139 }
140
141 function initTextEditor() {
142     activeCommand.put("save", lblSave);
143 //  activeCommand.put("print", lblPrint);
144     activeCommand.put("cut", lblCut);
145     activeCommand.put("copy", lblCopy);
146     activeCommand.put("paste", lblPaste);
147     activeCommand.put("undo", lblUndo);
148     activeCommand.put("redo", lblRedo);
149     activeCommand.put("bold", lblBold);
150     activeCommand.put("italic", lblItalic);
151     activeCommand.put("underline", lblUnderline);
152     activeCommand.put("list", lblUL);
153     activeCommand.put("numbered_list", lblOL);
154     activeCommand.put("indent", lblIndent);
155     activeCommand.put("outdent", lblOutdent);
156     activeCommand.put("replace", lblSearch);
157     activeCommand.put("hyperlink", lblInsertLink);
158
159     wrapWidth   = 15 * 24;
160     defaultFont = "Arial, Helvetica, sans-serif";
161     initRTE("../rtef/images/", "../rtef/", "", true);
162 }
163
164 function addCommand(name, action) {
165     var label = activeCommand.get(name);
166     if (label != null) {
167         insertImg(label, name + ".gif", action);
168         nbcommand += 1;
169     }
170 }
171
172 function displayTextEditor(inputname, initialtext, width, height) {
173     writeRichText(inputname, rteSafe(initialtext), '', width, height, true, false, false);
174 }
175 // [/DBC]
176
177 function initRTE(imgPath, incPath, css, genXHTML){
178         // CM 05/04/05 check args for compatibility with old RTE implementations
179         if (arguments.length == 3) {
180                 genXHTML = generateXHTML;
181         }
182         //set paths vars
183         imagesPath = imgPath;
184         includesPath = incPath;
185         cssFile = css;
186         generateXHTML = genXHTML;
187         if(isRichText){
188         document.writeln('<style type="text/css">@import "' + includesPath + 'rte.css";</style>');
189         }
190         if(!isIE){
191                 minWidth = minWidth-48;
192                 wrapWidth = wrapWidth-102;
193         }
194 }
195
196 function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscreen) {
197         currentRTE = rte;
198         if(allRTEs.length > 0){
199         allRTEs += ";";
200         }
201         allRTEs += rte;
202         // CM 06/04/05 stops single quotes from messing everything up
203         html=replaceIt(html,'\'','&apos;');
204         // CM 05/04/05 a bit of juggling for compatibility with old RTE implementations
205         if (arguments.length == 6) {
206                 fullscreen = false;
207                 readOnly = buttons;
208                 buttons = height;
209                 height = width;
210                 width = css;
211                 css = "";
212         }
213         var iconWrapWidth = wrapWidth;
214         var tablewidth;
215         if(readOnly) {
216                 buttons = false;
217         }
218         if(fullscreen) {
219                 readOnly = false; // fullscreen is not readOnly and must show buttons
220                 buttons = true;
221                 // resize rte on resize if the option resize_fullsrcreen = true.
222                 if(isRichText && resize_fullsrcreen) {
223                         window.onresize = resizeRTE;
224                 }
225                 document.body.style.margin = "0px";
226                 document.body.style.overflow = "hidden";
227                 //adjust maximum table widths
228                 findSize("");
229                 width = obj_width;
230                 if(width < iconWrapWidth) {
231                         height = (obj_height - 83);
232                 } else {
233                         height = (obj_height - 55);
234                 }
235                 if (width < minWidth) {
236                         document.body.style.overflow = "auto";
237                         if(isIE) {
238                                 height = obj_height-22;
239                         } else {
240                                 height = obj_height-24;
241                         }
242                         width = minWidth;
243                 }
244                 tablewidth = width;
245         } else {
246                 fullscreen = false;
247                 iconWrapWidth = iconWrapWidth-25;
248                 //adjust minimum table widths
249                 if(buttons && (width < minWidth)) {
250                   width = minWidth;
251           }
252           if(isIE){
253                   tablewidth = width;
254           } else {
255                   tablewidth = width + 4;
256           }
257   }
258   if(isRichText) {
259           var rte_css = "";
260           if(css.length > 0) {
261                   rte_css = css;
262           } else {
263                   rte_css = cssFile;
264           }
265           document.writeln('<span class="rteDiv">');
266           if(buttons) {
267                   document.writeln('<table class="rteBk" cellpadding=0 cellspacing=0 id="Buttons1_'+rte+'" width="' + tablewidth + '">');
268                   document.writeln('<tbody><tr>');
269                   insertBar();
270                   if(fullscreen || activeCommand.get("save") != null){
271                           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>');
272                           nbcommand += 1;
273                   }
274                   if(!isSafari && !isKonqueror) {
275                           addCommand("print","rtePrint('"+rte+"')");
276 //                        insertImg(lblPrint,"print.gif","rtePrint('"+rte+"')");
277                           insertSep();
278                           addCommand("selectall","toggleSelection('"+rte+"')");
279 //                        insertImg(lblSelectAll,"selectall.gif","toggleSelection('"+rte+"')");
280                           addCommand("unformat","rteCommand('"+rte+"','removeformat')");
281 //                        insertImg(lblUnformat,"unformat.gif","rteCommand('"+rte+"','removeformat')");
282                           insertSep();
283                   }
284                   if(isIE || isSafari || isKonqueror) {
285                           addCommand("cut","rteCommand('"+rte+"','cut')");
286 //                        insertImg(lblCut,"cut.gif","rteCommand('"+rte+"','cut')");
287                           addCommand("copy","rteCommand('"+rte+"','copy')");
288 //                        insertImg(lblCopy,"copy.gif","rteCommand('"+rte+"','copy')");
289                   }
290                   if(isSafari || isKonqueror) {
291                           addCommand("paste","rteCommand('"+rte+"','InsertText')");
292 //                        insertImg(lblPaste,"paste.gif","rteCommand('"+rte+"','InsertText')");
293                   }
294                   if(isIE) {
295                           addCommand("paste","rteCommand('"+rte+"','paste')");
296 //                        insertImg(lblPaste,"paste.gif","rteCommand('"+rte+"','paste')");
297                   }
298                   if(!isSafari && !isKonqueror) {
299                           addCommand("pastetext","dlgLaunch('"+rte+"','text')");
300 //                        insertImg(lblPasteText,"pastetext.gif","dlgLaunch('"+rte+"','text')");
301                           addCommand("pasteword","dlgLaunch('"+rte+"','word')");
302 //                        insertImg(lblPasteWord,"pasteword.gif","dlgLaunch('"+rte+"','word')");
303                   }
304                   insertSep();
305                   addCommand("undo","rteCommand('"+rte+"','undo')");
306 //                insertImg(lblUndo,"undo.gif","rteCommand('"+rte+"','undo')");
307                   addCommand("redo","rteCommand('"+rte+"','redo')");
308 //                insertImg(lblRedo,"redo.gif","rteCommand('"+rte+"','redo')");
309                   if(!isSafari && !isKonqueror) {
310 //                        insertSep();
311 //        document.writeln('<td>');
312 //        document.writeln('<select id="formatblock_'+rte+'" onchange="selectFont(\''+rte+'\', this.id);return false" style="font-size:14px;width:105px;height:20px;margin:1px;">');
313 //                        document.writeln(lblFormat);
314 //                        document.writeln('</select></td><td>');
315 //                        document.writeln('<select id="fontname_'+rte+'" onchange="selectFont(\''+rte+'\', this.id);return false" style="font-size:14px;width:125px;height:20px;margin:1px;">');
316 //                        document.writeln(lblFont);
317 //                        document.writeln('</select></td><td>');
318 //                        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;">');
319 //                        document.writeln(lblSize);
320 //                        document.writeln('</select></td>');
321                   }
322                   if(tablewidth < iconWrapWidth){
323                           document.writeln('<td width="100%"></td></tr></tbody></table>');
324                           document.writeln('<table class="rteBk" cellpadding="0" cellspacing="0" id="Buttons2_'+rte+'" width="' + tablewidth + '">');
325                           document.writeln('<tbody><tr>');
326                   }
327                   insertBar();
328                   addCommand("bold","rteCommand('"+rte+"','bold')");
329 //                insertImg(lblBold,"bold.gif","rteCommand('"+rte+"','bold')");
330                   addCommand("italic","rteCommand('"+rte+"','italic')");
331 //                insertImg(lblItalic,"italic.gif","rteCommand('"+rte+"','italic')");
332                   addCommand("underline","rteCommand('"+rte+"','underline')");
333 //                insertImg(lblUnderline,"underline.gif","rteCommand('"+rte+"','underline')");
334                   //if(!isSafari && !isKonqueror) insertImg(lblStrikeThrough,"strikethrough.gif","rteCommand('"+rte+"','strikethrough')");
335                   //insertImg(lblSuperscript,"superscript.gif","rteCommand('"+rte+"','superscript')");
336                   //if(!isSafari && !isKonqueror){
337       //insertImg(lblSubscript,"subscript.gif","rteCommand('"+rte+"','subscript')");
338       //} else {
339       //insertImg(lblSubscript,"subscript.gif","rteCommand('"+rte+"','StyleChange',sub)");
340       //}
341                   insertSep();
342                   addCommand("left_just","rteCommand('"+rte+"','justifyleft')");
343 //                insertImg(lblAlgnLeft,"left_just.gif","rteCommand('"+rte+"','justifyleft')");
344                   addCommand("centre","rteCommand('"+rte+"','justifycenter')");
345 //                insertImg(lblAlgnCenter,"centre.gif","rteCommand('"+rte+"','justifycenter')");
346                   addCommand("right_just","rteCommand('"+rte+"','justifyright')");
347 //                insertImg(lblAlgnRight,"right_just.gif","rteCommand('"+rte+"','justifyright')");
348                   addCommand("justifyfull","rteCommand('"+rte+"','justifyfull')");
349 //                insertImg(lblJustifyFull,"justifyfull.gif","rteCommand('"+rte+"','justifyfull')");
350                   if(!isSafari && !isKonqueror) {
351                         insertSep();
352                           addCommand("numbered_list","rteCommand('"+rte+"','insertorderedlist')");
353 //                        insertImg(lblOL,"numbered_list.gif","rteCommand('"+rte+"','insertorderedlist')");
354                           addCommand("list","rteCommand('"+rte+"','insertunorderedlist')");
355 //                        insertImg(lblUL,"list.gif","rteCommand('"+rte+"','insertunorderedlist')");
356                           addCommand("outdent","rteCommand('"+rte+"','outdent')");
357 //                        insertImg(lblOutdent,"outdent.gif","rteCommand('"+rte+"','outdent')");
358                           addCommand("indent","rteCommand('"+rte+"','indent')");
359 //                        insertImg(lblIndent,"indent.gif","rteCommand('"+rte+"','indent')");
360                           insertSep();
361                           addCommand("textcolor","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
362 //                        insertImg(lblTextColor,"textcolor.gif","dlgColorPalette('"+rte+"','forecolor')","forecolor_"+rte);
363                           addCommand("bgcolor","dlgColorPalette('"+rte+"','hilitecolor')","hilitecolor_"+rte);
364 //                        insertImg(lblBgColor,"bgcolor.gif","dlgColorPalette('"+rte+"','hilitecolor')","hilitecolor_"+rte);
365                           insertSep();
366                           addCommand("hr","rteCommand('"+rte+"','inserthorizontalrule')");
367 //                        insertImg(lblHR,"hr.gif","rteCommand('"+rte+"','inserthorizontalrule')");
368                           insertSep();
369                           addCommand("special_char","dlgLaunch('"+rte+"','char')");
370 //                        insertImg(lblInsertChar,"special_char.gif","dlgLaunch('"+rte+"','char')");
371                           addCommand("hyperlink","dlgLaunch('"+rte+"','link')");
372 //                        insertImg(lblInsertLink,"hyperlink.gif","dlgLaunch('"+rte+"','link')");
373                           addCommand("image","dlgLaunch('"+rte+"','image')");
374 //                        insertImg(lblAddImage,"image.gif","dlgLaunch('"+rte+"','image')");
375                           addCommand("insert_table","dlgLaunch('"+rte+"','table')");
376 //                        insertImg(lblInsertTable,"insert_table.gif","dlgLaunch('"+rte+"','table')");
377                   }
378                   insertSep();
379                   if(!isSafari && !isKonqueror) {
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+'" onMouseDown="'+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                                         oRTE.addEventListener("focus", function (){dlgCleanUp();}, false);
485                                 }
486                         } catch(e) {
487                                 alert(lblErrorPreload);
488                         }
489                 } catch(e) {
490                         //gecko may take some time to enable design mode.
491                         //Keep looping until able to set.
492                         if(isGecko){
493                                 setTimeout("enableDesignMode('"+rte+"', '"+html+"', '"+css+"', "+readOnly+");", 200);
494                         }else{
495                                 return false;
496                         }
497                 }
498         }       
499         setTimeout('showGuidelines("'+rte+'")',300);
500 }
501
502 function addLoadEvent(func) {
503         var oldonload = window.onload;
504         if (typeof window.onload != 'function') {
505                 window.onload = func;
506         } else {
507                 window.onload = function() {
508                         oldonload();
509                         func();
510                 };
511         }
512 }
513
514 function returnRTE(rte) {
515         var rtn;
516         if(document.all){
517                 rtn = frames[rte];
518         } else {
519                 rtn = document.getElementById(rte).contentWindow;
520         }       
521         return rtn;
522 }
523
524 function updateRTE(rte) {
525         if(isRichText) {
526           dlgCleanUp(); //      Closes Pop-ups
527           stripGuidelines(rte); // Removes Table Guidelines
528   }
529         parseRTE(rte);
530 }
531
532 function updateRTEs(){
533         var vRTEs = allRTEs.split(";");
534         for(var i=0; i<vRTEs.length; i++){
535                 updateRTE(vRTEs[i]);
536         }
537 }
538
539 function parseRTE(rte) {
540         if (!isRichText) {
541                  autoBRoff(rte); // sorts out autoBR
542                  return false;
543         }
544         //check for readOnly mode
545         var readOnly = false;
546         var oRTE = returnRTE(rte);
547   if(document.all){
548                 if(oRTE.document.designMode != "On"){
549       readOnly = true;
550     }
551         }else{
552                 if(oRTE.document.designMode != "on"){
553       readOnly = true;
554     }
555         }
556         if(isRichText && !readOnly){
557                 //if viewing source, switch back to design view
558                 if(document.getElementById("_xtSrc"+rte).innerHTML == lblModeRichText){
559                          if(document.getElementById("Buttons1_"+rte)){
560                                  toggleHTMLSrc(rte, true);
561                          }else{
562          toggleHTMLSrc(rte, false);
563                          }
564                  stripGuidelines(rte);
565                 }
566                 setHiddenVal(rte);
567         }
568 }
569
570 function setHiddenVal(rte){
571         //set hidden form field value for current rte
572         var oHdnField = document.getElementById('hdn'+rte);
573         //convert html output to xhtml (thanks Timothy Bell and Vyacheslav Smolin!)
574         if(oHdnField.value==null){
575     oHdnField.value = "";
576         }
577   var sRTE = returnRTE(rte).document.body;
578         if(generateXHTML){
579           try{
580                   oHdnField.value = getXHTML(sRTE.innerHTML);
581           }catch(e){
582       oHdnField.value = sRTE.innerHTML;
583     }
584         }else{
585           oHdnField.value = sRTE.innerHTML;
586         }
587         // fix to replace special characters added here: 
588   oHdnField.value = replaceSpecialChars(oHdnField.value); 
589   //if there is no content (other than formatting) set value to nothing
590         if(stripHTML(oHdnField.value.replace("&nbsp;", " ")) == "" &&
591                 oHdnField.value.toLowerCase().search("<hr") == -1 &&
592                 oHdnField.value.toLowerCase().search("<img") == -1){
593     oHdnField.value = "";
594   }
595 }
596
597 function rteCommand(rte, command, option){
598         dlgCleanUp();
599   //function to perform command
600         var oRTE = returnRTE(rte);
601         try{
602                 oRTE.focus();
603                 oRTE.document.execCommand(command, false, option);
604                 oRTE.focus();
605         }catch(e){
606 //              alert(e);
607 //              setTimeout("rteCommand('" + rte + "', '" + command + "', '" + option + "');", 10);
608         }
609 }
610
611 function toggleHTMLSrc(rte, buttons){
612         dlgCleanUp();
613   //contributed by Bob Hutzel (thanks Bob!)
614   var cRTE = document.getElementById(rte);
615   var hRTE = document.getElementById('hdn'+rte);
616   var sRTE = document.getElementById("size"+rte);
617   var tRTE = document.getElementById("_xtSrc"+rte);
618   var iRTE = document.getElementById("imgSrc"+rte);
619   var oRTE = returnRTE(rte).document;
620   var htmlSrc;
621         if(sRTE){
622           obj_height = parseInt(sRTE.value);
623   }else{
624     findSize(rte);
625         }
626         if(tRTE.innerHTML == lblModeHTML){
627                 //we are checking the box
628                 tRTE.innerHTML = lblModeRichText;
629                 stripGuidelines(rte);
630                 if(buttons){
631                         showHideElement("Buttons1_" + rte, "hide", true);
632                         if(document.getElementById("Buttons2_"+rte)){
633                                 showHideElement("Buttons2_" + rte, "hide", true);
634                           cRTE.style.height = obj_height+56;
635                         }else{
636                                 cRTE.style.height = obj_height+28;
637                         }
638                 }
639                 setHiddenVal(rte);
640         if(document.all){
641                 oRTE.body.innerText = hRTE.value;
642                 }else{
643                 htmlSrc = oRTE.createTextNode(hRTE.value);
644                         oRTE.body.innerHTML = "";
645                         oRTE.body.appendChild(htmlSrc);
646                 }
647                 iRTE.innerHTML = '<img src="'+imagesPath+'design.gif" alt="Switch Mode" style="margin:1px;" align=absmiddle>';
648         }else{
649                 //we are unchecking the box
650                 obj_height = parseInt(cRTE.style.height);
651                 tRTE.innerHTML = lblModeHTML;
652                 if(buttons){
653                         showHideElement("Buttons1_" + rte, "show", true);
654                   if(document.getElementById("Buttons2_"+rte)){
655         showHideElement("Buttons2_" + rte, "show", true);
656                           cRTE.style.height = obj_height-56;
657                         }else{
658         cRTE.style.height = obj_height-28;
659       }
660                 }
661                 if(document.all){
662                         //fix for IE
663                         var output = escape(oRTE.body.innerText);
664                         output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
665                         output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
666                         oRTE.body.innerHTML = unescape(output);
667                         // Disabled due to flaw in the regular expressions, this fix 
668       // does not work with the revamped's enhanced insert link dialog window.
669       //
670       // Prevent links from changing to absolute paths
671       if(!keep_absolute){
672         var tagfix = unescape(output).match(/<a[^>]*href=(['"])([^\1>]*)\1[^>]*>/ig); 
673         var coll = oRTE.body.all.tags('A'); 
674         for(i=0; i<coll.length; i++){ 
675           // the 2 alerts below show when we hinder the links from becoming absolute                    
676           //alert(tagfix[i]); 
677           coll[i].href = tagfix[i].replace(/.*href=(['"])([^\1]*)\1.*/i,"$2"); 
678           //alert(RegExp.$1 + " " + RegExp.$2 + " " + RegExp.$3); 
679         } 
680         var imgfix = unescape(output).match(/<img[^>]*src=['"][^'"]*['"][^>]*>/ig); 
681         var coll2 = oRTE.body.all.tags('IMG'); 
682         for(i=0; i<coll2.length; i++){ 
683           coll2[i].src = imgfix[i].replace(/.*src=['"]([^'"]*)['"].*/i,"$1"); 
684         } 
685       }
686       //end path fix                    
687                 }else{
688                 htmlSrc = oRTE.body.ownerDocument.createRange();
689                         htmlSrc.selectNodeContents(oRTE.body);
690                         oRTE.body.innerHTML = htmlSrc.toString();
691                 }
692                 oRTE.body.innerHTML = replaceSpecialChars(oRTE.body.innerHTML);
693                 showGuidelines(rte);
694                 // (IE Only)This prevents an undo operation from displaying a pervious HTML mode
695                 // This resets the undo/redo buffer.
696                 if(document.all){
697                         parseRTE(rte);
698           }
699           iRTE.innerHTML = '<img src="'+imagesPath+'code.gif" alt="Switch Mode" style="margin:1px;" align=absmiddle>';
700         }
701 }
702
703 function toggleSelection(rte) {
704   var rng = setRange(rte);
705   var oRTE = returnRTE(rte).document;
706         var length1;
707   var length2;
708         if(document.all){
709                 length1 = rng.text.length;
710                 var output = escape(oRTE.body.innerText);
711                 output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
712                 output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
713                 length2 = unescape(output).length;
714         }else{
715                 length1 = rng.toString().length;
716                 var htmlSrc = oRTE.body.ownerDocument.createRange();
717                 htmlSrc.selectNodeContents(oRTE.body);
718           length2 = htmlSrc.toString().length;
719         }
720         if(length1 < length2){
721           rteCommand(rte,'selectall','');
722         } else {
723                 if(!document.all){
724                   oRTE.designMode = "off";
725                   oRTE.designMode = "on";
726                 }else{
727                   rteCommand(rte,'unselect','');
728                 }
729         }
730 }
731
732 function dlgColorPalette(rte, command) {
733         //function to display or hide color palettes
734         setRange(rte);
735         //get dialog position
736         var oDialog = document.getElementById('cp' + rte);
737         var buttonElement = document.getElementById(command+"_"+rte);
738         var iLeftPos = buttonElement.offsetLeft+5; 
739   var iTopPos = buttonElement.offsetTop+53;
740   if (!document.getElementById('Buttons2_'+rte)){
741     iTopPos = iTopPos-28;
742         }
743   oDialog.style.left = iLeftPos + "px";
744         oDialog.style.top = iTopPos + "px";
745         
746   if((command == parent.command)&&(rte == currentRTE)){
747                 //if current command dialog is currently open, close it
748                 if(oDialog.style.visibility == "hidden"){
749                         showHideElement(oDialog, 'show', false);
750                 }else{
751                         showHideElement(oDialog, 'hide', false);
752                 }
753         }else{
754                 //if opening a new dialog, close all others
755                 var vRTEs = allRTEs.split(";");
756                 for(var i = 0; i<vRTEs.length; i++){
757                         showHideElement('cp' + vRTEs[i], 'hide', false);
758                 }
759                 showHideElement(oDialog, 'show', false);
760         }
761         //save current values
762         currentRTE = rte;
763         parent.command = command;
764 }
765
766 function dlgLaunch(rte, command) {
767         var selectedText = '';
768   //save current values
769         parent.command = command;
770         currentRTE = rte;
771         switch(command){
772   case "char":
773     InsertChar = popUpWin(includesPath+'insert_char.htm', 'InsertChar', 50, 50, 'status=yes,');
774     break;
775   case "table":
776     InsertTable = popUpWin(includesPath + 'insert_table.htm', 'InsertTable', 50, 50, 'status=yes,');
777     break;
778   case "image":
779     setRange(rte);
780     parseRTE(rte);
781     InsertImg = popUpWin(includesPath + 'insert_img.htm','AddImage', 50, 50, 'status=yes,');
782     break;
783   case "link":
784     selectedText = getText(rte);
785     InsertLink = popUpWin(includesPath + 'insert_link.htm', 'InsertLink', 50, 50, 'status=yes,');
786     setFormText("0", selectedText);
787     break;
788   case "replace":
789     selectedText = getText(rte);
790     dlgReplace = popUpWin(includesPath + 'replace.htm', 'dlgReplace', 50, 50, 'status=yes,');
791     setFormText("1", selectedText);
792     break;
793   case "text":
794     dlgPasteText = popUpWin(includesPath + 'paste_text.htm', 'dlgPasteText', 50, 50, 'status=yes,');
795     break;
796   case "word":
797     dlgPasteWord = popUpWin(includesPath + 'paste_word.htm', 'dlgPasteWord', 50, 50, 'status=yes,');
798     break;
799   }
800 }
801
802 function getText(rte) {
803         //get currently highlighted text and set link text value
804   setRange(rte);
805         var rtn = '';
806         if (isIE) {
807           rtn = stripHTML(rng.htmlText);
808         } else {
809           rtn = stripHTML(rng.toString());
810         }
811         parseRTE(rte);
812         if(document.all){
813     rtn = rtn.replace("'","\\\\\\'");
814   }else{
815     rtn = rtn.replace("'","\\'");
816   }
817   return rtn;
818 }
819
820 function setFormText(popup, content){
821         //set link text value in dialog windows
822         if(content != "undefined")
823         {
824           try{
825                   switch(popup){
826                     case "0": InsertLink.document.getElementById("linkText").value = content; break;
827                     case "1": dlgReplace.document.getElementById("searchText").value = content; break;
828                   }
829           }catch(e){
830                   //may take some time to create dialog window.
831                   //Keep looping until able to set.
832                   setTimeout("setFormText('"+popup+"','" + content + "');", 10);
833           }
834         }
835 }
836
837 function dlgCleanUp(){
838         var vRTEs = allRTEs.split(";");
839         for(var i = 0; i < vRTEs.length; i++){
840           showHideElement('cp' + vRTEs[i], 'hide', false);
841         }
842         if(InsertChar != null){
843     InsertChar.close();
844     InsertChar=null;
845         }
846   if(InsertTable != null){
847     InsertTable.close();
848     InsertTable=null;
849         }
850   if(InsertLink != null){
851     InsertLink.close();
852     InsertLink=null;
853         }
854   if(InsertImg != null){
855     InsertImg.close();
856     InsertImg=null;
857         }
858   if(dlgReplace != null){
859     dlgReplace.close();
860     dlgReplace=null;
861         }
862   if(dlgPasteText != null){
863     dlgPasteText.close();
864     dlgPasteText=null;
865         }
866   if(dlgPasteWord != null){
867     dlgPasteWord.close();
868     dlgPasteWord=null;
869   }
870 }
871
872 function popUpWin (url, win, width, height, options) {
873   dlgCleanUp();
874         var leftPos = (screen.availWidth - width) / 2;
875         var topPos = (screen.availHeight - height) / 2;
876         options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
877         return window.open(url, win, options);
878 }
879
880 function setColor(color) {
881         //function to set color
882         var rte = currentRTE;
883         var parentCommand = parent.command;
884         if(document.all){
885                 if(parentCommand == "hilitecolor"){
886       parentCommand = "backcolor";
887     }
888                 //retrieve selected range
889                 rng.select();
890         }
891         rteCommand(rte, parentCommand, color);
892         showHideElement('cp'+rte, "hide", false);
893 }
894
895 function addImage(rte) {
896   dlgCleanUp();
897         //function to add image
898         imagePath = prompt('Enter Image URL:', 'http://');                              
899         if((imagePath != null)&&(imagePath != "")){
900                 rteCommand(rte, 'InsertImage', imagePath);
901         }
902 }
903
904 function rtePrint(rte) {
905   dlgCleanUp();
906         if(isIE){
907           document.getElementById(rte).contentWindow.document.execCommand('Print');
908   }else{
909           document.getElementById(rte).contentWindow.print();
910         }
911 }
912
913 function selectFont(rte, selectname){
914         //function to handle font changes
915         var idx = document.getElementById(selectname).selectedIndex;
916         // First one is always a label
917         if(idx != 0){
918                 var selected = document.getElementById(selectname).options[idx].value;
919                 var cmd = selectname.replace('_'+rte, '');
920                 rteCommand(rte, cmd, selected);
921                 document.getElementById(selectname).selectedIndex = 0;
922         }
923 }
924
925 function insertHTML(html){
926         //function to add HTML -- thanks dannyuk1982
927         var rte = currentRTE;
928         var oRTE = returnRTE(rte);
929         oRTE.focus();
930         if(document.all){
931                 var oRng = oRTE.document.selection.createRange();
932                 oRng.pasteHTML(html);
933                 oRng.collapse(false);
934                 oRng.select();
935         }else{
936                 oRTE.document.execCommand('insertHTML', false, html);
937         }
938 }
939
940 function replaceHTML(tmpContent, searchFor, replaceWith) {
941   var runCount = 0;
942         var intBefore = 0;
943         var intAfter = 0;
944         var tmpOutput = "";
945         while(tmpContent.toUpperCase().indexOf(searchFor.toUpperCase()) > -1) {
946     runCount = runCount+1;
947     // Get all content before the match
948     intBefore = tmpContent.toUpperCase().indexOf(searchFor.toUpperCase());
949     tmpBefore = tmpContent.substring(0, intBefore);
950     tmpOutput = tmpOutput + tmpBefore;
951     // Get the string to replace
952     tmpOutput = tmpOutput + replaceWith;
953     // Get the rest of the content after the match until
954     // the next match or the end of the content
955     intAfter = tmpContent.length - searchFor.length + 1;
956     tmpContent = tmpContent.substring(intBefore + searchFor.length);
957   }
958   return runCount+"|^|"+tmpOutput+tmpContent;
959 }
960
961 function replaceSpecialChars(html){ 
962    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;"); 
963    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"); 
964    for(var i=0; i<specials.length; i++){ 
965       html = replaceIt(html,unicodes[i],specials[i]); 
966    } 
967    return html; 
968 }
969
970 function SearchAndReplace(searchFor, replaceWith, matchCase, wholeWord) {
971    var cfrmMsg = lblSearchConfirm.replace("SF",searchFor).replace("RW",replaceWith);
972    var rte = currentRTE;
973    stripGuidelines(rte);
974    var oRTE = returnRTE(rte);
975    var tmpContent = oRTE.document.body.innerHTML.replace("'", "\'").replace('"', '\"');
976    var strRegex;
977    if (matchCase && wholeWord) {
978       strRegex = "/(?!<[^>]*)(\\b(" + searchFor + ")\\b)(?![^<]*>)/g";
979    }
980    else if (matchCase) {
981       strRegex = "/(?!<[^>]*)(" + searchFor + ")(?![^<]*>)/g";
982    }
983    else if (wholeWord) {
984       strRegex = "/(?!<[^>]*)(\\b(" + searchFor + ")\\b)(?![^<]*>)/gi";
985    } else {
986       strRegex = "/(?!<[^>]*)(" + searchFor + ")(?![^<]*>)/gi";
987    }
988    var cmpRegex=eval(strRegex);
989    var runCount = 0;
990    var tmpNext = tmpContent;
991    var intFound = tmpNext.search(cmpRegex);
992    while(intFound > -1) {
993       runCount = runCount+1;
994       tmpNext = tmpNext.substr(intFound + searchFor.length);
995       intFound = tmpNext.search(cmpRegex);
996    }
997    if (runCount > 0) {
998       cfrmMsg = cfrmMsg.replace("[RUNCOUNT]",runCount);
999       if(confirm(cfrmMsg)) {
1000          tmpContent=tmpContent.replace(cmpRegex,replaceWith);
1001          oRTE.document.body.innerHTML = tmpContent.replace("\'", "'").replace('\"', '"');
1002       } else {
1003        alert(lblSearchAbort);
1004     }
1005       showGuidelines(rte);
1006    }
1007    else {
1008      showGuidelines(rte);
1009       alert("["+searchFor+"] "+lblSearchNotFound);
1010    }
1011 }
1012                 
1013 function showHideElement(element, showHide, rePosition){
1014         //function to show or hide elements
1015         //element variable can be string or object
1016         if(document.getElementById(element)){
1017                 element = document.getElementById(element);
1018         }
1019         if(showHide == "show"){
1020                 element.style.visibility = "visible";
1021           if(rePosition){
1022                   element.style.position = "relative";
1023             element.style.left = "auto";
1024             element.style.top = "auto";
1025     }
1026         }else if(showHide == "hide"){
1027                 element.style.visibility = "hidden";
1028     if(rePosition){
1029                         element.style.position = "absolute";
1030         element.style.left = "-1000px";
1031         element.style.top = "-1000px";
1032           }
1033   }
1034 }
1035
1036 function setRange(rte){
1037         //function to store range of current selection
1038         var oRTE = returnRTE(rte);
1039         var selection;
1040         if(document.all){
1041                 selection = oRTE.document.selection;
1042                 if(selection != null){
1043       rng = selection.createRange();
1044     }
1045         }else{
1046                 selection = oRTE.getSelection();
1047                 rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
1048         }
1049         return rng;
1050 }
1051
1052 function stripHTML(strU) {
1053         //strip all html
1054         var strN = strU.replace(/(<([^>]+)>)/ig,"");
1055         //replace carriage returns and line feeds
1056   strN = strN.replace(/\r\n/g," ");
1057   strN = strN.replace(/\n/g," ");
1058   strN = strN.replace(/\r/g," ");
1059         strN = trim(strN);
1060         return strN;
1061 }
1062
1063 function trim(inputString) {
1064   if (typeof inputString != "string"){
1065     return inputString;
1066   }
1067   inputString = inputString.replace(/^\s+|\s+$/g, "").replace(/\s{2,}/g, "");
1068   return inputString;
1069 }
1070
1071 function showGuidelines(rte) { 
1072   if(rte.length == 0) rte = currentRTE; 
1073   var oRTE = returnRTE(rte); 
1074   var tables = oRTE.document.getElementsByTagName("table"); 
1075   var sty = "dashed 1px "+zeroBorder;
1076   for(var i=0; i<tables.length; i++){
1077     if(tables[i].getAttribute("border") == 0){
1078       if(document.all){
1079         var trs = tables[i].getElementsByTagName("tr");
1080         for(var j=0; j<trs.length; j++){
1081           var tds = trs[j].getElementsByTagName("td");
1082           for(var k=0; k<tds.length; k++){
1083                                   if(j == 0 && k == 0){
1084                                    tds[k].style.border = sty;
1085                                           }else if(j == 0 && k != 0){
1086                       tds[k].style.borderBottom = sty;
1087                                                   tds[k].style.borderTop = sty;
1088                                                   tds[k].style.borderRight = sty;
1089                   }else if(j != 0 && k == 0) {
1090                                 tds[k].style.borderBottom = sty;
1091                                             tds[k].style.borderLeft = sty;
1092                                                   tds[k].style.borderRight = sty;
1093             }else if(j != 0 && k != 0) {
1094               tds[k].style.borderBottom = sty;
1095                                             tds[k].style.borderRight = sty;
1096                         }
1097           }
1098         }  
1099       }else{  
1100         tables[i].removeAttribute("border"); 
1101         tables[i].setAttribute("style","border: " + sty); 
1102         tables[i].setAttribute("rules", "all");
1103       } 
1104     } 
1105   } 
1106
1107
1108 function stripGuidelines(rte) { 
1109   var oRTE = returnRTE(rte); 
1110   var tbls = oRTE.document.getElementsByTagName("table"); 
1111   for(var j=0; j<tbls.length; j++) { 
1112     if(tbls[j].getAttribute("border") == 0 || tbls[j].getAttribute("border") == null){
1113       if(document.all) {
1114         var tds = tbls[j].getElementsByTagName("td");
1115         for(var k=0; k<tds.length; k++) {
1116           tds[k].removeAttribute("style");
1117         }
1118       } else { 
1119         tbls[j].removeAttribute("style"); 
1120         tbls[j].removeAttribute("rules"); 
1121         tbls[j].setAttribute("border","0");
1122       } 
1123     } 
1124   } 
1125 }
1126
1127 function findSize(obj) {
1128   if(obj.length > 0 && document.all) {
1129           obj = frames[obj];
1130   } else if(obj.length > 0 && !document.all) {
1131           obj = document.getElementById(obj).contentWindow;
1132   } else {
1133     obj = this;
1134         }
1135         if ( typeof( obj.window.innerWidth ) == 'number' ) {
1136     //Non-IE
1137     obj_width = obj.window.innerWidth;
1138     obj_height = obj.window.innerHeight;
1139   } else if( obj.document.documentElement && ( obj.document.documentElement.clientWidth || obj.document.documentElement.clientHeight ) ) {
1140     //IE 6+ in 'standards compliant mode'
1141     obj_width = document.documentElement.clientWidth;
1142     obj_height = document.documentElement.clientHeight;
1143   } else if( obj.document.body && ( obj.document.body.clientWidth || obj.document.body.clientHeight ) ) {
1144     //IE 4 compatible
1145     obj_width = obj.document.body.clientWidth;
1146     obj_height = obj.document.body.clientHeight;
1147   }
1148 }
1149
1150 function resizeRTE() {
1151   document.body.style.overflow = "hidden";
1152         var rte = currentRTE;
1153   var oRTE = document.getElementById(rte);
1154   var oBut1 = document.getElementById('Buttons1_'+rte);
1155   var oBut2;
1156   var oVS = document.getElementById('vs'+rte);
1157   findSize("");
1158   width = obj_width;
1159   if (width < minWidth){
1160                 document.body.style.overflow = "auto";
1161                 width = minWidth;
1162         }
1163   var height = obj_height - 83;
1164         if (document.getElementById("_xtSrc"+rte).innerHTML == lblModeRichText){
1165           height = obj_height-28;
1166                 if (!document.getElementById('Buttons2_'+rte) && width < wrapWidth) {
1167             document.body.style.overflow = "auto";
1168                         width = wrapWidth;
1169                 }
1170                 if (document.getElementById('Buttons2_'+rte)){
1171       document.getElementById('Buttons2_'+rte).style.width = width;
1172     }
1173   } else {
1174     if (document.getElementById('Buttons2_'+rte)) {
1175                   document.getElementById('Buttons2_'+rte).style.width = width;
1176     } else {
1177                         height = obj_height - 55;
1178                         if(width < wrapWidth){
1179                           document.body.style.overflow = "auto";
1180                     width = wrapWidth;
1181                         }
1182     }
1183   }
1184   if(document.body.style.overflow == "auto" && isIE){
1185     height = height-18;
1186   } 
1187   if(document.body.style.overflow == "auto" && !isIE){
1188     height = height-24;
1189   }
1190   oBut1.style.width = width;
1191   oVS.style.width = width;
1192         oRTE.style.width = width-2;
1193   oRTE.style.height = height;
1194   if(!document.all){
1195     oRTE.contentDocument.designMode = "on";
1196   }
1197 }
1198
1199 function replaceIt(string,text,by) {
1200   // CM 19/10/04 custom replace function
1201   var strLength = string.length, _xtLength = text.length;
1202   if ((strLength == 0) || (_xtLength == 0)){
1203     return string;
1204   }
1205   var i = string.indexOf(text);
1206   if ((!i) && (text != string.substring(0,_xtLength))){
1207   return string;
1208   }
1209   if(i == -1){
1210     return string;
1211   }
1212   var newstr = string.substring(0,i) + by;
1213   if(i+_xtLength < strLength){
1214     newstr += replaceIt(string.substring(i+_xtLength,strLength),text,by);
1215   }
1216   return newstr;
1217 }
1218
1219 function countWords(rte){
1220   parseRTE(rte);
1221   var words = document.getElementById("hdn"+rte).value;
1222   var str = stripHTML(words);
1223   var chars = trim(words);
1224   chars = chars.length;
1225   chars = maxchar - chars;
1226   str = str+" a ";  // word added to avoid error
1227   str = trim(str.replace(/&nbsp;/gi,' ').replace(/([\n\r\t])/g,' ').replace(/&(.*);/g,' '));
1228   var count = 0;
1229   for(x=0;x<str.length;x++){
1230     if(str.charAt(x)==" " && str.charAt(x-1)!=" "){
1231       count++;
1232     }  
1233   }
1234   if(str.charAt(str.length-1) != " "){
1235     count++;
1236   } 
1237         count = count - 1; // extra word removed
1238         var alarm = "";
1239   if(chars<0){
1240     alarm = "\n\n"+lblCountCharWarn;
1241   }
1242   alert(lblCountTotal+": "+count+ "\n\n"+lblCountChar+": "+chars+alarm);
1243 }
1244
1245 //********************
1246 // Non-designMode() Functions
1247 //********************
1248 function autoBRon(rte) {
1249   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (and clean up other muck)
1250         var oRTE = document.forms[0].elements[rte];
1251         oRTE.value=parseBreaks(oRTE.value);
1252         oRTE.value=replaceIt(oRTE.value,'&apos;','\'');
1253 }
1254
1255 function autoBRoff(rte) {
1256   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (auto carried out when the form is submitted)
1257         var oRTE = document.forms[0].elements[rte];
1258         oRTE.value=replaceIt(oRTE.value,'\n','<br />');
1259         oRTE.value=replaceIt(oRTE.value,'\'','&apos;');
1260 }
1261
1262 function parseBreaks(argIn) {
1263   // CM 19/10/04 used for non RTE browsers to deal with auto <BR> (and clean up other muck)
1264   argIn=replaceIt(argIn,'<br>','\n');
1265         argIn=replaceIt(argIn,'<BR>','\n');
1266         argIn=replaceIt(argIn,'<br/>','\n');
1267         argIn=replaceIt(argIn,'<br />','\n');
1268         argIn=replaceIt(argIn,'\t',' ');
1269         argIn=replaceIt(argIn,'\n ','\n');
1270         argIn=replaceIt(argIn,' <p>','<p>');
1271         argIn=replaceIt(argIn,'</p><p>','\n\n');
1272         argIn=replaceIt(argIn,'&apos;','\'');
1273         argIn = trim(argIn);
1274         return argIn;
1275 }
1276
1277 //********************
1278 //Gecko-Only Functions
1279 //********************
1280 function geckoKeyPress(evt) {
1281         //function to add bold, italic, and underline shortcut commands to gecko RTEs
1282         //contributed by Anti Veeranna (thanks Anti!)
1283         var rte = evt.target.id;
1284         if (evt.ctrlKey) {
1285                 var key = String.fromCharCode(evt.charCode).toLowerCase();
1286                 var cmd = '';
1287                 switch (key) {
1288                         case 'b': cmd = "bold"; break;
1289                         case 'i': cmd = "italic"; break;
1290                         case 'u': cmd = "underline"; break;
1291                 }
1292                 if (cmd) {
1293                         rteCommand(rte, cmd, null);
1294                         // stop the event bubble
1295                         evt.preventDefault();
1296                         evt.stopPropagation();
1297                 }
1298         }
1299 }
1300
1301 //*****************
1302 //IE-Only Functions
1303 //*****************
1304 function checkspell() {
1305         dlgCleanUp();
1306         //function to perform spell check
1307         try {
1308                 var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
1309                 tmpis.CheckAllLinkedDocuments(document);
1310         }
1311         catch(exception) {
1312                 if(exception.number==-2146827859) {
1313                         if(confirm("ieSpell not detected.  Click Ok to go to download page.")){
1314         window.open("http://www.iespell.com/download.php","DownLoad");
1315       }
1316                 }else{
1317                         alert("Error Loading ieSpell: Exception " + exception.number);
1318                 }
1319         }
1320 }