]> git.donarmstrong.com Git - roundcube.git/blob - program/js/tiny_mce/tiny_mce_src.js
Imported Upstream version 0.1
[roundcube.git] / program / js / tiny_mce / tiny_mce_src.js
1
2 /* file:jscripts/tiny_mce/classes/TinyMCE_Engine.class.js */
3
4 function TinyMCE_Engine() {
5         var ua;
6
7         this.majorVersion = "2";
8         this.minorVersion = "1.3";
9         this.releaseDate = "2007-11-27";
10
11         this.instances = [];
12         this.switchClassCache = [];
13         this.windowArgs = [];
14         this.loadedFiles = [];
15         this.pendingFiles = [];
16         this.loadingIndex = 0;
17         this.configs = [];
18         this.currentConfig = 0;
19         this.eventHandlers = [];
20         this.log = [];
21         this.undoLevels = [];
22         this.undoIndex = 0;
23         this.typingUndoIndex = -1;
24         this.settings = [];
25
26         // Browser check
27         ua = navigator.userAgent;
28         this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
29         this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1);
30         this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1);
31         this.isMSIE7 = this.isMSIE && (ua.indexOf('MSIE 7') != -1);
32         this.isGecko = ua.indexOf('Gecko') != -1; // Will also be true on Safari
33         this.isSafari = ua.indexOf('Safari') != -1;
34         this.isOpera = window['opera'] && opera.buildNumber ? true : false;
35         this.isMac = ua.indexOf('Mac') != -1;
36         this.isNS7 = ua.indexOf('Netscape/7') != -1;
37         this.isNS71 = ua.indexOf('Netscape/7.1') != -1;
38         this.dialogCounter = 0;
39         this.plugins = [];
40         this.themes = [];
41         this.menus = [];
42         this.loadedPlugins = [];
43         this.buttonMap = [];
44         this.isLoaded = false;
45
46         // Fake MSIE on Opera and if Opera fakes IE, Gecko or Safari cancel those
47         if (this.isOpera) {
48                 this.isMSIE = true;
49                 this.isGecko = false;
50                 this.isSafari =  false;
51         }
52
53         this.isIE = this.isMSIE;
54         this.isRealIE = this.isMSIE && !this.isOpera;
55
56         // TinyMCE editor id instance counter
57         this.idCounter = 0;
58 };
59
60 TinyMCE_Engine.prototype = {
61         init : function(settings) {
62                 var theme, nl, baseHREF = "", i, cssPath, entities, h, p, src, elements = [], head;
63
64                 // IE 5.0x is no longer supported since 5.5, 6.0 and 7.0 now exists. We can't support old browsers forever, sorry.
65                 if (this.isMSIE5_0)
66                         return;
67
68                 this.settings = settings;
69
70                 // Check if valid browser has execcommand support
71                 if (typeof(document.execCommand) == 'undefined')
72                         return;
73
74                 // Get script base path
75                 if (!tinyMCE.baseURL) {
76                         // Search through head
77                         head = document.getElementsByTagName('head')[0];
78
79                         if (head) {
80                                 for (i=0, nl = head.getElementsByTagName('script'); i<nl.length; i++)
81                                         elements.push(nl[i]);
82                         }
83
84                         // Search through rest of document
85                         for (i=0, nl = document.getElementsByTagName('script'); i<nl.length; i++)
86                                 elements.push(nl[i]);
87
88                         // If base element found, add that infront of baseURL
89                         nl = document.getElementsByTagName('base');
90                         for (i=0; i<nl.length; i++) {
91                                 if (nl[i].href)
92                                         baseHREF = nl[i].href;
93                         }
94
95                         for (i=0; i<elements.length; i++) {
96                                 if (elements[i].src && (elements[i].src.indexOf("tiny_mce.js") != -1 || elements[i].src.indexOf("tiny_mce_dev.js") != -1 || elements[i].src.indexOf("tiny_mce_src.js") != -1 || elements[i].src.indexOf("tiny_mce_gzip") != -1)) {
97                                         src = elements[i].src;
98
99                                         tinyMCE.srcMode = (src.indexOf('_src') != -1 || src.indexOf('_dev') != -1) ? '_src' : '';
100                                         tinyMCE.gzipMode = src.indexOf('_gzip') != -1;
101                                         src = src.substring(0, src.lastIndexOf('/'));
102
103                                         if (settings.exec_mode == "src" || settings.exec_mode == "normal")
104                                                 tinyMCE.srcMode = settings.exec_mode == "src" ? '_src' : '';
105
106                                         // Force it absolute if page has a base href
107                                         if (baseHREF !== '' && src.indexOf('://') == -1)
108                                                 tinyMCE.baseURL = baseHREF + src;
109                                         else
110                                                 tinyMCE.baseURL = src;
111
112                                         break;
113                                 }
114                         }
115                 }
116
117                 // Get document base path
118                 this.documentBasePath = document.location.href;
119                 if (this.documentBasePath.indexOf('?') != -1)
120                         this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.indexOf('?'));
121                 this.documentURL = this.documentBasePath;
122                 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.lastIndexOf('/'));
123
124                 // If not HTTP absolute
125                 if (tinyMCE.baseURL.indexOf('://') == -1 && tinyMCE.baseURL.charAt(0) != '/') {
126                         // If site absolute
127                         tinyMCE.baseURL = this.documentBasePath + "/" + tinyMCE.baseURL;
128                 }
129
130                 // Set default values on settings
131                 this._def("mode", "none");
132                 this._def("theme", "advanced");
133                 this._def("plugins", "", true);
134                 this._def("language", "en");
135                 this._def("docs_language", this.settings.language);
136                 this._def("elements", "");
137                 this._def("textarea_trigger", "mce_editable");
138                 this._def("editor_selector", "");
139                 this._def("editor_deselector", "mceNoEditor");
140                 this._def("valid_elements", "+a[id|style|rel|rev|charset|hreflang|dir|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],-strong/-b[class|style],-em/-i[class|style],-strike[class|style],-u[class|style],#p[id|style|dir|class|align],-ol[class|style],-ul[class|style],-li[class|style],br,img[id|dir|lang|longdesc|usemap|style|class|src|onmouseover|onmouseout|border|alt=|title|hspace|vspace|width|height|align],-sub[style|class],-sup[style|class],-blockquote[dir|style],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|style|dir|id|lang|bgcolor|background|bordercolor],-tr[id|lang|dir|class|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor],tbody[id|class],thead[id|class],tfoot[id|class],#td[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor|scope],-th[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|scope],caption[id|lang|dir|class|style],-div[id|dir|class|align|style],-span[style|class|align],-pre[class|align|style],address[class|align|style],-h1[id|style|dir|class|align],-h2[id|style|dir|class|align],-h3[id|style|dir|class|align],-h4[id|style|dir|class|align],-h5[id|style|dir|class|align],-h6[id|style|dir|class|align],hr[class|style],-font[face|size|style|id|class|dir|color],dd[id|class|title|style|dir|lang],dl[id|class|title|style|dir|lang],dt[id|class|title|style|dir|lang],cite[title|id|class|style|dir|lang],abbr[title|id|class|style|dir|lang],acronym[title|id|class|style|dir|lang],del[title|id|class|style|dir|lang|datetime|cite],ins[title|id|class|style|dir|lang|datetime|cite]");
141                 this._def("extended_valid_elements", "");
142                 this._def("invalid_elements", "");
143                 this._def("encoding", "");
144                 this._def("urlconverter_callback", tinyMCE.getParam("urlconvertor_callback", "TinyMCE_Engine.prototype.convertURL"));
145                 this._def("save_callback", "");
146                 this._def("force_br_newlines", false);
147                 this._def("force_p_newlines", true);
148                 this._def("add_form_submit_trigger", true);
149                 this._def("relative_urls", true);
150                 this._def("remove_script_host", true);
151                 this._def("focus_alert", true);
152                 this._def("document_base_url", this.documentURL);
153                 this._def("visual", true);
154                 this._def("visual_table_class", "mceVisualAid");
155                 this._def("setupcontent_callback", "");
156                 this._def("fix_content_duplication", true);
157                 this._def("custom_undo_redo", true);
158                 this._def("custom_undo_redo_levels", -1);
159                 this._def("custom_undo_redo_keyboard_shortcuts", true);
160                 this._def("custom_undo_redo_restore_selection", true);
161                 this._def("custom_undo_redo_global", false);
162                 this._def("verify_html", true);
163                 this._def("apply_source_formatting", false);
164                 this._def("directionality", "ltr");
165                 this._def("cleanup_on_startup", false);
166                 this._def("inline_styles", false);
167                 this._def("convert_newlines_to_brs", false);
168                 this._def("auto_reset_designmode", true);
169                 this._def("entities", "39,#39,160,nbsp,161,iexcl,162,cent,163,pound,164,curren,165,yen,166,brvbar,167,sect,168,uml,169,copy,170,ordf,171,laquo,172,not,173,shy,174,reg,175,macr,176,deg,177,plusmn,178,sup2,179,sup3,180,acute,181,micro,182,para,183,middot,184,cedil,185,sup1,186,ordm,187,raquo,188,frac14,189,frac12,190,frac34,191,iquest,192,Agrave,193,Aacute,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,201,Eacute,202,Ecirc,203,Euml,204,Igrave,205,Iacute,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,211,Oacute,212,Ocirc,213,Otilde,214,Ouml,215,times,216,Oslash,217,Ugrave,218,Uacute,219,Ucirc,220,Uuml,221,Yacute,222,THORN,223,szlig,224,agrave,225,aacute,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,233,eacute,234,ecirc,235,euml,236,igrave,237,iacute,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,243,oacute,244,ocirc,245,otilde,246,ouml,247,divide,248,oslash,249,ugrave,250,uacute,251,ucirc,252,uuml,253,yacute,254,thorn,255,yuml,402,fnof,913,Alpha,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,977,thetasym,978,upsih,982,piv,8226,bull,8230,hellip,8242,prime,8243,Prime,8254,oline,8260,frasl,8472,weierp,8465,image,8476,real,8482,trade,8501,alefsym,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8704,forall,8706,part,8707,exist,8709,empty,8711,nabla,8712,isin,8713,notin,8715,ni,8719,prod,8721,sum,8722,minus,8727,lowast,8730,radic,8733,prop,8734,infin,8736,ang,8743,and,8744,or,8745,cap,8746,cup,8747,int,8756,there4,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8804,le,8805,ge,8834,sub,8835,sup,8836,nsub,8838,sube,8839,supe,8853,oplus,8855,otimes,8869,perp,8901,sdot,8968,lceil,8969,rceil,8970,lfloor,8971,rfloor,9001,lang,9002,rang,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,34,quot,38,amp,60,lt,62,gt,338,OElig,339,oelig,352,Scaron,353,scaron,376,Yuml,710,circ,732,tilde,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,8211,ndash,8212,mdash,8216,lsquo,8217,rsquo,8218,sbquo,8220,ldquo,8221,rdquo,8222,bdquo,8224,dagger,8225,Dagger,8240,permil,8249,lsaquo,8250,rsaquo,8364,euro", true);
170                 this._def("entity_encoding", "named");
171                 this._def("cleanup_callback", "");
172                 this._def("add_unload_trigger", true);
173                 this._def("ask", false);
174                 this._def("nowrap", false);
175                 this._def("auto_resize", false);
176                 this._def("auto_focus", false);
177                 this._def("cleanup", true);
178                 this._def("remove_linebreaks", true);
179                 this._def("button_tile_map", false);
180                 this._def("submit_patch", true);
181                 this._def("browsers", "msie,safari,gecko,opera", true);
182                 this._def("dialog_type", "window");
183                 this._def("accessibility_warnings", true);
184                 this._def("accessibility_focus", true);
185                 this._def("merge_styles_invalid_parents", "");
186                 this._def("force_hex_style_colors", true);
187                 this._def("trim_span_elements", true);
188                 this._def("convert_fonts_to_spans", false);
189                 this._def("doctype", '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
190                 this._def("font_size_classes", '');
191                 this._def("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large', true);
192                 this._def("event_elements", 'a,img', true);
193                 this._def("convert_urls", true);
194                 this._def("table_inline_editing", false);
195                 this._def("object_resizing", true);
196                 this._def("custom_shortcuts", true);
197                 this._def("convert_on_click", false);
198                 this._def("content_css", '');
199                 this._def("fix_list_elements", true);
200                 this._def("fix_table_elements", false);
201                 this._def("strict_loading_mode", document.contentType == 'application/xhtml+xml');
202                 this._def("hidden_tab_class", '');
203                 this._def("display_tab_class", '');
204                 this._def("gecko_spellcheck", false);
205                 this._def("hide_selects_on_submit", true);
206                 this._def("forced_root_block", false);
207                 this._def("remove_trailing_nbsp", false);
208                 this._def("save_on_tinymce_forms", false);
209
210                 // Force strict loading mode to false on non Gecko browsers
211                 if (this.isMSIE && !this.isOpera)
212                         this.settings.strict_loading_mode = false;
213
214                 // Browser check IE
215                 if (this.isMSIE && this.settings.browsers.indexOf('msie') == -1)
216                         return;
217
218                 // Browser check Gecko
219                 if (this.isGecko && this.settings.browsers.indexOf('gecko') == -1)
220                         return;
221
222                 // Browser check Safari
223                 if (this.isSafari && this.settings.browsers.indexOf('safari') == -1)
224                         return;
225
226                 // Browser check Opera
227                 if (this.isOpera && this.settings.browsers.indexOf('opera') == -1)
228                         return;
229
230                 // If not super absolute make it so
231                 baseHREF = tinyMCE.settings.document_base_url;
232                 h = document.location.href;
233                 p = h.indexOf('://');
234                 if (p > 0 && document.location.protocol != "file:") {
235                         p = h.indexOf('/', p + 3);
236                         h = h.substring(0, p);
237
238                         if (baseHREF.indexOf('://') == -1)
239                                 baseHREF = h + baseHREF;
240
241                         tinyMCE.settings.document_base_url = baseHREF;
242                         tinyMCE.settings.document_base_prefix = h;
243                 }
244
245                 // Trim away query part
246                 if (baseHREF.indexOf('?') != -1)
247                         baseHREF = baseHREF.substring(0, baseHREF.indexOf('?'));
248
249                 this.settings.base_href = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/";
250
251                 theme = this.settings.theme;
252                 this.inlineStrict = 'A|BR|SPAN|BDO|MAP|OBJECT|IMG|TT|I|B|BIG|SMALL|EM|STRONG|DFN|CODE|Q|SAMP|KBD|VAR|CITE|ABBR|ACRONYM|SUB|SUP|#text|#comment';
253                 this.inlineTransitional = 'A|BR|SPAN|BDO|OBJECT|APPLET|IMG|MAP|IFRAME|TT|I|B|U|S|STRIKE|BIG|SMALL|FONT|BASEFONT|EM|STRONG|DFN|CODE|Q|SAMP|KBD|VAR|CITE|ABBR|ACRONYM|SUB|SUP|INPUT|SELECT|TEXTAREA|LABEL|BUTTON|#text|#comment';
254                 this.blockElms = 'H[1-6]|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TD|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|FORM|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP';
255                 this.blockRegExp = new RegExp("^(" + this.blockElms + ")$", "i");
256                 this.posKeyCodes = [13,45,36,35,33,34,37,38,39,40];
257                 this.uniqueURL = 'javascript:void(091039730);'; // Make unique URL non real URL
258                 this.uniqueTag = '<div id="mceTMPElement" style="display: none">TMP</div>';
259                 this.callbacks = ['onInit', 'getInfo', 'getEditorTemplate', 'setupContent', 'onChange', 'onPageLoad', 'handleNodeChange', 'initInstance', 'execCommand', 'getControlHTML', 'handleEvent', 'cleanup', 'removeInstance'];
260
261                 // Theme url
262                 this.settings.theme_href = tinyMCE.baseURL + "/themes/" + theme;
263
264                 if (!tinyMCE.isIE || tinyMCE.isOpera)
265                         this.settings.force_br_newlines = false;
266
267                 if (tinyMCE.getParam("popups_css", false)) {
268                         cssPath = tinyMCE.getParam("popups_css", "");
269
270                         // Is relative
271                         if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
272                                 this.settings.popups_css = this.documentBasePath + "/" + cssPath;
273                         else
274                                 this.settings.popups_css = cssPath;
275                 } else
276                         this.settings.popups_css = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css";
277
278                 if (tinyMCE.getParam("editor_css", false)) {
279                         cssPath = tinyMCE.getParam("editor_css", "");
280
281                         // Is relative
282                         if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
283                                 this.settings.editor_css = this.documentBasePath + "/" + cssPath;
284                         else
285                                 this.settings.editor_css = cssPath;
286                 } else {
287                         if (this.settings.editor_css !== '')
288                                 this.settings.editor_css = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";
289                 }
290
291                 // Only do this once
292                 if (this.configs.length == 0) {
293                         if (typeof(TinyMCECompressed) == "undefined") {
294                                 tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCE_Engine.prototype.onLoad);
295
296                                 if (tinyMCE.isRealIE) {
297                                         if (document.body)
298                                                 tinyMCE.addEvent(document.body, "readystatechange", TinyMCE_Engine.prototype.onLoad);
299                                         else
300                                                 tinyMCE.addEvent(document, "readystatechange", TinyMCE_Engine.prototype.onLoad);
301                                 }
302
303                                 tinyMCE.addEvent(window, "load", TinyMCE_Engine.prototype.onLoad);
304                                 tinyMCE._addUnloadEvents();
305                         }
306                 }
307
308                 this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings.theme + '/editor_template' + tinyMCE.srcMode + '.js');
309                 this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings.language +  '.js');
310                 this.loadCSS(this.settings.editor_css);
311
312                 // Add plugins
313                 p = tinyMCE.getParam('plugins', '', true, ',');
314                 if (p.length > 0) {
315                         for (i=0; i<p.length; i++) {
316                                 if (p[i].charAt(0) != '-')
317                                         this.loadScript(tinyMCE.baseURL + '/plugins/' + p[i] + '/editor_plugin' + tinyMCE.srcMode + '.js');
318                         }
319                 }
320
321                 // Setup entities
322                 if (tinyMCE.getParam('entity_encoding') == 'named') {
323                         settings.cleanup_entities = [];
324                         entities = tinyMCE.getParam('entities', '', true, ',');
325                         for (i=0; i<entities.length; i+=2)
326                                 settings.cleanup_entities['c' + entities[i]] = entities[i+1];
327                 }
328
329                 // Save away this config
330                 settings.index = this.configs.length;
331                 this.configs[this.configs.length] = settings;
332
333                 // Start loading first one in chain
334                 this.loadNextScript();
335
336                 // Force flicker free CSS backgrounds in IE
337                 if (this.isIE && !this.isOpera) {
338                         try {
339                                 document.execCommand('BackgroundImageCache', false, true);
340                         } catch (e) {
341                                 // Ignore
342                         }
343                 }
344
345                 // Setup XML encoding regexps
346                 this.xmlEncodeRe = new RegExp('[<>&"]', 'g');
347         },
348
349         _addUnloadEvents : function() {
350                 var st = tinyMCE.settings.add_unload_trigger;
351
352                 if (tinyMCE.isIE) {
353                         if (st) {
354                                 tinyMCE.addEvent(window, "unload", TinyMCE_Engine.prototype.unloadHandler);
355                                 tinyMCE.addEvent(window.document, "beforeunload", TinyMCE_Engine.prototype.unloadHandler);
356                         }
357                 } else {
358                         if (st)
359                                 tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);});
360                 }
361         },
362
363         _def : function(key, def_val, t) {
364                 var v = tinyMCE.getParam(key, def_val);
365
366                 v = t ? v.replace(/\s+/g, "") : v;
367
368                 this.settings[key] = v;
369         },
370
371         hasPlugin : function(n) {
372                 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
373         },
374
375         addPlugin : function(n, p) {
376                 var op = this.plugins[n];
377
378                 // Use the previous plugin object base URL used when loading external plugins
379                 p.baseURL = op ? op.baseURL : tinyMCE.baseURL + "/plugins/" + n;
380                 this.plugins[n] = p;
381
382                 this.loadNextScript();
383         },
384
385         setPluginBaseURL : function(n, u) {
386                 var op = this.plugins[n];
387
388                 if (op)
389                         op.baseURL = u;
390                 else
391                         this.plugins[n] = {baseURL : u};
392         },
393
394         loadPlugin : function(n, u) {
395                 u = u.indexOf('.js') != -1 ? u.substring(0, u.lastIndexOf('/')) : u;
396                 u = u.charAt(u.length-1) == '/' ? u.substring(0, u.length-1) : u;
397                 this.plugins[n] = {baseURL : u};
398                 this.loadScript(u + "/editor_plugin" + (tinyMCE.srcMode ? '_src' : '') + ".js");
399         },
400
401         hasTheme : function(n) {
402                 return typeof(this.themes[n]) != "undefined" && this.themes[n] != null;
403         },
404
405         addTheme : function(n, t) {
406                 this.themes[n] = t;
407
408                 this.loadNextScript();
409         },
410
411         addMenu : function(n, m) {
412                 this.menus[n] = m;
413         },
414
415         hasMenu : function(n) {
416                 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
417         },
418
419         loadScript : function(url) {
420                 var i;
421
422                 for (i=0; i<this.loadedFiles.length; i++) {
423                         if (this.loadedFiles[i] == url)
424                                 return;
425                 }
426
427                 if (tinyMCE.settings.strict_loading_mode)
428                         this.pendingFiles[this.pendingFiles.length] = url;
429                 else
430                         document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>');
431
432                 this.loadedFiles[this.loadedFiles.length] = url;
433         },
434
435         loadNextScript : function() {
436                 var d = document, se;
437
438                 if (!tinyMCE.settings.strict_loading_mode)
439                         return;
440
441                 if (this.loadingIndex < this.pendingFiles.length) {
442                         se = d.createElementNS('http://www.w3.org/1999/xhtml', 'script');
443                         se.setAttribute('language', 'javascript');
444                         se.setAttribute('type', 'text/javascript');
445                         se.setAttribute('src', this.pendingFiles[this.loadingIndex++]);
446
447                         d.getElementsByTagName("head")[0].appendChild(se);
448                 } else
449                         this.loadingIndex = -1; // Done with loading
450         },
451
452         loadCSS : function(url) {
453                 var ar = url.replace(/\s+/, '').split(',');
454                 var lflen = 0, csslen = 0, skip = false;
455                 var x = 0, i = 0, nl, le;
456
457                 for (x = 0,csslen = ar.length; x<csslen; x++) {
458                         if (ar[x] != null && ar[x] != 'null' && ar[x].length > 0) {
459                                 /* Make sure it doesn't exist. */
460                                 for (i=0, lflen=this.loadedFiles.length; i<lflen; i++) {
461                                         if (this.loadedFiles[i] == ar[x]) {
462                                                 skip = true;
463                                                 break;
464                                         }
465                                 }
466
467                                 if (!skip) {
468                                         if (tinyMCE.settings.strict_loading_mode) {
469                                                 nl = document.getElementsByTagName("head");
470
471                                                 le = document.createElement('link');
472                                                 le.setAttribute('href', ar[x]);
473                                                 le.setAttribute('rel', 'stylesheet');
474                                                 le.setAttribute('type', 'text/css');
475
476                                                 nl[0].appendChild(le);                  
477                                         } else
478                                                 document.write('<link href="' + ar[x] + '" rel="stylesheet" type="text/css" />');
479
480                                         this.loadedFiles[this.loadedFiles.length] = ar[x];
481                                 }
482                         }
483                 }
484         },
485
486         importCSS : function(doc, css) {
487                 var css_ary = css.replace(/\s+/, '').split(',');
488                 var csslen, elm, headArr, x, css_file;
489
490                 for (x = 0, csslen = css_ary.length; x<csslen; x++) {
491                         css_file = css_ary[x];
492
493                         if (css_file != null && css_file != 'null' && css_file.length > 0) {
494                                 // Is relative, make absolute
495                                 if (css_file.indexOf('://') == -1 && css_file.charAt(0) != '/')
496                                         css_file = this.documentBasePath + "/" + css_file;
497
498                                 if (typeof(doc.createStyleSheet) == "undefined") {
499                                         elm = doc.createElement("link");
500
501                                         elm.rel = "stylesheet";
502                                         elm.href = css_file;
503
504                                         if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
505                                                 headArr[0].appendChild(elm);
506                                 } else
507                                         doc.createStyleSheet(css_file);
508                         }
509                 }
510         },
511
512         confirmAdd : function(e, settings) {
513                 var elm = tinyMCE.isIE ? event.srcElement : e.target;
514                 var elementId = elm.name ? elm.name : elm.id;
515
516                 tinyMCE.settings = settings;
517
518                 if (tinyMCE.settings.convert_on_click || (!elm.getAttribute('mce_noask') && confirm(tinyMCELang.lang_edit_confirm)))
519                         tinyMCE.addMCEControl(elm, elementId);
520
521                 elm.setAttribute('mce_noask', 'true');
522         },
523
524         updateContent : function(form_element_name) {
525                 var formElement, n, inst, doc;
526
527                 // Find MCE instance linked to given form element and copy it's value
528                 formElement = document.getElementById(form_element_name);
529                 for (n in tinyMCE.instances) {
530                         inst = tinyMCE.instances[n];
531
532                         if (!tinyMCE.isInstance(inst))
533                                 continue;
534
535                         inst.switchSettings();
536
537                         if (inst.formElement == formElement) {
538                                 doc = inst.getDoc();
539
540                                 tinyMCE._setHTML(doc, inst.formElement.value);
541
542                                 if (!tinyMCE.isIE)
543                                         doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);
544                         }
545                 }
546         },
547
548         addMCEControl : function(replace_element, form_element_name, target_document) {
549                 var id = "mce_editor_" + tinyMCE.idCounter++;
550                 var inst = new TinyMCE_Control(tinyMCE.settings);
551
552                 inst.editorId = id;
553                 this.instances[id] = inst;
554
555                 inst._onAdd(replace_element, form_element_name, target_document);
556         },
557
558         removeInstance : function(ti) {
559                 var t = [], n, i;
560
561                 // Remove from instances
562                 for (n in tinyMCE.instances) {
563                         i = tinyMCE.instances[n];
564
565                         if (tinyMCE.isInstance(i) && ti != i)
566                                         t[n] = i;
567                 }
568
569                 tinyMCE.instances = t;
570
571                 // Remove from global undo/redo
572                 n = [];
573                 t = tinyMCE.undoLevels;
574
575                 for (i=0; i<t.length; i++) {
576                         if (t[i] != ti)
577                                 n.push(t[i]);
578                 }
579
580                 tinyMCE.undoLevels = n;
581                 tinyMCE.undoIndex = n.length;
582
583                 // Dispatch remove instance call
584                 tinyMCE.dispatchCallback(ti, 'remove_instance_callback', 'removeInstance', ti);
585
586                 return ti;
587         },
588
589         removeMCEControl : function(editor_id) {
590                 var inst = tinyMCE.getInstanceById(editor_id), h, re, ot, tn, n;
591
592                 if (inst) {
593                         inst.switchSettings();
594
595                         editor_id = inst.editorId;
596                         h = tinyMCE.getContent(editor_id);
597
598                         this.removeInstance(inst);
599
600                         tinyMCE.selectedElement = null;
601                         tinyMCE.selectedInstance = null;
602
603                         tinyMCE.selectedElement = null;
604                         tinyMCE.selectedInstance = null;
605
606                         // Try finding an instance
607                         for (n in tinyMCE.instances) {
608                                 if (!tinyMCE.isInstance(tinyMCE.instances[n]))
609                                         continue;
610
611                                 tinyMCE.selectedInstance = tinyMCE.instances[n];
612                                 break;
613                         }
614
615                         // Remove element
616                         re = document.getElementById(editor_id + "_parent");
617                         ot = inst.oldTargetElement;
618                         tn = ot.nodeName.toLowerCase();
619
620                         if (tn == "textarea" || tn == "input") {
621                                 re.parentNode.removeChild(re);
622                                 ot.style.display = "inline";
623                                 ot.value = h;
624                         } else {
625                                 ot.innerHTML = h;
626                                 ot.style.display = 'block';
627                                 re.parentNode.insertBefore(ot, re);
628                                 re.parentNode.removeChild(re);
629                         }
630                 }
631         },
632
633         triggerSave : function(skip_cleanup, skip_callback) {
634                 var inst, n;
635
636                 // Default to false
637                 if (typeof(skip_cleanup) == "undefined")
638                         skip_cleanup = false;
639
640                 // Default to false
641                 if (typeof(skip_callback) == "undefined")
642                         skip_callback = false;
643
644                 // Cleanup and set all form fields
645                 for (n in tinyMCE.instances) {
646                         inst = tinyMCE.instances[n];
647
648                         if (!tinyMCE.isInstance(inst))
649                                 continue;
650
651                         inst.triggerSave(skip_cleanup, skip_callback);
652                 }
653         },
654
655         resetForm : function(form_index) {
656                 var i, inst, n, formObj = document.forms[form_index];
657
658                 for (n in tinyMCE.instances) {
659                         inst = tinyMCE.instances[n];
660
661                         if (!tinyMCE.isInstance(inst))
662                                 continue;
663
664                         inst.switchSettings();
665
666                         for (i=0; i<formObj.elements.length; i++) {
667                                 if (inst.formTargetElementId == formObj.elements[i].name)
668                                         inst.getBody().innerHTML = inst.startContent;
669                         }
670                 }
671         },
672
673         execInstanceCommand : function(editor_id, command, user_interface, value, focus) {
674                 var inst = tinyMCE.getInstanceById(editor_id), r;
675
676                 if (inst) {
677                         r = inst.selection.getRng();
678
679                         if (typeof(focus) == "undefined")
680                                 focus = true;
681
682                         // IE bug lost focus on images in absolute divs Bug #1534575
683                         if (focus && (!r || !r.item))
684                                 inst.contentWindow.focus();
685
686                         // Reset design mode if lost
687                         inst.autoResetDesignMode();
688
689                         this.selectedElement = inst.getFocusElement();
690                         inst.select();
691                         tinyMCE.execCommand(command, user_interface, value);
692
693                         // Cancel event so it doesn't call onbeforeonunlaod
694                         if (tinyMCE.isIE && window.event != null)
695                                 tinyMCE.cancelEvent(window.event);
696                 }
697         },
698
699         execCommand : function(command, user_interface, value) {
700                 var inst = tinyMCE.selectedInstance, n, pe, te;
701
702                 // Default input
703                 user_interface = user_interface ? user_interface : false;
704                 value = value ? value : null;
705
706                 if (inst)
707                         inst.switchSettings();
708
709                 switch (command) {
710                         case "Undo":
711                                 if (this.getParam('custom_undo_redo_global')) {
712                                         if (this.undoIndex > 0) {
713                                                 tinyMCE.nextUndoRedoAction = 'Undo';
714                                                 inst = this.undoLevels[--this.undoIndex];
715                                                 inst.select();
716
717                                                 if (!tinyMCE.nextUndoRedoInstanceId)
718                                                         inst.execCommand('Undo');
719                                         }
720                                 } else
721                                         inst.execCommand('Undo');
722                                 return true;
723
724                         case "Redo":
725                                 if (this.getParam('custom_undo_redo_global')) {
726                                         if (this.undoIndex <= this.undoLevels.length - 1) {
727                                                 tinyMCE.nextUndoRedoAction = 'Redo';
728                                                 inst = this.undoLevels[this.undoIndex++];
729                                                 inst.select();
730
731                                                 if (!tinyMCE.nextUndoRedoInstanceId)
732                                                         inst.execCommand('Redo');
733                                         }
734                                 } else
735                                         inst.execCommand('Redo');
736
737                                 return true;
738
739                         case 'mceFocus':
740                                 inst = tinyMCE.getInstanceById(value);
741
742                                 if (inst)
743                                         inst.getWin().focus();
744                         return;
745
746                         case "mceAddControl":
747                         case "mceAddEditor":
748                                 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
749                                 return;
750
751                         case "mceAddFrameControl":
752                                 tinyMCE.addMCEControl(tinyMCE._getElementById(value.element, value.document), value.element, value.document);
753                                 return;
754
755                         case "mceRemoveControl":
756                         case "mceRemoveEditor":
757                                 tinyMCE.removeMCEControl(value);
758                                 return;
759
760                         case "mceToggleEditor":
761                                 inst = tinyMCE.getInstanceById(value);
762
763                                 if (inst) {
764                                         pe = document.getElementById(inst.editorId + '_parent');
765                                         te = inst.oldTargetElement;
766
767                                         if (typeof(inst.enabled) == 'undefined')
768                                                 inst.enabled = true;
769
770                                         inst.enabled = !inst.enabled;
771
772                                         if (!inst.enabled) {
773                                                 pe.style.display = 'none';
774
775                                                 if (te.nodeName == 'TEXTAREA' || te.nodeName == 'INPUT')
776                                                         te.value = inst.getHTML();
777                                                 else
778                                                         te.innerHTML = inst.getHTML();
779
780                                                 te.style.display = inst.oldTargetDisplay;
781                                                 tinyMCE.dispatchCallback(inst, 'hide_instance_callback', 'hideInstance', inst);
782                                         } else {
783                                                 pe.style.display = 'block';
784                                                 te.style.display = 'none';
785
786                                                 if (te.nodeName == 'TEXTAREA' || te.nodeName == 'INPUT')
787                                                         inst.setHTML(te.value);
788                                                 else
789                                                         inst.setHTML(te.innerHTML);
790
791                                                 inst.useCSS = false;
792                                                 tinyMCE.dispatchCallback(inst, 'show_instance_callback', 'showInstance', inst);
793                                         }
794                                 } else
795                                         tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
796
797                                 return;
798
799                         case "mceResetDesignMode":
800                                 // Resets the designmode state of the editors in Gecko
801                                 if (tinyMCE.isGecko) {
802                                         for (n in tinyMCE.instances) {
803                                                 if (!tinyMCE.isInstance(tinyMCE.instances[n]))
804                                                         continue;
805
806                                                 try {
807                                                         tinyMCE.instances[n].getDoc().designMode = "off";
808                                                         tinyMCE.instances[n].getDoc().designMode = "on";
809                                                         tinyMCE.instances[n].useCSS = false;
810                                                 } catch (e) {
811                                                         // Ignore any errors
812                                                 }
813                                         }
814                                 }
815
816                                 return;
817                 }
818
819                 if (inst) {
820                         inst.execCommand(command, user_interface, value);
821                 } else if (tinyMCE.settings.focus_alert)
822                         alert(tinyMCELang.lang_focus_alert);
823         },
824
825         _createIFrame : function(replace_element, doc, win) {
826                 var iframe, id = replace_element.getAttribute("id");
827                 var aw, ah;
828
829                 if (typeof(doc) == "undefined")
830                         doc = document;
831
832                 if (typeof(win) == "undefined")
833                         win = window;
834
835                 iframe = doc.createElement("iframe");
836
837                 aw = "" + tinyMCE.settings.area_width;
838                 ah = "" + tinyMCE.settings.area_height;
839
840                 if (aw.indexOf('%') == -1) {
841                         aw = parseInt(aw);
842                         aw = (isNaN(aw) || aw < 0) ? 300 : aw;
843                         aw = aw + "px";
844                 }
845
846                 if (ah.indexOf('%') == -1) {
847                         ah = parseInt(ah);
848                         ah = (isNaN(ah) || ah < 0) ? 240 : ah;
849                         ah = ah + "px";
850                 }
851
852                 iframe.setAttribute("id", id);
853                 iframe.setAttribute("name", id);
854                 iframe.setAttribute("class", "mceEditorIframe");
855                 iframe.setAttribute("border", "0");
856                 iframe.setAttribute("frameBorder", "0");
857                 iframe.setAttribute("marginWidth", "0");
858                 iframe.setAttribute("marginHeight", "0");
859                 iframe.setAttribute("leftMargin", "0");
860                 iframe.setAttribute("topMargin", "0");
861                 iframe.setAttribute("width", aw);
862                 iframe.setAttribute("height", ah);
863                 iframe.setAttribute("allowtransparency", "true");
864                 iframe.className = 'mceEditorIframe';
865
866                 if (tinyMCE.settings.auto_resize)
867                         iframe.setAttribute("scrolling", "no");
868
869                 // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs
870                 if (tinyMCE.isRealIE)
871                         iframe.setAttribute("src", this.settings.default_document);
872
873                 iframe.style.width = aw;
874                 iframe.style.height = ah;
875
876                 // Ugly hack for Gecko problem in strict mode
877                 if (tinyMCE.settings.strict_loading_mode)
878                         iframe.style.marginBottom = '-5px';
879
880                 // MSIE 5.0 issue
881                 if (tinyMCE.isRealIE)
882                         replace_element.outerHTML = iframe.outerHTML;
883                 else
884                         replace_element.parentNode.replaceChild(iframe, replace_element);
885
886                 if (tinyMCE.isRealIE)
887                         return win.frames[id];
888                 else
889                         return iframe;
890         },
891
892         setupContent : function(editor_id) {
893                 var inst = tinyMCE.instances[editor_id], i, doc = inst.getDoc(), head = doc.getElementsByTagName('head').item(0);
894                 var content = inst.startContent, contentElement, body;
895
896                 // HTML values get XML encoded in strict mode
897                 if (tinyMCE.settings.strict_loading_mode) {
898                         content = content.replace(/&lt;/g, '<');
899                         content = content.replace(/&gt;/g, '>');
900                         content = content.replace(/&quot;/g, '"');
901                         content = content.replace(/&amp;/g, '&');
902                 }
903
904                 tinyMCE.selectedInstance = inst;
905                 inst.switchSettings();
906
907                 // Not loaded correctly hit it again, Mozilla bug #997860
908                 if (!tinyMCE.isIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") {
909                         // This part will remove the designMode status
910                         // Failes first time in Firefox 1.5b2 on Mac
911                         try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {}
912                         window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000);
913                         return;
914                 }
915
916                 // Wait for it to load
917                 if (!head || !doc.body) {
918                         window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);
919                         return;
920                 }
921
922                 // Import theme specific content CSS the user specific
923                 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings.theme + "/css/editor_content.css");
924                 tinyMCE.importCSS(inst.getDoc(), inst.settings.content_css);
925                 tinyMCE.dispatchCallback(inst, 'init_instance_callback', 'initInstance', inst);
926
927                 // Setup keyboard shortcuts
928                 if (tinyMCE.getParam('custom_undo_redo_keyboard_shortcuts')) {
929                         inst.addShortcut('ctrl', 'z', 'lang_undo_desc', 'Undo');
930                         inst.addShortcut('ctrl', 'y', 'lang_redo_desc', 'Redo');
931                 }
932
933                 // BlockFormat shortcuts keys
934                 for (i=1; i<=6; i++)
935                         inst.addShortcut('ctrl', '' + i, '', 'FormatBlock', false, '<h' + i + '>');
936
937                 inst.addShortcut('ctrl', '7', '', 'FormatBlock', false, '<p>');
938                 inst.addShortcut('ctrl', '8', '', 'FormatBlock', false, '<div>');
939                 inst.addShortcut('ctrl', '9', '', 'FormatBlock', false, '<address>');
940
941                 // Add default shortcuts for gecko
942                 if (tinyMCE.isGecko) {
943                         inst.addShortcut('ctrl', 'b', 'lang_bold_desc', 'Bold');
944                         inst.addShortcut('ctrl', 'i', 'lang_italic_desc', 'Italic');
945                         inst.addShortcut('ctrl', 'u', 'lang_underline_desc', 'Underline');
946                 }
947
948                 // Setup span styles
949                 if (tinyMCE.getParam("convert_fonts_to_spans"))
950                         inst.getBody().setAttribute('id', 'mceSpanFonts');
951
952                 if (tinyMCE.settings.nowrap)
953                         doc.body.style.whiteSpace = "nowrap";
954
955                 doc.body.dir = this.settings.directionality;
956                 doc.editorId = editor_id;
957
958                 // Add on document element in Mozilla
959                 if (!tinyMCE.isIE)
960                         doc.documentElement.editorId = editor_id;
961
962                 inst.setBaseHREF(tinyMCE.settings.base_href);
963
964                 // Replace new line characters to BRs
965                 if (tinyMCE.settings.convert_newlines_to_brs) {
966                         content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi");
967                         content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi");
968                         content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi");
969                 }
970
971                 // Open closed anchors
972         //      content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
973
974                 // Call custom cleanup code
975                 content = tinyMCE.storeAwayURLs(content);
976                 content = tinyMCE._customCleanup(inst, "insert_to_editor", content);
977
978                 if (tinyMCE.isIE) {
979                         // Ugly!!!
980                         window.setInterval('try{tinyMCE.getCSSClasses(tinyMCE.instances["' + editor_id + '"].getDoc(), "' + editor_id + '");}catch(e){}', 500);
981
982                         if (tinyMCE.settings.force_br_newlines)
983                                 doc.styleSheets[0].addRule("p", "margin: 0;");
984
985                         body = inst.getBody();
986                         body.editorId = editor_id;
987                 }
988
989                 content = tinyMCE.cleanupHTMLCode(content);
990
991                 // Fix for bug #958637
992                 if (!tinyMCE.isIE) {
993                         contentElement = inst.getDoc().createElement("body");
994                         doc = inst.getDoc();
995
996                         contentElement.innerHTML = content;
997
998                         if (tinyMCE.settings.cleanup_on_startup)
999                                 tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));
1000                         else
1001                                 tinyMCE.setInnerHTML(inst.getBody(), content);
1002
1003                         tinyMCE.convertAllRelativeURLs(inst.getBody());
1004                 } else {
1005                         if (tinyMCE.settings.cleanup_on_startup) {
1006                                 tinyMCE._setHTML(inst.getDoc(), content);
1007
1008                                 // Produces permission denied error in MSIE 5.5
1009                                 try {
1010                                         tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));
1011                                 } catch(e) {
1012                                         // Ignore
1013                                 }
1014                         } else
1015                                 tinyMCE._setHTML(inst.getDoc(), content);
1016                 }
1017
1018                 // Fix for bug #957681
1019                 //inst.getDoc().designMode = inst.getDoc().designMode;
1020
1021                 tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings.visual, inst);
1022                 tinyMCE.dispatchCallback(inst, 'setupcontent_callback', 'setupContent', editor_id, inst.getBody(), inst.getDoc());
1023
1024                 // Re-add design mode on mozilla
1025                 if (!tinyMCE.isIE)
1026                         tinyMCE.addEventHandlers(inst);
1027
1028                 // Add blur handler
1029                 if (tinyMCE.isIE) {
1030                         tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE_Engine.prototype._eventPatch);
1031                         tinyMCE.addEvent(inst.getBody(), "beforedeactivate", TinyMCE_Engine.prototype._eventPatch); // Bug #1439953
1032
1033                         // Workaround for drag drop/copy paste base href bug
1034                         if (!tinyMCE.isOpera) {
1035                                 tinyMCE.addEvent(doc.body, "mousemove", TinyMCE_Engine.prototype.onMouseMove);
1036                                 tinyMCE.addEvent(doc.body, "beforepaste", TinyMCE_Engine.prototype._eventPatch);
1037                                 tinyMCE.addEvent(doc.body, "drop", TinyMCE_Engine.prototype._eventPatch);
1038                         }
1039                 }
1040
1041                 // Trigger node change, this call locks buttons for tables and so forth
1042                 inst.select();
1043                 tinyMCE.selectedElement = inst.contentWindow.document.body;
1044
1045                 // Call custom DOM cleanup
1046                 tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());
1047                 tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());
1048                 tinyMCE._setEventsEnabled(inst.getBody(), false);
1049                 tinyMCE.cleanupAnchors(inst.getDoc());
1050
1051                 if (tinyMCE.getParam("convert_fonts_to_spans"))
1052                         tinyMCE.convertSpansToFonts(inst.getDoc());
1053
1054                 inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
1055                 inst.undoRedo.add({ content : inst.startContent });
1056
1057                 // Cleanup any mess left from storyAwayURLs
1058                 if (tinyMCE.isGecko) {
1059                         // Remove mce_src from textnodes and comments
1060                         tinyMCE.selectNodes(inst.getBody(), function(n) {
1061                                 if (n.nodeType == 3 || n.nodeType == 8)
1062                                         n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
1063
1064                                 return false;
1065                         });
1066                 }
1067
1068                 // Remove Gecko spellchecking
1069                 if (tinyMCE.isGecko)
1070                         inst.getBody().spellcheck = tinyMCE.getParam("gecko_spellcheck");
1071
1072                 // Cleanup any mess left from storyAwayURLs
1073                 tinyMCE._removeInternal(inst.getBody());
1074
1075                 inst.select();
1076                 tinyMCE.triggerNodeChange(false, true);
1077         },
1078
1079         storeAwayURLs : function(s) {
1080                 // Remove all mce_src, mce_href and replace them with new ones
1081                 // s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
1082                 // s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
1083
1084                 if (!s.match(/(mce_src|mce_href)/gi, s)) {
1085                         s = s.replace(new RegExp('src\\s*=\\s*[\"\']([^ >\"]*)[\"\']', 'gi'), 'src="$1" mce_src="$1"');
1086                         s = s.replace(new RegExp('href\\s*=\\s*[\"\']([^ >\"]*)[\"\']', 'gi'), 'href="$1" mce_href="$1"');
1087                 }
1088
1089                 return s;
1090         },
1091
1092         _removeInternal : function(n) {
1093                 if (tinyMCE.isGecko) {
1094                         // Remove mce_src from textnodes and comments
1095                         tinyMCE.selectNodes(n, function(n) {
1096                                 if (n.nodeType == 3 || n.nodeType == 8)
1097                                         n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
1098
1099                                 return false;
1100                         });
1101                 }
1102         },
1103
1104         removeTinyMCEFormElements : function(form_obj) {
1105                 var i, elementId;
1106
1107                 // Skip form element removal
1108                 if (!tinyMCE.getParam('hide_selects_on_submit'))
1109                         return;
1110
1111                 // Check if form is valid
1112                 if (typeof(form_obj) == "undefined" || form_obj == null)
1113                         return;
1114
1115                 // If not a form, find the form
1116                 if (form_obj.nodeName != "FORM") {
1117                         if (form_obj.form)
1118                                 form_obj = form_obj.form;
1119                         else
1120                                 form_obj = tinyMCE.getParentElement(form_obj, "form");
1121                 }
1122
1123                 // Still nothing
1124                 if (form_obj == null)
1125                         return;
1126
1127                 // Disable all UI form elements that TinyMCE created
1128                 for (i=0; i<form_obj.elements.length; i++) {
1129                         elementId = form_obj.elements[i].name ? form_obj.elements[i].name : form_obj.elements[i].id;
1130
1131                         if (elementId.indexOf('mce_editor_') == 0)
1132                                 form_obj.elements[i].disabled = true;
1133                 }
1134         },
1135
1136         handleEvent : function(e) {
1137                 var inst = tinyMCE.selectedInstance, i, elm, keys;
1138
1139                 // Remove odd, error
1140                 if (typeof(tinyMCE) == "undefined")
1141                         return true;
1142
1143                 //tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""));
1144
1145                 if (tinyMCE.executeCallback(tinyMCE.selectedInstance, 'handle_event_callback', 'handleEvent', e))
1146                         return false;
1147
1148                 switch (e.type) {
1149                         case "beforedeactivate": // Was added due to bug #1439953
1150                         case "blur":
1151                                 if (tinyMCE.selectedInstance)
1152                                         tinyMCE.selectedInstance.execCommand('mceEndTyping');
1153
1154                                 tinyMCE.hideMenus();
1155
1156                                 return;
1157
1158                         // Workaround for drag drop/copy paste base href bug
1159                         case "drop":
1160                         case "beforepaste":
1161 /*                              if (tinyMCE.selectedInstance)
1162                                         tinyMCE.selectedInstance.setBaseHREF(null);
1163
1164                                 // Fixes odd MSIE bug where drag/droping elements in a iframe with height 100% breaks
1165                                 // This logic forces the width/height to be in pixels while the user is drag/dropping
1166                                 // NOTE: This has been disabled for now since it messes up copy/paste that is far more important than image drag
1167                                 if (tinyMCE.isRealIE) {
1168                                         var ife = tinyMCE.selectedInstance.iframeElement;
1169
1170                                         if (ife.style.height.indexOf('%') != -1) {
1171                                                 ife._oldHeight = ife.style.height;
1172                                                 ife.style.height = ife.clientHeight;
1173                                         }
1174                                 }
1175
1176                                 window.setTimeout("tinyMCE.selectedInstance.setBaseHREF(tinyMCE.settings.base_href);tinyMCE._resetIframeHeight();", 1);
1177                                 */
1178                                 return;
1179
1180                         case "submit":
1181                                 tinyMCE.formSubmit(tinyMCE.isMSIE ? window.event.srcElement : e.target);
1182                                 return;
1183
1184                         case "reset":
1185                                 var formObj = tinyMCE.isIE ? window.event.srcElement : e.target;
1186
1187                                 for (i=0; i<document.forms.length; i++) {
1188                                         if (document.forms[i] == formObj)
1189                                                 window.setTimeout('tinyMCE.resetForm(' + i + ');', 10);
1190                                 }
1191
1192                                 return;
1193
1194                         case "keypress":
1195                                 if (inst && inst.handleShortcut(e))
1196                                         return false;
1197
1198                                 if (e.target.editorId) {
1199                                         tinyMCE.instances[e.target.editorId].select();
1200                                 } else {
1201                                         if (e.target.ownerDocument.editorId)
1202                                                 tinyMCE.instances[e.target.ownerDocument.editorId].select();
1203                                 }
1204
1205                                 if (tinyMCE.selectedInstance)
1206                                         tinyMCE.selectedInstance.switchSettings();
1207
1208                                 // Insert P element
1209                                 if ((tinyMCE.isGecko || tinyMCE.isOpera || tinyMCE.isSafari) && tinyMCE.settings.force_p_newlines && e.keyCode == 13 && !e.shiftKey) {
1210                                         // Insert P element instead of BR
1211                                         if (TinyMCE_ForceParagraphs._insertPara(tinyMCE.selectedInstance, e)) {
1212                                                 // Cancel event
1213                                                 tinyMCE.execCommand("mceAddUndoLevel");
1214                                                 return tinyMCE.cancelEvent(e);
1215                                         }
1216                                 }
1217
1218                                 // Handle backspace
1219                                 if ((tinyMCE.isGecko && !tinyMCE.isSafari) && tinyMCE.settings.force_p_newlines && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
1220                                         // Insert P element instead of BR
1221                                         if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
1222                                                 // Cancel event
1223                                                 tinyMCE.execCommand("mceAddUndoLevel");
1224                                                 return tinyMCE.cancelEvent(e);
1225                                         }
1226                                 }
1227
1228                                 // Return key pressed
1229                                 if (tinyMCE.isIE && tinyMCE.settings.force_br_newlines && e.keyCode == 13) {
1230                                         if (e.target.editorId)
1231                                                 tinyMCE.instances[e.target.editorId].select();
1232
1233                                         if (tinyMCE.selectedInstance) {
1234                                                 var sel = tinyMCE.selectedInstance.getDoc().selection;
1235                                                 var rng = sel.createRange();
1236
1237                                                 if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)
1238                                                         return false;
1239
1240                                                 // Cancel event
1241                                                 e.returnValue = false;
1242                                                 e.cancelBubble = true;
1243
1244                                                 // Insert BR element
1245                                                 rng.pasteHTML("<br />");
1246                                                 rng.collapse(false);
1247                                                 rng.select();
1248
1249                                                 tinyMCE.execCommand("mceAddUndoLevel");
1250                                                 tinyMCE.triggerNodeChange(false);
1251                                                 return false;
1252                                         }
1253                                 }
1254
1255                                 // Backspace or delete
1256                                 if (e.keyCode == 8 || e.keyCode == 46) {
1257                                         tinyMCE.selectedElement = e.target;
1258                                         tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a");
1259                                         tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img");
1260                                         tinyMCE.triggerNodeChange(false);
1261                                 }
1262
1263                                 return false;
1264
1265                         case "keyup":
1266                         case "keydown":
1267                                 tinyMCE.hideMenus();
1268                                 tinyMCE.hasMouseMoved = false;
1269
1270                                 if (inst && inst.handleShortcut(e))
1271                                         return false;
1272
1273                                 inst._fixRootBlocks();
1274
1275                                 if (inst.settings.remove_trailing_nbsp)
1276                                         inst._fixTrailingNbsp();
1277
1278                                 if (e.target.editorId)
1279                                         tinyMCE.instances[e.target.editorId].select();
1280
1281                                 if (tinyMCE.selectedInstance)
1282                                         tinyMCE.selectedInstance.switchSettings();
1283
1284                                 inst = tinyMCE.selectedInstance;
1285
1286                                 // Handle backspace
1287                                 if (tinyMCE.isGecko && tinyMCE.settings.force_p_newlines && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
1288                                         // Insert P element instead of BR
1289                                         if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
1290                                                 // Cancel event
1291                                                 tinyMCE.execCommand("mceAddUndoLevel");
1292                                                 e.preventDefault();
1293                                                 return false;
1294                                         }
1295                                 }
1296
1297                                 tinyMCE.selectedElement = null;
1298                                 tinyMCE.selectedNode = null;
1299                                 elm = tinyMCE.selectedInstance.getFocusElement();
1300                                 tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a");
1301                                 tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img");
1302                                 tinyMCE.selectedElement = elm;
1303
1304                                 // Update visualaids on tabs
1305                                 if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9)
1306                                         tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings.visual, tinyMCE.selectedInstance);
1307
1308                                 // Fix empty elements on return/enter, check where enter occured
1309                                 if (tinyMCE.isIE && e.type == "keydown" && e.keyCode == 13)
1310                                         tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement();
1311
1312                                 // Fix empty elements on return/enter
1313                                 if (tinyMCE.isIE && e.type == "keyup" && e.keyCode == 13) {
1314                                         elm = tinyMCE.enterKeyElement;
1315                                         if (elm) {
1316                                                 var re = new RegExp('^HR|IMG|BR$','g'); // Skip these
1317                                                 var dre = new RegExp('^H[1-6]$','g'); // Add double on these
1318
1319                                                 if (!elm.hasChildNodes() && !re.test(elm.nodeName)) {
1320                                                         if (dre.test(elm.nodeName))
1321                                                                 elm.innerHTML = "&nbsp;&nbsp;";
1322                                                         else
1323                                                                 elm.innerHTML = "&nbsp;";
1324                                                 }
1325                                         }
1326                                 }
1327
1328                                 // Check if it's a position key
1329                                 keys = tinyMCE.posKeyCodes;
1330                                 var posKey = false;
1331                                 for (i=0; i<keys.length; i++) {
1332                                         if (keys[i] == e.keyCode) {
1333                                                 posKey = true;
1334                                                 break;
1335                                         }
1336                                 }
1337
1338                                 // MSIE custom key handling
1339                                 if (tinyMCE.isIE && tinyMCE.settings.custom_undo_redo) {
1340                                         keys = [8, 46]; // Backspace,Delete
1341
1342                                         for (i=0; i<keys.length; i++) {
1343                                                 if (keys[i] == e.keyCode) {
1344                                                         if (e.type == "keyup")
1345                                                                 tinyMCE.triggerNodeChange(false);
1346                                                 }
1347                                         }
1348                                 }
1349
1350                                 // If Ctrl key
1351                                 if (e.keyCode == 17)
1352                                         return true;
1353
1354                                 // Handle Undo/Redo when typing content
1355
1356                                 if (tinyMCE.isGecko) {
1357                                         // Start typing (not a position key or ctrl key, but ctrl+x and ctrl+p is ok)
1358                                         if (!posKey && e.type == "keyup" && !e.ctrlKey || (e.ctrlKey && (e.keyCode == 86 || e.keyCode == 88)))
1359                                                 tinyMCE.execCommand("mceStartTyping");
1360                                 } else {
1361                                         // IE seems to be working better with this setting
1362                                         if (!posKey && e.type == "keyup")
1363                                                 tinyMCE.execCommand("mceStartTyping");
1364                                 }
1365
1366                                 // Store undo bookmark
1367                                 if (e.type == "keydown" && (posKey || e.ctrlKey) && inst)
1368                                         inst.undoBookmark = inst.selection.getBookmark();
1369
1370                                 // End typing (position key) or some Ctrl event
1371                                 if (e.type == "keyup" && (posKey || e.ctrlKey))
1372                                         tinyMCE.execCommand("mceEndTyping");
1373
1374                                 if (posKey && e.type == "keyup")
1375                                         tinyMCE.triggerNodeChange(false);
1376
1377                                 if (tinyMCE.isIE && e.ctrlKey)
1378                                         window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
1379                         break;
1380
1381                         case "mousedown":
1382                         case "mouseup":
1383                         case "click":
1384                         case "dblclick":
1385                         case "focus":
1386                                 tinyMCE.hideMenus();
1387
1388                                 if (tinyMCE.selectedInstance) {
1389                                         tinyMCE.selectedInstance.switchSettings();
1390                                         tinyMCE.selectedInstance.isFocused = true;
1391                                 }
1392
1393                                 // Check instance event trigged on
1394                                 var targetBody = tinyMCE.getParentElement(e.target, "html");
1395                                 for (var instanceName in tinyMCE.instances) {
1396                                         if (!tinyMCE.isInstance(tinyMCE.instances[instanceName]))
1397                                                 continue;
1398
1399                                         inst = tinyMCE.instances[instanceName];
1400
1401                                         // Reset design mode if lost (on everything just in case)
1402                                         inst.autoResetDesignMode();
1403
1404                                         // Use HTML element since users might click outside of body element
1405                                         if (inst.getBody().parentNode == targetBody) {
1406                                                 inst.select();
1407                                                 tinyMCE.selectedElement = e.target;
1408                                                 tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
1409                                                 tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img");
1410                                                 break;
1411                                         }
1412                                 }
1413
1414                                 // Add first bookmark location
1415                                 if (!tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark && (e.type == "mouseup" || e.type == "dblclick"))
1416                                         tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark = tinyMCE.selectedInstance.selection.getBookmark();
1417
1418                                 // Reset selected node
1419                                 if (e.type != "focus")
1420                                         tinyMCE.selectedNode = null;
1421
1422                                 tinyMCE.triggerNodeChange(false);
1423                                 tinyMCE.execCommand("mceEndTyping");
1424
1425                                 if (e.type == "mouseup")
1426                                         tinyMCE.execCommand("mceAddUndoLevel");
1427
1428                                 // Just in case
1429                                 if (!tinyMCE.selectedInstance && e.target.editorId)
1430                                         tinyMCE.instances[e.target.editorId].select();
1431
1432                                 return false;
1433                 }
1434         },
1435
1436         getButtonHTML : function(id, lang, img, cmd, ui, val) {
1437                 var h = '', m, x, io = '';
1438
1439                 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
1440
1441                 if (typeof(ui) != "undefined" && ui != null)
1442                         cmd += ',' + ui;
1443
1444                 if (typeof(val) != "undefined" && val != null)
1445                         cmd += ",'" + val + "'";
1446
1447                 cmd += ');';
1448
1449                 // Patch for IE7 bug with hover out not restoring correctly
1450                 if (tinyMCE.isRealIE)
1451                         io = 'onmouseover="tinyMCE.lastHover = this;"';
1452
1453                 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
1454                 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = this.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
1455                         // Tiled button
1456                         x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
1457                         h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceTiledButton mceButtonNormal" target="_self">';
1458                         h += '<img src="{$themeurl}/images/spacer.gif" style="background-position: ' + x + 'px 0" alt="{$'+lang+'}" title="{$' + lang + '}" />';
1459                         h += '</a>';
1460                 } else {
1461                         // Normal button
1462                         h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceButtonNormal" target="_self">';
1463                         h += '<img src="' + img + '" alt="{$'+lang+'}" title="{$' + lang + '}" />';
1464                         h += '</a>';
1465                 }
1466
1467                 return h;
1468         },
1469
1470         getMenuButtonHTML : function(id, lang, img, mcmd, cmd, ui, val) {
1471                 var h = '', m, x;
1472
1473                 mcmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + mcmd + '\');';
1474                 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
1475
1476                 if (typeof(ui) != "undefined" && ui != null)
1477                         cmd += ',' + ui;
1478
1479                 if (typeof(val) != "undefined" && val != null)
1480                         cmd += ",'" + val + "'";
1481
1482                 cmd += ');';
1483
1484                 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
1485                 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = tinyMCE.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
1486                         x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
1487
1488                         if (tinyMCE.isRealIE)
1489                                 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
1490                         else
1491                                 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton">';
1492
1493                         h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceTiledButton mceMenuButtonNormal" target="_self">';
1494                         h += '<img src="{$themeurl}/images/spacer.gif" style="width: 20px; height: 20px; background-position: ' + x + 'px 0" title="{$' + lang + '}" /></a>';
1495                         h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
1496                         h += '</a></span>';
1497                 } else {
1498                         if (tinyMCE.isRealIE)
1499                                 h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
1500                         else
1501                                 h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton">';
1502
1503                         h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceMenuButtonNormal" target="_self">';
1504                         h += '<img src="' + img + '" title="{$' + lang + '}" /></a>';
1505                         h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
1506                         h += '</a></span>';
1507                 }
1508
1509                 return h;
1510         },
1511
1512         _menuButtonEvent : function(e, o) {
1513                 if (o.className == 'mceMenuButtonFocus')
1514                         return;
1515
1516                 if (e == 'over')
1517                         o.className = o.className + ' mceMenuHover';
1518                 else
1519                         o.className = o.className.replace(/\s.*$/, '');
1520         },
1521
1522         addButtonMap : function(m) {
1523                 var i, a = m.replace(/\s+/, '').split(',');
1524
1525                 for (i=0; i<a.length; i++)
1526                         this.buttonMap[a[i]] = i;
1527         },
1528
1529         formSubmit : function(f, p) {
1530                 var n, inst, found = false;
1531
1532                 if (f.form)
1533                         f = f.form;
1534
1535                 // Is it a form that has a TinyMCE instance
1536                 if (tinyMCE.getParam('save_on_tinymce_forms')) {
1537                         for (n in tinyMCE.instances) {
1538                                 inst = tinyMCE.instances[n];
1539
1540                                 if (!tinyMCE.isInstance(inst))
1541                                         continue;
1542
1543                                 if (inst.formElement) {
1544                                         if (f == inst.formElement.form) {
1545                                                 found = true;
1546                                                 inst.isNotDirty = true;
1547                                         }
1548                                 }
1549                         }
1550                 } else
1551                         found  = true;
1552
1553                 // Is valid
1554                 if (found) {
1555                         tinyMCE.removeTinyMCEFormElements(f);
1556                         tinyMCE.triggerSave();
1557                 }
1558
1559                 // Is it patched
1560                 if (f.mceOldSubmit && p)
1561                         f.mceOldSubmit();
1562         },
1563
1564         submitPatch : function() {
1565                 tinyMCE.formSubmit(this, true);
1566         },
1567
1568         onLoad : function() {
1569                 var r, i, c, mode, trigger, elements, element, settings, elementId, elm;
1570                 var selector, deselector, elementRefAr, form;
1571
1572                 // Wait for everything to be loaded first
1573                 if (tinyMCE.settings.strict_loading_mode && this.loadingIndex != -1) {
1574                         window.setTimeout('tinyMCE.onLoad();', 1);
1575                         return;
1576                 }
1577
1578                 if (tinyMCE.isRealIE && window.event.type == "readystatechange" && document.readyState != "complete")
1579                         return true;
1580
1581                 if (tinyMCE.isLoaded)
1582                         return true;
1583
1584                 tinyMCE.isLoaded = true;
1585
1586                 // IE produces JS error if TinyMCE is placed in a frame
1587                 // It seems to have something to do with the selection not beeing
1588                 // correctly initialized in IE so this hack solves the problem
1589                 if (tinyMCE.isRealIE && document.body && window.location.href != window.top.location.href) {
1590                         r = document.body.createTextRange();
1591                         r.collapse(true);
1592                         r.select();
1593                 }
1594
1595                 tinyMCE.dispatchCallback(null, 'onpageload', 'onPageLoad');
1596
1597                 for (c=0; c<tinyMCE.configs.length; c++) {
1598                         tinyMCE.settings = tinyMCE.configs[c];
1599
1600                         selector = tinyMCE.getParam("editor_selector");
1601                         deselector = tinyMCE.getParam("editor_deselector");
1602                         elementRefAr = [];
1603
1604                         // Add submit triggers
1605                         if (document.forms && tinyMCE.settings.add_form_submit_trigger && !tinyMCE.submitTriggers) {
1606                                 for (i=0; i<document.forms.length; i++) {
1607                                         form = document.forms[i];
1608
1609                                         tinyMCE.addEvent(form, "submit", TinyMCE_Engine.prototype.handleEvent);
1610                                         tinyMCE.addEvent(form, "reset", TinyMCE_Engine.prototype.handleEvent);
1611                                         tinyMCE.submitTriggers = true; // Do it only once
1612
1613                                         // Patch the form.submit function
1614                                         if (tinyMCE.settings.submit_patch) {
1615                                                 try {
1616                                                         form.mceOldSubmit = form.submit;
1617                                                         form.submit = TinyMCE_Engine.prototype.submitPatch;
1618                                                 } catch (e) {
1619                                                         // Do nothing
1620                                                 }
1621                                         }
1622                                 }
1623                         }
1624
1625                         // Add editor instances based on mode
1626                         mode = tinyMCE.settings.mode;
1627                         switch (mode) {
1628                                 case "exact":
1629                                         elements = tinyMCE.getParam('elements', '', true, ',');
1630
1631                                         for (i=0; i<elements.length; i++) {
1632                                                 element = tinyMCE._getElementById(elements[i]);
1633                                                 trigger = element ? element.getAttribute(tinyMCE.settings.textarea_trigger) : "";
1634
1635                                                 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(element, "class")))
1636                                                         continue;
1637
1638                                                 if (trigger == "false")
1639                                                         continue;
1640
1641                                                 if ((tinyMCE.settings.ask || tinyMCE.settings.convert_on_click) && element) {
1642                                                         elementRefAr[elementRefAr.length] = element;
1643                                                         continue;
1644                                                 }
1645
1646                                                 if (element)
1647                                                         tinyMCE.addMCEControl(element, elements[i]);
1648                                         }
1649                                 break;
1650
1651                                 case "specific_textareas":
1652                                 case "textareas":
1653                                         elements = document.getElementsByTagName("textarea");
1654
1655                                         for (i=0; i<elements.length; i++) {
1656                                                 elm = elements.item(i);
1657                                                 trigger = elm.getAttribute(tinyMCE.settings.textarea_trigger);
1658
1659                                                 if (selector !== '' && !new RegExp('\\b' + selector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
1660                                                         continue;
1661
1662                                                 if (selector !== '')
1663                                                         trigger = selector !== '' ? "true" : "";
1664
1665                                                 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
1666                                                         continue;
1667
1668                                                 if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))
1669                                                         elementRefAr[elementRefAr.length] = elm;
1670                                         }
1671                                 break;
1672                         }
1673
1674                         for (i=0; i<elementRefAr.length; i++) {
1675                                 element = elementRefAr[i];
1676                                 elementId = element.name ? element.name : element.id;
1677
1678                                 if (tinyMCE.settings.ask || tinyMCE.settings.convert_on_click) {
1679                                         // Focus breaks in Mozilla
1680                                         if (tinyMCE.isGecko) {
1681                                                 settings = tinyMCE.settings;
1682
1683                                                 tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
1684
1685                                                 if (element.nodeName != "TEXTAREA" && element.nodeName != "INPUT")
1686                                                         tinyMCE.addEvent(element, "click", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
1687                                                 // tinyMCE.addEvent(element, "mouseover", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
1688                                         } else {
1689                                                 settings = tinyMCE.settings;
1690
1691                                                 tinyMCE.addEvent(element, "focus", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
1692                                                 tinyMCE.addEvent(element, "click", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
1693                                                 // tinyMCE.addEvent(element, "mouseenter", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
1694                                         }
1695                                 } else
1696                                         tinyMCE.addMCEControl(element, elementId);
1697                         }
1698
1699                         // Handle auto focus
1700                         if (tinyMCE.settings.auto_focus) {
1701                                 window.setTimeout(function () {
1702                                         var inst = tinyMCE.getInstanceById(tinyMCE.settings.auto_focus);
1703                                         inst.selection.selectNode(inst.getBody(), true, true);
1704                                         inst.contentWindow.focus();
1705                                 }, 100);
1706                         }
1707
1708                         tinyMCE.dispatchCallback(null, 'oninit', 'onInit');
1709                 }
1710         },
1711
1712         isInstance : function(o) {
1713                 return o != null && typeof(o) == "object" && o.isTinyMCE_Control;
1714         },
1715
1716         getParam : function(name, default_value, strip_whitespace, split_chr) {
1717                 var i, outArray, value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
1718
1719                 // Fix bool values
1720                 if (value == "true" || value == "false")
1721                         return (value == "true");
1722
1723                 if (strip_whitespace)
1724                         value = tinyMCE.regexpReplace(value, "[ \t\r\n]", "");
1725
1726                 if (typeof(split_chr) != "undefined" && split_chr != null) {
1727                         value = value.split(split_chr);
1728                         outArray = [];
1729
1730                         for (i=0; i<value.length; i++) {
1731                                 if (value[i] && value[i] !== '')
1732                                         outArray[outArray.length] = value[i];
1733                         }
1734
1735                         value = outArray;
1736                 }
1737
1738                 return value;
1739         },
1740
1741         getLang : function(name, default_value, parse_entities, va) {
1742                 var v = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name], n;
1743
1744                 if (parse_entities)
1745                         v = tinyMCE.entityDecode(v);
1746
1747                 if (va) {
1748                         for (n in va)
1749                                 v = this.replaceVar(v, n, va[n]);
1750                 }
1751
1752                 return v;
1753         },
1754
1755         entityDecode : function(s) {
1756                 var e = document.createElement("div");
1757
1758                 e.innerHTML = s;
1759
1760                 return !e.firstChild ? s : e.firstChild.nodeValue;
1761         },
1762
1763         addToLang : function(prefix, ar) {
1764                 var k;
1765
1766                 for (k in ar) {
1767                         if (typeof(ar[k]) == 'function')
1768                                 continue;
1769
1770                         tinyMCELang[(k.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix !== '' ? (prefix + "_") : '') + k] = ar[k];
1771                 }
1772
1773                 this.loadNextScript();
1774         },
1775
1776         triggerNodeChange : function(focus, setup_content) {
1777                 var elm, inst, editorId, undoIndex = -1, undoLevels = -1, doc, anySelection, st;
1778
1779                 if (tinyMCE.selectedInstance) {
1780                         inst = tinyMCE.selectedInstance;
1781                         elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement();
1782
1783 /*                      if (elm == inst.lastTriggerEl)
1784                                 return;
1785
1786                         inst.lastTriggerEl = elm;*/
1787
1788                         editorId = inst.editorId;
1789                         st = inst.selection.getSelectedText();
1790
1791                         if (tinyMCE.settings.auto_resize)
1792                                 inst.resizeToContent();
1793
1794                         if (setup_content && tinyMCE.isGecko && inst.isHidden())
1795                                 elm = inst.getBody();
1796
1797                         inst.switchSettings();
1798                         anySelection = !inst.selection.isCollapsed();
1799
1800                         if (tinyMCE.settings.custom_undo_redo) {
1801                                 undoIndex = inst.undoRedo.undoIndex;
1802                                 undoLevels = inst.undoRedo.undoLevels.length;
1803                         }
1804
1805                         tinyMCE.dispatchCallback(inst, 'handle_node_change_callback', 'handleNodeChange', editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);
1806                 }
1807
1808                 if (this.selectedInstance && (typeof(focus) == "undefined" || focus))
1809                         this.selectedInstance.contentWindow.focus();
1810         },
1811
1812         _customCleanup : function(inst, type, content) {
1813                 var pl, po, i, customCleanup;
1814
1815                 // Call custom cleanup
1816                 customCleanup = tinyMCE.settings.cleanup_callback;
1817                 if (customCleanup != '')
1818                         content = tinyMCE.resolveDots(tinyMCE.settings.cleanup_callback, window)(type, content, inst);
1819
1820                 // Trigger theme cleanup
1821                 po = tinyMCE.themes[tinyMCE.settings.theme];
1822                 if (po && po.cleanup)
1823                         content = po.cleanup(type, content, inst);
1824
1825                 // Trigger plugin cleanups
1826                 pl = inst.plugins;
1827                 for (i=0; i<pl.length; i++) {
1828                         po = tinyMCE.plugins[pl[i]];
1829
1830                         if (po && po.cleanup)
1831                                 content = po.cleanup(type, content, inst);
1832                 }
1833
1834                 return content;
1835         },
1836
1837         setContent : function(h) {
1838                 if (tinyMCE.selectedInstance) {
1839                         tinyMCE.selectedInstance.execCommand('mceSetContent', false, h);
1840                         tinyMCE.selectedInstance.repaint();
1841                 }
1842         },
1843
1844         importThemeLanguagePack : function(name) {
1845                 if (typeof(name) == "undefined")
1846                         name = tinyMCE.settings.theme;
1847
1848                 tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings.language + '.js');
1849         },
1850
1851         importPluginLanguagePack : function(name) {
1852                 var b = tinyMCE.baseURL + '/plugins/' + name;
1853
1854                 if (this.plugins[name])
1855                         b = this.plugins[name].baseURL;
1856
1857                 tinyMCE.loadScript(b + '/langs/' + tinyMCE.settings.language +  '.js');
1858         },
1859
1860         applyTemplate : function(h, ag) {
1861                 return h.replace(new RegExp('\\{\\$([a-z0-9_]+)\\}', 'gi'), function(m, s) {
1862                         if (s.indexOf('lang_') == 0 && tinyMCELang[s])
1863                                 return tinyMCELang[s];
1864
1865                         if (ag && ag[s])
1866                                 return ag[s];
1867
1868                         if (tinyMCE.settings[s])
1869                                 return tinyMCE.settings[s];
1870
1871                         if (m == 'themeurl')
1872                                 return tinyMCE.themeURL;
1873
1874                         return m;
1875                 });
1876         },
1877
1878         replaceVar : function(h, r, v) {
1879                 return h.replace(new RegExp('{\\\$' + r + '}', 'g'), v);
1880         },
1881
1882         openWindow : function(template, args) {
1883                 var html, width, height, x, y, resizable, scrollbars, url, name, win, modal, features;
1884
1885                 args = !args ? {} : args;
1886
1887                 args.mce_template_file = template.file;
1888                 args.mce_width = template.width;
1889                 args.mce_height = template.height;
1890                 tinyMCE.windowArgs = args;
1891
1892                 html = template.html;
1893                 if (!(width = parseInt(template.width)))
1894                         width = 320;
1895
1896                 if (!(height = parseInt(template.height)))
1897                         height = 200;
1898
1899                 // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!
1900                 if (tinyMCE.isIE)
1901                         height += 40;
1902                 else
1903                         height += 20;
1904
1905                 x = parseInt(screen.width / 2.0) - (width / 2.0);
1906                 y = parseInt(screen.height / 2.0) - (height / 2.0);
1907
1908                 resizable = (args && args.resizable) ? args.resizable : "no";
1909                 scrollbars = (args && args.scrollbars) ? args.scrollbars : "no";
1910
1911                 if (template.file.charAt(0) != '/' && template.file.indexOf('://') == -1)
1912                         url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template.file;
1913                 else
1914                         url = template.file;
1915
1916                 // Replace all args as variables in URL
1917                 for (name in args) {
1918                         if (typeof(args[name]) == 'function')
1919                                 continue;
1920
1921                         url = tinyMCE.replaceVar(url, name, escape(args[name]));
1922                 }
1923
1924                 if (html) {
1925                         html = tinyMCE.replaceVar(html, "css", this.settings.popups_css);
1926                         html = tinyMCE.applyTemplate(html, args);
1927
1928                         win = window.open("", "mcePopup" + new Date().getTime(), "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,minimizable=" + resizable + ",modal=yes,width=" + width + ",height=" + height + ",resizable=" + resizable);
1929                         if (win == null) {
1930                                 alert(tinyMCELang.lang_popup_blocked);
1931                                 return;
1932                         }
1933
1934                         win.document.write(html);
1935                         win.document.close();
1936                         win.resizeTo(width, height);
1937                         win.focus();
1938                 } else {
1939                         if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings.dialog_type == "modal") {
1940                                 height += 10;
1941
1942                                 features = "resizable:" + resizable + ";scroll:" + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:" + width + "px;dialogHeight:" + height + "px;";
1943
1944                                 window.showModalDialog(url, window, features);
1945                         } else {
1946                                 modal = (resizable == "yes") ? "no" : "yes";
1947
1948                                 if (tinyMCE.isGecko && tinyMCE.isMac)
1949                                         modal = "no";
1950
1951                                 if (template.close_previous != "no")
1952                                         try {tinyMCE.lastWindow.close();} catch (ex) {}
1953
1954                                 win = window.open(url, "mcePopup" + new Date().getTime(), "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=" + modal + ",minimizable=" + resizable + ",modal=" + modal + ",width=" + width + ",height=" + height + ",resizable=" + resizable);
1955                                 if (win == null) {
1956                                         alert(tinyMCELang.lang_popup_blocked);
1957                                         return;
1958                                 }
1959
1960                                 if (template.close_previous != "no")
1961                                         tinyMCE.lastWindow = win;
1962
1963                                 try {
1964                                         win.resizeTo(width, height);
1965                                 } catch(e) {
1966                                         // Ignore
1967                                 }
1968
1969                                 // Make it bigger if statusbar is forced
1970                                 if (tinyMCE.isGecko && win.document) {
1971                                         if (win.document.defaultView.statusbar.visible)
1972                                                 win.resizeBy(0, tinyMCE.isMac ? 10 : 24);
1973                                 }
1974
1975                                 win.focus();
1976                         }
1977                 }
1978         },
1979
1980         closeWindow : function(win) {
1981                 win.close();
1982         },
1983
1984         getVisualAidClass : function(class_name, state) {
1985                 var i, classNames, ar, className, aidClass = tinyMCE.settings.visual_table_class;
1986
1987                 if (typeof(state) == "undefined")
1988                         state = tinyMCE.settings.visual;
1989
1990                 // Split
1991                 classNames = [];
1992                 ar = class_name.split(' ');
1993                 for (i=0; i<ar.length; i++) {
1994                         if (ar[i] == aidClass)
1995                                 ar[i] = "";
1996
1997                         if (ar[i] !== '')
1998                                 classNames[classNames.length] = ar[i];
1999                 }
2000
2001                 if (state)
2002                         classNames[classNames.length] = aidClass;
2003
2004                 // Glue
2005                 className = "";
2006                 for (i=0; i<classNames.length; i++) {
2007                         if (i > 0)
2008                                 className += " ";
2009
2010                         className += classNames[i];
2011                 }
2012
2013                 return className;
2014         },
2015
2016         handleVisualAid : function(el, deep, state, inst, skip_dispatch) {
2017                 var i, x, y, tableElement, anchorName, oldW, oldH, bo, cn;
2018
2019                 if (!el)
2020                         return;
2021
2022                 if (!skip_dispatch)
2023                         tinyMCE.dispatchCallback(inst, 'handle_visual_aid_callback', 'handleVisualAid', el, deep, state, inst);
2024
2025                 tableElement = null;
2026
2027                 switch (el.nodeName) {
2028                         case "TABLE":
2029                                 oldW = el.style.width;
2030                                 oldH = el.style.height;
2031                                 bo = tinyMCE.getAttrib(el, "border");
2032
2033                                 bo = bo == '' || bo == "0" ? true : false;
2034
2035                                 tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo));
2036
2037                                 el.style.width = oldW;
2038                                 el.style.height = oldH;
2039
2040                                 for (y=0; y<el.rows.length; y++) {
2041                                         for (x=0; x<el.rows[y].cells.length; x++) {
2042                                                 cn = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el.rows[y].cells[x], "class"), state && bo);
2043                                                 tinyMCE.setAttrib(el.rows[y].cells[x], "class", cn);
2044                                         }
2045                                 }
2046
2047                                 break;
2048
2049                         case "A":
2050                                 anchorName = tinyMCE.getAttrib(el, "name");
2051
2052                                 if (anchorName !== '' && state) {
2053                                         el.title = anchorName;
2054                                         tinyMCE.addCSSClass(el, 'mceItemAnchor');
2055                                 } else if (anchorName !== '' && !state)
2056                                         el.className = '';
2057
2058                                 break;
2059                 }
2060
2061                 if (deep && el.hasChildNodes()) {
2062                         for (i=0; i<el.childNodes.length; i++)
2063                                 tinyMCE.handleVisualAid(el.childNodes[i], deep, state, inst, true);
2064                 }
2065         },
2066
2067         fixGeckoBaseHREFBug : function(m, e, h) {
2068                 var xsrc, xhref;
2069
2070                 if (tinyMCE.isGecko) {
2071                         if (m == 1) {
2072                                 h = h.replace(/\ssrc=/gi, " mce_tsrc=");
2073                                 h = h.replace(/\shref=/gi, " mce_thref=");
2074
2075                                 return h;
2076                         } else {
2077                                 // Why bother if there is no src or href broken
2078                                 if (!new RegExp('(src|href)=', 'g').test(h))
2079                                         return h;
2080
2081                                 // Restore src and href that gets messed up by Gecko
2082                                 tinyMCE.selectElements(e, 'A,IMG,SELECT,AREA,IFRAME,BASE,INPUT,SCRIPT,EMBED,OBJECT,LINK', function (n) {
2083                                         xsrc = tinyMCE.getAttrib(n, "mce_tsrc");
2084                                         xhref = tinyMCE.getAttrib(n, "mce_thref");
2085
2086                                         if (xsrc !== '') {
2087                                                 try {
2088                                                         n.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, xsrc);
2089                                                 } catch (e) {
2090                                                         // Ignore, Firefox cast exception if local file wasn't found
2091                                                 }
2092
2093                                                 n.removeAttribute("mce_tsrc");
2094                                         }
2095
2096                                         if (xhref !== '') {
2097                                                 try {
2098                                                         n.href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, xhref);
2099                                                 } catch (e) {
2100                                                         // Ignore, Firefox cast exception if local file wasn't found
2101                                                 }
2102
2103                                                 n.removeAttribute("mce_thref");
2104                                         }
2105
2106                                         return false;
2107                                 });
2108
2109                                 // Restore text/comment nodes
2110                                 tinyMCE.selectNodes(e, function(n) {
2111                                         if (n.nodeType == 3 || n.nodeType == 8) {
2112                                                 n.nodeValue = n.nodeValue.replace(/\smce_tsrc=/gi, " src=");
2113                                                 n.nodeValue = n.nodeValue.replace(/\smce_thref=/gi, " href=");
2114                                         }
2115
2116                                         return false;
2117                                 });
2118                         }
2119                 }
2120
2121                 return h;
2122         },
2123
2124         _setHTML : function(doc, html_content) {
2125                 var i, html, paras, node;
2126
2127                 // Force closed anchors open
2128                 //html_content = html_content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
2129
2130                 html_content = tinyMCE.cleanupHTMLCode(html_content);
2131
2132                 // Try innerHTML if it fails use pasteHTML in MSIE
2133                 try {
2134                         tinyMCE.setInnerHTML(doc.body, html_content);
2135                 } catch (e) {
2136                         if (this.isMSIE)
2137                                 doc.body.createTextRange().pasteHTML(html_content);
2138                 }
2139
2140                 // Content duplication bug fix
2141                 if (tinyMCE.isIE && tinyMCE.settings.fix_content_duplication) {
2142                         // Remove P elements in P elements
2143                         paras = doc.getElementsByTagName("P");
2144                         for (i=0; i<paras.length; i++) {
2145                                 node = paras[i];
2146
2147                                 while ((node = node.parentNode) != null) {
2148                                         if (node.nodeName == "P")
2149                                                 node.outerHTML = node.innerHTML;
2150                                 }
2151                         }
2152
2153                         // Content duplication bug fix (Seems to be word crap)
2154                         html = doc.body.innerHTML;
2155
2156                         // Always set the htmlText output
2157                         tinyMCE.setInnerHTML(doc.body, html);
2158                 }
2159
2160                 tinyMCE.cleanupAnchors(doc);
2161
2162                 if (tinyMCE.getParam("convert_fonts_to_spans"))
2163                         tinyMCE.convertSpansToFonts(doc);
2164         },
2165
2166         getEditorId : function(form_element) {
2167                 var inst = this.getInstanceById(form_element);
2168
2169                 if (!inst)
2170                         return null;
2171
2172                 return inst.editorId;
2173         },
2174
2175         getInstanceById : function(editor_id) {
2176                 var inst = this.instances[editor_id], n;
2177
2178                 if (!inst) {
2179                         for (n in tinyMCE.instances) {
2180                                 inst = tinyMCE.instances[n];
2181
2182                                 if (!tinyMCE.isInstance(inst))
2183                                         continue;
2184
2185                                 if (inst.formTargetElementId == editor_id)
2186                                         return inst;
2187                         }
2188                 } else
2189                         return inst;
2190
2191                 return null;
2192         },
2193
2194         queryInstanceCommandValue : function(editor_id, command) {
2195                 var inst = tinyMCE.getInstanceById(editor_id);
2196
2197                 if (inst)
2198                         return inst.queryCommandValue(command);
2199
2200                 return false;
2201         },
2202
2203         queryInstanceCommandState : function(editor_id, command) {
2204                 var inst = tinyMCE.getInstanceById(editor_id);
2205
2206                 if (inst)
2207                         return inst.queryCommandState(command);
2208
2209                 return null;
2210         },
2211
2212         setWindowArg : function(n, v) {
2213                 this.windowArgs[n] = v;
2214         },
2215
2216         getWindowArg : function(n, d) {
2217                 return (typeof(this.windowArgs[n]) == "undefined") ? d : this.windowArgs[n];
2218         },
2219
2220         getCSSClasses : function(editor_id, doc) {
2221                 var i, c, x, rule, styles, rules, csses, selectorText, inst = tinyMCE.getInstanceById(editor_id);
2222                 var cssClass, addClass, p;
2223
2224                 if (!inst)
2225                         inst = tinyMCE.selectedInstance;
2226
2227                 if (!inst)
2228                         return [];
2229
2230                 if (!doc)
2231                         doc = inst.getDoc();
2232
2233                 // Is cached, use that
2234                 if (inst && inst.cssClasses.length > 0)
2235                         return inst.cssClasses;
2236
2237                 if (!doc)
2238                         return;
2239
2240                 styles = doc.styleSheets;
2241
2242                 if (styles && styles.length > 0) {
2243                         for (x=0; x<styles.length; x++) {
2244                                 csses = null;
2245
2246                                 try {
2247                                         csses = tinyMCE.isIE ? doc.styleSheets(x).rules : styles[x].cssRules;
2248                                 } catch(e) {
2249                                         // Just ignore any errors I know this is ugly!!
2250                                 }
2251         
2252                                 if (!csses)
2253                                         return [];
2254
2255                                 for (i=0; i<csses.length; i++) {
2256                                         selectorText = csses[i].selectorText;
2257
2258                                         // Can be multiple rules per selector
2259                                         if (selectorText) {
2260                                                 rules = selectorText.split(',');
2261                                                 for (c=0; c<rules.length; c++) {
2262                                                         rule = rules[c];
2263
2264                                                         // Strip spaces between selectors
2265                                                         while (rule.indexOf(' ') == 0)
2266                                                                 rule = rule.substring(1);
2267
2268                                                         // Invalid rule
2269                                                         if (rule.indexOf(' ') != -1 || rule.indexOf(':') != -1 || rule.indexOf('mceItem') != -1)
2270                                                                 continue;
2271
2272                                                         if (rule.indexOf(tinyMCE.settings.visual_table_class) != -1 || rule.indexOf('mceEditable') != -1 || rule.indexOf('mceNonEditable') != -1)
2273                                                                 continue;
2274
2275                                                         // Is class rule
2276                                                         if (rule.indexOf('.') != -1) {
2277                                                                 cssClass = rule.substring(rule.indexOf('.') + 1);
2278                                                                 addClass = true;
2279
2280                                                                 for (p=0; p<inst.cssClasses.length && addClass; p++) {
2281                                                                         if (inst.cssClasses[p] == cssClass)
2282                                                                                 addClass = false;
2283                                                                 }
2284
2285                                                                 if (addClass)
2286                                                                         inst.cssClasses[inst.cssClasses.length] = cssClass;
2287                                                         }
2288                                                 }
2289                                         }
2290                                 }
2291                         }
2292                 }
2293
2294                 return inst.cssClasses;
2295         },
2296
2297         regexpReplace : function(in_str, reg_exp, replace_str, opts) {
2298                 var re;
2299
2300                 if (in_str == null)
2301                         return in_str;
2302
2303                 if (typeof(opts) == "undefined")
2304                         opts = 'g';
2305
2306                 re = new RegExp(reg_exp, opts);
2307
2308                 return in_str.replace(re, replace_str);
2309         },
2310
2311         trim : function(s) {
2312                 return s.replace(/^\s*|\s*$/g, "");
2313         },
2314
2315         cleanupEventStr : function(s) {
2316                 s = "" + s;
2317                 s = s.replace('function anonymous()\n{\n', '');
2318                 s = s.replace('\n}', '');
2319                 s = s.replace(/^return true;/gi, ''); // Remove event blocker
2320
2321                 return s;
2322         },
2323
2324         getControlHTML : function(c) {
2325                 var i, l, n, o, v, rtl = tinyMCE.getLang('lang_dir') == 'rtl';
2326
2327                 l = tinyMCE.plugins;
2328                 for (n in l) {
2329                         o = l[n];
2330
2331                         if (o.getControlHTML && (v = o.getControlHTML(c)) !== '') {
2332                                 if (rtl)
2333                                         return '<span dir="rtl">' + tinyMCE.replaceVar(v, "pluginurl", o.baseURL) + '</span>';
2334
2335                                 return tinyMCE.replaceVar(v, "pluginurl", o.baseURL);
2336                         }
2337                 }
2338
2339                 o = tinyMCE.themes[tinyMCE.settings.theme];
2340                 if (o.getControlHTML && (v = o.getControlHTML(c)) !== '') {
2341                         if (rtl)
2342                                 return '<span dir="rtl">' + v + '</span>';
2343
2344                         return v;
2345                 }
2346
2347                 return '';
2348         },
2349
2350         evalFunc : function(f, idx, a, o) {
2351                 o = !o ? window : o;
2352                 f = typeof(f) == 'function' ? f : o[f];
2353
2354                 return f.apply(o, Array.prototype.slice.call(a, idx));
2355         },
2356
2357         dispatchCallback : function(i, p, n) {
2358                 return this.callFunc(i, p, n, 0, this.dispatchCallback.arguments);
2359         },
2360
2361         executeCallback : function(i, p, n) {
2362                 return this.callFunc(i, p, n, 1, this.executeCallback.arguments);
2363         },
2364
2365         execCommandCallback : function(i, p, n) {
2366                 return this.callFunc(i, p, n, 2, this.execCommandCallback.arguments);
2367         },
2368
2369         callFunc : function(ins, p, n, m, a) {
2370                 var l, i, on, o, s, v;
2371
2372                 s = m == 2;
2373
2374                 l = tinyMCE.getParam(p, '');
2375
2376                 if (l !== '' && (v = tinyMCE.evalFunc(l, 3, a)) == s && m > 0)
2377                         return true;
2378
2379                 if (ins != null) {
2380                         for (i=0, l = ins.plugins; i<l.length; i++) {
2381                                 o = tinyMCE.plugins[l[i]];
2382
2383                                 if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
2384                                         return true;
2385                         }
2386                 }
2387
2388                 l = tinyMCE.themes;
2389                 for (on in l) {
2390                         o = l[on];
2391
2392                         if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
2393                                 return true;
2394                 }
2395
2396                 return false;
2397         },
2398
2399         resolveDots : function(s, o) {
2400                 var i;
2401
2402                 if (typeof(s) == 'string') {
2403                         for (i=0, s=s.split('.'); i<s.length; i++)
2404                                 o = o[s[i]];
2405                 } else
2406                         o = s;
2407
2408                 return o;
2409         },
2410
2411         xmlEncode : function(s) {
2412                 return s ? ('' + s).replace(this.xmlEncodeRe, function (c, b) {
2413                         switch (c) {
2414                                 case '&':
2415                                         return '&amp;';
2416
2417                                 case '"':
2418                                         return '&quot;';
2419
2420                                 case '<':
2421                                         return '&lt;';
2422
2423                                 case '>':
2424                                         return '&gt;';
2425                         }
2426
2427                         return c;
2428                 }) : s;
2429         },
2430
2431         add : function(c, m) {
2432                 var n;
2433
2434                 for (n in m) {
2435                         if (m.hasOwnProperty(n))
2436                                 c.prototype[n] = m[n];
2437                 }
2438         },
2439
2440         extend : function(p, np) {
2441                 var o = {}, n;
2442
2443                 o.parent = p;
2444
2445                 for (n in p) {
2446                         if (p.hasOwnProperty(n))
2447                                 o[n] = p[n];
2448                 }
2449
2450                 for (n in np) {
2451                         if (np.hasOwnProperty(n))
2452                                 o[n] = np[n];
2453                 }
2454
2455                 return o;
2456         },
2457
2458         hideMenus : function() {
2459                 var e = tinyMCE.lastSelectedMenuBtn;
2460
2461                 if (tinyMCE.lastMenu) {
2462                         tinyMCE.lastMenu.hide();
2463                         tinyMCE.lastMenu = null;
2464                 }
2465
2466                 if (e) {
2467                         tinyMCE.switchClass(e, tinyMCE.lastMenuBtnClass);
2468                         tinyMCE.lastSelectedMenuBtn = null;
2469                 }
2470         }
2471
2472         };
2473
2474 // Global instances
2475 var TinyMCE = TinyMCE_Engine; // Compatiblity with gzip compressors
2476 var tinyMCE = new TinyMCE_Engine();
2477 var tinyMCELang = {};
2478
2479 /* file:jscripts/tiny_mce/classes/TinyMCE_Control.class.js */
2480
2481 function TinyMCE_Control(settings) {
2482         var t, i, tos, fu, p, x, fn, fu, pn, s = settings;
2483
2484         this.undoRedoLevel = true;
2485         this.isTinyMCE_Control = true;
2486
2487         // Default settings
2488         this.enabled = true;
2489         this.settings = s;
2490         this.settings.theme = tinyMCE.getParam("theme", "default");
2491         this.settings.width = tinyMCE.getParam("width", -1);
2492         this.settings.height = tinyMCE.getParam("height", -1);
2493         this.selection = new TinyMCE_Selection(this);
2494         this.undoRedo = new TinyMCE_UndoRedo(this);
2495         this.cleanup = new TinyMCE_Cleanup();
2496         this.shortcuts = [];
2497         this.hasMouseMoved = false;
2498         this.foreColor = this.backColor = "#999999";
2499         this.data = {};
2500         this.cssClasses = [];
2501
2502         this.cleanup.init({
2503                 valid_elements : s.valid_elements,
2504                 extended_valid_elements : s.extended_valid_elements,
2505                 valid_child_elements : s.valid_child_elements,
2506                 entities : s.entities,
2507                 entity_encoding : s.entity_encoding,
2508                 debug : s.cleanup_debug,
2509                 indent : s.apply_source_formatting,
2510                 invalid_elements : s.invalid_elements,
2511                 verify_html : s.verify_html,
2512                 fix_content_duplication : s.fix_content_duplication,
2513                 convert_fonts_to_spans : s.convert_fonts_to_spans
2514         });
2515
2516         // Wrap old theme
2517         t = this.settings.theme;
2518         if (!tinyMCE.hasTheme(t)) {
2519                 fn = tinyMCE.callbacks;
2520                 tos = {};
2521
2522                 for (i=0; i<fn.length; i++) {
2523                         if ((fu = window['TinyMCE_' + t + "_" + fn[i]]))
2524                                 tos[fn[i]] = fu;
2525                 }
2526
2527                 tinyMCE.addTheme(t, tos);
2528         }
2529
2530         // Wrap old plugins
2531         this.plugins = [];
2532         p = tinyMCE.getParam('plugins', '', true, ',');
2533         if (p.length > 0) {
2534                 for (i=0; i<p.length; i++) {
2535                         pn = p[i];
2536
2537                         if (pn.charAt(0) == '-')
2538                                 pn = pn.substring(1);
2539
2540                         if (!tinyMCE.hasPlugin(pn)) {
2541                                 fn = tinyMCE.callbacks;
2542                                 tos = {};
2543
2544                                 for (x=0; x<fn.length; x++) {
2545                                         if ((fu = window['TinyMCE_' + pn + "_" + fn[x]]))
2546                                                 tos[fn[x]] = fu;
2547                                 }
2548
2549                                 tinyMCE.addPlugin(pn, tos);
2550                         }
2551
2552                         this.plugins[this.plugins.length] = pn; 
2553                 }
2554         }
2555 };
2556
2557 TinyMCE_Control.prototype = {
2558         selection : null,
2559
2560         settings : null,
2561
2562         cleanup : null,
2563
2564         getData : function(na) {
2565                 var o = this.data[na];
2566
2567                 if (!o)
2568                         o = this.data[na] = {};
2569
2570                 return o;
2571         },
2572
2573         hasPlugin : function(n) {
2574                 var i;
2575
2576                 for (i=0; i<this.plugins.length; i++) {
2577                         if (this.plugins[i] == n)
2578                                 return true;
2579                 }
2580
2581                 return false;
2582         },
2583
2584         addPlugin : function(n, p) {
2585                 if (!this.hasPlugin(n)) {
2586                         tinyMCE.addPlugin(n, p);
2587                         this.plugins[this.plugins.length] = n;
2588                 }
2589         },
2590
2591         repaint : function() {
2592                 var s, b, ex;
2593
2594                 if (tinyMCE.isRealIE)
2595                         return;
2596
2597                 try {
2598                         s = this.selection;
2599                         b = s.getBookmark(true);
2600                         this.getBody().style.display = 'none';
2601                         this.getDoc().execCommand('selectall', false, null);
2602                         this.getSel().collapseToStart();
2603                         this.getBody().style.display = 'block';
2604                         s.moveToBookmark(b);
2605                 } catch (ex) {
2606                         // Ignore
2607                 }
2608         },
2609
2610         switchSettings : function() {
2611                 if (tinyMCE.configs.length > 1 && tinyMCE.currentConfig != this.settings.index) {
2612                         tinyMCE.settings = this.settings;
2613                         tinyMCE.currentConfig = this.settings.index;
2614                 }
2615         },
2616
2617         select : function() {
2618                 var oldInst = tinyMCE.selectedInstance;
2619
2620                 if (oldInst != this) {
2621                         if (oldInst)
2622                                 oldInst.execCommand('mceEndTyping');
2623
2624                         tinyMCE.dispatchCallback(this, 'select_instance_callback', 'selectInstance', this, oldInst);
2625                         tinyMCE.selectedInstance = this;
2626                 }
2627         },
2628
2629         getBody : function() {
2630                 return this.contentBody ? this.contentBody : this.getDoc().body;
2631         },
2632
2633         getDoc : function() {
2634 //              return this.contentDocument ? this.contentDocument : this.contentWindow.document; // Removed due to IE 5.5 ?
2635                 return this.contentWindow.document;
2636         },
2637
2638         getWin : function() {
2639                 return this.contentWindow;
2640         },
2641
2642         getContainerWin : function() {
2643                 return this.containerWindow ? this.containerWindow : window;
2644         },
2645
2646         getViewPort : function() {
2647                 return tinyMCE.getViewPort(this.getWin());
2648         },
2649
2650         getParentNode : function(n, f) {
2651                 return tinyMCE.getParentNode(n, f, this.getBody());
2652         },
2653
2654         getParentElement : function(n, na, f) {
2655                 return tinyMCE.getParentElement(n, na, f, this.getBody());
2656         },
2657
2658         getParentBlockElement : function(n) {
2659                 return tinyMCE.getParentBlockElement(n, this.getBody());
2660         },
2661
2662         resizeToContent : function() {
2663                 var d = this.getDoc(), b = d.body, de = d.documentElement;
2664
2665                 this.iframeElement.style.height = (tinyMCE.isRealIE) ? b.scrollHeight : de.offsetHeight + 'px';
2666         },
2667
2668         addShortcut : function(m, k, d, cmd, ui, va) {
2669                 var n = typeof(k) == "number", ie = tinyMCE.isIE, c, sc, i, scl = this.shortcuts;
2670
2671                 if (!tinyMCE.getParam('custom_shortcuts'))
2672                         return false;
2673
2674                 m = m.toLowerCase();
2675                 k = ie && !n ? k.toUpperCase() : k;
2676                 c = n ? null : k.charCodeAt(0);
2677                 d = d && d.indexOf('lang_') == 0 ? tinyMCE.getLang(d) : d;
2678
2679                 sc = {
2680                         alt : m.indexOf('alt') != -1,
2681                         ctrl : m.indexOf('ctrl') != -1,
2682                         shift : m.indexOf('shift') != -1,
2683                         charCode : c,
2684                         keyCode : n ? k : (ie ? c : null),
2685                         desc : d,
2686                         cmd : cmd,
2687                         ui : ui,
2688                         val : va
2689                 };
2690
2691                 for (i=0; i<scl.length; i++) {
2692                         if (sc.alt == scl[i].alt && sc.ctrl == scl[i].ctrl && sc.shift == scl[i].shift
2693                                 && sc.charCode == scl[i].charCode && sc.keyCode == scl[i].keyCode) {
2694                                 return false;
2695                         }
2696                 }
2697
2698                 scl[scl.length] = sc;
2699
2700                 return true;
2701         },
2702
2703         handleShortcut : function(e) {
2704                 var i, s, o;
2705
2706                 // Normal key press, then ignore it
2707                 if (!e.altKey && !e.ctrlKey)
2708                         return false;
2709
2710                 s = this.shortcuts;
2711
2712                 for (i=0; i<s.length; i++) {
2713                         o = s[i];
2714
2715                         if (o.alt == e.altKey && o.ctrl == e.ctrlKey && (o.keyCode == e.keyCode || o.charCode == e.charCode)) {
2716                                 if (o.cmd && (e.type == "keydown" || (e.type == "keypress" && !tinyMCE.isOpera)))
2717                                         tinyMCE.execCommand(o.cmd, o.ui, o.val);
2718
2719                                 tinyMCE.cancelEvent(e);
2720                                 return true;
2721                         }
2722                 }
2723
2724                 return false;
2725         },
2726
2727         autoResetDesignMode : function() {
2728                 // Add fix for tab/style.display none/block problems in Gecko
2729                 if (!tinyMCE.isIE && this.isHidden() && tinyMCE.getParam('auto_reset_designmode'))
2730                         eval('try { this.getDoc().designMode = "On"; this.useCSS = false; } catch(e) {}');
2731         },
2732
2733         isHidden : function() {
2734                 var s;
2735
2736                 if (tinyMCE.isIE)
2737                         return false;
2738
2739                 s = this.getSel();
2740
2741                 // Weird, wheres that cursor selection?
2742                 return (!s || !s.rangeCount || s.rangeCount == 0);
2743         },
2744
2745         isDirty : function() {
2746                 // Is content modified and not in a submit procedure
2747                 return tinyMCE.trim(this.startContent) != tinyMCE.trim(this.getBody().innerHTML) && !this.isNotDirty;
2748         },
2749
2750         _mergeElements : function(scmd, pa, ch, override) {
2751                 var st, stc, className, n;
2752
2753                 if (scmd == "removeformat") {
2754                         pa.className = "";
2755                         pa.style.cssText = "";
2756                         ch.className = "";
2757                         ch.style.cssText = "";
2758                         return;
2759                 }
2760
2761                 st = tinyMCE.parseStyle(tinyMCE.getAttrib(pa, "style"));
2762                 stc = tinyMCE.parseStyle(tinyMCE.getAttrib(ch, "style"));
2763                 className = tinyMCE.getAttrib(pa, "class");
2764
2765                 // Removed class adding due to bug #1478272
2766                 className = tinyMCE.getAttrib(ch, "class");
2767
2768                 if (override) {
2769                         for (n in st) {
2770                                 if (typeof(st[n]) == 'function')
2771                                         continue;
2772
2773                                 stc[n] = st[n];
2774                         }
2775                 } else {
2776                         for (n in stc) {
2777                                 if (typeof(stc[n]) == 'function')
2778                                         continue;
2779
2780                                 st[n] = stc[n];
2781                         }
2782                 }
2783
2784                 tinyMCE.setAttrib(pa, "style", tinyMCE.serializeStyle(st));
2785                 tinyMCE.setAttrib(pa, "class", tinyMCE.trim(className));
2786                 ch.className = "";
2787                 ch.style.cssText = "";
2788                 ch.removeAttribute("class");
2789                 ch.removeAttribute("style");
2790         },
2791
2792         _fixRootBlocks : function() {
2793                 var rb, b, ne, be, nx, bm;
2794
2795                 rb = tinyMCE.getParam('forced_root_block');
2796                 if (!rb)
2797                         return;
2798
2799                 b = this.getBody();
2800                 ne = b.firstChild;
2801
2802                 while (ne) {
2803                         nx = ne.nextSibling;
2804
2805                         // If text node or inline element wrap it in a block element
2806                         if ((ne.nodeType == 3 && ne.nodeValue.replace(/\s+/g, '') != '') || (ne.nodeType == 1 && !tinyMCE.blockRegExp.test(ne.nodeName))) {
2807                                 if (!bm)
2808                                         bm = this.selection.getBookmark();
2809
2810                                 if (!be) {
2811                                         be = this.getDoc().createElement(rb);
2812                                         be.appendChild(ne.cloneNode(true));
2813                                         b.replaceChild(be, ne);
2814                                 } else {
2815                                         be.appendChild(ne.cloneNode(true));
2816                                         b.removeChild(ne);
2817                                 }
2818                         } else
2819                                 be = null;
2820
2821                         ne = nx;
2822                 }
2823
2824                 if (bm)
2825                         this.selection.moveToBookmark(bm);
2826         },
2827
2828         _fixTrailingNbsp : function() {
2829                 var s = this.selection, e = s.getFocusElement(), bm, v;
2830
2831                 if (e && tinyMCE.blockRegExp.test(e.nodeName) && e.firstChild) {
2832                         v = e.firstChild.nodeValue;
2833
2834                         if (v && v.length > 1 && /(^\u00a0|\u00a0$)/.test(v)) {
2835                                 e.firstChild.nodeValue = v.replace(/(^\u00a0|\u00a0$)/, '');
2836                                 s.selectNode(e.firstChild, true, false, false); // Select and collapse
2837                         }
2838                 }
2839         },
2840
2841         _setUseCSS : function(b) {
2842                 var d = this.getDoc();
2843
2844                 try {d.execCommand("useCSS", false, !b);} catch (ex) {}
2845                 try {d.execCommand("styleWithCSS", false, b);} catch (ex) {}
2846
2847                 if (!tinyMCE.getParam("table_inline_editing"))
2848                         try {d.execCommand('enableInlineTableEditing', false, "false");} catch (ex) {}
2849
2850                 if (!tinyMCE.getParam("object_resizing"))
2851                         try {d.execCommand('enableObjectResizing', false, "false");} catch (ex) {}
2852         },
2853
2854         execCommand : function(command, user_interface, value) {
2855                 var i, x, z, align, img, div, doc = this.getDoc(), win = this.getWin(), focusElm = this.getFocusElement();
2856
2857                 // Is not a undo specific command
2858                 if (!new RegExp('mceStartTyping|mceEndTyping|mceBeginUndoLevel|mceEndUndoLevel|mceAddUndoLevel', 'gi').test(command))
2859                         this.undoBookmark = null;
2860
2861                 // Mozilla issue
2862                 if (!tinyMCE.isIE && !this.useCSS) {
2863                         this._setUseCSS(false);
2864                         this.useCSS = true;
2865                 }
2866
2867                 //debug("command: " + command + ", user_interface: " + user_interface + ", value: " + value);
2868                 this.contentDocument = doc; // <-- Strange, unless this is applied Mozilla 1.3 breaks
2869
2870                 // Don't dispatch key commands
2871                 if (!/mceStartTyping|mceEndTyping/.test(command)) {
2872                         if (tinyMCE.execCommandCallback(this, 'execcommand_callback', 'execCommand', this.editorId, this.getBody(), command, user_interface, value))
2873                                 return;
2874                 }
2875
2876                 // Fix align on images
2877                 if (focusElm && focusElm.nodeName == "IMG") {
2878                         align = focusElm.getAttribute('align');
2879                         img = command == "JustifyCenter" ? focusElm.cloneNode(false) : focusElm;
2880
2881                         switch (command) {
2882                                 case "JustifyLeft":
2883                                         if (align == 'left') {
2884                                                 img.setAttribute('align', ''); // Needed for IE
2885                                                 img.removeAttribute('align');
2886                                         } else
2887                                                 img.setAttribute('align', 'left');
2888
2889                                         // Remove the div
2890                                         div = focusElm.parentNode;
2891                                         if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
2892                                                 div.parentNode.replaceChild(img, div);
2893
2894                                         this.selection.selectNode(img);
2895                                         this.repaint();
2896                                         tinyMCE.triggerNodeChange();
2897                                         return;
2898
2899                                 case "JustifyCenter":
2900                                         img.setAttribute('align', ''); // Needed for IE
2901                                         img.removeAttribute('align');
2902
2903                                         // Is centered
2904                                         div = tinyMCE.getParentElement(focusElm, "div");
2905                                         if (div && div.style.textAlign == "center") {
2906                                                 // Remove div
2907                                                 if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
2908                                                         div.parentNode.replaceChild(img, div);
2909                                         } else {
2910                                                 // Add div
2911                                                 div = this.getDoc().createElement("div");
2912                                                 div.style.textAlign = 'center';
2913                                                 div.appendChild(img);
2914                                                 focusElm.parentNode.replaceChild(div, focusElm);
2915                                         }
2916
2917                                         this.selection.selectNode(img);
2918                                         this.repaint();
2919                                         tinyMCE.triggerNodeChange();
2920                                         return;
2921
2922                                 case "JustifyRight":
2923                                         if (align == 'right') {
2924                                                 img.setAttribute('align', ''); // Needed for IE
2925                                                 img.removeAttribute('align');
2926                                         } else
2927                                                 img.setAttribute('align', 'right');
2928
2929                                         // Remove the div
2930                                         div = focusElm.parentNode;
2931                                         if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
2932                                                 div.parentNode.replaceChild(img, div);
2933
2934                                         this.selection.selectNode(img);
2935                                         this.repaint();
2936                                         tinyMCE.triggerNodeChange();
2937                                         return;
2938                         }
2939                 }
2940
2941                 if (tinyMCE.settings.force_br_newlines) {
2942                         var alignValue = "";
2943
2944                         if (doc.selection.type != "Control") {
2945                                 switch (command) {
2946                                                 case "JustifyLeft":
2947                                                         alignValue = "left";
2948                                                         break;
2949
2950                                                 case "JustifyCenter":
2951                                                         alignValue = "center";
2952                                                         break;
2953
2954                                                 case "JustifyFull":
2955                                                         alignValue = "justify";
2956                                                         break;
2957
2958                                                 case "JustifyRight":
2959                                                         alignValue = "right";
2960                                                         break;
2961                                 }
2962
2963                                 if (alignValue !== '') {
2964                                         var rng = doc.selection.createRange();
2965
2966                                         if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null)
2967                                                 divElm.setAttribute("align", alignValue);
2968                                         else if (rng.pasteHTML && rng.htmlText.length > 0)
2969                                                 rng.pasteHTML('<div align="' + alignValue + '">' + rng.htmlText + "</div>");
2970
2971                                         tinyMCE.triggerNodeChange();
2972                                         return;
2973                                 }
2974                         }
2975                 }
2976
2977                 switch (command) {
2978                         case "mceRepaint":
2979                                 this.repaint();
2980                                 return true;
2981
2982                         case "JustifyLeft":
2983                         case "JustifyCenter":
2984                         case "JustifyFull":
2985                         case "JustifyRight":
2986                                 var el = tinyMCE.getParentNode(focusElm, function(n) {return tinyMCE.getAttrib(n, 'align');});
2987
2988                                 if (el) {
2989                                         el.setAttribute('align', ''); // Needed for IE
2990                                         el.removeAttribute('align');
2991                                 } else
2992                                         this.getDoc().execCommand(command, user_interface, value);
2993
2994                                 tinyMCE.triggerNodeChange();
2995
2996                                 return true;
2997
2998                         case "unlink":
2999                                 // Unlink if caret is inside link
3000                                 if (tinyMCE.isGecko && this.getSel().isCollapsed) {
3001                                         focusElm = tinyMCE.getParentElement(focusElm, 'A');
3002
3003                                         if (focusElm)
3004                                                 this.selection.selectNode(focusElm, false);
3005                                 }
3006
3007                                 this.getDoc().execCommand(command, user_interface, value);
3008
3009                                 tinyMCE.isGecko && this.getSel().collapseToEnd();
3010
3011                                 tinyMCE.triggerNodeChange();
3012
3013                                 return true;
3014
3015                         case "InsertUnorderedList":
3016                         case "InsertOrderedList":
3017                                 this.getDoc().execCommand(command, user_interface, value);
3018                                 tinyMCE.triggerNodeChange();
3019                                 break;
3020
3021                         case "Strikethrough":
3022                                 this.getDoc().execCommand(command, user_interface, value);
3023                                 tinyMCE.triggerNodeChange();
3024                                 break;
3025
3026                         case "mceSelectNode":
3027                                 this.selection.selectNode(value);
3028                                 tinyMCE.triggerNodeChange();
3029                                 tinyMCE.selectedNode = value;
3030                                 break;
3031
3032                         case "FormatBlock":
3033                                 if (value == null || value == '') {
3034                                         var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address,blockquote,dt,dl,dd,samp");
3035
3036                                         if (elm)
3037                                                 this.execCommand("mceRemoveNode", false, elm);
3038                                 } else {
3039                                         if (!this.cleanup.isValid(value))
3040                                                 return true;
3041
3042                                         if (tinyMCE.isGecko && new RegExp('<(div|blockquote|code|dt|dd|dl|samp)>', 'gi').test(value))
3043                                                 value = value.replace(/[^a-z]/gi, '');
3044
3045                                         if (tinyMCE.isIE && new RegExp('blockquote|code|samp', 'gi').test(value)) {
3046                                                 var b = this.selection.getBookmark();
3047                                                 this.getDoc().execCommand("FormatBlock", false, '<p>');
3048                                                 tinyMCE.renameElement(tinyMCE.getParentBlockElement(this.getFocusElement()), value);
3049                                                 this.selection.moveToBookmark(b);
3050                                         } else
3051                                                 this.getDoc().execCommand("FormatBlock", false, value);
3052                                 }
3053
3054                                 tinyMCE.triggerNodeChange();
3055
3056                                 break;
3057
3058                         case "mceRemoveNode":
3059                                 if (!value)
3060                                         value = tinyMCE.getParentElement(this.getFocusElement());
3061
3062                                 if (tinyMCE.isIE) {
3063                                         value.outerHTML = value.innerHTML;
3064                                 } else {
3065                                         var rng = value.ownerDocument.createRange();
3066                                         rng.setStartBefore(value);
3067                                         rng.setEndAfter(value);
3068                                         rng.deleteContents();
3069                                         rng.insertNode(rng.createContextualFragment(value.innerHTML));
3070                                 }
3071
3072                                 tinyMCE.triggerNodeChange();
3073
3074                                 break;
3075
3076                         case "mceSelectNodeDepth":
3077                                 var parentNode = this.getFocusElement();
3078                                 for (i=0; parentNode; i++) {
3079                                         if (parentNode.nodeName.toLowerCase() == "body")
3080                                                 break;
3081
3082                                         if (parentNode.nodeName.toLowerCase() == "#text") {
3083                                                 i--;
3084                                                 parentNode = parentNode.parentNode;
3085                                                 continue;
3086                                         }
3087
3088                                         if (i == value) {
3089                                                 this.selection.selectNode(parentNode, false);
3090                                                 tinyMCE.triggerNodeChange();
3091                                                 tinyMCE.selectedNode = parentNode;
3092                                                 return;
3093                                         }
3094
3095                                         parentNode = parentNode.parentNode;
3096                                 }
3097
3098                                 break;
3099
3100                         case "mceSetStyleInfo":
3101                         case "SetStyleInfo":
3102                                 var rng = this.getRng();
3103                                 var sel = this.getSel();
3104                                 var scmd = value.command;
3105                                 var sname = value.name;
3106                                 var svalue = value.value == null ? '' : value.value;
3107                                 //var svalue = value['value'] == null ? '' : value['value'];
3108                                 var wrapper = value.wrapper ? value.wrapper : "span";
3109                                 var parentElm = null;
3110                                 var invalidRe = new RegExp("^BODY|HTML$", "g");
3111                                 var invalidParentsRe = tinyMCE.settings.merge_styles_invalid_parents !== '' ? new RegExp(tinyMCE.settings.merge_styles_invalid_parents, "gi") : null;
3112
3113                                 // Whole element selected check
3114                                 if (tinyMCE.isIE) {
3115                                         // Control range
3116                                         if (rng.item)
3117                                                 parentElm = rng.item(0);
3118                                         else {
3119                                                 var pelm = rng.parentElement();
3120                                                 var prng = doc.selection.createRange();
3121                                                 prng.moveToElementText(pelm);
3122
3123                                                 if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) {
3124                                                         if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName))
3125                                                                 parentElm = pelm;
3126                                                 }
3127                                         }
3128                                 } else {
3129                                         var felm = this.getFocusElement();
3130                                         if (sel.isCollapsed || (new RegExp('td|tr|tbody|table|img', 'gi').test(felm.nodeName) && sel.anchorNode == felm.parentNode))
3131                                                 parentElm = felm;
3132                                 }
3133
3134                                 // Whole element selected
3135                                 if (parentElm && !invalidRe.test(parentElm.nodeName)) {
3136                                         if (scmd == "setstyle")
3137                                                 tinyMCE.setStyleAttrib(parentElm, sname, svalue);
3138
3139                                         if (scmd == "setattrib")
3140                                                 tinyMCE.setAttrib(parentElm, sname, svalue);
3141
3142                                         if (scmd == "removeformat") {
3143                                                 parentElm.style.cssText = '';
3144                                                 tinyMCE.setAttrib(parentElm, 'class', '');
3145                                         }
3146
3147                                         // Remove style/attribs from all children
3148                                         var ch = tinyMCE.getNodeTree(parentElm, [], 1);
3149                                         for (z=0; z<ch.length; z++) {
3150                                                 if (ch[z] == parentElm)
3151                                                         continue;
3152
3153                                                 if (scmd == "setstyle")
3154                                                         tinyMCE.setStyleAttrib(ch[z], sname, '');
3155
3156                                                 if (scmd == "setattrib")
3157                                                         tinyMCE.setAttrib(ch[z], sname, '');
3158
3159                                                 if (scmd == "removeformat") {
3160                                                         ch[z].style.cssText = '';
3161                                                         tinyMCE.setAttrib(ch[z], 'class', '');
3162                                                 }
3163                                         }
3164                                 } else {
3165                                         this._setUseCSS(false); // Bug in FF when running in fullscreen
3166                                         doc.execCommand("FontName", false, "#mce_temp_font#");
3167                                         var elementArray = tinyMCE.getElementsByAttributeValue(this.getBody(), "font", "face", "#mce_temp_font#");
3168
3169                                         // Change them all
3170                                         for (x=0; x<elementArray.length; x++) {
3171                                                 elm = elementArray[x];
3172                                                 if (elm) {
3173                                                         var spanElm = doc.createElement(wrapper);
3174
3175                                                         if (scmd == "setstyle")
3176                                                                 tinyMCE.setStyleAttrib(spanElm, sname, svalue);
3177
3178                                                         if (scmd == "setattrib")
3179                                                                 tinyMCE.setAttrib(spanElm, sname, svalue);
3180
3181                                                         if (scmd == "removeformat") {
3182                                                                 spanElm.style.cssText = '';
3183                                                                 tinyMCE.setAttrib(spanElm, 'class', '');
3184                                                         }
3185
3186                                                         if (elm.hasChildNodes()) {
3187                                                                 for (i=0; i<elm.childNodes.length; i++)
3188                                                                         spanElm.appendChild(elm.childNodes[i].cloneNode(true));
3189                                                         }
3190
3191                                                         spanElm.setAttribute("mce_new", "true");
3192                                                         elm.parentNode.replaceChild(spanElm, elm);
3193
3194                                                         // Remove style/attribs from all children
3195                                                         var ch = tinyMCE.getNodeTree(spanElm, [], 1);
3196                                                         for (z=0; z<ch.length; z++) {
3197                                                                 if (ch[z] == spanElm)
3198                                                                         continue;
3199
3200                                                                 if (scmd == "setstyle")
3201                                                                         tinyMCE.setStyleAttrib(ch[z], sname, '');
3202
3203                                                                 if (scmd == "setattrib")
3204                                                                         tinyMCE.setAttrib(ch[z], sname, '');
3205
3206                                                                 if (scmd == "removeformat") {
3207                                                                         ch[z].style.cssText = '';
3208                                                                         tinyMCE.setAttrib(ch[z], 'class', '');
3209                                                                 }
3210                                                         }
3211                                                 }
3212                                         }
3213                                 }
3214
3215                                 // Cleaup wrappers
3216                                 var nodes = doc.getElementsByTagName(wrapper);
3217                                 for (i=nodes.length-1; i>=0; i--) {
3218                                         var elm = nodes[i];
3219                                         var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true";
3220
3221                                         elm.removeAttribute("mce_new");
3222
3223                                         // Is only child a element
3224                                         if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) {
3225                                                 //tinyMCE.debug("merge1" + isNew);
3226                                                 this._mergeElements(scmd, elm, elm.childNodes[0], isNew);
3227                                                 continue;
3228                                         }
3229
3230                                         // Is I the only child
3231                                         if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) {
3232                                                 //tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName);
3233                                                 if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName))
3234                                                         this._mergeElements(scmd, elm.parentNode, elm, false);
3235                                         }
3236                                 }
3237
3238                                 // Remove empty wrappers
3239                                 var nodes = doc.getElementsByTagName(wrapper);
3240                                 for (i=nodes.length-1; i>=0; i--) {
3241                                         var elm = nodes[i], isEmpty = true;
3242
3243                                         // Check if it has any attribs
3244                                         var tmp = doc.createElement("body");
3245                                         tmp.appendChild(elm.cloneNode(false));
3246
3247                                         // Is empty span, remove it
3248                                         tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), '');
3249                                         //tinyMCE.debug(tmp.innerHTML);
3250                                         if (new RegExp('<span>', 'gi').test(tmp.innerHTML)) {
3251                                                 for (x=0; x<elm.childNodes.length; x++) {
3252                                                         if (elm.parentNode != null)
3253                                                                 elm.parentNode.insertBefore(elm.childNodes[x].cloneNode(true), elm);
3254                                                 }
3255
3256                                                 elm.parentNode.removeChild(elm);
3257                                         }
3258                                 }
3259
3260                                 // Re add the visual aids
3261                                 if (scmd == "removeformat")
3262                                         tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3263
3264                                 tinyMCE.triggerNodeChange();
3265
3266                                 break;
3267
3268                         case "FontName":
3269                                 if (value == null) {
3270                                         var s = this.getSel();
3271
3272                                         // Find font and select it
3273                                         if (tinyMCE.isGecko && s.isCollapsed) {
3274                                                 var f = tinyMCE.getParentElement(this.getFocusElement(), "font");
3275
3276                                                 if (f != null)
3277                                                         this.selection.selectNode(f, false);
3278                                         }
3279
3280                                         // Remove format
3281                                         this.getDoc().execCommand("RemoveFormat", false, null);
3282
3283                                         // Collapse range if font was found
3284                                         if (f != null && tinyMCE.isGecko) {
3285                                                 var r = this.getRng().cloneRange();
3286                                                 r.collapse(true);
3287                                                 s.removeAllRanges();
3288                                                 s.addRange(r);
3289                                         }
3290                                 } else
3291                                         this.getDoc().execCommand('FontName', false, value);
3292
3293                                 if (tinyMCE.isGecko)
3294                                         window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
3295
3296                                 return;
3297
3298                         case "FontSize":
3299                                 this.getDoc().execCommand('FontSize', false, value);
3300
3301                                 if (tinyMCE.isGecko)
3302                                         window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
3303
3304                                 return;
3305
3306                         case "forecolor":
3307                                 value = value == null ? this.foreColor : value;
3308                                 value = tinyMCE.trim(value);
3309                                 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
3310
3311                                 this.foreColor = value;
3312                                 this.getDoc().execCommand('forecolor', false, value);
3313                                 break;
3314
3315                         case "HiliteColor":
3316                                 value = value == null ? this.backColor : value;
3317                                 value = tinyMCE.trim(value);
3318                                 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
3319                                 this.backColor = value;
3320
3321                                 if (tinyMCE.isGecko || tinyMCE.isOpera) {
3322                                         this._setUseCSS(true);
3323                                         this.getDoc().execCommand('hilitecolor', false, value);
3324                                         this._setUseCSS(false);
3325                                 } else
3326                                         this.getDoc().execCommand('BackColor', false, value);
3327                                 break;
3328
3329                         case "Cut":
3330                         case "Copy":
3331                         case "Paste":
3332                                 var cmdFailed = false;
3333
3334                                 // Try executing command
3335                                 eval('try {this.getDoc().execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}');
3336
3337                                 if (tinyMCE.isOpera && cmdFailed)
3338                                         alert('Currently not supported by your browser, use keyboard shortcuts instead.');
3339
3340                                 // Alert error in gecko if command failed
3341                                 if (tinyMCE.isGecko && cmdFailed) {
3342                                         // Confirm more info
3343                                         if (confirm(tinyMCE.entityDecode(tinyMCE.getLang('lang_clipboard_msg'))))
3344                                                 window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal');
3345
3346                                         return;
3347                                 } else
3348                                         tinyMCE.triggerNodeChange();
3349                         break;
3350
3351                         case "mceSetContent":
3352                                 if (!value)
3353                                         value = "";
3354
3355                                 // Call custom cleanup code
3356                                 value = tinyMCE.storeAwayURLs(value);
3357                                 value = tinyMCE._customCleanup(this, "insert_to_editor", value);
3358
3359                                 if (this.getBody().nodeName == 'BODY')
3360                                         tinyMCE._setHTML(doc, value);
3361                                 else
3362                                         this.getBody().innerHTML = value;
3363
3364                                 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, doc, this.settings, this.getBody(), false, false, false, true));
3365                                 tinyMCE.convertAllRelativeURLs(this.getBody());
3366
3367                                 // Cleanup any mess left from storyAwayURLs
3368                                 tinyMCE._removeInternal(this.getBody());
3369
3370                                 // When editing always use fonts internaly
3371                                 if (tinyMCE.getParam("convert_fonts_to_spans"))
3372                                         tinyMCE.convertSpansToFonts(doc);
3373
3374                                 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3375                                 tinyMCE._setEventsEnabled(this.getBody(), false);
3376                                 this._addBogusBR();
3377
3378                                 return true;
3379
3380                         case "mceCleanup":
3381                                 var b = this.selection.getBookmark();
3382                                 tinyMCE._setHTML(this.contentDocument, this.getBody().innerHTML);
3383                                 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, this.getBody(), this.visualAid));
3384                                 tinyMCE.convertAllRelativeURLs(doc.body);
3385
3386                                 // When editing always use fonts internaly
3387                                 if (tinyMCE.getParam("convert_fonts_to_spans"))
3388                                         tinyMCE.convertSpansToFonts(doc);
3389
3390                                 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3391                                 tinyMCE._setEventsEnabled(this.getBody(), false);
3392                                 this._addBogusBR();
3393                                 this.repaint();
3394                                 this.selection.moveToBookmark(b);
3395                                 tinyMCE.triggerNodeChange();
3396                         break;
3397
3398                         case "mceReplaceContent":
3399                                 // Force empty string
3400                                 if (!value)
3401                                         value = '';
3402
3403                                 this.getWin().focus();
3404
3405                                 var selectedText = "";
3406
3407                                 if (tinyMCE.isIE) {
3408                                         var rng = doc.selection.createRange();
3409                                         selectedText = rng.text;
3410                                 } else
3411                                         selectedText = this.getSel().toString();
3412
3413                                 if (selectedText.length > 0) {
3414                                         value = tinyMCE.replaceVar(value, "selection", selectedText);
3415                                         tinyMCE.execCommand('mceInsertContent', false, value);
3416                                 }
3417
3418                                 this._addBogusBR();
3419                                 tinyMCE.triggerNodeChange();
3420                         break;
3421
3422                         case "mceSetAttribute":
3423                                 if (typeof(value) == 'object') {
3424                                         var targetElms = (typeof(value.targets) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value.targets;
3425                                         var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms);
3426
3427                                         if (targetNode) {
3428                                                 targetNode.setAttribute(value.name, value.value);
3429                                                 tinyMCE.triggerNodeChange();
3430                                         }
3431                                 }
3432                         break;
3433
3434                         case "mceSetCSSClass":
3435                                 this.execCommand("mceSetStyleInfo", false, {command : "setattrib", name : "class", value : value});
3436                         break;
3437
3438                         case "mceInsertRawHTML":
3439                                 var key = 'tiny_mce_marker';
3440
3441                                 this.execCommand('mceBeginUndoLevel');
3442
3443                                 // Insert marker key
3444                                 this.execCommand('mceInsertContent', false, key);
3445
3446                                 // Store away scroll pos
3447                                 var scrollX = this.getBody().scrollLeft + this.getDoc().documentElement.scrollLeft;
3448                                 var scrollY = this.getBody().scrollTop + this.getDoc().documentElement.scrollTop;
3449
3450                                 // Find marker and replace with RAW HTML
3451                                 var html = this.getBody().innerHTML;
3452                                 if ((pos = html.indexOf(key)) != -1)
3453                                         tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length));
3454
3455                                 // Restore scoll pos
3456                                 this.contentWindow.scrollTo(scrollX, scrollY);
3457
3458                                 this.execCommand('mceEndUndoLevel');
3459
3460                                 break;
3461
3462                         case "mceInsertContent":
3463                                 // Force empty string
3464                                 if (!value)
3465                                         value = '';
3466
3467                                 var insertHTMLFailed = false;
3468
3469                                 // Removed since it produced problems in IE
3470                                 // this.getWin().focus();
3471
3472                                 if (tinyMCE.isGecko || tinyMCE.isOpera) {
3473                                         try {
3474                                                 // Is plain text or HTML, &amp;, &nbsp; etc will be encoded wrong in FF
3475                                                 if (value.indexOf('<') == -1 && !value.match(/(&#38;|&#160;|&#60;|&#62;)/g)) {
3476                                                         var r = this.getRng();
3477                                                         var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value));
3478                                                         var s = this.getSel();
3479                                                         var r2 = r.cloneRange();
3480
3481                                                         // Insert text at cursor position
3482                                                         s.removeAllRanges();
3483                                                         r.deleteContents();
3484                                                         r.insertNode(n);
3485
3486                                                         // Move the cursor to the end of text
3487                                                         r2.selectNode(n);
3488                                                         r2.collapse(false);
3489                                                         s.removeAllRanges();
3490                                                         s.addRange(r2);
3491                                                 } else {
3492                                                         value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value);
3493                                                         this.getDoc().execCommand('inserthtml', false, value);
3494                                                         tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
3495                                                 }
3496                                         } catch (ex) {
3497                                                 insertHTMLFailed = true;
3498                                         }
3499
3500                                         if (!insertHTMLFailed) {
3501                                                 tinyMCE.triggerNodeChange();
3502                                                 return;
3503                                         }
3504                                 }
3505
3506                                 if (!tinyMCE.isIE) {
3507                                         var isHTML = value.indexOf('<') != -1;
3508                                         var sel = this.getSel();
3509                                         var rng = this.getRng();
3510
3511                                         if (isHTML) {
3512                                                 if (tinyMCE.isSafari) {
3513                                                         var tmpRng = this.getDoc().createRange();
3514
3515                                                         tmpRng.setStart(this.getBody(), 0);
3516                                                         tmpRng.setEnd(this.getBody(), 0);
3517
3518                                                         value = tmpRng.createContextualFragment(value);
3519                                                 } else
3520                                                         value = rng.createContextualFragment(value);
3521                                         } else {
3522                                                 // Setup text node
3523                                                 value = doc.createTextNode(tinyMCE.entityDecode(value));
3524                                         }
3525
3526                                         // Insert plain text in Safari
3527                                         if (tinyMCE.isSafari && !isHTML) {
3528                                                 this.execCommand('InsertText', false, value.nodeValue);
3529                                                 tinyMCE.triggerNodeChange();
3530                                                 return true;
3531                                         } else if (tinyMCE.isSafari && isHTML) {
3532                                                 rng.deleteContents();
3533                                                 rng.insertNode(value);
3534                                                 tinyMCE.triggerNodeChange();
3535                                                 return true;
3536                                         }
3537
3538                                         rng.deleteContents();
3539
3540                                         // If target node is text do special treatment, (Mozilla 1.3 fix)
3541                                         if (rng.startContainer.nodeType == 3) {
3542                                                 var node = rng.startContainer.splitText(rng.startOffset);
3543                                                 node.parentNode.insertBefore(value, node); 
3544                                         } else
3545                                                 rng.insertNode(value);
3546
3547                                         if (!isHTML) {
3548                                                 // Removes weird selection trails
3549                                                 sel.selectAllChildren(doc.body);
3550                                                 sel.removeAllRanges();
3551
3552                                                 // Move cursor to end of content
3553                                                 var rng = doc.createRange();
3554
3555                                                 rng.selectNode(value);
3556                                                 rng.collapse(false);
3557
3558                                                 sel.addRange(rng);
3559                                         } else
3560                                                 rng.collapse(false);
3561
3562                                         tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
3563                                 } else {
3564                                         var rng = doc.selection.createRange(), tmpRng = null;
3565                                         var c = value.indexOf('<!--') != -1;
3566
3567                                         // Fix comment bug, add tag before comments
3568                                         if (c)
3569                                                 value = tinyMCE.uniqueTag + value;
3570
3571                                         //      tmpRng = rng.duplicate(); // Store away range (Fixes Undo bookmark bug in IE)
3572
3573                                         if (rng.item)
3574                                                 rng.item(0).outerHTML = value;
3575                                         else
3576                                                 rng.pasteHTML(value);
3577
3578                                         //if (tmpRng)
3579                                         //      tmpRng.select(); // Restore range  (Fixes Undo bookmark bug in IE)
3580
3581                                         // Remove unique tag
3582                                         if (c) {
3583                                                 var e = this.getDoc().getElementById('mceTMPElement');
3584                                                 e.parentNode.removeChild(e);
3585                                         }
3586                                 }
3587
3588                                 tinyMCE.execCommand("mceAddUndoLevel");
3589                                 tinyMCE.triggerNodeChange();
3590                         break;
3591
3592                         case "mceStartTyping":
3593                                 if (tinyMCE.settings.custom_undo_redo && this.undoRedo.typingUndoIndex == -1) {
3594                                         this.undoRedo.typingUndoIndex = this.undoRedo.undoIndex;
3595                                         tinyMCE.typingUndoIndex = tinyMCE.undoIndex;
3596                                         this.execCommand('mceAddUndoLevel');
3597                                 }
3598                                 break;
3599
3600                         case "mceEndTyping":
3601                                 if (tinyMCE.settings.custom_undo_redo && this.undoRedo.typingUndoIndex != -1) {
3602                                         this.execCommand('mceAddUndoLevel');
3603                                         this.undoRedo.typingUndoIndex = -1;
3604                                 }
3605
3606                                 tinyMCE.typingUndoIndex = -1;
3607                                 break;
3608
3609                         case "mceBeginUndoLevel":
3610                                 this.undoRedoLevel = false;
3611                                 break;
3612
3613                         case "mceEndUndoLevel":
3614                                 this.undoRedoLevel = true;
3615                                 this.execCommand('mceAddUndoLevel');
3616                                 break;
3617
3618                         case "mceAddUndoLevel":
3619                                 if (tinyMCE.settings.custom_undo_redo && this.undoRedoLevel) {
3620                                         if (this.undoRedo.add())
3621                                                 tinyMCE.triggerNodeChange(false);
3622                                 }
3623                                 break;
3624
3625                         case "Undo":
3626                                 if (tinyMCE.settings.custom_undo_redo) {
3627                                         tinyMCE.execCommand("mceEndTyping");
3628                                         this.undoRedo.undo();
3629                                         tinyMCE.triggerNodeChange();
3630                                 } else
3631                                         this.getDoc().execCommand(command, user_interface, value);
3632                                 break;
3633
3634                         case "Redo":
3635                                 if (tinyMCE.settings.custom_undo_redo) {
3636                                         tinyMCE.execCommand("mceEndTyping");
3637                                         this.undoRedo.redo();
3638                                         tinyMCE.triggerNodeChange();
3639                                 } else
3640                                         this.getDoc().execCommand(command, user_interface, value);
3641                                 break;
3642
3643                         case "mceToggleVisualAid":
3644                                 this.visualAid = !this.visualAid;
3645                                 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3646                                 tinyMCE.triggerNodeChange();
3647                                 break;
3648
3649                         case "Indent":
3650                                 this.getDoc().execCommand(command, user_interface, value);
3651                                 tinyMCE.triggerNodeChange();
3652
3653                                 if (tinyMCE.isIE) {
3654                                         var n = tinyMCE.getParentElement(this.getFocusElement(), "blockquote");
3655                                         do {
3656                                                 if (n && n.nodeName == "BLOCKQUOTE") {
3657                                                         n.removeAttribute("dir");
3658                                                         n.removeAttribute("style");
3659                                                 }
3660                                         } while (n != null && (n = n.parentNode) != null);
3661                                 }
3662                                 break;
3663
3664                         case "RemoveFormat":
3665                         case "removeformat":
3666                                 var text = this.selection.getSelectedText();
3667
3668                                 if (tinyMCE.isOpera) {
3669                                         this.getDoc().execCommand("RemoveFormat", false, null);
3670                                         return;
3671                                 }
3672
3673                                 if (tinyMCE.isIE) {
3674                                         try {
3675                                                 var rng = doc.selection.createRange();
3676                                                 rng.execCommand("RemoveFormat", false, null);
3677                                         } catch (e) {
3678                                                 // Do nothing
3679                                         }
3680
3681                                         this.execCommand("mceSetStyleInfo", false, {command : "removeformat"});
3682                                 } else {
3683                                         this.getDoc().execCommand(command, user_interface, value);
3684
3685                                         this.execCommand("mceSetStyleInfo", false, {command : "removeformat"});
3686                                 }
3687
3688                                 // Remove class
3689                                 if (text.length == 0)
3690                                         this.execCommand("mceSetCSSClass", false, "");
3691
3692                                 tinyMCE.triggerNodeChange();
3693                                 break;
3694
3695                         default:
3696                                 this.getDoc().execCommand(command, user_interface, value);
3697
3698                                 if (tinyMCE.isGecko)
3699                                         window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
3700                                 else
3701                                         tinyMCE.triggerNodeChange();
3702                 }
3703
3704                 // Add undo level after modification
3705                 if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceStartTyping" && command != "mceEndTyping")
3706                         tinyMCE.execCommand("mceAddUndoLevel");
3707         },
3708
3709         queryCommandValue : function(c) {
3710                 try {
3711                         return this.getDoc().queryCommandValue(c);
3712                 } catch (e) {
3713                         return null;
3714                 }
3715         },
3716
3717         queryCommandState : function(c) {
3718                 return this.getDoc().queryCommandState(c);
3719         },
3720
3721         _addBogusBR : function() {
3722                 var b = this.getBody();
3723
3724                 if (tinyMCE.isGecko && !b.hasChildNodes())
3725                         b.innerHTML = '<br _moz_editor_bogus_node="TRUE" />';
3726         },
3727
3728         _onAdd : function(replace_element, form_element_name, target_document) {
3729                 var hc, th, tos, editorTemplate, targetDoc, deltaWidth, deltaHeight, html, rng, fragment;
3730                 var dynamicIFrame, tElm, doc, parentElm;
3731
3732                 th = this.settings.theme;
3733                 tos = tinyMCE.themes[th];
3734
3735                 targetDoc = target_document ? target_document : document;
3736
3737                 this.targetDoc = targetDoc;
3738
3739                 tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings.theme;
3740                 this.settings.themeurl = tinyMCE.themeURL;
3741
3742                 if (!replace_element) {
3743                         alert("Error: Could not find the target element.");
3744                         return false;
3745                 }
3746
3747                 if (tos.getEditorTemplate)
3748                         editorTemplate = tos.getEditorTemplate(this.settings, this.editorId);
3749
3750                 deltaWidth = editorTemplate.delta_width ? editorTemplate.delta_width : 0;
3751                 deltaHeight = editorTemplate.delta_height ? editorTemplate.delta_height : 0;
3752                 html = '<span id="' + this.editorId + '_parent" class="mceEditorContainer">' + editorTemplate.html;
3753
3754                 html = tinyMCE.replaceVar(html, "editor_id", this.editorId);
3755
3756                 if (!this.settings.default_document)
3757                         this.settings.default_document = tinyMCE.baseURL + "/blank.htm";
3758
3759                 this.settings.old_width = this.settings.width;
3760                 this.settings.old_height = this.settings.height;
3761
3762                 // Set default width, height
3763                 if (this.settings.width == -1)
3764                         this.settings.width = replace_element.offsetWidth;
3765
3766                 if (this.settings.height == -1)
3767                         this.settings.height = replace_element.offsetHeight;
3768
3769                 // Try the style width
3770                 if (this.settings.width == 0)
3771                         this.settings.width = replace_element.style.width;
3772
3773                 // Try the style height
3774                 if (this.settings.height == 0)
3775                         this.settings.height = replace_element.style.height; 
3776
3777                 // If no width/height then default to 320x240, better than nothing
3778                 if (this.settings.width == 0)
3779                         this.settings.width = 320;
3780
3781                 if (this.settings.height == 0)
3782                         this.settings.height = 240;
3783
3784                 this.settings.area_width = parseInt(this.settings.width);
3785                 this.settings.area_height = parseInt(this.settings.height);
3786                 this.settings.area_width += deltaWidth;
3787                 this.settings.area_height += deltaHeight;
3788                 this.settings.width_style = "" + this.settings.width;
3789                 this.settings.height_style = "" + this.settings.height;
3790
3791                 // Special % handling
3792                 if (("" + this.settings.width).indexOf('%') != -1)
3793                         this.settings.area_width = "100%";
3794                 else
3795                         this.settings.width_style += 'px';
3796
3797                 if (("" + this.settings.height).indexOf('%') != -1)
3798                         this.settings.area_height = "100%";
3799                 else
3800                         this.settings.height_style += 'px';
3801
3802                 if (("" + replace_element.style.width).indexOf('%') != -1) {
3803                         this.settings.width = replace_element.style.width;
3804                         this.settings.area_width = "100%";
3805                         this.settings.width_style = "100%";
3806                 }
3807
3808                 if (("" + replace_element.style.height).indexOf('%') != -1) {
3809                         this.settings.height = replace_element.style.height;
3810                         this.settings.area_height = "100%";
3811                         this.settings.height_style = "100%";
3812                 }
3813
3814                 html = tinyMCE.applyTemplate(html);
3815
3816                 this.settings.width = this.settings.old_width;
3817                 this.settings.height = this.settings.old_height;
3818
3819                 this.visualAid = this.settings.visual;
3820                 this.formTargetElementId = form_element_name;
3821
3822                 // Get replace_element contents
3823                 if (replace_element.nodeName == "TEXTAREA" || replace_element.nodeName == "INPUT")
3824                         this.startContent = replace_element.value;
3825                 else
3826                         this.startContent = replace_element.innerHTML;
3827
3828                 // If not text area or input
3829                 if (replace_element.nodeName != "TEXTAREA" && replace_element.nodeName != "INPUT") {
3830                         this.oldTargetElement = replace_element;
3831
3832                         // Debug mode
3833                         hc = '<input type="hidden" id="' + form_element_name + '" name="' + form_element_name + '" />';
3834                         this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline');
3835                         this.oldTargetElement.style.display = "none";
3836
3837                         html += '</span>';
3838
3839                         if (tinyMCE.isGecko)
3840                                 html = hc + html;
3841                         else
3842                                 html += hc;
3843
3844                         // Output HTML and set editable
3845                         if (tinyMCE.isGecko) {
3846                                 rng = replace_element.ownerDocument.createRange();
3847                                 rng.setStartBefore(replace_element);
3848
3849                                 fragment = rng.createContextualFragment(html);
3850                                 tinyMCE.insertAfter(fragment, replace_element);
3851                         } else
3852                                 replace_element.insertAdjacentHTML("beforeBegin", html);
3853                 } else {
3854                         html += '</span>';
3855
3856                         // Just hide the textarea element
3857                         this.oldTargetElement = replace_element;
3858
3859                         this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline');
3860                         this.oldTargetElement.style.display = "none";
3861
3862                         // Output HTML and set editable
3863                         if (tinyMCE.isGecko) {
3864                                 rng = replace_element.ownerDocument.createRange();
3865                                 rng.setStartBefore(replace_element);
3866
3867                                 fragment = rng.createContextualFragment(html);
3868                                 tinyMCE.insertAfter(fragment, replace_element);
3869                         } else
3870                                 replace_element.insertAdjacentHTML("beforeBegin", html);
3871                 }
3872
3873                 // Setup iframe
3874                 dynamicIFrame = false;
3875                 tElm = targetDoc.getElementById(this.editorId);
3876
3877                 if (!tinyMCE.isIE) {
3878                         // Node case is preserved in XML strict mode
3879                         if (tElm && (tElm.nodeName == "SPAN" || tElm.nodeName == "span")) {
3880                                 tElm = tinyMCE._createIFrame(tElm, targetDoc);
3881                                 dynamicIFrame = true;
3882                         }
3883
3884                         this.targetElement = tElm;
3885                         this.iframeElement = tElm;
3886                         this.contentDocument = tElm.contentDocument;
3887                         this.contentWindow = tElm.contentWindow;
3888
3889                         //this.getDoc().designMode = "on";
3890                 } else {
3891                         if (tElm && tElm.nodeName == "SPAN")
3892                                 tElm = tinyMCE._createIFrame(tElm, targetDoc, targetDoc.parentWindow);
3893                         else
3894                                 tElm = targetDoc.frames[this.editorId];
3895
3896                         this.targetElement = tElm;
3897                         this.iframeElement = targetDoc.getElementById(this.editorId);
3898
3899                         if (tinyMCE.isOpera) {
3900                                 this.contentDocument = this.iframeElement.contentDocument;
3901                                 this.contentWindow = this.iframeElement.contentWindow;
3902                                 dynamicIFrame = true;
3903                         } else {
3904                                 this.contentDocument = tElm.window.document;
3905                                 this.contentWindow = tElm.window;
3906                         }
3907
3908                         this.getDoc().designMode = "on";
3909                 }
3910
3911                 // Setup base HTML
3912                 doc = this.contentDocument;
3913                 if (dynamicIFrame) {
3914                         html = tinyMCE.getParam('doctype') + '<html><head xmlns="http://www.w3.org/1999/xhtml"><base href="' + tinyMCE.settings.base_href + '" /><title>blank_page</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body class="mceContentBody"></body></html>';
3915
3916                         try {
3917                                 if (!this.isHidden())
3918                                         this.getDoc().designMode = "on";
3919
3920                                 doc.open();
3921                                 doc.write(html);
3922                                 doc.close();
3923                         } catch (e) {
3924                                 // Failed Mozilla 1.3
3925                                 this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm";
3926                         }
3927                 }
3928
3929                 // This timeout is needed in MSIE 5.5 for some odd reason
3930                 // it seems that the document.frames isn't initialized yet?
3931                 if (tinyMCE.isIE)
3932                         window.setTimeout("tinyMCE.addEventHandlers(tinyMCE.instances[\"" + this.editorId + "\"]);", 1);
3933
3934                 // Setup element references
3935                 parentElm = this.targetDoc.getElementById(this.editorId + '_parent');
3936                 this.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;
3937
3938                 tinyMCE.setupContent(this.editorId, true);
3939
3940                 return true;
3941         },
3942
3943         setBaseHREF : function(u) {
3944                 var h, b, d, nl;
3945
3946                 d = this.getDoc();
3947                 nl = d.getElementsByTagName("base");
3948                 b = nl.length > 0 ? nl[0] : null;
3949
3950                 if (!b) {
3951                         nl = d.getElementsByTagName("head");
3952                         h = nl.length > 0 ? nl[0] : null;
3953
3954                         b = d.createElement("base");
3955                         b.setAttribute('href', u);
3956                         h.appendChild(b);
3957                 } else {
3958                         if (u == '' || u == null)
3959                                 b.parentNode.removeChild(b);
3960                         else
3961                                 b.setAttribute('href', u);
3962                 }
3963         },
3964
3965         getHTML : function(r) {
3966                 var h, d = this.getDoc(), b = this.getBody();
3967
3968                 if (r)
3969                         return b.innerHTML;
3970
3971                 h = tinyMCE._cleanupHTML(this, d, this.settings, b, false, true, false, true);
3972
3973                 if (tinyMCE.getParam("convert_fonts_to_spans"))
3974                         tinyMCE.convertSpansToFonts(d);
3975
3976                 return h;
3977         },
3978
3979         setHTML : function(h) {
3980                 this.execCommand('mceSetContent', false, h);
3981                 this.repaint();
3982         },
3983
3984         getFocusElement : function() {
3985                 return this.selection.getFocusElement();
3986         },
3987
3988         getSel : function() {
3989                 return this.selection.getSel();
3990         },
3991
3992         getRng : function() {
3993                 return this.selection.getRng();
3994         },
3995
3996         triggerSave : function(skip_cleanup, skip_callback) {
3997                 var e, nl = [], i, s, content, htm;
3998
3999                 if (!this.enabled)
4000                         return;
4001
4002                 this.switchSettings();
4003                 s = tinyMCE.settings;
4004
4005                 // Force hidden tabs visible while serializing
4006                 if (tinyMCE.isRealIE) {
4007                         e = this.iframeElement;
4008
4009                         do {
4010                                 if (e.style && e.style.display == 'none') {
4011                                         e.style.display = 'block';
4012                                         nl[nl.length] = {elm : e, type : 'style'};
4013                                 }
4014
4015                                 if (e.style && s.hidden_tab_class.length > 0 && e.className.indexOf(s.hidden_tab_class) != -1) {
4016                                         e.className = s.display_tab_class;
4017                                         nl[nl.length] = {elm : e, type : 'class'};
4018                                 }
4019                         } while ((e = e.parentNode) != null)
4020                 }
4021
4022                 tinyMCE.settings.preformatted = false;
4023
4024                 // Default to false
4025                 if (typeof(skip_cleanup) == "undefined")
4026                         skip_cleanup = false;
4027
4028                 // Default to false
4029                 if (typeof(skip_callback) == "undefined")
4030                         skip_callback = false;
4031
4032                 tinyMCE._setHTML(this.getDoc(), this.getBody().innerHTML);
4033
4034                 // Remove visual aids when cleanup is disabled
4035                 if (this.settings.cleanup == false) {
4036                         tinyMCE.handleVisualAid(this.getBody(), true, false, this);
4037                         tinyMCE._setEventsEnabled(this.getBody(), true);
4038                 }
4039
4040                 tinyMCE._customCleanup(this, "submit_content_dom", this.contentWindow.document.body);
4041                 htm = skip_cleanup ? this.getBody().innerHTML : tinyMCE._cleanupHTML(this, this.getDoc(), this.settings, this.getBody(), tinyMCE.visualAid, true, true);
4042                 htm = tinyMCE._customCleanup(this, "submit_content", htm);
4043
4044                 if (!skip_callback && tinyMCE.settings.save_callback !== '')
4045                         content = tinyMCE.resolveDots(tinyMCE.settings.save_callback, window)(this.formTargetElementId,htm,this.getBody());
4046
4047                 // Use callback content if available
4048                 if ((typeof(content) != "undefined") && content != null)
4049                         htm = content;
4050
4051                 // Replace some weird entities (Bug: #1056343)
4052                 htm = tinyMCE.regexpReplace(htm, "&#40;", "(", "gi");
4053                 htm = tinyMCE.regexpReplace(htm, "&#41;", ")", "gi");
4054                 htm = tinyMCE.regexpReplace(htm, "&#59;", ";", "gi");
4055                 htm = tinyMCE.regexpReplace(htm, "&#34;", "&quot;", "gi");
4056                 htm = tinyMCE.regexpReplace(htm, "&#94;", "^", "gi");
4057
4058                 if (this.formElement)
4059                         this.formElement.value = htm;
4060
4061                 if (tinyMCE.isSafari && this.formElement)
4062                         this.formElement.innerText = htm;
4063
4064                 // Hide them again (tabs in MSIE)
4065                 for (i=0; i<nl.length; i++) {
4066                         if (nl[i].type == 'style')
4067                                 nl[i].elm.style.display = 'none';
4068                         else
4069                                 nl[i].elm.className = s.hidden_tab_class;
4070                 }
4071         }
4072
4073         };
4074
4075 /* file:jscripts/tiny_mce/classes/TinyMCE_Cleanup.class.js */
4076
4077 tinyMCE.add(TinyMCE_Engine, {
4078         cleanupHTMLCode : function(s) {
4079                 s = s.replace(new RegExp('<p \\/>', 'gi'), '<p>&nbsp;</p>');
4080                 s = s.replace(new RegExp('<p>\\s*<\\/p>', 'gi'), '<p>&nbsp;</p>');
4081
4082                 // Fix close BR elements
4083                 s = s.replace(new RegExp('<br>\\s*<\\/br>', 'gi'), '<br />');
4084
4085                 // Open closed tags like <b/> to <b></b>
4086                 s = s.replace(new RegExp('<(h[1-6]|p|div|address|pre|form|table|li|ol|ul|td|b|font|em|strong|i|strike|u|span|a|ul|ol|li|blockquote)([a-z]*)([^\\\\|>]*)\\/>', 'gi'), '<$1$2$3></$1$2>');
4087
4088                 // Remove trailing space <b > to <b>
4089                 s = s.replace(new RegExp('\\s+></', 'gi'), '></');
4090
4091                 // Close tags <img></img> to <img/>
4092                 s = s.replace(new RegExp('<(img|br|hr)([^>]*)><\\/(img|br|hr)>', 'gi'), '<$1$2 />');
4093
4094                 // Weird MSIE bug, <p><hr /></p> breaks runtime?
4095                 if (tinyMCE.isIE)
4096                         s = s.replace(new RegExp('<p><hr \\/><\\/p>', 'gi'), "<hr>");
4097
4098                 // Weird tags will make IE error #bug: 1538495
4099                 if (tinyMCE.isIE)
4100                         s = s.replace(/<!(\s*)\/>/g, '');
4101
4102                 // Convert relative anchors to absolute URLs ex: #something to file.htm#something
4103                 // Removed: Since local document anchors should never be forced absolute example edit.php?id=something
4104                 //if (tinyMCE.getParam('convert_urls'))
4105                 //      s = s.replace(new RegExp('(href=\"{0,1})(\\s*#)', 'gi'), '$1' + tinyMCE.settings.document_base_url + "#");
4106
4107                 return s;
4108         },
4109
4110         parseStyle : function(str) {
4111                 var ar = [], st, i, re, pa;
4112
4113                 if (str == null)
4114                         return ar;
4115
4116                 st = str.split(';');
4117
4118                 tinyMCE.clearArray(ar);
4119
4120                 for (i=0; i<st.length; i++) {
4121                         if (st[i] == '')
4122                                 continue;
4123
4124                         re = new RegExp('^\\s*([^:]*):\\s*(.*)\\s*$');
4125                         pa = st[i].replace(re, '$1||$2').split('||');
4126         //tinyMCE.debug(str, pa[0] + "=" + pa[1], st[i].replace(re, '$1||$2'));
4127                         if (pa.length == 2)
4128                                 ar[pa[0].toLowerCase()] = pa[1];
4129                 }
4130
4131                 return ar;
4132         },
4133
4134         compressStyle : function(ar, pr, sf, res) {
4135                 var box = [], i, a;
4136
4137                 box[0] = ar[pr + '-top' + sf];
4138                 box[1] = ar[pr + '-left' + sf];
4139                 box[2] = ar[pr + '-right' + sf];
4140                 box[3] = ar[pr + '-bottom' + sf];
4141
4142                 for (i=0; i<box.length; i++) {
4143                         if (box[i] == null)
4144                                 return;
4145
4146                         if (i && box[i] != box[i-1])
4147                                 return;
4148                 }
4149
4150                 // They are all the same
4151                 ar[res] = box[0];
4152                 ar[pr + '-top' + sf] = null;
4153                 ar[pr + '-left' + sf] = null;
4154                 ar[pr + '-right' + sf] = null;
4155                 ar[pr + '-bottom' + sf] = null;
4156         },
4157
4158         serializeStyle : function(ar) {
4159                 var str = "", key, val, m;
4160
4161                 // Compress box
4162                 tinyMCE.compressStyle(ar, "border", "", "border");
4163                 tinyMCE.compressStyle(ar, "border", "-width", "border-width");
4164                 tinyMCE.compressStyle(ar, "border", "-color", "border-color");
4165                 tinyMCE.compressStyle(ar, "border", "-style", "border-style");
4166                 tinyMCE.compressStyle(ar, "padding", "", "padding");
4167                 tinyMCE.compressStyle(ar, "margin", "", "margin");
4168
4169                 for (key in ar) {
4170                         val = ar[key];
4171
4172                         if (typeof(val) == 'function')
4173                                 continue;
4174
4175                         if (key.indexOf('mso-') == 0)
4176                                 continue;
4177
4178                         if (val != null && val !== '') {
4179                                 val = '' + val; // Force string
4180
4181                                 // Fix style URL
4182                                 val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')");
4183
4184                                 // Convert URL
4185                                 if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) {
4186                                         m = new RegExp("url\\('(.*?)'\\)").exec(val);
4187
4188                                         if (m.length > 1)
4189                                                 val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";
4190                                 }
4191
4192                                 // Force HEX colors
4193                                 if (tinyMCE.getParam("force_hex_style_colors"))
4194                                         val = tinyMCE.convertRGBToHex(val, true);
4195
4196                                 val = val.replace(/\"/g, '\'');
4197
4198                                 if (val != "url('')")
4199                                         str += key.toLowerCase() + ": " + val + "; ";
4200                         }
4201                 }
4202
4203                 if (new RegExp('; $').test(str))
4204                         str = str.substring(0, str.length - 2);
4205
4206                 return str;
4207         },
4208
4209         convertRGBToHex : function(s, k) {
4210                 var re, rgb;
4211
4212                 if (s.toLowerCase().indexOf('rgb') != -1) {
4213                         re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
4214                         rgb = s.replace(re, "$1,$2,$3,$4,$5").split(',');
4215
4216                         if (rgb.length == 5) {
4217                                 r = parseInt(rgb[1]).toString(16);
4218                                 g = parseInt(rgb[2]).toString(16);
4219                                 b = parseInt(rgb[3]).toString(16);
4220
4221                                 r = r.length == 1 ? '0' + r : r;
4222                                 g = g.length == 1 ? '0' + g : g;
4223                                 b = b.length == 1 ? '0' + b : b;
4224
4225                                 s = "#" + r + g + b;
4226
4227                                 if (k)
4228                                         s = rgb[0] + s + rgb[4];
4229                         }
4230                 }
4231
4232                 return s;
4233         },
4234
4235         convertHexToRGB : function(s) {
4236                 if (s.indexOf('#') != -1) {
4237                         s = s.replace(new RegExp('[^0-9A-F]', 'gi'), '');
4238                         return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")";
4239                 }
4240
4241                 return s;
4242         },
4243
4244         convertSpansToFonts : function(doc) {
4245                 var s, i, size, fSize, x, fFace, fColor, sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
4246
4247                 s = tinyMCE.selectElements(doc, 'span,font');
4248                 for (i=0; i<s.length; i++) {
4249                         size = tinyMCE.trim(s[i].style.fontSize).toLowerCase();
4250                         fSize = 0;
4251
4252                         for (x=0; x<sizes.length; x++) {
4253                                 if (sizes[x] == size) {
4254                                         fSize = x + 1;
4255                                         break;
4256                                 }
4257                         }
4258
4259                         if (fSize > 0) {
4260                                 tinyMCE.setAttrib(s[i], 'size', fSize);
4261                                 s[i].style.fontSize = '';
4262                         }
4263
4264                         fFace = s[i].style.fontFamily;
4265                         if (fFace != null && fFace !== '') {
4266                                 tinyMCE.setAttrib(s[i], 'face', fFace);
4267                                 s[i].style.fontFamily = '';
4268                         }
4269
4270                         fColor = s[i].style.color;
4271                         if (fColor != null && fColor !== '') {
4272                                 tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor));
4273                                 s[i].style.color = '';
4274                         }
4275                 }
4276         },
4277
4278         convertFontsToSpans : function(doc) {
4279                 var fsClasses, s, i, fSize, fFace, fColor, sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
4280
4281                 fsClasses = tinyMCE.getParam('font_size_classes');
4282                 if (fsClasses !== '')
4283                         fsClasses = fsClasses.replace(/\s+/, '').split(',');
4284                 else
4285                         fsClasses = null;
4286
4287                 s = tinyMCE.selectElements(doc, 'span,font');
4288                 for (i=0; i<s.length; i++) {
4289                         fSize = tinyMCE.getAttrib(s[i], 'size');
4290                         fFace = tinyMCE.getAttrib(s[i], 'face');
4291                         fColor = tinyMCE.getAttrib(s[i], 'color');
4292
4293                         if (fSize !== '') {
4294                                 fSize = parseInt(fSize);
4295
4296                                 if (fSize > 0 && fSize < 8) {
4297                                         if (fsClasses != null)
4298                                                 tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]);
4299                                         else
4300                                                 s[i].style.fontSize = sizes[fSize-1];
4301                                 }
4302
4303                                 s[i].removeAttribute('size');
4304                         }
4305
4306                         if (fFace !== '') {
4307                                 s[i].style.fontFamily = fFace;
4308                                 s[i].removeAttribute('face');
4309                         }
4310
4311                         if (fColor !== '') {
4312                                 s[i].style.color = fColor;
4313                                 s[i].removeAttribute('color');
4314                         }
4315                 }
4316         },
4317
4318         cleanupAnchors : function(doc) {
4319                 var i, cn, x, an = doc.getElementsByTagName("a");
4320
4321                 // Loops backwards due to bug #1467987
4322                 for (i=an.length-1; i>=0; i--) {
4323                         if (tinyMCE.getAttrib(an[i], "name") !== '' && tinyMCE.getAttrib(an[i], "href") == '') {
4324                                 cn = an[i].childNodes;
4325
4326                                 for (x=cn.length-1; x>=0; x--)
4327                                         tinyMCE.insertAfter(cn[x], an[i]);
4328                         }
4329                 }
4330         },
4331
4332         getContent : function(editor_id) {
4333                 if (typeof(editor_id) != "undefined")
4334                          tinyMCE.getInstanceById(editor_id).select();
4335
4336                 if (tinyMCE.selectedInstance)
4337                         return tinyMCE.selectedInstance.getHTML();
4338
4339                 return null;
4340         },
4341
4342         _fixListElements : function(d) {
4343                 var nl, x, a = ['ol', 'ul'], i, n, p, r = new RegExp('^(OL|UL)$'), np;
4344
4345                 for (x=0; x<a.length; x++) {
4346                         nl = d.getElementsByTagName(a[x]);
4347
4348                         for (i=0; i<nl.length; i++) {
4349                                 n = nl[i];
4350                                 p = n.parentNode;
4351
4352                                 if (r.test(p.nodeName)) {
4353                                         np = tinyMCE.prevNode(n, 'LI');
4354
4355                                         if (!np) {
4356                                                 np = d.createElement('li');
4357                                                 np.innerHTML = '&nbsp;';
4358                                                 np.appendChild(n);
4359                                                 p.insertBefore(np, p.firstChild);
4360                                         } else
4361                                                 np.appendChild(n);
4362                                 }
4363                         }
4364                 }
4365         },
4366
4367         _fixTables : function(d) {
4368                 var nl, i, n, p, np, x, t;
4369
4370                 nl = d.getElementsByTagName('table');
4371                 for (i=0; i<nl.length; i++) {
4372                         n = nl[i];
4373
4374                         if ((p = tinyMCE.getParentElement(n, 'p,h1,h2,h3,h4,h5,h6')) != null) {
4375                                 np = p.cloneNode(false);
4376                                 np.removeAttribute('id');
4377
4378                                 t = n;
4379
4380                                 while ((n = n.nextSibling))
4381                                         np.appendChild(n);
4382
4383                                 tinyMCE.insertAfter(np, p);
4384                                 tinyMCE.insertAfter(t, p);
4385                         }
4386                 }
4387         },
4388
4389         _cleanupHTML : function(inst, doc, config, elm, visual, on_save, on_submit, inn) {
4390                 var h, d, t1, t2, t3, t4, t5, c, s, nb;
4391
4392                 if (!tinyMCE.getParam('cleanup'))
4393                         return elm.innerHTML;
4394
4395                 on_save = typeof(on_save) == 'undefined' ? false : on_save;
4396
4397                 c = inst.cleanup;
4398                 s = inst.settings;
4399                 d = c.settings.debug;
4400
4401                 if (d)
4402                         t1 = new Date().getTime();
4403
4404                 inst._fixRootBlocks();
4405
4406                 if (tinyMCE.getParam("convert_fonts_to_spans"))
4407                         tinyMCE.convertFontsToSpans(doc);
4408
4409                 if (tinyMCE.getParam("fix_list_elements"))
4410                         tinyMCE._fixListElements(doc);
4411
4412                 if (tinyMCE.getParam("fix_table_elements"))
4413                         tinyMCE._fixTables(doc);
4414
4415                 // Call custom cleanup code
4416                 tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body);
4417
4418                 if (d)
4419                         t2 = new Date().getTime();
4420
4421                 c.settings.on_save = on_save;
4422
4423                 c.idCount = 0;
4424                 c.serializationId++; // Unique ID needed for the content duplication bug
4425                 c.serializedNodes = [];
4426                 c.sourceIndex = -1;
4427
4428                 if (s.cleanup_serializer == "xml")
4429                         h = c.serializeNodeAsXML(elm, inn);
4430                 else
4431                         h = c.serializeNodeAsHTML(elm, inn);
4432
4433                 if (d)
4434                         t3 = new Date().getTime();
4435
4436                 // Post processing
4437                 nb = tinyMCE.getParam('entity_encoding') == 'numeric' ? '&#160;' : '&nbsp;';
4438                 h = h.replace(/<\/?(body|head|html)[^>]*>/gi, '');
4439                 h = h.replace(new RegExp(' (rowspan="1"|colspan="1")', 'g'), '');
4440                 h = h.replace(/<p><hr \/><\/p>/g, '<hr />');
4441                 h = h.replace(/<p>(&nbsp;|&#160;)<\/p><hr \/><p>(&nbsp;|&#160;)<\/p>/g, '<hr />');
4442                 h = h.replace(/<td>\s*<br \/>\s*<\/td>/g, '<td>' + nb + '</td>');
4443                 h = h.replace(/<p>\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
4444                 h = h.replace(/<br \/>$/, ''); // Remove last BR for Gecko
4445                 h = h.replace(/<br \/><\/p>/g, '</p>'); // Remove last BR in P tags for Gecko
4446                 h = h.replace(/<p>\s*(&nbsp;|&#160;)\s*<br \/>\s*(&nbsp;|&#160;)\s*<\/p>/g, '<p>' + nb + '</p>');
4447                 h = h.replace(/<p>\s*(&nbsp;|&#160;)\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
4448                 h = h.replace(/<p>\s*<br \/>\s*&nbsp;\s*<\/p>/g, '<p>' + nb + '</p>');
4449                 h = h.replace(new RegExp('<a>(.*?)<\\/a>', 'g'), '$1');
4450                 h = h.replace(/<p([^>]*)>\s*<\/p>/g, '<p$1>' + nb + '</p>');
4451
4452                 // Clean body
4453                 if (/^\s*(<br \/>|<p>&nbsp;<\/p>|<p>&#160;<\/p>|<p><\/p>)\s*$/.test(h))
4454                         h = '';
4455
4456                 // If preformatted
4457                 if (s.preformatted) {
4458                         h = h.replace(/^<pre>/, '');
4459                         h = h.replace(/<\/pre>$/, '');
4460                         h = '<pre>' + h + '</pre>';
4461                 }
4462
4463                 // Gecko specific processing
4464                 if (tinyMCE.isGecko) {
4465                         // Makes no sence but FF generates it!!
4466                         h = h.replace(/<br \/>\s*<\/li>/g, '</li>');
4467                         h = h.replace(/&nbsp;\s*<\/(dd|dt)>/g, '</$1>');
4468                         h = h.replace(/<o:p _moz-userdefined="" \/>/g, '');
4469                         h = h.replace(/<td([^>]*)>\s*<br \/>\s*<\/td>/g, '<td$1>' + nb + '</td>');
4470                 }
4471
4472                 if (s.force_br_newlines)
4473                         h = h.replace(/<p>(&nbsp;|&#160;)<\/p>/g, '<br />');
4474
4475                 // Call custom cleanup code
4476                 h = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", h);
4477
4478                 // Remove internal classes
4479                 if (on_save) {
4480                         h = h.replace(new RegExp(' ?(mceItem[a-zA-Z0-9]*|' + s.visual_table_class + ')', 'g'), '');
4481                         h = h.replace(new RegExp(' ?class=""', 'g'), '');
4482                 }
4483
4484                 if (s.remove_linebreaks && !c.settings.indent)
4485                         h = h.replace(/\n|\r/g, ' ');
4486
4487                 if (d)
4488                         t4 = new Date().getTime();
4489
4490                 if (on_save && c.settings.indent)
4491                         h = c.formatHTML(h);
4492
4493                 // If encoding (not recommended option)
4494                 if (on_submit && (s.encoding == "xml" || s.encoding == "html"))
4495                         h = c.xmlEncode(h);
4496
4497                 if (d)
4498                         t5 = new Date().getTime();
4499
4500                 if (c.settings.debug)
4501                         tinyMCE.debug("Cleanup in ms: Pre=" + (t2-t1) + ", Serialize: " + (t3-t2) + ", Post: " + (t4-t3) + ", Format: " + (t5-t4) + ", Sum: " + (t5-t1) + ".");
4502
4503                 return h;
4504         }
4505 });
4506
4507 function TinyMCE_Cleanup() {
4508         this.isIE = (navigator.appName == "Microsoft Internet Explorer");
4509         this.rules = tinyMCE.clearArray([]);
4510
4511         // Default config
4512         this.settings = {
4513                 indent_elements : 'head,table,tbody,thead,tfoot,form,tr,ul,ol,blockquote,object',
4514                 newline_before_elements : 'h1,h2,h3,h4,h5,h6,pre,address,div,ul,ol,li,meta,option,area,title,link,base,script,td',
4515                 newline_after_elements : 'br,hr,p,pre,address,div,ul,ol,meta,option,area,link,base,script',
4516                 newline_before_after_elements : 'html,head,body,table,thead,tbody,tfoot,tr,form,ul,ol,blockquote,p,object,param,hr,div',
4517                 indent_char : '\t',
4518                 indent_levels : 1,
4519                 entity_encoding : 'raw',
4520                 valid_elements : '*[*]',
4521                 entities : '',
4522                 url_converter : '',
4523                 invalid_elements : '',
4524                 verify_html : false
4525         };
4526
4527         this.vElements = tinyMCE.clearArray([]);
4528         this.vElementsRe = '';
4529         this.closeElementsRe = /^(IMG|BR|HR|LINK|META|BASE|INPUT|AREA)$/;
4530         this.codeElementsRe = /^(SCRIPT|STYLE)$/;
4531         this.serializationId = 0;
4532         this.mceAttribs = {
4533                 href : 'mce_href',
4534                 src : 'mce_src',
4535                 type : 'mce_type'
4536         };
4537 }
4538
4539 TinyMCE_Cleanup.prototype = {
4540         init : function(s) {
4541                 var n, a, i, ir, or, st;
4542
4543                 for (n in s)
4544                         this.settings[n] = s[n];
4545
4546                 // Setup code formating
4547                 s = this.settings;
4548
4549                 // Setup regexps
4550                 this.inRe = this._arrayToRe(s.indent_elements.split(','), '', '^<(', ')[^>]*');
4551                 this.ouRe = this._arrayToRe(s.indent_elements.split(','), '', '^<\\/(', ')[^>]*');
4552                 this.nlBeforeRe = this._arrayToRe(s.newline_before_elements.split(','), 'gi', '<(',  ')([^>]*)>');
4553                 this.nlAfterRe = this._arrayToRe(s.newline_after_elements.split(','), 'gi', '<(',  ')([^>]*)>');
4554                 this.nlBeforeAfterRe = this._arrayToRe(s.newline_before_after_elements.split(','), 'gi', '<(\\/?)(', ')([^>]*)>');
4555                 this.serializedNodes = [];
4556                 this.serializationId = 0;
4557
4558                 if (s.invalid_elements !== '')
4559                         this.iveRe = this._arrayToRe(s.invalid_elements.toUpperCase().split(','), 'g', '^(', ')$');
4560                 else
4561                         this.iveRe = null;
4562
4563                 // Setup separator
4564                 st = '';
4565                 for (i=0; i<s.indent_levels; i++)
4566                         st += s.indent_char;
4567
4568                 this.inStr = st;
4569
4570                 // If verify_html if false force *[*]
4571                 if (!s.verify_html) {
4572                         s.valid_elements = '*[*]';
4573                         s.extended_valid_elements = '';
4574                 }
4575
4576                 this.fillStr = s.entity_encoding == "named" ? "&nbsp;" : "&#160;";
4577                 this.idCount = 0;
4578                 this.xmlEncodeRe = new RegExp('[\u007F-\uFFFF<>&"]', 'g');
4579         },
4580
4581         addRuleStr : function(s) {
4582                 var r = this.parseRuleStr(s), n;
4583
4584                 for (n in r) {
4585                         if (r[n])
4586                                 this.rules[n] = r[n];
4587                 }
4588
4589                 this.vElements = tinyMCE.clearArray([]);
4590
4591                 for (n in this.rules) {
4592                         if (this.rules[n])
4593                                 this.vElements[this.vElements.length] = this.rules[n].tag;
4594                 }
4595
4596                 this.vElementsRe = this._arrayToRe(this.vElements, '');
4597         },
4598
4599         isValid : function(n) {
4600                 if (!this.rulesDone)
4601                         this._setupRules(); // Will initialize cleanup rules
4602
4603                 // Empty is true since it removes formatting
4604                 if (!n)
4605                         return true;
4606
4607                 // Clean the name up a bit
4608                 n = n.replace(/[^a-z0-9]+/gi, '').toUpperCase();
4609
4610                 return !tinyMCE.getParam('cleanup') || this.vElementsRe.test(n);
4611         },
4612
4613         addChildRemoveRuleStr : function(s) {
4614                 var x, y, p, i, t, tn, ta, cl, r;
4615
4616                 if (!s)
4617                         return;
4618
4619                 ta = s.split(',');
4620                 for (x=0; x<ta.length; x++) {
4621                         s = ta[x];
4622
4623                         // Split tag/children
4624                         p = this.split(/\[|\]/, s);
4625                         if (p == null || p.length < 1)
4626                                 t = s.toUpperCase();
4627                         else
4628                                 t = p[0].toUpperCase();
4629
4630                         // Handle all tag names
4631                         tn = this.split('/', t);
4632                         for (y=0; y<tn.length; y++) {
4633                                 r = "^(";
4634
4635                                 // Build regex
4636                                 cl = this.split(/\|/, p[1]);
4637                                 for (i=0; i<cl.length; i++) {
4638                                         if (cl[i] == '%istrict')
4639                                                 r += tinyMCE.inlineStrict;
4640                                         else if (cl[i] == '%itrans')
4641                                                 r += tinyMCE.inlineTransitional;
4642                                         else if (cl[i] == '%istrict_na')
4643                                                 r += tinyMCE.inlineStrict.substring(2);
4644                                         else if (cl[i] == '%itrans_na')
4645                                                 r += tinyMCE.inlineTransitional.substring(2);
4646                                         else if (cl[i] == '%btrans')
4647                                                 r += tinyMCE.blockElms;
4648                                         else if (cl[i] == '%strict')
4649                                                 r += tinyMCE.blockStrict;
4650                                         else
4651                                                 r += (cl[i].charAt(0) != '#' ? cl[i].toUpperCase() : cl[i]);
4652
4653                                         r += (i != cl.length - 1 ? '|' : '');
4654                                 }
4655
4656                                 r += ')$';
4657
4658                                 if (this.childRules == null)
4659                                         this.childRules = tinyMCE.clearArray([]);
4660
4661                                 this.childRules[tn[y]] = new RegExp(r);
4662
4663                                 if (p.length > 1)
4664                                         this.childRules[tn[y]].wrapTag = p[2];
4665                         }
4666                 }
4667         },
4668
4669         parseRuleStr : function(s) {
4670                 var ta, p, r, a, i, x, px, t, tn, y, av, or = tinyMCE.clearArray([]), dv;
4671
4672                 if (s == null || s.length == 0)
4673                         return or;
4674
4675                 ta = s.split(',');
4676                 for (x=0; x<ta.length; x++) {
4677                         s = ta[x];
4678                         if (s.length == 0)
4679                                 continue;
4680
4681                         // Split tag/attrs
4682                         p = this.split(/\[|\]/, s);
4683                         if (p == null || p.length < 1)
4684                                 t = s.toUpperCase();
4685                         else
4686                                 t = p[0].toUpperCase();
4687
4688                         // Handle all tag names
4689                         tn = this.split('/', t);
4690                         for (y=0; y<tn.length; y++) {
4691                                 r = {};
4692
4693                                 r.tag = tn[y];
4694                                 r.forceAttribs = null;
4695                                 r.defaultAttribs = null;
4696                                 r.validAttribValues = null;
4697
4698                                 // Handle prefixes
4699                                 px = r.tag.charAt(0);
4700                                 r.forceOpen = px == '+';
4701                                 r.removeEmpty = px == '-';
4702                                 r.fill = px == '#';
4703                                 r.tag = r.tag.replace(/\+|-|#/g, '');
4704                                 r.oTagName = tn[0].replace(/\+|-|#/g, '').toLowerCase();
4705                                 r.isWild = new RegExp('\\*|\\?|\\+', 'g').test(r.tag);
4706                                 r.validRe = new RegExp(this._wildcardToRe('^' + r.tag + '$'));
4707
4708                                 // Setup valid attributes
4709                                 if (p.length > 1) {
4710                                         r.vAttribsRe = '^(';
4711                                         a = this.split(/\|/, p[1]);
4712
4713                                         for (i=0; i<a.length; i++) {
4714                                                 t = a[i];
4715
4716                                                 if (t.charAt(0) == '!') {
4717                                                         a[i] = t = t.substring(1);
4718
4719                                                         if (!r.reqAttribsRe)
4720                                                                 r.reqAttribsRe = '\\s+(' + t;
4721                                                         else
4722                                                                 r.reqAttribsRe += '|' + t;
4723                                                 }
4724
4725                                                 av = new RegExp('(=|:|<)(.*?)$').exec(t);
4726                                                 t = t.replace(new RegExp('(=|:|<).*?$'), '');
4727                                                 if (av && av.length > 0) {
4728                                                         if (av[0].charAt(0) == ':') {
4729                                                                 if (!r.forceAttribs)
4730                                                                         r.forceAttribs = tinyMCE.clearArray([]);
4731
4732                                                                 r.forceAttribs[t.toLowerCase()] = av[0].substring(1);
4733                                                         } else if (av[0].charAt(0) == '=') {
4734                                                                 if (!r.defaultAttribs)
4735                                                                         r.defaultAttribs = tinyMCE.clearArray([]);
4736
4737                                                                 dv = av[0].substring(1);
4738
4739                                                                 r.defaultAttribs[t.toLowerCase()] = dv == '' ? "mce_empty" : dv;
4740                                                         } else if (av[0].charAt(0) == '<') {
4741                                                                 if (!r.validAttribValues)
4742                                                                         r.validAttribValues = tinyMCE.clearArray([]);
4743
4744                                                                 r.validAttribValues[t.toLowerCase()] = this._arrayToRe(this.split('?', av[0].substring(1)), 'i');
4745                                                         }
4746                                                 }
4747
4748                                                 r.vAttribsRe += '' + t.toLowerCase() + (i != a.length - 1 ? '|' : '');
4749
4750                                                 a[i] = t.toLowerCase();
4751                                         }
4752
4753                                         if (r.reqAttribsRe)
4754                                                 r.reqAttribsRe = new RegExp(r.reqAttribsRe + ')=\"', 'g');
4755
4756                                         r.vAttribsRe += ')$';
4757                                         r.vAttribsRe = this._wildcardToRe(r.vAttribsRe);
4758                                         r.vAttribsReIsWild = new RegExp('\\*|\\?|\\+', 'g').test(r.vAttribsRe);
4759                                         r.vAttribsRe = new RegExp(r.vAttribsRe);
4760                                         r.vAttribs = a.reverse();
4761
4762                                         //tinyMCE.debug(r.tag, r.oTagName, r.vAttribsRe, r.vAttribsReWC);
4763                                 } else {
4764                                         r.vAttribsRe = '';
4765                                         r.vAttribs = tinyMCE.clearArray([]);
4766                                         r.vAttribsReIsWild = false;
4767                                 }
4768
4769                                 or[r.tag] = r;
4770                         }
4771                 }
4772
4773                 return or;
4774         },
4775
4776         serializeNodeAsXML : function(n) {
4777                 var s, b;
4778
4779                 if (!this.xmlDoc) {
4780                         if (this.isIE) {
4781                                 try {this.xmlDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {}
4782
4783                                 if (!this.xmlDoc)
4784                                         try {this.xmlDoc = new ActiveXObject('Microsoft.XmlDom');} catch (e) {}
4785                         } else
4786                                 this.xmlDoc = document.implementation.createDocument('', '', null);
4787
4788                         if (!this.xmlDoc)
4789                                 alert("Error XML Parser could not be found.");
4790                 }
4791
4792                 if (this.xmlDoc.firstChild)
4793                         this.xmlDoc.removeChild(this.xmlDoc.firstChild);
4794
4795                 b = this.xmlDoc.createElement("html");
4796                 b = this.xmlDoc.appendChild(b);
4797
4798                 this._convertToXML(n, b);
4799
4800                 if (this.isIE)
4801                         return this.xmlDoc.xml;
4802                 else
4803                         return new XMLSerializer().serializeToString(this.xmlDoc);
4804         },
4805
4806         _convertToXML : function(n, xn) {
4807                 var xd, el, i, l, cn, at, no, hc = false;
4808
4809                 if (tinyMCE.isRealIE && this._isDuplicate(n))
4810                         return;
4811
4812                 xd = this.xmlDoc;
4813
4814                 switch (n.nodeType) {
4815                         case 1: // Element
4816                                 hc = n.hasChildNodes();
4817
4818                                 el = xd.createElement(n.nodeName.toLowerCase());
4819
4820                                 at = n.attributes;
4821                                 for (i=at.length-1; i>-1; i--) {
4822                                         no = at[i];
4823
4824                                         if (no.specified && no.nodeValue)
4825                                                 el.setAttribute(no.nodeName.toLowerCase(), no.nodeValue);
4826                                 }
4827
4828                                 if (!hc && !this.closeElementsRe.test(n.nodeName))
4829                                         el.appendChild(xd.createTextNode(""));
4830
4831                                 xn = xn.appendChild(el);
4832                                 break;
4833
4834                         case 3: // Text
4835                                 xn.appendChild(xd.createTextNode(n.nodeValue));
4836                                 return;
4837
4838                         case 8: // Comment
4839                                 xn.appendChild(xd.createComment(n.nodeValue));
4840                                 return;
4841                 }
4842
4843                 if (hc) {
4844                         cn = n.childNodes;
4845
4846                         for (i=0, l=cn.length; i<l; i++)
4847                                 this._convertToXML(cn[i], xn);
4848                 }
4849         },
4850
4851         serializeNodeAsHTML : function(n, inn) {
4852                 var en, no, h = '', i, l, t, st, r, cn, va = false, f = false, at, hc, cr, nn;
4853
4854                 if (!this.rulesDone)
4855                         this._setupRules(); // Will initialize cleanup rules
4856
4857                 if (tinyMCE.isRealIE && this._isDuplicate(n))
4858                         return '';
4859
4860                 // Skip non valid child elements
4861                 if (n.parentNode && this.childRules != null) {
4862                         cr = this.childRules[n.parentNode.nodeName];
4863
4864                         if (typeof(cr) != "undefined" && !cr.test(n.nodeName)) {
4865                                 st = true;
4866                                 t = null;
4867                         }
4868                 }
4869
4870                 switch (n.nodeType) {
4871                         case 1: // Element
4872                                 hc = n.hasChildNodes();
4873
4874                                 if (st)
4875                                         break;
4876
4877                                 nn = n.nodeName;
4878
4879                                 if (tinyMCE.isRealIE) {
4880                                         // MSIE sometimes produces <//tag>
4881                                         if (n.nodeName.indexOf('/') != -1)
4882                                                 break;
4883
4884                                         // MSIE has it's NS in a separate attrib
4885                                         if (n.scopeName && n.scopeName != 'HTML')
4886                                                 nn = n.scopeName.toUpperCase() + ':' + nn.toUpperCase();
4887                                 } else if (tinyMCE.isOpera && nn.indexOf(':') > 0)
4888                                         nn = nn.toUpperCase();
4889
4890                                 // Convert fonts to spans
4891                                 if (this.settings.convert_fonts_to_spans) {
4892                                         // On get content FONT -> SPAN
4893                                         if (this.settings.on_save && nn == 'FONT')
4894                                                 nn = 'SPAN';
4895
4896                                         // On insert content SPAN -> FONT
4897                                         if (!this.settings.on_save && nn == 'SPAN')
4898                                                 nn = 'FONT';
4899                                 }
4900
4901                                 if (this.vElementsRe.test(nn) && (!this.iveRe || !this.iveRe.test(nn)) && !inn) {
4902                                         va = true;
4903
4904                                         r = this.rules[nn];
4905                                         if (!r) {
4906                                                 at = this.rules;
4907                                                 for (no in at) {
4908                                                         if (at[no] && at[no].validRe.test(nn)) {
4909                                                                 r = at[no];
4910                                                                 break;
4911                                                         }
4912                                                 }
4913                                         }
4914
4915                                         en = r.isWild ? nn.toLowerCase() : r.oTagName;
4916                                         f = r.fill;
4917
4918                                         if (r.removeEmpty && !hc)
4919                                                 return "";
4920
4921                                         t = '<' + en;
4922
4923                                         if (r.vAttribsReIsWild) {
4924                                                 // Serialize wildcard attributes
4925                                                 at = n.attributes;
4926                                                 for (i=at.length-1; i>-1; i--) {
4927                                                         no = at[i];
4928                                                         if (no.specified && r.vAttribsRe.test(no.nodeName))
4929                                                                 t += this._serializeAttribute(n, r, no.nodeName);
4930                                                 }
4931                                         } else {
4932                                                 // Serialize specific attributes
4933                                                 for (i=r.vAttribs.length-1; i>-1; i--)
4934                                                         t += this._serializeAttribute(n, r, r.vAttribs[i]);
4935                                         }
4936
4937                                         // Serialize mce_ atts
4938                                         if (!this.settings.on_save) {
4939                                                 at = this.mceAttribs;
4940
4941                                                 for (no in at) {
4942                                                         if (at[no])
4943                                                                 t += this._serializeAttribute(n, r, at[no]);
4944                                                 }
4945                                         }
4946
4947                                         // Check for required attribs
4948                                         if (r.reqAttribsRe && !t.match(r.reqAttribsRe))
4949                                                 t = null;
4950
4951                                         // Close these
4952                                         if (t != null && this.closeElementsRe.test(nn))
4953                                                 return t + ' />';
4954
4955                                         if (t != null)
4956                                                 h += t + '>';
4957
4958                                         if (this.isIE && this.codeElementsRe.test(nn))
4959                                                 h += n.innerHTML;
4960                                 }
4961                         break;
4962
4963                         case 3: // Text
4964                                 if (st)
4965                                         break;
4966
4967                                 if (n.parentNode && this.codeElementsRe.test(n.parentNode.nodeName))
4968                                         return this.isIE ? '' : n.nodeValue;
4969
4970                                 return this.xmlEncode(n.nodeValue);
4971
4972                         case 8: // Comment
4973                                 if (st)
4974                                         break;
4975
4976                                 return "<!--" + this._trimComment(n.nodeValue) + "-->";
4977                 }
4978
4979                 if (hc) {
4980                         cn = n.childNodes;
4981
4982                         for (i=0, l=cn.length; i<l; i++)
4983                                 h += this.serializeNodeAsHTML(cn[i]);
4984                 }
4985
4986                 // Fill empty nodes
4987                 if (f && !hc)
4988                         h += this.fillStr;
4989
4990                 // End element
4991                 if (t != null && va)
4992                         h += '</' + en + '>';
4993
4994                 return h;
4995         },
4996
4997         _serializeAttribute : function(n, r, an) {
4998                 var av = '', t, os = this.settings.on_save;
4999
5000                 if (os && (an.indexOf('mce_') == 0 || an.indexOf('_moz') == 0))
5001                         return '';
5002
5003                 if (os && this.mceAttribs[an])
5004                         av = this._getAttrib(n, this.mceAttribs[an]);
5005
5006                 if (av.length == 0)
5007                         av = this._getAttrib(n, an);
5008
5009                 if (av.length == 0 && r.defaultAttribs && (t = r.defaultAttribs[an])) {
5010                         av = t;
5011
5012                         if (av == "mce_empty")
5013                                 return " " + an + '=""';
5014                 }
5015
5016                 if (r.forceAttribs && (t = r.forceAttribs[an]))
5017                         av = t;
5018
5019                 if (os && av.length != 0 && /^(src|href|longdesc)$/.test(an))
5020                         av = this._urlConverter(this, n, av);
5021
5022                 if (av.length != 0 && r.validAttribValues && r.validAttribValues[an] && !r.validAttribValues[an].test(av))
5023                         return "";
5024
5025                 if (av.length != 0 && av == "{$uid}")
5026                         av = "uid_" + (this.idCount++);
5027
5028                 if (av.length != 0) {
5029                         if (an.indexOf('on') != 0)
5030                                 av = this.xmlEncode(av, 1);
5031
5032                         return " " + an + "=" + '"' + av + '"';
5033                 }
5034
5035                 return "";
5036         },
5037
5038         formatHTML : function(h) {
5039                 var s = this.settings, p = '', i = 0, li = 0, o = '', l;
5040
5041                 // Replace BR in pre elements to \n
5042                 h = h.replace(/<pre([^>]*)>(.*?)<\/pre>/gi, function (a, b, c) {
5043                         c = c.replace(/<br\s*\/>/gi, '\n');
5044                         return '<pre' + b + '>' + c + '</pre>';
5045                 });
5046
5047                 h = h.replace(/\r/g, ''); // Windows sux, isn't carriage return a thing of the past :)
5048                 h = '\n' + h;
5049                 h = h.replace(new RegExp('\\n\\s+', 'gi'), '\n'); // Remove previous formatting
5050                 h = h.replace(this.nlBeforeRe, '\n<$1$2>');
5051                 h = h.replace(this.nlAfterRe, '<$1$2>\n');
5052                 h = h.replace(this.nlBeforeAfterRe, '\n<$1$2$3>\n');
5053                 h += '\n';
5054
5055                 //tinyMCE.debug(h);
5056
5057                 while ((i = h.indexOf('\n', i + 1)) != -1) {
5058                         if ((l = h.substring(li + 1, i)).length != 0) {
5059                                 if (this.ouRe.test(l) && p.length >= s.indent_levels)
5060                                         p = p.substring(s.indent_levels);
5061
5062                                 o += p + l + '\n';
5063         
5064                                 if (this.inRe.test(l))
5065                                         p += this.inStr;
5066                         }
5067
5068                         li = i;
5069                 }
5070
5071                 //tinyMCE.debug(h);
5072
5073                 return o;
5074         },
5075
5076         xmlEncode : function(s) {
5077                 var cl = this, re = this.xmlEncodeRe;
5078
5079                 if (!this.entitiesDone)
5080                         this._setupEntities(); // Will intialize lookup table
5081
5082                 switch (this.settings.entity_encoding) {
5083                         case "raw":
5084                                 return tinyMCE.xmlEncode(s);
5085
5086                         case "named":
5087                                 return s.replace(re, function (c) {
5088                                         var b = cl.entities[c.charCodeAt(0)];
5089
5090                                         return b ? '&' + b + ';' : c;
5091                                 });
5092
5093                         case "numeric":
5094                                 return s.replace(re, function (c) {
5095                                         return '&#' + c.charCodeAt(0) + ';';
5096                                 });
5097                 }
5098
5099                 return s;
5100         },
5101
5102         split : function(re, s) {
5103                 var i, l, o = [], c = s.split(re);
5104
5105                 for (i=0, l=c.length; i<l; i++) {
5106                         if (c[i] !== '')
5107                                 o[i] = c[i];
5108                 }
5109
5110                 return o;
5111         },
5112
5113         _trimComment : function(s) {
5114                 // Remove mce_src, mce_href
5115                 s = s.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), "");
5116                 s = s.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), "");
5117
5118                 return s;
5119         },
5120
5121         _getAttrib : function(e, n, d) {
5122                 var v, ex, nn;
5123
5124                 if (typeof(d) == "undefined")
5125                         d = "";
5126
5127                 if (!e || e.nodeType != 1)
5128                         return d;
5129
5130                 try {
5131                         v = e.getAttribute(n, 0);
5132                 } catch (ex) {
5133                         // IE 7 may cast exception on invalid attributes
5134                         v = e.getAttribute(n, 2);
5135                 }
5136
5137                 if (n == "class" && !v)
5138                         v = e.className;
5139
5140                 if (this.isIE) {
5141                         if (n == "http-equiv")
5142                                 v = e.httpEquiv;
5143
5144                         nn = e.nodeName;
5145
5146                         // Skip the default values that IE returns
5147                         if (nn == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded")
5148                                 v = "";
5149
5150                         if (nn == "INPUT" && n == "size" && v == "20")
5151                                 v = "";
5152
5153                         if (nn == "INPUT" && n == "maxlength" && v == "2147483647")
5154                                 v = "";
5155
5156                         // Images
5157                         if (n == "width" || n == "height")
5158                                 v = e.getAttribute(n, 2);
5159                 }
5160
5161                 if (n == 'style' && v) {
5162                         if (!tinyMCE.isOpera)
5163                                 v = e.style.cssText;
5164
5165                         v = tinyMCE.serializeStyle(tinyMCE.parseStyle(v));
5166                 }
5167
5168                 if (this.settings.on_save && n.indexOf('on') != -1 && this.settings.on_save && v && v !== '')
5169                         v = tinyMCE.cleanupEventStr(v);
5170
5171                 return (v && v !== '') ? '' + v : d;
5172         },
5173
5174         _urlConverter : function(c, n, v) {
5175                 if (!c.settings.on_save)
5176                         return tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, v);
5177                 else if (tinyMCE.getParam('convert_urls')) {
5178                         if (!this.urlConverter)
5179                                 this.urlConverter = eval(tinyMCE.settings.urlconverter_callback);
5180
5181                         return this.urlConverter(v, n, true);
5182                 }
5183
5184                 return v;
5185         },
5186
5187         _arrayToRe : function(a, op, be, af) {
5188                 var i, r;
5189
5190                 op = typeof(op) == "undefined" ? "gi" : op;
5191                 be = typeof(be) == "undefined" ? "^(" : be;
5192                 af = typeof(af) == "undefined" ? ")$" : af;
5193
5194                 r = be;
5195
5196                 for (i=0; i<a.length; i++)
5197                         r += this._wildcardToRe(a[i]) + (i != a.length-1 ? "|" : "");
5198
5199                 r += af;
5200
5201                 return new RegExp(r, op);
5202         },
5203
5204         _wildcardToRe : function(s) {
5205                 s = s.replace(/\?/g, '(\\S?)');
5206                 s = s.replace(/\+/g, '(\\S+)');
5207                 s = s.replace(/\*/g, '(\\S*)');
5208
5209                 return s;
5210         },
5211
5212         _setupEntities : function() {
5213                 var n, a, i, s = this.settings;
5214
5215                 // Setup entities
5216                 if (s.entity_encoding == "named") {
5217                         n = tinyMCE.clearArray([]);
5218                         a = this.split(',', s.entities);
5219                         for (i=0; i<a.length; i+=2)
5220                                 n[a[i]] = a[i+1];
5221
5222                         this.entities = n;
5223                 }
5224
5225                 this.entitiesDone = true;
5226         },
5227
5228         _setupRules : function() {
5229                 var s = this.settings;
5230
5231                 // Setup default rule
5232                 this.addRuleStr(s.valid_elements);
5233                 this.addRuleStr(s.extended_valid_elements);
5234                 this.addChildRemoveRuleStr(s.valid_child_elements);
5235
5236                 this.rulesDone = true;
5237         },
5238
5239         _isDuplicate : function(n) {
5240                 var i, l, sn;
5241
5242                 if (!this.settings.fix_content_duplication)
5243                         return false;
5244
5245                 if (tinyMCE.isRealIE && n.nodeType == 1) {
5246                         // Mark elements
5247                         if (n.mce_serialized == this.serializationId)
5248                                 return true;
5249
5250                         n.setAttribute('mce_serialized', this.serializationId);
5251                 } else {
5252                         sn = this.serializedNodes;
5253
5254                         // Search lookup table for text nodes  and comments
5255                         for (i=0, l = sn.length; i<l; i++) {
5256                                 if (sn[i] == n)
5257                                         return true;
5258                         }
5259
5260                         sn.push(n);
5261                 }
5262
5263                 return false;
5264         }
5265
5266         };
5267
5268 /* file:jscripts/tiny_mce/classes/TinyMCE_DOMUtils.class.js */
5269
5270 tinyMCE.add(TinyMCE_Engine, {
5271         createTagHTML : function(tn, a, h) {
5272                 var o = '', f = tinyMCE.xmlEncode, n;
5273
5274                 o = '<' + tn;
5275
5276                 if (a) {
5277                         for (n in a) {
5278                                 if (typeof(a[n]) != 'function' && a[n] != null)
5279                                         o += ' ' + f(n) + '="' + f('' + a[n]) + '"';
5280                         }
5281                 }
5282
5283                 o += !h ? ' />' : '>' + h + '</' + tn + '>';
5284
5285                 return o;
5286         },
5287
5288         createTag : function(d, tn, a, h) {
5289                 var o = d.createElement(tn), n;
5290
5291                 if (a) {
5292                         for (n in a) {
5293                                 if (typeof(a[n]) != 'function' && a[n] != null)
5294                                         tinyMCE.setAttrib(o, n, a[n]);
5295                         }
5296                 }
5297
5298                 if (h)
5299                         o.innerHTML = h;
5300
5301                 return o;
5302         },
5303
5304         getElementByAttributeValue : function(n, e, a, v) {
5305                 return (n = this.getElementsByAttributeValue(n, e, a, v)).length == 0 ? null : n[0];
5306         },
5307
5308         getElementsByAttributeValue : function(n, e, a, v) {
5309                 var i, nl = n.getElementsByTagName(e), o = [];
5310
5311                 for (i=0; i<nl.length; i++) {
5312                         if (tinyMCE.getAttrib(nl[i], a).indexOf(v) != -1)
5313                                 o[o.length] = nl[i];
5314                 }
5315
5316                 return o;
5317         },
5318
5319         isBlockElement : function(n) {
5320                 return n != null && n.nodeType == 1 && this.blockRegExp.test(n.nodeName);
5321         },
5322
5323         getParentBlockElement : function(n, r) {
5324                 return this.getParentNode(n, function(n) {
5325                         return tinyMCE.isBlockElement(n);
5326                 }, r);
5327
5328                 return null;
5329         },
5330
5331         insertAfter : function(n, r){
5332                 if (r.nextSibling)
5333                         r.parentNode.insertBefore(n, r.nextSibling);
5334                 else
5335                         r.parentNode.appendChild(n);
5336         },
5337
5338         setInnerHTML : function(e, h) {
5339                 var i, nl, n;
5340
5341                 // Convert all strong/em to b/i in Gecko
5342                 if (tinyMCE.isGecko) {
5343                         h = h.replace(/<embed([^>]*)>/gi, '<tmpembed$1>');
5344                         h = h.replace(/<em([^>]*)>/gi, '<i$1>');
5345                         h = h.replace(/<tmpembed([^>]*)>/gi, '<embed$1>');
5346                         h = h.replace(/<strong([^>]*)>/gi, '<b$1>');
5347                         h = h.replace(/<\/strong>/gi, '</b>');
5348                         h = h.replace(/<\/em>/gi, '</i>');
5349                 }
5350
5351                 if (tinyMCE.isRealIE) {
5352                         // Since MSIE handles invalid HTML better that valid XHTML we
5353                         // need to make some things invalid. <hr /> gets converted to <hr>.
5354                         h = h.replace(/\s\/>/g, '>');
5355
5356                         // Since MSIE auto generated emtpy P tags some times we must tell it to keep the real ones
5357                         h = h.replace(/<p([^>]*)>\u00A0?<\/p>/gi, '<p$1 mce_keep="true">&nbsp;</p>'); // Keep empty paragraphs
5358                         h = h.replace(/<p([^>]*)>\s*&nbsp;\s*<\/p>/gi, '<p$1 mce_keep="true">&nbsp;</p>'); // Keep empty paragraphs
5359                         h = h.replace(/<p([^>]*)>\s+<\/p>/gi, '<p$1 mce_keep="true">&nbsp;</p>'); // Keep empty paragraphs
5360
5361                         // Remove first comment
5362                         e.innerHTML = tinyMCE.uniqueTag + h;
5363                         e.firstChild.removeNode(true);
5364
5365                         // Remove weird auto generated empty paragraphs unless it's supposed to be there
5366                         nl = e.getElementsByTagName("p");
5367                         for (i=nl.length-1; i>=0; i--) {
5368                                 n = nl[i];
5369
5370                                 if (n.nodeName == 'P' && !n.hasChildNodes() && !n.mce_keep)
5371                                         n.parentNode.removeChild(n);
5372                         }
5373                 } else {
5374                         h = this.fixGeckoBaseHREFBug(1, e, h);
5375                         e.innerHTML = h;
5376                         this.fixGeckoBaseHREFBug(2, e, h);
5377                 }
5378         },
5379
5380         getOuterHTML : function(e) {
5381                 var d;
5382
5383                 if (tinyMCE.isIE)
5384                         return e.outerHTML;
5385
5386                 d = e.ownerDocument.createElement("body");
5387                 d.appendChild(e.cloneNode(true));
5388
5389                 return d.innerHTML;
5390         },
5391
5392         setOuterHTML : function(e, h, d) {
5393                 var d = typeof(d) == "undefined" ? e.ownerDocument : d, i, nl, t;
5394
5395                 if (tinyMCE.isIE && e.nodeType == 1)
5396                         e.outerHTML = h;
5397                 else {
5398                         t = d.createElement("body");
5399                         t.innerHTML = h;
5400
5401                         for (i=0, nl=t.childNodes; i<nl.length; i++)
5402                                 e.parentNode.insertBefore(nl[i].cloneNode(true), e);
5403
5404                         e.parentNode.removeChild(e);
5405                 }
5406         },
5407
5408         _getElementById : function(id, d) {
5409                 var e, i, j, f;
5410
5411                 if (typeof(d) == "undefined")
5412                         d = document;
5413
5414                 e = d.getElementById(id);
5415                 if (!e) {
5416                         f = d.forms;
5417
5418                         for (i=0; i<f.length; i++) {
5419                                 for (j=0; j<f[i].elements.length; j++) {
5420                                         if (f[i].elements[j].name == id) {
5421                                                 e = f[i].elements[j];
5422                                                 break;
5423                                         }
5424                                 }
5425                         }
5426                 }
5427
5428                 return e;
5429         },
5430
5431         getNodeTree : function(n, na, t, nn) {
5432                 return this.selectNodes(n, function(n) {
5433                         return (!t || n.nodeType == t) && (!nn || n.nodeName == nn);
5434                 }, na ? na : []);
5435         },
5436
5437         getParentElement : function(n, na, f, r) {
5438                 var re = na ? new RegExp('^(' + na.toUpperCase().replace(/,/g, '|') + ')$') : 0, v;
5439
5440                 // Compatiblity with old scripts where f param was a attribute string
5441                 if (f && typeof(f) == 'string')
5442                         return this.getParentElement(n, na, function(no) {return tinyMCE.getAttrib(no, f) !== '';});
5443
5444                 return this.getParentNode(n, function(n) {
5445                         return ((n.nodeType == 1 && !re) || (re && re.test(n.nodeName))) && (!f || f(n));
5446                 }, r);
5447         },
5448
5449         getParentNode : function(n, f, r) {
5450                 while (n) {
5451                         if (n == r)
5452                                 return null;
5453
5454                         if (f(n))
5455                                 return n;
5456
5457                         n = n.parentNode;
5458                 }
5459
5460                 return null;
5461         },
5462
5463         getAttrib : function(elm, name, dv) {
5464                 var v;
5465
5466                 if (typeof(dv) == "undefined")
5467                         dv = "";
5468
5469                 // Not a element
5470                 if (!elm || elm.nodeType != 1)
5471                         return dv;
5472
5473                 try {
5474                         v = elm.getAttribute(name, 0);
5475                 } catch (ex) {
5476                         // IE 7 may cast exception on invalid attributes
5477                         v = elm.getAttribute(name, 2);
5478                 }
5479
5480                 // Try className for class attrib
5481                 if (name == "class" && !v)
5482                         v = elm.className;
5483
5484                 // Workaround for a issue with Firefox 1.5rc2+
5485                 if (tinyMCE.isGecko) {
5486                         if (name == "src" && elm.src != null && elm.src !== '')
5487                                 v = elm.src;
5488
5489                         // Workaround for a issue with Firefox 1.5rc2+
5490                         if (name == "href" && elm.href != null && elm.href !== '')
5491                                 v = elm.href;
5492                 } else if (tinyMCE.isIE) {
5493                         switch (name) {
5494                                 case "http-equiv":
5495                                         v = elm.httpEquiv;
5496                                         break;
5497
5498                                 case "width":
5499                                 case "height":
5500                                         v = elm.getAttribute(name, 2);
5501                                         break;
5502                         }
5503                 }
5504
5505                 if (name == "style" && !tinyMCE.isOpera)
5506                         v = elm.style.cssText;
5507
5508                 return (v && v !== '') ? v : dv;
5509         },
5510
5511         setAttrib : function(el, name, va, fix) {
5512                 if (typeof(va) == "number" && va != null)
5513                         va = "" + va;
5514
5515                 if (fix) {
5516                         if (va == null)
5517                                 va = "";
5518
5519                         va = va.replace(/[^0-9%]/g, '');
5520                 }
5521
5522                 if (name == "style")
5523                         el.style.cssText = va;
5524
5525                 if (name == "class")
5526                         el.className = va;
5527
5528                 if (va != null && va !== '' && va != -1)
5529                         el.setAttribute(name, va);
5530                 else
5531                         el.removeAttribute(name);
5532         },
5533
5534         setStyleAttrib : function(e, n, v) {
5535                 e.style[n] = v;
5536
5537                 // Style attrib deleted in IE
5538                 if (tinyMCE.isIE && v == null || v == '') {
5539                         v = tinyMCE.serializeStyle(tinyMCE.parseStyle(e.style.cssText));
5540                         e.style.cssText = v;
5541                         e.setAttribute("style", v);
5542                 }
5543         },
5544
5545         switchClass : function(ei, c) {
5546                 var e;
5547
5548                 if (tinyMCE.switchClassCache[ei])
5549                         e = tinyMCE.switchClassCache[ei];
5550                 else
5551                         e = tinyMCE.switchClassCache[ei] = document.getElementById(ei);
5552
5553                 if (e) {
5554                         // Keep tile mode
5555                         if (tinyMCE.settings.button_tile_map && e.className && e.className.indexOf('mceTiledButton') == 0)
5556                                 c = 'mceTiledButton ' + c;
5557
5558                         e.className = c;
5559                 }
5560         },
5561
5562         getAbsPosition : function(n, cn) {
5563                 var l = 0, t = 0;
5564
5565                 while (n && n != cn) {
5566                         l += n.offsetLeft;
5567                         t += n.offsetTop;
5568                         n = n.offsetParent;
5569                 }
5570
5571                 return {absLeft : l, absTop : t};
5572         },
5573
5574         prevNode : function(e, n) {
5575                 var a = n.split(','), i;
5576
5577                 while ((e = e.previousSibling) != null) {
5578                         for (i=0; i<a.length; i++) {
5579                                 if (e.nodeName == a[i])
5580                                         return e;
5581                         }
5582                 }
5583
5584                 return null;
5585         },
5586
5587         nextNode : function(e, n) {
5588                 var a = n.split(','), i;
5589
5590                 while ((e = e.nextSibling) != null) {
5591                         for (i=0; i<a.length; i++) {
5592                                 if (e.nodeName == a[i])
5593                                         return e;
5594                         }
5595                 }
5596
5597                 return null;
5598         },
5599
5600         selectElements : function(n, na, f) {
5601                 var i, a = [], nl, x;
5602
5603                 for (x=0, na = na.split(','); x<na.length; x++)
5604                         for (i=0, nl = n.getElementsByTagName(na[x]); i<nl.length; i++)
5605                                 (!f || f(nl[i])) && a.push(nl[i]);
5606
5607                 return a;
5608         },
5609
5610         selectNodes : function(n, f, a) {
5611                 var i;
5612
5613                 if (!a)
5614                         a = [];
5615
5616                 if (f(n))
5617                         a[a.length] = n;
5618
5619                 if (n.hasChildNodes()) {
5620                         for (i=0; i<n.childNodes.length; i++)
5621                                 tinyMCE.selectNodes(n.childNodes[i], f, a);
5622                 }
5623
5624                 return a;
5625         },
5626
5627         addCSSClass : function(e, c, b) {
5628                 var o = this.removeCSSClass(e, c);
5629                 return e.className = b ? c + (o !== '' ? (' ' + o) : '') : (o !== '' ? (o + ' ') : '') + c;
5630         },
5631
5632         removeCSSClass : function(e, c) {
5633                 c = e.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ');
5634                 return e.className = c != ' ' ? c : '';
5635         },
5636
5637         hasCSSClass : function(n, c) {
5638                 return new RegExp('\\b' + c + '\\b', 'g').test(n.className);
5639         },
5640
5641         renameElement : function(e, n, d) {
5642                 var ne, i, ar;
5643
5644                 d = typeof(d) == "undefined" ? tinyMCE.selectedInstance.getDoc() : d;
5645
5646                 if (e) {
5647                         ne = d.createElement(n);
5648
5649                         ar = e.attributes;
5650                         for (i=ar.length-1; i>-1; i--) {
5651                                 if (ar[i].specified && ar[i].nodeValue)
5652                                         ne.setAttribute(ar[i].nodeName.toLowerCase(), ar[i].nodeValue);
5653                         }
5654
5655                         ar = e.childNodes;
5656                         for (i=0; i<ar.length; i++)
5657                                 ne.appendChild(ar[i].cloneNode(true));
5658
5659                         e.parentNode.replaceChild(ne, e);
5660                 }
5661         },
5662
5663         getViewPort : function(w) {
5664                 var d = w.document, m = d.compatMode == 'CSS1Compat', b = d.body, de = d.documentElement;
5665
5666                 return {
5667                         left : w.pageXOffset || (m ? de.scrollLeft : b.scrollLeft),
5668                         top : w.pageYOffset || (m ? de.scrollTop : b.scrollTop),
5669                         width : w.innerWidth || (m ? de.clientWidth : b.clientWidth),
5670                         height : w.innerHeight || (m ? de.clientHeight : b.clientHeight)
5671                 };
5672         },
5673
5674         getStyle : function(n, na, d) {
5675                 if (!n)
5676                         return false;
5677
5678                 // Gecko
5679                 if (tinyMCE.isGecko && n.ownerDocument.defaultView) {
5680                         try {
5681                                 return n.ownerDocument.defaultView.getComputedStyle(n, null).getPropertyValue(na);
5682                         } catch (n) {
5683                                 // Old safari might fail
5684                                 return null;
5685                         }
5686                 }
5687
5688                 // Camelcase it, if needed
5689                 na = na.replace(/-(\D)/g, function(a, b){
5690                         return b.toUpperCase();
5691                 });
5692
5693                 // IE & Opera
5694                 if (n.currentStyle)
5695                         return n.currentStyle[na];
5696
5697                 return false;
5698         }
5699
5700         });
5701
5702 /* file:jscripts/tiny_mce/classes/TinyMCE_URL.class.js */
5703
5704 tinyMCE.add(TinyMCE_Engine, {
5705         parseURL : function(url_str) {
5706                 var urlParts = [], i, pos, lastPos, chr;
5707
5708                 if (url_str) {
5709                         // Parse protocol part
5710                         pos = url_str.indexOf('://');
5711                         if (pos != -1) {
5712                                 urlParts.protocol = url_str.substring(0, pos);
5713                                 lastPos = pos + 3;
5714                         }
5715
5716                         // Find port or path start
5717                         for (i=lastPos; i<url_str.length; i++) {
5718                                 chr = url_str.charAt(i);
5719
5720                                 if (chr == ':')
5721                                         break;
5722
5723                                 if (chr == '/')
5724                                         break;
5725                         }
5726                         pos = i;
5727
5728                         // Get host
5729                         urlParts.host = url_str.substring(lastPos, pos);
5730
5731                         // Get port
5732                         urlParts.port = "";
5733                         lastPos = pos;
5734                         if (url_str.charAt(pos) == ':') {
5735                                 pos = url_str.indexOf('/', lastPos);
5736                                 urlParts.port = url_str.substring(lastPos+1, pos);
5737                         }
5738
5739                         // Get path
5740                         lastPos = pos;
5741                         pos = url_str.indexOf('?', lastPos);
5742
5743                         if (pos == -1)
5744                                 pos = url_str.indexOf('#', lastPos);
5745
5746                         if (pos == -1)
5747                                 pos = url_str.length;
5748
5749                         urlParts.path = url_str.substring(lastPos, pos);
5750
5751                         // Get query
5752                         lastPos = pos;
5753                         if (url_str.charAt(pos) == '?') {
5754                                 pos = url_str.indexOf('#');
5755                                 pos = (pos == -1) ? url_str.length : pos;
5756                                 urlParts.query = url_str.substring(lastPos+1, pos);
5757                         }
5758
5759                         // Get anchor
5760                         lastPos = pos;
5761                         if (url_str.charAt(pos) == '#') {
5762                                 pos = url_str.length;
5763                                 urlParts.anchor = url_str.substring(lastPos+1, pos);
5764                         }
5765                 }
5766
5767                 return urlParts;
5768         },
5769
5770         serializeURL : function(up) {
5771                 var o = "";
5772
5773                 if (up.protocol)
5774                         o += up.protocol + "://";
5775
5776                 if (up.host)
5777                         o += up.host;
5778
5779                 if (up.port)
5780                         o += ":" + up.port;
5781
5782                 if (up.path)
5783                         o += up.path;
5784
5785                 if (up.query)
5786                         o += "?" + up.query;
5787
5788                 if (up.anchor)
5789                         o += "#" + up.anchor;
5790
5791                 return o;
5792         },
5793
5794         convertAbsoluteURLToRelativeURL : function(base_url, url_to_relative) {
5795                 var baseURL = this.parseURL(base_url), targetURL = this.parseURL(url_to_relative);
5796                 var i, strTok1, strTok2, breakPoint = 0, outPath = "", forceSlash = false;
5797                 var fileName, pos;
5798
5799                 if (targetURL.path == '')
5800                         targetURL.path = "/";
5801                 else
5802                         forceSlash = true;
5803
5804                 // Crop away last path part
5805                 base_url = baseURL.path.substring(0, baseURL.path.lastIndexOf('/'));
5806                 strTok1 = base_url.split('/');
5807                 strTok2 = targetURL.path.split('/');
5808
5809                 if (strTok1.length >= strTok2.length) {
5810                         for (i=0; i<strTok1.length; i++) {
5811                                 if (i >= strTok2.length || strTok1[i] != strTok2[i]) {
5812                                         breakPoint = i + 1;
5813                                         break;
5814                                 }
5815                         }
5816                 }
5817
5818                 if (strTok1.length < strTok2.length) {
5819                         for (i=0; i<strTok2.length; i++) {
5820                                 if (i >= strTok1.length || strTok1[i] != strTok2[i]) {
5821                                         breakPoint = i + 1;
5822                                         break;
5823                                 }
5824                         }
5825                 }
5826
5827                 if (breakPoint == 1)
5828                         return targetURL.path;
5829
5830                 for (i=0; i<(strTok1.length-(breakPoint-1)); i++)
5831                         outPath += "../";
5832
5833                 for (i=breakPoint-1; i<strTok2.length; i++) {
5834                         if (i != (breakPoint-1))
5835                                 outPath += "/" + strTok2[i];
5836                         else
5837                                 outPath += strTok2[i];
5838                 }
5839
5840                 targetURL.protocol = null;
5841                 targetURL.host = null;
5842                 targetURL.port = null;
5843                 targetURL.path = outPath == '' && forceSlash ? "/" : outPath;
5844
5845                 // Remove document prefix from local anchors
5846                 fileName = baseURL.path;
5847
5848                 if ((pos = fileName.lastIndexOf('/')) != -1)
5849                         fileName = fileName.substring(pos + 1);
5850
5851                 // Is local anchor
5852                 if (fileName == targetURL.path && targetURL.anchor !== '')
5853                         targetURL.path = "";
5854
5855                 // If empty and not local anchor force filename or slash
5856                 if (targetURL.path == '' && !targetURL.anchor)
5857                         targetURL.path = fileName !== '' ? fileName : "/";
5858
5859                 return this.serializeURL(targetURL);
5860         },
5861
5862         convertRelativeToAbsoluteURL : function(base_url, relative_url) {
5863                 var baseURL = this.parseURL(base_url), baseURLParts, relURLParts, newRelURLParts, numBack, relURL = this.parseURL(relative_url), i;
5864                 var len, absPath, start, end, newBaseURLParts;
5865
5866                 if (relative_url == '' || relative_url.indexOf('://') != -1 || /^(mailto:|javascript:|#|\/)/.test(relative_url))
5867                         return relative_url;
5868
5869                 // Split parts
5870                 baseURLParts = baseURL.path.split('/');
5871                 relURLParts = relURL.path.split('/');
5872
5873                 // Remove empty chunks
5874                 newBaseURLParts = [];
5875                 for (i=baseURLParts.length-1; i>=0; i--) {
5876                         if (baseURLParts[i].length == 0)
5877                                 continue;
5878
5879                         newBaseURLParts[newBaseURLParts.length] = baseURLParts[i];
5880                 }
5881                 baseURLParts = newBaseURLParts.reverse();
5882
5883                 // Merge relURLParts chunks
5884                 newRelURLParts = [];
5885                 numBack = 0;
5886                 for (i=relURLParts.length-1; i>=0; i--) {
5887                         if (relURLParts[i].length == 0 || relURLParts[i] == ".")
5888                                 continue;
5889
5890                         if (relURLParts[i] == '..') {
5891                                 numBack++;
5892                                 continue;
5893                         }
5894
5895                         if (numBack > 0) {
5896                                 numBack--;
5897                                 continue;
5898                         }
5899
5900                         newRelURLParts[newRelURLParts.length] = relURLParts[i];
5901                 }
5902
5903                 relURLParts = newRelURLParts.reverse();
5904
5905                 // Remove end from absolute path
5906                 len = baseURLParts.length-numBack;
5907                 absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/');
5908                 start = "";
5909                 end = "";
5910
5911                 // Build output URL
5912                 relURL.protocol = baseURL.protocol;
5913                 relURL.host = baseURL.host;
5914                 relURL.port = baseURL.port;
5915
5916                 // Re-add trailing slash if it's removed
5917                 if (relURL.path.charAt(relURL.path.length-1) == "/")
5918                         absPath += "/";
5919
5920                 relURL.path = absPath;
5921
5922                 return this.serializeURL(relURL);
5923         },
5924
5925         convertURL : function(url, node, on_save) {
5926                 var dl = document.location, start, portPart, urlParts, baseUrlParts, tmpUrlParts, curl;
5927                 var prot = dl.protocol, host = dl.hostname, port = dl.port;
5928
5929                 // Pass through file protocol
5930                 if (prot == "file:")
5931                         return url;
5932
5933                 // Something is wrong, remove weirdness
5934                 url = tinyMCE.regexpReplace(url, '(http|https):///', '/');
5935
5936                 // Mailto link or anchor (Pass through)
5937                 if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || /^[ \t\r\n\+]*[#\?]/.test(url))
5938                         return url;
5939
5940                 // Fix relative/Mozilla
5941                 if (!tinyMCE.isIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/')
5942                         return tinyMCE.settings.base_href + url;
5943
5944                 // Handle relative URLs
5945                 if (on_save && tinyMCE.getParam('relative_urls')) {
5946                         curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url);
5947                         if (curl.charAt(0) == '/')
5948                                 curl = tinyMCE.settings.document_base_prefix + curl;
5949
5950                         urlParts = tinyMCE.parseURL(curl);
5951                         tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings.document_base_url);
5952
5953                         // Force relative
5954                         if (urlParts.host == tmpUrlParts.host && (urlParts.port == tmpUrlParts.port))
5955                                 return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings.document_base_url, curl);
5956                 }
5957
5958                 // Handle absolute URLs
5959                 if (!tinyMCE.getParam('relative_urls')) {
5960                         urlParts = tinyMCE.parseURL(url);
5961                         baseUrlParts = tinyMCE.parseURL(tinyMCE.settings.base_href);
5962
5963                         // Force absolute URLs from relative URLs
5964                         url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url);
5965
5966                         // If anchor and path is the same page
5967                         if (urlParts.anchor && urlParts.path == baseUrlParts.path)
5968                                 return "#" + urlParts.anchor;
5969                 }
5970
5971                 // Remove current domain
5972                 if (tinyMCE.getParam('remove_script_host')) {
5973                         start = "";
5974                         portPart = "";
5975
5976                         if (port !== '')
5977                                 portPart = ":" + port;
5978
5979                         start = prot + "//" + host + portPart + "/";
5980
5981                         if (url.indexOf(start) == 0)
5982                                 url = url.substring(start.length-1);
5983                 }
5984
5985                 return url;
5986         },
5987
5988         convertAllRelativeURLs : function(body) {
5989                 var i, elms, src, href, mhref, msrc;
5990
5991                 // Convert all image URL:s to absolute URL
5992                 elms = body.getElementsByTagName("img");
5993                 for (i=0; i<elms.length; i++) {
5994                         src = tinyMCE.getAttrib(elms[i], 'src');
5995
5996                         msrc = tinyMCE.getAttrib(elms[i], 'mce_src');
5997                         if (msrc !== '')
5998                                 src = msrc;
5999
6000                         if (src !== '') {
6001                                 src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, src);
6002                                 elms[i].setAttribute("src", src);
6003                         }
6004                 }
6005
6006                 // Convert all link URL:s to absolute URL
6007                 elms = body.getElementsByTagName("a");
6008                 for (i=0; i<elms.length; i++) {
6009                         href = tinyMCE.getAttrib(elms[i], 'href');
6010
6011                         mhref = tinyMCE.getAttrib(elms[i], 'mce_href');
6012                         if (mhref !== '')
6013                                 href = mhref;
6014
6015                         if (href && href !== '') {
6016                                 href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, href);
6017                                 elms[i].setAttribute("href", href);
6018                         }
6019                 }
6020         }
6021
6022         });
6023
6024 /* file:jscripts/tiny_mce/classes/TinyMCE_Array.class.js */
6025
6026 tinyMCE.add(TinyMCE_Engine, {
6027         clearArray : function(a) {
6028                 var n;
6029
6030                 for (n in a)
6031                         a[n] = null;
6032
6033                 return a;
6034         },
6035
6036         explode : function(d, s) {
6037                 var ar = s.split(d), oar = [], i;
6038
6039                 for (i = 0; i<ar.length; i++) {
6040                         if (ar[i] !== '')
6041                                 oar[oar.length] = ar[i];
6042                 }
6043
6044                 return oar;
6045         }
6046 });
6047
6048 /* file:jscripts/tiny_mce/classes/TinyMCE_Event.class.js */
6049
6050 tinyMCE.add(TinyMCE_Engine, {
6051         _setEventsEnabled : function(node, state) {
6052                 var evs, x, y, elms, i, event;
6053                 var events = ['onfocus','onblur','onclick','ondblclick',
6054                                         'onmousedown','onmouseup','onmouseover','onmousemove',
6055                                         'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup'];
6056
6057                 evs = tinyMCE.settings.event_elements.split(',');
6058                 for (y=0; y<evs.length; y++){
6059                         elms = node.getElementsByTagName(evs[y]);
6060                         for (i=0; i<elms.length; i++) {
6061                                 event = "";
6062
6063                                 for (x=0; x<events.length; x++) {
6064                                         if ((event = tinyMCE.getAttrib(elms[i], events[x])) !== '') {
6065                                                 event = tinyMCE.cleanupEventStr("" + event);
6066
6067                                                 if (!state)
6068                                                         event = "return true;" + event;
6069                                                 else
6070                                                         event = event.replace(/^return true;/gi, '');
6071
6072                                                 elms[i].removeAttribute(events[x]);
6073                                                 elms[i].setAttribute(events[x], event);
6074                                         }
6075                                 }
6076                         }
6077                 }
6078         },
6079
6080         _eventPatch : function(editor_id) {
6081                 var n, inst, win, e;
6082
6083                 // Remove odd, error
6084                 if (typeof(tinyMCE) == "undefined")
6085                         return true;
6086
6087                 try {
6088                         // Try selected instance first
6089                         if (tinyMCE.selectedInstance) {
6090                                 win = tinyMCE.selectedInstance.getWin();
6091
6092                                 if (win && win.event) {
6093                                         e = win.event;
6094
6095                                         if (!e.target)
6096                                                 e.target = e.srcElement;
6097
6098                                         TinyMCE_Engine.prototype.handleEvent(e);
6099                                         return;
6100                                 }
6101                         }
6102
6103                         // Search for it
6104                         for (n in tinyMCE.instances) {
6105                                 inst = tinyMCE.instances[n];
6106
6107                                 if (!tinyMCE.isInstance(inst))
6108                                         continue;
6109
6110                                 inst.select();
6111                                 win = inst.getWin();
6112
6113                                 if (win && win.event) {
6114                                         e = win.event;
6115
6116                                         if (!e.target)
6117                                                 e.target = e.srcElement;
6118
6119                                         TinyMCE_Engine.prototype.handleEvent(e);
6120                                         return;
6121                                 }
6122                         }
6123                 } catch (ex) {
6124                         // Ignore error if iframe is pointing to external URL
6125                 }
6126         },
6127
6128         findEvent : function(e) {
6129                 var n, inst;
6130
6131                 if (e)
6132                         return e;
6133
6134                 for (n in tinyMCE.instances) {
6135                         inst = tinyMCE.instances[n];
6136
6137                         if (tinyMCE.isInstance(inst) && inst.getWin().event)
6138                                 return inst.getWin().event;
6139                 }
6140
6141                 return null;
6142         },
6143
6144         unloadHandler : function() {
6145                 tinyMCE.triggerSave(true, true);
6146         },
6147
6148         addEventHandlers : function(inst) {
6149                 this.setEventHandlers(inst, 1);
6150         },
6151
6152         setEventHandlers : function(inst, s) {
6153                 var doc = inst.getDoc(), ie, ot, i, f = s ? tinyMCE.addEvent : tinyMCE.removeEvent;
6154
6155                 ie = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'controlselect', 'dblclick'];
6156                 ot = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'focus', 'blur', 'dragdrop'];
6157
6158                 inst.switchSettings();
6159
6160                 if (tinyMCE.isIE) {
6161                         for (i=0; i<ie.length; i++)
6162                                 f(doc, ie[i], TinyMCE_Engine.prototype._eventPatch);
6163                 } else {
6164                         for (i=0; i<ot.length; i++)
6165                                 f(doc, ot[i], tinyMCE.handleEvent);
6166
6167                         // Force designmode
6168                         try {
6169                                 doc.designMode = "On";
6170                         } catch (e) {
6171                                 // Ignore
6172                         }
6173                 }
6174         },
6175
6176         onMouseMove : function() {
6177                 var inst, lh;
6178
6179                 // Fix for IE7 bug where it's not restoring hover on anchors correctly
6180                 if (tinyMCE.lastHover) {
6181                         lh = tinyMCE.lastHover;
6182
6183                         // Call out on menus and refresh class on normal buttons
6184                         if (lh.className.indexOf('mceMenu') != -1)
6185                                 tinyMCE._menuButtonEvent('out', lh);
6186                         else
6187                                 lh.className = lh.className;
6188
6189                         tinyMCE.lastHover = null;
6190                 }
6191
6192                 if (!tinyMCE.hasMouseMoved) {
6193                         inst = tinyMCE.selectedInstance;
6194
6195                         // Workaround for bug #1437457 (Odd MSIE bug)
6196                         if (inst.isFocused) {
6197                                 inst.undoBookmark = inst.selection.getBookmark();
6198                                 tinyMCE.hasMouseMoved = true;
6199                         }
6200                 }
6201
6202         //      tinyMCE.cancelEvent(inst.getWin().event);
6203         //      return false;
6204         },
6205
6206         cancelEvent : function(e) {
6207                 if (!e)
6208                         return false;
6209
6210                 if (tinyMCE.isIE) {
6211                         e.returnValue = false;
6212                         e.cancelBubble = true;
6213                 } else {
6214                         e.preventDefault();
6215                         e.stopPropagation && e.stopPropagation();
6216                 }
6217
6218                 return false;
6219         },
6220
6221         addEvent : function(o, n, h) {
6222                 // Add cleanup for all non unload events
6223                 if (n != 'unload') {
6224                         function clean() {
6225                                 var ex;
6226
6227                                 try {
6228                                         tinyMCE.removeEvent(o, n, h);
6229                                         tinyMCE.removeEvent(window, 'unload', clean);
6230                                         o = n = h = null;
6231                                 } catch (ex) {
6232                                         // IE may produce access denied exception on unload
6233                                 }
6234                         }
6235
6236                         // Add memory cleaner
6237                         tinyMCE.addEvent(window, 'unload', clean);
6238                 }
6239
6240                 if (o.attachEvent)
6241                         o.attachEvent("on" + n, h);
6242                 else
6243                         o.addEventListener(n, h, false);
6244         },
6245
6246         removeEvent : function(o, n, h) {
6247                 if (o.detachEvent)
6248                         o.detachEvent("on" + n, h);
6249                 else
6250                         o.removeEventListener(n, h, false);
6251         },
6252
6253         addSelectAccessibility : function(e, s, w) {
6254                 // Add event handlers 
6255                 if (!s._isAccessible) {
6256                         s.onkeydown = tinyMCE.accessibleEventHandler;
6257                         s.onblur = tinyMCE.accessibleEventHandler;
6258                         s._isAccessible = true;
6259                         s._win = w;
6260                 }
6261
6262                 return false;
6263         },
6264
6265         accessibleEventHandler : function(e) {
6266                 var elm, win = this._win;
6267
6268                 e = tinyMCE.isIE ? win.event : e;
6269                 elm = tinyMCE.isIE ? e.srcElement : e.target;
6270
6271                 // Unpiggyback onchange on blur
6272                 if (e.type == "blur") {
6273                         if (elm.oldonchange) {
6274                                 elm.onchange = elm.oldonchange;
6275                                 elm.oldonchange = null;
6276                         }
6277
6278                         return true;
6279                 }
6280
6281                 // Piggyback onchange
6282                 if (elm.nodeName == "SELECT" && !elm.oldonchange) {
6283                         elm.oldonchange = elm.onchange;
6284                         elm.onchange = null;
6285                 }
6286
6287                 // Execute onchange and remove piggyback
6288                 if (e.keyCode == 13 || e.keyCode == 32) {
6289                         elm.onchange = elm.oldonchange;
6290                         elm.onchange();
6291                         elm.oldonchange = null;
6292
6293                         tinyMCE.cancelEvent(e);
6294                         return false;
6295                 }
6296
6297                 return true;
6298         },
6299
6300         _resetIframeHeight : function() {
6301                 var ife;
6302
6303                 if (tinyMCE.isRealIE) {
6304                         ife = tinyMCE.selectedInstance.iframeElement;
6305
6306         /*              if (ife._oldWidth) {
6307                                 ife.style.width = ife._oldWidth;
6308                                 ife.width = ife._oldWidth;
6309                         }*/
6310
6311                         if (ife._oldHeight) {
6312                                 ife.style.height = ife._oldHeight;
6313                                 ife.height = ife._oldHeight;
6314                         }
6315                 }
6316         }
6317
6318         });
6319
6320 /* file:jscripts/tiny_mce/classes/TinyMCE_Selection.class.js */
6321
6322 function TinyMCE_Selection(inst) {
6323         this.instance = inst;
6324 };
6325
6326 TinyMCE_Selection.prototype = {
6327         getSelectedHTML : function() {
6328                 var inst = this.instance, e, r = this.getRng(), h;
6329
6330                 if (!r)
6331                         return null;
6332
6333                 e = document.createElement("body");
6334
6335                 if (r.cloneContents)
6336                         e.appendChild(document.importNode(r.cloneContents(), true));
6337                 else if (typeof(r.item) != 'undefined' || typeof(r.htmlText) != 'undefined')
6338                         e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText;
6339                 else
6340                         e.innerHTML = r.toString(); // Failed, use text for now
6341
6342                 h = tinyMCE._cleanupHTML(inst, inst.contentDocument, inst.settings, e, e, false, true, false);
6343
6344                 // When editing always use fonts internaly
6345                 //if (tinyMCE.getParam("convert_fonts_to_spans"))
6346                 //      tinyMCE.convertSpansToFonts(inst.getDoc());
6347
6348                 return h;
6349         },
6350
6351         getSelectedText : function() {
6352                 var inst = this.instance, d, r, s, t;
6353
6354                 if (tinyMCE.isIE) {
6355                         d = inst.getDoc();
6356
6357                         if (d.selection.type == "Text") {
6358                                 r = d.selection.createRange();
6359                                 t = r.text;
6360                         } else
6361                                 t = '';
6362                 } else {
6363                         s = this.getSel();
6364
6365                         if (s && s.toString)
6366                                 t = s.toString();
6367                         else
6368                                 t = '';
6369                 }
6370
6371                 return t;
6372         },
6373
6374         getBookmark : function(simple) {
6375                 var inst = this.instance, rng = this.getRng(), doc = inst.getDoc(), b = inst.getBody();
6376                 var trng, sx, sy, xx = -999999999, vp = inst.getViewPort();
6377                 var sp, le, s, e, nl, i, si, ei, w;
6378
6379                 sx = vp.left;
6380                 sy = vp.top;
6381
6382                 if (simple)
6383                         return {rng : rng, scrollX : sx, scrollY : sy};
6384
6385                 if (tinyMCE.isRealIE) {
6386                         if (rng.item) {
6387                                 e = rng.item(0);
6388
6389                                 nl = b.getElementsByTagName(e.nodeName);
6390                                 for (i=0; i<nl.length; i++) {
6391                                         if (e == nl[i]) {
6392                                                 sp = i;
6393                                                 break;
6394                                         }
6395                                 }
6396
6397                                 return {
6398                                         tag : e.nodeName,
6399                                         index : sp,
6400                                         scrollX : sx,
6401                                         scrollY : sy
6402                                 };
6403                         } else {
6404                                 trng = doc.body.createTextRange();
6405                                 trng.moveToElementText(inst.getBody());
6406                                 trng.collapse(true);
6407                                 bp = Math.abs(trng.move('character', xx));
6408
6409                                 trng = rng.duplicate();
6410                                 trng.collapse(true);
6411                                 sp = Math.abs(trng.move('character', xx));
6412
6413                                 trng = rng.duplicate();
6414                                 trng.collapse(false);
6415                                 le = Math.abs(trng.move('character', xx)) - sp;
6416
6417                                 return {
6418                                         start : sp - bp,
6419                                         length : le,
6420                                         scrollX : sx,
6421                                         scrollY : sy
6422                                 };
6423                         }
6424                 } else {
6425                         s = this.getSel();
6426                         e = this.getFocusElement();
6427
6428                         if (!s)
6429                                 return null;
6430
6431                         if (e && e.nodeName == 'IMG') {
6432                                 /*nl = b.getElementsByTagName('IMG');
6433                                 for (i=0; i<nl.length; i++) {
6434                                         if (e == nl[i]) {
6435                                                 sp = i;
6436                                                 break;
6437                                         }
6438                                 }*/
6439
6440                                 return {
6441                                         start : -1,
6442                                         end : -1,
6443                                         index : sp,
6444                                         scrollX : sx,
6445                                         scrollY : sy
6446                                 };
6447                         }
6448
6449                         // Caret or selection
6450                         if (s.anchorNode == s.focusNode && s.anchorOffset == s.focusOffset) {
6451                                 e = this._getPosText(b, s.anchorNode, s.focusNode);
6452
6453                                 if (!e)
6454                                         return {scrollX : sx, scrollY : sy};
6455
6456                                 return {
6457                                         start : e.start + s.anchorOffset,
6458                                         end : e.end + s.focusOffset,
6459                                         scrollX : sx,
6460                                         scrollY : sy
6461                                 };
6462                         } else {
6463                                 e = this._getPosText(b, rng.startContainer, rng.endContainer);
6464
6465                                 if (!e)
6466                                         return {scrollX : sx, scrollY : sy};
6467
6468                                 return {
6469                                         start : e.start + rng.startOffset,
6470                                         end : e.end + rng.endOffset,
6471                                         scrollX : sx,
6472                                         scrollY : sy
6473                                 };
6474                         }
6475                 }
6476
6477                 return null;
6478         },
6479
6480         moveToBookmark : function(bookmark) {
6481                 var inst = this.instance, rng, nl, i, ex, b = inst.getBody(), sd;
6482                 var doc = inst.getDoc(), win = inst.getWin(), sel = this.getSel();
6483
6484                 if (!bookmark)
6485                         return false;
6486
6487                 if (tinyMCE.isSafari && bookmark.rng) {
6488                         sel.setBaseAndExtent(bookmark.rng.startContainer, bookmark.rng.startOffset, bookmark.rng.endContainer, bookmark.rng.endOffset);
6489                         return true;
6490                 }
6491
6492                 if (tinyMCE.isRealIE) {
6493                         if (bookmark.rng) {
6494                                 try {
6495                                         bookmark.rng.select();
6496                                 } catch (ex) {
6497                                         // Ignore
6498                                 }
6499
6500                                 return true;
6501                         }
6502
6503                         win.focus();
6504
6505                         if (bookmark.tag) {
6506                                 rng = b.createControlRange();
6507
6508                                 nl = b.getElementsByTagName(bookmark.tag);
6509
6510                                 if (nl.length > bookmark.index) {
6511                                         try {
6512                                                 rng.addElement(nl[bookmark.index]);
6513                                         } catch (ex) {
6514                                                 // Might be thrown if the node no longer exists
6515                                         }
6516                                 }
6517                         } else {
6518                                 // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs
6519                                 try {
6520                                         // Incorrect bookmark
6521                                         if (bookmark.start < 0)
6522                                                 return true;
6523
6524                                         rng = inst.getSel().createRange();
6525                                         rng.moveToElementText(inst.getBody());
6526                                         rng.collapse(true);
6527                                         rng.moveStart('character', bookmark.start);
6528                                         rng.moveEnd('character', bookmark.length);
6529                                 } catch (ex) {
6530                                         return true;
6531                                 }
6532                         }
6533
6534                         rng.select();
6535
6536                         win.scrollTo(bookmark.scrollX, bookmark.scrollY);
6537                         return true;
6538                 }
6539
6540                 if (tinyMCE.isGecko || tinyMCE.isOpera) {
6541                         if (!sel)
6542                                 return false;
6543
6544                         if (bookmark.rng) {
6545                                 sel.removeAllRanges();
6546                                 sel.addRange(bookmark.rng);
6547                         }
6548
6549                         if (bookmark.start != -1 && bookmark.end != -1) {
6550                                 try {
6551                                         sd = this._getTextPos(b, bookmark.start, bookmark.end);
6552                                         rng = doc.createRange();
6553                                         rng.setStart(sd.startNode, sd.startOffset);
6554                                         rng.setEnd(sd.endNode, sd.endOffset);
6555                                         sel.removeAllRanges();
6556                                         sel.addRange(rng);
6557
6558                                         if (!tinyMCE.isOpera)
6559                                                 win.focus();
6560                                 } catch (ex) {
6561                                         // Ignore
6562                                 }
6563                         }
6564
6565                         /*
6566                         if (typeof(bookmark.index) != 'undefined') {
6567                                 tinyMCE.selectElements(b, 'IMG', function (n) {
6568                                         if (bookmark.index-- == 0) {
6569                                                 // Select image in Gecko here
6570                                         }
6571
6572                                         return false;
6573                                 });
6574                         }
6575                         */
6576
6577                         win.scrollTo(bookmark.scrollX, bookmark.scrollY);
6578                         return true;
6579                 }
6580
6581                 return false;
6582         },
6583
6584         _getPosText : function(r, sn, en) {
6585                 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
6586
6587                 while ((n = w.nextNode()) != null) {
6588                         if (n == sn)
6589                                 d.start = p;
6590
6591                         if (n == en) {
6592                                 d.end = p;
6593                                 return d;
6594                         }
6595
6596                         p += n.nodeValue ? n.nodeValue.length : 0;
6597                 }
6598
6599                 return null;
6600         },
6601
6602         _getTextPos : function(r, sp, ep) {
6603                 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
6604
6605                 while ((n = w.nextNode()) != null) {
6606                         p += n.nodeValue ? n.nodeValue.length : 0;
6607
6608                         if (p >= sp && !d.startNode) {
6609                                 d.startNode = n;
6610                                 d.startOffset = sp - (p - n.nodeValue.length);
6611                         }
6612
6613                         if (p >= ep) {
6614                                 d.endNode = n;
6615                                 d.endOffset = ep - (p - n.nodeValue.length);
6616
6617                                 return d;
6618                         }
6619                 }
6620
6621                 return null;
6622         },
6623
6624         selectNode : function(node, collapse, select_text_node, to_start) {
6625                 var inst = this.instance, sel, rng, nodes;
6626
6627                 if (!node)
6628                         return;
6629
6630                 if (typeof(collapse) == "undefined")
6631                         collapse = true;
6632
6633                 if (typeof(select_text_node) == "undefined")
6634                         select_text_node = false;
6635
6636                 if (typeof(to_start) == "undefined")
6637                         to_start = true;
6638
6639                 if (inst.settings.auto_resize)
6640                         inst.resizeToContent();
6641
6642                 if (tinyMCE.isRealIE) {
6643                         rng = inst.getDoc().body.createTextRange();
6644
6645                         try {
6646                                 rng.moveToElementText(node);
6647
6648                                 if (collapse)
6649                                         rng.collapse(to_start);
6650
6651                                 rng.select();
6652                         } catch (e) {
6653                                 // Throws illigal agrument in MSIE some times
6654                         }
6655                 } else {
6656                         sel = this.getSel();
6657
6658                         if (!sel)
6659                                 return;
6660
6661                         if (tinyMCE.isSafari) {
6662                                 sel.setBaseAndExtent(node, 0, node, node.innerText.length);
6663
6664                                 if (collapse) {
6665                                         if (to_start)
6666                                                 sel.collapseToStart();
6667                                         else
6668                                                 sel.collapseToEnd();
6669                                 }
6670
6671                                 this.scrollToNode(node);
6672
6673                                 return;
6674                         }
6675
6676                         rng = inst.getDoc().createRange();
6677
6678                         if (select_text_node) {
6679                                 // Find first textnode in tree
6680                                 nodes = tinyMCE.getNodeTree(node, [], 3);
6681                                 if (nodes.length > 0)
6682                                         rng.selectNodeContents(nodes[0]);
6683                                 else
6684                                         rng.selectNodeContents(node);
6685                         } else
6686                                 rng.selectNode(node);
6687
6688                         if (collapse) {
6689                                 // Special treatment of textnode collapse
6690                                 if (!to_start && node.nodeType == 3) {
6691                                         rng.setStart(node, node.nodeValue.length);
6692                                         rng.setEnd(node, node.nodeValue.length);
6693                                 } else
6694                                         rng.collapse(to_start);
6695                         }
6696
6697                         sel.removeAllRanges();
6698                         sel.addRange(rng);
6699                 }
6700
6701                 this.scrollToNode(node);
6702
6703                 // Set selected element
6704                 tinyMCE.selectedElement = null;
6705                 if (node.nodeType == 1)
6706                         tinyMCE.selectedElement = node;
6707         },
6708
6709         scrollToNode : function(node) {
6710                 var inst = this.instance, w = inst.getWin(), vp = inst.getViewPort(), pos = tinyMCE.getAbsPosition(node), cvp, p, cwin;
6711
6712                 // Only scroll if out of visible area
6713                 if (pos.absLeft < vp.left || pos.absLeft > vp.left + vp.width || pos.absTop < vp.top || pos.absTop > vp.top + (vp.height-25))
6714                         w.scrollTo(pos.absLeft, pos.absTop - vp.height + 25);
6715
6716                 // Scroll container window
6717                 if (inst.settings.auto_resize) {
6718                         cwin = inst.getContainerWin();
6719                         cvp = tinyMCE.getViewPort(cwin);
6720                         p = this.getAbsPosition(node);
6721
6722                         if (p.absLeft < cvp.left || p.absLeft > cvp.left + cvp.width || p.absTop < cvp.top || p.absTop > cvp.top + cvp.height)
6723                                 cwin.scrollTo(p.absLeft, p.absTop - cvp.height + 25);
6724                 }
6725         },
6726
6727         getAbsPosition : function(n) {
6728                 var pos = tinyMCE.getAbsPosition(n), ipos = tinyMCE.getAbsPosition(this.instance.iframeElement);
6729
6730                 return {
6731                         absLeft : ipos.absLeft + pos.absLeft,
6732                         absTop : ipos.absTop + pos.absTop
6733                 };
6734         },
6735
6736         getSel : function() {
6737                 var inst = this.instance;
6738
6739                 if (tinyMCE.isRealIE)
6740                         return inst.getDoc().selection;
6741
6742                 return inst.contentWindow.getSelection();
6743         },
6744
6745         getRng : function() {
6746                 var s = this.getSel();
6747
6748                 if (s == null)
6749                         return null;
6750
6751                 if (tinyMCE.isRealIE)
6752                         return s.createRange();
6753
6754                 if (tinyMCE.isSafari && !s.getRangeAt)
6755                         return '' + window.getSelection();
6756
6757                 if (s.rangeCount > 0)
6758                         return s.getRangeAt(0);
6759
6760                 return null;
6761         },
6762
6763         isCollapsed : function() {
6764                 var r = this.getRng();
6765
6766                 if (r.item)
6767                         return false;
6768
6769                 return r.boundingWidth == 0 || this.getSel().isCollapsed;
6770         },
6771
6772         collapse : function(b) {
6773                 var r = this.getRng(), s = this.getSel();
6774
6775                 if (r.select) {
6776                         r.collapse(b);
6777                         r.select();
6778                 } else {
6779                         if (b)
6780                                 s.collapseToStart();
6781                         else
6782                                 s.collapseToEnd();
6783                 }
6784         },
6785
6786         getFocusElement : function() {
6787                 var inst = this.instance, doc, rng, sel, elm;
6788
6789                 if (tinyMCE.isRealIE) {
6790                         doc = inst.getDoc();
6791                         rng = doc.selection.createRange();
6792
6793         //              if (rng.collapse)
6794         //                      rng.collapse(true);
6795
6796                         elm = rng.item ? rng.item(0) : rng.parentElement();
6797                 } else {
6798                         if (!tinyMCE.isSafari && inst.isHidden())
6799                                 return inst.getBody();
6800
6801                         sel = this.getSel();
6802                         rng = this.getRng();
6803
6804                         if (!sel || !rng)
6805                                 return null;
6806
6807                         elm = rng.commonAncestorContainer;
6808                         //elm = (sel && sel.anchorNode) ? sel.anchorNode : null;
6809
6810                         // Handle selection a image or other control like element such as anchors
6811                         if (!rng.collapsed) {
6812                                 // Is selection small
6813                                 if (rng.startContainer == rng.endContainer) {
6814                                         if (rng.startOffset - rng.endOffset < 2) {
6815                                                 if (rng.startContainer.hasChildNodes())
6816                                                         elm = rng.startContainer.childNodes[rng.startOffset];
6817                                         }
6818                                 }
6819                         }
6820
6821                         // Get the element parent of the node
6822                         elm = tinyMCE.getParentElement(elm);
6823
6824                         //if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img")
6825                         //      elm = tinyMCE.selectedElement;
6826                 }
6827
6828                 return elm;
6829         }
6830
6831         };
6832
6833 /* file:jscripts/tiny_mce/classes/TinyMCE_UndoRedo.class.js */
6834
6835 function TinyMCE_UndoRedo(inst) {
6836         this.instance = inst;
6837         this.undoLevels = [];
6838         this.undoIndex = 0;
6839         this.typingUndoIndex = -1;
6840         this.undoRedo = true;
6841 };
6842
6843 TinyMCE_UndoRedo.prototype = {
6844         add : function(l) {
6845                 var b, customUndoLevels, newHTML, inst = this.instance, i, ul, ur;
6846
6847                 if (l) {
6848                         this.undoLevels[this.undoLevels.length] = l;
6849                         return true;
6850                 }
6851
6852                 if (this.typingUndoIndex != -1) {
6853                         this.undoIndex = this.typingUndoIndex;
6854
6855                         if (tinyMCE.typingUndoIndex != -1)
6856                                 tinyMCE.undoIndex = tinyMCE.typingUndoIndex;
6857                 }
6858
6859                 newHTML = tinyMCE.trim(inst.getBody().innerHTML);
6860                 if (this.undoLevels[this.undoIndex] && newHTML != this.undoLevels[this.undoIndex].content) {
6861                         //tinyMCE.debug(newHTML, this.undoLevels[this.undoIndex].content);
6862
6863                         // Is dirty again
6864                         inst.isNotDirty = false;
6865
6866                         tinyMCE.dispatchCallback(inst, 'onchange_callback', 'onChange', inst);
6867
6868                         // Time to compress
6869                         customUndoLevels = tinyMCE.settings.custom_undo_redo_levels;
6870                         if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) {
6871                                 for (i=0; i<this.undoLevels.length-1; i++)
6872                                         this.undoLevels[i] = this.undoLevels[i+1];
6873
6874                                 this.undoLevels.length--;
6875                                 this.undoIndex--;
6876
6877                                 // Todo: Implement global undo/redo logic here
6878                         }
6879
6880                         b = inst.undoBookmark;
6881
6882                         if (!b)
6883                                 b = inst.selection.getBookmark();
6884
6885                         this.undoIndex++;
6886                         this.undoLevels[this.undoIndex] = {
6887                                 content : newHTML,
6888                                 bookmark : b
6889                         };
6890
6891                         // Remove all above from global undo/redo
6892                         ul = tinyMCE.undoLevels;
6893                         for (i=tinyMCE.undoIndex + 1; i<ul.length; i++) {
6894                                 ur = ul[i].undoRedo;
6895
6896                                 if (ur.undoIndex == ur.undoLevels.length -1)
6897                                         ur.undoIndex--;
6898
6899                                 ur.undoLevels.length--;
6900                         }
6901
6902                         // Add global undo level
6903                         tinyMCE.undoLevels[tinyMCE.undoIndex++] = inst;
6904                         tinyMCE.undoLevels.length = tinyMCE.undoIndex;
6905
6906                         this.undoLevels.length = this.undoIndex + 1;
6907
6908                         return true;
6909                 }
6910
6911                 return false;
6912         },
6913
6914         undo : function() {
6915                 var inst = this.instance;
6916
6917                 // Do undo
6918                 if (this.undoIndex > 0) {
6919                         this.undoIndex--;
6920
6921                         tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
6922                         inst.repaint();
6923
6924                         if (inst.settings.custom_undo_redo_restore_selection)
6925                                 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
6926                 }
6927         },
6928
6929         redo : function() {
6930                 var inst = this.instance;
6931
6932                 tinyMCE.execCommand("mceEndTyping");
6933
6934                 if (this.undoIndex < (this.undoLevels.length-1)) {
6935                         this.undoIndex++;
6936
6937                         tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
6938                         inst.repaint();
6939
6940                         if (inst.settings.custom_undo_redo_restore_selection)
6941                                 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
6942                 }
6943
6944                 tinyMCE.triggerNodeChange();
6945         }
6946
6947         };
6948
6949 /* file:jscripts/tiny_mce/classes/TinyMCE_ForceParagraphs.class.js */
6950
6951 var TinyMCE_ForceParagraphs = {
6952         _insertPara : function(inst, e) {
6953                 var doc = inst.getDoc(), sel = inst.getSel(), body = inst.getBody(), win = inst.contentWindow, rng = sel.getRangeAt(0);
6954                 var rootElm = doc.documentElement, blockName = "P", startNode, endNode, startBlock, endBlock;
6955                 var rngBefore, rngAfter, direct, startNode, startOffset, endNode, endOffset, b = tinyMCE.isOpera ? inst.selection.getBookmark() : null;
6956                 var paraBefore, paraAfter, startChop, endChop, contents, i;
6957
6958                 function isEmpty(para) {
6959                         var nodes;
6960
6961                         function isEmptyHTML(html) {
6962                                 return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == '';
6963                         }
6964
6965                         // Check for images
6966                         if (para.getElementsByTagName("img").length > 0)
6967                                 return false;
6968
6969                         // Check for tables
6970                         if (para.getElementsByTagName("table").length > 0)
6971                                 return false;
6972
6973                         // Check for HRs
6974                         if (para.getElementsByTagName("hr").length > 0)
6975                                 return false;
6976
6977                         // Check all textnodes
6978                         nodes = tinyMCE.getNodeTree(para, [], 3);
6979                         for (i=0; i<nodes.length; i++) {
6980                                 if (!isEmptyHTML(nodes[i].nodeValue))
6981                                         return false;
6982                         }
6983
6984                         // No images, no tables, no hrs, no text content then it's empty
6985                         return true;
6986                 }
6987
6988         //      tinyMCE.debug(body.innerHTML);
6989
6990         //      debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString());
6991
6992                 // Setup before range
6993                 rngBefore = doc.createRange();
6994                 rngBefore.setStart(sel.anchorNode, sel.anchorOffset);
6995                 rngBefore.collapse(true);
6996
6997                 // Setup after range
6998                 rngAfter = doc.createRange();
6999                 rngAfter.setStart(sel.focusNode, sel.focusOffset);
7000                 rngAfter.collapse(true);
7001
7002                 // Setup start/end points
7003                 direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0;
7004                 startNode = direct ? sel.anchorNode : sel.focusNode;
7005                 startOffset = direct ? sel.anchorOffset : sel.focusOffset;
7006                 endNode = direct ? sel.focusNode : sel.anchorNode;
7007                 endOffset = direct ? sel.focusOffset : sel.anchorOffset;
7008
7009                 startNode = startNode.nodeName == "HTML" ? doc.body : startNode; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
7010                 startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode;
7011                 endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode;
7012
7013                 // Get block elements
7014                 startBlock = inst.getParentBlockElement(startNode);
7015                 endBlock = inst.getParentBlockElement(endNode);
7016
7017                 // If absolute force paragraph generation within
7018                 if (startBlock && (startBlock.nodeName == 'CAPTION' || /absolute|relative|static/gi.test(startBlock.style.position)))
7019                         startBlock = null;
7020
7021                 if (endBlock && (endBlock.nodeName == 'CAPTION' || /absolute|relative|static/gi.test(endBlock.style.position)))
7022                         endBlock = null;
7023
7024                 // Use current block name
7025                 if (startBlock != null) {
7026                         blockName = startBlock.nodeName;
7027
7028                         // Use P instead
7029                         if (/(TD|TABLE|TH|CAPTION)/.test(blockName) || (blockName == "DIV" && /left|right/gi.test(startBlock.style.cssFloat)))
7030                                 blockName = "P";
7031                 }
7032
7033                 // Within a list use normal behaviour
7034                 if (tinyMCE.getParentElement(startBlock, "OL,UL", null, body) != null)
7035                         return false;
7036
7037                 // Within a table create new paragraphs
7038                 if ((startBlock != null && startBlock.nodeName == "TABLE") || (endBlock != null && endBlock.nodeName == "TABLE"))
7039                         startBlock = endBlock = null;
7040
7041                 // Setup new paragraphs
7042                 paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName);
7043                 paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName);
7044
7045                 // Is header, then force paragraph under
7046                 if (/^(H[1-6])$/.test(blockName))
7047                         paraAfter = doc.createElement("p");
7048
7049                 // Setup chop nodes
7050                 startChop = startNode;
7051                 endChop = endNode;
7052
7053                 // Get startChop node
7054                 node = startChop;
7055                 do {
7056                         if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
7057                                 break;
7058
7059                         startChop = node;
7060                 } while ((node = node.previousSibling ? node.previousSibling : node.parentNode));
7061
7062                 // Get endChop node
7063                 node = endChop;
7064                 do {
7065                         if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
7066                                 break;
7067
7068                         endChop = node;
7069                 } while ((node = node.nextSibling ? node.nextSibling : node.parentNode));
7070
7071                 // Fix when only a image is within the TD
7072                 if (startChop.nodeName == "TD")
7073                         startChop = startChop.firstChild;
7074
7075                 if (endChop.nodeName == "TD")
7076                         endChop = endChop.lastChild;
7077
7078                 // If not in a block element
7079                 if (startBlock == null) {
7080                         // Delete selection
7081                         rng.deleteContents();
7082
7083                         if (!tinyMCE.isSafari)
7084                                 sel.removeAllRanges();
7085
7086                         if (startChop != rootElm && endChop != rootElm) {
7087                                 // Insert paragraph before
7088                                 rngBefore = rng.cloneRange();
7089
7090                                 if (startChop == body)
7091                                         rngBefore.setStart(startChop, 0);
7092                                 else
7093                                         rngBefore.setStartBefore(startChop);
7094
7095                                 paraBefore.appendChild(rngBefore.cloneContents());
7096
7097                                 // Insert paragraph after
7098                                 if (endChop.parentNode.nodeName == blockName)
7099                                         endChop = endChop.parentNode;
7100
7101                                 // If not after image
7102                                 //if (rng.startContainer.nodeName != "BODY" && rng.endContainer.nodeName != "BODY")
7103                                         rng.setEndAfter(endChop);
7104
7105                                 if (endChop.nodeName != "#text" && endChop.nodeName != "BODY")
7106                                         rngBefore.setEndAfter(endChop);
7107
7108                                 contents = rng.cloneContents();
7109                                 if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY"))
7110                                         paraAfter.innerHTML = contents.firstChild.innerHTML;
7111                                 else
7112                                         paraAfter.appendChild(contents);
7113
7114                                 // Check if it's a empty paragraph
7115                                 if (isEmpty(paraBefore))
7116                                         paraBefore.innerHTML = "&nbsp;";
7117
7118                                 // Check if it's a empty paragraph
7119                                 if (isEmpty(paraAfter))
7120                                         paraAfter.innerHTML = "&nbsp;";
7121
7122                                 // Delete old contents
7123                                 rng.deleteContents();
7124                                 rngAfter.deleteContents();
7125                                 rngBefore.deleteContents();
7126
7127                                 // Insert new paragraphs
7128                                 if (tinyMCE.isOpera) {
7129                                         paraBefore.normalize();
7130                                         rngBefore.insertNode(paraBefore);
7131                                         paraAfter.normalize();
7132                                         rngBefore.insertNode(paraAfter);
7133                                 } else {
7134                                         paraAfter.normalize();
7135                                         rngBefore.insertNode(paraAfter);
7136                                         paraBefore.normalize();
7137                                         rngBefore.insertNode(paraBefore);
7138                                 }
7139
7140                                 //tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML);
7141                         } else {
7142                                 body.innerHTML = "<" + blockName + ">&nbsp;</" + blockName + "><" + blockName + ">&nbsp;</" + blockName + ">";
7143                                 paraAfter = body.childNodes[1];
7144                         }
7145
7146                         inst.selection.moveToBookmark(b);
7147                         inst.selection.selectNode(paraAfter, true, true);
7148
7149                         return true;
7150                 }
7151
7152                 // Place first part within new paragraph
7153                 if (startChop.nodeName == blockName)
7154                         rngBefore.setStart(startChop, 0);
7155                 else
7156                         rngBefore.setStartBefore(startChop);
7157
7158                 rngBefore.setEnd(startNode, startOffset);
7159                 paraBefore.appendChild(rngBefore.cloneContents());
7160
7161                 // Place secound part within new paragraph
7162                 rngAfter.setEndAfter(endChop);
7163                 rngAfter.setStart(endNode, endOffset);
7164                 contents = rngAfter.cloneContents();
7165
7166                 if (contents.firstChild && contents.firstChild.nodeName == blockName) {
7167         /*              var nodes = contents.firstChild.childNodes;
7168                         for (i=0; i<nodes.length; i++) {
7169                                 //tinyMCE.debug(nodes[i].nodeName);
7170                                 if (nodes[i].nodeName != "BODY")
7171                                         paraAfter.appendChild(nodes[i]);
7172                         }
7173         */
7174                         paraAfter.innerHTML = contents.firstChild.innerHTML;
7175                 } else
7176                         paraAfter.appendChild(contents);
7177
7178                 // Check if it's a empty paragraph
7179                 if (isEmpty(paraBefore))
7180                         paraBefore.innerHTML = "&nbsp;";
7181
7182                 // Check if it's a empty paragraph
7183                 if (isEmpty(paraAfter))
7184                         paraAfter.innerHTML = "&nbsp;";
7185
7186                 // Create a range around everything
7187                 rng = doc.createRange();
7188
7189                 if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) {
7190                         rng.setStartBefore(startChop.parentNode);
7191                 } else {
7192                         if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0)
7193                                 rng.setStartBefore(rngBefore.startContainer);
7194                         else
7195                                 rng.setStart(rngBefore.startContainer, rngBefore.startOffset);
7196                 }
7197
7198                 if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName)
7199                         rng.setEndAfter(endChop.parentNode);
7200                 else
7201                         rng.setEnd(rngAfter.endContainer, rngAfter.endOffset);
7202
7203                 // Delete all contents and insert new paragraphs
7204                 rng.deleteContents();
7205
7206                 if (tinyMCE.isOpera) {
7207                         rng.insertNode(paraBefore);
7208                         rng.insertNode(paraAfter);
7209                 } else {
7210                         rng.insertNode(paraAfter);
7211                         rng.insertNode(paraBefore);
7212                 }
7213
7214                 //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML);
7215
7216                 // Normalize
7217                 paraAfter.normalize();
7218                 paraBefore.normalize();
7219
7220                 inst.selection.moveToBookmark(b);
7221                 inst.selection.selectNode(paraAfter, true, true);
7222
7223                 return true;
7224         },
7225
7226         _handleBackSpace : function(inst) {
7227                 var r = inst.getRng(), sn = r.startContainer, nv, s = false;
7228
7229                 // Added body check for bug #1527787
7230                 if (sn && sn.nextSibling && sn.nextSibling.nodeName == "BR" && sn.parentNode.nodeName != "BODY") {
7231                         nv = sn.nodeValue;
7232
7233                         // Handle if a backspace is pressed after a space character #bug 1466054 removed since fix for #1527787
7234                         /*if (nv != null && nv.length >= r.startOffset && nv.charAt(r.startOffset - 1) == ' ')
7235                                 s = true;*/
7236
7237                         // Only remove BRs if we are at the end of line #bug 1464152
7238                         if (nv != null && r.startOffset == nv.length)
7239                                 sn.nextSibling.parentNode.removeChild(sn.nextSibling);
7240                 }
7241
7242                 if (inst.settings.auto_resize)
7243                         inst.resizeToContent();
7244
7245                 return s;
7246         }
7247
7248         };
7249
7250 /* file:jscripts/tiny_mce/classes/TinyMCE_Layer.class.js */
7251
7252 function TinyMCE_Layer(id, bm) {
7253         this.id = id;
7254         this.blockerElement = null;
7255         this.events = false;
7256         this.element = null;
7257         this.blockMode = typeof(bm) != 'undefined' ? bm : true;
7258         this.doc = document;
7259 };
7260
7261 TinyMCE_Layer.prototype = {
7262         moveRelativeTo : function(re, p) {
7263                 var rep = this.getAbsPosition(re), e = this.getElement(), x, y;
7264                 var w = parseInt(re.offsetWidth), h = parseInt(re.offsetHeight);
7265                 var ew = parseInt(e.offsetWidth), eh = parseInt(e.offsetHeight);
7266
7267                 switch (p) {
7268                         case "tl":
7269                                 x = rep.absLeft;
7270                                 y = rep.absTop;
7271                                 break;
7272
7273                         case "tr":
7274                                 x = rep.absLeft + w;
7275                                 y = rep.absTop;
7276                                 break;
7277
7278                         case "bl":
7279                                 x = rep.absLeft;
7280                                 y = rep.absTop + h;
7281                                 break;
7282
7283                         case "br":
7284                                 x = rep.absLeft + w;
7285                                 y = rep.absTop + h;
7286                                 break;
7287
7288                         case "cc":
7289                                 x = rep.absLeft + (w / 2) - (ew / 2);
7290                                 y = rep.absTop + (h / 2) - (eh / 2);
7291                                 break;
7292                 }
7293
7294                 this.moveTo(x, y);
7295         },
7296
7297         moveBy : function(x, y) {
7298                 var e = this.getElement();
7299                 this.moveTo(parseInt(e.style.left) + x, parseInt(e.style.top) + y);
7300         },
7301
7302         moveTo : function(x, y) {
7303                 var e = this.getElement();
7304
7305                 e.style.left = x + "px";
7306                 e.style.top = y + "px";
7307
7308                 this.updateBlocker();
7309         },
7310
7311         resizeBy : function(w, h) {
7312                 var e = this.getElement();
7313                 this.resizeTo(parseInt(e.style.width) + w, parseInt(e.style.height) + h);
7314         },
7315
7316         resizeTo : function(w, h) {
7317                 var e = this.getElement();
7318
7319                 if (w != null)
7320                         e.style.width = w + "px";
7321
7322                 if (h != null)
7323                         e.style.height = h + "px";
7324
7325                 this.updateBlocker();
7326         },
7327
7328         show : function() {
7329                 var el = this.getElement();
7330
7331                 if (el) {
7332                         el.style.display = 'block';
7333                         this.updateBlocker();
7334                 }
7335         },
7336
7337         hide : function() {
7338                 var el = this.getElement();
7339
7340                 if (el) {
7341                         el.style.display = 'none';
7342                         this.updateBlocker();
7343                 }
7344         },
7345
7346         isVisible : function() {
7347                 return this.getElement().style.display == 'block';
7348         },
7349
7350         getElement : function() {
7351                 if (!this.element)
7352                         this.element = this.doc.getElementById(this.id);
7353
7354                 return this.element;
7355         },
7356
7357         setBlockMode : function(s) {
7358                 this.blockMode = s;
7359         },
7360
7361         updateBlocker : function() {
7362                 var e, b, x, y, w, h;
7363
7364                 b = this.getBlocker();
7365                 if (b) {
7366                         if (this.blockMode) {
7367                                 e = this.getElement();
7368                                 x = this.parseInt(e.style.left);
7369                                 y = this.parseInt(e.style.top);
7370                                 w = this.parseInt(e.offsetWidth);
7371                                 h = this.parseInt(e.offsetHeight);
7372
7373                                 b.style.left = x + 'px';
7374                                 b.style.top = y + 'px';
7375                                 b.style.width = w + 'px';
7376                                 b.style.height = h + 'px';
7377                                 b.style.display = e.style.display;
7378                         } else
7379                                 b.style.display = 'none';
7380                 }
7381         },
7382
7383         getBlocker : function() {
7384                 var d, b;
7385
7386                 if (!this.blockerElement && this.blockMode) {
7387                         d = this.doc;
7388                         b = d.getElementById(this.id + "_blocker");
7389
7390                         if (!b) {
7391                                 b = d.createElement("iframe");
7392
7393                                 b.setAttribute('id', this.id + "_blocker");
7394                                 b.style.cssText = 'display: none; position: absolute; left: 0; top: 0';
7395                                 b.src = 'javascript:false;';
7396                                 b.frameBorder = '0';
7397                                 b.scrolling = 'no';
7398         
7399                                 d.body.appendChild(b);
7400                         }
7401
7402                         this.blockerElement = b;
7403                 }
7404
7405                 return this.blockerElement;
7406         },
7407
7408         getAbsPosition : function(n) {
7409                 var p = {absLeft : 0, absTop : 0};
7410
7411                 while (n) {
7412                         p.absLeft += n.offsetLeft;
7413                         p.absTop += n.offsetTop;
7414                         n = n.offsetParent;
7415                 }
7416
7417                 return p;
7418         },
7419
7420         create : function(n, c, p, h) {
7421                 var d = this.doc, e = d.createElement(n);
7422
7423                 e.setAttribute('id', this.id);
7424
7425                 if (c)
7426                         e.className = c;
7427
7428                 if (!p)
7429                         p = d.body;
7430
7431                 if (h)
7432                         e.innerHTML = h;
7433
7434                 p.appendChild(e);
7435
7436                 return this.element = e;
7437         },
7438
7439         exists : function() {
7440                 return this.doc.getElementById(this.id) != null;
7441         },
7442
7443         parseInt : function(s) {
7444                 if (s == null || s == '')
7445                         return 0;
7446
7447                 return parseInt(s);
7448         },
7449
7450         remove : function() {
7451                 var e = this.getElement(), b = this.getBlocker();
7452
7453                 if (e)
7454                         e.parentNode.removeChild(e);
7455
7456                 if (b)
7457                         b.parentNode.removeChild(b);
7458         }
7459
7460         };
7461
7462 /* file:jscripts/tiny_mce/classes/TinyMCE_Menu.class.js */
7463
7464 function TinyMCE_Menu() {
7465         var id;
7466
7467         if (typeof(tinyMCE.menuCounter) == "undefined")
7468                 tinyMCE.menuCounter = 0;
7469
7470         id = "mc_menu_" + tinyMCE.menuCounter++;
7471
7472         TinyMCE_Layer.call(this, id, true);
7473
7474         this.id = id;
7475         this.items = [];
7476         this.needsUpdate = true;
7477 };
7478
7479 TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, {
7480         init : function(s) {
7481                 var n;
7482
7483                 // Default params
7484                 this.settings = {
7485                         separator_class : 'mceMenuSeparator',
7486                         title_class : 'mceMenuTitle',
7487                         disabled_class : 'mceMenuDisabled',
7488                         menu_class : 'mceMenu',
7489                         drop_menu : true
7490                 };
7491
7492                 for (n in s)
7493                         this.settings[n] = s[n];
7494
7495                 this.create('div', this.settings.menu_class);
7496         },
7497
7498         clear : function() {
7499                 this.items = [];
7500         },
7501
7502         addTitle : function(t) {
7503                 this.add({type : 'title', text : t});
7504         },
7505
7506         addDisabled : function(t) {
7507                 this.add({type : 'disabled', text : t});
7508         },
7509
7510         addSeparator : function() {
7511                 this.add({type : 'separator'});
7512         },
7513
7514         addItem : function(t, js) {
7515                 this.add({text : t, js : js});
7516         },
7517
7518         add : function(mi) {
7519                 this.items[this.items.length] = mi;
7520                 this.needsUpdate = true;
7521         },
7522
7523         update : function() {
7524                 var e = this.getElement(), h = '', i, t, m = this.items, s = this.settings;
7525
7526                 if (this.settings.drop_menu)
7527                         h += '<span class="mceMenuLine"></span>';
7528
7529                 h += '<table border="0" cellpadding="0" cellspacing="0">';
7530
7531                 for (i=0; i<m.length; i++) {
7532                         t = tinyMCE.xmlEncode(m[i].text);
7533                         c = m[i].class_name ? ' class="' + m[i].class_name + '"' : '';
7534
7535                         switch (m[i].type) {
7536                                 case 'separator':
7537                                         h += '<tr class="' + s.separator_class + '"><td>';
7538                                         break;
7539
7540                                 case 'title':
7541                                         h += '<tr class="' + s.title_class + '"><td><span' + c +'>' + t + '</span>';
7542                                         break;
7543
7544                                 case 'disabled':
7545                                         h += '<tr class="' + s.disabled_class + '"><td><span' + c +'>' + t + '</span>';
7546                                         break;
7547
7548                                 default:
7549                                         h += '<tr><td><a href="' + tinyMCE.xmlEncode(m[i].js) + '" onmousedown="' + tinyMCE.xmlEncode(m[i].js) + ';return tinyMCE.cancelEvent(event);" onclick="return tinyMCE.cancelEvent(event);" onmouseup="return tinyMCE.cancelEvent(event);"><span' + c +'>' + t + '</span></a>';
7550                         }
7551
7552                         h += '</td></tr>';
7553                 }
7554
7555                 h += '</table>';
7556
7557                 e.innerHTML = h;
7558
7559                 this.needsUpdate = false;
7560                 this.updateBlocker();
7561         },
7562
7563         show : function() {
7564                 var nl, i;
7565
7566                 if (tinyMCE.lastMenu == this)
7567                         return;
7568
7569                 if (this.needsUpdate)
7570                         this.update();
7571
7572                 if (tinyMCE.lastMenu && tinyMCE.lastMenu != this)
7573                         tinyMCE.lastMenu.hide();
7574
7575                 TinyMCE_Layer.prototype.show.call(this);
7576
7577                 if (!tinyMCE.isOpera) {
7578                         // Accessibility stuff
7579 /*                      nl = this.getElement().getElementsByTagName("a");
7580                         if (nl.length > 0)
7581                                 nl[0].focus();*/
7582                 }
7583
7584                 tinyMCE.lastMenu = this;
7585         }
7586
7587         });
7588
7589 /* file:jscripts/tiny_mce/classes/TinyMCE_Debug.class.js */
7590
7591 tinyMCE.add(TinyMCE_Engine, {
7592         debug : function() {
7593                 var m = "", a, i, l = tinyMCE.log.length;
7594
7595                 for (i=0, a = this.debug.arguments; i<a.length; i++) {
7596                         m += a[i];
7597
7598                         if (i<a.length-1)
7599                                 m += ', ';
7600                 }
7601
7602                 if (l < 1000)
7603                         tinyMCE.log[l] = "[debug] " + m;
7604         }
7605
7606         });
7607