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