472,950 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

trouble with tinyMCE images

matheussousuke
249 100+
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails.


The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg

instead of

http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg

As u see, there's the website URL before the image URL.

I tried activate and deactivate convert_urls, relative_urls, remove_scripthost function, and deteleting documentbaseURl but nothig worked to me, the website URL still keeps in there, what can I do?



PS: here goes the script

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. var tinymce = {
  4.     majorVersion : '3',
  5.     minorVersion : '2.7',
  6.     releaseDate : '2009-09-22',
  7.  
  8.     _init : function() {
  9.         var t = this, d = document, w = window, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  10.  
  11.         t.isOpera = w.opera && opera.buildNumber;
  12.  
  13.         t.isWebKit = /WebKit/.test(ua);
  14.  
  15.         t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  16.  
  17.         t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  18.  
  19.         t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  20.  
  21.         t.isMac = ua.indexOf('Mac') != -1;
  22.  
  23.         t.isAir = /adobeair/i.test(ua);
  24.  
  25.         // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  26.         if (w.tinyMCEPreInit) {
  27.             t.suffix = tinyMCEPreInit.suffix;
  28.             t.baseURL = tinyMCEPreInit.base;
  29.             t.query = tinyMCEPreInit.query;
  30.             return;
  31.         }
  32.  
  33.         // Get suffix and base
  34.         t.suffix = '';
  35.  
  36.         // If base element found, add that infront of baseURL
  37.         nl = d.getElementsByTagName('base');
  38.         for (i=0; i<nl.length; i++) {
  39.             if (v = nl[i].href) {
  40.                 // Host only value like http://site.com or http://site.com:8008
  41.                 if (/^https?:\/\/[^\/]+$/.test(v))
  42.                     v += '/';
  43.  
  44.                 base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  45.             }
  46.         }
  47.  
  48.         function getBase(n) {
  49.             if (n.src && /tiny_mce(|_gzip|_jquery|_prototype)(_dev|_src)?.js/.test(n.src)) {
  50.                 if (/_(src|dev)\.js/g.test(n.src))
  51.                     t.suffix = '_src';
  52.  
  53.                 if ((p = n.src.indexOf('?')) != -1)
  54.                     t.query = n.src.substring(p + 1);
  55.  
  56.                 t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  57.  
  58.                 // If path to script is relative and a base href was found add that one infront
  59.                 // the src property will always be an absolute one on non IE browsers and IE 8
  60.                 // so this logic will basically only be executed on older IE versions
  61.                 if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  62.                     t.baseURL = base + t.baseURL;
  63.  
  64.                 return t.baseURL;
  65.             }
  66.  
  67.             return null;
  68.         };
  69.  
  70.         // Check document
  71.         nl = d.getElementsByTagName('script');
  72.         for (i=0; i<nl.length; i++) {
  73.             if (getBase(nl[i]))
  74.                 return;
  75.         }
  76.  
  77.         // Check head
  78.         n = d.getElementsByTagName('head')[0];
  79.         if (n) {
  80.             nl = n.getElementsByTagName('script');
  81.             for (i=0; i<nl.length; i++) {
  82.                 if (getBase(nl[i]))
  83.                     return;
  84.             }
  85.         }
  86.  
  87.         return;
  88.     },
  89.  
  90.     is : function(o, t) {
  91.         var n = typeof(o);
  92.  
  93.         if (!t)
  94.             return n != 'undefined';
  95.  
  96.         if (t == 'array' && (o.hasOwnProperty && o instanceof Array))
  97.             return true;
  98.  
  99.         return n == t;
  100.     },
  101.  
  102.     each : function(o, cb, s) {
  103.         var n, l;
  104.  
  105.         if (!o)
  106.             return 0;
  107.  
  108.         s = s || o;
  109.  
  110.         if (typeof(o.length) != 'undefined') {
  111.             // Indexed arrays, needed for Safari
  112.             for (n=0, l = o.length; n<l; n++) {
  113.                 if (cb.call(s, o[n], n, o) === false)
  114.                     return 0;
  115.             }
  116.         } else {
  117.             // Hashtables
  118.             for (n in o) {
  119.                 if (o.hasOwnProperty(n)) {
  120.                     if (cb.call(s, o[n], n, o) === false)
  121.                         return 0;
  122.                 }
  123.             }
  124.         }
  125.  
  126.         return 1;
  127.     },
  128.  
  129.  
  130.     map : function(a, f) {
  131.         var o = [];
  132.  
  133.         tinymce.each(a, function(v) {
  134.             o.push(f(v));
  135.         });
  136.  
  137.         return o;
  138.     },
  139.  
  140.     grep : function(a, f) {
  141.         var o = [];
  142.  
  143.         tinymce.each(a, function(v) {
  144.             if (!f || f(v))
  145.                 o.push(v);
  146.         });
  147.  
  148.         return o;
  149.     },
  150.  
  151.     inArray : function(a, v) {
  152.         var i, l;
  153.  
  154.         if (a) {
  155.             for (i = 0, l = a.length; i < l; i++) {
  156.                 if (a[i] === v)
  157.                     return i;
  158.             }
  159.         }
  160.  
  161.         return -1;
  162.     },
  163.  
  164.     extend : function(o, e) {
  165.         var i, a = arguments;
  166.  
  167.         for (i=1; i<a.length; i++) {
  168.             e = a[i];
  169.  
  170.             tinymce.each(e, function(v, n) {
  171.                 if (typeof(v) !== 'undefined')
  172.                     o[n] = v;
  173.             });
  174.         }
  175.  
  176.         return o;
  177.     },
  178.  
  179.  
  180.     trim : function(s) {
  181.         return (s ? '' + s : '').replace(/^\s*|\s*$/g, '');
  182.     },
  183.  
  184.     create : function(s, p) {
  185.         var t = this, sp, ns, cn, scn, c, de = 0;
  186.  
  187.         // Parse : <prefix> <class>:<super class>
  188.         s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  189.         cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  190.  
  191.         // Create namespace for new class
  192.         ns = t.createNS(s[3].replace(/\.\w+$/, ''));
  193.  
  194.         // Class already exists
  195.         if (ns[cn])
  196.             return;
  197.  
  198.         // Make pure static class
  199.         if (s[2] == 'static') {
  200.             ns[cn] = p;
  201.  
  202.             if (this.onCreate)
  203.                 this.onCreate(s[2], s[3], ns[cn]);
  204.  
  205.             return;
  206.         }
  207.  
  208.         // Create default constructor
  209.         if (!p[cn]) {
  210.             p[cn] = function() {};
  211.             de = 1;
  212.         }
  213.  
  214.         // Add constructor and methods
  215.         ns[cn] = p[cn];
  216.         t.extend(ns[cn].prototype, p);
  217.  
  218.         // Extend
  219.         if (s[5]) {
  220.             sp = t.resolve(s[5]).prototype;
  221.             scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  222.  
  223.             // Extend constructor
  224.             c = ns[cn];
  225.             if (de) {
  226.                 // Add passthrough constructor
  227.                 ns[cn] = function() {
  228.                     return sp[scn].apply(this, arguments);
  229.                 };
  230.             } else {
  231.                 // Add inherit constructor
  232.                 ns[cn] = function() {
  233.                     this.parent = sp[scn];
  234.                     return c.apply(this, arguments);
  235.                 };
  236.             }
  237.             ns[cn].prototype[cn] = ns[cn];
  238.  
  239.             // Add super methods
  240.             t.each(sp, function(f, n) {
  241.                 ns[cn].prototype[n] = sp[n];
  242.             });
  243.  
  244.             // Add overridden methods
  245.             t.each(p, function(f, n) {
  246.                 // Extend methods if needed
  247.                 if (sp[n]) {
  248.                     ns[cn].prototype[n] = function() {
  249.                         this.parent = sp[n];
  250.                         return f.apply(this, arguments);
  251.                     };
  252.                 } else {
  253.                     if (n != cn)
  254.                         ns[cn].prototype[n] = f;
  255.                 }
  256.             });
  257.         }
  258.  
  259.         // Add static methods
  260.         t.each(p['static'], function(f, n) {
  261.             ns[cn][n] = f;
  262.         });
  263.  
  264.         if (this.onCreate)
  265.             this.onCreate(s[2], s[3], ns[cn].prototype);
  266.     },
  267.  
  268.     walk : function(o, f, n, s) {
  269.         s = s || this;
  270.  
  271.         if (o) {
  272.             if (n)
  273.                 o = o[n];
  274.  
  275.             tinymce.each(o, function(o, i) {
  276.                 if (f.call(s, o, i, n) === false)
  277.                     return false;
  278.  
  279.                 tinymce.walk(o, f, n, s);
  280.             });
  281.         }
  282.     },
  283.  
  284.     createNS : function(n, o) {
  285.         var i, v;
  286.  
  287.         o = o || window;
  288.  
  289.         n = n.split('.');
  290.         for (i=0; i<n.length; i++) {
  291.             v = n[i];
  292.  
  293.             if (!o[v])
  294.                 o[v] = {};
  295.  
  296.             o = o[v];
  297.         }
  298.  
  299.         return o;
  300.     },
  301.  
  302.     resolve : function(n, o) {
  303.         var i, l;
  304.  
  305.         o = o || window;
  306.  
  307.         n = n.split('.');
  308.         for (i = 0, l = n.length; i < l; i++) {
  309.             o = o[n[i]];
  310.  
  311.             if (!o)
  312.                 break;
  313.         }
  314.  
  315.         return o;
  316.     },
  317.  
  318.     addUnload : function(f, s) {
  319.         var t = this, w = window;
  320.  
  321.         f = {func : f, scope : s || this};
  322.  
  323.         if (!t.unloads) {
  324.             function unload() {
  325.                 var li = t.unloads, o, n;
  326.  
  327.                 if (li) {
  328.                     // Call unload handlers
  329.                     for (n in li) {
  330.                         o = li[n];
  331.  
  332.                         if (o && o.func)
  333.                             o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  334.                     }
  335.  
  336.                     // Detach unload function
  337.                     if (w.detachEvent) {
  338.                         w.detachEvent('onbeforeunload', fakeUnload);
  339.                         w.detachEvent('onunload', unload);
  340.                     } else if (w.removeEventListener)
  341.                         w.removeEventListener('unload', unload, false);
  342.  
  343.                     // Destroy references
  344.                     t.unloads = o = li = w = unload = 0;
  345.  
  346.                     // Run garbarge collector on IE
  347.                     if (window.CollectGarbage)
  348.                         window.CollectGarbage();
  349.                 }
  350.             };
  351.  
  352.             function fakeUnload() {
  353.                 var d = document;
  354.  
  355.                 // Is there things still loading, then do some magic
  356.                 if (d.readyState == 'interactive') {
  357.                     function stop() {
  358.                         // Prevent memory leak
  359.                         d.detachEvent('onstop', stop);
  360.  
  361.                         // Call unload handler
  362.                         if (unload)
  363.                             unload();
  364.  
  365.                         d = 0;
  366.                     };
  367.  
  368.                     // Fire unload when the currently loading page is stopped
  369.                     if (d)
  370.                         d.attachEvent('onstop', stop);
  371.  
  372.                     // Remove onstop listener after a while to prevent the unload function
  373.                     // to execute if the user presses cancel in an onbeforeunload
  374.                     // confirm dialog and then presses the browser stop button
  375.                     window.setTimeout(function() {
  376.                         if (d)
  377.                             d.detachEvent('onstop', stop);
  378.                     }, 0);
  379.                 }
  380.             };
  381.  
  382.             // Attach unload handler
  383.             if (w.attachEvent) {
  384.                 w.attachEvent('onunload', unload);
  385.                 w.attachEvent('onbeforeunload', fakeUnload);
  386.             } else if (w.addEventListener)
  387.                 w.addEventListener('unload', unload, false);
  388.  
  389.             // Setup initial unload handler array
  390.             t.unloads = [f];
  391.         } else
  392.             t.unloads.push(f);
  393.  
  394.         return f;
  395.     },
  396.  
  397.     removeUnload : function(f) {
  398.         var u = this.unloads, r = null;
  399.  
  400.         tinymce.each(u, function(o, i) {
  401.             if (o && o.func == f) {
  402.                 u.splice(i, 1);
  403.                 r = f;
  404.                 return false;
  405.             }
  406.         });
  407.  
  408.         return r;
  409.     },
  410.  
  411.     explode : function(s, d) {
  412.         return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s;
  413.     },
  414.  
  415.     _addVer : function(u) {
  416.         var v;
  417.  
  418.         if (!this.query)
  419.             return u;
  420.  
  421.         v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  422.  
  423.         if (u.indexOf('#') == -1)
  424.             return u + v;
  425.  
  426.         return u.replace('#', v + '#');
  427.     }
  428.  
  429.     };
  430.  
  431. // Required for GZip AJAX loading
  432. window.tinymce = tinymce;
  433.  
  434. // Initialize the API
  435. tinymce._init();
  436. tinymce.create('tinymce.util.Dispatcher', {
  437.     scope : null,
  438.     listeners : null,
  439.  
  440.     Dispatcher : function(s) {
  441.         this.scope = s || this;
  442.         this.listeners = [];
  443.     },
  444.  
  445.     add : function(cb, s) {
  446.         this.listeners.push({cb : cb, scope : s || this.scope});
  447.  
  448.         return cb;
  449.     },
  450.  
  451.     addToTop : function(cb, s) {
  452.         this.listeners.unshift({cb : cb, scope : s || this.scope});
  453.  
  454.         return cb;
  455.     },
  456.  
  457.     remove : function(cb) {
  458.         var l = this.listeners, o = null;
  459.  
  460.         tinymce.each(l, function(c, i) {
  461.             if (cb == c.cb) {
  462.                 o = cb;
  463.                 l.splice(i, 1);
  464.                 return false;
  465.             }
  466.         });
  467.  
  468.         return o;
  469.     },
  470.  
  471.     dispatch : function() {
  472.         var s, a = arguments, i, li = this.listeners, c;
  473.  
  474.         // Needs to be a real loop since the listener count might change while looping
  475.         // And this is also more efficient
  476.         for (i = 0; i<li.length; i++) {
  477.             c = li[i];
  478.             s = c.cb.apply(c.scope, a);
  479.  
  480.             if (s === false)
  481.                 break;
  482.         }
  483.  
  484.         return s;
  485.     }
  486.  
  487.     });
  488. (function() {
  489.     var each = tinymce.each;
  490.  
  491.     tinymce.create('tinymce.util.URI', {
  492.         URI : function(u, s) {
  493.             var t = this, o, a, b;
  494.  
  495.             // Trim whitespace
  496.             u = tinymce.trim(u);
  497.  
  498.             // Default settings
  499.             s = t.settings = s || {};
  500.  
  501.             // Strange app protocol or local anchor
  502.             if (/^(mailto|tel|news|javascript|about|data):/i.test(u) || /^\s*#/.test(u)) {
  503.                 t.source = u;
  504.                 return;
  505.             }
  506.  
  507.             // Absolute path with no host, fake host and protocol
  508.             if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  509.                 u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  510.  
  511.             // Relative path http:// or protocol relative //path
  512.             if (!/^\w*:?\/\//.test(u))
  513.                 u = (s.base_uri.protocol || 'http') + '://mce_host' + t.toAbsPath(s.base_uri.path, u);
  514.  
  515.             // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  516.             u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  517.             u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  518.             each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  519.                 var s = u[i];
  520.  
  521.                 // Zope 3 workaround, they use @@something
  522.                 if (s)
  523.                     s = s.replace(/\(mce_at\)/g, '@@');
  524.  
  525.                 t[v] = s;
  526.             });
  527.  
  528.             if (b = s.base_uri) {
  529.                 if (!t.protocol)
  530.                     t.protocol = b.protocol;
  531.  
  532.                 if (!t.userInfo)
  533.                     t.userInfo = b.userInfo;
  534.  
  535.                 if (!t.port && t.host == 'mce_host')
  536.                     t.port = b.port;
  537.  
  538.                 if (!t.host || t.host == 'mce_host')
  539.                     t.host = b.host;
  540.  
  541.                 t.source = '';
  542.             }
  543.  
  544.             //t.path = t.path || '/';
  545.         },
  546.  
  547.         setPath : function(p) {
  548.             var t = this;
  549.  
  550.             p = /^(.*?)\/?(\w+)?$/.exec(p);
  551.  
  552.             // Update path parts
  553.             t.path = p[0];
  554.             t.directory = p[1];
  555.             t.file = p[2];
  556.  
  557.             // Rebuild source
  558.             t.source = '';
  559.             t.getURI();
  560.         },
  561.  
  562.         toRelative : function(u) {
  563.             var t = this, o;
  564.  
  565.             if (u === "./")
  566.                 return u;
  567.  
  568.             u = new tinymce.util.URI(u, {base_uri : t});
  569.  
  570.             // Not on same domain/port or protocol
  571.             if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  572.                 return u.getURI();
  573.  
  574.             o = t.toRelPath(t.path, u.path);
  575.  
  576.             // Add query
  577.             if (u.query)
  578.                 o += '?' + u.query;
  579.  
  580.             // Add anchor
  581.             if (u.anchor)
  582.                 o += '#' + u.anchor;
  583.  
  584.             return o;
  585.         },
  586.  
  587.         toAbsolute : function(u, nh) {
  588.             var u = new tinymce.util.URI(u, {base_uri : this});
  589.  
  590.             return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  591.         },
  592.  
  593.         toRelPath : function(base, path) {
  594.             var items, bp = 0, out = '', i, l;
  595.  
  596.             // Split the paths
  597.             base = base.substring(0, base.lastIndexOf('/'));
  598.             base = base.split('/');
  599.             items = path.split('/');
  600.  
  601.             if (base.length >= items.length) {
  602.                 for (i = 0, l = base.length; i < l; i++) {
  603.                     if (i >= items.length || base[i] != items[i]) {
  604.                         bp = i + 1;
  605.                         break;
  606.                     }
  607.                 }
  608.             }
  609.  
  610.             if (base.length < items.length) {
  611.                 for (i = 0, l = items.length; i < l; i++) {
  612.                     if (i >= base.length || base[i] != items[i]) {
  613.                         bp = i + 1;
  614.                         break;
  615.                     }
  616.                 }
  617.             }
  618.  
  619.             if (bp == 1)
  620.                 return path;
  621.  
  622.             for (i = 0, l = base.length - (bp - 1); i < l; i++)
  623.                 out += "../";
  624.  
  625.             for (i = bp - 1, l = items.length; i < l; i++) {
  626.                 if (i != bp - 1)
  627.                     out += "/" + items[i];
  628.                 else
  629.                     out += items[i];
  630.             }
  631.  
  632.             return out;
  633.         },
  634.  
  635.         toAbsPath : function(base, path) {
  636.             var i, nb = 0, o = [], tr, outPath;
  637.  
  638.             // Split paths
  639.             tr = /\/$/.test(path) ? '/' : '';
  640.             base = base.split('/');
  641.             path = path.split('/');
  642.  
  643.             // Remove empty chunks
  644.             each(base, function(k) {
  645.                 if (k)
  646.                     o.push(k);
  647.             });
  648.  
  649.             base = o;
  650.  
  651.             // Merge relURLParts chunks
  652.             for (i = path.length - 1, o = []; i >= 0; i--) {
  653.                 // Ignore empty or .
  654.                 if (path[i].length == 0 || path[i] == ".")
  655.                     continue;
  656.  
  657.                 // Is parent
  658.                 if (path[i] == '..') {
  659.                     nb++;
  660.                     continue;
  661.                 }
  662.  
  663.                 // Move up
  664.                 if (nb > 0) {
  665.                     nb--;
  666.                     continue;
  667.                 }
  668.  
  669.                 o.push(path[i]);
  670.             }
  671.  
  672.             i = base.length - nb;
  673.  
  674.             // If /a/b/c or /
  675.             if (i <= 0)
  676.                 outPath = o.reverse().join('/');
  677.             else
  678.                 outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  679.  
  680.             // Add front / if it's needed
  681.             if (outPath.indexOf('/') !== 0)
  682.                 outPath = '/' + outPath;
  683.  
  684.             // Add traling / if it's needed
  685.             if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  686.                 outPath += tr;
  687.  
  688.             return outPath;
  689.         },
  690.  
  691.         getURI : function(nh) {
  692.             var s, t = this;
  693.  
  694.             // Rebuild source
  695.             if (!t.source || nh) {
  696.                 s = '';
  697.  
  698.                 if (!nh) {
  699.                     if (t.protocol)
  700.                         s += t.protocol + '://';
  701.  
  702.                     if (t.userInfo)
  703.                         s += t.userInfo + '@';
  704.  
  705.                     if (t.host)
  706.                         s += t.host;
  707.  
  708.                     if (t.port)
  709.                         s += ':' + t.port;
  710.                 }
  711.  
  712.                 if (t.path)
  713.                     s += t.path;
  714.  
  715.                 if (t.query)
  716.                     s += '?' + t.query;
  717.  
  718.                 if (t.anchor)
  719.                     s += '#' + t.anchor;
  720.  
  721.                 t.source = s;
  722.             }
  723.  
  724.             return t.source;
  725.         }
  726.     });
  727. })();
  728. (function() {
  729.     var each = tinymce.each;
  730.  
  731.     tinymce.create('static tinymce.util.Cookie', {
  732.         getHash : function(n) {
  733.             var v = this.get(n), h;
  734.  
  735.             if (v) {
  736.                 each(v.split('&'), function(v) {
  737.                     v = v.split('=');
  738.                     h = h || {};
  739.                     h[unescape(v[0])] = unescape(v[1]);
  740.                 });
  741.             }
  742.  
  743.             return h;
  744.         },
  745.  
  746.         setHash : function(n, v, e, p, d, s) {
  747.             var o = '';
  748.  
  749.             each(v, function(v, k) {
  750.                 o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  751.             });
  752.  
  753.             this.set(n, o, e, p, d, s);
  754.         },
  755.  
  756.         get : function(n) {
  757.             var c = document.cookie, e, p = n + "=", b;
  758.  
  759.             // Strict mode
  760.             if (!c)
  761.                 return;
  762.  
  763.             b = c.indexOf("; " + p);
  764.  
  765.             if (b == -1) {
  766.                 b = c.indexOf(p);
  767.  
  768.                 if (b != 0)
  769.                     return null;
  770.             } else
  771.                 b += 2;
  772.  
  773.             e = c.indexOf(";", b);
  774.  
  775.             if (e == -1)
  776.                 e = c.length;
  777.  
  778.             return unescape(c.substring(b + p.length, e));
  779.         },
  780.  
  781.         set : function(n, v, e, p, d, s) {
  782.             document.cookie = n + "=" + escape(v) +
  783.                 ((e) ? "; expires=" + e.toGMTString() : "") +
  784.                 ((p) ? "; path=" + escape(p) : "") +
  785.                 ((d) ? "; domain=" + d : "") +
  786.                 ((s) ? "; secure" : "");
  787.         },
  788.  
  789.         remove : function(n, p) {
  790.             var d = new Date();
  791.  
  792.             d.setTime(d.getTime() - 1000);
  793.  
  794.             this.set(n, '', d, p, d);
  795.         }
  796.     });
  797. })();
  798. tinymce.create('static tinymce.util.JSON', {
  799.     serialize : function(o) {
  800.         var i, v, s = tinymce.util.JSON.serialize, t;
  801.  
  802.         if (o == null)
  803.             return 'null';
  804.  
  805.         t = typeof o;
  806.  
  807.         if (t == 'string') {
  808.             v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  809.  
  810.             return '"' + o.replace(/([\u0080-\uFFFF\x00-\x1f\"])/g, function(a, b) {
  811.                 i = v.indexOf(b);
  812.  
  813.                 if (i + 1)
  814.                     return '\\' + v.charAt(i + 1);
  815.  
  816.                 a = b.charCodeAt().toString(16);
  817.  
  818.                 return '\\u' + '0000'.substring(a.length) + a;
  819.             }) + '"';
  820.         }
  821.  
  822.         if (t == 'object') {
  823.             if (o.hasOwnProperty && o instanceof Array) {
  824.                     for (i=0, v = '['; i<o.length; i++)
  825.                         v += (i > 0 ? ',' : '') + s(o[i]);
  826.  
  827.                     return v + ']';
  828.                 }
  829.  
  830.                 v = '{';
  831.  
  832.                 for (i in o)
  833.                     v += typeof o[i] != 'function' ? (v.length > 1 ? ',"' : '"') + i + '":' + s(o[i]) : '';
  834.  
  835.                 return v + '}';
  836.         }
  837.  
  838.         return '' + o;
  839.     },
  840.  
  841.     parse : function(s) {
  842.         try {
  843.             return eval('(' + s + ')');
  844.         } catch (ex) {
  845.             // Ignore
  846.         }
  847.     }
  848.  
  849.     });
  850. tinymce.create('static tinymce.util.XHR', {
  851.     send : function(o) {
  852.         var x, t, w = window, c = 0;
  853.  
  854.         // Default settings
  855.         o.scope = o.scope || this;
  856.         o.success_scope = o.success_scope || o.scope;
  857.         o.error_scope = o.error_scope || o.scope;
  858.         o.async = o.async === false ? false : true;
  859.         o.data = o.data || '';
  860.  
  861.         function get(s) {
  862.             x = 0;
  863.  
  864.             try {
  865.                 x = new ActiveXObject(s);
  866.             } catch (ex) {
  867.             }
  868.  
  869.             return x;
  870.         };
  871.  
  872.         x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  873.  
  874.         if (x) {
  875.             if (x.overrideMimeType)
  876.                 x.overrideMimeType(o.content_type);
  877.  
  878.             x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  879.  
  880.             if (o.content_type)
  881.                 x.setRequestHeader('Content-Type', o.content_type);
  882.  
  883.             x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  884.  
  885.             x.send(o.data);
  886.  
  887.             function ready() {
  888.                 if (!o.async || x.readyState == 4 || c++ > 10000) {
  889.                     if (o.success && c < 10000 && x.status == 200)
  890.                         o.success.call(o.success_scope, '' + x.responseText, x, o);
  891.                     else if (o.error)
  892.                         o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  893.  
  894.                     x = null;
  895.                 } else
  896.                     w.setTimeout(ready, 10);
  897.             };
  898.  
  899.             // Syncronous request
  900.             if (!o.async)
  901.                 return ready();
  902.  
  903.             // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  904.             t = w.setTimeout(ready, 10);
  905.         }
  906.     }
  907. });
  908. (function() {
  909.     var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  910.  
  911.     tinymce.create('tinymce.util.JSONRequest', {
  912.         JSONRequest : function(s) {
  913.             this.settings = extend({
  914.             }, s);
  915.             this.count = 0;
  916.         },
  917.  
  918.         send : function(o) {
  919.             var ecb = o.error, scb = o.success;
  920.  
  921.             o = extend(this.settings, o);
  922.  
  923.             o.success = function(c, x) {
  924.                 c = JSON.parse(c);
  925.  
  926.                 if (typeof(c) == 'undefined') {
  927.                     c = {
  928.                         error : 'JSON Parse error.'
  929.                     };
  930.                 }
  931.  
  932.                 if (c.error)
  933.                     ecb.call(o.error_scope || o.scope, c.error, x);
  934.                 else
  935.                     scb.call(o.success_scope || o.scope, c.result);
  936.             };
  937.  
  938.             o.error = function(ty, x) {
  939.                 ecb.call(o.error_scope || o.scope, ty, x);
  940.             };
  941.  
  942.             o.data = JSON.serialize({
  943.                 id : o.id || 'c' + (this.count++),
  944.                 method : o.method,
  945.                 params : o.params
  946.             });
  947.  
  948.             // JSON content type for Ruby on rails. Bug: #1883287
  949.             o.content_type = 'application/json';
  950.  
  951.             XHR.send(o);
  952.         },
  953.  
  954.         'static' : {
  955.             sendRPC : function(o) {
  956.                 return new tinymce.util.JSONRequest().send(o);
  957.             }
  958.         }
  959.     });
  960. }());(function(tinymce) {
  961.     // Shorten names
  962.     var each = tinymce.each, is = tinymce.is;
  963.     var isWebKit = tinymce.isWebKit, isIE = tinymce.isIE;
  964.  
  965.     tinymce.create('tinymce.dom.DOMUtils', {
  966.         doc : null,
  967.         root : null,
  968.         files : null,
  969.         pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  970.         props : {
  971.             "for" : "htmlFor",
  972.             "class" : "className",
  973.             className : "className",
  974.             checked : "checked",
  975.             disabled : "disabled",
  976.             maxlength : "maxLength",
  977.             readonly : "readOnly",
  978.             selected : "selected",
  979.             value : "value",
  980.             id : "id",
  981.             name : "name",
  982.             type : "type"
  983.         },
  984.  
  985.         DOMUtils : function(d, s) {
  986.             var t = this;
  987.  
  988.             t.doc = d;
  989.             t.win = window;
  990.             t.files = {};
  991.             t.cssFlicker = false;
  992.             t.counter = 0;
  993.             t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat"; 
  994.             t.stdMode = d.documentMode === 8;
  995.  
  996.             t.settings = s = tinymce.extend({
  997.                 keep_values : false,
  998.                 hex_colors : 1,
  999.                 process_html : 1
  1000.             }, s);
  1001.  
  1002.             // Fix IE6SP2 flicker and check it failed for pre SP2
  1003.             if (tinymce.isIE6) {
  1004.                 try {
  1005.                     d.execCommand('BackgroundImageCache', false, true);
  1006.                 } catch (e) {
  1007.                     t.cssFlicker = true;
  1008.                 }
  1009.             }
  1010.  
  1011.             tinymce.addUnload(t.destroy, t);
  1012.         },
  1013.  
  1014.         getRoot : function() {
  1015.             var t = this, s = t.settings;
  1016.  
  1017.             return (s && t.get(s.root_element)) || t.doc.body;
  1018.         },
  1019.  
  1020.         getViewPort : function(w) {
  1021.             var d, b;
  1022.  
  1023.             w = !w ? this.win : w;
  1024.             d = w.document;
  1025.             b = this.boxModel ? d.documentElement : d.body;
  1026.  
  1027.             // Returns viewport size excluding scrollbars
  1028.             return {
  1029.                 x : w.pageXOffset || b.scrollLeft,
  1030.                 y : w.pageYOffset || b.scrollTop,
  1031.                 w : w.innerWidth || b.clientWidth,
  1032.                 h : w.innerHeight || b.clientHeight
  1033.             };
  1034.         },
  1035.  
  1036.         getRect : function(e) {
  1037.             var p, t = this, sr;
  1038.  
  1039.             e = t.get(e);
  1040.             p = t.getPos(e);
  1041.             sr = t.getSize(e);
  1042.  
  1043.             return {
  1044.                 x : p.x,
  1045.                 y : p.y,
  1046.                 w : sr.w,
  1047.                 h : sr.h
  1048.             };
  1049.         },
  1050.  
  1051.         getSize : function(e) {
  1052.             var t = this, w, h;
  1053.  
  1054.             e = t.get(e);
  1055.             w = t.getStyle(e, 'width');
  1056.             h = t.getStyle(e, 'height');
  1057.  
  1058.             // Non pixel value, then force offset/clientWidth
  1059.             if (w.indexOf('px') === -1)
  1060.                 w = 0;
  1061.  
  1062.             // Non pixel value, then force offset/clientWidth
  1063.             if (h.indexOf('px') === -1)
  1064.                 h = 0;
  1065.  
  1066.             return {
  1067.                 w : parseInt(w) || e.offsetWidth || e.clientWidth,
  1068.                 h : parseInt(h) || e.offsetHeight || e.clientHeight
  1069.             };
  1070.         },
  1071.  
  1072.         getParent : function(n, f, r) {
  1073.             return this.getParents(n, f, r, false);
  1074.         },
  1075.  
  1076.         getParents : function(n, f, r, c) {
  1077.             var t = this, na, se = t.settings, o = [];
  1078.  
  1079.             n = t.get(n);
  1080.             c = c === undefined;
  1081.  
  1082.             if (se.strict_root)
  1083.                 r = r || t.getRoot();
  1084.  
  1085.             // Wrap node name as func
  1086.             if (is(f, 'string')) {
  1087.                 na = f;
  1088.  
  1089.                 if (f === '*') {
  1090.                     f = function(n) {return n.nodeType == 1;};
  1091.                 } else {
  1092.                     f = function(n) {
  1093.                         return t.is(n, na);
  1094.                     };
  1095.                 }
  1096.             }
  1097.  
  1098.             while (n) {
  1099.                 if (n == r || !n.nodeType || n.nodeType === 9)
  1100.                     break;
  1101.  
  1102.                 if (!f || f(n)) {
  1103.                     if (c)
  1104.                         o.push(n);
  1105.                     else
  1106.                         return n;
  1107.                 }
  1108.  
  1109.                 n = n.parentNode;
  1110.             }
  1111.  
  1112.             return c ? o : null;
  1113.         },
  1114.  
  1115.         get : function(e) {
  1116.             var n;
  1117.  
  1118.             if (e && this.doc && typeof(e) == 'string') {
  1119.                 n = e;
  1120.                 e = this.doc.getElementById(e);
  1121.  
  1122.                 // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  1123.                 if (e && e.id !== n)
  1124.                     return this.doc.getElementsByName(n)[1];
  1125.             }
  1126.  
  1127.             return e;
  1128.         },
  1129.  
  1130.         getNext : function(node, selector) {
  1131.             return this._findSib(node, selector, 'nextSibling');
  1132.         },
  1133.  
  1134.         getPrev : function(node, selector) {
  1135.             return this._findSib(node, selector, 'previousSibling');
  1136.         },
  1137.  
  1138.  
  1139.         select : function(pa, s) {
  1140.             var t = this;
  1141.  
  1142.             return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []);
  1143.         },
  1144.  
  1145.         is : function(n, patt) {
  1146.             return tinymce.dom.Sizzle.matches(patt, n.nodeType ? [n] : n).length > 0;
  1147.         },
  1148.  
  1149.  
  1150.         add : function(p, n, a, h, c) {
  1151.             var t = this;
  1152.  
  1153.             return this.run(p, function(p) {
  1154.                 var e, k;
  1155.  
  1156.                 e = is(n, 'string') ? t.doc.createElement(n) : n;
  1157.                 t.setAttribs(e, a);
  1158.  
  1159.                 if (h) {
  1160.                     if (h.nodeType)
  1161.                         e.appendChild(h);
  1162.                     else
  1163.                         t.setHTML(e, h);
  1164.                 }
  1165.  
  1166.                 return !c ? p.appendChild(e) : e;
  1167.             });
  1168.         },
  1169.  
  1170.         create : function(n, a, h) {
  1171.             return this.add(this.doc.createElement(n), n, a, h, 1);
  1172.         },
  1173.  
  1174.         createHTML : function(n, a, h) {
  1175.             var o = '', t = this, k;
  1176.  
  1177.             o += '<' + n;
  1178.  
  1179.             for (k in a) {
  1180.                 if (a.hasOwnProperty(k))
  1181.                     o += ' ' + k + '="' + t.encode(a[k]) + '"';
  1182.             }
  1183.  
  1184.             if (tinymce.is(h))
  1185.                 return o + '>' + h + '</' + n + '>';
  1186.  
  1187.             return o + ' />';
  1188.         },
  1189.  
  1190.         remove : function(n, k) {
  1191.             var t = this;
  1192.  
  1193.             return this.run(n, function(n) {
  1194.                 var p, g, i;
  1195.  
  1196.                 p = n.parentNode;
  1197.  
  1198.                 if (!p)
  1199.                     return null;
  1200.  
  1201.                 if (k) {
  1202.                     for (i = n.childNodes.length - 1; i >= 0; i--)
  1203.                         t.insertAfter(n.childNodes[i], n);
  1204.  
  1205.                     //each(n.childNodes, function(c) {
  1206.                     //    p.insertBefore(c.cloneNode(true), n);
  1207.                     //});
  1208.                 }
  1209.  
  1210.                 // Fix IE psuedo leak
  1211.                 if (t.fixPsuedoLeaks) {
  1212.                     p = n.cloneNode(true);
  1213.                     k = 'IELeakGarbageBin';
  1214.                     g = t.get(k) || t.add(t.doc.body, 'div', {id : k, style : 'display:none'});
  1215.                     g.appendChild(n);
  1216.                     g.innerHTML = '';
  1217.  
  1218.                     return p;
  1219.                 }
  1220.  
  1221.                 return p.removeChild(n);
  1222.             });
  1223.         },
  1224.  
  1225.         setStyle : function(n, na, v) {
  1226.             var t = this;
  1227.  
  1228.             return t.run(n, function(e) {
  1229.                 var s, i;
  1230.  
  1231.                 s = e.style;
  1232.  
  1233.                 // Camelcase it, if needed
  1234.                 na = na.replace(/-(\D)/g, function(a, b){
  1235.                     return b.toUpperCase();
  1236.                 });
  1237.  
  1238.                 // Default px suffix on these
  1239.                 if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  1240.                     v += 'px';
  1241.  
  1242.                 switch (na) {
  1243.                     case 'opacity':
  1244.                         // IE specific opacity
  1245.                         if (isIE) {
  1246.                             s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  1247.  
  1248.                             if (!n.currentStyle || !n.currentStyle.hasLayout)
  1249.                                 s.display = 'inline-block';
  1250.                         }
  1251.  
  1252.                         // Fix for older browsers
  1253.                         s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  1254.                         break;
  1255.  
  1256.                     case 'float':
  1257.                         isIE ? s.styleFloat = v : s.cssFloat = v;
  1258.                         break;
  1259.  
  1260.                     default:
  1261.                         s[na] = v || '';
  1262.                 }
  1263.  
  1264.                 // Force update of the style data
  1265.                 if (t.settings.update_styles)
  1266.                     t.setAttrib(e, 'mce_style');
  1267.             });
  1268.         },
  1269.  
  1270.         getStyle : function(n, na, c) {
  1271.             n = this.get(n);
  1272.  
  1273.             if (!n)
  1274.                 return false;
  1275.  
  1276.             // Gecko
  1277.             if (this.doc.defaultView && c) {
  1278.                 // Remove camelcase
  1279.                 na = na.replace(/[A-Z]/g, function(a){
  1280.                     return '-' + a;
  1281.                 });
  1282.  
  1283.                 try {
  1284.                     return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  1285.                 } catch (ex) {
  1286.                     // Old safari might fail
  1287.                     return null;
  1288.                 }
  1289.             }
  1290.  
  1291.             // Camelcase it, if needed
  1292.             na = na.replace(/-(\D)/g, function(a, b){
  1293.                 return b.toUpperCase();
  1294.             });
  1295.  
  1296.             if (na == 'float')
  1297.                 na = isIE ? 'styleFloat' : 'cssFloat';
  1298.  
  1299.             // IE & Opera
  1300.             if (n.currentStyle && c)
  1301.                 return n.currentStyle[na];
  1302.  
  1303.             return n.style[na];
  1304.         },
  1305.  
  1306.         setStyles : function(e, o) {
  1307.             var t = this, s = t.settings, ol;
  1308.  
  1309.             ol = s.update_styles;
  1310.             s.update_styles = 0;
  1311.  
  1312.             each(o, function(v, n) {
  1313.                 t.setStyle(e, n, v);
  1314.             });
  1315.  
  1316.             // Update style info
  1317.             s.update_styles = ol;
  1318.             if (s.update_styles)
  1319.                 t.setAttrib(e, s.cssText);
  1320.         },
  1321.  
  1322.         setAttrib : function(e, n, v) {
  1323.             var t = this;
  1324.  
  1325.             // Whats the point
  1326.             if (!e || !n)
  1327.                 return;
  1328.  
  1329.             // Strict XML mode
  1330.             if (t.settings.strict)
  1331.                 n = n.toLowerCase();
  1332.  
  1333.             return this.run(e, function(e) {
  1334.                 var s = t.settings;
  1335.  
  1336.                 switch (n) {
  1337.                     case "style":
  1338.                         if (!is(v, 'string')) {
  1339.                             each(v, function(v, n) {
  1340.                                 t.setStyle(e, n, v);
  1341.                             });
  1342.  
  1343.                             return;
  1344.                         }
  1345.  
  1346.                         // No mce_style for elements with these since they might get resized by the user
  1347.                         if (s.keep_values) {
  1348.                             if (v && !t._isRes(v))
  1349.                                 e.setAttribute('mce_style', v, 2);
  1350.                             else
  1351.                                 e.removeAttribute('mce_style', 2);
  1352.                         }
  1353.  
  1354.                         e.style.cssText = v;
  1355.                         break;
  1356.  
  1357.                     case "class":
  1358.                         e.className = v || ''; // Fix IE null bug
  1359.                         break;
  1360.  
  1361.                     case "src":
  1362.                     case "href":
  1363.                         if (s.keep_values) {
  1364.                             if (s.url_converter)
  1365.                                 v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  1366.  
  1367.                             t.setAttrib(e, 'mce_' + n, v, 2);
  1368.                         }
  1369.  
  1370.                         break;
  1371.  
  1372.                     case "shape":
  1373.                         e.setAttribute('mce_style', v);
  1374.                         break;
  1375.                 }
  1376.  
  1377.                 if (is(v) && v !== null && v.length !== 0)
  1378.                     e.setAttribute(n, '' + v, 2);
  1379.                 else
  1380.                     e.removeAttribute(n, 2);
  1381.             });
  1382.         },
  1383.  
  1384.         setAttribs : function(e, o) {
  1385.             var t = this;
  1386.  
  1387.             return this.run(e, function(e) {
  1388.                 each(o, function(v, n) {
  1389.                     t.setAttrib(e, n, v);
  1390.                 });
  1391.             });
  1392.         },
  1393.  
  1394.         getAttrib : function(e, n, dv) {
  1395.             var v, t = this;
  1396.  
  1397.             e = t.get(e);
  1398.  
  1399.             if (!e || e.nodeType !== 1)
  1400.                 return false;
  1401.  
  1402.             if (!is(dv))
  1403.                 dv = '';
  1404.  
  1405.             // Try the mce variant for these
  1406.             if (/^(src|href|style|coords|shape)$/.test(n)) {
  1407.                 v = e.getAttribute("mce_" + n);
  1408.  
  1409.                 if (v)
  1410.                     return v;
  1411.             }
  1412.  
  1413.             if (isIE && t.props[n]) {
  1414.                 v = e[t.props[n]];
  1415.                 v = v && v.nodeValue ? v.nodeValue : v;
  1416.             }
  1417.  
  1418.             if (!v)
  1419.                 v = e.getAttribute(n, 2);
  1420.  
  1421.             // Check boolean attribs
  1422.             if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  1423.                 if (e[t.props[n]] === true && v === '')
  1424.                     return n;
  1425.  
  1426.                 return v ? n : '';
  1427.             }
  1428.  
  1429.             // Inner input elements will override attributes on form elements
  1430.             if (e.nodeName === "FORM" && e.getAttributeNode(n))
  1431.                 return e.getAttributeNode(n).nodeValue;
  1432.  
  1433.             if (n === 'style') {
  1434.                 v = v || e.style.cssText;
  1435.  
  1436.                 if (v) {
  1437.                     v = t.serializeStyle(t.parseStyle(v));
  1438.  
  1439.                     if (t.settings.keep_values && !t._isRes(v))
  1440.                         e.setAttribute('mce_style', v);
  1441.                 }
  1442.             }
  1443.  
  1444.             // Remove Apple and WebKit stuff
  1445.             if (isWebKit && n === "class" && v)
  1446.                 v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  1447.  
  1448.             // Handle IE issues
  1449.             if (isIE) {
  1450.                 switch (n) {
  1451.                     case 'rowspan':
  1452.                     case 'colspan':
  1453.                         // IE returns 1 as default value
  1454.                         if (v === 1)
  1455.                             v = '';
  1456.  
  1457.                         break;
  1458.  
  1459.                     case 'size':
  1460.                         // IE returns +0 as default value for size
  1461.                         if (v === '+0' || v === 20 || v === 0)
  1462.                             v = '';
  1463.  
  1464.                         break;
  1465.  
  1466.                     case 'width':
  1467.                     case 'height':
  1468.                     case 'vspace':
  1469.                     case 'checked':
  1470.                     case 'disabled':
  1471.                     case 'readonly':
  1472.                         if (v === 0)
  1473.                             v = '';
  1474.  
  1475.                         break;
  1476.  
  1477.                     case 'hspace':
  1478.                         // IE returns -1 as default value
  1479.                         if (v === -1)
  1480.                             v = '';
  1481.  
  1482.                         break;
  1483.  
  1484.                     case 'maxlength':
  1485.                     case 'tabindex':
  1486.                         // IE returns default value
  1487.                         if (v === 32768 || v === 2147483647 || v === '32768')
  1488.                             v = '';
  1489.  
  1490.                         break;
  1491.  
  1492.                     case 'multiple':
  1493.                     case 'compact':
  1494.                     case 'noshade':
  1495.                     case 'nowrap':
  1496.                         if (v === 65535)
  1497.                             return n;
  1498.  
  1499.                         return dv;
  1500.  
  1501.                     case 'shape':
  1502.                         v = v.toLowerCase();
  1503.                         break;
  1504.  
  1505.                     default:
  1506.                         // IE has odd anonymous function for event attributes
  1507.                         if (n.indexOf('on') === 0 && v)
  1508.                             v = ('' + v).replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1');
  1509.                 }
  1510.             }
  1511.  
  1512.             return (v !== undefined && v !== null && v !== '') ? '' + v : dv;
  1513.         },
  1514.  
  1515.         getPos : function(n, ro) {
  1516.             var t = this, x = 0, y = 0, e, d = t.doc, r;
  1517.  
  1518.             n = t.get(n);
  1519.             ro = ro || d.body;
  1520.  
  1521.             if (n) {
  1522.                 // Use getBoundingClientRect on IE, Opera has it but it's not perfect
  1523.                 if (isIE && !t.stdMode) {
  1524.                     n = n.getBoundingClientRect();
  1525.                     e = t.boxModel ? d.documentElement : d.body;
  1526.                     x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border
  1527.                     x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x;
  1528.                     n.top += t.win.self != t.win.top ? 2 : 0; // IE adds some strange extra cord if used in a frameset
  1529.  
  1530.                     return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x};
  1531.                 }
  1532.  
  1533.                 r = n;
  1534.                 while (r && r != ro && r.nodeType) {
  1535.                     x += r.offsetLeft || 0;
  1536.                     y += r.offsetTop || 0;
  1537.                     r = r.offsetParent;
  1538.                 }
  1539.  
  1540.                 r = n.parentNode;
  1541.                 while (r && r != ro && r.nodeType) {
  1542.                     x -= r.scrollLeft || 0;
  1543.                     y -= r.scrollTop || 0;
  1544.                     r = r.parentNode;
  1545.                 }
  1546.             }
  1547.  
  1548.             return {x : x, y : y};
  1549.         },
  1550.  
  1551.         parseStyle : function(st) {
  1552.             var t = this, s = t.settings, o = {};
  1553.  
  1554.             if (!st)
  1555.                 return o;
  1556.  
  1557.             function compress(p, s, ot) {
  1558.                 var t, r, b, l;
  1559.  
  1560.                 // Get values and check it it needs compressing
  1561.                 t = o[p + '-top' + s];
  1562.                 if (!t)
  1563.                     return;
  1564.  
  1565.                 r = o[p + '-right' + s];
  1566.                 if (t != r)
  1567.                     return;
  1568.  
  1569.                 b = o[p + '-bottom' + s];
  1570.                 if (r != b)
  1571.                     return;
  1572.  
  1573.                 l = o[p + '-left' + s];
  1574.                 if (b != l)
  1575.                     return;
  1576.  
  1577.                 // Compress
  1578.                 o[ot] = l;
  1579.                 delete o[p + '-top' + s];
  1580.                 delete o[p + '-right' + s];
  1581.                 delete o[p + '-bottom' + s];
  1582.                 delete o[p + '-left' + s];
  1583.             };
  1584.  
  1585.             function compress2(ta, a, b, c) {
  1586.                 var t;
  1587.  
  1588.                 t = o[a];
  1589.                 if (!t)
  1590.                     return;
  1591.  
  1592.                 t = o[b];
  1593.                 if (!t)
  1594.                     return;
  1595.  
  1596.                 t = o[c];
  1597.                 if (!t)
  1598.                     return;
  1599.  
  1600.                 // Compress
  1601.                 o[ta] = o[a] + ' ' + o[b] + ' ' + o[c];
  1602.                 delete o[a];
  1603.                 delete o[b];
  1604.                 delete o[c];
  1605.             };
  1606.  
  1607.             st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities
  1608.  
  1609.             each(st.split(';'), function(v) {
  1610.                 var sv, ur = [];
  1611.  
  1612.                 if (v) {
  1613.                     v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities
  1614.                     v = v.replace(/url\([^\)]+\)/g, function(v) {ur.push(v);return 'url(' + ur.length + ')';});
  1615.                     v = v.split(':');
  1616.                     sv = tinymce.trim(v[1]);
  1617.                     sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b) {return ur[parseInt(b) - 1];});
  1618.  
  1619.                     sv = sv.replace(/rgb\([^\)]+\)/g, function(v) {
  1620.                         return t.toHex(v);
  1621.                     });
  1622.  
  1623.                     if (s.url_converter) {
  1624.                         sv = sv.replace(/url\([\'\"]?([^\)\'\"]+)[\'\"]?\)/g, function(x, c) {
  1625.                             return 'url(' + s.url_converter.call(s.url_converter_scope || t, t.decode(c), 'style', null) + ')';
  1626.                         });
  1627.                     }
  1628.  
  1629.                     o[tinymce.trim(v[0]).toLowerCase()] = sv;
  1630.                 }
  1631.             });
  1632.  
  1633.             compress("border", "", "border");
  1634.             compress("border", "-width", "border-width");
  1635.             compress("border", "-color", "border-color");
  1636.             compress("border", "-style", "border-style");
  1637.             compress("padding", "", "padding");
  1638.             compress("margin", "", "margin");
  1639.             compress2('border', 'border-width', 'border-style', 'border-color');
  1640.  
  1641.             if (isIE) {
  1642.                 // Remove pointless border
  1643.                 if (o.border == 'medium none')
  1644.                     o.border = '';
  1645.             }
  1646.  
  1647.             return o;
  1648.         },
  1649.  
  1650.         serializeStyle : function(o) {
  1651.             var s = '';
  1652.  
  1653.             each(o, function(v, k) {
  1654.                 if (k && v) {
  1655.                     if (tinymce.isGecko && k.indexOf('-moz-') === 0)
  1656.                         return;
  1657.  
  1658.                     switch (k) {
  1659.                         case 'color':
  1660.                         case 'background-color':
  1661.                             v = v.toLowerCase();
  1662.                             break;
  1663.                     }
  1664.  
  1665.                     s += (s ? ' ' : '') + k + ': ' + v + ';';
  1666.                 }
  1667.             });
  1668.  
  1669.             return s;
  1670.         },
  1671.  
  1672.         loadCSS : function(u) {
  1673.             var t = this, d = t.doc, head;
  1674.  
  1675.             if (!u)
  1676.                 u = '';
  1677.  
  1678.             head = t.select('head')[0];
  1679.  
  1680.             each(u.split(','), function(u) {
  1681.                 var link;
  1682.  
  1683.                 if (t.files[u])
  1684.                     return;
  1685.  
  1686.                 t.files[u] = true;
  1687.                 link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  1688.  
  1689.                 // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  1690.                 // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  1691.                 // It's ugly but it seems to work fine.
  1692.                 if (isIE && d.documentMode) {
  1693.                     link.onload = function() {
  1694.                         d.recalc();
  1695.                         link.onload = null;
  1696.                     };
  1697.                 }
  1698.  
  1699.                 head.appendChild(link);
  1700.             });
  1701.         },
  1702.  
  1703.         addClass : function(e, c) {
  1704.             return this.run(e, function(e) {
  1705.                 var o;
  1706.  
  1707.                 if (!c)
  1708.                     return 0;
  1709.  
  1710.                 if (this.hasClass(e, c))
  1711.                     return e.className;
  1712.  
  1713.                 o = this.removeClass(e, c);
  1714.  
  1715.                 return e.className = (o != '' ? (o + ' ') : '') + c;
  1716.             });
  1717.         },
  1718.  
  1719.         removeClass : function(e, c) {
  1720.             var t = this, re;
  1721.  
  1722.             return t.run(e, function(e) {
  1723.                 var v;
  1724.  
  1725.                 if (t.hasClass(e, c)) {
  1726.                     if (!re)
  1727.                         re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  1728.  
  1729.                     v = e.className.replace(re, ' ');
  1730.  
  1731.                     return e.className = tinymce.trim(v != ' ' ? v : '');
  1732.                 }
  1733.  
  1734.                 return e.className;
  1735.             });
  1736.         },
  1737.  
  1738.         hasClass : function(n, c) {
  1739.             n = this.get(n);
  1740.  
  1741.             if (!n || !c)
  1742.                 return false;
  1743.  
  1744.             return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  1745.         },
  1746.  
  1747.         show : function(e) {
  1748.             return this.setStyle(e, 'display', 'block');
  1749.         },
  1750.  
  1751.         hide : function(e) {
  1752.             return this.setStyle(e, 'display', 'none');
  1753.         },
  1754.  
  1755.         isHidden : function(e) {
  1756.             e = this.get(e);
  1757.  
  1758.             return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  1759.         },
  1760.  
  1761.         uniqueId : function(p) {
  1762.             return (!p ? 'mce_' : p) + (this.counter++);
  1763.         },
  1764.  
  1765.         setHTML : function(e, h) {
  1766.             var t = this;
  1767.  
  1768.             return this.run(e, function(e) {
  1769.                 var x, i, nl, n, p, x;
  1770.  
  1771.                 h = t.processHTML(h);
  1772.  
  1773.                 if (isIE) {
  1774.                     function set() {
  1775.                         try {
  1776.                             // IE will remove comments from the beginning
  1777.                             // unless you padd the contents with something
  1778.                             e.innerHTML = '<br />' + h;
  1779.                             e.removeChild(e.firstChild);
  1780.                         } catch (ex) {
  1781.                             // IE sometimes produces an unknown runtime error on innerHTML if it's an block element within a block element for example a div inside a p
  1782.                             // This seems to fix this problem
  1783.  
  1784.                             // Remove all child nodes
  1785.                             while (e.firstChild)
  1786.                                 e.firstChild.removeNode();
  1787.  
  1788.                             // Create new div with HTML contents and a BR infront to keep comments
  1789.                             x = t.create('div');
  1790.                             x.innerHTML = '<br />' + h;
  1791.  
  1792.                             // Add all children from div to target
  1793.                             each (x.childNodes, function(n, i) {
  1794.                                 // Skip br element
  1795.                                 if (i)
  1796.                                     e.appendChild(n);
  1797.                             });
  1798.                         }
  1799.                     };
  1800.  
  1801.                     // IE has a serious bug when it comes to paragraphs it can produce an invalid
  1802.                     // DOM tree if contents like this <p><ul><li>Item 1</li></ul></p> is inserted
  1803.                     // It seems to be that IE doesn't like a root block element placed inside another root block element
  1804.                     if (t.settings.fix_ie_paragraphs)
  1805.                         h = h.replace(/<p><\/p>|<p([^>]+)><\/p>|<p[^\/+]\/>/gi, '<p$1 mce_keep="true">&nbsp;</p>');
  1806.  
  1807.                     set();
  1808.  
  1809.                     if (t.settings.fix_ie_paragraphs) {
  1810.                         // Check for odd paragraphs this is a sign of a broken DOM
  1811.                         nl = e.getElementsByTagName("p");
  1812.                         for (i = nl.length - 1, x = 0; i >= 0; i--) {
  1813.                             n = nl[i];
  1814.  
  1815.                             if (!n.hasChildNodes()) {
  1816.                                 if (!n.mce_keep) {
  1817.                                     x = 1; // Is broken
  1818.                                     break;
  1819.                                 }
  1820.  
  1821.                                 n.removeAttribute('mce_keep');
  1822.                             }
  1823.                         }
  1824.                     }
  1825.  
  1826.                     // Time to fix the madness IE left us
  1827.                     if (x) {
  1828.                         // So if we replace the p elements with divs and mark them and then replace them back to paragraphs
  1829.                         // after we use innerHTML we can fix the DOM tree
  1830.                         h = h.replace(/<p ([^>]+)>|<p>/ig, '<div $1 mce_tmp="1">');
  1831.                         h = h.replace(/<\/p>/g, '</div>');
  1832.  
  1833.                         // Set the new HTML with DIVs
  1834.                         set();
  1835.  
  1836.                         // Replace all DIV elements with he mce_tmp attibute back to paragraphs
  1837.                         // This is needed since IE has a annoying bug see above for details
  1838.                         // This is a slow process but it has to be done. :(
  1839.                         if (t.settings.fix_ie_paragraphs) {
  1840.                             nl = e.getElementsByTagName("DIV");
  1841.                             for (i = nl.length - 1; i >= 0; i--) {
  1842.                                 n = nl[i];
  1843.  
  1844.                                 // Is it a temp div
  1845.                                 if (n.mce_tmp) {
  1846.                                     // Create new paragraph
  1847.                                     p = t.doc.createElement('p');
  1848.  
  1849.                                     // Copy all attributes
  1850.                                     n.cloneNode(false).outerHTML.replace(/([a-z0-9\-_]+)=/gi, function(a, b) {
  1851.                                         var v;
  1852.  
  1853.                                         if (b !== 'mce_tmp') {
  1854.                                             v = n.getAttribute(b);
  1855.  
  1856.                                             if (!v && b === 'class')
  1857.                                                 v = n.className;
  1858.  
  1859.                                             p.setAttribute(b, v);
  1860.                                         }
  1861.                                     });
  1862.  
  1863.                                     // Append all children to new paragraph
  1864.                                     for (x = 0; x<n.childNodes.length; x++)
  1865.                                         p.appendChild(n.childNodes[x].cloneNode(true));
  1866.  
  1867.                                     // Replace div with new paragraph
  1868.                                     n.swapNode(p);
  1869.                                 }
  1870.                             }
  1871.                         }
  1872.                     }
  1873.                 } else
  1874.                     e.innerHTML = h;
  1875.  
  1876.                 return h;
  1877.             });
  1878.         },
  1879.  
  1880.         processHTML : function(h) {
  1881.             var t = this, s = t.settings, codeBlocks = [];
  1882.  
  1883.             if (!s.process_html)
  1884.                 return h;
  1885.  
  1886.             // Convert strong and em to b and i in FF since it can't handle them
  1887.             if (tinymce.isGecko) {
  1888.                 h = h.replace(/<(\/?)strong>|<strong( [^>]+)>/gi, '<$1b$2>');
  1889.                 h = h.replace(/<(\/?)em>|<em( [^>]+)>/gi, '<$1i$2>');
  1890.             } else if (isIE) {
  1891.                 h = h.replace(/&apos;/g, '''); // IE can't handle apos
  1892.                 h = h.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/gi, ''); // IE doesn't handle default values correct
  1893.             }
  1894.  
  1895.             // Fix some issues
  1896.             h = h.replace(/<a( )([^>]+)\/>|<a\/>/gi, '<a$1$2></a>'); // Force open
  1897.  
  1898.             // Store away src and href in mce_src and mce_href since browsers mess them up
  1899.             if (s.keep_values) {
  1900.                 // Wrap scripts and styles in comments for serialization purposes
  1901.                 if (/<script|noscript|style/i.test(h)) {
  1902.                     function trim(s) {
  1903.                         // Remove prefix and suffix code for element
  1904.                         s = s.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n');
  1905.                         s = s.replace(/^[\r\n]*|[\r\n]*$/g, '');
  1906.                         s = s.replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '');
  1907.                         s = s.replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
  1908.  
  1909.                         return s;
  1910.                     };
  1911.  
  1912.                     // Wrap the script contents in CDATA and keep them from executing
  1913.                     h = h.replace(/<script([^>]+|)>([\s\S]*?)<\/script>/gi, function(v, attribs, text) {
  1914.                         // Force type attribute
  1915.                         if (!attribs)
  1916.                             attribs = ' type="text/javascript"';
  1917.  
  1918.                         // Convert the src attribute of the scripts
  1919.                         attribs = attribs.replace(/src=\"([^\"]+)\"?/i, function(a, url) {
  1920.                             if (s.url_converter)
  1921.                                 url = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(url), 'src', 'script'));
  1922.  
  1923.                             return 'mce_src="' + url + '"';
  1924.                         });
  1925.  
  1926.                         // Wrap text contents
  1927.                         if (tinymce.trim(text)) {
  1928.                             codeBlocks.push(trim(text));
  1929.                             text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n// -->';
  1930.                         }
  1931.  
  1932.                         return '<mce:script' + attribs + '>' + text + '</mce:script>';
  1933.                     });
  1934.  
  1935.                     // Wrap style elements
  1936.                     h = h.replace(/<style([^>]+|)>([\s\S]*?)<\/style>/gi, function(v, attribs, text) {
  1937.                         // Wrap text contents
  1938.                         if (text) {
  1939.                             codeBlocks.push(trim(text));
  1940.                             text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n-->';
  1941.                         }
  1942.  
  1943.                         return '<mce:style' + attribs + '>' + text + '</mce:style><style ' + attribs + ' mce_bogus="1">' + text + '</style>';
  1944.                     });
  1945.  
  1946.                     // Wrap noscript elements
  1947.                     h = h.replace(/<noscript([^>]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) {
  1948.                         return '<mce:noscript' + attribs + '><!--' + t.encode(text).replace(/--/g, '--') + '--></mce:noscript>';
  1949.                     });
  1950.                 }
  1951.  
  1952.                 h = h.replace(/<!\[CDATA\[([\s\S]+)\]\]>/g, '<!--[CDATA[$1]]-->');
  1953.  
  1954.                 // Remove false bool attributes and force attributes into xhtml style attr="attr"
  1955.                 h = h.replace(/<([\w:]+) [^>]*(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)[^>]*>/gi, function(val) {
  1956.                     function handle(val, name, value) {
  1957.                         // Remove false/0 attribs
  1958.                         if (value === 'false' || value === '0')
  1959.                             return '';
  1960.  
  1961.                         return ' ' + name + '="' + name + '"';
  1962.                     };
  1963.  
  1964.                     val = val.replace(/ (checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)=[\"]([^\"]+)[\"]/gi, handle); // W3C
  1965.                     val = val.replace(/ (checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)=[\']([^\']+)[\']/gi, handle); // W3C
  1966.                     val = val.replace(/ (checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)=([^\s\"\'>]+)/gi, handle); // IE
  1967.                     val = val.replace(/ (checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)([\s>])/gi, ' $1="$1"$2'); // Force attr="attr"
  1968.  
  1969.                     return val;
  1970.                 });
  1971.  
  1972.                 // Process all tags with src, href or style
  1973.                 h = h.replace(/<([\w:]+) [^>]*(src|href|style|shape|coords)[^>]*>/gi, function(a, n) {
  1974.                     function handle(m, b, c) {
  1975.                         var u = c;
  1976.  
  1977.                         // Tag already got a mce_ version
  1978.                         if (a.indexOf('mce_' + b) != -1)
  1979.                             return m;
  1980.  
  1981.                         if (b == 'style') {
  1982.                             // No mce_style for elements with these since they might get resized by the user
  1983.                             if (t._isRes(c))
  1984.                                 return m;
  1985.  
  1986.                             // Parse and serialize the style to convert for example uppercase styles like "BORDER: 1px"
  1987.                             u = t.encode(t.serializeStyle(t.parseStyle(u)));
  1988.                         } else if (b != 'coords' && b != 'shape') {
  1989.                             if (s.url_converter)
  1990.                                 u = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(c), b, n));
  1991.                         }
  1992.  
  1993.                         return ' ' + b + '="' + c + '" mce_' + b + '="' + u + '"';
  1994.                     };
  1995.  
  1996.                     a = a.replace(/ (src|href|style|coords|shape)=[\"]([^\"]+)[\"]/gi, handle); // W3C
  1997.                     a = a.replace(/ (src|href|style|coords|shape)=[\']([^\']+)[\']/gi, handle); // W3C
  1998.  
  1999.                     return a.replace(/ (src|href|style|coords|shape)=([^\s\"\'>]+)/gi, handle); // IE
  2000.                 });
  2001.  
  2002.                 // Restore script blocks
  2003.                 h = h.replace(/MCE_SCRIPT:([0-9]+)/g, function(val, idx) {
  2004.                     return codeBlocks[idx];
  2005.                 });
  2006.             }
  2007.  
  2008.             return h;
  2009.         },
  2010.  
  2011.         getOuterHTML : function(e) {
  2012.             var d;
  2013.  
  2014.             e = this.get(e);
  2015.  
  2016.             if (!e)
  2017.                 return null;
  2018.  
  2019.             if (e.outerHTML !== undefined)
  2020.                 return e.outerHTML;
  2021.  
  2022.             d = (e.ownerDocument || this.doc).createElement("body");
  2023.             d.appendChild(e.cloneNode(true));
  2024.  
  2025.             return d.innerHTML;
  2026.         },
  2027.  
  2028.         setOuterHTML : function(e, h, d) {
  2029.             var t = this;
  2030.  
  2031.             function setHTML(e, h, d) {
  2032.                 var n, tp;
  2033.  
  2034.                 tp = d.createElement("body");
  2035.                 tp.innerHTML = h;
  2036.  
  2037.                 n = tp.lastChild;
  2038.                 while (n) {
  2039.                     t.insertAfter(n.cloneNode(true), e);
  2040.                     n = n.previousSibling;
  2041.                 }
  2042.  
  2043.                 t.remove(e);
  2044.             };
  2045.  
  2046.             return this.run(e, function(e) {
  2047.                 e = t.get(e);
  2048.  
  2049.                 // Only set HTML on elements
  2050.                 if (e.nodeType == 1) {
  2051.                     d = d || e.ownerDocument || t.doc;
  2052.  
  2053.                     if (isIE) {
  2054.                         try {
  2055.                             // Try outerHTML for IE it sometimes produces an unknown runtime error
  2056.                             if (isIE && e.nodeType == 1)
  2057.                                 e.outerHTML = h;
  2058.                             else
  2059.                                 setHTML(e, h, d);
  2060.                         } catch (ex) {
  2061.                             // Fix for unknown runtime error
  2062.                             setHTML(e, h, d);
  2063.                         }
  2064.                     } else
  2065.                         setHTML(e, h, d);
  2066.                 }
  2067.             });
  2068.         },
  2069.  
  2070.         decode : function(s) {
  2071.             var e, n, v;
  2072.  
  2073.             // Look for entities to decode
  2074.             if (/&[^;]+;/.test(s)) {
  2075.                 // Decode the entities using a div element not super efficient but less code
  2076.                 e = this.doc.createElement("div");
  2077.                 e.innerHTML = s;
  2078.                 n = e.firstChild;
  2079.                 v = '';
  2080.  
  2081.                 if (n) {
  2082.                     do {
  2083.                         v += n.nodeValue;
  2084.                     } while (n.nextSibling);
  2085.                 }
  2086.  
  2087.                 return v || s;
  2088.             }
  2089.  
  2090.             return s;
  2091.         },
  2092.  
  2093.         encode : function(s) {
  2094.             return s ? ('' + s).replace(/[<>&\"]/g, function (c, b) {
  2095.                 switch (c) {
  2096.                     case '&':
  2097.                         return '&amp;';
  2098.  
  2099.                     case '"':
  2100.                         return '&quot;';
  2101.  
  2102.                     case '<':
  2103.                         return '&lt;';
  2104.  
  2105.                     case '>':
  2106.                         return '&gt;';
  2107.                 }
  2108.  
  2109.                 return c;
  2110.             }) : s;
  2111.         },
  2112.  
  2113.         insertAfter : function(n, r) {
  2114.             var t = this;
  2115.  
  2116.             r = t.get(r);
  2117.  
  2118.             return this.run(n, function(n) {
  2119.                 var p, ns;
  2120.  
  2121.                 p = r.parentNode;
  2122.                 ns = r.nextSibling;
  2123.  
  2124.                 if (ns)
  2125.                     p.insertBefore(n, ns);
  2126.                 else
  2127.                     p.appendChild(n);
  2128.  
  2129.                 return n;
  2130.             });
  2131.         },
  2132.  
  2133.         isBlock : function(n) {
  2134.             if (n.nodeType && n.nodeType !== 1)
  2135.                 return false;
  2136.  
  2137.             n = n.nodeName || n;
  2138.  
  2139.             return /^(H[1-6]|HR|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TH|TBODY|TR|TD|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP)$/.test(n);
  2140.         },
  2141.  
  2142.         replace : function(n, o, k) {
  2143.             var t = this;
  2144.  
  2145.             if (is(o, 'array'))
  2146.                 n = n.cloneNode(true);
  2147.  
  2148.             return t.run(o, function(o) {
  2149.                 if (k) {
  2150.                     each(o.childNodes, function(c) {
  2151.                         n.appendChild(c.cloneNode(true));
  2152.                     });
  2153.                 }
  2154.  
  2155.                 // Fix IE psuedo leak for elements since replacing elements if fairly common
  2156.                 // Will break parentNode for some unknown reason
  2157.                 if (t.fixPsuedoLeaks && o.nodeType === 1) {
  2158.                     o.parentNode.insertBefore(n, o);
  2159.                     t.remove(o);
  2160.                     return n;
  2161.                 }
  2162.  
  2163.                 return o.parentNode.replaceChild(n, o);
  2164.             });
  2165.         },
  2166.  
  2167.         findCommonAncestor : function(a, b) {
  2168.             var ps = a, pe;
  2169.  
  2170.             while (ps) {
  2171.                 pe = b;
  2172.  
  2173.                 while (pe && ps != pe)
  2174.                     pe = pe.parentNode;
  2175.  
  2176.                 if (ps == pe)
  2177.                     break;
  2178.  
  2179.                 ps = ps.parentNode;
  2180.             }
  2181.  
  2182.             if (!ps && a.ownerDocument)
  2183.                 return a.ownerDocument.documentElement;
  2184.  
  2185.             return ps;
  2186.         },
  2187.  
  2188.         toHex : function(s) {
  2189.             var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  2190.  
  2191.             function hex(s) {
  2192.                 s = parseInt(s).toString(16);
  2193.  
  2194.                 return s.length > 1 ? s : '0' + s; // 0 -> 00
  2195.             };
  2196.  
  2197.             if (c) {
  2198.                 s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  2199.  
  2200.                 return s;
  2201.             }
  2202.  
  2203.             return s;
  2204.         },
  2205.  
  2206.         getClasses : function() {
  2207.             var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  2208.  
  2209.             if (t.classes)
  2210.                 return t.classes;
  2211.  
  2212.             function addClasses(s) {
  2213.                 // IE style imports
  2214.                 each(s.imports, function(r) {
  2215.                     addClasses(r);
  2216.                 });
  2217.  
  2218.                 each(s.cssRules || s.rules, function(r) {
  2219.                     // Real type or fake it on IE
  2220.                     switch (r.type || 1) {
  2221.                         // Rule
  2222.                         case 1:
  2223.                             if (r.selectorText) {
  2224.                                 each(r.selectorText.split(','), function(v) {
  2225.                                     v = v.replace(/^\s*|\s*$|^\s\./g, "");
  2226.  
  2227.                                     // Is internal or it doesn't contain a class
  2228.                                     if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  2229.                                         return;
  2230.  
  2231.                                     // Remove everything but class name
  2232.                                     ov = v;
  2233.                                     v = v.replace(/.*\.([a-z0-9_\-]+).*/i, '$1');
  2234.  
  2235.                                     // Filter classes
  2236.                                     if (f && !(v = f(v, ov)))
  2237.                                         return;
  2238.  
  2239.                                     if (!lo[v]) {
  2240.                                         cl.push({'class' : v});
  2241.                                         lo[v] = 1;
  2242.                                     }
  2243.                                 });
  2244.                             }
  2245.                             break;
  2246.  
  2247.                         // Import
  2248.                         case 3:
  2249.                             addClasses(r.styleSheet);
  2250.                             break;
  2251.                     }
  2252.                 });
  2253.             };
  2254.  
  2255.             try {
  2256.                 each(t.doc.styleSheets, addClasses);
  2257.             } catch (ex) {
  2258.                 // Ignore
  2259.             }
  2260.  
  2261.             if (cl.length > 0)
  2262.                 t.classes = cl;
  2263.  
  2264.             return cl;
  2265.         },
  2266.  
  2267.         run : function(e, f, s) {
  2268.             var t = this, o;
  2269.  
  2270.             if (t.doc && typeof(e) === 'string')
  2271.                 e = t.get(e);
  2272.  
  2273.             if (!e)
  2274.                 return false;
  2275.  
  2276.             s = s || this;
  2277.             if (!e.nodeType && (e.length || e.length === 0)) {
  2278.                 o = [];
  2279.  
  2280.                 each(e, function(e, i) {
  2281.                     if (e) {
  2282.                         if (typeof(e) == 'string')
  2283.                             e = t.doc.getElementById(e);
  2284.  
  2285.                         o.push(f.call(s, e, i));
  2286.                     }
  2287.                 });
  2288.  
  2289.                 return o;
  2290.             }
  2291.  
  2292.             return f.call(s, e);
  2293.         },
  2294.  
  2295.         getAttribs : function(n) {
  2296.             var o;
  2297.  
  2298.             n = this.get(n);
  2299.  
  2300.             if (!n)
  2301.                 return [];
  2302.  
  2303.             if (isIE) {
  2304.                 o = [];
  2305.  
  2306.                 // Object will throw exception in IE
  2307.                 if (n.nodeName == 'OBJECT')
  2308.                     return n.attributes;
  2309.  
  2310.                 // IE doesn't keep the selected attribute if you clone option elements
  2311.                 if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  2312.                     o.push({specified : 1, nodeName : 'selected'});
  2313.  
  2314.                 // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  2315.                 n.cloneNode(false).outerHTML.replace(/<\/?[\w:]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=\w+|>/gi, '').replace(/[\w:]+/gi, function(a) {
  2316.                     o.push({specified : 1, nodeName : a});
  2317.                 });
  2318.  
  2319.                 return o;
  2320.             }
  2321.  
  2322.             return n.attributes;
  2323.         },
  2324.  
  2325.         destroy : function(s) {
  2326.             var t = this;
  2327.  
  2328.             if (t.events)
  2329.                 t.events.destroy();
  2330.  
  2331.             t.win = t.doc = t.root = t.events = null;
  2332.  
  2333.             // Manual destroy then remove unload handler
  2334.             if (!s)
  2335.                 tinymce.removeUnload(t.destroy);
  2336.         },
  2337.  
  2338.         createRng : function() {
  2339.             var d = this.doc;
  2340.  
  2341.             return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  2342.         },
  2343.  
  2344.         split : function(pe, e, re) {
  2345.             var t = this, r = t.createRng(), bef, aft, pa;
  2346.  
  2347.             // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sence
  2348.             // but we don't want that in our code since it serves no purpose
  2349.             // For example if this is chopped:
  2350.             //   <p>text 1<span><b>CHOP</b></span>text 2</p>
  2351.             // would produce:
  2352.             //   <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  2353.             // this function will then trim of empty edges and produce:
  2354.             //   <p>text 1</p><b>CHOP</b><p>text 2</p>
  2355.             function trimEdge(n, na) {
  2356.                 n = n[na];
  2357.  
  2358.                 if (n && n[na] && n[na].nodeType == 1 && isEmpty(n[na]))
  2359.                     t.remove(n[na]);
  2360.             };
  2361.  
  2362.             function isEmpty(n) {
  2363.                 n = t.getOuterHTML(n);
  2364.                 n = n.replace(/<(img|hr|table)/gi, '-'); // Keep these convert them to - chars
  2365.                 n = n.replace(/<[^>]+>/g, ''); // Remove all tags
  2366.  
  2367.                 return n.replace(/[ \t\r\n]+|&nbsp;| /g, '') == '';
  2368.             };
  2369.  
  2370.             // Added until Gecko can create real HTML documents using implementation.createHTMLDocument
  2371.             // this is to future proof it if Gecko decides to implement the error checking for range methods.
  2372.             function nodeIndex(n) {
  2373.                 var i = 0;
  2374.  
  2375.                 while (n.previousSibling) {
  2376.                     i++;
  2377.                     n = n.previousSibling;
  2378.                 }
  2379.  
  2380.                 return i;
  2381.             };
  2382.  
  2383.             if (pe && e) {
  2384.                 // Get before chunk
  2385.                 r.setStart(pe.parentNode, nodeIndex(pe));
  2386.                 r.setEnd(e.parentNode, nodeIndex(e));
  2387.                 bef = r.extractContents();
  2388.  
  2389.                 // Get after chunk
  2390.                 r = t.createRng();
  2391.                 r.setStart(e.parentNode, nodeIndex(e) + 1);
  2392.                 r.setEnd(pe.parentNode, nodeIndex(pe) + 1);
  2393.                 aft = r.extractContents();
  2394.  
  2395.                 // Insert chunks and remove parent
  2396.                 pa = pe.parentNode;
  2397.  
  2398.                 // Remove right side edge of the before contents
  2399.                 trimEdge(bef, 'lastChild');
  2400.  
  2401.                 if (!isEmpty(bef))
  2402.                     pa.insertBefore(bef, pe);
  2403.  
  2404.                 if (re)
  2405.                     pa.replaceChild(re, e);
  2406.                 else
  2407.                     pa.insertBefore(e, pe);
  2408.  
  2409.                 // Remove left site edge of the after contents
  2410.                 trimEdge(aft, 'firstChild');
  2411.  
  2412.                 if (!isEmpty(aft))
  2413.                     pa.insertBefore(aft, pe);
  2414.  
  2415.                 t.remove(pe);
  2416.  
  2417.                 return re || e;
  2418.             }
  2419.         },
  2420.  
  2421.         bind : function(target, name, func, scope) {
  2422.             var t = this;
  2423.  
  2424.             if (!t.events)
  2425.                 t.events = new tinymce.dom.EventUtils();
  2426.  
  2427.             return t.events.add(target, name, func, scope || this);
  2428.         },
  2429.  
  2430.         unbind : function(target, name, func) {
  2431.             var t = this;
  2432.  
  2433.             if (!t.events)
  2434.                 t.events = new tinymce.dom.EventUtils();
  2435.  
  2436.             return t.events.remove(target, name, func);
  2437.         },
  2438.  
  2439.  
  2440.         _findSib : function(node, selector, name) {
  2441.             var t = this, f = selector;
  2442.  
  2443.             if (node) {
  2444.                 // If expression make a function of it using is
  2445.                 if (is(f, 'string')) {
  2446.                     f = function(node) {
  2447.                         return t.is(node, selector);
  2448.                     };
  2449.                 }
  2450.  
  2451.                 // Loop all siblings
  2452.                 for (node = node[name]; node; node = node[name]) {
  2453.                     if (f(node))
  2454.                         return node;
  2455.                 }
  2456.             }
  2457.  
  2458.             return null;
  2459.         },
  2460.  
  2461.         _isRes : function(c) {
  2462.             // Is live resizble element
  2463.             return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  2464.         }
  2465.  
  2466.         /*
  2467.         walk : function(n, f, s) {
  2468.             var d = this.doc, w;
  2469.  
  2470.             if (d.createTreeWalker) {
  2471.                 w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  2472.  
  2473.                 while ((n = w.nextNode()) != null)
  2474.                     f.call(s || this, n);
  2475.             } else
  2476.                 tinymce.walk(n, f, 'childNodes', s);
  2477.         }
  2478.         */
  2479.  
  2480.         /*
  2481.         toRGB : function(s) {
  2482.             var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  2483.  
  2484.             if (c) {
  2485.                 // #FFF -> #FFFFFF
  2486.                 if (!is(c[3]))
  2487.                     c[3] = c[2] = c[1];
  2488.  
  2489.                 return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  2490.             }
  2491.  
  2492.             return s;
  2493.         }
  2494.         */
  2495.     });
  2496.  
  2497.     tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  2498. })(tinymce);
  2499. (function(ns) {
  2500.     // Traverse constants
  2501.     var EXTRACT = 0, CLONE = 1, DELETE = 2, extend = tinymce.extend;
  2502.  
  2503.     function indexOf(child, parent) {
  2504.         var i, node;
  2505.  
  2506.         if (child.parentNode != parent)
  2507.             return -1;
  2508.  
  2509.         for (node = parent.firstChild, i = 0; node != child; node = node.nextSibling)
  2510.             i++;
  2511.  
  2512.         return i;
  2513.     };
  2514.  
  2515.     function nodeIndex(n) {
  2516.         var i = 0;
  2517.  
  2518.         while (n.previousSibling) {
  2519.             i++;
  2520.             n = n.previousSibling;
  2521.         }
  2522.  
  2523.         return i;
  2524.     };
  2525.  
  2526.     function getSelectedNode(container, offset) {
  2527.         var child;
  2528.  
  2529.         if (container.nodeType == 3 /* TEXT_NODE */)
  2530.             return container;
  2531.  
  2532.         if (offset < 0)
  2533.             return container;
  2534.  
  2535.         child = container.firstChild;
  2536.         while (child != null && offset > 0) {
  2537.             --offset;
  2538.             child = child.nextSibling;
  2539.         }
  2540.  
  2541.         if (child != null)
  2542.             return child;
  2543.  
  2544.         return container;
  2545.     };
  2546.  
  2547.     // Range constructor
  2548.     function Range(dom) {
  2549.         var d = dom.doc;
  2550.  
  2551.         extend(this, {
  2552.             dom : dom,
  2553.  
  2554.             // Inital states
  2555.             startContainer : d,
  2556.             startOffset : 0,
  2557.             endContainer : d,
  2558.             endOffset : 0,
  2559.             collapsed : true,
  2560.             commonAncestorContainer : d,
  2561.  
  2562.             // Range constants
  2563.             START_TO_START : 0,
  2564.             START_TO_END : 1,
  2565.             END_TO_END : 2,
  2566.             END_TO_START : 3
  2567.         });
  2568.     };
  2569.  
  2570.     // Add range methods
  2571.     extend(Range.prototype, {
  2572.         setStart : function(n, o) {
  2573.             this._setEndPoint(true, n, o);
  2574.         },
  2575.  
  2576.         setEnd : function(n, o) {
  2577.             this._setEndPoint(false, n, o);
  2578.         },
  2579.  
  2580.         setStartBefore : function(n) {
  2581.             this.setStart(n.parentNode, nodeIndex(n));
  2582.         },
  2583.  
  2584.         setStartAfter : function(n) {
  2585.             this.setStart(n.parentNode, nodeIndex(n) + 1);
  2586.         },
  2587.  
  2588.         setEndBefore : function(n) {
  2589.             this.setEnd(n.parentNode, nodeIndex(n));
  2590.         },
  2591.  
  2592.         setEndAfter : function(n) {
  2593.             this.setEnd(n.parentNode, nodeIndex(n) + 1);
  2594.         },
  2595.  
  2596.         collapse : function(ts) {
  2597.             var t = this;
  2598.  
  2599.             if (ts) {
  2600.                 t.endContainer = t.startContainer;
  2601.                 t.endOffset = t.startOffset;
  2602.             } else {
  2603.                 t.startContainer = t.endContainer;
  2604.                 t.startOffset = t.endOffset;
  2605.             }
  2606.  
  2607.             t.collapsed = true;
  2608.         },
  2609.  
  2610.         selectNode : function(n) {
  2611.             this.setStartBefore(n);
  2612.             this.setEndAfter(n);
  2613.         },
  2614.  
  2615.         selectNodeContents : function(n) {
  2616.             this.setStart(n, 0);
  2617.             this.setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  2618.         },
  2619.  
  2620.         compareBoundaryPoints : function(h, r) {
  2621.             var t = this, sc = t.startContainer, so = t.startOffset, ec = t.endContainer, eo = t.endOffset;
  2622.  
  2623.             // Check START_TO_START
  2624.             if (h === 0)
  2625.                 return t._compareBoundaryPoints(sc, so, sc, so);
  2626.  
  2627.             // Check START_TO_END
  2628.             if (h === 1)
  2629.                 return t._compareBoundaryPoints(sc, so, ec, eo);
  2630.  
  2631.             // Check END_TO_END
  2632.             if (h === 2)
  2633.                 return t._compareBoundaryPoints(ec, eo, ec, eo);
  2634.  
  2635.             // Check END_TO_START
  2636.             if (h === 3)
  2637.                 return t._compareBoundaryPoints(ec, eo, sc, so);
  2638.         },
  2639.  
  2640.         deleteContents : function() {
  2641.             this._traverse(DELETE);
  2642.         },
  2643.  
  2644.         extractContents : function() {
  2645.             return this._traverse(EXTRACT);
  2646.         },
  2647.  
  2648.         cloneContents : function() {
  2649.             return this._traverse(CLONE);
  2650.         },
  2651.  
  2652.         insertNode : function(n) {
  2653.             var t = this, nn, o;
  2654.  
  2655.             // Node is TEXT_NODE or CDATA
  2656.             if (n.nodeType === 3 || n.nodeType === 4) {
  2657.                 nn = t.startContainer.splitText(t.startOffset);
  2658.                 t.startContainer.parentNode.insertBefore(n, nn);
  2659.             } else {
  2660.                 // Insert element node
  2661.                 if (t.startContainer.childNodes.length > 0)
  2662.                     o = t.startContainer.childNodes[t.startOffset];
  2663.  
  2664.                 t.startContainer.insertBefore(n, o);
  2665.             }
  2666.         },
  2667.  
  2668.         surroundContents : function(n) {
  2669.             var t = this, f = t.extractContents();
  2670.  
  2671.             t.insertNode(n);
  2672.             n.appendChild(f);
  2673.             t.selectNode(n);
  2674.         },
  2675.  
  2676.         cloneRange : function() {
  2677.             var t = this;
  2678.  
  2679.             return extend(new Range(t.dom), {
  2680.                 startContainer : t.startContainer,
  2681.                 startOffset : t.startOffset,
  2682.                 endContainer : t.endContainer,
  2683.                 endOffset : t.endOffset,
  2684.                 collapsed : t.collapsed,
  2685.                 commonAncestorContainer : t.commonAncestorContainer
  2686.             });
  2687.         },
  2688.  
  2689. /*
  2690.         detach : function() {
  2691.             // Not implemented
  2692.         },
  2693. */
  2694.         // Internal methods
  2695.  
  2696.         _isCollapsed : function() {
  2697.             return (this.startContainer == this.endContainer && this.startOffset == this.endOffset);
  2698.         },
  2699.  
  2700.         _compareBoundaryPoints : function (containerA, offsetA, containerB, offsetB) {
  2701.             var c, offsetC, n, cmnRoot, childA, childB;
  2702.  
  2703.             // In the first case the boundary-points have the same container. A is before B 
  2704.             // if its offset is less than the offset of B, A is equal to B if its offset is 
  2705.             // equal to the offset of B, and A is after B if its offset is greater than the 
  2706.             // offset of B.
  2707.             if (containerA == containerB) {
  2708.                 if (offsetA == offsetB) {
  2709.                     return 0; // equal
  2710.                 } else if (offsetA < offsetB) {
  2711.                     return -1; // before
  2712.                 } else {
  2713.                     return 1; // after
  2714.                 }
  2715.             }
  2716.  
  2717.             // In the second case a child node C of the container of A is an ancestor 
  2718.             // container of B. In this case, A is before B if the offset of A is less than or 
  2719.             // equal to the index of the child node C and A is after B otherwise.
  2720.             c = containerB;
  2721.             while (c && c.parentNode != containerA) {
  2722.                 c = c.parentNode;
  2723.             }
  2724.             if (c) {
  2725.                 offsetC = 0;
  2726.                 n = containerA.firstChild;
  2727.  
  2728.                 while (n != c && offsetC < offsetA) {
  2729.                     offsetC++;
  2730.                     n = n.nextSibling;
  2731.                 }
  2732.  
  2733.                 if (offsetA <= offsetC) {
  2734.                     return -1; // before
  2735.                 } else {
  2736.                     return 1; // after
  2737.                 }
  2738.             }
  2739.  
  2740.             // In the third case a child node C of the container of B is an ancestor container 
  2741.             // of A. In this case, A is before B if the index of the child node C is less than 
  2742.             // the offset of B and A is after B otherwise.
  2743.             c = containerA;
  2744.             while (c && c.parentNode != containerB) {
  2745.                 c = c.parentNode;
  2746.             }
  2747.  
  2748.             if (c) {
  2749.                 offsetC = 0;
  2750.                 n = containerB.firstChild;
  2751.  
  2752.                 while (n != c && offsetC < offsetB) {
  2753.                     offsetC++;
  2754.                     n = n.nextSibling;
  2755.                 }
  2756.  
  2757.                 if (offsetC < offsetB) {
  2758.                     return -1; // before
  2759.                 } else {
  2760.                     return 1; // after
  2761.                 }
  2762.             }
  2763.  
  2764.             // In the fourth case, none of three other cases hold: the containers of A and B 
  2765.             // are siblings or descendants of sibling nodes. In this case, A is before B if 
  2766.             // the container of A is before the container of B in a pre-order traversal of the
  2767.             // Ranges' context tree and A is after B otherwise.
  2768.             cmnRoot = this.dom.findCommonAncestor(containerA, containerB);
  2769.             childA = containerA;
  2770.  
  2771.             while (childA && childA.parentNode != cmnRoot) {
  2772.                 childA = childA.parentNode;  
  2773.             }
  2774.  
  2775.             if (!childA) {
  2776.                 childA = cmnRoot;
  2777.             }
  2778.  
  2779.             childB = containerB;
  2780.             while (childB && childB.parentNode != cmnRoot) {
  2781.                 childB = childB.parentNode;
  2782.             }
  2783.  
  2784.             if (!childB) {
  2785.                 childB = cmnRoot;
  2786.             }
  2787.  
  2788.             if (childA == childB) {
  2789.                 return 0; // equal
  2790.             }
  2791.  
  2792.             n = cmnRoot.firstChild;
  2793.             while (n) {
  2794.                 if (n == childA) {
  2795.                     return -1; // before
  2796.                 }
  2797.  
  2798.                 if (n == childB) {
  2799.                     return 1; // after
  2800.                 }
  2801.  
  2802.                 n = n.nextSibling;
  2803.             }
  2804.         },
  2805.  
  2806.         _setEndPoint : function(st, n, o) {
  2807.             var t = this, ec, sc;
  2808.  
  2809.             if (st) {
  2810.                 t.startContainer = n;
  2811.                 t.startOffset = o;
  2812.             } else {
  2813.                 t.endContainer = n;
  2814.                 t.endOffset = o;
  2815.             }
  2816.  
  2817.             // If one boundary-point of a Range is set to have a root container 
  2818.             // other than the current one for the Range, the Range is collapsed to 
  2819.             // the new position. This enforces the restriction that both boundary-
  2820.             // points of a Range must have the same root container.
  2821.             ec = t.endContainer;
  2822.             while (ec.parentNode)
  2823.                 ec = ec.parentNode;
  2824.  
  2825.             sc = t.startContainer;
  2826.             while (sc.parentNode)
  2827.                 sc = sc.parentNode;
  2828.  
  2829.             if (sc != ec) {
  2830.                 t.collapse(st);
  2831.             } else {
  2832.                 // The start position of a Range is guaranteed to never be after the 
  2833.                 // end position. To enforce this restriction, if the start is set to 
  2834.                 // be at a position after the end, the Range is collapsed to that 
  2835.                 // position.
  2836.                 if (t._compareBoundaryPoints(t.startContainer, t.startOffset, t.endContainer, t.endOffset) > 0)
  2837.                     t.collapse(st);
  2838.             }
  2839.  
  2840.             t.collapsed = t._isCollapsed();
  2841.             t.commonAncestorContainer = t.dom.findCommonAncestor(t.startContainer, t.endContainer);
  2842.         },
  2843.  
  2844.         // This code is heavily "inspired" by the Apache Xerces implementation. I hope they don't mind. :)
  2845.  
  2846.         _traverse : function(how) {
  2847.             var t = this, c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  2848.  
  2849.             if (t.startContainer == t.endContainer)
  2850.                 return t._traverseSameContainer(how);
  2851.  
  2852.             for (c = t.endContainer, p = c.parentNode; p != null; c = p, p = p.parentNode) {
  2853.                 if (p == t.startContainer)
  2854.                     return t._traverseCommonStartContainer(c, how);
  2855.  
  2856.                 ++endContainerDepth;
  2857.             }
  2858.  
  2859.             for (c = t.startContainer, p = c.parentNode; p != null; c = p, p = p.parentNode) {
  2860.                 if (p == t.endContainer)
  2861.                     return t._traverseCommonEndContainer(c, how);
  2862.  
  2863.                 ++startContainerDepth;
  2864.             }
  2865.  
  2866.             depthDiff = startContainerDepth - endContainerDepth;
  2867.  
  2868.             startNode = t.startContainer;
  2869.             while (depthDiff > 0) {
  2870.                 startNode = startNode.parentNode;
  2871.                 depthDiff--;
  2872.             }
  2873.  
  2874.             endNode = t.endContainer;
  2875.             while (depthDiff < 0) {
  2876.                 endNode = endNode.parentNode;
  2877.                 depthDiff++;
  2878.             }
  2879.  
  2880.             // ascend the ancestor hierarchy until we have a common parent.
  2881.             for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  2882.                 startNode = sp;
  2883.                 endNode = ep;
  2884.             }
  2885.  
  2886.             return t._traverseCommonAncestors(startNode, endNode, how);
  2887.         },
  2888.  
  2889.         _traverseSameContainer : function(how) {
  2890.             var t = this, frag, s, sub, n, cnt, sibling, xferNode;
  2891.  
  2892.             if (how != DELETE)
  2893.                 frag = t.dom.doc.createDocumentFragment();
  2894.  
  2895.             // If selection is empty, just return the fragment
  2896.             if (t.startOffset == t.endOffset)
  2897.                 return frag;
  2898.  
  2899.             // Text node needs special case handling
  2900.             if (t.startContainer.nodeType == 3 /* TEXT_NODE */) {
  2901.                 // get the substring
  2902.                 s = t.startContainer.nodeValue;
  2903.                 sub = s.substring(t.startOffset, t.endOffset);
  2904.  
  2905.                 // set the original text node to its new value
  2906.                 if (how != CLONE) {
  2907.                     t.startContainer.deleteData(t.startOffset, t.endOffset - t.startOffset);
  2908.  
  2909.                     // Nothing is partially selected, so collapse to start point
  2910.                     t.collapse(true);
  2911.                 }
  2912.  
  2913.                 if (how == DELETE)
  2914.                     return null;
  2915.  
  2916.                 frag.appendChild(t.dom.doc.createTextNode(sub));
  2917.                 return frag;
  2918.             }
  2919.  
  2920.             // Copy nodes between the start/end offsets.
  2921.             n = getSelectedNode(t.startContainer, t.startOffset);
  2922.             cnt = t.endOffset - t.startOffset;
  2923.  
  2924.             while (cnt > 0) {
  2925.                 sibling = n.nextSibling;
  2926.                 xferNode = t._traverseFullySelected(n, how);
  2927.  
  2928.                 if (frag)
  2929.                     frag.appendChild( xferNode );
  2930.  
  2931.                 --cnt;
  2932.                 n = sibling;
  2933.             }
  2934.  
  2935.             // Nothing is partially selected, so collapse to start point
  2936.             if (how != CLONE)
  2937.                 t.collapse(true);
  2938.  
  2939.             return frag;
  2940.         },
  2941.  
  2942.         _traverseCommonStartContainer : function(endAncestor, how) {
  2943.             var t = this, frag, n, endIdx, cnt, sibling, xferNode;
  2944.  
  2945.             if (how != DELETE)
  2946.                 frag = t.dom.doc.createDocumentFragment();
  2947.  
  2948.             n = t._traverseRightBoundary(endAncestor, how);
  2949.  
  2950.             if (frag)
  2951.                 frag.appendChild(n);
  2952.  
  2953.             endIdx = indexOf(endAncestor, t.startContainer);
  2954.             cnt = endIdx - t.startOffset;
  2955.  
  2956.             if (cnt <= 0) {
  2957.                 // Collapse to just before the endAncestor, which 
  2958.                 // is partially selected.
  2959.                 if (how != CLONE) {
  2960.                     t.setEndBefore(endAncestor);
  2961.                     t.collapse(false);
  2962.                 }
  2963.  
  2964.                 return frag;
  2965.             }
  2966.  
  2967.             n = endAncestor.previousSibling;
  2968.             while (cnt > 0) {
  2969.                 sibling = n.previousSibling;
  2970.                 xferNode = t._traverseFullySelected(n, how);
  2971.  
  2972.                 if (frag)
  2973.                     frag.insertBefore(xferNode, frag.firstChild);
  2974.  
  2975.                 --cnt;
  2976.                 n = sibling;
  2977.             }
  2978.  
  2979.             // Collapse to just before the endAncestor, which 
  2980.             // is partially selected.
  2981.             if (how != CLONE) {
  2982.                 t.setEndBefore(endAncestor);
  2983.                 t.collapse(false);
  2984.             }
  2985.  
  2986.             return frag;
  2987.         },
  2988.  
  2989.         _traverseCommonEndContainer : function(startAncestor, how) {
  2990.             var t = this, frag, startIdx, n, cnt, sibling, xferNode;
  2991.  
  2992.             if (how != DELETE)
  2993.                 frag = t.dom.doc.createDocumentFragment();
  2994.  
  2995.             n = t._traverseLeftBoundary(startAncestor, how);
  2996.             if (frag)
  2997.                 frag.appendChild(n);
  2998.  
  2999.             startIdx = indexOf(startAncestor, t.endContainer);
  3000.             ++startIdx;  // Because we already traversed it....
  3001.  
  3002.             cnt = t.endOffset - startIdx;
  3003.             n = startAncestor.nextSibling;
  3004.             while (cnt > 0) {
  3005.                 sibling = n.nextSibling;
  3006.                 xferNode = t._traverseFullySelected(n, how);
  3007.  
  3008.                 if (frag)
  3009.                     frag.appendChild(xferNode);
  3010.  
  3011.                 --cnt;
  3012.                 n = sibling;
  3013.             }
  3014.  
  3015.             if (how != CLONE) {
  3016.                 t.setStartAfter(startAncestor);
  3017.                 t.collapse(true);
  3018.             }
  3019.  
  3020.             return frag;
  3021.         },
  3022.  
  3023.         _traverseCommonAncestors : function(startAncestor, endAncestor, how) {
  3024.             var t = this, n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  3025.  
  3026.             if (how != DELETE)
  3027.                 frag = t.dom.doc.createDocumentFragment();
  3028.  
  3029.             n = t._traverseLeftBoundary(startAncestor, how);
  3030.             if (frag)
  3031.                 frag.appendChild(n);
  3032.  
  3033.             commonParent = startAncestor.parentNode;
  3034.             startOffset = indexOf(startAncestor, commonParent);
  3035.             endOffset = indexOf(endAncestor, commonParent);
  3036.             ++startOffset;
  3037.  
  3038.             cnt = endOffset - startOffset;
  3039.             sibling = startAncestor.nextSibling;
  3040.  
  3041.             while (cnt > 0) {
  3042.                 nextSibling = sibling.nextSibling;
  3043.                 n = t._traverseFullySelected(sibling, how);
  3044.  
  3045.                 if (frag)
  3046.                     frag.appendChild(n);
  3047.  
  3048.                 sibling = nextSibling;
  3049.                 --cnt;
  3050.             }
  3051.  
  3052.             n = t._traverseRightBoundary(endAncestor, how);
  3053.  
  3054.             if (frag)
  3055.                 frag.appendChild(n);
  3056.  
  3057.             if (how != CLONE) {
  3058.                 t.setStartAfter(startAncestor);
  3059.                 t.collapse(true);
  3060.             }
  3061.  
  3062.             return frag;
  3063.         },
  3064.  
  3065.         _traverseRightBoundary : function(root, how) {
  3066.             var t = this, next = getSelectedNode(t.endContainer, t.endOffset - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent;
  3067.             var isFullySelected = next != t.endContainer;
  3068.  
  3069.             if (next == root)
  3070.                 return t._traverseNode(next, isFullySelected, false, how);
  3071.  
  3072.             parent = next.parentNode;
  3073.             clonedParent = t._traverseNode(parent, false, false, how);
  3074.  
  3075.             while (parent != null) {
  3076.                 while (next != null) {
  3077.                     prevSibling = next.previousSibling;
  3078.                     clonedChild = t._traverseNode(next, isFullySelected, false, how);
  3079.  
  3080.                     if (how != DELETE)
  3081.                         clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  3082.  
  3083.                     isFullySelected = true;
  3084.                     next = prevSibling;
  3085.                 }
  3086.  
  3087.                 if (parent == root)
  3088.                     return clonedParent;
  3089.  
  3090.                 next = parent.previousSibling;
  3091.                 parent = parent.parentNode;
  3092.  
  3093.                 clonedGrandParent = t._traverseNode(parent, false, false, how);
  3094.  
  3095.                 if (how != DELETE)
  3096.                     clonedGrandParent.appendChild(clonedParent);
  3097.  
  3098.                 clonedParent = clonedGrandParent;
  3099.             }
  3100.  
  3101.             // should never occur
  3102.             return null;
  3103.         },
  3104.  
  3105.         _traverseLeftBoundary : function(root, how) {
  3106.             var t = this, next = getSelectedNode(t.startContainer, t.startOffset);
  3107.             var isFullySelected = next != t.startContainer, parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  3108.  
  3109.             if (next == root)
  3110.                 return t._traverseNode(next, isFullySelected, true, how);
  3111.  
  3112.             parent = next.parentNode;
  3113.             clonedParent = t._traverseNode(parent, false, true, how);
  3114.  
  3115.             while (parent != null) {
  3116.                 while (next != null) {
  3117.                     nextSibling = next.nextSibling;
  3118.                     clonedChild = t._traverseNode(next, isFullySelected, true, how);
  3119.  
  3120.                     if (how != DELETE)
  3121.                         clonedParent.appendChild(clonedChild);
  3122.  
  3123.                     isFullySelected = true;
  3124.                     next = nextSibling;
  3125.                 }
  3126.  
  3127.                 if (parent == root)
  3128.                     return clonedParent;
  3129.  
  3130.                 next = parent.nextSibling;
  3131.                 parent = parent.parentNode;
  3132.  
  3133.                 clonedGrandParent = t._traverseNode(parent, false, true, how);
  3134.  
  3135.                 if (how != DELETE)
  3136.                     clonedGrandParent.appendChild(clonedParent);
  3137.  
  3138.                 clonedParent = clonedGrandParent;
  3139.             }
  3140.  
  3141.             // should never occur
  3142.             return null;
  3143.         },
  3144.  
  3145.         _traverseNode : function(n, isFullySelected, isLeft, how) {
  3146.             var t = this, txtValue, newNodeValue, oldNodeValue, offset, newNode;
  3147.  
  3148.             if (isFullySelected)
  3149.                 return t._traverseFullySelected(n, how);
  3150.  
  3151.             if (n.nodeType == 3 /* TEXT_NODE */) {
  3152.                 txtValue = n.nodeValue;
  3153.  
  3154.                 if (isLeft) {
  3155.                     offset = t.startOffset;
  3156.                     newNodeValue = txtValue.substring(offset);
  3157.                     oldNodeValue = txtValue.substring(0, offset);
  3158.                 } else {
  3159.                     offset = t.endOffset;
  3160.                     newNodeValue = txtValue.substring(0, offset);
  3161.                     oldNodeValue = txtValue.substring(offset);
  3162.                 }
  3163.  
  3164.                 if (how != CLONE)
  3165.                     n.nodeValue = oldNodeValue;
  3166.  
  3167.                 if (how == DELETE)
  3168.                     return null;
  3169.  
  3170.                 newNode = n.cloneNode(false);
  3171.                 newNode.nodeValue = newNodeValue;
  3172.  
  3173.                 return newNode;
  3174.             }
  3175.  
  3176.             if (how == DELETE)
  3177.                 return null;
  3178.  
  3179.             return n.cloneNode(false);
  3180.         },
  3181.  
  3182.         _traverseFullySelected : function(n, how) {
  3183.             var t = this;
  3184.  
  3185.             if (how != DELETE)
  3186.                 return how == CLONE ? n.cloneNode(true) : n;
  3187.  
  3188.             n.parentNode.removeChild(n);
  3189.             return null;
  3190.         }
  3191.     });
  3192.  
  3193.     ns.Range = Range;
  3194. })(tinymce.dom);
  3195. (function() {
  3196.     function Selection(selection) {
  3197.         var t = this, invisibleChar = '\uFEFF', range, lastIERng;
  3198.  
  3199.         function compareRanges(rng1, rng2) {
  3200.             if (rng1 && rng2) {
  3201.                 // Both are control ranges and the selected element matches
  3202.                 if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  3203.                     return 1;
  3204.  
  3205.                 // Both are text ranges and the range matches
  3206.                 if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  3207.                     return 1;
  3208.             }
  3209.  
  3210.             return 0;
  3211.         };
  3212.  
  3213.         function getRange() {
  3214.             var dom = selection.dom, ieRange = selection.getRng(), domRange = dom.createRng(), startPos, endPos, element, sc, ec, collapsed;
  3215.  
  3216.             function findIndex(element) {
  3217.                 var nl = element.parentNode.childNodes, i;
  3218.  
  3219.                 for (i = nl.length - 1; i >= 0; i--) {
  3220.                     if (nl[i] == element)
  3221.                         return i;
  3222.                 }
  3223.  
  3224.                 return -1;
  3225.             };
  3226.  
  3227.             function findEndPoint(start) {
  3228.                 var rng = ieRange.duplicate(), parent, i, nl, n, offset = 0, index = 0, pos, tmpRng;
  3229.  
  3230.                 // Insert marker character
  3231.                 rng.collapse(start);
  3232.                 parent = rng.parentElement();
  3233.                 rng.pasteHTML(invisibleChar); // Needs to be a pasteHTML instead of .text = since IE has a bug with nodeValue
  3234.  
  3235.                 // Find marker character
  3236.                 nl = parent.childNodes;
  3237.                 for (i = 0; i < nl.length; i++) {
  3238.                     n = nl[i];
  3239.  
  3240.                     // Calculate node index excluding text node fragmentation
  3241.                     if (i > 0 && (n.nodeType !== 3 || nl[i - 1].nodeType !== 3))
  3242.                         index++;
  3243.  
  3244.                     // If text node then calculate offset
  3245.                     if (n.nodeType === 3) {
  3246.                         // Look for marker
  3247.                         pos = n.nodeValue.indexOf(invisibleChar);
  3248.                         if (pos !== -1) {
  3249.                             offset += pos;
  3250.                             break;
  3251.                         }
  3252.  
  3253.                         offset += n.nodeValue.length;
  3254.                     } else
  3255.                         offset = 0;
  3256.                 }
  3257.  
  3258.                 // Remove marker character
  3259.                 rng.moveStart('character', -1);
  3260.                 rng.text = '';
  3261.  
  3262.                 return {index : index, offset : offset, parent : parent};
  3263.             };
  3264.  
  3265.             // If selection is outside the current document just return an empty range
  3266.             element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  3267.             if (element.ownerDocument != dom.doc)
  3268.                 return domRange;
  3269.  
  3270.             // Handle control selection or text selection of a image
  3271.             if (ieRange.item || !element.hasChildNodes()) {
  3272.                 domRange.setStart(element.parentNode, findIndex(element));
  3273.                 domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  3274.  
  3275.                 return domRange;
  3276.             }
  3277.  
  3278.             // Check collapsed state
  3279.             collapsed = selection.isCollapsed();
  3280.  
  3281.             // Find start and end pos index and offset
  3282.             startPos = findEndPoint(true);
  3283.             endPos = findEndPoint(false);
  3284.  
  3285.             // Normalize the elements to avoid fragmented dom
  3286.             startPos.parent.normalize();
  3287.             endPos.parent.normalize();
  3288.  
  3289.             // Set start container and offset
  3290.             sc = startPos.parent.childNodes[Math.min(startPos.index, startPos.parent.childNodes.length - 1)];
  3291.  
  3292.             if (sc.nodeType != 3)
  3293.                 domRange.setStart(startPos.parent, startPos.index);
  3294.             else
  3295.                 domRange.setStart(startPos.parent.childNodes[startPos.index], startPos.offset);
  3296.  
  3297.             // Set end container and offset
  3298.             ec = endPos.parent.childNodes[Math.min(endPos.index, endPos.parent.childNodes.length - 1)];
  3299.  
  3300.             if (ec.nodeType != 3) {
  3301.                 if (!collapsed)
  3302.                     endPos.index++;
  3303.  
  3304.                 domRange.setEnd(endPos.parent, endPos.index);
  3305.             } else
  3306.                 domRange.setEnd(endPos.parent.childNodes[endPos.index], endPos.offset);
  3307.  
  3308.             // If not collapsed then make sure offsets are valid
  3309.             if (!collapsed) {
  3310.                 sc = domRange.startContainer;
  3311.                 if (sc.nodeType == 1)
  3312.                     domRange.setStart(sc, Math.min(domRange.startOffset, sc.childNodes.length));
  3313.  
  3314.                 ec = domRange.endContainer;
  3315.                 if (ec.nodeType == 1)
  3316.                     domRange.setEnd(ec, Math.min(domRange.endOffset, ec.childNodes.length));
  3317.             }
  3318.  
  3319.             // Restore selection to new range
  3320.             t.addRange(domRange);
  3321.  
  3322.             return domRange;
  3323.         };
  3324.  
  3325.         this.addRange = function(rng) {
  3326.             var ieRng, body = selection.dom.doc.body, startPos, endPos, sc, so, ec, eo;
  3327.  
  3328.             // Setup some shorter versions
  3329.             sc = rng.startContainer;
  3330.             so = rng.startOffset;
  3331.             ec = rng.endContainer;
  3332.             eo = rng.endOffset;
  3333.             ieRng = body.createTextRange();
  3334.  
  3335.             // Find element
  3336.             sc = sc.nodeType == 1 ? sc.childNodes[Math.min(so, sc.childNodes.length - 1)] : sc;
  3337.             ec = ec.nodeType == 1 ? ec.childNodes[Math.min(so == eo ? eo : eo - 1, ec.childNodes.length - 1)] : ec;
  3338.  
  3339.             // Single element selection
  3340.             if (sc == ec && sc.nodeType == 1) {
  3341.                 // Make control selection for some elements
  3342.                 if (/^(IMG|TABLE)$/.test(sc.nodeName) && so != eo) {
  3343.                     ieRng = body.createControlRange();
  3344.                     ieRng.addElement(sc);
  3345.                 } else {
  3346.                     ieRng = body.createTextRange();
  3347.  
  3348.                     // Padd empty elements with invisible character
  3349.                     if (!sc.hasChildNodes() && sc.canHaveHTML)
  3350.                         sc.innerHTML = invisibleChar;
  3351.  
  3352.                     // Select element contents
  3353.                     ieRng.moveToElementText(sc);
  3354.  
  3355.                     // If it's only containing a padding remove it so the caret remains
  3356.                     if (sc.innerHTML == invisibleChar) {
  3357.                         ieRng.collapse(true);
  3358.                         sc.removeChild(sc.firstChild);
  3359.                     }
  3360.                 }
  3361.  
  3362.                 if (so == eo)
  3363.                     ieRng.collapse(eo <= rng.endContainer.childNodes.length - 1);
  3364.  
  3365.                 ieRng.select();
  3366.  
  3367.                 return;
  3368.             }
  3369.  
  3370.             function getCharPos(container, offset) {
  3371.                 var nodeVal, rng, pos;
  3372.  
  3373.                 if (container.nodeType != 3)
  3374.                     return -1;
  3375.  
  3376.                 nodeVal = container.nodeValue;
  3377.                 rng = body.createTextRange();
  3378.  
  3379.                 // Insert marker at offset position
  3380.                 container.nodeValue = nodeVal.substring(0, offset) + invisibleChar + nodeVal.substring(offset);
  3381.  
  3382.                 // Find char pos of marker and remove it
  3383.                 rng.moveToElementText(container.parentNode);
  3384.                 rng.findText(invisibleChar);
  3385.                 pos = Math.abs(rng.moveStart('character', -0xFFFFF));
  3386.                 container.nodeValue = nodeVal;
  3387.  
  3388.                 return pos;
  3389.             };
  3390.  
  3391.             // Collapsed range
  3392.             if (rng.collapsed) {
  3393.                 pos = getCharPos(sc, so);
  3394.  
  3395.                 ieRng = body.createTextRange();
  3396.                 ieRng.move('character', pos);
  3397.                 ieRng.select();
  3398.  
  3399.                 return;
  3400.             } else {
  3401.                 // If same text container
  3402.                 if (sc == ec && sc.nodeType == 3) {
  3403.                     startPos = getCharPos(sc, so);
  3404.  
  3405.                     ieRng = body.createTextRange();
  3406.                     ieRng.move('character', startPos);
  3407.                     ieRng.moveEnd('character', eo - so);
  3408.                     ieRng.select();
  3409.  
  3410.                     return;
  3411.                 }
  3412.  
  3413.                 // Get caret positions
  3414.                 startPos = getCharPos(sc, so);
  3415.                 endPos = getCharPos(ec, eo);
  3416.                 ieRng = body.createTextRange();
  3417.  
  3418.                 // Move start of range to start character position or start element
  3419.                 if (startPos == -1) {
  3420.                     ieRng.moveToElementText(sc);
  3421.                     startPos = 0;
  3422.                 } else
  3423.                     ieRng.move('character', startPos);
  3424.  
  3425.                 // Move end of range to end character position or end element
  3426.                 tmpRng = body.createTextRange();
  3427.  
  3428.                 if (endPos == -1)
  3429.                     tmpRng.moveToElementText(ec);
  3430.                 else
  3431.                     tmpRng.move('character', endPos);
  3432.  
  3433.                 ieRng.setEndPoint('EndToEnd', tmpRng);
  3434.                 ieRng.select();
  3435.  
  3436.                 return;
  3437.             }
  3438.         };
  3439.  
  3440.         this.getRangeAt = function() {
  3441.             // Setup new range if the cache is empty
  3442.             if (!range || !compareRanges(lastIERng, selection.getRng())) {
  3443.                 range = getRange();
  3444.  
  3445.                 // Store away text range for next call
  3446.                 lastIERng = selection.getRng();
  3447.             }
  3448.  
  3449.             // Return cached range
  3450.             return range;
  3451.         };
  3452.  
  3453.         this.destroy = function() {
  3454.             // Destroy cached range and last IE range to avoid memory leaks
  3455.             lastIERng = range = null;
  3456.         };
  3457.     };
  3458.  
  3459.     // Expose the selection object
  3460.     tinymce.dom.TridentSelection = Selection;
  3461. })();
  3462.  
  3463. /*
  3464.  * Sizzle CSS Selector Engine - v1.0
  3465.  *  Copyright 2009, The Dojo Foundation
  3466.  *  Released under the MIT, BSD, and GPL Licenses.
  3467.  *  More information: http://sizzlejs.com/
  3468.  */
  3469. (function(){
  3470.  
  3471. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
  3472.     done = 0,
  3473.     toString = Object.prototype.toString,
  3474.     hasDuplicate = false;
  3475.  
  3476. var Sizzle = function(selector, context, results, seed) {
  3477.     results = results || [];
  3478.     var origContext = context = context || document;
  3479.  
  3480.     if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  3481.         return [];
  3482.     }
  3483.  
  3484.     if ( !selector || typeof selector !== "string" ) {
  3485.         return results;
  3486.     }
  3487.  
  3488.     var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context);
  3489.  
  3490.     // Reset the position of the chunker regexp (start from head)
  3491.     chunker.lastIndex = 0;
  3492.  
  3493.     while ( (m = chunker.exec(selector)) !== null ) {
  3494.         parts.push( m[1] );
  3495.  
  3496.         if ( m[2] ) {
  3497.             extra = RegExp.rightContext;
  3498.             break;
  3499.         }
  3500.     }
  3501.  
  3502.     if ( parts.length > 1 && origPOS.exec( selector ) ) {
  3503.         if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  3504.             set = posProcess( parts[0] + parts[1], context );
  3505.         } else {
  3506.             set = Expr.relative[ parts[0] ] ?
  3507.                 [ context ] :
  3508.                 Sizzle( parts.shift(), context );
  3509.  
  3510.             while ( parts.length ) {
  3511.                 selector = parts.shift();
  3512.  
  3513.                 if ( Expr.relative[ selector ] )
  3514.                     selector += parts.shift();
  3515.  
  3516.                 set = posProcess( selector, set );
  3517.             }
  3518.         }
  3519.     } else {
  3520.         // Take a shortcut and set the context if the root selector is an ID
  3521.         // (but not if it'll be faster if the inner selector is an ID)
  3522.         if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  3523.                 Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  3524.             var ret = Sizzle.find( parts.shift(), context, contextXML );
  3525.             context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
  3526.         }
  3527.  
  3528.         if ( context ) {
  3529.             var ret = seed ?
  3530.                 { expr: parts.pop(), set: makeArray(seed) } :
  3531.                 Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  3532.             set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set;
  3533.  
  3534.             if ( parts.length > 0 ) {
  3535.                 checkSet = makeArray(set);
  3536.             } else {
  3537.                 prune = false;
  3538.             }
  3539.  
  3540.             while ( parts.length ) {
  3541.                 var cur = parts.pop(), pop = cur;
  3542.  
  3543.                 if ( !Expr.relative[ cur ] ) {
  3544.                     cur = "";
  3545.                 } else {
  3546.                     pop = parts.pop();
  3547.                 }
  3548.  
  3549.                 if ( pop == null ) {
  3550.                     pop = context;
  3551.                 }
  3552.  
  3553.                 Expr.relative[ cur ]( checkSet, pop, contextXML );
  3554.             }
  3555.         } else {
  3556.             checkSet = parts = [];
  3557.         }
  3558.     }
  3559.  
  3560.     if ( !checkSet ) {
  3561.         checkSet = set;
  3562.     }
  3563.  
  3564.     if ( !checkSet ) {
  3565.         throw "Syntax error, unrecognized expression: " + (cur || selector);
  3566.     }
  3567.  
  3568.     if ( toString.call(checkSet) === "[object Array]" ) {
  3569.         if ( !prune ) {
  3570.             results.push.apply( results, checkSet );
  3571.         } else if ( context && context.nodeType === 1 ) {
  3572.             for ( var i = 0; checkSet[i] != null; i++ ) {
  3573.                 if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
  3574.                     results.push( set[i] );
  3575.                 }
  3576.             }
  3577.         } else {
  3578.             for ( var i = 0; checkSet[i] != null; i++ ) {
  3579.                 if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  3580.                     results.push( set[i] );
  3581.                 }
  3582.             }
  3583.         }
  3584.     } else {
  3585.         makeArray( checkSet, results );
  3586.     }
  3587.  
  3588.     if ( extra ) {
  3589.         Sizzle( extra, origContext, results, seed );
  3590.         Sizzle.uniqueSort( results );
  3591.     }
  3592.  
  3593.     return results;
  3594. };
  3595.  
  3596. Sizzle.uniqueSort = function(results){
  3597.     if ( sortOrder ) {
  3598.         hasDuplicate = false;
  3599.         results.sort(sortOrder);
  3600.  
  3601.         if ( hasDuplicate ) {
  3602.             for ( var i = 1; i < results.length; i++ ) {
  3603.                 if ( results[i] === results[i-1] ) {
  3604.                     results.splice(i--, 1);
  3605.                 }
  3606.             }
  3607.         }
  3608.     }
  3609. };
  3610.  
  3611. Sizzle.matches = function(expr, set){
  3612.     return Sizzle(expr, null, null, set);
  3613. };
  3614.  
  3615. Sizzle.find = function(expr, context, isXML){
  3616.     var set, match;
  3617.  
  3618.     if ( !expr ) {
  3619.         return [];
  3620.     }
  3621.  
  3622.     for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
  3623.         var type = Expr.order[i], match;
  3624.  
  3625.         if ( (match = Expr.match[ type ].exec( expr )) ) {
  3626.             var left = RegExp.leftContext;
  3627.  
  3628.             if ( left.substr( left.length - 1 ) !== "\\" ) {
  3629.                 match[1] = (match[1] || "").replace(/\\/g, "");
  3630.                 set = Expr.find[ type ]( match, context, isXML );
  3631.                 if ( set != null ) {
  3632.                     expr = expr.replace( Expr.match[ type ], "" );
  3633.                     break;
  3634.                 }
  3635.             }
  3636.         }
  3637.     }
  3638.  
  3639.     if ( !set ) {
  3640.         set = context.getElementsByTagName("*");
  3641.     }
  3642.  
  3643.     return {set: set, expr: expr};
  3644. };
  3645.  
  3646. Sizzle.filter = function(expr, set, inplace, not){
  3647.     var old = expr, result = [], curLoop = set, match, anyFound,
  3648.         isXMLFilter = set && set[0] && isXML(set[0]);
  3649.  
  3650.     while ( expr && set.length ) {
  3651.         for ( var type in Expr.filter ) {
  3652.             if ( (match = Expr.match[ type ].exec( expr )) != null ) {
  3653.                 var filter = Expr.filter[ type ], found, item;
  3654.                 anyFound = false;
  3655.  
  3656.                 if ( curLoop == result ) {
  3657.                     result = [];
  3658.                 }
  3659.  
  3660.                 if ( Expr.preFilter[ type ] ) {
  3661.                     match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  3662.  
  3663.                     if ( !match ) {
  3664.                         anyFound = found = true;
  3665.                     } else if ( match === true ) {
  3666.                         continue;
  3667.                     }
  3668.                 }
  3669.  
  3670.                 if ( match ) {
  3671.                     for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
  3672.                         if ( item ) {
  3673.                             found = filter( item, match, i, curLoop );
  3674.                             var pass = not ^ !!found;
  3675.  
  3676.                             if ( inplace && found != null ) {
  3677.                                 if ( pass ) {
  3678.                                     anyFound = true;
  3679.                                 } else {
  3680.                                     curLoop[i] = false;
  3681.                                 }
  3682.                             } else if ( pass ) {
  3683.                                 result.push( item );
  3684.                                 anyFound = true;
  3685.                             }
  3686.                         }
  3687.                     }
  3688.                 }
  3689.  
  3690.                 if ( found !== undefined ) {
  3691.                     if ( !inplace ) {
  3692.                         curLoop = result;
  3693.                     }
  3694.  
  3695.                     expr = expr.replace( Expr.match[ type ], "" );
  3696.  
  3697.                     if ( !anyFound ) {
  3698.                         return [];
  3699.                     }
  3700.  
  3701.                     break;
  3702.                 }
  3703.             }
  3704.         }
  3705.  
  3706.         // Improper expression
  3707.         if ( expr == old ) {
  3708.             if ( anyFound == null ) {
  3709.                 throw "Syntax error, unrecognized expression: " + expr;
  3710.             } else {
  3711.                 break;
  3712.             }
  3713.         }
  3714.  
  3715.         old = expr;
  3716.     }
  3717.  
  3718.     return curLoop;
  3719. };
  3720.  
  3721. var Expr = Sizzle.selectors = {
  3722.     order: [ "ID", "NAME", "TAG" ],
  3723.     match: {
  3724.         ID: /#((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,
  3725.         CLASS: /\.((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,
  3726.         NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF_-]|\\.)+)['"]*\]/,
  3727.         ATTR: /\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
  3728.         TAG: /^((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)/,
  3729.         CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,
  3730.         POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,
  3731.         PSEUDO: /:((?:[\w\u00c0-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
  3732.     },
  3733.     attrMap: {
  3734.         "class": "className",
  3735.         "for": "htmlFor"
  3736.     },
  3737.     attrHandle: {
  3738.         href: function(elem){
  3739.             return elem.getAttribute("href");
  3740.         }
  3741.     },
  3742.     relative: {
  3743.         "+": function(checkSet, part, isXML){
  3744.             var isPartStr = typeof part === "string",
  3745.                 isTag = isPartStr && !/\W/.test(part),
  3746.                 isPartStrNotTag = isPartStr && !isTag;
  3747.  
  3748.             if ( isTag && !isXML ) {
  3749.                 part = part.toUpperCase();
  3750.             }
  3751.  
  3752.             for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  3753.                 if ( (elem = checkSet[i]) ) {
  3754.                     while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  3755.  
  3756.                     checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
  3757.                         elem || false :
  3758.                         elem === part;
  3759.                 }
  3760.             }
  3761.  
  3762.             if ( isPartStrNotTag ) {
  3763.                 Sizzle.filter( part, checkSet, true );
  3764.             }
  3765.         },
  3766.         ">": function(checkSet, part, isXML){
  3767.             var isPartStr = typeof part === "string";
  3768.  
  3769.             if ( isPartStr && !/\W/.test(part) ) {
  3770.                 part = isXML ? part : part.toUpperCase();
  3771.  
  3772.                 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  3773.                     var elem = checkSet[i];
  3774.                     if ( elem ) {
  3775.                         var parent = elem.parentNode;
  3776.                         checkSet[i] = parent.nodeName === part ? parent : false;
  3777.                     }
  3778.                 }
  3779.             } else {
  3780.                 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  3781.                     var elem = checkSet[i];
  3782.                     if ( elem ) {
  3783.                         checkSet[i] = isPartStr ?
  3784.                             elem.parentNode :
  3785.                             elem.parentNode === part;
  3786.                     }
  3787.                 }
  3788.  
  3789.                 if ( isPartStr ) {
  3790.                     Sizzle.filter( part, checkSet, true );
  3791.                 }
  3792.             }
  3793.         },
  3794.         "": function(checkSet, part, isXML){
  3795.             var doneName = done++, checkFn = dirCheck;
  3796.  
  3797.             if ( !part.match(/\W/) ) {
  3798.                 var nodeCheck = part = isXML ? part : part.toUpperCase();
  3799.                 checkFn = dirNodeCheck;
  3800.             }
  3801.  
  3802.             checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
  3803.         },
  3804.         "~": function(checkSet, part, isXML){
  3805.             var doneName = done++, checkFn = dirCheck;
  3806.  
  3807.             if ( typeof part === "string" && !part.match(/\W/) ) {
  3808.                 var nodeCheck = part = isXML ? part : part.toUpperCase();
  3809.                 checkFn = dirNodeCheck;
  3810.             }
  3811.  
  3812.             checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
  3813.         }
  3814.     },
  3815.     find: {
  3816.         ID: function(match, context, isXML){
  3817.             if ( typeof context.getElementById !== "undefined" && !isXML ) {
  3818.                 var m = context.getElementById(match[1]);
  3819.                 return m ? [m] : [];
  3820.             }
  3821.         },
  3822.         NAME: function(match, context, isXML){
  3823.             if ( typeof context.getElementsByName !== "undefined" ) {
  3824.                 var ret = [], results = context.getElementsByName(match[1]);
  3825.  
  3826.                 for ( var i = 0, l = results.length; i < l; i++ ) {
  3827.                     if ( results[i].getAttribute("name") === match[1] ) {
  3828.                         ret.push( results[i] );
  3829.                     }
  3830.                 }
  3831.  
  3832.                 return ret.length === 0 ? null : ret;
  3833.             }
  3834.         },
  3835.         TAG: function(match, context){
  3836.             return context.getElementsByTagName(match[1]);
  3837.         }
  3838.     },
  3839.     preFilter: {
  3840.         CLASS: function(match, curLoop, inplace, result, not, isXML){
  3841.             match = " " + match[1].replace(/\\/g, "") + " ";
  3842.  
  3843.             if ( isXML ) {
  3844.                 return match;
  3845.             }
  3846.  
  3847.             for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  3848.                 if ( elem ) {
  3849.                     if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) {
  3850.                         if ( !inplace )
  3851.                             result.push( elem );
  3852.                     } else if ( inplace ) {
  3853.                         curLoop[i] = false;
  3854.                     }
  3855.                 }
  3856.             }
  3857.  
  3858.             return false;
  3859.         },
  3860.         ID: function(match){
  3861.             return match[1].replace(/\\/g, "");
  3862.         },
  3863.         TAG: function(match, curLoop){
  3864.             for ( var i = 0; curLoop[i] === false; i++ ){}
  3865.             return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase();
  3866.         },
  3867.         CHILD: function(match){
  3868.             if ( match[1] == "nth" ) {
  3869.                 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  3870.                 var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  3871.                     match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
  3872.                     !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  3873.  
  3874.                 // calculate the numbers (first)n+(last) including if they are negative
  3875.                 match[2] = (test[1] + (test[2] || 1)) - 0;
  3876.                 match[3] = test[3] - 0;
  3877.             }
  3878.  
  3879.             // TODO: Move to normal caching system
  3880.             match[0] = done++;
  3881.  
  3882.             return match;
  3883.         },
  3884.         ATTR: function(match, curLoop, inplace, result, not, isXML){
  3885.             var name = match[1].replace(/\\/g, "");
  3886.  
  3887.             if ( !isXML && Expr.attrMap[name] ) {
  3888.                 match[1] = Expr.attrMap[name];
  3889.             }
  3890.  
  3891.             if ( match[2] === "~=" ) {
  3892.                 match[4] = " " + match[4] + " ";
  3893.             }
  3894.  
  3895.             return match;
  3896.         },
  3897.         PSEUDO: function(match, curLoop, inplace, result, not){
  3898.             if ( match[1] === "not" ) {
  3899.                 // If we're dealing with a complex expression, or a simple one
  3900.                 if ( match[3].match(chunker).length > 1 || /^\w/.test(match[3]) ) {
  3901.                     match[3] = Sizzle(match[3], null, null, curLoop);
  3902.                 } else {
  3903.                     var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  3904.                     if ( !inplace ) {
  3905.                         result.push.apply( result, ret );
  3906.                     }
  3907.                     return false;
  3908.                 }
  3909.             } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  3910.                 return true;
  3911.             }
  3912.  
  3913.             return match;
  3914.         },
  3915.         POS: function(match){
  3916.             match.unshift( true );
  3917.             return match;
  3918.         }
  3919.     },
  3920.     filters: {
  3921.         enabled: function(elem){
  3922.             return elem.disabled === false && elem.type !== "hidden";
  3923.         },
  3924.         disabled: function(elem){
  3925.             return elem.disabled === true;
  3926.         },
  3927.         checked: function(elem){
  3928.             return elem.checked === true;
  3929.         },
  3930.         selected: function(elem){
  3931.             // Accessing this property makes selected-by-default
  3932.             // options in Safari work properly
  3933.             elem.parentNode.selectedIndex;
  3934.             return elem.selected === true;
  3935.         },
  3936.         parent: function(elem){
  3937.             return !!elem.firstChild;
  3938.         },
  3939.         empty: function(elem){
  3940.             return !elem.firstChild;
  3941.         },
  3942.         has: function(elem, i, match){
  3943.             return !!Sizzle( match[3], elem ).length;
  3944.         },
  3945.         header: function(elem){
  3946.             return /h\d/i.test( elem.nodeName );
  3947.         },
  3948.         text: function(elem){
  3949.             return "text" === elem.type;
  3950.         },
  3951.         radio: function(elem){
  3952.             return "radio" === elem.type;
  3953.         },
  3954.         checkbox: function(elem){
  3955.             return "checkbox" === elem.type;
  3956.         },
  3957.         file: function(elem){
  3958.             return "file" === elem.type;
  3959.         },
  3960.         password: function(elem){
  3961.             return "password" === elem.type;
  3962.         },
  3963.         submit: function(elem){
  3964.             return "submit" === elem.type;
  3965.         },
  3966.         image: function(elem){
  3967.             return "image" === elem.type;
  3968.         },
  3969.         reset: function(elem){
  3970.             return "reset" === elem.type;
  3971.         },
  3972.         button: function(elem){
  3973.             return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
  3974.         },
  3975.         input: function(elem){
  3976.             return /input|select|textarea|button/i.test(elem.nodeName);
  3977.         }
  3978.     },
  3979.     setFilters: {
  3980.         first: function(elem, i){
  3981.             return i === 0;
  3982.         },
  3983.         last: function(elem, i, match, array){
  3984.             return i === array.length - 1;
  3985.         },
  3986.         even: function(elem, i){
  3987.             return i % 2 === 0;
  3988.         },
  3989.         odd: function(elem, i){
  3990.             return i % 2 === 1;
  3991.         },
  3992.         lt: function(elem, i, match){
  3993.             return i < match[3] - 0;
  3994.         },
  3995.         gt: function(elem, i, match){
  3996.             return i > match[3] - 0;
  3997.         },
  3998.         nth: function(elem, i, match){
  3999.             return match[3] - 0 == i;
  4000.         },
  4001.         eq: function(elem, i, match){
  4002.             return match[3] - 0 == i;
  4003.         }
  4004.     },
  4005.     filter: {
  4006.         PSEUDO: function(elem, match, i, array){
  4007.             var name = match[1], filter = Expr.filters[ name ];
  4008.  
  4009.             if ( filter ) {
  4010.                 return filter( elem, i, match, array );
  4011.             } else if ( name === "contains" ) {
  4012.                 return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
  4013.             } else if ( name === "not" ) {
  4014.                 var not = match[3];
  4015.  
  4016.                 for ( var i = 0, l = not.length; i < l; i++ ) {
  4017.                     if ( not[i] === elem ) {
  4018.                         return false;
  4019.                     }
  4020.                 }
  4021.  
  4022.                 return true;
  4023.             }
  4024.         },
  4025.         CHILD: function(elem, match){
  4026.             var type = match[1], node = elem;
  4027.             switch (type) {
  4028.                 case 'only':
  4029.                 case 'first':
  4030.                     while (node = node.previousSibling)  {
  4031.                         if ( node.nodeType === 1 ) return false;
  4032.                     }
  4033.                     if ( type == 'first') return true;
  4034.                     node = elem;
  4035.                 case 'last':
  4036.                     while (node = node.nextSibling)  {
  4037.                         if ( node.nodeType === 1 ) return false;
  4038.                     }
  4039.                     return true;
  4040.                 case 'nth':
  4041.                     var first = match[2], last = match[3];
  4042.  
  4043.                     if ( first == 1 && last == 0 ) {
  4044.                         return true;
  4045.                     }
  4046.  
  4047.                     var doneName = match[0],
  4048.                         parent = elem.parentNode;
  4049.  
  4050.                     if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
  4051.                         var count = 0;
  4052.                         for ( node = parent.firstChild; node; node = node.nextSibling ) {
  4053.                             if ( node.nodeType === 1 ) {
  4054.                                 node.nodeIndex = ++count;
  4055.                             }
  4056.                         } 
  4057.                         parent.sizcache = doneName;
  4058.                     }
  4059.  
  4060.                     var diff = elem.nodeIndex - last;
  4061.                     if ( first == 0 ) {
  4062.                         return diff == 0;
  4063.                     } else {
  4064.                         return ( diff % first == 0 && diff / first >= 0 );
  4065.                     }
  4066.             }
  4067.         },
  4068.         ID: function(elem, match){
  4069.             return elem.nodeType === 1 && elem.getAttribute("id") === match;
  4070.         },
  4071.         TAG: function(elem, match){
  4072.             return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
  4073.         },
  4074.         CLASS: function(elem, match){
  4075.             return (" " + (elem.className || elem.getAttribute("class")) + " ")
  4076.                 .indexOf( match ) > -1;
  4077.         },
  4078.         ATTR: function(elem, match){
  4079.             var name = match[1],
  4080.                 result = Expr.attrHandle[ name ] ?
  4081.                     Expr.attrHandle[ name ]( elem ) :
  4082.                     elem[ name ] != null ?
  4083.                         elem[ name ] :
  4084.                         elem.getAttribute( name ),
  4085.                 value = result + "",
  4086.                 type = match[2],
  4087.                 check = match[4];
  4088.  
  4089.             return result == null ?
  4090.                 type === "!=" :
  4091.                 type === "=" ?
  4092.                 value === check :
  4093.                 type === "*=" ?
  4094.                 value.indexOf(check) >= 0 :
  4095.                 type === "~=" ?
  4096.                 (" " + value + " ").indexOf(check) >= 0 :
  4097.                 !check ?
  4098.                 value && result !== false :
  4099.                 type === "!=" ?
  4100.                 value != check :
  4101.                 type === "^=" ?
  4102.                 value.indexOf(check) === 0 :
  4103.                 type === "$=" ?
  4104.                 value.substr(value.length - check.length) === check :
  4105.                 type === "|=" ?
  4106.                 value === check || value.substr(0, check.length + 1) === check + "-" :
  4107.                 false;
  4108.         },
  4109.         POS: function(elem, match, i, array){
  4110.             var name = match[2], filter = Expr.setFilters[ name ];
  4111.  
  4112.             if ( filter ) {
  4113.                 return filter( elem, i, match, array );
  4114.             }
  4115.         }
  4116.     }
  4117. };
  4118.  
  4119. var origPOS = Expr.match.POS;
  4120.  
  4121. for ( var type in Expr.match ) {
  4122.     Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
  4123. }
  4124.  
  4125. var makeArray = function(array, results) {
  4126.     array = Array.prototype.slice.call( array );
  4127.  
  4128.     if ( results ) {
  4129.         results.push.apply( results, array );
  4130.         return results;
  4131.     }
  4132.  
  4133.     return array;
  4134. };
  4135.  
  4136. // Perform a simple check to determine if the browser is capable of
  4137. // converting a NodeList to an array using builtin methods.
  4138. try {
  4139.     Array.prototype.slice.call( document.documentElement.childNodes );
  4140.  
  4141. // Provide a fallback method if it does not work
  4142. } catch(e){
  4143.     makeArray = function(array, results) {
  4144.         var ret = results || [];
  4145.  
  4146.         if ( toString.call(array) === "[object Array]" ) {
  4147.             Array.prototype.push.apply( ret, array );
  4148.         } else {
  4149.             if ( typeof array.length === "number" ) {
  4150.                 for ( var i = 0, l = array.length; i < l; i++ ) {
  4151.                     ret.push( array[i] );
  4152.                 }
  4153.             } else {
  4154.                 for ( var i = 0; array[i]; i++ ) {
  4155.                     ret.push( array[i] );
  4156.                 }
  4157.             }
  4158.         }
  4159.  
  4160.         return ret;
  4161.     };
  4162. }
  4163.  
  4164. var sortOrder;
  4165.  
  4166. if ( document.documentElement.compareDocumentPosition ) {
  4167.     sortOrder = function( a, b ) {
  4168.         var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
  4169.         if ( ret === 0 ) {
  4170.             hasDuplicate = true;
  4171.         }
  4172.         return ret;
  4173.     };
  4174. } else if ( "sourceIndex" in document.documentElement ) {
  4175.     sortOrder = function( a, b ) {
  4176.         var ret = a.sourceIndex - b.sourceIndex;
  4177.         if ( ret === 0 ) {
  4178.             hasDuplicate = true;
  4179.         }
  4180.         return ret;
  4181.     };
  4182. } else if ( document.createRange ) {
  4183.     sortOrder = function( a, b ) {
  4184.         var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
  4185.         aRange.setStart(a, 0);
  4186.         aRange.setEnd(a, 0);
  4187.         bRange.setStart(b, 0);
  4188.         bRange.setEnd(b, 0);
  4189.         var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
  4190.         if ( ret === 0 ) {
  4191.             hasDuplicate = true;
  4192.         }
  4193.         return ret;
  4194.     };
  4195. }
  4196.  
  4197. // Check to see if the browser returns elements by name when
  4198. // querying by getElementById (and provide a workaround)
  4199. (function(){
  4200.     // We're going to inject a fake input element with a specified name
  4201.     var form = document.createElement("div"),
  4202.         id = "script" + (new Date).getTime();
  4203.     form.innerHTML = "<a name='" + id + "'/>";
  4204.  
  4205.     // Inject it into the root element, check its status, and remove it quickly
  4206.     var root = document.documentElement;
  4207.     root.insertBefore( form, root.firstChild );
  4208.  
  4209.     // The workaround has to do additional checks after a getElementById
  4210.     // Which slows things down for other browsers (hence the branching)
  4211.     if ( !!document.getElementById( id ) ) {
  4212.         Expr.find.ID = function(match, context, isXML){
  4213.             if ( typeof context.getElementById !== "undefined" && !isXML ) {
  4214.                 var m = context.getElementById(match[1]);
  4215.                 return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
  4216.             }
  4217.         };
  4218.  
  4219.         Expr.filter.ID = function(elem, match){
  4220.             var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  4221.             return elem.nodeType === 1 && node && node.nodeValue === match;
  4222.         };
  4223.     }
  4224.  
  4225.     root.removeChild( form );
  4226. })();
  4227.  
  4228. (function(){
  4229.     // Check to see if the browser returns only elements
  4230.     // when doing getElementsByTagName("*")
  4231.  
  4232.     // Create a fake element
  4233.     var div = document.createElement("div");
  4234.     div.appendChild( document.createComment("") );
  4235.  
  4236.     // Make sure no comments are found
  4237.     if ( div.getElementsByTagName("*").length > 0 ) {
  4238.         Expr.find.TAG = function(match, context){
  4239.             var results = context.getElementsByTagName(match[1]);
  4240.  
  4241.             // Filter out possible comments
  4242.             if ( match[1] === "*" ) {
  4243.                 var tmp = [];
  4244.  
  4245.                 for ( var i = 0; results[i]; i++ ) {
  4246.                     if ( results[i].nodeType === 1 ) {
  4247.                         tmp.push( results[i] );
  4248.                     }
  4249.                 }
  4250.  
  4251.                 results = tmp;
  4252.             }
  4253.  
  4254.             return results;
  4255.         };
  4256.     }
  4257.  
  4258.     // Check to see if an attribute returns normalized href attributes
  4259.     div.innerHTML = "<a href='#'></a>";
  4260.     if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  4261.             div.firstChild.getAttribute("href") !== "#" ) {
  4262.         Expr.attrHandle.href = function(elem){
  4263.             return elem.getAttribute("href", 2);
  4264.         };
  4265.     }
  4266. })();
  4267.  
  4268. if ( document.querySelectorAll ) (function(){
  4269.     var oldSizzle = Sizzle, div = document.createElement("div");
  4270.     div.innerHTML = "<p class='TEST'></p>";
  4271.  
  4272.     // Safari can't handle uppercase or unicode characters when
  4273.     // in quirks mode.
  4274.     if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  4275.         return;
  4276.     }
  4277.  
  4278.     Sizzle = function(query, context, extra, seed){
  4279.         context = context || document;
  4280.  
  4281.         // Only use querySelectorAll on non-XML documents
  4282.         // (ID selectors don't work in non-HTML documents)
  4283.         if ( !seed && context.nodeType === 9 && !isXML(context) ) {
  4284.             try {
  4285.                 return makeArray( context.querySelectorAll(query), extra );
  4286.             } catch(e){}
  4287.         }
  4288.  
  4289.         return oldSizzle(query, context, extra, seed);
  4290.     };
  4291.  
  4292.     for ( var prop in oldSizzle ) {
  4293.         Sizzle[ prop ] = oldSizzle[ prop ];
  4294.     }
  4295. })();
  4296.  
  4297. if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
  4298.     var div = document.createElement("div");
  4299.     div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  4300.  
  4301.     // Opera can't find a second classname (in 9.6)
  4302.     if ( div.getElementsByClassName("e").length === 0 )
  4303.         return;
  4304.  
  4305.     // Safari caches class attributes, doesn't catch changes (in 3.2)
  4306.     div.lastChild.className = "e";
  4307.  
  4308.     if ( div.getElementsByClassName("e").length === 1 )
  4309.         return;
  4310.  
  4311.     Expr.order.splice(1, 0, "CLASS");
  4312.     Expr.find.CLASS = function(match, context, isXML) {
  4313.         if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  4314.             return context.getElementsByClassName(match[1]);
  4315.         }
  4316.     };
  4317. })();
  4318.  
  4319. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  4320.     var sibDir = dir == "previousSibling" && !isXML;
  4321.     for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  4322.         var elem = checkSet[i];
  4323.         if ( elem ) {
  4324.             if ( sibDir && elem.nodeType === 1 ){
  4325.                 elem.sizcache = doneName;
  4326.                 elem.sizset = i;
  4327.             }
  4328.             elem = elem[dir];
  4329.             var match = false;
  4330.  
  4331.             while ( elem ) {
  4332.                 if ( elem.sizcache === doneName ) {
  4333.                     match = checkSet[elem.sizset];
  4334.                     break;
  4335.                 }
  4336.  
  4337.                 if ( elem.nodeType === 1 && !isXML ){
  4338.                     elem.sizcache = doneName;
  4339.                     elem.sizset = i;
  4340.                 }
  4341.  
  4342.                 if ( elem.nodeName === cur ) {
  4343.                     match = elem;
  4344.                     break;
  4345.                 }
  4346.  
  4347.                 elem = elem[dir];
  4348.             }
  4349.  
  4350.             checkSet[i] = match;
  4351.         }
  4352.     }
  4353. }
  4354.  
  4355. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  4356.     var sibDir = dir == "previousSibling" && !isXML;
  4357.     for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  4358.         var elem = checkSet[i];
  4359.         if ( elem ) {
  4360.             if ( sibDir && elem.nodeType === 1 ) {
  4361.                 elem.sizcache = doneName;
  4362.                 elem.sizset = i;
  4363.             }
  4364.             elem = elem[dir];
  4365.             var match = false;
  4366.  
  4367.             while ( elem ) {
  4368.                 if ( elem.sizcache === doneName ) {
  4369.                     match = checkSet[elem.sizset];
  4370.                     break;
  4371.                 }
  4372.  
  4373.                 if ( elem.nodeType === 1 ) {
  4374.                     if ( !isXML ) {
  4375.                         elem.sizcache = doneName;
  4376.                         elem.sizset = i;
  4377.                     }
  4378.                     if ( typeof cur !== "string" ) {
  4379.                         if ( elem === cur ) {
  4380.                             match = true;
  4381.                             break;
  4382.                         }
  4383.  
  4384.                     } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  4385.                         match = elem;
  4386.                         break;
  4387.                     }
  4388.                 }
  4389.  
  4390.                 elem = elem[dir];
  4391.             }
  4392.  
  4393.             checkSet[i] = match;
  4394.         }
  4395.     }
  4396. }
  4397.  
  4398. var contains = document.compareDocumentPosition ?  function(a, b){
  4399.     return a.compareDocumentPosition(b) & 16;
  4400. } : function(a, b){
  4401.     return a !== b && (a.contains ? a.contains(b) : true);
  4402. };
  4403.  
  4404. var isXML = function(elem){
  4405.     return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
  4406.         !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML";
  4407. };
  4408.  
  4409. var posProcess = function(selector, context){
  4410.     var tmpSet = [], later = "", match,
  4411.         root = context.nodeType ? [context] : context;
  4412.  
  4413.     // Position selectors must be done after the filter
  4414.     // And so must :not(positional) so we move all PSEUDOs to the end
  4415.     while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  4416.         later += match[0];
  4417.         selector = selector.replace( Expr.match.PSEUDO, "" );
  4418.     }
  4419.  
  4420.     selector = Expr.relative[selector] ? selector + "*" : selector;
  4421.  
  4422.     for ( var i = 0, l = root.length; i < l; i++ ) {
  4423.         Sizzle( selector, root[i], tmpSet );
  4424.     }
  4425.  
  4426.     return Sizzle.filter( later, tmpSet );
  4427. };
  4428.  
  4429. // EXPOSE
  4430.  
  4431. window.tinymce.dom.Sizzle = Sizzle;
  4432.  
  4433. })();
  4434.  
  4435. (function(tinymce) {
  4436.     // Shorten names
  4437.     var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event;
  4438.  
  4439.     tinymce.create('tinymce.dom.EventUtils', {
  4440.         EventUtils : function() {
  4441.             this.inits = [];
  4442.             this.events = [];
  4443.         },
  4444.  
  4445.         add : function(o, n, f, s) {
  4446.             var cb, t = this, el = t.events, r;
  4447.  
  4448.             if (n instanceof Array) {
  4449.                 r = [];
  4450.  
  4451.                 each(n, function(n) {
  4452.                     r.push(t.add(o, n, f, s));
  4453.                 });
  4454.  
  4455.                 return r;
  4456.             }
  4457.  
  4458.             // Handle array
  4459.             if (o && o.hasOwnProperty && o instanceof Array) {
  4460.                 r = [];
  4461.  
  4462.                 each(o, function(o) {
  4463.                     o = DOM.get(o);
  4464.                     r.push(t.add(o, n, f, s));
  4465.                 });
  4466.  
  4467.                 return r;
  4468.             }
  4469.  
  4470.             o = DOM.get(o);
  4471.  
  4472.             if (!o)
  4473.                 return;
  4474.  
  4475.             // Setup event callback
  4476.             cb = function(e) {
  4477.                 // Is all events disabled
  4478.                 if (t.disabled)
  4479.                     return;
  4480.  
  4481.                 e = e || window.event;
  4482.  
  4483.                 // Patch in target, preventDefault and stopPropagation in IE it's W3C valid
  4484.                 if (e && isIE) {
  4485.                     if (!e.target)
  4486.                         e.target = e.srcElement;
  4487.  
  4488.                     // Patch in preventDefault, stopPropagation methods for W3C compatibility
  4489.                     tinymce.extend(e, t._stoppers);
  4490.                 }
  4491.  
  4492.                 if (!s)
  4493.                     return f(e);
  4494.  
  4495.                 return f.call(s, e);
  4496.             };
  4497.  
  4498.             if (n == 'unload') {
  4499.                 tinymce.unloads.unshift({func : cb});
  4500.                 return cb;
  4501.             }
  4502.  
  4503.             if (n == 'init') {
  4504.                 if (t.domLoaded)
  4505.                     cb();
  4506.                 else
  4507.                     t.inits.push(cb);
  4508.  
  4509.                 return cb;
  4510.             }
  4511.  
  4512.             // Store away listener reference
  4513.             el.push({
  4514.                 obj : o,
  4515.                 name : n,
  4516.                 func : f,
  4517.                 cfunc : cb,
  4518.                 scope : s
  4519.             });
  4520.  
  4521.             t._add(o, n, cb);
  4522.  
  4523.             return f;
  4524.         },
  4525.  
  4526.         remove : function(o, n, f) {
  4527.             var t = this, a = t.events, s = false, r;
  4528.  
  4529.             // Handle array
  4530.             if (o && o.hasOwnProperty && o instanceof Array) {
  4531.                 r = [];
  4532.  
  4533.                 each(o, function(o) {
  4534.                     o = DOM.get(o);
  4535.                     r.push(t.remove(o, n, f));
  4536.                 });
  4537.  
  4538.                 return r;
  4539.             }
  4540.  
  4541.             o = DOM.get(o);
  4542.  
  4543.             each(a, function(e, i) {
  4544.                 if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) {
  4545.                     a.splice(i, 1);
  4546.                     t._remove(o, n, e.cfunc);
  4547.                     s = true;
  4548.                     return false;
  4549.                 }
  4550.             });
  4551.  
  4552.             return s;
  4553.         },
  4554.  
  4555.         clear : function(o) {
  4556.             var t = this, a = t.events, i, e;
  4557.  
  4558.             if (o) {
  4559.                 o = DOM.get(o);
  4560.  
  4561.                 for (i = a.length - 1; i >= 0; i--) {
  4562.                     e = a[i];
  4563.  
  4564.                     if (e.obj === o) {
  4565.                         t._remove(e.obj, e.name, e.cfunc);
  4566.                         e.obj = e.cfunc = null;
  4567.                         a.splice(i, 1);
  4568.                     }
  4569.                 }
  4570.             }
  4571.         },
  4572.  
  4573.         cancel : function(e) {
  4574.             if (!e)
  4575.                 return false;
  4576.  
  4577.             this.stop(e);
  4578.  
  4579.             return this.prevent(e);
  4580.         },
  4581.  
  4582.         stop : function(e) {
  4583.             if (e.stopPropagation)
  4584.                 e.stopPropagation();
  4585.             else
  4586.                 e.cancelBubble = true;
  4587.  
  4588.             return false;
  4589.         },
  4590.  
  4591.         prevent : function(e) {
  4592.             if (e.preventDefault)
  4593.                 e.preventDefault();
  4594.             else
  4595.                 e.returnValue = false;
  4596.  
  4597.             return false;
  4598.         },
  4599.  
  4600.         destroy : function() {
  4601.             var t = this;
  4602.  
  4603.             each(t.events, function(e, i) {
  4604.                 t._remove(e.obj, e.name, e.cfunc);
  4605.                 e.obj = e.cfunc = null;
  4606.             });
  4607.  
  4608.             t.events = [];
  4609.             t = null;
  4610.         },
  4611.  
  4612.         _add : function(o, n, f) {
  4613.             if (o.attachEvent)
  4614.                 o.attachEvent('on' + n, f);
  4615.             else if (o.addEventListener)
  4616.                 o.addEventListener(n, f, false);
  4617.             else
  4618.                 o['on' + n] = f;
  4619.         },
  4620.  
  4621.         _remove : function(o, n, f) {
  4622.             if (o) {
  4623.                 try {
  4624.                     if (o.detachEvent)
  4625.                         o.detachEvent('on' + n, f);
  4626.                     else if (o.removeEventListener)
  4627.                         o.removeEventListener(n, f, false);
  4628.                     else
  4629.                         o['on' + n] = null;
  4630.                 } catch (ex) {
  4631.                     // Might fail with permission denined on IE so we just ignore that
  4632.                 }
  4633.             }
  4634.         },
  4635.  
  4636.         _pageInit : function(win) {
  4637.             var t = this;
  4638.  
  4639.             // Keep it from running more than once
  4640.             if (t.domLoaded)
  4641.                 return;
  4642.  
  4643.             t.domLoaded = true;
  4644.  
  4645.             each(t.inits, function(c) {
  4646.                 c();
  4647.             });
  4648.  
  4649.             t.inits = [];
  4650.         },
  4651.  
  4652.         _wait : function(win) {
  4653.             var t = this, doc = win.document;
  4654.  
  4655.             // No need since the document is already loaded
  4656.             if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) {
  4657.                 t.domLoaded = 1;
  4658.                 return;
  4659.             }
  4660.  
  4661.             // Use IE method
  4662.             if (doc.attachEvent) {
  4663.                 doc.attachEvent("onreadystatechange", function() {
  4664.                     if (doc.readyState === "complete") {
  4665.                         doc.detachEvent("onreadystatechange", arguments.callee);
  4666.                         t._pageInit(win);
  4667.                     }
  4668.                 });
  4669.  
  4670.                 if (doc.documentElement.doScroll && win == win.top) {
  4671.                     (function() {
  4672.                         if (t.domLoaded)
  4673.                             return;
  4674.  
  4675.                         try {
  4676.                             // If IE is used, use the trick by Diego Perini
  4677.                             // http://javascript.nwbox.com/IEContentLoaded/
  4678.                             doc.documentElement.doScroll("left");
  4679.                         } catch (ex) {
  4680.                             setTimeout(arguments.callee, 0);
  4681.                             return;
  4682.                         }
  4683.  
  4684.                         t._pageInit(win);
  4685.                     })();
  4686.                 }
  4687.             } else if (doc.addEventListener) {
  4688.                 t._add(win, 'DOMContentLoaded', function() {
  4689.                     t._pageInit(win);
  4690.                 });
  4691.             }
  4692.  
  4693.             t._add(win, 'load', function() {
  4694.                 t._pageInit(win);
  4695.             });
  4696.         },
  4697.  
  4698.         _stoppers : {
  4699.             preventDefault :  function() {
  4700.                 this.returnValue = false;
  4701.             },
  4702.  
  4703.             stopPropagation : function() {
  4704.                 this.cancelBubble = true;
  4705.             }
  4706.         }
  4707.     });
  4708.  
  4709.     Event = tinymce.dom.Event = new tinymce.dom.EventUtils();
  4710.  
  4711.     // Dispatch DOM content loaded event for IE and Safari
  4712.     Event._wait(window);
  4713.  
  4714.     tinymce.addUnload(function() {
  4715.         Event.destroy();
  4716.     });
  4717. })(tinymce);
  4718. (function(tinymce) {
  4719.     var each = tinymce.each;
  4720.  
  4721.     tinymce.create('tinymce.dom.Element', {
  4722.         Element : function(id, s) {
  4723.             var t = this, dom, el;
  4724.  
  4725.             s = s || {};
  4726.             t.id = id;
  4727.             t.dom = dom = s.dom || tinymce.DOM;
  4728.             t.settings = s;
  4729.  
  4730.             // Only IE leaks DOM references, this is a lot faster
  4731.             if (!tinymce.isIE)
  4732.                 el = t.dom.get(t.id);
  4733.  
  4734.             each([
  4735.                 'getPos',
  4736.                 'getRect',
  4737.                 'getParent',
  4738.                 'add',
  4739.                 'setStyle',
  4740.                 'getStyle',
  4741.                 'setStyles',
  4742.                 'setAttrib',
  4743.                 'setAttribs',
  4744.                 'getAttrib',
  4745.                 'addClass',
  4746.                 'removeClass',
  4747.                 'hasClass',
  4748.                 'getOuterHTML',
  4749.                 'setOuterHTML',
  4750.                 'remove',
  4751.                 'show',
  4752.                 'hide',
  4753.                 'isHidden',
  4754.                 'setHTML',
  4755.                 'get'
  4756.             ], function(k) {
  4757.                 t[k] = function() {
  4758.                     var a = [id], i;
  4759.  
  4760.                     for (i = 0; i < arguments.length; i++)
  4761.                         a.push(arguments[i]);
  4762.  
  4763.                     a = dom[k].apply(dom, a);
  4764.                     t.update(k);
  4765.  
  4766.                     return a;
  4767.                 };
  4768.             });
  4769.         },
  4770.  
  4771.         on : function(n, f, s) {
  4772.             return tinymce.dom.Event.add(this.id, n, f, s);
  4773.         },
  4774.  
  4775.         getXY : function() {
  4776.             return {
  4777.                 x : parseInt(this.getStyle('left')),
  4778.                 y : parseInt(this.getStyle('top'))
  4779.             };
  4780.         },
  4781.  
  4782.         getSize : function() {
  4783.             var n = this.dom.get(this.id);
  4784.  
  4785.             return {
  4786.                 w : parseInt(this.getStyle('width') || n.clientWidth),
  4787.                 h : parseInt(this.getStyle('height') || n.clientHeight)
  4788.             };
  4789.         },
  4790.  
  4791.         moveTo : function(x, y) {
  4792.             this.setStyles({left : x, top : y});
  4793.         },
  4794.  
  4795.         moveBy : function(x, y) {
  4796.             var p = this.getXY();
  4797.  
  4798.             this.moveTo(p.x + x, p.y + y);
  4799.         },
  4800.  
  4801.         resizeTo : function(w, h) {
  4802.             this.setStyles({width : w, height : h});
  4803.         },
  4804.  
  4805.         resizeBy : function(w, h) {
  4806.             var s = this.getSize();
  4807.  
  4808.             this.resizeTo(s.w + w, s.h + h);
  4809.         },
  4810.  
  4811.         update : function(k) {
  4812.             var t = this, b, dom = t.dom;
  4813.  
  4814.             if (tinymce.isIE6 && t.settings.blocker) {
  4815.                 k = k || '';
  4816.  
  4817.                 // Ignore getters
  4818.                 if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  4819.                     return;
  4820.  
  4821.                 // Remove blocker on remove
  4822.                 if (k == 'remove') {
  4823.                     dom.remove(t.blocker);
  4824.                     return;
  4825.                 }
  4826.  
  4827.                 if (!t.blocker) {
  4828.                     t.blocker = dom.uniqueId();
  4829.                     b = dom.add(t.settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  4830.                     dom.setStyle(b, 'opacity', 0);
  4831.                 } else
  4832.                     b = dom.get(t.blocker);
  4833.  
  4834.                 dom.setStyle(b, 'left', t.getStyle('left', 1));
  4835.                 dom.setStyle(b, 'top', t.getStyle('top', 1));
  4836.                 dom.setStyle(b, 'width', t.getStyle('width', 1));
  4837.                 dom.setStyle(b, 'height', t.getStyle('height', 1));
  4838.                 dom.setStyle(b, 'display', t.getStyle('display', 1));
  4839.                 dom.setStyle(b, 'zIndex', parseInt(t.getStyle('zIndex', 1) || 0) - 1);
  4840.             }
  4841.         }
  4842.     });
  4843. })(tinymce);
  4844. (function(tinymce) {
  4845.     function trimNl(s) {
  4846.         return s.replace(/[\n\r]+/g, '');
  4847.     };
  4848.  
  4849.     // Shorten names
  4850.     var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each;
  4851.  
  4852.     tinymce.create('tinymce.dom.Selection', {
  4853.         Selection : function(dom, win, serializer) {
  4854.             var t = this;
  4855.  
  4856.             t.dom = dom;
  4857.             t.win = win;
  4858.             t.serializer = serializer;
  4859.  
  4860.             // Add events
  4861.             each([
  4862.                 'onBeforeSetContent',
  4863.                 'onBeforeGetContent',
  4864.                 'onSetContent',
  4865.                 'onGetContent'
  4866.             ], function(e) {
  4867.                 t[e] = new tinymce.util.Dispatcher(t);
  4868.             });
  4869.  
  4870.             // No W3C Range support
  4871.             if (!t.win.getSelection)
  4872.                 t.tridentSel = new tinymce.dom.TridentSelection(t);
  4873.  
  4874.             // Prevent leaks
  4875.             tinymce.addUnload(t.destroy, t);
  4876.         },
  4877.  
  4878.         getContent : function(s) {
  4879.             var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  4880.  
  4881.             s = s || {};
  4882.             wb = wa = '';
  4883.             s.get = true;
  4884.             s.format = s.format || 'html';
  4885.             t.onBeforeGetContent.dispatch(t, s);
  4886.  
  4887.             if (s.format == 'text')
  4888.                 return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  4889.  
  4890.             if (r.cloneContents) {
  4891.                 n = r.cloneContents();
  4892.  
  4893.                 if (n)
  4894.                     e.appendChild(n);
  4895.             } else if (is(r.item) || is(r.htmlText))
  4896.                 e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText;
  4897.             else
  4898.                 e.innerHTML = r.toString();
  4899.  
  4900.             // Keep whitespace before and after
  4901.             if (/^\s/.test(e.innerHTML))
  4902.                 wb = ' ';
  4903.  
  4904.             if (/\s+$/.test(e.innerHTML))
  4905.                 wa = ' ';
  4906.  
  4907.             s.getInner = true;
  4908.  
  4909.             s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  4910.             t.onGetContent.dispatch(t, s);
  4911.  
  4912.             return s.content;
  4913.         },
  4914.  
  4915.         setContent : function(h, s) {
  4916.             var t = this, r = t.getRng(), c, d = t.win.document;
  4917.  
  4918.             s = s || {format : 'html'};
  4919.             s.set = true;
  4920.             h = s.content = t.dom.processHTML(h);
  4921.  
  4922.             // Dispatch before set content event
  4923.             t.onBeforeSetContent.dispatch(t, s);
  4924.             h = s.content;
  4925.  
  4926.             if (r.insertNode) {
  4927.                 // Make caret marker since insertNode places the caret in the beginning of text after insert
  4928.                 h += '<span id="__caret">_</span>';
  4929.  
  4930.                 // Delete and insert new node
  4931.                 r.deleteContents();
  4932.                 r.insertNode(t.getRng().createContextualFragment(h));
  4933.  
  4934.                 // Move to caret marker
  4935.                 c = t.dom.get('__caret');
  4936.  
  4937.                 // Make sure we wrap it compleatly, Opera fails with a simple select call
  4938.                 r = d.createRange();
  4939.                 r.setStartBefore(c);
  4940.                 r.setEndAfter(c);
  4941.                 t.setRng(r);
  4942.  
  4943.                 // Delete the marker, and hopefully the caret gets placed in the right location
  4944.                 // Removed this since it seems to remove &nbsp; in FF and simply deleting it
  4945.                 // doesn't seem to affect the caret position in any browser
  4946.                 //d.execCommand('Delete', false, null);
  4947.  
  4948.                 // Remove the caret position
  4949.                 t.dom.remove('__caret');
  4950.             } else {
  4951.                 if (r.item) {
  4952.                     // Delete content and get caret text selection
  4953.                     d.execCommand('Delete', false, null);
  4954.                     r = t.getRng();
  4955.                 }
  4956.  
  4957.                 r.pasteHTML(h);
  4958.             }
  4959.  
  4960.             // Dispatch set content event
  4961.             t.onSetContent.dispatch(t, s);
  4962.         },
  4963.  
  4964.         getStart : function() {
  4965.             var t = this, r = t.getRng(), e;
  4966.  
  4967.             if (isIE) {
  4968.                 if (r.item)
  4969.                     return r.item(0);
  4970.  
  4971.                 r = r.duplicate();
  4972.                 r.collapse(1);
  4973.                 e = r.parentElement();
  4974.  
  4975.                 if (e && e.nodeName == 'BODY')
  4976.                     return e.firstChild;
  4977.  
  4978.                 return e;
  4979.             } else {
  4980.                 e = r.startContainer;
  4981.  
  4982.                 if (e.nodeName == 'BODY')
  4983.                     return e.firstChild;
  4984.  
  4985.                 return t.dom.getParent(e, '*');
  4986.             }
  4987.         },
  4988.  
  4989.         getEnd : function() {
  4990.             var t = this, r = t.getRng(), e;
  4991.  
  4992.             if (isIE) {
  4993.                 if (r.item)
  4994.                     return r.item(0);
  4995.  
  4996.                 r = r.duplicate();
  4997.                 r.collapse(0);
  4998.                 e = r.parentElement();
  4999.  
  5000.                 if (e && e.nodeName == 'BODY')
  5001.                     return e.lastChild;
  5002.  
  5003.                 return e;
  5004.             } else {
  5005.                 e = r.endContainer;
  5006.  
  5007.                 if (e.nodeName == 'BODY')
  5008.                     return e.lastChild;
  5009.  
  5010.                 return t.dom.getParent(e, '*');
  5011.             }
  5012.         },
  5013.  
  5014.         getBookmark : function(si) {
  5015.             var t = this, r = t.getRng(), tr, sx, sy, vp = t.dom.getViewPort(t.win), e, sp, bp, le, c = -0xFFFFFF, s, ro = t.dom.getRoot(), wb = 0, wa = 0, nv;
  5016.             sx = vp.x;
  5017.             sy = vp.y;
  5018.  
  5019.             // Simple bookmark fast but not as persistent
  5020.             if (si)
  5021.                 return {rng : r, scrollX : sx, scrollY : sy};
  5022.  
  5023.             // Handle IE
  5024.             if (isIE) {
  5025.                 // Control selection
  5026.                 if (r.item) {
  5027.                     e = r.item(0);
  5028.  
  5029.                     each(t.dom.select(e.nodeName), function(n, i) {
  5030.                         if (e == n) {
  5031.                             sp = i;
  5032.                             return false;
  5033.                         }
  5034.                     });
  5035.  
  5036.                     return {
  5037.                         tag : e.nodeName,
  5038.                         index : sp,
  5039.                         scrollX : sx,
  5040.                         scrollY : sy
  5041.                     };
  5042.                 }
  5043.  
  5044.                 // Text selection
  5045.                 tr = t.dom.doc.body.createTextRange();
  5046.                 tr.moveToElementText(ro);
  5047.                 tr.collapse(true);
  5048.                 bp = Math.abs(tr.move('character', c));
  5049.  
  5050.                 tr = r.duplicate();
  5051.                 tr.collapse(true);
  5052.                 sp = Math.abs(tr.move('character', c));
  5053.  
  5054.                 tr = r.duplicate();
  5055.                 tr.collapse(false);
  5056.                 le = Math.abs(tr.move('character', c)) - sp;
  5057.  
  5058.                 return {
  5059.                     start : sp - bp,
  5060.                     length : le,
  5061.                     scrollX : sx,
  5062.                     scrollY : sy
  5063.                 };
  5064.             }
  5065.  
  5066.             // Handle W3C
  5067.             e = t.getNode();
  5068.             s = t.getSel();
  5069.  
  5070.             if (!s)
  5071.                 return null;
  5072.  
  5073.             // Image selection
  5074.             if (e && e.nodeName == 'IMG') {
  5075.                 return {
  5076.                     scrollX : sx,
  5077.                     scrollY : sy
  5078.                 };
  5079.             }
  5080.  
  5081.             // Text selection
  5082.  
  5083.             function getPos(r, sn, en) {
  5084.                 var w = t.dom.doc.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
  5085.  
  5086.                 while ((n = w.nextNode()) != null) {
  5087.                     if (n == sn)
  5088.                         d.start = p;
  5089.  
  5090.                     if (n == en) {
  5091.                         d.end = p;
  5092.                         return d;
  5093.                     }
  5094.  
  5095.                     p += trimNl(n.nodeValue || '').length;
  5096.                 }
  5097.  
  5098.                 return null;
  5099.             };
  5100.  
  5101.             // Caret or selection
  5102.             if (s.anchorNode == s.focusNode && s.anchorOffset == s.focusOffset) {
  5103.                 e = getPos(ro, s.anchorNode, s.focusNode);
  5104.  
  5105.                 if (!e)
  5106.                     return {scrollX : sx, scrollY : sy};
  5107.  
  5108.                 // Count whitespace before
  5109.                 trimNl(s.anchorNode.nodeValue || '').replace(/^\s+/, function(a) {wb = a.length;});
  5110.  
  5111.                 return {
  5112.                     start : Math.max(e.start + s.anchorOffset - wb, 0),
  5113.                     end : Math.max(e.end + s.focusOffset - wb, 0),
  5114.                     scrollX : sx,
  5115.                     scrollY : sy,
  5116.                     beg : s.anchorOffset - wb == 0
  5117.                 };
  5118.             } else {
  5119.                 e = getPos(ro, r.startContainer, r.endContainer);
  5120.  
  5121.                 // Count whitespace before start and end container
  5122.                 //(r.startContainer.nodeValue || '').replace(/^\s+/, function(a) {wb = a.length;});
  5123.                 //(r.endContainer.nodeValue || '').replace(/^\s+/, function(a) {wa = a.length;});
  5124.  
  5125.                 if (!e)
  5126.                     return {scrollX : sx, scrollY : sy};
  5127.  
  5128.                 return {
  5129.                     start : Math.max(e.start + r.startOffset - wb, 0),
  5130.                     end : Math.max(e.end + r.endOffset - wa, 0),
  5131.                     scrollX : sx,
  5132.                     scrollY : sy,
  5133.                     beg : r.startOffset - wb == 0
  5134.                 };
  5135.             }
  5136.         },
  5137.  
  5138.         moveToBookmark : function(b) {
  5139.             var t = this, r = t.getRng(), s = t.getSel(), ro = t.dom.getRoot(), sd, nvl, nv;
  5140.  
  5141.             function getPos(r, sp, ep) {
  5142.                 var w = t.dom.doc.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {}, o, v, wa, wb;
  5143.  
  5144.                 while ((n = w.nextNode()) != null) {
  5145.                     wa = wb = 0;
  5146.  
  5147.                     nv = n.nodeValue || '';
  5148.                     //nv.replace(/^\s+[^\s]/, function(a) {wb = a.length - 1;});
  5149.                     //nv.replace(/[^\s]\s+$/, function(a) {wa = a.length - 1;});
  5150.  
  5151.                     nvl = trimNl(nv).length;
  5152.                     p += nvl;
  5153.  
  5154.                     if (p >= sp && !d.startNode) {
  5155.                         o = sp - (p - nvl);
  5156.  
  5157.                         // Fix for odd quirk in FF
  5158.                         if (b.beg && o >= nvl)
  5159.                             continue;
  5160.  
  5161.                         d.startNode = n;
  5162.                         d.startOffset = o + wb;
  5163.                     }
  5164.  
  5165.                     if (p >= ep) {
  5166.                         d.endNode = n;
  5167.                         d.endOffset = ep - (p - nvl) + wb;
  5168.                         return d;
  5169.                     }
  5170.                 }
  5171.  
  5172.                 return null;
  5173.             };
  5174.  
  5175.             if (!b)
  5176.                 return false;
  5177.  
  5178.             t.win.scrollTo(b.scrollX, b.scrollY);
  5179.  
  5180.             // Handle explorer
  5181.             if (isIE) {
  5182.                 t.tridentSel.destroy();
  5183.  
  5184.                 // Handle simple
  5185.                 if (r = b.rng) {
  5186.                     try {
  5187.                         r.select();
  5188.                     } catch (ex) {
  5189.                         // Ignore
  5190.                     }
  5191.  
  5192.                     return true;
  5193.                 }
  5194.  
  5195.                 t.win.focus();
  5196.  
  5197.                 // Handle control bookmark
  5198.                 if (b.tag) {
  5199.                     r = ro.createControlRange();
  5200.  
  5201.                     each(t.dom.select(b.tag), function(n, i) {
  5202.                         if (i == b.index)
  5203.                             r.addElement(n);
  5204.                     });
  5205.                 } else {
  5206.                     // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs
  5207.                     try {
  5208.                         // Incorrect bookmark
  5209.                         if (b.start < 0)
  5210.                             return true;
  5211.  
  5212.                         r = s.createRange();
  5213.                         r.moveToElementText(ro);
  5214.                         r.collapse(true);
  5215.                         r.moveStart('character', b.start);
  5216.                         r.moveEnd('character', b.length);
  5217.                     } catch (ex2) {
  5218.                         return true;
  5219.                     }
  5220.                 }
  5221.  
  5222.                 try {
  5223.                     r.select();
  5224.                 } catch (ex) {
  5225.                     // Needed for some odd IE bug #1843306
  5226.                 }
  5227.  
  5228.                 return true;
  5229.             }
  5230.  
  5231.             // Handle W3C
  5232.             if (!s)
  5233.                 return false;
  5234.  
  5235.             // Handle simple
  5236.             if (b.rng) {
  5237.                 s.removeAllRanges();
  5238.                 s.addRange(b.rng);
  5239.             } else {
  5240.                 if (is(b.start) && is(b.end)) {
  5241.                     try {
  5242.                         sd = getPos(ro, b.start, b.end);
  5243.  
  5244.                         if (sd) {
  5245.                             r = t.dom.doc.createRange();
  5246.                             r.setStart(sd.startNode, sd.startOffset);
  5247.                             r.setEnd(sd.endNode, sd.endOffset);
  5248.                             s.removeAllRanges();
  5249.                             s.addRange(r);
  5250.                         }
  5251.  
  5252.                         if (!tinymce.isOpera)
  5253.                             t.win.focus();
  5254.                     } catch (ex) {
  5255.                         // Ignore
  5256.                     }
  5257.                 }
  5258.             }
  5259.         },
  5260.  
  5261.         select : function(n, c) {
  5262.             var t = this, r = t.getRng(), s = t.getSel(), b, fn, ln, d = t.win.document;
  5263.  
  5264.             function find(n, start) {
  5265.                 var walker, o;
  5266.  
  5267.                 if (n) {
  5268.                     walker = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  5269.  
  5270.                     // Find first/last non empty text node
  5271.                     while (n = walker.nextNode()) {
  5272.                         o = n;
  5273.  
  5274.                         if (tinymce.trim(n.nodeValue).length != 0) {
  5275.                             if (start)
  5276.                                 return n;
  5277.                             else
  5278.                                 o = n;
  5279.                         }
  5280.                     }
  5281.                 }
  5282.  
  5283.                 return o;
  5284.             };
  5285.  
  5286.             if (isIE) {
  5287.                 try {
  5288.                     b = d.body;
  5289.  
  5290.                     if (/^(IMG|TABLE)$/.test(n.nodeName)) {
  5291.                         r = b.createControlRange();
  5292.                         r.addElement(n);
  5293.                     } else {
  5294.                         r = b.createTextRange();
  5295.                         r.moveToElementText(n);
  5296.                     }
  5297.  
  5298.                     r.select();
  5299.                 } catch (ex) {
  5300.                     // Throws illigal agrument in IE some times
  5301.                 }
  5302.             } else {
  5303.                 if (c) {
  5304.                     fn = find(n, 1) || t.dom.select('br:first', n)[0];
  5305.                     ln = find(n, 0) || t.dom.select('br:last', n)[0];
  5306.  
  5307.                     if (fn && ln) {
  5308.                         r = d.createRange();
  5309.  
  5310.                         if (fn.nodeName == 'BR')
  5311.                             r.setStartBefore(fn);
  5312.                         else
  5313.                             r.setStart(fn, 0);
  5314.  
  5315.                         if (ln.nodeName == 'BR')
  5316.                             r.setEndBefore(ln);
  5317.                         else
  5318.                             r.setEnd(ln, ln.nodeValue.length);
  5319.                     } else
  5320.                         r.selectNode(n);
  5321.                 } else
  5322.                     r.selectNode(n);
  5323.  
  5324.                 t.setRng(r);
  5325.             }
  5326.  
  5327.             return n;
  5328.         },
  5329.  
  5330.         isCollapsed : function() {
  5331.             var t = this, r = t.getRng(), s = t.getSel();
  5332.  
  5333.             if (!r || r.item)
  5334.                 return false;
  5335.  
  5336.             return !s || r.boundingWidth == 0 || r.collapsed;
  5337.         },
  5338.  
  5339.         collapse : function(b) {
  5340.             var t = this, r = t.getRng(), n;
  5341.  
  5342.             // Control range on IE
  5343.             if (r.item) {
  5344.                 n = r.item(0);
  5345.                 r = this.win.document.body.createTextRange();
  5346.                 r.moveToElementText(n);
  5347.             }
  5348.  
  5349.             r.collapse(!!b);
  5350.             t.setRng(r);
  5351.         },
  5352.  
  5353.         getSel : function() {
  5354.             var t = this, w = this.win;
  5355.  
  5356.             return w.getSelection ? w.getSelection() : w.document.selection;
  5357.         },
  5358.  
  5359.         getRng : function(w3c) {
  5360.             var t = this, s, r;
  5361.  
  5362.             // Found tridentSel object then we need to use that one
  5363.             if (w3c && t.tridentSel)
  5364.                 return t.tridentSel.getRangeAt(0);
  5365.  
  5366.             try {
  5367.                 if (s = t.getSel())
  5368.                     r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : t.win.document.createRange());
  5369.             } catch (ex) {
  5370.                 // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  5371.             }
  5372.  
  5373.             // No range found then create an empty one
  5374.             // This can occur when the editor is placed in a hidden container element on Gecko
  5375.             // Or on IE when there was an exception
  5376.             if (!r)
  5377.                 r = isIE ? t.win.document.body.createTextRange() : t.win.document.createRange();
  5378.  
  5379.             return r;
  5380.         },
  5381.  
  5382.         setRng : function(r) {
  5383.             var s, t = this;
  5384.  
  5385.             if (!t.tridentSel) {
  5386.                 s = t.getSel();
  5387.  
  5388.                 if (s) {
  5389.                     s.removeAllRanges();
  5390.                     s.addRange(r);
  5391.                 }
  5392.             } else {
  5393.                 // Is W3C Range
  5394.                 if (r.cloneRange) {
  5395.                     t.tridentSel.addRange(r);
  5396.                     return;
  5397.                 }
  5398.  
  5399.                 // Is IE specific range
  5400.                 try {
  5401.                     r.select();
  5402.                 } catch (ex) {
  5403.                     // Needed for some odd IE bug #1843306
  5404.                 }
  5405.             }
  5406.         },
  5407.  
  5408.         setNode : function(n) {
  5409.             var t = this;
  5410.  
  5411.             t.setContent(t.dom.getOuterHTML(n));
  5412.  
  5413.             return n;
  5414.         },
  5415.  
  5416.         getNode : function() {
  5417.             var t = this, r = t.getRng(), s = t.getSel(), e;
  5418.  
  5419.             if (!isIE) {
  5420.                 // Range maybe lost after the editor is made visible again
  5421.                 if (!r)
  5422.                     return t.dom.getRoot();
  5423.  
  5424.                 e = r.commonAncestorContainer;
  5425.  
  5426.                 // Handle selection a image or other control like element such as anchors
  5427.                 if (!r.collapsed) {
  5428.                     // If the anchor node is a element instead of a text node then return this element
  5429.                     if (tinymce.isWebKit && s.anchorNode && s.anchorNode.nodeType == 1) 
  5430.                         return s.anchorNode.childNodes[s.anchorOffset]; 
  5431.  
  5432.                     if (r.startContainer == r.endContainer) {
  5433.                         if (r.startOffset - r.endOffset < 2) {
  5434.                             if (r.startContainer.hasChildNodes())
  5435.                                 e = r.startContainer.childNodes[r.startOffset];
  5436.                         }
  5437.                     }
  5438.                 }
  5439.  
  5440.                 return t.dom.getParent(e, '*');
  5441.             }
  5442.  
  5443.             return r.item ? r.item(0) : r.parentElement();
  5444.         },
  5445.  
  5446.         getSelectedBlocks : function(st, en) {
  5447.             var t = this, dom = t.dom, sb, eb, n, bl = [];
  5448.  
  5449.             sb = dom.getParent(st || t.getStart(), dom.isBlock);
  5450.             eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  5451.  
  5452.             if (sb)
  5453.                 bl.push(sb);
  5454.  
  5455.             if (sb && eb && sb != eb) {
  5456.                 n = sb;
  5457.  
  5458.                 while ((n = n.nextSibling) && n != eb) {
  5459.                     if (dom.isBlock(n))
  5460.                         bl.push(n);
  5461.                 }
  5462.             }
  5463.  
  5464.             if (eb && sb != eb)
  5465.                 bl.push(eb);
  5466.  
  5467.             return bl;
  5468.         },
  5469.  
  5470.         destroy : function(s) {
  5471.             var t = this;
  5472.  
  5473.             t.win = null;
  5474.  
  5475.             if (t.tridentSel)
  5476.                 t.tridentSel.destroy();
  5477.  
  5478.             // Manual destroy then remove unload handler
  5479.             if (!s)
  5480.                 tinymce.removeUnload(t.destroy);
  5481.         }
  5482.     });
  5483. })(tinymce);
  5484. (function(tinymce) {
  5485.     tinymce.create('tinymce.dom.XMLWriter', {
  5486.         node : null,
  5487.  
  5488.         XMLWriter : function(s) {
  5489.             // Get XML document
  5490.             function getXML() {
  5491.                 var i = document.implementation;
  5492.  
  5493.                 if (!i || !i.createDocument) {
  5494.                     // Try IE objects
  5495.                     try {return new ActiveXObject('MSXML2.DOMDocument');} catch (ex) {}
  5496.                     try {return new ActiveXObject('Microsoft.XmlDom');} catch (ex) {}
  5497.                 } else
  5498.                     return i.createDocument('', '', null);
  5499.             };
  5500.  
  5501.             this.doc = getXML();
  5502.  
  5503.             // Since Opera and WebKit doesn't escape > into &gt; we need to do it our self to normalize the output for all browsers
  5504.             this.valid = tinymce.isOpera || tinymce.isWebKit;
  5505.  
  5506.             this.reset();
  5507.         },
  5508.  
  5509.         reset : function() {
  5510.             var t = this, d = t.doc;
  5511.  
  5512.             if (d.firstChild)
  5513.                 d.removeChild(d.firstChild);
  5514.  
  5515.             t.node = d.appendChild(d.createElement("html"));
  5516.         },
  5517.  
  5518.         writeStartElement : function(n) {
  5519.             var t = this;
  5520.  
  5521.             t.node = t.node.appendChild(t.doc.createElement(n));
  5522.         },
  5523.  
  5524.         writeAttribute : function(n, v) {
  5525.             if (this.valid)
  5526.                 v = v.replace(/>/g, '%MCGT%');
  5527.  
  5528.             this.node.setAttribute(n, v);
  5529.         },
  5530.  
  5531.         writeEndElement : function() {
  5532.             this.node = this.node.parentNode;
  5533.         },
  5534.  
  5535.         writeFullEndElement : function() {
  5536.             var t = this, n = t.node;
  5537.  
  5538.             n.appendChild(t.doc.createTextNode(""));
  5539.             t.node = n.parentNode;
  5540.         },
  5541.  
  5542.         writeText : function(v) {
  5543.             if (this.valid)
  5544.                 v = v.replace(/>/g, '%MCGT%');
  5545.  
  5546.             this.node.appendChild(this.doc.createTextNode(v));
  5547.         },
  5548.  
  5549.         writeCDATA : function(v) {
  5550.             this.node.appendChild(this.doc.createCDATASection(v));
  5551.         },
  5552.  
  5553.         writeComment : function(v) {
  5554.             // Fix for bug #2035694
  5555.             if (tinymce.isIE)
  5556.                 v = v.replace(/^\-|\-$/g, ' ');
  5557.  
  5558.             this.node.appendChild(this.doc.createComment(v.replace(/\-\-/g, ' ')));
  5559.         },
  5560.  
  5561.         getContent : function() {
  5562.             var h;
  5563.  
  5564.             h = this.doc.xml || new XMLSerializer().serializeToString(this.doc);
  5565.             h = h.replace(/<\?[^?]+\?>|<html>|<\/html>|<html\/>|<!DOCTYPE[^>]+>/g, '');
  5566.             h = h.replace(/ ?\/>/g, ' />');
  5567.  
  5568.             if (this.valid)
  5569.                 h = h.replace(/\%MCGT%/g, '&gt;');
  5570.  
  5571.             return h;
  5572.         }
  5573.     });
  5574. })(tinymce);
  5575. (function(tinymce) {
  5576.     tinymce.create('tinymce.dom.StringWriter', {
  5577.         str : null,
  5578.         tags : null,
  5579.         count : 0,
  5580.         settings : null,
  5581.         indent : null,
  5582.  
  5583.         StringWriter : function(s) {
  5584.             this.settings = tinymce.extend({
  5585.                 indent_char : ' ',
  5586.                 indentation : 0
  5587.             }, s);
  5588.  
  5589.             this.reset();
  5590.         },
  5591.  
  5592.         reset : function() {
  5593.             this.indent = '';
  5594.             this.str = "";
  5595.             this.tags = [];
  5596.             this.count = 0;
  5597.         },
  5598.  
  5599.         writeStartElement : function(n) {
  5600.             this._writeAttributesEnd();
  5601.             this.writeRaw('<' + n);
  5602.             this.tags.push(n);
  5603.             this.inAttr = true;
  5604.             this.count++;
  5605.             this.elementCount = this.count;
  5606.         },
  5607.  
  5608.         writeAttribute : function(n, v) {
  5609.             var t = this;
  5610.  
  5611.             t.writeRaw(" " + t.encode(n) + '="' + t.encode(v) + '"');
  5612.         },
  5613.  
  5614.         writeEndElement : function() {
  5615.             var n;
  5616.  
  5617.             if (this.tags.length > 0) {
  5618.                 n = this.tags.pop();
  5619.  
  5620.                 if (this._writeAttributesEnd(1))
  5621.                     this.writeRaw('</' + n + '>');
  5622.  
  5623.                 if (this.settings.indentation > 0)
  5624.                     this.writeRaw('\n');
  5625.             }
  5626.         },
  5627.  
  5628.         writeFullEndElement : function() {
  5629.             if (this.tags.length > 0) {
  5630.                 this._writeAttributesEnd();
  5631.                 this.writeRaw('</' + this.tags.pop() + '>');
  5632.  
  5633.                 if (this.settings.indentation > 0)
  5634.                     this.writeRaw('\n');
  5635.             }
  5636.         },
  5637.  
  5638.         writeText : function(v) {
  5639.             this._writeAttributesEnd();
  5640.             this.writeRaw(this.encode(v));
  5641.             this.count++;
  5642.         },
  5643.  
  5644.         writeCDATA : function(v) {
  5645.             this._writeAttributesEnd();
  5646.             this.writeRaw('<![CDATA[' + v + ']]>');
  5647.             this.count++;
  5648.         },
  5649.  
  5650.         writeComment : function(v) {
  5651.             this._writeAttributesEnd();
  5652.             this.writeRaw('<!-- ' + v + '-->');
  5653.             this.count++;
  5654.         },
  5655.  
  5656.         writeRaw : function(v) {
  5657.             this.str += v;
  5658.         },
  5659.  
  5660.         encode : function(s) {
  5661.             return s.replace(/[<>&"]/g, function(v) {
  5662.                 switch (v) {
  5663.                     case '<':
  5664.                         return '&lt;';
  5665.  
  5666.                     case '>':
  5667.                         return '&gt;';
  5668.  
  5669.                     case '&':
  5670.                         return '&amp;';
  5671.  
  5672.                     case '"':
  5673.                         return '&quot;';
  5674.                 }
  5675.  
  5676.                 return v;
  5677.             });
  5678.         },
  5679.  
  5680.         getContent : function() {
  5681.             return this.str;
  5682.         },
  5683.  
  5684.         _writeAttributesEnd : function(s) {
  5685.             if (!this.inAttr)
  5686.                 return;
  5687.  
  5688.             this.inAttr = false;
  5689.  
  5690.             if (s && this.elementCount == this.count) {
  5691.                 this.writeRaw(' />');
  5692.                 return false;
  5693.             }
  5694.  
  5695.             this.writeRaw('>');
  5696.  
  5697.             return true;
  5698.         }
  5699.     });
  5700. })(tinymce);
  5701. (function(tinymce) {
  5702.     // Shorten names
  5703.     var extend = tinymce.extend, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, isIE = tinymce.isIE, isGecko = tinymce.isGecko;
  5704.  
  5705.     function wildcardToRE(s) {
  5706.         return s.replace(/([?+*])/g, '.$1');
  5707.     };
  5708.  
  5709.     tinymce.create('tinymce.dom.Serializer', {
  5710.         Serializer : function(s) {
  5711.             var t = this;
  5712.  
  5713.             t.key = 0;
  5714.             t.onPreProcess = new Dispatcher(t);
  5715.             t.onPostProcess = new Dispatcher(t);
  5716.  
  5717.             try {
  5718.                 t.writer = new tinymce.dom.XMLWriter();
  5719.             } catch (ex) {
  5720.                 // IE might throw exception if ActiveX is disabled so we then switch to the slightly slower StringWriter
  5721.                 t.writer = new tinymce.dom.StringWriter();
  5722.             }
  5723.  
  5724.             // Default settings
  5725.             t.settings = s = extend({
  5726.                 dom : tinymce.DOM,
  5727.                 valid_nodes : 0,
  5728.                 node_filter : 0,
  5729.                 attr_filter : 0,
  5730.                 invalid_attrs : /^(mce_|_moz_|sizset|sizcache)/,
  5731.                 closed : /^(br|hr|input|meta|img|link|param|area)$/,
  5732.                 entity_encoding : 'named',
  5733.                 entities : '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,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',
  5734.                 valid_elements : '*[*]',
  5735.                 extended_valid_elements : 0,
  5736.                 valid_child_elements : 0,
  5737.                 invalid_elements : 0,
  5738.                 fix_table_elements : 1,
  5739.                 fix_list_elements : true,
  5740.                 fix_content_duplication : true,
  5741.                 convert_fonts_to_spans : false,
  5742.                 font_size_classes : 0,
  5743.                 font_size_style_values : 0,
  5744.                 apply_source_formatting : 0,
  5745.                 indent_mode : 'simple',
  5746.                 indent_char : '\t',
  5747.                 indent_levels : 1,
  5748.                 remove_linebreaks : 1,
  5749.                 remove_redundant_brs : 1,
  5750.                 element_format : 'xhtml'
  5751.             }, s);
  5752.  
  5753.             t.dom = s.dom;
  5754.  
  5755.             if (s.remove_redundant_brs) {
  5756.                 t.onPostProcess.add(function(se, o) {
  5757.                     // Remove single BR at end of block elements since they get rendered
  5758.                     o.content = o.content.replace(/(<br \/>\s*)+<\/(p|h[1-6]|div|li)>/gi, function(a, b, c) {
  5759.                         // Check if it's a single element
  5760.                         if (/^<br \/>\s*<\//.test(a))
  5761.                             return '</' + c + '>';
  5762.  
  5763.                         return a;
  5764.                     });
  5765.                 });
  5766.             }
  5767.  
  5768.             // Remove XHTML element endings i.e. produce crap :) XHTML is better
  5769.             if (s.element_format == 'html') {
  5770.                 t.onPostProcess.add(function(se, o) {
  5771.                     o.content = o.content.replace(/<([^>]+) \/>/g, '<$1>');
  5772.                 });
  5773.             }
  5774.  
  5775.             if (s.fix_list_elements) {
  5776.                 t.onPreProcess.add(function(se, o) {
  5777.                     var nl, x, a = ['ol', 'ul'], i, n, p, r = /^(OL|UL)$/, np;
  5778.  
  5779.                     function prevNode(e, n) {
  5780.                         var a = n.split(','), i;
  5781.  
  5782.                         while ((e = e.previousSibling) != null) {
  5783.                             for (i=0; i<a.length; i++) {
  5784.                                 if (e.nodeName == a[i])
  5785.                                     return e;
  5786.                             }
  5787.                         }
  5788.  
  5789.                         return null;
  5790.                     };
  5791.  
  5792.                     for (x=0; x<a.length; x++) {
  5793.                         nl = t.dom.select(a[x], o.node);
  5794.  
  5795.                         for (i=0; i<nl.length; i++) {
  5796.                             n = nl[i];
  5797.                             p = n.parentNode;
  5798.  
  5799.                             if (r.test(p.nodeName)) {
  5800.                                 np = prevNode(n, 'LI');
  5801.  
  5802.                                 if (!np) {
  5803.                                     np = t.dom.create('li');
  5804.                                     np.innerHTML = '&nbsp;';
  5805.                                     np.appendChild(n);
  5806.                                     p.insertBefore(np, p.firstChild);
  5807.                                 } else
  5808.                                     np.appendChild(n);
  5809.                             }
  5810.                         }
  5811.                     }
  5812.                 });
  5813.             }
  5814.  
  5815.             if (s.fix_table_elements) {
  5816.                 t.onPreProcess.add(function(se, o) {
  5817.                     // Since Opera will crash if you attach the node to a dynamic document we need to brrowser sniff a specific build
  5818.                     // so Opera users with an older version will have to live with less compaible output not much we can do here
  5819.                     if (!tinymce.isOpera || opera.buildNumber() >= 1767) {
  5820.                         each(t.dom.select('p table', o.node).reverse(), function(n) {
  5821.                             var parent = t.dom.getParent(n.parentNode, 'table,p');
  5822.  
  5823.                             if (parent.nodeName != 'TABLE') {
  5824.                                 try {
  5825.                                     t.dom.split(parent, n);
  5826.                                 } catch (ex) {
  5827.                                     // IE can sometimes fire an unknown runtime error so we just ignore it
  5828.                                 }
  5829.                             }
  5830.                         });
  5831.                     }
  5832.                 });
  5833.             }
  5834.         },
  5835.  
  5836.         setEntities : function(s) {
  5837.             var t = this, a, i, l = {}, re = '', v;
  5838.  
  5839.             // No need to setup more than once
  5840.             if (t.entityLookup)
  5841.                 return;
  5842.  
  5843.             // Build regex and lookup array
  5844.             a = s.split(',');
  5845.             for (i = 0; i < a.length; i += 2) {
  5846.                 v = a[i];
  5847.  
  5848.                 // Don't add default &amp; &quot; etc.
  5849.                 if (v == 34 || v == 38 || v == 60 || v == 62)
  5850.                     continue;
  5851.  
  5852.                 l[String.fromCharCode(a[i])] = a[i + 1];
  5853.  
  5854.                 v = parseInt(a[i]).toString(16);
  5855.                 re += '\\u' + '0000'.substring(v.length) + v;
  5856.             }
  5857.  
  5858.             if (!re) {
  5859.                 t.settings.entity_encoding = 'raw';
  5860.                 return;
  5861.             }
  5862.  
  5863.             t.entitiesRE = new RegExp('[' + re + ']', 'g');
  5864.             t.entityLookup = l;
  5865.         },
  5866.  
  5867.         setValidChildRules : function(s) {
  5868.             this.childRules = null;
  5869.             this.addValidChildRules(s);
  5870.         },
  5871.  
  5872.         addValidChildRules : function(s) {
  5873.             var t = this, inst, intr, bloc;
  5874.  
  5875.             if (!s)
  5876.                 return;
  5877.  
  5878.             inst = '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';
  5879.             intr = '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';
  5880.             bloc = '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';
  5881.  
  5882.             each(s.split(','), function(s) {
  5883.                 var p = s.split(/\[|\]/), re;
  5884.  
  5885.                 s = '';
  5886.                 each(p[1].split('|'), function(v) {
  5887.                     if (s)
  5888.                         s += '|';
  5889.  
  5890.                     switch (v) {
  5891.                         case '%itrans':
  5892.                             v = intr;
  5893.                             break;
  5894.  
  5895.                         case '%itrans_na':
  5896.                             v = intr.substring(2);
  5897.                             break;
  5898.  
  5899.                         case '%istrict':
  5900.                             v = inst;
  5901.                             break;
  5902.  
  5903.                         case '%istrict_na':
  5904.                             v = inst.substring(2);
  5905.                             break;
  5906.  
  5907.                         case '%btrans':
  5908.                             v = bloc;
  5909.                             break;
  5910.  
  5911.                         case '%bstrict':
  5912.                             v = bloc;
  5913.                             break;
  5914.                     }
  5915.  
  5916.                     s += v;
  5917.                 });
  5918.                 re = new RegExp('^(' + s.toLowerCase() + ')$', 'i');
  5919.  
  5920.                 each(p[0].split('/'), function(s) {
  5921.                     t.childRules = t.childRules || {};
  5922.                     t.childRules[s] = re;
  5923.                 });
  5924.             });
  5925.  
  5926.             // Build regex
  5927.             s = '';
  5928.             each(t.childRules, function(v, k) {
  5929.                 if (s)
  5930.                     s += '|';
  5931.  
  5932.                 s += k;
  5933.             });
  5934.  
  5935.             t.parentElementsRE = new RegExp('^(' + s.toLowerCase() + ')$', 'i');
  5936.  
  5937.             /*console.debug(t.parentElementsRE.toString());
  5938.             each(t.childRules, function(v) {
  5939.                 console.debug(v.toString());
  5940.             });*/
  5941.         },
  5942.  
  5943.         setRules : function(s) {
  5944.             var t = this;
  5945.  
  5946.             t._setup();
  5947.             t.rules = {};
  5948.             t.wildRules = [];
  5949.             t.validElements = {};
  5950.  
  5951.             return t.addRules(s);
  5952.         },
  5953.  
  5954.         addRules : function(s) {
  5955.             var t = this, dr;
  5956.  
  5957.             if (!s)
  5958.                 return;
  5959.  
  5960.             t._setup();
  5961.  
  5962.             each(s.split(','), function(s) {
  5963.                 var p = s.split(/\[|\]/), tn = p[0].split('/'), ra, at, wat, va = [];
  5964.  
  5965.                 // Extend with default rules
  5966.                 if (dr)
  5967.                     at = tinymce.extend([], dr.attribs);
  5968.  
  5969.                 // Parse attributes
  5970.                 if (p.length > 1) {
  5971.                     each(p[1].split('|'), function(s) {
  5972.                         var ar = {}, i;
  5973.  
  5974.                         at = at || [];
  5975.  
  5976.                         // Parse attribute rule
  5977.                         s = s.replace(/::/g, '~');
  5978.                         s = /^([!\-])?([\w*.?~_\-]+|)([=:<])?(.+)?$/.exec(s);
  5979.                         s[2] = s[2].replace(/~/g, ':');
  5980.  
  5981.                         // Add required attributes
  5982.                         if (s[1] == '!') {
  5983.                             ra = ra || [];
  5984.                             ra.push(s[2]);
  5985.                         }
  5986.  
  5987.                         // Remove inherited attributes
  5988.                         if (s[1] == '-') {
  5989.                             for (i = 0; i <at.length; i++) {
  5990.                                 if (at[i].name == s[2]) {
  5991.                                     at.splice(i, 1);
  5992.                                     return;
  5993.                                 }
  5994.                             }
  5995.                         }
  5996.  
  5997.                         switch (s[3]) {
  5998.                             // Add default attrib values
  5999.                             case '=':
  6000.                                 ar.defaultVal = s[4] || '';
  6001.                                 break;
  6002.  
  6003.                             // Add forced attrib values
  6004.                             case ':':
  6005.                                 ar.forcedVal = s[4];
  6006.                                 break;
  6007.  
  6008.                             // Add validation values
  6009.                             case '<':
  6010.                                 ar.validVals = s[4].split('?');
  6011.                                 break;
  6012.                         }
  6013.  
  6014.                         if (/[*.?]/.test(s[2])) {
  6015.                             wat = wat || [];
  6016.                             ar.nameRE = new RegExp('^' + wildcardToRE(s[2]) + '$');
  6017.                             wat.push(ar);
  6018.                         } else {
  6019.                             ar.name = s[2];
  6020.                             at.push(ar);
  6021.                         }
  6022.  
  6023.                         va.push(s[2]);
  6024.                     });
  6025.                 }
  6026.  
  6027.                 // Handle element names
  6028.                 each(tn, function(s, i) {
  6029.                     var pr = s.charAt(0), x = 1, ru = {};
  6030.  
  6031.                     // Extend with default rule data
  6032.                     if (dr) {
  6033.                         if (dr.noEmpty)
  6034.                             ru.noEmpty = dr.noEmpty;
  6035.  
  6036.                         if (dr.fullEnd)
  6037.                             ru.fullEnd = dr.fullEnd;
  6038.  
  6039.                         if (dr.padd)
  6040.                             ru.padd = dr.padd;
  6041.                     }
  6042.  
  6043.                     // Handle prefixes
  6044.                     switch (pr) {
  6045.                         case '-':
  6046.                             ru.noEmpty = true;
  6047.                             break;
  6048.  
  6049.                         case '+':
  6050.                             ru.fullEnd = true;
  6051.                             break;
  6052.  
  6053.                         case '#':
  6054.                             ru.padd = true;
  6055.                             break;
  6056.  
  6057.                         default:
  6058.                             x = 0;
  6059.                     }
  6060.  
  6061.                     tn[i] = s = s.substring(x);
  6062.                     t.validElements[s] = 1;
  6063.  
  6064.                     // Add element name or element regex
  6065.                     if (/[*.?]/.test(tn[0])) {
  6066.                         ru.nameRE = new RegExp('^' + wildcardToRE(tn[0]) + '$');
  6067.                         t.wildRules = t.wildRules || {};
  6068.                         t.wildRules.push(ru);
  6069.                     } else {
  6070.                         ru.name = tn[0];
  6071.  
  6072.                         // Store away default rule
  6073.                         if (tn[0] == '@')
  6074.                             dr = ru;
  6075.  
  6076.                         t.rules[s] = ru;
  6077.                     }
  6078.  
  6079.                     ru.attribs = at;
  6080.  
  6081.                     if (ra)
  6082.                         ru.requiredAttribs = ra;
  6083.  
  6084.                     if (wat) {
  6085.                         // Build valid attributes regexp
  6086.                         s = '';
  6087.                         each(va, function(v) {
  6088.                             if (s)
  6089.                                 s += '|';
  6090.  
  6091.                             s += '(' + wildcardToRE(v) + ')';
  6092.                         });
  6093.                         ru.validAttribsRE = new RegExp('^' + s.toLowerCase() + '$');
  6094.                         ru.wildAttribs = wat;
  6095.                     }
  6096.                 });
  6097.             });
  6098.  
  6099.             // Build valid elements regexp
  6100.             s = '';
  6101.             each(t.validElements, function(v, k) {
  6102.                 if (s)
  6103.                     s += '|';
  6104.  
  6105.                 if (k != '@')
  6106.                     s += k;
  6107.             });
  6108.             t.validElementsRE = new RegExp('^(' + wildcardToRE(s.toLowerCase()) + ')$');
  6109.  
  6110.             //console.debug(t.validElementsRE.toString());
  6111.             //console.dir(t.rules);
  6112.             //console.dir(t.wildRules);
  6113.         },
  6114.  
  6115.         findRule : function(n) {
  6116.             var t = this, rl = t.rules, i, r;
  6117.  
  6118.             t._setup();
  6119.  
  6120.             // Exact match
  6121.             r = rl[n];
  6122.             if (r)
  6123.                 return r;
  6124.  
  6125.             // Try wildcards
  6126.             rl = t.wildRules;
  6127.             for (i = 0; i < rl.length; i++) {
  6128.                 if (rl[i].nameRE.test(n))
  6129.                     return rl[i];
  6130.             }
  6131.  
  6132.             return null;
  6133.         },
  6134.  
  6135.         findAttribRule : function(ru, n) {
  6136.             var i, wa = ru.wildAttribs;
  6137.  
  6138.             for (i = 0; i < wa.length; i++) {
  6139.                 if (wa[i].nameRE.test(n))
  6140.                     return wa[i];
  6141.             }
  6142.  
  6143.             return null;
  6144.         },
  6145.  
  6146.         serialize : function(n, o) {
  6147.             var h, t = this, doc, oldDoc, impl, selected;
  6148.  
  6149.             t._setup();
  6150.             o = o || {};
  6151.             o.format = o.format || 'html';
  6152.             t.processObj = o;
  6153.  
  6154.             // IE looses the selected attribute on option elements so we need to store it
  6155.             // See: http://support.microsoft.com/kb/829907
  6156.             if (isIE) {
  6157.                 selected = [];
  6158.                 each(n.getElementsByTagName('option'), function(n) {
  6159.                     var v = t.dom.getAttrib(n, 'selected');
  6160.  
  6161.                     selected.push(v ? v : null);
  6162.                 });
  6163.             }
  6164.  
  6165.             n = n.cloneNode(true);
  6166.  
  6167.             // IE looses the selected attribute on option elements so we need to restore it
  6168.             if (isIE) {
  6169.                 each(n.getElementsByTagName('option'), function(n, i) {
  6170.                     t.dom.setAttrib(n, 'selected', selected[i]);
  6171.                 });
  6172.             }
  6173.  
  6174.             // Nodes needs to be attached to something in WebKit/Opera
  6175.             // Older builds of Opera crashes if you attach the node to an document created dynamically
  6176.             // and since we can't feature detect a crash we need to sniff the acutal build number
  6177.             // This fix will make DOM ranges and make Sizzle happy!
  6178.             impl = n.ownerDocument.implementation;
  6179.             if (impl.createHTMLDocument && (tinymce.isOpera && opera.buildNumber() >= 1767)) {
  6180.                 // Create an empty HTML document
  6181.                 doc = impl.createHTMLDocument("");
  6182.  
  6183.                 // Add the element or it's children if it's a body element to the new document
  6184.                 each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) {
  6185.                     doc.body.appendChild(doc.importNode(node, true));
  6186.                 });
  6187.  
  6188.                 // Grab first child or body element for serialization
  6189.                 if (n.nodeName != 'BODY')
  6190.                     n = doc.body.firstChild;
  6191.                 else
  6192.                     n = doc.body;
  6193.  
  6194.                 // set the new document in DOMUtils so createElement etc works
  6195.                 oldDoc = t.dom.doc;
  6196.                 t.dom.doc = doc;
  6197.             }
  6198.  
  6199.             t.key = '' + (parseInt(t.key) + 1);
  6200.  
  6201.             // Pre process
  6202.             if (!o.no_events) {
  6203.                 o.node = n;
  6204.                 t.onPreProcess.dispatch(t, o);
  6205.             }
  6206.  
  6207.             // Serialize HTML DOM into a string
  6208.             t.writer.reset();
  6209.             t._serializeNode(n, o.getInner);
  6210.  
  6211.             // Post process
  6212.             o.content = t.writer.getContent();
  6213.  
  6214.             // Restore the old document if it was changed
  6215.             if (oldDoc)
  6216.                 t.dom.doc = oldDoc;
  6217.  
  6218.             if (!o.no_events)
  6219.                 t.onPostProcess.dispatch(t, o);
  6220.  
  6221.             t._postProcess(o);
  6222.             o.node = null;
  6223.  
  6224.             return tinymce.trim(o.content);
  6225.         },
  6226.  
  6227.         // Internal functions
  6228.  
  6229.         _postProcess : function(o) {
  6230.             var t = this, s = t.settings, h = o.content, sc = [], p;
  6231.  
  6232.             if (o.format == 'html') {
  6233.                 // Protect some elements
  6234.                 p = t._protect({
  6235.                     content : h,
  6236.                     patterns : [
  6237.                         {pattern : /(<script[^>]*>)(.*?)(<\/script>)/g},
  6238.                         {pattern : /(<noscript[^>]*>)(.*?)(<\/noscript>)/g},
  6239.                         {pattern : /(<style[^>]*>)(.*?)(<\/style>)/g},
  6240.                         {pattern : /(<pre[^>]*>)(.*?)(<\/pre>)/g, encode : 1},
  6241.                         {pattern : /(<!--\[CDATA\[)(.*?)(\]\]-->)/g}
  6242.                     ]
  6243.                 });
  6244.  
  6245.                 h = p.content;
  6246.  
  6247.                 // Entity encode
  6248.                 if (s.entity_encoding !== 'raw')
  6249.                     h = t._encode(h);
  6250.  
  6251.                 // Use BR instead of &nbsp; padded P elements inside editor and use <p>&nbsp;</p> outside editor
  6252. /*                if (o.set)
  6253.                     h = h.replace(/<p>\s+(&nbsp;| |\u00a0|<br \/>)\s+<\/p>/g, '<p><br /></p>');
  6254.                 else
  6255.                     h = h.replace(/<p>\s+(&nbsp;| |\u00a0|<br \/>)\s+<\/p>/g, '<p>$1</p>');*/
  6256.  
  6257.                 // Since Gecko and Safari keeps whitespace in the DOM we need to
  6258.                 // remove it inorder to match other browsers. But I think Gecko and Safari is right.
  6259.                 // This process is only done when getting contents out from the editor.
  6260.                 if (!o.set) {
  6261.                     // We need to replace paragraph whitespace with an nbsp before indentation to keep the \u00a0 char
  6262.                     h = h.replace(/<p>\s+<\/p>|<p([^>]+)>\s+<\/p>/g, s.entity_encoding == 'numeric' ? '<p$1> </p>' : '<p$1>&nbsp;</p>');
  6263.  
  6264.                     if (s.remove_linebreaks) {
  6265.                         h = h.replace(/\r?\n|\r/g, ' ');
  6266.                         h = h.replace(/(<[^>]+>)\s+/g, '$1 ');
  6267.                         h = h.replace(/\s+(<\/[^>]+>)/g, ' $1');
  6268.                         h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object) ([^>]+)>\s+/g, '<$1 $2>'); // Trim block start
  6269.                         h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>\s+/g, '<$1>'); // Trim block start
  6270.                         h = h.replace(/\s+<\/(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>/g, '</$1>'); // Trim block end
  6271.                     }
  6272.  
  6273.                     // Simple indentation
  6274.                     if (s.apply_source_formatting && s.indent_mode == 'simple') {
  6275.                         // Add line breaks before and after block elements
  6276.                         h = h.replace(/<(\/?)(ul|hr|table|meta|link|tbody|tr|object|body|head|html|map)(|[^>]+)>\s*/g, '\n<$1$2$3>\n');
  6277.                         h = h.replace(/\s*<(p|h[1-6]|blockquote|div|title|style|pre|script|td|li|area)(|[^>]+)>/g, '\n<$1$2>');
  6278.                         h = h.replace(/<\/(p|h[1-6]|blockquote|div|title|style|pre|script|td|li)>\s*/g, '</$1>\n');
  6279.                         h = h.replace(/\n\n/g, '\n');
  6280.                     }
  6281.                 }
  6282.  
  6283.                 h = t._unprotect(h, p);
  6284.  
  6285.                 // Restore CDATA sections
  6286.                 h = h.replace(/<!--\[CDATA\[([\s\S]+)\]\]-->/g, '<![CDATA[$1]]>');
  6287.  
  6288.                 // Restore the \u00a0 character if raw mode is enabled
  6289.                 if (s.entity_encoding == 'raw')
  6290.                     h = h.replace(/<p>&nbsp;<\/p>|<p([^>]+)>&nbsp;<\/p>/g, '<p$1>\u00a0</p>');
  6291.  
  6292.                 // Restore noscript elements
  6293.                 h = h.replace(/<noscript([^>]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) {
  6294.                     return '<noscript' + attribs + '>' + t.dom.decode(text.replace(/<!--|-->/g, '')) + '</noscript>';
  6295.                 });
  6296.             }
  6297.  
  6298.             o.content = h;
  6299.         },
  6300.  
  6301.         _serializeNode : function(n, inn) {
  6302.             var t = this, s = t.settings, w = t.writer, hc, el, cn, i, l, a, at, no, v, nn, ru, ar, iv, closed;
  6303.  
  6304.             if (!s.node_filter || s.node_filter(n)) {
  6305.                 switch (n.nodeType) {
  6306.                     case 1: // Element
  6307.                         if (n.hasAttribute ? n.hasAttribute('mce_bogus') : n.getAttribute('mce_bogus'))
  6308.                             return;
  6309.  
  6310.                         iv = false;
  6311.                         hc = n.hasChildNodes();
  6312.                         nn = n.getAttribute('mce_name') || n.nodeName.toLowerCase();
  6313.  
  6314.                         // Add correct prefix on IE
  6315.                         if (isIE) {
  6316.                             if (n.scopeName !== 'HTML' && n.scopeName !== 'html')
  6317.                                 nn = n.scopeName + ':' + nn;
  6318.                         }
  6319.  
  6320.                         // Remove mce prefix on IE needed for the abbr element
  6321.                         if (nn.indexOf('mce:') === 0)
  6322.                             nn = nn.substring(4);
  6323.  
  6324.                         // Check if valid
  6325.                         if (!t.validElementsRE || !t.validElementsRE.test(nn) || (t.invalidElementsRE && t.invalidElementsRE.test(nn)) || inn) {
  6326.                             iv = true;
  6327.                             break;
  6328.                         }
  6329.  
  6330.                         if (isIE) {
  6331.                             // Fix IE content duplication (DOM can have multiple copies of the same node)
  6332.                             if (s.fix_content_duplication) {
  6333.                                 if (n.mce_serialized == t.key)
  6334.                                     return;
  6335.  
  6336.                                 n.mce_serialized = t.key;
  6337.                             }
  6338.  
  6339.                             // IE sometimes adds a / infront of the node name
  6340.                             if (nn.charAt(0) == '/')
  6341.                                 nn = nn.substring(1);
  6342.                         } else if (isGecko) {
  6343.                             // Ignore br elements
  6344.                             if (n.nodeName === 'BR' && n.getAttribute('type') == '_moz')
  6345.                                 return;
  6346.                         }
  6347.  
  6348.                         // Check if valid child
  6349.                         if (t.childRules) {
  6350.                             if (t.parentElementsRE.test(t.elementName)) {
  6351.                                 if (!t.childRules[t.elementName].test(nn)) {
  6352.                                     iv = true;
  6353.                                     break;
  6354.                                 }
  6355.                             }
  6356.  
  6357.                             t.elementName = nn;
  6358.                         }
  6359.  
  6360.                         ru = t.findRule(nn);
  6361.                         nn = ru.name || nn;
  6362.                         closed = s.closed.test(nn);
  6363.  
  6364.                         // Skip empty nodes or empty node name in IE
  6365.                         if ((!hc && ru.noEmpty) || (isIE && !nn)) {
  6366.                             iv = true;
  6367.                             break;
  6368.                         }
  6369.  
  6370.                         // Check required
  6371.                         if (ru.requiredAttribs) {
  6372.                             a = ru.requiredAttribs;
  6373.  
  6374.                             for (i = a.length - 1; i >= 0; i--) {
  6375.                                 if (this.dom.getAttrib(n, a[i]) !== '')
  6376.                                     break;
  6377.                             }
  6378.  
  6379.                             // None of the required was there
  6380.                             if (i == -1) {
  6381.                                 iv = true;
  6382.                                 break;
  6383.                             }
  6384.                         }
  6385.  
  6386.                         w.writeStartElement(nn);
  6387.  
  6388.                         // Add ordered attributes
  6389.                         if (ru.attribs) {
  6390.                             for (i=0, at = ru.attribs, l = at.length; i<l; i++) {
  6391.                                 a = at[i];
  6392.                                 v = t._getAttrib(n, a);
  6393.  
  6394.                                 if (v !== null)
  6395.                                     w.writeAttribute(a.name, v);
  6396.                             }
  6397.                         }
  6398.  
  6399.                         // Add wild attributes
  6400.                         if (ru.validAttribsRE) {
  6401.                             at = t.dom.getAttribs(n);
  6402.                             for (i=at.length-1; i>-1; i--) {
  6403.                                 no = at[i];
  6404.  
  6405.                                 if (no.specified) {
  6406.                                     a = no.nodeName.toLowerCase();
  6407.  
  6408.                                     if (s.invalid_attrs.test(a) || !ru.validAttribsRE.test(a))
  6409.                                         continue;
  6410.  
  6411.                                     ar = t.findAttribRule(ru, a);
  6412.                                     v = t._getAttrib(n, ar, a);
  6413.  
  6414.                                     if (v !== null)
  6415.                                         w.writeAttribute(a, v);
  6416.                                 }
  6417.                             }
  6418.                         }
  6419.  
  6420.                         // Write text from script
  6421.                         if (nn === 'script' && tinymce.trim(n.innerHTML)) {
  6422.                             w.writeText('// '); // Padd it with a comment so it will parse on older browsers
  6423.                             w.writeCDATA(n.innerHTML.replace(/<!--|-->|<\[CDATA\[|\]\]>/g, '')); // Remove comments and cdata stuctures
  6424.                             hc = false;
  6425.                             break;
  6426.                         }
  6427.  
  6428.                         // Padd empty nodes with a &nbsp;
  6429.                         if (ru.padd) {
  6430.                             // If it has only one bogus child, padd it anyway workaround for <td><br /></td> bug
  6431.                             if (hc && (cn = n.firstChild) && cn.nodeType === 1 && n.childNodes.length === 1) {
  6432.                                 if (cn.hasAttribute ? cn.hasAttribute('mce_bogus') : cn.getAttribute('mce_bogus'))
  6433.                                     w.writeText('\u00a0');
  6434.                             } else if (!hc)
  6435.                                 w.writeText('\u00a0'); // No children then padd it
  6436.                         }
  6437.  
  6438.                         break;
  6439.  
  6440.                     case 3: // Text
  6441.                         // Check if valid child
  6442.                         if (t.childRules && t.parentElementsRE.test(t.elementName)) {
  6443.                             if (!t.childRules[t.elementName].test(n.nodeName))
  6444.                                 return;
  6445.                         }
  6446.  
  6447.                         return w.writeText(n.nodeValue);
  6448.  
  6449.                     case 4: // CDATA
  6450.                         return w.writeCDATA(n.nodeValue);
  6451.  
  6452.                     case 8: // Comment
  6453.                         return w.writeComment(n.nodeValue);
  6454.                 }
  6455.             } else if (n.nodeType == 1)
  6456.                 hc = n.hasChildNodes();
  6457.  
  6458.             if (hc && !closed) {
  6459.                 cn = n.firstChild;
  6460.  
  6461.                 while (cn) {
  6462.                     t._serializeNode(cn);
  6463.                     t.elementName = nn;
  6464.                     cn = cn.nextSibling;
  6465.                 }
  6466.             }
  6467.  
  6468.             // Write element end
  6469.             if (!iv) {
  6470.                 if (!closed)
  6471.                     w.writeFullEndElement();
  6472.                 else
  6473.                     w.writeEndElement();
  6474.             }
  6475.         },
  6476.  
  6477.         _protect : function(o) {
  6478.             var t = this;
  6479.  
  6480.             o.items = o.items || [];
  6481.  
  6482.             function enc(s) {
  6483.                 return s.replace(/[\r\n\\]/g, function(c) {
  6484.                     if (c === '\n')
  6485.                         return '\\n';
  6486.                     else if (c === '\\')
  6487.                         return '\\\\';
  6488.  
  6489.                     return '\\r';
  6490.                 });
  6491.             };
  6492.  
  6493.             function dec(s) {
  6494.                 return s.replace(/\\[\\rn]/g, function(c) {
  6495.                     if (c === '\\n')
  6496.                         return '\n';
  6497.                     else if (c === '\\\\')
  6498.                         return '\\';
  6499.  
  6500.                     return '\r';
  6501.                 });
  6502.             };
  6503.  
  6504.             each(o.patterns, function(p) {
  6505.                 o.content = dec(enc(o.content).replace(p.pattern, function(x, a, b, c) {
  6506.                     b = dec(b);
  6507.  
  6508.                     if (p.encode)
  6509.                         b = t._encode(b);
  6510.  
  6511.                     o.items.push(b);
  6512.                     return a + '<!--mce:' + (o.items.length - 1) + '-->' + c;
  6513.                 }));
  6514.             });
  6515.  
  6516.             return o;
  6517.         },
  6518.  
  6519.         _unprotect : function(h, o) {
  6520.             h = h.replace(/\<!--mce:([0-9]+)--\>/g, function(a, b) {
  6521.                 return o.items[parseInt(b)];
  6522.             });
  6523.  
  6524.             o.items = [];
  6525.  
  6526.             return h;
  6527.         },
  6528.  
  6529.         _encode : function(h) {
  6530.             var t = this, s = t.settings, l;
  6531.  
  6532.             // Entity encode
  6533.             if (s.entity_encoding !== 'raw') {
  6534.                 if (s.entity_encoding.indexOf('named') != -1) {
  6535.                     t.setEntities(s.entities);
  6536.                     l = t.entityLookup;
  6537.  
  6538.                     h = h.replace(t.entitiesRE, function(a) {
  6539.                         var v;
  6540.  
  6541.                         if (v = l[a])
  6542.                             a = '&' + v + ';';
  6543.  
  6544.                         return a;
  6545.                     });
  6546.                 }
  6547.  
  6548.                 if (s.entity_encoding.indexOf('numeric') != -1) {
  6549.                     h = h.replace(/[\u007E-\uFFFF]/g, function(a) {
  6550.                         return '&#' + a.charCodeAt(0) + ';';
  6551.                     });
  6552.                 }
  6553.             }
  6554.  
  6555.             return h;
  6556.         },
  6557.  
  6558.         _setup : function() {
  6559.             var t = this, s = this.settings;
  6560.  
  6561.             if (t.done)
  6562.                 return;
  6563.  
  6564.             t.done = 1;
  6565.  
  6566.             t.setRules(s.valid_elements);
  6567.             t.addRules(s.extended_valid_elements);
  6568.             t.addValidChildRules(s.valid_child_elements);
  6569.  
  6570.             if (s.invalid_elements)
  6571.                 t.invalidElementsRE = new RegExp('^(' + wildcardToRE(s.invalid_elements.replace(/,/g, '|').toLowerCase()) + ')$');
  6572.  
  6573.             if (s.attrib_value_filter)
  6574.                 t.attribValueFilter = s.attribValueFilter;
  6575.         },
  6576.  
  6577.         _getAttrib : function(n, a, na) {
  6578.             var i, v;
  6579.  
  6580.             na = na || a.name;
  6581.  
  6582.             if (a.forcedVal && (v = a.forcedVal)) {
  6583.                 if (v === '{$uid}')
  6584.                     return this.dom.uniqueId();
  6585.  
  6586.                 return v;
  6587.             }
  6588.  
  6589.             v = this.dom.getAttrib(n, na);
  6590.  
  6591.             switch (na) {
  6592.                 case 'rowspan':
  6593.                 case 'colspan':
  6594.                     // Whats the point? Remove usless attribute value
  6595.                     if (v == '1')
  6596.                         v = '';
  6597.  
  6598.                     break;
  6599.             }
  6600.  
  6601.             if (this.attribValueFilter)
  6602.                 v = this.attribValueFilter(na, v, n);
  6603.  
  6604.             if (a.validVals) {
  6605.                 for (i = a.validVals.length - 1; i >= 0; i--) {
  6606.                     if (v == a.validVals[i])
  6607.                         break;
  6608.                 }
  6609.  
  6610.                 if (i == -1)
  6611.                     return null;
  6612.             }
  6613.  
  6614.             if (v === '' && typeof(a.defaultVal) != 'undefined') {
  6615.                 v = a.defaultVal;
  6616.  
  6617.                 if (v === '{$uid}')
  6618.                     return this.dom.uniqueId();
  6619.  
  6620.                 return v;
  6621.             } else {
  6622.                 // Remove internal mceItemXX classes when content is extracted from editor
  6623.                 if (na == 'class' && this.processObj.get)
  6624.                     v = v.replace(/\s?mceItem\w+\s?/g, '');
  6625.             }
  6626.  
  6627.             if (v === '')
  6628.                 return null;
  6629.  
  6630.  
  6631.             return v;
  6632.         }
  6633.     });
  6634. })(tinymce);
  6635. (function(tinymce) {
  6636.     var each = tinymce.each, Event = tinymce.dom.Event;
  6637.  
  6638.     tinymce.create('tinymce.dom.ScriptLoader', {
  6639.         ScriptLoader : function(s) {
  6640.             this.settings = s || {};
  6641.             this.queue = [];
  6642.             this.lookup = {};
  6643.         },
  6644.  
  6645.         isDone : function(u) {
  6646.             return this.lookup[u] ? this.lookup[u].state == 2 : 0;
  6647.         },
  6648.  
  6649.         markDone : function(u) {
  6650.             this.lookup[u] = {state : 2, url : u};
  6651.         },
  6652.  
  6653.         add : function(u, cb, s, pr) {
  6654.             var t = this, lo = t.lookup, o;
  6655.  
  6656.             if (o = lo[u]) {
  6657.                 // Is loaded fire callback
  6658.                 if (cb && o.state == 2)
  6659.                     cb.call(s || this);
  6660.  
  6661.                 return o;
  6662.             }
  6663.  
  6664.             o = {state : 0, url : u, func : cb, scope : s || this};
  6665.  
  6666.             if (pr)
  6667.                 t.queue.unshift(o);
  6668.             else
  6669.                 t.queue.push(o);
  6670.  
  6671.             lo[u] = o;
  6672.  
  6673.             return o;
  6674.         },
  6675.  
  6676.         load : function(u, cb, s) {
  6677.             var t = this, o;
  6678.  
  6679.             if (o = t.lookup[u]) {
  6680.                 // Is loaded fire callback
  6681.                 if (cb && o.state == 2)
  6682.                     cb.call(s || t);
  6683.  
  6684.                 return o;
  6685.             }
  6686.  
  6687.             function loadScript(u) {
  6688.                 if (Event.domLoaded || t.settings.strict_mode) {
  6689.                     tinymce.util.XHR.send({
  6690.                         url : tinymce._addVer(u),
  6691.                         error : t.settings.error,
  6692.                         async : false,
  6693.                         success : function(co) {
  6694.                             t.eval(co);
  6695.                         }
  6696.                     });
  6697.                 } else
  6698.                     document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>');
  6699.             };
  6700.  
  6701.             if (!tinymce.is(u, 'string')) {
  6702.                 each(u, function(u) {
  6703.                     loadScript(u);
  6704.                 });
  6705.  
  6706.                 if (cb)
  6707.                     cb.call(s || t);
  6708.             } else {
  6709.                 loadScript(u);
  6710.  
  6711.                 if (cb)
  6712.                     cb.call(s || t);
  6713.             }
  6714.         },
  6715.  
  6716.         loadQueue : function(cb, s) {
  6717.             var t = this;
  6718.  
  6719.             if (!t.queueLoading) {
  6720.                 t.queueLoading = 1;
  6721.                 t.queueCallbacks = [];
  6722.  
  6723.                 t.loadScripts(t.queue, function() {
  6724.                     t.queueLoading = 0;
  6725.  
  6726.                     if (cb)
  6727.                         cb.call(s || t);
  6728.  
  6729.                     each(t.queueCallbacks, function(o) {
  6730.                         o.func.call(o.scope);
  6731.                     });
  6732.                 });
  6733.             } else if (cb)
  6734.                 t.queueCallbacks.push({func : cb, scope : s || t});
  6735.         },
  6736.  
  6737.         eval : function(co) {
  6738.             var w = window;
  6739.  
  6740.             // Evaluate script
  6741.             if (!w.execScript) {
  6742.                 try {
  6743.                     eval.call(w, co);
  6744.                 } catch (ex) {
  6745.                     eval(co, w); // Firefox 3.0a8
  6746.                 }
  6747.             } else
  6748.                 w.execScript(co); // IE
  6749.         },
  6750.  
  6751.         loadScripts : function(sc, cb, s) {
  6752.             var t = this, lo = t.lookup;
  6753.  
  6754.             function done(o) {
  6755.                 o.state = 2; // Has been loaded
  6756.  
  6757.                 // Run callback
  6758.                 if (o.func)
  6759.                     o.func.call(o.scope || t);
  6760.             };
  6761.  
  6762.             function allDone() {
  6763.                 var l;
  6764.  
  6765.                 // Check if all files are loaded
  6766.                 l = sc.length;
  6767.                 each(sc, function(o) {
  6768.                     o = lo[o.url];
  6769.  
  6770.                     if (o.state === 2) {// It has finished loading
  6771.                         done(o);
  6772.                         l--;
  6773.                     } else
  6774.                         load(o);
  6775.                 });
  6776.  
  6777.                 // They are all loaded
  6778.                 if (l === 0 && cb) {
  6779.                     cb.call(s || t);
  6780.                     cb = 0;
  6781.                 }
  6782.             };
  6783.  
  6784.             function load(o) {
  6785.                 if (o.state > 0)
  6786.                     return;
  6787.  
  6788.                 o.state = 1; // Is loading
  6789.  
  6790.                 tinymce.dom.ScriptLoader.loadScript(o.url, function() {
  6791.                     done(o);
  6792.                     allDone();
  6793.                 });
  6794.  
  6795.                 /*
  6796.                 tinymce.util.XHR.send({
  6797.                     url : o.url,
  6798.                     error : t.settings.error,
  6799.                     success : function(co) {
  6800.                         t.eval(co);
  6801.                         done(o);
  6802.                         allDone();
  6803.                     }
  6804.                 });
  6805.                 */
  6806.             };
  6807.  
  6808.             each(sc, function(o) {
  6809.                 var u = o.url;
  6810.  
  6811.                 // Add to queue if needed
  6812.                 if (!lo[u]) {
  6813.                     lo[u] = o;
  6814.                     t.queue.push(o);
  6815.                 } else
  6816.                     o = lo[u];
  6817.  
  6818.                 // Is already loading or has been loaded
  6819.                 if (o.state > 0)
  6820.                     return;
  6821.  
  6822.                 if (!Event.domLoaded && !t.settings.strict_mode) {
  6823.                     var ix, ol = '';
  6824.  
  6825.                     // Add onload events
  6826.                     if (cb || o.func) {
  6827.                         o.state = 1; // Is loading
  6828.  
  6829.                         ix = tinymce.dom.ScriptLoader._addOnLoad(function() {
  6830.                             done(o);
  6831.                             allDone();
  6832.                         });
  6833.  
  6834.                         if (tinymce.isIE)
  6835.                             ol = ' onreadystatechange="';
  6836.                         else
  6837.                             ol = ' onload="';
  6838.  
  6839.                         ol += 'tinymce.dom.ScriptLoader._onLoad(this,\'' + u + '\',' + ix + ');"';
  6840.                     }
  6841.  
  6842.                     document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"' + ol + '></script>');
  6843.  
  6844.                     if (!o.func)
  6845.                         done(o);
  6846.                 } else
  6847.                     load(o);
  6848.             });
  6849.  
  6850.             allDone();
  6851.         },
  6852.  
  6853.         // Static methods
  6854.         'static' : {
  6855.             _addOnLoad : function(f) {
  6856.                 var t = this;
  6857.  
  6858.                 t._funcs = t._funcs || [];
  6859.                 t._funcs.push(f);
  6860.  
  6861.                 return t._funcs.length - 1;
  6862.             },
  6863.  
  6864.             _onLoad : function(e, u, ix) {
  6865.                 if (!tinymce.isIE || e.readyState == 'complete')
  6866.                     this._funcs[ix].call(this);
  6867.             },
  6868.  
  6869.             loadScript : function(u, cb) {
  6870.                 var id = tinymce.DOM.uniqueId(), e;
  6871.  
  6872.                 function done() {
  6873.                     Event.clear(id);
  6874.                     tinymce.DOM.remove(id);
  6875.  
  6876.                     if (cb) {
  6877.                         cb.call(document, u);
  6878.                         cb = 0;
  6879.                     }
  6880.                 };
  6881.  
  6882.                 if (tinymce.isIE) {
  6883. /*                    Event.add(e, 'readystatechange', function(e) {
  6884.                         if (e.target && e.target.readyState == 'complete')
  6885.                             done();
  6886.                     });*/
  6887.  
  6888.                     tinymce.util.XHR.send({
  6889.                         url : tinymce._addVer(u),
  6890.                         async : false,
  6891.                         success : function(co) {
  6892.                             window.execScript(co);
  6893.                             done();
  6894.                         }
  6895.                     });
  6896.                 } else {
  6897.                     e = tinymce.DOM.create('script', {id : id, type : 'text/javascript', src : tinymce._addVer(u)});
  6898.                     Event.add(e, 'load', done);
  6899.  
  6900.                     // Check for head or body
  6901.                     (document.getElementsByTagName('head')[0] || document.body).appendChild(e);
  6902.                 }
  6903.             }
  6904.         }
  6905.     });
  6906.  
  6907.     // Global script loader
  6908.     tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  6909. })(tinymce);
  6910. (function(tinymce) {
  6911.     // Shorten class names
  6912.     var DOM = tinymce.DOM, is = tinymce.is;
  6913.  
  6914.     tinymce.create('tinymce.ui.Control', {
  6915.         Control : function(id, s) {
  6916.             this.id = id;
  6917.             this.settings = s = s || {};
  6918.             this.rendered = false;
  6919.             this.onRender = new tinymce.util.Dispatcher(this);
  6920.             this.classPrefix = '';
  6921.             this.scope = s.scope || this;
  6922.             this.disabled = 0;
  6923.             this.active = 0;
  6924.         },
  6925.  
  6926.         setDisabled : function(s) {
  6927.             var e;
  6928.  
  6929.             if (s != this.disabled) {
  6930.                 e = DOM.get(this.id);
  6931.  
  6932.                 // Add accessibility title for unavailable actions
  6933.                 if (e && this.settings.unavailable_prefix) {
  6934.                     if (s) {
  6935.                         this.prevTitle = e.title;
  6936.                         e.title = this.settings.unavailable_prefix + ": " + e.title;
  6937.                     } else
  6938.                         e.title = this.prevTitle;
  6939.                 }
  6940.  
  6941.                 this.setState('Disabled', s);
  6942.                 this.setState('Enabled', !s);
  6943.                 this.disabled = s;
  6944.             }
  6945.         },
  6946.  
  6947.         isDisabled : function() {
  6948.             return this.disabled;
  6949.         },
  6950.  
  6951.         setActive : function(s) {
  6952.             if (s != this.active) {
  6953.                 this.setState('Active', s);
  6954.                 this.active = s;
  6955.             }
  6956.         },
  6957.  
  6958.         isActive : function() {
  6959.             return this.active;
  6960.         },
  6961.  
  6962.         setState : function(c, s) {
  6963.             var n = DOM.get(this.id);
  6964.  
  6965.             c = this.classPrefix + c;
  6966.  
  6967.             if (s)
  6968.                 DOM.addClass(n, c);
  6969.             else
  6970.                 DOM.removeClass(n, c);
  6971.         },
  6972.  
  6973.         isRendered : function() {
  6974.             return this.rendered;
  6975.         },
  6976.  
  6977.         renderHTML : function() {
  6978.         },
  6979.  
  6980.         renderTo : function(n) {
  6981.             DOM.setHTML(n, this.renderHTML());
  6982.         },
  6983.  
  6984.         postRender : function() {
  6985.             var t = this, b;
  6986.  
  6987.             // Set pending states
  6988.             if (is(t.disabled)) {
  6989.                 b = t.disabled;
  6990.                 t.disabled = -1;
  6991.                 t.setDisabled(b);
  6992.             }
  6993.  
  6994.             if (is(t.active)) {
  6995.                 b = t.active;
  6996.                 t.active = -1;
  6997.                 t.setActive(b);
  6998.             }
  6999.         },
  7000.  
  7001.         remove : function() {
  7002.             DOM.remove(this.id);
  7003.             this.destroy();
  7004.         },
  7005.  
  7006.         destroy : function() {
  7007.             tinymce.dom.Event.clear(this.id);
  7008.         }
  7009.     });
  7010. })(tinymce);tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  7011.     Container : function(id, s) {
  7012.         this.parent(id, s);
  7013.  
  7014.         this.controls = [];
  7015.  
  7016.         this.lookup = {};
  7017.     },
  7018.  
  7019.     add : function(c) {
  7020.         this.lookup[c.id] = c;
  7021.         this.controls.push(c);
  7022.  
  7023.         return c;
  7024.     },
  7025.  
  7026.     get : function(n) {
  7027.         return this.lookup[n];
  7028.     }
  7029. });
  7030.  
  7031. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  7032.     Separator : function(id, s) {
  7033.         this.parent(id, s);
  7034.         this.classPrefix = 'mceSeparator';
  7035.     },
  7036.  
  7037.     renderHTML : function() {
  7038.         return tinymce.DOM.createHTML('span', {'class' : this.classPrefix});
  7039.     }
  7040. });
  7041. (function(tinymce) {
  7042.     var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7043.  
  7044.     tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  7045.         MenuItem : function(id, s) {
  7046.             this.parent(id, s);
  7047.             this.classPrefix = 'mceMenuItem';
  7048.         },
  7049.  
  7050.         setSelected : function(s) {
  7051.             this.setState('Selected', s);
  7052.             this.selected = s;
  7053.         },
  7054.  
  7055.         isSelected : function() {
  7056.             return this.selected;
  7057.         },
  7058.  
  7059.         postRender : function() {
  7060.             var t = this;
  7061.  
  7062.             t.parent();
  7063.  
  7064.             // Set pending state
  7065.             if (is(t.selected))
  7066.                 t.setSelected(t.selected);
  7067.         }
  7068.     });
  7069. })(tinymce);
  7070. (function(tinymce) {
  7071.     var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7072.  
  7073.     tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  7074.         Menu : function(id, s) {
  7075.             var t = this;
  7076.  
  7077.             t.parent(id, s);
  7078.             t.items = {};
  7079.             t.collapsed = false;
  7080.             t.menuCount = 0;
  7081.             t.onAddItem = new tinymce.util.Dispatcher(this);
  7082.         },
  7083.  
  7084.         expand : function(d) {
  7085.             var t = this;
  7086.  
  7087.             if (d) {
  7088.                 walk(t, function(o) {
  7089.                     if (o.expand)
  7090.                         o.expand();
  7091.                 }, 'items', t);
  7092.             }
  7093.  
  7094.             t.collapsed = false;
  7095.         },
  7096.  
  7097.         collapse : function(d) {
  7098.             var t = this;
  7099.  
  7100.             if (d) {
  7101.                 walk(t, function(o) {
  7102.                     if (o.collapse)
  7103.                         o.collapse();
  7104.                 }, 'items', t);
  7105.             }
  7106.  
  7107.             t.collapsed = true;
  7108.         },
  7109.  
  7110.         isCollapsed : function() {
  7111.             return this.collapsed;
  7112.         },
  7113.  
  7114.         add : function(o) {
  7115.             if (!o.settings)
  7116.                 o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  7117.  
  7118.             this.onAddItem.dispatch(this, o);
  7119.  
  7120.             return this.items[o.id] = o;
  7121.         },
  7122.  
  7123.         addSeparator : function() {
  7124.             return this.add({separator : true});
  7125.         },
  7126.  
  7127.         addMenu : function(o) {
  7128.             if (!o.collapse)
  7129.                 o = this.createMenu(o);
  7130.  
  7131.             this.menuCount++;
  7132.  
  7133.             return this.add(o);
  7134.         },
  7135.  
  7136.         hasMenus : function() {
  7137.             return this.menuCount !== 0;
  7138.         },
  7139.  
  7140.         remove : function(o) {
  7141.             delete this.items[o.id];
  7142.         },
  7143.  
  7144.         removeAll : function() {
  7145.             var t = this;
  7146.  
  7147.             walk(t, function(o) {
  7148.                 if (o.removeAll)
  7149.                     o.removeAll();
  7150.                 else
  7151.                     o.remove();
  7152.  
  7153.                 o.destroy();
  7154.             }, 'items', t);
  7155.  
  7156.             t.items = {};
  7157.         },
  7158.  
  7159.         createMenu : function(o) {
  7160.             var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  7161.  
  7162.             m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  7163.  
  7164.             return m;
  7165.         }
  7166.     });
  7167. })(tinymce);(function(tinymce) {
  7168.     var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  7169.  
  7170.     tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  7171.         DropMenu : function(id, s) {
  7172.             s = s || {};
  7173.             s.container = s.container || DOM.doc.body;
  7174.             s.offset_x = s.offset_x || 0;
  7175.             s.offset_y = s.offset_y || 0;
  7176.             s.vp_offset_x = s.vp_offset_x || 0;
  7177.             s.vp_offset_y = s.vp_offset_y || 0;
  7178.  
  7179.             if (is(s.icons) && !s.icons)
  7180.                 s['class'] += ' mceNoIcons';
  7181.  
  7182.             this.parent(id, s);
  7183.             this.onShowMenu = new tinymce.util.Dispatcher(this);
  7184.             this.onHideMenu = new tinymce.util.Dispatcher(this);
  7185.             this.classPrefix = 'mceMenu';
  7186.         },
  7187.  
  7188.         createMenu : function(s) {
  7189.             var t = this, cs = t.settings, m;
  7190.  
  7191.             s.container = s.container || cs.container;
  7192.             s.parent = t;
  7193.             s.constrain = s.constrain || cs.constrain;
  7194.             s['class'] = s['class'] || cs['class'];
  7195.             s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  7196.             s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  7197.             m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  7198.  
  7199.             m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  7200.  
  7201.             return m;
  7202.         },
  7203.  
  7204.         update : function() {
  7205.             var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  7206.  
  7207.             tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth;
  7208.             th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight;
  7209.  
  7210.             if (!DOM.boxModel)
  7211.                 t.element.setStyles({width : tw + 2, height : th + 2});
  7212.             else
  7213.                 t.element.setStyles({width : tw, height : th});
  7214.  
  7215.             if (s.max_width)
  7216.                 DOM.setStyle(co, 'width', tw);
  7217.  
  7218.             if (s.max_height) {
  7219.                 DOM.setStyle(co, 'height', th);
  7220.  
  7221.                 if (tb.clientHeight < s.max_height)
  7222.                     DOM.setStyle(co, 'overflow', 'hidden');
  7223.             }
  7224.         },
  7225.  
  7226.         showMenu : function(x, y, px) {
  7227.             var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  7228.  
  7229.             t.collapse(1);
  7230.  
  7231.             if (t.isMenuVisible)
  7232.                 return;
  7233.  
  7234.             if (!t.rendered) {
  7235.                 co = DOM.add(t.settings.container, t.renderNode());
  7236.  
  7237.                 each(t.items, function(o) {
  7238.                     o.postRender();
  7239.                 });
  7240.  
  7241.                 t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7242.             } else
  7243.                 co = DOM.get('menu_' + t.id);
  7244.  
  7245.             // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  7246.             if (!tinymce.isOpera)
  7247.                 DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  7248.  
  7249.             DOM.show(co);
  7250.             t.update();
  7251.  
  7252.             x += s.offset_x || 0;
  7253.             y += s.offset_y || 0;
  7254.             vp.w -= 4;
  7255.             vp.h -= 4;
  7256.  
  7257.             // Move inside viewport if not submenu
  7258.             if (s.constrain) {
  7259.                 w = co.clientWidth - ot;
  7260.                 h = co.clientHeight - ot;
  7261.                 mx = vp.x + vp.w;
  7262.                 my = vp.y + vp.h;
  7263.  
  7264.                 if ((x + s.vp_offset_x + w) > mx)
  7265.                     x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  7266.  
  7267.                 if ((y + s.vp_offset_y + h) > my)
  7268.                     y = Math.max(0, (my - s.vp_offset_y) - h);
  7269.             }
  7270.  
  7271.             DOM.setStyles(co, {left : x , top : y});
  7272.             t.element.update();
  7273.  
  7274.             t.isMenuVisible = 1;
  7275.             t.mouseClickFunc = Event.add(co, 'click', function(e) {
  7276.                 var m;
  7277.  
  7278.                 e = e.target;
  7279.  
  7280.                 if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  7281.                     m = t.items[e.id];
  7282.  
  7283.                     if (m.isDisabled())
  7284.                         return;
  7285.  
  7286.                     dm = t;
  7287.  
  7288.                     while (dm) {
  7289.                         if (dm.hideMenu)
  7290.                             dm.hideMenu();
  7291.  
  7292.                         dm = dm.settings.parent;
  7293.                     }
  7294.  
  7295.                     if (m.settings.onclick)
  7296.                         m.settings.onclick(e);
  7297.  
  7298.                     return Event.cancel(e); // Cancel to fix onbeforeunload problem
  7299.                 }
  7300.             });
  7301.  
  7302.             if (t.hasMenus()) {
  7303.                 t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  7304.                     var m, r, mi;
  7305.  
  7306.                     e = e.target;
  7307.                     if (e && (e = DOM.getParent(e, 'tr'))) {
  7308.                         m = t.items[e.id];
  7309.  
  7310.                         if (t.lastMenu)
  7311.                             t.lastMenu.collapse(1);
  7312.  
  7313.                         if (m.isDisabled())
  7314.                             return;
  7315.  
  7316.                         if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  7317.                             //p = DOM.getPos(s.container);
  7318.                             r = DOM.getRect(e);
  7319.                             m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  7320.                             t.lastMenu = m;
  7321.                             DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  7322.                         }
  7323.                     }
  7324.                 });
  7325.             }
  7326.  
  7327.             t.onShowMenu.dispatch(t);
  7328.  
  7329.             if (s.keyboard_focus) {
  7330.                 Event.add(co, 'keydown', t._keyHandler, t);
  7331.                 DOM.select('a', 'menu_' + t.id)[0].focus(); // Select first link
  7332.                 t._focusIdx = 0;
  7333.             }
  7334.         },
  7335.  
  7336.         hideMenu : function(c) {
  7337.             var t = this, co = DOM.get('menu_' + t.id), e;
  7338.  
  7339.             if (!t.isMenuVisible)
  7340.                 return;
  7341.  
  7342.             Event.remove(co, 'mouseover', t.mouseOverFunc);
  7343.             Event.remove(co, 'click', t.mouseClickFunc);
  7344.             Event.remove(co, 'keydown', t._keyHandler);
  7345.             DOM.hide(co);
  7346.             t.isMenuVisible = 0;
  7347.  
  7348.             if (!c)
  7349.                 t.collapse(1);
  7350.  
  7351.             if (t.element)
  7352.                 t.element.hide();
  7353.  
  7354.             if (e = DOM.get(t.id))
  7355.                 DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  7356.  
  7357.             t.onHideMenu.dispatch(t);
  7358.         },
  7359.  
  7360.         add : function(o) {
  7361.             var t = this, co;
  7362.  
  7363.             o = t.parent(o);
  7364.  
  7365.             if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  7366.                 t._add(DOM.select('tbody', co)[0], o);
  7367.  
  7368.             return o;
  7369.         },
  7370.  
  7371.         collapse : function(d) {
  7372.             this.parent(d);
  7373.             this.hideMenu(1);
  7374.         },
  7375.  
  7376.         remove : function(o) {
  7377.             DOM.remove(o.id);
  7378.             this.destroy();
  7379.  
  7380.             return this.parent(o);
  7381.         },
  7382.  
  7383.         destroy : function() {
  7384.             var t = this, co = DOM.get('menu_' + t.id);
  7385.  
  7386.             Event.remove(co, 'mouseover', t.mouseOverFunc);
  7387.             Event.remove(co, 'click', t.mouseClickFunc);
  7388.  
  7389.             if (t.element)
  7390.                 t.element.remove();
  7391.  
  7392.             DOM.remove(co);
  7393.         },
  7394.  
  7395.         renderNode : function() {
  7396.             var t = this, s = t.settings, n, tb, co, w;
  7397.  
  7398.             w = DOM.create('div', {id : 'menu_' + t.id, 'class' : s['class'], 'style' : 'position:absolute;left:0;top:0;z-index:200000'});
  7399.             co = DOM.add(w, 'div', {id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  7400.             t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7401.  
  7402.             if (s.menu_line)
  7403.                 DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  7404.  
  7405. //            n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  7406.             n = DOM.add(co, 'table', {id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  7407.             tb = DOM.add(n, 'tbody');
  7408.  
  7409.             each(t.items, function(o) {
  7410.                 t._add(tb, o);
  7411.             });
  7412.  
  7413.             t.rendered = true;
  7414.  
  7415.             return w;
  7416.         },
  7417.  
  7418.         // Internal functions
  7419.  
  7420.         _keyHandler : function(e) {
  7421.             var t = this, kc = e.keyCode;
  7422.  
  7423.             function focus(d) {
  7424.                 var i = t._focusIdx + d, e = DOM.select('a', 'menu_' + t.id)[i];
  7425.  
  7426.                 if (e) {
  7427.                     t._focusIdx = i;
  7428.                     e.focus();
  7429.                 }
  7430.             };
  7431.  
  7432.             switch (kc) {
  7433.                 case 38:
  7434.                     focus(-1); // Select first link
  7435.                     return;
  7436.  
  7437.                 case 40:
  7438.                     focus(1);
  7439.                     return;
  7440.  
  7441.                 case 13:
  7442.                     return;
  7443.  
  7444.                 case 27:
  7445.                     return this.hideMenu();
  7446.             }
  7447.         },
  7448.  
  7449.         _add : function(tb, o) {
  7450.             var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  7451.  
  7452.             if (s.separator) {
  7453.                 ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  7454.                 DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  7455.  
  7456.                 if (n = ro.previousSibling)
  7457.                     DOM.addClass(n, 'mceLast');
  7458.  
  7459.                 return;
  7460.             }
  7461.  
  7462.             n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  7463.             n = it = DOM.add(n, 'td');
  7464.             n = a = DOM.add(n, 'a', {href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  7465.  
  7466.             DOM.addClass(it, s['class']);
  7467. //            n = DOM.add(n, 'span', {'class' : 'item'});
  7468.  
  7469.             ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  7470.  
  7471.             if (s.icon_src)
  7472.                 DOM.add(ic, 'img', {src : s.icon_src});
  7473.  
  7474.             n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  7475.  
  7476.             if (o.settings.style)
  7477.                 DOM.setAttrib(n, 'style', o.settings.style);
  7478.  
  7479.             if (tb.childNodes.length == 1)
  7480.                 DOM.addClass(ro, 'mceFirst');
  7481.  
  7482.             if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  7483.                 DOM.addClass(ro, 'mceFirst');
  7484.  
  7485.             if (o.collapse)
  7486.                 DOM.addClass(ro, cp + 'ItemSub');
  7487.  
  7488.             if (n = ro.previousSibling)
  7489.                 DOM.removeClass(n, 'mceLast');
  7490.  
  7491.             DOM.addClass(ro, 'mceLast');
  7492.         }
  7493.     });
  7494. })(tinymce);(function(tinymce) {
  7495.     var DOM = tinymce.DOM;
  7496.  
  7497.     tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  7498.         Button : function(id, s) {
  7499.             this.parent(id, s);
  7500.             this.classPrefix = 'mceButton';
  7501.         },
  7502.  
  7503.         renderHTML : function() {
  7504.             var cp = this.classPrefix, s = this.settings, h, l;
  7505.  
  7506.             l = DOM.encode(s.label || '');
  7507.             h = '<a id="' + this.id + '" href="javascript:;" class="' + cp + ' ' + cp + 'Enabled ' + s['class'] + (l ? ' ' + cp + 'Labeled' : '') +'" onmousedown="return false;" onclick="return false;" title="' + DOM.encode(s.title) + '">';
  7508.  
  7509.             if (s.image)
  7510.                 h += '<img class="mceIcon" src="' + s.image + '" />' + l + '</a>';
  7511.             else
  7512.                 h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '') + '</a>';
  7513.  
  7514.             return h;
  7515.         },
  7516.  
  7517.         postRender : function() {
  7518.             var t = this, s = t.settings;
  7519.  
  7520.             tinymce.dom.Event.add(t.id, 'click', function(e) {
  7521.                 if (!t.isDisabled())
  7522.                     return s.onclick.call(s.scope, e);
  7523.             });
  7524.         }
  7525.     });
  7526. })(tinymce);
  7527. (function(tinymce) {
  7528.     var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7529.  
  7530.     tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  7531.         ListBox : function(id, s) {
  7532.             var t = this;
  7533.  
  7534.             t.parent(id, s);
  7535.  
  7536.             t.items = [];
  7537.  
  7538.             t.onChange = new Dispatcher(t);
  7539.  
  7540.             t.onPostRender = new Dispatcher(t);
  7541.  
  7542.             t.onAdd = new Dispatcher(t);
  7543.  
  7544.             t.onRenderMenu = new tinymce.util.Dispatcher(this);
  7545.  
  7546.             t.classPrefix = 'mceListBox';
  7547.         },
  7548.  
  7549.         select : function(va) {
  7550.             var t = this, fv, f;
  7551.  
  7552.             if (va == undefined)
  7553.                 return t.selectByIndex(-1);
  7554.  
  7555.             // Is string or number make function selector
  7556.             if (va && va.call)
  7557.                 f = va;
  7558.             else {
  7559.                 f = function(v) {
  7560.                     return v == va;
  7561.                 };
  7562.             }
  7563.  
  7564.             // Do we need to do something?
  7565.             if (va != t.selectedValue) {
  7566.                 // Find item
  7567.                 each(t.items, function(o, i) {
  7568.                     if (f(o.value)) {
  7569.                         fv = 1;
  7570.                         t.selectByIndex(i);
  7571.                         return false;
  7572.                     }
  7573.                 });
  7574.  
  7575.                 if (!fv)
  7576.                     t.selectByIndex(-1);
  7577.             }
  7578.         },
  7579.  
  7580.         selectByIndex : function(idx) {
  7581.             var t = this, e, o;
  7582.  
  7583.             if (idx != t.selectedIndex) {
  7584.                 e = DOM.get(t.id + '_text');
  7585.                 o = t.items[idx];
  7586.  
  7587.                 if (o) {
  7588.                     t.selectedValue = o.value;
  7589.                     t.selectedIndex = idx;
  7590.                     DOM.setHTML(e, DOM.encode(o.title));
  7591.                     DOM.removeClass(e, 'mceTitle');
  7592.                 } else {
  7593.                     DOM.setHTML(e, DOM.encode(t.settings.title));
  7594.                     DOM.addClass(e, 'mceTitle');
  7595.                     t.selectedValue = t.selectedIndex = null;
  7596.                 }
  7597.  
  7598.                 e = 0;
  7599.             }
  7600.         },
  7601.  
  7602.         add : function(n, v, o) {
  7603.             var t = this;
  7604.  
  7605.             o = o || {};
  7606.             o = tinymce.extend(o, {
  7607.                 title : n,
  7608.                 value : v
  7609.             });
  7610.  
  7611.             t.items.push(o);
  7612.             t.onAdd.dispatch(t, o);
  7613.         },
  7614.  
  7615.         getLength : function() {
  7616.             return this.items.length;
  7617.         },
  7618.  
  7619.         renderHTML : function() {
  7620.             var h = '', t = this, s = t.settings, cp = t.classPrefix;
  7621.  
  7622.             h = '<table id="' + t.id + '" cellpadding="0" cellspacing="0" class="' + cp + ' ' + cp + 'Enabled' + (s['class'] ? (' ' + s['class']) : '') + '"><tbody><tr>';
  7623.             h += '<td>' + DOM.createHTML('a', {id : t.id + '_text', href : 'javascript:;', 'class' : 'mceText', onclick : "return false;", onmousedown : 'return false;'}, DOM.encode(t.settings.title)) + '</td>';
  7624.             h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', tabindex : -1, href : 'javascript:;', 'class' : 'mceOpen', onclick : "return false;", onmousedown : 'return false;'}, '<span></span>') + '</td>';
  7625.             h += '</tr></tbody></table>';
  7626.  
  7627.             return h;
  7628.         },
  7629.  
  7630.         showMenu : function() {
  7631.             var t = this, p1, p2, e = DOM.get(this.id), m;
  7632.  
  7633.             if (t.isDisabled() || t.items.length == 0)
  7634.                 return;
  7635.  
  7636.             if (t.menu && t.menu.isMenuVisible)
  7637.                 return t.hideMenu();
  7638.  
  7639.             if (!t.isMenuRendered) {
  7640.                 t.renderMenu();
  7641.                 t.isMenuRendered = true;
  7642.             }
  7643.  
  7644.             p1 = DOM.getPos(this.settings.menu_container);
  7645.             p2 = DOM.getPos(e);
  7646.  
  7647.             m = t.menu;
  7648.             m.settings.offset_x = p2.x;
  7649.             m.settings.offset_y = p2.y;
  7650.             m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  7651.  
  7652.             // Select in menu
  7653.             if (t.oldID)
  7654.                 m.items[t.oldID].setSelected(0);
  7655.  
  7656.             each(t.items, function(o) {
  7657.                 if (o.value === t.selectedValue) {
  7658.                     m.items[o.id].setSelected(1);
  7659.                     t.oldID = o.id;
  7660.                 }
  7661.             });
  7662.  
  7663.             m.showMenu(0, e.clientHeight);
  7664.  
  7665.             Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7666.             DOM.addClass(t.id, t.classPrefix + 'Selected');
  7667.  
  7668.             //DOM.get(t.id + '_text').focus();
  7669.         },
  7670.  
  7671.         hideMenu : function(e) {
  7672.             var t = this;
  7673.  
  7674.             // Prevent double toogles by canceling the mouse click event to the button
  7675.             if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  7676.                 return;
  7677.  
  7678.             if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7679.                 DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7680.                 Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7681.  
  7682.                 if (t.menu)
  7683.                     t.menu.hideMenu();
  7684.             }
  7685.         },
  7686.  
  7687.         renderMenu : function() {
  7688.             var t = this, m;
  7689.  
  7690.             m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7691.                 menu_line : 1,
  7692.                 'class' : t.classPrefix + 'Menu mceNoIcons',
  7693.                 max_width : 150,
  7694.                 max_height : 150
  7695.             });
  7696.  
  7697.             m.onHideMenu.add(t.hideMenu, t);
  7698.  
  7699.             m.add({
  7700.                 title : t.settings.title,
  7701.                 'class' : 'mceMenuItemTitle',
  7702.                 onclick : function() {
  7703.                     if (t.settings.onselect('') !== false)
  7704.                         t.select(''); // Must be runned after
  7705.                 }
  7706.             });
  7707.  
  7708.             each(t.items, function(o) {
  7709.                 o.id = DOM.uniqueId();
  7710.                 o.onclick = function() {
  7711.                     if (t.settings.onselect(o.value) !== false)
  7712.                         t.select(o.value); // Must be runned after
  7713.                 };
  7714.  
  7715.                 m.add(o);
  7716.             });
  7717.  
  7718.             t.onRenderMenu.dispatch(t, m);
  7719.             t.menu = m;
  7720.         },
  7721.  
  7722.         postRender : function() {
  7723.             var t = this, cp = t.classPrefix;
  7724.  
  7725.             Event.add(t.id, 'click', t.showMenu, t);
  7726.             Event.add(t.id + '_text', 'focus', function(e) {
  7727.                 if (!t._focused) {
  7728.                     t.keyDownHandler = Event.add(t.id + '_text', 'keydown', function(e) {
  7729.                         var idx = -1, v, kc = e.keyCode;
  7730.  
  7731.                         // Find current index
  7732.                         each(t.items, function(v, i) {
  7733.                             if (t.selectedValue == v.value)
  7734.                                 idx = i;
  7735.                         });
  7736.  
  7737.                         // Move up/down
  7738.                         if (kc == 38)
  7739.                             v = t.items[idx - 1];
  7740.                         else if (kc == 40)
  7741.                             v = t.items[idx + 1];
  7742.                         else if (kc == 13) {
  7743.                             // Fake select on enter
  7744.                             v = t.selectedValue;
  7745.                             t.selectedValue = null; // Needs to be null to fake change
  7746.                             t.settings.onselect(v);
  7747.                             return Event.cancel(e);
  7748.                         }
  7749.  
  7750.                         if (v) {
  7751.                             t.hideMenu();
  7752.                             t.select(v.value);
  7753.                         }
  7754.                     });
  7755.                 }
  7756.  
  7757.                 t._focused = 1;
  7758.             });
  7759.             Event.add(t.id + '_text', 'blur', function() {Event.remove(t.id + '_text', 'keydown', t.keyDownHandler); t._focused = 0;});
  7760.  
  7761.             // Old IE doesn't have hover on all elements
  7762.             if (tinymce.isIE6 || !DOM.boxModel) {
  7763.                 Event.add(t.id, 'mouseover', function() {
  7764.                     if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7765.                         DOM.addClass(t.id, cp + 'Hover');
  7766.                 });
  7767.  
  7768.                 Event.add(t.id, 'mouseout', function() {
  7769.                     if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7770.                         DOM.removeClass(t.id, cp + 'Hover');
  7771.                 });
  7772.             }
  7773.  
  7774.             t.onPostRender.dispatch(t, DOM.get(t.id));
  7775.         },
  7776.  
  7777.         destroy : function() {
  7778.             this.parent();
  7779.  
  7780.             Event.clear(this.id + '_text');
  7781.             Event.clear(this.id + '_open');
  7782.         }
  7783.     });
  7784. })(tinymce);(function(tinymce) {
  7785.     var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7786.  
  7787.     tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  7788.         NativeListBox : function(id, s) {
  7789.             this.parent(id, s);
  7790.             this.classPrefix = 'mceNativeListBox';
  7791.         },
  7792.  
  7793.         setDisabled : function(s) {
  7794.             DOM.get(this.id).disabled = s;
  7795.         },
  7796.  
  7797.         isDisabled : function() {
  7798.             return DOM.get(this.id).disabled;
  7799.         },
  7800.  
  7801.         select : function(va) {
  7802.             var t = this, fv, f;
  7803.  
  7804.             if (va == undefined)
  7805.                 return t.selectByIndex(-1);
  7806.  
  7807.             // Is string or number make function selector
  7808.             if (va && va.call)
  7809.                 f = va;
  7810.             else {
  7811.                 f = function(v) {
  7812.                     return v == va;
  7813.                 };
  7814.             }
  7815.  
  7816.             // Do we need to do something?
  7817.             if (va != t.selectedValue) {
  7818.                 // Find item
  7819.                 each(t.items, function(o, i) {
  7820.                     if (f(o.value)) {
  7821.                         fv = 1;
  7822.                         t.selectByIndex(i);
  7823.                         return false;
  7824.                     }
  7825.                 });
  7826.  
  7827.                 if (!fv)
  7828.                     t.selectByIndex(-1);
  7829.             }
  7830.         },
  7831.  
  7832.         selectByIndex : function(idx) {
  7833.             DOM.get(this.id).selectedIndex = idx + 1;
  7834.             this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  7835.         },
  7836.  
  7837.         add : function(n, v, a) {
  7838.             var o, t = this;
  7839.  
  7840.             a = a || {};
  7841.             a.value = v;
  7842.  
  7843.             if (t.isRendered())
  7844.                 DOM.add(DOM.get(this.id), 'option', a, n);
  7845.  
  7846.             o = {
  7847.                 title : n,
  7848.                 value : v,
  7849.                 attribs : a
  7850.             };
  7851.  
  7852.             t.items.push(o);
  7853.             t.onAdd.dispatch(t, o);
  7854.         },
  7855.  
  7856.         getLength : function() {
  7857.             return DOM.get(this.id).options.length - 1;
  7858.         },
  7859.  
  7860.         renderHTML : function() {
  7861.             var h, t = this;
  7862.  
  7863.             h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  7864.  
  7865.             each(t.items, function(it) {
  7866.                 h += DOM.createHTML('option', {value : it.value}, it.title);
  7867.             });
  7868.  
  7869.             h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox'}, h);
  7870.  
  7871.             return h;
  7872.         },
  7873.  
  7874.         postRender : function() {
  7875.             var t = this, ch;
  7876.  
  7877.             t.rendered = true;
  7878.  
  7879.             function onChange(e) {
  7880.                 var v = t.items[e.target.selectedIndex - 1];
  7881.  
  7882.                 if (v && (v = v.value)) {
  7883.                     t.onChange.dispatch(t, v);
  7884.  
  7885.                     if (t.settings.onselect)
  7886.                         t.settings.onselect(v);
  7887.                 }
  7888.             };
  7889.  
  7890.             Event.add(t.id, 'change', onChange);
  7891.  
  7892.             // Accessibility keyhandler
  7893.             Event.add(t.id, 'keydown', function(e) {
  7894.                 var bf;
  7895.  
  7896.                 Event.remove(t.id, 'change', ch);
  7897.  
  7898.                 bf = Event.add(t.id, 'blur', function() {
  7899.                     Event.add(t.id, 'change', onChange);
  7900.                     Event.remove(t.id, 'blur', bf);
  7901.                 });
  7902.  
  7903.                 if (e.keyCode == 13 || e.keyCode == 32) {
  7904.                     onChange(e);
  7905.                     return Event.cancel(e);
  7906.                 }
  7907.             });
  7908.  
  7909.             t.onPostRender.dispatch(t, DOM.get(t.id));
  7910.         }
  7911.     });
  7912. })(tinymce);(function(tinymce) {
  7913.     var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  7914.  
  7915.     tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  7916.         MenuButton : function(id, s) {
  7917.             this.parent(id, s);
  7918.  
  7919.             this.onRenderMenu = new tinymce.util.Dispatcher(this);
  7920.  
  7921.             s.menu_container = s.menu_container || DOM.doc.body;
  7922.         },
  7923.  
  7924.         showMenu : function() {
  7925.             var t = this, p1, p2, e = DOM.get(t.id), m;
  7926.  
  7927.             if (t.isDisabled())
  7928.                 return;
  7929.  
  7930.             if (!t.isMenuRendered) {
  7931.                 t.renderMenu();
  7932.                 t.isMenuRendered = true;
  7933.             }
  7934.  
  7935.             if (t.isMenuVisible)
  7936.                 return t.hideMenu();
  7937.  
  7938.             p1 = DOM.getPos(t.settings.menu_container);
  7939.             p2 = DOM.getPos(e);
  7940.  
  7941.             m = t.menu;
  7942.             m.settings.offset_x = p2.x;
  7943.             m.settings.offset_y = p2.y;
  7944.             m.settings.vp_offset_x = p2.x;
  7945.             m.settings.vp_offset_y = p2.y;
  7946.             m.settings.keyboard_focus = t._focused;
  7947.             m.showMenu(0, e.clientHeight);
  7948.  
  7949.             Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7950.             t.setState('Selected', 1);
  7951.  
  7952.             t.isMenuVisible = 1;
  7953.         },
  7954.  
  7955.         renderMenu : function() {
  7956.             var t = this, m;
  7957.  
  7958.             m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7959.                 menu_line : 1,
  7960.                 'class' : this.classPrefix + 'Menu',
  7961.                 icons : t.settings.icons
  7962.             });
  7963.  
  7964.             m.onHideMenu.add(t.hideMenu, t);
  7965.  
  7966.             t.onRenderMenu.dispatch(t, m);
  7967.             t.menu = m;
  7968.         },
  7969.  
  7970.         hideMenu : function(e) {
  7971.             var t = this;
  7972.  
  7973.             // Prevent double toogles by canceling the mouse click event to the button
  7974.             if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  7975.                 return;
  7976.  
  7977.             if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7978.                 t.setState('Selected', 0);
  7979.                 Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7980.                 if (t.menu)
  7981.                     t.menu.hideMenu();
  7982.             }
  7983.  
  7984.             t.isMenuVisible = 0;
  7985.         },
  7986.  
  7987.         postRender : function() {
  7988.             var t = this, s = t.settings;
  7989.  
  7990.             Event.add(t.id, 'click', function() {
  7991.                 if (!t.isDisabled()) {
  7992.                     if (s.onclick)
  7993.                         s.onclick(t.value);
  7994.  
  7995.                     t.showMenu();
  7996.                 }
  7997.             });
  7998.         }
  7999.     });
  8000. })(tinymce);
  8001. (function(tinymce) {
  8002.     var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8003.  
  8004.     tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  8005.         SplitButton : function(id, s) {
  8006.             this.parent(id, s);
  8007.             this.classPrefix = 'mceSplitButton';
  8008.         },
  8009.  
  8010.         renderHTML : function() {
  8011.             var h, t = this, s = t.settings, h1;
  8012.  
  8013.             h = '<tbody><tr>';
  8014.  
  8015.             if (s.image)
  8016.                 h1 = DOM.createHTML('img ', {src : s.image, 'class' : 'mceAction ' + s['class']});
  8017.             else
  8018.                 h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  8019.  
  8020.             h += '<td>' + DOM.createHTML('a', {id : t.id + '_action', href : 'javascript:;', 'class' : 'mceAction ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
  8021.  
  8022.             h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']});
  8023.             h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', href : 'javascript:;', 'class' : 'mceOpen ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
  8024.  
  8025.             h += '</tr></tbody>';
  8026.  
  8027.             return DOM.createHTML('table', {id : t.id, 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', onmousedown : 'return false;', title : s.title}, h);
  8028.         },
  8029.  
  8030.         postRender : function() {
  8031.             var t = this, s = t.settings;
  8032.  
  8033.             if (s.onclick) {
  8034.                 Event.add(t.id + '_action', 'click', function() {
  8035.                     if (!t.isDisabled())
  8036.                         s.onclick(t.value);
  8037.                 });
  8038.             }
  8039.  
  8040.             Event.add(t.id + '_open', 'click', t.showMenu, t);
  8041.             Event.add(t.id + '_open', 'focus', function() {t._focused = 1;});
  8042.             Event.add(t.id + '_open', 'blur', function() {t._focused = 0;});
  8043.  
  8044.             // Old IE doesn't have hover on all elements
  8045.             if (tinymce.isIE6 || !DOM.boxModel) {
  8046.                 Event.add(t.id, 'mouseover', function() {
  8047.                     if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8048.                         DOM.addClass(t.id, 'mceSplitButtonHover');
  8049.                 });
  8050.  
  8051.                 Event.add(t.id, 'mouseout', function() {
  8052.                     if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8053.                         DOM.removeClass(t.id, 'mceSplitButtonHover');
  8054.                 });
  8055.             }
  8056.         },
  8057.  
  8058.         destroy : function() {
  8059.             this.parent();
  8060.  
  8061.             Event.clear(this.id + '_action');
  8062.             Event.clear(this.id + '_open');
  8063.         }
  8064.     });
  8065. })(tinymce);
  8066. (function(tinymce) {
  8067.     var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  8068.  
  8069.     tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  8070.         ColorSplitButton : function(id, s) {
  8071.             var t = this;
  8072.  
  8073.             t.parent(id, s);
  8074.  
  8075.             t.settings = s = tinymce.extend({
  8076.                 colors : '000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,008000,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF',
  8077.                 grid_width : 8,
  8078.                 default_color : '#888888'
  8079.             }, t.settings);
  8080.  
  8081.             t.onShowMenu = new tinymce.util.Dispatcher(t);
  8082.  
  8083.             t.onHideMenu = new tinymce.util.Dispatcher(t);
  8084.  
  8085.             t.value = s.default_color;
  8086.         },
  8087.  
  8088.         showMenu : function() {
  8089.             var t = this, r, p, e, p2;
  8090.  
  8091.             if (t.isDisabled())
  8092.                 return;
  8093.  
  8094.             if (!t.isMenuRendered) {
  8095.                 t.renderMenu();
  8096.                 t.isMenuRendered = true;
  8097.             }
  8098.  
  8099.             if (t.isMenuVisible)
  8100.                 return t.hideMenu();
  8101.  
  8102.             e = DOM.get(t.id);
  8103.             DOM.show(t.id + '_menu');
  8104.             DOM.addClass(e, 'mceSplitButtonSelected');
  8105.             p2 = DOM.getPos(e);
  8106.             DOM.setStyles(t.id + '_menu', {
  8107.                 left : p2.x,
  8108.                 top : p2.y + e.clientHeight,
  8109.                 zIndex : 200000
  8110.             });
  8111.             e = 0;
  8112.  
  8113.             Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8114.             t.onShowMenu.dispatch(t);
  8115.  
  8116.             if (t._focused) {
  8117.                 t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  8118.                     if (e.keyCode == 27)
  8119.                         t.hideMenu();
  8120.                 });
  8121.  
  8122.                 DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  8123.             }
  8124.  
  8125.             t.isMenuVisible = 1;
  8126.         },
  8127.  
  8128.         hideMenu : function(e) {
  8129.             var t = this;
  8130.  
  8131.             // Prevent double toogles by canceling the mouse click event to the button
  8132.             if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  8133.                 return;
  8134.  
  8135.             if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  8136.                 DOM.removeClass(t.id, 'mceSplitButtonSelected');
  8137.                 Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8138.                 Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  8139.                 DOM.hide(t.id + '_menu');
  8140.             }
  8141.  
  8142.             t.onHideMenu.dispatch(t);
  8143.  
  8144.             t.isMenuVisible = 0;
  8145.         },
  8146.  
  8147.         renderMenu : function() {
  8148.             var t = this, m, i = 0, s = t.settings, n, tb, tr, w;
  8149.  
  8150.             w = DOM.add(s.menu_container, 'div', {id : t.id + '_menu', 'class' : s['menu_class'] + ' ' + s['class'], style : 'position:absolute;left:0;top:-1000px;'});
  8151.             m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  8152.             DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  8153.  
  8154.             n = DOM.add(m, 'table', {'class' : 'mceColorSplitMenu'});
  8155.             tb = DOM.add(n, 'tbody');
  8156.  
  8157.             // Generate color grid
  8158.             i = 0;
  8159.             each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  8160.                 c = c.replace(/^#/, '');
  8161.  
  8162.                 if (!i--) {
  8163.                     tr = DOM.add(tb, 'tr');
  8164.                     i = s.grid_width - 1;
  8165.                 }
  8166.  
  8167.                 n = DOM.add(tr, 'td');
  8168.  
  8169.                 n = DOM.add(n, 'a', {
  8170.                     href : 'javascript:;',
  8171.                     style : {
  8172.                         backgroundColor : '#' + c
  8173.                     },
  8174.                     mce_color : '#' + c
  8175.                 });
  8176.             });
  8177.  
  8178.             if (s.more_colors_func) {
  8179.                 n = DOM.add(tb, 'tr');
  8180.                 n = DOM.add(n, 'td', {colspan : s.grid_width,&