Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / adapter / prototype / ext-prototype-adapter-debug.js
1 /*!
2  * Ext JS Library 3.3.1
3  * Copyright(c) 2006-2010 Sencha Inc.
4  * licensing@sencha.com
5  * http://www.sencha.com/license
6  */
7 // for old browsers
8 window.undefined = window.undefined;
9
10 /**
11  * @class Ext
12  * Ext core utilities and functions.
13  * @singleton
14  */
15
16 Ext = {
17     /**
18      * The version of the framework
19      * @type String
20      */
21     version : '3.3.1',
22     versionDetail : {
23         major : 3,
24         minor : 3,
25         patch : 1
26     }
27 };
28
29 /**
30  * Copies all the properties of config to obj.
31  * @param {Object} obj The receiver of the properties
32  * @param {Object} config The source of the properties
33  * @param {Object} defaults A different object that will also be applied for default values
34  * @return {Object} returns obj
35  * @member Ext apply
36  */
37 Ext.apply = function(o, c, defaults){
38     // no "this" reference for friendly out of scope calls
39     if(defaults){
40         Ext.apply(o, defaults);
41     }
42     if(o && c && typeof c == 'object'){
43         for(var p in c){
44             o[p] = c[p];
45         }
46     }
47     return o;
48 };
49
50 (function(){
51     var idSeed = 0,
52         toString = Object.prototype.toString,
53         ua = navigator.userAgent.toLowerCase(),
54         check = function(r){
55             return r.test(ua);
56         },
57         DOC = document,
58         docMode = DOC.documentMode,
59         isStrict = DOC.compatMode == "CSS1Compat",
60         isOpera = check(/opera/),
61         isChrome = check(/\bchrome\b/),
62         isWebKit = check(/webkit/),
63         isSafari = !isChrome && check(/safari/),
64         isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
65         isSafari3 = isSafari && check(/version\/3/),
66         isSafari4 = isSafari && check(/version\/4/),
67         isIE = !isOpera && check(/msie/),
68         isIE7 = isIE && (check(/msie 7/) || docMode == 7),
69         isIE8 = isIE && (check(/msie 8/) && docMode != 7),
70         isIE6 = isIE && !isIE7 && !isIE8,
71         isGecko = !isWebKit && check(/gecko/),
72         isGecko2 = isGecko && check(/rv:1\.8/),
73         isGecko3 = isGecko && check(/rv:1\.9/),
74         isBorderBox = isIE && !isStrict,
75         isWindows = check(/windows|win32/),
76         isMac = check(/macintosh|mac os x/),
77         isAir = check(/adobeair/),
78         isLinux = check(/linux/),
79         isSecure = /^https/i.test(window.location.protocol);
80
81     // remove css image flicker
82     if(isIE6){
83         try{
84             DOC.execCommand("BackgroundImageCache", false, true);
85         }catch(e){}
86     }
87
88     Ext.apply(Ext, {
89         /**
90          * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
91          * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
92          * @type String
93          */
94         SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
95         /**
96          * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
97          * @type Boolean
98          */
99         isStrict : isStrict,
100         /**
101          * True if the page is running over SSL
102          * @type Boolean
103          */
104         isSecure : isSecure,
105         /**
106          * True when the document is fully initialized and ready for action
107          * @type Boolean
108          */
109         isReady : false,
110
111         /**
112          * True if the {@link Ext.Fx} Class is available
113          * @type Boolean
114          * @property enableFx
115          */
116
117         /**
118          * HIGHLY EXPERIMENTAL
119          * True to force css based border-box model override and turning off javascript based adjustments. This is a
120          * runtime configuration and must be set before onReady.
121          * @type Boolean
122          */
123         enableForcedBoxModel : false,
124
125         /**
126          * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
127          * @type Boolean
128          */
129         enableGarbageCollector : true,
130
131         /**
132          * True to automatically purge event listeners during garbageCollection (defaults to false).
133          * @type Boolean
134          */
135         enableListenerCollection : false,
136
137         /**
138          * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
139          * Currently not optimized for performance.
140          * @type Boolean
141          */
142         enableNestedListenerRemoval : false,
143
144         /**
145          * Indicates whether to use native browser parsing for JSON methods.
146          * This option is ignored if the browser does not support native JSON methods.
147          * <b>Note: Native JSON methods will not work with objects that have functions.
148          * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
149          * @type Boolean
150          */
151         USE_NATIVE_JSON : false,
152
153         /**
154          * Copies all the properties of config to obj if they don't already exist.
155          * @param {Object} obj The receiver of the properties
156          * @param {Object} config The source of the properties
157          * @return {Object} returns obj
158          */
159         applyIf : function(o, c){
160             if(o){
161                 for(var p in c){
162                     if(!Ext.isDefined(o[p])){
163                         o[p] = c[p];
164                     }
165                 }
166             }
167             return o;
168         },
169
170         /**
171          * Generates unique ids. If the element already has an id, it is unchanged
172          * @param {Mixed} el (optional) The element to generate an id for
173          * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
174          * @return {String} The generated Id.
175          */
176         id : function(el, prefix){
177             el = Ext.getDom(el, true) || {};
178             if (!el.id) {
179                 el.id = (prefix || "ext-gen") + (++idSeed);
180             }
181             return el.id;
182         },
183
184         /**
185          * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
186          * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
187          * For example, to create a subclass of Ext GridPanel:
188          * <pre><code>
189 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
190     constructor: function(config) {
191
192 //      Create configuration for this Grid.
193         var store = new Ext.data.Store({...});
194         var colModel = new Ext.grid.ColumnModel({...});
195
196 //      Create a new config object containing our computed properties
197 //      *plus* whatever was in the config parameter.
198         config = Ext.apply({
199             store: store,
200             colModel: colModel
201         }, config);
202
203         MyGridPanel.superclass.constructor.call(this, config);
204
205 //      Your postprocessing here
206     },
207
208     yourMethod: function() {
209         // etc.
210     }
211 });
212 </code></pre>
213          *
214          * <p>This function also supports a 3-argument call in which the subclass's constructor is
215          * passed as an argument. In this form, the parameters are as follows:</p>
216          * <div class="mdetail-params"><ul>
217          * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
218          * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
219          * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
220          * prototype, and are therefore shared among all instances of the new class.</div></li>
221          * </ul></div>
222          *
223          * @param {Function} superclass The constructor of class being extended.
224          * @param {Object} overrides <p>A literal with members which are copied into the subclass's
225          * prototype, and are therefore shared between all instances of the new class.</p>
226          * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
227          * to define the constructor of the new class, and is returned. If this property is
228          * <i>not</i> specified, a constructor is generated and returned which just calls the
229          * superclass's constructor passing on its parameters.</p>
230          * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
231          * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
232          */
233         extend : function(){
234             // inline overrides
235             var io = function(o){
236                 for(var m in o){
237                     this[m] = o[m];
238                 }
239             };
240             var oc = Object.prototype.constructor;
241
242             return function(sb, sp, overrides){
243                 if(typeof sp == 'object'){
244                     overrides = sp;
245                     sp = sb;
246                     sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
247                 }
248                 var F = function(){},
249                     sbp,
250                     spp = sp.prototype;
251
252                 F.prototype = spp;
253                 sbp = sb.prototype = new F();
254                 sbp.constructor=sb;
255                 sb.superclass=spp;
256                 if(spp.constructor == oc){
257                     spp.constructor=sp;
258                 }
259                 sb.override = function(o){
260                     Ext.override(sb, o);
261                 };
262                 sbp.superclass = sbp.supr = (function(){
263                     return spp;
264                 });
265                 sbp.override = io;
266                 Ext.override(sb, overrides);
267                 sb.extend = function(o){return Ext.extend(sb, o);};
268                 return sb;
269             };
270         }(),
271
272         /**
273          * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
274          * Usage:<pre><code>
275 Ext.override(MyClass, {
276     newMethod1: function(){
277         // etc.
278     },
279     newMethod2: function(foo){
280         // etc.
281     }
282 });
283 </code></pre>
284          * @param {Object} origclass The class to override
285          * @param {Object} overrides The list of functions to add to origClass.  This should be specified as an object literal
286          * containing one or more methods.
287          * @method override
288          */
289         override : function(origclass, overrides){
290             if(overrides){
291                 var p = origclass.prototype;
292                 Ext.apply(p, overrides);
293                 if(Ext.isIE && overrides.hasOwnProperty('toString')){
294                     p.toString = overrides.toString;
295                 }
296             }
297         },
298
299         /**
300          * Creates namespaces to be used for scoping variables and classes so that they are not global.
301          * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
302          * <pre><code>
303 Ext.namespace('Company', 'Company.data');
304 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
305 Company.Widget = function() { ... }
306 Company.data.CustomStore = function(config) { ... }
307 </code></pre>
308          * @param {String} namespace1
309          * @param {String} namespace2
310          * @param {String} etc
311          * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
312          * @method namespace
313          */
314         namespace : function(){
315             var o, d;
316             Ext.each(arguments, function(v) {
317                 d = v.split(".");
318                 o = window[d[0]] = window[d[0]] || {};
319                 Ext.each(d.slice(1), function(v2){
320                     o = o[v2] = o[v2] || {};
321                 });
322             });
323             return o;
324         },
325
326         /**
327          * Takes an object and converts it to an encoded URL. e.g. Ext.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2".  Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value.
328          * @param {Object} o
329          * @param {String} pre (optional) A prefix to add to the url encoded string
330          * @return {String}
331          */
332         urlEncode : function(o, pre){
333             var empty,
334                 buf = [],
335                 e = encodeURIComponent;
336
337             Ext.iterate(o, function(key, item){
338                 empty = Ext.isEmpty(item);
339                 Ext.each(empty ? key : item, function(val){
340                     buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
341                 });
342             });
343             if(!pre){
344                 buf.shift();
345                 pre = '';
346             }
347             return pre + buf.join('');
348         },
349
350         /**
351          * Takes an encoded URL and and converts it to an object. Example: <pre><code>
352 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
353 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
354 </code></pre>
355          * @param {String} string
356          * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
357          * @return {Object} A literal with members
358          */
359         urlDecode : function(string, overwrite){
360             if(Ext.isEmpty(string)){
361                 return {};
362             }
363             var obj = {},
364                 pairs = string.split('&'),
365                 d = decodeURIComponent,
366                 name,
367                 value;
368             Ext.each(pairs, function(pair) {
369                 pair = pair.split('=');
370                 name = d(pair[0]);
371                 value = d(pair[1]);
372                 obj[name] = overwrite || !obj[name] ? value :
373                             [].concat(obj[name]).concat(value);
374             });
375             return obj;
376         },
377
378         /**
379          * Appends content to the query string of a URL, handling logic for whether to place
380          * a question mark or ampersand.
381          * @param {String} url The URL to append to.
382          * @param {String} s The content to append to the URL.
383          * @return (String) The resulting URL
384          */
385         urlAppend : function(url, s){
386             if(!Ext.isEmpty(s)){
387                 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
388             }
389             return url;
390         },
391
392         /**
393          * Converts any iterable (numeric indices and a length property) into a true array
394          * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
395          * For strings, use this instead: "abc".match(/./g) => [a,b,c];
396          * @param {Iterable} the iterable object to be turned into a true Array.
397          * @return (Array) array
398          */
399          toArray : function(){
400              return isIE ?
401                  function(a, i, j, res){
402                      res = [];
403                      for(var x = 0, len = a.length; x < len; x++) {
404                          res.push(a[x]);
405                      }
406                      return res.slice(i || 0, j || res.length);
407                  } :
408                  function(a, i, j){
409                      return Array.prototype.slice.call(a, i || 0, j || a.length);
410                  };
411          }(),
412
413         isIterable : function(v){
414             //check for array or arguments
415             if(Ext.isArray(v) || v.callee){
416                 return true;
417             }
418             //check for node list type
419             if(/NodeList|HTMLCollection/.test(toString.call(v))){
420                 return true;
421             }
422             //NodeList has an item and length property
423             //IXMLDOMNodeList has nextNode method, needs to be checked first.
424             return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));
425         },
426
427         /**
428          * Iterates an array calling the supplied function.
429          * @param {Array/NodeList/Mixed} array The array to be iterated. If this
430          * argument is not really an array, the supplied function is called once.
431          * @param {Function} fn The function to be called with each item. If the
432          * supplied function returns false, iteration stops and this method returns
433          * the current <code>index</code>. This function is called with
434          * the following arguments:
435          * <div class="mdetail-params"><ul>
436          * <li><code>item</code> : <i>Mixed</i>
437          * <div class="sub-desc">The item at the current <code>index</code>
438          * in the passed <code>array</code></div></li>
439          * <li><code>index</code> : <i>Number</i>
440          * <div class="sub-desc">The current index within the array</div></li>
441          * <li><code>allItems</code> : <i>Array</i>
442          * <div class="sub-desc">The <code>array</code> passed as the first
443          * argument to <code>Ext.each</code>.</div></li>
444          * </ul></div>
445          * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
446          * Defaults to the <code>item</code> at the current <code>index</code>
447          * within the passed <code>array</code>.
448          * @return See description for the fn parameter.
449          */
450         each : function(array, fn, scope){
451             if(Ext.isEmpty(array, true)){
452                 return;
453             }
454             if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
455                 array = [array];
456             }
457             for(var i = 0, len = array.length; i < len; i++){
458                 if(fn.call(scope || array[i], array[i], i, array) === false){
459                     return i;
460                 };
461             }
462         },
463
464         /**
465          * Iterates either the elements in an array, or each of the properties in an object.
466          * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
467          * @param {Object/Array} object The object or array to be iterated
468          * @param {Function} fn The function to be called for each iteration.
469          * The iteration will stop if the supplied function returns false, or
470          * all array elements / object properties have been covered. The signature
471          * varies depending on the type of object being interated:
472          * <div class="mdetail-params"><ul>
473          * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
474          * <div class="sub-desc">
475          * When iterating an array, the supplied function is called with each item.</div></li>
476          * <li>Objects : <tt>(String key, Object value, Object)</tt>
477          * <div class="sub-desc">
478          * When iterating an object, the supplied function is called with each key-value pair in
479          * the object, and the iterated object</div></li>
480          * </ul></div>
481          * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
482          * the <code>object</code> being iterated.
483          */
484         iterate : function(obj, fn, scope){
485             if(Ext.isEmpty(obj)){
486                 return;
487             }
488             if(Ext.isIterable(obj)){
489                 Ext.each(obj, fn, scope);
490                 return;
491             }else if(typeof obj == 'object'){
492                 for(var prop in obj){
493                     if(obj.hasOwnProperty(prop)){
494                         if(fn.call(scope || obj, prop, obj[prop], obj) === false){
495                             return;
496                         };
497                     }
498                 }
499             }
500         },
501
502         /**
503          * Return the dom node for the passed String (id), dom node, or Ext.Element.
504          * Optional 'strict' flag is needed for IE since it can return 'name' and
505          * 'id' elements by using getElementById.
506          * Here are some examples:
507          * <pre><code>
508 // gets dom node based on id
509 var elDom = Ext.getDom('elId');
510 // gets dom node based on the dom node
511 var elDom1 = Ext.getDom(elDom);
512
513 // If we don&#39;t know if we are working with an
514 // Ext.Element or a dom node use Ext.getDom
515 function(el){
516     var dom = Ext.getDom(el);
517     // do something with the dom node
518 }
519          * </code></pre>
520          * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
521          * when this method is called to be successful.
522          * @param {Mixed} el
523          * @return HTMLElement
524          */
525         getDom : function(el, strict){
526             if(!el || !DOC){
527                 return null;
528             }
529             if (el.dom){
530                 return el.dom;
531             } else {
532                 if (typeof el == 'string') {
533                     var e = DOC.getElementById(el);
534                     // IE returns elements with the 'name' and 'id' attribute.
535                     // we do a strict check to return the element with only the id attribute
536                     if (e && isIE && strict) {
537                         if (el == e.getAttribute('id')) {
538                             return e;
539                         } else {
540                             return null;
541                         }
542                     }
543                     return e;
544                 } else {
545                     return el;
546                 }
547             }
548         },
549
550         /**
551          * Returns the current document body as an {@link Ext.Element}.
552          * @return Ext.Element The document body
553          */
554         getBody : function(){
555             return Ext.get(DOC.body || DOC.documentElement);
556         },
557         
558         /**
559          * Returns the current document body as an {@link Ext.Element}.
560          * @return Ext.Element The document body
561          */
562         getHead : function() {
563             var head;
564             
565             return function() {
566                 if (head == undefined) {
567                     head = Ext.get(DOC.getElementsByTagName("head")[0]);
568                 }
569                 
570                 return head;
571             };
572         }(),
573
574         /**
575          * Removes a DOM node from the document.
576          */
577         /**
578          * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
579          * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
580          * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
581          * will be ignored if passed in.</p>
582          * @param {HTMLElement} node The node to remove
583          */
584         removeNode : isIE && !isIE8 ? function(){
585             var d;
586             return function(n){
587                 if(n && n.tagName != 'BODY'){
588                     (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
589                     d = d || DOC.createElement('div');
590                     d.appendChild(n);
591                     d.innerHTML = '';
592                     delete Ext.elCache[n.id];
593                 }
594             };
595         }() : function(n){
596             if(n && n.parentNode && n.tagName != 'BODY'){
597                 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
598                 n.parentNode.removeChild(n);
599                 delete Ext.elCache[n.id];
600             }
601         },
602
603         /**
604          * <p>Returns true if the passed value is empty.</p>
605          * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
606          * <li>null</li>
607          * <li>undefined</li>
608          * <li>an empty array</li>
609          * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
610          * </ul></div>
611          * @param {Mixed} value The value to test
612          * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
613          * @return {Boolean}
614          */
615         isEmpty : function(v, allowBlank){
616             return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
617         },
618
619         /**
620          * Returns true if the passed value is a JavaScript array, otherwise false.
621          * @param {Mixed} value The value to test
622          * @return {Boolean}
623          */
624         isArray : function(v){
625             return toString.apply(v) === '[object Array]';
626         },
627
628         /**
629          * Returns true if the passed object is a JavaScript date object, otherwise false.
630          * @param {Object} object The object to test
631          * @return {Boolean}
632          */
633         isDate : function(v){
634             return toString.apply(v) === '[object Date]';
635         },
636
637         /**
638          * Returns true if the passed value is a JavaScript Object, otherwise false.
639          * @param {Mixed} value The value to test
640          * @return {Boolean}
641          */
642         isObject : function(v){
643             return !!v && Object.prototype.toString.call(v) === '[object Object]';
644         },
645
646         /**
647          * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
648          * @param {Mixed} value The value to test
649          * @return {Boolean}
650          */
651         isPrimitive : function(v){
652             return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
653         },
654
655         /**
656          * Returns true if the passed value is a JavaScript Function, otherwise false.
657          * @param {Mixed} value The value to test
658          * @return {Boolean}
659          */
660         isFunction : function(v){
661             return toString.apply(v) === '[object Function]';
662         },
663
664         /**
665          * Returns true if the passed value is a number. Returns false for non-finite numbers.
666          * @param {Mixed} value The value to test
667          * @return {Boolean}
668          */
669         isNumber : function(v){
670             return typeof v === 'number' && isFinite(v);
671         },
672
673         /**
674          * Returns true if the passed value is a string.
675          * @param {Mixed} value The value to test
676          * @return {Boolean}
677          */
678         isString : function(v){
679             return typeof v === 'string';
680         },
681
682         /**
683          * Returns true if the passed value is a boolean.
684          * @param {Mixed} value The value to test
685          * @return {Boolean}
686          */
687         isBoolean : function(v){
688             return typeof v === 'boolean';
689         },
690
691         /**
692          * Returns true if the passed value is an HTMLElement
693          * @param {Mixed} value The value to test
694          * @return {Boolean}
695          */
696         isElement : function(v) {
697             return v ? !!v.tagName : false;
698         },
699
700         /**
701          * Returns true if the passed value is not undefined.
702          * @param {Mixed} value The value to test
703          * @return {Boolean}
704          */
705         isDefined : function(v){
706             return typeof v !== 'undefined';
707         },
708
709         /**
710          * True if the detected browser is Opera.
711          * @type Boolean
712          */
713         isOpera : isOpera,
714         /**
715          * True if the detected browser uses WebKit.
716          * @type Boolean
717          */
718         isWebKit : isWebKit,
719         /**
720          * True if the detected browser is Chrome.
721          * @type Boolean
722          */
723         isChrome : isChrome,
724         /**
725          * True if the detected browser is Safari.
726          * @type Boolean
727          */
728         isSafari : isSafari,
729         /**
730          * True if the detected browser is Safari 3.x.
731          * @type Boolean
732          */
733         isSafari3 : isSafari3,
734         /**
735          * True if the detected browser is Safari 4.x.
736          * @type Boolean
737          */
738         isSafari4 : isSafari4,
739         /**
740          * True if the detected browser is Safari 2.x.
741          * @type Boolean
742          */
743         isSafari2 : isSafari2,
744         /**
745          * True if the detected browser is Internet Explorer.
746          * @type Boolean
747          */
748         isIE : isIE,
749         /**
750          * True if the detected browser is Internet Explorer 6.x.
751          * @type Boolean
752          */
753         isIE6 : isIE6,
754         /**
755          * True if the detected browser is Internet Explorer 7.x.
756          * @type Boolean
757          */
758         isIE7 : isIE7,
759         /**
760          * True if the detected browser is Internet Explorer 8.x.
761          * @type Boolean
762          */
763         isIE8 : isIE8,
764         /**
765          * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
766          * @type Boolean
767          */
768         isGecko : isGecko,
769         /**
770          * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
771          * @type Boolean
772          */
773         isGecko2 : isGecko2,
774         /**
775          * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
776          * @type Boolean
777          */
778         isGecko3 : isGecko3,
779         /**
780          * True if the detected browser is Internet Explorer running in non-strict mode.
781          * @type Boolean
782          */
783         isBorderBox : isBorderBox,
784         /**
785          * True if the detected platform is Linux.
786          * @type Boolean
787          */
788         isLinux : isLinux,
789         /**
790          * True if the detected platform is Windows.
791          * @type Boolean
792          */
793         isWindows : isWindows,
794         /**
795          * True if the detected platform is Mac OS.
796          * @type Boolean
797          */
798         isMac : isMac,
799         /**
800          * True if the detected platform is Adobe Air.
801          * @type Boolean
802          */
803         isAir : isAir
804     });
805
806     /**
807      * Creates namespaces to be used for scoping variables and classes so that they are not global.
808      * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
809      * <pre><code>
810 Ext.namespace('Company', 'Company.data');
811 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
812 Company.Widget = function() { ... }
813 Company.data.CustomStore = function(config) { ... }
814 </code></pre>
815      * @param {String} namespace1
816      * @param {String} namespace2
817      * @param {String} etc
818      * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
819      * @method ns
820      */
821     Ext.ns = Ext.namespace;
822 })();
823
824 Ext.ns('Ext.util', 'Ext.lib', 'Ext.data', 'Ext.supports');
825
826 Ext.elCache = {};
827
828 /**
829  * @class Function
830  * These functions are available on every Function object (any JavaScript function).
831  */
832 Ext.apply(Function.prototype, {
833      /**
834      * Creates an interceptor function. The passed function is called before the original one. If it returns false,
835      * the original one is not called. The resulting function returns the results of the original function.
836      * The passed function is called with the parameters of the original function. Example usage:
837      * <pre><code>
838 var sayHi = function(name){
839     alert('Hi, ' + name);
840 }
841
842 sayHi('Fred'); // alerts "Hi, Fred"
843
844 // create a new function that validates input without
845 // directly modifying the original function:
846 var sayHiToFriend = sayHi.createInterceptor(function(name){
847     return name == 'Brian';
848 });
849
850 sayHiToFriend('Fred');  // no alert
851 sayHiToFriend('Brian'); // alerts "Hi, Brian"
852 </code></pre>
853      * @param {Function} fcn The function to call before the original
854      * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
855      * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
856      * @return {Function} The new function
857      */
858     createInterceptor : function(fcn, scope){
859         var method = this;
860         return !Ext.isFunction(fcn) ?
861                 this :
862                 function() {
863                     var me = this,
864                         args = arguments;
865                     fcn.target = me;
866                     fcn.method = method;
867                     return (fcn.apply(scope || me || window, args) !== false) ?
868                             method.apply(me || window, args) :
869                             null;
870                 };
871     },
872
873      /**
874      * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
875      * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
876      * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
877      * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
878      * executes in the window scope.
879      * <p>This method is required when you want to pass arguments to a callback function.  If no arguments
880      * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
881      * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
882      * would simply execute immediately when the code is parsed. Example usage:
883      * <pre><code>
884 var sayHi = function(name){
885     alert('Hi, ' + name);
886 }
887
888 // clicking the button alerts "Hi, Fred"
889 new Ext.Button({
890     text: 'Say Hi',
891     renderTo: Ext.getBody(),
892     handler: sayHi.createCallback('Fred')
893 });
894 </code></pre>
895      * @return {Function} The new function
896     */
897     createCallback : function(/*args...*/){
898         // make args available, in function below
899         var args = arguments,
900             method = this;
901         return function() {
902             return method.apply(window, args);
903         };
904     },
905
906     /**
907      * Creates a delegate (callback) that sets the scope to obj.
908      * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
909      * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
910      * callback points to obj. Example usage:
911      * <pre><code>
912 var sayHi = function(name){
913     // Note this use of "this.text" here.  This function expects to
914     // execute within a scope that contains a text property.  In this
915     // example, the "this" variable is pointing to the btn object that
916     // was passed in createDelegate below.
917     alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
918 }
919
920 var btn = new Ext.Button({
921     text: 'Say Hi',
922     renderTo: Ext.getBody()
923 });
924
925 // This callback will execute in the scope of the
926 // button instance. Clicking the button alerts
927 // "Hi, Fred. You clicked the "Say Hi" button."
928 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
929 </code></pre>
930      * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
931      * <b>If omitted, defaults to the browser window.</b>
932      * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
933      * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
934      * if a number the args are inserted at the specified position
935      * @return {Function} The new function
936      */
937     createDelegate : function(obj, args, appendArgs){
938         var method = this;
939         return function() {
940             var callArgs = args || arguments;
941             if (appendArgs === true){
942                 callArgs = Array.prototype.slice.call(arguments, 0);
943                 callArgs = callArgs.concat(args);
944             }else if (Ext.isNumber(appendArgs)){
945                 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
946                 var applyArgs = [appendArgs, 0].concat(args); // create method call params
947                 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
948             }
949             return method.apply(obj || window, callArgs);
950         };
951     },
952
953     /**
954      * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
955      * <pre><code>
956 var sayHi = function(name){
957     alert('Hi, ' + name);
958 }
959
960 // executes immediately:
961 sayHi('Fred');
962
963 // executes after 2 seconds:
964 sayHi.defer(2000, this, ['Fred']);
965
966 // this syntax is sometimes useful for deferring
967 // execution of an anonymous function:
968 (function(){
969     alert('Anonymous');
970 }).defer(100);
971 </code></pre>
972      * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
973      * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
974      * <b>If omitted, defaults to the browser window.</b>
975      * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
976      * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
977      * if a number the args are inserted at the specified position
978      * @return {Number} The timeout id that can be used with clearTimeout
979      */
980     defer : function(millis, obj, args, appendArgs){
981         var fn = this.createDelegate(obj, args, appendArgs);
982         if(millis > 0){
983             return setTimeout(fn, millis);
984         }
985         fn();
986         return 0;
987     }
988 });
989
990 /**
991  * @class String
992  * These functions are available on every String object.
993  */
994 Ext.applyIf(String, {
995     /**
996      * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens.  Each
997      * token must be unique, and must increment in the format {0}, {1}, etc.  Example usage:
998      * <pre><code>
999 var cls = 'my-class', text = 'Some text';
1000 var s = String.format('&lt;div class="{0}">{1}&lt;/div>', cls, text);
1001 // s now contains the string: '&lt;div class="my-class">Some text&lt;/div>'
1002      * </code></pre>
1003      * @param {String} string The tokenized string to be formatted
1004      * @param {String} value1 The value to replace token {0}
1005      * @param {String} value2 Etc...
1006      * @return {String} The formatted string
1007      * @static
1008      */
1009     format : function(format){
1010         var args = Ext.toArray(arguments, 1);
1011         return format.replace(/\{(\d+)\}/g, function(m, i){
1012             return args[i];
1013         });
1014     }
1015 });
1016
1017 /**
1018  * @class Array
1019  */
1020 Ext.applyIf(Array.prototype, {
1021     /**
1022      * Checks whether or not the specified object exists in the array.
1023      * @param {Object} o The object to check for
1024      * @param {Number} from (Optional) The index at which to begin the search
1025      * @return {Number} The index of o in the array (or -1 if it is not found)
1026      */
1027     indexOf : function(o, from){
1028         var len = this.length;
1029         from = from || 0;
1030         from += (from < 0) ? len : 0;
1031         for (; from < len; ++from){
1032             if(this[from] === o){
1033                 return from;
1034             }
1035         }
1036         return -1;
1037     },
1038
1039     /**
1040      * Removes the specified object from the array.  If the object is not found nothing happens.
1041      * @param {Object} o The object to remove
1042      * @return {Array} this array
1043      */
1044     remove : function(o){
1045         var index = this.indexOf(o);
1046         if(index != -1){
1047             this.splice(index, 1);
1048         }
1049         return this;
1050     }
1051 });
1052 /**
1053  * @class Ext.util.TaskRunner
1054  * Provides the ability to execute one or more arbitrary tasks in a multithreaded
1055  * manner.  Generally, you can use the singleton {@link Ext.TaskMgr} instead, but
1056  * if needed, you can create separate instances of TaskRunner.  Any number of
1057  * separate tasks can be started at any time and will run independently of each
1058  * other. Example usage:
1059  * <pre><code>
1060 // Start a simple clock task that updates a div once per second
1061 var updateClock = function(){
1062     Ext.fly('clock').update(new Date().format('g:i:s A'));
1063
1064 var task = {
1065     run: updateClock,
1066     interval: 1000 //1 second
1067 }
1068 var runner = new Ext.util.TaskRunner();
1069 runner.start(task);
1070
1071 // equivalent using TaskMgr
1072 Ext.TaskMgr.start({
1073     run: updateClock,
1074     interval: 1000
1075 });
1076
1077  * </code></pre>
1078  * <p>See the {@link #start} method for details about how to configure a task object.</p>
1079  * Also see {@link Ext.util.DelayedTask}. 
1080  * 
1081  * @constructor
1082  * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
1083  * (defaults to 10)
1084  */
1085 Ext.util.TaskRunner = function(interval){
1086     interval = interval || 10;
1087     var tasks = [], 
1088         removeQueue = [],
1089         id = 0,
1090         running = false,
1091
1092         // private
1093         stopThread = function(){
1094                 running = false;
1095                 clearInterval(id);
1096                 id = 0;
1097             },
1098
1099         // private
1100         startThread = function(){
1101                 if(!running){
1102                     running = true;
1103                     id = setInterval(runTasks, interval);
1104                 }
1105             },
1106
1107         // private
1108         removeTask = function(t){
1109                 removeQueue.push(t);
1110                 if(t.onStop){
1111                     t.onStop.apply(t.scope || t);
1112                 }
1113             },
1114             
1115         // private
1116         runTasks = function(){
1117                 var rqLen = removeQueue.length,
1118                         now = new Date().getTime();                                             
1119             
1120                 if(rqLen > 0){
1121                     for(var i = 0; i < rqLen; i++){
1122                         tasks.remove(removeQueue[i]);
1123                     }
1124                     removeQueue = [];
1125                     if(tasks.length < 1){
1126                         stopThread();
1127                         return;
1128                     }
1129                 }               
1130                 for(var i = 0, t, itime, rt, len = tasks.length; i < len; ++i){
1131                     t = tasks[i];
1132                     itime = now - t.taskRunTime;
1133                     if(t.interval <= itime){
1134                         rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
1135                         t.taskRunTime = now;
1136                         if(rt === false || t.taskRunCount === t.repeat){
1137                             removeTask(t);
1138                             return;
1139                         }
1140                     }
1141                     if(t.duration && t.duration <= (now - t.taskStartTime)){
1142                         removeTask(t);
1143                     }
1144                 }
1145             };
1146
1147     /**
1148      * Starts a new task.
1149      * @method start
1150      * @param {Object} task <p>A config object that supports the following properties:<ul>
1151      * <li><code>run</code> : Function<div class="sub-desc"><p>The function to execute each time the task is invoked. The
1152      * function will be called at each interval and passed the <code>args</code> argument if specified, and the
1153      * current invocation count if not.</p>
1154      * <p>If a particular scope (<code>this</code> reference) is required, be sure to specify it using the <code>scope</code> argument.</p>
1155      * <p>Return <code>false</code> from this function to terminate the task.</p></div></li>
1156      * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
1157      * should be invoked.</div></li>
1158      * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
1159      * specified by <code>run</code>. If not specified, the current invocation count is passed.</div></li>
1160      * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the
1161      * <code>run</code> function. Defaults to the task config object.</div></li>
1162      * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to invoke
1163      * the task before stopping automatically (defaults to indefinite).</div></li>
1164      * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to invoke the task before
1165      * stopping automatically (defaults to indefinite).</div></li>
1166      * </ul></p>
1167      * <p>Before each invocation, Ext injects the property <code>taskRunCount</code> into the task object so
1168      * that calculations based on the repeat count can be performed.</p>
1169      * @return {Object} The task
1170      */
1171     this.start = function(task){
1172         tasks.push(task);
1173         task.taskStartTime = new Date().getTime();
1174         task.taskRunTime = 0;
1175         task.taskRunCount = 0;
1176         startThread();
1177         return task;
1178     };
1179
1180     /**
1181      * Stops an existing running task.
1182      * @method stop
1183      * @param {Object} task The task to stop
1184      * @return {Object} The task
1185      */
1186     this.stop = function(task){
1187         removeTask(task);
1188         return task;
1189     };
1190
1191     /**
1192      * Stops all tasks that are currently running.
1193      * @method stopAll
1194      */
1195     this.stopAll = function(){
1196         stopThread();
1197         for(var i = 0, len = tasks.length; i < len; i++){
1198             if(tasks[i].onStop){
1199                 tasks[i].onStop();
1200             }
1201         }
1202         tasks = [];
1203         removeQueue = [];
1204     };
1205 };
1206
1207 /**
1208  * @class Ext.TaskMgr
1209  * @extends Ext.util.TaskRunner
1210  * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks.  See
1211  * {@link Ext.util.TaskRunner} for supported methods and task config properties.
1212  * <pre><code>
1213 // Start a simple clock task that updates a div once per second
1214 var task = {
1215     run: function(){
1216         Ext.fly('clock').update(new Date().format('g:i:s A'));
1217     },
1218     interval: 1000 //1 second
1219 }
1220 Ext.TaskMgr.start(task);
1221 </code></pre>
1222  * <p>See the {@link #start} method for details about how to configure a task object.</p>
1223  * @singleton
1224  */
1225 Ext.TaskMgr = new Ext.util.TaskRunner();(function(){
1226
1227 var libFlyweight,
1228     version = Prototype.Version.split('.'),
1229     mouseEnterSupported = (parseInt(version[0], 10) >= 2) || (parseInt(version[1], 10) >= 7) || (parseInt(version[2], 10) >= 1),
1230     mouseCache = {},
1231     elContains = function(parent, child) {
1232        if(parent && parent.firstChild){
1233          while(child) {
1234             if(child === parent) {
1235                 return true;
1236             }
1237             child = child.parentNode;
1238             if(child && (child.nodeType != 1)) {
1239                 child = null;
1240             }
1241           }
1242         }
1243         return false;
1244     },
1245     checkRelatedTarget = function(e) {
1246         return !elContains(e.currentTarget, Ext.lib.Event.getRelatedTarget(e));
1247     };
1248
1249 Ext.lib.Dom = {
1250     getViewWidth : function(full){
1251         return full ? this.getDocumentWidth() : this.getViewportWidth();
1252     },
1253
1254     getViewHeight : function(full){
1255         return full ? this.getDocumentHeight() : this.getViewportHeight();
1256     },
1257
1258     getDocumentHeight: function() { // missing from prototype?
1259         var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1260         return Math.max(scrollHeight, this.getViewportHeight());
1261     },
1262
1263     getDocumentWidth: function() { // missing from prototype?
1264         var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1265         return Math.max(scrollWidth, this.getViewportWidth());
1266     },
1267
1268     getViewportHeight: function() { // missing from prototype?
1269         var height = self.innerHeight;
1270         var mode = document.compatMode;
1271
1272         if ( (mode || Ext.isIE) && !Ext.isOpera ) {
1273             height = (mode == "CSS1Compat") ?
1274                     document.documentElement.clientHeight : // Standards
1275                     document.body.clientHeight; // Quirks
1276         }
1277
1278         return height;
1279     },
1280
1281     getViewportWidth: function() { // missing from prototype?
1282         var width = self.innerWidth;  // Safari
1283         var mode = document.compatMode;
1284
1285         if (mode || Ext.isIE) { // IE, Gecko, Opera
1286             width = (mode == "CSS1Compat") ?
1287                     document.documentElement.clientWidth : // Standards
1288                     document.body.clientWidth; // Quirks
1289         }
1290         return width;
1291     },
1292
1293     isAncestor : function(p, c){ // missing from prototype?
1294         var ret = false;
1295
1296         p = Ext.getDom(p);
1297         c = Ext.getDom(c);
1298         if (p && c) {
1299             if (p.contains) {
1300                 return p.contains(c);
1301             } else if (p.compareDocumentPosition) {
1302                 return !!(p.compareDocumentPosition(c) & 16);
1303             } else {
1304                 while (c = c.parentNode) {
1305                     ret = c == p || ret;
1306                 }
1307             }
1308         }
1309         return ret;
1310     },
1311
1312     getRegion : function(el){
1313         return Ext.lib.Region.getRegion(el);
1314     },
1315
1316     getY : function(el){
1317         return this.getXY(el)[1];
1318     },
1319
1320     getX : function(el){
1321         return this.getXY(el)[0];
1322     },
1323
1324     getXY : function(el){ // this initially used Position.cumulativeOffset but it is not accurate enough
1325         var p, pe, b, scroll, bd = (document.body || document.documentElement);
1326         el = Ext.getDom(el);
1327
1328         if(el == bd){
1329             return [0, 0];
1330         }
1331
1332         if (el.getBoundingClientRect) {
1333             b = el.getBoundingClientRect();
1334             scroll = fly(document).getScroll();
1335             return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
1336         }
1337         var x = 0, y = 0;
1338
1339         p = el;
1340
1341         var hasAbsolute = fly(el).getStyle("position") == "absolute";
1342
1343         while (p) {
1344
1345             x += p.offsetLeft;
1346             y += p.offsetTop;
1347
1348             if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1349                 hasAbsolute = true;
1350             }
1351
1352             if (Ext.isGecko) {
1353                 pe = fly(p);
1354
1355                 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1356                 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1357
1358
1359                 x += bl;
1360                 y += bt;
1361
1362
1363                 if (p != el && pe.getStyle('overflow') != 'visible') {
1364                     x += bl;
1365                     y += bt;
1366                 }
1367             }
1368             p = p.offsetParent;
1369         }
1370
1371         if (Ext.isSafari && hasAbsolute) {
1372             x -= bd.offsetLeft;
1373             y -= bd.offsetTop;
1374         }
1375
1376         if (Ext.isGecko && !hasAbsolute) {
1377             var dbd = fly(bd);
1378             x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1379             y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1380         }
1381
1382         p = el.parentNode;
1383         while (p && p != bd) {
1384             if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1385                 x -= p.scrollLeft;
1386                 y -= p.scrollTop;
1387             }
1388             p = p.parentNode;
1389         }
1390         return [x, y];
1391     },
1392
1393     setXY : function(el, xy){ // this initially used Position.cumulativeOffset but it is not accurate enough
1394         el = Ext.fly(el, '_setXY');
1395         el.position();
1396         var pts = el.translatePoints(xy);
1397         if(xy[0] !== false){
1398             el.dom.style.left = pts.left + "px";
1399         }
1400         if(xy[1] !== false){
1401             el.dom.style.top = pts.top + "px";
1402         }
1403     },
1404
1405     setX : function(el, x){
1406         this.setXY(el, [x, false]);
1407     },
1408
1409     setY : function(el, y){
1410         this.setXY(el, [false, y]);
1411     }
1412 };
1413
1414 Ext.lib.Event = {
1415     getPageX : function(e){
1416         return Event.pointerX(e.browserEvent || e);
1417     },
1418
1419     getPageY : function(e){
1420         return Event.pointerY(e.browserEvent || e);
1421     },
1422
1423     getXY : function(e){
1424         e = e.browserEvent || e;
1425         return [Event.pointerX(e), Event.pointerY(e)];
1426     },
1427
1428     getTarget : function(e){
1429         return Event.element(e.browserEvent || e);
1430     },
1431
1432     resolveTextNode: Ext.isGecko ? function(node){
1433         if(!node){
1434             return;
1435         }
1436         var s = HTMLElement.prototype.toString.call(node);
1437         if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
1438             return;
1439         }
1440         return node.nodeType == 3 ? node.parentNode : node;
1441     } : function(node){
1442         return node && node.nodeType == 3 ? node.parentNode : node;
1443     },
1444
1445     getRelatedTarget: function(ev) { // missing from prototype?
1446         ev = ev.browserEvent || ev;
1447         var t = ev.relatedTarget;
1448         if (!t) {
1449             if (ev.type == "mouseout") {
1450                 t = ev.toElement;
1451             } else if (ev.type == "mouseover") {
1452                 t = ev.fromElement;
1453             }
1454         }
1455
1456         return this.resolveTextNode(t);
1457     },
1458
1459     on : function(el, eventName, fn){
1460         if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
1461             var item = mouseCache[el.id] || (mouseCache[el.id] = {});
1462             item[eventName] = fn;
1463             fn = fn.createInterceptor(checkRelatedTarget);
1464             eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
1465         }
1466         Event.observe(el, eventName, fn, false);
1467     },
1468
1469     un : function(el, eventName, fn){
1470         if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
1471             var item = mouseCache[el.id],
1472                 ev = item && item[eventName];
1473
1474             if(ev){
1475                 fn = ev.fn;
1476                 delete item[eventName];
1477                 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
1478             }
1479         }
1480         Event.stopObserving(el, eventName, fn, false);
1481     },
1482
1483     purgeElement : function(el){
1484         // no equiv?
1485     },
1486
1487     preventDefault : function(e){   // missing from prototype?
1488         e = e.browserEvent || e;
1489         if(e.preventDefault) {
1490             e.preventDefault();
1491         } else {
1492             e.returnValue = false;
1493         }
1494     },
1495
1496     stopPropagation : function(e){   // missing from prototype?
1497         e = e.browserEvent || e;
1498         if(e.stopPropagation) {
1499             e.stopPropagation();
1500         } else {
1501             e.cancelBubble = true;
1502         }
1503     },
1504
1505     stopEvent : function(e){
1506         Event.stop(e.browserEvent || e);
1507     },
1508
1509     onAvailable : function(id, fn, scope){  // no equiv
1510         var start = new Date(), iid;
1511         var f = function(){
1512             if(start.getElapsed() > 10000){
1513                 clearInterval(iid);
1514             }
1515             var el = document.getElementById(id);
1516             if(el){
1517                 clearInterval(iid);
1518                 fn.call(scope||window, el);
1519             }
1520         };
1521         iid = setInterval(f, 50);
1522     }
1523 };
1524
1525 Ext.lib.Ajax = function(){
1526     var createSuccess = function(cb){
1527          return cb.success ? function(xhr){
1528             cb.success.call(cb.scope||window, createResponse(cb, xhr));
1529          } : Ext.emptyFn;
1530     };
1531     var createFailure = function(cb){
1532          return cb.failure ? function(xhr){
1533             cb.failure.call(cb.scope||window, createResponse(cb, xhr));
1534          } : Ext.emptyFn;
1535     };
1536     var createResponse = function(cb, xhr){
1537         var headerObj = {},
1538             headerStr,
1539             t,
1540             s;
1541
1542         try {
1543             headerStr = xhr.getAllResponseHeaders();
1544             Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
1545                 t = v.indexOf(':');
1546                 if(t >= 0){
1547                     s = v.substr(0, t).toLowerCase();
1548                     if(v.charAt(t + 1) == ' '){
1549                         ++t;
1550                     }
1551                     headerObj[s] = v.substr(t + 1);
1552                 }
1553             });
1554         } catch(e) {}
1555
1556         return {
1557             responseText: xhr.responseText,
1558             responseXML : xhr.responseXML,
1559             argument: cb.argument,
1560             status: xhr.status,
1561             statusText: xhr.statusText,
1562             getResponseHeader : function(header){
1563                 return headerObj[header.toLowerCase()];
1564             },
1565             getAllResponseHeaders : function(){
1566                 return headerStr;
1567             }
1568         };
1569     };
1570     return {
1571         request : function(method, uri, cb, data, options){
1572             var o = {
1573                 method: method,
1574                 parameters: data || '',
1575                 timeout: cb.timeout,
1576                 onSuccess: createSuccess(cb),
1577                 onFailure: createFailure(cb)
1578             };
1579             if(options){
1580                 var hs = options.headers;
1581                 if(hs){
1582                     o.requestHeaders = hs;
1583                 }
1584                 if(options.xmlData){
1585                     method = (method ? method : (options.method ? options.method : 'POST'));
1586                     if (!hs || !hs['Content-Type']){
1587                         o.contentType = 'text/xml';
1588                     }
1589                     o.postBody = options.xmlData;
1590                     delete o.parameters;
1591                 }
1592                 if(options.jsonData){
1593                     method = (method ? method : (options.method ? options.method : 'POST'));
1594                     if (!hs || !hs['Content-Type']){
1595                         o.contentType = 'application/json';
1596                     }
1597                     o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
1598                     delete o.parameters;
1599                 }
1600             }
1601             new Ajax.Request(uri, o);
1602         },
1603
1604         formRequest : function(form, uri, cb, data, isUpload, sslUri){
1605             new Ajax.Request(uri, {
1606                 method: Ext.getDom(form).method ||'POST',
1607                 parameters: Form.serialize(form)+(data?'&'+data:''),
1608                 timeout: cb.timeout,
1609                 onSuccess: createSuccess(cb),
1610                 onFailure: createFailure(cb)
1611             });
1612         },
1613
1614         isCallInProgress : function(trans){
1615             return false;
1616         },
1617
1618         abort : function(trans){
1619             return false;
1620         },
1621
1622         serializeForm : function(form){
1623             return Form.serialize(form.dom||form);
1624         }
1625     };
1626 }();
1627
1628
1629 Ext.lib.Anim = function(){
1630
1631     var easings = {
1632         easeOut: function(pos) {
1633             return 1-Math.pow(1-pos,2);
1634         },
1635         easeIn: function(pos) {
1636             return 1-Math.pow(1-pos,2);
1637         }
1638     };
1639     var createAnim = function(cb, scope){
1640         return {
1641             stop : function(skipToLast){
1642                 this.effect.cancel();
1643             },
1644
1645             isAnimated : function(){
1646                 return this.effect.state == 'running';
1647             },
1648
1649             proxyCallback : function(){
1650                 Ext.callback(cb, scope);
1651             }
1652         };
1653     };
1654     return {
1655         scroll : function(el, args, duration, easing, cb, scope){
1656             // not supported so scroll immediately?
1657             var anim = createAnim(cb, scope);
1658             el = Ext.getDom(el);
1659             if(typeof args.scroll.to[0] == 'number'){
1660                 el.scrollLeft = args.scroll.to[0];
1661             }
1662             if(typeof args.scroll.to[1] == 'number'){
1663                 el.scrollTop = args.scroll.to[1];
1664             }
1665             anim.proxyCallback();
1666             return anim;
1667         },
1668
1669         motion : function(el, args, duration, easing, cb, scope){
1670             return this.run(el, args, duration, easing, cb, scope);
1671         },
1672
1673         color : function(el, args, duration, easing, cb, scope){
1674             return this.run(el, args, duration, easing, cb, scope);
1675         },
1676
1677         run : function(el, args, duration, easing, cb, scope, type){
1678             var o = {};
1679             for(var k in args){
1680                 switch(k){   // scriptaculous doesn't support, so convert these
1681                     case 'points':
1682                         var by, pts, e = Ext.fly(el, '_animrun');
1683                         e.position();
1684                         if(by = args.points.by){
1685                             var xy = e.getXY();
1686                             pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
1687                         }else{
1688                             pts = e.translatePoints(args.points.to);
1689                         }
1690                         o.left = pts.left+'px';
1691                         o.top = pts.top+'px';
1692                     break;
1693                     case 'width':
1694                         o.width = args.width.to+'px';
1695                     break;
1696                     case 'height':
1697                         o.height = args.height.to+'px';
1698                     break;
1699                     case 'opacity':
1700                         o.opacity = String(args.opacity.to);
1701                     break;
1702                     default:
1703                         o[k] = String(args[k].to);
1704                     break;
1705                 }
1706             }
1707             var anim = createAnim(cb, scope);
1708             anim.effect = new Effect.Morph(Ext.id(el), {
1709                 duration: duration,
1710                 afterFinish: anim.proxyCallback,
1711                 transition: easings[easing] || Effect.Transitions.linear,
1712                 style: o
1713             });
1714             return anim;
1715         }
1716     };
1717 }();
1718
1719
1720 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
1721 function fly(el){
1722     if(!libFlyweight){
1723         libFlyweight = new Ext.Element.Flyweight();
1724     }
1725     libFlyweight.dom = el;
1726     return libFlyweight;
1727 }
1728
1729 Ext.lib.Region = function(t, r, b, l) {
1730     this.top = t;
1731     this[1] = t;
1732     this.right = r;
1733     this.bottom = b;
1734     this.left = l;
1735     this[0] = l;
1736 };
1737
1738 Ext.lib.Region.prototype = {
1739     contains : function(region) {
1740         return ( region.left   >= this.left   &&
1741                  region.right  <= this.right  &&
1742                  region.top    >= this.top    &&
1743                  region.bottom <= this.bottom    );
1744
1745     },
1746
1747     getArea : function() {
1748         return ( (this.bottom - this.top) * (this.right - this.left) );
1749     },
1750
1751     intersect : function(region) {
1752         var t = Math.max( this.top,    region.top    );
1753         var r = Math.min( this.right,  region.right  );
1754         var b = Math.min( this.bottom, region.bottom );
1755         var l = Math.max( this.left,   region.left   );
1756
1757         if (b >= t && r >= l) {
1758             return new Ext.lib.Region(t, r, b, l);
1759         } else {
1760             return null;
1761         }
1762     },
1763     union : function(region) {
1764         var t = Math.min( this.top,    region.top    );
1765         var r = Math.max( this.right,  region.right  );
1766         var b = Math.max( this.bottom, region.bottom );
1767         var l = Math.min( this.left,   region.left   );
1768
1769         return new Ext.lib.Region(t, r, b, l);
1770     },
1771
1772     constrainTo : function(r) {
1773             this.top = this.top.constrain(r.top, r.bottom);
1774             this.bottom = this.bottom.constrain(r.top, r.bottom);
1775             this.left = this.left.constrain(r.left, r.right);
1776             this.right = this.right.constrain(r.left, r.right);
1777             return this;
1778     },
1779
1780     adjust : function(t, l, b, r){
1781         this.top += t;
1782         this.left += l;
1783         this.right += r;
1784         this.bottom += b;
1785         return this;
1786     }
1787 };
1788
1789 Ext.lib.Region.getRegion = function(el) {
1790     var p = Ext.lib.Dom.getXY(el);
1791
1792     var t = p[1];
1793     var r = p[0] + el.offsetWidth;
1794     var b = p[1] + el.offsetHeight;
1795     var l = p[0];
1796
1797     return new Ext.lib.Region(t, r, b, l);
1798 };
1799
1800 Ext.lib.Point = function(x, y) {
1801    if (Ext.isArray(x)) {
1802       y = x[1];
1803       x = x[0];
1804    }
1805     this.x = this.right = this.left = this[0] = x;
1806     this.y = this.top = this.bottom = this[1] = y;
1807 };
1808
1809 Ext.lib.Point.prototype = new Ext.lib.Region();
1810
1811
1812 // prevent IE leaks
1813 if(Ext.isIE) {
1814     function fnCleanUp() {
1815         var p = Function.prototype;
1816         delete p.createSequence;
1817         delete p.defer;
1818         delete p.createDelegate;
1819         delete p.createCallback;
1820         delete p.createInterceptor;
1821
1822         window.detachEvent("onunload", fnCleanUp);
1823     }
1824     window.attachEvent("onunload", fnCleanUp);
1825 }
1826 })();