sync
[roojs1] / roojs-all.js
1
2
3  
4
5
6
7
8
9 window["undefined"] = window["undefined"];
10
11
12
13 var  Roo = {}; 
14
15
16
17  
18 Roo.apply = function(o, c, A){
19     if(A){
20         
21         Roo.apply(o, A);
22     }
23     if(o && c && typeof  c == 'object'){
24         for(var  p  in  c){
25             o[p] = c[p];
26         }
27     }
28     return  o;
29 };
30
31
32 (function(){
33     var  B = 0;
34     var  ua = navigator.userAgent.toLowerCase();
35
36     var  C = document.compatMode == "CSS1Compat",
37         D = ua.indexOf("opera") > -1,
38         E = (/webkit|khtml/).test(ua),
39         F = ua.indexOf("msie") > -1,
40         G = ua.indexOf("msie 7") > -1,
41         H = !E && ua.indexOf("gecko") > -1,
42         I = F && !C,
43         J = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
44         K = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
45         L = (ua.indexOf("linux") != -1),
46         M = window.location.href.toLowerCase().indexOf("https") === 0;
47
48     
49         if(F && !G){
50         try{
51             document.execCommand("BackgroundImageCache", false, true);
52         }catch(e){}
53     }
54
55
56     Roo.apply(Roo, {
57         
58
59         isStrict : C,
60         
61
62         isSecure : M,
63         
64
65         isReady : false,
66         
67
68         
69         debug: false,
70
71         
72
73         enableGarbageCollector : true,
74
75         
76
77         enableListenerCollection:false,
78
79         
80
81         SSL_SECURE_URL : "javascript:false",
82
83         
84
85         BLANK_IMAGE_URL : "http:/"+"/localhost/s.gif",
86
87         emptyFn : function(){},
88
89         
90
91         applyIf : function(o, c){
92             if(o && c){
93                 for(var  p  in  c){
94                     if(typeof  o[p] == "undefined"){ o[p] = c[p]; }
95                 }
96             }
97             return  o;
98         },
99
100         
101
102         addBehaviors : function(o){
103             if(!Roo.isReady){
104                 Roo.onReady(function(){
105                     Roo.addBehaviors(o);
106                 });
107                 return;
108             }
109             var  N = {}; 
110             for(var  b  in  o){
111                 var  parts = b.split('@');
112                 if(parts[1]){ 
113                     var  s = parts[0];
114                     if(!N[s]){
115                         N[s] = Roo.select(s);
116                     }
117
118                     N[s].on(parts[1], o[b]);
119                 }
120             }
121
122             N = null;
123         },
124
125         
126
127         id : function(el, O){
128             O = O || "roo-gen";
129             el = Roo.getDom(el);
130             var  id = O + (++B);
131             return  el ? (el.id ? el.id : (el.id = id)) : id;
132         },
133          
134        
135         
136
137         extend : function(){
138             
139             var  io = function(o){
140                 for(var  m  in  o){
141                     this[m] = o[m];
142                 }
143             };
144             return  function(sb, sp, P){
145                 if(typeof  sp == 'object'){ 
146                     P = sp;
147                     sp = sb;
148                     sb = function(){sp.apply(this, arguments);};
149                 }
150                 var  F = function(){}, sbp, spp = sp.prototype;
151                 F.prototype = spp;
152                 sbp = sb.prototype = new  F();
153                 sbp.constructor=sb;
154                 sb.superclass=spp;
155                 
156                 if(spp.constructor == Object.prototype.constructor){
157                     spp.constructor=sp;
158                    
159                 }
160
161                 
162                 sb.override = function(o){
163                     Roo.override(sb, o);
164                 };
165                 sbp.override = io;
166                 Roo.override(sb, P);
167                 return  sb;
168             };
169         }(),
170
171         
172
173         override : function(P, Q){
174             if(Q){
175                 var  p = P.prototype;
176                 for(var  method  in  Q){
177                     p[method] = Q[method];
178                 }
179             }
180         },
181         
182
183         namespace : function(){
184             var  a=arguments, o=null, i, j, d, rt;
185             for (i=0; i<a.length; ++i) {
186                 d=a[i].split(".");
187                 rt = d[0];
188                 
189
190                 eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
191                 for (j=1; j<d.length; ++j) {
192                     o[d[j]]=o[d[j]] || {};
193                     o=o[d[j]];
194                 }
195             }
196         },
197         
198
199          
200         factory : function(c, ns)
201         {
202             
203             if (!c.xtype   || (!ns && !c.xns) ||  (c.xns === false)) { 
204                 return  c;
205             }
206
207             ns = c.xns ? c.xns : ns; 
208             if (c.constructor == ns[c.xtype]) {
209                 return  c;
210             }
211             if (ns[c.xtype]) {
212                 if (Roo.debug) Roo.log("Roo.Factory(" + c.xtype + ")");
213                 var  ret = new  ns[c.xtype](c);
214                 ret.xns = false;
215                 return  ret;
216             }
217
218             c.xns = false; 
219             return  c;
220         },
221          
222
223         log : function(s)
224         {
225             if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) {
226                 return; 
227             }
228
229             console.log(s);
230             
231         },
232         
233
234         urlEncode : function(o){
235             if(!o){
236                 return  "";
237             }
238             var  R = [];
239             for(var  key  in  o){
240                 var  ov = o[key], k = encodeURIComponent(key);
241                 var  type = typeof  ov;
242                 if(type == 'undefined'){
243                     R.push(k, "=&");
244                 }else  if(type != "function" && type != "object"){
245                     R.push(k, "=", encodeURIComponent(ov), "&");
246                 }else  if(ov  instanceof  Array){
247                     if (ov.length) {
248                             for(var  i = 0, len = ov.length; i < len; i++) {
249                                 R.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
250                             }
251                         } else  {
252                             R.push(k, "=&");
253                         }
254                 }
255             }
256
257             R.pop();
258             return  R.join("");
259         },
260
261         
262
263         urlDecode : function(S, T){
264             if(!S || !S.length){
265                 return  {};
266             }
267             var  U = {};
268             var  V = S.split('&');
269             var  W, X, Y;
270             for(var  i = 0, len = V.length; i < len; i++){
271                 W = V[i].split('=');
272                 X = decodeURIComponent(W[0]);
273                 Y = decodeURIComponent(W[1]);
274                 if(T !== true){
275                     if(typeof  U[X] == "undefined"){
276                         U[X] = Y;
277                     }else  if(typeof  U[X] == "string"){
278                         U[X] = [U[X]];
279                         U[X].push(Y);
280                     }else {
281                         U[X].push(Y);
282                     }
283                 }else {
284                     U[X] = Y;
285                 }
286             }
287             return  U;
288         },
289
290         
291
292         each : function(Z, fn, f){
293             if(typeof  Z.length == "undefined" || typeof  Z == "string"){
294                 Z = [Z];
295             }
296             for(var  i = 0, len = Z.length; i < len; i++){
297                 if(fn.call(f || Z[i], Z[i], i, Z) === false){ return  i; };
298             }
299         },
300
301         
302         combine : function(){
303             var  as = arguments, l = as.length, r = [];
304             for(var  i = 0; i < l; i++){
305                 var  a = as[i];
306                 if(a  instanceof  Array){
307                     r = r.concat(a);
308                 }else  if(a.length !== undefined && !a.substr){
309                     r = r.concat(Array.prototype.slice.call(a, 0));
310                 }else {
311                     r.push(a);
312                 }
313             }
314             return  r;
315         },
316
317         
318
319         escapeRe : function(s) {
320             return  s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
321         },
322
323         
324         callback : function(cb, g, h, n){
325             if(typeof  cb == "function"){
326                 if(n){
327                     cb.defer(n, g, h || []);
328                 }else {
329                     cb.apply(g, h || []);
330                 }
331             }
332         },
333
334         
335
336         getDom : function(el){
337             if(!el){
338                 return  null;
339             }
340             return  el.dom ? el.dom : (typeof  el == 'string' ? document.getElementById(el) : el);
341         },
342
343         
344
345         getCmp : function(id){
346             return  Roo.ComponentMgr.get(id);
347         },
348          
349         num : function(v, q){
350             if(typeof  v != 'number'){
351                 return  q;
352             }
353             return  v;
354         },
355
356         destroy : function(){
357             for(var  i = 0, a = arguments, len = a.length; i < len; i++) {
358                 var  as = a[i];
359                 if(as){
360                     if(as.dom){
361                         as.removeAllListeners();
362                         as.remove();
363                         continue;
364                     }
365                     if(typeof  as.purgeListeners == 'function'){
366                         as.purgeListeners();
367                     }
368                     if(typeof  as.destroy == 'function'){
369                         as.destroy();
370                     }
371                 }
372             }
373         },
374
375         
376         
377
378         type : function(o){
379             if(o === undefined || o === null){
380                 return  false;
381             }
382             if(o.htmlElement){
383                 return  'element';
384             }
385             var  t = typeof  o;
386             if(t == 'object' && o.nodeName) {
387                 switch(o.nodeType) {
388                     case  1: return  'element';
389                     case  3: return  (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
390                 }
391             }
392             if(t == 'object' || t == 'function') {
393                 switch(o.constructor) {
394                     case  Array: return  'array';
395                     case  RegExp: return  'regexp';
396                 }
397                 if(typeof  o.length == 'number' && typeof  o.item == 'function') {
398                     return  'nodelist';
399                 }
400             }
401             return  t;
402         },
403
404         
405
406         isEmpty : function(v, u){
407             return  v === null || v === undefined || (!u ? v === '' : false);
408         },
409         
410         
411
412         isOpera : D,
413         
414
415         isSafari : E,
416         
417
418         isIE : F,
419         
420
421         isIE7 : G,
422         
423
424         isGecko : H,
425         
426
427         isBorderBox : I,
428         
429
430         isWindows : J,
431         
432
433         isLinux : L,
434         
435
436         isMac : K,
437
438         
439
440         useShims : ((F && !G) || (H && K))
441     });
442
443
444 })();
445
446 Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data",
447                 "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout", "Roo.app", "Roo.ux");
448
449
450
451
452 (function() {    
453     
454     if(Roo.isIE) {
455         function  A() {
456             var  p = Function.prototype;
457             delete  p.createSequence;
458             delete  p.defer;
459             delete  p.createDelegate;
460             delete  p.createCallback;
461             delete  p.createInterceptor;
462
463             window.detachEvent("onunload", A);
464         }
465
466         window.attachEvent("onunload", A);
467     }
468 })();
469
470
471
472
473 Roo.apply(Function.prototype, {
474      
475
476     createCallback : function(
477 ){
478         
479         var  B = arguments;
480         var  C = this;
481         return  function() {
482             return  C.apply(window, B);
483         };
484     },
485
486     
487
488     createDelegate : function(D, E, F){
489         var  G = this;
490         return  function() {
491             var  H = E || arguments;
492             if(F === true){
493                 H = Array.prototype.slice.call(arguments, 0);
494                 H = H.concat(E);
495             }else  if(typeof  F == "number"){
496                 H = Array.prototype.slice.call(arguments, 0); 
497                 var  applyArgs = [F, 0].concat(E); 
498                 Array.prototype.splice.apply(H, applyArgs); 
499             }
500             return  G.apply(D || window, H);
501         };
502     },
503
504     
505
506     defer : function(H, I, J, K){
507         var  fn = this.createDelegate(I, J, K);
508         if(H){
509             return  setTimeout(fn, H);
510         }
511
512         fn();
513         return  0;
514     },
515     
516
517     createSequence : function(L, M){
518         if(typeof  L != "function"){
519             return  this;
520         }
521         var  N = this;
522         return  function() {
523             var  O = N.apply(this || window, arguments);
524             L.apply(M || this || window, arguments);
525             return  O;
526         };
527     },
528
529     
530
531     createInterceptor : function(O, P){
532         if(typeof  O != "function"){
533             return  this;
534         }
535         var  Q = this;
536         return  function() {
537             O.target = this;
538             O.method = Q;
539             if(O.apply(P || this || window, arguments) === false){
540                 return;
541             }
542             return  Q.apply(this || window, arguments);
543         };
544     }
545 });
546
547
548
549
550 Roo.applyIf(String, {
551     
552     
553
554     
555     
556
557     escape : function(A) {
558         return  A.replace(/('|\\)/g, "\\$1");
559     },
560
561     
562
563     leftPad : function (B, C, ch) {
564         var  D = new  String(B);
565         if(ch === null || ch === undefined || ch === '') {
566             ch = " ";
567         }
568         while (D.length < C) {
569             D = ch + D;
570         }
571         return  D;
572     },
573
574     
575
576     format : function(E){
577         var  F = Array.prototype.slice.call(arguments, 1);
578         return  E.replace(/\{(\d+)\}/g, function(m, i){
579             return  Roo.util.Format.htmlEncode(F[i]);
580         });
581     }
582 });
583
584
585
586  
587 String.prototype.toggle = function(G, H){
588     return  this == G ? H : G;
589 };
590
591
592
593  
594
595 Roo.applyIf(Number.prototype, {
596     
597
598     constrain : function(A, B){
599         return  Math.min(Math.max(this, A), B);
600     }
601 });
602
603
604  
605
606 Roo.applyIf(Array.prototype, {
607     
608
609     indexOf : function(o){
610        for (var  i = 0, len = this.length; i < len; i++){
611               if(this[i] == o) return  i;
612        }
613            return  -1;
614     },
615
616     
617
618     remove : function(o){
619        var  A = this.indexOf(o);
620        if(A != -1){
621            this.splice(A, 1);
622        }
623     },
624     
625
626     map : function(B )
627     {
628         var  C = this.length >>> 0;
629         if (typeof  B != "function")
630             throw  new  TypeError();
631
632         var  D = new  Array(C);
633         var  E = arguments[1];
634         for (var  i = 0; i < C; i++)
635         {
636             if (i  in  this)
637                 D[i] = B.call(E, this[i], i, this);
638         }
639
640         return  D;
641     }
642     
643 });
644
645
646  
647
648
649
650
651
652
653
654
655  
656  
657  
658
659
660 Date.prototype.getElapsed = function(A) {
661         return  Math.abs((A || new  Date()).getTime()-this.getTime());
662 };
663
664
665
666
667 Date.parseFunctions = {count:0};
668
669 Date.parseRegexes = [];
670
671 Date.formatFunctions = {count:0};
672
673
674 Date.prototype.dateFormat = function(B) {
675     if (Date.formatFunctions[B] == null) {
676         Date.createNewFormat(B);
677     }
678     var  C = Date.formatFunctions[B];
679     return  this[C]();
680 };
681
682
683
684
685 Date.prototype.format = Date.prototype.dateFormat;
686
687
688 Date.createNewFormat = function(D) {
689     var  E = "format" + Date.formatFunctions.count++;
690     Date.formatFunctions[D] = E;
691     var  F = "Date.prototype." + E + " = function(){return ";
692     var  G = false;
693     var  ch = '';
694     for (var  i = 0; i < D.length; ++i) {
695         ch = D.charAt(i);
696         if (!G && ch == "\\") {
697             G = true;
698         }
699         else  if (G) {
700             G = false;
701             F += "'" + String.escape(ch) + "' + ";
702         }
703         else  {
704             F += Date.getFormatCode(ch);
705         }
706     }
707     
708
709     eval(F.substring(0, F.length - 3) + ";}");
710 };
711
712
713 Date.getFormatCode = function(H) {
714     switch (H) {
715     case  "d":
716         return  "String.leftPad(this.getDate(), 2, '0') + ";
717     case  "D":
718         return  "Date.dayNames[this.getDay()].substring(0, 3) + ";
719     case  "j":
720         return  "this.getDate() + ";
721     case  "l":
722         return  "Date.dayNames[this.getDay()] + ";
723     case  "S":
724         return  "this.getSuffix() + ";
725     case  "w":
726         return  "this.getDay() + ";
727     case  "z":
728         return  "this.getDayOfYear() + ";
729     case  "W":
730         return  "this.getWeekOfYear() + ";
731     case  "F":
732         return  "Date.monthNames[this.getMonth()] + ";
733     case  "m":
734         return  "String.leftPad(this.getMonth() + 1, 2, '0') + ";
735     case  "M":
736         return  "Date.monthNames[this.getMonth()].substring(0, 3) + ";
737     case  "n":
738         return  "(this.getMonth() + 1) + ";
739     case  "t":
740         return  "this.getDaysInMonth() + ";
741     case  "L":
742         return  "(this.isLeapYear() ? 1 : 0) + ";
743     case  "Y":
744         return  "this.getFullYear() + ";
745     case  "y":
746         return  "('' + this.getFullYear()).substring(2, 4) + ";
747     case  "a":
748         return  "(this.getHours() < 12 ? 'am' : 'pm') + ";
749     case  "A":
750         return  "(this.getHours() < 12 ? 'AM' : 'PM') + ";
751     case  "g":
752         return  "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
753     case  "G":
754         return  "this.getHours() + ";
755     case  "h":
756         return  "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
757     case  "H":
758         return  "String.leftPad(this.getHours(), 2, '0') + ";
759     case  "i":
760         return  "String.leftPad(this.getMinutes(), 2, '0') + ";
761     case  "s":
762         return  "String.leftPad(this.getSeconds(), 2, '0') + ";
763     case  "O":
764         return  "this.getGMTOffset() + ";
765     case  "T":
766         return  "this.getTimezone() + ";
767     case  "Z":
768         return  "(this.getTimezoneOffset() * -60) + ";
769     default:
770         return  "'" + String.escape(H) + "' + ";
771     }
772 };
773
774
775
776 Date.parseDate = function(I, J) {
777     if (Date.parseFunctions[J] == null) {
778         Date.createParser(J);
779     }
780     var  K = Date.parseFunctions[J];
781     return  Date[K](I);
782 };
783
784
785 Date.createParser = function(L) {
786     var  M = "parse" + Date.parseFunctions.count++;
787     var  N = Date.parseRegexes.length;
788     var  O = 1;
789     Date.parseFunctions[L] = M;
790
791     var  P = "Date." + M + " = function(input){\n"
792         + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"
793         + "var d = new Date();\n"
794         + "y = d.getFullYear();\n"
795         + "m = d.getMonth();\n"
796         + "d = d.getDate();\n"
797         + "var results = input.match(Date.parseRegexes[" + N + "]);\n"
798         + "if (results && results.length > 0) {";
799     var  Q = "";
800
801     var  R = false;
802     var  ch = '';
803     for (var  i = 0; i < L.length; ++i) {
804         ch = L.charAt(i);
805         if (!R && ch == "\\") {
806             R = true;
807         }
808         else  if (R) {
809             R = false;
810             Q += String.escape(ch);
811         }
812         else  {
813             var  obj = Date.formatCodeToRegex(ch, O);
814             O += obj.g;
815             Q += obj.s;
816             if (obj.g && obj.c) {
817                 P += obj.c;
818             }
819         }
820     }
821
822
823     P += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
824         + "{v = new Date(y, m, d, h, i, s);}\n"
825         + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
826         + "{v = new Date(y, m, d, h, i);}\n"
827         + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
828         + "{v = new Date(y, m, d, h);}\n"
829         + "else if (y >= 0 && m >= 0 && d > 0)\n"
830         + "{v = new Date(y, m, d);}\n"
831         + "else if (y >= 0 && m >= 0)\n"
832         + "{v = new Date(y, m);}\n"
833         + "else if (y >= 0)\n"
834         + "{v = new Date(y);}\n"
835         + "}return (v && (z || o))?\n" 
836         + "    ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" 
837         + "        v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" 
838         + ";}";
839
840     Date.parseRegexes[N] = new  RegExp("^" + Q + "$");
841     
842
843     eval(P);
844 };
845
846
847 Date.formatCodeToRegex = function(S, T) {
848     switch (S) {
849     case  "D":
850         return  {g:0,
851         c:null,
852         s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
853     case  "j":
854         return  {g:1,
855             c:"d = parseInt(results[" + T + "], 10);\n",
856             s:"(\\d{1,2})"}; 
857     case  "d":
858         return  {g:1,
859             c:"d = parseInt(results[" + T + "], 10);\n",
860             s:"(\\d{2})"}; 
861     case  "l":
862         return  {g:0,
863             c:null,
864             s:"(?:" + Date.dayNames.join("|") + ")"};
865     case  "S":
866         return  {g:0,
867             c:null,
868             s:"(?:st|nd|rd|th)"};
869     case  "w":
870         return  {g:0,
871             c:null,
872             s:"\\d"};
873     case  "z":
874         return  {g:0,
875             c:null,
876             s:"(?:\\d{1,3})"};
877     case  "W":
878         return  {g:0,
879             c:null,
880             s:"(?:\\d{2})"};
881     case  "F":
882         return  {g:1,
883             c:"m = parseInt(Date.monthNumbers[results[" + T + "].substring(0, 3)], 10);\n",
884             s:"(" + Date.monthNames.join("|") + ")"};
885     case  "M":
886         return  {g:1,
887             c:"m = parseInt(Date.monthNumbers[results[" + T + "]], 10);\n",
888             s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
889     case  "n":
890         return  {g:1,
891             c:"m = parseInt(results[" + T + "], 10) - 1;\n",
892             s:"(\\d{1,2})"}; 
893     case  "m":
894         return  {g:1,
895             c:"m = parseInt(results[" + T + "], 10) - 1;\n",
896             s:"(\\d{2})"}; 
897     case  "t":
898         return  {g:0,
899             c:null,
900             s:"\\d{1,2}"};
901     case  "L":
902         return  {g:0,
903             c:null,
904             s:"(?:1|0)"};
905     case  "Y":
906         return  {g:1,
907             c:"y = parseInt(results[" + T + "], 10);\n",
908             s:"(\\d{4})"};
909     case  "y":
910         return  {g:1,
911             c:"var ty = parseInt(results[" + T + "], 10);\n"
912                 + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
913             s:"(\\d{1,2})"};
914     case  "a":
915         return  {g:1,
916             c:"if (results[" + T + "] == 'am') {\n"
917                 + "if (h == 12) { h = 0; }\n"
918                 + "} else { if (h < 12) { h += 12; }}",
919             s:"(am|pm)"};
920     case  "A":
921         return  {g:1,
922             c:"if (results[" + T + "] == 'AM') {\n"
923                 + "if (h == 12) { h = 0; }\n"
924                 + "} else { if (h < 12) { h += 12; }}",
925             s:"(AM|PM)"};
926     case  "g":
927     case  "G":
928         return  {g:1,
929             c:"h = parseInt(results[" + T + "], 10);\n",
930             s:"(\\d{1,2})"}; 
931     case  "h":
932     case  "H":
933         return  {g:1,
934             c:"h = parseInt(results[" + T + "], 10);\n",
935             s:"(\\d{2})"}; 
936     case  "i":
937         return  {g:1,
938             c:"i = parseInt(results[" + T + "], 10);\n",
939             s:"(\\d{2})"};
940     case  "s":
941         return  {g:1,
942             c:"s = parseInt(results[" + T + "], 10);\n",
943             s:"(\\d{2})"};
944     case  "O":
945         return  {g:1,
946             c:[
947                 "o = results[", T, "];\n",
948                 "var sn = o.substring(0,1);\n", 
949                 "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", 
950                 "var mn = o.substring(3,5) % 60;\n", 
951                 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", 
952                 "    (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
953             ].join(""),
954             s:"([+\-]\\d{4})"};
955     case  "T":
956         return  {g:0,
957             c:null,
958             s:"[A-Z]{1,4}"}; 
959     case  "Z":
960         return  {g:1,
961             c:"z = results[" + T + "];\n" 
962                   + "z = (-43200 <= z*1 && z*1 <= 50400)? z : null;\n",
963             s:"([+\-]?\\d{1,5})"}; 
964     default:
965         return  {g:0,
966             c:null,
967             s:String.escape(S)};
968     }
969 };
970
971
972
973 Date.prototype.getTimezone = function() {
974     return  this.toString().replace(/^.*? ([A-Z]{1,4})[\-+][0-9]{4} .*$/, "$1");
975 };
976
977
978
979 Date.prototype.getGMTOffset = function() {
980     return  (this.getTimezoneOffset() > 0 ? "-" : "+")
981         + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
982         + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
983 };
984
985
986
987 Date.prototype.getDayOfYear = function() {
988     var  U = 0;
989     Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
990     for (var  i = 0; i < this.getMonth(); ++i) {
991         U += Date.daysInMonth[i];
992     }
993     return  U + this.getDate() - 1;
994 };
995
996
997
998 Date.prototype.getWeekOfYear = function() {
999     
1000     var  V = this.getDayOfYear() + (4 - this.getDay());
1001     
1002     var  W = new  Date(this.getFullYear(), 0, 1);
1003     var  X = (7 - W.getDay() + 4);
1004     return  String.leftPad(((V - X) / 7) + 1, 2, "0");
1005 };
1006
1007
1008
1009 Date.prototype.isLeapYear = function() {
1010     var  Y = this.getFullYear();
1011     return  ((Y & 3) == 0 && (Y % 100 || (Y % 400 == 0 && Y)));
1012 };
1013
1014
1015
1016 Date.prototype.getFirstDayOfMonth = function() {
1017     var  Z = (this.getDay() - (this.getDate() - 1)) % 7;
1018     return  (Z < 0) ? (Z + 7) : Z;
1019 };
1020
1021
1022
1023 Date.prototype.getLastDayOfMonth = function() {
1024     var  a = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
1025     return  (a < 0) ? (a + 7) : a;
1026 };
1027
1028
1029
1030
1031 Date.prototype.getFirstDateOfMonth = function() {
1032     return  new  Date(this.getFullYear(), this.getMonth(), 1);
1033 };
1034
1035
1036
1037 Date.prototype.getLastDateOfMonth = function() {
1038     return  new  Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
1039 };
1040
1041
1042 Date.prototype.getDaysInMonth = function() {
1043     Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
1044     return  Date.daysInMonth[this.getMonth()];
1045 };
1046
1047
1048
1049 Date.prototype.getSuffix = function() {
1050     switch (this.getDate()) {
1051         case  1:
1052         case  21:
1053         case  31:
1054             return  "st";
1055         case  2:
1056         case  22:
1057             return  "nd";
1058         case  3:
1059         case  23:
1060             return  "rd";
1061         default:
1062             return  "th";
1063     }
1064 };
1065
1066
1067 Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
1068
1069
1070
1071 Date.monthNames =
1072    ["January",
1073     "February",
1074     "March",
1075     "April",
1076     "May",
1077     "June",
1078     "July",
1079     "August",
1080     "September",
1081     "October",
1082     "November",
1083     "December"];
1084
1085
1086
1087 Date.dayNames =
1088    ["Sunday",
1089     "Monday",
1090     "Tuesday",
1091     "Wednesday",
1092     "Thursday",
1093     "Friday",
1094     "Saturday"];
1095
1096
1097 Date.y2kYear = 50;
1098
1099 Date.monthNumbers = {
1100     Jan:0,
1101     Feb:1,
1102     Mar:2,
1103     Apr:3,
1104     May:4,
1105     Jun:5,
1106     Jul:6,
1107     Aug:7,
1108     Sep:8,
1109     Oct:9,
1110     Nov:10,
1111     Dec:11};
1112
1113
1114
1115 Date.prototype.clone = function() {
1116         return  new  Date(this.getTime());
1117 };
1118
1119
1120
1121 Date.prototype.clearTime = function(b){
1122     if(b){
1123         return  this.clone().clearTime();
1124     }
1125
1126     this.setHours(0);
1127     this.setMinutes(0);
1128     this.setSeconds(0);
1129     this.setMilliseconds(0);
1130     return  this;
1131 };
1132
1133
1134
1135 if(Roo.isSafari){
1136     Date.brokenSetMonth = Date.prototype.setMonth;
1137         Date.prototype.setMonth = function(c){
1138                 if(c <= -1){
1139                         var  n = Math.ceil(-c);
1140                         var  back_year = Math.ceil(n/12);
1141                         var  month = (n % 12) ? 12 - n % 12 : 0 ;
1142                         this.setFullYear(this.getFullYear() - back_year);
1143                         return  Date.brokenSetMonth.call(this, month);
1144                 } else  {
1145                         return  Date.brokenSetMonth.apply(this, arguments);
1146                 }
1147         };
1148 }
1149
1150
1151
1152
1153 Date.MILLI = "ms";
1154
1155
1156 Date.SECOND = "s";
1157
1158
1159 Date.MINUTE = "mi";
1160
1161
1162 Date.HOUR = "h";
1163
1164
1165 Date.DAY = "d";
1166
1167
1168 Date.MONTH = "mo";
1169
1170
1171 Date.YEAR = "y";
1172
1173
1174
1175 Date.prototype.add = function(e, f){
1176   var  d = this.clone();
1177   if (!e || f === 0) return  d;
1178   switch(e.toLowerCase()){
1179     case  Date.MILLI:
1180       d.setMilliseconds(this.getMilliseconds() + f);
1181       break;
1182     case  Date.SECOND:
1183       d.setSeconds(this.getSeconds() + f);
1184       break;
1185     case  Date.MINUTE:
1186       d.setMinutes(this.getMinutes() + f);
1187       break;
1188     case  Date.HOUR:
1189       d.setHours(this.getHours() + f);
1190       break;
1191     case  Date.DAY:
1192       d.setDate(this.getDate() + f);
1193       break;
1194     case  Date.MONTH:
1195       var  a = this.getDate();
1196       if(a > 28){
1197           a = Math.min(a, this.getFirstDateOfMonth().add('mo', f).getLastDateOfMonth().getDate());
1198       }
1199
1200       d.setDate(a);
1201       d.setMonth(this.getMonth() + f);
1202       break;
1203     case  Date.YEAR:
1204       d.setFullYear(this.getFullYear() + f);
1205       break;
1206   }
1207   return  d;
1208 };
1209
1210
1211
1212 Roo.lib.Dom = {
1213     getViewWidth : function(A) {
1214         return  A ? this.getDocumentWidth() : this.getViewportWidth();
1215     },
1216
1217     getViewHeight : function(B) {
1218         return  B ? this.getDocumentHeight() : this.getViewportHeight();
1219     },
1220
1221     getDocumentHeight: function() {
1222         var  C = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
1223         return  Math.max(C, this.getViewportHeight());
1224     },
1225
1226     getDocumentWidth: function() {
1227         var  D = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
1228         return  Math.max(D, this.getViewportWidth());
1229     },
1230
1231     getViewportHeight: function() {
1232         var  E = self.innerHeight;
1233         var  F = document.compatMode;
1234
1235         if ((F || Roo.isIE) && !Roo.isOpera) {
1236             E = (F == "CSS1Compat") ?
1237                      document.documentElement.clientHeight :
1238                      document.body.clientHeight;
1239         }
1240
1241         return  E;
1242     },
1243
1244     getViewportWidth: function() {
1245         var  G = self.innerWidth;
1246         var  H = document.compatMode;
1247
1248         if (H || Roo.isIE) {
1249             G = (H == "CSS1Compat") ?
1250                     document.documentElement.clientWidth :
1251                     document.body.clientWidth;
1252         }
1253         return  G;
1254     },
1255
1256     isAncestor : function(p, c) {
1257         p = Roo.getDom(p);
1258         c = Roo.getDom(c);
1259         if (!p || !c) {
1260             return  false;
1261         }
1262
1263         if (p.contains && !Roo.isSafari) {
1264             return  p.contains(c);
1265         } else  if (p.compareDocumentPosition) {
1266             return  !!(p.compareDocumentPosition(c) & 16);
1267         } else  {
1268             var  parent = c.parentNode;
1269             while (parent) {
1270                 if (parent == p) {
1271                     return  true;
1272                 }
1273                 else  if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
1274                     return  false;
1275                 }
1276
1277                 parent = parent.parentNode;
1278             }
1279             return  false;
1280         }
1281     },
1282
1283     getRegion : function(el) {
1284         return  Roo.lib.Region.getRegion(el);
1285     },
1286
1287     getY : function(el) {
1288         return  this.getXY(el)[1];
1289     },
1290
1291     getX : function(el) {
1292         return  this.getXY(el)[0];
1293     },
1294
1295     getXY : function(el) {
1296         var  p, pe, b, I, bd = document.body;
1297         el = Roo.getDom(el);
1298         var  J = Roo.lib.AnimBase.fly;
1299         if (el.getBoundingClientRect) {
1300             b = el.getBoundingClientRect();
1301             I = J(document).getScroll();
1302             return  [b.left + I.left, b.top + I.top];
1303         }
1304         var  x = 0, y = 0;
1305
1306         p = el;
1307
1308         var  K = J(el).getStyle("position") == "absolute";
1309
1310         while (p) {
1311
1312             x += p.offsetLeft;
1313             y += p.offsetTop;
1314
1315             if (!K && J(p).getStyle("position") == "absolute") {
1316                 K = true;
1317             }
1318
1319             if (Roo.isGecko) {
1320                 pe = J(p);
1321
1322                 var  bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1323                 var  bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1324
1325
1326                 x += bl;
1327                 y += bt;
1328
1329
1330                 if (p != el && pe.getStyle('overflow') != 'visible') {
1331                     x += bl;
1332                     y += bt;
1333                 }
1334             }
1335
1336             p = p.offsetParent;
1337         }
1338
1339         if (Roo.isSafari && K) {
1340             x -= bd.offsetLeft;
1341             y -= bd.offsetTop;
1342         }
1343
1344         if (Roo.isGecko && !K) {
1345             var  dbd = J(bd);
1346             x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1347             y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1348         }
1349
1350
1351         p = el.parentNode;
1352         while (p && p != bd) {
1353             if (!Roo.isOpera || (p.tagName != 'TR' && J(p).getStyle("display") != "inline")) {
1354                 x -= p.scrollLeft;
1355                 y -= p.scrollTop;
1356             }
1357
1358             p = p.parentNode;
1359         }
1360         return  [x, y];
1361     },
1362  
1363   
1364
1365
1366     setXY : function(el, xy) {
1367         el = Roo.fly(el, '_setXY');
1368         el.position();
1369         var  L = el.translatePoints(xy);
1370         if (xy[0] !== false) {
1371             el.dom.style.left = L.left + "px";
1372         }
1373         if (xy[1] !== false) {
1374             el.dom.style.top = L.top + "px";
1375         }
1376     },
1377
1378     setX : function(el, x) {
1379         this.setXY(el, [x, false]);
1380     },
1381
1382     setY : function(el, y) {
1383         this.setXY(el, [false, y]);
1384     }
1385 };
1386
1387
1388
1389
1390 Roo.lib.Event = function() {
1391     var  A = false;
1392     var  B = [];
1393     var  C = [];
1394     var  D = 0;
1395     var  E = [];
1396     var  F = 0;
1397     var  G = null;
1398
1399     return  {
1400         POLL_RETRYS: 200,
1401         POLL_INTERVAL: 20,
1402         EL: 0,
1403         TYPE: 1,
1404         FN: 2,
1405         WFN: 3,
1406         OBJ: 3,
1407         ADJ_SCOPE: 4,
1408         _interval: null,
1409
1410         startInterval: function() {
1411             if (!this._interval) {
1412                 var  self = this;
1413                 var  callback = function() {
1414                     self._tryPreloadAttach();
1415                 };
1416                 this._interval = setInterval(callback, this.POLL_INTERVAL);
1417
1418             }
1419         },
1420
1421         onAvailable: function(h, k, m, n) {
1422             E.push({ id:         h,
1423                 fn:         k,
1424                 obj:        m,
1425                 override:   n,
1426                 checkReady: false    });
1427
1428             D = this.POLL_RETRYS;
1429             this.startInterval();
1430         },
1431
1432
1433         addListener: function(el, o, fn) {
1434             el = Roo.getDom(el);
1435             if (!el || !fn) {
1436                 return  false;
1437             }
1438
1439             if ("unload" == o) {
1440                 C[C.length] =
1441                 [el, o, fn];
1442                 return  true;
1443             }
1444
1445             var  p = function(e) {
1446                 return  fn(Roo.lib.Event.getEvent(e));
1447             };
1448
1449             var  li = [el, o, fn, p];
1450
1451             var  q = B.length;
1452             B[q] = li;
1453
1454             this.doAdd(el, o, p, false);
1455             return  true;
1456
1457         },
1458
1459
1460         removeListener: function(el, r, fn) {
1461             var  i, s;
1462
1463             el = Roo.getDom(el);
1464
1465             if(!fn) {
1466                 return  this.purgeElement(el, false, r);
1467             }
1468
1469
1470             if ("unload" == r) {
1471
1472                 for (i = 0,s = C.length; i < s; i++) {
1473                     var  li = C[i];
1474                     if (li &&
1475                         li[0] == el &&
1476                         li[1] == r &&
1477                         li[2] == fn) {
1478                         C.splice(i, 1);
1479                         return  true;
1480                     }
1481                 }
1482
1483                 return  false;
1484             }
1485
1486             var  u = null;
1487
1488
1489             var  v = arguments[3];
1490
1491             if ("undefined" == typeof  v) {
1492                 v = this._getCacheIndex(el, r, fn);
1493             }
1494
1495             if (v >= 0) {
1496                 u = B[v];
1497             }
1498
1499             if (!el || !u) {
1500                 return  false;
1501             }
1502
1503
1504             this.doRemove(el, r, u[this.WFN], false);
1505
1506             delete  B[v][this.WFN];
1507             delete  B[v][this.FN];
1508             B.splice(v, 1);
1509
1510             return  true;
1511
1512         },
1513
1514
1515         getTarget: function(ev, w) {
1516             ev = ev.browserEvent || ev;
1517             var  t = ev.target || ev.srcElement;
1518             return  this.resolveTextNode(t);
1519         },
1520
1521
1522         resolveTextNode: function(z) {
1523             if (Roo.isSafari && z && 3 == z.nodeType) {
1524                 return  z.parentNode;
1525             } else  {
1526                 return  z;
1527             }
1528         },
1529
1530
1531         getPageX: function(ev) {
1532             ev = ev.browserEvent || ev;
1533             var  x = ev.pageX;
1534             if (!x && 0 !== x) {
1535                 x = ev.clientX || 0;
1536
1537                 if (Roo.isIE) {
1538                     x += this.getScroll()[1];
1539                 }
1540             }
1541
1542             return  x;
1543         },
1544
1545
1546         getPageY: function(ev) {
1547             ev = ev.browserEvent || ev;
1548             var  y = ev.pageY;
1549             if (!y && 0 !== y) {
1550                 y = ev.clientY || 0;
1551
1552                 if (Roo.isIE) {
1553                     y += this.getScroll()[0];
1554                 }
1555             }
1556
1557
1558             return  y;
1559         },
1560
1561
1562         getXY: function(ev) {
1563             ev = ev.browserEvent || ev;
1564             return  [this.getPageX(ev), this.getPageY(ev)];
1565         },
1566
1567
1568         getRelatedTarget: function(ev) {
1569             ev = ev.browserEvent || ev;
1570             var  t = ev.relatedTarget;
1571             if (!t) {
1572                 if (ev.type == "mouseout") {
1573                     t = ev.toElement;
1574                 } else  if (ev.type == "mouseover") {
1575                     t = ev.fromElement;
1576                 }
1577             }
1578
1579             return  this.resolveTextNode(t);
1580         },
1581
1582
1583         getTime: function(ev) {
1584             ev = ev.browserEvent || ev;
1585             if (!ev.time) {
1586                 var  t = new  Date().getTime();
1587                 try {
1588                     ev.time = t;
1589                 } catch(ex) {
1590                     this.lastError = ex;
1591                     return  t;
1592                 }
1593             }
1594
1595             return  ev.time;
1596         },
1597
1598
1599         stopEvent: function(ev) {
1600             this.stopPropagation(ev);
1601             this.preventDefault(ev);
1602         },
1603
1604
1605         stopPropagation: function(ev) {
1606             ev = ev.browserEvent || ev;
1607             if (ev.stopPropagation) {
1608                 ev.stopPropagation();
1609             } else  {
1610                 ev.cancelBubble = true;
1611             }
1612         },
1613
1614
1615         preventDefault: function(ev) {
1616             ev = ev.browserEvent || ev;
1617             if(ev.preventDefault) {
1618                 ev.preventDefault();
1619             } else  {
1620                 ev.returnValue = false;
1621             }
1622         },
1623
1624
1625         getEvent: function(e) {
1626             var  ev = e || window.event;
1627             if (!ev) {
1628                 var  c = this.getEvent.caller;
1629                 while (c) {
1630                     ev = c.arguments[0];
1631                     if (ev && Event == ev.constructor) {
1632                         break;
1633                     }
1634
1635                     c = c.caller;
1636                 }
1637             }
1638             return  ev;
1639         },
1640
1641
1642         getCharCode: function(ev) {
1643             ev = ev.browserEvent || ev;
1644             return  ev.charCode || ev.keyCode || 0;
1645         },
1646
1647
1648         _getCacheIndex: function(el, AA, fn) {
1649             for (var  i = 0,s = B.length; i < s; ++i) {
1650                 var  li = B[i];
1651                 if (li &&
1652                     li[this.FN] == fn &&
1653                     li[this.EL] == el &&
1654                     li[this.TYPE] == AA) {
1655                     return  i;
1656                 }
1657             }
1658
1659             return  -1;
1660         },
1661
1662
1663         elCache: {},
1664
1665
1666         getEl: function(id) {
1667             return  document.getElementById(id);
1668         },
1669
1670
1671         clearCache: function() {
1672         },
1673
1674
1675         _load: function(e) {
1676             A = true;
1677             var  EU = Roo.lib.Event;
1678
1679
1680             if (Roo.isIE) {
1681                 EU.doRemove(window, "load", EU._load);
1682             }
1683         },
1684
1685
1686         _tryPreloadAttach: function() {
1687
1688             if (this.locked) {
1689                 return  false;
1690             }
1691
1692
1693             this.locked = true;
1694
1695
1696             var  AB = !A;
1697             if (!AB) {
1698                 AB = (D > 0);
1699             }
1700
1701
1702             var  AC = [];
1703             for (var  i = 0,s = E.length; i < s; ++i) {
1704                 var  item = E[i];
1705                 if (item) {
1706                     var  el = this.getEl(item.id);
1707
1708                     if (el) {
1709                         if (!item.checkReady ||
1710                             A ||
1711                             el.nextSibling ||
1712                             (document && document.body)) {
1713
1714                             var  scope = el;
1715                             if (item.override) {
1716                                 if (item.override === true) {
1717                                     scope = item.obj;
1718                                 } else  {
1719                                     scope = item.override;
1720                                 }
1721                             }
1722
1723                             item.fn.call(scope, item.obj);
1724                             E[i] = null;
1725                         }
1726                     } else  {
1727                         AC.push(item);
1728                     }
1729                 }
1730             }
1731
1732
1733             D = (AC.length === 0) ? 0 : D - 1;
1734
1735             if (AB) {
1736
1737                 this.startInterval();
1738             } else  {
1739                 clearInterval(this._interval);
1740                 this._interval = null;
1741             }
1742
1743
1744             this.locked = false;
1745
1746             return  true;
1747
1748         },
1749
1750
1751         purgeElement: function(el, AD, AE) {
1752             var  AF = this.getListeners(el, AE);
1753             if (AF) {
1754                 for (var  i = 0,s = AF.length; i < s; ++i) {
1755                     var  l = AF[i];
1756                     this.removeListener(el, l.type, l.fn);
1757                 }
1758             }
1759
1760             if (AD && el && el.childNodes) {
1761                 for (i = 0,s = el.childNodes.length; i < s; ++i) {
1762                     this.purgeElement(el.childNodes[i], AD, AE);
1763                 }
1764             }
1765         },
1766
1767
1768         getListeners: function(el, AG) {
1769             var  AH = [], AI;
1770             if (!AG) {
1771                 AI = [B, C];
1772             } else  if (AG == "unload") {
1773                 AI = [C];
1774             } else  {
1775                 AI = [B];
1776             }
1777
1778             for (var  j = 0; j < AI.length; ++j) {
1779                 var  searchList = AI[j];
1780                 if (searchList && searchList.length > 0) {
1781                     for (var  i = 0,s = searchList.length; i < s; ++i) {
1782                         var  l = searchList[i];
1783                         if (l && l[this.EL] === el &&
1784                             (!AG || AG === l[this.TYPE])) {
1785                             AH.push({
1786                                 type:   l[this.TYPE],
1787                                 fn:     l[this.FN],
1788                                 obj:    l[this.OBJ],
1789                                 adjust: l[this.ADJ_SCOPE],
1790                                 index:  i
1791                             });
1792                         }
1793                     }
1794                 }
1795             }
1796
1797             return  (AH.length) ? AH : null;
1798         },
1799
1800
1801         _unload: function(e) {
1802
1803             var  EU = Roo.lib.Event, i, j, l, AJ, AK;
1804
1805             for (i = 0,AJ = C.length; i < AJ; ++i) {
1806                 l = C[i];
1807                 if (l) {
1808                     var  scope = window;
1809                     if (l[EU.ADJ_SCOPE]) {
1810                         if (l[EU.ADJ_SCOPE] === true) {
1811                             scope = l[EU.OBJ];
1812                         } else  {
1813                             scope = l[EU.ADJ_SCOPE];
1814                         }
1815                     }
1816
1817                     l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
1818                     C[i] = null;
1819                     l = null;
1820                     scope = null;
1821                 }
1822             }
1823
1824
1825             C = null;
1826
1827             if (B && B.length > 0) {
1828                 j = B.length;
1829                 while (j) {
1830                     AK = j - 1;
1831                     l = B[AK];
1832                     if (l) {
1833                         EU.removeListener(l[EU.EL], l[EU.TYPE],
1834                                 l[EU.FN], AK);
1835                     }
1836
1837                     j = j - 1;
1838                 }
1839
1840                 l = null;
1841
1842                 EU.clearCache();
1843             }
1844
1845
1846             EU.doRemove(window, "unload", EU._unload);
1847
1848         },
1849
1850
1851         getScroll: function() {
1852             var  dd = document.documentElement, db = document.body;
1853             if (dd && (dd.scrollTop || dd.scrollLeft)) {
1854                 return  [dd.scrollTop, dd.scrollLeft];
1855             } else  if (db) {
1856                 return  [db.scrollTop, db.scrollLeft];
1857             } else  {
1858                 return  [0, 0];
1859             }
1860         },
1861
1862
1863         doAdd: function () {
1864             if (window.addEventListener) {
1865                 return  function(el, AL, fn, AM) {
1866                     el.addEventListener(AL, fn, (AM));
1867                 };
1868             } else  if (window.attachEvent) {
1869                 return  function(el, AL, fn, AM) {
1870                     el.attachEvent("on" + AL, fn);
1871                 };
1872             } else  {
1873                 return  function() {
1874                 };
1875             }
1876         }(),
1877
1878
1879         doRemove: function() {
1880             if (window.removeEventListener) {
1881                 return  function (el, AL, fn, AM) {
1882                     el.removeEventListener(AL, fn, (AM));
1883                 };
1884             } else  if (window.detachEvent) {
1885                 return  function (el, AL, fn) {
1886                     el.detachEvent("on" + AL, fn);
1887                 };
1888             } else  {
1889                 return  function() {
1890                 };
1891             }
1892         }()
1893     };
1894     
1895 }();
1896 (function() {     
1897    
1898     var  E = Roo.lib.Event;
1899     E.on = E.addListener;
1900     E.un = E.removeListener;
1901
1902     if (document && document.body) {
1903         E._load();
1904     } else  {
1905         E.doAdd(window, "load", E._load);
1906     }
1907
1908     E.doAdd(window, "unload", E._unload);
1909     E._tryPreloadAttach();
1910 })();
1911
1912
1913
1914
1915
1916 (function() {
1917     
1918     Roo.lib.Ajax = {
1919         request : function(A, B, cb, C, D) {
1920             if(D){
1921                 var  hs = D.headers;
1922                 if(hs){
1923                     for(var  h  in  hs){
1924                         if(hs.hasOwnProperty(h)){
1925                             this.initHeader(h, hs[h], false);
1926                         }
1927                     }
1928                 }
1929                 if(D.xmlData){
1930                     this.initHeader('Content-Type', 'text/xml', false);
1931                     A = 'POST';
1932                     C = D.xmlData;
1933                 }
1934             }
1935
1936             return  this.asyncRequest(A, B, cb, C);
1937         },
1938
1939         serializeForm : function(E) {
1940             if(typeof  E == 'string') {
1941                 E = (document.getElementById(E) || document.forms[E]);
1942             }
1943
1944             var  el, F, G, H, I = '', J = false;
1945             for (var  i = 0; i < E.elements.length; i++) {
1946                 el = E.elements[i];
1947                 H = E.elements[i].disabled;
1948                 F = E.elements[i].name;
1949                 G = E.elements[i].value;
1950
1951                 if (!H && F){
1952                     switch (el.type)
1953                             {
1954                         case  'select-one':
1955                         case  'select-multiple':
1956                             for (var  j = 0; j < el.options.length; j++) {
1957                                 if (el.options[j].selected) {
1958                                     if (Roo.isIE) {
1959                                         I += encodeURIComponent(F) + '=' + encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
1960                                     }
1961                                     else  {
1962                                         I += encodeURIComponent(F) + '=' + encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
1963                                     }
1964                                 }
1965                             }
1966                             break;
1967                         case  'radio':
1968                         case  'checkbox':
1969                             if (el.checked) {
1970                                 I += encodeURIComponent(F) + '=' + encodeURIComponent(G) + '&';
1971                             }
1972                             break;
1973                         case  'file':
1974
1975                         case  undefined:
1976
1977                         case  'reset':
1978
1979                         case  'button':
1980
1981                             break;
1982                         case  'submit':
1983                             if(J == false) {
1984                                 I += encodeURIComponent(F) + '=' + encodeURIComponent(G) + '&';
1985                                 J = true;
1986                             }
1987                             break;
1988                         default:
1989                             I += encodeURIComponent(F) + '=' + encodeURIComponent(G) + '&';
1990                             break;
1991                     }
1992                 }
1993             }
1994
1995             I = I.substr(0, I.length - 1);
1996             return  I;
1997         },
1998
1999         headers:{},
2000
2001         hasHeaders:false,
2002
2003         useDefaultHeader:true,
2004
2005         defaultPostHeader:'application/x-www-form-urlencoded',
2006
2007         useDefaultXhrHeader:true,
2008
2009         defaultXhrHeader:'XMLHttpRequest',
2010
2011         hasDefaultHeaders:true,
2012
2013         defaultHeaders:{},
2014
2015         poll:{},
2016
2017         timeout:{},
2018
2019         pollInterval:50,
2020
2021         transactionId:0,
2022
2023         setProgId:function(id)
2024         {
2025             this.activeX.unshift(id);
2026         },
2027
2028         setDefaultPostHeader:function(b)
2029         {
2030             this.useDefaultHeader = b;
2031         },
2032
2033         setDefaultXhrHeader:function(b)
2034         {
2035             this.useDefaultXhrHeader = b;
2036         },
2037
2038         setPollingInterval:function(i)
2039         {
2040             if (typeof  i == 'number' && isFinite(i)) {
2041                 this.pollInterval = i;
2042             }
2043         },
2044
2045         createXhrObject:function(K)
2046         {
2047             var  L,M;
2048             try
2049             {
2050
2051                 M = new  XMLHttpRequest();
2052
2053                 L = { conn:M, tId:K };
2054             }
2055             catch(e)
2056             {
2057                 for (var  i = 0; i < this.activeX.length; ++i) {
2058                     try
2059                     {
2060
2061                         http = new  ActiveXObject(this.activeX[i]);
2062
2063                         obj = { conn:http, tId:transactionId };
2064                         break;
2065                     }
2066                     catch(e) {
2067                     }
2068                 }
2069             }
2070             finally
2071             {
2072                 return  L;
2073             }
2074         },
2075
2076         getConnectionObject:function()
2077         {
2078             var  o;
2079             var  N = this.transactionId;
2080
2081             try
2082             {
2083                 o = this.createXhrObject(N);
2084                 if (o) {
2085                     this.transactionId++;
2086                 }
2087             }
2088             catch(e) {
2089             }
2090             finally
2091             {
2092                 return  o;
2093             }
2094         },
2095
2096         asyncRequest:function(O, P, Q, R)
2097         {
2098             var  o = this.getConnectionObject();
2099
2100             if (!o) {
2101                 return  null;
2102             }
2103             else  {
2104                 o.conn.open(O, P, true);
2105
2106                 if (this.useDefaultXhrHeader) {
2107                     if (!this.defaultHeaders['X-Requested-With']) {
2108                         this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
2109                     }
2110                 }
2111
2112                 if(R && this.useDefaultHeader){
2113                     this.initHeader('Content-Type', this.defaultPostHeader);
2114                 }
2115
2116                  if (this.hasDefaultHeaders || this.hasHeaders) {
2117                     this.setHeader(o);
2118                 }
2119
2120
2121                 this.handleReadyState(o, Q);
2122                 o.conn.send(R || null);
2123
2124                 return  o;
2125             }
2126         },
2127
2128         handleReadyState:function(o, S)
2129         {
2130             var  T = this;
2131
2132             if (S && S.timeout) {
2133                 this.timeout[o.tId] = window.setTimeout(function() {
2134                     T.abort(o, S, true);
2135                 }, S.timeout);
2136             }
2137
2138
2139             this.poll[o.tId] = window.setInterval(
2140                     function() {
2141                         if (o.conn && o.conn.readyState == 4) {
2142                             window.clearInterval(T.poll[o.tId]);
2143                             delete  T.poll[o.tId];
2144
2145                             if(S && S.timeout) {
2146                                 window.clearTimeout(T.timeout[o.tId]);
2147                                 delete  T.timeout[o.tId];
2148                             }
2149
2150
2151                             T.handleTransactionResponse(o, S);
2152                         }
2153                     }
2154                     , this.pollInterval);
2155         },
2156
2157         handleTransactionResponse:function(o, U, V)
2158         {
2159
2160             if (!U) {
2161                 this.releaseObject(o);
2162                 return;
2163             }
2164
2165             var  W, X;
2166
2167             try
2168             {
2169                 if (o.conn.status !== undefined && o.conn.status != 0) {
2170                     W = o.conn.status;
2171                 }
2172                 else  {
2173                     W = 13030;
2174                 }
2175             }
2176             catch(e) {
2177
2178
2179                 httpStatus = 13030;
2180             }
2181
2182             if (W >= 200 && W < 300) {
2183                 X = this.createResponseObject(o, U.argument);
2184                 if (U.success) {
2185                     if (!U.scope) {
2186                         U.success(X);
2187                     }
2188                     else  {
2189
2190
2191                         U.success.apply(U.scope, [X]);
2192                     }
2193                 }
2194             }
2195             else  {
2196                 switch (W) {
2197
2198                     case  12002:
2199                     case  12029:
2200                     case  12030:
2201                     case  12031:
2202                     case  12152:
2203                     case  13030:
2204                         X = this.createExceptionObject(o.tId, U.argument, (V ? V : false));
2205                         if (U.failure) {
2206                             if (!U.scope) {
2207                                 U.failure(X);
2208                             }
2209                             else  {
2210                                 U.failure.apply(U.scope, [X]);
2211                             }
2212                         }
2213                         break;
2214                     default:
2215                         X = this.createResponseObject(o, U.argument);
2216                         if (U.failure) {
2217                             if (!U.scope) {
2218                                 U.failure(X);
2219                             }
2220                             else  {
2221                                 U.failure.apply(U.scope, [X]);
2222                             }
2223                         }
2224                 }
2225             }
2226
2227
2228             this.releaseObject(o);
2229             X = null;
2230         },
2231
2232         createResponseObject:function(o, Y)
2233         {
2234             var  Z = {};
2235             var  a = {};
2236
2237             try
2238             {
2239                 var  headerStr = o.conn.getAllResponseHeaders();
2240                 var  header = headerStr.split('\n');
2241                 for (var  i = 0; i < header.length; i++) {
2242                     var  delimitPos = header[i].indexOf(':');
2243                     if (delimitPos != -1) {
2244                         a[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
2245                     }
2246                 }
2247             }
2248             catch(e) {
2249             }
2250
2251
2252             Z.tId = o.tId;
2253             Z.status = o.conn.status;
2254             Z.statusText = o.conn.statusText;
2255             Z.getResponseHeader = a;
2256             Z.getAllResponseHeaders = headerStr;
2257             Z.responseText = o.conn.responseText;
2258             Z.responseXML = o.conn.responseXML;
2259
2260             if (typeof  Y !== undefined) {
2261                 Z.argument = Y;
2262             }
2263
2264             return  Z;
2265         },
2266
2267         createExceptionObject:function(c, d, f)
2268         {
2269             var  g = 0;
2270             var  k = 'communication failure';
2271             var  l = -1;
2272             var  m = 'transaction aborted';
2273
2274             var  n = {};
2275
2276             n.tId = c;
2277             if (f) {
2278                 n.status = l;
2279                 n.statusText = m;
2280             }
2281             else  {
2282                 n.status = g;
2283                 n.statusText = k;
2284             }
2285
2286             if (d) {
2287                 n.argument = d;
2288             }
2289
2290             return  n;
2291         },
2292
2293         initHeader:function(p, q, r)
2294         {
2295             var  s = (r) ? this.defaultHeaders : this.headers;
2296
2297             if (s[p] === undefined) {
2298                 s[p] = q;
2299             }
2300             else  {
2301
2302
2303                 s[p] = q + "," + s[p];
2304             }
2305
2306             if (r) {
2307                 this.hasDefaultHeaders = true;
2308             }
2309             else  {
2310                 this.hasHeaders = true;
2311             }
2312         },
2313
2314
2315         setHeader:function(o)
2316         {
2317             if (this.hasDefaultHeaders) {
2318                 for (var  prop  in  this.defaultHeaders) {
2319                     if (this.defaultHeaders.hasOwnProperty(prop)) {
2320                         o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
2321                     }
2322                 }
2323             }
2324
2325             if (this.hasHeaders) {
2326                 for (var  prop  in  this.headers) {
2327                     if (this.headers.hasOwnProperty(prop)) {
2328                         o.conn.setRequestHeader(prop, this.headers[prop]);
2329                     }
2330                 }
2331
2332                 this.headers = {};
2333                 this.hasHeaders = false;
2334             }
2335         },
2336
2337         resetDefaultHeaders:function() {
2338             delete  this.defaultHeaders;
2339             this.defaultHeaders = {};
2340             this.hasDefaultHeaders = false;
2341         },
2342
2343         abort:function(o, t, u)
2344         {
2345             if(this.isCallInProgress(o)) {
2346                 o.conn.abort();
2347                 window.clearInterval(this.poll[o.tId]);
2348                 delete  this.poll[o.tId];
2349                 if (u) {
2350                     delete  this.timeout[o.tId];
2351                 }
2352
2353
2354                 this.handleTransactionResponse(o, t, true);
2355
2356                 return  true;
2357             }
2358             else  {
2359                 return  false;
2360             }
2361         },
2362
2363
2364         isCallInProgress:function(o)
2365         {
2366             if (o && o.conn) {
2367                 return  o.conn.readyState != 4 && o.conn.readyState != 0;
2368             }
2369             else  {
2370
2371                 return  false;
2372             }
2373         },
2374
2375
2376         releaseObject:function(o)
2377         {
2378
2379             o.conn = null;
2380
2381             o = null;
2382         },
2383
2384         activeX:[
2385         'MSXML2.XMLHTTP.3.0',
2386         'MSXML2.XMLHTTP',
2387         'Microsoft.XMLHTTP'
2388         ]
2389
2390
2391     };
2392 })();
2393
2394
2395
2396 Roo.lib.Region = function(t, r, b, l) {
2397     this.top = t;
2398     this[1] = t;
2399     this.right = r;
2400     this.bottom = b;
2401     this.left = l;
2402     this[0] = l;
2403 };
2404
2405
2406 Roo.lib.Region.prototype = {
2407     contains : function(A) {
2408         return  ( A.left >= this.left &&
2409                  A.right <= this.right &&
2410                  A.top >= this.top &&
2411                  A.bottom <= this.bottom    );
2412
2413     },
2414
2415     getArea : function() {
2416         return  ( (this.bottom - this.top) * (this.right - this.left) );
2417     },
2418
2419     intersect : function(B) {
2420         var  t = Math.max(this.top, B.top);
2421         var  r = Math.min(this.right, B.right);
2422         var  b = Math.min(this.bottom, B.bottom);
2423         var  l = Math.max(this.left, B.left);
2424
2425         if (b >= t && r >= l) {
2426             return  new  Roo.lib.Region(t, r, b, l);
2427         } else  {
2428             return  null;
2429         }
2430     },
2431     union : function(C) {
2432         var  t = Math.min(this.top, C.top);
2433         var  r = Math.max(this.right, C.right);
2434         var  b = Math.max(this.bottom, C.bottom);
2435         var  l = Math.min(this.left, C.left);
2436
2437         return  new  Roo.lib.Region(t, r, b, l);
2438     },
2439
2440     adjust : function(t, l, b, r) {
2441         this.top += t;
2442         this.left += l;
2443         this.right += r;
2444         this.bottom += b;
2445         return  this;
2446     }
2447 };
2448
2449 Roo.lib.Region.getRegion = function(el) {
2450     var  p = Roo.lib.Dom.getXY(el);
2451
2452     var  t = p[1];
2453     var  r = p[0] + el.offsetWidth;
2454     var  b = p[1] + el.offsetHeight;
2455     var  l = p[0];
2456
2457     return  new  Roo.lib.Region(t, r, b, l);
2458 };
2459
2460
2461
2462
2463
2464
2465 Roo.lib.Point = function(x, y) {
2466     if (x  instanceof  Array) {
2467         y = x[1];
2468         x = x[0];
2469     }
2470
2471     this.x = this.right = this.left = this[0] = x;
2472     this.y = this.top = this.bottom = this[1] = y;
2473 };
2474
2475 Roo.lib.Point.prototype = new  Roo.lib.Region();
2476
2477
2478
2479  
2480 (function() {   
2481
2482     Roo.lib.Anim = {
2483         scroll : function(el, A, B, C, cb, D) {
2484             this.run(el, A, B, C, cb, D, Roo.lib.Scroll);
2485         },
2486
2487         motion : function(el, E, F, G, cb, H) {
2488             this.run(el, E, F, G, cb, H, Roo.lib.Motion);
2489         },
2490
2491         color : function(el, I, J, K, cb, L) {
2492             this.run(el, I, J, K, cb, L, Roo.lib.ColorAnim);
2493         },
2494
2495         run : function(el, M, N, O, cb, P, Q) {
2496             Q = Q || Roo.lib.AnimBase;
2497             if (typeof  O == "string") {
2498                 O = Roo.lib.Easing[O];
2499             }
2500             var  R = new  Q(el, M, N, O);
2501             R.animateX(function() {
2502                 Roo.callback(cb, P);
2503             });
2504             return  R;
2505         }
2506     };
2507 })();
2508
2509
2510
2511 (function() {    
2512     var  A;
2513     
2514     function  B(el) {
2515         if (!A) {
2516             A = new  Roo.Element.Flyweight();
2517         }
2518
2519         A.dom = el;
2520         return  A;
2521     }
2522
2523
2524     
2525     
2526    
2527     
2528     Roo.lib.AnimBase = function(el, C, D, E) {
2529         if (el) {
2530             this.init(el, C, D, E);
2531         }
2532     };
2533
2534     Roo.lib.AnimBase.fly = B;
2535     
2536     
2537     
2538     Roo.lib.AnimBase.prototype = {
2539
2540         toString: function() {
2541             var  el = this.getEl();
2542             var  id = el.id || el.tagName;
2543             return  ("Anim " + id);
2544         },
2545
2546         patterns: {
2547             noNegatives:        /width|height|opacity|padding/i,
2548             offsetAttribute:  /^((width|height)|(top|left))$/,
2549             defaultUnit:        /width|height|top$|bottom$|left$|right$/i,
2550             offsetUnit:         /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
2551         },
2552
2553
2554         doMethod: function(C, D, E) {
2555             return  this.method(this.currentFrame, D, E - D, this.totalFrames);
2556         },
2557
2558
2559         setAttribute: function(F, G, H) {
2560             if (this.patterns.noNegatives.test(F)) {
2561                 G = (G > 0) ? G : 0;
2562             }
2563
2564
2565             Roo.fly(this.getEl(), '_anim').setStyle(F, G + H);
2566         },
2567
2568
2569         getAttribute: function(I) {
2570             var  el = this.getEl();
2571             var  J = B(el).getStyle(I);
2572
2573             if (J !== 'auto' && !this.patterns.offsetUnit.test(J)) {
2574                 return  parseFloat(J);
2575             }
2576
2577             var  a = this.patterns.offsetAttribute.exec(I) || [];
2578             var  K = !!( a[3] );
2579             var  L = !!( a[2] );
2580
2581
2582             if (L || (B(el).getStyle('position') == 'absolute' && K)) {
2583                 J = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
2584             } else  {
2585                 J = 0;
2586             }
2587
2588             return  J;
2589         },
2590
2591
2592         getDefaultUnit: function(M) {
2593             if (this.patterns.defaultUnit.test(M)) {
2594                 return  'px';
2595             }
2596
2597             return  '';
2598         },
2599
2600         animateX : function(N, O) {
2601             var  f = function() {
2602                 this.onComplete.removeListener(f);
2603                 if (typeof  N == "function") {
2604                     N.call(O || this, this);
2605                 }
2606             };
2607             this.onComplete.addListener(f, this);
2608             this.animate();
2609         },
2610
2611
2612         setRuntimeAttribute: function(P) {
2613             var  Q;
2614             var  R;
2615             var  S = this.attributes;
2616
2617             this.runtimeAttributes[P] = {};
2618
2619             var  T = function(U) {
2620                 return  (typeof  U !== 'undefined');
2621             };
2622
2623             if (!T(S[P]['to']) && !T(S[P]['by'])) {
2624                 return  false;
2625             }
2626
2627
2628             Q = ( T(S[P]['from']) ) ? S[P]['from'] : this.getAttribute(P);
2629
2630
2631             if (T(S[P]['to'])) {
2632                 R = S[P]['to'];
2633             } else  if (T(S[P]['by'])) {
2634                 if (Q.constructor == Array) {
2635                     R = [];
2636                     for (var  i = 0, len = Q.length; i < len; ++i) {
2637                         R[i] = Q[i] + S[P]['by'][i];
2638                     }
2639                 } else  {
2640                     R = Q + S[P]['by'];
2641                 }
2642             }
2643
2644
2645             this.runtimeAttributes[P].start = Q;
2646             this.runtimeAttributes[P].end = R;
2647
2648
2649             this.runtimeAttributes[P].unit = ( T(S[P].unit) ) ? S[P]['unit'] : this.getDefaultUnit(P);
2650         },
2651
2652
2653         init: function(el, U, V, W) {
2654
2655             var  X = false;
2656
2657
2658             var  Y = null;
2659
2660
2661             var  Z = 0;
2662
2663
2664             el = Roo.getDom(el);
2665
2666
2667             this.attributes = U || {};
2668
2669
2670             this.duration = V || 1;
2671
2672
2673             this.method = W || Roo.lib.Easing.easeNone;
2674
2675
2676             this.useSeconds = true;
2677
2678
2679             this.currentFrame = 0;
2680
2681
2682             this.totalFrames = Roo.lib.AnimMgr.fps;
2683
2684
2685             this.getEl = function() {
2686                 return  el;
2687             };
2688
2689
2690             this.isAnimated = function() {
2691                 return  X;
2692             };
2693
2694
2695             this.getStartTime = function() {
2696                 return  Y;
2697             };
2698
2699             this.runtimeAttributes = {};
2700
2701
2702             this.animate = function() {
2703                 if (this.isAnimated()) {
2704                     return  false;
2705                 }
2706
2707
2708                 this.currentFrame = 0;
2709
2710                 this.totalFrames = ( this.useSeconds ) ? Math.ceil(Roo.lib.AnimMgr.fps * this.duration) : this.duration;
2711
2712                 Roo.lib.AnimMgr.registerElement(this);
2713             };
2714
2715
2716             this.stop = function(e) {
2717                 if (e) {
2718                     this.currentFrame = this.totalFrames;
2719                     this._onTween.fire();
2720                 }
2721
2722                 Roo.lib.AnimMgr.stop(this);
2723             };
2724
2725             var  b = function() {
2726                 this.onStart.fire();
2727
2728                 this.runtimeAttributes = {};
2729                 for (var  P  in  this.attributes) {
2730                     this.setRuntimeAttribute(P);
2731                 }
2732
2733
2734                 X = true;
2735                 Z = 0;
2736                 Y = new  Date();
2737             };
2738
2739
2740             var  c = function() {
2741                 var  e = {
2742                     duration: new  Date() - this.getStartTime(),
2743                     currentFrame: this.currentFrame
2744                 };
2745
2746                 e.toString = function() {
2747                     return  (
2748                             'duration: ' + e.duration +
2749                             ', currentFrame: ' + e.currentFrame
2750                             );
2751                 };
2752
2753                 this.onTween.fire(e);
2754
2755                 var  g = this.runtimeAttributes;
2756
2757                 for (var  P  in  g) {
2758                     this.setAttribute(P, this.doMethod(P, g[P].start, g[P].end), g[P].unit);
2759                 }
2760
2761
2762                 Z += 1;
2763             };
2764
2765             var  d = function() {
2766                 var  e = (new  Date() - Y) / 1000 ;
2767
2768                 var  g = {
2769                     duration: e,
2770                     frames: Z,
2771                     fps: Z / e
2772                 };
2773
2774                 g.toString = function() {
2775                     return  (
2776                             'duration: ' + g.duration +
2777                             ', frames: ' + g.frames +
2778                             ', fps: ' + g.fps
2779                             );
2780                 };
2781
2782                 X = false;
2783                 Z = 0;
2784                 this.onComplete.fire(g);
2785             };
2786
2787
2788             this._onStart = new  Roo.util.Event(this);
2789             this.onStart = new  Roo.util.Event(this);
2790             this.onTween = new  Roo.util.Event(this);
2791             this._onTween = new  Roo.util.Event(this);
2792             this.onComplete = new  Roo.util.Event(this);
2793             this._onComplete = new  Roo.util.Event(this);
2794             this._onStart.addListener(b);
2795             this._onTween.addListener(c);
2796             this._onComplete.addListener(d);
2797         }
2798     };
2799 })();
2800
2801
2802
2803
2804 Roo.lib.AnimMgr = new  function() {
2805
2806         var  A = null;
2807
2808
2809         var  B = [];
2810
2811
2812         var  C = 0;
2813
2814
2815         this.fps = 1000;
2816
2817
2818         this.delay = 1;
2819
2820
2821         this.registerElement = function(F) {
2822             B[B.length] = F;
2823             C += 1;
2824             F._onStart.fire();
2825             this.start();
2826         };
2827
2828
2829         this.unRegister = function(F, G) {
2830             F._onComplete.fire();
2831             G = G || D(F);
2832             if (G != -1) {
2833                 B.splice(G, 1);
2834             }
2835
2836
2837             C -= 1;
2838             if (C <= 0) {
2839                 this.stop();
2840             }
2841         };
2842
2843
2844         this.start = function() {
2845             if (A === null) {
2846                 A = setInterval(this.run, this.delay);
2847             }
2848         };
2849
2850
2851         this.stop = function(F) {
2852             if (!F) {
2853                 clearInterval(A);
2854
2855                 for (var  i = 0, len = B.length; i < len; ++i) {
2856                     if (B[0].isAnimated()) {
2857                         this.unRegister(B[0], 0);
2858                     }
2859                 }
2860
2861
2862                 B = [];
2863                 A = null;
2864                 C = 0;
2865             }
2866             else  {
2867                 this.unRegister(F);
2868             }
2869         };
2870
2871
2872         this.run = function() {
2873             for (var  i = 0, len = B.length; i < len; ++i) {
2874                 var  tween = B[i];
2875                 if (!tween || !tween.isAnimated()) {
2876                     continue;
2877                 }
2878
2879                 if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
2880                 {
2881                     tween.currentFrame += 1;
2882
2883                     if (tween.useSeconds) {
2884                         E(tween);
2885                     }
2886
2887                     tween._onTween.fire();
2888                 }
2889                 else  {
2890                     Roo.lib.AnimMgr.stop(tween, i);
2891                 }
2892             }
2893         };
2894
2895         var  D = function(F) {
2896             for (var  i = 0, len = B.length; i < len; ++i) {
2897                 if (B[i] == F) {
2898                     return  i;
2899                 }
2900             }
2901             return  -1;
2902         };
2903
2904
2905         var  E = function(F) {
2906             var  G = F.totalFrames;
2907             var  H = F.currentFrame;
2908             var  I = (F.currentFrame * F.duration * 1000 / F.totalFrames);
2909             var  J = (new  Date() - F.getStartTime());
2910             var  K = 0;
2911
2912             if (J < F.duration * 1000) {
2913                 K = Math.round((J / I - 1) * F.currentFrame);
2914             } else  {
2915                 K = G - (H + 1);
2916             }
2917             if (K > 0 && isFinite(K)) {
2918                 if (F.currentFrame + K >= G) {
2919                     K = G - (H + 1);
2920                 }
2921
2922
2923                 F.currentFrame += K;
2924             }
2925         };
2926     };
2927
2928
2929 Roo.lib.Bezier = new  function() {
2930
2931         this.getPosition = function(A, t) {
2932             var  n = A.length;
2933             var  B = [];
2934
2935             for (var  i = 0; i < n; ++i) {
2936                 B[i] = [A[i][0], A[i][1]];
2937             }
2938
2939             for (var  j = 1; j < n; ++j) {
2940                 for (i = 0; i < n - j; ++i) {
2941                     B[i][0] = (1 - t) * B[i][0] + t * B[parseInt(i + 1, 10)][0];
2942                     B[i][1] = (1 - t) * B[i][1] + t * B[parseInt(i + 1, 10)][1];
2943                 }
2944             }
2945
2946             return  [ B[0][0], B[0][1] ];
2947
2948         };
2949     };
2950
2951
2952 (function() {
2953
2954     Roo.lib.ColorAnim = function(el, D, E, F) {
2955         Roo.lib.ColorAnim.superclass.constructor.call(this, el, D, E, F);
2956     };
2957
2958     Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
2959
2960     var  A = Roo.lib.AnimBase.fly;
2961     var  Y = Roo.lib;
2962     var  B = Y.ColorAnim.superclass;
2963     var  C = Y.ColorAnim.prototype;
2964
2965     C.toString = function() {
2966         var  el = this.getEl();
2967         var  id = el.id || el.tagName;
2968         return  ("ColorAnim " + id);
2969     };
2970
2971     C.patterns.color = /color$/i;
2972     C.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
2973     C.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
2974     C.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
2975     C.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
2976
2977
2978     C.parseColor = function(s) {
2979         if (s.length == 3) {
2980             return  s;
2981         }
2982
2983         var  c = this.patterns.hex.exec(s);
2984         if (c && c.length == 4) {
2985             return  [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
2986         }
2987
2988
2989         c = this.patterns.rgb.exec(s);
2990         if (c && c.length == 4) {
2991             return  [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
2992         }
2993
2994
2995         c = this.patterns.hex3.exec(s);
2996         if (c && c.length == 4) {
2997             return  [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
2998         }
2999
3000         return  null;
3001     };
3002     
3003     C.getAttribute = function(D) {
3004         var  el = this.getEl();
3005         if (this.patterns.color.test(D)) {
3006             var  val = A(el).getStyle(D);
3007
3008             if (this.patterns.transparent.test(val)) {
3009                 var  parent = el.parentNode;
3010                 val = A(parent).getStyle(D);
3011
3012                 while (parent && this.patterns.transparent.test(val)) {
3013                     parent = parent.parentNode;
3014                     val = A(parent).getStyle(D);
3015                     if (parent.tagName.toUpperCase() == 'HTML') {
3016                         val = '#fff';
3017                     }
3018                 }
3019             }
3020         } else  {
3021             val = B.getAttribute.call(this, D);
3022         }
3023
3024         return  val;
3025     };
3026     C.getAttribute = function(D) {
3027         var  el = this.getEl();
3028         if (this.patterns.color.test(D)) {
3029             var  val = A(el).getStyle(D);
3030
3031             if (this.patterns.transparent.test(val)) {
3032                 var  parent = el.parentNode;
3033                 val = A(parent).getStyle(D);
3034
3035                 while (parent && this.patterns.transparent.test(val)) {
3036                     parent = parent.parentNode;
3037                     val = A(parent).getStyle(D);
3038                     if (parent.tagName.toUpperCase() == 'HTML') {
3039                         val = '#fff';
3040                     }
3041                 }
3042             }
3043         } else  {
3044             val = B.getAttribute.call(this, D);
3045         }
3046
3047         return  val;
3048     };
3049
3050     C.doMethod = function(D, E, F) {
3051         var  G;
3052
3053         if (this.patterns.color.test(D)) {
3054             G = [];
3055             for (var  i = 0, len = E.length; i < len; ++i) {
3056                 G[i] = B.doMethod.call(this, D, E[i], F[i]);
3057             }
3058
3059
3060             G = 'rgb(' + Math.floor(G[0]) + ',' + Math.floor(G[1]) + ',' + Math.floor(G[2]) + ')';
3061         }
3062         else  {
3063             G = B.doMethod.call(this, D, E, F);
3064         }
3065
3066         return  G;
3067     };
3068
3069     C.setRuntimeAttribute = function(D) {
3070         B.setRuntimeAttribute.call(this, D);
3071
3072         if (this.patterns.color.test(D)) {
3073             var  attributes = this.attributes;
3074             var  start = this.parseColor(this.runtimeAttributes[D].start);
3075             var  end = this.parseColor(this.runtimeAttributes[D].end);
3076
3077             if (typeof  attributes[D]['to'] === 'undefined' && typeof  attributes[D]['by'] !== 'undefined') {
3078                 end = this.parseColor(attributes[D].by);
3079
3080                 for (var  i = 0, len = start.length; i < len; ++i) {
3081                     end[i] = start[i] + end[i];
3082                 }
3083             }
3084
3085
3086             this.runtimeAttributes[D].start = start;
3087             this.runtimeAttributes[D].end = end;
3088         }
3089     };
3090 })();
3091
3092
3093
3094
3095 Roo.lib.Easing = {
3096
3097
3098     easeNone: function (t, b, c, d) {
3099         return  c * t / d + b;
3100     },
3101
3102
3103     easeIn: function (t, b, c, d) {
3104         return  c * (t /= d) * t + b;
3105     },
3106
3107
3108     easeOut: function (t, b, c, d) {
3109         return  -c * (t /= d) * (t - 2) + b;
3110     },
3111
3112
3113     easeBoth: function (t, b, c, d) {
3114         if ((t /= d / 2) < 1) {
3115             return  c / 2 * t * t + b;
3116         }
3117
3118         return  -c / 2 * ((--t) * (t - 2) - 1) + b;
3119     },
3120
3121
3122     easeInStrong: function (t, b, c, d) {
3123         return  c * (t /= d) * t * t * t + b;
3124     },
3125
3126
3127     easeOutStrong: function (t, b, c, d) {
3128         return  -c * ((t = t / d - 1) * t * t * t - 1) + b;
3129     },
3130
3131
3132     easeBothStrong: function (t, b, c, d) {
3133         if ((t /= d / 2) < 1) {
3134             return  c / 2 * t * t * t * t + b;
3135         }
3136
3137         return  -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3138     },
3139
3140
3141
3142     elasticIn: function (t, b, c, d, a, p) {
3143         if (t == 0) {
3144             return  b;
3145         }
3146         if ((t /= d) == 1) {
3147             return  b + c;
3148         }
3149         if (!p) {
3150             p = d * .3;
3151         }
3152
3153         if (!a || a < Math.abs(c)) {
3154             a = c;
3155             var  s = p / 4;
3156         }
3157         else  {
3158             var  s = p / (2 * Math.PI) * Math.asin(c / a);
3159         }
3160
3161         return  -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3162     },
3163
3164
3165     elasticOut: function (t, b, c, d, a, p) {
3166         if (t == 0) {
3167             return  b;
3168         }
3169         if ((t /= d) == 1) {
3170             return  b + c;
3171         }
3172         if (!p) {
3173             p = d * .3;
3174         }
3175
3176         if (!a || a < Math.abs(c)) {
3177             a = c;
3178             var  s = p / 4;
3179         }
3180         else  {
3181             var  s = p / (2 * Math.PI) * Math.asin(c / a);
3182         }
3183
3184         return  a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
3185     },
3186
3187
3188     elasticBoth: function (t, b, c, d, a, p) {
3189         if (t == 0) {
3190             return  b;
3191         }
3192
3193         if ((t /= d / 2) == 2) {
3194             return  b + c;
3195         }
3196
3197         if (!p) {
3198             p = d * (.3 * 1.5);
3199         }
3200
3201         if (!a || a < Math.abs(c)) {
3202             a = c;
3203             var  s = p / 4;
3204         }
3205         else  {
3206             var  s = p / (2 * Math.PI) * Math.asin(c / a);
3207         }
3208
3209         if (t < 1) {
3210             return  -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
3211                           Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
3212         }
3213         return  a * Math.pow(2, -10 * (t -= 1)) *
3214                Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
3215     },
3216
3217
3218
3219     backIn: function (t, b, c, d, s) {
3220         if (typeof  s == 'undefined') {
3221             s = 1.70158;
3222         }
3223         return  c * (t /= d) * t * ((s + 1) * t - s) + b;
3224     },
3225
3226
3227     backOut: function (t, b, c, d, s) {
3228         if (typeof  s == 'undefined') {
3229             s = 1.70158;
3230         }
3231         return  c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3232     },
3233
3234
3235     backBoth: function (t, b, c, d, s) {
3236         if (typeof  s == 'undefined') {
3237             s = 1.70158;
3238         }
3239
3240         if ((t /= d / 2 ) < 1) {
3241             return  c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
3242         }
3243         return  c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3244     },
3245
3246
3247     bounceIn: function (t, b, c, d) {
3248         return  c - Roo.lib.Easing.bounceOut(d - t, 0, c, d) + b;
3249     },
3250
3251
3252     bounceOut: function (t, b, c, d) {
3253         if ((t /= d) < (1 / 2.75)) {
3254             return  c * (7.5625 * t * t) + b;
3255         } else  if (t < (2 / 2.75)) {
3256             return  c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3257         } else  if (t < (2.5 / 2.75)) {
3258             return  c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3259         }
3260         return  c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3261     },
3262
3263
3264     bounceBoth: function (t, b, c, d) {
3265         if (t < d / 2) {
3266             return  Roo.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
3267         }
3268         return  Roo.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3269     }
3270 };
3271
3272
3273     (function() {
3274         Roo.lib.Motion = function(el, E, F, G) {
3275             if (el) {
3276                 Roo.lib.Motion.superclass.constructor.call(this, el, E, F, G);
3277             }
3278         };
3279
3280         Roo.extend(Roo.lib.Motion, Roo.lib.ColorAnim);
3281
3282
3283         var  Y = Roo.lib;
3284         var  A = Y.Motion.superclass;
3285         var  B = Y.Motion.prototype;
3286
3287         B.toString = function() {
3288             var  el = this.getEl();
3289             var  id = el.id || el.tagName;
3290             return  ("Motion " + id);
3291         };
3292
3293         B.patterns.points = /^points$/i;
3294
3295         B.setAttribute = function(E, F, G) {
3296             if (this.patterns.points.test(E)) {
3297                 G = G || 'px';
3298                 A.setAttribute.call(this, 'left', F[0], G);
3299                 A.setAttribute.call(this, 'top', F[1], G);
3300             } else  {
3301                 A.setAttribute.call(this, E, F, G);
3302             }
3303         };
3304
3305         B.getAttribute = function(E) {
3306             if (this.patterns.points.test(E)) {
3307                 var  val = [
3308                         A.getAttribute.call(this, 'left'),
3309                         A.getAttribute.call(this, 'top')
3310                         ];
3311             } else  {
3312                 val = A.getAttribute.call(this, E);
3313             }
3314
3315             return  val;
3316         };
3317
3318         B.doMethod = function(E, F, G) {
3319             var  H = null;
3320
3321             if (this.patterns.points.test(E)) {
3322                 var  t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
3323                 H = Y.Bezier.getPosition(this.runtimeAttributes[E], t);
3324             } else  {
3325                 H = A.doMethod.call(this, E, F, G);
3326             }
3327             return  H;
3328         };
3329
3330         B.setRuntimeAttribute = function(E) {
3331             if (this.patterns.points.test(E)) {
3332                 var  el = this.getEl();
3333                 var  attributes = this.attributes;
3334                 var  start;
3335                 var  control = attributes['points']['control'] || [];
3336                 var  end;
3337                 var  i, len;
3338
3339                 if (control.length > 0 && !(control[0]  instanceof  Array)) {
3340                     control = [control];
3341                 } else  {
3342                     var  tmp = [];
3343                     for (i = 0,len = control.length; i < len; ++i) {
3344                         tmp[i] = control[i];
3345                     }
3346
3347                     control = tmp;
3348                 }
3349
3350
3351                 Roo.fly(el).position();
3352
3353                 if (D(attributes['points']['from'])) {
3354                     Roo.lib.Dom.setXY(el, attributes['points']['from']);
3355                 }
3356                 else  {
3357                     Roo.lib.Dom.setXY(el, Roo.lib.Dom.getXY(el));
3358                 }
3359
3360
3361                 start = this.getAttribute('points');
3362
3363
3364                 if (D(attributes['points']['to'])) {
3365                     end = C.call(this, attributes['points']['to'], start);
3366
3367                     var  pageXY = Roo.lib.Dom.getXY(this.getEl());
3368                     for (i = 0,len = control.length; i < len; ++i) {
3369                         control[i] = C.call(this, control[i], start);
3370                     }
3371
3372
3373                 } else  if (D(attributes['points']['by'])) {
3374                     end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
3375
3376                     for (i = 0,len = control.length; i < len; ++i) {
3377                         control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
3378                     }
3379                 }
3380
3381
3382                 this.runtimeAttributes[E] = [start];
3383
3384                 if (control.length > 0) {
3385                     this.runtimeAttributes[E] = this.runtimeAttributes[E].concat(control);
3386                 }
3387
3388
3389                 this.runtimeAttributes[E][this.runtimeAttributes[E].length] = end;
3390             }
3391             else  {
3392                 A.setRuntimeAttribute.call(this, E);
3393             }
3394         };
3395
3396         var  C = function(E, F) {
3397             var  G = Roo.lib.Dom.getXY(this.getEl());
3398             E = [ E[0] - G[0] + F[0], E[1] - G[1] + F[1] ];
3399
3400             return  E;
3401         };
3402
3403         var  D = function(E) {
3404             return  (typeof  E !== 'undefined');
3405         };
3406     })();
3407
3408
3409
3410     (function() {
3411         Roo.lib.Scroll = function(el, C, D, E) {
3412             if (el) {
3413                 Roo.lib.Scroll.superclass.constructor.call(this, el, C, D, E);
3414             }
3415         };
3416
3417         Roo.extend(Roo.lib.Scroll, Roo.lib.ColorAnim);
3418
3419
3420         var  Y = Roo.lib;
3421         var  A = Y.Scroll.superclass;
3422         var  B = Y.Scroll.prototype;
3423
3424         B.toString = function() {
3425             var  el = this.getEl();
3426             var  id = el.id || el.tagName;
3427             return  ("Scroll " + id);
3428         };
3429
3430         B.doMethod = function(C, D, E) {
3431             var  F = null;
3432
3433             if (C == 'scroll') {
3434                 F = [
3435                         this.method(this.currentFrame, D[0], E[0] - D[0], this.totalFrames),
3436                         this.method(this.currentFrame, D[1], E[1] - D[1], this.totalFrames)
3437                         ];
3438
3439             } else  {
3440                 F = A.doMethod.call(this, C, D, E);
3441             }
3442             return  F;
3443         };
3444
3445         B.getAttribute = function(C) {
3446             var  D = null;
3447             var  el = this.getEl();
3448
3449             if (C == 'scroll') {
3450                 D = [ el.scrollLeft, el.scrollTop ];
3451             } else  {
3452                 D = A.getAttribute.call(this, C);
3453             }
3454
3455             return  D;
3456         };
3457
3458         B.setAttribute = function(C, D, E) {
3459             var  el = this.getEl();
3460
3461             if (C == 'scroll') {
3462                 el.scrollLeft = D[0];
3463                 el.scrollTop = D[1];
3464             } else  {
3465                 A.setAttribute.call(this, C, D, E);
3466             }
3467         };
3468     })();
3469
3470
3471
3472  
3473
3474
3475
3476 Roo.DomHelper = function(){
3477     var  A = null;
3478     var  B = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
3479     var  C = /^table|tbody|tr|td$/i;
3480     var  D = {};
3481     
3482     
3483
3484     var  E = function(o){
3485         if(typeof  o == 'string'){
3486             return  o;
3487         }
3488         var  b = "";
3489         if(!o.tag){
3490             o.tag = "div";
3491         }
3492
3493         b += "<" + o.tag;
3494         for(var  attr  in  o){
3495             if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof  o[attr] == "function") continue;
3496             if(attr == "style"){
3497                 var  s = o["style"];
3498                 if(typeof  s == "function"){
3499                     s = s.call();
3500                 }
3501                 if(typeof  s == "string"){
3502                     b += ' style="' + s + '"';
3503                 }else  if(typeof  s == "object"){
3504                     b += ' style="';
3505                     for(var  key  in  s){
3506                         if(typeof  s[key] != "function"){
3507                             b += key + ":" + s[key] + ";";
3508                         }
3509                     }
3510
3511                     b += '"';
3512                 }
3513             }else {
3514                 if(attr == "cls"){
3515                     b += ' class="' + o["cls"] + '"';
3516                 }else  if(attr == "htmlFor"){
3517                     b += ' for="' + o["htmlFor"] + '"';
3518                 }else {
3519                     b += " " + attr + '="' + o[attr] + '"';
3520                 }
3521             }
3522         }
3523         if(B.test(o.tag)){
3524             b += "/>";
3525         }else {
3526             b += ">";
3527             var  cn = o.children || o.cn;
3528             if(cn){
3529                 
3530                 if((cn  instanceof  Array) || (Roo.isSafari && typeof(cn.join) == "function")){
3531                     for(var  i = 0, len = cn.length; i < len; i++) {
3532                         b += E(cn[i], b);
3533                     }
3534                 }else {
3535                     b += E(cn, b);
3536                 }
3537             }
3538             if(o.html){
3539                 b += o.html;
3540             }
3541
3542             b += "</" + o.tag + ">";
3543         }
3544         return  b;
3545     };
3546
3547     
3548     
3549
3550     var  F = function(o, M){
3551          
3552         
3553         var  ns = false;
3554         if (o.ns && o.ns != 'html') {
3555                
3556             if (o.xmlns && typeof(D[o.ns]) == 'undefined') {
3557                 D[o.ns] = o.xmlns;
3558                 ns = o.xmlns;
3559             }
3560             if (typeof(D[o.ns]) == 'undefined') {
3561                 console.log("Trying to create namespace element " + o.ns + ", however no xmlns was sent to builder previously");
3562             }
3563
3564             ns = D[o.ns];
3565         }
3566         
3567         
3568         if (typeof(o) == 'string') {
3569             return  M.appendChild(document.createTextNode(o));
3570         }
3571
3572         o.tag = o.tag || div;
3573         if (o.ns && Roo.isIE) {
3574             ns = false;
3575             o.tag = o.ns + ':' + o.tag;
3576             
3577         }
3578         var  el = ns ? document.createElementNS( ns, o.tag||'div') :  document.createElement(o.tag||'div');
3579         var  N = el.setAttribute ? true : false; 
3580         for(var  attr  in  o){
3581             
3582             if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" || 
3583                     attr == "style" || typeof  o[attr] == "function") continue;
3584                     
3585             if(attr=="cls" && Roo.isIE){
3586                 el.className = o["cls"];
3587             }else {
3588                 if(N) el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);
3589                 else  el[attr] = o[attr];
3590             }
3591         }
3592
3593         Roo.DomHelper.applyStyles(el, o.style);
3594         var  cn = o.children || o.cn;
3595         if(cn){
3596             
3597              if((cn  instanceof  Array) || (Roo.isSafari && typeof(cn.join) == "function")){
3598                 for(var  i = 0, len = cn.length; i < len; i++) {
3599                     F(cn[i], el);
3600                 }
3601             }else {
3602                 F(cn, el);
3603             }
3604         }
3605         if(o.html){
3606             el.innerHTML = o.html;
3607         }
3608         if(M){
3609            M.appendChild(el);
3610         }
3611         return  el;
3612     };
3613
3614     var  G = function(M, s, h, e){
3615         A.innerHTML = [s, h, e].join('');
3616         var  i = -1, el = A;
3617         while(++i < M){
3618             el = el.firstChild;
3619         }
3620         return  el;
3621     };
3622
3623     
3624     var  ts = '<table>',
3625         te = '</table>',
3626         H = ts+'<tbody>',
3627         I = '</tbody>'+te,
3628         J = H + '<tr>',
3629         K = '</tr>'+I;
3630
3631     
3632
3633     var  L = function(M, N, el, O){
3634         if(!A){
3635             A = document.createElement('div');
3636         }
3637         var  P;
3638         var  Q = null;
3639         if(M == 'td'){
3640             if(N == 'afterbegin' || N == 'beforeend'){ 
3641                 return;
3642             }
3643             if(N == 'beforebegin'){
3644                 Q = el;
3645                 el = el.parentNode;
3646             } else {
3647                 Q = el.nextSibling;
3648                 el = el.parentNode;
3649             }
3650
3651             P = G(4, J, O, K);
3652         }
3653         else  if(M == 'tr'){
3654             if(N == 'beforebegin'){
3655                 Q = el;
3656                 el = el.parentNode;
3657                 P = G(3, H, O, I);
3658             } else  if(N == 'afterend'){
3659                 Q = el.nextSibling;
3660                 el = el.parentNode;
3661                 P = G(3, H, O, I);
3662             } else { 
3663                 if(N == 'afterbegin'){
3664                     Q = el.firstChild;
3665                 }
3666
3667                 P = G(4, J, O, K);
3668             }
3669         } else  if(M == 'tbody'){
3670             if(N == 'beforebegin'){
3671                 Q = el;
3672                 el = el.parentNode;
3673                 P = G(2, ts, O, te);
3674             } else  if(N == 'afterend'){
3675                 Q = el.nextSibling;
3676                 el = el.parentNode;
3677                 P = G(2, ts, O, te);
3678             } else {
3679                 if(N == 'afterbegin'){
3680                     Q = el.firstChild;
3681                 }
3682
3683                 P = G(3, H, O, I);
3684             }
3685         } else { 
3686             if(N == 'beforebegin' || N == 'afterend'){ 
3687                 return;
3688             }
3689             if(N == 'afterbegin'){
3690                 Q = el.firstChild;
3691             }
3692
3693             P = G(2, ts, O, te);
3694         }
3695
3696         el.insertBefore(P, Q);
3697         return  P;
3698     };
3699
3700     return  {
3701     
3702
3703     useDom : false,
3704
3705     
3706
3707     markup : function(o){
3708         return  E(o);
3709     },
3710
3711     
3712
3713     applyStyles : function(el, c){
3714         if(c){
3715            el = Roo.fly(el);
3716            if(typeof  c == "string"){
3717                var  re = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
3718                var  matches;
3719                while ((matches = re.exec(c)) != null){
3720                    el.setStyle(matches[1], matches[2]);
3721                }
3722            }else  if (typeof  c == "object"){
3723                for (var  style  in  c){
3724                   el.setStyle(style, c[style]);
3725                }
3726            }else  if (typeof  c == "function"){
3727                 Roo.DomHelper.applyStyles(el, c.call());
3728            }
3729         }
3730     },
3731
3732     
3733
3734     insertHtml : function(d, el, e){
3735         d = d.toLowerCase();
3736         if(el.insertAdjacentHTML){
3737             if(C.test(el.tagName)){
3738                 var  rs;
3739                 if(rs = L(el.tagName.toLowerCase(), d, el, e)){
3740                     return  rs;
3741                 }
3742             }
3743             switch(d){
3744                 case  "beforebegin":
3745                     el.insertAdjacentHTML('BeforeBegin', e);
3746                     return  el.previousSibling;
3747                 case  "afterbegin":
3748                     el.insertAdjacentHTML('AfterBegin', e);
3749                     return  el.firstChild;
3750                 case  "beforeend":
3751                     el.insertAdjacentHTML('BeforeEnd', e);
3752                     return  el.lastChild;
3753                 case  "afterend":
3754                     el.insertAdjacentHTML('AfterEnd', e);
3755                     return  el.nextSibling;
3756             }
3757             throw  'Illegal insertion point -> "' + d + '"';
3758         }
3759         var  f = el.ownerDocument.createRange();
3760         var  g;
3761         switch(d){
3762              case  "beforebegin":
3763                 f.setStartBefore(el);
3764                 g = f.createContextualFragment(e);
3765                 el.parentNode.insertBefore(g, el);
3766                 return  el.previousSibling;
3767              case  "afterbegin":
3768                 if(el.firstChild){
3769                     f.setStartBefore(el.firstChild);
3770                     g = f.createContextualFragment(e);
3771                     el.insertBefore(g, el.firstChild);
3772                     return  el.firstChild;
3773                 }else {
3774                     el.innerHTML = e;
3775                     return  el.firstChild;
3776                 }
3777             case  "beforeend":
3778                 if(el.lastChild){
3779                     f.setStartAfter(el.lastChild);
3780                     g = f.createContextualFragment(e);
3781                     el.appendChild(g);
3782                     return  el.lastChild;
3783                 }else {
3784                     el.innerHTML = e;
3785                     return  el.lastChild;
3786                 }
3787             case  "afterend":
3788                 f.setStartAfter(el);
3789                 g = f.createContextualFragment(e);
3790                 el.parentNode.insertBefore(g, el.nextSibling);
3791                 return  el.nextSibling;
3792             }
3793             throw  'Illegal insertion point -> "' + d + '"';
3794     },
3795
3796     
3797
3798     insertBefore : function(el, o, h){
3799         return  this.doInsert(el, o, h, "beforeBegin");
3800     },
3801
3802     
3803
3804     insertAfter : function(el, o, j){
3805         return  this.doInsert(el, o, j, "afterEnd", "nextSibling");
3806     },
3807
3808     
3809
3810     insertFirst : function(el, o, k){
3811         return  this.doInsert(el, o, k, "afterBegin");
3812     },
3813
3814     
3815     doInsert : function(el, o, l, m, n){
3816         el = Roo.getDom(el);
3817         var  p;
3818         if(this.useDom || o.ns){
3819             p = F(o, null);
3820             el.parentNode.insertBefore(p, n ? el[n] : el);
3821         }else {
3822             var  e = E(o);
3823             p = this.insertHtml(m, el, e);
3824         }
3825         return  l ? Roo.get(p, true) : p;
3826     },
3827
3828     
3829
3830     append : function(el, o, q){
3831         el = Roo.getDom(el);
3832         var  r;
3833         if(this.useDom || o.ns){
3834             r = F(o, null);
3835             el.appendChild(r);
3836         }else {
3837             var  e = E(o);
3838             r = this.insertHtml("beforeEnd", el, e);
3839         }
3840         return  q ? Roo.get(r, true) : r;
3841     },
3842
3843     
3844
3845     overwrite : function(el, o, t){
3846         el = Roo.getDom(el);
3847         if (o.ns) {
3848           
3849             while (el.childNodes.length) {
3850                 el.removeChild(el.firstChild);
3851             }
3852
3853             F(o, el);
3854         } else  {
3855             el.innerHTML = E(o);   
3856         }
3857         
3858         return  t ? Roo.get(el.firstChild, true) : el.firstChild;
3859     },
3860
3861     
3862
3863     createTemplate : function(o){
3864         var  u = E(o);
3865         return  new  Roo.Template(u);
3866     }
3867     };
3868 }();
3869
3870
3871
3872  
3873
3874
3875 Roo.Template = function(A){
3876     
3877     if(A  instanceof  Array){
3878         A = A.join("");
3879     }else  if(arguments.length > 1){
3880         A = Array.prototype.join.call(arguments, "");
3881     }
3882     
3883     
3884     if (typeof(A) == 'object') {
3885         Roo.apply(this,A)
3886     } else  {
3887         
3888         this.html = A;
3889     }
3890     
3891     
3892 };
3893 Roo.Template.prototype = {
3894     
3895     
3896
3897     html : '',
3898     
3899
3900     applyTemplate : function(values){
3901         try {
3902             
3903             if(this.compiled){
3904                 return  this.compiled(values);
3905             }
3906             var  useF = this.disableFormats !== true;
3907             var  fm = Roo.util.Format, tpl = this;
3908             var  fn = function(m, E, F, G){
3909                 if(F && useF){
3910                     if(F.substr(0, 5) == "this."){
3911                         return  tpl.call(F.substr(5), values[E], values);
3912                     }else {
3913                         if(G){
3914                             
3915                             
3916                             
3917                             var  re = /^\s*['"](.*)["']\s*$/;
3918                             G = G.split(',');
3919                             for(var  i = 0, len = G.length; i < len; i++){
3920                                 G[i] = G[i].replace(re, "$1");
3921                             }
3922
3923                             G = [values[E]].concat(G);
3924                         }else {
3925                             G = [values[E]];
3926                         }
3927                         return  fm[F].apply(fm, G);
3928                     }
3929                 }else {
3930                     return  values[E] !== undefined ? values[E] : "";
3931                 }
3932             };
3933             return  this.html.replace(this.re, fn);
3934         } catch (e) {
3935             Roo.log(e);
3936             throw  e;
3937         }
3938          
3939     },
3940     
3941     
3942
3943     set : function(B, C){
3944         this.html = B;
3945         this.compiled = null;
3946         if(C){
3947             this.compile();
3948         }
3949         return  this;
3950     },
3951     
3952     
3953
3954     disableFormats : false,
3955     
3956     
3957
3958     re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
3959     
3960     
3961
3962     compile : function(){
3963         var  fm = Roo.util.Format;
3964         var  D = this.disableFormats !== true;
3965         var  E = Roo.isGecko ? "+" : ",";
3966         var  fn = function(m, G, H, I){
3967             if(H && D){
3968                 I = I ? ',' + I : "";
3969                 if(H.substr(0, 5) != "this."){
3970                     H = "fm." + H + '(';
3971                 }else {
3972                     H = 'this.call("'+ H.substr(5) + '", ';
3973                     I = ", values";
3974                 }
3975             }else {
3976                 I= ''; H = "(values['" + G + "'] == undefined ? '' : ";
3977             }
3978             return  "'"+ E + H + "values['" + G + "']" + I + ")"+E+"'";
3979         };
3980         var  F;
3981         
3982         if(Roo.isGecko){
3983             F = "this.compiled = function(values){ return '" +
3984                    this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
3985                     "';};";
3986         }else {
3987             F = ["this.compiled = function(values){ return ['"];
3988             F.push(this.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
3989             F.push("'].join('');};");
3990             F = F.join('');
3991         }
3992         
3993
3994         eval(F);
3995         return  this;
3996     },
3997     
3998     
3999     call : function(G, H, I){
4000         return  this[G](H, I);
4001     },
4002     
4003     
4004
4005     insertFirst: function(el, J, K){
4006         return  this.doInsert('afterBegin', el, J, K);
4007     },
4008
4009     
4010
4011     insertBefore: function(el, L, M){
4012         return  this.doInsert('beforeBegin', el, L, M);
4013     },
4014
4015     
4016
4017     insertAfter : function(el, N, O){
4018         return  this.doInsert('afterEnd', el, N, O);
4019     },
4020     
4021     
4022
4023     append : function(el, P, Q){
4024         return  this.doInsert('beforeEnd', el, P, Q);
4025     },
4026
4027     doInsert : function(R, el, S, T){
4028         el = Roo.getDom(el);
4029         var  U = Roo.DomHelper.insertHtml(R, el, this.applyTemplate(S));
4030         return  T ? Roo.get(U, true) : U;
4031     },
4032
4033     
4034
4035     overwrite : function(el, V, W){
4036         el = Roo.getDom(el);
4037         el.innerHTML = this.applyTemplate(V);
4038         return  W ? Roo.get(el.firstChild, true) : el.firstChild;
4039     }
4040 };
4041
4042
4043 Roo.Template.prototype.apply = Roo.Template.prototype.applyTemplate;
4044
4045
4046 Roo.DomHelper.Template = Roo.Template;
4047
4048
4049
4050 Roo.Template.from = function(el){
4051     el = Roo.getDom(el);
4052     return  new  Roo.Template(el.value || el.innerHTML);
4053 };
4054
4055
4056  
4057
4058
4059
4060
4061
4062 Roo.DomQuery = function(){
4063     var  A = {}, simpleCache = {}, valueCache = {};
4064     var  B = /\S/;
4065     var  C = /^\s+|\s+$/g;
4066     var  D = /\{(\d+)\}/g;
4067     var  E = /^(\s?[\/>+~]\s?|\s|$)/;
4068     var  F = /^(#)?([\w-\*]+)/;
4069     var  G = /(\d*)n\+?(\d*)/, H = /\D/;
4070
4071     function  I(p, T){
4072         var  i = 0;
4073         var  n = p.firstChild;
4074         while(n){
4075             if(n.nodeType == 1){
4076                if(++i == T){
4077                    return  n;
4078                }
4079             }
4080
4081             n = n.nextSibling;
4082         }
4083         return  null;
4084     };
4085
4086     function  J(n){
4087         while((n = n.nextSibling) && n.nodeType != 1);
4088         return  n;
4089     };
4090
4091     function  K(n){
4092         while((n = n.previousSibling) && n.nodeType != 1);
4093         return  n;
4094     };
4095
4096     function  L(d){
4097         var  n = d.firstChild, ni = -1;
4098             while(n){
4099                 var  nx = n.nextSibling;
4100                 if(n.nodeType == 3 && !B.test(n.nodeValue)){
4101                     d.removeChild(n);
4102                 }else {
4103                     n.nodeIndex = ++ni;
4104                 }
4105
4106                 n = nx;
4107             }
4108             return  this;
4109         };
4110
4111     function  byClassName(c, a, v){
4112         if(!v){
4113             return  c;
4114         }
4115         var  r = [], ri = -1, cn;
4116         for(var  i = 0, ci; ci = c[i]; i++){
4117             if((' '+ci.className+' ').indexOf(v) != -1){
4118                 r[++ri] = ci;
4119             }
4120         }
4121         return  r;
4122     };
4123
4124     function  attrValue(n, T){
4125         if(!n.tagName && typeof  n.length != "undefined"){
4126             n = n[0];
4127         }
4128         if(!n){
4129             return  null;
4130         }
4131         if(T == "for"){
4132             return  n.htmlFor;
4133         }
4134         if(T == "class" || T == "className"){
4135             return  n.className;
4136         }
4137         return  n.getAttribute(T) || n[T];
4138
4139     };
4140
4141     function  getNodes(ns, T, U){
4142         var  V = [], ri = -1, cs;
4143         if(!ns){
4144             return  V;
4145         }
4146
4147         U = U || "*";
4148         if(typeof  ns.getElementsByTagName != "undefined"){
4149             ns = [ns];
4150         }
4151         if(!T){
4152             for(var  i = 0, ni; ni = ns[i]; i++){
4153                 cs = ni.getElementsByTagName(U);
4154                 for(var  j = 0, ci; ci = cs[j]; j++){
4155                     V[++ri] = ci;
4156                 }
4157             }
4158         }else  if(T == "/" || T == ">"){
4159             var  utag = U.toUpperCase();
4160             for(var  i = 0, ni, cn; ni = ns[i]; i++){
4161                 cn = ni.children || ni.childNodes;
4162                 for(var  j = 0, cj; cj = cn[j]; j++){
4163                     if(cj.nodeName == utag || cj.nodeName == U  || U == '*'){
4164                         V[++ri] = cj;
4165                     }
4166                 }
4167             }
4168         }else  if(T == "+"){
4169             var  utag = U.toUpperCase();
4170             for(var  i = 0, n; n = ns[i]; i++){
4171                 while((n = n.nextSibling) && n.nodeType != 1);
4172                 if(n && (n.nodeName == utag || n.nodeName == U || U == '*')){
4173                     V[++ri] = n;
4174                 }
4175             }
4176         }else  if(T == "~"){
4177             for(var  i = 0, n; n = ns[i]; i++){
4178                 while((n = n.nextSibling) && (n.nodeType != 1 || (U == '*' || n.tagName.toLowerCase()!=U)));
4179                 if(n){
4180                     V[++ri] = n;
4181                 }
4182             }
4183         }
4184         return  V;
4185     };
4186
4187     function  M(a, b){
4188         if(b.slice){
4189             return  a.concat(b);
4190         }
4191         for(var  i = 0, l = b.length; i < l; i++){
4192             a[a.length] = b[i];
4193         }
4194         return  a;
4195     }
4196
4197     function  byTag(cs, T){
4198         if(cs.tagName || cs == document){
4199             cs = [cs];
4200         }
4201         if(!T){
4202             return  cs;
4203         }
4204         var  r = [], ri = -1;
4205         T = T.toLowerCase();
4206         for(var  i = 0, ci; ci = cs[i]; i++){
4207             if(ci.nodeType == 1 && ci.tagName.toLowerCase()==T){
4208                 r[++ri] = ci;
4209             }
4210         }
4211         return  r;
4212     };
4213
4214     function  N(cs, T, id){
4215         if(cs.tagName || cs == document){
4216             cs = [cs];
4217         }
4218         if(!id){
4219             return  cs;
4220         }
4221         var  r = [], ri = -1;
4222         for(var  i = 0,ci; ci = cs[i]; i++){
4223             if(ci && ci.id == id){
4224                 r[++ri] = ci;
4225                 return  r;
4226             }
4227         }
4228         return  r;
4229     };
4230
4231     function  byAttribute(cs, T, U, op, V){
4232         var  r = [], ri = -1, st = V=="{";
4233         var  f = Roo.DomQuery.operators[op];
4234         for(var  i = 0, ci; ci = cs[i]; i++){
4235             var  a;
4236             if(st){
4237                 a = Roo.DomQuery.getStyle(ci, T);
4238             }
4239             else  if(T == "class" || T == "className"){
4240                 a = ci.className;
4241             }else  if(T == "for"){
4242                 a = ci.htmlFor;
4243             }else  if(T == "href"){
4244                 a = ci.getAttribute("href", 2);
4245             }else {
4246                 a = ci.getAttribute(T);
4247             }
4248             if((f && f(a, U)) || (!f && a)){
4249                 r[++ri] = ci;
4250             }
4251         }
4252         return  r;
4253     };
4254
4255     function  byPseudo(cs, T, U){
4256         return  Roo.DomQuery.pseudos[T](cs, U);
4257     };
4258
4259     
4260     
4261     
4262     var  O = window.ActiveXObject ? true : false;
4263
4264     
4265     
4266     
4267     
4268
4269     var  batch = 30803; 
4270
4271     var  P = 30803;
4272
4273     function  Q(cs){
4274         var  d = ++P;
4275         cs[0].setAttribute("_nodup", d);
4276         var  r = [cs[0]];
4277         for(var  i = 1, len = cs.length; i < len; i++){
4278             var  c = cs[i];
4279             if(!c.getAttribute("_nodup") != d){
4280                 c.setAttribute("_nodup", d);
4281                 r[r.length] = c;
4282             }
4283         }
4284         for(var  i = 0, len = cs.length; i < len; i++){
4285             cs[i].removeAttribute("_nodup");
4286         }
4287         return  r;
4288     }
4289
4290     function  nodup(cs){
4291         if(!cs){
4292             return  [];
4293         }
4294         var  T = cs.length, c, i, r = cs, cj, ri = -1;
4295         if(!T || typeof  cs.nodeType != "undefined" || T == 1){
4296             return  cs;
4297         }
4298         if(O && typeof  cs[0].selectSingleNode != "undefined"){
4299             return  Q(cs);
4300         }
4301         var  d = ++P;
4302         cs[0]._nodup = d;
4303         for(i = 1; c = cs[i]; i++){
4304             if(c._nodup != d){
4305                 c._nodup = d;
4306             }else {
4307                 r = [];
4308                 for(var  j = 0; j < i; j++){
4309                     r[++ri] = cs[j];
4310                 }
4311                 for(j = i+1; cj = cs[j]; j++){
4312                     if(cj._nodup != d){
4313                         cj._nodup = d;
4314                         r[++ri] = cj;
4315                     }
4316                 }
4317                 return  r;
4318             }
4319         }
4320         return  r;
4321     }
4322
4323     function  R(c1, c2){
4324         var  d = ++P;
4325         for(var  i = 0, len = c1.length; i < len; i++){
4326             c1[i].setAttribute("_qdiff", d);
4327         }
4328         var  r = [];
4329         for(var  i = 0, len = c2.length; i < len; i++){
4330             if(c2[i].getAttribute("_qdiff") != d){
4331                 r[r.length] = c2[i];
4332             }
4333         }
4334         for(var  i = 0, len = c1.length; i < len; i++){
4335            c1[i].removeAttribute("_qdiff");
4336         }
4337         return  r;
4338     }
4339
4340     function  S(c1, c2){
4341         var  T = c1.length;
4342         if(!T){
4343             return  c2;
4344         }
4345         if(O && c1[0].selectSingleNode){
4346             return  R(c1, c2);
4347         }
4348         var  d = ++P;
4349         for(var  i = 0; i < T; i++){
4350             c1[i]._qdiff = d;
4351         }
4352         var  r = [];
4353         for(var  i = 0, len = c2.length; i < len; i++){
4354             if(c2[i]._qdiff != d){
4355                 r[r.length] = c2[i];
4356             }
4357         }
4358         return  r;
4359     }
4360
4361     function  quickId(ns, T, U, id){
4362         if(ns == U){
4363            var  d = U.ownerDocument || U;
4364            return  d.getElementById(id);
4365         }
4366
4367         ns = getNodes(ns, T, "*");
4368         return  N(ns, null, id);
4369     }
4370
4371     return  {
4372         getStyle : function(el, AA){
4373             return  Roo.fly(el).getStyle(AA);
4374         },
4375         
4376
4377         compile : function(AB, AC){
4378             AC = AC || "select";
4379             
4380             var  fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"];
4381             var  q = AB, mode, lq;
4382             var  tk = Roo.DomQuery.matchers;
4383             var  AD = tk.length;
4384             var  mm;
4385
4386             
4387             var  AE = q.match(E);
4388             if(AE && AE[1]){
4389                 fn[fn.length] = 'mode="'+AE[1].replace(C, "")+'";';
4390                 q = q.replace(AE[1], "");
4391             }
4392             
4393             while(AB.substr(0, 1)=="/"){
4394                 AB = AB.substr(1);
4395             }
4396
4397             while(q && lq != q){
4398                 lq = q;
4399                 var  tm = q.match(F);
4400                 if(AC == "select"){
4401                     if(tm){
4402                         if(tm[1] == "#"){
4403                             fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
4404                         }else {
4405                             fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
4406                         }
4407
4408                         q = q.replace(tm[0], "");
4409                     }else  if(q.substr(0, 1) != '@'){
4410                         fn[fn.length] = 'n = getNodes(n, mode, "*");';
4411                     }
4412                 }else {
4413                     if(tm){
4414                         if(tm[1] == "#"){
4415                             fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
4416                         }else {
4417                             fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
4418                         }
4419
4420                         q = q.replace(tm[0], "");
4421                     }
4422                 }
4423                 while(!(mm = q.match(E))){
4424                     var  matched = false;
4425                     for(var  j = 0; j < AD; j++){
4426                         var  t = tk[j];
4427                         var  m = q.match(t.re);
4428                         if(m){
4429                             fn[fn.length] = t.select.replace(D, function(x, i){
4430                                                     return  m[i];
4431                                                 });
4432                             q = q.replace(m[0], "");
4433                             matched = true;
4434                             break;
4435                         }
4436                     }
4437                     
4438                     if(!matched){
4439                         throw  'Error parsing selector, parsing failed at "' + q + '"';
4440                     }
4441                 }
4442                 if(mm[1]){
4443                     fn[fn.length] = 'mode="'+mm[1].replace(C, "")+'";';
4444                     q = q.replace(mm[1], "");
4445                 }
4446             }
4447
4448             fn[fn.length] = "return nodup(n);\n}";
4449             
4450              
4451  
4452             eval(fn.join(""));
4453             return  f;
4454         },
4455
4456         
4457
4458         select : function(AF, AG, AH){
4459             if(!AG || AG == document){
4460                 AG = document;
4461             }
4462             if(typeof  AG == "string"){
4463                 AG = document.getElementById(AG);
4464             }
4465             var  AI = AF.split(",");
4466             var  AJ = [];
4467             for(var  i = 0, len = AI.length; i < len; i++){
4468                 var  p = AI[i].replace(C, "");
4469                 if(!A[p]){
4470                     A[p] = Roo.DomQuery.compile(p);
4471                     if(!A[p]){
4472                         throw  p + " is not a valid selector";
4473                     }
4474                 }
4475                 var  z = A[p](AG);
4476                 if(z && z != document){
4477                     AJ = AJ.concat(z);
4478                 }
4479             }
4480             if(AI.length > 1){
4481                 return  nodup(AJ);
4482             }
4483             return  AJ;
4484         },
4485
4486         
4487
4488         selectNode : function(AK, AL){
4489             return  Roo.DomQuery.select(AK, AL)[0];
4490         },
4491
4492         
4493
4494         selectValue : function(AM, AN, AO){
4495             AM = AM.replace(C, "");
4496             if(!valueCache[AM]){
4497                 valueCache[AM] = Roo.DomQuery.compile(AM, "select");
4498             }
4499             var  n = valueCache[AM](AN);
4500             n = n[0] ? n[0] : n;
4501             var  v = (n && n.firstChild ? n.firstChild.nodeValue : null);
4502             return  ((v === null||v === undefined||v==='') ? AO : v);
4503         },
4504
4505         
4506
4507         selectNumber : function(AP, AQ, AR){
4508             var  v = Roo.DomQuery.selectValue(AP, AQ, AR || 0);
4509             return  parseFloat(v);
4510         },
4511
4512         
4513
4514         is : function(el, ss){
4515             if(typeof  el == "string"){
4516                 el = document.getElementById(el);
4517             }
4518             var  AS = (el  instanceof  Array);
4519             var  AT = Roo.DomQuery.filter(AS ? el : [el], ss);
4520             return  AS ? (AT.length == el.length) : (AT.length > 0);
4521         },
4522
4523         
4524
4525         filter : function(AU, ss, AV){
4526             ss = ss.replace(C, "");
4527             if(!simpleCache[ss]){
4528                 simpleCache[ss] = Roo.DomQuery.compile(ss, "simple");
4529             }
4530             var  AW = simpleCache[ss](AU);
4531             return  AV ? S(AW, AU) : AW;
4532         },
4533
4534         
4535
4536         matchers : [{
4537                 re: /^\.([\w-]+)/,
4538                 select: 'n = byClassName(n, null, " {1} ");'
4539             }, {
4540                 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
4541                 select: 'n = byPseudo(n, "{1}", "{2}");'
4542             },{
4543                 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
4544                 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
4545             }, {
4546                 re: /^#([\w-]+)/,
4547                 select: 'n = byId(n, null, "{1}");'
4548             },{
4549                 re: /^@([\w-]+)/,
4550                 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
4551             }
4552         ],
4553
4554         
4555
4556         operators : {
4557             "=" : function(a, v){
4558                 return  a == v;
4559             },
4560             "!=" : function(a, v){
4561                 return  a != v;
4562             },
4563             "^=" : function(a, v){
4564                 return  a && a.substr(0, v.length) == v;
4565             },
4566             "$=" : function(a, v){
4567                 return  a && a.substr(a.length-v.length) == v;
4568             },
4569             "*=" : function(a, v){
4570                 return  a && a.indexOf(v) !== -1;
4571             },
4572             "%=" : function(a, v){
4573                 return  (a % v) == 0;
4574             },
4575             "|=" : function(a, v){
4576                 return  a && (a == v || a.substr(0, v.length+1) == v+'-');
4577             },
4578             "~=" : function(a, v){
4579                 return  a && (' '+a+' ').indexOf(' '+v+' ') != -1;
4580             }
4581         },
4582
4583         
4584
4585         pseudos : {
4586             "first-child" : function(c){
4587                 var  r = [], ri = -1, n;
4588                 for(var  i = 0, ci; ci = n = c[i]; i++){
4589                     while((n = n.previousSibling) && n.nodeType != 1);
4590                     if(!n){
4591                         r[++ri] = ci;
4592                     }
4593                 }
4594                 return  r;
4595             },
4596
4597             "last-child" : function(c){
4598                 var  r = [], ri = -1, n;
4599                 for(var  i = 0, ci; ci = n = c[i]; i++){
4600                     while((n = n.nextSibling) && n.nodeType != 1);
4601                     if(!n){
4602                         r[++ri] = ci;
4603                     }
4604                 }
4605                 return  r;
4606             },
4607
4608             "nth-child" : function(c, a) {
4609                 var  r = [], ri = -1;
4610                 var  m = G.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !H.test(a) && "n+" + a || a);
4611                 var  f = (m[1] || 1) - 0, l = m[2] - 0;
4612                 for(var  i = 0, n; n = c[i]; i++){
4613                     var  pn = n.parentNode;
4614                     if (batch != pn._batch) {
4615                         var  j = 0;
4616                         for(var  cn = pn.firstChild; cn; cn = cn.nextSibling){
4617                             if(cn.nodeType == 1){
4618                                cn.nodeIndex = ++j;
4619                             }
4620                         }
4621
4622                         pn._batch = batch;
4623                     }
4624                     if (f == 1) {
4625                         if (l == 0 || n.nodeIndex == l){
4626                             r[++ri] = n;
4627                         }
4628                     } else  if ((n.nodeIndex + l) % f == 0){
4629                         r[++ri] = n;
4630                     }
4631                 }
4632
4633                 return  r;
4634             },
4635
4636             "only-child" : function(c){
4637                 var  r = [], ri = -1;;
4638                 for(var  i = 0, ci; ci = c[i]; i++){
4639                     if(!K(ci) && !J(ci)){
4640                         r[++ri] = ci;
4641                     }
4642                 }
4643                 return  r;
4644             },
4645
4646             "empty" : function(c){
4647                 var  r = [], ri = -1;
4648                 for(var  i = 0, ci; ci = c[i]; i++){
4649                     var  cns = ci.childNodes, j = 0, cn, empty = true;
4650                     while(cn = cns[j]){
4651                         ++j;
4652                         if(cn.nodeType == 1 || cn.nodeType == 3){
4653                             empty = false;
4654                             break;
4655                         }
4656                     }
4657                     if(empty){
4658                         r[++ri] = ci;
4659                     }
4660                 }
4661                 return  r;
4662             },
4663
4664             "contains" : function(c, v){
4665                 var  r = [], ri = -1;
4666                 for(var  i = 0, ci; ci = c[i]; i++){
4667                     if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
4668                         r[++ri] = ci;
4669                     }
4670                 }
4671                 return  r;
4672             },
4673
4674             "nodeValue" : function(c, v){
4675                 var  r = [], ri = -1;
4676                 for(var  i = 0, ci; ci = c[i]; i++){
4677                     if(ci.firstChild && ci.firstChild.nodeValue == v){
4678                         r[++ri] = ci;
4679                     }
4680                 }
4681                 return  r;
4682             },
4683
4684             "checked" : function(c){
4685                 var  r = [], ri = -1;
4686                 for(var  i = 0, ci; ci = c[i]; i++){
4687                     if(ci.checked == true){
4688                         r[++ri] = ci;
4689                     }
4690                 }
4691                 return  r;
4692             },
4693
4694             "not" : function(c, ss){
4695                 return  Roo.DomQuery.filter(c, ss, true);
4696             },
4697
4698             "odd" : function(c){
4699                 return  this["nth-child"](c, "odd");
4700             },
4701
4702             "even" : function(c){
4703                 return  this["nth-child"](c, "even");
4704             },
4705
4706             "nth" : function(c, a){
4707                 return  c[a-1] || [];
4708             },
4709
4710             "first" : function(c){
4711                 return  c[0] || [];
4712             },
4713
4714             "last" : function(c){
4715                 return  c[c.length-1] || [];
4716             },
4717
4718             "has" : function(c, ss){
4719                 var  s = Roo.DomQuery.select;
4720                 var  r = [], ri = -1;
4721                 for(var  i = 0, ci; ci = c[i]; i++){
4722                     if(s(ss, ci).length > 0){
4723                         r[++ri] = ci;
4724                     }
4725                 }
4726                 return  r;
4727             },
4728
4729             "next" : function(c, ss){
4730                 var  is = Roo.DomQuery.is;
4731                 var  r = [], ri = -1;
4732                 for(var  i = 0, ci; ci = c[i]; i++){
4733                     var  n = J(ci);
4734                     if(n && is(n, ss)){
4735                         r[++ri] = ci;
4736                     }
4737                 }
4738                 return  r;
4739             },
4740
4741             "prev" : function(c, ss){
4742                 var  is = Roo.DomQuery.is;
4743                 var  r = [], ri = -1;
4744                 for(var  i = 0, ci; ci = c[i]; i++){
4745                     var  n = K(ci);
4746                     if(n && is(n, ss)){
4747                         r[++ri] = ci;
4748                     }
4749                 }
4750                 return  r;
4751             }
4752         }
4753     };
4754 }();
4755
4756
4757
4758 Roo.query = Roo.DomQuery.select;
4759
4760
4761
4762
4763
4764
4765
4766 Roo.util.Observable = function(A){
4767     
4768     A = A|| {};
4769     this.addEvents(A.events || {});
4770     if (A.events) {
4771         delete  A.events; 
4772     }
4773
4774      
4775     Roo.apply(this, A);
4776     
4777     if(this.listeners){
4778         this.on(this.listeners);
4779         delete  this.listeners;
4780     }
4781 };
4782 Roo.util.Observable.prototype = {
4783     
4784
4785     
4786     
4787     
4788
4789     fireEvent : function(){
4790         var  ce = this.events[arguments[0].toLowerCase()];
4791         if(typeof  ce == "object"){
4792             return  ce.fire.apply(ce, Array.prototype.slice.call(arguments, 1));
4793         }else {
4794             return  true;
4795         }
4796     },
4797
4798     
4799     filterOptRe : /^(?:scope|delay|buffer|single)$/,
4800
4801     
4802
4803     addListener : function(B, fn, C, o){
4804         if(typeof  B == "object"){
4805             o = B;
4806             for(var  e  in  o){
4807                 if(this.filterOptRe.test(e)){
4808                     continue;
4809                 }
4810                 if(typeof  o[e] == "function"){
4811                     
4812                     this.addListener(e, o[e], o.scope,  o);
4813                 }else {
4814                     
4815                     this.addListener(e, o[e].fn, o[e].scope, o[e]);
4816                 }
4817             }
4818             return;
4819         }
4820
4821         o = (!o || typeof  o == "boolean") ? {} : o;
4822         B = B.toLowerCase();
4823         var  ce = this.events[B] || true;
4824         if(typeof  ce == "boolean"){
4825             ce = new  Roo.util.Event(this, B);
4826             this.events[B] = ce;
4827         }
4828
4829         ce.addListener(fn, C, o);
4830     },
4831
4832     
4833
4834     removeListener : function(D, fn, E){
4835         var  ce = this.events[D.toLowerCase()];
4836         if(typeof  ce == "object"){
4837             ce.removeListener(fn, E);
4838         }
4839     },
4840
4841     
4842
4843     purgeListeners : function(){
4844         for(var  evt  in  this.events){
4845             if(typeof  this.events[evt] == "object"){
4846                  this.events[evt].clearListeners();
4847             }
4848         }
4849     },
4850
4851     relayEvents : function(o, F){
4852         var  G = function(H){
4853             return  function(){
4854                 return  this.fireEvent.apply(this, Roo.combine(H, Array.prototype.slice.call(arguments, 0)));
4855             };
4856         };
4857         for(var  i = 0, len = F.length; i < len; i++){
4858             var  ename = F[i];
4859             if(!this.events[ename]){ this.events[ename] = true; };
4860             o.on(ename, G(ename), this);
4861         }
4862     },
4863
4864     
4865
4866     addEvents : function(o){
4867         if(!this.events){
4868             this.events = {};
4869         }
4870
4871         Roo.applyIf(this.events, o);
4872     },
4873
4874     
4875
4876     hasListener : function(H){
4877         var  e = this.events[H];
4878         return  typeof  e == "object" && e.listeners.length > 0;
4879     }
4880 };
4881
4882
4883 Roo.util.Observable.prototype.on = Roo.util.Observable.prototype.addListener;
4884
4885
4886 Roo.util.Observable.prototype.un = Roo.util.Observable.prototype.removeListener;
4887
4888
4889
4890 Roo.util.Observable.capture = function(o, fn, I){
4891     o.fireEvent = o.fireEvent.createInterceptor(fn, I);
4892 };
4893
4894
4895
4896 Roo.util.Observable.releaseCapture = function(o){
4897     o.fireEvent = Roo.util.Observable.prototype.fireEvent;
4898 };
4899
4900 (function(){
4901
4902     var  J = function(h, o, M){
4903         var  N = new  Roo.util.DelayedTask();
4904         return  function(){
4905             N.delay(o.buffer, h, M, Array.prototype.slice.call(arguments, 0));
4906         };
4907     };
4908
4909     var  K = function(h, e, fn, M){
4910         return  function(){
4911             e.removeListener(fn, M);
4912             return  h.apply(M, arguments);
4913         };
4914     };
4915
4916     var  L = function(h, o, M){
4917         return  function(){
4918             var  N = Array.prototype.slice.call(arguments, 0);
4919             setTimeout(function(){
4920                 h.apply(M, N);
4921             }, o.delay || 10);
4922         };
4923     };
4924
4925     Roo.util.Event = function(M, N){
4926         this.name = N;
4927         this.obj = M;
4928         this.listeners = [];
4929     };
4930
4931     Roo.util.Event.prototype = {
4932         addListener : function(fn, M, N){
4933             var  o = N || {};
4934             M = M || this.obj;
4935             if(!this.isListening(fn, M)){
4936                 var  l = {fn: fn, scope: M, options: o};
4937                 var  h = fn;
4938                 if(o.delay){
4939                     h = L(h, o, M);
4940                 }
4941                 if(o.single){
4942                     h = K(h, this, fn, M);
4943                 }
4944                 if(o.buffer){
4945                     h = J(h, o, M);
4946                 }
4947
4948                 l.fireFn = h;
4949                 if(!this.firing){ 
4950                     this.listeners.push(l);
4951                 }else {
4952                     this.listeners = this.listeners.slice(0);
4953                     this.listeners.push(l);
4954                 }
4955             }
4956         },
4957
4958         findListener : function(fn, O){
4959             O = O || this.obj;
4960             var  ls = this.listeners;
4961             for(var  i = 0, len = ls.length; i < len; i++){
4962                 var  l = ls[i];
4963                 if(l.fn == fn && l.scope == O){
4964                     return  i;
4965                 }
4966             }
4967             return  -1;
4968         },
4969
4970         isListening : function(fn, P){
4971             return  this.findListener(fn, P) != -1;
4972         },
4973
4974         removeListener : function(fn, Q){
4975             var  R;
4976             if((R = this.findListener(fn, Q)) != -1){
4977                 if(!this.firing){
4978                     this.listeners.splice(R, 1);
4979                 }else {
4980                     this.listeners = this.listeners.slice(0);
4981                     this.listeners.splice(R, 1);
4982                 }
4983                 return  true;
4984             }
4985             return  false;
4986         },
4987
4988         clearListeners : function(){
4989             this.listeners = [];
4990         },
4991
4992         fire : function(){
4993             var  ls = this.listeners, S, T = ls.length;
4994             if(T > 0){
4995                 this.firing = true;
4996                 var  args = Array.prototype.slice.call(arguments, 0);
4997                 for(var  i = 0; i < T; i++){
4998                     var  l = ls[i];
4999                     if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
5000                         this.firing = false;
5001                         return  false;
5002                     }
5003                 }
5004
5005                 this.firing = false;
5006             }
5007             return  true;
5008         }
5009     };
5010 })();
5011
5012
5013
5014
5015
5016 Roo.EventManager = function(){
5017     var  A, B, C = false;
5018     var  F, G, H, I;
5019     var  E = Roo.lib.Event;
5020     var  D = Roo.lib.Dom;
5021
5022
5023     var  J = function(){
5024         if(!C){
5025             C = true;
5026             Roo.isReady = true;
5027             if(B){
5028                 clearInterval(B);
5029             }
5030             if(Roo.isGecko || Roo.isOpera) {
5031                 document.removeEventListener("DOMContentLoaded", J, false);
5032             }
5033             if(Roo.isIE){
5034                 var  defer = document.getElementById("ie-deferred-loader");
5035                 if(defer){
5036                     defer.onreadystatechange = null;
5037                     defer.parentNode.removeChild(defer);
5038                 }
5039             }
5040             if(A){
5041                 A.fire();
5042                 A.clearListeners();
5043             }
5044         }
5045     };
5046     
5047     var  K = function(){
5048         A = new  Roo.util.Event();
5049         if(Roo.isGecko || Roo.isOpera) {
5050             document.addEventListener("DOMContentLoaded", J, false);
5051         }else  if(Roo.isIE){
5052             document.write("<s"+'cript id="ie-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>");
5053             var  defer = document.getElementById("ie-deferred-loader");
5054             defer.onreadystatechange = function(){
5055                 if(this.readyState == "complete"){
5056                     J();
5057                 }
5058             };
5059         }else  if(Roo.isSafari){ 
5060             B = setInterval(function(){
5061                 var  rs = document.readyState;
5062                 if(rs == "complete") {
5063                     J();     
5064                  }
5065             }, 10);
5066         }
5067
5068         
5069         E.on(window, "load", J);
5070     };
5071
5072     var  L = function(h, o){
5073         var  S = new  Roo.util.DelayedTask(h);
5074         return  function(e){
5075             
5076             e = new  Roo.EventObjectImpl(e);
5077             S.delay(o.buffer, h, null, [e]);
5078         };
5079     };
5080
5081     var  M = function(h, el, S, fn){
5082         return  function(e){
5083             Roo.EventManager.removeListener(el, S, fn);
5084             h(e);
5085         };
5086     };
5087
5088     var  N = function(h, o){
5089         return  function(e){
5090             
5091             e = new  Roo.EventObjectImpl(e);
5092             setTimeout(function(){
5093                 h(e);
5094             }, o.delay || 10);
5095         };
5096     };
5097
5098     var  O = function(S, T, U, fn, V){
5099         var  o = (!U || typeof  U == "boolean") ? {} : U;
5100         fn = fn || o.fn; V = V || o.scope;
5101         var  el = Roo.getDom(S);
5102         if(!el){
5103             throw  "Error listening for \"" + T + '\". Element "' + S + '" doesn\'t exist.';
5104         }
5105         var  h = function(e){
5106             e = Roo.EventObject.setEvent(e);
5107             var  t;
5108             if(o.delegate){
5109                 t = e.getTarget(o.delegate, el);
5110                 if(!t){
5111                     return;
5112                 }
5113             }else {
5114                 t = e.target;
5115             }
5116             if(o.stopEvent === true){
5117                 e.stopEvent();
5118             }
5119             if(o.preventDefault === true){
5120                e.preventDefault();
5121             }
5122             if(o.stopPropagation === true){
5123                 e.stopPropagation();
5124             }
5125
5126             if(o.normalized === false){
5127                 e = e.browserEvent;
5128             }
5129
5130
5131             fn.call(V || el, e, t, o);
5132         };
5133         if(o.delay){
5134             h = N(h, o);
5135         }
5136         if(o.single){
5137             h = M(h, el, T, fn);
5138         }
5139         if(o.buffer){
5140             h = L(h, o);
5141         }
5142
5143         fn._handlers = fn._handlers || [];
5144         fn._handlers.push([Roo.id(el), T, h]);
5145
5146         E.on(el, T, h);
5147         if(T == "mousewheel" && el.addEventListener){ 
5148             el.addEventListener("DOMMouseScroll", h, false);
5149             E.on(window, 'unload', function(){
5150                 el.removeEventListener("DOMMouseScroll", h, false);
5151             });
5152         }
5153         if(T == "mousedown" && el == document){ 
5154             Roo.EventManager.stoppedMouseDownEvent.addListener(h);
5155         }
5156         return  h;
5157     };
5158
5159     var  P = function(el, S, fn){
5160         var  id = Roo.id(el), T = fn._handlers, hd = fn;
5161         if(T){
5162             for(var  i = 0, len = T.length; i < len; i++){
5163                 var  h = T[i];
5164                 if(h[0] == id && h[1] == S){
5165                     hd = h[2];
5166                     T.splice(i, 1);
5167                     break;
5168                 }
5169             }
5170         }
5171
5172         E.un(el, S, hd);
5173         el = Roo.getDom(el);
5174         if(S == "mousewheel" && el.addEventListener){
5175             el.removeEventListener("DOMMouseScroll", hd, false);
5176         }
5177         if(S == "mousedown" && el == document){ 
5178             Roo.EventManager.stoppedMouseDownEvent.removeListener(hd);
5179         }
5180     };
5181
5182     var  Q = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
5183     
5184     var  R = {
5185         
5186         
5187         
5188
5189         
5190         
5191         
5192
5193         wrap : function(fn, S, T){
5194             return  function(e){
5195                 Roo.EventObject.setEvent(e);
5196                 fn.call(T ? S || window : window, Roo.EventObject, S);
5197             };
5198         },
5199         
5200         
5201
5202         addListener : function(U, V, fn, W, X){
5203             if(typeof  V == "object"){
5204                 var  o = V;
5205                 for(var  e  in  o){
5206                     if(Q.test(e)){
5207                         continue;
5208                     }
5209                     if(typeof  o[e] == "function"){
5210                         
5211                         O(U, e, o, o[e], o.scope);
5212                     }else {
5213                         
5214                         O(U, e, o[e]);
5215                     }
5216                 }
5217                 return;
5218             }
5219             return  O(U, V, X, fn, W);
5220         },
5221         
5222         
5223
5224         removeListener : function(Y, Z, fn){
5225             return  P(Y, Z, fn);
5226         },
5227         
5228         
5229
5230         onDocumentReady : function(fn, a, b){
5231             if(C){ 
5232                 A.addListener(fn, a, b);
5233                 A.fire();
5234                 A.clearListeners();
5235                 return;
5236             }
5237             if(!A){
5238                 K();
5239             }
5240
5241             A.addListener(fn, a, b);
5242         },
5243         
5244         
5245
5246         onWindowResize : function(fn, c, d){
5247             if(!F){
5248                 F = new  Roo.util.Event();
5249                 G = new  Roo.util.DelayedTask(function(){
5250                     F.fire(D.getViewWidth(), D.getViewHeight());
5251                 });
5252                 E.on(window, "resize", function(){
5253                     if(Roo.isIE){
5254                         G.delay(50);
5255                     }else {
5256                         F.fire(D.getViewWidth(), D.getViewHeight());
5257                     }
5258                 });
5259             }
5260
5261             F.addListener(fn, c, d);
5262         },
5263
5264         
5265
5266         onTextResize : function(fn, f, g){
5267             if(!H){
5268                 H = new  Roo.util.Event();
5269                 var  textEl = new  Roo.Element(document.createElement('div'));
5270                 textEl.dom.className = 'x-text-resize';
5271                 textEl.dom.innerHTML = 'X';
5272                 textEl.appendTo(document.body);
5273                 I = textEl.dom.offsetHeight;
5274                 setInterval(function(){
5275                     if(textEl.dom.offsetHeight != I){
5276                         H.fire(I, I = textEl.dom.offsetHeight);
5277                     }
5278                 }, this.textResizeInterval);
5279             }
5280
5281             H.addListener(fn, f, g);
5282         },
5283
5284         
5285
5286         removeResizeListener : function(fn, j){
5287             if(F){
5288                 F.removeListener(fn, j);
5289             }
5290         },
5291
5292         
5293         fireResize : function(){
5294             if(F){
5295                 F.fire(D.getViewWidth(), D.getViewHeight());
5296             }   
5297         },
5298         
5299
5300         ieDeferSrc : false,
5301         
5302
5303         textResizeInterval : 50
5304     };
5305     
5306     
5307
5308     
5309      
5310
5311     R.on = R.addListener;
5312     R.un = R.removeListener;
5313
5314     R.stoppedMouseDownEvent = new  Roo.util.Event();
5315     return  R;
5316 }();
5317
5318
5319 Roo.onReady = Roo.EventManager.onDocumentReady;
5320
5321 Roo.onReady(function(){
5322     var  bd = Roo.get(document.body);
5323     if(!bd){ return; }
5324
5325     var  S = [
5326             Roo.isIE ? "roo-ie"
5327             : Roo.isGecko ? "roo-gecko"
5328             : Roo.isOpera ? "roo-opera"
5329             : Roo.isSafari ? "roo-safari" : ""];
5330
5331     if(Roo.isMac){
5332         S.push("roo-mac");
5333     }
5334     if(Roo.isLinux){
5335         S.push("roo-linux");
5336     }
5337     if(Roo.isBorderBox){
5338         S.push('roo-border-box');
5339     }
5340     if(Roo.isStrict){ 
5341         var  p = bd.dom.parentNode;
5342         if(p){
5343             p.className += ' roo-strict';
5344         }
5345     }
5346
5347     bd.addClass(S.join(' '));
5348 });
5349
5350
5351
5352 Roo.EventObject = function(){
5353     
5354     var  E = Roo.lib.Event;
5355     
5356     
5357     var  T = {
5358         63234 : 37, 
5359         63235 : 39, 
5360         63232 : 38, 
5361         63233 : 40, 
5362         63276 : 33, 
5363         63277 : 34, 
5364         63272 : 46, 
5365         63273 : 36, 
5366         63275 : 35  
5367     };
5368
5369     
5370     var  U = Roo.isIE ? {1:0,4:1,2:2} :
5371                 (Roo.isSafari ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
5372
5373     Roo.EventObjectImpl = function(e){
5374         if(e){
5375             this.setEvent(e.browserEvent || e);
5376         }
5377     };
5378     Roo.EventObjectImpl.prototype = {
5379         
5380
5381             
5382
5383         
5384         
5385         
5386
5387         browserEvent : null,
5388         
5389
5390         button : -1,
5391         
5392
5393         shiftKey : false,
5394         
5395
5396         ctrlKey : false,
5397         
5398
5399         altKey : false,
5400
5401         
5402
5403         BACKSPACE : 8,
5404         
5405
5406         TAB : 9,
5407         
5408
5409         RETURN  : 13,
5410         
5411
5412         ENTER : 13,
5413         
5414
5415         SHIFT : 16,
5416         
5417
5418         CONTROL : 17,
5419         
5420
5421         ESC : 27,
5422         
5423
5424         SPACE : 32,
5425         
5426
5427         PAGEUP : 33,
5428         
5429
5430         PAGEDOWN : 34,
5431         
5432
5433         END : 35,
5434         
5435
5436         HOME : 36,
5437         
5438
5439         LEFT : 37,
5440         
5441
5442         UP : 38,
5443         
5444
5445         RIGHT : 39,
5446         
5447
5448         DOWN : 40,
5449         
5450
5451         DELETE  : 46,
5452         
5453
5454         F5 : 116,
5455
5456            
5457
5458         setEvent : function(e){
5459             if(e == this || (e && e.browserEvent)){ 
5460                 return  e;
5461             }
5462
5463             this.browserEvent = e;
5464             if(e){
5465                 
5466                 this.button = e.button ? U[e.button] : (e.which ? e.which-1 : -1);
5467                 if(e.type == 'click' && this.button == -1){
5468                     this.button = 0;
5469                 }
5470
5471                 this.type = e.type;
5472                 this.shiftKey = e.shiftKey;
5473                 
5474                 this.ctrlKey = e.ctrlKey || e.metaKey;
5475                 this.altKey = e.altKey;
5476                 
5477                 this.keyCode = e.keyCode;
5478                 
5479                 this.charCode = (e.type == 'keyup' || e.type == 'keydown') ? 0 : e.charCode;
5480                 
5481                 this.target = E.getTarget(e);
5482                 
5483                 this.xy = E.getXY(e);
5484             }else {
5485                 this.button = -1;
5486                 this.shiftKey = false;
5487                 this.ctrlKey = false;
5488                 this.altKey = false;
5489                 this.keyCode = 0;
5490                 this.charCode =0;
5491                 this.target = null;
5492                 this.xy = [0, 0];
5493             }
5494             return  this;
5495         },
5496
5497         
5498
5499         stopEvent : function(){
5500             if(this.browserEvent){
5501                 if(this.browserEvent.type == 'mousedown'){
5502                     Roo.EventManager.stoppedMouseDownEvent.fire(this);
5503                 }
5504
5505                 E.stopEvent(this.browserEvent);
5506             }
5507         },
5508
5509         
5510
5511         preventDefault : function(){
5512             if(this.browserEvent){
5513                 E.preventDefault(this.browserEvent);
5514             }
5515         },
5516
5517         
5518
5519         isNavKeyPress : function(){
5520             var  k = this.keyCode;
5521             k = Roo.isSafari ? (T[k] || k) : k;
5522             return  (k >= 33 && k <= 40) || k == this.RETURN  || k == this.TAB || k == this.ESC;
5523         },
5524
5525         isSpecialKey : function(){
5526             var  k = this.keyCode;
5527             return  (this.type == 'keypress' && this.ctrlKey) || k == 9 || k == 13  || k == 40 || k == 27 ||
5528             (k == 16) || (k == 17) ||
5529             (k >= 18 && k <= 20) ||
5530             (k >= 33 && k <= 35) ||
5531             (k >= 36 && k <= 39) ||
5532             (k >= 44 && k <= 45);
5533         },
5534         
5535
5536         stopPropagation : function(){
5537             if(this.browserEvent){
5538                 if(this.type == 'mousedown'){
5539                     Roo.EventManager.stoppedMouseDownEvent.fire(this);
5540                 }
5541
5542                 E.stopPropagation(this.browserEvent);
5543             }
5544         },
5545
5546         
5547
5548         getCharCode : function(){
5549             return  this.charCode || this.keyCode;
5550         },
5551
5552         
5553
5554         getKey : function(){
5555             var  k = this.keyCode || this.charCode;
5556             return  Roo.isSafari ? (T[k] || k) : k;
5557         },
5558
5559         
5560
5561         getPageX : function(){
5562             return  this.xy[0];
5563         },
5564
5565         
5566
5567         getPageY : function(){
5568             return  this.xy[1];
5569         },
5570
5571         
5572
5573         getTime : function(){
5574             if(this.browserEvent){
5575                 return  E.getTime(this.browserEvent);
5576             }
5577             return  null;
5578         },
5579
5580         
5581
5582         getXY : function(){
5583             return  this.xy;
5584         },
5585
5586         
5587
5588         getTarget : function(V, W, X){
5589             return  V ? Roo.fly(this.target).findParent(V, W, X) : this.target;
5590         },
5591         
5592
5593         getRelatedTarget : function(){
5594             if(this.browserEvent){
5595                 return  E.getRelatedTarget(this.browserEvent);
5596             }
5597             return  null;
5598         },
5599
5600         
5601
5602         getWheelDelta : function(){
5603             var  e = this.browserEvent;
5604             var  Y = 0;
5605             if(e.wheelDelta){ 
5606
5607                 Y = e.wheelDelta/120;
5608             }else  if(e.detail){ 
5609
5610                 Y = -e.detail/3;
5611             }
5612             return  Y;
5613         },
5614
5615         
5616
5617         hasModifier : function(){
5618             return  !!((this.ctrlKey || this.altKey) || this.shiftKey);
5619         },
5620
5621         
5622
5623         within : function(el, Z){
5624             var  t = this[Z ? "getRelatedTarget" : "getTarget"]();
5625             return  t && Roo.fly(el).contains(t);
5626         },
5627
5628         getPoint : function(){
5629             return  new  Roo.lib.Point(this.xy[0], this.xy[1]);
5630         }
5631     };
5632
5633     return  new  Roo.EventObjectImpl();
5634 }();
5635             
5636     
5637
5638
5639
5640  
5641
5642  
5643 (function(){
5644     var  D = Roo.lib.Dom;
5645     var  E = Roo.lib.Event;
5646     var  A = Roo.lib.Anim;
5647
5648     
5649     var  B = {};
5650     var  C = /(-[a-z])/gi;
5651     var  F = function(m, a){ return  a.charAt(1).toUpperCase(); };
5652     var  G = document.defaultView;
5653
5654
5655
5656     Roo.Element = function(J, K){
5657         var  L = typeof  J == "string" ?
5658                 document.getElementById(J) : J;
5659         if(!L){ 
5660             return  null;
5661         }
5662         var  id = L.id;
5663         if(K !== true && id && Roo.Element.cache[id]){ 
5664             return  Roo.Element.cache[id];
5665         }
5666
5667
5668         
5669
5670         this.dom = L;
5671
5672         
5673
5674         this.id = id || Roo.id(L);
5675     };
5676
5677     var  El = Roo.Element;
5678
5679     El.prototype = {
5680         
5681
5682         originalDisplay : "",
5683
5684         visibilityMode : 1,
5685         
5686
5687         defaultUnit : "px",
5688         
5689
5690         setVisibilityMode : function(J){
5691             this.visibilityMode = J;
5692             return  this;
5693         },
5694         
5695
5696         enableDisplayMode : function(K){
5697             this.setVisibilityMode(El.DISPLAY);
5698             if(typeof  K != "undefined") this.originalDisplay = K;
5699             return  this;
5700         },
5701
5702         
5703
5704         findParent : function(L, M, N){
5705             var  p = this.dom, b = document.body, O = 0, dq = Roo.DomQuery, P;
5706             M = M || 50;
5707             if(typeof  M != "number"){
5708                 P = Roo.getDom(M);
5709                 M = 10;
5710             }
5711             while(p && p.nodeType == 1 && O < M && p != b && p != P){
5712                 if(dq.is(p, L)){
5713                     return  N ? Roo.get(p) : p;
5714                 }
5715
5716                 O++;
5717                 p = p.parentNode;
5718             }
5719             return  null;
5720         },
5721
5722
5723         
5724
5725         findParentNode : function(Q, R, S){
5726             var  p = Roo.fly(this.dom.parentNode, '_internal');
5727             return  p ? p.findParent(Q, R, S) : null;
5728         },
5729
5730         
5731
5732         up : function(T, U){
5733             return  this.findParentNode(T, U, true);
5734         },
5735
5736
5737
5738         
5739
5740         is : function(V){
5741             return  Roo.DomQuery.is(this.dom, V);
5742         },
5743
5744         
5745
5746         animate : function(W, X, Y, Z, c){
5747             this.anim(W, {duration: X, callback: Y, easing: Z}, c);
5748             return  this;
5749         },
5750
5751         
5752
5753         anim : function(e, g, h, j, k, cb){
5754             h = h || 'run';
5755             g = g || {};
5756             var  l = Roo.lib.Anim[h](
5757                 this.dom, e,
5758                 (g.duration || j) || .35,
5759                 (g.easing || k) || 'easeOut',
5760                 function(){
5761                     Roo.callback(cb, this);
5762                     Roo.callback(g.callback, g.scope || this, [this, g]);
5763                 },
5764                 this
5765             );
5766             g.anim = l;
5767             return  l;
5768         },
5769
5770         
5771         preanim : function(a, i){
5772             return  !a[i] ? false : (typeof  a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
5773         },
5774
5775         
5776
5777         clean : function(o){
5778             if(this.isCleaned && o !== true){
5779                 return  this;
5780             }
5781             var  ns = /\S/;
5782             var  d = this.dom, n = d.firstChild, ni = -1;
5783             while(n){
5784                 var  nx = n.nextSibling;
5785                 if(n.nodeType == 3 && !ns.test(n.nodeValue)){
5786                     d.removeChild(n);
5787                 }else {
5788                     n.nodeIndex = ++ni;
5789                 }
5790
5791                 n = nx;
5792             }
5793
5794             this.isCleaned = true;
5795             return  this;
5796         },
5797
5798         
5799         calcOffsetsTo : function(el){
5800             el = Roo.get(el);
5801             var  d = el.dom;
5802             var  q = false;
5803             if(el.getStyle('position') == 'static'){
5804                 el.position('relative');
5805                 q = true;
5806             }
5807             var  x = 0, y =0;
5808             var  op = this.dom;
5809             while(op && op != d && op.tagName != 'HTML'){
5810                 x+= op.offsetLeft;
5811                 y+= op.offsetTop;
5812                 op = op.offsetParent;
5813             }
5814             if(q){
5815                 el.position('static');
5816             }
5817             return  [x, y];
5818         },
5819
5820         
5821
5822         scrollIntoView : function(u, v){
5823             var  c = Roo.getDom(u) || document.body;
5824             var  el = this.dom;
5825
5826             var  o = this.calcOffsetsTo(c),
5827                 l = o[0],
5828                 t = o[1],
5829                 b = t+el.offsetHeight,
5830                 r = l+el.offsetWidth;
5831
5832             var  ch = c.clientHeight;
5833             var  ct = parseInt(c.scrollTop, 10);
5834             var  cl = parseInt(c.scrollLeft, 10);
5835             var  cb = ct + ch;
5836             var  cr = cl + c.clientWidth;
5837
5838             if(t < ct){
5839                 c.scrollTop = t;
5840             }else  if(b > cb){
5841                 c.scrollTop = b-ch;
5842             }
5843
5844             if(v !== false){
5845                 if(l < cl){
5846                     c.scrollLeft = l;
5847                 }else  if(r > cr){
5848                     c.scrollLeft = r-c.clientWidth;
5849                 }
5850             }
5851             return  this;
5852         },
5853
5854         
5855         scrollChildIntoView : function(w, z){
5856             Roo.fly(w, '_scrollChildIntoView').scrollIntoView(this, z);
5857         },
5858
5859         
5860
5861         autoHeight : function(AA, AB, AC, AD){
5862             var  AE = this.getHeight();
5863             this.clip();
5864             this.setHeight(1); 
5865             setTimeout(function(){
5866                 var  AG = parseInt(this.dom.scrollHeight, 10); 
5867                 if(!AA){
5868                     this.setHeight(AG);
5869                     this.unclip();
5870                     if(typeof  AC == "function"){
5871                         AC();
5872                     }
5873                 }else {
5874                     this.setHeight(AE); 
5875                     this.setHeight(AG, AA, AB, function(){
5876                         this.unclip();
5877                         if(typeof  AC == "function") AC();
5878                     }.createDelegate(this), AD);
5879                 }
5880             }.createDelegate(this), 0);
5881             return  this;
5882         },
5883
5884         
5885
5886         contains : function(el){
5887             if(!el){return  false;}
5888             return  D.isAncestor(this.dom, el.dom ? el.dom : el);
5889         },
5890
5891         
5892
5893         isVisible : function(AF) {
5894             var  AG = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
5895             if(AF !== true || !AG){
5896                 return  AG;
5897             }
5898             var  p = this.dom.parentNode;
5899             while(p && p.tagName.toLowerCase() != "body"){
5900                 if(!Roo.fly(p, '_isVisible').isVisible()){
5901                     return  false;
5902                 }
5903
5904                 p = p.parentNode;
5905             }
5906             return  true;
5907         },
5908
5909         
5910
5911         select : function(AH, AI){
5912             return  El.select(AH, AI, this.dom);
5913         },
5914
5915         
5916
5917         query : function(AJ, AK){
5918             return  Roo.DomQuery.select(AJ, this.dom);
5919         },
5920
5921         
5922
5923         child : function(AL, AM){
5924             var  n = Roo.DomQuery.selectNode(AL, this.dom);
5925             return  AM ? n : Roo.get(n);
5926         },
5927
5928         
5929
5930         down : function(AN, AO){
5931             var  n = Roo.DomQuery.selectNode(" > " + AN, this.dom);
5932             return  AO ? n : Roo.get(n);
5933         },
5934
5935         
5936
5937         initDD : function(AP, AQ, AR){
5938             var  dd = new  Roo.dd.DD(Roo.id(this.dom), AP, AQ);
5939             return  Roo.apply(dd, AR);
5940         },
5941
5942         
5943
5944         initDDProxy : function(AS, AT, AU){
5945             var  dd = new  Roo.dd.DDProxy(Roo.id(this.dom), AS, AT);
5946             return  Roo.apply(dd, AU);
5947         },
5948
5949         
5950
5951         initDDTarget : function(AV, AW, AX){
5952             var  dd = new  Roo.dd.DDTarget(Roo.id(this.dom), AV, AW);
5953             return  Roo.apply(dd, AX);
5954         },
5955
5956         
5957
5958          setVisible : function(AY, AZ){
5959             if(!AZ || !A){
5960                 if(this.visibilityMode == El.DISPLAY){
5961                     this.setDisplayed(AY);
5962                 }else {
5963                     this.fixDisplay();
5964                     this.dom.style.visibility = AY ? "visible" : "hidden";
5965                 }
5966             }else {
5967                 
5968                 var  dom = this.dom;
5969                 var  J = this.visibilityMode;
5970                 if(AY){
5971                     this.setOpacity(.01);
5972                     this.setVisible(true);
5973                 }
5974
5975                 this.anim({opacity: { to: (AY?1:0) }},
5976                       this.preanim(arguments, 1),
5977                       null, .35, 'easeIn', function(){
5978                          if(!AY){
5979                              if(J == El.DISPLAY){
5980                                  dom.style.display = "none";
5981                              }else {
5982                                  dom.style.visibility = "hidden";
5983                              }
5984
5985                              Roo.get(dom).setOpacity(1);
5986                          }
5987                      });
5988             }
5989             return  this;
5990         },
5991
5992         
5993
5994         isDisplayed : function() {
5995             return  this.getStyle("display") != "none";
5996         },
5997
5998         
5999
6000         toggle : function(Aa){
6001             this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
6002             return  this;
6003         },
6004
6005         
6006
6007         setDisplayed : function(Ab) {
6008             if(typeof  Ab == "boolean"){
6009                Ab = Ab ? this.originalDisplay : "none";
6010             }
6011
6012             this.setStyle("display", Ab);
6013             return  this;
6014         },
6015
6016         
6017
6018         focus : function() {
6019             try{
6020                 this.dom.focus();
6021             }catch(e){}
6022             return  this;
6023         },
6024
6025         
6026
6027         blur : function() {
6028             try{
6029                 this.dom.blur();
6030             }catch(e){}
6031             return  this;
6032         },
6033
6034         
6035
6036         addClass : function(Ac){
6037             if(Ac  instanceof  Array){
6038                 for(var  i = 0, len = Ac.length; i < len; i++) {
6039                     this.addClass(Ac[i]);
6040                 }
6041             }else {
6042                 if(Ac && !this.hasClass(Ac)){
6043                     this.dom.className = this.dom.className + " " + Ac;
6044                 }
6045             }
6046             return  this;
6047         },
6048
6049         
6050
6051         radioClass : function(Ad){
6052             var  Ae = this.dom.parentNode.childNodes;
6053             for(var  i = 0; i < Ae.length; i++) {
6054                 var  s = Ae[i];
6055                 if(s.nodeType == 1){
6056                     Roo.get(s).removeClass(Ad);
6057                 }
6058             }
6059
6060             this.addClass(Ad);
6061             return  this;
6062         },
6063
6064         
6065
6066         removeClass : function(Af){
6067             if(!Af || !this.dom.className){
6068                 return  this;
6069             }
6070             if(Af  instanceof  Array){
6071                 for(var  i = 0, len = Af.length; i < len; i++) {
6072                     this.removeClass(Af[i]);
6073                 }
6074             }else {
6075                 if(this.hasClass(Af)){
6076                     var  re = this.classReCache[Af];
6077                     if (!re) {
6078                        re = new  RegExp('(?:^|\\s+)' + Af + '(?:\\s+|$)', "g");
6079                        this.classReCache[Af] = re;
6080                     }
6081
6082                     this.dom.className =
6083                         this.dom.className.replace(re, " ");
6084                 }
6085             }
6086             return  this;
6087         },
6088
6089         
6090         classReCache: {},
6091
6092         
6093
6094         toggleClass : function(Ag){
6095             if(this.hasClass(Ag)){
6096                 this.removeClass(Ag);
6097             }else {
6098                 this.addClass(Ag);
6099             }
6100             return  this;
6101         },
6102
6103         
6104
6105         hasClass : function(Ah){
6106             return  Ah && (' '+this.dom.className+' ').indexOf(' '+Ah+' ') != -1;
6107         },
6108
6109         
6110
6111         replaceClass : function(Ai, Aj){
6112             this.removeClass(Ai);
6113             this.addClass(Aj);
6114             return  this;
6115         },
6116
6117         
6118
6119         getStyles : function(){
6120             var  a = arguments, Ak = a.length, r = {};
6121             for(var  i = 0; i < Ak; i++){
6122                 r[a[i]] = this.getStyle(a[i]);
6123             }
6124             return  r;
6125         },
6126
6127         
6128
6129         getStyle : function(){
6130             return  G && G.getComputedStyle ?
6131                 function(Al){
6132                     var  el = this.dom, v, cs, Am;
6133                     if(Al == 'float'){
6134                         Al = "cssFloat";
6135                     }
6136                     if(el.style && (v = el.style[Al])){
6137                         return  v;
6138                     }
6139                     if(cs = G.getComputedStyle(el, "")){
6140                         if(!(Am = B[Al])){
6141                             Am = B[Al] = Al.replace(C, F);
6142                         }
6143                         return  cs[Am];
6144                     }
6145                     return  null;
6146                 } :
6147                 function(Al){
6148                     var  el = this.dom, v, cs, Am;
6149                     if(Al == 'opacity'){
6150                         if(typeof  el.style.filter == 'string'){
6151                             var  m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
6152                             if(m){
6153                                 var  fv = parseFloat(m[1]);
6154                                 if(!isNaN(fv)){
6155                                     return  fv ? fv / 100 : 0;
6156                                 }
6157                             }
6158                         }
6159                         return  1;
6160                     }else  if(Al == 'float'){
6161                         Al = "styleFloat";
6162                     }
6163                     if(!(Am = B[Al])){
6164                         Am = B[Al] = Al.replace(C, F);
6165                     }
6166                     if(v = el.style[Am]){
6167                         return  v;
6168                     }
6169                     if(cs = el.currentStyle){
6170                         return  cs[Am];
6171                     }
6172                     return  null;
6173                 };
6174         }(),
6175
6176         
6177
6178         setStyle : function(Al, Am){
6179             if(typeof  Al == "string"){
6180                 
6181                 if (Al == 'float') {
6182                     this.setStyle(Roo.isIE ? 'styleFloat'  : 'cssFloat', Am);
6183                     return  this;
6184                 }
6185                 
6186                 var  camel;
6187                 if(!(camel = B[Al])){
6188                     camel = B[Al] = Al.replace(C, F);
6189                 }
6190                 
6191                 if(camel == 'opacity') {
6192                     this.setOpacity(Am);
6193                 }else {
6194                     this.dom.style[camel] = Am;
6195                 }
6196             }else {
6197                 for(var  style  in  Al){
6198                     if(typeof  Al[style] != "function"){
6199                        this.setStyle(style, Al[style]);
6200                     }
6201                 }
6202             }
6203             return  this;
6204         },
6205
6206         
6207
6208         applyStyles : function(An){
6209             Roo.DomHelper.applyStyles(this.dom, An);
6210             return  this;
6211         },
6212
6213         
6214
6215         getX : function(){
6216             return  D.getX(this.dom);
6217         },
6218
6219         
6220
6221         getY : function(){
6222             return  D.getY(this.dom);
6223         },
6224
6225         
6226
6227         getXY : function(){
6228             return  D.getXY(this.dom);
6229         },
6230
6231         
6232
6233         setX : function(x, Ao){
6234             if(!Ao || !A){
6235                 D.setX(this.dom, x);
6236             }else {
6237                 this.setXY([x, this.getY()], this.preanim(arguments, 1));
6238             }
6239             return  this;
6240         },
6241
6242         
6243
6244         setY : function(y, Ap){
6245             if(!Ap || !A){
6246                 D.setY(this.dom, y);
6247             }else {
6248                 this.setXY([this.getX(), y], this.preanim(arguments, 1));
6249             }
6250             return  this;
6251         },
6252
6253         
6254
6255         setLeft : function(Aq){
6256             this.setStyle("left", this.addUnits(Aq));
6257             return  this;
6258         },
6259
6260         
6261
6262         setTop : function(Ar){
6263             this.setStyle("top", this.addUnits(Ar));
6264             return  this;
6265         },
6266
6267         
6268
6269         setRight : function(As){
6270             this.setStyle("right", this.addUnits(As));
6271             return  this;
6272         },
6273
6274         
6275
6276         setBottom : function(At){
6277             this.setStyle("bottom", this.addUnits(At));
6278             return  this;
6279         },
6280
6281         
6282
6283         setXY : function(Au, Av){
6284             if(!Av || !A){
6285                 D.setXY(this.dom, Au);
6286             }else {
6287                 this.anim({points: {to: Au}}, this.preanim(arguments, 1), 'motion');
6288             }
6289             return  this;
6290         },
6291
6292         
6293
6294         setLocation : function(x, y, Aw){
6295             this.setXY([x, y], this.preanim(arguments, 2));
6296             return  this;
6297         },
6298
6299         
6300
6301         moveTo : function(x, y, Ax){
6302             this.setXY([x, y], this.preanim(arguments, 2));
6303             return  this;
6304         },
6305
6306         
6307
6308         getRegion : function(){
6309             return  D.getRegion(this.dom);
6310         },
6311
6312         
6313
6314         getHeight : function(Ay){
6315             var  h = this.dom.offsetHeight || 0;
6316             return  Ay !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
6317         },
6318
6319         
6320
6321         getWidth : function(Az){
6322             var  w = this.dom.offsetWidth || 0;
6323             return  Az !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
6324         },
6325
6326         
6327
6328         getComputedHeight : function(){
6329             var  h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
6330             if(!h){
6331                 h = parseInt(this.getStyle('height'), 10) || 0;
6332                 if(!this.isBorderBox()){
6333                     h += this.getFrameWidth('tb');
6334                 }
6335             }
6336             return  h;
6337         },
6338
6339         
6340
6341         getComputedWidth : function(){
6342             var  w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
6343             if(!w){
6344                 w = parseInt(this.getStyle('width'), 10) || 0;
6345                 if(!this.isBorderBox()){
6346                     w += this.getFrameWidth('lr');
6347                 }
6348             }
6349             return  w;
6350         },
6351
6352         
6353
6354         getSize : function(A0){
6355             return  {width: this.getWidth(A0), height: this.getHeight(A0)};
6356         },
6357
6358         
6359
6360         getViewSize : function(){
6361             var  d = this.dom, A1 = document, aw = 0, ah = 0;
6362             if(d == A1 || d == A1.body){
6363                 return  {width : D.getViewWidth(), height: D.getViewHeight()};
6364             }else {
6365                 return  {
6366                     width : d.clientWidth,
6367                     height: d.clientHeight
6368                 };
6369             }
6370         },
6371
6372         
6373
6374         getValue : function(A2){
6375             return  A2 ? parseInt(this.dom.value, 10) : this.dom.value;
6376         },
6377
6378         
6379         adjustWidth : function(A3){
6380             if(typeof  A3 == "number"){
6381                 if(this.autoBoxAdjust && !this.isBorderBox()){
6382                    A3 -= (this.getBorderWidth("lr") + this.getPadding("lr"));
6383                 }
6384                 if(A3 < 0){
6385                     A3 = 0;
6386                 }
6387             }
6388             return  A3;
6389         },
6390
6391         
6392         adjustHeight : function(A4){
6393             if(typeof  A4 == "number"){
6394                if(this.autoBoxAdjust && !this.isBorderBox()){
6395                    A4 -= (this.getBorderWidth("tb") + this.getPadding("tb"));
6396                }
6397                if(A4 < 0){
6398                    A4 = 0;
6399                }
6400             }
6401             return  A4;
6402         },
6403
6404         
6405
6406         setWidth : function(A5, A6){
6407             A5 = this.adjustWidth(A5);
6408             if(!A6 || !A){
6409                 this.dom.style.width = this.addUnits(A5);
6410             }else {
6411                 this.anim({width: {to: A5}}, this.preanim(arguments, 1));
6412             }
6413             return  this;
6414         },
6415
6416         
6417
6418          setHeight : function(A7, A8){
6419             A7 = this.adjustHeight(A7);
6420             if(!A8 || !A){
6421                 this.dom.style.height = this.addUnits(A7);
6422             }else {
6423                 this.anim({height: {to: A7}}, this.preanim(arguments, 1));
6424             }
6425             return  this;
6426         },
6427
6428         
6429
6430          setSize : function(A9, BA, BB){
6431             if(typeof  A9 == "object"){ 
6432                 BA = A9.height; A9 = A9.width;
6433             }
6434
6435             A9 = this.adjustWidth(A9); BA = this.adjustHeight(BA);
6436             if(!BB || !A){
6437                 this.dom.style.width = this.addUnits(A9);
6438                 this.dom.style.height = this.addUnits(BA);
6439             }else {
6440                 this.anim({width: {to: A9}, height: {to: BA}}, this.preanim(arguments, 2));
6441             }
6442             return  this;
6443         },
6444
6445         
6446
6447         setBounds : function(x, y, BC, BD, BE){
6448             if(!BE || !A){
6449                 this.setSize(BC, BD);
6450                 this.setLocation(x, y);
6451             }else {
6452                 BC = this.adjustWidth(BC); BD = this.adjustHeight(BD);
6453                 this.anim({points: {to: [x, y]}, width: {to: BC}, height: {to: BD}},
6454                               this.preanim(arguments, 4), 'motion');
6455             }
6456             return  this;
6457         },
6458
6459         
6460
6461         setRegion : function(BF, BG){
6462             this.setBounds(BF.left, BF.top, BF.right-BF.left, BF.bottom-BF.top, this.preanim(arguments, 1));
6463             return  this;
6464         },
6465
6466         
6467
6468         addListener : function(BH, fn, BI, BJ){
6469             Roo.EventManager.on(this.dom,  BH, fn, BI || this, BJ);
6470         },
6471
6472         
6473
6474         removeListener : function(BK, fn){
6475             Roo.EventManager.removeListener(this.dom,  BK, fn);
6476             return  this;
6477         },
6478
6479         
6480
6481         removeAllListeners : function(){
6482             E.purgeElement(this.dom);
6483             return  this;
6484         },
6485
6486         relayEvent : function(BL, BM){
6487             this.on(BL, function(e){
6488                 BM.fireEvent(BL, e);
6489             });
6490         },
6491
6492         
6493
6494          setOpacity : function(BN, BO){
6495             if(!BO || !A){
6496                 var  s = this.dom.style;
6497                 if(Roo.isIE){
6498                     s.zoom = 1;
6499                     s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
6500                                (BN == 1 ? "" : "alpha(opacity=" + BN * 100 + ")");
6501                 }else {
6502                     s.opacity = BN;
6503                 }
6504             }else {
6505                 this.anim({opacity: {to: BN}}, this.preanim(arguments, 1), null, .35, 'easeIn');
6506             }
6507             return  this;
6508         },
6509
6510         
6511
6512         getLeft : function(BP){
6513             if(!BP){
6514                 return  this.getX();
6515             }else {
6516                 return  parseInt(this.getStyle("left"), 10) || 0;
6517             }
6518         },
6519
6520         
6521
6522         getRight : function(BQ){
6523             if(!BQ){
6524                 return  this.getX() + this.getWidth();
6525             }else {
6526                 return  (this.getLeft(true) + this.getWidth()) || 0;
6527             }
6528         },
6529
6530         
6531
6532         getTop : function(BR) {
6533             if(!BR){
6534                 return  this.getY();
6535             }else {
6536                 return  parseInt(this.getStyle("top"), 10) || 0;
6537             }
6538         },
6539
6540         
6541
6542         getBottom : function(BS){
6543             if(!BS){
6544                 return  this.getY() + this.getHeight();
6545             }else {
6546                 return  (this.getTop(true) + this.getHeight()) || 0;
6547             }
6548         },
6549
6550         
6551
6552         position : function(BT, BU, x, y){
6553             if(!BT){
6554                if(this.getStyle('position') == 'static'){
6555                    this.setStyle('position', 'relative');
6556                }
6557             }else {
6558                 this.setStyle("position", BT);
6559             }
6560             if(BU){
6561                 this.setStyle("z-index", BU);
6562             }
6563             if(x !== undefined && y !== undefined){
6564                 this.setXY([x, y]);
6565             }else  if(x !== undefined){
6566                 this.setX(x);
6567             }else  if(y !== undefined){
6568                 this.setY(y);
6569             }
6570         },
6571
6572         
6573
6574         clearPositioning : function(BV){
6575             BV = BV ||'';
6576             this.setStyle({
6577                 "left": BV,
6578                 "right": BV,
6579                 "top": BV,
6580                 "bottom": BV,
6581                 "z-index": "",
6582                 "position" : "static"
6583             });
6584             return  this;
6585         },
6586
6587         
6588
6589         getPositioning : function(){
6590             var  l = this.getStyle("left");
6591             var  t = this.getStyle("top");
6592             return  {
6593                 "position" : this.getStyle("position"),
6594                 "left" : l,
6595                 "right" : l ? "" : this.getStyle("right"),
6596                 "top" : t,
6597                 "bottom" : t ? "" : this.getStyle("bottom"),
6598                 "z-index" : this.getStyle("z-index")
6599             };
6600         },
6601
6602         
6603
6604         getBorderWidth : function(BW){
6605             return  this.addStyles(BW, El.borders);
6606         },
6607
6608         
6609
6610         getPadding : function(BX){
6611             return  this.addStyles(BX, El.paddings);
6612         },
6613
6614         
6615
6616         setPositioning : function(pc){
6617             this.applyStyles(pc);
6618             if(pc.right == "auto"){
6619                 this.dom.style.right = "";
6620             }
6621             if(pc.bottom == "auto"){
6622                 this.dom.style.bottom = "";
6623             }
6624             return  this;
6625         },
6626
6627         
6628         fixDisplay : function(){
6629             if(this.getStyle("display") == "none"){
6630                 this.setStyle("visibility", "hidden");
6631                 this.setStyle("display", this.originalDisplay); 
6632                 if(this.getStyle("display") == "none"){ 
6633                     this.setStyle("display", "block");
6634                 }
6635             }
6636         },
6637
6638         
6639
6640          setLeftTop : function(BY, BZ){
6641             this.dom.style.left = this.addUnits(BY);
6642             this.dom.style.top = this.addUnits(BZ);
6643             return  this;
6644         },
6645
6646         
6647
6648          move : function(Ba, Bb, Bc){
6649             var  xy = this.getXY();
6650             Ba = Ba.toLowerCase();
6651             switch(Ba){
6652                 case  "l":
6653                 case  "left":
6654                     this.moveTo(xy[0]-Bb, xy[1], this.preanim(arguments, 2));
6655                     break;
6656                case  "r":
6657                case  "right":
6658                     this.moveTo(xy[0]+Bb, xy[1], this.preanim(arguments, 2));
6659                     break;
6660                case  "t":
6661                case  "top":
6662                case  "up":
6663                     this.moveTo(xy[0], xy[1]-Bb, this.preanim(arguments, 2));
6664                     break;
6665                case  "b":
6666                case  "bottom":
6667                case  "down":
6668                     this.moveTo(xy[0], xy[1]+Bb, this.preanim(arguments, 2));
6669                     break;
6670             }
6671             return  this;
6672         },
6673
6674         
6675
6676         clip : function(){
6677             if(!this.isClipped){
6678                this.isClipped = true;
6679                this.originalClip = {
6680                    "o": this.getStyle("overflow"),
6681                    "x": this.getStyle("overflow-x"),
6682                    "y": this.getStyle("overflow-y")
6683                };
6684                this.setStyle("overflow", "hidden");
6685                this.setStyle("overflow-x", "hidden");
6686                this.setStyle("overflow-y", "hidden");
6687             }
6688             return  this;
6689         },
6690
6691         
6692
6693         unclip : function(){
6694             if(this.isClipped){
6695                 this.isClipped = false;
6696                 var  o = this.originalClip;
6697                 if(o.o){this.setStyle("overflow", o.o);}
6698                 if(o.x){this.setStyle("overflow-x", o.x);}
6699                 if(o.y){this.setStyle("overflow-y", o.y);}
6700             }
6701             return  this;
6702         },
6703
6704
6705         
6706
6707         getAnchorXY : function(Bd, Be, s){
6708             
6709             
6710
6711             var  w, h, vp = false;
6712             if(!s){
6713                 var  d = this.dom;
6714                 if(d == document.body || d == document){
6715                     vp = true;
6716                     w = D.getViewWidth(); h = D.getViewHeight();
6717                 }else {
6718                     w = this.getWidth(); h = this.getHeight();
6719                 }
6720             }else {
6721                 w = s.width;  h = s.height;
6722             }
6723             var  x = 0, y = 0, r = Math.round;
6724             switch((Bd || "tl").toLowerCase()){
6725                 case  "c":
6726                     x = r(w*.5);
6727                     y = r(h*.5);
6728                 break;
6729                 case  "t":
6730                     x = r(w*.5);
6731                     y = 0;
6732                 break;
6733                 case  "l":
6734                     x = 0;
6735                     y = r(h*.5);
6736                 break;
6737                 case  "r":
6738                     x = w;
6739                     y = r(h*.5);
6740                 break;
6741                 case  "b":
6742                     x = r(w*.5);
6743                     y = h;
6744                 break;
6745                 case  "tl":
6746                     x = 0;
6747                     y = 0;
6748                 break;
6749                 case  "bl":
6750                     x = 0;
6751                     y = h;
6752                 break;
6753                 case  "br":
6754                     x = w;
6755                     y = h;
6756                 break;
6757                 case  "tr":
6758                     x = w;
6759                     y = 0;
6760                 break;
6761             }
6762             if(Be === true){
6763                 return  [x, y];
6764             }
6765             if(vp){
6766                 var  sc = this.getScroll();
6767                 return  [x + sc.left, y + sc.top];
6768             }
6769             
6770             var  o = this.getXY();
6771             return  [x+o[0], y+o[1]];
6772         },
6773
6774         
6775
6776         getAlignToXY : function(el, p, o){
6777             el = Roo.get(el);
6778             var  d = this.dom;
6779             if(!el.dom){
6780                 throw  "Element.alignTo with an element that doesn't exist";
6781             }
6782             var  c = false; 
6783             var  p1 = "", p2 = "";
6784             o = o || [0,0];
6785
6786             if(!p){
6787                 p = "tl-bl";
6788             }else  if(p == "?"){
6789                 p = "tl-bl?";
6790             }else  if(p.indexOf("-") == -1){
6791                 p = "tl-" + p;
6792             }
6793
6794             p = p.toLowerCase();
6795             var  m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
6796             if(!m){
6797                throw  "Element.alignTo with an invalid alignment " + p;
6798             }
6799
6800             p1 = m[1]; p2 = m[2]; c = !!m[3];
6801
6802             
6803             
6804             var  a1 = this.getAnchorXY(p1, true);
6805             var  a2 = el.getAnchorXY(p2, false);
6806             var  x = a2[0] - a1[0] + o[0];
6807             var  y = a2[1] - a1[1] + o[1];
6808             if(c){
6809                 
6810                 var  w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
6811                 
6812                 var  dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
6813
6814                 
6815                 
6816                 
6817                 var  p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
6818                var  p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
6819                var  swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
6820                var  swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
6821
6822                var  A1 = document;
6823                var  scrollX = (A1.documentElement.scrollLeft || A1.body.scrollLeft || 0)+5;
6824                var  scrollY = (A1.documentElement.scrollTop || A1.body.scrollTop || 0)+5;
6825
6826                if((x+w) > dw + scrollX){
6827                     x = swapX ? r.left-w : dw+scrollX-w;
6828                 }
6829                if(x < scrollX){
6830                    x = swapX ? r.right : scrollX;
6831                }
6832                if((y+h) > dh + scrollY){
6833                     y = swapY ? r.top-h : dh+scrollY-h;
6834                 }
6835                if (y < scrollY){
6836                    y = swapY ? r.bottom : scrollY;
6837                }
6838             }
6839             return  [x,y];
6840         },
6841
6842         
6843         getConstrainToXY : function(){
6844             var  os = {top:0, left:0, bottom:0, right: 0};
6845
6846             return  function(el, Bf, Bg, Bh){
6847                 el = Roo.get(el);
6848                 Bg = Bg ? Roo.applyIf(Bg, os) : os;
6849
6850                 var  vw, vh, vx = 0, vy = 0;
6851                 if(el.dom == document.body || el.dom == document){
6852                     vw = Roo.lib.Dom.getViewWidth();
6853                     vh = Roo.lib.Dom.getViewHeight();
6854                 }else {
6855                     vw = el.dom.clientWidth;
6856                     vh = el.dom.clientHeight;
6857                     if(!Bf){
6858                         var  vxy = el.getXY();
6859                         vx = vxy[0];
6860                         vy = vxy[1];
6861                     }
6862                 }
6863
6864                 var  s = el.getScroll();
6865
6866                 vx += Bg.left + s.left;
6867                 vy += Bg.top + s.top;
6868
6869                 vw -= Bg.right;
6870                 vh -= Bg.bottom;
6871
6872                 var  vr = vx+vw;
6873                 var  vb = vy+vh;
6874
6875                 var  xy = Bh || (!Bf ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
6876                 var  x = xy[0], y = xy[1];
6877                 var  w = this.dom.offsetWidth, h = this.dom.offsetHeight;
6878
6879                 
6880                 var  Bi = false;
6881
6882                 
6883                 if((x + w) > vr){
6884                     x = vr - w;
6885                     Bi = true;
6886                 }
6887                 if((y + h) > vb){
6888                     y = vb - h;
6889                     Bi = true;
6890                 }
6891                 
6892                 if(x < vx){
6893                     x = vx;
6894                     Bi = true;
6895                 }
6896                 if(y < vy){
6897                     y = vy;
6898                     Bi = true;
6899                 }
6900                 return  Bi ? [x, y] : false;
6901             };
6902         }(),
6903
6904         
6905         adjustForConstraints : function(xy, Bf, Bg){
6906             return  this.getConstrainToXY(Bf || document, false, Bg, xy) ||  xy;
6907         },
6908
6909         
6910
6911         alignTo : function(Bh, Bi, Bj, Bk){
6912             var  xy = this.getAlignToXY(Bh, Bi, Bj);
6913             this.setXY(xy, this.preanim(arguments, 3));
6914             return  this;
6915         },
6916
6917         
6918
6919         anchorTo : function(el, Bl, Bm, Bn, Bo, Bp){
6920             var  Bq = function(){
6921                 this.alignTo(el, Bl, Bm, Bn);
6922                 Roo.callback(Bp, this);
6923             };
6924             Roo.EventManager.onWindowResize(Bq, this);
6925             var  tm = typeof  Bo;
6926             if(tm != 'undefined'){
6927                 Roo.EventManager.on(window, 'scroll', Bq, this,
6928                     {buffer: tm == 'number' ? Bo : 50});
6929             }
6930
6931             Bq.call(this); 
6932             return  this;
6933         },
6934         
6935
6936         clearOpacity : function(){
6937             if (window.ActiveXObject) {
6938                 if(typeof  this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
6939                     this.dom.style.filter = "";
6940                 }
6941             } else  {
6942                 this.dom.style.opacity = "";
6943                 this.dom.style["-moz-opacity"] = "";
6944                 this.dom.style["-khtml-opacity"] = "";
6945             }
6946             return  this;
6947         },
6948
6949         
6950
6951         hide : function(Br){
6952             this.setVisible(false, this.preanim(arguments, 0));
6953             return  this;
6954         },
6955
6956         
6957
6958         show : function(Bs){
6959             this.setVisible(true, this.preanim(arguments, 0));
6960             return  this;
6961         },
6962
6963         
6964
6965         addUnits : function(Bt){
6966             return  Roo.Element.addUnits(Bt, this.defaultUnit);
6967         },
6968
6969         
6970
6971         beginMeasure : function(){
6972             var  el = this.dom;
6973             if(el.offsetWidth || el.offsetHeight){
6974                 return  this; 
6975             }
6976             var  Bu = [];
6977             var  p = this.dom, b = document.body; 
6978             while((!el.offsetWidth && !el.offsetHeight) && p && p.tagName && p != b){
6979                 var  pe = Roo.get(p);
6980                 if(pe.getStyle('display') == 'none'){
6981                     Bu.push({el: p, visibility: pe.getStyle("visibility")});
6982                     p.style.visibility = "hidden";
6983                     p.style.display = "block";
6984                 }
6985
6986                 p = p.parentNode;
6987             }
6988
6989             this._measureChanged = Bu;
6990             return  this;
6991
6992         },
6993
6994         
6995
6996         endMeasure : function(){
6997             var  Bv = this._measureChanged;
6998             if(Bv){
6999                 for(var  i = 0, Ak = Bv.length; i < Ak; i++) {
7000                     var  r = Bv[i];
7001                     r.el.style.visibility = r.visibility;
7002                     r.el.style.display = "none";
7003                 }
7004
7005                 this._measureChanged = null;
7006             }
7007             return  this;
7008         },
7009
7010         
7011
7012         update : function(Bw, Bx, By){
7013             if(typeof  Bw == "undefined"){
7014                 Bw = "";
7015             }
7016             if(Bx !== true){
7017                 this.dom.innerHTML = Bw;
7018                 if(typeof  By == "function"){
7019                     By();
7020                 }
7021                 return  this;
7022             }
7023             var  id = Roo.id();
7024             var  Bz = this.dom;
7025
7026             Bw += '<span id="' + id + '"></span>';
7027
7028             E.onAvailable(id, function(){
7029                 var  hd = document.getElementsByTagName("head")[0];
7030                 var  re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
7031                 var  B0 = /\ssrc=([\'\"])(.*?)\1/i;
7032                 var  B1 = /\stype=([\'\"])(.*?)\1/i;
7033
7034                 var  B2;
7035                 while(B2 = re.exec(Bw)){
7036                     var  attrs = B2[1];
7037                     var  srcMatch = attrs ? attrs.match(B0) : false;
7038                     if(srcMatch && srcMatch[2]){
7039                        var  s = document.createElement("script");
7040                        s.src = srcMatch[2];
7041                        var  typeMatch = attrs.match(B1);
7042                        if(typeMatch && typeMatch[2]){
7043                            s.type = typeMatch[2];
7044                        }
7045
7046                        hd.appendChild(s);
7047                     }else  if(B2[2] && B2[2].length > 0){
7048                         if(window.execScript) {
7049                            window.execScript(B2[2]);
7050                         } else  {
7051                             
7052
7053                            window.eval(B2[2]);
7054                         }
7055                     }
7056                 }
7057                 var  el = document.getElementById(id);
7058                 if(el){el.parentNode.removeChild(el);}
7059                 if(typeof  By == "function"){
7060                     By();
7061                 }
7062             });
7063             Bz.innerHTML = Bw.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
7064             return  this;
7065         },
7066
7067         
7068
7069         load : function(){
7070             var  um = this.getUpdateManager();
7071             um.update.apply(um, arguments);
7072             return  this;
7073         },
7074
7075         
7076
7077         getUpdateManager : function(){
7078             if(!this.updateManager){
7079                 this.updateManager = new  Roo.UpdateManager(this);
7080             }
7081             return  this.updateManager;
7082         },
7083
7084         
7085
7086         unselectable : function(){
7087             this.dom.unselectable = "on";
7088             this.swallowEvent("selectstart", true);
7089             this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
7090             this.addClass("x-unselectable");
7091             return  this;
7092         },
7093
7094         
7095
7096         getCenterXY : function(){
7097             return  this.getAlignToXY(document, 'c-c');
7098         },
7099
7100         
7101
7102         center : function(B0){
7103             this.alignTo(B0 || document, 'c-c');
7104             return  this;
7105         },
7106
7107         
7108
7109         isBorderBox : function(){
7110             return  I[this.dom.tagName.toLowerCase()] || Roo.isBorderBox;
7111         },
7112
7113         
7114
7115         getBox : function(B1, B2){
7116             var  xy;
7117             if(!B2){
7118                 xy = this.getXY();
7119             }else {
7120                 var  BY = parseInt(this.getStyle("left"), 10) || 0;
7121                 var  BZ = parseInt(this.getStyle("top"), 10) || 0;
7122                 xy = [BY, BZ];
7123             }
7124             var  el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
7125             if(!B1){
7126                 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
7127             }else {
7128                 var  l = this.getBorderWidth("l")+this.getPadding("l");
7129                 var  r = this.getBorderWidth("r")+this.getPadding("r");
7130                 var  t = this.getBorderWidth("t")+this.getPadding("t");
7131                 var  b = this.getBorderWidth("b")+this.getPadding("b");
7132                 bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};
7133             }
7134
7135             bx.right = bx.x + bx.width;
7136             bx.bottom = bx.y + bx.height;
7137             return  bx;
7138         },
7139
7140         
7141
7142         getFrameWidth : function(B3, B4){
7143             return  B4 && Roo.isBorderBox ? 0 : (this.getPadding(B3) + this.getBorderWidth(B3));
7144         },
7145
7146         
7147
7148         setBox : function(B5, B6, B7){
7149             var  w = B5.width, h = B5.height;
7150             if((B6 && !this.autoBoxAdjust) && !this.isBorderBox()){
7151                w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
7152                h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
7153             }
7154
7155             this.setBounds(B5.x, B5.y, w, h, this.preanim(arguments, 2));
7156             return  this;
7157         },
7158
7159         
7160
7161          repaint : function(){
7162             var  B8 = this.dom;
7163             this.addClass("x-repaint");
7164             setTimeout(function(){
7165                 Roo.get(B8).removeClass("x-repaint");
7166             }, 1);
7167             return  this;
7168         },
7169
7170         
7171
7172         getMargins : function(B9){
7173             if(!B9){
7174                 return  {
7175                     top: parseInt(this.getStyle("margin-top"), 10) || 0,
7176                     left: parseInt(this.getStyle("margin-left"), 10) || 0,
7177                     bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
7178                     right: parseInt(this.getStyle("margin-right"), 10) || 0
7179                 };
7180             }else {
7181                 return  this.addStyles(B9, El.margins);
7182              }
7183         },
7184
7185         
7186         addStyles : function(CA, CB){
7187             var  CC = 0, v, w;
7188             for(var  i = 0, Ak = CA.length; i < Ak; i++){
7189                 v = this.getStyle(CB[CA.charAt(i)]);
7190                 if(v){
7191                      w = parseInt(v, 10);
7192                      if(w){ CC += w; }
7193                 }
7194             }
7195             return  CC;
7196         },
7197
7198         
7199
7200         createProxy : function(CD, CE, CF){
7201             if(CE){
7202                 CE = Roo.getDom(CE);
7203             }else {
7204                 CE = document.body;
7205             }
7206
7207             CD = typeof  CD == "object" ?
7208                 CD : {tag : "div", cls: CD};
7209             var  CG = Roo.DomHelper.append(CE, CD, true);
7210             if(CF){
7211                CG.setBox(this.getBox());
7212             }
7213             return  CG;
7214         },
7215
7216         
7217
7218         mask : function(CH, CI){
7219             if(this.getStyle("position") == "static"){
7220                 this.setStyle("position", "relative");
7221             }
7222             if(!this._mask){
7223                 this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true);
7224             }
7225
7226             this.addClass("x-masked");
7227             this._mask.setDisplayed(true);
7228             if(typeof  CH == 'string'){
7229                 if(!this._maskMsg){
7230                     this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true);
7231                 }
7232                 var  mm = this._maskMsg;
7233                 mm.dom.className = CI ? "roo-el-mask-msg " + CI : "roo-el-mask-msg";
7234                 mm.dom.firstChild.innerHTML = CH;
7235                 mm.setDisplayed(true);
7236                 mm.center(this);
7237             }
7238             if(Roo.isIE && !(Roo.isIE7 && Roo.isStrict) && this.getStyle('height') == 'auto'){ 
7239                 this._mask.setHeight(this.getHeight());
7240             }
7241             return  this._mask;
7242         },
7243
7244         
7245
7246         unmask : function(CJ){
7247             if(this._mask){
7248                 if(CJ === true){
7249                     this._mask.remove();
7250                     delete  this._mask;
7251                     if(this._maskMsg){
7252                         this._maskMsg.remove();
7253                         delete  this._maskMsg;
7254                     }
7255                 }else {
7256                     this._mask.setDisplayed(false);
7257                     if(this._maskMsg){
7258                         this._maskMsg.setDisplayed(false);
7259                     }
7260                 }
7261             }
7262
7263             this.removeClass("x-masked");
7264         },
7265
7266         
7267
7268         isMasked : function(){
7269             return  this._mask && this._mask.isVisible();
7270         },
7271
7272         
7273
7274         createShim : function(){
7275             var  el = document.createElement('iframe');
7276             el.frameBorder = 'no';
7277             el.className = 'roo-shim';
7278             if(Roo.isIE && Roo.isSecure){
7279                 el.src = Roo.SSL_SECURE_URL;
7280             }
7281             var  CK = Roo.get(this.dom.parentNode.insertBefore(el, this.dom));
7282             CK.autoBoxAdjust = false;
7283             return  CK;
7284         },
7285
7286         
7287
7288         remove : function(){
7289             if(this.dom.parentNode){
7290                 this.dom.parentNode.removeChild(this.dom);
7291             }
7292             delete  El.cache[this.dom.id];
7293         },
7294
7295         
7296
7297         addClassOnOver : function(CL, CM){
7298             this.on("mouseover", function(){
7299                 Roo.fly(this, '_internal').addClass(CL);
7300             }, this.dom);
7301             var  CN = function(e){
7302                 if(CM !== true || !e.within(this, true)){
7303                     Roo.fly(this, '_internal').removeClass(CL);
7304                 }
7305             };
7306             this.on("mouseout", CN, this.dom);
7307             return  this;
7308         },
7309
7310         
7311
7312         addClassOnFocus : function(CO){
7313             this.on("focus", function(){
7314                 Roo.fly(this, '_internal').addClass(CO);
7315             }, this.dom);
7316             this.on("blur", function(){
7317                 Roo.fly(this, '_internal').removeClass(CO);
7318             }, this.dom);
7319             return  this;
7320         },
7321         
7322
7323         addClassOnClick : function(CP){
7324             var  CQ = this.dom;
7325             this.on("mousedown", function(){
7326                 Roo.fly(CQ, '_internal').addClass(CP);
7327                 var  d = Roo.get(document);
7328                 var  fn = function(){
7329                     Roo.fly(CQ, '_internal').removeClass(CP);
7330                     d.removeListener("mouseup", fn);
7331                 };
7332                 d.on("mouseup", fn);
7333             });
7334             return  this;
7335         },
7336
7337         
7338
7339         swallowEvent : function(CR, CS){
7340             var  fn = function(e){
7341                 e.stopPropagation();
7342                 if(CS){
7343                     e.preventDefault();
7344                 }
7345             };
7346             if(CR  instanceof  Array){
7347                 for(var  i = 0, Ak = CR.length; i < Ak; i++){
7348                      this.on(CR[i], fn);
7349                 }
7350                 return  this;
7351             }
7352
7353             this.on(CR, fn);
7354             return  this;
7355         },
7356
7357         
7358
7359       fitToParentDelegate : Roo.emptyFn, 
7360
7361         
7362
7363         fitToParent : function(CT, CU) {
7364           Roo.EventManager.removeResizeListener(this.fitToParentDelegate); 
7365           this.fitToParentDelegate = Roo.emptyFn; 
7366           if (CT === true && !this.dom.parentNode) { 
7367             return;
7368           }
7369           var  p = Roo.get(CU || this.dom.parentNode);
7370           this.setSize(p.getComputedWidth() - p.getFrameWidth('lr'), p.getComputedHeight() - p.getFrameWidth('tb'));
7371           if (CT === true) {
7372             this.fitToParentDelegate = this.fitToParent.createDelegate(this, [true, CU]);
7373             Roo.EventManager.onWindowResize(this.fitToParentDelegate);
7374           }
7375           return  this;
7376         },
7377
7378         
7379
7380         getNextSibling : function(){
7381             var  n = this.dom.nextSibling;
7382             while(n && n.nodeType != 1){
7383                 n = n.nextSibling;
7384             }
7385             return  n;
7386         },
7387
7388         
7389
7390         getPrevSibling : function(){
7391             var  n = this.dom.previousSibling;
7392             while(n && n.nodeType != 1){
7393                 n = n.previousSibling;
7394             }
7395             return  n;
7396         },
7397
7398
7399         
7400
7401         appendChild: function(el){
7402             el = Roo.get(el);
7403             el.appendTo(this);
7404             return  this;
7405         },
7406
7407         
7408
7409         createChild: function(CV, CW, CX){
7410             CV = CV || {tag:'div'};
7411             if(CW){
7412                 return  Roo.DomHelper.insertBefore(CW, CV, CX !== true);
7413             }
7414             return  Roo.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, CV,  CX !== true);
7415         },
7416
7417         
7418
7419         appendTo: function(el){
7420             el = Roo.getDom(el);
7421             el.appendChild(this.dom);
7422             return  this;
7423         },
7424
7425         
7426
7427         insertBefore: function(el){
7428             el = Roo.getDom(el);
7429             el.parentNode.insertBefore(this.dom, el);
7430             return  this;
7431         },
7432
7433         
7434
7435         insertAfter: function(el){
7436             el = Roo.getDom(el);
7437             el.parentNode.insertBefore(this.dom, el.nextSibling);
7438             return  this;
7439         },
7440
7441         
7442
7443         insertFirst: function(el, CY){
7444             el = el || {};
7445             if(typeof  el == 'object' && !el.nodeType){ 
7446                 return  this.createChild(el, this.dom.firstChild, CY);
7447             }else {
7448                 el = Roo.getDom(el);
7449                 this.dom.insertBefore(el, this.dom.firstChild);
7450                 return  !CY ? Roo.get(el) : el;
7451             }
7452         },
7453
7454         
7455
7456         insertSibling: function(el, CZ, Ca){
7457             CZ = CZ ? CZ.toLowerCase() : 'before';
7458             el = el || {};
7459             var  rt, Cb = CZ == 'before' ? this.dom : this.dom.nextSibling;
7460
7461             if(typeof  el == 'object' && !el.nodeType){ 
7462                 if(CZ == 'after' && !this.dom.nextSibling){
7463                     rt = Roo.DomHelper.append(this.dom.parentNode, el, !Ca);
7464                 }else {
7465                     rt = Roo.DomHelper[CZ == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !Ca);
7466                 }
7467
7468             }else {
7469                 rt = this.dom.parentNode.insertBefore(Roo.getDom(el),
7470                             CZ == 'before' ? this.dom : this.dom.nextSibling);
7471                 if(!Ca){
7472                     rt = Roo.get(rt);
7473                 }
7474             }
7475             return  rt;
7476         },
7477
7478         
7479
7480         wrap: function(Cc, Cd){
7481             if(!Cc){
7482                 Cc = {tag: "div"};
7483             }
7484             var  Ce = Roo.DomHelper.insertBefore(this.dom, Cc, !Cd);
7485             Ce.dom ? Ce.dom.appendChild(this.dom) : Ce.appendChild(this.dom);
7486             return  Ce;
7487         },
7488
7489         
7490
7491         replace: function(el){
7492             el = Roo.get(el);
7493             this.insertBefore(el);
7494             el.remove();
7495             return  this;
7496         },
7497
7498         
7499
7500         insertHtml : function(Cf, Cg, Ch){
7501             var  el = Roo.DomHelper.insertHtml(Cf, this.dom, Cg);
7502             return  Ch ? Roo.get(el) : el;
7503         },
7504
7505         
7506
7507         set : function(o, Ci){
7508             var  el = this.dom;
7509             Ci = typeof  Ci == 'undefined' ? (el.setAttribute ? true : false) : Ci;
7510             for(var  attr  in  o){
7511                 if(attr == "style" || typeof  o[attr] == "function") continue;
7512                 if(attr=="cls"){
7513                     el.className = o["cls"];
7514                 }else {
7515                     if(Ci) el.setAttribute(attr, o[attr]);
7516                     else  el[attr] = o[attr];
7517                 }
7518             }
7519             if(o.style){
7520                 Roo.DomHelper.applyStyles(el, o.style);
7521             }
7522             return  this;
7523         },
7524
7525         
7526
7527         addKeyListener : function(Cj, fn, Ck){
7528             var  Cl;
7529             if(typeof  Cj != "object" || Cj  instanceof  Array){
7530                 Cl = {
7531                     key: Cj,
7532                     fn: fn,
7533                     scope: Ck
7534                 };
7535             }else {
7536                 Cl = {
7537                     key : Cj.key,
7538                     shift : Cj.shift,
7539                     ctrl : Cj.ctrl,
7540                     alt : Cj.alt,
7541                     fn: fn,
7542                     scope: Ck
7543                 };
7544             }
7545             return  new  Roo.KeyMap(this, Cl);
7546         },
7547
7548         
7549
7550         addKeyMap : function(Cm){
7551             return  new  Roo.KeyMap(this, Cm);
7552         },
7553
7554         
7555
7556          isScrollable : function(){
7557             var  Cn = this.dom;
7558             return  Cn.scrollHeight > Cn.clientHeight || Cn.scrollWidth > Cn.clientWidth;
7559         },
7560
7561         
7562
7563
7564         scrollTo : function(Co, Cp, Cq){
7565             var  Cr = Co.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
7566             if(!Cq || !A){
7567                 this.dom[Cr] = Cp;
7568             }else {
7569                 var  to = Cr == "scrollLeft" ? [Cp, this.dom.scrollTop] : [this.dom.scrollLeft, Cp];
7570                 this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
7571             }
7572             return  this;
7573         },
7574
7575         
7576
7577          scroll : function(Cs, Ct, Cu){
7578              if(!this.isScrollable()){
7579                  return;
7580              }
7581              var  el = this.dom;
7582              var  l = el.scrollLeft, t = el.scrollTop;
7583              var  w = el.scrollWidth, h = el.scrollHeight;
7584              var  cw = el.clientWidth, ch = el.clientHeight;
7585              Cs = Cs.toLowerCase();
7586              var  Cv = false;
7587              var  a = this.preanim(arguments, 2);
7588              switch(Cs){
7589                  case  "l":
7590                  case  "left":
7591                      if(w - l > cw){
7592                          var  v = Math.min(l + Ct, w-cw);
7593                          this.scrollTo("left", v, a);
7594                          Cv = true;
7595                      }
7596                      break;
7597                 case  "r":
7598                 case  "right":
7599                      if(l > 0){
7600                          var  v = Math.max(l - Ct, 0);
7601                          this.scrollTo("left", v, a);
7602                          Cv = true;
7603                      }
7604                      break;
7605                 case  "t":
7606                 case  "top":
7607                 case  "up":
7608                      if(t > 0){
7609                          var  v = Math.max(t - Ct, 0);
7610                          this.scrollTo("top", v, a);
7611                          Cv = true;
7612                      }
7613                      break;
7614                 case  "b":
7615                 case  "bottom":
7616                 case  "down":
7617                      if(h - t > ch){
7618                          var  v = Math.min(t + Ct, h-ch);
7619                          this.scrollTo("top", v, a);
7620                          Cv = true;
7621                      }
7622                      break;
7623              }
7624              return  Cv;
7625         },
7626
7627         
7628
7629         translatePoints : function(x, y){
7630             if(typeof  x == 'object' || x  instanceof  Array){
7631                 y = x[1]; x = x[0];
7632             }
7633             var  p = this.getStyle('position');
7634             var  o = this.getXY();
7635
7636             var  l = parseInt(this.getStyle('left'), 10);
7637             var  t = parseInt(this.getStyle('top'), 10);
7638
7639             if(isNaN(l)){
7640                 l = (p == "relative") ? 0 : this.dom.offsetLeft;
7641             }
7642             if(isNaN(t)){
7643                 t = (p == "relative") ? 0 : this.dom.offsetTop;
7644             }
7645
7646             return  {left: (x - o[0] + l), top: (y - o[1] + t)};
7647         },
7648
7649         
7650
7651         getScroll : function(){
7652             var  d = this.dom, Cw = document;
7653             if(d == Cw || d == Cw.body){
7654                 var  l = window.pageXOffset || Cw.documentElement.scrollLeft || Cw.body.scrollLeft || 0;
7655                 var  t = window.pageYOffset || Cw.documentElement.scrollTop || Cw.body.scrollTop || 0;
7656                 return  {left: l, top: t};
7657             }else {
7658                 return  {left: d.scrollLeft, top: d.scrollTop};
7659             }
7660         },
7661
7662         
7663
7664         getColor : function(Cx, Cy, Cz){
7665             var  v = this.getStyle(Cx);
7666             if(!v || v == "transparent" || v == "inherit") {
7667                 return  Cy;
7668             }
7669             var  C0 = typeof  Cz == "undefined" ? "#" : Cz;
7670             if(v.substr(0, 4) == "rgb("){
7671                 var  rvs = v.slice(4, v.length -1).split(",");
7672                 for(var  i = 0; i < 3; i++){
7673                     var  h = parseInt(rvs[i]).toString(16);
7674                     if(h < 16){
7675                         h = "0" + h;
7676                     }
7677
7678                     C0 += h;
7679                 }
7680             } else  {
7681                 if(v.substr(0, 1) == "#"){
7682                     if(v.length == 4) {
7683                         for(var  i = 1; i < 4; i++){
7684                             var  c = v.charAt(i);
7685                             C0 +=  c + c;
7686                         }
7687                     }else  if(v.length == 7){
7688                         C0 += v.substr(1);
7689                     }
7690                 }
7691             }
7692             return (C0.length > 5 ? C0.toLowerCase() : Cy);
7693         },
7694
7695         
7696
7697         boxWrap : function(C1){
7698             C1 = C1 || 'x-box';
7699             var  el = Roo.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', C1)));
7700             el.child('.'+C1+'-mc').dom.appendChild(this.dom);
7701             return  el;
7702         },
7703
7704         
7705
7706         getAttributeNS : Roo.isIE ? function(ns, C2){
7707             var  d = this.dom;
7708             var  C3 = typeof  d[ns+":"+C2];
7709             if(C3 != 'undefined' && C3 != 'unknown'){
7710                 return  d[ns+":"+C2];
7711             }
7712             return  d[C2];
7713         } : function(ns, C4){
7714             var  d = this.dom;
7715             return  d.getAttributeNS(ns, C4) || d.getAttribute(ns+":"+C4) || d.getAttribute(C4) || d[C4];
7716         }
7717     };
7718
7719     var  ep = El.prototype;
7720
7721     
7722
7723     ep.on = ep.addListener;
7724         
7725     ep.mon = ep.addListener;
7726
7727     
7728
7729     ep.un = ep.removeListener;
7730
7731     
7732
7733     ep.autoBoxAdjust = true;
7734
7735     
7736     El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
7737
7738     
7739     El.addUnits = function(v, J){
7740         if(v === "" || v == "auto"){
7741             return  v;
7742         }
7743         if(v === undefined){
7744             return  '';
7745         }
7746         if(typeof  v == "number" || !El.unitPattern.test(v)){
7747             return  v + (J || 'px');
7748         }
7749         return  v;
7750     };
7751
7752     
7753     El.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
7754     
7755
7756     El.VISIBILITY = 1;
7757     
7758
7759     El.DISPLAY = 2;
7760
7761     El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
7762     El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
7763     El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
7764
7765
7766
7767     
7768
7769     El.cache = {};
7770
7771     var  H;
7772
7773     
7774
7775     El.get = function(el){
7776         var  ex, J, id;
7777         if(!el){ return  null; }
7778         if(typeof  el == "string"){ 
7779             if(!(J = document.getElementById(el))){
7780                 return  null;
7781             }
7782             if(ex = El.cache[el]){
7783                 ex.dom = J;
7784             }else {
7785                 ex = El.cache[el] = new  El(J);
7786             }
7787             return  ex;
7788         }else  if(el.tagName){ 
7789             if(!(id = el.id)){
7790                 id = Roo.id(el);
7791             }
7792             if(ex = El.cache[id]){
7793                 ex.dom = el;
7794             }else {
7795                 ex = El.cache[id] = new  El(el);
7796             }
7797             return  ex;
7798         }else  if(el  instanceof  El){
7799             if(el != H){
7800                 el.dom = document.getElementById(el.id) || el.dom; 
7801                                                               
7802                 El.cache[el.id] = el; 
7803             }
7804             return  el;
7805         }else  if(el.isComposite){
7806             return  el;
7807         }else  if(el  instanceof  Array){
7808             return  El.select(el);
7809         }else  if(el == document){
7810             
7811             if(!H){
7812                 var  f = function(){};
7813                 f.prototype = El.prototype;
7814                 H = new  f();
7815                 H.dom = document;
7816             }
7817             return  H;
7818         }
7819         return  null;
7820     };
7821
7822     
7823     El.uncache = function(el){
7824         for(var  i = 0, a = arguments, len = a.length; i < len; i++) {
7825             if(a[i]){
7826                 delete  El.cache[a[i].id || a[i]];
7827             }
7828         }
7829     };
7830
7831     
7832     
7833     
7834     El.garbageCollect = function(){
7835         if(!Roo.enableGarbageCollector){
7836             clearInterval(El.collectorThread);
7837             return;
7838         }
7839         for(var  eid  in  El.cache){
7840             var  el = El.cache[eid], d = el.dom;
7841             
7842             
7843             
7844             
7845             
7846             
7847             
7848             
7849             
7850             
7851             
7852             
7853             
7854             
7855             
7856             
7857             
7858             if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
7859                 delete  El.cache[eid];
7860                 if(d && Roo.enableListenerCollection){
7861                     E.purgeElement(d);
7862                 }
7863             }
7864         }
7865     }
7866
7867     El.collectorThreadId = setInterval(El.garbageCollect, 30000);
7868
7869
7870     
7871     El.Flyweight = function(J){
7872         this.dom = J;
7873     };
7874     El.Flyweight.prototype = El.prototype;
7875
7876     El._flyweights = {};
7877     
7878
7879     El.fly = function(el, J){
7880         J = J || '_global';
7881         el = Roo.getDom(el);
7882         if(!el){
7883             return  null;
7884         }
7885         if(!El._flyweights[J]){
7886             El._flyweights[J] = new  El.Flyweight();
7887         }
7888
7889         El._flyweights[J].dom = el;
7890         return  El._flyweights[J];
7891     };
7892
7893     
7894
7895     Roo.get = El.get;
7896     
7897
7898     Roo.fly = El.fly;
7899
7900     
7901     var  I = Roo.isStrict ? {
7902         select:1
7903     } : {
7904         input:1, select:1, textarea:1
7905     };
7906     if(Roo.isIE || Roo.isGecko){
7907         I['button'] = 1;
7908     }
7909
7910
7911
7912     Roo.EventManager.on(window, 'unload', function(){
7913         delete  El.cache;
7914         delete  El._flyweights;
7915     });
7916 })();
7917
7918
7919
7920
7921 if(Roo.DomQuery){
7922     Roo.Element.selectorFunction = Roo.DomQuery.select;
7923 }
7924
7925
7926 Roo.Element.select = function(J, K, L){
7927     var  M;
7928     if(typeof  J == "string"){
7929         M = Roo.Element.selectorFunction(J, L);
7930     }else  if(J.length !== undefined){
7931         M = J;
7932     }else {
7933         throw  "Invalid selector";
7934     }
7935     if(K === true){
7936         return  new  Roo.CompositeElement(M);
7937     }else {
7938         return  new  Roo.CompositeElementLite(M);
7939     }
7940 };
7941
7942
7943 Roo.select = Roo.Element.select;
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965 Roo.enableFx = true;
7966
7967
7968
7969 Roo.Fx = {
7970         
7971
7972     slideIn : function(A, o){
7973         var  el = this.getFxEl();
7974         o = o || {};
7975
7976         el.queueFx(o, function(){
7977
7978             A = A || "t";
7979
7980             
7981             this.fixDisplay();
7982
7983             
7984             var  r = this.getFxRestore();
7985             var  b = this.getBox();
7986             
7987             this.setSize(b);
7988
7989             
7990             var  B = this.fxWrap(r.pos, o, "hidden");
7991
7992             var  st = this.dom.style;
7993             st.visibility = "visible";
7994             st.position = "absolute";
7995
7996             
7997             var  C = function(){
7998                 el.fxUnwrap(B, r.pos, o);
7999                 st.width = r.width;
8000                 st.height = r.height;
8001                 el.afterFx(o);
8002             };
8003             
8004             var  a, pt = {to: [b.x, b.y]}, bw = {to: b.width}, bh = {to: b.height};
8005
8006             switch(A.toLowerCase()){
8007                 case  "t":
8008                     B.setSize(b.width, 0);
8009                     st.left = st.bottom = "0";
8010                     a = {height: bh};
8011                 break;
8012                 case  "l":
8013                     B.setSize(0, b.height);
8014                     st.right = st.top = "0";
8015                     a = {width: bw};
8016                 break;
8017                 case  "r":
8018                     B.setSize(0, b.height);
8019                     B.setX(b.right);
8020                     st.left = st.top = "0";
8021                     a = {width: bw, points: pt};
8022                 break;
8023                 case  "b":
8024                     B.setSize(b.width, 0);
8025                     B.setY(b.bottom);
8026                     st.left = st.top = "0";
8027                     a = {height: bh, points: pt};
8028                 break;
8029                 case  "tl":
8030                     B.setSize(0, 0);
8031                     st.right = st.bottom = "0";
8032                     a = {width: bw, height: bh};
8033                 break;
8034                 case  "bl":
8035                     B.setSize(0, 0);
8036                     B.setY(b.y+b.height);
8037                     st.right = st.top = "0";
8038                     a = {width: bw, height: bh, points: pt};
8039                 break;
8040                 case  "br":
8041                     B.setSize(0, 0);
8042                     B.setXY([b.right, b.bottom]);
8043                     st.left = st.top = "0";
8044                     a = {width: bw, height: bh, points: pt};
8045                 break;
8046                 case  "tr":
8047                     B.setSize(0, 0);
8048                     B.setX(b.x+b.width);
8049                     st.left = st.bottom = "0";
8050                     a = {width: bw, height: bh, points: pt};
8051                 break;
8052             }
8053
8054             this.dom.style.visibility = "visible";
8055             B.show();
8056
8057             arguments.callee.anim = B.fxanim(a,
8058                 o,
8059                 'motion',
8060                 .5,
8061                 'easeOut', C);
8062         });
8063         return  this;
8064     },
8065     
8066         
8067
8068     slideOut : function(B, o){
8069         var  el = this.getFxEl();
8070         o = o || {};
8071
8072         el.queueFx(o, function(){
8073
8074             B = B || "t";
8075
8076             
8077             var  r = this.getFxRestore();
8078             
8079             var  b = this.getBox();
8080             
8081             this.setSize(b);
8082
8083             
8084             var  C = this.fxWrap(r.pos, o, "visible");
8085
8086             var  st = this.dom.style;
8087             st.visibility = "visible";
8088             st.position = "absolute";
8089
8090             C.setSize(b);
8091
8092             var  D = function(){
8093                 if(o.useDisplay){
8094                     el.setDisplayed(false);
8095                 }else {
8096                     el.hide();
8097                 }
8098
8099
8100                 el.fxUnwrap(C, r.pos, o);
8101
8102                 st.width = r.width;
8103                 st.height = r.height;
8104
8105                 el.afterFx(o);
8106             };
8107
8108             var  a, E = {to: 0};
8109             switch(B.toLowerCase()){
8110                 case  "t":
8111                     st.left = st.bottom = "0";
8112                     a = {height: E};
8113                 break;
8114                 case  "l":
8115                     st.right = st.top = "0";
8116                     a = {width: E};
8117                 break;
8118                 case  "r":
8119                     st.left = st.top = "0";
8120                     a = {width: E, points: {to:[b.right, b.y]}};
8121                 break;
8122                 case  "b":
8123                     st.left = st.top = "0";
8124                     a = {height: E, points: {to:[b.x, b.bottom]}};
8125                 break;
8126                 case  "tl":
8127                     st.right = st.bottom = "0";
8128                     a = {width: E, height: E};
8129                 break;
8130                 case  "bl":
8131                     st.right = st.top = "0";
8132                     a = {width: E, height: E, points: {to:[b.x, b.bottom]}};
8133                 break;
8134                 case  "br":
8135                     st.left = st.top = "0";
8136                     a = {width: E, height: E, points: {to:[b.x+b.width, b.bottom]}};
8137                 break;
8138                 case  "tr":
8139                     st.left = st.bottom = "0";
8140                     a = {width: E, height: E, points: {to:[b.right, b.y]}};
8141                 break;
8142             }
8143
8144
8145             arguments.callee.anim = C.fxanim(a,
8146                 o,
8147                 'motion',
8148                 .5,
8149                 "easeOut", D);
8150         });
8151         return  this;
8152     },
8153
8154         
8155
8156     puff : function(o){
8157         var  el = this.getFxEl();
8158         o = o || {};
8159
8160         el.queueFx(o, function(){
8161             this.clearOpacity();
8162             this.show();
8163
8164             
8165             var  r = this.getFxRestore();
8166             var  st = this.dom.style;
8167
8168             var  C = function(){
8169                 if(o.useDisplay){
8170                     el.setDisplayed(false);
8171                 }else {
8172                     el.hide();
8173                 }
8174
8175
8176                 el.clearOpacity();
8177
8178                 el.setPositioning(r.pos);
8179                 st.width = r.width;
8180                 st.height = r.height;
8181                 st.fontSize = '';
8182                 el.afterFx(o);
8183             };
8184
8185             var  D = this.getWidth();
8186             var  E = this.getHeight();
8187
8188             arguments.callee.anim = this.fxanim({
8189                     width : {to: this.adjustWidth(D * 2)},
8190                     height : {to: this.adjustHeight(E * 2)},
8191                     points : {by: [-(D * .5), -(E * .5)]},
8192                     opacity : {to: 0},
8193                     fontSize: {to:200, unit: "%"}
8194                 },
8195                 o,
8196                 'motion',
8197                 .5,
8198                 "easeOut", C);
8199         });
8200         return  this;
8201     },
8202
8203         
8204
8205     switchOff : function(o){
8206         var  el = this.getFxEl();
8207         o = o || {};
8208
8209         el.queueFx(o, function(){
8210             this.clearOpacity();
8211             this.clip();
8212
8213             
8214             var  r = this.getFxRestore();
8215             var  st = this.dom.style;
8216
8217             var  C = function(){
8218                 if(o.useDisplay){
8219                     el.setDisplayed(false);
8220                 }else {
8221                     el.hide();
8222                 }
8223
8224
8225                 el.clearOpacity();
8226                 el.setPositioning(r.pos);
8227                 st.width = r.width;
8228                 st.height = r.height;
8229
8230                 el.afterFx(o);
8231             };
8232
8233             this.fxanim({opacity:{to:0.3}}, null, null, .1, null, function(){
8234                 this.clearOpacity();
8235                 (function(){
8236                     this.fxanim({
8237                         height:{to:1},
8238                         points:{by:[0, this.getHeight() * .5]}
8239                     }, o, 'motion', 0.3, 'easeIn', C);
8240                 }).defer(100, this);
8241             });
8242         });
8243         return  this;
8244     },
8245
8246     
8247         
8248     highlight : function(C, o){
8249         var  el = this.getFxEl();
8250         o = o || {};
8251
8252         el.queueFx(o, function(){
8253             C = C || "ffff9c";
8254             attr = o.attr || "backgroundColor";
8255
8256             this.clearOpacity();
8257             this.show();
8258
8259             var  D = this.getColor(attr);
8260             var  E = this.dom.style[attr];
8261             endColor = (o.endColor || D) || "ffffff";
8262
8263             var  F = function(){
8264                 el.dom.style[attr] = E;
8265                 el.afterFx(o);
8266             };
8267
8268             var  a = {};
8269             a[attr] = {from: C, to: endColor};
8270             arguments.callee.anim = this.fxanim(a,
8271                 o,
8272                 'color',
8273                 1,
8274                 'easeIn', F);
8275         });
8276         return  this;
8277     },
8278
8279    
8280
8281     frame : function(D, E, o){
8282         var  el = this.getFxEl();
8283         o = o || {};
8284
8285         el.queueFx(o, function(){
8286             D = D || "#C3DAF9";
8287             if(D.length == 6){
8288                 D = "#" + D;
8289             }
8290
8291             E = E || 1;
8292             duration = o.duration || 1;
8293             this.show();
8294
8295             var  b = this.getBox();
8296             var  F = function(){
8297                 var  G = this.createProxy({
8298
8299                      style:{
8300                         visbility:"hidden",
8301                         position:"absolute",
8302                         "z-index":"35000", 
8303                         border:"0px solid " + D
8304                      }
8305                   });
8306                 var  H = Roo.isBorderBox ? 2 : 1;
8307                 G.animate({
8308                     top:{from:b.y, to:b.y - 20},
8309                     left:{from:b.x, to:b.x - 20},
8310                     borderWidth:{from:0, to:10},
8311                     opacity:{from:1, to:0},
8312                     height:{from:b.height, to:(b.height + (20*H))},
8313                     width:{from:b.width, to:(b.width + (20*H))}
8314                 }, duration, function(){
8315                     G.remove();
8316                 });
8317                 if(--E > 0){
8318                      F.defer((duration/2)*1000, this);
8319                 }else {
8320                     el.afterFx(o);
8321                 }
8322             };
8323             F.call(this);
8324         });
8325         return  this;
8326     },
8327
8328    
8329
8330     pause : function(F){
8331         var  el = this.getFxEl();
8332         var  o = {};
8333
8334         el.queueFx(o, function(){
8335             setTimeout(function(){
8336                 el.afterFx(o);
8337             }, F * 1000);
8338         });
8339         return  this;
8340     },
8341
8342    
8343
8344     fadeIn : function(o){
8345         var  el = this.getFxEl();
8346         o = o || {};
8347         el.queueFx(o, function(){
8348             this.setOpacity(0);
8349             this.fixDisplay();
8350             this.dom.style.visibility = 'visible';
8351             var  to = o.endOpacity || 1;
8352             arguments.callee.anim = this.fxanim({opacity:{to:to}},
8353                 o, null, .5, "easeOut", function(){
8354                 if(to == 1){
8355                     this.clearOpacity();
8356                 }
8357
8358                 el.afterFx(o);
8359             });
8360         });
8361         return  this;
8362     },
8363
8364    
8365
8366     fadeOut : function(o){
8367         var  el = this.getFxEl();
8368         o = o || {};
8369         el.queueFx(o, function(){
8370             arguments.callee.anim = this.fxanim({opacity:{to:o.endOpacity || 0}},
8371                 o, null, .5, "easeOut", function(){
8372                 if(this.visibilityMode == Roo.Element.DISPLAY || o.useDisplay){
8373                      this.dom.style.display = "none";
8374                 }else {
8375                      this.dom.style.visibility = "hidden";
8376                 }
8377
8378                 this.clearOpacity();
8379                 el.afterFx(o);
8380             });
8381         });
8382         return  this;
8383     },
8384
8385    
8386
8387     scale : function(w, h, o){
8388         this.shift(Roo.apply({}, o, {
8389             width: w,
8390             height: h
8391         }));
8392         return  this;
8393     },
8394
8395    
8396
8397     shift : function(o){
8398         var  el = this.getFxEl();
8399         o = o || {};
8400         el.queueFx(o, function(){
8401             var  a = {}, w = o.width, h = o.height, x = o.x, y = o.y,  op = o.opacity;
8402             if(w !== undefined){
8403                 a.width = {to: this.adjustWidth(w)};
8404             }
8405             if(h !== undefined){
8406                 a.height = {to: this.adjustHeight(h)};
8407             }
8408             if(x !== undefined || y !== undefined){
8409                 a.points = {to: [
8410                     x !== undefined ? x : this.getX(),
8411                     y !== undefined ? y : this.getY()
8412                 ]};
8413             }
8414             if(op !== undefined){
8415                 a.opacity = {to: op};
8416             }
8417             if(o.xy !== undefined){
8418                 a.points = {to: o.xy};
8419             }
8420
8421             arguments.callee.anim = this.fxanim(a,
8422                 o, 'motion', .35, "easeOut", function(){
8423                 el.afterFx(o);
8424             });
8425         });
8426         return  this;
8427     },
8428
8429         
8430
8431     ghost : function(G, o){
8432         var  el = this.getFxEl();
8433         o = o || {};
8434
8435         el.queueFx(o, function(){
8436             G = G || "b";
8437
8438             
8439             var  r = this.getFxRestore();
8440             var  w = this.getWidth(),
8441                 h = this.getHeight();
8442
8443             var  st = this.dom.style;
8444
8445             var  H = function(){
8446                 if(o.useDisplay){
8447                     el.setDisplayed(false);
8448                 }else {
8449                     el.hide();
8450                 }
8451
8452
8453                 el.clearOpacity();
8454                 el.setPositioning(r.pos);
8455                 st.width = r.width;
8456                 st.height = r.height;
8457
8458                 el.afterFx(o);
8459             };
8460
8461             var  a = {opacity: {to: 0}, points: {}}, pt = a.points;
8462             switch(G.toLowerCase()){
8463                 case  "t":
8464                     pt.by = [0, -h];
8465                 break;
8466                 case  "l":
8467                     pt.by = [-w, 0];
8468                 break;
8469                 case  "r":
8470                     pt.by = [w, 0];
8471                 break;
8472                 case  "b":
8473                     pt.by = [0, h];
8474                 break;
8475                 case  "tl":
8476                     pt.by = [-w, -h];
8477                 break;
8478                 case  "bl":
8479                     pt.by = [-w, h];
8480                 break;
8481                 case  "br":
8482                     pt.by = [w, h];
8483                 break;
8484                 case  "tr":
8485                     pt.by = [w, -h];
8486                 break;
8487             }
8488
8489
8490             arguments.callee.anim = this.fxanim(a,
8491                 o,
8492                 'motion',
8493                 .5,
8494                 "easeOut", H);
8495         });
8496         return  this;
8497     },
8498
8499         
8500
8501     syncFx : function(){
8502         this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
8503             block : false,
8504             concurrent : true,
8505             stopFx : false
8506         });
8507         return  this;
8508     },
8509
8510         
8511
8512     sequenceFx : function(){
8513         this.fxDefaults = Roo.apply(this.fxDefaults || {}, {
8514             block : false,
8515             concurrent : false,
8516             stopFx : false
8517         });
8518         return  this;
8519     },
8520
8521         
8522
8523     nextFx : function(){
8524         var  ef = this.fxQueue[0];
8525         if(ef){
8526             ef.call(this);
8527         }
8528     },
8529
8530         
8531
8532     hasActiveFx : function(){
8533         return  this.fxQueue && this.fxQueue[0];
8534     },
8535
8536         
8537
8538     stopFx : function(){
8539         if(this.hasActiveFx()){
8540             var  cur = this.fxQueue[0];
8541             if(cur && cur.anim && cur.anim.isAnimated()){
8542                 this.fxQueue = [cur]; 
8543                 cur.anim.stop(true);
8544             }
8545         }
8546         return  this;
8547     },
8548
8549         
8550
8551     beforeFx : function(o){
8552         if(this.hasActiveFx() && !o.concurrent){
8553            if(o.stopFx){
8554                this.stopFx();
8555                return  true;
8556            }
8557            return  false;
8558         }
8559         return  true;
8560     },
8561
8562         
8563
8564     hasFxBlock : function(){
8565         var  q = this.fxQueue;
8566         return  q && q[0] && q[0].block;
8567     },
8568
8569         
8570
8571     queueFx : function(o, fn){
8572         if(!this.fxQueue){
8573             this.fxQueue = [];
8574         }
8575         if(!this.hasFxBlock()){
8576             Roo.applyIf(o, this.fxDefaults);
8577             if(!o.concurrent){
8578                 var  run = this.beforeFx(o);
8579                 fn.block = o.block;
8580                 this.fxQueue.push(fn);
8581                 if(run){
8582                     this.nextFx();
8583                 }
8584             }else {
8585                 fn.call(this);
8586             }
8587         }
8588         return  this;
8589     },
8590
8591         
8592
8593     fxWrap : function(H, o, I){
8594         var  J;
8595         if(!o.wrap || !(J = Roo.get(o.wrap))){
8596             var  wrapXY;
8597             if(o.fixPosition){
8598                 wrapXY = this.getXY();
8599             }
8600             var  div = document.createElement("div");
8601             div.style.visibility = I;
8602             J = Roo.get(this.dom.parentNode.insertBefore(div, this.dom));
8603             J.setPositioning(H);
8604             if(J.getStyle("position") == "static"){
8605                 J.position("relative");
8606             }
8607
8608             this.clearPositioning('auto');
8609             J.clip();
8610             J.dom.appendChild(this.dom);
8611             if(wrapXY){
8612                 J.setXY(wrapXY);
8613             }
8614         }
8615         return  J;
8616     },
8617
8618         
8619
8620     fxUnwrap : function(K, L, o){
8621         this.clearPositioning();
8622         this.setPositioning(L);
8623         if(!o.wrap){
8624             K.dom.parentNode.insertBefore(this.dom, K.dom);
8625             K.remove();
8626         }
8627     },
8628
8629         
8630
8631     getFxRestore : function(){
8632         var  st = this.dom.style;
8633         return  {pos: this.getPositioning(), width: st.width, height : st.height};
8634     },
8635
8636         
8637
8638     afterFx : function(o){
8639         if(o.afterStyle){
8640             this.applyStyles(o.afterStyle);
8641         }
8642         if(o.afterCls){
8643             this.addClass(o.afterCls);
8644         }
8645         if(o.remove === true){
8646             this.remove();
8647         }
8648
8649         Roo.callback(o.callback, o.scope, [this]);
8650         if(!o.concurrent){
8651             this.fxQueue.shift();
8652             this.nextFx();
8653         }
8654     },
8655
8656         
8657
8658     getFxEl : function(){ 
8659         return  Roo.get(this.dom);
8660     },
8661
8662         
8663
8664     fxanim : function(M, N, O, P, Q, cb){
8665         O = O || 'run';
8666         N = N || {};
8667         var  R = Roo.lib.Anim[O](
8668             this.dom, M,
8669             (N.duration || P) || .35,
8670             (N.easing || Q) || 'easeOut',
8671             function(){
8672                 Roo.callback(cb, this);
8673             },
8674             this
8675         );
8676         N.anim = R;
8677         return  R;
8678     }
8679 };
8680
8681
8682 Roo.Fx.resize = Roo.Fx.scale;
8683
8684
8685
8686 Roo.apply(Roo.Element.prototype, Roo.Fx);
8687
8688
8689
8690
8691
8692
8693 Roo.CompositeElement = function(A){
8694     this.elements = [];
8695     this.addElements(A);
8696 };
8697 Roo.CompositeElement.prototype = {
8698     isComposite: true,
8699     addElements : function(B){
8700         if(!B) return  this;
8701         if(typeof  B == "string"){
8702             B = Roo.Element.selectorFunction(B);
8703         }
8704         var  C = this.elements;
8705         var  D = C.length-1;
8706         for(var  i = 0, len = B.length; i < len; i++) {
8707                 C[++D] = Roo.get(B[i]);
8708         }
8709         return  this;
8710     },
8711
8712     
8713
8714     fill : function(E){
8715         this.elements = [];
8716         this.add(E);
8717         return  this;
8718     },
8719
8720     
8721
8722     filter : function(F){
8723         var  G = [];
8724         this.each(function(el){
8725             if(el.is(F)){
8726                 G[G.length] = el.dom;
8727             }
8728         });
8729         this.fill(G);
8730         return  this;
8731     },
8732
8733     invoke : function(fn, H){
8734         var  I = this.elements;
8735         for(var  i = 0, len = I.length; i < len; i++) {
8736                 Roo.Element.prototype[fn].apply(I[i], H);
8737         }
8738         return  this;
8739     },
8740     
8741
8742     add : function(J){
8743         if(typeof  J == "string"){
8744             this.addElements(Roo.Element.selectorFunction(J));
8745         }else  if(J.length !== undefined){
8746             this.addElements(J);
8747         }else {
8748             this.addElements([J]);
8749         }
8750         return  this;
8751     },
8752     
8753
8754     each : function(fn, K){
8755         var  L = this.elements;
8756         for(var  i = 0, len = L.length; i < len; i++){
8757             if(fn.call(K || L[i], L[i], this, i) === false) {
8758                 break;
8759             }
8760         }
8761         return  this;
8762     },
8763
8764     
8765
8766     item : function(M){
8767         return  this.elements[M] || null;
8768     },
8769
8770     
8771
8772     first : function(){
8773         return  this.item(0);
8774     },
8775
8776     
8777
8778     last : function(){
8779         return  this.item(this.elements.length-1);
8780     },
8781
8782     
8783
8784     getCount : function(){
8785         return  this.elements.length;
8786     },
8787
8788     
8789
8790     contains : function(el){
8791         return  this.indexOf(el) !== -1;
8792     },
8793
8794     
8795
8796     indexOf : function(el){
8797         return  this.elements.indexOf(Roo.get(el));
8798     },
8799
8800
8801     
8802
8803     removeElement : function(el, N){
8804         if(el  instanceof  Array){
8805             for(var  i = 0, len = el.length; i < len; i++){
8806                 this.removeElement(el[i]);
8807             }
8808             return  this;
8809         }
8810         var  O = typeof  el == 'number' ? el : this.indexOf(el);
8811         if(O !== -1){
8812             if(N){
8813                 var  d = this.elements[O];
8814                 if(d.dom){
8815                     d.remove();
8816                 }else {
8817                     d.parentNode.removeChild(d);
8818                 }
8819             }
8820
8821             this.elements.splice(O, 1);
8822         }
8823         return  this;
8824     },
8825
8826     
8827
8828     replaceElement : function(el, P, Q){
8829         var  R = typeof  el == 'number' ? el : this.indexOf(el);
8830         if(R !== -1){
8831             if(Q){
8832                 this.elements[R].replaceWith(P);
8833             }else {
8834                 this.elements.splice(R, 1, Roo.get(P))
8835             }
8836         }
8837         return  this;
8838     },
8839
8840     
8841
8842     clear : function(){
8843         this.elements = [];
8844     }
8845 };
8846 (function(){
8847     Roo.CompositeElement.createCall = function(S, T){
8848         if(!S[T]){
8849             S[T] = function(){
8850                 return  this.invoke(T, arguments);
8851             };
8852         }
8853     };
8854     for(var  fnName  in  Roo.Element.prototype){
8855         if(typeof  Roo.Element.prototype[fnName] == "function"){
8856             Roo.CompositeElement.createCall(Roo.CompositeElement.prototype, fnName);
8857         }
8858     };
8859 })();
8860
8861
8862
8863
8864
8865
8866 Roo.CompositeElementLite = function(A){
8867     Roo.CompositeElementLite.superclass.constructor.call(this, A);
8868     this.el = new  Roo.Element.Flyweight();
8869 };
8870 Roo.extend(Roo.CompositeElementLite, Roo.CompositeElement, {
8871     addElements : function(B){
8872         if(B){
8873             if(B  instanceof  Array){
8874                 this.elements = this.elements.concat(B);
8875             }else {
8876                 var  yels = this.elements;
8877                 var  index = yels.length-1;
8878                 for(var  i = 0, len = B.length; i < len; i++) {
8879                     yels[++index] = B[i];
8880                 }
8881             }
8882         }
8883         return  this;
8884     },
8885     invoke : function(fn, C){
8886         var  D = this.elements;
8887         var  el = this.el;
8888         for(var  i = 0, len = D.length; i < len; i++) {
8889             el.dom = D[i];
8890                 Roo.Element.prototype[fn].apply(el, C);
8891         }
8892         return  this;
8893     },
8894     
8895
8896     item : function(E){
8897         if(!this.elements[E]){
8898             return  null;
8899         }
8900
8901         this.el.dom = this.elements[E];
8902         return  this.el;
8903     },
8904
8905     
8906     addListener : function(F, G, H, I){
8907         var  J = this.elements;
8908         for(var  i = 0, len = J.length; i < len; i++) {
8909             Roo.EventManager.on(J[i], F, G, H || J[i], I);
8910         }
8911         return  this;
8912     },
8913
8914     
8915
8916     each : function(fn, K){
8917         var  L = this.elements;
8918         var  el = this.el;
8919         for(var  i = 0, len = L.length; i < len; i++){
8920             el.dom = L[i];
8921                 if(fn.call(K || el, el, this, i) === false){
8922                 break;
8923             }
8924         }
8925         return  this;
8926     },
8927
8928     indexOf : function(el){
8929         return  this.elements.indexOf(Roo.getDom(el));
8930     },
8931
8932     replaceElement : function(el, M, N){
8933         var  O = typeof  el == 'number' ? el : this.indexOf(el);
8934         if(O !== -1){
8935             M = Roo.getDom(M);
8936             if(N){
8937                 var  d = this.elements[O];
8938                 d.parentNode.insertBefore(M, d);
8939                 d.parentNode.removeChild(d);
8940             }
8941
8942             this.elements.splice(O, 1, M);
8943         }
8944         return  this;
8945     }
8946 });
8947 Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addListener;
8948
8949
8950
8951
8952
8953  
8954
8955
8956
8957 Roo.data.Connection = function(A){
8958     Roo.apply(this, A);
8959     this.addEvents({
8960         
8961
8962         "beforerequest" : true,
8963         
8964
8965         "requestcomplete" : true,
8966         
8967
8968         "requestexception" : true
8969     });
8970     Roo.data.Connection.superclass.constructor.call(this);
8971 };
8972
8973 Roo.extend(Roo.data.Connection, Roo.util.Observable, {
8974     
8975
8976     
8977
8978     
8979
8980     
8981
8982     
8983
8984     timeout : 30000,
8985     
8986
8987     autoAbort:false,
8988
8989     
8990
8991     disableCaching: true,
8992
8993     
8994
8995     request : function(o){
8996         if(this.fireEvent("beforerequest", this, o) !== false){
8997             var  p = o.params;
8998
8999             if(typeof  p == "function"){
9000                 p = p.call(o.scope||window, o);
9001             }
9002             if(typeof  p == "object"){
9003                 p = Roo.urlEncode(o.params);
9004             }
9005             if(this.extraParams){
9006                 var  extras = Roo.urlEncode(this.extraParams);
9007                 p = p ? (p + '&' + extras) : extras;
9008             }
9009
9010             var  url = o.url || this.url;
9011             if(typeof  url == 'function'){
9012                 url = url.call(o.scope||window, o);
9013             }
9014
9015             if(o.form){
9016                 var  form = Roo.getDom(o.form);
9017                 url = url || form.action;
9018
9019                 var  enctype = form.getAttribute("enctype");
9020                 if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){
9021                     return  this.doFormUpload(o, p, url);
9022                 }
9023                 var  f = Roo.lib.Ajax.serializeForm(form);
9024                 p = p ? (p + '&' + f) : f;
9025             }
9026
9027             var  hs = o.headers;
9028             if(this.defaultHeaders){
9029                 hs = Roo.apply(hs || {}, this.defaultHeaders);
9030                 if(!o.headers){
9031                     o.headers = hs;
9032                 }
9033             }
9034
9035             var  cb = {
9036                 success: this.handleResponse,
9037                 failure: this.handleFailure,
9038                 scope: this,
9039                 argument: {options: o},
9040                 timeout : this.timeout
9041             };
9042
9043             var  method = o.method||this.method||(p ? "POST" : "GET");
9044
9045             if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
9046                 url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new  Date().getTime());
9047             }
9048
9049             if(typeof  o.autoAbort == 'boolean'){ 
9050                 if(o.autoAbort){
9051                     this.abort();
9052                 }
9053             }else  if(this.autoAbort !== false){
9054                 this.abort();
9055             }
9056
9057             if((method == 'GET' && p) || o.xmlData){
9058                 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
9059                 p = '';
9060             }
9061
9062             this.transId = Roo.lib.Ajax.request(method, url, cb, p, o);
9063             return  this.transId;
9064         }else {
9065             Roo.callback(o.callback, o.scope, [o, null, null]);
9066             return  null;
9067         }
9068     },
9069
9070     
9071
9072     isLoading : function(B){
9073         if(B){
9074             return  Roo.lib.Ajax.isCallInProgress(B);
9075         }else {
9076             return  this.transId ? true : false;
9077         }
9078     },
9079
9080     
9081
9082     abort : function(C){
9083         if(C || this.isLoading()){
9084             Roo.lib.Ajax.abort(C || this.transId);
9085         }
9086     },
9087
9088     
9089     handleResponse : function(D){
9090         this.transId = false;
9091         var  E = D.argument.options;
9092         D.argument = E ? E.argument : null;
9093         this.fireEvent("requestcomplete", this, D, E);
9094         Roo.callback(E.success, E.scope, [D, E]);
9095         Roo.callback(E.callback, E.scope, [E, true, D]);
9096     },
9097
9098     
9099     handleFailure : function(F, e){
9100         this.transId = false;
9101         var  G = F.argument.options;
9102         F.argument = G ? G.argument : null;
9103         this.fireEvent("requestexception", this, F, G, e);
9104         Roo.callback(G.failure, G.scope, [F, G]);
9105         Roo.callback(G.callback, G.scope, [G, false, F]);
9106     },
9107
9108     
9109     doFormUpload : function(o, ps, H){
9110         var  id = Roo.id();
9111         var  I = document.createElement('iframe');
9112         I.id = id;
9113         I.name = id;
9114         I.className = 'x-hidden';
9115         if(Roo.isIE){
9116             I.src = Roo.SSL_SECURE_URL;
9117         }
9118
9119         document.body.appendChild(I);
9120
9121         if(Roo.isIE){
9122            document.frames[id].name = id;
9123         }
9124
9125         var  J = Roo.getDom(o.form);
9126         J.target = id;
9127         J.method = 'POST';
9128         J.enctype = J.encoding = 'multipart/form-data';
9129         if(H){
9130             J.action = H;
9131         }
9132
9133         var  K, hd;
9134         if(ps){ 
9135             K = [];
9136             ps = Roo.urlDecode(ps, false);
9137             for(var  k  in  ps){
9138                 if(ps.hasOwnProperty(k)){
9139                     hd = document.createElement('input');
9140                     hd.type = 'hidden';
9141                     hd.name = k;
9142                     hd.value = ps[k];
9143                     J.appendChild(hd);
9144                     K.push(hd);
9145                 }
9146             }
9147         }
9148
9149         function  cb(){
9150             var  r = {  
9151                 responseText : '',
9152                 responseXML : null
9153             };
9154
9155             r.argument = o ? o.argument : null;
9156
9157             try { 
9158                 var  doc;
9159                 if(Roo.isIE){
9160                     doc = I.contentWindow.document;
9161                 }else  {
9162                     doc = (I.contentDocument || window.frames[id].document);
9163                 }
9164                 if(doc && doc.body){
9165                     r.responseText = doc.body.innerHTML;
9166                 }
9167                 if(doc && doc.XMLDocument){
9168                     r.responseXML = doc.XMLDocument;
9169                 }else  {
9170                     r.responseXML = doc;
9171                 }
9172             }
9173             catch(e) {
9174                 
9175             }
9176
9177
9178             Roo.EventManager.removeListener(I, 'load', cb, this);
9179
9180             this.fireEvent("requestcomplete", this, r, o);
9181             Roo.callback(o.success, o.scope, [r, o]);
9182             Roo.callback(o.callback, o.scope, [o, true, r]);
9183
9184             setTimeout(function(){document.body.removeChild(I);}, 100);
9185         }
9186
9187
9188         Roo.EventManager.on(I, 'load', cb, this);
9189         J.submit();
9190
9191         if(K){ 
9192             for(var  i = 0, len = K.length; i < len; i++){
9193                 J.removeChild(K[i]);
9194             }
9195         }
9196     }
9197 });
9198
9199
9200
9201 Roo.Ajax = new  Roo.data.Connection({
9202     
9203    
9204
9205     
9206
9207     
9208
9209     
9210
9211     
9212
9213     
9214
9215
9216     
9217
9218
9219     
9220
9221     
9222
9223     
9224
9225     
9226
9227     
9228
9229     
9230
9231
9232     
9233
9234     autoAbort : false,
9235
9236     
9237
9238     serializeForm : function(L){
9239         return  Roo.lib.Ajax.serializeForm(L);
9240     }
9241 });
9242
9243
9244  
9245
9246
9247 Roo.Ajax = new  Roo.data.Connection({
9248     
9249     
9250     
9251
9252     
9253    
9254
9255     
9256
9257     
9258
9259     
9260
9261     
9262
9263     
9264
9265
9266     
9267
9268
9269     
9270
9271     
9272
9273     
9274
9275     
9276
9277     
9278
9279     
9280
9281
9282     
9283
9284     autoAbort : false,
9285
9286     
9287
9288     serializeForm : function(A){
9289         return  Roo.lib.Ajax.serializeForm(A);
9290     }
9291 });
9292
9293
9294
9295  
9296
9297
9298 Roo.UpdateManager = function(el, A){
9299     el = Roo.get(el);
9300     if(!A && el.updateManager){
9301         return  el.updateManager;
9302     }
9303
9304     
9305
9306     this.el = el;
9307     
9308
9309     this.defaultUrl = null;
9310
9311     this.addEvents({
9312         
9313
9314         "beforeupdate": true,
9315         
9316
9317         "update": true,
9318         
9319
9320         "failure": true
9321     });
9322     var  d = Roo.UpdateManager.defaults;
9323     
9324
9325     this.sslBlankUrl = d.sslBlankUrl;
9326     
9327
9328     this.disableCaching = d.disableCaching;
9329     
9330
9331     this.indicatorText = d.indicatorText;
9332     
9333
9334     this.showLoadIndicator = d.showLoadIndicator;
9335     
9336
9337     this.timeout = d.timeout;
9338
9339     
9340
9341     this.loadScripts = d.loadScripts;
9342
9343     
9344
9345     this.transaction = null;
9346
9347     
9348
9349     this.autoRefreshProcId = null;
9350     
9351
9352     this.refreshDelegate = this.refresh.createDelegate(this);
9353     
9354
9355     this.updateDelegate = this.update.createDelegate(this);
9356     
9357
9358     this.formUpdateDelegate = this.formUpdate.createDelegate(this);
9359     
9360
9361     this.successDelegate = this.processSuccess.createDelegate(this);
9362     
9363
9364     this.failureDelegate = this.processFailure.createDelegate(this);
9365
9366     if(!this.renderer){
9367      
9368
9369     this.renderer = new  Roo.UpdateManager.BasicRenderer();
9370     }
9371
9372     
9373     Roo.UpdateManager.superclass.constructor.call(this);
9374 };
9375
9376 Roo.extend(Roo.UpdateManager, Roo.util.Observable, {
9377     
9378
9379     getEl : function(){
9380         return  this.el;
9381     },
9382     
9383
9384     update : function(B, C, D, E){
9385         if(this.fireEvent("beforeupdate", this.el, B, C) !== false){
9386             var  method = this.method, cfg;
9387             if(typeof  B == "object"){ 
9388                 cfg = B;
9389                 B = cfg.url;
9390                 C = C || cfg.params;
9391                 D = D || cfg.callback;
9392                 E = E || cfg.discardUrl;
9393                 if(D && cfg.scope){
9394                     D = D.createDelegate(cfg.scope);
9395                 }
9396                 if(typeof  cfg.method != "undefined"){method = cfg.method;};
9397                 if(typeof  cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;};
9398                 if(typeof  cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
9399                 if(typeof  cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;};
9400                 if(typeof  cfg.timeout != "undefined"){this.timeout = cfg.timeout;};
9401             }
9402
9403             this.showLoading();
9404             if(!E){
9405                 this.defaultUrl = B;
9406             }
9407             if(typeof  B == "function"){
9408                 B = B.call(this);
9409             }
9410
9411
9412             method = method || (C ? "POST" : "GET");
9413             if(method == "GET"){
9414                 B = this.prepareUrl(B);
9415             }
9416
9417             var  o = Roo.apply(cfg ||{}, {
9418                 url : B,
9419                 params: C,
9420                 success: this.successDelegate,
9421                 failure: this.failureDelegate,
9422                 callback: undefined,
9423                 timeout: (this.timeout*1000),
9424                 argument: {"url": B, "form": null, "callback": D, "params": C}
9425             });
9426
9427             this.transaction = Roo.Ajax.request(o);
9428         }
9429     },
9430
9431     
9432
9433     formUpdate : function(F, G, H, I){
9434         if(this.fireEvent("beforeupdate", this.el, F, G) !== false){
9435             if(typeof  G == "function"){
9436                 G = G.call(this);
9437             }
9438
9439             F = Roo.getDom(F);
9440             this.transaction = Roo.Ajax.request({
9441                 form: F,
9442                 url:G,
9443                 success: this.successDelegate,
9444                 failure: this.failureDelegate,
9445                 timeout: (this.timeout*1000),
9446                 argument: {"url": G, "form": F, "callback": I, "reset": H}
9447             });
9448             this.showLoading.defer(1, this);
9449         }
9450     },
9451
9452     
9453
9454     refresh : function(J){
9455         if(this.defaultUrl == null){
9456             return;
9457         }
9458
9459         this.update(this.defaultUrl, null, J, true);
9460     },
9461
9462     
9463
9464     startAutoRefresh : function(K, L, M, N, O){
9465         if(O){
9466             this.update(L || this.defaultUrl, M, N, true);
9467         }
9468         if(this.autoRefreshProcId){
9469             clearInterval(this.autoRefreshProcId);
9470         }
9471
9472         this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [L || this.defaultUrl, M, N, true]), K*1000);
9473     },
9474
9475     
9476
9477      stopAutoRefresh : function(){
9478         if(this.autoRefreshProcId){
9479             clearInterval(this.autoRefreshProcId);
9480             delete  this.autoRefreshProcId;
9481         }
9482     },
9483
9484     isAutoRefreshing : function(){
9485        return  this.autoRefreshProcId ? true : false;
9486     },
9487     
9488
9489     showLoading : function(){
9490         if(this.showLoadIndicator){
9491             this.el.update(this.indicatorText);
9492         }
9493     },
9494
9495     
9496
9497     prepareUrl : function(P){
9498         if(this.disableCaching){
9499             var  append = "_dc=" + (new  Date().getTime());
9500             if(P.indexOf("?") !== -1){
9501                 P += "&" + append;
9502             }else {
9503                 P += "?" + append;
9504             }
9505         }
9506         return  P;
9507     },
9508
9509     
9510
9511     processSuccess : function(Q){
9512         this.transaction = null;
9513         if(Q.argument.form && Q.argument.reset){
9514             try{ 
9515                 Q.argument.form.reset();
9516             }catch(e){}
9517         }
9518         if(this.loadScripts){
9519             this.renderer.render(this.el, Q, this,
9520                 this.updateComplete.createDelegate(this, [Q]));
9521         }else {
9522             this.renderer.render(this.el, Q, this);
9523             this.updateComplete(Q);
9524         }
9525     },
9526
9527     updateComplete : function(R){
9528         this.fireEvent("update", this.el, R);
9529         if(typeof  R.argument.callback == "function"){
9530             R.argument.callback(this.el, true, R);
9531         }
9532     },
9533
9534     
9535
9536     processFailure : function(S){
9537         this.transaction = null;
9538         this.fireEvent("failure", this.el, S);
9539         if(typeof  S.argument.callback == "function"){
9540             S.argument.callback(this.el, false, S);
9541         }
9542     },
9543
9544     
9545
9546     setRenderer : function(T){
9547         this.renderer = T;
9548     },
9549
9550     getRenderer : function(){
9551        return  this.renderer;
9552     },
9553
9554     
9555
9556     setDefaultUrl : function(U){
9557         this.defaultUrl = U;
9558     },
9559
9560     
9561
9562     abort : function(){
9563         if(this.transaction){
9564             Roo.Ajax.abort(this.transaction);
9565         }
9566     },
9567
9568     
9569
9570     isUpdating : function(){
9571         if(this.transaction){
9572             return  Roo.Ajax.isLoading(this.transaction);
9573         }
9574         return  false;
9575     }
9576 });
9577
9578
9579
9580    Roo.UpdateManager.defaults = {
9581        
9582
9583          timeout : 30,
9584
9585          
9586
9587         loadScripts : false,
9588
9589         
9590
9591         sslBlankUrl : (Roo.SSL_SECURE_URL || "javascript:false"),
9592         
9593
9594         disableCaching : false,
9595         
9596
9597         showLoadIndicator : true,
9598         
9599
9600         indicatorText : '<div class="loading-indicator">Loading...</div>'
9601    };
9602
9603
9604
9605 Roo.UpdateManager.updateElement = function(el, V, W, X){
9606     var  um = Roo.get(el, true).getUpdateManager();
9607     Roo.apply(um, X);
9608     um.update(V, W, X ? X.callback : null);
9609 };
9610
9611 Roo.UpdateManager.update = Roo.UpdateManager.updateElement;
9612
9613
9614 Roo.UpdateManager.BasicRenderer = function(){};
9615
9616 Roo.UpdateManager.BasicRenderer.prototype = {
9617     
9618
9619      render : function(el, Y, Z, a){
9620         el.update(Y.responseText, Z.loadScripts, a);
9621     }
9622 };
9623
9624
9625
9626
9627
9628
9629 Roo.util.DelayedTask = function(fn, A, B){
9630     var  id = null, d, t;
9631
9632     var  C = function(){
9633         var  D = new  Date().getTime();
9634         if(D - t >= d){
9635             clearInterval(id);
9636             id = null;
9637             fn.apply(A, B || []);
9638         }
9639     };
9640     
9641
9642     this.delay = function(D, E, F, G){
9643         if(id && D != d){
9644             this.cancel();
9645         }
9646
9647         d = D;
9648         t = new  Date().getTime();
9649         fn = E || fn;
9650         A = F || A;
9651         B = G || B;
9652         if(!id){
9653             id = setInterval(C, d);
9654         }
9655     };
9656
9657     
9658
9659     this.cancel = function(){
9660         if(id){
9661             clearInterval(id);
9662             id = null;
9663         }
9664     };
9665 };
9666
9667
9668  
9669  
9670 Roo.util.TaskRunner = function(A){
9671     A = A || 10;
9672     var  B = [], C = [];
9673     var  id = 0;
9674     var  D = false;
9675
9676     var  E = function(){
9677         D = false;
9678         clearInterval(id);
9679         id = 0;
9680     };
9681
9682     var  F = function(){
9683         if(!D){
9684             D = true;
9685             id = setInterval(H, A);
9686         }
9687     };
9688
9689     var  G = function(I){
9690         C.push(I);
9691         if(I.onStop){
9692             I.onStop();
9693         }
9694     };
9695
9696     var  H = function(){
9697         if(C.length > 0){
9698             for(var  i = 0, len = C.length; i < len; i++){
9699                 B.remove(C[i]);
9700             }
9701
9702             C = [];
9703             if(B.length < 1){
9704                 E();
9705                 return;
9706             }
9707         }
9708         var  I = new  Date().getTime();
9709         for(var  i = 0, len = B.length; i < len; ++i){
9710             var  t = B[i];
9711             var  itime = I - t.taskRunTime;
9712             if(t.interval <= itime){
9713                 var  rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
9714                 t.taskRunTime = I;
9715                 if(rt === false || t.taskRunCount === t.repeat){
9716                     G(t);
9717                     return;
9718                 }
9719             }
9720             if(t.duration && t.duration <= (I - t.taskStartTime)){
9721                 G(t);
9722             }
9723         }
9724     };
9725
9726     
9727
9728     this.start = function(I){
9729         B.push(I);
9730         I.taskStartTime = new  Date().getTime();
9731         I.taskRunTime = 0;
9732         I.taskRunCount = 0;
9733         F();
9734         return  I;
9735     };
9736
9737     this.stop = function(I){
9738         G(I);
9739         return  I;
9740     };
9741
9742     this.stopAll = function(){
9743         E();
9744         for(var  i = 0, len = B.length; i < len; i++){
9745             if(B[i].onStop){
9746                 B[i].onStop();
9747             }
9748         }
9749
9750         B = [];
9751         C = [];
9752     };
9753 };
9754
9755 Roo.TaskMgr = new  Roo.util.TaskRunner();
9756
9757
9758
9759  
9760
9761
9762 Roo.util.MixedCollection = function(A, B){
9763     this.items = [];
9764     this.map = {};
9765     this.keys = [];
9766     this.length = 0;
9767     this.addEvents({
9768         
9769
9770         "clear" : true,
9771         
9772
9773         "add" : true,
9774         
9775
9776         "replace" : true,
9777         
9778
9779         "remove" : true,
9780         "sort" : true
9781     });
9782     this.allowFunctions = A === true;
9783     if(B){
9784         this.getKey = B;
9785     }
9786
9787     Roo.util.MixedCollection.superclass.constructor.call(this);
9788 };
9789
9790 Roo.extend(Roo.util.MixedCollection, Roo.util.Observable, {
9791     allowFunctions : false,
9792     
9793
9794
9795     add : function(C, o){
9796         if(arguments.length == 1){
9797             o = arguments[0];
9798             C = this.getKey(o);
9799         }
9800         if(typeof  C == "undefined" || C === null){
9801             this.length++;
9802             this.items.push(o);
9803             this.keys.push(null);
9804         }else {
9805             var  old = this.map[C];
9806             if(old){
9807                 return  this.replace(C, o);
9808             }
9809
9810             this.length++;
9811             this.items.push(o);
9812             this.map[C] = o;
9813             this.keys.push(C);
9814         }
9815
9816         this.fireEvent("add", this.length-1, o, C);
9817         return  o;
9818     },
9819    
9820
9821
9822     getKey : function(o){
9823          return  o.id; 
9824     },
9825    
9826
9827
9828     replace : function(D, o){
9829         if(arguments.length == 1){
9830             o = arguments[0];
9831             D = this.getKey(o);
9832         }
9833         var  E = this.item(D);
9834         if(typeof  D == "undefined" || D === null || typeof  E == "undefined"){
9835              return  this.add(D, o);
9836         }
9837         var  F = this.indexOfKey(D);
9838         this.items[F] = o;
9839         this.map[D] = o;
9840         this.fireEvent("replace", D, E, o);
9841         return  o;
9842     },
9843    
9844
9845
9846     addAll : function(G){
9847         if(arguments.length > 1 || G  instanceof  Array){
9848             var  args = arguments.length > 1 ? arguments : G;
9849             for(var  i = 0, len = args.length; i < len; i++){
9850                 this.add(args[i]);
9851             }
9852         }else {
9853             for(var  D  in  G){
9854                 if(this.allowFunctions || typeof  G[D] != "function"){
9855                     this.add(D, G[D]);
9856                 }
9857             }
9858         }
9859     },
9860    
9861
9862
9863     each : function(fn, H){
9864         var  I = [].concat(this.items); 
9865         for(var  i = 0, len = I.length; i < len; i++){
9866             if(fn.call(H || I[i], I[i], i, len) === false){
9867                 break;
9868             }
9869         }
9870     },
9871    
9872
9873
9874     eachKey : function(fn, J){
9875         for(var  i = 0, len = this.keys.length; i < len; i++){
9876             fn.call(J || window, this.keys[i], this.items[i], i, len);
9877         }
9878     },
9879    
9880
9881
9882     find : function(fn, K){
9883         for(var  i = 0, len = this.items.length; i < len; i++){
9884             if(fn.call(K || window, this.items[i], this.keys[i])){
9885                 return  this.items[i];
9886             }
9887         }
9888         return  null;
9889     },
9890    
9891
9892
9893     insert : function(L, M, o){
9894         if(arguments.length == 2){
9895             o = arguments[1];
9896             M = this.getKey(o);
9897         }
9898         if(L >= this.length){
9899             return  this.add(M, o);
9900         }
9901
9902         this.length++;
9903         this.items.splice(L, 0, o);
9904         if(typeof  M != "undefined" && M != null){
9905             this.map[M] = o;
9906         }
9907
9908         this.keys.splice(L, 0, M);
9909         this.fireEvent("add", L, o, M);
9910         return  o;
9911     },
9912    
9913
9914
9915     remove : function(o){
9916         return  this.removeAt(this.indexOf(o));
9917     },
9918    
9919
9920
9921     removeAt : function(N){
9922         if(N < this.length && N >= 0){
9923             this.length--;
9924             var  o = this.items[N];
9925             this.items.splice(N, 1);
9926             var  M = this.keys[N];
9927             if(typeof  M != "undefined"){
9928                 delete  this.map[M];
9929             }
9930
9931             this.keys.splice(N, 1);
9932             this.fireEvent("remove", o, M);
9933         }
9934     },
9935    
9936
9937
9938     removeKey : function(O){
9939         return  this.removeAt(this.indexOfKey(O));
9940     },
9941    
9942
9943
9944     getCount : function(){
9945         return  this.length; 
9946     },
9947    
9948
9949
9950     indexOf : function(o){
9951         if(!this.items.indexOf){
9952             for(var  i = 0, len = this.items.length; i < len; i++){
9953                 if(this.items[i] == o) return  i;
9954             }
9955             return  -1;
9956         }else {
9957             return  this.items.indexOf(o);
9958         }
9959     },
9960    
9961
9962
9963     indexOfKey : function(P){
9964         if(!this.keys.indexOf){
9965             for(var  i = 0, len = this.keys.length; i < len; i++){
9966                 if(this.keys[i] == P) return  i;
9967             }
9968             return  -1;
9969         }else {
9970             return  this.keys.indexOf(P);
9971         }
9972     },
9973    
9974
9975
9976     item : function(Q){
9977         var  R = typeof  this.map[Q] != "undefined" ? this.map[Q] : this.items[Q];
9978         return  typeof  R != 'function' || this.allowFunctions ? R : null; 
9979     },
9980     
9981
9982
9983     itemAt : function(S){
9984         return  this.items[S];
9985     },
9986     
9987
9988
9989     key : function(T){
9990         return  this.map[T];
9991     },
9992    
9993
9994
9995     contains : function(o){
9996         return  this.indexOf(o) != -1;
9997     },
9998    
9999
10000
10001     containsKey : function(U){
10002         return  typeof  this.map[U] != "undefined";
10003     },
10004    
10005
10006
10007     clear : function(){
10008         this.length = 0;
10009         this.items = [];
10010         this.keys = [];
10011         this.map = {};
10012         this.fireEvent("clear");
10013     },
10014    
10015
10016
10017     first : function(){
10018         return  this.items[0]; 
10019     },
10020    
10021
10022
10023     last : function(){
10024         return  this.items[this.length-1];   
10025     },
10026     
10027     _sort : function(V, W, fn){
10028         var  X = String(W).toUpperCase() == "DESC" ? -1 : 1;
10029         fn = fn || function(a, b){
10030             return  a-b;
10031         };
10032         var  c = [], k = this.keys, Y = this.items;
10033         for(var  i = 0, len = Y.length; i < len; i++){
10034             c[c.length] = {key: k[i], value: Y[i], index: i};
10035         }
10036
10037         c.sort(function(a, b){
10038             var  v = fn(a[V], b[V]) * X;
10039             if(v == 0){
10040                 v = (a.index < b.index ? -1 : 1);
10041             }
10042             return  v;
10043         });
10044         for(var  i = 0, len = c.length; i < len; i++){
10045             Y[i] = c[i].value;
10046             k[i] = c[i].key;
10047         }
10048
10049         this.fireEvent("sort", this);
10050     },
10051     
10052     
10053
10054     sort : function(Z, fn){
10055         this._sort("value", Z, fn);
10056     },
10057     
10058     
10059
10060     keySort : function(a, fn){
10061         this._sort("key", a, fn || function(a, b){
10062             return  String(a).toUpperCase()-String(b).toUpperCase();
10063         });
10064     },
10065     
10066     
10067
10068     getRange : function(b, d){
10069         var  e = this.items;
10070         if(e.length < 1){
10071             return  [];
10072         }
10073
10074         b = b || 0;
10075         d = Math.min(typeof  d == "undefined" ? this.length-1 : d, this.length-1);
10076         var  r = [];
10077         if(b <= d){
10078             for(var  i = b; i <= d; i++) {
10079                     r[r.length] = e[i];
10080             }
10081         }else {
10082             for(var  i = b; i >= d; i--) {
10083                     r[r.length] = e[i];
10084             }
10085         }
10086         return  r;
10087     },
10088         
10089     
10090
10091     filter : function(f, g){
10092         if(!g.exec){ 
10093             g = String(g);
10094             if(g.length == 0){
10095                 return  this.clone();
10096             }
10097
10098             g = new  RegExp("^" + Roo.escapeRe(g), "i");
10099         }
10100         return  this.filterBy(function(o){
10101             return  o && g.test(o[f]);
10102         });
10103         },
10104     
10105     
10106
10107     filterBy : function(fn, h){
10108         var  r = new  Roo.util.MixedCollection();
10109         r.getKey = this.getKey;
10110         var  k = this.keys, it = this.items;
10111         for(var  i = 0, len = it.length; i < len; i++){
10112             if(fn.call(h||this, it[i], k[i])){
10113                                 r.add(k[i], it[i]);
10114                         }
10115         }
10116         return  r;
10117     },
10118     
10119     
10120
10121     clone : function(){
10122         var  r = new  Roo.util.MixedCollection();
10123         var  k = this.keys, it = this.items;
10124         for(var  i = 0, len = it.length; i < len; i++){
10125             r.add(k[i], it[i]);
10126         }
10127
10128         r.getKey = this.getKey;
10129         return  r;
10130     }
10131 });
10132
10133
10134 Roo.util.MixedCollection.prototype.get = Roo.util.MixedCollection.prototype.item;
10135
10136
10137
10138
10139 Roo.util.JSON = new  (function(){
10140     var  useHasOwn = {}.hasOwnProperty ? true : false;
10141     
10142     
10143     
10144     
10145     var  pad = function(n) {
10146         return  n < 10 ? "0" + n : n;
10147     };
10148     
10149     var  m = {
10150         "\b": '\\b',
10151         "\t": '\\t',
10152         "\n": '\\n',
10153         "\f": '\\f',
10154         "\r": '\\r',
10155         '"' : '\\"',
10156         "\\": '\\\\'
10157     };
10158
10159     var  encodeString = function(s){
10160         if (/["\\\x00-\x1f]/.test(s)) {
10161             return  '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
10162                 var  c = m[b];
10163                 if(c){
10164                     return  c;
10165                 }
10166
10167                 c = b.charCodeAt();
10168                 return  "\\u00" +
10169                     Math.floor(c / 16).toString(16) +
10170                     (c % 16).toString(16);
10171             }) + '"';
10172         }
10173         return  '"' + s + '"';
10174     };
10175     
10176     var  encodeArray = function(o){
10177         var  a = ["["], b, i, l = o.length, v;
10178             for (i = 0; i < l; i += 1) {
10179                 v = o[i];
10180                 switch (typeof  v) {
10181                     case  "undefined":
10182                     case  "function":
10183                     case  "unknown":
10184                         break;
10185                     default:
10186                         if (b) {
10187                             a.push(',');
10188                         }
10189
10190                         a.push(v === null ? "null" : Roo.util.JSON.encode(v));
10191                         b = true;
10192                 }
10193             }
10194
10195             a.push("]");
10196             return  a.join("");
10197     };
10198     
10199     var  encodeDate = function(o){
10200         return  '"' + o.getFullYear() + "-" +
10201                 pad(o.getMonth() + 1) + "-" +
10202                 pad(o.getDate()) + "T" +
10203                 pad(o.getHours()) + ":" +
10204                 pad(o.getMinutes()) + ":" +
10205                 pad(o.getSeconds()) + '"';
10206     };
10207     
10208     
10209
10210     this.encode = function(o){
10211         if(typeof  o == "undefined" || o === null){
10212             return  "null";
10213         }else  if(o  instanceof  Array){
10214             return  encodeArray(o);
10215         }else  if(o  instanceof  Date){
10216             return  encodeDate(o);
10217         }else  if(typeof  o == "string"){
10218             return  encodeString(o);
10219         }else  if(typeof  o == "number"){
10220             return  isFinite(o) ? String(o) : "null";
10221         }else  if(typeof  o == "boolean"){
10222             return  String(o);
10223         }else  {
10224             var  a = ["{"], b, i, v;
10225             for (i  in  o) {
10226                 if(!useHasOwn || o.hasOwnProperty(i)) {
10227                     v = o[i];
10228                     switch (typeof  v) {
10229                     case  "undefined":
10230                     case  "function":
10231                     case  "unknown":
10232                         break;
10233                     default:
10234                         if(b){
10235                             a.push(',');
10236                         }
10237
10238                         a.push(this.encode(i), ":",
10239                                 v === null ? "null" : this.encode(v));
10240                         b = true;
10241                     }
10242                 }
10243             }
10244
10245             a.push("}");
10246             return  a.join("");
10247         }
10248     };
10249     
10250     
10251
10252     this.decode = function(json){
10253         
10254
10255         return  eval("(" + json + ')');
10256     };
10257 })();
10258
10259
10260 Roo.encode = Roo.util.JSON.encode;
10261
10262
10263 Roo.decode = Roo.util.JSON.decode;
10264
10265
10266
10267  
10268
10269
10270 Roo.util.Format = function(){
10271     var  A = /^\s+|\s+$/g;
10272     return  {
10273         
10274
10275         ellipsis : function(R, S){
10276             if(R && R.length > S){
10277                 return  R.substr(0, S-3)+"...";
10278             }
10279             return  R;
10280         },
10281
10282         
10283
10284         undef : function(T){
10285             return  typeof  T != "undefined" ? T : "";
10286         },
10287
10288         
10289
10290         htmlEncode : function(U){
10291             return  !U ? U : String(U).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
10292         },
10293
10294         
10295
10296         htmlDecode : function(V){
10297             return  !V ? V : String(V).replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"');
10298         },
10299
10300         
10301
10302         trim : function(W){
10303             return  String(W).replace(A, "");
10304         },
10305
10306         
10307
10308         substr : function(X, Y, Z){
10309             return  String(X).substr(Y, Z);
10310         },
10311
10312         
10313
10314         lowercase : function(a){
10315             return  String(a).toLowerCase();
10316         },
10317
10318         
10319
10320         uppercase : function(b){
10321             return  String(b).toUpperCase();
10322         },
10323
10324         
10325
10326         capitalize : function(c){
10327             return  !c ? c : c.charAt(0).toUpperCase() + c.substr(1).toLowerCase();
10328         },
10329
10330         
10331         call : function(value, fn){
10332             if(arguments.length > 2){
10333                 var  args = Array.prototype.slice.call(arguments, 2);
10334                 args.unshift(value);
10335                  
10336                 return  
10337   eval(fn).apply(window, args);
10338             }else {
10339                 
10340
10341                 return  
10342  eval(fn).call(window, value);
10343             }
10344         },
10345
10346         
10347
10348         usMoney : function(v){
10349             v = (Math.round((v-0)*100))/100;
10350             v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
10351             v = String(v);
10352             var  ps = v.split('.');
10353             var  d = ps[0];
10354             var  e = ps[1] ? '.'+ ps[1] : '.00';
10355             var  r = /(\d+)(\d{3})/;
10356             while (r.test(d)) {
10357                 d = d.replace(r, '$1' + ',' + '$2');
10358             }
10359             return  "$" + d + e ;
10360         },
10361
10362         
10363
10364         date : function(v, f){
10365             if(!v){
10366                 return  "";
10367             }
10368             if(!(v  instanceof  Date)){
10369                 v = new  Date(Date.parse(v));
10370             }
10371             return  v.dateFormat(f || "m/d/Y");
10372         },
10373
10374         
10375
10376         dateRenderer : function(g){
10377             return  function(v){
10378                 return  Roo.util.Format.date(v, g);  
10379             };
10380         },
10381
10382         
10383         stripTagsRE : /<\/?[^>]+>/gi,
10384         
10385         
10386
10387         stripTags : function(v){
10388             return  !v ? v : String(v).replace(this.stripTagsRE, "");
10389         }
10390     };
10391 }();
10392
10393
10394
10395
10396  
10397
10398
10399
10400 Roo.MasterTemplate = function(){
10401     Roo.MasterTemplate.superclass.constructor.apply(this, arguments);
10402     this.originalHtml = this.html;
10403     var  st = {};
10404     var  m, re = this.subTemplateRe;
10405     re.lastIndex = 0;
10406     var  A = 0;
10407     while(m = re.exec(this.html)){
10408         var  name = m[1], content = m[2];
10409         st[A] = {
10410             name: name,
10411             index: A,
10412             buffer: [],
10413             tpl : new  Roo.Template(content)
10414         };
10415         if(name){
10416             st[name] = st[A];
10417         }
10418
10419         st[A].tpl.compile();
10420         st[A].tpl.call = this.call.createDelegate(this);
10421         A++;
10422     }
10423
10424     this.subCount = A;
10425     this.subs = st;
10426 };
10427 Roo.extend(Roo.MasterTemplate, Roo.Template, {
10428     
10429
10430     subTemplateRe : /<tpl(?:\sname="([\w-]+)")?>((?:.|\n)*?)<\/tpl>/gi,
10431
10432     
10433
10434      add : function(B, C){
10435         if(arguments.length == 1){
10436             C = arguments[0];
10437             B = 0;
10438         }
10439         var  s = this.subs[B];
10440         s.buffer[s.buffer.length] = s.tpl.apply(C);
10441         return  this;
10442     },
10443
10444     
10445
10446     fill : function(D, E, F){
10447         var  a = arguments;
10448         if(a.length == 1 || (a.length == 2 && typeof  a[1] == "boolean")){
10449             E = a[0];
10450             D = 0;
10451             F = a[1];
10452         }
10453         if(F){
10454             this.reset();
10455         }
10456         for(var  i = 0, len = E.length; i < len; i++){
10457             this.add(D, E[i]);
10458         }
10459         return  this;
10460     },
10461
10462     
10463
10464      reset : function(){
10465         var  s = this.subs;
10466         for(var  i = 0; i < this.subCount; i++){
10467             s[i].buffer = [];
10468         }
10469         return  this;
10470     },
10471
10472     applyTemplate : function(G){
10473         var  s = this.subs;
10474         var  H = -1;
10475         this.html = this.originalHtml.replace(this.subTemplateRe, function(m, I){
10476             return  s[++H].buffer.join("");
10477         });
10478         return  Roo.MasterTemplate.superclass.applyTemplate.call(this, G);
10479     },
10480
10481     apply : function(){
10482         return  this.applyTemplate.apply(this, arguments);
10483     },
10484
10485     compile : function(){return  this;}
10486 });
10487
10488
10489
10490 Roo.MasterTemplate.prototype.addAll = Roo.MasterTemplate.prototype.fill;
10491  
10492
10493 Roo.MasterTemplate.from = function(el, I){
10494     el = Roo.getDom(el);
10495     return  new  Roo.MasterTemplate(el.value || el.innerHTML, I || '');
10496 };
10497
10498
10499
10500  
10501
10502
10503 Roo.util.CSS = function(){
10504         var  A = null;
10505         var  B = document;
10506
10507     var  C = /(-[a-z])/gi;
10508     var  D = function(m, a){ return  a.charAt(1).toUpperCase(); };
10509
10510    return  {
10511    
10512
10513     createStyleSheet : function(Q, id){
10514         var  ss;
10515         var  R = B.getElementsByTagName("head")[0];
10516         var  S = B.createElement("style");
10517         S.setAttribute("type", "text/css");
10518         if(id){
10519             S.setAttribute("id", id);
10520         }
10521         if (typeof(Q) != 'string') {
10522             
10523             
10524             
10525             
10526             var  cssTextNew = [];
10527             for(var  n  in  Q) {
10528                 var  citems = [];
10529                 for(var  k  in  Q[n]) {
10530                     citems.push( k + ' : ' +Q[n][k] + ';' );
10531                 }
10532
10533                 cssTextNew.push( n + ' { ' + citems.join(' ') + '} ');
10534                 
10535             }
10536
10537             Q = cssTextNew.join("\n");
10538             
10539         }
10540        
10541        
10542        if(Roo.isIE){
10543            R.appendChild(S);
10544            ss = S.styleSheet;
10545            ss.cssText = Q;
10546        }else {
10547            try{
10548                 S.appendChild(B.createTextNode(Q));
10549            }catch(e){
10550                S.cssText = Q; 
10551            }
10552
10553            R.appendChild(S);
10554            ss = S.styleSheet ? S.styleSheet : (S.sheet || B.styleSheets[B.styleSheets.length-1]);
10555        }
10556
10557        this.cacheStyleSheet(ss);
10558        return  ss;
10559    },
10560
10561    
10562
10563    removeStyleSheet : function(id){
10564        var  T = B.getElementById(id);
10565        if(T){
10566            T.parentNode.removeChild(T);
10567        }
10568    },
10569
10570    
10571
10572    swapStyleSheet : function(id, U){
10573        this.removeStyleSheet(id);
10574        var  ss = B.createElement("link");
10575        ss.setAttribute("rel", "stylesheet");
10576        ss.setAttribute("type", "text/css");
10577        ss.setAttribute("id", id);
10578        ss.setAttribute("href", U);
10579        B.getElementsByTagName("head")[0].appendChild(ss);
10580    },
10581    
10582    
10583
10584    refreshCache : function(){
10585        return  this.getRules(true);
10586    },
10587
10588    
10589    cacheStyleSheet : function(V){
10590        if(!A){
10591            A = {};
10592        }
10593        try{
10594            var  ssRules = V.cssRules || V.rules;
10595            for(var  j = ssRules.length-1; j >= 0; --j){
10596                A[ssRules[j].selectorText] = ssRules[j];
10597            }
10598        }catch(e){}
10599    },
10600    
10601    
10602
10603    getRules : function(W){
10604                 if(A == null || W){
10605                         A = {};
10606                         var  ds = B.styleSheets;
10607                         for(var  i =0, len = ds.length; i < len; i++){
10608                             try{
10609                         this.cacheStyleSheet(ds[i]);
10610                     }catch(e){} 
10611                 }
10612                 }
10613                 return  A;
10614         },
10615         
10616         
10617
10618    getRule : function(X, Y){
10619                 var  rs = this.getRules(Y);
10620                 if(!(X  instanceof  Array)){
10621                     return  rs[X];
10622                 }
10623                 for(var  i = 0; i < X.length; i++){
10624                         if(rs[X[i]]){
10625                                 return  rs[X[i]];
10626                         }
10627                 }
10628                 return  null;
10629         },
10630         
10631         
10632         
10633
10634    updateRule : function(Z, a, b){
10635                 if(!(Z  instanceof  Array)){
10636                         var  rule = this.getRule(Z);
10637                         if(rule){
10638                                 rule.style[a.replace(C, D)] = b;
10639                                 return  true;
10640                         }
10641                 }else {
10642                         for(var  i = 0; i < Z.length; i++){
10643                                 if(this.updateRule(Z[i], a, b)){
10644                                         return  true;
10645                                 }
10646                         }
10647                 }
10648                 return  false;
10649         }
10650    };   
10651 }();
10652
10653
10654
10655  
10656
10657
10658
10659 Roo.util.ClickRepeater = function(el, A)
10660 {
10661     this.el = Roo.get(el);
10662     this.el.unselectable();
10663
10664     Roo.apply(this, A);
10665
10666     this.addEvents({
10667     
10668
10669         "mousedown" : true,
10670     
10671
10672         "click" : true,
10673     
10674
10675         "mouseup" : true
10676     });
10677
10678     this.el.on("mousedown", this.handleMouseDown, this);
10679     if(this.preventDefault || this.stopDefault){
10680         this.el.on("click", function(e){
10681             if(this.preventDefault){
10682                 e.preventDefault();
10683             }
10684             if(this.stopDefault){
10685                 e.stopEvent();
10686             }
10687         }, this);
10688     }
10689
10690     
10691     if(this.handler){
10692         this.on("click", this.handler,  this.scope || this);
10693     }
10694
10695
10696     Roo.util.ClickRepeater.superclass.constructor.call(this);
10697 };
10698
10699 Roo.extend(Roo.util.ClickRepeater, Roo.util.Observable, {
10700     interval : 20,
10701     delay: 250,
10702     preventDefault : true,
10703     stopDefault : false,
10704     timer : 0,
10705
10706     
10707     handleMouseDown : function(){
10708         clearTimeout(this.timer);
10709         this.el.blur();
10710         if(this.pressClass){
10711             this.el.addClass(this.pressClass);
10712         }
10713
10714         this.mousedownTime = new  Date();
10715
10716         Roo.get(document).on("mouseup", this.handleMouseUp, this);
10717         this.el.on("mouseout", this.handleMouseOut, this);
10718
10719         this.fireEvent("mousedown", this);
10720         this.fireEvent("click", this);
10721         
10722         this.timer = this.click.defer(this.delay || this.interval, this);
10723     },
10724
10725     
10726     click : function(){
10727         this.fireEvent("click", this);
10728         this.timer = this.click.defer(this.getInterval(), this);
10729     },
10730
10731     
10732     getInterval: function(){
10733         if(!this.accelerate){
10734             return  this.interval;
10735         }
10736         var  B = this.mousedownTime.getElapsed();
10737         if(B < 500){
10738             return  400;
10739         }else  if(B < 1700){
10740             return  320;
10741         }else  if(B < 2600){
10742             return  250;
10743         }else  if(B < 3500){
10744             return  180;
10745         }else  if(B < 4400){
10746             return  140;
10747         }else  if(B < 5300){
10748             return  80;
10749         }else  if(B < 6200){
10750             return  50;
10751         }else {
10752             return  10;
10753         }
10754     },
10755
10756     
10757     handleMouseOut : function(){
10758         clearTimeout(this.timer);
10759         if(this.pressClass){
10760             this.el.removeClass(this.pressClass);
10761         }
10762
10763         this.el.on("mouseover", this.handleMouseReturn, this);
10764     },
10765
10766     
10767     handleMouseReturn : function(){
10768         this.el.un("mouseover", this.handleMouseReturn);
10769         if(this.pressClass){
10770             this.el.addClass(this.pressClass);
10771         }
10772
10773         this.click();
10774     },
10775
10776     
10777     handleMouseUp : function(){
10778         clearTimeout(this.timer);
10779         this.el.un("mouseover", this.handleMouseReturn);
10780         this.el.un("mouseout", this.handleMouseOut);
10781         Roo.get(document).un("mouseup", this.handleMouseUp);
10782         this.el.removeClass(this.pressClass);
10783         this.fireEvent("mouseup", this);
10784     }
10785 });
10786
10787
10788
10789  
10790
10791
10792 Roo.KeyNav = function(el, A){
10793     this.el = Roo.get(el);
10794     Roo.apply(this, A);
10795     if(!this.disabled){
10796         this.disabled = true;
10797         this.enable();
10798     }
10799 };
10800
10801 Roo.KeyNav.prototype = {
10802     
10803
10804     disabled : false,
10805     
10806
10807     defaultEventAction: "stopEvent",
10808     
10809
10810     forceKeyDown : false,
10811
10812     
10813     prepareEvent : function(e){
10814         var  k = e.getKey();
10815         var  h = this.keyToHandler[k];
10816         
10817         
10818         
10819         if(Roo.isSafari && h && k >= 37 && k <= 40){
10820             e.stopEvent();
10821         }
10822     },
10823
10824     
10825     relay : function(e){
10826         var  k = e.getKey();
10827         var  h = this.keyToHandler[k];
10828         if(h && this[h]){
10829             if(this.doRelay(e, this[h], h) !== true){
10830                 e[this.defaultEventAction]();
10831             }
10832         }
10833     },
10834
10835     
10836     doRelay : function(e, h, B){
10837         return  h.call(this.scope || this, e);
10838     },
10839
10840     
10841     enter : false,
10842     left : false,
10843     right : false,
10844     up : false,
10845     down : false,
10846     tab : false,
10847     esc : false,
10848     pageUp : false,
10849     pageDown : false,
10850     del : false,
10851     home : false,
10852     end : false,
10853
10854     
10855     keyToHandler : {
10856         37 : "left",
10857         39 : "right",
10858         38 : "up",
10859         40 : "down",
10860         33 : "pageUp",
10861         34 : "pageDown",
10862         46 : "del",
10863         36 : "home",
10864         35 : "end",
10865         13 : "enter",
10866         27 : "esc",
10867         9  : "tab"
10868     },
10869
10870         
10871
10872         enable: function(){
10873                 if(this.disabled){
10874             
10875             
10876             if(this.forceKeyDown || Roo.isIE || Roo.isAir){
10877                 this.el.on("keydown", this.relay,  this);
10878             }else {
10879                 this.el.on("keydown", this.prepareEvent,  this);
10880                 this.el.on("keypress", this.relay,  this);
10881             }
10882
10883                     this.disabled = false;
10884                 }
10885         },
10886
10887         
10888
10889         disable: function(){
10890                 if(!this.disabled){
10891                     if(this.forceKeyDown || Roo.isIE || Roo.isAir){
10892                 this.el.un("keydown", this.relay);
10893             }else {
10894                 this.el.un("keydown", this.prepareEvent);
10895                 this.el.un("keypress", this.relay);
10896             }
10897
10898                     this.disabled = true;
10899                 }
10900         }
10901 };
10902
10903
10904
10905  
10906
10907
10908 Roo.KeyMap = function(el, A, B){
10909     this.el  = Roo.get(el);
10910     this.eventName = B || "keydown";
10911     this.bindings = [];
10912     if(A){
10913         this.addBinding(A);
10914     }
10915
10916     this.enable();
10917 };
10918
10919 Roo.KeyMap.prototype = {
10920     
10921
10922     stopEvent : false,
10923
10924     
10925
10926         addBinding : function(C){
10927         if(C  instanceof  Array){
10928             for(var  i = 0, len = C.length; i < len; i++){
10929                 this.addBinding(C[i]);
10930             }
10931             return;
10932         }
10933         var  D = C.key,
10934             E = C.shift, 
10935             F = C.ctrl, 
10936             G = C.alt,
10937             fn = C.fn,
10938             H = C.scope;
10939         if(typeof  D == "string"){
10940             var  ks = [];
10941             var  keyString = D.toUpperCase();
10942             for(var  j = 0, len = keyString.length; j < len; j++){
10943                 ks.push(keyString.charCodeAt(j));
10944             }
10945
10946             D = ks;
10947         }
10948         var  I = D  instanceof  Array;
10949         var  J = function(e){
10950             if((!E || e.shiftKey) && (!F || e.ctrlKey) &&  (!G || e.altKey)){
10951                 var  k = e.getKey();
10952                 if(I){
10953                     for(var  i = 0, len = D.length; i < len; i++){
10954                         if(D[i] == k){
10955                           if(this.stopEvent){
10956                               e.stopEvent();
10957                           }
10958
10959                           fn.call(H || window, k, e);
10960                           return;
10961                         }
10962                     }
10963                 }else {
10964                     if(k == D){
10965                         if(this.stopEvent){
10966                            e.stopEvent();
10967                         }
10968
10969                         fn.call(H || window, k, e);
10970                     }
10971                 }
10972             }
10973         };
10974         this.bindings.push(J);  
10975         },
10976
10977     
10978
10979     on : function(K, fn, L){
10980         var  M, N, O, P;
10981         if(typeof  K == "object" && !(K  instanceof  Array)){
10982             M = K.key;
10983             N = K.shift;
10984             O = K.ctrl;
10985             P = K.alt;
10986         }else {
10987             M = K;
10988         }
10989
10990         this.addBinding({
10991             key: M,
10992             shift: N,
10993             ctrl: O,
10994             alt: P,
10995             fn: fn,
10996             scope: L
10997         })
10998     },
10999
11000     
11001     handleKeyDown : function(e){
11002             if(this.enabled){ 
11003             var  b = this.bindings;
11004             for(var  i = 0, len = b.length; i < len; i++){
11005                 b[i].call(this, e);
11006             }
11007             }
11008         },
11009         
11010         
11011
11012         isEnabled : function(){
11013             return  this.enabled;  
11014         },
11015         
11016         
11017
11018         enable: function(){
11019                 if(!this.enabled){
11020                     this.el.on(this.eventName, this.handleKeyDown, this);
11021                     this.enabled = true;
11022                 }
11023         },
11024
11025         
11026
11027         disable: function(){
11028                 if(this.enabled){
11029                     this.el.removeListener(this.eventName, this.handleKeyDown, this);
11030                     this.enabled = false;
11031                 }
11032         }
11033 };
11034
11035
11036
11037  
11038
11039
11040 Roo.util.TextMetrics = function(){
11041     var  A;
11042     return  {
11043         
11044
11045         measure : function(el, E, F){
11046             if(!A){
11047                 A = Roo.util.TextMetrics.Instance(el, F);
11048             }
11049
11050             A.bind(el);
11051             A.setFixedWidth(F || 'auto');
11052             return  A.getSize(E);
11053         },
11054
11055         
11056
11057         createInstance : function(el, G){
11058             return  Roo.util.TextMetrics.Instance(el, G);
11059         }
11060     };
11061 }();
11062
11063  
11064
11065 Roo.util.TextMetrics.Instance = function(B, C){
11066     var  ml = new  Roo.Element(document.createElement('div'));
11067     document.body.appendChild(ml.dom);
11068     ml.position('absolute');
11069     ml.setLeftTop(-1000, -1000);
11070     ml.hide();
11071
11072     if(C){
11073         ml.setWidth(C);
11074     }
11075      
11076     var  D = {
11077         
11078
11079         getSize : function(E){
11080             ml.update(E);
11081             var  s = ml.getSize();
11082             ml.update('');
11083             return  s;
11084         },
11085
11086         
11087
11088         bind : function(el){
11089             ml.setStyle(
11090                 Roo.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height')
11091             );
11092         },
11093
11094         
11095
11096         setFixedWidth : function(F){
11097             ml.setWidth(F);
11098         },
11099
11100         
11101
11102         getWidth : function(G){
11103             ml.dom.style.width = 'auto';
11104             return  this.getSize(G).width;
11105         },
11106
11107         
11108
11109         getHeight : function(H){
11110             return  this.getSize(H).height;
11111         }
11112     };
11113
11114     D.bind(B);
11115
11116     return  D;
11117 };
11118
11119
11120 Roo.Element.measureText = Roo.util.TextMetrics.measure;
11121
11122
11123
11124
11125
11126 Roo.state.Provider = function(){
11127     
11128
11129     this.addEvents({
11130         "statechange": true
11131     });
11132     this.state = {};
11133     Roo.state.Provider.superclass.constructor.call(this);
11134 };
11135 Roo.extend(Roo.state.Provider, Roo.util.Observable, {
11136     
11137
11138     get : function(A, B){
11139         return  typeof  this.state[A] == "undefined" ?
11140             B : this.state[A];
11141     },
11142     
11143     
11144
11145     clear : function(C){
11146         delete  this.state[C];
11147         this.fireEvent("statechange", this, C, null);
11148     },
11149     
11150     
11151
11152     set : function(D, E){
11153         this.state[D] = E;
11154         this.fireEvent("statechange", this, D, E);
11155     },
11156     
11157     
11158
11159     decodeValue : function(F){
11160         var  re = /^(a|n|d|b|s|o)\:(.*)$/;
11161         var  G = re.exec(unescape(F));
11162         if(!G || !G[1]) return; 
11163         var  H = G[1];
11164         var  v = G[2];
11165         switch(H){
11166             case  "n":
11167                 return  parseFloat(v);
11168             case  "d":
11169                 return  new  Date(Date.parse(v));
11170             case  "b":
11171                 return  (v == "1");
11172             case  "a":
11173                 var  all = [];
11174                 var  values = v.split("^");
11175                 for(var  i = 0, len = values.length; i < len; i++){
11176                     all.push(this.decodeValue(values[i]));
11177                 }
11178                 return  all;
11179            case  "o":
11180                 var  all = {};
11181                 var  values = v.split("^");
11182                 for(var  i = 0, len = values.length; i < len; i++){
11183                     var  kv = values[i].split("=");
11184                     all[kv[0]] = this.decodeValue(kv[1]);
11185                 }
11186                 return  all;
11187            default:
11188                 return  v;
11189         }
11190     },
11191     
11192     
11193
11194     encodeValue : function(v){
11195         var  I;
11196         if(typeof  v == "number"){
11197             I = "n:" + v;
11198         }else  if(typeof  v == "boolean"){
11199             I = "b:" + (v ? "1" : "0");
11200         }else  if(v  instanceof  Date){
11201             I = "d:" + v.toGMTString();
11202         }else  if(v  instanceof  Array){
11203             var  flat = "";
11204             for(var  i = 0, len = v.length; i < len; i++){
11205                 flat += this.encodeValue(v[i]);
11206                 if(i != len-1) flat += "^";
11207             }
11208
11209             I = "a:" + flat;
11210         }else  if(typeof  v == "object"){
11211             var  flat = "";
11212             for(var  key  in  v){
11213                 if(typeof  v[key] != "function"){
11214                     flat += key + "=" + this.encodeValue(v[key]) + "^";
11215                 }
11216             }
11217
11218             I = "o:" + flat.substring(0, flat.length-1);
11219         }else {
11220             I = "s:" + v;
11221         }
11222         return  escape(I);        
11223     }
11224 });
11225
11226
11227
11228
11229
11230
11231 Roo.state.Manager = function(){
11232     var  A = new  Roo.state.Provider();
11233     
11234     return  {
11235         
11236
11237         setProvider : function(H){
11238             A = H;
11239         },
11240         
11241         
11242
11243         get : function(I, J){
11244             return  A.get(I, J);
11245         },
11246         
11247         
11248
11249          set : function(K, L){
11250             A.set(K, L);
11251         },
11252         
11253         
11254
11255         clear : function(M){
11256             A.clear(M);
11257         },
11258         
11259         
11260
11261         getProvider : function(){
11262             return  A;
11263         }
11264     };
11265 }();
11266
11267
11268
11269
11270
11271 Roo.state.CookieProvider = function(A){
11272     Roo.state.CookieProvider.superclass.constructor.call(this);
11273     this.path = "/";
11274     this.expires = new  Date(new  Date().getTime()+(1000*60*60*24*7)); 
11275     this.domain = null;
11276     this.secure = false;
11277     Roo.apply(this, A);
11278     this.state = this.readCookies();
11279 };
11280
11281 Roo.extend(Roo.state.CookieProvider, Roo.state.Provider, {
11282     
11283     set : function(B, C){
11284         if(typeof  C == "undefined" || C === null){
11285             this.clear(B);
11286             return;
11287         }
11288
11289         this.setCookie(B, C);
11290         Roo.state.CookieProvider.superclass.set.call(this, B, C);
11291     },
11292
11293     
11294     clear : function(D){
11295         this.clearCookie(D);
11296         Roo.state.CookieProvider.superclass.clear.call(this, D);
11297     },
11298
11299     
11300     readCookies : function(){
11301         var  E = {};
11302         var  c = document.cookie + ";";
11303         var  re = /\s?(.*?)=(.*?);/g;
11304         var  F;
11305         while((F = re.exec(c)) != null){
11306             var  D = F[1];
11307             var  C = F[2];
11308             if(D && D.substring(0,3) == "ys-"){
11309                 E[D.substr(3)] = this.decodeValue(C);
11310             }
11311         }
11312         return  E;
11313     },
11314
11315     
11316     setCookie : function(G, H){
11317         document.cookie = "ys-"+ G + "=" + this.encodeValue(H) +
11318            ((this.expires == null) ? "" : ("; expires=" + this.expires.toGMTString())) +
11319            ((this.path == null) ? "" : ("; path=" + this.path)) +
11320            ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
11321            ((this.secure == true) ? "; secure" : "");
11322     },
11323
11324     
11325     clearCookie : function(I){
11326         document.cookie = "ys-" + I + "=null; expires=Thu, 01-Jan-70 00:00:01 GMT" +
11327            ((this.path == null) ? "" : ("; path=" + this.path)) +
11328            ((this.domain == null) ? "" : ("; domain=" + this.domain)) +
11329            ((this.secure == true) ? "; secure" : "");
11330     }
11331 });
11332
11333
11334
11335
11336
11337
11338
11339
11340 (function() {
11341
11342 var  A=Roo.EventManager;
11343 var  B=Roo.lib.Dom;
11344
11345
11346
11347 Roo.dd.DragDrop = function(id, C, D) {
11348     if (id) {
11349         this.init(id, C, D);
11350     }
11351 };
11352
11353 Roo.dd.DragDrop.prototype = {
11354
11355     
11356
11357     id: null,
11358
11359     
11360
11361     config: null,
11362
11363     
11364
11365     dragElId: null,
11366
11367     
11368
11369     handleElId: null,
11370
11371     
11372
11373     invalidHandleTypes: null,
11374
11375     
11376
11377     invalidHandleIds: null,
11378
11379     
11380
11381     invalidHandleClasses: null,
11382
11383     
11384
11385     startPageX: 0,
11386
11387     
11388
11389     startPageY: 0,
11390
11391     
11392
11393     groups: null,
11394
11395     
11396
11397     locked: false,
11398
11399     
11400
11401     lock: function() { this.locked = true; },
11402
11403     
11404
11405     unlock: function() { this.locked = false; },
11406
11407     
11408
11409     isTarget: true,
11410
11411     
11412
11413     padding: null,
11414
11415     
11416
11417     _domRef: null,
11418
11419     
11420
11421     __ygDragDrop: true,
11422
11423     
11424
11425     constrainX: false,
11426
11427     
11428
11429     constrainY: false,
11430
11431     
11432
11433     minX: 0,
11434
11435     
11436
11437     maxX: 0,
11438
11439     
11440
11441     minY: 0,
11442
11443     
11444
11445     maxY: 0,
11446
11447     
11448
11449     maintainOffset: false,
11450
11451     
11452
11453     xTicks: null,
11454
11455     
11456
11457     yTicks: null,
11458
11459     
11460
11461     primaryButtonOnly: true,
11462
11463     
11464
11465     available: false,
11466
11467     
11468
11469     hasOuterHandles: false,
11470
11471     
11472
11473     b4StartDrag: function(x, y) { },
11474
11475     
11476
11477     startDrag: function(x, y) { 
11478  },
11479
11480     
11481
11482     b4Drag: function(e) { },
11483
11484     
11485
11486     onDrag: function(e) { 
11487  },
11488
11489     
11490
11491     onDragEnter: function(e, id) { 
11492  },
11493
11494     
11495
11496     b4DragOver: function(e) { },
11497
11498     
11499
11500     onDragOver: function(e, id) { 
11501  },
11502
11503     
11504
11505     b4DragOut: function(e) { },
11506
11507     
11508
11509     onDragOut: function(e, id) { 
11510  },
11511
11512     
11513
11514     b4DragDrop: function(e) { },
11515
11516     
11517
11518     onDragDrop: function(e, id) { 
11519  },
11520
11521     
11522
11523     onInvalidDrop: function(e) { 
11524  },
11525
11526     
11527
11528     b4EndDrag: function(e) { },
11529
11530     
11531
11532     endDrag: function(e) { 
11533  },
11534
11535     
11536
11537     b4MouseDown: function(e) {  },
11538
11539     
11540
11541     onMouseDown: function(e) { 
11542  },
11543
11544     
11545
11546     onMouseUp: function(e) { 
11547  },
11548
11549     
11550
11551     onAvailable: function () {
11552     },
11553
11554     
11555
11556     defaultPadding : {left:0, right:0, top:0, bottom:0},
11557
11558     
11559
11560     constrainTo : function(C, D, E){
11561         if(typeof  D == "number"){
11562             D = {left: D, right:D, top:D, bottom:D};
11563         }
11564
11565         D = D || this.defaultPadding;
11566         var  b = Roo.get(this.getEl()).getBox();
11567         var  ce = Roo.get(C);
11568         var  s = ce.getScroll();
11569         var  c, cd = ce.dom;
11570         if(cd == document.body){
11571             c = { x: s.left, y: s.top, width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
11572         }else {
11573             xy = ce.getXY();
11574             c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight};
11575         }
11576
11577
11578         var  F = b.y - c.y;
11579         var  G = b.x - c.x;
11580
11581         this.resetConstraints();
11582         this.setXConstraint(G - (D.left||0), 
11583                 c.width - G - b.width - (D.right||0) 
11584         );
11585         this.setYConstraint(F - (D.top||0), 
11586                 c.height - F - b.height - (D.bottom||0) 
11587         );
11588     },
11589
11590     
11591
11592     getEl: function() {
11593         if (!this._domRef) {
11594             this._domRef = Roo.getDom(this.id);
11595         }
11596
11597         return  this._domRef;
11598     },
11599
11600     
11601
11602     getDragEl: function() {
11603         return  Roo.getDom(this.dragElId);
11604     },
11605
11606     
11607
11608     init: function(id, H, I) {
11609         this.initTarget(id, H, I);
11610         A.on(this.id, "mousedown", this.handleMouseDown, this);
11611         
11612     },
11613
11614     
11615
11616     initTarget: function(id, J, K) {
11617
11618         
11619         this.config = K || {};
11620
11621         
11622         this.DDM = Roo.dd.DDM;
11623         
11624         this.groups = {};
11625
11626         
11627         
11628         if (typeof  id !== "string") {
11629             id = Roo.id(id);
11630         }
11631
11632
11633         
11634         this.id = id;
11635
11636         
11637         this.addToGroup((J) ? J : "default");
11638
11639         
11640         
11641         this.handleElId = id;
11642
11643         
11644         this.setDragElId(id);
11645
11646         
11647         this.invalidHandleTypes = { A: "A" };
11648         this.invalidHandleIds = {};
11649         this.invalidHandleClasses = [];
11650
11651         this.applyConfig();
11652
11653         this.handleOnAvailable();
11654     },
11655
11656     
11657
11658     applyConfig: function() {
11659
11660         
11661         
11662         this.padding           = this.config.padding || [0, 0, 0, 0];
11663         this.isTarget          = (this.config.isTarget !== false);
11664         this.maintainOffset    = (this.config.maintainOffset);
11665         this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
11666
11667     },
11668
11669     
11670
11671     handleOnAvailable: function() {
11672         this.available = true;
11673         this.resetConstraints();
11674         this.onAvailable();
11675     },
11676
11677      
11678
11679     setPadding: function(L, M, N, O) {
11680         
11681         if (!M && 0 !== M) {
11682             this.padding = [L, L, L, L];
11683         } else  if (!N && 0 !== N) {
11684             this.padding = [L, M, L, M];
11685         } else  {
11686             this.padding = [L, M, N, O];
11687         }
11688     },
11689
11690     
11691
11692     setInitPosition: function(P, Q) {
11693         var  el = this.getEl();
11694
11695         if (!this.DDM.verifyEl(el)) {
11696             return;
11697         }
11698
11699         var  dx = P || 0;
11700         var  dy = Q || 0;
11701
11702         var  p = B.getXY( el );
11703
11704         this.initPageX = p[0] - dx;
11705         this.initPageY = p[1] - dy;
11706
11707         this.lastPageX = p[0];
11708         this.lastPageY = p[1];
11709
11710
11711         this.setStartPosition(p);
11712     },
11713
11714     
11715
11716     setStartPosition: function(R) {
11717         var  p = R || B.getXY( this.getEl() );
11718         this.deltaSetXY = null;
11719
11720         this.startPageX = p[0];
11721         this.startPageY = p[1];
11722     },
11723
11724     
11725
11726     addToGroup: function(S) {
11727         this.groups[S] = true;
11728         this.DDM.regDragDrop(this, S);
11729     },
11730
11731     
11732
11733     removeFromGroup: function(T) {
11734         if (this.groups[T]) {
11735             delete  this.groups[T];
11736         }
11737
11738
11739         this.DDM.removeDDFromGroup(this, T);
11740     },
11741
11742     
11743
11744     setDragElId: function(id) {
11745         this.dragElId = id;
11746     },
11747
11748     
11749
11750     setHandleElId: function(id) {
11751         if (typeof  id !== "string") {
11752             id = Roo.id(id);
11753         }
11754
11755         this.handleElId = id;
11756         this.DDM.regHandle(this.id, id);
11757     },
11758
11759     
11760
11761     setOuterHandleElId: function(id) {
11762         if (typeof  id !== "string") {
11763             id = Roo.id(id);
11764         }
11765
11766         A.on(id, "mousedown",
11767                 this.handleMouseDown, this);
11768         this.setHandleElId(id);
11769
11770         this.hasOuterHandles = true;
11771     },
11772
11773     
11774
11775     unreg: function() {
11776         A.un(this.id, "mousedown",
11777                 this.handleMouseDown);
11778         this._domRef = null;
11779         this.DDM._remove(this);
11780     },
11781
11782     destroy : function(){
11783         this.unreg();
11784     },
11785
11786     
11787
11788     isLocked: function() {
11789         return  (this.DDM.isLocked() || this.locked);
11790     },
11791
11792     
11793
11794     handleMouseDown: function(e, U){
11795         if (this.primaryButtonOnly && e.button != 0) {
11796             return;
11797         }
11798
11799         if (this.isLocked()) {
11800             return;
11801         }
11802
11803
11804         this.DDM.refreshCache(this.groups);
11805
11806         var  pt = new  Roo.lib.Point(Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e));
11807         if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) )  {
11808         } else  {
11809             if (this.clickValidator(e)) {
11810
11811                 
11812                 this.setStartPosition();
11813
11814
11815                 this.b4MouseDown(e);
11816                 this.onMouseDown(e);
11817
11818                 this.DDM.handleMouseDown(e, this);
11819
11820                 this.DDM.stopEvent(e);
11821             } else  {
11822
11823
11824             }
11825         }
11826     },
11827
11828     clickValidator: function(e) {
11829         var  V = e.getTarget();
11830         return  ( this.isValidHandleChild(V) &&
11831                     (this.id == this.handleElId ||
11832                         this.DDM.handleWasClicked(V, this.id)) );
11833     },
11834
11835     
11836
11837     addInvalidHandleType: function(W) {
11838         var  X = W.toUpperCase();
11839         this.invalidHandleTypes[X] = X;
11840     },
11841
11842     
11843
11844     addInvalidHandleId: function(id) {
11845         if (typeof  id !== "string") {
11846             id = Roo.id(id);
11847         }
11848
11849         this.invalidHandleIds[id] = id;
11850     },
11851
11852     
11853
11854     addInvalidHandleClass: function(Y) {
11855         this.invalidHandleClasses.push(Y);
11856     },
11857
11858     
11859
11860     removeInvalidHandleType: function(Z) {
11861         var  a = Z.toUpperCase();
11862         
11863         delete  this.invalidHandleTypes[a];
11864     },
11865
11866     
11867
11868     removeInvalidHandleId: function(id) {
11869         if (typeof  id !== "string") {
11870             id = Roo.id(id);
11871         }
11872         delete  this.invalidHandleIds[id];
11873     },
11874
11875     
11876
11877     removeInvalidHandleClass: function(d) {
11878         for (var  i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
11879             if (this.invalidHandleClasses[i] == d) {
11880                 delete  this.invalidHandleClasses[i];
11881             }
11882         }
11883     },
11884
11885     
11886
11887     isValidHandleChild: function(f) {
11888
11889         var  g = true;
11890         
11891         var  h;
11892         try {
11893             h = f.nodeName.toUpperCase();
11894         } catch(e) {
11895             nodeName = node.nodeName;
11896         }
11897
11898         g = g && !this.invalidHandleTypes[h];
11899         g = g && !this.invalidHandleIds[f.id];
11900
11901         for (var  i=0, len=this.invalidHandleClasses.length; g && i<len; ++i) {
11902             g = !B.hasClass(f, this.invalidHandleClasses[i]);
11903         }
11904
11905
11906         return  g;
11907
11908     },
11909
11910     
11911
11912     setXTicks: function(j, k) {
11913         this.xTicks = [];
11914         this.xTickSize = k;
11915
11916         var  l = {};
11917
11918         for (var  i = this.initPageX; i >= this.minX; i = i - k) {
11919             if (!l[i]) {
11920                 this.xTicks[this.xTicks.length] = i;
11921                 l[i] = true;
11922             }
11923         }
11924
11925         for (i = this.initPageX; i <= this.maxX; i = i + k) {
11926             if (!l[i]) {
11927                 this.xTicks[this.xTicks.length] = i;
11928                 l[i] = true;
11929             }
11930         }
11931
11932
11933         this.xTicks.sort(this.DDM.numericSort) ;
11934     },
11935
11936     
11937
11938     setYTicks: function(m, n) {
11939         this.yTicks = [];
11940         this.yTickSize = n;
11941
11942         var  o = {};
11943
11944         for (var  i = this.initPageY; i >= this.minY; i = i - n) {
11945             if (!o[i]) {
11946                 this.yTicks[this.yTicks.length] = i;
11947                 o[i] = true;
11948             }
11949         }
11950
11951         for (i = this.initPageY; i <= this.maxY; i = i + n) {
11952             if (!o[i]) {
11953                 this.yTicks[this.yTicks.length] = i;
11954                 o[i] = true;
11955             }
11956         }
11957
11958
11959         this.yTicks.sort(this.DDM.numericSort) ;
11960     },
11961
11962     
11963
11964     setXConstraint: function(q, r, t) {
11965         this.leftConstraint = q;
11966         this.rightConstraint = r;
11967
11968         this.minX = this.initPageX - q;
11969         this.maxX = this.initPageX + r;
11970         if (t) { this.setXTicks(this.initPageX, t); }
11971
11972
11973         this.constrainX = true;
11974     },
11975
11976     
11977
11978     clearConstraints: function() {
11979         this.constrainX = false;
11980         this.constrainY = false;
11981         this.clearTicks();
11982     },
11983
11984     
11985
11986     clearTicks: function() {
11987         this.xTicks = null;
11988         this.yTicks = null;
11989         this.xTickSize = 0;
11990         this.yTickSize = 0;
11991     },
11992
11993     
11994
11995     setYConstraint: function(u, v, w) {
11996         this.topConstraint = u;
11997         this.bottomConstraint = v;
11998
11999         this.minY = this.initPageY - u;
12000         this.maxY = this.initPageY + v;
12001         if (w) { this.setYTicks(this.initPageY, w); }
12002
12003
12004         this.constrainY = true;
12005
12006     },
12007
12008     
12009
12010     resetConstraints: function() {
12011
12012
12013         
12014         if (this.initPageX || this.initPageX === 0) {
12015             
12016             var  dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
12017             var  dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
12018
12019             this.setInitPosition(dx, dy);
12020
12021         
12022         } else  {
12023             this.setInitPosition();
12024         }
12025
12026         if (this.constrainX) {
12027             this.setXConstraint( this.leftConstraint,
12028                                  this.rightConstraint,
12029                                  this.xTickSize        );
12030         }
12031
12032         if (this.constrainY) {
12033             this.setYConstraint( this.topConstraint,
12034                                  this.bottomConstraint,
12035                                  this.yTickSize         );
12036         }
12037     },
12038
12039     
12040
12041     getTick: function(z, AA) {
12042
12043         if (!AA) {
12044             
12045             
12046             return  z;
12047         } else  if (AA[0] >= z) {
12048             
12049             
12050             return  AA[0];
12051         } else  {
12052             for (var  i=0, len=AA.length; i<len; ++i) {
12053                 var  next = i + 1;
12054                 if (AA[next] && AA[next] >= z) {
12055                     var  diff1 = z - AA[i];
12056                     var  diff2 = AA[next] - z;
12057                     return  (diff2 > diff1) ? AA[i] : AA[next];
12058                 }
12059             }
12060
12061             
12062             
12063             return  AA[AA.length - 1];
12064         }
12065     },
12066
12067     
12068
12069     toString: function() {
12070         return  ("DragDrop " + this.id);
12071     }
12072
12073 };
12074
12075 })();
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086 if (!Roo.dd.DragDropMgr) {
12087
12088
12089
12090 Roo.dd.DragDropMgr = function() {
12091
12092     var  A = Roo.EventManager;
12093
12094     return  {
12095
12096         
12097
12098         ids: {},
12099
12100         
12101
12102         handleIds: {},
12103
12104         
12105
12106         dragCurrent: null,
12107
12108         
12109
12110         dragOvers: {},
12111
12112         
12113
12114         deltaX: 0,
12115
12116         
12117
12118         deltaY: 0,
12119
12120         
12121
12122         preventDefault: true,
12123
12124         
12125
12126         stopPropagation: true,
12127
12128         
12129
12130         initalized: false,
12131
12132         
12133
12134         locked: false,
12135
12136         
12137
12138         init: function() {
12139             this.initialized = true;
12140         },
12141
12142         
12143
12144         POINT: 0,
12145
12146         
12147
12148         INTERSECT: 1,
12149
12150         
12151
12152         mode: 0,
12153
12154         
12155
12156         _execOnAll: function(AG, AH) {
12157             for (var  i  in  this.ids) {
12158                 for (var  j  in  this.ids[i]) {
12159                     var  h = this.ids[i][j];
12160                     if (! this.isTypeOfDD(h)) {
12161                         continue;
12162                     }
12163
12164                     h[AG].apply(h, AH);
12165                 }
12166             }
12167         },
12168
12169         
12170
12171         _onLoad: function() {
12172
12173             this.init();
12174
12175
12176             A.on(document, "mouseup",   this.handleMouseUp, this, true);
12177             A.on(document, "mousemove", this.handleMouseMove, this, true);
12178             A.on(window,   "unload",    this._onUnload, this, true);
12179             A.on(window,   "resize",    this._onResize, this, true);
12180             
12181
12182         },
12183
12184         
12185
12186         _onResize: function(e) {
12187             this._execOnAll("resetConstraints", []);
12188         },
12189
12190         
12191
12192         lock: function() { this.locked = true; },
12193
12194         
12195
12196         unlock: function() { this.locked = false; },
12197
12198         
12199
12200         isLocked: function() { return  this.locked; },
12201
12202         
12203
12204         locationCache: {},
12205
12206         
12207
12208         useCache: true,
12209
12210         
12211
12212         clickPixelThresh: 3,
12213
12214         
12215
12216         clickTimeThresh: 350,
12217
12218         
12219
12220         dragThreshMet: false,
12221
12222         
12223
12224         clickTimeout: null,
12225
12226         
12227
12228         startX: 0,
12229
12230         
12231
12232         startY: 0,
12233
12234         
12235
12236         regDragDrop: function(AI, AJ) {
12237             if (!this.initialized) { this.init(); }
12238
12239             if (!this.ids[AJ]) {
12240                 this.ids[AJ] = {};
12241             }
12242
12243             this.ids[AJ][AI.id] = AI;
12244         },
12245
12246         
12247
12248         removeDDFromGroup: function(AK, AL) {
12249             if (!this.ids[AL]) {
12250                 this.ids[AL] = {};
12251             }
12252
12253             var  AM = this.ids[AL];
12254             if (AM && AM[AK.id]) {
12255                 delete  AM[AK.id];
12256             }
12257         },
12258
12259         
12260
12261         _remove: function(AN) {
12262             for (var  g  in  AN.groups) {
12263                 if (g && this.ids[g][AN.id]) {
12264                     delete  this.ids[g][AN.id];
12265                 }
12266             }
12267             delete  this.handleIds[AN.id];
12268         },
12269
12270         
12271
12272         regHandle: function(AO, AP) {
12273             if (!this.handleIds[AO]) {
12274                 this.handleIds[AO] = {};
12275             }
12276
12277             this.handleIds[AO][AP] = AP;
12278         },
12279
12280         
12281
12282         isDragDrop: function(id) {
12283             return  ( this.getDDById(id) ) ? true : false;
12284         },
12285
12286         
12287
12288         getRelated: function(AQ, AR) {
12289             var  AS = [];
12290             for (var  i  in  AQ.groups) {
12291                 for (j  in  this.ids[i]) {
12292                     var  dd = this.ids[i][j];
12293                     if (! this.isTypeOfDD(dd)) {
12294                         continue;
12295                     }
12296                     if (!AR || dd.isTarget) {
12297                         AS[AS.length] = dd;
12298                     }
12299                 }
12300             }
12301
12302             return  AS;
12303         },
12304
12305         
12306
12307         isLegalTarget: function (AT, AU) {
12308             var  AV = this.getRelated(AT, true);
12309             for (var  i=0, d=AV.length;i<d;++i) {
12310                 if (AV[i].id == AU.id) {
12311                     return  true;
12312                 }
12313             }
12314
12315             return  false;
12316         },
12317
12318         
12319
12320         isTypeOfDD: function (AW) {
12321             return  (AW && AW.__ygDragDrop);
12322         },
12323
12324         
12325
12326         isHandle: function(AX, AY) {
12327             return  ( this.handleIds[AX] &&
12328                             this.handleIds[AX][AY] );
12329         },
12330
12331         
12332
12333         getDDById: function(id) {
12334             for (var  i  in  this.ids) {
12335                 if (this.ids[i][id]) {
12336                     return  this.ids[i][id];
12337                 }
12338             }
12339             return  null;
12340         },
12341
12342         
12343
12344         handleMouseDown: function(e, AZ) {
12345             if(Roo.QuickTips){
12346                 Roo.QuickTips.disable();
12347             }
12348
12349             this.currentTarget = e.getTarget();
12350
12351             this.dragCurrent = AZ;
12352
12353             var  el = AZ.getEl();
12354
12355             
12356             this.startX = e.getPageX();
12357             this.startY = e.getPageY();
12358
12359             this.deltaX = this.startX - el.offsetLeft;
12360             this.deltaY = this.startY - el.offsetTop;
12361
12362             this.dragThreshMet = false;
12363
12364             this.clickTimeout = setTimeout(
12365                     function() {
12366                         var  Aa = Roo.dd.DDM;
12367                         Aa.startDrag(Aa.startX, Aa.startY);
12368                     },
12369                     this.clickTimeThresh );
12370         },
12371
12372         
12373
12374         startDrag: function(x, y) {
12375             clearTimeout(this.clickTimeout);
12376             if (this.dragCurrent) {
12377                 this.dragCurrent.b4StartDrag(x, y);
12378                 this.dragCurrent.startDrag(x, y);
12379             }
12380
12381             this.dragThreshMet = true;
12382         },
12383
12384         
12385
12386         handleMouseUp: function(e) {
12387
12388             if(Roo.QuickTips){
12389                 Roo.QuickTips.enable();
12390             }
12391             if (! this.dragCurrent) {
12392                 return;
12393             }
12394
12395
12396             clearTimeout(this.clickTimeout);
12397
12398             if (this.dragThreshMet) {
12399                 this.fireEvents(e, true);
12400             } else  {
12401             }
12402
12403
12404             this.stopDrag(e);
12405
12406             this.stopEvent(e);
12407         },
12408
12409         
12410
12411         stopEvent: function(e){
12412             if(this.stopPropagation) {
12413                 e.stopPropagation();
12414             }
12415
12416             if (this.preventDefault) {
12417                 e.preventDefault();
12418             }
12419         },
12420
12421         
12422
12423         stopDrag: function(e) {
12424             
12425             if (this.dragCurrent) {
12426                 if (this.dragThreshMet) {
12427                     this.dragCurrent.b4EndDrag(e);
12428                     this.dragCurrent.endDrag(e);
12429                 }
12430
12431
12432                 this.dragCurrent.onMouseUp(e);
12433             }
12434
12435
12436             this.dragCurrent = null;
12437             this.dragOvers = {};
12438         },
12439
12440         
12441
12442         handleMouseMove: function(e) {
12443             if (! this.dragCurrent) {
12444                 return  true;
12445             }
12446
12447             
12448
12449             
12450             if (Roo.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
12451                 this.stopEvent(e);
12452                 return  this.handleMouseUp(e);
12453             }
12454
12455             if (!this.dragThreshMet) {
12456                 var  diffX = Math.abs(this.startX - e.getPageX());
12457                 var  diffY = Math.abs(this.startY - e.getPageY());
12458                 if (diffX > this.clickPixelThresh ||
12459                             diffY > this.clickPixelThresh) {
12460                     this.startDrag(this.startX, this.startY);
12461                 }
12462             }
12463
12464             if (this.dragThreshMet) {
12465                 this.dragCurrent.b4Drag(e);
12466                 this.dragCurrent.onDrag(e);
12467                 if(!this.dragCurrent.moveOnly){
12468                     this.fireEvents(e, false);
12469                 }
12470             }
12471
12472
12473             this.stopEvent(e);
12474
12475             return  true;
12476         },
12477
12478         
12479
12480         fireEvents: function(e, Aa) {
12481             var  dc = this.dragCurrent;
12482
12483             
12484             
12485             if (!dc || dc.isLocked()) {
12486                 return;
12487             }
12488
12489             var  pt = e.getPoint();
12490
12491             
12492             var  Ab = [];
12493
12494             var  Ac   = [];
12495             var  Ad  = [];
12496             var  Ae  = [];
12497             var  Af = [];
12498
12499             
12500             
12501             for (var  i  in  this.dragOvers) {
12502
12503                 var  ddo = this.dragOvers[i];
12504
12505                 if (! this.isTypeOfDD(ddo)) {
12506                     continue;
12507                 }
12508
12509                 if (! this.isOverTarget(pt, ddo, this.mode)) {
12510                     Ac.push( ddo );
12511                 }
12512
12513
12514                 Ab[i] = true;
12515                 delete  this.dragOvers[i];
12516             }
12517
12518             for (var  AL  in  dc.groups) {
12519
12520                 if ("string" != typeof  AL) {
12521                     continue;
12522                 }
12523
12524                 for (i  in  this.ids[AL]) {
12525                     var  AZ = this.ids[AL][i];
12526                     if (! this.isTypeOfDD(AZ)) {
12527                         continue;
12528                     }
12529
12530                     if (AZ.isTarget && !AZ.isLocked() && AZ != dc) {
12531                         if (this.isOverTarget(pt, AZ, this.mode)) {
12532                             
12533                             if (Aa) {
12534                                 Ae.push( AZ );
12535                             
12536                             } else  {
12537
12538                                 
12539                                 if (!Ab[AZ.id]) {
12540                                     Af.push( AZ );
12541                                 
12542                                 } else  {
12543                                     Ad.push( AZ );
12544                                 }
12545
12546
12547                                 this.dragOvers[AZ.id] = AZ;
12548                             }
12549                         }
12550                     }
12551                 }
12552             }
12553
12554             if (this.mode) {
12555                 if (Ac.length) {
12556                     dc.b4DragOut(e, Ac);
12557                     dc.onDragOut(e, Ac);
12558                 }
12559
12560                 if (Af.length) {
12561                     dc.onDragEnter(e, Af);
12562                 }
12563
12564                 if (Ad.length) {
12565                     dc.b4DragOver(e, Ad);
12566                     dc.onDragOver(e, Ad);
12567                 }
12568
12569                 if (Ae.length) {
12570                     dc.b4DragDrop(e, Ae);
12571                     dc.onDragDrop(e, Ae);
12572                 }
12573
12574             } else  {
12575                 
12576                 var  d = 0;
12577                 for (i=0, d=Ac.length; i<d; ++i) {
12578                     dc.b4DragOut(e, Ac[i].id);
12579                     dc.onDragOut(e, Ac[i].id);
12580                 }
12581
12582                 
12583                 for (i=0,d=Af.length; i<d; ++i) {
12584                     
12585                     dc.onDragEnter(e, Af[i].id);
12586                 }
12587
12588                 
12589                 for (i=0,d=Ad.length; i<d; ++i) {
12590                     dc.b4DragOver(e, Ad[i].id);
12591                     dc.onDragOver(e, Ad[i].id);
12592                 }
12593
12594                 
12595                 for (i=0, d=Ae.length; i<d; ++i) {
12596                     dc.b4DragDrop(e, Ae[i].id);
12597                     dc.onDragDrop(e, Ae[i].id);
12598                 }
12599
12600             }
12601
12602             
12603             if (Aa && !Ae.length) {
12604                 dc.onInvalidDrop(e);
12605             }
12606
12607         },
12608
12609         
12610
12611         getBestMatch: function(Ag) {
12612             var  Ah = null;
12613             
12614             
12615                
12616             
12617             
12618
12619             var  Ai = Ag.length;
12620
12621             if (Ai == 1) {
12622                 Ah = Ag[0];
12623             } else  {
12624                 
12625                 for (var  i=0; i<Ai; ++i) {
12626                     var  dd = Ag[i];
12627                     
12628                     
12629                     
12630                     if (dd.cursorIsOver) {
12631                         Ah = dd;
12632                         break;
12633                     
12634                     } else  {
12635                         if (!Ah ||
12636                             Ah.overlap.getArea() < dd.overlap.getArea()) {
12637                             Ah = dd;
12638                         }
12639                     }
12640                 }
12641             }
12642
12643             return  Ah;
12644         },
12645
12646         
12647
12648         refreshCache: function(Aj) {
12649             for (var  AL  in  Aj) {
12650                 if ("string" != typeof  AL) {
12651                     continue;
12652                 }
12653                 for (var  i  in  this.ids[AL]) {
12654                     var  AZ = this.ids[AL][i];
12655
12656                     if (this.isTypeOfDD(AZ)) {
12657                     
12658                         var  o = this.getLocation(AZ);
12659                         if (o) {
12660                             this.locationCache[AZ.id] = o;
12661                         } else  {
12662                             delete  this.locationCache[AZ.id];
12663                             
12664                             
12665                             
12666                         }
12667                     }
12668                 }
12669             }
12670         },
12671
12672         
12673
12674         verifyEl: function(el) {
12675             if (el) {
12676                 var  parent;
12677                 if(Roo.isIE){
12678                     try{
12679                         parent = el.offsetParent;
12680                     }catch(e){}
12681                 }else {
12682                     parent = el.offsetParent;
12683                 }
12684                 if (parent) {
12685                     return  true;
12686                 }
12687             }
12688
12689             return  false;
12690         },
12691
12692         
12693
12694         getLocation: function(Ak) {
12695             if (! this.isTypeOfDD(Ak)) {
12696                 return  null;
12697             }
12698
12699             var  el = Ak.getEl(), Al, x1, x2, y1, y2, t, r, b, l;
12700
12701             try {
12702                 Al= Roo.lib.Dom.getXY(el);
12703             } catch (e) { }
12704
12705             if (!Al) {
12706                 return  null;
12707             }
12708
12709
12710             x1 = Al[0];
12711             x2 = x1 + el.offsetWidth;
12712             y1 = Al[1];
12713             y2 = y1 + el.offsetHeight;
12714
12715             t = y1 - Ak.padding[0];
12716             r = x2 + Ak.padding[1];
12717             b = y2 + Ak.padding[2];
12718             l = x1 - Ak.padding[3];
12719
12720             return  new  Roo.lib.Region( t, r, b, l );
12721         },
12722
12723         
12724
12725         isOverTarget: function(pt, Am, An) {
12726             
12727             var  Ao = this.locationCache[Am.id];
12728             if (!Ao || !this.useCache) {
12729                 Ao = this.getLocation(Am);
12730                 this.locationCache[Am.id] = Ao;
12731
12732             }
12733
12734             if (!Ao) {
12735                 return  false;
12736             }
12737
12738
12739             Am.cursorIsOver = Ao.contains( pt );
12740
12741             
12742             
12743             
12744             
12745             
12746             var  dc = this.dragCurrent;
12747             if (!dc || !dc.getTargetCoord ||
12748                     (!An && !dc.constrainX && !dc.constrainY)) {
12749                 return  Am.cursorIsOver;
12750             }
12751
12752
12753             Am.overlap = null;
12754
12755             
12756             
12757             
12758             
12759             var  Ap = dc.getTargetCoord(pt.x, pt.y);
12760
12761             var  el = dc.getDragEl();
12762             var  Aq = new  Roo.lib.Region( Ap.y,
12763                                                    Ap.x + el.offsetWidth,
12764                                                    Ap.y + el.offsetHeight,
12765                                                    Ap.x );
12766
12767             var  Ar = Aq.intersect(Ao);
12768
12769             if (Ar) {
12770                 Am.overlap = Ar;
12771                 return  (An) ? true : Am.cursorIsOver;
12772             } else  {
12773                 return  false;
12774             }
12775         },
12776
12777         
12778
12779         _onUnload: function(e, me) {
12780             Roo.dd.DragDropMgr.unregAll();
12781         },
12782
12783         
12784
12785         unregAll: function() {
12786
12787             if (this.dragCurrent) {
12788                 this.stopDrag();
12789                 this.dragCurrent = null;
12790             }
12791
12792
12793             this._execOnAll("unreg", []);
12794
12795             for (i  in  this.elementCache) {
12796                 delete  this.elementCache[i];
12797             }
12798
12799
12800             this.elementCache = {};
12801             this.ids = {};
12802         },
12803
12804         
12805
12806         elementCache: {},
12807
12808         
12809
12810         getElWrapper: function(id) {
12811             var  As = this.elementCache[id];
12812             if (!As || !As.el) {
12813                 As = this.elementCache[id] =
12814                     new  this.ElementWrapper(Roo.getDom(id));
12815             }
12816             return  As;
12817         },
12818
12819         
12820
12821         getElement: function(id) {
12822             return  Roo.getDom(id);
12823         },
12824
12825         
12826
12827         getCss: function(id) {
12828             var  el = Roo.getDom(id);
12829             return  (el) ? el.style : null;
12830         },
12831
12832         
12833
12834         ElementWrapper: function(el) {
12835                 
12836
12837                 this.el = el || null;
12838                 
12839
12840                 this.id = this.el && el.id;
12841                 
12842
12843                 this.css = this.el && el.style;
12844             },
12845
12846         
12847
12848         getPosX: function(el) {
12849             return  Roo.lib.Dom.getX(el);
12850         },
12851
12852         
12853
12854         getPosY: function(el) {
12855             return  Roo.lib.Dom.getY(el);
12856         },
12857
12858         
12859
12860         swapNode: function(n1, n2) {
12861             if (n1.swapNode) {
12862                 n1.swapNode(n2);
12863             } else  {
12864                 var  p = n2.parentNode;
12865                 var  s = n2.nextSibling;
12866
12867                 if (s == n1) {
12868                     p.insertBefore(n1, n2);
12869                 } else  if (n2 == n1.nextSibling) {
12870                     p.insertBefore(n2, n1);
12871                 } else  {
12872                     n1.parentNode.replaceChild(n2, n1);
12873                     p.insertBefore(n1, s);
12874                 }
12875             }
12876         },
12877
12878         
12879
12880         getScroll: function () {
12881             var  t, l, At=document.documentElement, db=document.body;
12882             if (At && (At.scrollTop || At.scrollLeft)) {
12883                 t = At.scrollTop;
12884                 l = At.scrollLeft;
12885             } else  if (db) {
12886                 t = db.scrollTop;
12887                 l = db.scrollLeft;
12888             } else  {
12889
12890             }
12891             return  { top: t, left: l };
12892         },
12893
12894         
12895
12896         getStyle: function(el, Au) {
12897             return  Roo.fly(el).getStyle(Au);
12898         },
12899
12900         
12901
12902         getScrollTop: function () { return  this.getScroll().top; },
12903
12904         
12905
12906         getScrollLeft: function () { return  this.getScroll().left; },
12907
12908         
12909
12910         moveToEl: function (Av, Aw) {
12911             var  Ax = Roo.lib.Dom.getXY(Aw);
12912             Roo.lib.Dom.setXY(Av, Ax);
12913         },
12914
12915         
12916
12917         numericSort: function(a, b) { return  (a - b); },
12918
12919         
12920
12921         _timeoutCount: 0,
12922
12923         
12924
12925         _addListeners: function() {
12926             var  Ay = Roo.dd.DDM;
12927             if ( Roo.lib.Event && document ) {
12928                 Ay._onLoad();
12929             } else  {
12930                 if (Ay._timeoutCount > 2000) {
12931                 } else  {
12932                     setTimeout(Ay._addListeners, 10);
12933                     if (document && document.body) {
12934                         Ay._timeoutCount += 1;
12935                     }
12936                 }
12937             }
12938         },
12939
12940         
12941
12942         handleWasClicked: function(Az, id) {
12943             if (this.isHandle(id, Az.id)) {
12944                 return  true;
12945             } else  {
12946                 
12947                 var  p = Az.parentNode;
12948
12949                 while (p) {
12950                     if (this.isHandle(id, p.id)) {
12951                         return  true;
12952                     } else  {
12953                         p = p.parentNode;
12954                     }
12955                 }
12956             }
12957
12958             return  false;
12959         }
12960
12961     };
12962
12963 }();
12964
12965
12966 Roo.dd.DDM = Roo.dd.DragDropMgr;
12967 Roo.dd.DDM._addListeners();
12968
12969 }
12970
12971
12972
12973
12974
12975 Roo.dd.DD = function(id, A, B) {
12976     if (id) {
12977         this.init(id, A, B);
12978     }
12979 };
12980
12981 Roo.extend(Roo.dd.DD, Roo.dd.DragDrop, {
12982
12983     
12984
12985     scroll: true,
12986
12987     
12988
12989     autoOffset: function(C, D) {
12990         var  x = C - this.startPageX;
12991         var  y = D - this.startPageY;
12992         this.setDelta(x, y);
12993     },
12994
12995     
12996
12997     setDelta: function(E, F) {
12998         this.deltaX = E;
12999         this.deltaY = F;
13000     },
13001
13002     
13003
13004     setDragElPos: function(G, H) {
13005         
13006         
13007
13008         var  el = this.getDragEl();
13009         this.alignElWithMouse(el, G, H);
13010     },
13011
13012     
13013
13014     alignElWithMouse: function(el, I, J) {
13015         var  K = this.getTargetCoord(I, J);
13016         var  L = el.dom ? el : Roo.fly(el);
13017         if (!this.deltaSetXY) {
13018             var  aCoord = [K.x, K.y];
13019             L.setXY(aCoord);
13020             var  newLeft = L.getLeft(true);
13021             var  newTop  = L.getTop(true);
13022             this.deltaSetXY = [ newLeft - K.x, newTop - K.y ];
13023         } else  {
13024             L.setLeftTop(K.x + this.deltaSetXY[0], K.y + this.deltaSetXY[1]);
13025         }
13026
13027
13028         this.cachePosition(K.x, K.y);
13029         this.autoScroll(K.x, K.y, el.offsetHeight, el.offsetWidth);
13030         return  K;
13031     },
13032
13033     
13034
13035     cachePosition: function(M, N) {
13036         if (M) {
13037             this.lastPageX = M;
13038             this.lastPageY = N;
13039         } else  {
13040             var  aCoord = Roo.lib.Dom.getXY(this.getEl());
13041             this.lastPageX = aCoord[0];
13042             this.lastPageY = aCoord[1];
13043         }
13044     },
13045
13046     
13047
13048     autoScroll: function(x, y, h, w) {
13049
13050         if (this.scroll) {
13051             
13052             var  clientH = Roo.lib.Dom.getViewWidth();
13053
13054             
13055             var  clientW = Roo.lib.Dom.getViewHeight();
13056
13057             
13058             var  st = this.DDM.getScrollTop();
13059
13060             
13061             var  sl = this.DDM.getScrollLeft();
13062
13063             
13064             var  bot = h + y;
13065
13066             
13067             var  right = w + x;
13068
13069             
13070             
13071             
13072             var  toBot = (clientH + st - y - this.deltaY);
13073
13074             
13075             var  toRight = (clientW + sl - x - this.deltaX);
13076
13077
13078             
13079             
13080             var  thresh = 40;
13081
13082             
13083             
13084             
13085             var  scrAmt = (document.all) ? 80 : 30;
13086
13087             
13088             
13089             if ( bot > clientH && toBot < thresh ) {
13090                 window.scrollTo(sl, st + scrAmt);
13091             }
13092
13093             
13094             
13095             if ( y < st && st > 0 && y - st < thresh ) {
13096                 window.scrollTo(sl, st - scrAmt);
13097             }
13098
13099             
13100             
13101             if ( right > clientW && toRight < thresh ) {
13102                 window.scrollTo(sl + scrAmt, st);
13103             }
13104
13105             
13106             
13107             if ( x < sl && sl > 0 && x - sl < thresh ) {
13108                 window.scrollTo(sl - scrAmt, st);
13109             }
13110         }
13111     },
13112
13113     
13114
13115     getTargetCoord: function(O, P) {
13116
13117
13118         var  x = O - this.deltaX;
13119         var  y = P - this.deltaY;
13120
13121         if (this.constrainX) {
13122             if (x < this.minX) { x = this.minX; }
13123             if (x > this.maxX) { x = this.maxX; }
13124         }
13125
13126         if (this.constrainY) {
13127             if (y < this.minY) { y = this.minY; }
13128             if (y > this.maxY) { y = this.maxY; }
13129         }
13130
13131
13132         x = this.getTick(x, this.xTicks);
13133         y = this.getTick(y, this.yTicks);
13134
13135
13136         return  {x:x, y:y};
13137     },
13138
13139     
13140
13141     applyConfig: function() {
13142         Roo.dd.DD.superclass.applyConfig.call(this);
13143         this.scroll = (this.config.scroll !== false);
13144     },
13145
13146     
13147
13148     b4MouseDown: function(e) {
13149         
13150         this.autoOffset(e.getPageX(),
13151                             e.getPageY());
13152     },
13153
13154     
13155
13156     b4Drag: function(e) {
13157         this.setDragElPos(e.getPageX(),
13158                             e.getPageY());
13159     },
13160
13161     toString: function() {
13162         return  ("DD " + this.id);
13163     }
13164
13165     
13166     
13167     
13168     
13169
13170
13171 });
13172
13173
13174
13175
13176
13177 Roo.dd.DDProxy = function(id, A, B) {
13178     if (id) {
13179         this.init(id, A, B);
13180         this.initFrame();
13181     }
13182 };
13183
13184
13185
13186 Roo.dd.DDProxy.dragElId = "ygddfdiv";
13187
13188 Roo.extend(Roo.dd.DDProxy, Roo.dd.DD, {
13189
13190     
13191
13192     resizeFrame: true,
13193
13194     
13195
13196     centerFrame: false,
13197
13198     
13199
13200     createFrame: function() {
13201         var  C = this;
13202         var  D = document.body;
13203
13204         if (!D || !D.firstChild) {
13205             setTimeout( function() { C.createFrame(); }, 50 );
13206             return;
13207         }
13208
13209         var  E = this.getDragEl();
13210
13211         if (!E) {
13212             E    = document.createElement("div");
13213             E.id = this.dragElId;
13214             var  s  = E.style;
13215
13216             s.position   = "absolute";
13217             s.visibility = "hidden";
13218             s.cursor     = "move";
13219             s.border     = "2px solid #aaa";
13220             s.zIndex     = 999;
13221
13222             
13223             
13224             
13225             D.insertBefore(E, D.firstChild);
13226         }
13227     },
13228
13229     
13230
13231     initFrame: function() {
13232         this.createFrame();
13233     },
13234
13235     applyConfig: function() {
13236         Roo.dd.DDProxy.superclass.applyConfig.call(this);
13237
13238         this.resizeFrame = (this.config.resizeFrame !== false);
13239         this.centerFrame = (this.config.centerFrame);
13240         this.setDragElId(this.config.dragElId || Roo.dd.DDProxy.dragElId);
13241     },
13242
13243     
13244
13245     showFrame: function(F, G) {
13246         var  el = this.getEl();
13247         var  H = this.getDragEl();
13248         var  s = H.style;
13249
13250         this._resizeProxy();
13251
13252         if (this.centerFrame) {
13253             this.setDelta( Math.round(parseInt(s.width,  10)/2),
13254                            Math.round(parseInt(s.height, 10)/2) );
13255         }
13256
13257
13258         this.setDragElPos(F, G);
13259
13260         Roo.fly(H).show();
13261     },
13262
13263     
13264
13265     _resizeProxy: function() {
13266         if (this.resizeFrame) {
13267             var  el = this.getEl();
13268             Roo.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
13269         }
13270     },
13271
13272     
13273     b4MouseDown: function(e) {
13274         var  x = e.getPageX();
13275         var  y = e.getPageY();
13276         this.autoOffset(x, y);
13277         this.setDragElPos(x, y);
13278     },
13279
13280     
13281     b4StartDrag: function(x, y) {
13282         
13283         this.showFrame(x, y);
13284     },
13285
13286     
13287     b4EndDrag: function(e) {
13288         Roo.fly(this.getDragEl()).hide();
13289     },
13290
13291     
13292     
13293     
13294     endDrag: function(e) {
13295
13296         var  I = this.getEl();
13297         var  J = this.getDragEl();
13298
13299         
13300         J.style.visibility = "";
13301
13302         this.beforeMove();
13303         
13304         
13305         I.style.visibility = "hidden";
13306         Roo.dd.DDM.moveToEl(I, J);
13307         J.style.visibility = "hidden";
13308         I.style.visibility = "";
13309
13310         this.afterDrag();
13311     },
13312
13313     beforeMove : function(){
13314
13315     },
13316
13317     afterDrag : function(){
13318
13319     },
13320
13321     toString: function() {
13322         return  ("DDProxy " + this.id);
13323     }
13324
13325 });
13326
13327
13328
13329
13330  
13331
13332 Roo.dd.DDTarget = function(id, A, B) {
13333     if (id) {
13334         this.initTarget(id, A, B);
13335     }
13336 };
13337
13338
13339 Roo.extend(Roo.dd.DDTarget, Roo.dd.DragDrop, {
13340     toString: function() {
13341         return  ("DDTarget " + this.id);
13342     }
13343 });
13344
13345
13346
13347  
13348
13349
13350
13351 Roo.dd.ScrollManager = function(){
13352     var  A = Roo.dd.DragDropMgr;
13353     var  B = {};
13354     var  C = null;
13355     var  D = {};
13356     
13357     var  E = function(e){
13358         C = null;
13359         H();
13360     };
13361     
13362     var  F = function(){
13363         if(A.dragCurrent){
13364              A.refreshCache(A.dragCurrent.groups);
13365         }
13366     };
13367     
13368     var  G = function(){
13369         if(A.dragCurrent){
13370             var  dds = Roo.dd.ScrollManager;
13371             if(!dds.animate){
13372                 if(D.el.scroll(D.dir, dds.increment)){
13373                     F();
13374                 }
13375             }else {
13376                 D.el.scroll(D.dir, dds.increment, true, dds.animDuration, F);
13377             }
13378         }
13379     };
13380     
13381     var  H = function(){
13382         if(D.id){
13383             clearInterval(D.id);
13384         }
13385
13386         D.id = 0;
13387         D.el = null;
13388         D.dir = "";
13389     };
13390     
13391     var  I = function(el, K){
13392         H();
13393         D.el = el;
13394         D.dir = K;
13395         D.id = setInterval(G, Roo.dd.ScrollManager.frequency);
13396     };
13397     
13398     var  J = function(e, K){
13399         if(K || !A.dragCurrent){ return; }
13400         var  L = Roo.dd.ScrollManager;
13401         if(!C || C != A.dragCurrent){
13402             C = A.dragCurrent;
13403             
13404             L.refreshCache();
13405         }
13406         
13407         var  xy = Roo.lib.Event.getXY(e);
13408         var  pt = new  Roo.lib.Point(xy[0], xy[1]);
13409         for(var  id  in  B){
13410             var  el = B[id], r = el._region;
13411             if(r && r.contains(pt) && el.isScrollable()){
13412                 if(r.bottom - pt.y <= L.thresh){
13413                     if(D.el != el){
13414                         I(el, "down");
13415                     }
13416                     return;
13417                 }else  if(r.right - pt.x <= L.thresh){
13418                     if(D.el != el){
13419                         I(el, "left");
13420                     }
13421                     return;
13422                 }else  if(pt.y - r.top <= L.thresh){
13423                     if(D.el != el){
13424                         I(el, "up");
13425                     }
13426                     return;
13427                 }else  if(pt.x - r.left <= L.thresh){
13428                     if(D.el != el){
13429                         I(el, "right");
13430                     }
13431                     return;
13432                 }
13433             }
13434         }
13435
13436         H();
13437     };
13438     
13439     A.fireEvents = A.fireEvents.createSequence(J, A);
13440     A.stopDrag = A.stopDrag.createSequence(E, A);
13441     
13442     return  {
13443         
13444
13445         register : function(el){
13446             if(el  instanceof  Array){
13447                 for(var  i = 0, len = el.length; i < len; i++) {
13448                         this.register(el[i]);
13449                 }
13450             }else {
13451                 el = Roo.get(el);
13452                 B[el.id] = el;
13453             }
13454         },
13455         
13456         
13457
13458         unregister : function(el){
13459             if(el  instanceof  Array){
13460                 for(var  i = 0, len = el.length; i < len; i++) {
13461                         this.unregister(el[i]);
13462                 }
13463             }else {
13464                 el = Roo.get(el);
13465                 delete  B[el.id];
13466             }
13467         },
13468         
13469         
13470
13471         thresh : 25,
13472         
13473         
13474
13475         increment : 100,
13476         
13477         
13478
13479         frequency : 500,
13480         
13481         
13482
13483         animate: true,
13484         
13485         
13486
13487         animDuration: .4,
13488         
13489         
13490
13491         refreshCache : function(){
13492             for(var  id  in  B){
13493                 if(typeof  B[id] == 'object'){ 
13494                     B[id]._region = B[id].getRegion();
13495                 }
13496             }
13497         }
13498     };
13499 }();
13500
13501
13502  
13503
13504
13505
13506 Roo.dd.Registry = function(){
13507     var  A = {}; 
13508     var  B = {}; 
13509     var  C = 0;
13510
13511     var  D = function(el, E){
13512         if(typeof  el == "string"){
13513             return  el;
13514         }
13515         var  id = el.id;
13516         if(!id && E !== false){
13517             id = "roodd-" + (++C);
13518             el.id = id;
13519         }
13520         return  id;
13521     };
13522     
13523     return  {
13524     
13525
13526         register : function(el, G){
13527             G = G || {};
13528             if(typeof  el == "string"){
13529                 el = document.getElementById(el);
13530             }
13531
13532             G.ddel = el;
13533             A[D(el)] = G;
13534             if(G.isHandle !== false){
13535                 B[G.ddel.id] = G;
13536             }
13537             if(G.handles){
13538                 var  hs = G.handles;
13539                 for(var  i = 0, len = hs.length; i < len; i++){
13540                         B[D(hs[i])] = G;
13541                 }
13542             }
13543         },
13544
13545     
13546
13547         unregister : function(el){
13548             var  id = D(el, false);
13549             var  H = A[id];
13550             if(H){
13551                 delete  A[id];
13552                 if(H.handles){
13553                     var  hs = H.handles;
13554                     for(var  i = 0, len = hs.length; i < len; i++){
13555                         delete  B[D(hs[i], false)];
13556                     }
13557                 }
13558             }
13559         },
13560
13561     
13562
13563         getHandle : function(id){
13564             if(typeof  id != "string"){ 
13565                 id = id.id;
13566             }
13567             return  B[id];
13568         },
13569
13570     
13571
13572         getHandleFromEvent : function(e){
13573             var  t = Roo.lib.Event.getTarget(e);
13574             return  t ? B[t.id] : null;
13575         },
13576
13577     
13578
13579         getTarget : function(id){
13580             if(typeof  id != "string"){ 
13581                 id = id.id;
13582             }
13583             return  A[id];
13584         },
13585
13586     
13587
13588         getTargetFromEvent : function(e){
13589             var  t = Roo.lib.Event.getTarget(e);
13590             return  t ? A[t.id] || B[t.id] : null;
13591         }
13592     };
13593 }();
13594
13595
13596  
13597
13598
13599
13600 Roo.dd.StatusProxy = function(A){
13601     Roo.apply(this, A);
13602     this.id = this.id || Roo.id();
13603     this.el = new  Roo.Layer({
13604         dh: {
13605             id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
13606                 {tag: "div", cls: "x-dd-drop-icon"},
13607                 {tag: "div", cls: "x-dd-drag-ghost"}
13608             ]
13609         }, 
13610         shadow: !A || A.shadow !== false
13611     });
13612     this.ghost = Roo.get(this.el.dom.childNodes[1]);
13613     this.dropStatus = this.dropNotAllowed;
13614 };
13615
13616 Roo.dd.StatusProxy.prototype = {
13617     
13618
13619     dropAllowed : "x-dd-drop-ok",
13620     
13621
13622     dropNotAllowed : "x-dd-drop-nodrop",
13623
13624     
13625
13626     setStatus : function(B){
13627         B = B || this.dropNotAllowed;
13628         if(this.dropStatus != B){
13629             this.el.replaceClass(this.dropStatus, B);
13630             this.dropStatus = B;
13631         }
13632     },
13633
13634     
13635
13636     reset : function(C){
13637         this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
13638         this.dropStatus = this.dropNotAllowed;
13639         if(C){
13640             this.ghost.update("");
13641         }
13642     },
13643
13644     
13645
13646     update : function(D){
13647         if(typeof  D == "string"){
13648             this.ghost.update(D);
13649         }else {
13650             this.ghost.update("");
13651             D.style.margin = "0";
13652             this.ghost.dom.appendChild(D);
13653         }
13654         
13655         var  el = this.ghost.dom.firstChild;
13656                 if(el){
13657                         Roo.fly(el).setStyle('float', 'none');
13658                 }
13659     },
13660     
13661     
13662
13663     getEl : function(){
13664         return  this.el;
13665     },
13666
13667     
13668
13669     getGhost : function(){
13670         return  this.ghost;
13671     },
13672
13673     
13674
13675     hide : function(E){
13676         this.el.hide();
13677         if(E){
13678             this.reset(true);
13679         }
13680     },
13681
13682     
13683
13684     stop : function(){
13685         if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
13686             this.anim.stop();
13687         }
13688     },
13689
13690     
13691
13692     show : function(){
13693         this.el.show();
13694     },
13695
13696     
13697
13698     sync : function(){
13699         this.el.sync();
13700     },
13701
13702     
13703
13704     repair : function(xy, F, G){
13705         this.callback = F;
13706         this.scope = G;
13707         if(xy && this.animRepair !== false){
13708             this.el.addClass("x-dd-drag-repair");
13709             this.el.hideUnders(true);
13710             this.anim = this.el.shift({
13711                 duration: this.repairDuration || .5,
13712                 easing: 'easeOut',
13713                 xy: xy,
13714                 stopFx: true,
13715                 callback: this.afterRepair,
13716                 scope: this
13717             });
13718         }else {
13719             this.afterRepair();
13720         }
13721     },
13722
13723     
13724     afterRepair : function(){
13725         this.hide(true);
13726         if(typeof  this.callback == "function"){
13727             this.callback.call(this.scope || this);
13728         }
13729
13730         this.callback = null;
13731         this.scope = null;
13732     }
13733 };
13734
13735
13736
13737
13738
13739 Roo.dd.DragSource = function(el, A){
13740     this.el = Roo.get(el);
13741     this.dragData = {};
13742     
13743     Roo.apply(this, A);
13744     
13745     if(!this.proxy){
13746         this.proxy = new  Roo.dd.StatusProxy();
13747     }
13748
13749
13750     Roo.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
13751           {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
13752     
13753     this.dragging = false;
13754 };
13755
13756 Roo.extend(Roo.dd.DragSource, Roo.dd.DDProxy, {
13757     
13758
13759     dropAllowed : "x-dd-drop-ok",
13760     
13761
13762     dropNotAllowed : "x-dd-drop-nodrop",
13763
13764     
13765
13766     getDragData : function(e){
13767         return  this.dragData;
13768     },
13769
13770     
13771     onDragEnter : function(e, id){
13772         var  B = Roo.dd.DragDropMgr.getDDById(id);
13773         this.cachedTarget = B;
13774         if(this.beforeDragEnter(B, e, id) !== false){
13775             if(B.isNotifyTarget){
13776                 var  status = B.notifyEnter(this, e, this.dragData);
13777                 this.proxy.setStatus(status);
13778             }else {
13779                 this.proxy.setStatus(this.dropAllowed);
13780             }
13781             
13782             if(this.afterDragEnter){
13783                 
13784
13785                 this.afterDragEnter(B, e, id);
13786             }
13787         }
13788     },
13789
13790     
13791
13792     beforeDragEnter : function(C, e, id){
13793         return  true;
13794     },
13795
13796     
13797     alignElWithMouse: function() {
13798         Roo.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
13799         this.proxy.sync();
13800     },
13801
13802     
13803     onDragOver : function(e, id){
13804         var  D = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
13805         if(this.beforeDragOver(D, e, id) !== false){
13806             if(D.isNotifyTarget){
13807                 var  status = D.notifyOver(this, e, this.dragData);
13808                 this.proxy.setStatus(status);
13809             }
13810
13811             if(this.afterDragOver){
13812                 
13813
13814                 this.afterDragOver(D, e, id);
13815             }
13816         }
13817     },
13818
13819     
13820
13821     beforeDragOver : function(E, e, id){
13822         return  true;
13823     },
13824
13825     
13826     onDragOut : function(e, id){
13827         var  F = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
13828         if(this.beforeDragOut(F, e, id) !== false){
13829             if(F.isNotifyTarget){
13830                 F.notifyOut(this, e, this.dragData);
13831             }
13832
13833             this.proxy.reset();
13834             if(this.afterDragOut){
13835                 
13836
13837                 this.afterDragOut(F, e, id);
13838             }
13839         }
13840
13841         this.cachedTarget = null;
13842     },
13843
13844     
13845
13846     beforeDragOut : function(G, e, id){
13847         return  true;
13848     },
13849     
13850     
13851     onDragDrop : function(e, id){
13852         var  H = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
13853         if(this.beforeDragDrop(H, e, id) !== false){
13854             if(H.isNotifyTarget){
13855                 if(H.notifyDrop(this, e, this.dragData)){ 
13856                     this.onValidDrop(H, e, id);
13857                 }else {
13858                     this.onInvalidDrop(H, e, id);
13859                 }
13860             }else {
13861                 this.onValidDrop(H, e, id);
13862             }
13863             
13864             if(this.afterDragDrop){
13865                 
13866
13867                 this.afterDragDrop(H, e, id);
13868             }
13869         }
13870         delete  this.cachedTarget;
13871     },
13872
13873     
13874
13875     beforeDragDrop : function(I, e, id){
13876         return  true;
13877     },
13878
13879     
13880     onValidDrop : function(J, e, id){
13881         this.hideProxy();
13882         if(this.afterValidDrop){
13883             
13884
13885             this.afterValidDrop(J, e, id);
13886         }
13887     },
13888
13889     
13890     getRepairXY : function(e, K){
13891         return  this.el.getXY();  
13892     },
13893
13894     
13895     onInvalidDrop : function(L, e, id){
13896         this.beforeInvalidDrop(L, e, id);
13897         if(this.cachedTarget){
13898             if(this.cachedTarget.isNotifyTarget){
13899                 this.cachedTarget.notifyOut(this, e, this.dragData);
13900             }
13901
13902             this.cacheTarget = null;
13903         }
13904
13905         this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
13906
13907         if(this.afterInvalidDrop){
13908             
13909
13910             this.afterInvalidDrop(e, id);
13911         }
13912     },
13913
13914     
13915     afterRepair : function(){
13916         if(Roo.enableFx){
13917             this.el.highlight(this.hlColor || "c3daf9");
13918         }
13919
13920         this.dragging = false;
13921     },
13922
13923     
13924
13925     beforeInvalidDrop : function(M, e, id){
13926         return  true;
13927     },
13928
13929     
13930     handleMouseDown : function(e){
13931         if(this.dragging) {
13932             return;
13933         }
13934         var  N = this.getDragData(e);
13935         if(N && this.onBeforeDrag(N, e) !== false){
13936             this.dragData = N;
13937             this.proxy.stop();
13938             Roo.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
13939         } 
13940     },
13941
13942     
13943
13944     onBeforeDrag : function(O, e){
13945         return  true;
13946     },
13947
13948     
13949
13950     onStartDrag : Roo.emptyFn,
13951
13952     
13953     startDrag : function(x, y){
13954         this.proxy.reset();
13955         this.dragging = true;
13956         this.proxy.update("");
13957         this.onInitDrag(x, y);
13958         this.proxy.show();
13959     },
13960
13961     
13962     onInitDrag : function(x, y){
13963         var  P = this.el.dom.cloneNode(true);
13964         P.id = Roo.id(); 
13965         this.proxy.update(P);
13966         this.onStartDrag(x, y);
13967         return  true;
13968     },
13969
13970     
13971
13972     getProxy : function(){
13973         return  this.proxy;  
13974     },
13975
13976     
13977
13978     hideProxy : function(){
13979         this.proxy.hide();  
13980         this.proxy.reset(true);
13981         this.dragging = false;
13982     },
13983
13984     
13985     triggerCacheRefresh : function(){
13986         Roo.dd.DDM.refreshCache(this.groups);
13987     },
13988
13989     
13990     b4EndDrag: function(e) {
13991     },
13992
13993     
13994     endDrag : function(e){
13995         this.onEndDrag(this.dragData, e);
13996     },
13997
13998     
13999     onEndDrag : function(Q, e){
14000     },
14001     
14002     
14003     autoOffset : function(x, y) {
14004         this.setDelta(-12, -20);
14005     }    
14006 });
14007
14008
14009
14010
14011
14012
14013 Roo.dd.DropTarget = function(el, A){
14014     this.el = Roo.get(el);
14015     
14016     Roo.apply(this, A);
14017     
14018     if(this.containerScroll){
14019         Roo.dd.ScrollManager.register(this.el);
14020     }
14021
14022     
14023     Roo.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, 
14024           {isTarget: true});
14025
14026 };
14027
14028 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
14029     
14030
14031     
14032
14033     dropAllowed : "x-dd-drop-ok",
14034     
14035
14036     dropNotAllowed : "x-dd-drop-nodrop",
14037
14038     
14039     isTarget : true,
14040
14041     
14042     isNotifyTarget : true,
14043
14044     
14045
14046     notifyEnter : function(dd, e, B){
14047         if(this.overClass){
14048             this.el.addClass(this.overClass);
14049         }
14050         return  this.dropAllowed;
14051     },
14052
14053     
14054
14055     notifyOver : function(dd, e, C){
14056         return  this.dropAllowed;
14057     },
14058
14059     
14060
14061     notifyOut : function(dd, e, D){
14062         if(this.overClass){
14063             this.el.removeClass(this.overClass);
14064         }
14065     },
14066
14067     
14068
14069     notifyDrop : function(dd, e, E){
14070         return  false;
14071     }
14072 });
14073
14074
14075
14076
14077
14078
14079 Roo.dd.DragZone = function(el, A){
14080     Roo.dd.DragZone.superclass.constructor.call(this, el, A);
14081     if(this.containerScroll){
14082         Roo.dd.ScrollManager.register(this.el);
14083     }
14084 };
14085
14086 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
14087     
14088
14089     
14090
14091
14092     
14093
14094     getDragData : function(e){
14095         return  Roo.dd.Registry.getHandleFromEvent(e);
14096     },
14097     
14098     
14099
14100     onInitDrag : function(x, y){
14101         this.proxy.update(this.dragData.ddel.cloneNode(true));
14102         this.onStartDrag(x, y);
14103         return  true;
14104     },
14105     
14106     
14107
14108     afterRepair : function(){
14109         if(Roo.enableFx){
14110             Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
14111         }
14112
14113         this.dragging = false;
14114     },
14115
14116     
14117
14118     getRepairXY : function(e){
14119         return  Roo.Element.fly(this.dragData.ddel).getXY();  
14120     }
14121 });
14122
14123
14124
14125
14126 Roo.dd.DropZone = function(el, A){
14127     Roo.dd.DropZone.superclass.constructor.call(this, el, A);
14128 };
14129
14130 Roo.extend(Roo.dd.DropZone, Roo.dd.DropTarget, {
14131     
14132
14133     getTargetFromEvent : function(e){
14134         return  Roo.dd.Registry.getTargetFromEvent(e);
14135     },
14136
14137     
14138
14139     onNodeEnter : function(n, dd, e, B){
14140         
14141     },
14142
14143     
14144
14145     onNodeOver : function(n, dd, e, C){
14146         return  this.dropAllowed;
14147     },
14148
14149     
14150
14151     onNodeOut : function(n, dd, e, D){
14152         
14153     },
14154
14155     
14156
14157     onNodeDrop : function(n, dd, e, E){
14158         return  false;
14159     },
14160
14161     
14162
14163     onContainerOver : function(dd, e, F){
14164         return  this.dropNotAllowed;
14165     },
14166
14167     
14168
14169     onContainerDrop : function(dd, e, G){
14170         return  false;
14171     },
14172
14173     
14174
14175     notifyEnter : function(dd, e, H){
14176         return  this.dropNotAllowed;
14177     },
14178
14179     
14180
14181     notifyOver : function(dd, e, I){
14182         var  n = this.getTargetFromEvent(e);
14183         if(!n){ 
14184             if(this.lastOverNode){
14185                 this.onNodeOut(this.lastOverNode, dd, e, I);
14186                 this.lastOverNode = null;
14187             }
14188             return  this.onContainerOver(dd, e, I);
14189         }
14190         if(this.lastOverNode != n){
14191             if(this.lastOverNode){
14192                 this.onNodeOut(this.lastOverNode, dd, e, I);
14193             }
14194
14195             this.onNodeEnter(n, dd, e, I);
14196             this.lastOverNode = n;
14197         }
14198         return  this.onNodeOver(n, dd, e, I);
14199     },
14200
14201     
14202
14203     notifyOut : function(dd, e, J){
14204         if(this.lastOverNode){
14205             this.onNodeOut(this.lastOverNode, dd, e, J);
14206             this.lastOverNode = null;
14207         }
14208     },
14209
14210     
14211
14212     notifyDrop : function(dd, e, K){
14213         if(this.lastOverNode){
14214             this.onNodeOut(this.lastOverNode, dd, e, K);
14215             this.lastOverNode = null;
14216         }
14217         var  n = this.getTargetFromEvent(e);
14218         return  n ?
14219             this.onNodeDrop(n, dd, e, K) :
14220             this.onContainerDrop(dd, e, K);
14221     },
14222
14223     
14224     triggerCacheRefresh : function(){
14225         Roo.dd.DDM.refreshCache(this.groups);
14226     }  
14227 });
14228
14229
14230
14231
14232
14233
14234 Roo.data.SortTypes = {
14235     
14236
14237     none : function(s){
14238         return  s;
14239     },
14240     
14241     
14242
14243     stripTagsRE : /<\/?[^>]+>/gi,
14244     
14245     
14246
14247     asText : function(s){
14248         return  String(s).replace(this.stripTagsRE, "");
14249     },
14250     
14251     
14252
14253     asUCText : function(s){
14254         return  String(s).toUpperCase().replace(this.stripTagsRE, "");
14255     },
14256     
14257     
14258
14259     asUCString : function(s) {
14260         return  String(s).toUpperCase();
14261     },
14262     
14263     
14264
14265     asDate : function(s) {
14266         if(!s){
14267             return  0;
14268         }
14269         if(s  instanceof  Date){
14270             return  s.getTime();
14271         }
14272         return  Date.parse(String(s));
14273     },
14274     
14275     
14276
14277     asFloat : function(s) {
14278         var  A = parseFloat(String(s).replace(/,/g, ""));
14279         if(isNaN(A)) A = 0;
14280         return  A;
14281     },
14282     
14283     
14284
14285     asInt : function(s) {
14286         var  B = parseInt(String(s).replace(/,/g, ""));
14287         if(isNaN(B)) B = 0;
14288         return  B;
14289     }
14290 };
14291
14292
14293
14294
14295
14296 Roo.data.Record = function(A, id){
14297     this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
14298     this.data = A;
14299 };
14300
14301
14302
14303 Roo.data.Record.create = function(o){
14304     var  f = function(){
14305         f.superclass.constructor.apply(this, arguments);
14306     };
14307     Roo.extend(f, Roo.data.Record);
14308     var  p = f.prototype;
14309     p.fields = new  Roo.util.MixedCollection(false, function(B){
14310         return  B.name;
14311     });
14312     for(var  i = 0, len = o.length; i < len; i++){
14313         p.fields.add(new  Roo.data.Field(o[i]));
14314     }
14315
14316     f.getField = function(B){
14317         return  p.fields.get(B);  
14318     };
14319     return  f;
14320 };
14321
14322 Roo.data.Record.AUTO_ID = 1000;
14323 Roo.data.Record.EDIT = 'edit';
14324 Roo.data.Record.REJECT = 'reject';
14325 Roo.data.Record.COMMIT = 'commit';
14326
14327 Roo.data.Record.prototype = {
14328     
14329
14330     dirty : false,
14331     editing : false,
14332     error: null,
14333     modified: null,
14334
14335     
14336     join : function(B){
14337         this.store = B;
14338     },
14339
14340     
14341
14342     set : function(C, D){
14343         if(this.data[C] == D){
14344             return;
14345         }
14346
14347         this.dirty = true;
14348         if(!this.modified){
14349             this.modified = {};
14350         }
14351         if(typeof  this.modified[C] == 'undefined'){
14352             this.modified[C] = this.data[C];
14353         }
14354
14355         this.data[C] = D;
14356         if(!this.editing){
14357             this.store.afterEdit(this);
14358         }       
14359     },
14360
14361     
14362
14363     get : function(E){
14364         return  this.data[E]; 
14365     },
14366
14367     
14368     beginEdit : function(){
14369         this.editing = true;
14370         this.modified = {}; 
14371     },
14372
14373     
14374     cancelEdit : function(){
14375         this.editing = false;
14376         delete  this.modified;
14377     },
14378
14379     
14380     endEdit : function(){
14381         this.editing = false;
14382         if(this.dirty && this.store){
14383             this.store.afterEdit(this);
14384         }
14385     },
14386
14387     
14388
14389     reject : function(){
14390         var  m = this.modified;
14391         for(var  n  in  m){
14392             if(typeof  m[n] != "function"){
14393                 this.data[n] = m[n];
14394             }
14395         }
14396
14397         this.dirty = false;
14398         delete  this.modified;
14399         this.editing = false;
14400         if(this.store){
14401             this.store.afterReject(this);
14402         }
14403     },
14404
14405     
14406
14407     commit : function(){
14408         this.dirty = false;
14409         delete  this.modified;
14410         this.editing = false;
14411         if(this.store){
14412             this.store.afterCommit(this);
14413         }
14414     },
14415
14416     
14417     hasError : function(){
14418         return  this.error != null;
14419     },
14420
14421     
14422     clearError : function(){
14423         this.error = null;
14424     },
14425
14426     
14427
14428     copy : function(F) {
14429         return  new  this.constructor(Roo.apply({}, this.data), F || this.id);
14430     }
14431 };
14432
14433
14434
14435
14436
14437
14438
14439 Roo.data.Store = function(A){
14440     this.data = new  Roo.util.MixedCollection(false);
14441     this.data.getKey = function(o){
14442         return  o.id;
14443     };
14444     this.baseParams = {};
14445     
14446     this.paramNames = {
14447         "start" : "start",
14448         "limit" : "limit",
14449         "sort" : "sort",
14450         "dir" : "dir"
14451     };
14452
14453     if(A && A.data){
14454         this.inlineData = A.data;
14455         delete  A.data;
14456     }
14457
14458
14459     Roo.apply(this, A);
14460     
14461     if(this.reader){ 
14462         this.reader = Roo.factory(this.reader, Roo.data);
14463         this.reader.xmodule = this.xmodule || false;
14464         if(!this.recordType){
14465             this.recordType = this.reader.recordType;
14466         }
14467         if(this.reader.onMetaChange){
14468             this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
14469         }
14470     }
14471
14472     if(this.recordType){
14473         this.fields = this.recordType.prototype.fields;
14474     }
14475
14476     this.modified = [];
14477
14478     this.addEvents({
14479         
14480
14481         datachanged : true,
14482         
14483
14484         metachange : true,
14485         
14486
14487         add : true,
14488         
14489
14490         remove : true,
14491         
14492
14493         update : true,
14494         
14495
14496         clear : true,
14497         
14498
14499         beforeload : true,
14500         
14501
14502         load : true,
14503         
14504
14505         loadexception : true
14506     });
14507     
14508     if(this.proxy){
14509         this.proxy = Roo.factory(this.proxy, Roo.data);
14510         this.proxy.xmodule = this.xmodule || false;
14511         this.relayEvents(this.proxy,  ["loadexception"]);
14512     }
14513
14514     this.sortToggle = {};
14515
14516     Roo.data.Store.superclass.constructor.call(this);
14517
14518     if(this.inlineData){
14519         this.loadData(this.inlineData);
14520         delete  this.inlineData;
14521     }
14522 };
14523 Roo.extend(Roo.data.Store, Roo.util.Observable, {
14524      
14525
14526     
14527     
14528
14529     
14530
14531     
14532
14533     
14534
14535     
14536
14537     
14538
14539     remoteSort : false,
14540
14541     
14542
14543     pruneModifiedRecords : false,
14544
14545     
14546     lastOptions : null,
14547
14548     
14549
14550     add : function(B){
14551         B = [].concat(B);
14552         for(var  i = 0, len = B.length; i < len; i++){
14553             B[i].join(this);
14554         }
14555         var  C = this.data.length;
14556         this.data.addAll(B);
14557         this.fireEvent("add", this, B, C);
14558     },
14559
14560     
14561
14562     remove : function(D){
14563         var  E = this.data.indexOf(D);
14564         this.data.removeAt(E);
14565         if(this.pruneModifiedRecords){
14566             this.modified.remove(D);
14567         }
14568
14569         this.fireEvent("remove", this, D, E);
14570     },
14571
14572     
14573
14574     removeAll : function(){
14575         this.data.clear();
14576         if(this.pruneModifiedRecords){
14577             this.modified = [];
14578         }
14579
14580         this.fireEvent("clear", this);
14581     },
14582
14583     
14584
14585     insert : function(F, G){
14586         G = [].concat(G);
14587         for(var  i = 0, len = G.length; i < len; i++){
14588             this.data.insert(F, G[i]);
14589             G[i].join(this);
14590         }
14591
14592         this.fireEvent("add", this, G, F);
14593     },
14594
14595     
14596
14597     indexOf : function(H){
14598         return  this.data.indexOf(H);
14599     },
14600
14601     
14602
14603     indexOfId : function(id){
14604         return  this.data.indexOfKey(id);
14605     },
14606
14607     
14608
14609     getById : function(id){
14610         return  this.data.key(id);
14611     },
14612
14613     
14614
14615     getAt : function(I){
14616         return  this.data.itemAt(I);
14617     },
14618
14619     
14620
14621     getRange : function(J, K){
14622         return  this.data.getRange(J, K);
14623     },
14624
14625     
14626     storeOptions : function(o){
14627         o = Roo.apply({}, o);
14628         delete  o.callback;
14629         delete  o.scope;
14630         this.lastOptions = o;
14631     },
14632
14633     
14634
14635     load : function(L){
14636         L = L || {};
14637         if(this.fireEvent("beforeload", this, L) !== false){
14638             this.storeOptions(L);
14639             var  p = Roo.apply(L.params || {}, this.baseParams);
14640             if(this.sortInfo && this.remoteSort){
14641                 var  pn = this.paramNames;
14642                 p[pn["sort"]] = this.sortInfo.field;
14643                 p[pn["dir"]] = this.sortInfo.direction;
14644             }
14645
14646             this.proxy.load(p, this.reader, this.loadRecords, this, L);
14647         }
14648     },
14649
14650     
14651
14652     reload : function(M){
14653         this.load(Roo.applyIf(M||{}, this.lastOptions));
14654     },
14655
14656     
14657     
14658     loadRecords : function(o, N, O){
14659         if(!o || O === false){
14660             if(O !== false){
14661                 this.fireEvent("load", this, [], N);
14662             }
14663             if(N.callback){
14664                 N.callback.call(N.scope || this, [], N, false);
14665             }
14666             return;
14667         }
14668         
14669         if (o.success === false) {
14670             this.fireEvent("loadexception", this, o, N, this.reader.jsonData);
14671             return;
14672         }
14673         var  r = o.records, t = o.totalRecords || r.length;
14674         if(!N || N.add !== true){
14675             if(this.pruneModifiedRecords){
14676                 this.modified = [];
14677             }
14678             for(var  i = 0, len = r.length; i < len; i++){
14679                 r[i].join(this);
14680             }
14681             if(this.snapshot){
14682                 this.data = this.snapshot;
14683                 delete  this.snapshot;
14684             }
14685
14686             this.data.clear();
14687             this.data.addAll(r);
14688             this.totalLength = t;
14689             this.applySort();
14690             this.fireEvent("datachanged", this);
14691         }else {
14692             this.totalLength = Math.max(t, this.data.length+r.length);
14693             this.add(r);
14694         }
14695
14696         this.fireEvent("load", this, r, N);
14697         if(N.callback){
14698             N.callback.call(N.scope || this, r, N, true);
14699         }
14700     },
14701
14702     
14703
14704     loadData : function(o, P){
14705         var  r = this.reader.readRecords(o);
14706         this.loadRecords(r, {add: P}, true);
14707     },
14708
14709     
14710
14711     getCount : function(){
14712         return  this.data.length || 0;
14713     },
14714
14715     
14716
14717     getTotalCount : function(){
14718         return  this.totalLength || 0;
14719     },
14720
14721     
14722
14723     getSortState : function(){
14724         return  this.sortInfo;
14725     },
14726
14727     
14728     applySort : function(){
14729         if(this.sortInfo && !this.remoteSort){
14730             var  s = this.sortInfo, f = s.field;
14731             var  st = this.fields.get(f).sortType;
14732             var  fn = function(r1, r2){
14733                 var  v1 = st(r1.data[f]), v2 = st(r2.data[f]);
14734                 return  v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
14735             };
14736             this.data.sort(s.direction, fn);
14737             if(this.snapshot && this.snapshot != this.data){
14738                 this.snapshot.sort(s.direction, fn);
14739             }
14740         }
14741     },
14742
14743     
14744
14745     setDefaultSort : function(Q, R){
14746         this.sortInfo = {field: Q, direction: R ? R.toUpperCase() : "ASC"};
14747     },
14748
14749     
14750
14751     sort : function(S, T){
14752         var  f = this.fields.get(S);
14753         if(!T){
14754             if(this.sortInfo && this.sortInfo.field == f.name){ 
14755                 T = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
14756             }else {
14757                 T = f.sortDir;
14758             }
14759         }
14760
14761         this.sortToggle[f.name] = T;
14762         this.sortInfo = {field: f.name, direction: T};
14763         if(!this.remoteSort){
14764             this.applySort();
14765             this.fireEvent("datachanged", this);
14766         }else {
14767             this.load(this.lastOptions);
14768         }
14769     },
14770
14771     
14772
14773     each : function(fn, U){
14774         this.data.each(fn, U);
14775     },
14776
14777     
14778
14779     getModifiedRecords : function(){
14780         return  this.modified;
14781     },
14782
14783     
14784     createFilterFn : function(V, W, X){
14785         if(!W.exec){ 
14786             W = String(W);
14787             if(W.length == 0){
14788                 return  false;
14789             }
14790
14791             W = new  RegExp((X === true ? '' : '^') + Roo.escapeRe(W), "i");
14792         }
14793         return  function(r){
14794             return  W.test(r.data[V]);
14795         };
14796     },
14797
14798     
14799
14800     sum : function(Y, Z, a){
14801         var  rs = this.data.items, v = 0;
14802         Z = Z || 0;
14803         a = (a || a === 0) ? a : rs.length-1;
14804
14805         for(var  i = Z; i <= a; i++){
14806             v += (rs[i].data[Y] || 0);
14807         }
14808         return  v;
14809     },
14810
14811     
14812
14813     filter : function(b, c, d){
14814         var  fn = this.createFilterFn(b, c, d);
14815         return  fn ? this.filterBy(fn) : this.clearFilter();
14816     },
14817
14818     
14819
14820     filterBy : function(fn, e){
14821         this.snapshot = this.snapshot || this.data;
14822         this.data = this.queryBy(fn, e||this);
14823         this.fireEvent("datachanged", this);
14824     },
14825
14826     
14827
14828     query : function(g, h, j){
14829         var  fn = this.createFilterFn(g, h, j);
14830         return  fn ? this.queryBy(fn) : this.data.clone();
14831     },
14832
14833     
14834
14835     queryBy : function(fn, k){
14836         var  l = this.snapshot || this.data;
14837         return  l.filterBy(fn, k||this);
14838     },
14839
14840     
14841
14842     collect : function(m, n, q){
14843         var  d = (q === true && this.snapshot) ?
14844                 this.snapshot.items : this.data.items;
14845         var  v, sv, r = [], l = {};
14846         for(var  i = 0, len = d.length; i < len; i++){
14847             v = d[i].data[m];
14848             sv = String(v);
14849             if((n || !Roo.isEmpty(v)) && !l[sv]){
14850                 l[sv] = true;
14851                 r[r.length] = v;
14852             }
14853         }
14854         return  r;
14855     },
14856
14857     
14858
14859     clearFilter : function(u){
14860         if(this.snapshot && this.snapshot != this.data){
14861             this.data = this.snapshot;
14862             delete  this.snapshot;
14863             if(u !== true){
14864                 this.fireEvent("datachanged", this);
14865             }
14866         }
14867     },
14868
14869     
14870     afterEdit : function(w){
14871         if(this.modified.indexOf(w) == -1){
14872             this.modified.push(w);
14873         }
14874
14875         this.fireEvent("update", this, w, Roo.data.Record.EDIT);
14876     },
14877
14878     
14879     afterReject : function(x){
14880         this.modified.remove(x);
14881         this.fireEvent("update", this, x, Roo.data.Record.REJECT);
14882     },
14883
14884     
14885     afterCommit : function(y){
14886         this.modified.remove(y);
14887         this.fireEvent("update", this, y, Roo.data.Record.COMMIT);
14888     },
14889
14890     
14891
14892     commitChanges : function(){
14893         var  m = this.modified.slice(0);
14894         this.modified = [];
14895         for(var  i = 0, len = m.length; i < len; i++){
14896             m[i].commit();
14897         }
14898     },
14899
14900     
14901
14902     rejectChanges : function(){
14903         var  m = this.modified.slice(0);
14904         this.modified = [];
14905         for(var  i = 0, len = m.length; i < len; i++){
14906             m[i].reject();
14907         }
14908     },
14909
14910     onMetaChange : function(z, AA, o){
14911         this.recordType = AA;
14912         this.fields = AA.prototype.fields;
14913         delete  this.snapshot;
14914         this.sortInfo = z.sortInfo;
14915         this.modified = [];
14916         this.fireEvent('metachange', this, this.reader.meta);
14917     }
14918 });
14919
14920
14921
14922
14923
14924 Roo.data.SimpleStore = function(A){
14925     Roo.data.SimpleStore.superclass.constructor.call(this, {
14926         isLocal : true,
14927         reader: new  Roo.data.ArrayReader({
14928                 id: A.id
14929             },
14930             Roo.data.Record.create(A.fields)
14931         ),
14932         proxy : new  Roo.data.MemoryProxy(A.data)
14933     });
14934     this.load();
14935 };
14936 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);
14937
14938
14939
14940
14941
14942 Roo.data.JsonStore = function(c){
14943     Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
14944         proxy: !c.data ? new  Roo.data.HttpProxy({url: c.url}) : undefined,
14945         reader: new  Roo.data.JsonReader(c, c.fields)
14946     }));
14947 };
14948 Roo.extend(Roo.data.JsonStore, Roo.data.Store);
14949
14950
14951
14952  
14953 Roo.data.Field = function(A){
14954     if(typeof  A == "string"){
14955         A = {name: A};
14956     }
14957
14958     Roo.apply(this, A);
14959     
14960     if(!this.type){
14961         this.type = "auto";
14962     }
14963     
14964     var  st = Roo.data.SortTypes;
14965     
14966     if(typeof  this.sortType == "string"){
14967         this.sortType = st[this.sortType];
14968     }
14969     
14970     
14971     if(!this.sortType){
14972         switch(this.type){
14973             case  "string":
14974                 this.sortType = st.asUCString;
14975                 break;
14976             case  "date":
14977                 this.sortType = st.asDate;
14978                 break;
14979             default:
14980                 this.sortType = st.none;
14981         }
14982     }
14983
14984     
14985     var  B = /[\$,%]/g;
14986
14987     
14988     
14989     if(!this.convert){
14990         var  cv, dateFormat = this.dateFormat;
14991         switch(this.type){
14992             case  "":
14993             case  "auto":
14994             case  undefined:
14995                 cv = function(v){ return  v; };
14996                 break;
14997             case  "string":
14998                 cv = function(v){ return  (v === undefined || v === null) ? '' : String(v); };
14999                 break;
15000             case  "int":
15001                 cv = function(v){
15002                     return  v !== undefined && v !== null && v !== '' ?
15003                            parseInt(String(v).replace(B, ""), 10) : '';
15004                     };
15005                 break;
15006             case  "float":
15007                 cv = function(v){
15008                     return  v !== undefined && v !== null && v !== '' ?
15009                            parseFloat(String(v).replace(B, ""), 10) : ''; 
15010                     };
15011                 break;
15012             case  "bool":
15013             case  "boolean":
15014                 cv = function(v){ return  v === true || v === "true" || v == 1; };
15015                 break;
15016             case  "date":
15017                 cv = function(v){
15018                     if(!v){
15019                         return  '';
15020                     }
15021                     if(v  instanceof  Date){
15022                         return  v;
15023                     }
15024                     if(dateFormat){
15025                         if(dateFormat == "timestamp"){
15026                             return  new  Date(v*1000);
15027                         }
15028                         return  Date.parseDate(v, dateFormat);
15029                     }
15030                     var  C = Date.parse(v);
15031                     return  C ? new  Date(C) : null;
15032                 };
15033              break;
15034             
15035         }
15036
15037         this.convert = cv;
15038     }
15039 };
15040
15041 Roo.data.Field.prototype = {
15042     dateFormat: null,
15043     defaultValue: "",
15044     mapping: null,
15045     sortType : null,
15046     sortDir : "ASC"
15047 };
15048
15049
15050  
15051
15052
15053
15054
15055
15056
15057 Roo.data.DataReader = function(A, B){
15058     
15059     this.meta = A;
15060     
15061     this.recordType = B  instanceof  Array ? 
15062         Roo.data.Record.create(B) : B;
15063 };
15064
15065 Roo.data.DataReader.prototype = {
15066      
15067
15068     newRow :  function(d) {
15069         var  da =  {};
15070         this.recordType.prototype.fields.each(function(c) {
15071             switch( c.type) {
15072                 case  'int' : da[c.name] = 0; break;
15073                 case  'date' : da[c.name] = new  Date(); break;
15074                 case  'float' : da[c.name] = 0.0; break;
15075                 case  'boolean' : da[c.name] = false; break;
15076                 default : da[c.name] = ""; break;
15077             }
15078             
15079         });
15080         return  new  this.recordType(Roo.apply(da, d));
15081     }
15082     
15083 };
15084
15085
15086
15087
15088
15089 Roo.data.DataProxy = function(){
15090     this.addEvents({
15091         
15092
15093         beforeload : true,
15094         
15095
15096         load : true,
15097         
15098
15099         loadexception : true
15100     });
15101     Roo.data.DataProxy.superclass.constructor.call(this);
15102 };
15103
15104 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
15105
15106     
15107
15108
15109
15110
15111
15112
15113 Roo.data.MemoryProxy = function(A){
15114     if (A.data) {
15115         A = A.data;
15116     }
15117
15118     Roo.data.MemoryProxy.superclass.constructor.call(this);
15119     this.data = A;
15120 };
15121
15122 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
15123     
15124
15125     load : function(B, C, D, E, F){
15126         B = B || {};
15127         var  G;
15128         try {
15129             G = C.readRecords(this.data);
15130         }catch(e){
15131             this.fireEvent("loadexception", this, arg, null, e);
15132             callback.call(scope, null, arg, false);
15133             return;
15134         }
15135
15136         D.call(E, G, F, true);
15137     },
15138     
15139     
15140     update : function(H, I){
15141         
15142     }
15143 });
15144
15145
15146
15147
15148 Roo.data.HttpProxy = function(A){
15149     Roo.data.HttpProxy.superclass.constructor.call(this);
15150     
15151     this.conn = A;
15152     this.useAjax = !A || !A.events;
15153   
15154 };
15155
15156 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
15157     
15158     
15159     
15160
15161     
15162
15163     
15164
15165     
15166
15167     
15168
15169      
15170
15171   
15172
15173     
15174
15175     
15176
15177     getConnection : function(){
15178         return  this.useAjax ? Roo.Ajax : this.conn;
15179     },
15180
15181     
15182
15183     load : function(B, C, D, E, F){
15184         if(this.fireEvent("beforeload", this, B) !== false){
15185             var   o = {
15186                 params : B || {},
15187                 request: {
15188                     callback : D,
15189                     scope : E,
15190                     arg : F
15191                 },
15192                 reader: C,
15193                 callback : this.loadResponse,
15194                 scope: this
15195             };
15196             if(this.useAjax){
15197                 Roo.applyIf(o, this.conn);
15198                 if(this.activeRequest){
15199                     Roo.Ajax.abort(this.activeRequest);
15200                 }
15201
15202                 this.activeRequest = Roo.Ajax.request(o);
15203             }else {
15204                 this.conn.request(o);
15205             }
15206         }else {
15207             D.call(E||this, null, F, false);
15208         }
15209     },
15210
15211     
15212     loadResponse : function(o, G, H){
15213         delete  this.activeRequest;
15214         if(!G){
15215             this.fireEvent("loadexception", this, o, H);
15216             o.request.callback.call(o.request.scope, null, o.request.arg, false);
15217             return;
15218         }
15219         var  I;
15220         try {
15221             I = o.reader.read(H);
15222         }catch(e){
15223             this.fireEvent("loadexception", this, o, response, e);
15224             o.request.callback.call(o.request.scope, null, o.request.arg, false);
15225             return;
15226         }
15227
15228         
15229         this.fireEvent("load", this, o, o.request.arg);
15230         o.request.callback.call(o.request.scope, I, o.request.arg, true);
15231     },
15232
15233     
15234     update : function(J){
15235
15236     },
15237
15238     
15239     updateResponse : function(K){
15240
15241     }
15242 });
15243
15244
15245
15246
15247
15248 Roo.data.ScriptTagProxy = function(A){
15249     Roo.data.ScriptTagProxy.superclass.constructor.call(this);
15250     Roo.apply(this, A);
15251     this.head = document.getElementsByTagName("head")[0];
15252 };
15253
15254 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
15255
15256 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
15257     
15258
15259     
15260
15261     timeout : 30000,
15262     
15263
15264     callbackParam : "callback",
15265     
15266
15267     nocache : true,
15268
15269     
15270
15271     load : function(B, C, D, E, F){
15272         if(this.fireEvent("beforeload", this, B) !== false){
15273
15274             var  p = Roo.urlEncode(Roo.apply(B, this.extraParams));
15275
15276             var  url = this.url;
15277             url += (url.indexOf("?") != -1 ? "&" : "?") + p;
15278             if(this.nocache){
15279                 url += "&_dc=" + (new  Date().getTime());
15280             }
15281             var  transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
15282             var  trans = {
15283                 id : transId,
15284                 cb : "stcCallback"+transId,
15285                 scriptId : "stcScript"+transId,
15286                 params : B,
15287                 arg : F,
15288                 url : url,
15289                 callback : D,
15290                 scope : E,
15291                 reader : C
15292             };
15293             var  conn = this;
15294
15295             window[trans.cb] = function(o){
15296                 conn.handleResponse(o, trans);
15297             };
15298
15299             url += String.format("&{0}={1}", this.callbackParam, trans.cb);
15300
15301             if(this.autoAbort !== false){
15302                 this.abort();
15303             }
15304
15305
15306             trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
15307
15308             var  script = document.createElement("script");
15309             script.setAttribute("src", url);
15310             script.setAttribute("type", "text/javascript");
15311             script.setAttribute("id", trans.scriptId);
15312             this.head.appendChild(script);
15313
15314             this.trans = trans;
15315         }else {
15316             D.call(E||this, null, F, false);
15317         }
15318     },
15319
15320     
15321     isLoading : function(){
15322         return  this.trans ? true : false;
15323     },
15324
15325     
15326
15327     abort : function(){
15328         if(this.isLoading()){
15329             this.destroyTrans(this.trans);
15330         }
15331     },
15332
15333     
15334     destroyTrans : function(G, H){
15335         this.head.removeChild(document.getElementById(G.scriptId));
15336         clearTimeout(G.timeoutId);
15337         if(H){
15338             window[G.cb] = undefined;
15339             try{
15340                 delete  window[G.cb];
15341             }catch(e){}
15342         }else {
15343             
15344             window[G.cb] = function(){
15345                 window[G.cb] = undefined;
15346                 try{
15347                     delete  window[G.cb];
15348                 }catch(e){}
15349             };
15350         }
15351     },
15352
15353     
15354     handleResponse : function(o, I){
15355         this.trans = false;
15356         this.destroyTrans(I, true);
15357         var  J;
15358         try {
15359             J = I.reader.readRecords(o);
15360         }catch(e){
15361             this.fireEvent("loadexception", this, o, trans.arg, e);
15362             trans.callback.call(trans.scope||window, null, trans.arg, false);
15363             return;
15364         }
15365
15366         this.fireEvent("load", this, o, I.arg);
15367         I.callback.call(I.scope||window, J, I.arg, true);
15368     },
15369
15370     
15371     handleFailure : function(K){
15372         this.trans = false;
15373         this.destroyTrans(K, false);
15374         this.fireEvent("loadexception", this, null, K.arg);
15375         K.callback.call(K.scope||window, null, K.arg, false);
15376     }
15377 });
15378
15379
15380
15381
15382
15383 Roo.data.JsonReader = function(meta, recordType){
15384     
15385     meta = meta || {};
15386     
15387     Roo.applyIf(meta, {
15388         totalProperty: 'total',
15389         successProperty : 'success',
15390         root : 'data',
15391         id : 'id'
15392     });
15393     
15394     Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
15395 };
15396 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
15397     
15398
15399     read : function(response){
15400         var  json = response.responseText;
15401         
15402
15403         var  o = eval("("+json+")");
15404         if(!o) {
15405             throw  {message: "JsonReader.read: Json object not found"};
15406         }
15407         
15408         if(o.metaData){
15409             delete  this.ef;
15410             this.meta = o.metaData;
15411             this.recordType = Roo.data.Record.create(o.metaData.fields);
15412             this.onMetaChange(this.meta, this.recordType, o);
15413         }
15414         return  this.readRecords(o);
15415     },
15416
15417     
15418     onMetaChange : function(meta, recordType, o){
15419
15420     },
15421
15422     
15423
15424     simpleAccess: function(obj, subsc) {
15425         return  obj[subsc];
15426     },
15427
15428         
15429
15430     getJsonAccessor: function(){
15431         var  re = /[\[\.]/;
15432         return  function(expr) {
15433             try {
15434                 return (re.test(expr))
15435                     ? new  Function("obj", "return obj." + expr)
15436                     : function(obj){
15437                         return  obj[expr];
15438                     };
15439             } catch(e){}
15440             return  Roo.emptyFn;
15441         };
15442     }(),
15443
15444     
15445
15446     readRecords : function(o){
15447         
15448
15449         this.jsonData = o;
15450         var  s = this.meta, Record = this.recordType,
15451             f = Record.prototype.fields, fi = f.items, fl = f.length;
15452
15453
15454         if (!this.ef) {
15455             if(s.totalProperty) {
15456                     this.getTotal = this.getJsonAccessor(s.totalProperty);
15457                 }
15458                 if(s.successProperty) {
15459                     this.getSuccess = this.getJsonAccessor(s.successProperty);
15460                 }
15461
15462                 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return  p;};
15463                 if (s.id) {
15464                         var  g = this.getJsonAccessor(s.id);
15465                         this.getId = function(rec) {
15466                                 var  r = g(rec);
15467                                 return  (r === undefined || r === "") ? null : r;
15468                         };
15469                 } else  {
15470                         this.getId = function(){return  null;};
15471                 }
15472
15473             this.ef = [];
15474             for(var  i = 0; i < fl; i++){
15475                 f = fi[i];
15476                 var  map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
15477                 this.ef[i] = this.getJsonAccessor(map);
15478             }
15479         }
15480
15481         var  root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
15482         if(s.totalProperty){
15483             var  v = parseInt(this.getTotal(o), 10);
15484             if(!isNaN(v)){
15485                 totalRecords = v;
15486             }
15487         }
15488         if(s.successProperty){
15489             var  v = this.getSuccess(o);
15490             if(v === false || v === 'false'){
15491                 success = false;
15492             }
15493         }
15494         var  records = [];
15495             for(var  i = 0; i < c; i++){
15496                     var  n = root[i];
15497                 var  values = {};
15498                 var  id = this.getId(n);
15499                 for(var  j = 0; j < fl; j++){
15500                     f = fi[j];
15501                 var  v = this.ef[j](n);
15502                 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
15503                 }
15504                 var  record = new  Record(values, id);
15505                 record.json = n;
15506                 records[i] = record;
15507             }
15508             return  {
15509                 success : success,
15510                 records : records,
15511                 totalRecords : totalRecords
15512             };
15513     }
15514 });
15515
15516
15517
15518
15519
15520 Roo.data.XmlReader = function(A, B){
15521     A = A || {};
15522     Roo.data.XmlReader.superclass.constructor.call(this, A, B||A.fields);
15523 };
15524 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
15525     
15526
15527     read : function(C){
15528         var  D = C.responseXML;
15529         if(!D) {
15530             throw  {message: "XmlReader.read: XML Document not available"};
15531         }
15532         return  this.readRecords(D);
15533     },
15534
15535     
15536
15537     readRecords : function(E){
15538         
15539
15540         this.xmlData = E;
15541         var  F = E.documentElement || E;
15542         var  q = Roo.DomQuery;
15543         var  G = this.recordType, H = G.prototype.fields;
15544         var  I = this.meta.id;
15545         var  J = 0, K = true;
15546         if(this.meta.totalRecords){
15547             J = q.selectNumber(this.meta.totalRecords, F, 0);
15548         }
15549         
15550         if(this.meta.success){
15551             var  sv = q.selectValue(this.meta.success, F, true);
15552             K = sv !== false && sv !== 'false';
15553         }
15554         var  L = [];
15555         var  ns = q.select(this.meta.record, F);
15556         for(var  i = 0, len = ns.length; i < len; i++) {
15557                 var  n = ns[i];
15558                 var  values = {};
15559                 var  id = I ? q.selectValue(I, n) : undefined;
15560                 for(var  j = 0, jlen = H.length; j < jlen; j++){
15561                     var  f = H.items[j];
15562                 var  v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
15563                     v = f.convert(v);
15564                     values[f.name] = v;
15565                 }
15566                 var  record = new  G(values, id);
15567                 record.node = n;
15568                 L[L.length] = record;
15569             }
15570
15571             return  {
15572                 success : K,
15573                 records : L,
15574                 totalRecords : J || L.length
15575             };
15576     }
15577 });
15578
15579
15580
15581
15582
15583 Roo.data.ArrayReader = function(A, B){
15584     Roo.data.ArrayReader.superclass.constructor.call(this, A, B);
15585 };
15586
15587 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
15588     
15589
15590     readRecords : function(o){
15591         var  C = this.meta ? this.meta.id : null;
15592         var  D = this.recordType, E = D.prototype.fields;
15593         var  F = [];
15594         var  G = o;
15595             for(var  i = 0; i < G.length; i++){
15596                     var  n = G[i];
15597                 var  values = {};
15598                 var  id = ((C || C === 0) && n[C] !== undefined && n[C] !== "" ? n[C] : null);
15599                 for(var  j = 0, jlen = E.length; j < jlen; j++){
15600                 var  f = E.items[j];
15601                 var  k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
15602                 var  v = n[k] !== undefined ? n[k] : f.defaultValue;
15603                 v = f.convert(v);
15604                 values[f.name] = v;
15605             }
15606                 var  record = new  D(values, id);
15607                 record.json = n;
15608                 F[F.length] = record;
15609             }
15610             return  {
15611                 records : F,
15612                 totalRecords : F.length
15613             };
15614     }
15615 });
15616
15617
15618
15619
15620
15621
15622 Roo.data.Tree = function(A){
15623    this.nodeHash = {};
15624    
15625
15626    this.root = null;
15627    if(A){
15628        this.setRootNode(A);
15629    }
15630
15631    this.addEvents({
15632        
15633
15634        "append" : true,
15635        
15636
15637        "remove" : true,
15638        
15639
15640        "move" : true,
15641        
15642
15643        "insert" : true,
15644        
15645
15646        "beforeappend" : true,
15647        
15648
15649        "beforeremove" : true,
15650        
15651
15652        "beforemove" : true,
15653        
15654
15655        "beforeinsert" : true
15656    });
15657
15658     Roo.data.Tree.superclass.constructor.call(this);
15659 };
15660
15661 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
15662     pathSeparator: "/",
15663
15664     proxyNodeEvent : function(){
15665         return  this.fireEvent.apply(this, arguments);
15666     },
15667
15668     
15669
15670     getRootNode : function(){
15671         return  this.root;
15672     },
15673
15674     
15675
15676     setRootNode : function(B){
15677         this.root = B;
15678         B.ownerTree = this;
15679         B.isRoot = true;
15680         this.registerNode(B);
15681         return  B;
15682     },
15683
15684     
15685
15686     getNodeById : function(id){
15687         return  this.nodeHash[id];
15688     },
15689
15690     registerNode : function(C){
15691         this.nodeHash[C.id] = C;
15692     },
15693
15694     unregisterNode : function(D){
15695         delete  this.nodeHash[D.id];
15696     },
15697
15698     toString : function(){
15699         return  "[Tree"+(this.id?" "+this.id:"")+"]";
15700     }
15701 });
15702
15703
15704
15705 Roo.data.Node = function(E){
15706     
15707
15708     this.attributes = E || {};
15709     this.leaf = this.attributes.leaf;
15710     
15711
15712     this.id = this.attributes.id;
15713     if(!this.id){
15714         this.id = Roo.id(null, "ynode-");
15715         this.attributes.id = this.id;
15716     }
15717
15718     
15719
15720     this.childNodes = [];
15721     if(!this.childNodes.indexOf){ 
15722         this.childNodes.indexOf = function(o){
15723             for(var  i = 0, len = this.length; i < len; i++){
15724                 if(this[i] == o) return  i;
15725             }
15726             return  -1;
15727         };
15728     }
15729
15730     
15731
15732     this.parentNode = null;
15733     
15734
15735     this.firstChild = null;
15736     
15737
15738     this.lastChild = null;
15739     
15740
15741     this.previousSibling = null;
15742     
15743
15744     this.nextSibling = null;
15745
15746     this.addEvents({
15747        
15748
15749        "append" : true,
15750        
15751
15752        "remove" : true,
15753        
15754
15755        "move" : true,
15756        
15757
15758        "insert" : true,
15759        
15760
15761        "beforeappend" : true,
15762        
15763
15764        "beforeremove" : true,
15765        
15766
15767        "beforemove" : true,
15768        
15769
15770        "beforeinsert" : true
15771    });
15772     this.listeners = this.attributes.listeners;
15773     Roo.data.Node.superclass.constructor.call(this);
15774 };
15775
15776 Roo.extend(Roo.data.Node, Roo.util.Observable, {
15777     fireEvent : function(F){
15778         
15779         if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
15780             return  false;
15781         }
15782         
15783         var  ot = this.getOwnerTree();
15784         if(ot){
15785             if(ot.proxyNodeEvent.apply(ot, arguments) === false){
15786                 return  false;
15787             }
15788         }
15789         return  true;
15790     },
15791
15792     
15793
15794     isLeaf : function(){
15795         return  this.leaf === true;
15796     },
15797
15798     
15799     setFirstChild : function(G){
15800         this.firstChild = G;
15801     },
15802
15803     
15804     setLastChild : function(H){
15805         this.lastChild = H;
15806     },
15807
15808
15809     
15810
15811     isLast : function(){
15812        return  (!this.parentNode ? true : this.parentNode.lastChild == this);
15813     },
15814
15815     
15816
15817     isFirst : function(){
15818        return  (!this.parentNode ? true : this.parentNode.firstChild == this);
15819     },
15820
15821     hasChildNodes : function(){
15822         return  !this.isLeaf() && this.childNodes.length > 0;
15823     },
15824
15825     
15826
15827     appendChild : function(I){
15828         var  J = false;
15829         if(I  instanceof  Array){
15830             J = I;
15831         }else  if(arguments.length > 1){
15832             J = arguments;
15833         }
15834         
15835         if(J){
15836             for(var  i = 0, len = J.length; i < len; i++) {
15837                 this.appendChild(J[i]);
15838             }
15839         }else {
15840             if(this.fireEvent("beforeappend", this.ownerTree, this, I) === false){
15841                 return  false;
15842             }
15843             var  index = this.childNodes.length;
15844             var  oldParent = I.parentNode;
15845             
15846             if(oldParent){
15847                 if(I.fireEvent("beforemove", I.getOwnerTree(), I, oldParent, this, index) === false){
15848                     return  false;
15849                 }
15850
15851                 oldParent.removeChild(I);
15852             }
15853
15854             index = this.childNodes.length;
15855             if(index == 0){
15856                 this.setFirstChild(I);
15857             }
15858
15859             this.childNodes.push(I);
15860             I.parentNode = this;
15861             var  ps = this.childNodes[index-1];
15862             if(ps){
15863                 I.previousSibling = ps;
15864                 ps.nextSibling = I;
15865             }else {
15866                 I.previousSibling = null;
15867             }
15868
15869             I.nextSibling = null;
15870             this.setLastChild(I);
15871             I.setOwnerTree(this.getOwnerTree());
15872             this.fireEvent("append", this.ownerTree, this, I, index);
15873             if(oldParent){
15874                 I.fireEvent("move", this.ownerTree, I, oldParent, this, index);
15875             }
15876             return  I;
15877         }
15878     },
15879
15880     
15881
15882     removeChild : function(K){
15883         var  L = this.childNodes.indexOf(K);
15884         if(L == -1){
15885             return  false;
15886         }
15887         if(this.fireEvent("beforeremove", this.ownerTree, this, K) === false){
15888             return  false;
15889         }
15890
15891
15892         
15893         this.childNodes.splice(L, 1);
15894
15895         
15896         if(K.previousSibling){
15897             K.previousSibling.nextSibling = K.nextSibling;
15898         }
15899         if(K.nextSibling){
15900             K.nextSibling.previousSibling = K.previousSibling;
15901         }
15902
15903         
15904         if(this.firstChild == K){
15905             this.setFirstChild(K.nextSibling);
15906         }
15907         if(this.lastChild == K){
15908             this.setLastChild(K.previousSibling);
15909         }
15910
15911
15912         K.setOwnerTree(null);
15913         
15914         K.parentNode = null;
15915         K.previousSibling = null;
15916         K.nextSibling = null;
15917         this.fireEvent("remove", this.ownerTree, this, K);
15918         return  K;
15919     },
15920
15921     
15922
15923     insertBefore : function(M, N){
15924         if(!N){ 
15925             return  this.appendChild(M);
15926         }
15927         
15928         if(M == N){
15929             return  false;
15930         }
15931
15932         if(this.fireEvent("beforeinsert", this.ownerTree, this, M, N) === false){
15933             return  false;
15934         }
15935         var  O = this.childNodes.indexOf(N);
15936         var  P = M.parentNode;
15937         var  Q = O;
15938
15939         
15940         if(P == this && this.childNodes.indexOf(M) < O){
15941             Q--;
15942         }
15943
15944         
15945         if(P){
15946             if(M.fireEvent("beforemove", M.getOwnerTree(), M, P, this, O, N) === false){
15947                 return  false;
15948             }
15949
15950             P.removeChild(M);
15951         }
15952         if(Q == 0){
15953             this.setFirstChild(M);
15954         }
15955
15956         this.childNodes.splice(Q, 0, M);
15957         M.parentNode = this;
15958         var  ps = this.childNodes[Q-1];
15959         if(ps){
15960             M.previousSibling = ps;
15961             ps.nextSibling = M;
15962         }else {
15963             M.previousSibling = null;
15964         }
15965
15966         M.nextSibling = N;
15967         N.previousSibling = M;
15968         M.setOwnerTree(this.getOwnerTree());
15969         this.fireEvent("insert", this.ownerTree, this, M, N);
15970         if(P){
15971             M.fireEvent("move", this.ownerTree, M, P, this, Q, N);
15972         }
15973         return  M;
15974     },
15975
15976     
15977
15978     item : function(R){
15979         return  this.childNodes[R];
15980     },
15981
15982     
15983
15984     replaceChild : function(S, T){
15985         this.insertBefore(S, T);
15986         this.removeChild(T);
15987         return  T;
15988     },
15989
15990     
15991
15992     indexOf : function(U){
15993         return  this.childNodes.indexOf(U);
15994     },
15995
15996     
15997
15998     getOwnerTree : function(){
15999         
16000         if(!this.ownerTree){
16001             var  p = this;
16002             while(p){
16003                 if(p.ownerTree){
16004                     this.ownerTree = p.ownerTree;
16005                     break;
16006                 }
16007
16008                 p = p.parentNode;
16009             }
16010         }
16011         return  this.ownerTree;
16012     },
16013
16014     
16015
16016     getDepth : function(){
16017         var  V = 0;
16018         var  p = this;
16019         while(p.parentNode){
16020             ++V;
16021             p = p.parentNode;
16022         }
16023         return  V;
16024     },
16025
16026     
16027     setOwnerTree : function(W){
16028         
16029         if(W != this.ownerTree){
16030             if(this.ownerTree){
16031                 this.ownerTree.unregisterNode(this);
16032             }
16033
16034             this.ownerTree = W;
16035             var  cs = this.childNodes;
16036             for(var  i = 0, len = cs.length; i < len; i++) {
16037                 cs[i].setOwnerTree(W);
16038             }
16039             if(W){
16040                 W.registerNode(this);
16041             }
16042         }
16043     },
16044
16045     
16046
16047     getPath : function(X){
16048         X = X || "id";
16049         var  p = this.parentNode;
16050         var  b = [this.attributes[X]];
16051         while(p){
16052             b.unshift(p.attributes[X]);
16053             p = p.parentNode;
16054         }
16055         var  Y = this.getOwnerTree().pathSeparator;
16056         return  Y + b.join(Y);
16057     },
16058
16059     
16060
16061     bubble : function(fn, Z, a){
16062         var  p = this;
16063         while(p){
16064             if(fn.call(Z || p, a || p) === false){
16065                 break;
16066             }
16067
16068             p = p.parentNode;
16069         }
16070     },
16071
16072     
16073
16074     cascade : function(fn, c, d){
16075         if(fn.call(c || this, d || this) !== false){
16076             var  cs = this.childNodes;
16077             for(var  i = 0, len = cs.length; i < len; i++) {
16078                 cs[i].cascade(fn, c, d);
16079             }
16080         }
16081     },
16082
16083     
16084
16085     eachChild : function(fn, e, f){
16086         var  cs = this.childNodes;
16087         for(var  i = 0, len = cs.length; i < len; i++) {
16088                 if(fn.call(e || this, f || cs[i]) === false){
16089                     break;
16090                 }
16091         }
16092     },
16093
16094     
16095
16096     findChild : function(g, h){
16097         var  cs = this.childNodes;
16098         for(var  i = 0, len = cs.length; i < len; i++) {
16099                 if(cs[i].attributes[g] == h){
16100                     return  cs[i];
16101                 }
16102         }
16103         return  null;
16104     },
16105
16106     
16107
16108     findChildBy : function(fn, j){
16109         var  cs = this.childNodes;
16110         for(var  i = 0, len = cs.length; i < len; i++) {
16111                 if(fn.call(j||cs[i], cs[i]) === true){
16112                     return  cs[i];
16113                 }
16114         }
16115         return  null;
16116     },
16117
16118     
16119
16120     sort : function(fn, k){
16121         var  cs = this.childNodes;
16122         var  l = cs.length;
16123         if(l > 0){
16124             var  sortFn = k ? function(){fn.apply(k, arguments);} : fn;
16125             cs.sort(sortFn);
16126             for(var  i = 0; i < l; i++){
16127                 var  n = cs[i];
16128                 n.previousSibling = cs[i-1];
16129                 n.nextSibling = cs[i+1];
16130                 if(i == 0){
16131                     this.setFirstChild(n);
16132                 }
16133                 if(i == l-1){
16134                     this.setLastChild(n);
16135                 }
16136             }
16137         }
16138     },
16139
16140     
16141
16142     contains : function(m){
16143         return  m.isAncestor(this);
16144     },
16145
16146     
16147
16148     isAncestor : function(o){
16149         var  p = this.parentNode;
16150         while(p){
16151             if(p == o){
16152                 return  true;
16153             }
16154
16155             p = p.parentNode;
16156         }
16157         return  false;
16158     },
16159
16160     toString : function(){
16161         return  "[Node"+(this.id?" "+this.id:"")+"]";
16162     }
16163 });
16164
16165
16166  
16167
16168
16169
16170 Roo.ComponentMgr = function(){
16171     var  A = new  Roo.util.MixedCollection();
16172
16173     return  {
16174         
16175
16176         register : function(c){
16177             A.add(c);
16178         },
16179
16180         
16181
16182         unregister : function(c){
16183             A.remove(c);
16184         },
16185
16186         
16187
16188         get : function(id){
16189             return  A.get(id);
16190         },
16191
16192         
16193
16194         onAvailable : function(id, fn, C){
16195             A.on("add", function(D, o){
16196                 if(o.id == id){
16197                     fn.call(C || o, o);
16198                     A.un("add", fn, C);
16199                 }
16200             });
16201         }
16202     };
16203 }();
16204
16205
16206  
16207
16208
16209 Roo.Component = function(A){
16210     A = A || {};
16211     if(A.tagName || A.dom || typeof  A == "string"){ 
16212         A = {el: A, id: A.id || A};
16213     }
16214
16215     this.initialConfig = A;
16216
16217     Roo.apply(this, A);
16218     this.addEvents({
16219         
16220
16221         disable : true,
16222         
16223
16224         enable : true,
16225         
16226
16227         beforeshow : true,
16228         
16229
16230         show : true,
16231         
16232
16233         beforehide : true,
16234         
16235
16236         hide : true,
16237         
16238
16239         beforerender : true,
16240         
16241
16242         render : true,
16243         
16244
16245         beforedestroy : true,
16246         
16247
16248         destroy : true
16249     });
16250     if(!this.id){
16251         this.id = "ext-comp-" + (++Roo.Component.AUTO_ID);
16252     }
16253
16254     Roo.ComponentMgr.register(this);
16255     Roo.Component.superclass.constructor.call(this);
16256     this.initComponent();
16257     if(this.renderTo){ 
16258         this.render(this.renderTo);
16259         delete  this.renderTo;
16260     }
16261 };
16262
16263
16264 Roo.Component.AUTO_ID = 1000;
16265
16266 Roo.extend(Roo.Component, Roo.util.Observable, {
16267     
16268
16269     hidden : false,
16270     
16271
16272     disabled : false,
16273     
16274
16275     rendered : false,
16276     
16277     
16278
16279     disabledClass : "x-item-disabled",
16280         
16281
16282     allowDomMove : true,
16283     
16284
16285     hideMode: 'display',
16286
16287     
16288     ctype : "Roo.Component",
16289
16290     
16291
16292     actionMode : "el",
16293
16294     
16295     getActionEl : function(){
16296         return  this[this.actionMode];
16297     },
16298
16299     initComponent : Roo.emptyFn,
16300     
16301
16302     render : function(B, C){
16303         if(!this.rendered && this.fireEvent("beforerender", this) !== false){
16304             if(!B && this.el){
16305                 this.el = Roo.get(this.el);
16306                 B = this.el.dom.parentNode;
16307                 this.allowDomMove = false;
16308             }
16309
16310             this.container = Roo.get(B);
16311             this.rendered = true;
16312             if(C !== undefined){
16313                 if(typeof  C == 'number'){
16314                     C = this.container.dom.childNodes[C];
16315                 }else {
16316                     C = Roo.getDom(C);
16317                 }
16318             }
16319
16320             this.onRender(this.container, C || null);
16321             if(this.cls){
16322                 this.el.addClass(this.cls);
16323                 delete  this.cls;
16324             }
16325             if(this.style){
16326                 this.el.applyStyles(this.style);
16327                 delete  this.style;
16328             }
16329
16330             this.fireEvent("render", this);
16331             this.afterRender(this.container);
16332             if(this.hidden){
16333                 this.hide();
16334             }
16335             if(this.disabled){
16336                 this.disable();
16337             }
16338         }
16339         return  this;
16340     },
16341
16342     
16343     
16344     onRender : function(ct, D){
16345         if(this.el){
16346             this.el = Roo.get(this.el);
16347             if(this.allowDomMove !== false){
16348                 ct.dom.insertBefore(this.el.dom, D);
16349             }
16350         }
16351     },
16352
16353     
16354     getAutoCreate : function(){
16355         var  E = typeof  this.autoCreate == "object" ?
16356                       this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
16357         if(this.id && !E.id){
16358             E.id = this.id;
16359         }
16360         return  E;
16361     },
16362
16363     
16364     afterRender : Roo.emptyFn,
16365
16366     
16367
16368     destroy : function(){
16369         if(this.fireEvent("beforedestroy", this) !== false){
16370             this.purgeListeners();
16371             this.beforeDestroy();
16372             if(this.rendered){
16373                 this.el.removeAllListeners();
16374                 this.el.remove();
16375                 if(this.actionMode == "container"){
16376                     this.container.remove();
16377                 }
16378             }
16379
16380             this.onDestroy();
16381             Roo.ComponentMgr.unregister(this);
16382             this.fireEvent("destroy", this);
16383         }
16384     },
16385
16386         
16387     beforeDestroy : function(){
16388
16389     },
16390
16391         
16392         onDestroy : function(){
16393
16394     },
16395
16396     
16397
16398     getEl : function(){
16399         return  this.el;
16400     },
16401
16402     
16403
16404     getId : function(){
16405         return  this.id;
16406     },
16407
16408     
16409
16410     focus : function(F){
16411         if(this.rendered){
16412             this.el.focus();
16413             if(F === true){
16414                 this.el.dom.select();
16415             }
16416         }
16417         return  this;
16418     },
16419
16420     
16421     blur : function(){
16422         if(this.rendered){
16423             this.el.blur();
16424         }
16425         return  this;
16426     },
16427
16428     
16429
16430     disable : function(){
16431         if(this.rendered){
16432             this.onDisable();
16433         }
16434
16435         this.disabled = true;
16436         this.fireEvent("disable", this);
16437         return  this;
16438     },
16439
16440         
16441     onDisable : function(){
16442         this.getActionEl().addClass(this.disabledClass);
16443         this.el.dom.disabled = true;
16444     },
16445
16446     
16447
16448     enable : function(){
16449         if(this.rendered){
16450             this.onEnable();
16451         }
16452
16453         this.disabled = false;
16454         this.fireEvent("enable", this);
16455         return  this;
16456     },
16457
16458         
16459     onEnable : function(){
16460         this.getActionEl().removeClass(this.disabledClass);
16461         this.el.dom.disabled = false;
16462     },
16463
16464     
16465
16466     setDisabled : function(G){
16467         this[G ? "disable" : "enable"]();
16468     },
16469
16470     
16471
16472     show: function(){
16473         if(this.fireEvent("beforeshow", this) !== false){
16474             this.hidden = false;
16475             if(this.rendered){
16476                 this.onShow();
16477             }
16478
16479             this.fireEvent("show", this);
16480         }
16481         return  this;
16482     },
16483
16484     
16485     onShow : function(){
16486         var  ae = this.getActionEl();
16487         if(this.hideMode == 'visibility'){
16488             ae.dom.style.visibility = "visible";
16489         }else  if(this.hideMode == 'offsets'){
16490             ae.removeClass('x-hidden');
16491         }else {
16492             ae.dom.style.display = "";
16493         }
16494     },
16495
16496     
16497
16498     hide: function(){
16499         if(this.fireEvent("beforehide", this) !== false){
16500             this.hidden = true;
16501             if(this.rendered){
16502                 this.onHide();
16503             }
16504
16505             this.fireEvent("hide", this);
16506         }
16507         return  this;
16508     },
16509
16510     
16511     onHide : function(){
16512         var  ae = this.getActionEl();
16513         if(this.hideMode == 'visibility'){
16514             ae.dom.style.visibility = "hidden";
16515         }else  if(this.hideMode == 'offsets'){
16516             ae.addClass('x-hidden');
16517         }else {
16518             ae.dom.style.display = "none";
16519         }
16520     },
16521
16522     
16523
16524     setVisible: function(H){
16525         if(H) {
16526             this.show();
16527         }else {
16528             this.hide();
16529         }
16530         return  this;
16531     },
16532
16533     
16534
16535     isVisible : function(){
16536         return  this.getActionEl().isVisible();
16537     },
16538
16539     cloneConfig : function(I){
16540         I = I || {};
16541         var  id = I.id || Roo.id();
16542         var  J = Roo.applyIf(I, this.initialConfig);
16543         J.id = id; 
16544         return  new  this.constructor(J);
16545     }
16546 });
16547
16548
16549  (function(){ 
16550
16551
16552
16553 Roo.Layer = function(C, D){
16554     C = C || {};
16555     var  dh = Roo.DomHelper;
16556     var  cp = C.parentEl, E = cp ? Roo.getDom(cp) : document.body;
16557     if(D){
16558         this.dom = Roo.getDom(D);
16559     }
16560     if(!this.dom){
16561         var  o = C.dh || {tag: "div", cls: "x-layer"};
16562         this.dom = dh.append(E, o);
16563     }
16564     if(C.cls){
16565         this.addClass(C.cls);
16566     }
16567
16568     this.constrain = C.constrain !== false;
16569     this.visibilityMode = Roo.Element.VISIBILITY;
16570     if(C.id){
16571         this.id = this.dom.id = C.id;
16572     }else {
16573         this.id = Roo.id(this.dom);
16574     }
16575
16576     this.zindex = C.zindex || this.getZIndex();
16577     this.position("absolute", this.zindex);
16578     if(C.shadow){
16579         this.shadowOffset = C.shadowOffset || 4;
16580         this.shadow = new  Roo.Shadow({
16581             offset : this.shadowOffset,
16582             mode : C.shadow
16583         });
16584     }else {
16585         this.shadowOffset = 0;
16586     }
16587
16588     this.useShim = C.shim !== false && Roo.useShims;
16589     this.useDisplay = C.useDisplay;
16590     this.hide();
16591 };
16592
16593 var  A = Roo.Element.prototype;
16594
16595
16596 var  B = [];
16597
16598 Roo.extend(Roo.Layer, Roo.Element, {
16599
16600     getZIndex : function(){
16601         return  this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
16602     },
16603
16604     getShim : function(){
16605         if(!this.useShim){
16606             return  null;
16607         }
16608         if(this.shim){
16609             return  this.shim;
16610         }
16611         var  C = B.shift();
16612         if(!C){
16613             C = this.createShim();
16614             C.enableDisplayMode('block');
16615             C.dom.style.display = 'none';
16616             C.dom.style.visibility = 'visible';
16617         }
16618         var  pn = this.dom.parentNode;
16619         if(C.dom.parentNode != pn){
16620             pn.insertBefore(C.dom, this.dom);
16621         }
16622
16623         C.setStyle('z-index', this.getZIndex()-2);
16624         this.shim = C;
16625         return  C;
16626     },
16627
16628     hideShim : function(){
16629         if(this.shim){
16630             this.shim.setDisplayed(false);
16631             B.push(this.shim);
16632             delete  this.shim;
16633         }
16634     },
16635
16636     disableShadow : function(){
16637         if(this.shadow){
16638             this.shadowDisabled = true;
16639             this.shadow.hide();
16640             this.lastShadowOffset = this.shadowOffset;
16641             this.shadowOffset = 0;
16642         }
16643     },
16644
16645     enableShadow : function(D){
16646         if(this.shadow){
16647             this.shadowDisabled = false;
16648             this.shadowOffset = this.lastShadowOffset;
16649             delete  this.lastShadowOffset;
16650             if(D){
16651                 this.sync(true);
16652             }
16653         }
16654     },
16655
16656     
16657     
16658     
16659     sync : function(E){
16660         var  sw = this.shadow;
16661         if(!this.updating && this.isVisible() && (sw || this.useShim)){
16662             var  sh = this.getShim();
16663
16664             var  w = this.getWidth(),
16665                 h = this.getHeight();
16666
16667             var  l = this.getLeft(true),
16668                 t = this.getTop(true);
16669
16670             if(sw && !this.shadowDisabled){
16671                 if(E && !sw.isVisible()){
16672                     sw.show(this);
16673                 }else {
16674                     sw.realign(l, t, w, h);
16675                 }
16676                 if(sh){
16677                     if(E){
16678                        sh.show();
16679                     }
16680                     
16681                     var  a = sw.adjusts, s = sh.dom.style;
16682                     s.left = (Math.min(l, l+a.l))+"px";
16683                     s.top = (Math.min(t, t+a.t))+"px";
16684                     s.width = (w+a.w)+"px";
16685                     s.height = (h+a.h)+"px";
16686                 }
16687             }else  if(sh){
16688                 if(E){
16689                    sh.show();
16690                 }
16691
16692                 sh.setSize(w, h);
16693                 sh.setLeftTop(l, t);
16694             }
16695             
16696         }
16697     },
16698
16699     
16700     destroy : function(){
16701         this.hideShim();
16702         if(this.shadow){
16703             this.shadow.hide();
16704         }
16705
16706         this.removeAllListeners();
16707         var  pn = this.dom.parentNode;
16708         if(pn){
16709             pn.removeChild(this.dom);
16710         }
16711
16712         Roo.Element.uncache(this.id);
16713     },
16714
16715     remove : function(){
16716         this.destroy();
16717     },
16718
16719     
16720     beginUpdate : function(){
16721         this.updating = true;
16722     },
16723
16724     
16725     endUpdate : function(){
16726         this.updating = false;
16727         this.sync(true);
16728     },
16729
16730     
16731     hideUnders : function(F){
16732         if(this.shadow){
16733             this.shadow.hide();
16734         }
16735
16736         this.hideShim();
16737     },
16738
16739     
16740     constrainXY : function(){
16741         if(this.constrain){
16742             var  vw = Roo.lib.Dom.getViewWidth(),
16743                 vh = Roo.lib.Dom.getViewHeight();
16744             var  s = Roo.get(document).getScroll();
16745
16746             var  xy = this.getXY();
16747             var  x = xy[0], y = xy[1];   
16748             var  w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
16749             
16750             var  moved = false;
16751             
16752             if((x + w) > vw+s.left){
16753                 x = vw - w - this.shadowOffset;
16754                 moved = true;
16755             }
16756             if((y + h) > vh+s.top){
16757                 y = vh - h - this.shadowOffset;
16758                 moved = true;
16759             }
16760             
16761             if(x < s.left){
16762                 x = s.left;
16763                 moved = true;
16764             }
16765             if(y < s.top){
16766                 y = s.top;
16767                 moved = true;
16768             }
16769             if(moved){
16770                 if(this.avoidY){
16771                     var  ay = this.avoidY;
16772                     if(y <= ay && (y+h) >= ay){
16773                         y = ay-h-5;   
16774                     }
16775                 }
16776
16777                 xy = [x, y];
16778                 this.storeXY(xy);
16779                 A.setXY.call(this, xy);
16780                 this.sync();
16781             }
16782         }
16783     },
16784
16785     isVisible : function(){
16786         return  this.visible;    
16787     },
16788
16789     
16790     showAction : function(){
16791         this.visible = true; 
16792         if(this.useDisplay === true){
16793             this.setDisplayed("");
16794         }else  if(this.lastXY){
16795             A.setXY.call(this, this.lastXY);
16796         }else  if(this.lastLT){
16797             A.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
16798         }
16799     },
16800
16801     
16802     hideAction : function(){
16803         this.visible = false;
16804         if(this.useDisplay === true){
16805             this.setDisplayed(false);
16806         }else {
16807             this.setLeftTop(-10000,-10000);
16808         }
16809     },
16810
16811     
16812     setVisible : function(v, a, d, c, e){
16813         if(v){
16814             this.showAction();
16815         }
16816         if(a && v){
16817             var  cb = function(){
16818                 this.sync(true);
16819                 if(c){
16820                     c();
16821                 }
16822             }.createDelegate(this);
16823             A.setVisible.call(this, true, true, d, cb, e);
16824         }else {
16825             if(!v){
16826                 this.hideUnders(true);
16827             }
16828             var  cb = c;
16829             if(a){
16830                 cb = function(){
16831                     this.hideAction();
16832                     if(c){
16833                         c();
16834                     }
16835                 }.createDelegate(this);
16836             }
16837
16838             A.setVisible.call(this, v, a, d, cb, e);
16839             if(v){
16840                 this.sync(true);
16841             }else  if(!a){
16842                 this.hideAction();
16843             }
16844         }
16845     },
16846
16847     storeXY : function(xy){
16848         delete  this.lastLT;
16849         this.lastXY = xy;
16850     },
16851
16852     storeLeftTop : function(G, H){
16853         delete  this.lastXY;
16854         this.lastLT = [G, H];
16855     },
16856
16857     
16858     beforeFx : function(){
16859         this.beforeAction();
16860         return  Roo.Layer.superclass.beforeFx.apply(this, arguments);
16861     },
16862
16863     
16864     afterFx : function(){
16865         Roo.Layer.superclass.afterFx.apply(this, arguments);
16866         this.sync(this.isVisible());
16867     },
16868
16869     
16870     beforeAction : function(){
16871         if(!this.updating && this.shadow){
16872             this.shadow.hide();
16873         }
16874     },
16875
16876     
16877     setLeft : function(I){
16878         this.storeLeftTop(I, this.getTop(true));
16879         A.setLeft.apply(this, arguments);
16880         this.sync();
16881     },
16882
16883     setTop : function(J){
16884         this.storeLeftTop(this.getLeft(true), J);
16885         A.setTop.apply(this, arguments);
16886         this.sync();
16887     },
16888
16889     setLeftTop : function(K, L){
16890         this.storeLeftTop(K, L);
16891         A.setLeftTop.apply(this, arguments);
16892         this.sync();
16893     },
16894
16895     setXY : function(xy, a, d, c, e){
16896         this.fixDisplay();
16897         this.beforeAction();
16898         this.storeXY(xy);
16899         var  cb = this.createCB(c);
16900         A.setXY.call(this, xy, a, d, cb, e);
16901         if(!a){
16902             cb();
16903         }
16904     },
16905
16906     
16907     createCB : function(c){
16908         var  el = this;
16909         return  function(){
16910             el.constrainXY();
16911             el.sync(true);
16912             if(c){
16913                 c();
16914             }
16915         };
16916     },
16917
16918     
16919     setX : function(x, a, d, c, e){
16920         this.setXY([x, this.getY()], a, d, c, e);
16921     },
16922
16923     
16924     setY : function(y, a, d, c, e){
16925         this.setXY([this.getX(), y], a, d, c, e);
16926     },
16927
16928     
16929     setSize : function(w, h, a, d, c, e){
16930         this.beforeAction();
16931         var  cb = this.createCB(c);
16932         A.setSize.call(this, w, h, a, d, cb, e);
16933         if(!a){
16934             cb();
16935         }
16936     },
16937
16938     
16939     setWidth : function(w, a, d, c, e){
16940         this.beforeAction();
16941         var  cb = this.createCB(c);
16942         A.setWidth.call(this, w, a, d, cb, e);
16943         if(!a){
16944             cb();
16945         }
16946     },
16947
16948     
16949     setHeight : function(h, a, d, c, e){
16950         this.beforeAction();
16951         var  cb = this.createCB(c);
16952         A.setHeight.call(this, h, a, d, cb, e);
16953         if(!a){
16954             cb();
16955         }
16956     },
16957
16958     
16959     setBounds : function(x, y, w, h, a, d, c, e){
16960         this.beforeAction();
16961         var  cb = this.createCB(c);
16962         if(!a){
16963             this.storeXY([x, y]);
16964             A.setXY.call(this, [x, y]);
16965             A.setSize.call(this, w, h, a, d, cb, e);
16966             cb();
16967         }else {
16968             A.setBounds.call(this, x, y, w, h, a, d, cb, e);
16969         }
16970         return  this;
16971     },
16972     
16973     
16974
16975     setZIndex : function(M){
16976         this.zindex = M;
16977         this.setStyle("z-index", M + 2);
16978         if(this.shadow){
16979             this.shadow.setZIndex(M + 1);
16980         }
16981         if(this.shim){
16982             this.shim.setStyle("z-index", M);
16983         }
16984     }
16985 });
16986 })();
16987
16988
16989
16990
16991
16992
16993 Roo.Shadow = function(A){
16994     Roo.apply(this, A);
16995     if(typeof  this.mode != "string"){
16996         this.mode = this.defaultMode;
16997     }
16998     var  o = this.offset, a = {h: 0};
16999     var  B = Math.floor(this.offset/2);
17000     switch(this.mode.toLowerCase()){ 
17001         case  "drop":
17002             a.w = 0;
17003             a.l = a.t = o;
17004             a.t -= 1;
17005             if(Roo.isIE){
17006                 a.l -= this.offset + B;
17007                 a.t -= this.offset + B;
17008                 a.w -= B;
17009                 a.h -= B;
17010                 a.t += 1;
17011             }
17012         break;
17013         case  "sides":
17014             a.w = (o*2);
17015             a.l = -o;
17016             a.t = o-1;
17017             if(Roo.isIE){
17018                 a.l -= (this.offset - B);
17019                 a.t -= this.offset + B;
17020                 a.l += 1;
17021                 a.w -= (this.offset - B)*2;
17022                 a.w -= B + 1;
17023                 a.h -= 1;
17024             }
17025         break;
17026         case  "frame":
17027             a.w = a.h = (o*2);
17028             a.l = a.t = -o;
17029             a.t += 1;
17030             a.h -= 2;
17031             if(Roo.isIE){
17032                 a.l -= (this.offset - B);
17033                 a.t -= (this.offset - B);
17034                 a.l += 1;
17035                 a.w -= (this.offset + B + 1);
17036                 a.h -= (this.offset + B);
17037                 a.h += 1;
17038             }
17039         break;
17040     };
17041
17042     this.adjusts = a;
17043 };
17044
17045 Roo.Shadow.prototype = {
17046     
17047
17048     
17049
17050     offset: 4,
17051
17052     
17053     defaultMode: "drop",
17054
17055     
17056
17057     show : function(C){
17058         C = Roo.get(C);
17059         if(!this.el){
17060             this.el = Roo.Shadow.Pool.pull();
17061             if(this.el.dom.nextSibling != C.dom){
17062                 this.el.insertBefore(C);
17063             }
17064         }
17065
17066         this.el.setStyle("z-index", this.zIndex || parseInt(C.getStyle("z-index"), 10)-1);
17067         if(Roo.isIE){
17068             this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
17069         }
17070
17071         this.realign(
17072             C.getLeft(true),
17073             C.getTop(true),
17074             C.getWidth(),
17075             C.getHeight()
17076         );
17077         this.el.dom.style.display = "block";
17078     },
17079
17080     
17081
17082     isVisible : function(){
17083         return  this.el ? true : false;  
17084     },
17085
17086     
17087
17088     realign : function(l, t, w, h){
17089         if(!this.el){
17090             return;
17091         }
17092         var  a = this.adjusts, d = this.el.dom, s = d.style;
17093         var  D = 0;
17094         s.left = (l+a.l)+"px";
17095         s.top = (t+a.t)+"px";
17096         var  sw = (w+a.w), sh = (h+a.h), E = sw +"px", F = sh + "px";
17097         if(s.width != E || s.height != F){
17098             s.width = E;
17099             s.height = F;
17100             if(!Roo.isIE){
17101                 var  cn = d.childNodes;
17102                 var  sww = Math.max(0, (sw-12))+"px";
17103                 cn[0].childNodes[1].style.width = sww;
17104                 cn[1].childNodes[1].style.width = sww;
17105                 cn[2].childNodes[1].style.width = sww;
17106                 cn[1].style.height = Math.max(0, (sh-12))+"px";
17107             }
17108         }
17109     },
17110
17111     
17112
17113     hide : function(){
17114         if(this.el){
17115             this.el.dom.style.display = "none";
17116             Roo.Shadow.Pool.push(this.el);
17117             delete  this.el;
17118         }
17119     },
17120
17121     
17122
17123     setZIndex : function(z){
17124         this.zIndex = z;
17125         if(this.el){
17126             this.el.setStyle("z-index", z);
17127         }
17128     }
17129 };
17130
17131
17132 Roo.Shadow.Pool = function(){
17133     var  p = [];
17134     var  G = Roo.isIE ?
17135                  '<div class="x-ie-shadow"></div>' :
17136                  '<div class="x-shadow"><div class="xst"><div class="xstl"></div><div class="xstc"></div><div class="xstr"></div></div><div class="xsc"><div class="xsml"></div><div class="xsmc"></div><div class="xsmr"></div></div><div class="xsb"><div class="xsbl"></div><div class="xsbc"></div><div class="xsbr"></div></div></div>';
17137     return  {
17138         pull : function(){
17139             var  sh = p.shift();
17140             if(!sh){
17141                 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, G));
17142                 sh.autoBoxAdjust = false;
17143             }
17144             return  sh;
17145         },
17146
17147         push : function(sh){
17148             p.push(sh);
17149         }
17150     };
17151 }();
17152
17153
17154
17155
17156
17157 Roo.BoxComponent = function(A){
17158     Roo.Component.call(this, A);
17159     this.addEvents({
17160         
17161
17162         resize : true,
17163         
17164
17165         move : true
17166     });
17167 };
17168
17169 Roo.extend(Roo.BoxComponent, Roo.Component, {
17170     
17171     boxReady : false,
17172     
17173     deferHeight: false,
17174     
17175
17176      
17177
17178      
17179     
17180
17181     setSize : function(w, h){
17182         
17183         if(typeof  w == 'object'){
17184             h = w.height;
17185             w = w.width;
17186         }
17187         
17188         if(!this.boxReady){
17189             this.width = w;
17190             this.height = h;
17191             return  this;
17192         }
17193
17194         
17195         if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
17196             return  this;
17197         }
17198
17199         this.lastSize = {width: w, height: h};
17200
17201         var  B = this.adjustSize(w, h);
17202         var  aw = B.width, ah = B.height;
17203         if(aw !== undefined || ah !== undefined){ 
17204             var  rz = this.getResizeEl();
17205             if(!this.deferHeight && aw !== undefined && ah !== undefined){
17206                 rz.setSize(aw, ah);
17207             }else  if(!this.deferHeight && ah !== undefined){
17208                 rz.setHeight(ah);
17209             }else  if(aw !== undefined){
17210                 rz.setWidth(aw);
17211             }
17212
17213             this.onResize(aw, ah, w, h);
17214             this.fireEvent('resize', this, aw, ah, w, h);
17215         }
17216         return  this;
17217     },
17218
17219     
17220
17221     getSize : function(){
17222         return  this.el.getSize();
17223     },
17224
17225     
17226
17227     getPosition : function(C){
17228         if(C === true){
17229             return  [this.el.getLeft(true), this.el.getTop(true)];
17230         }
17231         return  this.xy || this.el.getXY();
17232     },
17233
17234     
17235
17236     getBox : function(D){
17237         var  s = this.el.getSize();
17238         if(D){
17239             s.x = this.el.getLeft(true);
17240             s.y = this.el.getTop(true);
17241         }else {
17242             var  xy = this.xy || this.el.getXY();
17243             s.x = xy[0];
17244             s.y = xy[1];
17245         }
17246         return  s;
17247     },
17248
17249     
17250
17251     updateBox : function(E){
17252         this.setSize(E.width, E.height);
17253         this.setPagePosition(E.x, E.y);
17254         return  this;
17255     },
17256
17257     
17258     getResizeEl : function(){
17259         return  this.resizeEl || this.el;
17260     },
17261
17262     
17263     getPositionEl : function(){
17264         return  this.positionEl || this.el;
17265     },
17266
17267     
17268
17269     setPosition : function(x, y){
17270         this.x = x;
17271         this.y = y;
17272         if(!this.boxReady){
17273             return  this;
17274         }
17275         var  F = this.adjustPosition(x, y);
17276         var  ax = F.x, ay = F.y;
17277
17278         var  el = this.getPositionEl();
17279         if(ax !== undefined || ay !== undefined){
17280             if(ax !== undefined && ay !== undefined){
17281                 el.setLeftTop(ax, ay);
17282             }else  if(ax !== undefined){
17283                 el.setLeft(ax);
17284             }else  if(ay !== undefined){
17285                 el.setTop(ay);
17286             }
17287
17288             this.onPosition(ax, ay);
17289             this.fireEvent('move', this, ax, ay);
17290         }
17291         return  this;
17292     },
17293
17294     
17295
17296     setPagePosition : function(x, y){
17297         this.pageX = x;
17298         this.pageY = y;
17299         if(!this.boxReady){
17300             return;
17301         }
17302         if(x === undefined || y === undefined){ 
17303             return;
17304         }
17305         var  p = this.el.translatePoints(x, y);
17306         this.setPosition(p.left, p.top);
17307         return  this;
17308     },
17309
17310     
17311     onRender : function(ct, G){
17312         Roo.BoxComponent.superclass.onRender.call(this, ct, G);
17313         if(this.resizeEl){
17314             this.resizeEl = Roo.get(this.resizeEl);
17315         }
17316         if(this.positionEl){
17317             this.positionEl = Roo.get(this.positionEl);
17318         }
17319     },
17320
17321     
17322     afterRender : function(){
17323         Roo.BoxComponent.superclass.afterRender.call(this);
17324         this.boxReady = true;
17325         this.setSize(this.width, this.height);
17326         if(this.x || this.y){
17327             this.setPosition(this.x, this.y);
17328         }
17329         if(this.pageX || this.pageY){
17330             this.setPagePosition(this.pageX, this.pageY);
17331         }
17332     },
17333
17334     
17335
17336     syncSize : function(){
17337         delete  this.lastSize;
17338         this.setSize(this.el.getWidth(), this.el.getHeight());
17339         return  this;
17340     },
17341
17342     
17343
17344     onResize : function(H, I, J, K){
17345
17346     },
17347
17348     
17349
17350     onPosition : function(x, y){
17351
17352     },
17353
17354     
17355     adjustSize : function(w, h){
17356         if(this.autoWidth){
17357             w = 'auto';
17358         }
17359         if(this.autoHeight){
17360             h = 'auto';
17361         }
17362         return  {width : w, height: h};
17363     },
17364
17365     
17366     adjustPosition : function(x, y){
17367         return  {x : x, y: y};
17368     }
17369 });
17370
17371
17372
17373
17374
17375
17376 Roo.SplitBar = function(A, B, C, D, E){
17377     
17378     
17379
17380     this.el = Roo.get(A, true);
17381     this.el.dom.unselectable = "on";
17382     
17383
17384     this.resizingEl = Roo.get(B, true);
17385
17386     
17387
17388     this.orientation = C || Roo.SplitBar.HORIZONTAL;
17389     
17390     
17391
17392     this.minSize = 0;
17393     
17394     
17395
17396     this.maxSize = 2000;
17397     
17398     
17399
17400     this.animate = false;
17401     
17402     
17403
17404     this.useShim = false;
17405     
17406     
17407
17408     this.shim = null;
17409     
17410     if(!E){
17411         
17412
17413         this.proxy = Roo.SplitBar.createProxy(this.orientation);
17414     }else {
17415         this.proxy = Roo.get(E).dom;
17416     }
17417
17418     
17419
17420     this.dd = new  Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
17421     
17422     
17423
17424     this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
17425     
17426     
17427
17428     this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
17429     
17430     
17431
17432     this.dragSpecs = {};
17433     
17434     
17435
17436     this.adapter = new  Roo.SplitBar.BasicLayoutAdapter();
17437     this.adapter.init(this);
17438     
17439     if(this.orientation == Roo.SplitBar.HORIZONTAL){
17440         
17441
17442         this.placement = D || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
17443         this.el.addClass("x-splitbar-h");
17444     }else {
17445         
17446
17447         this.placement = D || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
17448         this.el.addClass("x-splitbar-v");
17449     }
17450
17451     
17452     this.addEvents({
17453         
17454
17455         "resize" : true,
17456         
17457
17458         "moved" : true,
17459         
17460
17461         "beforeresize" : true,
17462
17463         "beforeapply" : true
17464     });
17465
17466     Roo.util.Observable.call(this);
17467 };
17468
17469 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
17470     onStartProxyDrag : function(x, y){
17471         this.fireEvent("beforeresize", this);
17472         if(!this.overlay){
17473             var  o = Roo.DomHelper.insertFirst(document.body,  {cls: "x-drag-overlay", html: "&#160;"}, true);
17474             o.unselectable();
17475             o.enableDisplayMode("block");
17476             
17477             Roo.SplitBar.prototype.overlay = o;
17478         }
17479
17480         this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
17481         this.overlay.show();
17482         Roo.get(this.proxy).setDisplayed("block");
17483         var  F = this.adapter.getElementSize(this);
17484         this.activeMinSize = this.getMinimumSize();;
17485         this.activeMaxSize = this.getMaximumSize();;
17486         var  c1 = F - this.activeMinSize;
17487         var  c2 = Math.max(this.activeMaxSize - F, 0);
17488         if(this.orientation == Roo.SplitBar.HORIZONTAL){
17489             this.dd.resetConstraints();
17490             this.dd.setXConstraint(
17491                 this.placement == Roo.SplitBar.LEFT ? c1 : c2, 
17492                 this.placement == Roo.SplitBar.LEFT ? c2 : c1
17493             );
17494             this.dd.setYConstraint(0, 0);
17495         }else {
17496             this.dd.resetConstraints();
17497             this.dd.setXConstraint(0, 0);
17498             this.dd.setYConstraint(
17499                 this.placement == Roo.SplitBar.TOP ? c1 : c2, 
17500                 this.placement == Roo.SplitBar.TOP ? c2 : c1
17501             );
17502          }
17503
17504         this.dragSpecs.startSize = F;
17505         this.dragSpecs.startPoint = [x, y];
17506         Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
17507     },
17508     
17509     
17510
17511     onEndProxyDrag : function(e){
17512         Roo.get(this.proxy).setDisplayed(false);
17513         var  G = Roo.lib.Event.getXY(e);
17514         if(this.overlay){
17515             this.overlay.hide();
17516         }
17517         var  H;
17518         if(this.orientation == Roo.SplitBar.HORIZONTAL){
17519             H = this.dragSpecs.startSize + 
17520                 (this.placement == Roo.SplitBar.LEFT ?
17521                     G[0] - this.dragSpecs.startPoint[0] :
17522                     this.dragSpecs.startPoint[0] - G[0]
17523                 );
17524         }else {
17525             H = this.dragSpecs.startSize + 
17526                 (this.placement == Roo.SplitBar.TOP ?
17527                     G[1] - this.dragSpecs.startPoint[1] :
17528                     this.dragSpecs.startPoint[1] - G[1]
17529                 );
17530         }
17531
17532         H = Math.min(Math.max(H, this.activeMinSize), this.activeMaxSize);
17533         if(H != this.dragSpecs.startSize){
17534             if(this.fireEvent('beforeapply', this, H) !== false){
17535                 this.adapter.setElementSize(this, H);
17536                 this.fireEvent("moved", this, H);
17537                 this.fireEvent("resize", this, H);
17538             }
17539         }
17540     },
17541     
17542     
17543
17544     getAdapter : function(){
17545         return  this.adapter;
17546     },
17547     
17548     
17549
17550     setAdapter : function(I){
17551         this.adapter = I;
17552         this.adapter.init(this);
17553     },
17554     
17555     
17556
17557     getMinimumSize : function(){
17558         return  this.minSize;
17559     },
17560     
17561     
17562
17563     setMinimumSize : function(J){
17564         this.minSize = J;
17565     },
17566     
17567     
17568
17569     getMaximumSize : function(){
17570         return  this.maxSize;
17571     },
17572     
17573     
17574
17575     setMaximumSize : function(K){
17576         this.maxSize = K;
17577     },
17578     
17579     
17580
17581     setCurrentSize : function(L){
17582         var  M = this.animate;
17583         this.animate = false;
17584         this.adapter.setElementSize(this, L);
17585         this.animate = M;
17586     },
17587     
17588     
17589
17590     destroy : function(N){
17591         if(this.shim){
17592             this.shim.remove();
17593         }
17594
17595         this.dd.unreg();
17596         this.proxy.parentNode.removeChild(this.proxy);
17597         if(N){
17598             this.el.remove();
17599         }
17600     }
17601 });
17602
17603
17604
17605 Roo.SplitBar.createProxy = function(O){
17606     var  P = new  Roo.Element(document.createElement("div"));
17607     P.unselectable();
17608     var  Q = 'x-splitbar-proxy';
17609     P.addClass(Q + ' ' + (O == Roo.SplitBar.HORIZONTAL ? Q +'-h' : Q + '-v'));
17610     document.body.appendChild(P.dom);
17611     return  P.dom;
17612 };
17613
17614
17615
17616 Roo.SplitBar.BasicLayoutAdapter = function(){
17617 };
17618
17619 Roo.SplitBar.BasicLayoutAdapter.prototype = {
17620     
17621     init : function(s){
17622     
17623     },
17624     
17625
17626      getElementSize : function(s){
17627         if(s.orientation == Roo.SplitBar.HORIZONTAL){
17628             return  s.resizingEl.getWidth();
17629         }else {
17630             return  s.resizingEl.getHeight();
17631         }
17632     },
17633     
17634     
17635
17636     setElementSize : function(s, R, S){
17637         if(s.orientation == Roo.SplitBar.HORIZONTAL){
17638             if(!s.animate){
17639                 s.resizingEl.setWidth(R);
17640                 if(S){
17641                     S(s, R);
17642                 }
17643             }else {
17644                 s.resizingEl.setWidth(R, true, .1, S, 'easeOut');
17645             }
17646         }else {
17647             
17648             if(!s.animate){
17649                 s.resizingEl.setHeight(R);
17650                 if(S){
17651                     S(s, R);
17652                 }
17653             }else {
17654                 s.resizingEl.setHeight(R, true, .1, S, 'easeOut');
17655             }
17656         }
17657     }
17658 };
17659
17660
17661
17662 Roo.SplitBar.AbsoluteLayoutAdapter = function(T){
17663     this.basic = new  Roo.SplitBar.BasicLayoutAdapter();
17664     this.container = Roo.get(T);
17665 };
17666
17667 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
17668     init : function(s){
17669         this.basic.init(s);
17670     },
17671     
17672     getElementSize : function(s){
17673         return  this.basic.getElementSize(s);
17674     },
17675     
17676     setElementSize : function(s, U, V){
17677         this.basic.setElementSize(s, U, this.moveSplitter.createDelegate(this, [s]));
17678     },
17679     
17680     moveSplitter : function(s){
17681         var  W = Roo.SplitBar;
17682         switch(s.placement){
17683             case  W.LEFT:
17684                 s.el.setX(s.resizingEl.getRight());
17685                 break;
17686             case  W.RIGHT:
17687                 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
17688                 break;
17689             case  W.TOP:
17690                 s.el.setY(s.resizingEl.getBottom());
17691                 break;
17692             case  W.BOTTOM:
17693                 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
17694                 break;
17695         }
17696     }
17697 };
17698
17699
17700
17701 Roo.SplitBar.VERTICAL = 1;
17702
17703
17704
17705 Roo.SplitBar.HORIZONTAL = 2;
17706
17707
17708
17709 Roo.SplitBar.LEFT = 1;
17710
17711
17712
17713 Roo.SplitBar.RIGHT = 2;
17714
17715
17716
17717 Roo.SplitBar.TOP = 3;
17718
17719
17720
17721 Roo.SplitBar.BOTTOM = 4;
17722
17723
17724
17725
17726
17727
17728 Roo.View = function(A, B, C){
17729     
17730     if (typeof(B) == 'undefined') {
17731         
17732         Roo.apply(this, A);
17733         this.el  = Roo.get(this.el);
17734     } else  {
17735         
17736         this.el  = Roo.get(A);
17737         this.tpl = B;
17738         Roo.apply(this, C);
17739     }
17740      
17741     
17742     if(typeof(this.tpl) == "string"){
17743         this.tpl = new  Roo.Template(this.tpl);
17744     } else  {
17745         
17746         this.tpl = new  Roo.factory(this.tpl, Roo);
17747     }
17748
17749     
17750     
17751     this.tpl.compile();
17752    
17753
17754      
17755     
17756
17757     this.addEvents({
17758     
17759
17760         "beforeclick" : true,
17761     
17762
17763         "click" : true,
17764     
17765
17766         "dblclick" : true,
17767     
17768
17769         "contextmenu" : true,
17770     
17771
17772         "selectionchange" : true,
17773
17774     
17775
17776         "beforeselect" : true
17777     });
17778
17779     this.el.on({
17780         "click": this.onClick,
17781         "dblclick": this.onDblClick,
17782         "contextmenu": this.onContextMenu,
17783         scope:this
17784     });
17785
17786     this.selections = [];
17787     this.nodes = [];
17788     this.cmp = new  Roo.CompositeElementLite([]);
17789     if(this.store){
17790         this.store = Roo.factory(this.store, Roo.data);
17791         this.setStore(this.store, true);
17792     }
17793
17794     Roo.View.superclass.constructor.call(this);
17795 };
17796
17797 Roo.extend(Roo.View, Roo.util.Observable, {
17798     
17799      
17800
17801     store : false,
17802     
17803     
17804
17805     el : '',
17806     
17807     
17808
17809     tpl : false,
17810     
17811     
17812
17813     selectedClass : "x-view-selected",
17814      
17815
17816     emptyText : "",
17817     
17818
17819     getEl : function(){
17820         return  this.el;
17821     },
17822
17823     
17824
17825     refresh : function(){
17826         var  t = this.tpl;
17827         this.clearSelections();
17828         this.el.update("");
17829         var  D = [];
17830         var  E = this.store.getRange();
17831         if(E.length < 1){
17832             this.el.update(this.emptyText);
17833             return;
17834         }
17835         for(var  i = 0, len = E.length; i < len; i++){
17836             var  data = this.prepareData(E[i].data, i, E[i]);
17837             D[D.length] = t.apply(data);
17838         }
17839
17840         this.el.update(D.join(""));
17841         this.nodes = this.el.dom.childNodes;
17842         this.updateIndexes(0);
17843     },
17844
17845     
17846
17847     prepareData : function(F){
17848         return  F;
17849     },
17850
17851     onUpdate : function(ds, G){
17852         this.clearSelections();
17853         var  H = this.store.indexOf(G);
17854         var  n = this.nodes[H];
17855         this.tpl.insertBefore(n, this.prepareData(G.data));
17856         n.parentNode.removeChild(n);
17857         this.updateIndexes(H, H);
17858     },
17859
17860     onAdd : function(ds, I, J){
17861         this.clearSelections();
17862         if(this.nodes.length == 0){
17863             this.refresh();
17864             return;
17865         }
17866         var  n = this.nodes[J];
17867         for(var  i = 0, len = I.length; i < len; i++){
17868             var  d = this.prepareData(I[i].data);
17869             if(n){
17870                 this.tpl.insertBefore(n, d);
17871             }else {
17872                 this.tpl.append(this.el, d);
17873             }
17874         }
17875
17876         this.updateIndexes(J);
17877     },
17878
17879     onRemove : function(ds, K, L){
17880         this.clearSelections();
17881         this.el.dom.removeChild(this.nodes[L]);
17882         this.updateIndexes(L);
17883     },
17884
17885     
17886
17887     refreshNode : function(M){
17888         this.onUpdate(this.store, this.store.getAt(M));
17889     },
17890
17891     updateIndexes : function(N, O){
17892         var  ns = this.nodes;
17893         N = N || 0;
17894         O = O || ns.length - 1;
17895         for(var  i = N; i <= O; i++){
17896             ns[i].nodeIndex = i;
17897         }
17898     },
17899
17900     
17901
17902     setStore : function(P, Q){
17903         if(!Q && this.store){
17904             this.store.un("datachanged", this.refresh);
17905             this.store.un("add", this.onAdd);
17906             this.store.un("remove", this.onRemove);
17907             this.store.un("update", this.onUpdate);
17908             this.store.un("clear", this.refresh);
17909         }
17910         if(P){
17911           
17912             P.on("datachanged", this.refresh, this);
17913             P.on("add", this.onAdd, this);
17914             P.on("remove", this.onRemove, this);
17915             P.on("update", this.onUpdate, this);
17916             P.on("clear", this.refresh, this);
17917         }
17918         
17919         if(P){
17920             this.refresh();
17921         }
17922     },
17923
17924     
17925
17926     findItemFromChild : function(R){
17927         var  el = this.el.dom;
17928         if(!R || R.parentNode == el){
17929                     return  R;
17930             }
17931             var  p = R.parentNode;
17932             while(p && p != el){
17933             if(p.parentNode == el){
17934                 return  p;
17935             }
17936
17937             p = p.parentNode;
17938         }
17939             return  null;
17940     },
17941
17942     
17943
17944     onClick : function(e){
17945         var  S = this.findItemFromChild(e.getTarget());
17946         if(S){
17947             var  M = this.indexOf(S);
17948             if(this.onItemClick(S, M, e) !== false){
17949                 this.fireEvent("click", this, M, S, e);
17950             }
17951         }else {
17952             this.clearSelections();
17953         }
17954     },
17955
17956     
17957
17958     onContextMenu : function(e){
17959         var  T = this.findItemFromChild(e.getTarget());
17960         if(T){
17961             this.fireEvent("contextmenu", this, this.indexOf(T), T, e);
17962         }
17963     },
17964
17965     
17966
17967     onDblClick : function(e){
17968         var  U = this.findItemFromChild(e.getTarget());
17969         if(U){
17970             this.fireEvent("dblclick", this, this.indexOf(U), U, e);
17971         }
17972     },
17973
17974     onItemClick : function(V, W, e){
17975         if(this.fireEvent("beforeclick", this, W, V, e) === false){
17976             return  false;
17977         }
17978         if(this.multiSelect || this.singleSelect){
17979             if(this.multiSelect && e.shiftKey && this.lastSelection){
17980                 this.select(this.getNodes(this.indexOf(this.lastSelection), W), false);
17981             }else {
17982                 this.select(V, this.multiSelect && e.ctrlKey);
17983                 this.lastSelection = V;
17984             }
17985
17986             e.preventDefault();
17987         }
17988         return  true;
17989     },
17990
17991     
17992
17993     getSelectionCount : function(){
17994         return  this.selections.length;
17995     },
17996
17997     
17998
17999     getSelectedNodes : function(){
18000         return  this.selections;
18001     },
18002
18003     
18004
18005     getSelectedIndexes : function(){
18006         var  X = [], s = this.selections;
18007         for(var  i = 0, len = s.length; i < len; i++){
18008             X.push(s[i].nodeIndex);
18009         }
18010         return  X;
18011     },
18012
18013     
18014
18015     clearSelections : function(Y){
18016         if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
18017             this.cmp.elements = this.selections;
18018             this.cmp.removeClass(this.selectedClass);
18019             this.selections = [];
18020             if(!Y){
18021                 this.fireEvent("selectionchange", this, this.selections);
18022             }
18023         }
18024     },
18025
18026     
18027
18028     isSelected : function(Z){
18029         var  s = this.selections;
18030         if(s.length < 1){
18031             return  false;
18032         }
18033
18034         Z = this.getNode(Z);
18035         return  s.indexOf(Z) !== -1;
18036     },
18037
18038     
18039
18040     select : function(a, b, c){
18041         if(a  instanceof  Array){
18042             if(!b){
18043                 this.clearSelections(true);
18044             }
18045             for(var  i = 0, len = a.length; i < len; i++){
18046                 this.select(a[i], true, true);
18047             }
18048         } else {
18049             var  Z = this.getNode(a);
18050             if(Z && !this.isSelected(Z)){
18051                 if(!b){
18052                     this.clearSelections(true);
18053                 }
18054                 if(this.fireEvent("beforeselect", this, Z, this.selections) !== false){
18055                     Roo.fly(Z).addClass(this.selectedClass);
18056                     this.selections.push(Z);
18057                     if(!c){
18058                         this.fireEvent("selectionchange", this, this.selections);
18059                     }
18060                 }
18061             }
18062         }
18063     },
18064
18065     
18066
18067     getNode : function(f){
18068         if(typeof  f == "string"){
18069             return  document.getElementById(f);
18070         }else  if(typeof  f == "number"){
18071             return  this.nodes[f];
18072         }
18073         return  f;
18074     },
18075
18076     
18077
18078     getNodes : function(g, h){
18079         var  ns = this.nodes;
18080         g = g || 0;
18081         h = typeof  h == "undefined" ? ns.length - 1 : h;
18082         var  j = [];
18083         if(g <= h){
18084             for(var  i = g; i <= h; i++){
18085                 j.push(ns[i]);
18086             }
18087         } else {
18088             for(var  i = g; i >= h; i--){
18089                 j.push(ns[i]);
18090             }
18091         }
18092         return  j;
18093     },
18094
18095     
18096
18097     indexOf : function(k){
18098         k = this.getNode(k);
18099         if(typeof  k.nodeIndex == "number"){
18100             return  k.nodeIndex;
18101         }
18102         var  ns = this.nodes;
18103         for(var  i = 0, len = ns.length; i < len; i++){
18104             if(ns[i] == k){
18105                 return  i;
18106             }
18107         }
18108         return  -1;
18109     }
18110 });
18111
18112
18113
18114
18115
18116
18117 Roo.JsonView = function(A, B, C){
18118     
18119     
18120     Roo.JsonView.superclass.constructor.call(this, A, B, C);
18121
18122     var  um = this.el.getUpdateManager();
18123     um.setRenderer(this);
18124     um.on("update", this.onLoad, this);
18125     um.on("failure", this.onLoadException, this);
18126
18127     
18128
18129     
18130
18131     
18132
18133     this.addEvents({
18134         'beforerender' : true,
18135         'load' : true,
18136         'loadexception' : true
18137     });
18138 };
18139 Roo.extend(Roo.JsonView, Roo.View, {
18140     
18141
18142     jsonRoot : "",
18143
18144     
18145
18146     refresh : function(){
18147         this.clearSelections();
18148         this.el.update("");
18149         var  D = [];
18150         var  o = this.jsonData;
18151         if(o && o.length > 0){
18152             for(var  i = 0, len = o.length; i < len; i++){
18153                 var  data = this.prepareData(o[i], i, o);
18154                 D[D.length] = this.tpl.apply(data);
18155             }
18156         }else {
18157             D.push(this.emptyText);
18158         }
18159
18160         this.el.update(D.join(""));
18161         this.nodes = this.el.dom.childNodes;
18162         this.updateIndexes(0);
18163     },
18164
18165     
18166
18167     load : function(){
18168         var  um = this.el.getUpdateManager();
18169         um.update.apply(um, arguments);
18170     },
18171
18172     render : function(el, E){
18173         this.clearSelections();
18174         this.el.update("");
18175         var  o;
18176         try{
18177             o = Roo.util.JSON.decode(E.responseText);
18178             if(this.jsonRoot){
18179                 
18180                 o = 
18181  eval("o." + this.jsonRoot);
18182             }
18183         } catch(e){
18184         }
18185
18186         
18187
18188         this.jsonData = o;
18189         this.beforeRender();
18190         this.refresh();
18191     },
18192
18193
18194
18195     getCount : function(){
18196         return  this.jsonData ? this.jsonData.length : 0;
18197     },
18198
18199
18200
18201     getNodeData : function(F){
18202         if(F  instanceof  Array){
18203             var  data = [];
18204             for(var  i = 0, len = F.length; i < len; i++){
18205                 data.push(this.getNodeData(F[i]));
18206             }
18207             return  data;
18208         }
18209         return  this.jsonData[this.indexOf(F)] || null;
18210     },
18211
18212     beforeRender : function(){
18213         this.snapshot = this.jsonData;
18214         if(this.sortInfo){
18215             this.sort.apply(this, this.sortInfo);
18216         }
18217
18218         this.fireEvent("beforerender", this, this.jsonData);
18219     },
18220
18221     onLoad : function(el, o){
18222         this.fireEvent("load", this, this.jsonData, o);
18223     },
18224
18225     onLoadException : function(el, o){
18226         this.fireEvent("loadexception", this, o);
18227     },
18228
18229
18230
18231     filter : function(G, H){
18232         if(this.jsonData){
18233             var  data = [];
18234             var  ss = this.snapshot;
18235             if(typeof  H == "string"){
18236                 var  vlen = H.length;
18237                 if(vlen == 0){
18238                     this.clearFilter();
18239                     return;
18240                 }
18241
18242                 H = H.toLowerCase();
18243                 for(var  i = 0, len = ss.length; i < len; i++){
18244                     var  o = ss[i];
18245                     if(o[G].substr(0, vlen).toLowerCase() == H){
18246                         data.push(o);
18247                     }
18248                 }
18249             } else  if(H.exec){ 
18250                 for(var  i = 0, len = ss.length; i < len; i++){
18251                     var  o = ss[i];
18252                     if(H.test(o[G])){
18253                         data.push(o);
18254                     }
18255                 }
18256             } else {
18257                 return;
18258             }
18259
18260             this.jsonData = data;
18261             this.refresh();
18262         }
18263     },
18264
18265
18266
18267     filterBy : function(fn, I){
18268         if(this.jsonData){
18269             var  data = [];
18270             var  ss = this.snapshot;
18271             for(var  i = 0, len = ss.length; i < len; i++){
18272                 var  o = ss[i];
18273                 if(fn.call(I || this, o)){
18274                     data.push(o);
18275                 }
18276             }
18277
18278             this.jsonData = data;
18279             this.refresh();
18280         }
18281     },
18282
18283
18284
18285     clearFilter : function(){
18286         if(this.snapshot && this.jsonData != this.snapshot){
18287             this.jsonData = this.snapshot;
18288             this.refresh();
18289         }
18290     },
18291
18292
18293
18294
18295     sort : function(J, K, L){
18296         this.sortInfo = Array.prototype.slice.call(arguments, 0);
18297         if(this.jsonData){
18298             var  p = J;
18299             var  dsc = K && K.toLowerCase() == "desc";
18300             var  f = function(o1, o2){
18301                 var  v1 = L ? L(o1[p]) : o1[p];
18302                 var  v2 = L ? L(o2[p]) : o2[p];
18303                 ;
18304                 if(v1 < v2){
18305                     return  dsc ? +1 : -1;
18306                 } else  if(v1 > v2){
18307                     return  dsc ? -1 : +1;
18308                 } else {
18309                     return  0;
18310                 }
18311             };
18312             this.jsonData.sort(f);
18313             this.refresh();
18314             if(this.jsonData != this.snapshot){
18315                 this.snapshot.sort(f);
18316             }
18317         }
18318     }
18319 });
18320
18321
18322  
18323
18324
18325
18326 Roo.ColorPalette = function(A){
18327     Roo.ColorPalette.superclass.constructor.call(this, A);
18328     this.addEvents({
18329         
18330
18331         select: true
18332     });
18333
18334     if(this.handler){
18335         this.on("select", this.handler, this.scope, true);
18336     }
18337 };
18338 Roo.extend(Roo.ColorPalette, Roo.Component, {
18339     
18340
18341     itemCls : "x-color-palette",
18342     
18343
18344     value : null,
18345     clickEvent:'click',
18346     
18347     ctype: "Roo.ColorPalette",
18348
18349     
18350
18351     allowReselect : false,
18352
18353     
18354
18355     colors : [
18356         "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
18357         "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
18358         "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
18359         "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
18360         "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
18361     ],
18362
18363     
18364     onRender : function(B, C){
18365         var  t = new  Roo.MasterTemplate(
18366             '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on">&#160;</span></em></a></tpl>'
18367         );
18368         var  c = this.colors;
18369         for(var  i = 0, len = c.length; i < len; i++){
18370             t.add([c[i]]);
18371         }
18372         var  el = document.createElement("div");
18373         el.className = this.itemCls;
18374         t.overwrite(el);
18375         B.dom.insertBefore(el, C);
18376         this.el = Roo.get(el);
18377         this.el.on(this.clickEvent, this.handleClick,  this, {delegate: "a"});
18378         if(this.clickEvent != 'click'){
18379             this.el.on('click', Roo.emptyFn,  this, {delegate: "a", preventDefault:true});
18380         }
18381     },
18382
18383     
18384     afterRender : function(){
18385         Roo.ColorPalette.superclass.afterRender.call(this);
18386         if(this.value){
18387             var  s = this.value;
18388             this.value = null;
18389             this.select(s);
18390         }
18391     },
18392
18393     
18394     handleClick : function(e, t){
18395         e.preventDefault();
18396         if(!this.disabled){
18397             var  c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
18398             this.select(c.toUpperCase());
18399         }
18400     },
18401
18402     
18403
18404     select : function(D){
18405         D = D.replace("#", "");
18406         if(D != this.value || this.allowReselect){
18407             var  el = this.el;
18408             if(this.value){
18409                 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
18410             }
18411
18412             el.child("a.color-"+D).addClass("x-color-palette-sel");
18413             this.value = D;
18414             this.fireEvent("select", this, D);
18415         }
18416     }
18417 });
18418
18419
18420  
18421
18422
18423 Roo.DatePicker = function(A){
18424     Roo.DatePicker.superclass.constructor.call(this, A);
18425
18426     this.value = A && A.value ?
18427                  A.value.clearTime() : new  Date().clearTime();
18428
18429     this.addEvents({
18430         
18431
18432         select: true
18433     });
18434
18435     if(this.handler){
18436         this.on("select", this.handler,  this.scope || this);
18437     }
18438     
18439     if(!this.disabledDatesRE && this.disabledDates){
18440         var  dd = this.disabledDates;
18441         var  re = "(?:";
18442         for(var  i = 0; i < dd.length; i++){
18443             re += dd[i];
18444             if(i != dd.length-1) re += "|";
18445         }
18446
18447         this.disabledDatesRE = new  RegExp(re + ")");
18448     }
18449 };
18450
18451 Roo.extend(Roo.DatePicker, Roo.Component, {
18452     
18453
18454     todayText : "Today",
18455     
18456
18457     okText : "&#160;OK&#160;", 
18458     
18459
18460     cancelText : "Cancel",
18461     
18462
18463     todayTip : "{0} (Spacebar)",
18464     
18465
18466     minDate : null,
18467     
18468
18469     maxDate : null,
18470     
18471
18472     minText : "This date is before the minimum date",
18473     
18474
18475     maxText : "This date is after the maximum date",
18476     
18477
18478     format : "m/d/y",
18479     
18480
18481     disabledDays : null,
18482     
18483
18484     disabledDaysText : "",
18485     
18486
18487     disabledDatesRE : null,
18488     
18489
18490     disabledDatesText : "",
18491     
18492
18493     constrainToViewport : true,
18494     
18495
18496     monthNames : Date.monthNames,
18497     
18498
18499     dayNames : Date.dayNames,
18500     
18501
18502     nextText: 'Next Month (Control+Right)',
18503     
18504
18505     prevText: 'Previous Month (Control+Left)',
18506     
18507
18508     monthYearText: 'Choose a month (Control+Up/Down to move years)',
18509     
18510
18511     startDay : 0,
18512     
18513
18514     
18515     showClear: false,
18516     
18517     
18518
18519     setValue : function(B){
18520         var  C = this.value;
18521         this.value = B.clearTime(true);
18522         if(this.el){
18523             this.update(this.value);
18524         }
18525     },
18526
18527     
18528
18529     getValue : function(){
18530         return  this.value;
18531     },
18532
18533     
18534     focus : function(){
18535         if(this.el){
18536             this.update(this.activeDate);
18537         }
18538     },
18539
18540     
18541     onRender : function(D, E){
18542         var  m = [
18543              '<table cellspacing="0">',
18544                 '<tr><td class="x-date-left"><a href="#" title="', this.prevText ,'">&#160;</a></td><td class="x-date-middle" align="center"></td><td class="x-date-right"><a href="#" title="', this.nextText ,'">&#160;</a></td></tr>',
18545                 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
18546         var  dn = this.dayNames;
18547         for(var  i = 0; i < 7; i++){
18548             var  d = this.startDay+i;
18549             if(d > 6){
18550                 d = d-7;
18551             }
18552
18553             m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
18554         }
18555
18556         m[m.length] = "</tr></thead><tbody><tr>";
18557         for(var  i = 0; i < 42; i++) {
18558             if(i % 7 == 0 && i != 0){
18559                 m[m.length] = "</tr><tr>";
18560             }
18561
18562             m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
18563         }
18564
18565         m[m.length] = '</tr></tbody></table></td></tr><tr>'+
18566             '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
18567
18568         var  el = document.createElement("div");
18569         el.className = "x-date-picker";
18570         el.innerHTML = m.join("");
18571
18572         D.dom.insertBefore(el, E);
18573
18574         this.el = Roo.get(el);
18575         this.eventEl = Roo.get(el.firstChild);
18576
18577         new  Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
18578             handler: this.showPrevMonth,
18579             scope: this,
18580             preventDefault:true,
18581             stopDefault:true
18582         });
18583
18584         new  Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
18585             handler: this.showNextMonth,
18586             scope: this,
18587             preventDefault:true,
18588             stopDefault:true
18589         });
18590
18591         this.eventEl.on("mousewheel", this.handleMouseWheel,  this);
18592
18593         this.monthPicker = this.el.down('div.x-date-mp');
18594         this.monthPicker.enableDisplayMode('block');
18595         
18596         var  kn = new  Roo.KeyNav(this.eventEl, {
18597             "left" : function(e){
18598                 e.ctrlKey ?
18599                     this.showPrevMonth() :
18600                     this.update(this.activeDate.add("d", -1));
18601             },
18602
18603             "right" : function(e){
18604                 e.ctrlKey ?
18605                     this.showNextMonth() :
18606                     this.update(this.activeDate.add("d", 1));
18607             },
18608
18609             "up" : function(e){
18610                 e.ctrlKey ?
18611                     this.showNextYear() :
18612                     this.update(this.activeDate.add("d", -7));
18613             },
18614
18615             "down" : function(e){
18616                 e.ctrlKey ?
18617                     this.showPrevYear() :
18618                     this.update(this.activeDate.add("d", 7));
18619             },
18620
18621             "pageUp" : function(e){
18622                 this.showNextMonth();
18623             },
18624
18625             "pageDown" : function(e){
18626                 this.showPrevMonth();
18627             },
18628
18629             "enter" : function(e){
18630                 e.stopPropagation();
18631                 return  true;
18632             },
18633
18634             scope : this
18635         });
18636
18637         this.eventEl.on("click", this.handleDateClick,  this, {delegate: "a.x-date-date"});
18638
18639         this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday,  this);
18640
18641         this.el.unselectable();
18642         
18643         this.cells = this.el.select("table.x-date-inner tbody td");
18644         this.textNodes = this.el.query("table.x-date-inner tbody span");
18645
18646         this.mbtn = new  Roo.Button(this.el.child("td.x-date-middle", true), {
18647             text: "&#160;",
18648             tooltip: this.monthYearText
18649         });
18650
18651         this.mbtn.on('click', this.showMonthPicker, this);
18652         this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
18653
18654
18655         var  F = (new  Date()).dateFormat(this.format);
18656         
18657         var  G = new  Roo.Toolbar(this.el.child("td.x-date-bottom", true));
18658         G.add({
18659             text: String.format(this.todayText, F),
18660             tooltip: String.format(this.todayTip, F),
18661             handler: this.selectToday,
18662             scope: this
18663         });
18664         
18665         
18666             
18667         
18668         if (this.showClear) {
18669             
18670             G.add( new  Roo.Toolbar.Fill());
18671             G.add({
18672                 text: '&#160;',
18673                 cls: 'x-btn-icon x-btn-clear',
18674                 handler: function() {
18675                     
18676                     this.fireEvent("select", this, '');
18677                 },
18678                 scope: this
18679             });
18680         }
18681         
18682         
18683         if(Roo.isIE){
18684             this.el.repaint();
18685         }
18686
18687         this.update(this.value);
18688     },
18689
18690     createMonthPicker : function(){
18691         if(!this.monthPicker.dom.firstChild){
18692             var  buf = ['<table border="0" cellspacing="0">'];
18693             for(var  i = 0; i < 6; i++){
18694                 buf.push(
18695                     '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
18696                     '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
18697                     i == 0 ?
18698                     '<td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-prev"></a></td><td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-next"></a></td></tr>' :
18699                     '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
18700                 );
18701             }
18702
18703             buf.push(
18704                 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
18705                     this.okText,
18706                     '</button><button type="button" class="x-date-mp-cancel">',
18707                     this.cancelText,
18708                     '</button></td></tr>',
18709                 '</table>'
18710             );
18711             this.monthPicker.update(buf.join(''));
18712             this.monthPicker.on('click', this.onMonthClick, this);
18713             this.monthPicker.on('dblclick', this.onMonthDblClick, this);
18714
18715             this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
18716             this.mpYears = this.monthPicker.select('td.x-date-mp-year');
18717
18718             this.mpMonths.each(function(m, a, i){
18719                 i += 1;
18720                 if((i%2) == 0){
18721                     m.dom.xmonth = 5 + Math.round(i * .5);
18722                 }else {
18723                     m.dom.xmonth = Math.round((i-1) * .5);
18724                 }
18725             });
18726         }
18727     },
18728
18729     showMonthPicker : function(){
18730         this.createMonthPicker();
18731         var  H = this.el.getSize();
18732         this.monthPicker.setSize(H);
18733         this.monthPicker.child('table').setSize(H);
18734
18735         this.mpSelMonth = (this.activeDate || this.value).getMonth();
18736         this.updateMPMonth(this.mpSelMonth);
18737         this.mpSelYear = (this.activeDate || this.value).getFullYear();
18738         this.updateMPYear(this.mpSelYear);
18739
18740         this.monthPicker.slideIn('t', {duration:.2});
18741     },
18742
18743     updateMPYear : function(y){
18744         this.mpyear = y;
18745         var  ys = this.mpYears.elements;
18746         for(var  i = 1; i <= 10; i++){
18747             var  td = ys[i-1], y2;
18748             if((i%2) == 0){
18749                 y2 = y + Math.round(i * .5);
18750                 td.firstChild.innerHTML = y2;
18751                 td.xyear = y2;
18752             }else {
18753                 y2 = y - (5-Math.round(i * .5));
18754                 td.firstChild.innerHTML = y2;
18755                 td.xyear = y2;
18756             }
18757
18758             this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
18759         }
18760     },
18761
18762     updateMPMonth : function(sm){
18763         this.mpMonths.each(function(m, a, i){
18764             m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
18765         });
18766     },
18767
18768     selectMPMonth: function(m){
18769         
18770     },
18771
18772     onMonthClick : function(e, t){
18773         e.stopEvent();
18774         var  el = new  Roo.Element(t), pn;
18775         if(el.is('button.x-date-mp-cancel')){
18776             this.hideMonthPicker();
18777         }
18778         else  if(el.is('button.x-date-mp-ok')){
18779             this.update(new  Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
18780             this.hideMonthPicker();
18781         }
18782         else  if(pn = el.up('td.x-date-mp-month', 2)){
18783             this.mpMonths.removeClass('x-date-mp-sel');
18784             pn.addClass('x-date-mp-sel');
18785             this.mpSelMonth = pn.dom.xmonth;
18786         }
18787         else  if(pn = el.up('td.x-date-mp-year', 2)){
18788             this.mpYears.removeClass('x-date-mp-sel');
18789             pn.addClass('x-date-mp-sel');
18790             this.mpSelYear = pn.dom.xyear;
18791         }
18792         else  if(el.is('a.x-date-mp-prev')){
18793             this.updateMPYear(this.mpyear-10);
18794         }
18795         else  if(el.is('a.x-date-mp-next')){
18796             this.updateMPYear(this.mpyear+10);
18797         }
18798     },
18799
18800     onMonthDblClick : function(e, t){
18801         e.stopEvent();
18802         var  el = new  Roo.Element(t), pn;
18803         if(pn = el.up('td.x-date-mp-month', 2)){
18804             this.update(new  Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
18805             this.hideMonthPicker();
18806         }
18807         else  if(pn = el.up('td.x-date-mp-year', 2)){
18808             this.update(new  Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
18809             this.hideMonthPicker();
18810         }
18811     },
18812
18813     hideMonthPicker : function(I){
18814         if(this.monthPicker){
18815             if(I === true){
18816                 this.monthPicker.hide();
18817             }else {
18818                 this.monthPicker.slideOut('t', {duration:.2});
18819             }
18820         }
18821     },
18822
18823     
18824     showPrevMonth : function(e){
18825         this.update(this.activeDate.add("mo", -1));
18826     },
18827
18828     
18829     showNextMonth : function(e){
18830         this.update(this.activeDate.add("mo", 1));
18831     },
18832
18833     
18834     showPrevYear : function(){
18835         this.update(this.activeDate.add("y", -1));
18836     },
18837
18838     
18839     showNextYear : function(){
18840         this.update(this.activeDate.add("y", 1));
18841     },
18842
18843     
18844     handleMouseWheel : function(e){
18845         var  J = e.getWheelDelta();
18846         if(J > 0){
18847             this.showPrevMonth();
18848             e.stopEvent();
18849         } else  if(J < 0){
18850             this.showNextMonth();
18851             e.stopEvent();
18852         }
18853     },
18854
18855     
18856     handleDateClick : function(e, t){
18857         e.stopEvent();
18858         if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
18859             this.setValue(new  Date(t.dateValue));
18860             this.fireEvent("select", this, this.value);
18861         }
18862     },
18863
18864     
18865     selectToday : function(){
18866         this.setValue(new  Date().clearTime());
18867         this.fireEvent("select", this, this.value);
18868     },
18869
18870     
18871     update : function(K){
18872         var  vd = this.activeDate;
18873         this.activeDate = K;
18874         if(vd && this.el){
18875             var  t = K.getTime();
18876             if(vd.getMonth() == K.getMonth() && vd.getFullYear() == K.getFullYear()){
18877                 this.cells.removeClass("x-date-selected");
18878                 this.cells.each(function(c){
18879                    if(c.dom.firstChild.dateValue == t){
18880                        c.addClass("x-date-selected");
18881                        setTimeout(function(){
18882                             try{c.dom.firstChild.focus();}catch(e){}
18883                        }, 50);
18884                        return  false;
18885                    }
18886                 });
18887                 return;
18888             }
18889         }
18890         var  L = K.getDaysInMonth();
18891         var  M = K.getFirstDateOfMonth();
18892         var  N = M.getDay()-this.startDay;
18893
18894         if(N <= this.startDay){
18895             N += 7;
18896         }
18897
18898         var  pm = K.add("mo", -1);
18899         var  O = pm.getDaysInMonth()-N;
18900
18901         var  P = this.cells.elements;
18902         var  Q = this.textNodes;
18903         L += N;
18904
18905         
18906         var  R = 86400000;
18907         var  d = (new  Date(pm.getFullYear(), pm.getMonth(), O)).clearTime();
18908         var  S = new  Date().clearTime().getTime();
18909         var  T = K.clearTime().getTime();
18910         var  U = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
18911         var  V = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
18912         var  W = this.disabledDatesRE;
18913         var  X = this.disabledDatesText;
18914         var  Y = this.disabledDays ? this.disabledDays.join("") : false;
18915         var  Z = this.disabledDaysText;
18916         var  a = this.format;
18917
18918         var  b = function(f, g){
18919             g.title = "";
18920             var  t = d.getTime();
18921             g.firstChild.dateValue = t;
18922             if(t == S){
18923                 g.className += " x-date-today";
18924                 g.title = f.todayText;
18925             }
18926             if(t == T){
18927                 g.className += " x-date-selected";
18928                 setTimeout(function(){
18929                     try{g.firstChild.focus();}catch(e){}
18930                 }, 50);
18931             }
18932             
18933             if(t < U) {
18934                 g.className = " x-date-disabled";
18935                 g.title = f.minText;
18936                 return;
18937             }
18938             if(t > V) {
18939                 g.className = " x-date-disabled";
18940                 g.title = f.maxText;
18941                 return;
18942             }
18943             if(Y){
18944                 if(Y.indexOf(d.getDay()) != -1){
18945                     g.title = Z;
18946                     g.className = " x-date-disabled";
18947                 }
18948             }
18949             if(W && a){
18950                 var  fvalue = d.dateFormat(a);
18951                 if(W.test(fvalue)){
18952                     g.title = X.replace("%0", fvalue);
18953                     g.className = " x-date-disabled";
18954                 }
18955             }
18956         };
18957
18958         var  i = 0;
18959         for(; i < N; i++) {
18960             Q[i].innerHTML = (++O);
18961             d.setDate(d.getDate()+1);
18962             P[i].className = "x-date-prevday";
18963             b(this, P[i]);
18964         }
18965         for(; i < L; i++){
18966             intDay = i - N + 1;
18967             Q[i].innerHTML = (intDay);
18968             d.setDate(d.getDate()+1);
18969             P[i].className = "x-date-active";
18970             b(this, P[i]);
18971         }
18972         var  c = 0;
18973         for(; i < 42; i++) {
18974              Q[i].innerHTML = (++c);
18975              d.setDate(d.getDate()+1);
18976              P[i].className = "x-date-nextday";
18977              b(this, P[i]);
18978         }
18979
18980
18981         this.mbtn.setText(this.monthNames[K.getMonth()] + " " + K.getFullYear());
18982
18983         if(!this.internalRender){
18984             var  main = this.el.dom.firstChild;
18985             var  w = main.offsetWidth;
18986             this.el.setWidth(w + this.el.getBorderWidth("lr"));
18987             Roo.fly(main).setWidth(w);
18988             this.internalRender = true;
18989             
18990             
18991             
18992             if(Roo.isOpera && !this.secondPass){
18993                 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
18994                 this.secondPass = true;
18995                 this.update.defer(10, this, [K]);
18996             }
18997         }
18998     }
18999 });
19000
19001
19002
19003
19004 Roo.TabPanel = function(A, B){
19005     
19006
19007     this.el = Roo.get(A, true);
19008     if(B){
19009         if(typeof  B == "boolean"){
19010             this.tabPosition = B ? "bottom" : "top";
19011         }else {
19012             Roo.apply(this, B);
19013         }
19014     }
19015     if(this.tabPosition == "bottom"){
19016         this.bodyEl = Roo.get(this.createBody(this.el.dom));
19017         this.el.addClass("x-tabs-bottom");
19018     }
19019
19020     this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
19021     this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
19022     this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
19023     if(Roo.isIE){
19024         Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
19025     }
19026     if(this.tabPosition != "bottom"){
19027     
19028
19029       this.bodyEl = Roo.get(this.createBody(this.el.dom));
19030       this.el.addClass("x-tabs-top");
19031     }
19032
19033     this.items = [];
19034
19035     this.bodyEl.setStyle("position", "relative");
19036
19037     this.active = null;
19038     this.activateDelegate = this.activate.createDelegate(this);
19039
19040     this.addEvents({
19041         
19042
19043         "tabchange": true,
19044         
19045
19046         "beforetabchange" : true
19047     });
19048
19049     Roo.EventManager.onWindowResize(this.onResize, this);
19050     this.cpad = this.el.getPadding("lr");
19051     this.hiddenCount = 0;
19052
19053     Roo.TabPanel.superclass.constructor.call(this);
19054 };
19055
19056 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
19057         
19058
19059     tabPosition : "top",
19060         
19061
19062     currentTabWidth : 0,
19063         
19064
19065     minTabWidth : 40,
19066         
19067
19068     maxTabWidth : 250,
19069         
19070
19071     preferredTabWidth : 175,
19072         
19073
19074     resizeTabs : false,
19075         
19076
19077     monitorResize : true,
19078
19079     
19080
19081     addTab : function(id, C, D, E){
19082         var  F = new  Roo.TabPanelItem(this, id, C, E);
19083         this.addTabItem(F);
19084         if(D){
19085             F.setContent(D);
19086         }
19087         return  F;
19088     },
19089
19090     
19091
19092     getTab : function(id){
19093         return  this.items[id];
19094     },
19095
19096     
19097
19098     hideTab : function(id){
19099         var  t = this.items[id];
19100         if(!t.isHidden()){
19101            t.setHidden(true);
19102            this.hiddenCount++;
19103            this.autoSizeTabs();
19104         }
19105     },
19106
19107     
19108
19109     unhideTab : function(id){
19110         var  t = this.items[id];
19111         if(t.isHidden()){
19112            t.setHidden(false);
19113            this.hiddenCount--;
19114            this.autoSizeTabs();
19115         }
19116     },
19117
19118     
19119
19120     addTabItem : function(G){
19121         this.items[G.id] = G;
19122         this.items.push(G);
19123         if(this.resizeTabs){
19124            G.setWidth(this.currentTabWidth || this.preferredTabWidth);
19125            this.autoSizeTabs();
19126         }else {
19127             G.autoSize();
19128         }
19129     },
19130
19131     
19132
19133     removeTab : function(id){
19134         var  H = this.items;
19135         var  I = H[id];
19136         if(!I) return;
19137         var  J = H.indexOf(I);
19138         if(this.active == I && H.length > 1){
19139             var  newTab = this.getNextAvailable(J);
19140             if(newTab)newTab.activate();
19141         }
19142
19143         this.stripEl.dom.removeChild(I.pnode.dom);
19144         if(I.bodyEl.dom.parentNode == this.bodyEl.dom){ 
19145             this.bodyEl.dom.removeChild(I.bodyEl.dom);
19146         }
19147
19148         H.splice(J, 1);
19149         delete  this.items[I.id];
19150         I.fireEvent("close", I);
19151         I.purgeListeners();
19152         this.autoSizeTabs();
19153     },
19154
19155     getNextAvailable : function(K){
19156         var  L = this.items;
19157         var  M = K;
19158         
19159         
19160         while(M < L.length){
19161             var  G = L[++M];
19162             if(G && !G.isHidden()){
19163                 return  G;
19164             }
19165         }
19166
19167         
19168         M = K;
19169         while(M >= 0){
19170             var  G = L[--M];
19171             if(G && !G.isHidden()){
19172                 return  G;
19173             }
19174         }
19175         return  null;
19176     },
19177
19178     
19179
19180     disableTab : function(id){
19181         var  N = this.items[id];
19182         if(N && this.active != N){
19183             N.disable();
19184         }
19185     },
19186
19187     
19188
19189     enableTab : function(id){
19190         var  O = this.items[id];
19191         O.enable();
19192     },
19193
19194     
19195
19196     activate : function(id){
19197         var  P = this.items[id];
19198         if(!P){
19199             return  null;
19200         }
19201         if(P == this.active || P.disabled){
19202             return  P;
19203         }
19204         var  e = {};
19205         this.fireEvent("beforetabchange", this, e, P);
19206         if(e.cancel !== true && !P.disabled){
19207             if(this.active){
19208                 this.active.hide();
19209             }
19210
19211             this.active = this.items[id];
19212             this.active.show();
19213             this.fireEvent("tabchange", this, this.active);
19214         }
19215         return  P;
19216     },
19217
19218     
19219
19220     getActiveTab : function(){
19221         return  this.active;
19222     },
19223
19224     
19225
19226     syncHeight : function(Q){
19227         var  R = (Q || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
19228         var  bm = this.bodyEl.getMargins();
19229         var  S = R-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
19230         this.bodyEl.setHeight(S);
19231         return  S;
19232     },
19233
19234     onResize : function(){
19235         if(this.monitorResize){
19236             this.autoSizeTabs();
19237         }
19238     },
19239
19240     
19241
19242     beginUpdate : function(){
19243         this.updating = true;
19244     },
19245
19246     
19247
19248     endUpdate : function(){
19249         this.updating = false;
19250         this.autoSizeTabs();
19251     },
19252
19253     
19254
19255     autoSizeTabs : function(){
19256         var  T = this.items.length;
19257         var  U = T - this.hiddenCount;
19258         if(!this.resizeTabs || T < 1 || U < 1 || this.updating) return;
19259         var  w = Math.max(this.el.getWidth() - this.cpad, 10);
19260         var  V = Math.floor(w / U);
19261         var  b = this.stripBody;
19262         if(b.getWidth() > w){
19263             var  tabs = this.items;
19264             this.setTabWidth(Math.max(V, this.minTabWidth)-2);
19265             if(V < this.minTabWidth){
19266                 
19267
19268             }
19269         }else {
19270             if(this.currentTabWidth < this.preferredTabWidth){
19271                 this.setTabWidth(Math.min(V, this.preferredTabWidth)-2);
19272             }
19273         }
19274     },
19275
19276     
19277
19278      getCount : function(){
19279          return  this.items.length;
19280      },
19281
19282     
19283
19284     setTabWidth : function(W){
19285         this.currentTabWidth = W;
19286         for(var  i = 0, len = this.items.length; i < len; i++) {
19287                 if(!this.items[i].isHidden())this.items[i].setWidth(W);
19288         }
19289     },
19290
19291     
19292
19293     destroy : function(X){
19294         Roo.EventManager.removeResizeListener(this.onResize, this);
19295         for(var  i = 0, len = this.items.length; i < len; i++){
19296             this.items[i].purgeListeners();
19297         }
19298         if(X === true){
19299             this.el.update("");
19300             this.el.remove();
19301         }
19302     }
19303 });
19304
19305
19306
19307 Roo.TabPanelItem = function(Y, id, Z, a){
19308     
19309
19310     this.tabPanel = Y;
19311     
19312
19313     this.id = id;
19314     
19315
19316     this.disabled = false;
19317     
19318
19319     this.text = Z;
19320     
19321
19322     this.loaded = false;
19323     this.closable = a;
19324
19325     
19326
19327     this.bodyEl = Roo.get(Y.createItemBody(Y.bodyEl.dom, id));
19328     this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
19329     this.bodyEl.setStyle("display", "block");
19330     this.bodyEl.setStyle("zoom", "1");
19331     this.hideAction();
19332
19333     var  d = Y.createStripElements(Y.stripEl.dom, Z, a);
19334     
19335
19336     this.el = Roo.get(d.el, true);
19337     this.inner = Roo.get(d.inner, true);
19338     this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
19339     this.pnode = Roo.get(d.el.parentNode, true);
19340     this.el.on("mousedown", this.onTabMouseDown, this);
19341     this.el.on("click", this.onTabClick, this);
19342     
19343
19344     if(a){
19345         var  c = Roo.get(d.close, true);
19346         c.dom.title = this.closeText;
19347         c.addClassOnOver("close-over");
19348         c.on("click", this.closeClick, this);
19349      }
19350
19351
19352     this.addEvents({
19353          
19354
19355         "activate": true,
19356         
19357
19358         "beforeclose": true,
19359         
19360
19361          "close": true,
19362         
19363
19364          "deactivate" : true
19365     });
19366     this.hidden = false;
19367
19368     Roo.TabPanelItem.superclass.constructor.call(this);
19369 };
19370
19371 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
19372     purgeListeners : function(){
19373        Roo.util.Observable.prototype.purgeListeners.call(this);
19374        this.el.removeAllListeners();
19375     },
19376     
19377
19378     show : function(){
19379         this.pnode.addClass("on");
19380         this.showAction();
19381         if(Roo.isOpera){
19382             this.tabPanel.stripWrap.repaint();
19383         }
19384
19385         this.fireEvent("activate", this.tabPanel, this);
19386     },
19387
19388     
19389
19390     isActive : function(){
19391         return  this.tabPanel.getActiveTab() == this;
19392     },
19393
19394     
19395
19396     hide : function(){
19397         this.pnode.removeClass("on");
19398         this.hideAction();
19399         this.fireEvent("deactivate", this.tabPanel, this);
19400     },
19401
19402     hideAction : function(){
19403         this.bodyEl.hide();
19404         this.bodyEl.setStyle("position", "absolute");
19405         this.bodyEl.setLeft("-20000px");
19406         this.bodyEl.setTop("-20000px");
19407     },
19408
19409     showAction : function(){
19410         this.bodyEl.setStyle("position", "relative");
19411         this.bodyEl.setTop("");
19412         this.bodyEl.setLeft("");
19413         this.bodyEl.show();
19414     },
19415
19416     
19417
19418     setTooltip : function(f){
19419         if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
19420             this.textEl.dom.qtip = f;
19421             this.textEl.dom.removeAttribute('title');
19422         }else {
19423             this.textEl.dom.title = f;
19424         }
19425     },
19426
19427     onTabClick : function(e){
19428         e.preventDefault();
19429         this.tabPanel.activate(this.id);
19430     },
19431
19432     onTabMouseDown : function(e){
19433         e.preventDefault();
19434         this.tabPanel.activate(this.id);
19435     },
19436
19437     getWidth : function(){
19438         return  this.inner.getWidth();
19439     },
19440
19441     setWidth : function(g){
19442         var  h = g - this.pnode.getPadding("lr");
19443         this.inner.setWidth(h);
19444         this.textEl.setWidth(h-this.inner.getPadding("lr"));
19445         this.pnode.setWidth(g);
19446     },
19447
19448     
19449
19450     setHidden : function(j){
19451         this.hidden = j;
19452         this.pnode.setStyle("display", j ? "none" : "");
19453     },
19454
19455     
19456
19457     isHidden : function(){
19458         return  this.hidden;
19459     },
19460
19461     
19462
19463     getText : function(){
19464         return  this.text;
19465     },
19466
19467     autoSize : function(){
19468         
19469         this.textEl.setWidth(1);
19470         this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr"));
19471         
19472     },
19473
19474     
19475
19476     setText : function(k){
19477         this.text = k;
19478         this.textEl.update(k);
19479         this.setTooltip(k);
19480         if(!this.tabPanel.resizeTabs){
19481             this.autoSize();
19482         }
19483     },
19484     
19485
19486     activate : function(){
19487         this.tabPanel.activate(this.id);
19488     },
19489
19490     
19491
19492     disable : function(){
19493         if(this.tabPanel.active != this){
19494             this.disabled = true;
19495             this.pnode.addClass("disabled");
19496         }
19497     },
19498
19499     
19500
19501     enable : function(){
19502         this.disabled = false;
19503         this.pnode.removeClass("disabled");
19504     },
19505
19506     
19507
19508     setContent : function(l, m){
19509         this.bodyEl.update(l, m);
19510     },
19511
19512     
19513
19514     getUpdateManager : function(){
19515         return  this.bodyEl.getUpdateManager();
19516     },
19517
19518     
19519
19520     setUrl : function(n, o, p){
19521         if(this.refreshDelegate){
19522             this.un('activate', this.refreshDelegate);
19523         }
19524
19525         this.refreshDelegate = this._handleRefresh.createDelegate(this, [n, o, p]);
19526         this.on("activate", this.refreshDelegate);
19527         return  this.bodyEl.getUpdateManager();
19528     },
19529
19530     
19531
19532     _handleRefresh : function(q, r, s){
19533         if(!s || !this.loaded){
19534             var  updater = this.bodyEl.getUpdateManager();
19535             updater.update(q, r, this._setLoaded.createDelegate(this));
19536         }
19537     },
19538
19539     
19540
19541     refresh : function(){
19542         if(this.refreshDelegate){
19543            this.loaded = false;
19544            this.refreshDelegate();
19545         }
19546     },
19547
19548     
19549
19550     _setLoaded : function(){
19551         this.loaded = true;
19552     },
19553
19554     
19555
19556     closeClick : function(e){
19557         var  o = {};
19558         e.stopEvent();
19559         this.fireEvent("beforeclose", this, o);
19560         if(o.cancel !== true){
19561             this.tabPanel.removeTab(this.id);
19562         }
19563     },
19564     
19565
19566     closeText : "Close this tab"
19567 });
19568
19569
19570
19571 Roo.TabPanel.prototype.createStrip = function(u){
19572     var  v = document.createElement("div");
19573     v.className = "x-tabs-wrap";
19574     u.appendChild(v);
19575     return  v;
19576 };
19577
19578
19579 Roo.TabPanel.prototype.createStripList = function(x){
19580     
19581     x.innerHTML = '<div class="x-tabs-strip-wrap"><table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr></tr></tbody></table></div>';
19582     return  x.firstChild.firstChild.firstChild.firstChild;
19583 };
19584
19585
19586 Roo.TabPanel.prototype.createBody = function(y){
19587     var  z = document.createElement("div");
19588     Roo.id(z, "tab-body");
19589     Roo.fly(z).addClass("x-tabs-body");
19590     y.appendChild(z);
19591     return  z;
19592 };
19593
19594
19595 Roo.TabPanel.prototype.createItemBody = function(AA, id){
19596     var  AB = Roo.getDom(id);
19597     if(!AB){
19598         AB = document.createElement("div");
19599         AB.id = id;
19600     }
19601
19602     Roo.fly(AB).addClass("x-tabs-item-body");
19603     AA.insertBefore(AB, AA.firstChild);
19604     return  AB;
19605 };
19606
19607
19608 Roo.TabPanel.prototype.createStripElements = function(AC, AD, AE){
19609     var  td = document.createElement("td");
19610     AC.appendChild(td);
19611     if(AE){
19612         td.className = "x-tabs-closable";
19613         if(!this.closeTpl){
19614             this.closeTpl = new  Roo.Template(
19615                '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
19616                '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
19617                '<div unselectable="on" class="close-icon">&#160;</div></em></span></a>'
19618             );
19619         }
19620         var  el = this.closeTpl.overwrite(td, {"text": AD});
19621         var  close = el.getElementsByTagName("div")[0];
19622         var  inner = el.getElementsByTagName("em")[0];
19623         return  {"el": el, "close": close, "inner": inner};
19624     } else  {
19625         if(!this.tabTpl){
19626             this.tabTpl = new  Roo.Template(
19627                '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
19628                '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
19629             );
19630         }
19631         var  el = this.tabTpl.overwrite(td, {"text": AD});
19632         var  inner = el.getElementsByTagName("em")[0];
19633         return  {"el": el, "inner": inner};
19634     }
19635 };
19636
19637
19638
19639
19640
19641 Roo.Button = function(A, B)
19642 {
19643     if (!B) {
19644         B = A;
19645         A = B.renderTo || false;
19646     }
19647
19648     
19649     Roo.apply(this, B);
19650     this.addEvents({
19651         
19652
19653             "click" : true,
19654         
19655
19656             "toggle" : true,
19657         
19658
19659         'mouseover' : true,
19660         
19661
19662         'mouseout': true,
19663          
19664
19665         'render': true
19666     });
19667     if(this.menu){
19668         this.menu = Roo.menu.MenuMgr.get(this.menu);
19669     }
19670     if(A){
19671         this.render(A);
19672     }
19673
19674     
19675     Roo.util.Observable.call(this);
19676 };
19677
19678 Roo.extend(Roo.Button, Roo.util.Observable, {
19679     
19680
19681     
19682     
19683
19684     hidden : false,
19685     
19686
19687     disabled : false,
19688     
19689
19690     pressed : false,
19691
19692     
19693
19694     tabIndex : undefined,
19695
19696     
19697
19698     enableToggle: false,
19699     
19700
19701     menu : undefined,
19702     
19703
19704     menuAlign : "tl-bl?",
19705
19706     
19707
19708     iconCls : undefined,
19709     
19710
19711     type : 'button',
19712
19713     
19714     menuClassTarget: 'tr',
19715
19716     
19717
19718     clickEvent : 'click',
19719
19720     
19721
19722     handleMouseEvents : true,
19723
19724     
19725
19726     tooltipType : 'qtip',
19727
19728     
19729
19730     
19731     
19732
19733
19734     
19735     render : function(C){
19736         var  D;
19737         if(this.hideParent){
19738             this.parentEl = Roo.get(C);
19739         }
19740         if(!this.dhconfig){
19741             if(!this.template){
19742                 if(!Roo.Button.buttonTemplate){
19743                     
19744                     Roo.Button.buttonTemplate = new  Roo.Template(
19745                         '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
19746                         '<td class="x-btn-left"><i>&#160;</i></td><td class="x-btn-center"><em unselectable="on"><button class="x-btn-text" type="{1}">{0}</button></em></td><td class="x-btn-right"><i>&#160;</i></td>',
19747                         "</tr></tbody></table>");
19748                 }
19749
19750                 this.template = Roo.Button.buttonTemplate;
19751             }
19752
19753             D = this.template.append(C, [this.text || '&#160;', this.type], true);
19754             var  btnEl = D.child("button:first");
19755             btnEl.on('focus', this.onFocus, this);
19756             btnEl.on('blur', this.onBlur, this);
19757             if(this.cls){
19758                 D.addClass(this.cls);
19759             }
19760             if(this.icon){
19761                 btnEl.setStyle('background-image', 'url(' +this.icon +')');
19762             }
19763             if(this.iconCls){
19764                 btnEl.addClass(this.iconCls);
19765                 if(!this.cls){
19766                     D.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
19767                 }
19768             }
19769             if(this.tabIndex !== undefined){
19770                 btnEl.dom.tabIndex = this.tabIndex;
19771             }
19772             if(this.tooltip){
19773                 if(typeof  this.tooltip == 'object'){
19774                     Roo.QuickTips.tips(Roo.apply({
19775                           target: btnEl.id
19776                     }, this.tooltip));
19777                 } else  {
19778                     btnEl.dom[this.tooltipType] = this.tooltip;
19779                 }
19780             }
19781         }else {
19782             D = Roo.DomHelper.append(Roo.get(C).dom, this.dhconfig, true);
19783         }
19784
19785         this.el = D;
19786         if(this.id){
19787             this.el.dom.id = this.el.id = this.id;
19788         }
19789         if(this.menu){
19790             this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
19791             this.menu.on("show", this.onMenuShow, this);
19792             this.menu.on("hide", this.onMenuHide, this);
19793         }
19794
19795         D.addClass("x-btn");
19796         if(Roo.isIE && !Roo.isIE7){
19797             this.autoWidth.defer(1, this);
19798         }else {
19799             this.autoWidth();
19800         }
19801         if(this.handleMouseEvents){
19802             D.on("mouseover", this.onMouseOver, this);
19803             D.on("mouseout", this.onMouseOut, this);
19804             D.on("mousedown", this.onMouseDown, this);
19805         }
19806
19807         D.on(this.clickEvent, this.onClick, this);
19808         
19809         if(this.hidden){
19810             this.hide();
19811         }
19812         if(this.disabled){
19813             this.disable();
19814         }
19815
19816         Roo.ButtonToggleMgr.register(this);
19817         if(this.pressed){
19818             this.el.addClass("x-btn-pressed");
19819         }
19820         if(this.repeat){
19821             var  repeater = new  Roo.util.ClickRepeater(D,
19822                 typeof  this.repeat == "object" ? this.repeat : {}
19823             );
19824             repeater.on("click", this.onClick,  this);
19825         }
19826
19827         this.fireEvent('render', this);
19828         
19829     },
19830     
19831
19832     getEl : function(){
19833         return  this.el;  
19834     },
19835     
19836     
19837
19838     destroy : function(){
19839         Roo.ButtonToggleMgr.unregister(this);
19840         this.el.removeAllListeners();
19841         this.purgeListeners();
19842         this.el.remove();
19843     },
19844
19845     
19846     autoWidth : function(){
19847         if(this.el){
19848             this.el.setWidth("auto");
19849             if(Roo.isIE7 && Roo.isStrict){
19850                 var  ib = this.el.child('button');
19851                 if(ib && ib.getWidth() > 20){
19852                     ib.clip();
19853                     ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
19854                 }
19855             }
19856             if(this.minWidth){
19857                 if(this.hidden){
19858                     this.el.beginMeasure();
19859                 }
19860                 if(this.el.getWidth() < this.minWidth){
19861                     this.el.setWidth(this.minWidth);
19862                 }
19863                 if(this.hidden){
19864                     this.el.endMeasure();
19865                 }
19866             }
19867         }
19868     },
19869
19870     
19871
19872     setHandler : function(E, F){
19873         this.handler = E;
19874         this.scope = F;  
19875     },
19876     
19877     
19878
19879     setText : function(G){
19880         this.text = G;
19881         if(this.el){
19882             this.el.child("td.x-btn-center button.x-btn-text").update(G);
19883         }
19884
19885         this.autoWidth();
19886     },
19887     
19888     
19889
19890     getText : function(){
19891         return  this.text;  
19892     },
19893     
19894     
19895
19896     show: function(){
19897         this.hidden = false;
19898         if(this.el){
19899             this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
19900         }
19901     },
19902     
19903     
19904
19905     hide: function(){
19906         this.hidden = true;
19907         if(this.el){
19908             this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
19909         }
19910     },
19911     
19912     
19913
19914     setVisible: function(H){
19915         if(H) {
19916             this.show();
19917         }else {
19918             this.hide();
19919         }
19920     },
19921     
19922     
19923
19924     toggle : function(I){
19925         I = I === undefined ? !this.pressed : I;
19926         if(I != this.pressed){
19927             if(I){
19928                 this.el.addClass("x-btn-pressed");
19929                 this.pressed = true;
19930                 this.fireEvent("toggle", this, true);
19931             }else {
19932                 this.el.removeClass("x-btn-pressed");
19933                 this.pressed = false;
19934                 this.fireEvent("toggle", this, false);
19935             }
19936             if(this.toggleHandler){
19937                 this.toggleHandler.call(this.scope || this, this, I);
19938             }
19939         }
19940     },
19941     
19942     
19943
19944     focus : function(){
19945         this.el.child('button:first').focus();
19946     },
19947     
19948     
19949
19950     disable : function(){
19951         if(this.el){
19952             this.el.addClass("x-btn-disabled");
19953         }
19954
19955         this.disabled = true;
19956     },
19957     
19958     
19959
19960     enable : function(){
19961         if(this.el){
19962             this.el.removeClass("x-btn-disabled");
19963         }
19964
19965         this.disabled = false;
19966     },
19967
19968     
19969
19970     setDisabled : function(v){
19971         this[v !== true ? "enable" : "disable"]();
19972     },
19973
19974     
19975     onClick : function(e){
19976         if(e){
19977             e.preventDefault();
19978         }
19979         if(e.button != 0){
19980             return;
19981         }
19982         if(!this.disabled){
19983             if(this.enableToggle){
19984                 this.toggle();
19985             }
19986             if(this.menu && !this.menu.isVisible()){
19987                 this.menu.show(this.el, this.menuAlign);
19988             }
19989
19990             this.fireEvent("click", this, e);
19991             if(this.handler){
19992                 this.el.removeClass("x-btn-over");
19993                 this.handler.call(this.scope || this, this, e);
19994             }
19995         }
19996     },
19997     
19998     onMouseOver : function(e){
19999         if(!this.disabled){
20000             this.el.addClass("x-btn-over");
20001             this.fireEvent('mouseover', this, e);
20002         }
20003     },
20004     
20005     onMouseOut : function(e){
20006         if(!e.within(this.el,  true)){
20007             this.el.removeClass("x-btn-over");
20008             this.fireEvent('mouseout', this, e);
20009         }
20010     },
20011     
20012     onFocus : function(e){
20013         if(!this.disabled){
20014             this.el.addClass("x-btn-focus");
20015         }
20016     },
20017     
20018     onBlur : function(e){
20019         this.el.removeClass("x-btn-focus");
20020     },
20021     
20022     onMouseDown : function(e){
20023         if(!this.disabled && e.button == 0){
20024             this.el.addClass("x-btn-click");
20025             Roo.get(document).on('mouseup', this.onMouseUp, this);
20026         }
20027     },
20028     
20029     onMouseUp : function(e){
20030         if(e.button == 0){
20031             this.el.removeClass("x-btn-click");
20032             Roo.get(document).un('mouseup', this.onMouseUp, this);
20033         }
20034     },
20035     
20036     onMenuShow : function(e){
20037         this.el.addClass("x-btn-menu-active");
20038     },
20039     
20040     onMenuHide : function(e){
20041         this.el.removeClass("x-btn-menu-active");
20042     }   
20043 });
20044
20045
20046 Roo.ButtonToggleMgr = function(){
20047    var  J = {};
20048    
20049    function  K(L, M){
20050        if(M){
20051            var  g = J[L.toggleGroup];
20052            for(var  i = 0, l = g.length; i < l; i++){
20053                if(g[i] != L){
20054                    g[i].toggle(false);
20055                }
20056            }
20057        }
20058    }
20059    
20060    return  {
20061        register : function(N){
20062            if(!N.toggleGroup){
20063                return;
20064            }
20065            var  g = J[N.toggleGroup];
20066            if(!g){
20067                g = J[N.toggleGroup] = [];
20068            }
20069
20070            g.push(N);
20071            N.on("toggle", K);
20072        },
20073        
20074        unregister : function(O){
20075            if(!O.toggleGroup){
20076                return;
20077            }
20078            var  g = J[O.toggleGroup];
20079            if(g){
20080                g.remove(O);
20081                O.un("toggle", K);
20082            }
20083        }
20084    };
20085 }();
20086
20087
20088  
20089
20090
20091 Roo.SplitButton = function(A, B){
20092     Roo.SplitButton.superclass.constructor.call(this, A, B);
20093     
20094
20095     this.addEvents({"arrowclick":true});
20096 };
20097
20098 Roo.extend(Roo.SplitButton, Roo.Button, {
20099     render : function(C){
20100         
20101         var  D = new  Roo.Template(
20102             '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
20103             '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
20104             '<tr><td class="x-btn-left"><i>&#160;</i></td><td class="x-btn-center"><button class="x-btn-text" type="{1}">{0}</button></td></tr>',
20105             "</tbody></table></td><td>",
20106             '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
20107             '<tr><td class="x-btn-center"><button class="x-btn-menu-arrow-el" type="button">&#160;</button></td><td class="x-btn-right"><i>&#160;</i></td></tr>',
20108             "</tbody></table></td></tr></table>"
20109         );
20110         var  E = D.append(C, [this.text, this.type], true);
20111         var  F = E.child("button");
20112         if(this.cls){
20113             E.addClass(this.cls);
20114         }
20115         if(this.icon){
20116             F.setStyle('background-image', 'url(' +this.icon +')');
20117         }
20118         if(this.iconCls){
20119             F.addClass(this.iconCls);
20120             if(!this.cls){
20121                 E.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
20122             }
20123         }
20124
20125         this.el = E;
20126         if(this.handleMouseEvents){
20127             E.on("mouseover", this.onMouseOver, this);
20128             E.on("mouseout", this.onMouseOut, this);
20129             E.on("mousedown", this.onMouseDown, this);
20130             E.on("mouseup", this.onMouseUp, this);
20131         }
20132
20133         E.on(this.clickEvent, this.onClick, this);
20134         if(this.tooltip){
20135             if(typeof  this.tooltip == 'object'){
20136                 Roo.QuickTips.tips(Roo.apply({
20137                       target: F.id
20138                 }, this.tooltip));
20139             } else  {
20140                 F.dom[this.tooltipType] = this.tooltip;
20141             }
20142         }
20143         if(this.arrowTooltip){
20144             E.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
20145         }
20146         if(this.hidden){
20147             this.hide();
20148         }
20149         if(this.disabled){
20150             this.disable();
20151         }
20152         if(this.pressed){
20153             this.el.addClass("x-btn-pressed");
20154         }
20155         if(Roo.isIE && !Roo.isIE7){
20156             this.autoWidth.defer(1, this);
20157         }else {
20158             this.autoWidth();
20159         }
20160         if(this.menu){
20161             this.menu.on("show", this.onMenuShow, this);
20162             this.menu.on("hide", this.onMenuHide, this);
20163         }
20164
20165         this.fireEvent('render', this);
20166     },
20167
20168     
20169     autoWidth : function(){
20170         if(this.el){
20171             var  tbl = this.el.child("table:first");
20172             var  tbl2 = this.el.child("table:last");
20173             this.el.setWidth("auto");
20174             tbl.setWidth("auto");
20175             if(Roo.isIE7 && Roo.isStrict){
20176                 var  ib = this.el.child('button:first');
20177                 if(ib && ib.getWidth() > 20){
20178                     ib.clip();
20179                     ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
20180                 }
20181             }
20182             if(this.minWidth){
20183                 if(this.hidden){
20184                     this.el.beginMeasure();
20185                 }
20186                 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
20187                     tbl.setWidth(this.minWidth-tbl2.getWidth());
20188                 }
20189                 if(this.hidden){
20190                     this.el.endMeasure();
20191                 }
20192             }
20193
20194             this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
20195         } 
20196     },
20197     
20198
20199     setHandler : function(G, H){
20200         this.handler = G;
20201         this.scope = H;  
20202     },
20203     
20204     
20205
20206     setArrowHandler : function(I, J){
20207         this.arrowHandler = I;
20208         this.scope = J;  
20209     },
20210     
20211     
20212
20213     focus : function(){
20214         if(this.el){
20215             this.el.child("button:first").focus();
20216         }
20217     },
20218
20219     
20220     onClick : function(e){
20221         e.preventDefault();
20222         if(!this.disabled){
20223             if(e.getTarget(".x-btn-menu-arrow-wrap")){
20224                 if(this.menu && !this.menu.isVisible()){
20225                     this.menu.show(this.el, this.menuAlign);
20226                 }
20227
20228                 this.fireEvent("arrowclick", this, e);
20229                 if(this.arrowHandler){
20230                     this.arrowHandler.call(this.scope || this, this, e);
20231                 }
20232             }else {
20233                 this.fireEvent("click", this, e);
20234                 if(this.handler){
20235                     this.handler.call(this.scope || this, this, e);
20236                 }
20237             }
20238         }
20239     },
20240     
20241     onMouseDown : function(e){
20242         if(!this.disabled){
20243             Roo.fly(e.getTarget("table")).addClass("x-btn-click");
20244         }
20245     },
20246     
20247     onMouseUp : function(e){
20248         Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
20249     }   
20250 });
20251
20252
20253
20254 Roo.MenuButton = Roo.SplitButton;
20255
20256
20257
20258
20259  
20260 Roo.Toolbar = function(A, B, C)
20261 {
20262     
20263     if(A  instanceof  Array){ 
20264         B = A;
20265         C = B;
20266         A = null;
20267     }
20268     if (typeof(A) == 'object' && A.xtype) {
20269         C = A;
20270         A = C.container;
20271         B = C.buttons; 
20272     }
20273     var  D = [];
20274     if (C && C.items) {
20275         D = C.items;
20276         delete  C.items;
20277     }
20278
20279     Roo.apply(this, C);
20280     this.buttons = B;
20281     
20282     if(A){
20283         this.render(A);
20284     }
20285
20286     Roo.each(D, function(b) {
20287         this.add(b);
20288     }, this);
20289     
20290 };
20291
20292 Roo.Toolbar.prototype = {
20293     
20294
20295     
20296     
20297
20298     
20299     render : function(ct){
20300         this.el = Roo.get(ct);
20301         if(this.cls){
20302             this.el.addClass(this.cls);
20303         }
20304
20305         
20306         
20307         this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
20308         this.tr = this.el.child("tr", true);
20309         var  E = 0;
20310         this.items = new  Roo.util.MixedCollection(false, function(o){
20311             return  o.id || ("item" + (++E));
20312         });
20313         if(this.buttons){
20314             this.add.apply(this, this.buttons);
20315             delete  this.buttons;
20316         }
20317     },
20318
20319     
20320
20321     add : function(){
20322         var  a = arguments, l = a.length;
20323         for(var  i = 0; i < l; i++){
20324             this._add(a[i]);
20325         }
20326     },
20327     
20328     _add : function(el) {
20329         
20330         if (el.xtype) {
20331             el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
20332         }
20333         
20334         if (el.applyTo){ 
20335             return  this.addField(el);
20336         } 
20337         if (el.render){ 
20338             return  this.addItem(el);
20339         }
20340         if (typeof  el == "string"){ 
20341             if(el == "separator" || el == "-"){
20342                 return  this.addSeparator();
20343             }
20344             if (el == " "){
20345                 return  this.addSpacer();
20346             }
20347             if(el == "->"){
20348                 return  this.addFill();
20349             }
20350             return  this.addText(el);
20351             
20352         }
20353         if(el.tagName){ 
20354             return  this.addElement(el);
20355         }
20356         if(typeof  el == "object"){ 
20357             return  this.addButton(el);
20358         }
20359         
20360         return  false;
20361         
20362     },
20363     
20364     
20365
20366     addxtype : function(e){
20367         return  this.add(e);  
20368     },
20369     
20370     
20371
20372     getEl : function(){
20373         return  this.el;  
20374     },
20375     
20376     
20377
20378     addSeparator : function(){
20379         return  this.addItem(new  Roo.Toolbar.Separator());
20380     },
20381
20382     
20383
20384     addSpacer : function(){
20385         return  this.addItem(new  Roo.Toolbar.Spacer());
20386     },
20387
20388     
20389
20390     addFill : function(){
20391         return  this.addItem(new  Roo.Toolbar.Fill());
20392     },
20393
20394     
20395
20396     addElement : function(el){
20397         return  this.addItem(new  Roo.Toolbar.Item(el));
20398     },
20399     
20400
20401     items : false,
20402      
20403     
20404
20405     addItem : function(F){
20406         var  td = this.nextBlock();
20407         F.render(td);
20408         this.items.add(F);
20409         return  F;
20410     },
20411     
20412     
20413
20414     addButton : function(G){
20415         if(G  instanceof  Array){
20416             var  B = [];
20417             for(var  i = 0, len = G.length; i < len; i++) {
20418                 B.push(this.addButton(G[i]));
20419             }
20420             return  B;
20421         }
20422         var  b = G;
20423         if(!(G  instanceof  Roo.Toolbar.Button)){
20424             b = G.split ?
20425                 new  Roo.Toolbar.SplitButton(G) :
20426                 new  Roo.Toolbar.Button(G);
20427         }
20428         var  td = this.nextBlock();
20429         b.render(td);
20430         this.items.add(b);
20431         return  b;
20432     },
20433     
20434     
20435
20436     addText : function(H){
20437         return  this.addItem(new  Roo.Toolbar.TextItem(H));
20438     },
20439     
20440     
20441
20442     insertButton : function(I, J){
20443         if(J  instanceof  Array){
20444             var  B = [];
20445             for(var  i = 0, len = J.length; i < len; i++) {
20446                B.push(this.insertButton(I + i, J[i]));
20447             }
20448             return  B;
20449         }
20450         if (!(J  instanceof  Roo.Toolbar.Button)){
20451            J = new  Roo.Toolbar.Button(J);
20452         }
20453         var  td = document.createElement("td");
20454         this.tr.insertBefore(td, this.tr.childNodes[I]);
20455         J.render(td);
20456         this.items.insert(I, J);
20457         return  J;
20458     },
20459     
20460     
20461
20462     addDom : function(K, L){
20463         var  td = this.nextBlock();
20464         Roo.DomHelper.overwrite(td, K);
20465         var  ti = new  Roo.Toolbar.Item(td.firstChild);
20466         ti.render(td);
20467         this.items.add(ti);
20468         return  ti;
20469     },
20470
20471     
20472
20473     fields : false,
20474     
20475     
20476
20477      
20478       
20479     addField : function(M) {
20480         if (!this.fields) {
20481             var  E = 0;
20482             this.fields = new  Roo.util.MixedCollection(false, function(o){
20483                 return  o.id || ("item" + (++E));
20484             });
20485
20486         }
20487         
20488         var  td = this.nextBlock();
20489         M.render(td);
20490         var  ti = new  Roo.Toolbar.Item(td.firstChild);
20491         ti.render(td);
20492         this.items.add(ti);
20493         this.fields.add(M);
20494         return  ti;
20495     },
20496     
20497
20498      
20499       
20500     hide : function()
20501     {
20502         this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
20503         this.el.child('div').hide();
20504     },
20505     
20506
20507     show : function()
20508     {
20509         this.el.child('div').show();
20510     },
20511       
20512     
20513     nextBlock : function(){
20514         var  td = document.createElement("td");
20515         this.tr.appendChild(td);
20516         return  td;
20517     },
20518
20519     
20520     destroy : function(){
20521         if(this.items){ 
20522             Roo.destroy.apply(Roo, this.items.items);
20523         }
20524         if(this.fields){ 
20525             Roo.destroy.apply(Roo, this.fields.items);
20526         }
20527
20528         Roo.Element.uncache(this.el, this.tr);
20529     }
20530 };
20531
20532
20533
20534 Roo.Toolbar.Item = function(el){
20535     this.el = Roo.getDom(el);
20536     this.id = Roo.id(this.el);
20537     this.hidden = false;
20538 };
20539
20540 Roo.Toolbar.Item.prototype = {
20541     
20542     
20543
20544     getEl : function(){
20545        return  this.el;  
20546     },
20547
20548     
20549     render : function(td){
20550         this.td = td;
20551         td.appendChild(this.el);
20552     },
20553     
20554     
20555
20556     destroy : function(){
20557         this.td.parentNode.removeChild(this.td);
20558     },
20559     
20560     
20561
20562     show: function(){
20563         this.hidden = false;
20564         this.td.style.display = "";
20565     },
20566     
20567     
20568
20569     hide: function(){
20570         this.hidden = true;
20571         this.td.style.display = "none";
20572     },
20573     
20574     
20575
20576     setVisible: function(N){
20577         if(N) {
20578             this.show();
20579         }else {
20580             this.hide();
20581         }
20582     },
20583     
20584     
20585
20586     focus : function(){
20587         Roo.fly(this.el).focus();
20588     },
20589     
20590     
20591
20592     disable : function(){
20593         Roo.fly(this.td).addClass("x-item-disabled");
20594         this.disabled = true;
20595         this.el.disabled = true;
20596     },
20597     
20598     
20599
20600     enable : function(){
20601         Roo.fly(this.td).removeClass("x-item-disabled");
20602         this.disabled = false;
20603         this.el.disabled = false;
20604     }
20605 };
20606
20607
20608
20609
20610 Roo.Toolbar.Separator = function(){
20611     var  s = document.createElement("span");
20612     s.className = "ytb-sep";
20613     Roo.Toolbar.Separator.superclass.constructor.call(this, s);
20614 };
20615 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
20616     enable:Roo.emptyFn,
20617     disable:Roo.emptyFn,
20618     focus:Roo.emptyFn
20619 });
20620
20621
20622
20623 Roo.Toolbar.Spacer = function(){
20624     var  s = document.createElement("div");
20625     s.className = "ytb-spacer";
20626     Roo.Toolbar.Spacer.superclass.constructor.call(this, s);
20627 };
20628 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
20629     enable:Roo.emptyFn,
20630     disable:Roo.emptyFn,
20631     focus:Roo.emptyFn
20632 });
20633
20634
20635
20636 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
20637     
20638     render : function(td){
20639         td.style.width = '100%';
20640         Roo.Toolbar.Fill.superclass.render.call(this, td);
20641     }
20642 });
20643
20644
20645
20646 Roo.Toolbar.TextItem = function(O){
20647     if (typeof(O) == 'object') {
20648         O = O.text;
20649     }
20650     var  s = document.createElement("span");
20651     s.className = "ytb-text";
20652     s.innerHTML = O;
20653     Roo.Toolbar.TextItem.superclass.constructor.call(this, s);
20654 };
20655 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
20656     enable:Roo.emptyFn,
20657     disable:Roo.emptyFn,
20658     focus:Roo.emptyFn
20659 });
20660
20661
20662
20663 Roo.Toolbar.Button = function(P){
20664     Roo.Toolbar.Button.superclass.constructor.call(this, null, P);
20665 };
20666 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
20667     render : function(td){
20668         this.td = td;
20669         Roo.Toolbar.Button.superclass.render.call(this, td);
20670     },
20671     
20672     
20673
20674     destroy : function(){
20675         Roo.Toolbar.Button.superclass.destroy.call(this);
20676         this.td.parentNode.removeChild(this.td);
20677     },
20678     
20679     
20680
20681     show: function(){
20682         this.hidden = false;
20683         this.td.style.display = "";
20684     },
20685     
20686     
20687
20688     hide: function(){
20689         this.hidden = true;
20690         this.td.style.display = "none";
20691     },
20692
20693     
20694
20695     disable : function(){
20696         Roo.fly(this.td).addClass("x-item-disabled");
20697         this.disabled = true;
20698     },
20699
20700     
20701
20702     enable : function(){
20703         Roo.fly(this.td).removeClass("x-item-disabled");
20704         this.disabled = false;
20705     }
20706 });
20707
20708 Roo.ToolbarButton = Roo.Toolbar.Button;
20709
20710
20711
20712 Roo.Toolbar.SplitButton = function(Q){
20713     Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, Q);
20714 };
20715 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
20716     render : function(td){
20717         this.td = td;
20718         Roo.Toolbar.SplitButton.superclass.render.call(this, td);
20719     },
20720     
20721     
20722
20723     destroy : function(){
20724         Roo.Toolbar.SplitButton.superclass.destroy.call(this);
20725         this.td.parentNode.removeChild(this.td);
20726     },
20727     
20728     
20729
20730     show: function(){
20731         this.hidden = false;
20732         this.td.style.display = "";
20733     },
20734     
20735     
20736
20737     hide: function(){
20738         this.hidden = true;
20739         this.td.style.display = "none";
20740     }
20741 });
20742
20743
20744 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;
20745
20746
20747  
20748
20749
20750 Roo.PagingToolbar = function(el, ds, A)
20751 {
20752     
20753     if (typeof(el) == 'object' && el.xtype) {
20754         
20755         A = el;
20756         ds = el.dataSource;
20757         el = A.container;
20758     }
20759
20760     
20761     
20762     Roo.PagingToolbar.superclass.constructor.call(this, el, null, A);
20763     this.ds = ds;
20764     this.cursor = 0;
20765     this.renderButtons(this.el);
20766     this.bind(ds);
20767 };
20768
20769 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
20770     
20771
20772     
20773
20774     
20775
20776     
20777
20778     pageSize: 20,
20779     
20780
20781     displayMsg : 'Displaying {0} - {1} of {2}',
20782     
20783
20784     emptyMsg : 'No data to display',
20785     
20786
20787     beforePageText : "Page",
20788     
20789
20790     afterPageText : "of {0}",
20791     
20792
20793     firstText : "First Page",
20794     
20795
20796     prevText : "Previous Page",
20797     
20798
20799     nextText : "Next Page",
20800     
20801
20802     lastText : "Last Page",
20803     
20804
20805     refreshText : "Refresh",
20806
20807     
20808     renderButtons : function(el){
20809         Roo.PagingToolbar.superclass.render.call(this, el);
20810         this.first = this.addButton({
20811             tooltip: this.firstText,
20812             cls: "x-btn-icon x-grid-page-first",
20813             disabled: true,
20814             handler: this.onClick.createDelegate(this, ["first"])
20815         });
20816         this.prev = this.addButton({
20817             tooltip: this.prevText,
20818             cls: "x-btn-icon x-grid-page-prev",
20819             disabled: true,
20820             handler: this.onClick.createDelegate(this, ["prev"])
20821         });
20822         this.addSeparator();
20823         this.add(this.beforePageText);
20824         this.field = Roo.get(this.addDom({
20825            tag: "input",
20826            type: "text",
20827            size: "3",
20828            value: "1",
20829            cls: "x-grid-page-number"
20830         }).el);
20831         this.field.on("keydown", this.onPagingKeydown, this);
20832         this.field.on("focus", function(){this.dom.select();});
20833         this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
20834         this.field.setHeight(18);
20835         this.addSeparator();
20836         this.next = this.addButton({
20837             tooltip: this.nextText,
20838             cls: "x-btn-icon x-grid-page-next",
20839             disabled: true,
20840             handler: this.onClick.createDelegate(this, ["next"])
20841         });
20842         this.last = this.addButton({
20843             tooltip: this.lastText,
20844             cls: "x-btn-icon x-grid-page-last",
20845             disabled: true,
20846             handler: this.onClick.createDelegate(this, ["last"])
20847         });
20848         this.addSeparator();
20849         this.loading = this.addButton({
20850             tooltip: this.refreshText,
20851             cls: "x-btn-icon x-grid-loading",
20852             handler: this.onClick.createDelegate(this, ["refresh"])
20853         });
20854
20855         if(this.displayInfo){
20856             this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
20857         }
20858     },
20859
20860     
20861     updateInfo : function(){
20862         if(this.displayEl){
20863             var  count = this.ds.getCount();
20864             var  msg = count == 0 ?
20865                 this.emptyMsg :
20866                 String.format(
20867                     this.displayMsg,
20868                     this.cursor+1, this.cursor+count, this.ds.getTotalCount()    
20869                 );
20870             this.displayEl.update(msg);
20871         }
20872     },
20873
20874     
20875     onLoad : function(ds, r, o){
20876        this.cursor = o.params ? o.params.start : 0;
20877        var  d = this.getPageData(), ap = d.activePage, ps = d.pages;
20878
20879        this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
20880        this.field.dom.value = ap;
20881        this.first.setDisabled(ap == 1);
20882        this.prev.setDisabled(ap == 1);
20883        this.next.setDisabled(ap == ps);
20884        this.last.setDisabled(ap == ps);
20885        this.loading.enable();
20886        this.updateInfo();
20887     },
20888
20889     
20890     getPageData : function(){
20891         var  B = this.ds.getTotalCount();
20892         return  {
20893             total : B,
20894             activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
20895             pages :  B < this.pageSize ? 1 : Math.ceil(B/this.pageSize)
20896         };
20897     },
20898
20899     
20900     onLoadError : function(){
20901         this.loading.enable();
20902     },
20903
20904     
20905     onPagingKeydown : function(e){
20906         var  k = e.getKey();
20907         var  d = this.getPageData();
20908         if(k == e.RETURN ){
20909             var  v = this.field.dom.value, pageNum;
20910             if(!v || isNaN(pageNum = parseInt(v, 10))){
20911                 this.field.dom.value = d.activePage;
20912                 return;
20913             }
20914
20915             pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
20916             this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
20917             e.stopEvent();
20918         }
20919         else  if(k == e.HOME || (k == e.UP && e.ctrlKey) || (k == e.PAGEUP && e.ctrlKey) || (k == e.RIGHT && e.ctrlKey) || k == e.END || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey))
20920         {
20921           var  pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
20922           this.field.dom.value = pageNum;
20923           this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
20924           e.stopEvent();
20925         }
20926         else  if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
20927         {
20928           var  v = this.field.dom.value, pageNum; 
20929           var  increment = (e.shiftKey) ? 10 : 1;
20930           if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
20931             increment *= -1;
20932           if(!v || isNaN(pageNum = parseInt(v, 10))) {
20933             this.field.dom.value = d.activePage;
20934             return;
20935           }
20936           else  if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
20937           {
20938             this.field.dom.value = parseInt(v, 10) + increment;
20939             pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
20940             this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
20941           }
20942
20943           e.stopEvent();
20944         }
20945     },
20946
20947     
20948     beforeLoad : function(){
20949         if(this.loading){
20950             this.loading.disable();
20951         }
20952     },
20953
20954     
20955     onClick : function(C){
20956         var  ds = this.ds;
20957         switch(C){
20958             case  "first":
20959                 ds.load({params:{start: 0, limit: this.pageSize}});
20960             break;
20961             case  "prev":
20962                 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
20963             break;
20964             case  "next":
20965                 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
20966             break;
20967             case  "last":
20968                 var  B = ds.getTotalCount();
20969                 var  extra = B % this.pageSize;
20970                 var  lastStart = extra ? (B - extra) : B-this.pageSize;
20971                 ds.load({params:{start: lastStart, limit: this.pageSize}});
20972             break;
20973             case  "refresh":
20974                 ds.load({params:{start: this.cursor, limit: this.pageSize}});
20975             break;
20976         }
20977     },
20978
20979     
20980
20981     unbind : function(ds){
20982         ds.un("beforeload", this.beforeLoad, this);
20983         ds.un("load", this.onLoad, this);
20984         ds.un("loadexception", this.onLoadError, this);
20985         ds.un("remove", this.updateInfo, this);
20986         ds.un("add", this.updateInfo, this);
20987         this.ds = undefined;
20988     },
20989
20990     
20991
20992     bind : function(ds){
20993         ds.on("beforeload", this.beforeLoad, this);
20994         ds.on("load", this.onLoad, this);
20995         ds.on("loadexception", this.onLoadError, this);
20996         ds.on("remove", this.updateInfo, this);
20997         ds.on("add", this.updateInfo, this);
20998         this.ds = ds;
20999     }
21000 });
21001
21002
21003
21004
21005
21006 Roo.Resizable = function(el, A){
21007     this.el = Roo.get(el);
21008
21009     if(A && A.wrap){
21010         A.resizeChild = this.el;
21011         this.el = this.el.wrap(typeof  A.wrap == "object" ? A.wrap : {cls:"xresizable-wrap"});
21012         this.el.id = this.el.dom.id = A.resizeChild.id + "-rzwrap";
21013         this.el.setStyle("overflow", "hidden");
21014         this.el.setPositioning(A.resizeChild.getPositioning());
21015         A.resizeChild.clearPositioning();
21016         if(!A.width || !A.height){
21017             var  csize = A.resizeChild.getSize();
21018             this.el.setSize(csize.width, csize.height);
21019         }
21020         if(A.pinned && !A.adjustments){
21021             A.adjustments = "auto";
21022         }
21023     }
21024
21025
21026     this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
21027     this.proxy.unselectable();
21028     this.proxy.enableDisplayMode('block');
21029
21030     Roo.apply(this, A);
21031
21032     if(this.pinned){
21033         this.disableTrackOver = true;
21034         this.el.addClass("x-resizable-pinned");
21035     }
21036     
21037     var  B = this.el.getStyle("position");
21038     if(B != "absolute" && B != "fixed"){
21039         this.el.setStyle("position", "relative");
21040     }
21041     if(!this.handles){ 
21042         this.handles = 's,e,se';
21043         if(this.multiDirectional){
21044             this.handles += ',n,w';
21045         }
21046     }
21047     if(this.handles == "all"){
21048         this.handles = "n s e w ne nw se sw";
21049     }
21050     var  hs = this.handles.split(/\s*?[,;]\s*?| /);
21051     var  ps = Roo.Resizable.positions;
21052     for(var  i = 0, len = hs.length; i < len; i++){
21053         if(hs[i] && ps[hs[i]]){
21054             var  pos = ps[hs[i]];
21055             this[pos] = new  Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
21056         }
21057     }
21058
21059     
21060     this.corner = this.southeast;
21061
21062     if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1){
21063         this.updateBox = true;
21064     }
21065
21066
21067     this.activeHandle = null;
21068
21069     if(this.resizeChild){
21070         if(typeof  this.resizeChild == "boolean"){
21071             this.resizeChild = Roo.get(this.el.dom.firstChild, true);
21072         }else {
21073             this.resizeChild = Roo.get(this.resizeChild, true);
21074         }
21075     }
21076
21077     if(this.adjustments == "auto"){
21078         var  rc = this.resizeChild;
21079         var  hw = this.west, he = this.east, hn = this.north, hs = this.south;
21080         if(rc && (hw || hn)){
21081             rc.position("relative");
21082             rc.setLeft(hw ? hw.el.getWidth() : 0);
21083             rc.setTop(hn ? hn.el.getHeight() : 0);
21084         }
21085
21086         this.adjustments = [
21087             (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
21088             (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
21089         ];
21090     }
21091
21092     if(this.draggable){
21093         this.dd = this.dynamic ?
21094             this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
21095         this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
21096     }
21097
21098
21099     
21100     this.addEvents({
21101         
21102
21103         "beforeresize" : true,
21104         
21105
21106         "resize" : true
21107     });
21108
21109     if(this.width !== null && this.height !== null){
21110         this.resizeTo(this.width, this.height);
21111     }else {
21112         this.updateChildSize();
21113     }
21114     if(Roo.isIE){
21115         this.el.dom.style.zoom = 1;
21116     }
21117
21118     Roo.Resizable.superclass.constructor.call(this);
21119 };
21120
21121 Roo.extend(Roo.Resizable, Roo.util.Observable, {
21122         resizeChild : false,
21123         adjustments : [0, 0],
21124         minWidth : 5,
21125         minHeight : 5,
21126         maxWidth : 10000,
21127         maxHeight : 10000,
21128         enabled : true,
21129         animate : false,
21130         duration : .35,
21131         dynamic : false,
21132         handles : false,
21133         multiDirectional : false,
21134         disableTrackOver : false,
21135         easing : 'easeOutStrong',
21136         widthIncrement : 0,
21137         heightIncrement : 0,
21138         pinned : false,
21139         width : null,
21140         height : null,
21141         preserveRatio : false,
21142         transparent: false,
21143         minX: 0,
21144         minY: 0,
21145         draggable: false,
21146
21147         
21148
21149         constrainTo: undefined,
21150         
21151
21152         resizeRegion: undefined,
21153
21154
21155     
21156
21157     resizeTo : function(C, D){
21158         this.el.setSize(C, D);
21159         this.updateChildSize();
21160         this.fireEvent("resize", this, C, D, null);
21161     },
21162
21163     
21164     startSizing : function(e, E){
21165         this.fireEvent("beforeresize", this, e);
21166         if(this.enabled){ 
21167
21168             if(!this.overlay){
21169                 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: "&#160;"});
21170                 this.overlay.unselectable();
21171                 this.overlay.enableDisplayMode("block");
21172                 this.overlay.on("mousemove", this.onMouseMove, this);
21173                 this.overlay.on("mouseup", this.onMouseUp, this);
21174             }
21175
21176             this.overlay.setStyle("cursor", E.el.getStyle("cursor"));
21177
21178             this.resizing = true;
21179             this.startBox = this.el.getBox();
21180             this.startPoint = e.getXY();
21181             this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
21182                             (this.startBox.y + this.startBox.height) - this.startPoint[1]];
21183
21184             this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
21185             this.overlay.show();
21186
21187             if(this.constrainTo) {
21188                 var  ct = Roo.get(this.constrainTo);
21189                 this.resizeRegion = ct.getRegion().adjust(
21190                     ct.getFrameWidth('t'),
21191                     ct.getFrameWidth('l'),
21192                     -ct.getFrameWidth('b'),
21193                     -ct.getFrameWidth('r')
21194                 );
21195             }
21196
21197
21198             this.proxy.setStyle('visibility', 'hidden'); 
21199             this.proxy.show();
21200             this.proxy.setBox(this.startBox);
21201             if(!this.dynamic){
21202                 this.proxy.setStyle('visibility', 'visible');
21203             }
21204         }
21205     },
21206
21207     
21208     onMouseDown : function(F, e){
21209         if(this.enabled){
21210             e.stopEvent();
21211             this.activeHandle = F;
21212             this.startSizing(e, F);
21213         }
21214     },
21215
21216     
21217     onMouseUp : function(e){
21218         var  G = this.resizeElement();
21219         this.resizing = false;
21220         this.handleOut();
21221         this.overlay.hide();
21222         this.proxy.hide();
21223         this.fireEvent("resize", this, G.width, G.height, e);
21224     },
21225
21226     
21227     updateChildSize : function(){
21228         if(this.resizeChild){
21229             var  el = this.el;
21230             var  child = this.resizeChild;
21231             var  adj = this.adjustments;
21232             if(el.dom.offsetWidth){
21233                 var  b = el.getSize(true);
21234                 child.setSize(b.width+adj[0], b.height+adj[1]);
21235             }
21236             
21237             
21238             
21239             
21240             if(Roo.isIE){
21241                 setTimeout(function(){
21242                     if(el.dom.offsetWidth){
21243                         var  b = el.getSize(true);
21244                         child.setSize(b.width+adj[0], b.height+adj[1]);
21245                     }
21246                 }, 10);
21247             }
21248         }
21249     },
21250
21251     
21252     snap : function(H, I, J){
21253         if(!I || !H) return  H;
21254         var  K = H;
21255         var  m = H % I;
21256         if(m > 0){
21257             if(m > (I/2)){
21258                 K = H + (I-m);
21259             }else {
21260                 K = H - m;
21261             }
21262         }
21263         return  Math.max(J, K);
21264     },
21265
21266     
21267     resizeElement : function(){
21268         var  L = this.proxy.getBox();
21269         if(this.updateBox){
21270             this.el.setBox(L, false, this.animate, this.duration, null, this.easing);
21271         }else {
21272             this.el.setSize(L.width, L.height, this.animate, this.duration, null, this.easing);
21273         }
21274
21275         this.updateChildSize();
21276         if(!this.dynamic){
21277             this.proxy.hide();
21278         }
21279         return  L;
21280     },
21281
21282     
21283     constrain : function(v, M, m, mx){
21284         if(v - M < m){
21285             M = v - m;
21286         }else  if(v - M > mx){
21287             M = mx - v;
21288         }
21289         return  M;
21290     },
21291
21292     
21293     onMouseMove : function(e){
21294         if(this.enabled){
21295             try{
21296
21297             if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
21298                 return;
21299             }
21300
21301             
21302             var  curSize = this.curSize || this.startBox;
21303             var  x = this.startBox.x, y = this.startBox.y;
21304             var  ox = x, oy = y;
21305             var  w = curSize.width, h = curSize.height;
21306             var  ow = w, oh = h;
21307             var  mw = this.minWidth, mh = this.minHeight;
21308             var  mxw = this.maxWidth, mxh = this.maxHeight;
21309             var  wi = this.widthIncrement;
21310             var  hi = this.heightIncrement;
21311
21312             var  eventXY = e.getXY();
21313             var  diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
21314             var  diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
21315
21316             var  pos = this.activeHandle.position;
21317
21318             switch(pos){
21319                 case  "east":
21320                     w += diffX;
21321                     w = Math.min(Math.max(mw, w), mxw);
21322                     break;
21323                 case  "south":
21324                     h += diffY;
21325                     h = Math.min(Math.max(mh, h), mxh);
21326                     break;
21327                 case  "southeast":
21328                     w += diffX;
21329                     h += diffY;
21330                     w = Math.min(Math.max(mw, w), mxw);
21331                     h = Math.min(Math.max(mh, h), mxh);
21332                     break;
21333                 case  "north":
21334                     diffY = this.constrain(h, diffY, mh, mxh);
21335                     y += diffY;
21336                     h -= diffY;
21337                     break;
21338                 case  "west":
21339                     diffX = this.constrain(w, diffX, mw, mxw);
21340                     x += diffX;
21341                     w -= diffX;
21342                     break;
21343                 case  "northeast":
21344                     w += diffX;
21345                     w = Math.min(Math.max(mw, w), mxw);
21346                     diffY = this.constrain(h, diffY, mh, mxh);
21347                     y += diffY;
21348                     h -= diffY;
21349                     break;
21350                 case  "northwest":
21351                     diffX = this.constrain(w, diffX, mw, mxw);
21352                     diffY = this.constrain(h, diffY, mh, mxh);
21353                     y += diffY;
21354                     h -= diffY;
21355                     x += diffX;
21356                     w -= diffX;
21357                     break;
21358                case  "southwest":
21359                     diffX = this.constrain(w, diffX, mw, mxw);
21360                     h += diffY;
21361                     h = Math.min(Math.max(mh, h), mxh);
21362                     x += diffX;
21363                     w -= diffX;
21364                     break;
21365             }
21366
21367             var  sw = this.snap(w, wi, mw);
21368             var  sh = this.snap(h, hi, mh);
21369             if(sw != w || sh != h){
21370                 switch(pos){
21371                     case  "northeast":
21372                         y -= sh - h;
21373                     break;
21374                     case  "north":
21375                         y -= sh - h;
21376                         break;
21377                     case  "southwest":
21378                         x -= sw - w;
21379                     break;
21380                     case  "west":
21381                         x -= sw - w;
21382                         break;
21383                     case  "northwest":
21384                         x -= sw - w;
21385                         y -= sh - h;
21386                     break;
21387                 }
21388
21389                 w = sw;
21390                 h = sh;
21391             }
21392
21393             if(this.preserveRatio){
21394                 switch(pos){
21395                     case  "southeast":
21396                     case  "east":
21397                         h = oh * (w/ow);
21398                         h = Math.min(Math.max(mh, h), mxh);
21399                         w = ow * (h/oh);
21400                        break;
21401                     case  "south":
21402                         w = ow * (h/oh);
21403                         w = Math.min(Math.max(mw, w), mxw);
21404                         h = oh * (w/ow);
21405                         break;
21406                     case  "northeast":
21407                         w = ow * (h/oh);
21408                         w = Math.min(Math.max(mw, w), mxw);
21409                         h = oh * (w/ow);
21410                     break;
21411                     case  "north":
21412                         var  tw = w;
21413                         w = ow * (h/oh);
21414                         w = Math.min(Math.max(mw, w), mxw);
21415                         h = oh * (w/ow);
21416                         x += (tw - w) / 2;
21417                         break;
21418                     case  "southwest":
21419                         h = oh * (w/ow);
21420                         h = Math.min(Math.max(mh, h), mxh);
21421                         var  tw = w;
21422                         w = ow * (h/oh);
21423                         x += tw - w;
21424                         break;
21425                     case  "west":
21426                         var  th = h;
21427                         h = oh * (w/ow);
21428                         h = Math.min(Math.max(mh, h), mxh);
21429                         y += (th - h) / 2;
21430                         var  tw = w;
21431                         w = ow * (h/oh);
21432                         x += tw - w;
21433                        break;
21434                     case  "northwest":
21435                         var  tw = w;
21436                         var  th = h;
21437                         h = oh * (w/ow);
21438                         h = Math.min(Math.max(mh, h), mxh);
21439                         w = ow * (h/oh);
21440                         y += th - h;
21441                          x += tw - w;
21442                        break;
21443
21444                 }
21445             }
21446
21447             this.proxy.setBounds(x, y, w, h);
21448             if(this.dynamic){
21449                 this.resizeElement();
21450             }
21451             }catch(e){}
21452         }
21453     },
21454
21455     
21456     handleOver : function(){
21457         if(this.enabled){
21458             this.el.addClass("x-resizable-over");
21459         }
21460     },
21461
21462     
21463     handleOut : function(){
21464         if(!this.resizing){
21465             this.el.removeClass("x-resizable-over");
21466         }
21467     },
21468
21469     
21470
21471     getEl : function(){
21472         return  this.el;
21473     },
21474
21475     
21476
21477     getResizeChild : function(){
21478         return  this.resizeChild;
21479     },
21480
21481     
21482
21483     destroy : function(N){
21484         this.proxy.remove();
21485         if(this.overlay){
21486             this.overlay.removeAllListeners();
21487             this.overlay.remove();
21488         }
21489         var  ps = Roo.Resizable.positions;
21490         for(var  k  in  ps){
21491             if(typeof  ps[k] != "function" && this[ps[k]]){
21492                 var  h = this[ps[k]];
21493                 h.el.removeAllListeners();
21494                 h.el.remove();
21495             }
21496         }
21497         if(N){
21498             this.el.update("");
21499             this.el.remove();
21500         }
21501     }
21502 });
21503
21504
21505
21506 Roo.Resizable.positions = {
21507     n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast"
21508 };
21509
21510
21511 Roo.Resizable.Handle = function(rz, O, P, Q){
21512     if(!this.tpl){
21513         
21514         var  tpl = Roo.DomHelper.createTemplate(
21515             {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
21516         );
21517         tpl.compile();
21518         Roo.Resizable.Handle.prototype.tpl = tpl;
21519     }
21520
21521     this.position = O;
21522     this.rz = rz;
21523     this.el = this.tpl.append(rz.el.dom, [this.position], true);
21524     this.el.unselectable();
21525     if(Q){
21526         this.el.setOpacity(0);
21527     }
21528
21529     this.el.on("mousedown", this.onMouseDown, this);
21530     if(!P){
21531         this.el.on("mouseover", this.onMouseOver, this);
21532         this.el.on("mouseout", this.onMouseOut, this);
21533     }
21534 };
21535
21536
21537 Roo.Resizable.Handle.prototype = {
21538     afterResize : function(rz){
21539         
21540     },
21541     
21542     onMouseDown : function(e){
21543         this.rz.onMouseDown(this, e);
21544     },
21545     
21546     onMouseOver : function(e){
21547         this.rz.handleOver(this, e);
21548     },
21549     
21550     onMouseOut : function(e){
21551         this.rz.handleOut(this, e);
21552     }
21553 };
21554
21555
21556
21557
21558
21559 Roo.Editor = function(A, B){
21560     Roo.Editor.superclass.constructor.call(this, B);
21561     this.field = A;
21562     this.addEvents({
21563         
21564
21565         "beforestartedit" : true,
21566         
21567
21568         "startedit" : true,
21569         
21570
21571         "beforecomplete" : true,
21572         
21573
21574         "complete" : true,
21575         
21576
21577         "specialkey" : true
21578     });
21579 };
21580
21581 Roo.extend(Roo.Editor, Roo.Component, {
21582     
21583
21584     
21585
21586     
21587
21588     
21589
21590     
21591
21592     value : "",
21593     
21594
21595     alignment: "c-c?",
21596     
21597
21598     shadow : "frame",
21599     
21600
21601     constrain : false,
21602     
21603
21604     completeOnEnter : false,
21605     
21606
21607     cancelOnEsc : false,
21608     
21609
21610     updateEl : false,
21611
21612     
21613     onRender : function(ct, C){
21614         this.el = new  Roo.Layer({
21615             shadow: this.shadow,
21616             cls: "x-editor",
21617             parentEl : ct,
21618             shim : this.shim,
21619             shadowOffset:4,
21620             id: this.id,
21621             constrain: this.constrain
21622         });
21623         this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
21624         if(this.field.msgTarget != 'title'){
21625             this.field.msgTarget = 'qtip';
21626         }
21627
21628         this.field.render(this.el);
21629         if(Roo.isGecko){
21630             this.field.el.dom.setAttribute('autocomplete', 'off');
21631         }
21632
21633         this.field.on("specialkey", this.onSpecialKey, this);
21634         if(this.swallowKeys){
21635             this.field.el.swallowEvent(['keydown','keypress']);
21636         }
21637
21638         this.field.show();
21639         this.field.on("blur", this.onBlur, this);
21640         if(this.field.grow){
21641             this.field.on("autosize", this.el.sync,  this.el, {delay:1});
21642         }
21643     },
21644
21645     onSpecialKey : function(D, e){
21646         if(this.completeOnEnter && e.getKey() == e.ENTER){
21647             e.stopEvent();
21648             this.completeEdit();
21649         }else  if(this.cancelOnEsc && e.getKey() == e.ESC){
21650             this.cancelEdit();
21651         }else {
21652             this.fireEvent('specialkey', D, e);
21653         }
21654     },
21655
21656     
21657
21658     startEdit : function(el, E){
21659         if(this.editing){
21660             this.completeEdit();
21661         }
21662
21663         this.boundEl = Roo.get(el);
21664         var  v = E !== undefined ? E : this.boundEl.dom.innerHTML;
21665         if(!this.rendered){
21666             this.render(this.parentEl || document.body);
21667         }
21668         if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
21669             return;
21670         }
21671
21672         this.startValue = v;
21673         this.field.setValue(v);
21674         if(this.autoSize){
21675             var  sz = this.boundEl.getSize();
21676             switch(this.autoSize){
21677                 case  "width":
21678                 this.setSize(sz.width,  "");
21679                 break;
21680                 case  "height":
21681                 this.setSize("",  sz.height);
21682                 break;
21683                 default:
21684                 this.setSize(sz.width,  sz.height);
21685             }
21686         }
21687
21688         this.el.alignTo(this.boundEl, this.alignment);
21689         this.editing = true;
21690         if(Roo.QuickTips){
21691             Roo.QuickTips.disable();
21692         }
21693
21694         this.show();
21695     },
21696
21697     
21698
21699     setSize : function(w, h){
21700         this.field.setSize(w, h);
21701         if(this.el){
21702             this.el.sync();
21703         }
21704     },
21705
21706     
21707
21708     realign : function(){
21709         this.el.alignTo(this.boundEl, this.alignment);
21710     },
21711
21712     
21713
21714     completeEdit : function(F){
21715         if(!this.editing){
21716             return;
21717         }
21718         var  v = this.getValue();
21719         if(this.revertInvalid !== false && !this.field.isValid()){
21720             v = this.startValue;
21721             this.cancelEdit(true);
21722         }
21723         if(String(v) === String(this.startValue) && this.ignoreNoChange){
21724             this.editing = false;
21725             this.hide();
21726             return;
21727         }
21728         if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
21729             this.editing = false;
21730             if(this.updateEl && this.boundEl){
21731                 this.boundEl.update(v);
21732             }
21733             if(F !== true){
21734                 this.hide();
21735             }
21736
21737             this.fireEvent("complete", this, v, this.startValue);
21738         }
21739     },
21740
21741     
21742     onShow : function(){
21743         this.el.show();
21744         if(this.hideEl !== false){
21745             this.boundEl.hide();
21746         }
21747
21748         this.field.show();
21749         if(Roo.isIE && !this.fixIEFocus){ 
21750             this.fixIEFocus = true;
21751             this.deferredFocus.defer(50, this);
21752         }else {
21753             this.field.focus();
21754         }
21755
21756         this.fireEvent("startedit", this.boundEl, this.startValue);
21757     },
21758
21759     deferredFocus : function(){
21760         if(this.editing){
21761             this.field.focus();
21762         }
21763     },
21764
21765     
21766
21767     cancelEdit : function(G){
21768         if(this.editing){
21769             this.setValue(this.startValue);
21770             if(G !== true){
21771                 this.hide();
21772             }
21773         }
21774     },
21775
21776     
21777     onBlur : function(){
21778         if(this.allowBlur !== true && this.editing){
21779             this.completeEdit();
21780         }
21781     },
21782
21783     
21784     onHide : function(){
21785         if(this.editing){
21786             this.completeEdit();
21787             return;
21788         }
21789
21790         this.field.blur();
21791         if(this.field.collapse){
21792             this.field.collapse();
21793         }
21794
21795         this.el.hide();
21796         if(this.hideEl !== false){
21797             this.boundEl.show();
21798         }
21799         if(Roo.QuickTips){
21800             Roo.QuickTips.enable();
21801         }
21802     },
21803
21804     
21805
21806     setValue : function(v){
21807         this.field.setValue(v);
21808     },
21809
21810     
21811
21812     getValue : function(){
21813         return  this.field.getValue();
21814     }
21815 });
21816
21817
21818  
21819
21820
21821 Roo.BasicDialog = function(el, A){
21822     this.el = Roo.get(el);
21823     var  dh = Roo.DomHelper;
21824     if(!this.el && A && A.autoCreate){
21825         if(typeof  A.autoCreate == "object"){
21826             if(!A.autoCreate.id){
21827                 A.autoCreate.id = el;
21828             }
21829
21830             this.el = dh.append(document.body,
21831                         A.autoCreate, true);
21832         }else {
21833             this.el = dh.append(document.body,
21834                         {tag: "div", id: el, style:'visibility:hidden;'}, true);
21835         }
21836     }
21837
21838     el = this.el;
21839     el.setDisplayed(true);
21840     el.hide = this.hideAction;
21841     this.id = el.id;
21842     el.addClass("x-dlg");
21843
21844     Roo.apply(this, A);
21845
21846     this.proxy = el.createProxy("x-dlg-proxy");
21847     this.proxy.hide = this.hideAction;
21848     this.proxy.setOpacity(.5);
21849     this.proxy.hide();
21850
21851     if(A.width){
21852         el.setWidth(A.width);
21853     }
21854     if(A.height){
21855         el.setHeight(A.height);
21856     }
21857
21858     this.size = el.getSize();
21859     if(typeof  A.x != "undefined" && typeof  A.y != "undefined"){
21860         this.xy = [A.x,A.y];
21861     }else {
21862         this.xy = el.getCenterXY(true);
21863     }
21864
21865     
21866
21867     this.header = el.child("> .x-dlg-hd");
21868     
21869
21870     this.body = el.child("> .x-dlg-bd");
21871     
21872
21873     this.footer = el.child("> .x-dlg-ft");
21874
21875     if(!this.header){
21876         this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: "&#160;"}, this.body ? this.body.dom : null);
21877     }
21878     if(!this.body){
21879         this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
21880     }
21881
21882
21883     this.header.unselectable();
21884     if(this.title){
21885         this.header.update(this.title);
21886     }
21887
21888     
21889     this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
21890     this.focusEl.swallowEvent("click", true);
21891
21892     this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
21893
21894     
21895     this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
21896     if(this.footer){
21897         this.bwrap.dom.appendChild(this.footer.dom);
21898     }
21899
21900
21901     this.bg = this.el.createChild({
21902         tag: "div", cls:"x-dlg-bg",
21903         html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center">&#160;</div></div></div>'
21904     });
21905     this.centerBg = this.bg.child("div.x-dlg-bg-center");
21906
21907
21908     if(this.autoScroll !== false && !this.autoTabs){
21909         this.body.setStyle("overflow", "auto");
21910     }
21911
21912
21913     this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
21914
21915     if(this.closable !== false){
21916         this.el.addClass("x-dlg-closable");
21917         this.close = this.toolbox.createChild({cls:"x-dlg-close"});
21918         this.close.on("click", this.closeClick, this);
21919         this.close.addClassOnOver("x-dlg-close-over");
21920     }
21921     if(this.collapsible !== false){
21922         this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
21923         this.collapseBtn.on("click", this.collapseClick, this);
21924         this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
21925         this.header.on("dblclick", this.collapseClick, this);
21926     }
21927     if(this.resizable !== false){
21928         this.el.addClass("x-dlg-resizable");
21929         this.resizer = new  Roo.Resizable(el, {
21930             minWidth: this.minWidth || 80,
21931             minHeight:this.minHeight || 80,
21932             handles: this.resizeHandles || "all",
21933             pinned: true
21934         });
21935         this.resizer.on("beforeresize", this.beforeResize, this);
21936         this.resizer.on("resize", this.onResize, this);
21937     }
21938     if(this.draggable !== false){
21939         el.addClass("x-dlg-draggable");
21940         if (!this.proxyDrag) {
21941             var  dd = new  Roo.dd.DD(el.dom.id, "WindowDrag");
21942         }
21943         else  {
21944             var  dd = new  Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
21945         }
21946
21947         dd.setHandleElId(this.header.id);
21948         dd.endDrag = this.endMove.createDelegate(this);
21949         dd.startDrag = this.startMove.createDelegate(this);
21950         dd.onDrag = this.onDrag.createDelegate(this);
21951         dd.scroll = false;
21952         this.dd = dd;
21953     }
21954     if(this.modal){
21955         this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
21956         this.mask.enableDisplayMode("block");
21957         this.mask.hide();
21958         this.el.addClass("x-dlg-modal");
21959     }
21960     if(this.shadow){
21961         this.shadow = new  Roo.Shadow({
21962             mode : typeof  this.shadow == "string" ? this.shadow : "sides",
21963             offset : this.shadowOffset
21964         });
21965     }else {
21966         this.shadowOffset = 0;
21967     }
21968     if(Roo.useShims && this.shim !== false){
21969         this.shim = this.el.createShim();
21970         this.shim.hide = this.hideAction;
21971         this.shim.hide();
21972     }else {
21973         this.shim = false;
21974     }
21975     if(this.autoTabs){
21976         this.initTabs();
21977     }
21978     if (this.buttons) { 
21979         var  bts= this.buttons;
21980         this.buttons = [];
21981         Roo.each(bts, function(b) {
21982             this.addButton(b);
21983         }, this);
21984     }
21985
21986     
21987     
21988     this.addEvents({
21989         
21990
21991         "keydown" : true,
21992         
21993
21994         "move" : true,
21995         
21996
21997         "resize" : true,
21998         
21999
22000         "beforehide" : true,
22001         
22002
22003         "hide" : true,
22004         
22005
22006         "beforeshow" : true,
22007         
22008
22009         "show" : true
22010     });
22011     el.on("keydown", this.onKeyDown, this);
22012     el.on("mousedown", this.toFront, this);
22013     Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
22014     this.el.hide();
22015     Roo.DialogManager.register(this);
22016     Roo.BasicDialog.superclass.constructor.call(this);
22017 };
22018
22019 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
22020     shadowOffset: Roo.isIE ? 6 : 5,
22021     minHeight: 80,
22022     minWidth: 200,
22023     minButtonWidth: 75,
22024     defaultButton: null,
22025     buttonAlign: "right",
22026     tabTag: 'div',
22027     firstShow: true,
22028
22029     
22030
22031     setTitle : function(B){
22032         this.header.update(B);
22033         return  this;
22034     },
22035
22036     
22037     closeClick : function(){
22038         this.hide();
22039     },
22040
22041     
22042     collapseClick : function(){
22043         this[this.collapsed ? "expand" : "collapse"]();
22044     },
22045
22046     
22047
22048     collapse : function(){
22049         if(!this.collapsed){
22050             this.collapsed = true;
22051             this.el.addClass("x-dlg-collapsed");
22052             this.restoreHeight = this.el.getHeight();
22053             this.resizeTo(this.el.getWidth(), this.header.getHeight());
22054         }
22055     },
22056
22057     
22058
22059     expand : function(){
22060         if(this.collapsed){
22061             this.collapsed = false;
22062             this.el.removeClass("x-dlg-collapsed");
22063             this.resizeTo(this.el.getWidth(), this.restoreHeight);
22064         }
22065     },
22066
22067     
22068
22069     initTabs : function(){
22070         var  C = this.getTabs();
22071         while(C.getTab(0)){
22072             C.removeTab(0);
22073         }
22074
22075         this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
22076             var  D = el.dom;
22077             C.addTab(Roo.id(D), D.title);
22078             D.title = "";
22079         });
22080         C.activate(0);
22081         return  C;
22082     },
22083
22084     
22085     beforeResize : function(){
22086         this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
22087     },
22088
22089     
22090     onResize : function(){
22091         this.refreshSize();
22092         this.syncBodyHeight();
22093         this.adjustAssets();
22094         this.focus();
22095         this.fireEvent("resize", this, this.size.width, this.size.height);
22096     },
22097
22098     
22099     onKeyDown : function(e){
22100         if(this.isVisible()){
22101             this.fireEvent("keydown", this, e);
22102         }
22103     },
22104
22105     
22106
22107     resizeTo : function(D, E){
22108         this.el.setSize(D, E);
22109         this.size = {width: D, height: E};
22110         this.syncBodyHeight();
22111         if(this.fixedcenter){
22112             this.center();
22113         }
22114         if(this.isVisible()){
22115             this.constrainXY();
22116             this.adjustAssets();
22117         }
22118
22119         this.fireEvent("resize", this, D, E);
22120         return  this;
22121     },
22122
22123
22124     
22125
22126     setContentSize : function(w, h){
22127         h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
22128         w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
22129         
22130             h +=  this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
22131             w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
22132         
22133         if(this.tabs){
22134             h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
22135             w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
22136         }
22137
22138         this.resizeTo(w, h);
22139         return  this;
22140     },
22141
22142     
22143
22144     addKeyListener : function(F, fn, G){
22145         var  H, I, J, K;
22146         if(typeof  F == "object" && !(F  instanceof  Array)){
22147             H = F["key"];
22148             I = F["shift"];
22149             J = F["ctrl"];
22150             K = F["alt"];
22151         }else {
22152             H = F;
22153         }
22154         var  L = function(M, e){
22155             if((!I || e.shiftKey) && (!J || e.ctrlKey) &&  (!K || e.altKey)){
22156                 var  k = e.getKey();
22157                 if(H  instanceof  Array){
22158                     for(var  i = 0, len = H.length; i < len; i++){
22159                         if(H[i] == k){
22160                           fn.call(G || window, M, k, e);
22161                           return;
22162                         }
22163                     }
22164                 }else {
22165                     if(k == H){
22166                         fn.call(G || window, M, k, e);
22167                     }
22168                 }
22169             }
22170         };
22171         this.on("keydown", L);
22172         return  this;
22173     },
22174
22175     
22176
22177     getTabs : function(){
22178         if(!this.tabs){
22179             this.el.addClass("x-dlg-auto-tabs");
22180             this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
22181             this.tabs = new  Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
22182         }
22183         return  this.tabs;
22184     },
22185
22186     
22187
22188     addButton : function(M, N, O){
22189         var  dh = Roo.DomHelper;
22190         if(!this.footer){
22191             this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
22192         }
22193         if(!this.btnContainer){
22194             var  tb = this.footer.createChild({
22195
22196                 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
22197                 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
22198             }, null, true);
22199             this.btnContainer = tb.firstChild.firstChild.firstChild;
22200         }
22201         var  P = {
22202             handler: N,
22203             scope: O,
22204             minWidth: this.minButtonWidth,
22205             hideParent:true
22206         };
22207         if(typeof  M == "string"){
22208             P.text = M;
22209         }else {
22210             if(M.tag){
22211                 P.dhconfig = M;
22212             }else {
22213                 Roo.apply(P, M);
22214             }
22215         }
22216         var  fc = false;
22217         if ((typeof(P.position) != 'undefined') && P.position < this.btnContainer.childNodes.length-1) {
22218             P.position = Math.max(0, P.position);
22219             fc = this.btnContainer.childNodes[P.position];
22220         }
22221          
22222         var  Q = new  Roo.Button(
22223             fc ? 
22224                 this.btnContainer.insertBefore(document.createElement("td"),fc)
22225                 : this.btnContainer.appendChild(document.createElement("td")),
22226             
22227             P
22228         );
22229         this.syncBodyHeight();
22230         if(!this.buttons){
22231             
22232
22233             this.buttons = [];
22234         }
22235
22236         this.buttons.push(Q);
22237         return  Q;
22238     },
22239
22240     
22241
22242     setDefaultButton : function(R){
22243         this.defaultButton = R;
22244         return  this;
22245     },
22246
22247     
22248     getHeaderFooterHeight : function(S){
22249         var  T = 0;
22250         if(this.header){
22251            T += this.header.getHeight();
22252         }
22253         if(this.footer){
22254            var  fm = this.footer.getMargins();
22255             T += (this.footer.getHeight()+fm.top+fm.bottom);
22256         }
22257
22258         T += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
22259         T += this.centerBg.getPadding("tb");
22260         return  T;
22261     },
22262
22263     
22264     syncBodyHeight : function(){
22265         var  bd = this.body, cb = this.centerBg, bw = this.bwrap;
22266         var  U = this.size.height - this.getHeaderFooterHeight(false);
22267         bd.setHeight(U-bd.getMargins("tb"));
22268         var  hh = this.header.getHeight();
22269         var  h = this.size.height-hh;
22270         cb.setHeight(h);
22271         bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
22272         bw.setHeight(h-cb.getPadding("tb"));
22273         bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
22274         bd.setWidth(bw.getWidth(true));
22275         if(this.tabs){
22276             this.tabs.syncHeight();
22277             if(Roo.isIE){
22278                 this.tabs.el.repaint();
22279             }
22280         }
22281     },
22282
22283     
22284
22285     restoreState : function(){
22286         var  V = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
22287         if(V && V.width){
22288             this.xy = [V.x, V.y];
22289             this.resizeTo(V.width, V.height);
22290         }
22291         return  this;
22292     },
22293
22294     
22295     beforeShow : function(){
22296         this.expand();
22297         if(this.fixedcenter){
22298             this.xy = this.el.getCenterXY(true);
22299         }
22300         if(this.modal){
22301             Roo.get(document.body).addClass("x-body-masked");
22302             this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
22303             this.mask.show();
22304         }
22305
22306         this.constrainXY();
22307     },
22308
22309     
22310     animShow : function(){
22311         var  b = Roo.get(this.animateTarget, true).getBox();
22312         this.proxy.setSize(b.width, b.height);
22313         this.proxy.setLocation(b.x, b.y);
22314         this.proxy.show();
22315         this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
22316                     true, .35, this.showEl.createDelegate(this));
22317     },
22318
22319     
22320
22321     show : function(W){
22322         if (this.fireEvent("beforeshow", this) === false){
22323             return;
22324         }
22325         if(this.syncHeightBeforeShow){
22326             this.syncBodyHeight();
22327         }else  if(this.firstShow){
22328             this.firstShow = false;
22329             this.syncBodyHeight(); 
22330         }
22331
22332         this.animateTarget = W || this.animateTarget;
22333         if(!this.el.isVisible()){
22334             this.beforeShow();
22335             if(this.animateTarget){
22336                 this.animShow();
22337             }else {
22338                 this.showEl();
22339             }
22340         }
22341         return  this;
22342     },
22343
22344     
22345     showEl : function(){
22346         this.proxy.hide();
22347         this.el.setXY(this.xy);
22348         this.el.show();
22349         this.adjustAssets(true);
22350         this.toFront();
22351         this.focus();
22352         
22353         if(Roo.isIE){
22354             this.el.repaint();
22355         }
22356
22357         this.fireEvent("show", this);
22358     },
22359
22360     
22361
22362     focus : function(){
22363         if(this.defaultButton){
22364             this.defaultButton.focus();
22365         }else {
22366             this.focusEl.focus();
22367         }
22368     },
22369
22370     
22371     constrainXY : function(){
22372         if(this.constraintoviewport !== false){
22373             if(!this.viewSize){
22374                 if(this.container){
22375                     var  s = this.container.getSize();
22376                     this.viewSize = [s.width, s.height];
22377                 }else {
22378                     this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
22379                 }
22380             }
22381             var  s = Roo.get(this.container||document).getScroll();
22382
22383             var  x = this.xy[0], y = this.xy[1];
22384             var  w = this.size.width, h = this.size.height;
22385             var  vw = this.viewSize[0], vh = this.viewSize[1];
22386             
22387             var  moved = false;
22388             
22389             if(x + w > vw+s.left){
22390                 x = vw - w;
22391                 moved = true;
22392             }
22393             if(y + h > vh+s.top){
22394                 y = vh - h;
22395                 moved = true;
22396             }
22397             
22398             if(x < s.left){
22399                 x = s.left;
22400                 moved = true;
22401             }
22402             if(y < s.top){
22403                 y = s.top;
22404                 moved = true;
22405             }
22406             if(moved){
22407                 
22408                 this.xy = [x, y];
22409                 if(this.isVisible()){
22410                     this.el.setLocation(x, y);
22411                     this.adjustAssets();
22412                 }
22413             }
22414         }
22415     },
22416
22417     
22418     onDrag : function(){
22419         if(!this.proxyDrag){
22420             this.xy = this.el.getXY();
22421             this.adjustAssets();
22422         }
22423     },
22424
22425     
22426     adjustAssets : function(X){
22427         var  x = this.xy[0], y = this.xy[1];
22428         var  w = this.size.width, h = this.size.height;
22429         if(X === true){
22430             if(this.shadow){
22431                 this.shadow.show(this.el);
22432             }
22433             if(this.shim){
22434                 this.shim.show();
22435             }
22436         }
22437         if(this.shadow && this.shadow.isVisible()){
22438             this.shadow.show(this.el);
22439         }
22440         if(this.shim && this.shim.isVisible()){
22441             this.shim.setBounds(x, y, w, h);
22442         }
22443     },
22444
22445     
22446     adjustViewport : function(w, h){
22447         if(!w || !h){
22448             w = Roo.lib.Dom.getViewWidth();
22449             h = Roo.lib.Dom.getViewHeight();
22450         }
22451
22452         
22453         this.viewSize = [w, h];
22454         if(this.modal && this.mask.isVisible()){
22455             this.mask.setSize(w, h); 
22456             this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
22457         }
22458         if(this.isVisible()){
22459             this.constrainXY();
22460         }
22461     },
22462
22463     
22464
22465     destroy : function(Y){
22466         if(this.isVisible()){
22467             this.animateTarget = null;
22468             this.hide();
22469         }
22470
22471         Roo.EventManager.removeResizeListener(this.adjustViewport, this);
22472         if(this.tabs){
22473             this.tabs.destroy(Y);
22474         }
22475
22476         Roo.destroy(
22477              this.shim,
22478              this.proxy,
22479              this.resizer,
22480              this.close,
22481              this.mask
22482         );
22483         if(this.dd){
22484             this.dd.unreg();
22485         }
22486         if(this.buttons){
22487            for(var  i = 0, len = this.buttons.length; i < len; i++){
22488                this.buttons[i].destroy();
22489            }
22490         }
22491
22492         this.el.removeAllListeners();
22493         if(Y === true){
22494             this.el.update("");
22495             this.el.remove();
22496         }
22497
22498         Roo.DialogManager.unregister(this);
22499     },
22500
22501     
22502     startMove : function(){
22503         if(this.proxyDrag){
22504             this.proxy.show();
22505         }
22506         if(this.constraintoviewport !== false){
22507             this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
22508         }
22509     },
22510
22511     
22512     endMove : function(){
22513         if(!this.proxyDrag){
22514             Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
22515         }else {
22516             Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
22517             this.proxy.hide();
22518         }
22519
22520         this.refreshSize();
22521         this.adjustAssets();
22522         this.focus();
22523         this.fireEvent("move", this, this.xy[0], this.xy[1]);
22524     },
22525
22526     
22527
22528     toFront : function(){
22529         Roo.DialogManager.bringToFront(this);
22530         return  this;
22531     },
22532
22533     
22534
22535     toBack : function(){
22536         Roo.DialogManager.sendToBack(this);
22537         return  this;
22538     },
22539
22540     
22541
22542     center : function(){
22543         var  xy = this.el.getCenterXY(true);
22544         this.moveTo(xy[0], xy[1]);
22545         return  this;
22546     },
22547
22548     
22549
22550     moveTo : function(x, y){
22551         this.xy = [x,y];
22552         if(this.isVisible()){
22553             this.el.setXY(this.xy);
22554             this.adjustAssets();
22555         }
22556         return  this;
22557     },
22558
22559     
22560
22561     alignTo : function(Z, a, c){
22562         this.xy = this.el.getAlignToXY(Z, a, c);
22563         if(this.isVisible()){
22564             this.el.setXY(this.xy);
22565             this.adjustAssets();
22566         }
22567         return  this;
22568     },
22569
22570     
22571
22572     anchorTo : function(el, d, f, g){
22573         var  j = function(){
22574             this.alignTo(el, d, f);
22575         };
22576         Roo.EventManager.onWindowResize(j, this);
22577         var  tm = typeof  g;
22578         if(tm != 'undefined'){
22579             Roo.EventManager.on(window, 'scroll', j, this,
22580                 {buffer: tm == 'number' ? g : 50});
22581         }
22582
22583         j.call(this);
22584         return  this;
22585     },
22586
22587     
22588
22589     isVisible : function(){
22590         return  this.el.isVisible();
22591     },
22592
22593     
22594     animHide : function(l){
22595         var  b = Roo.get(this.animateTarget).getBox();
22596         this.proxy.show();
22597         this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
22598         this.el.hide();
22599         this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
22600                     this.hideEl.createDelegate(this, [l]));
22601     },
22602
22603     
22604
22605     hide : function(m){
22606         if (this.fireEvent("beforehide", this) === false){
22607             return;
22608         }
22609         if(this.shadow){
22610             this.shadow.hide();
22611         }
22612         if(this.shim) {
22613           this.shim.hide();
22614         }
22615         if(this.animateTarget){
22616            this.animHide(m);
22617         }else {
22618             this.el.hide();
22619             this.hideEl(m);
22620         }
22621         return  this;
22622     },
22623
22624     
22625     hideEl : function(n){
22626         this.proxy.hide();
22627         if(this.modal){
22628             this.mask.hide();
22629             Roo.get(document.body).removeClass("x-body-masked");
22630         }
22631
22632         this.fireEvent("hide", this);
22633         if(typeof  n == "function"){
22634             n();
22635         }
22636     },
22637
22638     
22639     hideAction : function(){
22640         this.setLeft("-10000px");
22641         this.setTop("-10000px");
22642         this.setStyle("visibility", "hidden");
22643     },
22644
22645     
22646     refreshSize : function(){
22647         this.size = this.el.getSize();
22648         this.xy = this.el.getXY();
22649         Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
22650     },
22651
22652     
22653     
22654     setZIndex : function(o){
22655         if(this.modal){
22656             this.mask.setStyle("z-index", o);
22657         }
22658         if(this.shim){
22659             this.shim.setStyle("z-index", ++o);
22660         }
22661         if(this.shadow){
22662             this.shadow.setZIndex(++o);
22663         }
22664
22665         this.el.setStyle("z-index", ++o);
22666         if(this.proxy){
22667             this.proxy.setStyle("z-index", ++o);
22668         }
22669         if(this.resizer){
22670             this.resizer.proxy.setStyle("z-index", ++o);
22671         }
22672
22673
22674         this.lastZIndex = o;
22675     },
22676
22677     
22678
22679     getEl : function(){
22680         return  this.el;
22681     }
22682 });
22683
22684
22685
22686 Roo.DialogManager = function(){
22687     var  p = {};
22688     var  q = [];
22689     var  r = null;
22690
22691     
22692     var  t = function(d1, d2){
22693         return  (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
22694     };
22695
22696     
22697     var  u = function(){
22698         q.sort(t);
22699         var  v = Roo.DialogManager.zseed;
22700         for(var  i = 0, len = q.length; i < len; i++){
22701             var  dlg = q[i];
22702             if(dlg){
22703                 dlg.setZIndex(v + (i*10));
22704             }
22705         }
22706     };
22707
22708     return  {
22709         
22710
22711         zseed : 9000,
22712
22713         
22714         register : function(AD){
22715             p[AD.id] = AD;
22716             q.push(AD);
22717         },
22718
22719         
22720         unregister : function(AE){
22721             delete  p[AE.id];
22722             var  i=0;
22723             var  AF=0;
22724             if(!q.indexOf){
22725                 for(  i = 0, AF = q.length; i < AF; i++){
22726                     if(q[i] == AE){
22727                         q.splice(i, 1);
22728                         return;
22729                     }
22730                 }
22731             }else {
22732                  i = q.indexOf(AE);
22733                 if(i != -1){
22734                     q.splice(i, 1);
22735                 }
22736             }
22737         },
22738
22739         
22740
22741         get : function(id){
22742             return  typeof  id == "object" ? id : p[id];
22743         },
22744
22745         
22746
22747         bringToFront : function(AG){
22748             AG = this.get(AG);
22749             if(AG != r){
22750                 r = AG;
22751                 AG._lastAccess = new  Date().getTime();
22752                 u();
22753             }
22754             return  AG;
22755         },
22756
22757         
22758
22759         sendToBack : function(AH){
22760             AH = this.get(AH);
22761             AH._lastAccess = -(new  Date().getTime());
22762             u();
22763             return  AH;
22764         },
22765
22766         
22767
22768         hideAll : function(){
22769             for(var  id  in  p){
22770                 if(p[id] && typeof  p[id] != "function" && p[id].isVisible()){
22771                     p[id].hide();
22772                 }
22773             }
22774         }
22775     };
22776 }();
22777
22778
22779
22780 Roo.LayoutDialog = function(el, v){
22781     
22782     var  z=  v;
22783     if (typeof(v) == 'undefined') {
22784         z = Roo.apply({}, el);
22785         el = Roo.get( document.documentElement || document.body).createChild();
22786         
22787     }
22788
22789     
22790     
22791     z.autoTabs = false;
22792     Roo.LayoutDialog.superclass.constructor.call(this, el, z);
22793     this.body.setStyle({overflow:"hidden", position:"relative"});
22794     this.layout = new  Roo.BorderLayout(this.body.dom, z);
22795     this.layout.monitorWindowResize = false;
22796     this.el.addClass("x-dlg-auto-layout");
22797     
22798     this.center = Roo.BasicDialog.prototype.center;
22799     this.on("show", this.layout.layout, this.layout, true);
22800     if (z.items) {
22801         var  xitems = z.items;
22802         delete  z.items;
22803         Roo.each(xitems, this.addxtype, this);
22804     }
22805     
22806     
22807 };
22808 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
22809     
22810
22811     endUpdate : function(){
22812         this.layout.endUpdate();
22813     },
22814
22815     
22816
22817     beginUpdate : function(){
22818         this.layout.beginUpdate();
22819     },
22820
22821     
22822
22823     getLayout : function(){
22824         return  this.layout;
22825     },
22826
22827     showEl : function(){
22828         Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
22829         if(Roo.isIE7){
22830             this.layout.layout();
22831         }
22832     },
22833
22834     
22835     
22836     syncBodyHeight : function(){
22837         Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
22838         if(this.layout){this.layout.layout();}
22839     },
22840     
22841       
22842
22843     
22844     addxtype : function(c) {
22845         return  this.layout.addxtype(c);
22846     }
22847 });
22848
22849
22850  
22851
22852
22853 Roo.MessageBox = function(){
22854     var  A, B, C, D;
22855     var  E, F, G, H, I, pp;
22856     var  J, K, L;
22857
22858     
22859     var  M = function(Q){
22860         A.hide();
22861         Roo.callback(B.fn, B.scope||window, [Q, K.dom.value], 1);
22862     };
22863
22864     
22865     var  N = function(){
22866         if(B && B.cls){
22867             A.el.removeClass(B.cls);
22868         }
22869         if(D){
22870             Roo.TaskMgr.stop(D);
22871             D = null;
22872         }
22873     };
22874
22875     
22876     var  O = function(b){
22877         var  Q = 0;
22878         if(!b){
22879             J["ok"].hide();
22880             J["cancel"].hide();
22881             J["yes"].hide();
22882             J["no"].hide();
22883             A.footer.dom.style.display = 'none';
22884             return  Q;
22885         }
22886
22887         A.footer.dom.style.display = '';
22888         for(var  k  in  J){
22889             if(typeof  J[k] != "function"){
22890                 if(b[k]){
22891                     J[k].show();
22892                     J[k].setText(typeof  b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
22893                     Q += J[k].el.getWidth()+15;
22894                 }else {
22895                     J[k].hide();
22896                 }
22897             }
22898         }
22899         return  Q;
22900     };
22901
22902     
22903     var  P = function(d, k, e){
22904         if(B && B.closable !== false){
22905             A.hide();
22906         }
22907         if(e){
22908             e.stopEvent();
22909         }
22910     };
22911
22912     return  {
22913         
22914
22915         getDialog : function(){
22916            if(!A){
22917                 A = new  Roo.BasicDialog("x-msg-box", {
22918                     autoCreate : true,
22919                     shadow: true,
22920                     draggable: true,
22921                     resizable:false,
22922                     constraintoviewport:false,
22923                     fixedcenter:true,
22924                     collapsible : false,
22925                     shim:true,
22926                     modal: true,
22927                     width:400, height:100,
22928                     buttonAlign:"center",
22929                     closeClick : function(){
22930                         if(B && B.buttons && B.buttons.no && !B.buttons.cancel){
22931                             M("no");
22932                         }else {
22933                             M("cancel");
22934                         }
22935                     }
22936                 });
22937                 A.on("hide", N);
22938                 C = A.mask;
22939                 A.addKeyListener(27, P);
22940                 J = {};
22941                 var  bt = this.buttonText;
22942                 J["ok"] = A.addButton(bt["ok"], M.createCallback("ok"));
22943                 J["yes"] = A.addButton(bt["yes"], M.createCallback("yes"));
22944                 J["no"] = A.addButton(bt["no"], M.createCallback("no"));
22945                 J["cancel"] = A.addButton(bt["cancel"], M.createCallback("cancel"));
22946                 E = A.body.createChild({
22947
22948                     html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" /><textarea class="roo-mb-textarea"></textarea><div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar">&#160;</div></div></div>'
22949                 });
22950                 F = E.dom.firstChild;
22951                 G = Roo.get(E.dom.childNodes[2]);
22952                 G.enableDisplayMode();
22953                 G.addKeyListener([10,13], function(){
22954                     if(A.isVisible() && B && B.buttons){
22955                         if(B.buttons.ok){
22956                             M("ok");
22957                         }else  if(B.buttons.yes){
22958                             M("yes");
22959                         }
22960                     }
22961                 });
22962                 H = Roo.get(E.dom.childNodes[3]);
22963                 H.enableDisplayMode();
22964                 I = Roo.get(E.dom.childNodes[4]);
22965                 I.enableDisplayMode();
22966                 var  pf = I.dom.firstChild;
22967                 if (pf) {
22968                     pp = Roo.get(pf.firstChild);
22969                     pp.setHeight(pf.offsetHeight);
22970                 }
22971                 
22972             }
22973             return  A;
22974         },
22975
22976         
22977
22978         updateText : function(j){
22979             if(!A.isVisible() && !B.width){
22980                 A.resizeTo(this.maxWidth, 100); 
22981             }
22982
22983             F.innerHTML = j || '&#160;';
22984             var  w = Math.max(Math.min(B.width || F.offsetWidth, this.maxWidth), 
22985                         Math.max(B.minWidth || this.minWidth, L));
22986             if(B.prompt){
22987                 K.setWidth(w);
22988             }
22989             if(A.isVisible()){
22990                 A.fixedcenter = false;
22991             }
22992
22993             A.setContentSize(w, E.getHeight());
22994             if(A.isVisible()){
22995                 A.fixedcenter = true;
22996             }
22997             return  this;
22998         },
22999
23000         
23001
23002         updateProgress : function(l, m){
23003             if(m){
23004                 this.updateText(m);
23005             }
23006             if (pp) { 
23007                 pp.setWidth(Math.floor(l*I.dom.firstChild.offsetWidth));
23008             }
23009             return  this;
23010         },        
23011
23012         
23013
23014         isVisible : function(){
23015             return  A && A.isVisible();  
23016         },
23017
23018         
23019
23020         hide : function(){
23021             if(this.isVisible()){
23022                 A.hide();
23023             }  
23024         },
23025
23026         
23027
23028         show : function(n){
23029             if(this.isVisible()){
23030                 this.hide();
23031             }
23032             var  d = this.getDialog();
23033             B = n;
23034             d.setTitle(B.title || "&#160;");
23035             d.close.setDisplayed(B.closable !== false);
23036             K = G;
23037             B.prompt = B.prompt || (B.multiline ? true : false);
23038             if(B.prompt){
23039                 if(B.multiline){
23040                     G.hide();
23041                     H.show();
23042                     H.setHeight(typeof  B.multiline == "number" ?
23043                         B.multiline : this.defaultTextHeight);
23044                     K = H;
23045                 }else {
23046                     G.show();
23047                     H.hide();
23048                 }
23049             }else {
23050                 G.hide();
23051                 H.hide();
23052             }
23053
23054             I.setDisplayed(B.progress === true);
23055             this.updateProgress(0);
23056             K.dom.value = B.value || "";
23057             if(B.prompt){
23058                 A.setDefaultButton(K);
23059             }else {
23060                 var  bs = B.buttons;
23061                 var  db = null;
23062                 if(bs && bs.ok){
23063                     db = J["ok"];
23064                 }else  if(bs && bs.yes){
23065                     db = J["yes"];
23066                 }
23067
23068                 A.setDefaultButton(db);
23069             }
23070
23071             L = O(B.buttons);
23072             this.updateText(B.msg);
23073             if(B.cls){
23074                 d.el.addClass(B.cls);
23075             }
23076
23077             d.proxyDrag = B.proxyDrag === true;
23078             d.modal = B.modal !== false;
23079             d.mask = B.modal !== false ? C : false;
23080             if(!d.isVisible()){
23081                 
23082                 document.body.appendChild(A.el.dom);
23083                 d.animateTarget = null;
23084                 d.show(n.animEl);
23085             }
23086             return  this;
23087         },
23088
23089         
23090
23091         progress : function(o, p){
23092             this.show({
23093                 title : o,
23094                 msg : p,
23095                 buttons: false,
23096                 progress:true,
23097                 closable:false,
23098                 minWidth: this.minProgressWidth,
23099                 modal : true
23100             });
23101             return  this;
23102         },
23103
23104         
23105
23106         alert : function(q, r, fn, s){
23107             this.show({
23108                 title : q,
23109                 msg : r,
23110                 buttons: this.OK,
23111                 fn: fn,
23112                 scope : s,
23113                 modal : true
23114             });
23115             return  this;
23116         },
23117
23118         
23119
23120         wait : function(t, u){
23121             this.show({
23122                 title : u,
23123                 msg : t,
23124                 buttons: false,
23125                 closable:false,
23126                 progress:true,
23127                 modal:true,
23128                 width:300,
23129                 wait:true
23130             });
23131             D = Roo.TaskMgr.start({
23132                 run: function(i){
23133                     Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
23134                 },
23135                 interval: 1000
23136             });
23137             return  this;
23138         },
23139
23140         
23141
23142         confirm : function(v, x, fn, y){
23143             this.show({
23144                 title : v,
23145                 msg : x,
23146                 buttons: this.YESNO,
23147                 fn: fn,
23148                 scope : y,
23149                 modal : true
23150             });
23151             return  this;
23152         },
23153
23154         
23155
23156         prompt : function(z, AA, fn, AB, AC){
23157             this.show({
23158                 title : z,
23159                 msg : AA,
23160                 buttons: this.OKCANCEL,
23161                 fn: fn,
23162                 minWidth:250,
23163                 scope : AB,
23164                 prompt:true,
23165                 multiline: AC,
23166                 modal : true
23167             });
23168             return  this;
23169         },
23170
23171         
23172
23173         OK : {ok:true},
23174         
23175
23176         YESNO : {yes:true, no:true},
23177         
23178
23179         OKCANCEL : {ok:true, cancel:true},
23180         
23181
23182         YESNOCANCEL : {yes:true, no:true, cancel:true},
23183
23184         
23185
23186         defaultTextHeight : 75,
23187         
23188
23189         maxWidth : 600,
23190         
23191
23192         minWidth : 100,
23193         
23194
23195         minProgressWidth : 250,
23196         
23197
23198         buttonText : {
23199             ok : "OK",
23200             cancel : "Cancel",
23201             yes : "Yes",
23202             no : "No"
23203         }
23204     };
23205 }();
23206
23207
23208
23209 Roo.Msg = Roo.MessageBox;
23210
23211
23212
23213
23214 Roo.QuickTips = function(){
23215     var  el, A, B, C, tm, D, E, F = {}, esc, removeCls = null, bdLeft, bdRight;
23216     var  ce, bd, xy, dd;
23217     var  G = false, H = true, I = false;
23218     var  J = 1, K = 1, L = 1, M = [];
23219     
23220     var  N = function(e){
23221         if(H){
23222             return;
23223         }
23224         var  t = e.getTarget();
23225         if(!t || t.nodeType !== 1 || t == document || t == document.body){
23226             return;
23227         }
23228         if(ce && t == ce.el){
23229             clearTimeout(K);
23230             return;
23231         }
23232         if(t && F[t.id]){
23233             F[t.id].el = t;
23234             J = S.defer(tm.showDelay, tm, [F[t.id]]);
23235             return;
23236         }
23237         var  W, et = Roo.fly(t);
23238         var  ns = D.namespace;
23239         if(tm.interceptTitles && t.title){
23240             W = t.title;
23241             t.qtip = W;
23242             t.removeAttribute("title");
23243             e.preventDefault();
23244         }else {
23245             W = t.qtip || et.getAttributeNS(ns, D.attribute);
23246         }
23247         if(W){
23248             J = S.defer(tm.showDelay, tm, [{
23249                 el: t, 
23250                 text: W, 
23251                 width: et.getAttributeNS(ns, D.width),
23252                 autoHide: et.getAttributeNS(ns, D.hide) != "user",
23253                 title: et.getAttributeNS(ns, D.title),
23254                     cls: et.getAttributeNS(ns, D.cls)
23255             }]);
23256         }
23257     };
23258     
23259     var  O = function(e){
23260         clearTimeout(J);
23261         var  t = e.getTarget();
23262         if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
23263             K = setTimeout(U, tm.hideDelay);
23264         }
23265     };
23266     
23267     var  P = function(e){
23268         if(H){
23269             return;
23270         }
23271
23272         xy = e.getXY();
23273         xy[1] += 18;
23274         if(tm.trackMouse && ce){
23275             el.setXY(xy);
23276         }
23277     };
23278     
23279     var  Q = function(e){
23280         clearTimeout(J);
23281         clearTimeout(K);
23282         if(!e.within(el)){
23283             if(tm.hideOnClick){
23284                 U();
23285                 tm.disable();
23286                 tm.enable.defer(100, tm);
23287             }
23288         }
23289     };
23290     
23291     var  R = function(){
23292         return  2;
23293     };
23294
23295     var  S = function(o){
23296         if(H){
23297             return;
23298         }
23299
23300         clearTimeout(L);
23301         ce = o;
23302         if(removeCls){ 
23303             el.removeClass(removeCls);
23304             removeCls = null;
23305         }
23306         if(ce.cls){
23307             el.addClass(ce.cls);
23308             removeCls = ce.cls;
23309         }
23310         if(ce.title){
23311             C.update(ce.title);
23312             C.show();
23313         }else {
23314             C.update('');
23315             C.hide();
23316         }
23317
23318         el.dom.style.width  = tm.maxWidth+'px';
23319         
23320         B.update(o.text);
23321         var  p = R(), w = ce.width;
23322         if(!w){
23323             var  td = B.dom;
23324             var  aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
23325             if(aw > tm.maxWidth){
23326                 w = tm.maxWidth;
23327             }else  if(aw < tm.minWidth){
23328                 w = tm.minWidth;
23329             }else {
23330                 w = aw;
23331             }
23332         }
23333
23334         
23335         el.setWidth(parseInt(w, 10) + p);
23336         if(ce.autoHide === false){
23337             E.setDisplayed(true);
23338             if(dd){
23339                 dd.unlock();
23340             }
23341         }else {
23342             E.setDisplayed(false);
23343             if(dd){
23344                 dd.lock();
23345             }
23346         }
23347         if(xy){
23348             el.avoidY = xy[1]-18;
23349             el.setXY(xy);
23350         }
23351         if(tm.animate){
23352             el.setOpacity(.1);
23353             el.setStyle("visibility", "visible");
23354             el.fadeIn({callback: T});
23355         }else {
23356             T();
23357         }
23358     };
23359     
23360     var  T = function(){
23361         if(ce){
23362             el.show();
23363             esc.enable();
23364             if(tm.autoDismiss && ce.autoHide !== false){
23365                 L = setTimeout(U, tm.autoDismissDelay);
23366             }
23367         }
23368     };
23369     
23370     var  U = function(W){
23371         clearTimeout(L);
23372         clearTimeout(K);
23373         ce = null;
23374         if(el.isVisible()){
23375             esc.disable();
23376             if(W !== true && tm.animate){
23377                 el.fadeOut({callback: V});
23378             }else {
23379                 V();
23380             } 
23381         }
23382     };
23383     
23384     var  V = function(){
23385         el.hide();
23386         if(removeCls){
23387             el.removeClass(removeCls);
23388             removeCls = null;
23389         }
23390     };
23391     
23392     return  {
23393         
23394
23395        minWidth : 40,
23396         
23397
23398        maxWidth : 300,
23399         
23400
23401        interceptTitles : false,
23402         
23403
23404        trackMouse : false,
23405         
23406
23407        hideOnClick : true,
23408         
23409
23410        showDelay : 500,
23411         
23412
23413        hideDelay : 200,
23414         
23415
23416        autoHide : true,
23417         
23418
23419        autoDismiss : true,
23420         
23421
23422        autoDismissDelay : 5000,
23423        
23424
23425        animate : false,
23426
23427        
23428
23429         title: '',
23430        
23431
23432         text : '',
23433        
23434
23435         cls : '',
23436        
23437
23438         width : null,
23439
23440     
23441
23442        init : function(){
23443           tm = Roo.QuickTips;
23444           D = tm.tagConfig;
23445           if(!I){
23446               if(!Roo.isReady){ 
23447                   Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
23448                   return;
23449               }
23450
23451               el = new  Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
23452               el.fxDefaults = {stopFx: true};
23453               
23454               
23455               el.update('<div class="x-tip-bd"><div class="x-tip-close"></div><h3></h3><div class="x-tip-bd-inner"></div><div class="x-clear"></div></div>');              
23456               C = el.child('h3');
23457               C.enableDisplayMode("block");
23458               A = el.child('div.x-tip-bd');
23459               B = el.child('div.x-tip-bd-inner');
23460               
23461               
23462               E = el.child('div.x-tip-close');
23463               E.enableDisplayMode("block");
23464               E.on("click", U);
23465               var  d = Roo.get(document);
23466               d.on("mousedown", Q);
23467               d.on("mouseover", N);
23468               d.on("mouseout", O);
23469               d.on("mousemove", P);
23470               esc = d.addKeyListener(27, U);
23471               esc.disable();
23472               if(Roo.dd.DD){
23473                   dd = el.initDD("default", null, {
23474                       onDrag : function(){
23475                           el.sync();  
23476                       }
23477                   });
23478                   dd.setHandleElId(C.id);
23479                   dd.lock();
23480               }
23481
23482               I = true;
23483           }
23484
23485           this.enable(); 
23486        },
23487
23488     
23489
23490        register : function(X){
23491            var  cs = X  instanceof  Array ? X : arguments;
23492            for(var  i = 0, len = cs.length; i < len; i++) {
23493                var  c = cs[i];
23494                var  target = c.target;
23495                if(target){
23496                    if(target  instanceof  Array){
23497                        for(var  j = 0, jlen = target.length; j < jlen; j++){
23498                            F[target[j]] = c;
23499                        }
23500                    }else {
23501                        F[typeof  target == 'string' ? target : Roo.id(target)] = c;
23502                    }
23503                }
23504            }
23505        },
23506
23507     
23508
23509        unregister : function(el){
23510            delete  F[Roo.id(el)];
23511        },
23512
23513     
23514
23515        enable : function(){
23516            if(I && H){
23517                M.pop();
23518                if(M.length < 1){
23519                    H = false;
23520                }
23521            }
23522        },
23523
23524     
23525
23526        disable : function(){
23527           H = true;
23528           clearTimeout(J);
23529           clearTimeout(K);
23530           clearTimeout(L);
23531           if(ce){
23532               U(true);
23533           }
23534
23535           M.push(1);
23536        },
23537
23538     
23539
23540        isEnabled : function(){
23541             return  !H;
23542        },
23543
23544         
23545        tagConfig : {
23546            namespace : "ext",
23547            attribute : "qtip",
23548            width : "width",
23549            target : "target",
23550            title : "qtitle",
23551            hide : "hide",
23552            cls : "qclass"
23553        }
23554    };
23555 }();
23556
23557
23558 Roo.QuickTips.tips = Roo.QuickTips.register;
23559
23560
23561  
23562
23563
23564
23565 Roo.tree.TreePanel = function(el, A){
23566     var  B = false;
23567     var  C = false;
23568     if (A.root) {
23569         B = A.root;
23570         delete  A.root;
23571     }
23572     if (A.loader) {
23573         C = A.loader;
23574         delete  A.loader;
23575     }
23576
23577     
23578     Roo.apply(this, A);
23579     Roo.tree.TreePanel.superclass.constructor.call(this);
23580     this.el = Roo.get(el);
23581     this.el.addClass('x-tree');
23582     
23583     if (B) {
23584         this.setRootNode( Roo.factory(B, Roo.tree));
23585     }
23586     if (C) {
23587         this.loader = Roo.factory(C, Roo.tree);
23588     }
23589
23590    
23591
23592    this.id = this.el.id;
23593    this.addEvents({
23594         
23595
23596         "beforeload" : true,
23597         
23598
23599         "load" : true,
23600         
23601
23602         "textchange" : true,
23603         
23604
23605         "beforeexpand" : true,
23606         
23607
23608         "beforecollapse" : true,
23609         
23610
23611         "expand" : true,
23612         
23613
23614         "disabledchange" : true,
23615         
23616
23617         "collapse" : true,
23618         
23619
23620         "beforeclick":true,
23621         
23622
23623         "checkchange":true,
23624         
23625
23626         "click":true,
23627         
23628
23629         "dblclick":true,
23630         
23631
23632         "contextmenu":true,
23633         
23634
23635         "beforechildrenrendered":true,
23636        
23637  
23638             "startdrag" : true,
23639             
23640
23641             "enddrag" : true,
23642             
23643
23644             "dragdrop" : true,
23645             
23646
23647             "beforenodedrop" : true,
23648             
23649
23650             "nodedrop" : true,
23651              
23652
23653             "nodedragover" : true
23654         
23655    });
23656    if(this.singleExpand){
23657        this.on("beforeexpand", this.restrictExpand, this);
23658    }
23659 };
23660 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
23661     rootVisible : true,
23662     animate: Roo.enableFx,
23663     lines : true,
23664     enableDD : false,
23665     hlDrop : Roo.enableFx,
23666   
23667     renderer: false,
23668     
23669     rendererTip: false,
23670     
23671     restrictExpand : function(D){
23672         var  p = D.parentNode;
23673         if(p){
23674             if(p.expandedChild && p.expandedChild.parentNode == p){
23675                 p.expandedChild.collapse();
23676             }
23677
23678             p.expandedChild = D;
23679         }
23680     },
23681
23682     
23683     setRootNode : function(E){
23684         Roo.tree.TreePanel.superclass.setRootNode.call(this, E);
23685         if(!this.rootVisible){
23686             E.ui = new  Roo.tree.RootTreeNodeUI(E);
23687         }
23688         return  E;
23689     },
23690
23691     
23692
23693     getEl : function(){
23694         return  this.el;
23695     },
23696
23697     
23698
23699     getLoader : function(){
23700         return  this.loader;
23701     },
23702
23703     
23704
23705     expandAll : function(){
23706         this.root.expand(true);
23707     },
23708
23709     
23710
23711     collapseAll : function(){
23712         this.root.collapse(true);
23713     },
23714
23715     
23716
23717     getSelectionModel : function(){
23718         if(!this.selModel){
23719             this.selModel = new  Roo.tree.DefaultSelectionModel();
23720         }
23721         return  this.selModel;
23722     },
23723
23724     
23725
23726     getChecked : function(a, F){
23727         F = F || this.root;
23728         var  r = [];
23729         var  f = function(){
23730             if(this.attributes.checked){
23731                 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
23732             }
23733         }
23734
23735         F.cascade(f);
23736         return  r;
23737     },
23738
23739     
23740
23741     expandPath : function(G, H, I){
23742         H = H || "id";
23743         var  J = G.split(this.pathSeparator);
23744         var  K = this.root;
23745         if(K.attributes[H] != J[1]){ 
23746             if(I){
23747                 I(false, null);
23748             }
23749             return;
23750         }
23751         var  L = 1;
23752         var  f = function(){
23753             if(++L == J.length){
23754                 if(I){
23755                     I(true, K);
23756                 }
23757                 return;
23758             }
23759             var  c = K.findChild(H, J[L]);
23760             if(!c){
23761                 if(I){
23762                     I(false, K);
23763                 }
23764                 return;
23765             }
23766
23767             K = c;
23768             c.expand(false, false, f);
23769         };
23770         K.expand(false, false, f);
23771     },
23772
23773     
23774
23775     selectPath : function(M, N, O){
23776         N = N || "id";
23777         var  P = M.split(this.pathSeparator);
23778         var  v = P.pop();
23779         if(P.length > 0){
23780             var  f = function(Q, R){
23781                 if(Q && R){
23782                     var  n = R.findChild(N, v);
23783                     if(n){
23784                         n.select();
23785                         if(O){
23786                             O(true, n);
23787                         }
23788                     }else  if(O){
23789                         O(false, n);
23790                     }
23791                 }else {
23792                     if(O){
23793                         O(false, n);
23794                     }
23795                 }
23796             };
23797             this.expandPath(P.join(this.pathSeparator), N, f);
23798         }else {
23799             this.root.select();
23800             if(O){
23801                 O(true, this.root);
23802             }
23803         }
23804     },
23805
23806     getTreeEl : function(){
23807         return  this.el;
23808     },
23809
23810     
23811
23812     render : function(){
23813         if (this.innerCt) {
23814             return  this; 
23815         }
23816
23817         
23818         this.innerCt = this.el.createChild({tag:"ul",
23819                cls:"x-tree-root-ct " +
23820                (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
23821
23822         if(this.containerScroll){
23823             Roo.dd.ScrollManager.register(this.el);
23824         }
23825         if((this.enableDD || this.enableDrop) && !this.dropZone){
23826            
23827
23828              this.dropZone = new  Roo.tree.TreeDropZone(this, this.dropConfig || {
23829                ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
23830            });
23831         }
23832         if((this.enableDD || this.enableDrag) && !this.dragZone){
23833            
23834
23835             this.dragZone = new  Roo.tree.TreeDragZone(this, this.dragConfig || {
23836                ddGroup: this.ddGroup || "TreeDD",
23837                scroll: this.ddScroll
23838            });
23839         }
23840
23841         this.getSelectionModel().init(this);
23842         if (!this.root) {
23843             console.log("ROOT not set in tree");
23844             return;
23845         }
23846
23847         this.root.render();
23848         if(!this.rootVisible){
23849             this.root.renderChildren();
23850         }
23851         return  this;
23852     }
23853 });
23854
23855
23856  
23857
23858
23859
23860 Roo.tree.DefaultSelectionModel = function(){
23861    this.selNode = null;
23862    
23863    this.addEvents({
23864        
23865
23866        "selectionchange" : true,
23867
23868        
23869
23870        "beforeselect" : true
23871    });
23872 };
23873
23874 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
23875     init : function(A){
23876         this.tree = A;
23877         A.getTreeEl().on("keydown", this.onKeyDown, this);
23878         A.on("click", this.onNodeClick, this);
23879     },
23880     
23881     onNodeClick : function(B, e){
23882         if (e.ctrlKey && this.selNode == B)  {
23883             this.unselect(B);
23884             return;
23885         }
23886
23887         this.select(B);
23888     },
23889     
23890     
23891
23892     select : function(C){
23893         var  D = this.selNode;
23894         if(D != C && this.fireEvent('beforeselect', this, C, D) !== false){
23895             if(D){
23896                 D.ui.onSelectedChange(false);
23897             }
23898
23899             this.selNode = C;
23900             C.ui.onSelectedChange(true);
23901             this.fireEvent("selectionchange", this, C, D);
23902         }
23903         return  C;
23904     },
23905     
23906     
23907
23908     unselect : function(E){
23909         if(this.selNode == E){
23910             this.clearSelections();
23911         }    
23912     },
23913     
23914     
23915
23916     clearSelections : function(){
23917         var  n = this.selNode;
23918         if(n){
23919             n.ui.onSelectedChange(false);
23920             this.selNode = null;
23921             this.fireEvent("selectionchange", this, null);
23922         }
23923         return  n;
23924     },
23925     
23926     
23927
23928     getSelectedNode : function(){
23929         return  this.selNode;    
23930     },
23931     
23932     
23933
23934     isSelected : function(F){
23935         return  this.selNode == F;  
23936     },
23937
23938     
23939
23940     selectPrevious : function(){
23941         var  s = this.selNode || this.lastSelNode;
23942         if(!s){
23943             return  null;
23944         }
23945         var  ps = s.previousSibling;
23946         if(ps){
23947             if(!ps.isExpanded() || ps.childNodes.length < 1){
23948                 return  this.select(ps);
23949             } else {
23950                 var  lc = ps.lastChild;
23951                 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
23952                     lc = lc.lastChild;
23953                 }
23954                 return  this.select(lc);
23955             }
23956         } else  if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
23957             return  this.select(s.parentNode);
23958         }
23959         return  null;
23960     },
23961
23962     
23963
23964     selectNext : function(){
23965         var  s = this.selNode || this.lastSelNode;
23966         if(!s){
23967             return  null;
23968         }
23969         if(s.firstChild && s.isExpanded()){
23970              return  this.select(s.firstChild);
23971          }else  if(s.nextSibling){
23972              return  this.select(s.nextSibling);
23973          }else  if(s.parentNode){
23974             var  newS = null;
23975             s.parentNode.bubble(function(){
23976                 if(this.nextSibling){
23977                     newS = this.getOwnerTree().selModel.select(this.nextSibling);
23978                     return  false;
23979                 }
23980             });
23981             return  newS;
23982          }
23983         return  null;
23984     },
23985
23986     onKeyDown : function(e){
23987         var  s = this.selNode || this.lastSelNode;
23988         
23989         var  sm = this;
23990         if(!s){
23991             return;
23992         }
23993         var  k = e.getKey();
23994         switch(k){
23995              case  e.DOWN:
23996                  e.stopEvent();
23997                  this.selectNext();
23998              break;
23999              case  e.UP:
24000                  e.stopEvent();
24001                  this.selectPrevious();
24002              break;
24003              case  e.RIGHT:
24004                  e.preventDefault();
24005                  if(s.hasChildNodes()){
24006                      if(!s.isExpanded()){
24007                          s.expand();
24008                      }else  if(s.firstChild){
24009                          this.select(s.firstChild, e);
24010                      }
24011                  }
24012              break;
24013              case  e.LEFT:
24014                  e.preventDefault();
24015                  if(s.hasChildNodes() && s.isExpanded()){
24016                      s.collapse();
24017                  }else  if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
24018                      this.select(s.parentNode, e);
24019                  }
24020              break;
24021         };
24022     }
24023 });
24024
24025
24026
24027 Roo.tree.MultiSelectionModel = function(){
24028    this.selNodes = [];
24029    this.selMap = {};
24030    this.addEvents({
24031        
24032
24033        "selectionchange" : true
24034    });
24035 };
24036
24037 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
24038     init : function(G){
24039         this.tree = G;
24040         G.getTreeEl().on("keydown", this.onKeyDown, this);
24041         G.on("click", this.onNodeClick, this);
24042     },
24043     
24044     onNodeClick : function(H, e){
24045         this.select(H, e, e.ctrlKey);
24046     },
24047     
24048     
24049
24050     select : function(I, e, J){
24051         if(J !== true){
24052             this.clearSelections(true);
24053         }
24054         if(this.isSelected(I)){
24055             this.lastSelNode = I;
24056             return  I;
24057         }
24058
24059         this.selNodes.push(I);
24060         this.selMap[I.id] = I;
24061         this.lastSelNode = I;
24062         I.ui.onSelectedChange(true);
24063         this.fireEvent("selectionchange", this, this.selNodes);
24064         return  I;
24065     },
24066     
24067     
24068
24069     unselect : function(K){
24070         if(this.selMap[K.id]){
24071             K.ui.onSelectedChange(false);
24072             var  sn = this.selNodes;
24073             var  index = -1;
24074             if(sn.indexOf){
24075                 index = sn.indexOf(K);
24076             }else {
24077                 for(var  i = 0, len = sn.length; i < len; i++){
24078                     if(sn[i] == K){
24079                         index = i;
24080                         break;
24081                     }
24082                 }
24083             }
24084             if(index != -1){
24085                 this.selNodes.splice(index, 1);
24086             }
24087             delete  this.selMap[K.id];
24088             this.fireEvent("selectionchange", this, this.selNodes);
24089         }
24090     },
24091     
24092     
24093
24094     clearSelections : function(L){
24095         var  sn = this.selNodes;
24096         if(sn.length > 0){
24097             for(var  i = 0, len = sn.length; i < len; i++){
24098                 sn[i].ui.onSelectedChange(false);
24099             }
24100
24101             this.selNodes = [];
24102             this.selMap = {};
24103             if(L !== true){
24104                 this.fireEvent("selectionchange", this, this.selNodes);
24105             }
24106         }
24107     },
24108     
24109     
24110
24111     isSelected : function(M){
24112         return  this.selMap[M.id] ? true : false;  
24113     },
24114     
24115     
24116
24117     getSelectedNodes : function(){
24118         return  this.selNodes;    
24119     },
24120
24121     onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
24122
24123     selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
24124
24125     selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
24126 });
24127
24128
24129  
24130
24131
24132 Roo.tree.TreeNode = function(A){
24133     A = A || {};
24134     if(typeof  A == "string"){
24135         A = {text: A};
24136     }
24137
24138     this.childrenRendered = false;
24139     this.rendered = false;
24140     Roo.tree.TreeNode.superclass.constructor.call(this, A);
24141     this.expanded = A.expanded === true;
24142     this.isTarget = A.isTarget !== false;
24143     this.draggable = A.draggable !== false && A.allowDrag !== false;
24144     this.allowChildren = A.allowChildren !== false && A.allowDrop !== false;
24145
24146     
24147
24148     this.text = A.text;
24149     
24150
24151     this.disabled = A.disabled === true;
24152
24153     this.addEvents({
24154         
24155
24156         "textchange" : true,
24157         
24158
24159         "beforeexpand" : true,
24160         
24161
24162         "beforecollapse" : true,
24163         
24164
24165         "expand" : true,
24166         
24167
24168         "disabledchange" : true,
24169         
24170
24171         "collapse" : true,
24172         
24173
24174         "beforeclick":true,
24175         
24176
24177         "checkchange":true,
24178         
24179
24180         "click":true,
24181         
24182
24183         "dblclick":true,
24184         
24185
24186         "contextmenu":true,
24187         
24188
24189         "beforechildrenrendered":true
24190     });
24191
24192     var  B = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
24193
24194     
24195
24196     this.ui = new  B(this);
24197 };
24198 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
24199     preventHScroll: true,
24200     
24201
24202     isExpanded : function(){
24203         return  this.expanded;
24204     },
24205
24206     
24207
24208     getUI : function(){
24209         return  this.ui;
24210     },
24211
24212     
24213     setFirstChild : function(C){
24214         var  of = this.firstChild;
24215         Roo.tree.TreeNode.superclass.setFirstChild.call(this, C);
24216         if(this.childrenRendered && of && C != of){
24217             of.renderIndent(true, true);
24218         }
24219         if(this.rendered){
24220             this.renderIndent(true, true);
24221         }
24222     },
24223
24224     
24225     setLastChild : function(D){
24226         var  ol = this.lastChild;
24227         Roo.tree.TreeNode.superclass.setLastChild.call(this, D);
24228         if(this.childrenRendered && ol && D != ol){
24229             ol.renderIndent(true, true);
24230         }
24231         if(this.rendered){
24232             this.renderIndent(true, true);
24233         }
24234     },
24235
24236     
24237     
24238     appendChild : function(){
24239         var  E = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
24240         if(E && this.childrenRendered){
24241             E.render();
24242         }
24243
24244         this.ui.updateExpandIcon();
24245         return  E;
24246     },
24247
24248     
24249     removeChild : function(F){
24250         this.ownerTree.getSelectionModel().unselect(F);
24251         Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
24252         
24253         if(this.childrenRendered){
24254             F.ui.remove();
24255         }
24256         if(this.childNodes.length < 1){
24257             this.collapse(false, false);
24258         }else {
24259             this.ui.updateExpandIcon();
24260         }
24261         if(!this.firstChild) {
24262             this.childrenRendered = false;
24263         }
24264         return  F;
24265     },
24266
24267     
24268     insertBefore : function(G, H){
24269         var  I = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
24270         if(I && H && this.childrenRendered){
24271             G.render();
24272         }
24273
24274         this.ui.updateExpandIcon();
24275         return  I;
24276     },
24277
24278     
24279
24280     setText : function(J){
24281         var  K = this.text;
24282         this.text = J;
24283         this.attributes.text = J;
24284         if(this.rendered){ 
24285             this.ui.onTextChange(this, J, K);
24286         }
24287
24288         this.fireEvent("textchange", this, J, K);
24289     },
24290
24291     
24292
24293     select : function(){
24294         this.getOwnerTree().getSelectionModel().select(this);
24295     },
24296
24297     
24298
24299     unselect : function(){
24300         this.getOwnerTree().getSelectionModel().unselect(this);
24301     },
24302
24303     
24304
24305     isSelected : function(){
24306         return  this.getOwnerTree().getSelectionModel().isSelected(this);
24307     },
24308
24309     
24310
24311     expand : function(L, M, N){
24312         if(!this.expanded){
24313             if(this.fireEvent("beforeexpand", this, L, M) === false){
24314                 return;
24315             }
24316             if(!this.childrenRendered){
24317                 this.renderChildren();
24318             }
24319
24320             this.expanded = true;
24321             if(!this.isHiddenRoot() && (this.getOwnerTree().animate && M !== false) || M){
24322                 this.ui.animExpand(function(){
24323                     this.fireEvent("expand", this);
24324                     if(typeof  N == "function"){
24325                         N(this);
24326                     }
24327                     if(L === true){
24328                         this.expandChildNodes(true);
24329                     }
24330                 }.createDelegate(this));
24331                 return;
24332             }else {
24333                 this.ui.expand();
24334                 this.fireEvent("expand", this);
24335                 if(typeof  N == "function"){
24336                     N(this);
24337                 }
24338             }
24339         }else {
24340            if(typeof  N == "function"){
24341                N(this);
24342            }
24343         }
24344         if(L === true){
24345             this.expandChildNodes(true);
24346         }
24347     },
24348
24349     isHiddenRoot : function(){
24350         return  this.isRoot && !this.getOwnerTree().rootVisible;
24351     },
24352
24353     
24354
24355     collapse : function(O, P){
24356         if(this.expanded && !this.isHiddenRoot()){
24357             if(this.fireEvent("beforecollapse", this, O, P) === false){
24358                 return;
24359             }
24360
24361             this.expanded = false;
24362             if((this.getOwnerTree().animate && P !== false) || P){
24363                 this.ui.animCollapse(function(){
24364                     this.fireEvent("collapse", this);
24365                     if(O === true){
24366                         this.collapseChildNodes(true);
24367                     }
24368                 }.createDelegate(this));
24369                 return;
24370             }else {
24371                 this.ui.collapse();
24372                 this.fireEvent("collapse", this);
24373             }
24374         }
24375         if(O === true){
24376             var  cs = this.childNodes;
24377             for(var  i = 0, len = cs.length; i < len; i++) {
24378                 cs[i].collapse(true, false);
24379             }
24380         }
24381     },
24382
24383     
24384     delayedExpand : function(Q){
24385         if(!this.expandProcId){
24386             this.expandProcId = this.expand.defer(Q, this);
24387         }
24388     },
24389
24390     
24391     cancelExpand : function(){
24392         if(this.expandProcId){
24393             clearTimeout(this.expandProcId);
24394         }
24395
24396         this.expandProcId = false;
24397     },
24398
24399     
24400
24401     toggle : function(){
24402         if(this.expanded){
24403             this.collapse();
24404         }else {
24405             this.expand();
24406         }
24407     },
24408
24409     
24410
24411     ensureVisible : function(R){
24412         var  S = this.getOwnerTree();
24413         S.expandPath(this.parentNode.getPath(), false, function(){
24414             S.getTreeEl().scrollChildIntoView(this.ui.anchor);
24415             Roo.callback(R);
24416         }.createDelegate(this));
24417     },
24418
24419     
24420
24421     expandChildNodes : function(T){
24422         var  cs = this.childNodes;
24423         for(var  i = 0, len = cs.length; i < len; i++) {
24424                 cs[i].expand(T);
24425         }
24426     },
24427
24428     
24429
24430     collapseChildNodes : function(U){
24431         var  cs = this.childNodes;
24432         for(var  i = 0, len = cs.length; i < len; i++) {
24433                 cs[i].collapse(U);
24434         }
24435     },
24436
24437     
24438
24439     disable : function(){
24440         this.disabled = true;
24441         this.unselect();
24442         if(this.rendered && this.ui.onDisableChange){ 
24443             this.ui.onDisableChange(this, true);
24444         }
24445
24446         this.fireEvent("disabledchange", this, true);
24447     },
24448
24449     
24450
24451     enable : function(){
24452         this.disabled = false;
24453         if(this.rendered && this.ui.onDisableChange){ 
24454             this.ui.onDisableChange(this, false);
24455         }
24456
24457         this.fireEvent("disabledchange", this, false);
24458     },
24459
24460     
24461     renderChildren : function(V){
24462         if(V !== false){
24463             this.fireEvent("beforechildrenrendered", this);
24464         }
24465         var  cs = this.childNodes;
24466         for(var  i = 0, len = cs.length; i < len; i++){
24467             cs[i].render(true);
24468         }
24469
24470         this.childrenRendered = true;
24471     },
24472
24473     
24474     sort : function(fn, W){
24475         Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
24476         if(this.childrenRendered){
24477             var  cs = this.childNodes;
24478             for(var  i = 0, len = cs.length; i < len; i++){
24479                 cs[i].render(true);
24480             }
24481         }
24482     },
24483
24484     
24485     render : function(X){
24486         this.ui.render(X);
24487         if(!this.rendered){
24488             this.rendered = true;
24489             if(this.expanded){
24490                 this.expanded = false;
24491                 this.expand(false, false);
24492             }
24493         }
24494     },
24495
24496     
24497     renderIndent : function(Y, Z){
24498         if(Z){
24499             this.ui.childIndent = null;
24500         }
24501
24502         this.ui.renderIndent();
24503         if(Y === true && this.childrenRendered){
24504             var  cs = this.childNodes;
24505             for(var  i = 0, len = cs.length; i < len; i++){
24506                 cs[i].renderIndent(true, Z);
24507             }
24508         }
24509     }
24510 });
24511
24512
24513  
24514
24515
24516  Roo.tree.AsyncTreeNode = function(A){
24517     this.loaded = false;
24518     this.loading = false;
24519     Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
24520     
24521
24522     this.addEvents({'beforeload':true, 'load': true});
24523     
24524
24525     
24526
24527 };
24528 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
24529     expand : function(B, C, D){
24530         if(this.loading){ 
24531             var  timer;
24532             var  f = function(){
24533                 if(!this.loading){ 
24534                     clearInterval(timer);
24535                     this.expand(B, C, D);
24536                 }
24537             }.createDelegate(this);
24538             timer = setInterval(f, 200);
24539             return;
24540         }
24541         if(!this.loaded){
24542             if(this.fireEvent("beforeload", this) === false){
24543                 return;
24544             }
24545
24546             this.loading = true;
24547             this.ui.beforeLoad(this);
24548             var  loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
24549             if(loader){
24550                 loader.load(this, this.loadComplete.createDelegate(this, [B, C, D]));
24551                 return;
24552             }
24553         }
24554
24555         Roo.tree.AsyncTreeNode.superclass.expand.call(this, B, C, D);
24556     },
24557     
24558     
24559
24560     isLoading : function(){
24561         return  this.loading;  
24562     },
24563     
24564     loadComplete : function(E, F, G){
24565         this.loading = false;
24566         this.loaded = true;
24567         this.ui.afterLoad(this);
24568         this.fireEvent("load", this);
24569         this.expand(E, F, G);
24570     },
24571     
24572     
24573
24574     isLoaded : function(){
24575         return  this.loaded;
24576     },
24577     
24578     hasChildNodes : function(){
24579         if(!this.isLeaf() && !this.loaded){
24580             return  true;
24581         }else {
24582             return  Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
24583         }
24584     },
24585
24586     
24587
24588     reload : function(H){
24589         this.collapse(false, false);
24590         while(this.firstChild){
24591             this.removeChild(this.firstChild);
24592         }
24593
24594         this.childrenRendered = false;
24595         this.loaded = false;
24596         if(this.isHiddenRoot()){
24597             this.expanded = false;
24598         }
24599
24600         this.expand(false, false, H);
24601     }
24602 });
24603
24604
24605  
24606
24607
24608 Roo.tree.TreeNodeUI = function(A){
24609     this.node = A;
24610     this.rendered = false;
24611     this.animating = false;
24612     this.emptyIcon = Roo.BLANK_IMAGE_URL;
24613 };
24614
24615 Roo.tree.TreeNodeUI.prototype = {
24616     removeChild : function(B){
24617         if(this.rendered){
24618             this.ctNode.removeChild(B.ui.getEl());
24619         }
24620     },
24621
24622     beforeLoad : function(){
24623          this.addClass("x-tree-node-loading");
24624     },
24625
24626     afterLoad : function(){
24627          this.removeClass("x-tree-node-loading");
24628     },
24629
24630     onTextChange : function(C, D, E){
24631         if(this.rendered){
24632             this.textNode.innerHTML = D;
24633         }
24634     },
24635
24636     onDisableChange : function(F, G){
24637         this.disabled = G;
24638         if(G){
24639             this.addClass("x-tree-node-disabled");
24640         }else {
24641             this.removeClass("x-tree-node-disabled");
24642         }
24643     },
24644
24645     onSelectedChange : function(H){
24646         if(H){
24647             this.focus();
24648             this.addClass("x-tree-selected");
24649         }else {
24650             
24651             this.removeClass("x-tree-selected");
24652         }
24653     },
24654
24655     onMove : function(I, J, K, L, M, N){
24656         this.childIndent = null;
24657         if(this.rendered){
24658             var  targetNode = L.ui.getContainer();
24659             if(!targetNode){
24660                 this.holder = document.createElement("div");
24661                 this.holder.appendChild(this.wrap);
24662                 return;
24663             }
24664             var  insertBefore = N ? N.ui.getEl() : null;
24665             if(insertBefore){
24666                 targetNode.insertBefore(this.wrap, insertBefore);
24667             }else {
24668                 targetNode.appendChild(this.wrap);
24669             }
24670
24671             this.node.renderIndent(true);
24672         }
24673     },
24674
24675     addClass : function(O){
24676         if(this.elNode){
24677             Roo.fly(this.elNode).addClass(O);
24678         }
24679     },
24680
24681     removeClass : function(P){
24682         if(this.elNode){
24683             Roo.fly(this.elNode).removeClass(P);
24684         }
24685     },
24686
24687     remove : function(){
24688         if(this.rendered){
24689             this.holder = document.createElement("div");
24690             this.holder.appendChild(this.wrap);
24691         }
24692     },
24693
24694     fireEvent : function(){
24695         return  this.node.fireEvent.apply(this.node, arguments);
24696     },
24697
24698     initEvents : function(){
24699         this.node.on("move", this.onMove, this);
24700         var  E = Roo.EventManager;
24701         var  a = this.anchor;
24702
24703         var  el = Roo.fly(a, '_treeui');
24704
24705         if(Roo.isOpera){ 
24706             el.setStyle("text-decoration", "none");
24707         }
24708
24709
24710         el.on("click", this.onClick, this);
24711         el.on("dblclick", this.onDblClick, this);
24712
24713         if(this.checkbox){
24714             Roo.EventManager.on(this.checkbox,
24715                     Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
24716         }
24717
24718
24719         el.on("contextmenu", this.onContextMenu, this);
24720
24721         var  Q = Roo.fly(this.iconNode);
24722         Q.on("click", this.onClick, this);
24723         Q.on("dblclick", this.onDblClick, this);
24724         Q.on("contextmenu", this.onContextMenu, this);
24725         E.on(this.ecNode, "click", this.ecClick, this, true);
24726
24727         if(this.node.disabled){
24728             this.addClass("x-tree-node-disabled");
24729         }
24730         if(this.node.hidden){
24731             this.addClass("x-tree-node-disabled");
24732         }
24733         var  ot = this.node.getOwnerTree();
24734         var  dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
24735         if(dd && (!this.node.isRoot || ot.rootVisible)){
24736             Roo.dd.Registry.register(this.elNode, {
24737                 node: this.node,
24738                 handles: this.getDDHandles(),
24739                 isHandle: false
24740             });
24741         }
24742     },
24743
24744     getDDHandles : function(){
24745         return  [this.iconNode, this.textNode];
24746     },
24747
24748     hide : function(){
24749         if(this.rendered){
24750             this.wrap.style.display = "none";
24751         }
24752     },
24753
24754     show : function(){
24755         if(this.rendered){
24756             this.wrap.style.display = "";
24757         }
24758     },
24759
24760     onContextMenu : function(e){
24761         if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
24762             e.preventDefault();
24763             this.focus();
24764             this.fireEvent("contextmenu", this.node, e);
24765         }
24766     },
24767
24768     onClick : function(e){
24769         if(this.dropping){
24770             e.stopEvent();
24771             return;
24772         }
24773         if(this.fireEvent("beforeclick", this.node, e) !== false){
24774             if(!this.disabled && this.node.attributes.href){
24775                 this.fireEvent("click", this.node, e);
24776                 return;
24777             }
24778
24779             e.preventDefault();
24780             if(this.disabled){
24781                 return;
24782             }
24783
24784             if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
24785                 this.node.toggle();
24786             }
24787
24788
24789             this.fireEvent("click", this.node, e);
24790         }else {
24791             e.stopEvent();
24792         }
24793     },
24794
24795     onDblClick : function(e){
24796         e.preventDefault();
24797         if(this.disabled){
24798             return;
24799         }
24800         if(this.checkbox){
24801             this.toggleCheck();
24802         }
24803         if(!this.animating && this.node.hasChildNodes()){
24804             this.node.toggle();
24805         }
24806
24807         this.fireEvent("dblclick", this.node, e);
24808     },
24809
24810     onCheckChange : function(){
24811         var  R = this.checkbox.checked;
24812         this.node.attributes.checked = R;
24813         this.fireEvent('checkchange', this.node, R);
24814     },
24815
24816     ecClick : function(e){
24817         if(!this.animating && this.node.hasChildNodes()){
24818             this.node.toggle();
24819         }
24820     },
24821
24822     startDrop : function(){
24823         this.dropping = true;
24824     },
24825
24826     
24827     endDrop : function(){
24828        setTimeout(function(){
24829            this.dropping = false;
24830        }.createDelegate(this), 50);
24831     },
24832
24833     expand : function(){
24834         this.updateExpandIcon();
24835         this.ctNode.style.display = "";
24836     },
24837
24838     focus : function(){
24839         if(!this.node.preventHScroll){
24840             try{this.anchor.focus();
24841             }catch(e){}
24842         }else  if(!Roo.isIE){
24843             try{
24844                 var  noscroll = this.node.getOwnerTree().getTreeEl().dom;
24845                 var  l = noscroll.scrollLeft;
24846                 this.anchor.focus();
24847                 noscroll.scrollLeft = l;
24848             }catch(e){}
24849         }
24850     },
24851
24852     toggleCheck : function(S){
24853         var  cb = this.checkbox;
24854         if(cb){
24855             cb.checked = (S === undefined ? !cb.checked : S);
24856         }
24857     },
24858
24859     blur : function(){
24860         try{
24861             this.anchor.blur();
24862         }catch(e){}
24863     },
24864
24865     animExpand : function(T){
24866         var  ct = Roo.get(this.ctNode);
24867         ct.stopFx();
24868         if(!this.node.hasChildNodes()){
24869             this.updateExpandIcon();
24870             this.ctNode.style.display = "";
24871             Roo.callback(T);
24872             return;
24873         }
24874
24875         this.animating = true;
24876         this.updateExpandIcon();
24877
24878         ct.slideIn('t', {
24879            callback : function(){
24880                this.animating = false;
24881                Roo.callback(T);
24882             },
24883             scope: this,
24884             duration: this.node.ownerTree.duration || .25
24885         });
24886     },
24887
24888     highlight : function(){
24889         var  U = this.node.getOwnerTree();
24890         Roo.fly(this.wrap).highlight(
24891             U.hlColor || "C3DAF9",
24892             {endColor: U.hlBaseColor}
24893         );
24894     },
24895
24896     collapse : function(){
24897         this.updateExpandIcon();
24898         this.ctNode.style.display = "none";
24899     },
24900
24901     animCollapse : function(V){
24902         var  ct = Roo.get(this.ctNode);
24903         ct.enableDisplayMode('block');
24904         ct.stopFx();
24905
24906         this.animating = true;
24907         this.updateExpandIcon();
24908
24909         ct.slideOut('t', {
24910             callback : function(){
24911                this.animating = false;
24912                Roo.callback(V);
24913             },
24914             scope: this,
24915             duration: this.node.ownerTree.duration || .25
24916         });
24917     },
24918
24919     getContainer : function(){
24920         return  this.ctNode;
24921     },
24922
24923     getEl : function(){
24924         return  this.wrap;
24925     },
24926
24927     appendDDGhost : function(W){
24928         W.appendChild(this.elNode.cloneNode(true));
24929     },
24930
24931     getDDRepairXY : function(){
24932         return  Roo.lib.Dom.getXY(this.iconNode);
24933     },
24934
24935     onRender : function(){
24936         this.render();
24937     },
24938
24939     render : function(X){
24940         var  n = this.node, a = n.attributes;
24941         var  Y = n.parentNode ?
24942               n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
24943
24944         if(!this.rendered){
24945             this.rendered = true;
24946
24947             this.renderElements(n, a, Y, X);
24948
24949             if(a.qtip){
24950                if(this.textNode.setAttributeNS){
24951                    this.textNode.setAttributeNS("ext", "qtip", a.qtip);
24952                    if(a.qtipTitle){
24953                        this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
24954                    }
24955                }else {
24956                    this.textNode.setAttribute("ext:qtip", a.qtip);
24957                    if(a.qtipTitle){
24958                        this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
24959                    }
24960                }
24961             }else  if(a.qtipCfg){
24962                 a.qtipCfg.target = Roo.id(this.textNode);
24963                 Roo.QuickTips.register(a.qtipCfg);
24964             }
24965
24966             this.initEvents();
24967             if(!this.node.expanded){
24968                 this.updateExpandIcon();
24969             }
24970         }else {
24971             if(X === true) {
24972                 Y.appendChild(this.wrap);
24973             }
24974         }
24975     },
24976
24977     renderElements : function(n, a, Z, b){
24978         
24979         this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
24980         var  t = n.getOwnerTree();
24981         var  c = t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
24982         var  d = t.rendererTip ? t.rendererTip(n.attributes) : c;
24983         var  cb = typeof  a.checked == 'boolean';
24984         var  f = a.href ? a.href : Roo.isGecko ? "" : "#";
24985         var  g = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
24986             '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
24987             '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
24988             '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
24989             cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
24990             '<a hidefocus="on" href="',f,'" tabIndex="1" ',
24991              a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", 
24992                 '><span unselectable="on" qtip="' , d ,'">',c,"</span></a></div>",
24993             '<ul class="x-tree-node-ct" style="display:none;"></ul>',
24994             "</li>"];
24995
24996         if(b !== true && n.nextSibling && n.nextSibling.ui.getEl()){
24997             this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
24998                                 n.nextSibling.ui.getEl(), g.join(""));
24999         }else {
25000             this.wrap = Roo.DomHelper.insertHtml("beforeEnd", Z, g.join(""));
25001         }
25002
25003
25004         this.elNode = this.wrap.childNodes[0];
25005         this.ctNode = this.wrap.childNodes[1];
25006         var  cs = this.elNode.childNodes;
25007         this.indentNode = cs[0];
25008         this.ecNode = cs[1];
25009         this.iconNode = cs[2];
25010         var  h = 3;
25011         if(cb){
25012             this.checkbox = cs[3];
25013             h++;
25014         }
25015
25016         this.anchor = cs[h];
25017         this.textNode = cs[h].firstChild;
25018     },
25019
25020     getAnchor : function(){
25021         return  this.anchor;
25022     },
25023
25024     getTextEl : function(){
25025         return  this.textNode;
25026     },
25027
25028     getIconEl : function(){
25029         return  this.iconNode;
25030     },
25031
25032     isChecked : function(){
25033         return  this.checkbox ? this.checkbox.checked : false;
25034     },
25035
25036     updateExpandIcon : function(){
25037         if(this.rendered){
25038             var  n = this.node, c1, c2;
25039             var  P = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
25040             var  hasChild = n.hasChildNodes();
25041             if(hasChild){
25042                 if(n.expanded){
25043                     P += "-minus";
25044                     c1 = "x-tree-node-collapsed";
25045                     c2 = "x-tree-node-expanded";
25046                 }else {
25047                     P += "-plus";
25048                     c1 = "x-tree-node-expanded";
25049                     c2 = "x-tree-node-collapsed";
25050                 }
25051                 if(this.wasLeaf){
25052                     this.removeClass("x-tree-node-leaf");
25053                     this.wasLeaf = false;
25054                 }
25055                 if(this.c1 != c1 || this.c2 != c2){
25056                     Roo.fly(this.elNode).replaceClass(c1, c2);
25057                     this.c1 = c1; this.c2 = c2;
25058                 }
25059             }else {
25060                 if(!this.wasLeaf){
25061                     Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
25062                     delete  this.c1;
25063                     delete  this.c2;
25064                     this.wasLeaf = true;
25065                 }
25066             }
25067             var  ecc = "x-tree-ec-icon "+P;
25068             if(this.ecc != ecc){
25069                 this.ecNode.className = ecc;
25070                 this.ecc = ecc;
25071             }
25072         }
25073     },
25074
25075     getChildIndent : function(){
25076         if(!this.childIndent){
25077             var  g = [];
25078             var  p = this.node;
25079             while(p){
25080                 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
25081                     if(!p.isLast()) {
25082                         g.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
25083                     } else  {
25084                         g.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
25085                     }
25086                 }
25087
25088                 p = p.parentNode;
25089             }
25090
25091             this.childIndent = g.join("");
25092         }
25093         return  this.childIndent;
25094     },
25095
25096     renderIndent : function(){
25097         if(this.rendered){
25098             var  indent = "";
25099             var  p = this.node.parentNode;
25100             if(p){
25101                 indent = p.ui.getChildIndent();
25102             }
25103             if(this.indentMarkup != indent){ 
25104                 this.indentNode.innerHTML = indent;
25105                 this.indentMarkup = indent;
25106             }
25107
25108             this.updateExpandIcon();
25109         }
25110     }
25111 };
25112
25113 Roo.tree.RootTreeNodeUI = function(){
25114     Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
25115 };
25116 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
25117     render : function(){
25118         if(!this.rendered){
25119             var  Z = this.node.ownerTree.innerCt.dom;
25120             this.node.expanded = true;
25121             Z.innerHTML = '<div class="x-tree-root-node"></div>';
25122             this.wrap = this.ctNode = Z.firstChild;
25123         }
25124     },
25125     collapse : function(){
25126     },
25127     expand : function(){
25128     }
25129 });
25130
25131
25132
25133
25134 Roo.tree.TreeLoader = function(A){
25135     this.baseParams = {};
25136     this.requestMethod = "POST";
25137     Roo.apply(this, A);
25138
25139     this.addEvents({
25140     
25141         
25142
25143         beforeload : true,
25144         
25145
25146         load : true,
25147         
25148
25149         loadexception : true,
25150         
25151
25152         create : true
25153     });
25154
25155     Roo.tree.TreeLoader.superclass.constructor.call(this);
25156 };
25157
25158 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
25159     
25160
25161     
25162
25163     
25164
25165     
25166
25167     uiProviders : {},
25168
25169     
25170
25171     clearOnLoad : true,
25172
25173     
25174
25175     
25176     root : false,
25177      
25178
25179     
25180     
25181     queryParam: false,
25182     
25183     
25184
25185     load : function(B, C){
25186         if(this.clearOnLoad){
25187             while(B.firstChild){
25188                 B.removeChild(B.firstChild);
25189             }
25190         }
25191         if(B.attributes.children){ 
25192             var  cs = B.attributes.children;
25193             for(var  i = 0, len = cs.length; i < len; i++){
25194                 B.appendChild(this.createNode(cs[i]));
25195             }
25196             if(typeof  C == "function"){
25197                 C();
25198             }
25199         }else  if(this.dataUrl){
25200             this.requestData(B, C);
25201         }
25202     },
25203
25204     getParams: function(D){
25205         var  E = [], bp = this.baseParams;
25206         for(var  key  in  bp){
25207             if(typeof  bp[key] != "function"){
25208                 E.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
25209             }
25210         }
25211         var  n = this.queryParam === false ? 'node' : this.queryParam;
25212         E.push(n + "=", encodeURIComponent(D.id));
25213         return  E.join("");
25214     },
25215
25216     requestData : function(F, G){
25217         if(this.fireEvent("beforeload", this, F, G) !== false){
25218             this.transId = Roo.Ajax.request({
25219                 method:this.requestMethod,
25220                 url: this.dataUrl||this.url,
25221                 success: this.handleResponse,
25222                 failure: this.handleFailure,
25223                 scope: this,
25224                 argument: {callback: G, node: F},
25225                 params: this.getParams(F)
25226             });
25227         }else {
25228             
25229             
25230             if(typeof  G == "function"){
25231                 G();
25232             }
25233         }
25234     },
25235
25236     isLoading : function(){
25237         return  this.transId ? true : false;
25238     },
25239
25240     abort : function(){
25241         if(this.isLoading()){
25242             Roo.Ajax.abort(this.transId);
25243         }
25244     },
25245
25246     
25247     createNode : function(attr){
25248         
25249         if(this.baseAttrs){
25250             Roo.applyIf(attr, this.baseAttrs);
25251         }
25252         if(this.applyLoader !== false){
25253             attr.loader = this;
25254         }
25255         
25256         
25257         if(typeof(attr.uiProvider) == 'string'){
25258            attr.uiProvider = this.uiProviders[attr.uiProvider] || 
25259                 
25260  eval(attr.uiProvider);
25261         }
25262         if(typeof(this.uiProviders['default']) != 'undefined') {
25263             attr.uiProvider = this.uiProviders['default'];
25264         }
25265
25266         
25267         this.fireEvent('create', this, attr);
25268         
25269         attr.leaf  = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
25270         return (attr.leaf ?
25271                         new  Roo.tree.TreeNode(attr) :
25272                         new  Roo.tree.AsyncTreeNode(attr));
25273     },
25274
25275     processResponse : function(H, I, J){
25276         var  K = H.responseText;
25277         try {
25278             
25279             var  o = 
25280  eval("("+K+")");
25281             if (this.root !== false) {
25282                 o = o[this.root];
25283             }
25284             
25285             for(var  i = 0, len = o.length; i < len; i++){
25286                 var  n = this.createNode(o[i]);
25287                 if(n){
25288                     I.appendChild(n);
25289                 }
25290             }
25291             if(typeof  J == "function"){
25292                 J(this, I);
25293             }
25294         }catch(e){
25295             this.handleFailure(response);
25296         }
25297     },
25298
25299     handleResponse : function(L){
25300         this.transId = false;
25301         var  a = L.argument;
25302         this.processResponse(L, a.node, a.callback);
25303         this.fireEvent("load", this, a.node, L);
25304     },
25305
25306     handleFailure : function(M){
25307         this.transId = false;
25308         var  a = M.argument;
25309         this.fireEvent("loadexception", this, a.node, M);
25310         if(typeof  a.callback == "function"){
25311             a.callback(this, a.node);
25312         }
25313     }
25314 });
25315
25316
25317
25318
25319
25320 Roo.tree.TreeFilter = function(A, B){
25321     this.tree = A;
25322     this.filtered = {};
25323     Roo.apply(this, B);
25324 };
25325
25326 Roo.tree.TreeFilter.prototype = {
25327     clearBlank:false,
25328     reverse:false,
25329     autoClear:false,
25330     remove:false,
25331
25332      
25333
25334     filter : function(C, D, E){
25335         D = D || "text";
25336         var  f;
25337         if(typeof  C == "string"){
25338             var  vlen = C.length;
25339             
25340             if(vlen == 0 && this.clearBlank){
25341                 this.clear();
25342                 return;
25343             }
25344
25345             C = C.toLowerCase();
25346             f = function(n){
25347                 return  n.attributes[D].substr(0, vlen).toLowerCase() == C;
25348             };
25349         }else  if(C.exec){ 
25350             f = function(n){
25351                 return  C.test(n.attributes[D]);
25352             };
25353         }else {
25354             throw  'Illegal filter type, must be string or regex';
25355         }
25356
25357         this.filterBy(f, null, E);
25358         },
25359
25360     
25361
25362     filterBy : function(fn, F, G){
25363         G = G || this.tree.root;
25364         if(this.autoClear){
25365             this.clear();
25366         }
25367         var  af = this.filtered, rv = this.reverse;
25368         var  f = function(n){
25369             if(n == G){
25370                 return  true;
25371             }
25372             if(af[n.id]){
25373                 return  false;
25374             }
25375             var  m = fn.call(F || n, n);
25376             if(!m || rv){
25377                 af[n.id] = n;
25378                 n.ui.hide();
25379                 return  false;
25380             }
25381             return  true;
25382         };
25383         G.cascade(f);
25384         if(this.remove){
25385            for(var  id  in  af){
25386                if(typeof  id != "function"){
25387                    var  n = af[id];
25388                    if(n && n.parentNode){
25389                        n.parentNode.removeChild(n);
25390                    }
25391                }
25392            }
25393         }
25394     },
25395
25396     
25397
25398     clear : function(){
25399         var  t = this.tree;
25400         var  af = this.filtered;
25401         for(var  id  in  af){
25402             if(typeof  id != "function"){
25403                 var  n = af[id];
25404                 if(n){
25405                     n.ui.show();
25406                 }
25407             }
25408         }
25409
25410         this.filtered = {};
25411     }
25412 };
25413
25414
25415
25416  
25417
25418
25419
25420 Roo.tree.TreeSorter = function(A, B){
25421     Roo.apply(this, B);
25422     A.on("beforechildrenrendered", this.doSort, this);
25423     A.on("append", this.updateSort, this);
25424     A.on("insert", this.updateSort, this);
25425     
25426     var  C = this.dir && this.dir.toLowerCase() == "desc";
25427     var  p = this.property || "text";
25428     var  D = this.sortType;
25429     var  fs = this.folderSort;
25430     var  cs = this.caseSensitive === true;
25431     var  E = this.leafAttr || 'leaf';
25432
25433     this.sortFn = function(n1, n2){
25434         if(fs){
25435             if(n1.attributes[E] && !n2.attributes[E]){
25436                 return  1;
25437             }
25438             if(!n1.attributes[E] && n2.attributes[E]){
25439                 return  -1;
25440             }
25441         }
25442         var  v1 = D ? D(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
25443         var  v2 = D ? D(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
25444         if(v1 < v2){
25445                         return  C ? +1 : -1;
25446                 }else  if(v1 > v2){
25447                         return  C ? -1 : +1;
25448         }else {
25449                 return  0;
25450         }
25451     };
25452 };
25453
25454 Roo.tree.TreeSorter.prototype = {
25455     doSort : function(F){
25456         F.sort(this.sortFn);
25457     },
25458     
25459     compareNodes : function(n1, n2){
25460         return  (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
25461     },
25462     
25463     updateSort : function(G, H){
25464         if(H.childrenRendered){
25465             this.doSort.defer(1, this, [H]);
25466         }
25467     }
25468 };
25469
25470
25471
25472 if(Roo.dd.DropZone){
25473     
25474 Roo.tree.TreeDropZone = function(A, B){
25475     this.allowParentInsert = false;
25476     this.allowContainerDrop = false;
25477     this.appendOnly = false;
25478     Roo.tree.TreeDropZone.superclass.constructor.call(this, A.innerCt, B);
25479     this.tree = A;
25480     this.lastInsertClass = "x-tree-no-status";
25481     this.dragOverData = {};
25482 };
25483
25484 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
25485     ddGroup : "TreeDD",
25486     
25487     expandDelay : 1000,
25488     
25489     expandNode : function(C){
25490         if(C.hasChildNodes() && !C.isExpanded()){
25491             C.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
25492         }
25493     },
25494     
25495     queueExpand : function(D){
25496         this.expandProcId = this.expandNode.defer(this.expandDelay, this, [D]);
25497     },
25498     
25499     cancelExpand : function(){
25500         if(this.expandProcId){
25501             clearTimeout(this.expandProcId);
25502             this.expandProcId = false;
25503         }
25504     },
25505     
25506     isValidDropPoint : function(n, pt, dd, e, E){
25507         if(!n || !E){ return  false; }
25508         var  F = n.node;
25509         var  G = E.node;
25510         
25511         if(!(F && F.isTarget && pt)){
25512             return  false;
25513         }
25514         if(pt == "append" && F.allowChildren === false){
25515             return  false;
25516         }
25517         if((pt == "above" || pt == "below") && (F.parentNode && F.parentNode.allowChildren === false)){
25518             return  false;
25519         }
25520         if(G && (F == G || G.contains(F))){
25521             return  false;
25522         }
25523         
25524         var  H = this.dragOverData;
25525         H.tree = this.tree;
25526         H.target = F;
25527         H.data = E;
25528         H.point = pt;
25529         H.source = dd;
25530         H.rawEvent = e;
25531         H.dropNode = G;
25532         H.cancel = false;  
25533         var  I = this.tree.fireEvent("nodedragover", H);
25534         return  H.cancel === false && I !== false;
25535     },
25536     
25537     getDropPoint : function(e, n, dd){
25538         var  tn = n.node;
25539         if(tn.isRoot){
25540             return  tn.allowChildren !== false ? "append" : false; 
25541         }
25542         var  J = n.ddel;
25543         var  t = Roo.lib.Dom.getY(J), b = t + J.offsetHeight;
25544         var  y = Roo.lib.Event.getPageY(e);
25545         var  K = tn.allowChildren === false || tn.isLeaf();
25546         if(this.appendOnly || tn.parentNode.allowChildren === false){
25547             return  K ? false : "append";
25548         }
25549         var  L = false;
25550         if(!this.allowParentInsert){
25551             L = tn.hasChildNodes() && tn.isExpanded();
25552         }
25553         var  q = (b - t) / (K ? 2 : 3);
25554         if(y >= t && y < (t + q)){
25555             return  "above";
25556         }else  if(!L && (K || y >= b-q && y <= b)){
25557             return  "below";
25558         }else {
25559             return  "append";
25560         }
25561     },
25562     
25563     onNodeEnter : function(n, dd, e, M){
25564         this.cancelExpand();
25565     },
25566     
25567     onNodeOver : function(n, dd, e, N){
25568         var  pt = this.getDropPoint(e, n, dd);
25569         var  O = n.node;
25570         
25571         
25572         if(!this.expandProcId && pt == "append" && O.hasChildNodes() && !n.node.isExpanded()){
25573             this.queueExpand(O);
25574         }else  if(pt != "append"){
25575             this.cancelExpand();
25576         }
25577         
25578         
25579         var  P = this.dropNotAllowed;
25580         if(this.isValidDropPoint(n, pt, dd, e, N)){
25581            if(pt){
25582                var  el = n.ddel;
25583                var  cls;
25584                if(pt == "above"){
25585                    P = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
25586                    cls = "x-tree-drag-insert-above";
25587                }else  if(pt == "below"){
25588                    P = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
25589                    cls = "x-tree-drag-insert-below";
25590                }else {
25591                    P = "x-tree-drop-ok-append";
25592                    cls = "x-tree-drag-append";
25593                }
25594                if(this.lastInsertClass != cls){
25595                    Roo.fly(el).replaceClass(this.lastInsertClass, cls);
25596                    this.lastInsertClass = cls;
25597                }
25598            }
25599        }
25600        return  P;
25601     },
25602     
25603     onNodeOut : function(n, dd, e, Q){
25604         this.cancelExpand();
25605         this.removeDropIndicators(n);
25606     },
25607     
25608     onNodeDrop : function(n, dd, e, R){
25609         var  S = this.getDropPoint(e, n, dd);
25610         var  T = n.node;
25611         T.ui.startDrop();
25612         if(!this.isValidDropPoint(n, S, dd, e, R)){
25613             T.ui.endDrop();
25614             return  false;
25615         }
25616         
25617         var  U = R.node || (dd.getTreeNode ? dd.getTreeNode(R, T, S, e) : null);
25618         var  V = {
25619             tree : this.tree,
25620             target: T,
25621             data: R,
25622             point: S,
25623             source: dd,
25624             rawEvent: e,
25625             dropNode: U,
25626             cancel: !U   
25627         };
25628         var  W = this.tree.fireEvent("beforenodedrop", V);
25629         if(W === false || V.cancel === true || !V.dropNode){
25630             T.ui.endDrop();
25631             return  false;
25632         }
25633
25634         
25635         T = V.target;
25636         if(S == "append" && !T.isExpanded()){
25637             T.expand(false, null, function(){
25638                 this.completeDrop(V);
25639             }.createDelegate(this));
25640         }else {
25641             this.completeDrop(V);
25642         }
25643         return  true;
25644     },
25645     
25646     completeDrop : function(de){
25647         var  ns = de.dropNode, p = de.point, t = de.target;
25648         if(!(ns  instanceof  Array)){
25649             ns = [ns];
25650         }
25651         var  n;
25652         for(var  i = 0, len = ns.length; i < len; i++){
25653             n = ns[i];
25654             if(p == "above"){
25655                 t.parentNode.insertBefore(n, t);
25656             }else  if(p == "below"){
25657                 t.parentNode.insertBefore(n, t.nextSibling);
25658             }else {
25659                 t.appendChild(n);
25660             }
25661         }
25662
25663         n.ui.focus();
25664         if(this.tree.hlDrop){
25665             n.ui.highlight();
25666         }
25667
25668         t.ui.endDrop();
25669         this.tree.fireEvent("nodedrop", de);
25670     },
25671     
25672     afterNodeMoved : function(dd, X, e, Y, Z){
25673         if(this.tree.hlDrop){
25674             Z.ui.focus();
25675             Z.ui.highlight();
25676         }
25677
25678         this.tree.fireEvent("nodedrop", this.tree, Y, X, dd, e);
25679     },
25680     
25681     getTree : function(){
25682         return  this.tree;
25683     },
25684     
25685     removeDropIndicators : function(n){
25686         if(n && n.ddel){
25687             var  el = n.ddel;
25688             Roo.fly(el).removeClass([
25689                     "x-tree-drag-insert-above",
25690                     "x-tree-drag-insert-below",
25691                     "x-tree-drag-append"]);
25692             this.lastInsertClass = "_noclass";
25693         }
25694     },
25695     
25696     beforeDragDrop : function(a, e, id){
25697         this.cancelExpand();
25698         return  true;
25699     },
25700     
25701     afterRepair : function(c){
25702         if(c && Roo.enableFx){
25703             c.node.ui.highlight();
25704         }
25705
25706         this.hideProxy();
25707     }    
25708 });
25709
25710 }
25711
25712
25713  
25714
25715 if(Roo.dd.DragZone){
25716 Roo.tree.TreeDragZone = function(A, B){
25717     Roo.tree.TreeDragZone.superclass.constructor.call(this, A.getTreeEl(), B);
25718     this.tree = A;
25719 };
25720
25721 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
25722     ddGroup : "TreeDD",
25723     
25724     onBeforeDrag : function(C, e){
25725         var  n = C.node;
25726         return  n && n.draggable && !n.disabled;
25727     },
25728     
25729     onInitDrag : function(e){
25730         var  D = this.dragData;
25731         this.tree.getSelectionModel().select(D.node);
25732         this.proxy.update("");
25733         D.node.ui.appendDDGhost(this.proxy.ghost.dom);
25734         this.tree.fireEvent("startdrag", this.tree, D.node, e);
25735     },
25736     
25737     getRepairXY : function(e, E){
25738         return  E.node.ui.getDDRepairXY();
25739     },
25740     
25741     onEndDrag : function(F, e){
25742         this.tree.fireEvent("enddrag", this.tree, F.node, e);
25743     },
25744     
25745     onValidDrop : function(dd, e, id){
25746         this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
25747         this.hideProxy();
25748     },
25749     
25750     beforeInvalidDrop : function(e, id){
25751         
25752         var  sm = this.tree.getSelectionModel();
25753         sm.clearSelections();
25754         sm.select(this.dragData.node);
25755     }
25756 });
25757 }
25758
25759
25760
25761
25762 Roo.tree.TreeEditor = function(A, B){
25763     B = B || {};
25764     var  C = B.events ? B : new  Roo.form.TextField(B);
25765     Roo.tree.TreeEditor.superclass.constructor.call(this, C);
25766
25767     this.tree = A;
25768
25769     A.on('beforeclick', this.beforeNodeClick, this);
25770     A.getTreeEl().on('mousedown', this.hide, this);
25771     this.on('complete', this.updateNode, this);
25772     this.on('beforestartedit', this.fitToTree, this);
25773     this.on('startedit', this.bindScroll, this, {delay:10});
25774     this.on('specialkey', this.onSpecialKey, this);
25775 };
25776
25777 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
25778     
25779
25780     alignment: "l-l",
25781     
25782     autoSize: false,
25783     
25784
25785     hideEl : false,
25786     
25787
25788     cls: "x-small-editor x-tree-editor",
25789     
25790
25791     shim:false,
25792     
25793     shadow:"frame",
25794     
25795
25796     maxWidth: 250,
25797
25798     editDelay : 350,
25799
25800     
25801     fitToTree : function(ed, el){
25802         var  td = this.tree.getTreeEl().dom, nd = el.dom;
25803         if(td.scrollLeft >  nd.offsetLeft){ 
25804             td.scrollLeft = nd.offsetLeft;
25805         }
25806         var  w = Math.min(
25807                 this.maxWidth,
25808                 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - 
25809 5);
25810         this.setSize(w, '');
25811     },
25812
25813     
25814     triggerEdit : function(D){
25815         this.completeEdit();
25816         this.editNode = D;
25817         this.startEdit(D.ui.textNode, D.text);
25818     },
25819
25820     
25821     bindScroll : function(){
25822         this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
25823     },
25824
25825     
25826     beforeNodeClick : function(E, e){
25827         var  F = (this.lastClick ? this.lastClick.getElapsed() : 0);
25828         this.lastClick = new  Date();
25829         if(F > this.editDelay && this.tree.getSelectionModel().isSelected(E)){
25830             e.stopEvent();
25831             this.triggerEdit(E);
25832             return  false;
25833         }
25834     },
25835
25836     
25837     updateNode : function(ed, G){
25838         this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
25839         this.editNode.setText(G);
25840     },
25841
25842     
25843     onHide : function(){
25844         Roo.tree.TreeEditor.superclass.onHide.call(this);
25845         if(this.editNode){
25846             this.editNode.ui.focus();
25847         }
25848     },
25849
25850     
25851     onSpecialKey : function(H, e){
25852         var  k = e.getKey();
25853         if(k == e.ESC){
25854             e.stopEvent();
25855             this.cancelEdit();
25856         }else  if(k == e.ENTER && !e.hasModifier()){
25857             e.stopEvent();
25858             this.completeEdit();
25859         }
25860     }
25861 });
25862
25863
25864
25865  
25866
25867
25868
25869 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
25870     
25871     
25872     renderElements : function(n, a, A, B){
25873         
25874         this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
25875
25876         var  t = n.getOwnerTree();
25877         var  C = Pman.Tab.Document_TypesTree.tree.el.id;
25878         
25879         var  D = t.columns;
25880         var  bw = t.borderWidth;
25881         var  c = D[0];
25882         var  E = a.href ? a.href : Roo.isGecko ? "" : "#";
25883          var  cb = typeof  a.checked == "boolean";
25884         var  tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
25885         var  F = 'x-t-' + C + '-c0';
25886         var  G = [
25887             '<li class="x-tree-node">',
25888             
25889                 
25890                 '<div class="x-tree-node-el ', a.cls,'">',
25891                     
25892                     '<div class="x-tree-col ', F, '" style="width:', c.width-bw, 'px;">',
25893                 
25894                 
25895                         '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
25896                         '<img src="', this.emptyIcon, '" class="x-tree-ec-icon  " />',
25897                         '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
25898                            (a.icon ? ' x-tree-node-inline-icon' : ''),
25899                            (a.iconCls ? ' '+a.iconCls : ''),
25900                            '" unselectable="on" />',
25901                         (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + 
25902                              (a.checked ? 'checked="checked" />' : ' />')) : ''),
25903                              
25904                         '<a class="x-tree-node-anchor" hidefocus="on" href="',E,'" tabIndex="1" ',
25905                             (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
25906                             '<span unselectable="on" qtip="' + tx + '">',
25907                              tx,
25908                              '</span></a>' ,
25909                     '</div>',
25910                      '<a class="x-tree-node-anchor" hidefocus="on" href="',E,'" tabIndex="1" ',
25911                             (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
25912                  ];
25913         
25914         for(var  i = 1, len = D.length; i < len; i++){
25915             c = D[i];
25916             F = 'x-t-' + C + '-c' +i;
25917             tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
25918             G.push('<div class="x-tree-col ', F, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
25919                         '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
25920                       "</div>");
25921          }
25922
25923          
25924          G.push(
25925             '</a>',
25926             '<div class="x-clear"></div></div>',
25927             '<ul class="x-tree-node-ct" style="display:none;"></ul>',
25928             "</li>");
25929         
25930         if(B !== true && n.nextSibling && n.nextSibling.ui.getEl()){
25931             this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
25932                                 n.nextSibling.ui.getEl(), G.join(""));
25933         }else {
25934             this.wrap = Roo.DomHelper.insertHtml("beforeEnd", A, G.join(""));
25935         }
25936         var  el = this.wrap.firstChild;
25937         this.elRow = el;
25938         this.elNode = el.firstChild;
25939         this.ranchor = el.childNodes[1];
25940         this.ctNode = this.wrap.childNodes[1];
25941         var  cs = el.firstChild.childNodes;
25942         this.indentNode = cs[0];
25943         this.ecNode = cs[1];
25944         this.iconNode = cs[2];
25945         var  H = 3;
25946         if(cb){
25947             this.checkbox = cs[3];
25948             H++;
25949         }
25950
25951         this.anchor = cs[H];
25952         
25953         this.textNode = cs[H].firstChild;
25954         
25955         
25956         
25957         
25958         
25959        
25960     },
25961     initEvents : function(){
25962         Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
25963         
25964             
25965         var  a = this.ranchor;
25966
25967         var  el = Roo.get(a);
25968
25969         if(Roo.isOpera){ 
25970             el.setStyle("text-decoration", "none");
25971         }
25972
25973
25974         el.on("click", this.onClick, this);
25975         el.on("dblclick", this.onDblClick, this);
25976         el.on("contextmenu", this.onContextMenu, this);
25977         
25978     },
25979     
25980     
25981
25982     addClass : function(I){
25983         if(this.elRow){
25984             Roo.fly(this.elRow).addClass(I);
25985         }
25986         
25987     },
25988     
25989     
25990     removeClass : function(J){
25991         if(this.elRow){
25992             Roo.fly(this.elRow).removeClass(J);
25993         }
25994     }
25995
25996     
25997     
25998 });
25999
26000
26001
26002
26003  
26004
26005
26006
26007 Roo.tree.ColumnTree =  function(el, A)
26008 {
26009    Roo.tree.ColumnTree.superclass.constructor.call(this, el , A);
26010    this.addEvents({
26011         
26012
26013        "resize" : true
26014     });
26015     this.on('resize', this.onResize, this);
26016 };
26017
26018 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
26019     
26020     
26021     
26022     borderWidth: Roo.isBorderBox ? 0 : 2, 
26023     headEls : false,
26024     
26025     render : function(){
26026         
26027        
26028         Roo.tree.ColumnTree.superclass.render.apply(this);
26029         
26030         this.el.addClass('x-column-tree');
26031         
26032         this.headers = this.el.createChild(
26033             {cls:'x-tree-headers'},this.innerCt.dom);
26034    
26035         var  B = this.columns, c;
26036         var  C = 0;
26037         this.headEls = [];
26038         var   D = B.length;
26039         for(var  i = 0; i < D; i++){
26040              c = B[i];
26041              C += c.width;
26042             this.headEls.push(this.headers.createChild({
26043                  cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
26044                  cn: {
26045                      cls:'x-tree-hd-text',
26046                      html: c.header
26047                  },
26048                  style:'width:'+(c.width-this.borderWidth)+'px;'
26049              }));
26050         }
26051
26052         this.headers.createChild({cls:'x-clear'});
26053         
26054         this.headers.setWidth(C);
26055         
26056         this.innerCt.setStyle({ overflow: 'auto' });
26057         this.onResize(this.width, this.height);
26058              
26059         
26060     },
26061     onResize : function(w,h)
26062     {
26063         this.height = h;
26064         this.width = w;
26065         
26066         this.innerCt.setWidth(this.width);
26067         this.innerCt.setHeight(this.height-20);
26068         
26069         
26070         var  E = this.columns, c;
26071         var  F = 0;
26072         var  G = false;
26073         var  H = E.length;
26074         for(var  i = 0; i < H; i++){
26075             c = E[i];
26076             if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
26077                 
26078                 G  = this.headEls[i];
26079                 continue;
26080             }
26081
26082             F += c.width;
26083             
26084         }
26085         if (G) {
26086             G.setWidth(  ((w - F)-this.borderWidth - 20));
26087         }
26088
26089         this.headers.setWidth(w-20);
26090
26091         
26092         
26093         
26094     }
26095 });
26096
26097
26098
26099  
26100
26101
26102 Roo.menu.Menu = function(A){
26103     Roo.apply(this, A);
26104     this.id = this.id || Roo.id();
26105     this.addEvents({
26106         
26107
26108         beforeshow : true,
26109         
26110
26111         beforehide : true,
26112         
26113
26114         show : true,
26115         
26116
26117         hide : true,
26118         
26119
26120         click : true,
26121         
26122
26123         mouseover : true,
26124         
26125
26126         mouseout : true,
26127         
26128
26129         itemclick: true
26130     });
26131     if (this.registerMenu) {
26132         Roo.menu.MenuMgr.register(this);
26133     }
26134     
26135     var  B = this.items;
26136     this.items = new  Roo.util.MixedCollection();
26137     if(B){
26138         this.add.apply(this, B);
26139     }
26140 };
26141
26142 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
26143     
26144
26145     minWidth : 120,
26146     
26147
26148     shadow : "sides",
26149     
26150
26151     subMenuAlign : "tl-tr?",
26152     
26153
26154     defaultAlign : "tl-bl?",
26155     
26156
26157     allowOtherMenus : false,
26158     
26159
26160     registerMenu : true,
26161
26162     hidden:true,
26163
26164     
26165     render : function(){
26166         if(this.el){
26167             return;
26168         }
26169         var  el = this.el = new  Roo.Layer({
26170             cls: "x-menu",
26171             shadow:this.shadow,
26172             constrain: false,
26173             parentEl: this.parentEl || document.body,
26174             zindex:15000
26175         });
26176
26177         this.keyNav = new  Roo.menu.MenuNav(this);
26178
26179         if(this.plain){
26180             el.addClass("x-menu-plain");
26181         }
26182         if(this.cls){
26183             el.addClass(this.cls);
26184         }
26185
26186         
26187         this.focusEl = el.createChild({
26188             tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
26189         });
26190         var  ul = el.createChild({tag: "ul", cls: "x-menu-list"});
26191         ul.on("click", this.onClick, this);
26192         ul.on("mouseover", this.onMouseOver, this);
26193         ul.on("mouseout", this.onMouseOut, this);
26194         this.items.each(function(C){
26195             var  li = document.createElement("li");
26196             li.className = "x-menu-list-item";
26197             ul.dom.appendChild(li);
26198             C.render(li, this);
26199         }, this);
26200         this.ul = ul;
26201         this.autoWidth();
26202     },
26203
26204     
26205     autoWidth : function(){
26206         var  el = this.el, ul = this.ul;
26207         if(!el){
26208             return;
26209         }
26210         var  w = this.width;
26211         if(w){
26212             el.setWidth(w);
26213         }else  if(Roo.isIE){
26214             el.setWidth(this.minWidth);
26215             var  t = el.dom.offsetWidth; 
26216             el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
26217         }
26218     },
26219
26220     
26221     delayAutoWidth : function(){
26222         if(this.rendered){
26223             if(!this.awTask){
26224                 this.awTask = new  Roo.util.DelayedTask(this.autoWidth, this);
26225             }
26226
26227             this.awTask.delay(20);
26228         }
26229     },
26230
26231     
26232     findTargetItem : function(e){
26233         var  t = e.getTarget(".x-menu-list-item", this.ul,  true);
26234         if(t && t.menuItemId){
26235             return  this.items.get(t.menuItemId);
26236         }
26237     },
26238
26239     
26240     onClick : function(e){
26241         var  t;
26242         if(t = this.findTargetItem(e)){
26243             t.onClick(e);
26244             this.fireEvent("click", this, t, e);
26245         }
26246     },
26247
26248     
26249     setActiveItem : function(C, D){
26250         if(C != this.activeItem){
26251             if(this.activeItem){
26252                 this.activeItem.deactivate();
26253             }
26254
26255             this.activeItem = C;
26256             C.activate(D);
26257         }else  if(D){
26258             C.expandMenu();
26259         }
26260     },
26261
26262     
26263     tryActivate : function(E, F){
26264         var  G = this.items;
26265         for(var  i = E, len = G.length; i >= 0 && i < len; i+= F){
26266             var  C = G.get(i);
26267             if(!C.disabled && C.canActivate){
26268                 this.setActiveItem(C, false);
26269                 return  C;
26270             }
26271         }
26272         return  false;
26273     },
26274
26275     
26276     onMouseOver : function(e){
26277         var  t;
26278         if(t = this.findTargetItem(e)){
26279             if(t.canActivate && !t.disabled){
26280                 this.setActiveItem(t, true);
26281             }
26282         }
26283
26284         this.fireEvent("mouseover", this, e, t);
26285     },
26286
26287     
26288     onMouseOut : function(e){
26289         var  t;
26290         if(t = this.findTargetItem(e)){
26291             if(t == this.activeItem && t.shouldDeactivate(e)){
26292                 this.activeItem.deactivate();
26293                 delete  this.activeItem;
26294             }
26295         }
26296
26297         this.fireEvent("mouseout", this, e, t);
26298     },
26299
26300     
26301
26302     isVisible : function(){
26303         return  this.el && !this.hidden;
26304     },
26305
26306     
26307
26308     show : function(el, H, I){
26309         this.parentMenu = I;
26310         if(!this.el){
26311             this.render();
26312         }
26313
26314         this.fireEvent("beforeshow", this);
26315         this.showAt(this.el.getAlignToXY(el, H || this.defaultAlign), I, false);
26316     },
26317
26318     
26319
26320     showAt : function(xy, J, 
26321 _e){
26322         this.parentMenu = J;
26323         if(!this.el){
26324             this.render();
26325         }
26326         if(_e !== false){
26327             this.fireEvent("beforeshow", this);
26328             xy = this.el.adjustForConstraints(xy);
26329         }
26330
26331         this.el.setXY(xy);
26332         this.el.show();
26333         this.hidden = false;
26334         this.focus();
26335         this.fireEvent("show", this);
26336     },
26337
26338     focus : function(){
26339         if(!this.hidden){
26340             this.doFocus.defer(50, this);
26341         }
26342     },
26343
26344     doFocus : function(){
26345         if(!this.hidden){
26346             this.focusEl.focus();
26347         }
26348     },
26349
26350     
26351
26352     hide : function(K){
26353         if(this.el && this.isVisible()){
26354             this.fireEvent("beforehide", this);
26355             if(this.activeItem){
26356                 this.activeItem.deactivate();
26357                 this.activeItem = null;
26358             }
26359
26360             this.el.hide();
26361             this.hidden = true;
26362             this.fireEvent("hide", this);
26363         }
26364         if(K === true && this.parentMenu){
26365             this.parentMenu.hide(true);
26366         }
26367     },
26368
26369     
26370
26371     add : function(){
26372         var  a = arguments, l = a.length, L;
26373         for(var  i = 0; i < l; i++){
26374             var  el = a[i];
26375             if(el.render){ 
26376                 L = this.addItem(el);
26377             }else  if(typeof  el == "string"){ 
26378                 if(el == "separator" || el == "-"){
26379                     L = this.addSeparator();
26380                 }else {
26381                     L = this.addText(el);
26382                 }
26383             }else  if(el.tagName || el.el){ 
26384                 L = this.addElement(el);
26385             }else  if(typeof  el == "object"){ 
26386                 L = this.addMenuItem(el);
26387             }
26388         }
26389         return  L;
26390     },
26391
26392     
26393
26394     getEl : function(){
26395         if(!this.el){
26396             this.render();
26397         }
26398         return  this.el;
26399     },
26400
26401     
26402
26403     addSeparator : function(){
26404         return  this.addItem(new  Roo.menu.Separator());
26405     },
26406
26407     
26408
26409     addElement : function(el){
26410         return  this.addItem(new  Roo.menu.BaseItem(el));
26411     },
26412
26413     
26414
26415     addItem : function(M){
26416         this.items.add(M);
26417         if(this.ul){
26418             var  li = document.createElement("li");
26419             li.className = "x-menu-list-item";
26420             this.ul.dom.appendChild(li);
26421             M.render(li, this);
26422             this.delayAutoWidth();
26423         }
26424         return  M;
26425     },
26426
26427     
26428
26429     addMenuItem : function(N){
26430         if(!(N  instanceof  Roo.menu.Item)){
26431             if(typeof  N.checked == "boolean"){ 
26432                 N = new  Roo.menu.CheckItem(N);
26433             }else {
26434                 N = new  Roo.menu.Item(N);
26435             }
26436         }
26437         return  this.addItem(N);
26438     },
26439
26440     
26441
26442     addText : function(O){
26443         return  this.addItem(new  Roo.menu.TextItem(O));
26444     },
26445
26446     
26447
26448     insert : function(P, Q){
26449         this.items.insert(P, Q);
26450         if(this.ul){
26451             var  li = document.createElement("li");
26452             li.className = "x-menu-list-item";
26453             this.ul.dom.insertBefore(li, this.ul.dom.childNodes[P]);
26454             Q.render(li, this);
26455             this.delayAutoWidth();
26456         }
26457         return  Q;
26458     },
26459
26460     
26461
26462     remove : function(R){
26463         this.items.removeKey(R.id);
26464         R.destroy();
26465     },
26466
26467     
26468
26469     removeAll : function(){
26470         var  f;
26471         while(f = this.items.first()){
26472             this.remove(f);
26473         }
26474     }
26475 });
26476
26477
26478 Roo.menu.MenuNav = function(S){
26479     Roo.menu.MenuNav.superclass.constructor.call(this, S.el);
26480     this.scope = this.menu = S;
26481 };
26482
26483 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
26484     doRelay : function(e, h){
26485         var  k = e.getKey();
26486         if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN ){
26487             this.menu.tryActivate(0, 1);
26488             return  false;
26489         }
26490         return  h.call(this.scope || this, e, this.menu);
26491     },
26492
26493     up : function(e, m){
26494         if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
26495             m.tryActivate(m.items.length-1, -1);
26496         }
26497     },
26498
26499     down : function(e, m){
26500         if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
26501             m.tryActivate(0, 1);
26502         }
26503     },
26504
26505     right : function(e, m){
26506         if(m.activeItem){
26507             m.activeItem.expandMenu(true);
26508         }
26509     },
26510
26511     left : function(e, m){
26512         m.hide();
26513         if(m.parentMenu && m.parentMenu.activeItem){
26514             m.parentMenu.activeItem.activate();
26515         }
26516     },
26517
26518     enter : function(e, m){
26519         if(m.activeItem){
26520             e.stopPropagation();
26521             m.activeItem.onClick(e);
26522             m.fireEvent("click", this, m.activeItem);
26523             return  true;
26524         }
26525     }
26526 });
26527
26528
26529  
26530
26531
26532 Roo.menu.MenuMgr = function(){
26533    var  A, B, C = {}, attached = false, lastShow = new  Date();
26534
26535    
26536    function  D(){
26537        A = {};
26538        B = new  Roo.util.MixedCollection();
26539        Roo.get(document).addKeyListener(27, function(){
26540            if(B.length > 0){
26541                E();
26542            }
26543        });
26544    }
26545
26546    
26547    function  E(){
26548        if(B && B.length > 0){
26549            var  c = B.clone();
26550            c.each(function(m){
26551                m.hide();
26552            });
26553        }
26554    }
26555
26556    
26557    function  F(m){
26558        B.remove(m);
26559        if(B.length < 1){
26560            Roo.get(document).un("mousedown", J);
26561            attached = false;
26562        }
26563    }
26564
26565    
26566    function  G(m){
26567        var  L = B.last();
26568        lastShow = new  Date();
26569        B.add(m);
26570        if(!attached){
26571            Roo.get(document).on("mousedown", J);
26572            attached = true;
26573        }
26574        if(m.parentMenu){
26575           m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
26576           m.parentMenu.activeChild = m;
26577        }else  if(L && L.isVisible()){
26578           m.getEl().setZIndex(parseInt(L.getEl().getStyle("z-index"), 10) + 3);
26579        }
26580    }
26581
26582    
26583    function  H(m){
26584        if(m.activeChild){
26585            m.activeChild.hide();
26586        }
26587        if(m.autoHideTimer){
26588            clearTimeout(m.autoHideTimer);
26589            delete  m.autoHideTimer;
26590        }
26591    }
26592
26593    
26594    function  I(m){
26595        var  pm = m.parentMenu;
26596        if(!pm && !m.allowOtherMenus){
26597            E();
26598        }else  if(pm && pm.activeChild && B != m){
26599            pm.activeChild.hide();
26600        }
26601    }
26602
26603    
26604    function  J(e){
26605        if(lastShow.getElapsed() > 50 && B.length > 0 && !e.getTarget(".x-menu")){
26606            E();
26607        }
26608    }
26609
26610    
26611    function  K(mi, L){
26612        if(L){
26613            var  g = C[mi.group];
26614            for(var  i = 0, l = g.length; i < l; i++){
26615                if(g[i] != mi){
26616                    g[i].setChecked(false);
26617                }
26618            }
26619        }
26620    }
26621
26622    return  {
26623
26624        
26625
26626        hideAll : function(){
26627             E();  
26628        },
26629
26630        
26631        register : function(Q){
26632            if(!A){
26633                D();
26634            }
26635
26636            A[Q.id] = Q;
26637            Q.on("beforehide", H);
26638            Q.on("hide", F);
26639            Q.on("beforeshow", I);
26640            Q.on("show", G);
26641            var  g = Q.group;
26642            if(g && Q.events["checkchange"]){
26643                if(!C[g]){
26644                    C[g] = [];
26645                }
26646
26647                C[g].push(Q);
26648                Q.on("checkchange", onCheck);
26649            }
26650        },
26651
26652         
26653
26654        get : function(R){
26655            if(typeof  R == "string"){ 
26656                return  A[R];
26657            }else  if(R.events){  
26658                return  R;
26659            }else  if(typeof  R.length == 'number'){ 
26660                return  new  Roo.menu.Menu({items:R});
26661            }else { 
26662                return  new  Roo.menu.Menu(R);
26663            }
26664        },
26665
26666        
26667        unregister : function(S){
26668            delete  A[S.id];
26669            S.un("beforehide", H);
26670            S.un("hide", F);
26671            S.un("beforeshow", I);
26672            S.un("show", G);
26673            var  g = S.group;
26674            if(g && S.events["checkchange"]){
26675                C[g].remove(S);
26676                S.un("checkchange", onCheck);
26677            }
26678        },
26679
26680        
26681        registerCheckable : function(T){
26682            var  g = T.group;
26683            if(g){
26684                if(!C[g]){
26685                    C[g] = [];
26686                }
26687
26688                C[g].push(T);
26689                T.on("beforecheckchange", K);
26690            }
26691        },
26692
26693        
26694        unregisterCheckable : function(U){
26695            var  g = U.group;
26696            if(g){
26697                C[g].remove(U);
26698                U.un("beforecheckchange", K);
26699            }
26700        }
26701    };
26702 }();
26703
26704
26705  
26706
26707
26708
26709 Roo.menu.BaseItem = function(A){
26710     Roo.menu.BaseItem.superclass.constructor.call(this, A);
26711
26712     this.addEvents({
26713         
26714
26715         click: true,
26716         
26717
26718         activate : true,
26719         
26720
26721         deactivate : true
26722     });
26723
26724     if(this.handler){
26725         this.on("click", this.handler, this.scope, true);
26726     }
26727 };
26728
26729 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
26730     
26731
26732     
26733
26734     canActivate : false,
26735     
26736
26737     activeClass : "x-menu-item-active",
26738     
26739
26740     hideOnClick : true,
26741     
26742
26743     hideDelay : 100,
26744
26745     
26746     ctype: "Roo.menu.BaseItem",
26747
26748     
26749     actionMode : "container",
26750
26751     
26752     render : function(B, C){
26753         this.parentMenu = C;
26754         Roo.menu.BaseItem.superclass.render.call(this, B);
26755         this.container.menuItemId = this.id;
26756     },
26757
26758     
26759     onRender : function(D, E){
26760         this.el = Roo.get(this.el);
26761         D.dom.appendChild(this.el.dom);
26762     },
26763
26764     
26765     onClick : function(e){
26766         if(!this.disabled && this.fireEvent("click", this, e) !== false
26767                 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
26768             this.handleClick(e);
26769         }else {
26770             e.stopEvent();
26771         }
26772     },
26773
26774     
26775     activate : function(){
26776         if(this.disabled){
26777             return  false;
26778         }
26779         var  li = this.container;
26780         li.addClass(this.activeClass);
26781         this.region = li.getRegion().adjust(2, 2, -2, -2);
26782         this.fireEvent("activate", this);
26783         return  true;
26784     },
26785
26786     
26787     deactivate : function(){
26788         this.container.removeClass(this.activeClass);
26789         this.fireEvent("deactivate", this);
26790     },
26791
26792     
26793     shouldDeactivate : function(e){
26794         return  !this.region || !this.region.contains(e.getPoint());
26795     },
26796
26797     
26798     handleClick : function(e){
26799         if(this.hideOnClick){
26800             this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
26801         }
26802     },
26803
26804     
26805     expandMenu : function(F){
26806         
26807     },
26808
26809     
26810     hideMenu : function(){
26811         
26812     }
26813 });
26814
26815
26816  
26817
26818
26819 Roo.menu.Adapter = function(A, B){
26820     Roo.menu.Adapter.superclass.constructor.call(this, B);
26821     this.component = A;
26822 };
26823 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
26824     
26825     canActivate : true,
26826
26827     
26828     onRender : function(C, D){
26829         this.component.render(C);
26830         this.el = this.component.getEl();
26831     },
26832
26833     
26834     activate : function(){
26835         if(this.disabled){
26836             return  false;
26837         }
26838
26839         this.component.focus();
26840         this.fireEvent("activate", this);
26841         return  true;
26842     },
26843
26844     
26845     deactivate : function(){
26846         this.fireEvent("deactivate", this);
26847     },
26848
26849     
26850     disable : function(){
26851         this.component.disable();
26852         Roo.menu.Adapter.superclass.disable.call(this);
26853     },
26854
26855     
26856     enable : function(){
26857         this.component.enable();
26858         Roo.menu.Adapter.superclass.enable.call(this);
26859     }
26860 });
26861
26862
26863
26864
26865
26866 Roo.menu.TextItem = function(A){
26867     this.text = A;
26868     Roo.menu.TextItem.superclass.constructor.call(this);
26869 };
26870
26871 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
26872     
26873
26874     hideOnClick : false,
26875     
26876
26877     itemCls : "x-menu-text",
26878
26879     
26880     onRender : function(){
26881         var  s = document.createElement("span");
26882         s.className = this.itemCls;
26883         s.innerHTML = this.text;
26884         this.el = s;
26885         Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
26886     }
26887 });
26888
26889
26890
26891
26892
26893 Roo.menu.Separator = function(A){
26894     Roo.menu.Separator.superclass.constructor.call(this, A);
26895 };
26896
26897 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
26898     
26899
26900     itemCls : "x-menu-sep",
26901     
26902
26903     hideOnClick : false,
26904
26905     
26906     onRender : function(li){
26907         var  s = document.createElement("span");
26908         s.className = this.itemCls;
26909         s.innerHTML = "&#160;";
26910         this.el = s;
26911         li.addClass("x-menu-sep-li");
26912         Roo.menu.Separator.superclass.onRender.apply(this, arguments);
26913     }
26914 });
26915
26916
26917
26918
26919 Roo.menu.Item = function(A){
26920     Roo.menu.Item.superclass.constructor.call(this, A);
26921     if(this.menu){
26922         this.menu = Roo.menu.MenuMgr.get(this.menu);
26923     }
26924 };
26925 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
26926     
26927
26928     
26929
26930     itemCls : "x-menu-item",
26931     
26932
26933     canActivate : true,
26934     
26935
26936     showDelay: 200,
26937     
26938     hideDelay: 200,
26939
26940     
26941     ctype: "Roo.menu.Item",
26942     
26943     
26944     onRender : function(B, C){
26945         var  el = document.createElement("a");
26946         el.hideFocus = true;
26947         el.unselectable = "on";
26948         el.href = this.href || "#";
26949         if(this.hrefTarget){
26950             el.target = this.hrefTarget;
26951         }
26952
26953         el.className = this.itemCls + (this.menu ?  " x-menu-item-arrow" : "") + (this.cls ?  " " + this.cls : "");
26954         el.innerHTML = String.format(
26955                 '<img src="{0}" class="x-menu-item-icon {2}" />{1}',
26956                 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || '');
26957         this.el = el;
26958         Roo.menu.Item.superclass.onRender.call(this, B, C);
26959     },
26960
26961     
26962
26963     setText : function(D){
26964         this.text = D;
26965         if(this.rendered){
26966             this.el.update(String.format(
26967                 '<img src="{0}" class="x-menu-item-icon {2}">{1}',
26968                 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
26969             this.parentMenu.autoWidth();
26970         }
26971     },
26972
26973     
26974     handleClick : function(e){
26975         if(!this.href){ 
26976             e.stopEvent();
26977         }
26978
26979         Roo.menu.Item.superclass.handleClick.apply(this, arguments);
26980     },
26981
26982     
26983     activate : function(E){
26984         if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
26985             this.focus();
26986             if(E){
26987                 this.expandMenu();
26988             }
26989         }
26990         return  true;
26991     },
26992
26993     
26994     shouldDeactivate : function(e){
26995         if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
26996             if(this.menu && this.menu.isVisible()){
26997                 return  !this.menu.getEl().getRegion().contains(e.getPoint());
26998             }
26999             return  true;
27000         }
27001         return  false;
27002     },
27003
27004     
27005     deactivate : function(){
27006         Roo.menu.Item.superclass.deactivate.apply(this, arguments);
27007         this.hideMenu();
27008     },
27009
27010     
27011     expandMenu : function(F){
27012         if(!this.disabled && this.menu){
27013             clearTimeout(this.hideTimer);
27014             delete  this.hideTimer;
27015             if(!this.menu.isVisible() && !this.showTimer){
27016                 this.showTimer = this.deferExpand.defer(this.showDelay, this, [F]);
27017             }else  if (this.menu.isVisible() && F){
27018                 this.menu.tryActivate(0, 1);
27019             }
27020         }
27021     },
27022
27023     
27024     deferExpand : function(G){
27025         delete  this.showTimer;
27026         this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
27027         if(G){
27028             this.menu.tryActivate(0, 1);
27029         }
27030     },
27031
27032     
27033     hideMenu : function(){
27034         clearTimeout(this.showTimer);
27035         delete  this.showTimer;
27036         if(!this.hideTimer && this.menu && this.menu.isVisible()){
27037             this.hideTimer = this.deferHide.defer(this.hideDelay, this);
27038         }
27039     },
27040
27041     
27042     deferHide : function(){
27043         delete  this.hideTimer;
27044         this.menu.hide();
27045     }
27046 });
27047
27048
27049  
27050
27051
27052 Roo.menu.CheckItem = function(A){
27053     Roo.menu.CheckItem.superclass.constructor.call(this, A);
27054     this.addEvents({
27055         
27056
27057         "beforecheckchange" : true,
27058         
27059
27060         "checkchange" : true
27061     });
27062     if(this.checkHandler){
27063         this.on('checkchange', this.checkHandler, this.scope);
27064     }
27065 };
27066 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
27067     
27068
27069     
27070
27071     itemCls : "x-menu-item x-menu-check-item",
27072     
27073
27074     groupClass : "x-menu-group-item",
27075
27076     
27077
27078     checked: false,
27079
27080     
27081     ctype: "Roo.menu.CheckItem",
27082
27083     
27084     onRender : function(c){
27085         Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
27086         if(this.group){
27087             this.el.addClass(this.groupClass);
27088         }
27089
27090         Roo.menu.MenuMgr.registerCheckable(this);
27091         if(this.checked){
27092             this.checked = false;
27093             this.setChecked(true, true);
27094         }
27095     },
27096
27097     
27098     destroy : function(){
27099         if(this.rendered){
27100             Roo.menu.MenuMgr.unregisterCheckable(this);
27101         }
27102
27103         Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
27104     },
27105
27106     
27107
27108     setChecked : function(B, C){
27109         if(this.checked != B && this.fireEvent("beforecheckchange", this, B) !== false){
27110             if(this.container){
27111                 this.container[B ? "addClass" : "removeClass"]("x-menu-item-checked");
27112             }
27113
27114             this.checked = B;
27115             if(C !== true){
27116                 this.fireEvent("checkchange", this, B);
27117             }
27118         }
27119     },
27120
27121     
27122     handleClick : function(e){
27123        if(!this.disabled && !(this.checked && this.group)){
27124            this.setChecked(!this.checked);
27125        }
27126
27127        Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
27128     }
27129 });
27130
27131
27132  
27133
27134
27135 Roo.menu.DateItem = function(A){
27136     Roo.menu.DateItem.superclass.constructor.call(this, new  Roo.DatePicker(A), A);
27137     
27138
27139     this.picker = this.component;
27140     this.addEvents({select: true});
27141     
27142     this.picker.on("render", function(B){
27143         B.getEl().swallowEvent("click");
27144         B.container.addClass("x-menu-date-item");
27145     });
27146
27147     this.picker.on("select", this.onSelect, this);
27148 };
27149
27150 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
27151     
27152     onSelect : function(B, C){
27153         this.fireEvent("select", this, C, B);
27154         Roo.menu.DateItem.superclass.handleClick.call(this);
27155     }
27156 });
27157
27158
27159  
27160
27161
27162 Roo.menu.ColorItem = function(A){
27163     Roo.menu.ColorItem.superclass.constructor.call(this, new  Roo.ColorPalette(A), A);
27164     
27165
27166     this.palette = this.component;
27167     this.relayEvents(this.palette, ["select"]);
27168     if(this.selectHandler){
27169         this.on('select', this.selectHandler, this.scope);
27170     }
27171 };
27172 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);
27173
27174
27175  
27176
27177
27178
27179 Roo.menu.DateMenu = function(A){
27180     Roo.menu.DateMenu.superclass.constructor.call(this, A);
27181     this.plain = true;
27182     var  di = new  Roo.menu.DateItem(A);
27183     this.add(di);
27184     
27185
27186     this.picker = di.picker;
27187     
27188
27189     this.relayEvents(di, ["select"]);
27190
27191     this.on('beforeshow', function(){
27192         if(this.picker){
27193             this.picker.hideMonthPicker(true);
27194         }
27195     }, this);
27196 };
27197 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
27198     cls:'x-date-menu'
27199 });
27200
27201
27202  
27203
27204
27205
27206 Roo.menu.ColorMenu = function(A){
27207     Roo.menu.ColorMenu.superclass.constructor.call(this, A);
27208     this.plain = true;
27209     var  ci = new  Roo.menu.ColorItem(A);
27210     this.add(ci);
27211     
27212
27213     this.palette = ci.palette;
27214     
27215
27216     this.relayEvents(ci, ["select"]);
27217 };
27218 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);
27219
27220
27221  
27222
27223
27224 Roo.form.Field = function(A){
27225     Roo.form.Field.superclass.constructor.call(this, A);
27226 };
27227
27228 Roo.extend(Roo.form.Field, Roo.BoxComponent,  {
27229     
27230
27231        
27232
27233      
27234     
27235
27236     invalidClass : "x-form-invalid",
27237     
27238
27239     invalidText : "The value in this field is invalid",
27240     
27241
27242     focusClass : "x-form-focus",
27243     
27244
27245     validationEvent : "keyup",
27246     
27247
27248     validateOnBlur : true,
27249     
27250
27251     validationDelay : 250,
27252     
27253
27254     defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"},
27255     
27256
27257     fieldClass : "x-form-field",
27258     
27259
27260     msgTarget : 'qtip',
27261     
27262
27263     msgFx : 'normal',
27264
27265     
27266
27267     readOnly : false,
27268
27269     
27270
27271     disabled : false,
27272
27273     
27274
27275     inputType : undefined,
27276     
27277     
27278
27279         tabIndex : undefined,
27280         
27281     
27282     isFormField : true,
27283
27284     
27285     hasFocus : false,
27286     
27287
27288     
27289
27290     value : undefined,
27291
27292     
27293
27294     
27295
27296
27297         
27298         initComponent : function(){
27299         Roo.form.Field.superclass.initComponent.call(this);
27300         this.addEvents({
27301             
27302
27303             focus : true,
27304             
27305
27306             blur : true,
27307             
27308
27309             specialkey : true,
27310             
27311
27312             change : true,
27313             
27314
27315             invalid : true,
27316             
27317
27318             valid : true
27319         });
27320     },
27321
27322     
27323
27324     getName: function(){
27325          return  this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
27326     },
27327
27328     
27329     onRender : function(ct, B){
27330         Roo.form.Field.superclass.onRender.call(this, ct, B);
27331         if(!this.el){
27332             var  cfg = this.getAutoCreate();
27333             if(!cfg.name){
27334                 cfg.name = this.name || this.id;
27335             }
27336             if(this.inputType){
27337                 cfg.type = this.inputType;
27338             }
27339
27340             this.el = ct.createChild(cfg, B);
27341         }
27342         var  C = this.el.dom.type;
27343         if(C){
27344             if(C == 'password'){
27345                 C = 'text';
27346             }
27347
27348             this.el.addClass('x-form-'+C);
27349         }
27350         if(this.readOnly){
27351             this.el.dom.readOnly = true;
27352         }
27353         if(this.tabIndex !== undefined){
27354             this.el.dom.setAttribute('tabIndex', this.tabIndex);
27355         }
27356
27357
27358         this.el.addClass([this.fieldClass, this.cls]);
27359         this.initValue();
27360     },
27361
27362     
27363
27364     applyTo : function(D){
27365         this.allowDomMove = false;
27366         this.el = Roo.get(D);
27367         this.render(this.el.dom.parentNode);
27368         return  this;
27369     },
27370
27371     
27372     initValue : function(){
27373         if(this.value !== undefined){
27374             this.setValue(this.value);
27375         }else  if(this.el.dom.value.length > 0){
27376             this.setValue(this.el.dom.value);
27377         }
27378     },
27379
27380     
27381
27382     isDirty : function() {
27383         if(this.disabled) {
27384             return  false;
27385         }
27386         return  String(this.getValue()) !== String(this.originalValue);
27387     },
27388
27389     
27390     afterRender : function(){
27391         Roo.form.Field.superclass.afterRender.call(this);
27392         this.initEvents();
27393     },
27394
27395     
27396     fireKey : function(e){
27397         if(e.isNavKeyPress()){
27398             this.fireEvent("specialkey", this, e);
27399         }
27400     },
27401
27402     
27403
27404     reset : function(){
27405         this.setValue(this.originalValue);
27406         this.clearInvalid();
27407     },
27408
27409     
27410     initEvents : function(){
27411         this.el.on(Roo.isIE ? "keydown" : "keypress", this.fireKey,  this);
27412         this.el.on("focus", this.onFocus,  this);
27413         this.el.on("blur", this.onBlur,  this);
27414
27415         
27416         this.originalValue = this.getValue();
27417     },
27418
27419     
27420     onFocus : function(){
27421         if(!Roo.isOpera && this.focusClass){ 
27422             this.el.addClass(this.focusClass);
27423         }
27424         if(!this.hasFocus){
27425             this.hasFocus = true;
27426             this.startValue = this.getValue();
27427             this.fireEvent("focus", this);
27428         }
27429     },
27430
27431     beforeBlur : Roo.emptyFn,
27432
27433     
27434     onBlur : function(){
27435         this.beforeBlur();
27436         if(!Roo.isOpera && this.focusClass){ 
27437             this.el.removeClass(this.focusClass);
27438         }
27439
27440         this.hasFocus = false;
27441         if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
27442             this.validate();
27443         }
27444         var  v = this.getValue();
27445         if(String(v) !== String(this.startValue)){
27446             this.fireEvent('change', this, v, this.startValue);
27447         }
27448
27449         this.fireEvent("blur", this);
27450     },
27451
27452     
27453
27454     isValid : function(E){
27455         if(this.disabled){
27456             return  true;
27457         }
27458         var  F = this.preventMark;
27459         this.preventMark = E === true;
27460         var  v = this.validateValue(this.processValue(this.getRawValue()));
27461         this.preventMark = F;
27462         return  v;
27463     },
27464
27465     
27466
27467     validate : function(){
27468         if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
27469             this.clearInvalid();
27470             return  true;
27471         }
27472         return  false;
27473     },
27474
27475     processValue : function(G){
27476         return  G;
27477     },
27478
27479     
27480     
27481     validateValue : function(H){
27482         return  true;
27483     },
27484
27485     
27486
27487     markInvalid : function(I){
27488         if(!this.rendered || this.preventMark){ 
27489             return;
27490         }
27491
27492         this.el.addClass(this.invalidClass);
27493         I = I || this.invalidText;
27494         switch(this.msgTarget){
27495             case  'qtip':
27496                 this.el.dom.qtip = I;
27497                 this.el.dom.qclass = 'x-form-invalid-tip';
27498                 if(Roo.QuickTips){ 
27499                     Roo.QuickTips.enable();
27500                 }
27501                 break;
27502             case  'title':
27503                 this.el.dom.title = I;
27504                 break;
27505             case  'under':
27506                 if(!this.errorEl){
27507                     var  elp = this.el.findParent('.x-form-element', 5, true);
27508                     this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
27509                     this.errorEl.setWidth(elp.getWidth(true)-20);
27510                 }
27511
27512                 this.errorEl.update(I);
27513                 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
27514                 break;
27515             case  'side':
27516                 if(!this.errorIcon){
27517                     var  elp = this.el.findParent('.x-form-element', 5, true);
27518                     this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
27519                 }
27520
27521                 this.alignErrorIcon();
27522                 this.errorIcon.dom.qtip = I;
27523                 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
27524                 this.errorIcon.show();
27525                 this.on('resize', this.alignErrorIcon, this);
27526                 break;
27527             default:
27528                 var  t = Roo.getDom(this.msgTarget);
27529                 t.innerHTML = I;
27530                 t.style.display = this.msgDisplay;
27531                 break;
27532         }
27533
27534         this.fireEvent('invalid', this, I);
27535     },
27536
27537     
27538     alignErrorIcon : function(){
27539         this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
27540     },
27541
27542     
27543
27544     clearInvalid : function(){
27545         if(!this.rendered || this.preventMark){ 
27546             return;
27547         }
27548
27549         this.el.removeClass(this.invalidClass);
27550         switch(this.msgTarget){
27551             case  'qtip':
27552                 this.el.dom.qtip = '';
27553                 break;
27554             case  'title':
27555                 this.el.dom.title = '';
27556                 break;
27557             case  'under':
27558                 if(this.errorEl){
27559                     Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
27560                 }
27561                 break;
27562             case  'side':
27563                 if(this.errorIcon){
27564                     this.errorIcon.dom.qtip = '';
27565                     this.errorIcon.hide();
27566                     this.un('resize', this.alignErrorIcon, this);
27567                 }
27568                 break;
27569             default:
27570                 var  t = Roo.getDom(this.msgTarget);
27571                 t.innerHTML = '';
27572                 t.style.display = 'none';
27573                 break;
27574         }
27575
27576         this.fireEvent('valid', this);
27577     },
27578
27579     
27580
27581     getRawValue : function(){
27582         var  v = this.el.getValue();
27583         if(v === this.emptyText){
27584             v = '';
27585         }
27586         return  v;
27587     },
27588
27589     
27590
27591     getValue : function(){
27592         var  v = this.el.getValue();
27593         if(v === this.emptyText || v === undefined){
27594             v = '';
27595         }
27596         return  v;
27597     },
27598
27599     
27600
27601     setRawValue : function(v){
27602         return  this.el.dom.value = (v === null || v === undefined ? '' : v);
27603     },
27604
27605     
27606
27607     setValue : function(v){
27608         this.value = v;
27609         if(this.rendered){
27610             this.el.dom.value = (v === null || v === undefined ? '' : v);
27611             this.validate();
27612         }
27613     },
27614
27615     adjustSize : function(w, h){
27616         var  s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
27617         s.width = this.adjustWidth(this.el.dom.tagName, s.width);
27618         return  s;
27619     },
27620
27621     adjustWidth : function(J, w){
27622         J = J.toLowerCase();
27623         if(typeof  w == 'number' && Roo.isStrict && !Roo.isSafari){
27624             if(Roo.isIE && (J == 'input' || J == 'textarea')){
27625                 if(J == 'input'){
27626                     return  w + 2;
27627                 }
27628                 if(J = 'textarea'){
27629                     return  w-2;
27630                 }
27631             }else  if(Roo.isOpera){
27632                 if(J == 'input'){
27633                     return  w + 2;
27634                 }
27635                 if(J = 'textarea'){
27636                     return  w-2;
27637                 }
27638             }
27639         }
27640         return  w;
27641     }
27642 });
27643
27644
27645
27646 Roo.form.Field.msgFx = {
27647     normal : {
27648         show: function(K, f){
27649             K.setDisplayed('block');
27650         },
27651
27652         hide : function(L, f){
27653             L.setDisplayed(false).update('');
27654         }
27655     },
27656
27657     slide : {
27658         show: function(M, f){
27659             M.slideIn('t', {stopFx:true});
27660         },
27661
27662         hide : function(N, f){
27663             N.slideOut('t', {stopFx:true,useDisplay:true});
27664         }
27665     },
27666
27667     slideRight : {
27668         show: function(O, f){
27669             O.fixDisplay();
27670             O.alignTo(f.el, 'tl-tr');
27671             O.slideIn('l', {stopFx:true});
27672         },
27673
27674         hide : function(P, f){
27675             P.slideOut('l', {stopFx:true,useDisplay:true});
27676         }
27677     }
27678 };
27679
27680
27681  
27682
27683
27684
27685 Roo.form.TextField = function(A){
27686     Roo.form.TextField.superclass.constructor.call(this, A);
27687     this.addEvents({
27688         
27689
27690         autosize : true
27691     });
27692 };
27693
27694 Roo.extend(Roo.form.TextField, Roo.form.Field,  {
27695     
27696
27697     grow : false,
27698     
27699
27700     growMin : 30,
27701     
27702
27703     growMax : 800,
27704     
27705
27706     vtype : null,
27707     
27708
27709     maskRe : null,
27710     
27711
27712     disableKeyFilter : false,
27713     
27714
27715     allowBlank : true,
27716     
27717
27718     minLength : 0,
27719     
27720
27721     maxLength : Number.MAX_VALUE,
27722     
27723
27724     minLengthText : "The minimum length for this field is {0}",
27725     
27726
27727     maxLengthText : "The maximum length for this field is {0}",
27728     
27729
27730     selectOnFocus : false,
27731     
27732
27733     blankText : "This field is required",
27734     
27735
27736     validator : null,
27737     
27738
27739     regex : null,
27740     
27741
27742     regexText : "",
27743     
27744
27745     emptyText : null,
27746     
27747
27748     emptyClass : 'x-form-empty-field',
27749
27750     
27751     initEvents : function(){
27752         Roo.form.TextField.superclass.initEvents.call(this);
27753         if(this.validationEvent == 'keyup'){
27754             this.validationTask = new  Roo.util.DelayedTask(this.validate, this);
27755             this.el.on('keyup', this.filterValidation, this);
27756         }
27757         else  if(this.validationEvent !== false){
27758             this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
27759         }
27760         if(this.selectOnFocus || this.emptyText){
27761             this.on("focus", this.preFocus, this);
27762             if(this.emptyText){
27763                 this.on('blur', this.postBlur, this);
27764                 this.applyEmptyText();
27765             }
27766         }
27767         if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
27768             this.el.on("keypress", this.filterKeys, this);
27769         }
27770         if(this.grow){
27771             this.el.on("keyup", this.onKeyUp,  this, {buffer:50});
27772             this.el.on("click", this.autoSize,  this);
27773         }
27774     },
27775
27776     processValue : function(B){
27777         if(this.stripCharsRe){
27778             var  newValue = B.replace(this.stripCharsRe, '');
27779             if(newValue !== B){
27780                 this.setRawValue(newValue);
27781                 return  newValue;
27782             }
27783         }
27784         return  B;
27785     },
27786
27787     filterValidation : function(e){
27788         if(!e.isNavKeyPress()){
27789             this.validationTask.delay(this.validationDelay);
27790         }
27791     },
27792
27793     
27794     onKeyUp : function(e){
27795         if(!e.isNavKeyPress()){
27796             this.autoSize();
27797         }
27798     },
27799
27800     
27801
27802     reset : function(){
27803         Roo.form.TextField.superclass.reset.call(this);
27804         this.applyEmptyText();
27805     },
27806
27807     applyEmptyText : function(){
27808         if(this.rendered && this.emptyText && this.getRawValue().length < 1){
27809             this.setRawValue(this.emptyText);
27810             this.el.addClass(this.emptyClass);
27811         }
27812     },
27813
27814     
27815     preFocus : function(){
27816         if(this.emptyText){
27817             if(this.el.dom.value == this.emptyText){
27818                 this.setRawValue('');
27819             }
27820
27821             this.el.removeClass(this.emptyClass);
27822         }
27823         if(this.selectOnFocus){
27824             this.el.dom.select();
27825         }
27826     },
27827
27828     
27829     postBlur : function(){
27830         this.applyEmptyText();
27831     },
27832
27833     
27834     filterKeys : function(e){
27835         var  k = e.getKey();
27836         if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE  && e.button == -1))){
27837             return;
27838         }
27839         var  c = e.getCharCode(), cc = String.fromCharCode(c);
27840         if(Roo.isIE && (e.isSpecialKey() || !cc)){
27841             return;
27842         }
27843         if(!this.maskRe.test(cc)){
27844             e.stopEvent();
27845         }
27846     },
27847
27848     setValue : function(v){
27849         if(this.emptyText && this.el && v !== undefined && v !== null && v !== ''){
27850             this.el.removeClass(this.emptyClass);
27851         }
27852
27853         Roo.form.TextField.superclass.setValue.apply(this, arguments);
27854         this.applyEmptyText();
27855         this.autoSize();
27856     },
27857
27858     
27859
27860     validateValue : function(C){
27861         if(C.length < 1 || C === this.emptyText){ 
27862              if(this.allowBlank){
27863                 this.clearInvalid();
27864                 return  true;
27865              }else {
27866                 this.markInvalid(this.blankText);
27867                 return  false;
27868              }
27869         }
27870         if(C.length < this.minLength){
27871             this.markInvalid(String.format(this.minLengthText, this.minLength));
27872             return  false;
27873         }
27874         if(C.length > this.maxLength){
27875             this.markInvalid(String.format(this.maxLengthText, this.maxLength));
27876             return  false;
27877         }
27878         if(this.vtype){
27879             var  vt = Roo.form.VTypes;
27880             if(!vt[this.vtype](C, this)){
27881                 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
27882                 return  false;
27883             }
27884         }
27885         if(typeof  this.validator == "function"){
27886             var  msg = this.validator(C);
27887             if(msg !== true){
27888                 this.markInvalid(msg);
27889                 return  false;
27890             }
27891         }
27892         if(this.regex && !this.regex.test(C)){
27893             this.markInvalid(this.regexText);
27894             return  false;
27895         }
27896         return  true;
27897     },
27898
27899     
27900
27901     selectText : function(D, E){
27902         var  v = this.getRawValue();
27903         if(v.length > 0){
27904             D = D === undefined ? 0 : D;
27905             E = E === undefined ? v.length : E;
27906             var  d = this.el.dom;
27907             if(d.setSelectionRange){
27908                 d.setSelectionRange(D, E);
27909             }else  if(d.createTextRange){
27910                 var  range = d.createTextRange();
27911                 range.moveStart("character", D);
27912                 range.moveEnd("character", v.length-E);
27913                 range.select();
27914             }
27915         }
27916     },
27917
27918     
27919
27920     autoSize : function(){
27921         if(!this.grow || !this.rendered){
27922             return;
27923         }
27924         if(!this.metrics){
27925             this.metrics = Roo.util.TextMetrics.createInstance(this.el);
27926         }
27927         var  el = this.el;
27928         var  v = el.dom.value;
27929         var  d = document.createElement('div');
27930         d.appendChild(document.createTextNode(v));
27931         v = d.innerHTML;
27932         d = null;
27933         v += "&#160;";
27934         var  w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + 
27935  10, this.growMin));
27936         this.el.setWidth(w);
27937         this.fireEvent("autosize", this, w);
27938     }
27939 });
27940
27941
27942  
27943
27944
27945
27946
27947
27948
27949 Roo.form.Hidden = function(A){
27950     Roo.form.Hidden.superclass.constructor.call(this, A);
27951 };
27952   
27953 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
27954     fieldLabel:      '',
27955     inputType:      'hidden',
27956     width:          50,
27957     allowBlank:     true,
27958     labelSeparator: '',
27959     hidden:         true,
27960     itemCls :       'x-form-item-display-none'
27961
27962
27963 });
27964
27965
27966
27967
27968
27969  
27970
27971
27972 Roo.form.TriggerField = function(A){
27973     this.mimicing = false;
27974     Roo.form.TriggerField.superclass.constructor.call(this, A);
27975 };
27976
27977 Roo.extend(Roo.form.TriggerField, Roo.form.TextField,  {
27978     
27979
27980     
27981
27982     defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
27983     
27984
27985     hideTrigger:false,
27986
27987     
27988
27989     
27990
27991     
27992
27993
27994     
27995
27996     autoSize: Roo.emptyFn,
27997     
27998     monitorTab : true,
27999     
28000     deferHeight : true,
28001
28002     
28003     actionMode : 'wrap',
28004     
28005     onResize : function(w, h){
28006         Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
28007         if(typeof  w == 'number'){
28008             this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth()));
28009         }
28010     },
28011
28012     
28013     adjustSize : Roo.BoxComponent.prototype.adjustSize,
28014
28015     
28016     getResizeEl : function(){
28017         return  this.wrap;
28018     },
28019
28020     
28021     getPositionEl : function(){
28022         return  this.wrap;
28023     },
28024
28025     
28026     alignErrorIcon : function(){
28027         this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
28028     },
28029
28030     
28031     onRender : function(ct, B){
28032         Roo.form.TriggerField.superclass.onRender.call(this, ct, B);
28033         this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
28034         this.trigger = this.wrap.createChild(this.triggerConfig ||
28035                 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
28036         if(this.hideTrigger){
28037             this.trigger.setDisplayed(false);
28038         }
28039
28040         this.initTrigger();
28041         if(!this.width){
28042             this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
28043         }
28044     },
28045
28046     
28047     initTrigger : function(){
28048         this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
28049         this.trigger.addClassOnOver('x-form-trigger-over');
28050         this.trigger.addClassOnClick('x-form-trigger-click');
28051     },
28052
28053     
28054     onDestroy : function(){
28055         if(this.trigger){
28056             this.trigger.removeAllListeners();
28057             this.trigger.remove();
28058         }
28059         if(this.wrap){
28060             this.wrap.remove();
28061         }
28062
28063         Roo.form.TriggerField.superclass.onDestroy.call(this);
28064     },
28065
28066     
28067     onFocus : function(){
28068         Roo.form.TriggerField.superclass.onFocus.call(this);
28069         if(!this.mimicing){
28070             this.wrap.addClass('x-trigger-wrap-focus');
28071             this.mimicing = true;
28072             Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
28073             if(this.monitorTab){
28074                 this.el.on("keydown", this.checkTab, this);
28075             }
28076         }
28077     },
28078
28079     
28080     checkTab : function(e){
28081         if(e.getKey() == e.TAB){
28082             this.triggerBlur();
28083         }
28084     },
28085
28086     
28087     onBlur : function(){
28088         
28089     },
28090
28091     
28092     mimicBlur : function(e, t){
28093         if(!this.wrap.contains(t) && this.validateBlur()){
28094             this.triggerBlur();
28095         }
28096     },
28097
28098     
28099     triggerBlur : function(){
28100         this.mimicing = false;
28101         Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
28102         if(this.monitorTab){
28103             this.el.un("keydown", this.checkTab, this);
28104         }
28105
28106         this.wrap.removeClass('x-trigger-wrap-focus');
28107         Roo.form.TriggerField.superclass.onBlur.call(this);
28108     },
28109
28110     
28111     
28112     validateBlur : function(e, t){
28113         return  true;
28114     },
28115
28116     
28117     onDisable : function(){
28118         Roo.form.TriggerField.superclass.onDisable.call(this);
28119         if(this.wrap){
28120             this.wrap.addClass('x-item-disabled');
28121         }
28122     },
28123
28124     
28125     onEnable : function(){
28126         Roo.form.TriggerField.superclass.onEnable.call(this);
28127         if(this.wrap){
28128             this.wrap.removeClass('x-item-disabled');
28129         }
28130     },
28131
28132     
28133     onShow : function(){
28134         var  ae = this.getActionEl();
28135         
28136         if(ae){
28137             ae.dom.style.display = '';
28138             ae.dom.style.visibility = 'visible';
28139         }
28140     },
28141
28142     
28143     
28144     onHide : function(){
28145         var  ae = this.getActionEl();
28146         ae.dom.style.display = 'none';
28147     },
28148
28149     
28150
28151     onTriggerClick : Roo.emptyFn
28152 });
28153
28154
28155
28156
28157 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
28158     initComponent : function(){
28159         Roo.form.TwinTriggerField.superclass.initComponent.call(this);
28160
28161         this.triggerConfig = {
28162             tag:'span', cls:'x-form-twin-triggers', cn:[
28163             {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
28164             {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
28165         ]};
28166     },
28167
28168     getTrigger : function(C){
28169         return  this.triggers[C];
28170     },
28171
28172     initTrigger : function(){
28173         var  ts = this.trigger.select('.x-form-trigger', true);
28174         this.wrap.setStyle('overflow', 'hidden');
28175         var  D = this;
28176         ts.each(function(t, E, F){
28177             t.hide = function(){
28178                 var  w = D.wrap.getWidth();
28179                 this.dom.style.display = 'none';
28180                 D.el.setWidth(w-D.trigger.getWidth());
28181             };
28182             t.show = function(){
28183                 var  w = D.wrap.getWidth();
28184                 this.dom.style.display = '';
28185                 D.el.setWidth(w-D.trigger.getWidth());
28186             };
28187             var  G = 'Trigger'+(F+1);
28188
28189             if(this['hide'+G]){
28190                 t.dom.style.display = 'none';
28191             }
28192
28193             t.on("click", this['on'+G+'Click'], this, {preventDefault:true});
28194             t.addClassOnOver('x-form-trigger-over');
28195             t.addClassOnClick('x-form-trigger-click');
28196         }, this);
28197         this.triggers = ts.elements;
28198     },
28199
28200     onTrigger1Click : Roo.emptyFn,
28201     onTrigger2Click : Roo.emptyFn
28202 });
28203
28204
28205  
28206
28207
28208 Roo.form.TextArea = function(A){
28209     Roo.form.TextArea.superclass.constructor.call(this, A);
28210     
28211     
28212     
28213     if(this.minHeight !== undefined){
28214         this.growMin = this.minHeight;
28215     }
28216     if(this.maxHeight !== undefined){
28217         this.growMax = this.maxHeight;
28218     }
28219 };
28220
28221 Roo.extend(Roo.form.TextArea, Roo.form.TextField,  {
28222     
28223
28224     growMin : 60,
28225     
28226
28227     growMax: 1000,
28228     
28229
28230     preventScrollbars: false,
28231     
28232
28233
28234     
28235     onRender : function(ct, B){
28236         if(!this.el){
28237             this.defaultAutoCreate = {
28238                 tag: "textarea",
28239                 style:"width:300px;height:60px;",
28240                 autocomplete: "off"
28241             };
28242         }
28243
28244         Roo.form.TextArea.superclass.onRender.call(this, ct, B);
28245         if(this.grow){
28246             this.textSizeEl = Roo.DomHelper.append(document.body, {
28247                 tag: "pre", cls: "x-form-grow-sizer"
28248             });
28249             if(this.preventScrollbars){
28250                 this.el.setStyle("overflow", "hidden");
28251             }
28252
28253             this.el.setHeight(this.growMin);
28254         }
28255     },
28256
28257     onDestroy : function(){
28258         if(this.textSizeEl){
28259             this.textSizeEl.parentNode.removeChild(this.textSizeEl);
28260         }
28261
28262         Roo.form.TextArea.superclass.onDestroy.call(this);
28263     },
28264
28265     
28266     onKeyUp : function(e){
28267         if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
28268             this.autoSize();
28269         }
28270     },
28271
28272     
28273
28274     autoSize : function(){
28275         if(!this.grow || !this.textSizeEl){
28276             return;
28277         }
28278         var  el = this.el;
28279         var  v = el.dom.value;
28280         var  ts = this.textSizeEl;
28281
28282         ts.innerHTML = '';
28283         ts.appendChild(document.createTextNode(v));
28284         v = ts.innerHTML;
28285
28286         Roo.fly(ts).setWidth(this.el.getWidth());
28287         if(v.length < 1){
28288             v = "&#160;&#160;";
28289         }else {
28290             if(Roo.isIE){
28291                 v = v.replace(/\n/g, '<p>&#160;</p>');
28292             }
28293
28294             v += "&#160;\n&#160;";
28295         }
28296
28297         ts.innerHTML = v;
28298         var  h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
28299         if(h != this.lastHeight){
28300             this.lastHeight = h;
28301             this.el.setHeight(h);
28302             this.fireEvent("autosize", this, h);
28303         }
28304     }
28305 });
28306
28307
28308  
28309
28310
28311
28312 Roo.form.NumberField = function(A){
28313     Roo.form.NumberField.superclass.constructor.call(this, A);
28314 };
28315
28316 Roo.extend(Roo.form.NumberField, Roo.form.TextField,  {
28317     
28318
28319     fieldClass: "x-form-field x-form-num-field",
28320     
28321
28322     allowDecimals : true,
28323     
28324
28325     decimalSeparator : ".",
28326     
28327
28328     decimalPrecision : 2,
28329     
28330
28331     allowNegative : true,
28332     
28333
28334     minValue : Number.NEGATIVE_INFINITY,
28335     
28336
28337     maxValue : Number.MAX_VALUE,
28338     
28339
28340     minText : "The minimum value for this field is {0}",
28341     
28342
28343     maxText : "The maximum value for this field is {0}",
28344     
28345
28346     nanText : "{0} is not a valid number",
28347
28348     
28349     initEvents : function(){
28350         Roo.form.NumberField.superclass.initEvents.call(this);
28351         var  B = "0123456789";
28352         if(this.allowDecimals){
28353             B += this.decimalSeparator;
28354         }
28355         if(this.allowNegative){
28356             B += "-";
28357         }
28358
28359         this.stripCharsRe = new  RegExp('[^'+B+']', 'gi');
28360         var  C = function(e){
28361             var  k = e.getKey();
28362             if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE )){
28363                 return;
28364             }
28365             var  c = e.getCharCode();
28366             if(B.indexOf(String.fromCharCode(c)) === -1){
28367                 e.stopEvent();
28368             }
28369         };
28370         this.el.on("keypress", C, this);
28371     },
28372
28373     
28374     validateValue : function(D){
28375         if(!Roo.form.NumberField.superclass.validateValue.call(this, D)){
28376             return  false;
28377         }
28378         if(D.length < 1){ 
28379              return  true;
28380         }
28381         var  E = this.parseValue(D);
28382         if(isNaN(E)){
28383             this.markInvalid(String.format(this.nanText, D));
28384             return  false;
28385         }
28386         if(E < this.minValue){
28387             this.markInvalid(String.format(this.minText, this.minValue));
28388             return  false;
28389         }
28390         if(E > this.maxValue){
28391             this.markInvalid(String.format(this.maxText, this.maxValue));
28392             return  false;
28393         }
28394         return  true;
28395     },
28396
28397     getValue : function(){
28398         return  this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
28399     },
28400
28401     
28402     parseValue : function(F){
28403         F = parseFloat(String(F).replace(this.decimalSeparator, "."));
28404         return  isNaN(F) ? '' : F;
28405     },
28406
28407     
28408     fixPrecision : function(G){
28409         var  H = isNaN(G);
28410         if(!this.allowDecimals || this.decimalPrecision == -1 || H || !G){
28411             return  H ? '' : G;
28412         }
28413         return  parseFloat(G).toFixed(this.decimalPrecision);
28414     },
28415
28416     setValue : function(v){
28417         Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
28418     },
28419
28420     
28421     decimalPrecisionFcn : function(v){
28422         return  Math.floor(v);
28423     },
28424
28425     beforeBlur : function(){
28426         var  v = this.parseValue(this.getRawValue());
28427         if(v){
28428             this.setValue(this.fixPrecision(v));
28429         }
28430     }
28431 });
28432
28433
28434  
28435
28436
28437 Roo.form.DateField = function(A){
28438     Roo.form.DateField.superclass.constructor.call(this, A);
28439     
28440       this.addEvents({
28441          
28442         
28443
28444         'select' : true
28445          
28446     });
28447     
28448     
28449     if(typeof  this.minValue == "string") this.minValue = this.parseDate(this.minValue);
28450     if(typeof  this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
28451     this.ddMatch = null;
28452     if(this.disabledDates){
28453         var  dd = this.disabledDates;
28454         var  re = "(?:";
28455         for(var  i = 0; i < dd.length; i++){
28456             re += dd[i];
28457             if(i != dd.length-1) re += "|";
28458         }
28459
28460         this.ddMatch = new  RegExp(re + ")");
28461     }
28462 };
28463
28464 Roo.extend(Roo.form.DateField, Roo.form.TriggerField,  {
28465     
28466
28467     format : "m/d/y",
28468     
28469
28470     altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
28471     
28472
28473     disabledDays : null,
28474     
28475
28476     disabledDaysText : "Disabled",
28477     
28478
28479     disabledDates : null,
28480     
28481
28482     disabledDatesText : "Disabled",
28483     
28484
28485     minValue : null,
28486     
28487
28488     maxValue : null,
28489     
28490
28491     minText : "The date in this field must be equal to or after {0}",
28492     
28493
28494     maxText : "The date in this field must be equal to or before {0}",
28495     
28496
28497     invalidText : "{0} is not a valid date - it must be in the format {1}",
28498     
28499
28500     triggerClass : 'x-form-date-trigger',
28501     
28502
28503     
28504  
28505     useIso : false,
28506     
28507  
28508     
28509     defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
28510     
28511     
28512     hiddenField: false,
28513     
28514     onRender : function(ct, B)
28515     {
28516         Roo.form.DateField.superclass.onRender.call(this, ct, B);
28517         if (this.useIso) {
28518             this.el.dom.removeAttribute('name'); 
28519             this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
28520                     'before', true);
28521             this.hiddenField.value = this.formatDate(this.value, 'Y-m-d');
28522             
28523             this.hiddenName = this.name;
28524         }
28525             
28526             
28527     },
28528     
28529     
28530     validateValue : function(C)
28531     {
28532         C = this.formatDate(C);
28533         if(!Roo.form.DateField.superclass.validateValue.call(this, C)){
28534             return  false;
28535         }
28536         if(C.length < 1){ 
28537              return  true;
28538         }
28539         var  D = C;
28540         C = this.parseDate(C);
28541         if(!C){
28542             this.markInvalid(String.format(this.invalidText, D, this.format));
28543             return  false;
28544         }
28545         var  E = C.getTime();
28546         if(this.minValue && E < this.minValue.getTime()){
28547             this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
28548             return  false;
28549         }
28550         if(this.maxValue && E > this.maxValue.getTime()){
28551             this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
28552             return  false;
28553         }
28554         if(this.disabledDays){
28555             var  day = C.getDay();
28556             for(var  i = 0; i < this.disabledDays.length; i++) {
28557                 if(day === this.disabledDays[i]){
28558                     this.markInvalid(this.disabledDaysText);
28559                     return  false;
28560                 }
28561             }
28562         }
28563         var  F = this.formatDate(C);
28564         if(this.ddMatch && this.ddMatch.test(F)){
28565             this.markInvalid(String.format(this.disabledDatesText, F));
28566             return  false;
28567         }
28568         return  true;
28569     },
28570
28571     
28572     
28573     validateBlur : function(){
28574         return  !this.menu || !this.menu.isVisible();
28575     },
28576
28577     
28578
28579     getValue : function(){
28580         
28581         return   this.hiddenField ? this.hiddenField.value : this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
28582     },
28583
28584     
28585
28586     setValue : function(G){
28587         if (this.hiddenField) {
28588             this.hiddenField.value = this.formatDate(this.parseDate(G), 'Y-m-d');
28589         }
28590
28591         Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(G)));
28592     },
28593
28594     
28595     parseDate : function(H){
28596         if(!H || H  instanceof  Date){
28597             return  H;
28598         }
28599         var  v = Date.parseDate(H, this.format);
28600         if(!v && this.altFormats){
28601             if(!this.altFormatsArray){
28602                 this.altFormatsArray = this.altFormats.split("|");
28603             }
28604             for(var  i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
28605                 v = Date.parseDate(H, this.altFormatsArray[i]);
28606             }
28607         }
28608         return  v;
28609     },
28610
28611     
28612     formatDate : function(I, J){
28613         return  (!I || !(I  instanceof  Date)) ?
28614                I : I.dateFormat(J || this.format);
28615     },
28616
28617     
28618     menuListeners : {
28619         select: function(m, d){
28620             this.setValue(d);
28621             this.fireEvent('select', this, d);
28622         },
28623         show : function(){ 
28624             this.onFocus();
28625         },
28626         hide : function(){
28627             this.focus.defer(10, this);
28628             var  ml = this.menuListeners;
28629             this.menu.un("select", ml.select,  this);
28630             this.menu.un("show", ml.show,  this);
28631             this.menu.un("hide", ml.hide,  this);
28632         }
28633     },
28634
28635     
28636     
28637     onTriggerClick : function(){
28638         if(this.disabled){
28639             return;
28640         }
28641         if(this.menu == null){
28642             this.menu = new  Roo.menu.DateMenu();
28643         }
28644
28645         Roo.apply(this.menu.picker,  {
28646             showClear: this.allowBlank,
28647             minDate : this.minValue,
28648             maxDate : this.maxValue,
28649             disabledDatesRE : this.ddMatch,
28650             disabledDatesText : this.disabledDatesText,
28651             disabledDays : this.disabledDays,
28652             disabledDaysText : this.disabledDaysText,
28653             format : this.format,
28654             minText : String.format(this.minText, this.formatDate(this.minValue)),
28655             maxText : String.format(this.maxText, this.formatDate(this.maxValue))
28656         });
28657         this.menu.on(Roo.apply({}, this.menuListeners, {
28658             scope:this
28659         }));
28660         this.menu.picker.setValue(this.getValue() || new  Date());
28661         this.menu.show(this.el, "tl-bl?");
28662     },
28663
28664     beforeBlur : function(){
28665         var  v = this.parseDate(this.getRawValue());
28666         if(v){
28667             this.setValue(v);
28668         }
28669     }
28670
28671     
28672
28673     
28674
28675     
28676
28677     
28678
28679 });
28680
28681
28682  
28683
28684
28685
28686 Roo.form.ComboBox = function(A){
28687     Roo.form.ComboBox.superclass.constructor.call(this, A);
28688     this.addEvents({
28689         
28690
28691         'expand' : true,
28692         
28693
28694         'collapse' : true,
28695         
28696
28697         'beforeselect' : true,
28698         
28699
28700         'select' : true,
28701         
28702
28703         'beforequery': true
28704     });
28705     if(this.transform){
28706         this.allowDomMove = false;
28707         var  s = Roo.getDom(this.transform);
28708         if(!this.hiddenName){
28709             this.hiddenName = s.name;
28710         }
28711         if(!this.store){
28712             this.mode = 'local';
28713             var  d = [], opts = s.options;
28714             for(var  i = 0, len = opts.length;i < len; i++){
28715                 var  o = opts[i];
28716                 var  value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
28717                 if(o.selected) {
28718                     this.value = value;
28719                 }
28720
28721                 d.push([value, o.text]);
28722             }
28723
28724             this.store = new  Roo.data.SimpleStore({
28725                 'id': 0,
28726                 fields: ['value', 'text'],
28727                 data : d
28728             });
28729             this.valueField = 'value';
28730             this.displayField = 'text';
28731         }
28732
28733         s.name = Roo.id(); 
28734         if(!this.lazyRender){
28735             this.target = true;
28736             this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
28737             s.parentNode.removeChild(s); 
28738             this.render(this.el.parentNode);
28739         }else {
28740             s.parentNode.removeChild(s); 
28741         }
28742
28743     }
28744     if (this.store) {
28745         this.store = Roo.factory(this.store, Roo.data);
28746     }
28747
28748     
28749     this.selectedIndex = -1;
28750     if(this.mode == 'local'){
28751         if(A.queryDelay === undefined){
28752             this.queryDelay = 10;
28753         }
28754         if(A.minChars === undefined){
28755             this.minChars = 0;
28756         }
28757     }
28758 };
28759
28760 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
28761     
28762
28763     
28764
28765     
28766
28767     
28768
28769     
28770
28771
28772      
28773
28774      
28775     
28776     defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
28777     
28778
28779     listWidth: undefined,
28780     
28781
28782     displayField: undefined,
28783     
28784
28785     valueField: undefined,
28786     
28787
28788     hiddenName: undefined,
28789     
28790
28791     listClass: '',
28792     
28793
28794     selectedClass: 'x-combo-selected',
28795     
28796
28797     triggerClass : 'x-form-arrow-trigger',
28798     
28799
28800     shadow:'sides',
28801     
28802
28803     listAlign: 'tl-bl?',
28804     
28805
28806     maxHeight: 300,
28807     
28808
28809     triggerAction: 'query',
28810     
28811
28812     minChars : 4,
28813     
28814
28815     typeAhead: false,
28816     
28817
28818     queryDelay: 500,
28819     
28820
28821     pageSize: 0,
28822     
28823
28824     selectOnFocus:false,
28825     
28826
28827     queryParam: 'query',
28828     
28829
28830     loadingText: 'Loading...',
28831     
28832
28833     resizable: false,
28834     
28835
28836     handleHeight : 8,
28837     
28838
28839     editable: true,
28840     
28841
28842     allQuery: '',
28843     
28844
28845     mode: 'remote',
28846     
28847
28848     minListWidth : 70,
28849     
28850
28851     forceSelection:false,
28852     
28853
28854     typeAheadDelay : 250,
28855     
28856
28857     valueNotFoundText : undefined,
28858     
28859
28860     blockFocus : false,
28861     
28862     
28863
28864     disableClear : false,
28865     
28866     
28867     onRender : function(ct, B){
28868         Roo.form.ComboBox.superclass.onRender.call(this, ct, B);
28869         if(this.hiddenName){
28870             this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id:  (this.hiddenId||this.hiddenName)},
28871                     'before', true);
28872             this.hiddenField.value =
28873                 this.hiddenValue !== undefined ? this.hiddenValue :
28874                 this.value !== undefined ? this.value : '';
28875
28876             
28877             this.el.dom.removeAttribute('name');
28878         }
28879         if(Roo.isGecko){
28880             this.el.dom.setAttribute('autocomplete', 'off');
28881         }
28882
28883         var  C = 'x-combo-list';
28884
28885         this.list = new  Roo.Layer({
28886             shadow: this.shadow, cls: [C, this.listClass].join(' '), constrain:false
28887         });
28888
28889         var  lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
28890         this.list.setWidth(lw);
28891         this.list.swallowEvent('mousewheel');
28892         this.assetHeight = 0;
28893
28894         if(this.title){
28895             this.header = this.list.createChild({cls:C+'-hd', html: this.title});
28896             this.assetHeight += this.header.getHeight();
28897         }
28898
28899
28900         this.innerList = this.list.createChild({cls:C+'-inner'});
28901         this.innerList.on('mouseover', this.onViewOver, this);
28902         this.innerList.on('mousemove', this.onViewMove, this);
28903         this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
28904         
28905         if(this.allowBlank && !this.pageSize && !this.disableClear){
28906             this.footer = this.list.createChild({cls:C+'-ft'});
28907             this.pageTb = new  Roo.Toolbar(this.footer);
28908            
28909         }
28910         if(this.pageSize){
28911             this.footer = this.list.createChild({cls:C+'-ft'});
28912             this.pageTb = new  Roo.PagingToolbar(this.footer, this.store,
28913                     {pageSize: this.pageSize});
28914             
28915         }
28916         
28917         if (this.pageTb && this.allowBlank && !this.disableClear) {
28918             var  _this = this;
28919             this.pageTb.add(new  Roo.Toolbar.Fill(), {
28920                 cls: 'x-btn-icon x-btn-clear',
28921                 text: '&#160;',
28922                 handler: function()
28923                 {
28924                     _this.collapse();
28925                     _this.clearValue();
28926                     _this.onSelect(false, -1);
28927                 }
28928             });
28929         }
28930         if (this.footer) {
28931             this.assetHeight += this.footer.getHeight();
28932         }
28933         
28934
28935         if(!this.tpl){
28936             this.tpl = '<div class="'+C+'-item">{' + this.displayField + '}</div>';
28937         }
28938
28939
28940         this.view = new  Roo.View(this.innerList, this.tpl, {
28941             singleSelect:true, store: this.store, selectedClass: this.selectedClass
28942         });
28943
28944         this.view.on('click', this.onViewClick, this);
28945
28946         this.store.on('beforeload', this.onBeforeLoad, this);
28947         this.store.on('load', this.onLoad, this);
28948         this.store.on('loadexception', this.collapse, this);
28949
28950         if(this.resizable){
28951             this.resizer = new  Roo.Resizable(this.list,  {
28952                pinned:true, handles:'se'
28953             });
28954             this.resizer.on('resize', function(r, w, h){
28955                 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
28956                 this.listWidth = w;
28957                 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
28958                 this.restrictHeight();
28959             }, this);
28960             this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
28961         }
28962         if(!this.editable){
28963             this.editable = true;
28964             this.setEditable(false);
28965         }
28966     },
28967
28968     
28969     initEvents : function(){
28970         Roo.form.ComboBox.superclass.initEvents.call(this);
28971
28972         this.keyNav = new  Roo.KeyNav(this.el, {
28973             "up" : function(e){
28974                 this.inKeyMode = true;
28975                 this.selectPrev();
28976             },
28977
28978             "down" : function(e){
28979                 if(!this.isExpanded()){
28980                     this.onTriggerClick();
28981                 }else {
28982                     this.inKeyMode = true;
28983                     this.selectNext();
28984                 }
28985             },
28986
28987             "enter" : function(e){
28988                 this.onViewClick();
28989                 
28990             },
28991
28992             "esc" : function(e){
28993                 this.collapse();
28994             },
28995
28996             "tab" : function(e){
28997                 this.onViewClick(false);
28998                 return  true;
28999             },
29000
29001             scope : this,
29002
29003             doRelay : function(D, E, F){
29004                 if(F == 'down' || this.scope.isExpanded()){
29005                    return  Roo.KeyNav.prototype.doRelay.apply(this, arguments);
29006                 }
29007                 return  true;
29008             },
29009
29010             forceKeyDown: true
29011         });
29012         this.queryDelay = Math.max(this.queryDelay || 10,
29013                 this.mode == 'local' ? 10 : 250);
29014         this.dqTask = new  Roo.util.DelayedTask(this.initQuery, this);
29015         if(this.typeAhead){
29016             this.taTask = new  Roo.util.DelayedTask(this.onTypeAhead, this);
29017         }
29018         if(this.editable !== false){
29019             this.el.on("keyup", this.onKeyUp, this);
29020         }
29021         if(this.forceSelection){
29022             this.on('blur', this.doForce, this);
29023         }
29024     },
29025
29026     onDestroy : function(){
29027         if(this.view){
29028             this.view.setStore(null);
29029             this.view.el.removeAllListeners();
29030             this.view.el.remove();
29031             this.view.purgeListeners();
29032         }
29033         if(this.list){
29034             this.list.destroy();
29035         }
29036         if(this.store){
29037             this.store.un('beforeload', this.onBeforeLoad, this);
29038             this.store.un('load', this.onLoad, this);
29039             this.store.un('loadexception', this.collapse, this);
29040         }
29041
29042         Roo.form.ComboBox.superclass.onDestroy.call(this);
29043     },
29044
29045     
29046     fireKey : function(e){
29047         if(e.isNavKeyPress() && !this.list.isVisible()){
29048             this.fireEvent("specialkey", this, e);
29049         }
29050     },
29051
29052     
29053     onResize: function(w, h){
29054         Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
29055         if(this.list && this.listWidth === undefined){
29056             var  lw = Math.max(w, this.minListWidth);
29057             this.list.setWidth(lw);
29058             this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
29059         }
29060     },
29061
29062     
29063
29064     setEditable : function(D){
29065         if(D == this.editable){
29066             return;
29067         }
29068
29069         this.editable = D;
29070         if(!D){
29071             this.el.dom.setAttribute('readOnly', true);
29072             this.el.on('mousedown', this.onTriggerClick,  this);
29073             this.el.addClass('x-combo-noedit');
29074         }else {
29075             this.el.dom.setAttribute('readOnly', false);
29076             this.el.un('mousedown', this.onTriggerClick,  this);
29077             this.el.removeClass('x-combo-noedit');
29078         }
29079     },
29080
29081     
29082     onBeforeLoad : function(){
29083         if(!this.hasFocus){
29084             return;
29085         }
29086
29087         this.innerList.update(this.loadingText ?
29088                '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
29089         this.restrictHeight();
29090         this.selectedIndex = -1;
29091     },
29092
29093     
29094     onLoad : function(){
29095         if(!this.hasFocus){
29096             return;
29097         }
29098         if(this.store.getCount() > 0){
29099             this.expand();
29100             this.restrictHeight();
29101             if(this.lastQuery == this.allQuery){
29102                 if(this.editable){
29103                     this.el.dom.select();
29104                 }
29105                 if(!this.selectByValue(this.value, true)){
29106                     this.select(0, true);
29107                 }
29108             }else {
29109                 this.selectNext();
29110                 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE ){
29111                     this.taTask.delay(this.typeAheadDelay);
29112                 }
29113             }
29114         }else {
29115             this.onEmptyResults();
29116         }
29117         
29118     },
29119
29120     
29121     onTypeAhead : function(){
29122         if(this.store.getCount() > 0){
29123             var  r = this.store.getAt(0);
29124             var  newValue = r.data[this.displayField];
29125             var  len = newValue.length;
29126             var  selStart = this.getRawValue().length;
29127             if(selStart != len){
29128                 this.setRawValue(newValue);
29129                 this.selectText(selStart, newValue.length);
29130             }
29131         }
29132     },
29133
29134     
29135     onSelect : function(E, F){
29136         if(this.fireEvent('beforeselect', this, E, F) !== false){
29137             this.setFromData(F > -1 ? E.data : false);
29138             this.collapse();
29139             this.fireEvent('select', this, E, F);
29140         }
29141     },
29142
29143     
29144
29145     getValue : function(){
29146         if(this.valueField){
29147             return  typeof  this.value != 'undefined' ? this.value : '';
29148         }else {
29149             return  Roo.form.ComboBox.superclass.getValue.call(this);
29150         }
29151     },
29152
29153     
29154
29155     clearValue : function(){
29156         if(this.hiddenField){
29157             this.hiddenField.value = '';
29158         }
29159
29160         this.value = '';
29161         this.setRawValue('');
29162         this.lastSelectionText = '';
29163         this.applyEmptyText();
29164     },
29165
29166     
29167
29168     setValue : function(v){
29169         var  G = v;
29170         if(this.valueField){
29171             var  r = this.findRecord(this.valueField, v);
29172             if(r){
29173                 G = r.data[this.displayField];
29174             }else  if(this.valueNotFoundText !== undefined){
29175                 G = this.valueNotFoundText;
29176             }
29177         }
29178
29179         this.lastSelectionText = G;
29180         if(this.hiddenField){
29181             this.hiddenField.value = v;
29182         }
29183
29184         Roo.form.ComboBox.superclass.setValue.call(this, G);
29185         this.value = v;
29186     },
29187     
29188
29189     
29190     lastData : false,
29191     
29192
29193     setFromData : function(o){
29194         var  dv = ''; 
29195         var  vv = ''; 
29196         this.lastData = o;
29197         if (this.displayField) {
29198             dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
29199         } else  {
29200             
29201             console.log('no value field set for '+ this.name);
29202         }
29203         
29204         if(this.valueField){
29205             vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
29206         }
29207         if(this.hiddenField){
29208             this.hiddenField.value = vv;
29209             
29210             this.lastSelectionText = dv;
29211             Roo.form.ComboBox.superclass.setValue.call(this, dv);
29212             this.value = vv;
29213             return;
29214         }
29215
29216         
29217         
29218         this.lastSelectionText = dv;
29219         Roo.form.ComboBox.superclass.setValue.call(this, dv);
29220         this.value = vv;
29221         
29222         
29223     },
29224     
29225     reset : function(){
29226         
29227         this.setValue(this.originalValue);
29228         this.clearInvalid();
29229         this.lastData = false;
29230     },
29231     
29232     findRecord : function(H, I){
29233         var  J;
29234         if(this.store.getCount() > 0){
29235             this.store.each(function(r){
29236                 if(r.data[H] == I){
29237                     J = r;
29238                     return  false;
29239                 }
29240             });
29241         }
29242         return  J;
29243     },
29244
29245     
29246     onViewMove : function(e, t){
29247         this.inKeyMode = false;
29248     },
29249
29250     
29251     onViewOver : function(e, t){
29252         if(this.inKeyMode){ 
29253             return;
29254         }
29255         var  K = this.view.findItemFromChild(t);
29256         if(K){
29257             var  F = this.view.indexOf(K);
29258             this.select(F, false);
29259         }
29260     },
29261
29262     
29263     onViewClick : function(L){
29264         var  M = this.view.getSelectedIndexes()[0];
29265         var  r = this.store.getAt(M);
29266         if(r){
29267             this.onSelect(r, M);
29268         }
29269         if(L !== false && !this.blockFocus){
29270             this.el.focus();
29271         }
29272     },
29273
29274     
29275     restrictHeight : function(){
29276         this.innerList.dom.style.height = '';
29277         var  N = this.innerList.dom;
29278         var  h = Math.max(N.clientHeight, N.offsetHeight, N.scrollHeight);
29279         this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
29280         this.list.beginUpdate();
29281         this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
29282         this.list.alignTo(this.el, this.listAlign);
29283         this.list.endUpdate();
29284     },
29285
29286     
29287     onEmptyResults : function(){
29288         this.collapse();
29289     },
29290
29291     
29292
29293     isExpanded : function(){
29294         return  this.list.isVisible();
29295     },
29296
29297     
29298
29299     selectByValue : function(v, O){
29300         if(v !== undefined && v !== null){
29301             var  r = this.findRecord(this.valueField || this.displayField, v);
29302             if(r){
29303                 this.select(this.store.indexOf(r), O);
29304                 return  true;
29305             }
29306         }
29307         return  false;
29308     },
29309
29310     
29311
29312     select : function(P, Q){
29313         this.selectedIndex = P;
29314         this.view.select(P);
29315         if(Q !== false){
29316             var  el = this.view.getNode(P);
29317             if(el){
29318                 this.innerList.scrollChildIntoView(el, false);
29319             }
29320         }
29321     },
29322
29323     
29324     selectNext : function(){
29325         var  ct = this.store.getCount();
29326         if(ct > 0){
29327             if(this.selectedIndex == -1){
29328                 this.select(0);
29329             }else  if(this.selectedIndex < ct-1){
29330                 this.select(this.selectedIndex+1);
29331             }
29332         }
29333     },
29334
29335     
29336     selectPrev : function(){
29337         var  ct = this.store.getCount();
29338         if(ct > 0){
29339             if(this.selectedIndex == -1){
29340                 this.select(0);
29341             }else  if(this.selectedIndex != 0){
29342                 this.select(this.selectedIndex-1);
29343             }
29344         }
29345     },
29346
29347     
29348     onKeyUp : function(e){
29349         if(this.editable !== false && !e.isSpecialKey()){
29350             this.lastKey = e.getKey();
29351             this.dqTask.delay(this.queryDelay);
29352         }
29353     },
29354
29355     
29356     validateBlur : function(){
29357         return  !this.list || !this.list.isVisible();   
29358     },
29359
29360     
29361     initQuery : function(){
29362         this.doQuery(this.getRawValue());
29363     },
29364
29365     
29366     doForce : function(){
29367         if(this.el.dom.value.length > 0){
29368             this.el.dom.value =
29369                 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
29370             this.applyEmptyText();
29371         }
29372     },
29373
29374     
29375
29376     doQuery : function(q, R){
29377         if(q === undefined || q === null){
29378             q = '';
29379         }
29380         var  qe = {
29381             query: q,
29382             forceAll: R,
29383             combo: this,
29384             cancel:false
29385         };
29386         if(this.fireEvent('beforequery', qe)===false || qe.cancel){
29387             return  false;
29388         }
29389
29390         q = qe.query;
29391         R = qe.forceAll;
29392         if(R === true || (q.length >= this.minChars)){
29393             if(this.lastQuery != q){
29394                 this.lastQuery = q;
29395                 if(this.mode == 'local'){
29396                     this.selectedIndex = -1;
29397                     if(R){
29398                         this.store.clearFilter();
29399                     }else {
29400                         this.store.filter(this.displayField, q);
29401                     }
29402
29403                     this.onLoad();
29404                 }else {
29405                     this.store.baseParams[this.queryParam] = q;
29406                     this.store.load({
29407                         params: this.getParams(q)
29408                     });
29409                     this.expand();
29410                 }
29411             }else {
29412                 this.selectedIndex = -1;
29413                 this.onLoad();   
29414             }
29415         }
29416     },
29417
29418     
29419     getParams : function(q){
29420         var  p = {};
29421         
29422         if(this.pageSize){
29423             p.start = 0;
29424             p.limit = this.pageSize;
29425         }
29426         return  p;
29427     },
29428
29429     
29430
29431     collapse : function(){
29432         if(!this.isExpanded()){
29433             return;
29434         }
29435
29436         this.list.hide();
29437         Roo.get(document).un('mousedown', this.collapseIf, this);
29438         Roo.get(document).un('mousewheel', this.collapseIf, this);
29439         this.fireEvent('collapse', this);
29440     },
29441
29442     
29443     collapseIf : function(e){
29444         if(!e.within(this.wrap) && !e.within(this.list)){
29445             this.collapse();
29446         }
29447     },
29448
29449     
29450
29451     expand : function(){
29452         if(this.isExpanded() || !this.hasFocus){
29453             return;
29454         }
29455
29456         this.list.alignTo(this.el, this.listAlign);
29457         this.list.show();
29458         Roo.get(document).on('mousedown', this.collapseIf, this);
29459         Roo.get(document).on('mousewheel', this.collapseIf, this);
29460         this.fireEvent('expand', this);
29461     },
29462
29463     
29464     
29465     onTriggerClick : function(){
29466         if(this.disabled){
29467             return;
29468         }
29469         if(this.isExpanded()){
29470             this.collapse();
29471             if (!this.blockFocus) {
29472                 this.el.focus();
29473             }
29474             
29475         }else  {
29476             this.hasFocus = true;
29477             if(this.triggerAction == 'all') {
29478                 this.doQuery(this.allQuery, true);
29479             } else  {
29480                 this.doQuery(this.getRawValue());
29481             }
29482             if (!this.blockFocus) {
29483                 this.el.focus();
29484             }
29485         }
29486     }
29487
29488     
29489
29490     
29491
29492     
29493
29494     
29495
29496 });
29497
29498
29499
29500
29501 Roo.form.Checkbox = function(A){
29502     Roo.form.Checkbox.superclass.constructor.call(this, A);
29503     this.addEvents({
29504         
29505
29506         check : true
29507     });
29508 };
29509
29510 Roo.extend(Roo.form.Checkbox, Roo.form.Field,  {
29511     
29512
29513     focusClass : undefined,
29514     
29515
29516     fieldClass: "x-form-field",
29517     
29518
29519     checked: false,
29520     
29521
29522     defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
29523     
29524
29525     boxLabel : "",
29526     
29527   
29528     inputValue : '1',
29529     
29530
29531      valueOff: '0', 
29532
29533     actionMode : 'viewEl', 
29534     
29535     
29536     itemCls : 'x-menu-check-item x-form-item',
29537     groupClass : 'x-menu-group-item',
29538     inputType : 'hidden',
29539     
29540     
29541     inSetChecked: false, 
29542     
29543     inputElement: false, 
29544     basedOn: false, 
29545     
29546     isFormField: true, 
29547
29548     onResize : function(){
29549         Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
29550         if(!this.boxLabel){
29551             this.el.alignTo(this.wrap, 'c-c');
29552         }
29553     },
29554
29555     initEvents : function(){
29556         Roo.form.Checkbox.superclass.initEvents.call(this);
29557         this.el.on("click", this.onClick,  this);
29558         this.el.on("change", this.onClick,  this);
29559     },
29560
29561
29562     getResizeEl : function(){
29563         return  this.wrap;
29564     },
29565
29566     getPositionEl : function(){
29567         return  this.wrap;
29568     },
29569
29570     
29571     onRender : function(ct, B){
29572         Roo.form.Checkbox.superclass.onRender.call(this, ct, B);
29573         
29574
29575         
29576         this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
29577         var  C = this.wrap.createChild({ 
29578             tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
29579         this.viewEl = C;   
29580         this.wrap.on('click', this.onClick,  this); 
29581         
29582         this.el.on('DOMAttrModified', this.setFromHidden,  this); 
29583         this.el.on('propertychange', this.setFromHidden,  this);  
29584         
29585         
29586         
29587         if(this.boxLabel){
29588             this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
29589         
29590         }
29591
29592         
29593             this.setChecked(this.checked);
29594         
29595             
29596         
29597
29598     },
29599
29600     
29601     initValue : Roo.emptyFn,
29602
29603     
29604
29605     getValue : function(){
29606         if(this.el){
29607             return  String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
29608         }
29609         return  this.valueOff;
29610         
29611     },
29612
29613         
29614     onClick : function(){ 
29615         this.setChecked(!this.checked);
29616
29617         
29618         
29619        
29620     },
29621
29622     
29623
29624     setValue : function(v,D){
29625         
29626         
29627         
29628         
29629         
29630         this.setChecked(v === this.inputValue);
29631         
29632     },
29633     
29634     setChecked : function(E,F)
29635     {
29636         if (this.inSetChecked) {
29637             this.checked = E;
29638             return;
29639         }
29640         
29641     
29642         if(this.wrap){
29643             this.wrap[E ? 'addClass' : 'removeClass']('x-menu-item-checked');
29644         }
29645
29646         this.checked = E;
29647         if(F !== true){
29648             this.fireEvent('checkchange', this, E);
29649         }
29650
29651         this.inSetChecked = true;
29652         this.el.dom.value = E ? this.inputValue : this.valueOff;
29653         this.inSetChecked = false;
29654         
29655     },
29656     
29657     setFromHidden: function()
29658     {
29659         if(!this.el){
29660             return;
29661         }
29662
29663         
29664         
29665         this.setValue(this.el.dom.value);
29666     },
29667     
29668     onDestroy : function()
29669     {
29670         if(this.viewEl){
29671             Roo.get(this.viewEl).remove();
29672         }
29673
29674          
29675         Roo.form.Checkbox.superclass.onDestroy.call(this);
29676     }
29677
29678 });
29679
29680
29681  
29682
29683
29684 Roo.form.Radio = function(){
29685     Roo.form.Radio.superclass.constructor.apply(this, arguments);
29686 };
29687 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
29688     inputType: 'radio',
29689
29690     
29691
29692     getGroupValue : function(){
29693         return  this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
29694     }
29695 });
29696
29697
29698
29699
29700  
29701  
29702
29703  
29704
29705
29706
29707 Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
29708       
29709
29710     toolbars : false,
29711     
29712
29713     createLinkText : 'Please enter the URL for the link:',
29714     
29715
29716     defaultLinkValue : 'http:/'+'/',
29717    
29718     
29719     
29720     frameId: false,
29721     
29722     
29723     validationEvent : false,
29724     deferHeight: true,
29725     initialized : false,
29726     activated : false,
29727     sourceEditMode : false,
29728     onFocus : Roo.emptyFn,
29729     iframePad:3,
29730     hideMode:'offsets',
29731     defaultAutoCreate : {
29732         tag: "textarea",
29733         style:"width:500px;height:300px;",
29734         autocomplete: "off"
29735     },
29736
29737     
29738     initComponent : function(){
29739         this.addEvents({
29740             
29741
29742             initialize: true,
29743             
29744
29745             activate: true,
29746              
29747
29748             beforesync: true,
29749              
29750
29751             beforepush: true,
29752              
29753
29754             sync: true,
29755              
29756
29757             push: true,
29758              
29759
29760             editmodechange: true,
29761             
29762
29763             editorevent: true
29764         })
29765     },
29766
29767     
29768
29769     createToolbar : function(A){
29770         if (!A.toolbars || !A.toolbars.length) {
29771             A.toolbars = [ new  Roo.form.HtmlEditor.ToolbarStandard() ]; 
29772         }
29773         
29774         for (var  i =0 ; i < A.toolbars.length;i++) {
29775             A.toolbars[i].init(A);
29776         }
29777          
29778         
29779     },
29780
29781     
29782
29783     getDocMarkup : function(){
29784         return  '<html><head><style type="text/css">body{border:0;margin:0;padding:3px;height:98%;cursor:text;}</style></head><body></body></html>';
29785     },
29786
29787     
29788     onRender : function(ct, B){
29789         Roo.form.HtmlEditor.superclass.onRender.call(this, ct, B);
29790         this.el.dom.style.border = '0 none';
29791         this.el.dom.setAttribute('tabIndex', -1);
29792         this.el.addClass('x-hidden');
29793         if(Roo.isIE){ 
29794             this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
29795         }
29796
29797         this.wrap = this.el.wrap({
29798             cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
29799         });
29800
29801         this.frameId = Roo.id();
29802         this.createToolbar(this);
29803         
29804         
29805         
29806         
29807       
29808         
29809         var  C = this.wrap.createChild({
29810             tag: 'iframe',
29811             id: this.frameId,
29812             name: this.frameId,
29813             frameBorder : 'no',
29814             'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL  :  "javascript:false"
29815         });
29816         
29817        
29818         
29819
29820         this.iframe = C.dom;
29821
29822          this.assignDocWin();
29823         
29824         this.doc.designMode = 'on';
29825        
29826         this.doc.open();
29827         this.doc.write(this.getDocMarkup());
29828         this.doc.close();
29829
29830         
29831         var  D = { 
29832             run : function(){
29833                 
29834                 this.assignDocWin();
29835                 if(this.doc.body || this.doc.readyState == 'complete'){
29836                     try {
29837                         
29838                        
29839                         this.doc.designMode="on";
29840                     } catch (e) {
29841                         return;
29842                     }
29843
29844                     Roo.TaskMgr.stop(D);
29845                     this.initEditor.defer(10, this);
29846                 }
29847             },
29848             interval : 10,
29849             duration:10000,
29850             scope: this
29851         };
29852         Roo.TaskMgr.start(D);
29853
29854         if(!this.width){
29855             this.setSize(this.el.getSize());
29856         }
29857     },
29858
29859     
29860     onResize : function(w, h){
29861         Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
29862         if(this.el && this.iframe){
29863             if(typeof  w == 'number'){
29864                 var  aw = w - this.wrap.getFrameWidth('lr');
29865                 this.el.setWidth(this.adjustWidth('textarea', aw));
29866                 this.iframe.style.width = aw + 'px';
29867             }
29868             if(typeof  h == 'number'){
29869                 var  tbh = 0;
29870                 for (var  i =0; i < this.toolbars.length;i++) {
29871                     
29872                     tbh += this.toolbars[i].tb.el.getHeight();
29873                 }
29874                 
29875                 
29876                 
29877                 
29878                 var  ah = h - this.wrap.getFrameWidth('tb') - tbh;
29879                 this.el.setHeight(this.adjustWidth('textarea', ah));
29880                 this.iframe.style.height = ah + 'px';
29881                 if(this.doc){
29882                     (this.doc.body || this.doc.documentElement).style.height = (ah - (this.iframePad*2)) + 'px';
29883                 }
29884             }
29885         }
29886     },
29887
29888     
29889
29890     toggleSourceEdit : function(E){
29891         
29892         this.sourceEditMode = E === true;
29893         
29894         if(this.sourceEditMode){
29895           
29896             this.syncValue();
29897             this.iframe.className = 'x-hidden';
29898             this.el.removeClass('x-hidden');
29899             this.el.dom.removeAttribute('tabIndex');
29900             this.el.focus();
29901         }else {
29902              
29903             this.pushValue();
29904             this.iframe.className = '';
29905             this.el.addClass('x-hidden');
29906             this.el.dom.setAttribute('tabIndex', -1);
29907             this.deferFocus();
29908         }
29909
29910         this.setSize(this.wrap.getSize());
29911         this.fireEvent('editmodechange', this, this.sourceEditMode);
29912     },
29913
29914     
29915     createLink : function(){
29916         var  F = prompt(this.createLinkText, this.defaultLinkValue);
29917         if(F && F != 'http:/'+'/'){
29918             this.relayCmd('createlink', F);
29919         }
29920     },
29921
29922     
29923     adjustSize : Roo.BoxComponent.prototype.adjustSize,
29924
29925     
29926     getResizeEl : function(){
29927         return  this.wrap;
29928     },
29929
29930     
29931     getPositionEl : function(){
29932         return  this.wrap;
29933     },
29934
29935     
29936     initEvents : function(){
29937         this.originalValue = this.getValue();
29938     },
29939
29940     
29941
29942     markInvalid : Roo.emptyFn,
29943     
29944
29945     clearInvalid : Roo.emptyFn,
29946
29947     setValue : function(v){
29948         Roo.form.HtmlEditor.superclass.setValue.call(this, v);
29949         this.pushValue();
29950     },
29951
29952     
29953
29954     cleanHtml : function(G){
29955         G = String(G);
29956         if(G.length > 5){
29957             if(Roo.isSafari){ 
29958                 G = G.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
29959             }
29960         }
29961         if(G == '&nbsp;'){
29962             G = '';
29963         }
29964         return  G;
29965     },
29966
29967     
29968
29969     syncValue : function(){
29970         if(this.initialized){
29971             var  bd = (this.doc.body || this.doc.documentElement);
29972             var  G = bd.innerHTML;
29973             if(Roo.isSafari){
29974                 var  bs = bd.getAttribute('style'); 
29975                 var  m = bs.match(/text-align:(.*?);/i);
29976                 if(m && m[1]){
29977                     G = '<div style="'+m[0]+'">' + G + '</div>';
29978                 }
29979             }
29980
29981             G = this.cleanHtml(G);
29982             if(this.fireEvent('beforesync', this, G) !== false){
29983                 this.el.dom.value = G;
29984                 this.fireEvent('sync', this, G);
29985             }
29986         }
29987     },
29988
29989     
29990
29991     pushValue : function(){
29992         if(this.initialized){
29993             var  v = this.el.dom.value;
29994             if(v.length < 1){
29995                 v = '&#160;';
29996             }
29997             if(this.fireEvent('beforepush', this, v) !== false){
29998                 (this.doc.body || this.doc.documentElement).innerHTML = v;
29999                 this.fireEvent('push', this, v);
30000             }
30001         }
30002     },
30003
30004     
30005     deferFocus : function(){
30006         this.focus.defer(10, this);
30007     },
30008
30009     
30010     focus : function(){
30011         if(this.win && !this.sourceEditMode){
30012             this.win.focus();
30013         }else {
30014             this.el.focus();
30015         }
30016     },
30017     
30018     assignDocWin: function()
30019     {
30020         var  H = this.iframe;
30021         
30022          if(Roo.isIE){
30023             this.doc = H.contentWindow.document;
30024             this.win = H.contentWindow;
30025         } else  {
30026             this.doc = (H.contentDocument || Roo.get(this.frameId).dom.document);
30027             this.win = Roo.get(this.frameId).dom.contentWindow;
30028         }
30029     },
30030     
30031     
30032     initEditor : function(){
30033         
30034         this.assignDocWin();
30035         
30036         
30037         
30038         this.doc.designMode="on";
30039         this.doc.open();
30040         this.doc.write(this.getDocMarkup());
30041         this.doc.close();
30042         
30043         var  I = (this.doc.body || this.doc.documentElement);
30044         
30045         
30046         
30047         var  ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
30048         ss['background-attachment'] = 'fixed'; 
30049         I.bgProperties = 'fixed'; 
30050         Roo.DomHelper.applyStyles(I, ss);
30051         Roo.EventManager.on(this.doc, {
30052             'mousedown': this.onEditorEvent,
30053             'dblclick': this.onEditorEvent,
30054             'click': this.onEditorEvent,
30055             'keyup': this.onEditorEvent,
30056             buffer:100,
30057             scope: this
30058         });
30059         if(Roo.isGecko){
30060             Roo.EventManager.on(this.doc, 'keypress', this.applyCommand, this);
30061         }
30062         if(Roo.isIE || Roo.isSafari || Roo.isOpera){
30063             Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
30064         }
30065
30066         this.initialized = true;
30067
30068         this.fireEvent('initialize', this);
30069         this.pushValue();
30070     },
30071
30072     
30073     onDestroy : function(){
30074         
30075         
30076         
30077         if(this.rendered){
30078             
30079             for (var  i =0; i < this.toolbars.length;i++) {
30080                 
30081                 this.toolbars[i].onDestroy();
30082             }
30083
30084             
30085             this.wrap.dom.innerHTML = '';
30086             this.wrap.remove();
30087         }
30088     },
30089
30090     
30091     onFirstFocus : function(){
30092         
30093         this.assignDocWin();
30094         
30095         
30096         this.activated = true;
30097         for (var  i =0; i < this.toolbars.length;i++) {
30098             this.toolbars[i].onFirstFocus();
30099         }
30100        
30101         if(Roo.isGecko){ 
30102             this.win.focus();
30103             var  s = this.win.getSelection();
30104             if(!s.focusNode || s.focusNode.nodeType != 3){
30105                 var  r = s.getRangeAt(0);
30106                 r.selectNodeContents((this.doc.body || this.doc.documentElement));
30107                 r.collapse(true);
30108                 this.deferFocus();
30109             }
30110             try{
30111                 this.execCmd('useCSS', true);
30112                 this.execCmd('styleWithCSS', false);
30113             }catch(e){}
30114         }
30115
30116         this.fireEvent('activate', this);
30117     },
30118
30119     
30120     adjustFont: function(J){
30121         var  K = J.cmd == 'increasefontsize' ? 1 : -1;
30122         
30123         
30124        
30125         var  v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
30126         if(Roo.isSafari){ 
30127             var  sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
30128             v =  (v < 10) ? 10 : v;
30129             v =  (v > 48) ? 48 : v;
30130             v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
30131             
30132         }
30133
30134         
30135         
30136         v = Math.max(1, v+K);
30137         
30138         this.execCmd('FontSize', v  );
30139     },
30140
30141     onEditorEvent : function(e){
30142         this.fireEvent('editorevent', this, e);
30143       
30144         this.syncValue();
30145     },
30146
30147     insertTag : function(tg)
30148     {
30149         
30150         
30151         this.execCmd("formatblock",   tg);
30152         
30153     },
30154     
30155     insertText : function(L)
30156     {
30157         
30158         
30159         range = this.createRange();
30160         range.deleteContents();
30161                
30162                
30163         range.insertNode(this.doc.createTextNode(L));
30164     } ,
30165     
30166     
30167     relayBtnCmd : function(M){
30168         this.relayCmd(M.cmd);
30169     },
30170
30171     
30172
30173     relayCmd : function(N, O){
30174         this.win.focus();
30175         this.execCmd(N, O);
30176         this.fireEvent('editorevent', this);
30177         
30178         this.deferFocus();
30179     },
30180
30181     
30182
30183     execCmd : function(P, Q){
30184         this.doc.execCommand(P, false, Q === undefined ? null : Q);
30185         this.syncValue();
30186     },
30187
30188     
30189     applyCommand : function(e){
30190         if(e.ctrlKey){
30191             var  c = e.getCharCode(), P;
30192             if(c > 0){
30193                 c = String.fromCharCode(c);
30194                 switch(c){
30195                     case  'b':
30196                         P = 'bold';
30197                     break;
30198                     case  'i':
30199                         P = 'italic';
30200                     break;
30201                     case  'u':
30202                         P = 'underline';
30203                     break;
30204                 }
30205                 if(P){
30206                     this.win.focus();
30207                     this.execCmd(P);
30208                     this.deferFocus();
30209                     e.preventDefault();
30210                 }
30211             }
30212         }
30213     },
30214
30215     
30216
30217     insertAtCursor : function(R){
30218         if(!this.activated){
30219             return;
30220         }
30221         if(Roo.isIE){
30222             this.win.focus();
30223             var  r = this.doc.selection.createRange();
30224             if(r){
30225                 r.collapse(true);
30226                 r.pasteHTML(R);
30227                 this.syncValue();
30228                 this.deferFocus();
30229             }
30230         }else  if(Roo.isGecko || Roo.isOpera){
30231             this.win.focus();
30232             this.execCmd('InsertHTML', R);
30233             this.deferFocus();
30234         }else  if(Roo.isSafari){
30235             this.execCmd('InsertText', R);
30236             this.deferFocus();
30237         }
30238     },
30239
30240     
30241     fixKeys : function(){ 
30242         if(Roo.isIE){
30243             return  function(e){
30244                 var  k = e.getKey(), r;
30245                 if(k == e.TAB){
30246                     e.stopEvent();
30247                     r = this.doc.selection.createRange();
30248                     if(r){
30249                         r.collapse(true);
30250                         r.pasteHTML('&#160;&#160;&#160;&#160;');
30251                         this.deferFocus();
30252                     }
30253                 }else  if(k == e.ENTER){
30254                     r = this.doc.selection.createRange();
30255                     if(r){
30256                         var  target = r.parentElement();
30257                         if(!target || target.tagName.toLowerCase() != 'li'){
30258                             e.stopEvent();
30259                             r.pasteHTML('<br />');
30260                             r.collapse(false);
30261                             r.select();
30262                         }
30263                     }
30264                 }
30265             };
30266         }else  if(Roo.isOpera){
30267             return  function(e){
30268                 var  k = e.getKey();
30269                 if(k == e.TAB){
30270                     e.stopEvent();
30271                     this.win.focus();
30272                     this.execCmd('InsertHTML','&#160;&#160;&#160;&#160;');
30273                     this.deferFocus();
30274                 }
30275             };
30276         }else  if(Roo.isSafari){
30277             return  function(e){
30278                 var  k = e.getKey();
30279                 if(k == e.TAB){
30280                     e.stopEvent();
30281                     this.execCmd('InsertText','\t');
30282                     this.deferFocus();
30283                 }
30284              };
30285         }
30286     }(),
30287     
30288     getAllAncestors: function()
30289     {
30290         var  p = this.getSelectedNode();
30291         var  a = [];
30292         if (!p) {
30293             a.push(p); 
30294             p = this.getParentElement();
30295         }
30296         
30297         
30298         while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
30299             a.push(p);
30300             p = p.parentNode;
30301         }
30302
30303         a.push(this.doc.body);
30304         return  a;
30305     },
30306     lastSel : false,
30307     lastSelNode : false,
30308     
30309     
30310     getSelection : function() 
30311     {
30312         this.assignDocWin();
30313         return  Roo.isIE ? this.doc.selection : this.win.getSelection();
30314     },
30315     
30316     getSelectedNode: function() 
30317     {
30318         
30319         
30320         
30321         
30322         
30323         
30324          
30325         var  S = this.createRange(this.getSelection());
30326         
30327         if (Roo.isIE) {
30328             var  parent = S.parentElement();
30329             while (true) {
30330                 var  testRange = S.duplicate();
30331                 testRange.moveToElementText(parent);
30332                 if (testRange.inRange(S)) {
30333                     break;
30334                 }
30335                 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
30336                     break;
30337                 }
30338
30339                 parent = parent.parentElement;
30340             }
30341             return  parent;
30342         }
30343         
30344         
30345         var  ar = S.endContainer.childNodes;
30346         if (!ar.length) {
30347             ar = S.commonAncestorContainer.childNodes;
30348             
30349         }
30350         var  T = [];
30351         var  U = [];
30352         var  V = false;
30353         for (var  i=0;i<ar.length;i++) {
30354             if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { 
30355                 continue;
30356             }
30357             
30358             
30359             if (this.rangeIntersectsNode(S,ar[i]) && this.rangeCompareNode(S,ar[i]) == 3) {
30360                 T.push(ar[i]);
30361                 continue;
30362             }
30363             
30364             
30365             if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(S,ar[i]) && (this.rangeCompareNode(S,ar[i]) > 0)) {
30366                 U.push(ar[i]);
30367                 continue;
30368             }
30369             if (!this.rangeIntersectsNode(S,ar[i])|| (this.rangeCompareNode(S,ar[i]) == 0))  {
30370                 continue;
30371             }
30372
30373             
30374             
30375             V = true;
30376         }
30377         if (!T.length && U.length) {
30378             T= U;
30379         }
30380         if (V || !T.length || (T.length > 1)) {
30381             return  false;
30382         }
30383         
30384         return  T[0];
30385     },
30386     createRange: function(W)
30387     {
30388         
30389         
30390         
30391         if (typeof  W != "undefined") {
30392             try {
30393                 return  W.getRangeAt ? W.getRangeAt(0) : W.createRange();
30394             } catch(e) {
30395                 return  this.doc.createRange();
30396             }
30397         } else  {
30398             return  this.doc.createRange();
30399         }
30400     },
30401     getParentElement: function()
30402     {
30403         
30404         this.assignDocWin();
30405         var  X = Roo.isIE ? this.doc.selection : this.win.getSelection();
30406         
30407         var  Y = this.createRange(X);
30408          
30409         try {
30410             var  p = Y.commonAncestorContainer;
30411             while (p.nodeType == 3) { 
30412                 p = p.parentNode;
30413             }
30414             return  p;
30415         } catch (e) {
30416             return  null;
30417         }
30418     
30419     },
30420     
30421     
30422     
30423     
30424     rangeIntersectsNode : function(Z, b)
30425     {
30426         var  d = b.ownerDocument.createRange();
30427         try {
30428             d.selectNode(b);
30429         }
30430         catch (e) {
30431             nodeRange.selectNodeContents(node);
30432         }
30433
30434         return  Z.compareBoundaryPoints(Range.END_TO_START, d) == -1 &&
30435                  Z.compareBoundaryPoints(Range.START_TO_END, d) == 1;
30436     },
30437     rangeCompareNode : function(f, g) {
30438         var  j = g.ownerDocument.createRange();
30439         try {
30440             j.selectNode(g);
30441         } catch (e) {
30442             nodeRange.selectNodeContents(node);
30443         }
30444         var  k = f.compareBoundaryPoints(Range.START_TO_START, j) == 1;
30445         var  l = f.compareBoundaryPoints(Range.END_TO_END, j) == -1;
30446
30447         if (k && !l)
30448             return  0;
30449         if (!k && l)
30450             return  1;
30451         if (k && l)
30452             return  2;
30453
30454         return  3;
30455     }
30456
30457     
30458     
30459     
30460     
30461
30462     
30463
30464     
30465
30466     
30467
30468     
30469
30470     
30471
30472     
30473
30474     
30475
30476     
30477
30478     
30479
30480     
30481
30482     
30483
30484 });
30485
30486
30487
30488
30489
30490
30491  
30492 Roo.form.HtmlEditor.ToolbarStandard = function(A)
30493 {
30494     
30495     Roo.apply(this, A);
30496     
30497     
30498 }
30499
30500
30501 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype,  {
30502     
30503     tb: false,
30504     
30505     rendered: false,
30506     
30507     editor : false,
30508     
30509
30510     disable : false,
30511       
30512
30513     fontFamilies : [
30514         'Arial',
30515         'Courier New',
30516         'Tahoma',
30517         'Times New Roman',
30518         'Verdana'
30519     ],
30520     
30521     specialChars : [
30522            "&#169;",
30523           "&#174;",     
30524           "&#8482;",    
30525           "&#163;" ,    
30526          
30527           "&#8230;",    
30528           "&#247;" ,    
30529         
30530            "&#8364;"    , 
30531        
30532         
30533         
30534           "&#176;"  
30535
30536          
30537          
30538     ],
30539     inputElements : [ 
30540             "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password", 
30541             "input:submit", "input:button", "select", "textarea", "label" ],
30542     formats : [
30543         ["p"] ,  
30544         ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"], 
30545         ["pre"],[ "code"], 
30546         ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
30547     ],
30548      
30549
30550     defaultFont: 'tahoma',
30551    
30552     fontSelect : false,
30553     
30554     
30555     formatCombo : false,
30556     
30557     init : function(B)
30558     {
30559         this.editor = B;
30560         
30561         
30562         var  C = B.frameId;
30563         var  D = this;
30564         function  E(id, G, H){
30565             var  I = C + '-'+ id ;
30566             return  {
30567                 id : I,
30568                 cmd : id,
30569                 cls : 'x-btn-icon x-edit-'+id,
30570                 enableToggle:G !== false,
30571                 scope: B, 
30572                 handler:H||B.relayBtnCmd,
30573                 clickEvent:'mousedown',
30574                 tooltip: D.buttonTips[id] || undefined, 
30575                 tabIndex:-1
30576             };
30577         }
30578         
30579         
30580         
30581         var  tb = new  Roo.Toolbar(B.wrap.dom.firstChild);
30582         this.tb = tb;
30583          
30584         tb.el.on('click', function(e){
30585             e.preventDefault(); 
30586         });
30587
30588         if(!this.disable.font && !Roo.isSafari){
30589             
30590
30591         };
30592         if(!this.disable.formats){
30593             this.formatCombo = new  Roo.form.ComboBox({
30594                 store: new  Roo.data.SimpleStore({
30595                     id : 'tag',
30596                     fields: ['tag'],
30597                     data : this.formats 
30598                 }),
30599                 blockFocus : true,
30600                 
30601                 displayField:'tag',
30602                 typeAhead: false,
30603                 mode: 'local',
30604                 editable : false,
30605                 triggerAction: 'all',
30606                 emptyText:'Add tag',
30607                 selectOnFocus:true,
30608                 width:135,
30609                 listeners : {
30610                     'select': function(c, r, i) {
30611                         B.insertTag(r.get('tag'));
30612                         B.focus();
30613                     }
30614                 }
30615
30616             });
30617             tb.addField(this.formatCombo);
30618             
30619         }
30620         
30621         if(!this.disable.format){
30622             tb.add(
30623                 E('bold'),
30624                 E('italic'),
30625                 E('underline')
30626             );
30627         };
30628         if(!this.disable.fontSize){
30629             tb.add(
30630                 '-',
30631                 
30632                 
30633                 E('increasefontsize', false, B.adjustFont),
30634                 E('decreasefontsize', false, B.adjustFont)
30635             );
30636         };
30637         
30638         
30639         if(this.disable.colors){
30640             tb.add(
30641                 '-', {
30642                     id:B.frameId +'-forecolor',
30643                     cls:'x-btn-icon x-edit-forecolor',
30644                     clickEvent:'mousedown',
30645                     tooltip: this.buttonTips['forecolor'] || undefined,
30646                     tabIndex:-1,
30647                     menu : new  Roo.menu.ColorMenu({
30648                         allowReselect: true,
30649                         focus: Roo.emptyFn,
30650                         value:'000000',
30651                         plain:true,
30652                         selectHandler: function(cp, G){
30653                             B.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+G : G);
30654                             B.deferFocus();
30655                         },
30656                         scope: B,
30657                         clickEvent:'mousedown'
30658                     })
30659                 }, {
30660                     id:B.frameId +'backcolor',
30661                     cls:'x-btn-icon x-edit-backcolor',
30662                     clickEvent:'mousedown',
30663                     tooltip: this.buttonTips['backcolor'] || undefined,
30664                     tabIndex:-1,
30665                     menu : new  Roo.menu.ColorMenu({
30666                         focus: Roo.emptyFn,
30667                         value:'FFFFFF',
30668                         plain:true,
30669                         allowReselect: true,
30670                         selectHandler: function(cp, H){
30671                             if(Roo.isGecko){
30672                                 B.execCmd('useCSS', false);
30673                                 B.execCmd('hilitecolor', H);
30674                                 B.execCmd('useCSS', true);
30675                                 B.deferFocus();
30676                             }else {
30677                                 B.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor', 
30678                                     Roo.isSafari || Roo.isIE ? '#'+H : H);
30679                                 B.deferFocus();
30680                             }
30681                         },
30682                         scope:B,
30683                         clickEvent:'mousedown'
30684                     })
30685                 }
30686             );
30687         };
30688         
30689         
30690
30691         if(!this.disable.alignments){
30692             tb.add(
30693                 '-',
30694                 E('justifyleft'),
30695                 E('justifycenter'),
30696                 E('justifyright')
30697             );
30698         };
30699
30700         
30701             if(!this.disable.links){
30702                 tb.add(
30703                     '-',
30704                     E('createlink', false, B.createLink)    
30705                 );
30706             };
30707
30708             if(!this.disable.lists){
30709                 tb.add(
30710                     '-',
30711                     E('insertorderedlist'),
30712                     E('insertunorderedlist')
30713                 );
30714             }
30715             if(!this.disable.sourceEdit){
30716                 tb.add(
30717                     '-',
30718                     E('sourceedit', true, function(G){
30719                         this.toggleSourceEdit(G.pressed);
30720                     })
30721                 );
30722             }
30723         
30724         
30725         var  F = { };
30726         
30727         if (!this.disable.special) {
30728             F = {
30729                 text: "&#169;",
30730                 cls: 'x-edit-none',
30731                 menu : {
30732                     items : []
30733                    }
30734             };
30735             for (var  i =0; i < this.specialChars.length; i++) {
30736                 F.menu.items.push({
30737                     
30738                     text: this.specialChars[i],
30739                     handler: function(a,b) {
30740                         B.insertAtCursor(String.fromCharCode(a.text.replace('&#','').replace(';', '')));
30741                     },
30742                     tabIndex:-1
30743                 });
30744             }
30745
30746             
30747             
30748             tb.add(F);
30749             
30750             
30751         }
30752         if (this.btns) {
30753             for(var  i =0; i< this.btns.length;i++) {
30754                 var  b = this.btns[i];
30755                 b.cls =  'x-edit-none';
30756                 b.scope = B;
30757                 tb.add(b);
30758             }
30759         
30760         }
30761
30762         
30763         
30764         
30765         
30766         
30767         this.tb.items.each(function(G){
30768            if(G.id != B.frameId+ '-sourceedit'){
30769                 G.disable();
30770             }
30771         });
30772         this.rendered = true;
30773         
30774         
30775         B.on('editorevent', this.updateToolbar, this);
30776         
30777         
30778     },
30779     
30780     
30781     
30782     
30783
30784     updateToolbar: function(){
30785
30786         if(!this.editor.activated){
30787             this.editor.onFirstFocus();
30788             return;
30789         }
30790
30791         var  G = this.tb.items.map, 
30792             H = this.editor.doc,
30793             I = this.editor.frameId;
30794
30795         if(!this.disable.font && !Roo.isSafari){
30796             
30797
30798         }
30799         if(!this.disable.format){
30800             G[I + '-bold'].toggle(H.queryCommandState('bold'));
30801             G[I + '-italic'].toggle(H.queryCommandState('italic'));
30802             G[I + '-underline'].toggle(H.queryCommandState('underline'));
30803         }
30804         if(!this.disable.alignments){
30805             G[I + '-justifyleft'].toggle(H.queryCommandState('justifyleft'));
30806             G[I + '-justifycenter'].toggle(H.queryCommandState('justifycenter'));
30807             G[I + '-justifyright'].toggle(H.queryCommandState('justifyright'));
30808         }
30809         if(!Roo.isSafari && !this.disable.lists){
30810             G[I + '-insertorderedlist'].toggle(H.queryCommandState('insertorderedlist'));
30811             G[I + '-insertunorderedlist'].toggle(H.queryCommandState('insertunorderedlist'));
30812         }
30813         
30814         var  J = this.editor.getAllAncestors();
30815         if (this.formatCombo) {
30816             
30817             
30818             var  store = this.formatCombo.store;
30819             this.formatCombo.setValue("");
30820             for (var  i =0; i < J.length;i++) {
30821                 if (J[i] && store.query('tag',J[i].tagName.toLowerCase(), true).length) {
30822                     
30823                     this.formatCombo.setValue(J[i].tagName.toLowerCase());
30824                     break;
30825                 }
30826             }
30827         }
30828
30829         
30830         
30831         
30832         
30833         Roo.menu.MenuMgr.hideAll();
30834
30835         
30836     },
30837    
30838     
30839     createFontOptions : function(){
30840         var  K = [], fs = this.fontFamilies, ff, lc;
30841         for(var  i = 0, len = fs.length; i< len; i++){
30842             ff = fs[i];
30843             lc = ff.toLowerCase();
30844             K.push(
30845                 '<option value="',lc,'" style="font-family:',ff,';"',
30846                     (this.defaultFont == lc ? ' selected="true">' : '>'),
30847                     ff,
30848                 '</option>'
30849             );
30850         }
30851         return  K.join('');
30852     },
30853     
30854     toggleSourceEdit : function(L){
30855         if(L === undefined){
30856             L = !this.sourceEditMode;
30857         }
30858
30859         this.sourceEditMode = L === true;
30860         var  M = this.tb.items.get(this.editor.frameId +'-sourceedit');
30861         
30862         if(M.pressed !== this.editor.sourceEditMode){
30863             M.toggle(this.editor.sourceEditMode);
30864             return;
30865         }
30866         
30867         if(this.sourceEditMode){
30868             this.tb.items.each(function(N){
30869                 if(N.cmd != 'sourceedit'){
30870                     N.disable();
30871                 }
30872             });
30873           
30874         }else {
30875             if(this.initialized){
30876                 this.tb.items.each(function(O){
30877                     O.enable();
30878                 });
30879             }
30880             
30881         }
30882
30883         
30884         this.editor.toggleSourceEdit(L);
30885        
30886     },
30887      
30888
30889     buttonTips : {
30890         bold : {
30891             title: 'Bold (Ctrl+B)',
30892             text: 'Make the selected text bold.',
30893             cls: 'x-html-editor-tip'
30894         },
30895         italic : {
30896             title: 'Italic (Ctrl+I)',
30897             text: 'Make the selected text italic.',
30898             cls: 'x-html-editor-tip'
30899         },
30900         underline : {
30901             title: 'Underline (Ctrl+U)',
30902             text: 'Underline the selected text.',
30903             cls: 'x-html-editor-tip'
30904         },
30905         increasefontsize : {
30906             title: 'Grow Text',
30907             text: 'Increase the font size.',
30908             cls: 'x-html-editor-tip'
30909         },
30910         decreasefontsize : {
30911             title: 'Shrink Text',
30912             text: 'Decrease the font size.',
30913             cls: 'x-html-editor-tip'
30914         },
30915         backcolor : {
30916             title: 'Text Highlight Color',
30917             text: 'Change the background color of the selected text.',
30918             cls: 'x-html-editor-tip'
30919         },
30920         forecolor : {
30921             title: 'Font Color',
30922             text: 'Change the color of the selected text.',
30923             cls: 'x-html-editor-tip'
30924         },
30925         justifyleft : {
30926             title: 'Align Text Left',
30927             text: 'Align text to the left.',
30928             cls: 'x-html-editor-tip'
30929         },
30930         justifycenter : {
30931             title: 'Center Text',
30932             text: 'Center text in the editor.',
30933             cls: 'x-html-editor-tip'
30934         },
30935         justifyright : {
30936             title: 'Align Text Right',
30937             text: 'Align text to the right.',
30938             cls: 'x-html-editor-tip'
30939         },
30940         insertunorderedlist : {
30941             title: 'Bullet List',
30942             text: 'Start a bulleted list.',
30943             cls: 'x-html-editor-tip'
30944         },
30945         insertorderedlist : {
30946             title: 'Numbered List',
30947             text: 'Start a numbered list.',
30948             cls: 'x-html-editor-tip'
30949         },
30950         createlink : {
30951             title: 'Hyperlink',
30952             text: 'Make the selected text a hyperlink.',
30953             cls: 'x-html-editor-tip'
30954         },
30955         sourceedit : {
30956             title: 'Source Edit',
30957             text: 'Switch to source editing mode.',
30958             cls: 'x-html-editor-tip'
30959         }
30960     },
30961     
30962     onDestroy : function(){
30963         if(this.rendered){
30964             
30965             this.tb.items.each(function(N){
30966                 if(N.menu){
30967                     N.menu.removeAll();
30968                     if(N.menu.el){
30969                         N.menu.el.destroy();
30970                     }
30971                 }
30972
30973                 N.destroy();
30974             });
30975              
30976         }
30977     },
30978     onFirstFocus: function() {
30979         this.tb.items.each(function(N){
30980            N.enable();
30981         });
30982     }
30983 });
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993  
30994
30995
30996
30997 Roo.form.HtmlEditor.ToolbarContext = function(A)
30998 {
30999     
31000     Roo.apply(this, A);
31001     
31002     
31003 }
31004
31005 Roo.form.HtmlEditor.ToolbarContext.types = {
31006     'IMG' : {
31007         width : {
31008             title: "Width",
31009             width: 40
31010         },
31011         height:  {
31012             title: "Height",
31013             width: 40
31014         },
31015         align: {
31016             title: "Align",
31017             opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
31018             width : 80
31019             
31020         },
31021         border: {
31022             title: "Border",
31023             width: 40
31024         },
31025         alt: {
31026             title: "Alt",
31027             width: 120
31028         },
31029         src : {
31030             title: "Src",
31031             width: 220
31032         }
31033         
31034     },
31035     'A' : {
31036         name : {
31037             title: "Name",
31038             width: 50
31039         },
31040         href:  {
31041             title: "Href",
31042             width: 220
31043         } 
31044         
31045     },
31046     'TABLE' : {
31047         rows : {
31048             title: "Rows",
31049             width: 20
31050         },
31051         cols : {
31052             title: "Cols",
31053             width: 20
31054         },
31055         width : {
31056             title: "Width",
31057             width: 40
31058         },
31059         height : {
31060             title: "Height",
31061             width: 40
31062         },
31063         border : {
31064             title: "Border",
31065             width: 20
31066         }
31067     },
31068     'TD' : {
31069         width : {
31070             title: "Width",
31071             width: 40
31072         },
31073         height : {
31074             title: "Height",
31075             width: 40
31076         },   
31077         align: {
31078             title: "Align",
31079             opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
31080             width: 40
31081         },
31082         valign: {
31083             title: "Valign",
31084             opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
31085             width: 40
31086         },
31087         colspan: {
31088             title: "Colspan",
31089             width: 20
31090             
31091         }
31092     },
31093     'INPUT' : {
31094         name : {
31095             title: "name",
31096             width: 120
31097         },
31098         value : {
31099             title: "Value",
31100             width: 120
31101         },
31102         width : {
31103             title: "Width",
31104             width: 40
31105         }
31106     },
31107     'LABEL' : {
31108         'for' : {
31109             title: "For",
31110             width: 120
31111         }
31112     },
31113     'TEXTAREA' : {
31114           name : {
31115             title: "name",
31116             width: 120
31117         },
31118         rows : {
31119             title: "Rows",
31120             width: 20
31121         },
31122         cols : {
31123             title: "Cols",
31124             width: 20
31125         }
31126     },
31127     'SELECT' : {
31128         name : {
31129             title: "name",
31130             width: 120
31131         },
31132         selectoptions : {
31133             title: "Options",
31134             width: 200
31135         }
31136     },
31137     'BODY' : {
31138         title : {
31139             title: "title",
31140             width: 120,
31141             disabled : true
31142         }
31143     }
31144 };
31145
31146
31147
31148 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype,  {
31149     
31150     tb: false,
31151     
31152     rendered: false,
31153     
31154     editor : false,
31155     
31156
31157     disable : false,
31158     
31159     
31160     
31161     toolbars : false,
31162     
31163     init : function(B)
31164     {
31165         this.editor = B;
31166         
31167         
31168         var  C = B.frameId;
31169         var  D = this;
31170         function  E(id, G, H){
31171             var  I = C + '-'+ id ;
31172             return  {
31173                 id : I,
31174                 cmd : id,
31175                 cls : 'x-btn-icon x-edit-'+id,
31176                 enableToggle:G !== false,
31177                 scope: B, 
31178                 handler:H||B.relayBtnCmd,
31179                 clickEvent:'mousedown',
31180                 tooltip: D.buttonTips[id] || undefined, 
31181                 tabIndex:-1
31182             };
31183         }
31184         
31185         var  F = B.wrap.createChild({
31186                 tag: 'div'
31187             }, B.wrap.dom.firstChild.nextSibling, true);
31188         
31189         
31190         
31191          
31192       
31193  
31194         
31195         var  ty= Roo.form.HtmlEditor.ToolbarContext.types;
31196         this.toolbars = {};
31197            
31198         for (var  i  in   ty) {
31199             this.toolbars[i] = this.buildToolbar(ty[i],i);
31200         }
31201
31202         this.tb = this.toolbars.BODY;
31203         this.tb.el.show();
31204         
31205          
31206         this.rendered = true;
31207         
31208         
31209         B.on('editorevent', this.updateToolbar, this);
31210         
31211         
31212     },
31213     
31214     
31215     
31216     
31217
31218     updateToolbar: function(){
31219
31220         if(!this.editor.activated){
31221             this.editor.onFirstFocus();
31222             return;
31223         }
31224
31225         
31226         var  G = this.editor.getAllAncestors();
31227         
31228         
31229         var  ty= Roo.form.HtmlEditor.ToolbarContext.types;
31230         var  H = G.length ? (G[0] ?  G[0]  : G[1]) : this.editor.doc.body;
31231         H = H ? H : this.editor.doc.body;
31232         H = H.tagName.length ? H : this.editor.doc.body;
31233         var  tn = H.tagName.toUpperCase();
31234         H = typeof(ty[tn]) != 'undefined' ? H : this.editor.doc.body;
31235         tn = H.tagName.toUpperCase();
31236         if (this.tb.name  == tn) {
31237             return; 
31238         }
31239
31240         this.tb.el.hide();
31241         
31242         this.tb =  this.toolbars[tn];
31243         this.tb.el.show();
31244         this.tb.fields.each(function(e) {
31245             e.setValue(H.getAttribute(e.name));
31246         });
31247         this.tb.selectedNode = H;
31248         
31249         
31250         Roo.menu.MenuMgr.hideAll();
31251
31252         
31253     },
31254    
31255        
31256     
31257     onDestroy : function(){
31258         if(this.rendered){
31259             
31260             this.tb.items.each(function(I){
31261                 if(I.menu){
31262                     I.menu.removeAll();
31263                     if(I.menu.el){
31264                         I.menu.el.destroy();
31265                     }
31266                 }
31267
31268                 I.destroy();
31269             });
31270              
31271         }
31272     },
31273     onFirstFocus: function() {
31274         
31275         this.tb.items.each(function(I){
31276            I.enable();
31277         });
31278     },
31279     buildToolbar: function(I, nm)
31280     {
31281         var  J = this.editor;
31282          
31283         var  K = J.wrap.createChild({
31284                 tag: 'div'
31285             }, J.wrap.dom.firstChild.nextSibling, true);
31286         
31287        
31288         var  tb = new  Roo.Toolbar(K);
31289         tb.add(nm+ ":&nbsp;");
31290         for (var  i  in  I) {
31291             var  item = I[i];
31292             tb.add(item.title + ":&nbsp;");
31293             if (item.opts) {
31294                 
31295                 
31296               
31297                 tb.addField( new  Roo.form.ComboBox({
31298                     store: new  Roo.data.SimpleStore({
31299                         id : 'val',
31300                         fields: ['val'],
31301                         data : item.opts 
31302                     }),
31303                     name : i,
31304                     displayField:'val',
31305                     typeAhead: false,
31306                     mode: 'local',
31307                     editable : false,
31308                     triggerAction: 'all',
31309                     emptyText:'Select',
31310                     selectOnFocus:true,
31311                     width: item.width ? item.width  : 130,
31312                     listeners : {
31313                         'select': function(c, r, i) {
31314                             tb.selectedNode.setAttribute(c.name, r.get('val'));
31315                         }
31316                     }
31317
31318                 }));
31319                 continue;
31320                     
31321                 
31322                 
31323                 
31324                 
31325                 tb.addField( new  Roo.form.TextField({
31326                     name: i,
31327                     width: 100,
31328                     
31329                     value: ''
31330                 }));
31331                 continue;
31332             }
31333
31334             tb.addField( new  Roo.form.TextField({
31335                 name: i,
31336                 width: item.width,
31337                 
31338                 value: '',
31339                 listeners: {
31340                     'change' : function(f, nv, ov) {
31341                         tb.selectedNode.setAttribute(f.name, nv);
31342                     }
31343                 }
31344             }));
31345              
31346         }
31347
31348         tb.el.on('click', function(e){
31349             e.preventDefault(); 
31350         });
31351         tb.el.setVisibilityMode( Roo.Element.DISPLAY);
31352         tb.el.hide();
31353         tb.name = nm;
31354         
31355         return  tb;
31356          
31357         
31358     }
31359     
31360     
31361     
31362     
31363 });
31364
31365
31366
31367
31368
31369
31370
31371
31372  
31373
31374
31375 Roo.form.BasicForm = function(el, A){
31376     this.allItems = [];
31377     this.childForms = [];
31378     Roo.apply(this, A);
31379     
31380
31381      
31382      
31383     this.items = new  Roo.util.MixedCollection(false, function(o){
31384         return  o.id || (o.id = Roo.id());
31385     });
31386     this.addEvents({
31387         
31388
31389         beforeaction: true,
31390         
31391
31392         actionfailed : true,
31393         
31394
31395         actioncomplete : true
31396     });
31397     if(el){
31398         this.initEl(el);
31399     }
31400
31401     Roo.form.BasicForm.superclass.constructor.call(this);
31402 };
31403
31404 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
31405     
31406
31407     
31408
31409     
31410
31411     
31412
31413     
31414
31415     
31416
31417     
31418
31419     timeout: 30,
31420
31421     
31422     activeAction : null,
31423
31424     
31425
31426     trackResetOnLoad : false,
31427     
31428     
31429     
31430
31431     childForms : false,
31432     
31433     
31434
31435     allItems : false,
31436     
31437     
31438
31439     waitMsgTarget : undefined,
31440
31441     
31442     initEl : function(el){
31443         this.el = Roo.get(el);
31444         this.id = this.el.id || Roo.id();
31445         this.el.on('submit', this.onSubmit, this);
31446         this.el.addClass('x-form');
31447     },
31448
31449     
31450     onSubmit : function(e){
31451         e.stopEvent();
31452     },
31453
31454     
31455
31456     isValid : function(){
31457         var  B = true;
31458         this.items.each(function(f){
31459            if(!f.validate()){
31460                B = false;
31461            }
31462         });
31463         return  B;
31464     },
31465
31466     
31467
31468     isDirty : function(){
31469         var  C = false;
31470         this.items.each(function(f){
31471            if(f.isDirty()){
31472                C = true;
31473                return  false;
31474            }
31475         });
31476         return  C;
31477     },
31478
31479     
31480
31481     doAction : function(D, E){
31482         if(typeof  D == 'string'){
31483             D = new  Roo.form.Action.ACTION_TYPES[D](this, E);
31484         }
31485         if(this.fireEvent('beforeaction', this, D) !== false){
31486             this.beforeAction(D);
31487             D.run.defer(100, D);
31488         }
31489         return  this;
31490     },
31491
31492     
31493
31494     submit : function(F){
31495         this.doAction('submit', F);
31496         return  this;
31497     },
31498
31499     
31500
31501     load : function(G){
31502         this.doAction('load', G);
31503         return  this;
31504     },
31505
31506     
31507
31508     updateRecord : function(H){
31509         H.beginEdit();
31510         var  fs = H.fields;
31511         fs.each(function(f){
31512             var  I = this.findField(f.name);
31513             if(I){
31514                 H.set(f.name, I.getValue());
31515             }
31516         }, this);
31517         H.endEdit();
31518         return  this;
31519     },
31520
31521     
31522
31523     loadRecord : function(I){
31524         this.setValues(I.data);
31525         return  this;
31526     },
31527
31528     
31529     beforeAction : function(J){
31530         var  o = J.options;
31531         if(o.waitMsg){
31532             if(this.waitMsgTarget === true){
31533                 this.el.mask(o.waitMsg, 'x-mask-loading');
31534             }else  if(this.waitMsgTarget){
31535                 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
31536                 this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
31537             }else {
31538                 Roo.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...');
31539             }
31540         }
31541     },
31542
31543     
31544     afterAction : function(K, L){
31545         this.activeAction = null;
31546         var  o = K.options;
31547         if(o.waitMsg){
31548             if(this.waitMsgTarget === true){
31549                 this.el.unmask();
31550             }else  if(this.waitMsgTarget){
31551                 this.waitMsgTarget.unmask();
31552             }else {
31553                 Roo.MessageBox.updateProgress(1);
31554                 Roo.MessageBox.hide();
31555             }
31556         }
31557         if(L){
31558             if(o.reset){
31559                 this.reset();
31560             }
31561
31562             Roo.callback(o.success, o.scope, [this, K]);
31563             this.fireEvent('actioncomplete', this, K);
31564         }else {
31565             Roo.callback(o.failure, o.scope, [this, K]);
31566             this.fireEvent('actionfailed', this, K);
31567         }
31568     },
31569
31570     
31571
31572     findField : function(id){
31573         var  M = this.items.get(id);
31574         if(!M){
31575             this.items.each(function(f){
31576                 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
31577                     M = f;
31578                     return  false;
31579                 }
31580             });
31581         }
31582         return  M || null;
31583     },
31584
31585     
31586
31587     addForm : function(N){
31588        
31589         this.childForms.push(N);
31590         Roo.each(N.allItems, function (fe) {
31591             
31592             if (this.findField(fe.name)) { 
31593                 return;
31594             }
31595
31596             this.add( new  Roo.form.Hidden({
31597                 name : fe.name
31598             }));
31599         }, this);
31600         
31601     },
31602     
31603
31604     markInvalid : function(O){
31605         if(O  instanceof  Array){
31606             for(var  i = 0, len = O.length; i < len; i++){
31607                 var  fieldError = O[i];
31608                 var  f = this.findField(fieldError.id);
31609                 if(f){
31610                     f.markInvalid(fieldError.msg);
31611                 }
31612             }
31613         }else {
31614             var  M, id;
31615             for(id  in  O){
31616                 if(typeof  O[id] != 'function' && (M = this.findField(id))){
31617                     M.markInvalid(O[id]);
31618                 }
31619             }
31620         }
31621
31622         Roo.each(this.childForms || [], function (f) {
31623             f.markInvalid(O);
31624         });
31625         
31626         return  this;
31627     },
31628
31629     
31630
31631     setValues : function(P){
31632         if(P  instanceof  Array){ 
31633             for(var  i = 0, len = P.length; i < len; i++){
31634                 var  v = P[i];
31635                 var  f = this.findField(v.id);
31636                 if(f){
31637                     f.setValue(v.value);
31638                     if(this.trackResetOnLoad){
31639                         f.originalValue = f.getValue();
31640                     }
31641                 }
31642             }
31643         }else { 
31644             var  M, id;
31645             for(id  in  P){
31646                 if(typeof  P[id] != 'function' && (M = this.findField(id))){
31647                     
31648                     if (M.setFromData && 
31649                         M.valueField && 
31650                         M.displayField &&
31651                         
31652                         
31653                         
31654                         (M.store && !M.store.isLocal)
31655                         ) {
31656                         
31657                         var  sd = { };
31658                         sd[M.valueField] = typeof(P[M.hiddenName]) == 'undefined' ? '' : P[M.hiddenName];
31659                         sd[M.displayField] = typeof(P[M.name]) == 'undefined' ? '' : P[M.name];
31660                         M.setFromData(sd);
31661                         
31662                     } else  {
31663                         M.setValue(P[id]);
31664                     }
31665                     
31666                     
31667                     if(this.trackResetOnLoad){
31668                         M.originalValue = M.getValue();
31669                     }
31670                 }
31671             }
31672         }
31673
31674          
31675         Roo.each(this.childForms || [], function (f) {
31676             f.setValues(P);
31677         });
31678                 
31679         return  this;
31680     },
31681
31682     
31683
31684     getValues : function(Q){
31685         if (this.childForms) {
31686             
31687             Roo.each(this.childForms, function (f) {
31688                 if (f.allFields) {
31689                     Roo.each(f.allFields, function (e) {
31690                         if (e.name && e.getValue && this.findField(e.name)) {
31691                             this.findField(e.name).setValue(e.getValue());
31692                         }
31693                     });
31694                 }
31695             }, this);
31696         }
31697         
31698         
31699         
31700         var  fs = Roo.lib.Ajax.serializeForm(this.el.dom);
31701         if(Q === true){
31702             return  fs;
31703         }
31704         return  Roo.urlDecode(fs);
31705     },
31706
31707     
31708
31709     clearInvalid : function(){
31710         this.items.each(function(f){
31711            f.clearInvalid();
31712         });
31713         
31714         Roo.each(this.childForms || [], function (f) {
31715             f.clearInvalid();
31716         });
31717         
31718         
31719         return  this;
31720     },
31721
31722     
31723
31724     reset : function(){
31725         this.items.each(function(f){
31726             f.reset();
31727         });
31728         
31729         Roo.each(this.childForms || [], function (f) {
31730             f.reset();
31731         });
31732        
31733         
31734         return  this;
31735     },
31736
31737     
31738
31739     add : function(){
31740         this.items.addAll(Array.prototype.slice.call(arguments, 0));
31741         return  this;
31742     },
31743
31744
31745     
31746
31747     remove : function(R){
31748         this.items.remove(R);
31749         return  this;
31750     },
31751
31752     
31753
31754     render : function(){
31755         this.items.each(function(f){
31756             if(f.isFormField && !f.rendered && document.getElementById(f.id)){ 
31757                 f.applyTo(f.id);
31758             }
31759         });
31760         return  this;
31761     },
31762
31763     
31764
31765     applyToFields : function(o){
31766         this.items.each(function(f){
31767            Roo.apply(f, o);
31768         });
31769         return  this;
31770     },
31771
31772     
31773
31774     applyIfToFields : function(o){
31775         this.items.each(function(f){
31776            Roo.applyIf(f, o);
31777         });
31778         return  this;
31779     }
31780 });
31781
31782
31783 Roo.BasicForm = Roo.form.BasicForm;
31784
31785
31786
31787
31788
31789 Roo.form.Form = function(A){
31790     var  B =  [];
31791     if (A.items) {
31792         B = A.items;
31793         delete  A.items;
31794     }
31795
31796    
31797     
31798     Roo.form.Form.superclass.constructor.call(this, null, A);
31799     this.url = this.url || this.action;
31800     if(!this.root){
31801         this.root = new  Roo.form.Layout(Roo.applyIf({
31802             id: Roo.id()
31803         }, A));
31804     }
31805
31806     this.active = this.root;
31807     
31808
31809     this.buttons = [];
31810     this.allItems = [];
31811     this.addEvents({
31812         
31813
31814         clientvalidation: true,
31815         
31816
31817         rendered : true
31818     });
31819     
31820     Roo.each(B, this.addxtype, this);
31821     
31822     
31823     
31824 };
31825
31826 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
31827     
31828
31829     
31830
31831     
31832
31833     buttonAlign:'center',
31834
31835     
31836
31837     minButtonWidth:75,
31838
31839     
31840
31841     labelAlign:'left',
31842
31843     
31844
31845     monitorValid : false,
31846
31847     
31848
31849     monitorPoll : 200,
31850
31851   
31852     
31853
31854     column : function(c){
31855         var  C = new  Roo.form.Column(c);
31856         this.start(C);
31857         if(arguments.length > 1){ 
31858             this.add.apply(this, Array.prototype.slice.call(arguments, 1));
31859             this.end();
31860         }
31861         return  C;
31862     },
31863
31864     
31865
31866     fieldset : function(c){
31867         var  fs = new  Roo.form.FieldSet(c);
31868         this.start(fs);
31869         if(arguments.length > 1){ 
31870             this.add.apply(this, Array.prototype.slice.call(arguments, 1));
31871             this.end();
31872         }
31873         return  fs;
31874     },
31875
31876     
31877
31878     container : function(c){
31879         var  l = new  Roo.form.Layout(c);
31880         this.start(l);
31881         if(arguments.length > 1){ 
31882             this.add.apply(this, Array.prototype.slice.call(arguments, 1));
31883             this.end();
31884         }
31885         return  l;
31886     },
31887
31888     
31889
31890     start : function(c){
31891         
31892         Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
31893         this.active.stack.push(c);
31894         c.ownerCt = this.active;
31895         this.active = c;
31896         return  this;
31897     },
31898
31899     
31900
31901     end : function(){
31902         if(this.active == this.root){
31903             return  this;
31904         }
31905
31906         this.active = this.active.ownerCt;
31907         return  this;
31908     },
31909
31910     
31911
31912     add : function(){
31913         this.active.stack.push.apply(this.active.stack, arguments);
31914         this.allItems.push.apply(this.allItems,arguments);
31915         var  r = [];
31916         for(var  i = 0, a = arguments, len = a.length; i < len; i++) {
31917             if(a[i].isFormField){
31918                 r.push(a[i]);
31919             }
31920         }
31921         if(r.length > 0){
31922             Roo.form.Form.superclass.add.apply(this, r);
31923         }
31924         return  this;
31925     },
31926     
31927
31928     
31929     
31930     
31931      
31932
31933     findbyId : function(id)
31934     {
31935         var  D = false;
31936         if (!id) {
31937             return  D;
31938         }
31939
31940         Ext.each(this.allItems, function(f){
31941             if (f.id == id || f.name == id ){
31942                 D = f;
31943                 return  false;
31944             }
31945         });
31946         return  D;
31947     },
31948
31949     
31950     
31951     
31952
31953     render : function(ct){
31954         ct = Roo.get(ct);
31955         var  o = this.autoCreate || {
31956             tag: 'form',
31957             method : this.method || 'POST',
31958             id : this.id || Roo.id()
31959         };
31960         this.initEl(ct.createChild(o));
31961
31962         this.root.render(this.el);
31963
31964         this.items.each(function(f){
31965             f.render('x-form-el-'+f.id);
31966         });
31967
31968         if(this.buttons.length > 0){
31969             
31970             var  tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
31971                 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
31972                 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
31973             }}, null, true);
31974             var  tr = tb.getElementsByTagName('tr')[0];
31975             for(var  i = 0, len = this.buttons.length; i < len; i++) {
31976                 var  b = this.buttons[i];
31977                 var  td = document.createElement('td');
31978                 td.className = 'x-form-btn-td';
31979                 b.render(tr.appendChild(td));
31980             }
31981         }
31982         if(this.monitorValid){ 
31983             this.startMonitoring();
31984         }
31985
31986         this.fireEvent('rendered', this);
31987         return  this;
31988     },
31989
31990     
31991
31992     addButton : function(E, F, G){
31993         var  bc = {
31994             handler: F,
31995             scope: G,
31996             minWidth: this.minButtonWidth,
31997             hideParent:true
31998         };
31999         if(typeof  E == "string"){
32000             bc.text = E;
32001         }else {
32002             Roo.apply(bc, E);
32003         }
32004         var  H = new  Roo.Button(null, bc);
32005         this.buttons.push(H);
32006         return  H;
32007     },
32008
32009      
32010
32011     
32012     addxtype : function()
32013     {
32014         var  ar = Array.prototype.slice.call(arguments, 0);
32015         var  I = false;
32016         for(var  i = 0; i < ar.length; i++) {
32017             if (!ar[i]) {
32018                 continue; 
32019                 
32020                 
32021             }
32022             
32023             if (Roo.form[ar[i].xtype]) {
32024                 ar[i].form = this;
32025                 var  fe = Roo.factory(ar[i], Roo.form);
32026                 if (!I) {
32027                     I = fe;
32028                 }
32029
32030                 fe.form = this;
32031                 if (fe.store) {
32032                     fe.store.form = this;
32033                 }
32034                 if (fe.isLayout) {  
32035                          
32036                     this.start(fe);
32037                     this.allItems.push(fe);
32038                     if (fe.items && fe.addxtype) {
32039                         fe.addxtype.apply(fe, fe.items);
32040                         delete  fe.items;
32041                     }
32042
32043                      this.end();
32044                     continue;
32045                 }
32046
32047                 
32048                 
32049                  
32050                 this.add(fe);
32051               
32052             }
32053             if (ar[i].xtype == 'Button') {  
32054                 
32055                 
32056                 this.addButton(ar[i]);
32057                 this.allItems.push(fe);
32058                 continue;
32059             }
32060             
32061             if (ar[i].xtype == 'end') { 
32062                 alert('end is not supported on xtype any more, use items');
32063             
32064             
32065             }
32066             
32067         }
32068         return  I;
32069     },
32070     
32071     
32072
32073     startMonitoring : function(){
32074         if(!this.bound){
32075             this.bound = true;
32076             Roo.TaskMgr.start({
32077                 run : this.bindHandler,
32078                 interval : this.monitorPoll || 200,
32079                 scope: this
32080             });
32081         }
32082     },
32083
32084     
32085
32086     stopMonitoring : function(){
32087         this.bound = false;
32088     },
32089
32090     
32091     bindHandler : function(){
32092         if(!this.bound){
32093             return  false; 
32094         }
32095         var  J = true;
32096         this.items.each(function(f){
32097             if(!f.isValid(true)){
32098                 J = false;
32099                 return  false;
32100             }
32101         });
32102         for(var  i = 0, len = this.buttons.length; i < len; i++){
32103             var  H = this.buttons[i];
32104             if(H.formBind === true && H.disabled === J){
32105                 H.setDisabled(!J);
32106             }
32107         }
32108
32109         this.fireEvent('clientvalidation', this, J);
32110     }
32111     
32112     
32113     
32114     
32115     
32116     
32117     
32118     
32119 });
32120
32121
32122
32123 Roo.Form = Roo.form.Form;
32124
32125
32126
32127  
32128  
32129
32130  
32131  
32132
32133 Roo.form.Action = function(A, B){
32134     this.form = A;
32135     this.options = B || {};
32136 };
32137
32138
32139 Roo.form.Action.CLIENT_INVALID = 'client';
32140
32141
32142  Roo.form.Action.SERVER_INVALID = 'server';
32143  
32144
32145 Roo.form.Action.CONNECT_FAILURE = 'connect';
32146
32147
32148 Roo.form.Action.LOAD_FAILURE = 'load';
32149
32150 Roo.form.Action.prototype = {
32151     type : 'default',
32152     failureType : undefined,
32153     response : undefined,
32154     result : undefined,
32155
32156     
32157     run : function(C){
32158
32159     },
32160
32161     
32162     success : function(D){
32163
32164     },
32165
32166     
32167     handleResponse : function(E){
32168
32169     },
32170
32171     
32172     failure : function(F){
32173         this.response = F;
32174         this.failureType = Roo.form.Action.CONNECT_FAILURE;
32175         this.form.afterAction(this, false);
32176     },
32177
32178     processResponse : function(G){
32179         this.response = G;
32180         if(!G.responseText){
32181             return  true;
32182         }
32183
32184         this.result = this.handleResponse(G);
32185         return  this.result;
32186     },
32187
32188     
32189     getUrl : function(H){
32190         var  I = this.options.url || this.form.url || this.form.el.dom.action;
32191         if(H){
32192             var  p = this.getParams();
32193             if(p){
32194                 I += (I.indexOf('?') != -1 ? '&' : '?') + p;
32195             }
32196         }
32197         return  I;
32198     },
32199
32200     getMethod : function(){
32201         return  (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
32202     },
32203
32204     getParams : function(){
32205         var  bp = this.form.baseParams;
32206         var  p = this.options.params;
32207         if(p){
32208             if(typeof  p == "object"){
32209                 p = Roo.urlEncode(Roo.applyIf(p, bp));
32210             }else  if(typeof  p == 'string' && bp){
32211                 p += '&' + Roo.urlEncode(bp);
32212             }
32213         }else  if(bp){
32214             p = Roo.urlEncode(bp);
32215         }
32216         return  p;
32217     },
32218
32219     createCallback : function(){
32220         return  {
32221             success: this.success,
32222             failure: this.failure,
32223             scope: this,
32224             timeout: (this.form.timeout*1000),
32225             upload: this.form.fileUpload ? this.success : undefined
32226         };
32227     }
32228 };
32229
32230 Roo.form.Action.Submit = function(J, K){
32231     Roo.form.Action.Submit.superclass.constructor.call(this, J, K);
32232 };
32233
32234 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
32235     type : 'submit',
32236
32237     run : function(){
32238         var  o = this.options;
32239         var  L = this.getMethod();
32240         var  M = L == 'POST';
32241         if(o.clientValidation === false || this.form.isValid()){
32242             Roo.Ajax.request(Roo.apply(this.createCallback(), {
32243                 form:this.form.el.dom,
32244                 url:this.getUrl(!M),
32245                 method: L,
32246                 params:M ? this.getParams() : null,
32247                 isUpload: this.form.fileUpload
32248             }));
32249
32250         }else  if (o.clientValidation !== false){ 
32251             this.failureType = Roo.form.Action.CLIENT_INVALID;
32252             this.form.afterAction(this, false);
32253         }
32254     },
32255
32256     success : function(N){
32257         var  O = this.processResponse(N);
32258         if(O === true || O.success){
32259             this.form.afterAction(this, true);
32260             return;
32261         }
32262         if(O.errors){
32263             this.form.markInvalid(O.errors);
32264             this.failureType = Roo.form.Action.SERVER_INVALID;
32265         }
32266
32267         this.form.afterAction(this, false);
32268     },
32269
32270     handleResponse : function(P){
32271         if(this.form.errorReader){
32272             var  rs = this.form.errorReader.read(P);
32273             var  errors = [];
32274             if(rs.records){
32275                 for(var  i = 0, len = rs.records.length; i < len; i++) {
32276                     var  r = rs.records[i];
32277                     errors[i] = r.data;
32278                 }
32279             }
32280             if(errors.length < 1){
32281                 errors = null;
32282             }
32283             return  {
32284                 success : rs.success,
32285                 errors : errors
32286             };
32287         }
32288         var  Q = false;
32289         try {
32290             Q = Roo.decode(P.responseText);
32291         } catch (e) {
32292             ret = {
32293                 success: false,
32294                 errorMsg: "Failed to read server message: " + response.responseText,
32295                 errors : []
32296             };
32297         }
32298         return  Q;
32299         
32300     }
32301 });
32302
32303
32304 Roo.form.Action.Load = function(R, S){
32305     Roo.form.Action.Load.superclass.constructor.call(this, R, S);
32306     this.reader = this.form.reader;
32307 };
32308
32309 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
32310     type : 'load',
32311
32312     run : function(){
32313         Roo.Ajax.request(Roo.apply(
32314                 this.createCallback(), {
32315                     method:this.getMethod(),
32316                     url:this.getUrl(false),
32317                     params:this.getParams()
32318         }));
32319     },
32320
32321     success : function(T){
32322         var  U = this.processResponse(T);
32323         if(U === true || !U.success || !U.data){
32324             this.failureType = Roo.form.Action.LOAD_FAILURE;
32325             this.form.afterAction(this, false);
32326             return;
32327         }
32328
32329         this.form.clearInvalid();
32330         this.form.setValues(U.data);
32331         this.form.afterAction(this, true);
32332     },
32333
32334     handleResponse : function(V){
32335         if(this.form.reader){
32336             var  rs = this.form.reader.read(V);
32337             var  data = rs.records && rs.records[0] ? rs.records[0].data : null;
32338             return  {
32339                 success : rs.success,
32340                 data : data
32341             };
32342         }
32343         return  Roo.decode(V.responseText);
32344     }
32345 });
32346
32347 Roo.form.Action.ACTION_TYPES = {
32348     'load' : Roo.form.Action.Load,
32349     'submit' : Roo.form.Action.Submit
32350 };
32351
32352
32353  
32354
32355
32356 Roo.form.Layout = function(A){
32357     var  B = [];
32358     if (A.items) {
32359         B = A.items;
32360         delete  A.items;
32361     }
32362
32363     Roo.form.Layout.superclass.constructor.call(this, A);
32364     this.stack = [];
32365     Roo.each(B, this.addxtype, this);
32366      
32367 };
32368
32369 Roo.extend(Roo.form.Layout, Roo.Component, {
32370     
32371
32372     
32373
32374     
32375
32376     
32377
32378     
32379
32380     clear : true,
32381     
32382
32383     labelSeparator : ':',
32384     
32385
32386     hideLabels : false,
32387
32388     
32389     defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
32390     
32391     isLayout : true,
32392     
32393     
32394     onRender : function(ct, C){
32395         if(this.el){ 
32396             this.el = Roo.get(this.el);
32397         }else  {  
32398             var  cfg = this.getAutoCreate();
32399             this.el = ct.createChild(cfg, C);
32400         }
32401         if(this.style){
32402             this.el.applyStyles(this.style);
32403         }
32404         if(this.labelAlign){
32405             this.el.addClass('x-form-label-'+this.labelAlign);
32406         }
32407         if(this.hideLabels){
32408             this.labelStyle = "display:none";
32409             this.elementStyle = "padding-left:0;";
32410         }else {
32411             if(typeof  this.labelWidth == 'number'){
32412                 this.labelStyle = "width:"+this.labelWidth+"px;";
32413                 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof  this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
32414             }
32415             if(this.labelAlign == 'top'){
32416                 this.labelStyle = "width:auto;";
32417                 this.elementStyle = "padding-left:0;";
32418             }
32419         }
32420         var  D = this.stack;
32421         var  E = D.length;
32422         if(E > 0){
32423             if(!this.fieldTpl){
32424                 var  t = new  Roo.Template(
32425                     '<div class="x-form-item {5}">',
32426                         '<label for="{0}" style="{2}">{1}{4}</label>',
32427                         '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
32428                         '</div>',
32429                     '</div><div class="x-form-clear-left"></div>'
32430                 );
32431                 t.disableFormats = true;
32432                 t.compile();
32433                 Roo.form.Layout.prototype.fieldTpl = t;
32434             }
32435             for(var  i = 0; i < E; i++) {
32436                 if(D[i].isFormField){
32437                     this.renderField(D[i]);
32438                 }else {
32439                     this.renderComponent(D[i]);
32440                 }
32441             }
32442         }
32443         if(this.clear){
32444             this.el.createChild({cls:'x-form-clear'});
32445         }
32446     },
32447
32448     
32449     renderField : function(f){
32450         f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
32451                f.id, 
32452                f.fieldLabel, 
32453                f.labelStyle||this.labelStyle||'', 
32454                this.elementStyle||'', 
32455                typeof  f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, 
32456                f.itemCls||this.itemCls||''  
32457        ], true).getPrevSibling());
32458     },
32459
32460     
32461     renderComponent : function(c){
32462         c.render(c.isLayout ? this.el : this.el.createChild());    
32463     },
32464     
32465
32466     addxtype : function(o)
32467     {
32468         
32469         o.form = this.form;
32470         var  fe = Roo.factory(o, Roo.form);
32471         this.form.allItems.push(fe);
32472         this.stack.push(fe);
32473         
32474         if (fe.isFormField) {
32475             this.form.items.add(fe);
32476         }
32477          
32478         return  fe;
32479     }
32480 });
32481
32482
32483
32484 Roo.form.Column = function(F){
32485     Roo.form.Column.superclass.constructor.call(this, F);
32486 };
32487
32488 Roo.extend(Roo.form.Column, Roo.form.Layout, {
32489     
32490
32491     
32492
32493
32494     
32495     defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
32496
32497     
32498     onRender : function(ct, G){
32499         Roo.form.Column.superclass.onRender.call(this, ct, G);
32500         if(this.width){
32501             this.el.setWidth(this.width);
32502         }
32503     }
32504 });
32505
32506
32507
32508
32509
32510  
32511 Roo.form.Row = function(H){
32512     Roo.form.Row.superclass.constructor.call(this, H);
32513 };
32514  
32515 Roo.extend(Roo.form.Row, Roo.form.Layout, {
32516       
32517
32518     
32519
32520     defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
32521     
32522     padWidth : 20,
32523     
32524     onRender : function(ct, I){
32525         
32526         if(!this.rowTpl){
32527             var  t = new  Roo.Template(
32528                 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
32529                     '<label for="{0}" style="{2}">{1}{4}</label>',
32530                     '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
32531                     '</div>',
32532                 '</div>'
32533             );
32534             t.disableFormats = true;
32535             t.compile();
32536             Roo.form.Layout.prototype.rowTpl = t;
32537         }
32538
32539         this.fieldTpl = this.rowTpl;
32540         
32541         
32542         var  J = 100;
32543         
32544         if ((this.labelAlign != 'top')) {
32545             if (typeof  this.labelWidth == 'number') {
32546                 J = this.labelWidth
32547             }
32548
32549             this.padWidth =  20 + J;
32550             
32551         }
32552
32553         
32554         Roo.form.Column.superclass.onRender.call(this, ct, I);
32555         if(this.width){
32556             this.el.setWidth(this.width);
32557         }
32558         if(this.height){
32559             this.el.setHeight(this.height);
32560         }
32561     },
32562     
32563     
32564     renderField : function(f){
32565         f.fieldEl = this.fieldTpl.append(this.el, [
32566                f.id, f.fieldLabel,
32567                f.labelStyle||this.labelStyle||'',
32568                this.elementStyle||'',
32569                typeof  f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
32570                f.itemCls||this.itemCls||'',
32571                f.width ? f.width + this.padWidth : 160 + this.padWidth
32572        ],true);
32573     }
32574 });
32575  
32576
32577
32578
32579 Roo.form.FieldSet = function(K){
32580     Roo.form.FieldSet.superclass.constructor.call(this, K);
32581 };
32582
32583 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
32584     
32585
32586     
32587
32588
32589     
32590     defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
32591
32592     
32593     onRender : function(ct, L){
32594         Roo.form.FieldSet.superclass.onRender.call(this, ct, L);
32595         if(this.legend){
32596             this.setLegend(this.legend);
32597         }
32598     },
32599
32600     
32601     setLegend : function(M){
32602         if(this.rendered){
32603             this.el.child('legend').update(M);
32604         }
32605     }
32606 });
32607
32608
32609
32610
32611 Roo.form.VTypes = function(){
32612     
32613     var  A = /^[a-zA-Z_]+$/;
32614     var  B = /^[a-zA-Z0-9_]+$/;
32615     var  C = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
32616     var  D = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
32617
32618     
32619     return  {
32620         
32621
32622         'email' : function(v){
32623             return  C.test(v);
32624         },
32625         
32626
32627         'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
32628         
32629
32630         'emailMask' : /[a-z0-9_\.\-@]/i,
32631
32632         
32633
32634         'url' : function(v){
32635             return  D.test(v);
32636         },
32637         
32638
32639         'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
32640         
32641         
32642
32643         'alpha' : function(v){
32644             return  A.test(v);
32645         },
32646         
32647
32648         'alphaText' : 'This field should only contain letters and _',
32649         
32650
32651         'alphaMask' : /[a-z_]/i,
32652
32653         
32654
32655         'alphanum' : function(v){
32656             return  B.test(v);
32657         },
32658         
32659
32660         'alphanumText' : 'This field should only contain letters, numbers and _',
32661         
32662
32663         'alphanumMask' : /[a-z0-9_]/i
32664     };
32665 }();
32666
32667
32668
32669
32670 Roo.form.FCKeditor = function(A){
32671     Roo.form.FCKeditor.superclass.constructor.call(this, A);
32672     this.addEvents({
32673          
32674
32675         editorinit : true
32676     });
32677     
32678     
32679 };
32680 Roo.form.FCKeditor.editors = { };
32681 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
32682 {
32683     
32684     
32685     
32686     
32687     
32688
32689     fckconfig : false,
32690     
32691     
32692
32693     toolbarSet : 'Basic',
32694     
32695  
32696     basePath : '/fckeditor/',
32697     
32698     
32699     frame : false,
32700     
32701     value : '',
32702     
32703    
32704     onRender : function(ct, B)
32705     {
32706         if(!this.el){
32707             this.defaultAutoCreate = {
32708                 tag: "textarea",
32709                 style:"width:300px;height:60px;",
32710                 autocomplete: "off"
32711             };
32712         }
32713
32714         Roo.form.FCKeditor.superclass.onRender.call(this, ct, B);
32715         
32716
32717         
32718         Roo.form.FCKeditor.editors[this.getId()] = this;
32719          
32720
32721         this.replaceTextarea() ;
32722         
32723     },
32724     
32725     getEditor : function() {
32726         return  this.fckEditor;
32727     },
32728     
32729
32730     
32731     
32732     setValue : function(C)
32733     {
32734         
32735         
32736         if(typeof(C) == 'undefined') { 
32737             return;
32738         }
32739
32740         Roo.form.FCKeditor.superclass.setValue.apply(this,[C]);
32741         
32742         
32743         
32744             
32745         
32746         
32747         
32748         if(!this.getEditor()) {
32749             return;
32750         }
32751
32752         
32753         this.getEditor().SetData(C);
32754         
32755         
32756
32757     },
32758
32759     
32760
32761     getValue : function()
32762     {
32763         
32764         if (this.frame && this.frame.dom.style.display == 'none') {
32765             return  Roo.form.FCKeditor.superclass.getValue.call(this);
32766         }
32767         
32768         if(!this.el || !this.getEditor()) {
32769            
32770            
32771             return  this.value;
32772         }
32773        
32774         
32775         var  D=this.getEditor().GetData();
32776         Roo.form.FCKeditor.superclass.setValue.apply(this,[D]);
32777         return  Roo.form.FCKeditor.superclass.getValue.call(this);
32778         
32779
32780     },
32781
32782     
32783
32784     getRawValue : function()
32785     {
32786         if (this.frame && this.frame.dom.style.display == 'none') {
32787             return  Roo.form.FCKeditor.superclass.getRawValue.call(this);
32788         }
32789         
32790         if(!this.el || !this.getEditor()) {
32791             
32792             return  this.value;
32793             return;
32794         }
32795         
32796         
32797         
32798         var  E=this.getEditor().GetData();
32799         Roo.form.FCKeditor.superclass.setRawValue.apply(this,[E]);
32800         return  Roo.form.FCKeditor.superclass.getRawValue.call(this);
32801          
32802     },
32803     
32804     setSize : function(w,h) {
32805         
32806         
32807         
32808         
32809         
32810         
32811         
32812         
32813         
32814         
32815         
32816         
32817         
32818         
32819         Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
32820         
32821         this.frame.dom.setAttribute('width', w);
32822         this.frame.dom.setAttribute('height', h);
32823         this.frame.setSize(w,h);
32824         
32825     },
32826     
32827     toggleSourceEdit : function(F) {
32828         
32829       
32830          
32831         this.el.dom.style.display = F ? '' : 'none';
32832         this.frame.dom.style.display = F ?  'none' : '';
32833         
32834     },
32835     
32836     
32837     focus: function(G)
32838     {
32839         if (this.frame.dom.style.display == 'none') {
32840             return  Roo.form.FCKeditor.superclass.focus.call(this);
32841         }
32842         if(!this.el || !this.getEditor()) {
32843             this.focus.defer(100,this, [G]); 
32844             return;
32845         }
32846         
32847         
32848         
32849         
32850         var  H = this.getEditor().EditorDocument.getElementsByTagName(G);
32851         this.getEditor().Focus();
32852         if (H.length) {
32853             if (!this.getEditor().Selection.GetSelection()) {
32854                 this.focus.defer(100,this, [G]); 
32855                 return;
32856             }
32857             
32858             
32859             var  r = this.getEditor().EditorDocument.createRange();
32860             r.setStart(H[0],0);
32861             r.setEnd(H[0],0);
32862             this.getEditor().Selection.GetSelection().removeAllRanges();
32863             this.getEditor().Selection.GetSelection().addRange(r);
32864             this.getEditor().Focus();
32865         }
32866         
32867     },
32868     
32869     
32870     
32871     replaceTextarea : function()
32872     {
32873         if ( document.getElementById( this.getId() + '___Frame' ) )
32874             return ;
32875         
32876         
32877             
32878         var  I = document.getElementById( this.getId() );
32879         
32880         var  J = document.getElementsByName( this.getId() ) ;
32881          
32882         I.style.display = 'none' ;
32883
32884         if ( I.tabIndex ) {            
32885             this.TabIndex = I.tabIndex ;
32886         }
32887
32888         
32889         this._insertHtmlBefore( this._getConfigHtml(), I ) ;
32890         this._insertHtmlBefore( this._getIFrameHtml(), I ) ;
32891         this.frame = Roo.get(this.getId() + '___Frame')
32892     },
32893     
32894     _getConfigHtml : function()
32895     {
32896         var  K = '' ;
32897
32898         for ( var  o  in  this.fckconfig ) {
32899             K += K.length > 0  ? '&amp;' : '';
32900             K += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
32901         }
32902
32903         return  '<input type="hidden" id="' + this.getId() + '___Config" value="' + K + '" style="display:none" />' ;
32904     },
32905     
32906     
32907     _getIFrameHtml : function()
32908     {
32909         var  L = 'fckeditor.html' ;
32910         
32911
32912
32913         var  M = this.basePath + 'editor/' + L + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
32914         M += this.toolbarSet ? ( '&amp;Toolbar=' + this.toolbarSet)  : '';
32915         
32916         
32917         var  N = '<iframe id="' + this.getId() +
32918             '___Frame" src="' + M +
32919             '" width="' + this.width +
32920             '" height="' + this.height + '"' +
32921             (this.tabIndex ?  ' tabindex="' + this.tabIndex + '"' :'' ) +
32922             ' frameborder="0" scrolling="no"></iframe>' ;
32923
32924         return  N ;
32925     },
32926     
32927     _insertHtmlBefore : function( O, P )
32928     {
32929         if ( P.insertAdjacentHTML )     {
32930             
32931             P.insertAdjacentHTML( 'beforeBegin', O ) ;
32932         } else  { 
32933             var  oRange = document.createRange() ;
32934             oRange.setStartBefore( P ) ;
32935             var  oFragment = oRange.createContextualFragment( O );
32936             P.parentNode.insertBefore( oFragment, P ) ;
32937         }
32938     }
32939     
32940     
32941   
32942     
32943     
32944     
32945     
32946
32947 });
32948
32949
32950
32951 function  Q(R){
32952     var  f = Roo.form.FCKeditor.editors[R.Name];
32953     f.fckEditor = R;
32954     
32955     f.fireEvent('editorinit', f, R);
32956
32957   
32958
32959  
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979 Roo.form.GridField = function(A){
32980     Roo.form.GridField.superclass.constructor.call(this, A);
32981      
32982 };
32983
32984 Roo.extend(Roo.form.GridField, Roo.form.Field,  {
32985     
32986
32987     width : 100,
32988     
32989
32990     height : 50,
32991      
32992
32993     xgrid : false, 
32994     
32995
32996    
32997     defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
32998     
32999
33000     addTitle : false,
33001     
33002     onResize : function(){
33003         Roo.form.Field.superclass.onResize.apply(this, arguments);
33004     },
33005
33006     initEvents : function(){
33007         
33008         
33009        
33010     },
33011
33012
33013     getResizeEl : function(){
33014         return  this.wrap;
33015     },
33016
33017     getPositionEl : function(){
33018         return  this.wrap;
33019     },
33020
33021     
33022     onRender : function(ct, B){
33023         
33024         this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
33025         var  C = this.style;
33026         delete  this.style;
33027         
33028         Roo.form.DisplayImage.superclass.onRender.call(this, ct, B);
33029         this.wrap = this.el.wrap({cls: ''}); 
33030         this.viewEl = this.wrap.createChild({ tag: 'div' });
33031         if (C) {
33032             this.viewEl.applyStyles(C);
33033         }
33034         if (this.width) {
33035             this.viewEl.setWidth(this.width);
33036         }
33037         if (this.height) {
33038             this.viewEl.setHeight(this.height);
33039         }
33040
33041         
33042         
33043         
33044         
33045         this.grid = new  Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
33046         
33047         
33048         this.grid.render();
33049         this.grid.getDataSource().on('remove', this.refreshValue, this);
33050         this.grid.getDataSource().on('update', this.refreshValue, this);
33051         this.grid.on('afteredit', this.refreshValue, this);
33052  
33053     },
33054      
33055     
33056     
33057
33058     setValue : function(v){
33059         
33060         v = v || []; 
33061         
33062         if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
33063             var  ds = this.grid.getDataSource();
33064             
33065             var  data = {}
33066
33067             data[ds.reader.meta.root ] =  typeof(v) == 'string' ? Roo.decode(v) : v;
33068             ds.loadData( data);
33069         }
33070
33071         Roo.form.GridField.superclass.setValue.call(this, v);
33072         this.refreshValue();
33073         
33074     },
33075     
33076     
33077     refreshValue: function() {
33078          var  D = [];
33079         this.grid.getDataSource().each(function(r) {
33080             D.push(r.data);
33081         });
33082         this.el.dom.value = Roo.encode(D);
33083     }
33084     
33085      
33086     
33087     
33088 });
33089
33090  
33091
33092
33093
33094  
33095 Roo.DDView = function(A, B, C) {
33096     Roo.DDView.superclass.constructor.apply(this, arguments);
33097     this.getEl().setStyle("outline", "0px none");
33098     this.getEl().unselectable();
33099     if (this.dragGroup) {
33100                 this.setDraggable(this.dragGroup.split(","));
33101     }
33102     if (this.dropGroup) {
33103                 this.setDroppable(this.dropGroup.split(","));
33104     }
33105     if (this.deletable) {
33106         this.setDeletable();
33107     }
33108
33109     this.isDirtyFlag = false;
33110         this.addEvents({
33111                 "drop" : true
33112         });
33113 };
33114
33115 Roo.extend(Roo.DDView, Roo.View, {
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125         isFormField: true,
33126
33127         reset: Roo.emptyFn,
33128         
33129         clearInvalid: Roo.form.Field.prototype.clearInvalid,
33130
33131         validate: function() {
33132                 return  true;
33133         },
33134         
33135         destroy: function() {
33136                 this.purgeListeners();
33137                 this.getEl.removeAllListeners();
33138                 this.getEl().remove();
33139                 if (this.dragZone) {
33140                         if (this.dragZone.destroy) {
33141                                 this.dragZone.destroy();
33142                         }
33143                 }
33144                 if (this.dropZone) {
33145                         if (this.dropZone.destroy) {
33146                                 this.dropZone.destroy();
33147                         }
33148                 }
33149         },
33150
33151
33152
33153         getName: function() {
33154                 return  this.name;
33155         },
33156
33157
33158
33159         setValue: function(v) {
33160                 if (!this.store) {
33161                         throw  "DDView.setValue(). DDView must be constructed with a valid Store";
33162                 }
33163                 var  D = {};
33164                 D[this.store.reader.meta.root] = v ? [].concat(v) : [];
33165                 this.store.proxy = new  Roo.data.MemoryProxy(D);
33166                 this.store.load();
33167         },
33168
33169
33170
33171         getValue: function() {
33172                 var  E = '(';
33173                 this.store.each(function(F) {
33174                         E += F.id + ',';
33175                 });
33176                 return  E.substr(0, E.length - 1) + ')';
33177         },
33178         
33179         getIds: function() {
33180                 var  i = 0, F = new  Array(this.store.getCount());
33181                 this.store.each(function(G) {
33182                         F[i++] = G.id;
33183                 });
33184                 return  F;
33185         },
33186         
33187         isDirty: function() {
33188                 return  this.isDirtyFlag;
33189         },
33190
33191
33192
33193     getTargetFromEvent : function(e) {
33194                 var  G = e.getTarget();
33195                 while ((G !== null) && (G.parentNode != this.el.dom)) {
33196                 G = G.parentNode;
33197                 }
33198                 if (!G) {
33199                         G = this.el.dom.lastChild || this.el.dom;
33200                 }
33201                 return  G;
33202     },
33203
33204
33205
33206     getDragData : function(e) {
33207         var  H = this.findItemFromChild(e.getTarget());
33208                 if(H) {
33209                         this.handleSelection(e);
33210                         var  selNodes = this.getSelectedNodes();
33211             var  dragData = {
33212                 source: this,
33213                 copy: this.copy || (this.allowCopy && e.ctrlKey),
33214                 nodes: selNodes,
33215                 records: []
33216                         };
33217                         var  selectedIndices = this.getSelectedIndexes();
33218                         for (var  i = 0; i < selectedIndices.length; i++) {
33219                                 dragData.records.push(this.store.getAt(selectedIndices[i]));
33220                         }
33221                         if (selNodes.length == 1) {
33222                                 dragData.ddel = H.cloneNode(true);      
33223                         } else  {
33224                                 var  div = document.createElement('div'); 
33225                                 div.className = 'multi-proxy';
33226                                 for (var  i = 0, len = selNodes.length; i < len; i++) {
33227                                         div.appendChild(selNodes[i].cloneNode(true));
33228                                 }
33229
33230                                 dragData.ddel = div;
33231                         }
33232             
33233             
33234                         return  dragData;
33235                 }
33236         
33237                 return  false;
33238     },
33239     
33240
33241
33242     setDraggable: function(I) {
33243         if (I  instanceof  Array) {
33244                 Roo.each(I, this.setDraggable, this);
33245                 return;
33246         }
33247         if (this.dragZone) {
33248                 this.dragZone.addToGroup(I);
33249         } else  {
33250                         this.dragZone = new  Roo.dd.DragZone(this.getEl(), {
33251                                 containerScroll: true,
33252                                 ddGroup: I 
33253
33254                         });
33255
33256                         if (!this.multiSelect) { this.singleSelect = true; }
33257
33258
33259
33260                         this.dragZone.getDragData = this.getDragData.createDelegate(this);
33261                 }
33262     },
33263
33264
33265
33266     setDroppable: function(J) {
33267         if (J  instanceof  Array) {
33268                 Roo.each(J, this.setDroppable, this);
33269                 return;
33270         }
33271         if (this.dropZone) {
33272                 this.dropZone.addToGroup(J);
33273         } else  {
33274                         this.dropZone = new  Roo.dd.DropZone(this.getEl(), {
33275                                 containerScroll: true,
33276                                 ddGroup: J
33277                         });
33278
33279
33280                         this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
33281                         this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
33282                         this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
33283                         this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
33284                         this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
33285                 }
33286     },
33287
33288
33289
33290     getDropPoint : function(e, n, dd){
33291         if (n == this.el.dom) { return  "above"; }
33292                 var  t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
33293                 var  c = t + (b - t) / 2;
33294                 var  y = Roo.lib.Event.getPageY(e);
33295                 if(y <= c) {
33296                         return  "above";
33297                 }else {
33298                         return  "below";
33299                 }
33300     },
33301
33302     onNodeEnter : function(n, dd, e, K){
33303                 return  false;
33304     },
33305     
33306     onNodeOver : function(n, dd, e, L){
33307                 var  pt = this.getDropPoint(e, n, dd);
33308                 
33309                 var  M = this.dropNotAllowed;
33310                 if (pt) {
33311                         var  targetElClass;
33312                         if (pt == "above"){
33313                                 M = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
33314                                 targetElClass = "x-view-drag-insert-above";
33315                         } else  {
33316                                 M = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
33317                                 targetElClass = "x-view-drag-insert-below";
33318                         }
33319                         if (this.lastInsertClass != targetElClass){
33320                                 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
33321                                 this.lastInsertClass = targetElClass;
33322                         }
33323                 }
33324                 return  M;
33325         },
33326
33327     onNodeOut : function(n, dd, e, N){
33328                 this.removeDropIndicators(n);
33329     },
33330
33331     onNodeDrop : function(n, dd, e, O){
33332         if (this.fireEvent("drop", this, n, dd, e, O) === false) {
33333                 return  false;
33334         }
33335         var  pt = this.getDropPoint(e, n, dd);
33336                 var  P = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
33337                 if (pt == "below") { P++; }
33338                 for (var  i = 0; i < O.records.length; i++) {
33339                         var  r = O.records[i];
33340                         var  dup = this.store.getById(r.id);
33341                         if (dup && (dd != this.dragZone)) {
33342                                 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
33343                         } else  {
33344                                 if (O.copy) {
33345                                         this.store.insert(P++, r.copy());
33346                                 } else  {
33347                                         O.source.isDirtyFlag = true;
33348                                         r.store.remove(r);
33349                                         this.store.insert(P++, r);
33350                                 }
33351
33352                                 this.isDirtyFlag = true;
33353                         }
33354                 }
33355
33356                 this.dragZone.cachedTarget = null;
33357                 return  true;
33358     },
33359
33360     removeDropIndicators : function(n){
33361                 if(n){
33362                         Roo.fly(n).removeClass([
33363                                 "x-view-drag-insert-above",
33364                                 "x-view-drag-insert-below"]);
33365                         this.lastInsertClass = "_noclass";
33366                 }
33367     },
33368
33369
33370
33371         setDeletable: function(Q) {
33372                 if (!this.singleSelect && !this.multiSelect) {
33373                         this.singleSelect = true;
33374                 }
33375                 var  c = this.getContextMenu();
33376                 this.contextMenu.on("itemclick", function(R) {
33377                         switch (R.id) {
33378                                 case  "delete":
33379                                         this.remove(this.getSelectedIndexes());
33380                                         break;
33381                         }
33382                 }, this);
33383                 this.contextMenu.add({
33384                         icon: Q,
33385                         id: "delete",
33386                         text: 'Delete'
33387                 });
33388         },
33389         
33390
33391
33392         getContextMenu: function() {
33393                 if (!this.contextMenu) {
33394
33395                         this.contextMenu = new  Roo.menu.Menu({
33396                                 id: this.id + "-contextmenu"
33397                         });
33398                         this.el.on("contextmenu", this.showContextMenu, this);
33399                 }
33400                 return  this.contextMenu;
33401         },
33402         
33403         disableContextMenu: function() {
33404                 if (this.contextMenu) {
33405                         this.el.un("contextmenu", this.showContextMenu, this);
33406                 }
33407         },
33408
33409         showContextMenu: function(e, R) {
33410         R = this.findItemFromChild(e.getTarget());
33411                 if (R) {
33412                         e.stopEvent();
33413                         this.select(this.getNode(R), this.multiSelect && e.ctrlKey, true);
33414                         this.contextMenu.showAt(e.getXY());
33415             }
33416     },
33417
33418
33419
33420     remove: function(S) {
33421                 S = [].concat(S);
33422                 for (var  i = 0; i < S.length; i++) {
33423                         var  rec = this.store.getAt(S[i]);
33424                         this.store.remove(rec);
33425                 }
33426     },
33427
33428
33429
33430     onDblClick : function(e){
33431         var  T = this.findItemFromChild(e.getTarget());
33432         if(T){
33433             if (this.fireEvent("dblclick", this, this.indexOf(T), T, e) === false) {
33434                 return  false;
33435             }
33436             if (this.dragGroup) {
33437                     var  targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
33438                     while (targets.indexOf(this.dropZone) > -1) {
33439                             targets.remove(this.dropZone);
33440                                 }
33441                     if (targets.length == 1) {
33442                                         this.dragZone.cachedTarget = null;
33443                         var  el = Roo.get(targets[0].getEl());
33444                         var  box = el.getBox(true);
33445                         targets[0].onNodeDrop(el.dom, {
33446                                 target: el.dom,
33447                                 xy: [box.x, box.y + box.height - 1]
33448                         }, null, this.getDragData(e));
33449                     }
33450                 }
33451         }
33452     },
33453     
33454     handleSelection: function(e) {
33455                 this.dragZone.cachedTarget = null;
33456         var  U = this.findItemFromChild(e.getTarget());
33457         if (!U) {
33458                 this.clearSelections(true);
33459                 return;
33460         }
33461                 if (U && (this.multiSelect || this.singleSelect)){
33462                         if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
33463                                 this.select(this.getNodes(this.indexOf(this.lastSelection), U.nodeIndex), false);
33464                         }else  if (this.isSelected(this.getNode(U)) && e.ctrlKey){
33465                                 this.unselect(U);
33466                         } else  {
33467                                 this.select(U, this.multiSelect && e.ctrlKey);
33468                                 this.lastSelection = U;
33469                         }
33470                 }
33471     },
33472
33473     onItemClick : function(V, W, e){
33474                 if(this.fireEvent("beforeclick", this, W, V, e) === false){
33475                         return  false;
33476                 }
33477                 return  true;
33478     },
33479
33480     unselect : function(X, Y){
33481                 var  Z = this.getNode(X);
33482                 if(Z && this.isSelected(Z)){
33483                         if(this.fireEvent("beforeselect", this, Z, this.selections) !== false){
33484                                 Roo.fly(Z).removeClass(this.selectedClass);
33485                                 this.selections.remove(Z);
33486                                 if(!Y){
33487                                         this.fireEvent("selectionchange", this, this.selections);
33488                                 }
33489                         }
33490                 }
33491     }
33492 });
33493
33494
33495
33496  
33497
33498
33499 Roo.LayoutManager = function(A, B){
33500     Roo.LayoutManager.superclass.constructor.call(this);
33501     this.el = Roo.get(A);
33502     
33503     if(this.el.dom == document.body && Roo.isIE && !B.allowScroll){
33504         document.body.scroll = "no";
33505     }else  if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
33506         this.el.position('relative');
33507     }
33508
33509     this.id = this.el.id;
33510     this.el.addClass("x-layout-container");
33511     
33512
33513     this.monitorWindowResize = true;
33514     this.regions = {};
33515     this.addEvents({
33516         
33517
33518         "layout" : true,
33519         
33520
33521         "regionresized" : true,
33522         
33523
33524         "regioncollapsed" : true,
33525         
33526
33527         "regionexpanded" : true
33528     });
33529     this.updating = false;
33530     Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
33531 };
33532
33533 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
33534     
33535
33536     isUpdating : function(){
33537         return  this.updating; 
33538     },
33539     
33540     
33541
33542     beginUpdate : function(){
33543         this.updating = true;    
33544     },
33545     
33546     
33547
33548     endUpdate : function(C){
33549         this.updating = false;
33550         if(!C){
33551             this.layout();
33552         }    
33553     },
33554     
33555     layout: function(){
33556         
33557     },
33558     
33559     onRegionResized : function(D, E){
33560         this.fireEvent("regionresized", D, E);
33561         this.layout();
33562     },
33563     
33564     onRegionCollapsed : function(F){
33565         this.fireEvent("regioncollapsed", F);
33566     },
33567     
33568     onRegionExpanded : function(G){
33569         this.fireEvent("regionexpanded", G);
33570     },
33571         
33572     
33573
33574     getViewSize : function(){
33575         var  H;
33576         if(this.el.dom != document.body){
33577             H = this.el.getSize();
33578         }else {
33579             H = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
33580         }
33581
33582         H.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
33583         H.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
33584         return  H;
33585     },
33586     
33587     
33588
33589     getEl : function(){
33590         return  this.el;
33591     },
33592     
33593     
33594
33595     getRegion : function(I){
33596         return  this.regions[I.toLowerCase()];
33597     },
33598     
33599     onWindowResize : function(){
33600         if(this.monitorWindowResize){
33601             this.layout();
33602         }
33603     }
33604 });
33605
33606
33607
33608
33609 Roo.BorderLayout = function(A, B){
33610     B = B || {};
33611     Roo.BorderLayout.superclass.constructor.call(this, A, B);
33612     this.factory = B.factory || Roo.BorderLayout.RegionFactory;
33613     for(var  i = 0, len = this.factory.validRegions.length; i < len; i++) {
33614         var  target = this.factory.validRegions[i];
33615         if(B[target]){
33616             this.addRegion(target, B[target]);
33617         }
33618     }
33619 };
33620
33621 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
33622     
33623
33624     addRegion : function(C, D){
33625         if(!this.regions[C]){
33626             var  r = this.factory.create(C, this, D);
33627             this.bindRegion(C, r);
33628         }
33629         return  this.regions[C];
33630     },
33631
33632     
33633     bindRegion : function(E, r){
33634         this.regions[E] = r;
33635         r.on("visibilitychange", this.layout, this);
33636         r.on("paneladded", this.layout, this);
33637         r.on("panelremoved", this.layout, this);
33638         r.on("invalidated", this.layout, this);
33639         r.on("resized", this.onRegionResized, this);
33640         r.on("collapsed", this.onRegionCollapsed, this);
33641         r.on("expanded", this.onRegionExpanded, this);
33642     },
33643
33644     
33645
33646     layout : function(){
33647         if(this.updating) return;
33648         var  F = this.getViewSize();
33649         var  w = F.width;
33650         var  h = F.height;
33651         var  G = w;
33652         var  H = h;
33653         var  I = 0;
33654         var  J = 0;
33655         
33656
33657         var  rs = this.regions;
33658         var  K = rs["north"];
33659         var  L = rs["south"]; 
33660         var  M = rs["west"];
33661         var  N = rs["east"];
33662         var  O = rs["center"];
33663         
33664             
33665         
33666         if(K && K.isVisible()){
33667             var  b = K.getBox();
33668             var  m = K.getMargins();
33669             b.width = w - (m.left+m.right);
33670             b.x = m.left;
33671             b.y = m.top;
33672             I = b.height + b.y + m.bottom;
33673             H -= I;
33674             K.updateBox(this.safeBox(b));
33675         }
33676         if(L && L.isVisible()){
33677             var  b = L.getBox();
33678             var  m = L.getMargins();
33679             b.width = w - (m.left+m.right);
33680             b.x = m.left;
33681             var  totalHeight = (b.height + m.top + m.bottom);
33682             b.y = h - totalHeight + m.top;
33683             H -= totalHeight;
33684             L.updateBox(this.safeBox(b));
33685         }
33686         if(M && M.isVisible()){
33687             var  b = M.getBox();
33688             var  m = M.getMargins();
33689             b.height = H - (m.top+m.bottom);
33690             b.x = m.left;
33691             b.y = I + m.top;
33692             var  totalWidth = (b.width + m.left + m.right);
33693             J += totalWidth;
33694             G -= totalWidth;
33695             M.updateBox(this.safeBox(b));
33696         }
33697         if(N && N.isVisible()){
33698             var  b = N.getBox();
33699             var  m = N.getMargins();
33700             b.height = H - (m.top+m.bottom);
33701             var  totalWidth = (b.width + m.left + m.right);
33702             b.x = w - totalWidth + m.left;
33703             b.y = I + m.top;
33704             G -= totalWidth;
33705             N.updateBox(this.safeBox(b));
33706         }
33707         if(O){
33708             var  m = O.getMargins();
33709             var  centerBox = {
33710                 x: J + m.left,
33711                 y: I + m.top,
33712                 width: G - (m.left+m.right),
33713                 height: H - (m.top+m.bottom)
33714             };
33715             
33716                 
33717             
33718             O.updateBox(this.safeBox(centerBox));
33719         }
33720
33721         this.el.repaint();
33722         this.fireEvent("layout", this);
33723     },
33724
33725     
33726     safeBox : function(P){
33727         P.width = Math.max(0, P.width);
33728         P.height = Math.max(0, P.height);
33729         return  P;
33730     },
33731
33732     
33733
33734     add : function(Q, R){
33735          
33736         Q = Q.toLowerCase();
33737         return  this.regions[Q].add(R);
33738     },
33739
33740     
33741
33742     remove : function(S, T){
33743         S = S.toLowerCase();
33744         return  this.regions[S].remove(T);
33745     },
33746
33747     
33748
33749     findPanel : function(U){
33750         var  rs = this.regions;
33751         for(var  S  in  rs){
33752             if(typeof  rs[S] != "function"){
33753                 var  p = rs[S].getPanel(U);
33754                 if(p){
33755                     return  p;
33756                 }
33757             }
33758         }
33759         return  null;
33760     },
33761
33762     
33763
33764     showPanel : function(V) {
33765       var  rs = this.regions;
33766       for(var  S  in  rs){
33767          var  r = rs[S];
33768          if(typeof  r != "function"){
33769             if(r.hasPanel(V)){
33770                return  r.showPanel(V);
33771             }
33772          }
33773       }
33774       return  null;
33775    },
33776
33777    
33778
33779     restoreState : function(W){
33780         if(!W){
33781             W = Roo.state.Manager;
33782         }
33783         var  sm = new  Roo.LayoutStateManager();
33784         sm.init(this, W);
33785     },
33786
33787     
33788
33789     batchAdd : function(X){
33790         this.beginUpdate();
33791         for(var  rname  in  X){
33792             var  lr = this.regions[rname];
33793             if(lr){
33794                 this.addTypedPanels(lr, X[rname]);
33795             }
33796         }
33797
33798         this.endUpdate();
33799     },
33800
33801     
33802     addTypedPanels : function(lr, ps){
33803         if(typeof  ps == 'string'){
33804             lr.add(new  Roo.ContentPanel(ps));
33805         }
33806         else  if(ps  instanceof  Array){
33807             for(var  i =0, len = ps.length; i < len; i++){
33808                 this.addTypedPanels(lr, ps[i]);
33809             }
33810         }
33811         else  if(!ps.events){ 
33812             var  el = ps.el;
33813             delete  ps.el; 
33814             lr.add(new  Roo.ContentPanel(el || Roo.id(), ps));
33815         }
33816         else  {  
33817             lr.add(ps);
33818         }
33819     },
33820     
33821
33822     addxtype : function(Y)
33823     {
33824         
33825         
33826        
33827         
33828         if (!Y.xtype.match(/Panel$/)) {
33829             return  false;
33830         }
33831         var  Z = false;
33832         var  a = Y.region;
33833         delete  Y.region;
33834         
33835           
33836         var  c = [];
33837         if (Y.items) {
33838             c = Y.items;
33839             delete  Y.items;
33840         }
33841         
33842         
33843         switch(Y.xtype) 
33844         {
33845             case  'ContentPanel':  
33846                 if(Y.autoCreate) {
33847                     Z = new  Roo[Y.xtype](Y); 
33848                 } else  {
33849                     var  el = this.el.createChild();
33850                     Z = new  Roo[Y.xtype](el, Y); 
33851                 }
33852
33853                 
33854                 this.add(a, Z);
33855                 break;
33856             
33857             
33858             case  'TreePanel': 
33859                 Y.el = this.el.createChild();
33860                 Z = new  Roo[Y.xtype](Y); 
33861                 this.add(a, Z);
33862                 break;
33863             
33864             case  'NestedLayoutPanel': 
33865                 
33866                 var  el = this.el.createChild();
33867                 var  clayout = Y.layout;
33868                 delete  Y.layout;
33869                 clayout.items   = clayout.items  || [];
33870                 
33871                 c = clayout.items;
33872                  
33873                 
33874                 if (a == 'center' && this.active && this.getRegion('center').panels.length < 1) {
33875                     Y.background = false;
33876                 }
33877                 var  layout = new  Roo.BorderLayout(el, clayout);
33878                 
33879                 Z = new  Roo[Y.xtype](layout, Y); 
33880                 
33881                 this.add(a, Z);
33882                 
33883                 break;
33884                 
33885             case  'GridPanel': 
33886             
33887                 
33888                 
33889                 
33890                 var  el = this.el.createChild();
33891                 
33892                 
33893                 var  grid = new  Roo.grid[Y.grid.xtype](el, Y.grid);
33894                 delete  Y.grid;
33895                 if (a == 'center' && this.active ) {
33896                     Y.background = false;
33897                 }
33898
33899                 Z = new  Roo[Y.xtype](grid, Y); 
33900                 
33901                 this.add(a, Z);
33902                 if (Y.background) {
33903                     Z.on('activate', function(gp) {
33904                         if (!gp.grid.rendered) {
33905                             gp.grid.render();
33906                         }
33907                     });
33908                 } else  {
33909                     grid.render();
33910                 }
33911                 break;
33912            
33913                
33914                 
33915                 
33916             default: 
33917                 alert("Can not add '" + Y.xtype + "' to BorderLayout");
33918                 return;
33919              
33920             
33921         }
33922
33923         this.beginUpdate();
33924         
33925         Roo.each(c, function(i)  {
33926             Z.addxtype(i);
33927         });
33928         this.endUpdate();
33929         return  Z;
33930         
33931     }
33932 });
33933
33934
33935
33936 Roo.BorderLayout.create = function(d, e){
33937     var  f = new  Roo.BorderLayout(e || document.body, d);
33938     f.beginUpdate();
33939     var  g = Roo.BorderLayout.RegionFactory.validRegions;
33940     for(var  j = 0, jlen = g.length; j < jlen; j++){
33941         var  lr = g[j];
33942         if(f.regions[lr] && d[lr].panels){
33943             var  r = f.regions[lr];
33944             var  ps = d[lr].panels;
33945             f.addTypedPanels(r, ps);
33946         }
33947     }
33948
33949     f.endUpdate();
33950     return  f;
33951 };
33952
33953
33954 Roo.BorderLayout.RegionFactory = {
33955     
33956     validRegions : ["north","south","east","west","center"],
33957
33958     
33959     create : function(k, l, n){
33960         k = k.toLowerCase();
33961         if(n.lightweight || n.basic){
33962             return  new  Roo.BasicLayoutRegion(l, n, k);
33963         }
33964         switch(k){
33965             case  "north":
33966                 return  new  Roo.NorthLayoutRegion(l, n);
33967             case  "south":
33968                 return  new  Roo.SouthLayoutRegion(l, n);
33969             case  "east":
33970                 return  new  Roo.EastLayoutRegion(l, n);
33971             case  "west":
33972                 return  new  Roo.WestLayoutRegion(l, n);
33973             case  "center":
33974                 return  new  Roo.CenterLayoutRegion(l, n);
33975         }
33976         throw  'Layout region "'+k+'" not supported.';
33977     }
33978 };
33979
33980
33981  
33982
33983
33984 Roo.BasicLayoutRegion = function(A, B, C, D){
33985     this.mgr = A;
33986     this.position  = C;
33987     this.events = {
33988         
33989
33990         
33991         
33992
33993         "beforeremove" : true,
33994         
33995
33996         "invalidated" : true,
33997         
33998
33999         "visibilitychange" : true,
34000         
34001
34002         "paneladded" : true,
34003         
34004
34005         "panelremoved" : true,
34006         
34007
34008         "collapsed" : true,
34009         
34010
34011         "expanded" : true,
34012         
34013
34014         "slideshow" : true,
34015         
34016
34017         "slidehide" : true,
34018         
34019
34020         "panelactivated" : true,
34021         
34022
34023         "resized" : true
34024     };
34025     
34026
34027     this.panels = new  Roo.util.MixedCollection();
34028     this.panels.getKey = this.getPanelId.createDelegate(this);
34029     this.box = null;
34030     this.activePanel = null;
34031     
34032     
34033     if (B.listeners || B.events) {
34034         Roo.BasicLayoutRegion.superclass.constructor.call(this, {
34035             listeners : B.listeners || {},
34036             events : B.events || {}
34037         });
34038     }
34039     
34040     if(D !== true){
34041         this.applyConfig(B);
34042     }
34043 };
34044
34045 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
34046     getPanelId : function(p){
34047         return  p.getId();
34048     },
34049     
34050     applyConfig : function(E){
34051         this.margins = E.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
34052         this.config = E;
34053         
34054     },
34055     
34056     
34057
34058     resizeTo : function(F){
34059         var  el = this.el ? this.el :
34060                  (this.activePanel ? this.activePanel.getEl() : null);
34061         if(el){
34062             switch(this.position){
34063                 case  "east":
34064                 case  "west":
34065                     el.setWidth(F);
34066                     this.fireEvent("resized", this, F);
34067                 break;
34068                 case  "north":
34069                 case  "south":
34070                     el.setHeight(F);
34071                     this.fireEvent("resized", this, F);
34072                 break;                
34073             }
34074         }
34075     },
34076     
34077     getBox : function(){
34078         return  this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
34079     },
34080     
34081     getMargins : function(){
34082         return  this.margins;
34083     },
34084     
34085     updateBox : function(G){
34086         this.box = G;
34087         var  el = this.activePanel.getEl();
34088         el.dom.style.left = G.x + "px";
34089         el.dom.style.top = G.y + "px";
34090         this.activePanel.setSize(G.width, G.height);
34091     },
34092     
34093     
34094
34095     getEl : function(){
34096         return  this.activePanel;
34097     },
34098     
34099     
34100
34101     isVisible : function(){
34102         return  this.activePanel ? true : false;
34103     },
34104     
34105     setActivePanel : function(H){
34106         H = this.getPanel(H);
34107         if(this.activePanel && this.activePanel != H){
34108             this.activePanel.setActiveState(false);
34109             this.activePanel.getEl().setLeftTop(-10000,-10000);
34110         }
34111
34112         this.activePanel = H;
34113         H.setActiveState(true);
34114         if(this.box){
34115             H.setSize(this.box.width, this.box.height);
34116         }
34117
34118         this.fireEvent("panelactivated", this, H);
34119         this.fireEvent("invalidated");
34120     },
34121     
34122     
34123
34124     showPanel : function(I){
34125         if(I = this.getPanel(I)){
34126             this.setActivePanel(I);
34127         }
34128         return  I;
34129     },
34130     
34131     
34132
34133     getActivePanel : function(){
34134         return  this.activePanel;
34135     },
34136     
34137     
34138
34139     add : function(J){
34140         if(arguments.length > 1){
34141             for(var  i = 0, len = arguments.length; i < len; i++) {
34142                 this.add(arguments[i]);
34143             }
34144             return  null;
34145         }
34146         if(this.hasPanel(J)){
34147             this.showPanel(J);
34148             return  J;
34149         }
34150         var  el = J.getEl();
34151         if(el.dom.parentNode != this.mgr.el.dom){
34152             this.mgr.el.dom.appendChild(el.dom);
34153         }
34154         if(J.setRegion){
34155             J.setRegion(this);
34156         }
34157
34158         this.panels.add(J);
34159         el.setStyle("position", "absolute");
34160         if(!J.background){
34161             this.setActivePanel(J);
34162             if(this.config.initialSize && this.panels.getCount()==1){
34163                 this.resizeTo(this.config.initialSize);
34164             }
34165         }
34166
34167         this.fireEvent("paneladded", this, J);
34168         return  J;
34169     },
34170     
34171     
34172
34173     hasPanel : function(K){
34174         if(typeof  K == "object"){ 
34175             K = K.getId();
34176         }
34177         return  this.getPanel(K) ? true : false;
34178     },
34179     
34180     
34181
34182     remove : function(L, M){
34183         L = this.getPanel(L);
34184         if(!L){
34185             return  null;
34186         }
34187         var  e = {};
34188         this.fireEvent("beforeremove", this, L, e);
34189         if(e.cancel === true){
34190             return  null;
34191         }
34192         var  N = L.getId();
34193         this.panels.removeKey(N);
34194         return  L;
34195     },
34196     
34197     
34198
34199     getPanel : function(id){
34200         if(typeof  id == "object"){ 
34201             return  id;
34202         }
34203         return  this.panels.get(id);
34204     },
34205     
34206     
34207
34208     getPosition: function(){
34209         return  this.position;    
34210     }
34211 });
34212
34213
34214  
34215
34216
34217 Roo.LayoutRegion = function(A, B, C){
34218     Roo.LayoutRegion.superclass.constructor.call(this, A, B, C, true);
34219     var  dh = Roo.DomHelper;
34220     
34221
34222     this.el = dh.append(A.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
34223     
34224
34225
34226     this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
34227         {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: "&#160;"},
34228         {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
34229     ]}, true);
34230     this.titleEl.enableDisplayMode();
34231     
34232
34233     this.titleTextEl = this.titleEl.dom.firstChild;
34234     this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
34235     this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
34236     this.closeBtn.enableDisplayMode();
34237     this.closeBtn.on("click", this.closeClicked, this);
34238     this.closeBtn.hide();
34239
34240     this.createBody(B);
34241     this.visible = true;
34242     this.collapsed = false;
34243
34244     if(B.hideWhenEmpty){
34245         this.hide();
34246         this.on("paneladded", this.validateVisibility, this);
34247         this.on("panelremoved", this.validateVisibility, this);
34248     }
34249
34250     this.applyConfig(B);
34251 };
34252
34253 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
34254
34255     createBody : function(){
34256         
34257
34258         this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
34259     },
34260
34261     applyConfig : function(c){
34262         if(c.collapsible && this.position != "center" && !this.collapsedEl){
34263             var  dh = Roo.DomHelper;
34264             if(c.titlebar !== false){
34265                 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
34266                 this.collapseBtn.on("click", this.collapse, this);
34267                 this.collapseBtn.enableDisplayMode();
34268
34269                 if(c.showPin === true || this.showPin){
34270                     this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
34271                     this.stickBtn.enableDisplayMode();
34272                     this.stickBtn.on("click", this.expand, this);
34273                     this.stickBtn.hide();
34274                 }
34275             }
34276
34277             
34278
34279             this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
34280                 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
34281             ]}, true);
34282             if(c.floatable !== false){
34283                this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
34284                this.collapsedEl.on("click", this.collapseClick, this);
34285             }
34286
34287             if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
34288                 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
34289                    id: "message", unselectable: "on", style:{"float":"left"}});
34290                this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
34291              }
34292
34293             this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
34294             this.expandBtn.on("click", this.expand, this);
34295         }
34296         if(this.collapseBtn){
34297             this.collapseBtn.setVisible(c.collapsible == true);
34298         }
34299
34300         this.cmargins = c.cmargins || this.cmargins ||
34301                          (this.position == "west" || this.position == "east" ?
34302                              {top: 0, left: 2, right:2, bottom: 0} :
34303                              {top: 2, left: 0, right:0, bottom: 2});
34304         this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
34305         this.bottomTabs = c.tabPosition != "top";
34306         this.autoScroll = c.autoScroll || false;
34307         if(this.autoScroll){
34308             this.bodyEl.setStyle("overflow", "auto");
34309         }else {
34310             this.bodyEl.setStyle("overflow", "hidden");
34311         }
34312         
34313             if((!c.titlebar && !c.title) || c.titlebar === false){
34314                 this.titleEl.hide();
34315             }else {
34316                 this.titleEl.show();
34317                 if(c.title){
34318                     this.titleTextEl.innerHTML = c.title;
34319                 }
34320             }
34321
34322         
34323         this.duration = c.duration || .30;
34324         this.slideDuration = c.slideDuration || .45;
34325         this.config = c;
34326         if(c.collapsed){
34327             this.collapse(true);
34328         }
34329         if(c.hidden){
34330             this.hide();
34331         }
34332     },
34333     
34334
34335     isVisible : function(){
34336         return  this.visible;
34337     },
34338
34339     
34340
34341     setCollapsedTitle : function(D){
34342         D = D || "&#160;";
34343         if(this.collapsedTitleTextEl){
34344             this.collapsedTitleTextEl.innerHTML = D;
34345         }
34346     },
34347
34348     getBox : function(){
34349         var  b;
34350         if(!this.collapsed){
34351             b = this.el.getBox(false, true);
34352         }else {
34353             b = this.collapsedEl.getBox(false, true);
34354         }
34355         return  b;
34356     },
34357
34358     getMargins : function(){
34359         return  this.collapsed ? this.cmargins : this.margins;
34360     },
34361
34362     highlight : function(){
34363         this.el.addClass("x-layout-panel-dragover");
34364     },
34365
34366     unhighlight : function(){
34367         this.el.removeClass("x-layout-panel-dragover");
34368     },
34369
34370     updateBox : function(E){
34371         this.box = E;
34372         if(!this.collapsed){
34373             this.el.dom.style.left = E.x + "px";
34374             this.el.dom.style.top = E.y + "px";
34375             this.updateBody(E.width, E.height);
34376         }else {
34377             this.collapsedEl.dom.style.left = E.x + "px";
34378             this.collapsedEl.dom.style.top = E.y + "px";
34379             this.collapsedEl.setSize(E.width, E.height);
34380         }
34381         if(this.tabs){
34382             this.tabs.autoSizeTabs();
34383         }
34384     },
34385
34386     updateBody : function(w, h){
34387         if(w !== null){
34388             this.el.setWidth(w);
34389             w -= this.el.getBorderWidth("rl");
34390             if(this.config.adjustments){
34391                 w += this.config.adjustments[0];
34392             }
34393         }
34394         if(h !== null){
34395             this.el.setHeight(h);
34396             h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
34397             h -= this.el.getBorderWidth("tb");
34398             if(this.config.adjustments){
34399                 h += this.config.adjustments[1];
34400             }
34401
34402             this.bodyEl.setHeight(h);
34403             if(this.tabs){
34404                 h = this.tabs.syncHeight(h);
34405             }
34406         }
34407         if(this.panelSize){
34408             w = w !== null ? w : this.panelSize.width;
34409             h = h !== null ? h : this.panelSize.height;
34410         }
34411         if(this.activePanel){
34412             var  el = this.activePanel.getEl();
34413             w = w !== null ? w : el.getWidth();
34414             h = h !== null ? h : el.getHeight();
34415             this.panelSize = {width: w, height: h};
34416             this.activePanel.setSize(w, h);
34417         }
34418         if(Roo.isIE && this.tabs){
34419             this.tabs.el.repaint();
34420         }
34421     },
34422
34423     
34424
34425     getEl : function(){
34426         return  this.el;
34427     },
34428
34429     
34430
34431     hide : function(){
34432         if(!this.collapsed){
34433             this.el.dom.style.left = "-2000px";
34434             this.el.hide();
34435         }else {
34436             this.collapsedEl.dom.style.left = "-2000px";
34437             this.collapsedEl.hide();
34438         }
34439
34440         this.visible = false;
34441         this.fireEvent("visibilitychange", this, false);
34442     },
34443
34444     
34445
34446     show : function(){
34447         if(!this.collapsed){
34448             this.el.show();
34449         }else {
34450             this.collapsedEl.show();
34451         }
34452
34453         this.visible = true;
34454         this.fireEvent("visibilitychange", this, true);
34455     },
34456
34457     closeClicked : function(){
34458         if(this.activePanel){
34459             this.remove(this.activePanel);
34460         }
34461     },
34462
34463     collapseClick : function(e){
34464         if(this.isSlid){
34465            e.stopPropagation();
34466            this.slideIn();
34467         }else {
34468            e.stopPropagation();
34469            this.slideOut();
34470         }
34471     },
34472
34473     
34474
34475     collapse : function(F){
34476         if(this.collapsed) return;
34477         this.collapsed = true;
34478         if(this.split){
34479             this.split.el.hide();
34480         }
34481         if(this.config.animate && F !== true){
34482             this.fireEvent("invalidated", this);
34483             this.animateCollapse();
34484         }else {
34485             this.el.setLocation(-20000,-20000);
34486             this.el.hide();
34487             this.collapsedEl.show();
34488             this.fireEvent("collapsed", this);
34489             this.fireEvent("invalidated", this);
34490         }
34491     },
34492
34493     animateCollapse : function(){
34494         
34495     },
34496
34497     
34498
34499     expand : function(e, G){
34500         if(e) e.stopPropagation();
34501         if(!this.collapsed || this.el.hasActiveFx()) return;
34502         if(this.isSlid){
34503             this.afterSlideIn();
34504             G = true;
34505         }
34506
34507         this.collapsed = false;
34508         if(this.config.animate && G !== true){
34509             this.animateExpand();
34510         }else {
34511             this.el.show();
34512             if(this.split){
34513                 this.split.el.show();
34514             }
34515
34516             this.collapsedEl.setLocation(-2000,-2000);
34517             this.collapsedEl.hide();
34518             this.fireEvent("invalidated", this);
34519             this.fireEvent("expanded", this);
34520         }
34521     },
34522
34523     animateExpand : function(){
34524         
34525     },
34526
34527     initTabs : function(){
34528         this.bodyEl.setStyle("overflow", "hidden");
34529         var  ts = new  Roo.TabPanel(this.bodyEl.dom, {
34530             tabPosition: this.bottomTabs ? 'bottom' : 'top',
34531             disableTooltips: this.config.disableTabTips
34532         });
34533         if(this.config.hideTabs){
34534             ts.stripWrap.setDisplayed(false);
34535         }
34536
34537         this.tabs = ts;
34538         ts.resizeTabs = this.config.resizeTabs === true;
34539         ts.minTabWidth = this.config.minTabWidth || 40;
34540         ts.maxTabWidth = this.config.maxTabWidth || 250;
34541         ts.preferredTabWidth = this.config.preferredTabWidth || 150;
34542         ts.monitorResize = false;
34543         ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
34544         ts.bodyEl.addClass('x-layout-tabs-body');
34545         this.panels.each(this.initPanelAsTab, this);
34546     },
34547
34548     initPanelAsTab : function(H){
34549         var  ti = this.tabs.addTab(H.getEl().id, H.getTitle(), null,
34550                     this.config.closeOnTab && H.isClosable());
34551         if(H.tabTip !== undefined){
34552             ti.setTooltip(H.tabTip);
34553         }
34554
34555         ti.on("activate", function(){
34556               this.setActivePanel(H);
34557         }, this);
34558         if(this.config.closeOnTab){
34559             ti.on("beforeclose", function(t, e){
34560                 e.cancel = true;
34561                 this.remove(H);
34562             }, this);
34563         }
34564         return  ti;
34565     },
34566
34567     updatePanelTitle : function(I, J){
34568         if(this.activePanel == I){
34569             this.updateTitle(J);
34570         }
34571         if(this.tabs){
34572             var  ti = this.tabs.getTab(I.getEl().id);
34573             ti.setText(J);
34574             if(I.tabTip !== undefined){
34575                 ti.setTooltip(I.tabTip);
34576             }
34577         }
34578     },
34579
34580     updateTitle : function(K){
34581         if(this.titleTextEl && !this.config.title){
34582             this.titleTextEl.innerHTML = (typeof  K != "undefined" && K.length > 0 ? K : "&#160;");
34583         }
34584     },
34585
34586     setActivePanel : function(L){
34587         L = this.getPanel(L);
34588         if(this.activePanel && this.activePanel != L){
34589             this.activePanel.setActiveState(false);
34590         }
34591
34592         this.activePanel = L;
34593         L.setActiveState(true);
34594         if(this.panelSize){
34595             L.setSize(this.panelSize.width, this.panelSize.height);
34596         }
34597         if(this.closeBtn){
34598             this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && L.isClosable());
34599         }
34600
34601         this.updateTitle(L.getTitle());
34602         if(this.tabs){
34603             this.fireEvent("invalidated", this);
34604         }
34605
34606         this.fireEvent("panelactivated", this, L);
34607     },
34608
34609     
34610
34611     showPanel : function(M){
34612         if(M = this.getPanel(M)){
34613             if(this.tabs){
34614                 var  tab = this.tabs.getTab(M.getEl().id);
34615                 if(tab.isHidden()){
34616                     this.tabs.unhideTab(tab.id);
34617                 }
34618
34619                 tab.activate();
34620             }else {
34621                 this.setActivePanel(M);
34622             }
34623         }
34624         return  M;
34625     },
34626
34627     
34628
34629     getActivePanel : function(){
34630         return  this.activePanel;
34631     },
34632
34633     validateVisibility : function(){
34634         if(this.panels.getCount() < 1){
34635             this.updateTitle("&#160;");
34636             this.closeBtn.hide();
34637             this.hide();
34638         }else {
34639             if(!this.isVisible()){
34640                 this.show();
34641             }
34642         }
34643     },
34644
34645     
34646
34647     add : function(N){
34648         if(arguments.length > 1){
34649             for(var  i = 0, len = arguments.length; i < len; i++) {
34650                 this.add(arguments[i]);
34651             }
34652             return  null;
34653         }
34654         if(this.hasPanel(N)){
34655             this.showPanel(N);
34656             return  N;
34657         }
34658
34659         N.setRegion(this);
34660         this.panels.add(N);
34661         if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
34662             this.bodyEl.dom.appendChild(N.getEl().dom);
34663             if(N.background !== true){
34664                 this.setActivePanel(N);
34665             }
34666
34667             this.fireEvent("paneladded", this, N);
34668             return  N;
34669         }
34670         if(!this.tabs){
34671             this.initTabs();
34672         }else {
34673             this.initPanelAsTab(N);
34674         }
34675         if(N.background !== true){
34676             this.tabs.activate(N.getEl().id);
34677         }
34678
34679         this.fireEvent("paneladded", this, N);
34680         return  N;
34681     },
34682
34683     
34684
34685     hidePanel : function(O){
34686         if(this.tabs && (O = this.getPanel(O))){
34687             this.tabs.hideTab(O.getEl().id);
34688         }
34689     },
34690
34691     
34692
34693     unhidePanel : function(P){
34694         if(this.tabs && (P = this.getPanel(P))){
34695             this.tabs.unhideTab(P.getEl().id);
34696         }
34697     },
34698
34699     clearPanels : function(){
34700         while(this.panels.getCount() > 0){
34701              this.remove(this.panels.first());
34702         }
34703     },
34704
34705     
34706
34707     remove : function(Q, R){
34708         Q = this.getPanel(Q);
34709         if(!Q){
34710             return  null;
34711         }
34712         var  e = {};
34713         this.fireEvent("beforeremove", this, Q, e);
34714         if(e.cancel === true){
34715             return  null;
34716         }
34717
34718         R = (typeof  R != "undefined" ? R : (this.config.preservePanels === true || Q.preserve === true));
34719         var  S = Q.getId();
34720         this.panels.removeKey(S);
34721         if(R){
34722             document.body.appendChild(Q.getEl().dom);
34723         }
34724         if(this.tabs){
34725             this.tabs.removeTab(Q.getEl().id);
34726         }else  if (!R){
34727             this.bodyEl.dom.removeChild(Q.getEl().dom);
34728         }
34729         if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
34730             var  p = this.panels.first();
34731             var  tempEl = document.createElement("div"); 
34732             tempEl.appendChild(p.getEl().dom);
34733             this.bodyEl.update("");
34734             this.bodyEl.dom.appendChild(p.getEl().dom);
34735             tempEl = null;
34736             this.updateTitle(p.getTitle());
34737             this.tabs = null;
34738             this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
34739             this.setActivePanel(p);
34740         }
34741
34742         Q.setRegion(null);
34743         if(this.activePanel == Q){
34744             this.activePanel = null;
34745         }
34746         if(this.config.autoDestroy !== false && R !== true){
34747             try{Q.destroy();}catch(e){}
34748         }
34749
34750         this.fireEvent("panelremoved", this, Q);
34751         return  Q;
34752     },
34753
34754     
34755
34756     getTabs : function(){
34757         return  this.tabs;
34758     },
34759
34760     createTool : function(T, U){
34761         var  V = Roo.DomHelper.append(T, {tag: "div", cls: "x-layout-tools-button",
34762             children: [{tag: "div", cls: "x-layout-tools-button-inner " + U, html: "&#160;"}]}, true);
34763         V.addClassOnOver("x-layout-tools-button-over");
34764         return  V;
34765     }
34766 });
34767
34768
34769  
34770
34771
34772
34773
34774 Roo.SplitLayoutRegion = function(A, B, C, D){
34775     this.cursor = D;
34776     Roo.SplitLayoutRegion.superclass.constructor.call(this, A, B, C);
34777 };
34778
34779 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
34780     splitTip : "Drag to resize.",
34781     collapsibleSplitTip : "Drag to resize. Double click to hide.",
34782     useSplitTips : false,
34783
34784     applyConfig : function(E){
34785         Roo.SplitLayoutRegion.superclass.applyConfig.call(this, E);
34786         if(E.split){
34787             if(!this.split){
34788                 var  splitEl = Roo.DomHelper.append(this.mgr.el.dom, 
34789                         {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: "&#160;"});
34790                 
34791
34792                 this.split = new  Roo.SplitBar(splitEl, this.el, this.orientation);
34793                 this.split.on("moved", this.onSplitMove, this);
34794                 this.split.useShim = E.useShim === true;
34795                 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
34796                 if(this.useSplitTips){
34797                     this.split.el.dom.title = E.collapsible ? this.collapsibleSplitTip : this.splitTip;
34798                 }
34799                 if(E.collapsible){
34800                     this.split.el.on("dblclick", this.collapse,  this);
34801                 }
34802             }
34803             if(typeof  E.minSize != "undefined"){
34804                 this.split.minSize = E.minSize;
34805             }
34806             if(typeof  E.maxSize != "undefined"){
34807                 this.split.maxSize = E.maxSize;
34808             }
34809             if(E.hideWhenEmpty || E.hidden || E.collapsed){
34810                 this.hideSplitter();
34811             }
34812         }
34813     },
34814
34815     getHMaxSize : function(){
34816          var  F = this.config.maxSize || 10000;
34817          var  G = this.mgr.getRegion("center");
34818          return  Math.min(F, (this.el.getWidth()+G.getEl().getWidth())-G.getMinWidth());
34819     },
34820
34821     getVMaxSize : function(){
34822          var  H = this.config.maxSize || 10000;
34823          var  I = this.mgr.getRegion("center");
34824          return  Math.min(H, (this.el.getHeight()+I.getEl().getHeight())-I.getMinHeight());
34825     },
34826
34827     onSplitMove : function(J, K){
34828         this.fireEvent("resized", this, K);
34829     },
34830     
34831     
34832
34833     getSplitBar : function(){
34834         return  this.split;
34835     },
34836     
34837     hide : function(){
34838         this.hideSplitter();
34839         Roo.SplitLayoutRegion.superclass.hide.call(this);
34840     },
34841
34842     hideSplitter : function(){
34843         if(this.split){
34844             this.split.el.setLocation(-2000,-2000);
34845             this.split.el.hide();
34846         }
34847     },
34848
34849     show : function(){
34850         if(this.split){
34851             this.split.el.show();
34852         }
34853
34854         Roo.SplitLayoutRegion.superclass.show.call(this);
34855     },
34856     
34857     beforeSlide: function(){
34858         if(Roo.isGecko){
34859             this.bodyEl.clip();
34860             if(this.tabs) this.tabs.bodyEl.clip();
34861             if(this.activePanel){
34862                 this.activePanel.getEl().clip();
34863                 
34864                 if(this.activePanel.beforeSlide){
34865                     this.activePanel.beforeSlide();
34866                 }
34867             }
34868         }
34869     },
34870     
34871     afterSlide : function(){
34872         if(Roo.isGecko){
34873             this.bodyEl.unclip();
34874             if(this.tabs) this.tabs.bodyEl.unclip();
34875             if(this.activePanel){
34876                 this.activePanel.getEl().unclip();
34877                 if(this.activePanel.afterSlide){
34878                     this.activePanel.afterSlide();
34879                 }
34880             }
34881         }
34882     },
34883
34884     initAutoHide : function(){
34885         if(this.autoHide !== false){
34886             if(!this.autoHideHd){
34887                 var  st = new  Roo.util.DelayedTask(this.slideIn, this);
34888                 this.autoHideHd = {
34889                     "mouseout": function(e){
34890                         if(!e.within(this.el, true)){
34891                             st.delay(500);
34892                         }
34893                     },
34894                     "mouseover" : function(e){
34895                         st.cancel();
34896                     },
34897                     scope : this
34898                 };
34899             }
34900
34901             this.el.on(this.autoHideHd);
34902         }
34903     },
34904
34905     clearAutoHide : function(){
34906         if(this.autoHide !== false){
34907             this.el.un("mouseout", this.autoHideHd.mouseout);
34908             this.el.un("mouseover", this.autoHideHd.mouseover);
34909         }
34910     },
34911
34912     clearMonitor : function(){
34913         Roo.get(document).un("click", this.slideInIf, this);
34914     },
34915
34916     
34917     slideOut : function(){
34918         if(this.isSlid || this.el.hasActiveFx()){
34919             return;
34920         }
34921
34922         this.isSlid = true;
34923         if(this.collapseBtn){
34924             this.collapseBtn.hide();
34925         }
34926
34927         this.closeBtnState = this.closeBtn.getStyle('display');
34928         this.closeBtn.hide();
34929         if(this.stickBtn){
34930             this.stickBtn.show();
34931         }
34932
34933         this.el.show();
34934         this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
34935         this.beforeSlide();
34936         this.el.setStyle("z-index", 10001);
34937         this.el.slideIn(this.getSlideAnchor(), {
34938             callback: function(){
34939                 this.afterSlide();
34940                 this.initAutoHide();
34941                 Roo.get(document).on("click", this.slideInIf, this);
34942                 this.fireEvent("slideshow", this);
34943             },
34944             scope: this,
34945             block: true
34946         });
34947     },
34948
34949     afterSlideIn : function(){
34950         this.clearAutoHide();
34951         this.isSlid = false;
34952         this.clearMonitor();
34953         this.el.setStyle("z-index", "");
34954         if(this.collapseBtn){
34955             this.collapseBtn.show();
34956         }
34957
34958         this.closeBtn.setStyle('display', this.closeBtnState);
34959         if(this.stickBtn){
34960             this.stickBtn.hide();
34961         }
34962
34963         this.fireEvent("slidehide", this);
34964     },
34965
34966     slideIn : function(cb){
34967         if(!this.isSlid || this.el.hasActiveFx()){
34968             Roo.callback(cb);
34969             return;
34970         }
34971
34972         this.isSlid = false;
34973         this.beforeSlide();
34974         this.el.slideOut(this.getSlideAnchor(), {
34975             callback: function(){
34976                 this.el.setLeftTop(-10000, -10000);
34977                 this.afterSlide();
34978                 this.afterSlideIn();
34979                 Roo.callback(cb);
34980             },
34981             scope: this,
34982             block: true
34983         });
34984     },
34985     
34986     slideInIf : function(e){
34987         if(!e.within(this.el)){
34988             this.slideIn();
34989         }
34990     },
34991
34992     animateCollapse : function(){
34993         this.beforeSlide();
34994         this.el.setStyle("z-index", 20000);
34995         var  L = this.getSlideAnchor();
34996         this.el.slideOut(L, {
34997             callback : function(){
34998                 this.el.setStyle("z-index", "");
34999                 this.collapsedEl.slideIn(L, {duration:.3});
35000                 this.afterSlide();
35001                 this.el.setLocation(-10000,-10000);
35002                 this.el.hide();
35003                 this.fireEvent("collapsed", this);
35004             },
35005             scope: this,
35006             block: true
35007         });
35008     },
35009
35010     animateExpand : function(){
35011         this.beforeSlide();
35012         this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
35013         this.el.setStyle("z-index", 20000);
35014         this.collapsedEl.hide({
35015             duration:.1
35016         });
35017         this.el.slideIn(this.getSlideAnchor(), {
35018             callback : function(){
35019                 this.el.setStyle("z-index", "");
35020                 this.afterSlide();
35021                 if(this.split){
35022                     this.split.el.show();
35023                 }
35024
35025                 this.fireEvent("invalidated", this);
35026                 this.fireEvent("expanded", this);
35027             },
35028             scope: this,
35029             block: true
35030         });
35031     },
35032
35033     anchors : {
35034         "west" : "left",
35035         "east" : "right",
35036         "north" : "top",
35037         "south" : "bottom"
35038     },
35039
35040     sanchors : {
35041         "west" : "l",
35042         "east" : "r",
35043         "north" : "t",
35044         "south" : "b"
35045     },
35046
35047     canchors : {
35048         "west" : "tl-tr",
35049         "east" : "tr-tl",
35050         "north" : "tl-bl",
35051         "south" : "bl-tl"
35052     },
35053
35054     getAnchor : function(){
35055         return  this.anchors[this.position];
35056     },
35057
35058     getCollapseAnchor : function(){
35059         return  this.canchors[this.position];
35060     },
35061
35062     getSlideAnchor : function(){
35063         return  this.sanchors[this.position];
35064     },
35065
35066     getAlignAdj : function(){
35067         var  cm = this.cmargins;
35068         switch(this.position){
35069             case  "west":
35070                 return  [0, 0];
35071             break;
35072             case  "east":
35073                 return  [0, 0];
35074             break;
35075             case  "north":
35076                 return  [0, 0];
35077             break;
35078             case  "south":
35079                 return  [0, 0];
35080             break;
35081         }
35082     },
35083
35084     getExpandAdj : function(){
35085         var  c = this.collapsedEl, cm = this.cmargins;
35086         switch(this.position){
35087             case  "west":
35088                 return  [-(cm.right+c.getWidth()+cm.left), 0];
35089             break;
35090             case  "east":
35091                 return  [cm.right+c.getWidth()+cm.left, 0];
35092             break;
35093             case  "north":
35094                 return  [0, -(cm.top+cm.bottom+c.getHeight())];
35095             break;
35096             case  "south":
35097                 return  [0, cm.top+cm.bottom+c.getHeight()];
35098             break;
35099         }
35100     }
35101 });
35102
35103
35104
35105
35106 Roo.CenterLayoutRegion = function(A, B){
35107     Roo.LayoutRegion.call(this, A, B, "center");
35108     this.visible = true;
35109     this.minWidth = B.minWidth || 20;
35110     this.minHeight = B.minHeight || 20;
35111 };
35112
35113 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
35114     hide : function(){
35115         
35116     },
35117     
35118     show : function(){
35119         
35120     },
35121     
35122     getMinWidth: function(){
35123         return  this.minWidth;
35124     },
35125     
35126     getMinHeight: function(){
35127         return  this.minHeight;
35128     }
35129 });
35130
35131
35132 Roo.NorthLayoutRegion = function(C, D){
35133     Roo.LayoutRegion.call(this, C, D, "north", "n-resize");
35134     if(this.split){
35135         this.split.placement = Roo.SplitBar.TOP;
35136         this.split.orientation = Roo.SplitBar.VERTICAL;
35137         this.split.el.addClass("x-layout-split-v");
35138     }
35139     var  E = D.initialSize || D.height;
35140     if(typeof  E != "undefined"){
35141         this.el.setHeight(E);
35142     }
35143 };
35144 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
35145     orientation: Roo.SplitBar.VERTICAL,
35146     getBox : function(){
35147         if(this.collapsed){
35148             return  this.collapsedEl.getBox();
35149         }
35150         var  F = this.el.getBox();
35151         if(this.split){
35152             F.height += this.split.el.getHeight();
35153         }
35154         return  F;
35155     },
35156     
35157     updateBox : function(G){
35158         if(this.split && !this.collapsed){
35159             G.height -= this.split.el.getHeight();
35160             this.split.el.setLeft(G.x);
35161             this.split.el.setTop(G.y+G.height);
35162             this.split.el.setWidth(G.width);
35163         }
35164         if(this.collapsed){
35165             this.updateBody(G.width, null);
35166         }
35167
35168         Roo.LayoutRegion.prototype.updateBox.call(this, G);
35169     }
35170 });
35171
35172 Roo.SouthLayoutRegion = function(H, I){
35173     Roo.SplitLayoutRegion.call(this, H, I, "south", "s-resize");
35174     if(this.split){
35175         this.split.placement = Roo.SplitBar.BOTTOM;
35176         this.split.orientation = Roo.SplitBar.VERTICAL;
35177         this.split.el.addClass("x-layout-split-v");
35178     }
35179     var  J = I.initialSize || I.height;
35180     if(typeof  J != "undefined"){
35181         this.el.setHeight(J);
35182     }
35183 };
35184 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
35185     orientation: Roo.SplitBar.VERTICAL,
35186     getBox : function(){
35187         if(this.collapsed){
35188             return  this.collapsedEl.getBox();
35189         }
35190         var  K = this.el.getBox();
35191         if(this.split){
35192             var  sh = this.split.el.getHeight();
35193             K.height += sh;
35194             K.y -= sh;
35195         }
35196         return  K;
35197     },
35198     
35199     updateBox : function(L){
35200         if(this.split && !this.collapsed){
35201             var  sh = this.split.el.getHeight();
35202             L.height -= sh;
35203             L.y += sh;
35204             this.split.el.setLeft(L.x);
35205             this.split.el.setTop(L.y-sh);
35206             this.split.el.setWidth(L.width);
35207         }
35208         if(this.collapsed){
35209             this.updateBody(L.width, null);
35210         }
35211
35212         Roo.LayoutRegion.prototype.updateBox.call(this, L);
35213     }
35214 });
35215
35216 Roo.EastLayoutRegion = function(M, N){
35217     Roo.SplitLayoutRegion.call(this, M, N, "east", "e-resize");
35218     if(this.split){
35219         this.split.placement = Roo.SplitBar.RIGHT;
35220         this.split.orientation = Roo.SplitBar.HORIZONTAL;
35221         this.split.el.addClass("x-layout-split-h");
35222     }
35223     var  O = N.initialSize || N.width;
35224     if(typeof  O != "undefined"){
35225         this.el.setWidth(O);
35226     }
35227 };
35228 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
35229     orientation: Roo.SplitBar.HORIZONTAL,
35230     getBox : function(){
35231         if(this.collapsed){
35232             return  this.collapsedEl.getBox();
35233         }
35234         var  P = this.el.getBox();
35235         if(this.split){
35236             var  sw = this.split.el.getWidth();
35237             P.width += sw;
35238             P.x -= sw;
35239         }
35240         return  P;
35241     },
35242
35243     updateBox : function(Q){
35244         if(this.split && !this.collapsed){
35245             var  sw = this.split.el.getWidth();
35246             Q.width -= sw;
35247             this.split.el.setLeft(Q.x);
35248             this.split.el.setTop(Q.y);
35249             this.split.el.setHeight(Q.height);
35250             Q.x += sw;
35251         }
35252         if(this.collapsed){
35253             this.updateBody(null, Q.height);
35254         }
35255
35256         Roo.LayoutRegion.prototype.updateBox.call(this, Q);
35257     }
35258 });
35259
35260 Roo.WestLayoutRegion = function(R, S){
35261     Roo.SplitLayoutRegion.call(this, R, S, "west", "w-resize");
35262     if(this.split){
35263         this.split.placement = Roo.SplitBar.LEFT;
35264         this.split.orientation = Roo.SplitBar.HORIZONTAL;
35265         this.split.el.addClass("x-layout-split-h");
35266     }
35267     var  T = S.initialSize || S.width;
35268     if(typeof  T != "undefined"){
35269         this.el.setWidth(T);
35270     }
35271 };
35272 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
35273     orientation: Roo.SplitBar.HORIZONTAL,
35274     getBox : function(){
35275         if(this.collapsed){
35276             return  this.collapsedEl.getBox();
35277         }
35278         var  U = this.el.getBox();
35279         if(this.split){
35280             U.width += this.split.el.getWidth();
35281         }
35282         return  U;
35283     },
35284     
35285     updateBox : function(V){
35286         if(this.split && !this.collapsed){
35287             var  sw = this.split.el.getWidth();
35288             V.width -= sw;
35289             this.split.el.setLeft(V.x+V.width);
35290             this.split.el.setTop(V.y);
35291             this.split.el.setHeight(V.height);
35292         }
35293         if(this.collapsed){
35294             this.updateBody(null, V.height);
35295         }
35296
35297         Roo.LayoutRegion.prototype.updateBox.call(this, V);
35298     }
35299 });
35300
35301
35302
35303  
35304  
35305
35306
35307 Roo.LayoutStateManager = function(A){
35308      
35309      this.state = {
35310         north: {},
35311         south: {},
35312         east: {},
35313         west: {}       
35314     };
35315 };
35316
35317 Roo.LayoutStateManager.prototype = {
35318     init : function(B, C){
35319         this.provider = C;
35320         var  D = C.get(B.id+"-layout-state");
35321         if(D){
35322             var  wasUpdating = B.isUpdating();
35323             if(!wasUpdating){
35324                 B.beginUpdate();
35325             }
35326             for(var  key  in  D){
35327                 if(typeof  D[key] != "function"){
35328                     var  rstate = D[key];
35329                     var  r = B.getRegion(key);
35330                     if(r && rstate){
35331                         if(rstate.size){
35332                             r.resizeTo(rstate.size);
35333                         }
35334                         if(rstate.collapsed == true){
35335                             r.collapse(true);
35336                         }else {
35337                             r.expand(null, true);
35338                         }
35339                     }
35340                 }
35341             }
35342             if(!wasUpdating){
35343                 B.endUpdate();
35344             }
35345
35346             this.state = D; 
35347         }
35348
35349         this.layout = B;
35350         B.on("regionresized", this.onRegionResized, this);
35351         B.on("regioncollapsed", this.onRegionCollapsed, this);
35352         B.on("regionexpanded", this.onRegionExpanded, this);
35353     },
35354     
35355     storeState : function(){
35356         this.provider.set(this.layout.id+"-layout-state", this.state);
35357     },
35358     
35359     onRegionResized : function(E, F){
35360         this.state[E.getPosition()].size = F;
35361         this.storeState();
35362     },
35363     
35364     onRegionCollapsed : function(G){
35365         this.state[G.getPosition()].collapsed = true;
35366         this.storeState();
35367     },
35368     
35369     onRegionExpanded : function(H){
35370         this.state[H.getPosition()].collapsed = false;
35371         this.storeState();
35372     }
35373 };
35374
35375
35376
35377
35378 Roo.ContentPanel = function(el, A, B){
35379     
35380      
35381     
35382
35383     if(el.autoCreate){ 
35384         A = el;
35385         el = Roo.id();
35386     }
35387
35388     this.el = Roo.get(el);
35389     if(!this.el && A && A.autoCreate){
35390         if(typeof  A.autoCreate == "object"){
35391             if(!A.autoCreate.id){
35392                 A.autoCreate.id = A.id||el;
35393             }
35394
35395             this.el = Roo.DomHelper.append(document.body,
35396                         A.autoCreate, true);
35397         }else {
35398             this.el = Roo.DomHelper.append(document.body,
35399                         {tag: "div", cls: "x-layout-inactive-content", id: A.id||el}, true);
35400         }
35401     }
35402
35403     this.closable = false;
35404     this.loaded = false;
35405     this.active = false;
35406     if(typeof  A == "string"){
35407         this.title = A;
35408     }else {
35409         Roo.apply(this, A);
35410     }
35411     
35412     if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
35413         this.wrapEl = this.el.wrap();    
35414         this.toolbar = new  Roo.Toolbar(this.el.insertSibling(false, 'before'), [] , this.toolbar);
35415         
35416     }
35417     
35418     
35419     
35420     if(this.resizeEl){
35421         this.resizeEl = Roo.get(this.resizeEl, true);
35422     }else {
35423         this.resizeEl = this.el;
35424     }
35425
35426     this.addEvents({
35427         
35428
35429         "activate" : true,
35430         
35431
35432         "deactivate" : true,
35433
35434         
35435
35436         "resize" : true
35437     });
35438     if(this.autoScroll){
35439         this.resizeEl.setStyle("overflow", "auto");
35440     }
35441
35442     B = B || this.content;
35443     if(B){
35444         this.setContent(B);
35445     }
35446     if(A && A.url){
35447         this.setUrl(this.url, this.params, this.loadOnce);
35448     }
35449
35450     
35451     
35452     
35453     Roo.ContentPanel.superclass.constructor.call(this);
35454 };
35455
35456 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
35457     tabTip:'',
35458     setRegion : function(C){
35459         this.region = C;
35460         if(C){
35461            this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
35462         }else {
35463            this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
35464         } 
35465     },
35466     
35467     
35468
35469     getToolbar : function(){
35470         return  this.toolbar;
35471     },
35472     
35473     setActiveState : function(D){
35474         this.active = D;
35475         if(!D){
35476             this.fireEvent("deactivate", this);
35477         }else {
35478             this.fireEvent("activate", this);
35479         }
35480     },
35481     
35482
35483     setContent : function(E, F){
35484         this.el.update(E, F);
35485     },
35486
35487     ignoreResize : function(w, h){
35488         if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
35489             return  true;
35490         }else {
35491             this.lastSize = {width: w, height: h};
35492             return  false;
35493         }
35494     },
35495     
35496
35497     getUpdateManager : function(){
35498         return  this.el.getUpdateManager();
35499     },
35500      
35501
35502     load : function(){
35503         var  um = this.el.getUpdateManager();
35504         um.update.apply(um, arguments);
35505         return  this;
35506     },
35507
35508
35509     
35510
35511     setUrl : function(G, H, I){
35512         if(this.refreshDelegate){
35513             this.removeListener("activate", this.refreshDelegate);
35514         }
35515
35516         this.refreshDelegate = this._handleRefresh.createDelegate(this, [G, H, I]);
35517         this.on("activate", this.refreshDelegate);
35518         return  this.el.getUpdateManager();
35519     },
35520     
35521     _handleRefresh : function(J, K, L){
35522         if(!L || !this.loaded){
35523             var  updater = this.el.getUpdateManager();
35524             updater.update(J, K, this._setLoaded.createDelegate(this));
35525         }
35526     },
35527     
35528     _setLoaded : function(){
35529         this.loaded = true;
35530     }, 
35531     
35532     
35533
35534     getId : function(){
35535         return  this.el.id;
35536     },
35537     
35538     
35539
35540     getEl : function(){
35541         return  this.wrapEl || this.el;
35542     },
35543     
35544     adjustForComponents : function(M, N){
35545         if(this.resizeEl != this.el){
35546             M -= this.el.getFrameWidth('lr');
35547             N -= this.el.getFrameWidth('tb');
35548         }
35549         if(this.toolbar){
35550             var  te = this.toolbar.getEl();
35551             N -= te.getHeight();
35552             te.setWidth(M);
35553         }
35554         if(this.adjustments){
35555             M += this.adjustments[0];
35556             N += this.adjustments[1];
35557         }
35558         return  {"width": M, "height": N};
35559     },
35560     
35561     setSize : function(O, P){
35562         if(this.fitToFrame && !this.ignoreResize(O, P)){
35563             if(this.fitContainer && this.resizeEl != this.el){
35564                 this.el.setSize(O, P);
35565             }
35566             var  size = this.adjustForComponents(O, P);
35567             this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
35568             this.fireEvent('resize', this, size.width, size.height);
35569         }
35570     },
35571     
35572     
35573
35574     getTitle : function(){
35575         return  this.title;
35576     },
35577     
35578     
35579
35580     setTitle : function(Q){
35581         this.title = Q;
35582         if(this.region){
35583             this.region.updatePanelTitle(this, Q);
35584         }
35585     },
35586     
35587     
35588
35589     isClosable : function(){
35590         return  this.closable;
35591     },
35592     
35593     beforeSlide : function(){
35594         this.el.clip();
35595         this.resizeEl.clip();
35596     },
35597     
35598     afterSlide : function(){
35599         this.el.unclip();
35600         this.resizeEl.unclip();
35601     },
35602     
35603     
35604
35605     refresh : function(){
35606         if(this.refreshDelegate){
35607            this.loaded = false;
35608            this.refreshDelegate();
35609         }
35610     },
35611     
35612     
35613
35614     destroy : function(){
35615         this.el.removeAllListeners();
35616         var  R = document.createElement("span");
35617         R.appendChild(this.el.dom);
35618         R.innerHTML = "";
35619         this.el.remove();
35620         this.el = null;
35621     },
35622     
35623       
35624
35625     
35626     addxtype : function(S) {
35627         
35628         if (S.xtype.match(/^Form$/)) {
35629             var  el = this.el.createChild();
35630
35631             this.form = new   Roo.form.Form(S);
35632             
35633             
35634             if ( this.form.allItems.length) this.form.render(el.dom);
35635             return  this.form;
35636         }
35637         if (['View', 'JsonView'].indexOf(S.xtype) > -1) {
35638             
35639             S.el = this.el.appendChild(document.createElement("div"));
35640             
35641             var  ret = new  Roo[S.xtype](S);
35642             ret.render(false, ''); 
35643             return  ret;
35644             
35645         }
35646         return  false;
35647         
35648     }
35649 });
35650
35651
35652
35653 Roo.GridPanel = function(T, U){
35654     
35655   
35656     this.wrapper = Roo.DomHelper.append(document.body, 
35657         {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
35658         
35659     this.wrapper.dom.appendChild(T.getGridEl().dom);
35660     
35661     Roo.GridPanel.superclass.constructor.call(this, this.wrapper, U);
35662     
35663     if(this.toolbar){
35664         this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
35665     }
35666     
35667     if (this.footer && !this.footer.el && this.footer.xtype) {
35668         
35669         this.footer.container = this.grid.getView().getFooterPanel(true);
35670         this.footer.dataSource = this.grid.dataSource;
35671         this.footer = Roo.factory(this.footer, Roo);
35672         
35673     }
35674
35675     
35676     T.monitorWindowResize = false; 
35677     T.autoHeight = false;
35678     T.autoWidth = false;
35679     this.grid = T;
35680     this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
35681 };
35682
35683 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
35684     getId : function(){
35685         return  this.grid.id;
35686     },
35687     
35688     
35689
35690     getGrid : function(){
35691         return  this.grid;    
35692     },
35693     
35694     setSize : function(V, W){
35695         if(!this.ignoreResize(V, W)){
35696             var  T = this.grid;
35697             var  size = this.adjustForComponents(V, W);
35698             T.getGridEl().setSize(size.width, size.height);
35699             T.autoSize();
35700         }
35701     },
35702     
35703     beforeSlide : function(){
35704         this.grid.getView().scroller.clip();
35705     },
35706     
35707     afterSlide : function(){
35708         this.grid.getView().scroller.unclip();
35709     },
35710     
35711     destroy : function(){
35712         this.grid.destroy();
35713         delete  this.grid;
35714         Roo.GridPanel.superclass.destroy.call(this); 
35715     }
35716 });
35717
35718
35719
35720
35721 Roo.NestedLayoutPanel = function(X, Y)
35722 {
35723     
35724     
35725
35726     
35727     Roo.NestedLayoutPanel.superclass.constructor.call(this, X.getEl(), Y);
35728     
35729     X.monitorWindowResize = false; 
35730     this.layout = X;
35731     this.layout.getEl().addClass("x-layout-nested-layout");
35732     
35733     
35734     
35735 };
35736
35737 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
35738
35739     setSize : function(Z, a){
35740         if(!this.ignoreResize(Z, a)){
35741             var  size = this.adjustForComponents(Z, a);
35742             var  el = this.layout.getEl();
35743             el.setSize(size.width, size.height);
35744             var  touch = el.dom.offsetWidth;
35745             this.layout.layout();
35746             
35747             if(Roo.isIE && !this.initialized){
35748                 this.initialized = true;
35749                 this.layout.layout();
35750             }
35751         }
35752     },
35753     
35754     
35755     
35756     setActiveState : function(b){
35757         this.active = b;
35758         if(!b){
35759             this.fireEvent("deactivate", this);
35760             return;
35761         }
35762
35763         
35764         this.fireEvent("activate", this);
35765         
35766         if (!this.layout) {
35767             return; 
35768         }
35769         var  c = false;
35770         for (var  r  in  this.layout.regions) {
35771             c = this.layout.getRegion(r);
35772             if (c.getActivePanel()) {
35773                 
35774                 c.setActivePanel(c.getActivePanel());
35775                 continue;
35776             }
35777             if (!c.panels.length) {
35778                 continue;
35779             }
35780
35781             c.showPanel(c.getPanel(0));
35782         }
35783         
35784         
35785         
35786         
35787     },
35788     
35789     
35790
35791     getLayout : function(){
35792         return  this.layout;
35793     },
35794     
35795      
35796
35797     addxtype : function(d) {
35798         return  this.layout.addxtype(d);
35799     
35800     }
35801 });
35802
35803 Roo.ScrollPanel = function(el, e, f){
35804     e = e || {};
35805     e.fitToFrame = true;
35806     Roo.ScrollPanel.superclass.constructor.call(this, el, e, f);
35807     
35808     this.el.dom.style.overflow = "hidden";
35809     var  g = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
35810     this.el.removeClass("x-layout-inactive-content");
35811     this.el.on("mousewheel", this.onWheel, this);
35812
35813     var  up = g.createChild({cls: "x-scroller-up", html: "&#160;"}, this.el.dom);
35814     var  i = g.createChild({cls: "x-scroller-down", html: "&#160;"});
35815     up.unselectable(); i.unselectable();
35816     up.on("click", this.scrollUp, this);
35817     i.on("click", this.scrollDown, this);
35818     up.addClassOnOver("x-scroller-btn-over");
35819     i.addClassOnOver("x-scroller-btn-over");
35820     up.addClassOnClick("x-scroller-btn-click");
35821     i.addClassOnClick("x-scroller-btn-click");
35822     this.adjustments = [0, -(up.getHeight() + i.getHeight())];
35823
35824     this.resizeEl = this.el;
35825     this.el = g; this.up = up; this.down = i;
35826 };
35827
35828 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
35829     increment : 100,
35830     wheelIncrement : 5,
35831     scrollUp : function(){
35832         this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
35833     },
35834
35835     scrollDown : function(){
35836         this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
35837     },
35838
35839     afterScroll : function(){
35840         var  el = this.resizeEl;
35841         var  t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
35842         this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
35843         this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
35844     },
35845
35846     setSize : function(){
35847         Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
35848         this.afterScroll();
35849     },
35850
35851     onWheel : function(e){
35852         var  d = e.getWheelDelta();
35853         this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
35854         this.afterScroll();
35855         e.stopEvent();
35856     },
35857
35858     setContent : function(j, k){
35859         this.resizeEl.update(j, k);
35860     }
35861
35862 });
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874 Roo.TreePanel = function(l){
35875     var  el = l.el;
35876     var  m = l.tree;
35877     delete  l.tree; 
35878     delete  l.el; 
35879     Roo.TreePanel.superclass.constructor.call(this, el, l);
35880     var  n = el.createChild();
35881     this.tree = new  Roo.tree.TreePanel(n , m);
35882     
35883     this.on('activate', function()
35884     {
35885         if (this.tree.rendered) {
35886             return;
35887         }
35888
35889         
35890         this.tree.render();
35891     });
35892     
35893     this.on('resize',  function (cp, w, h) {
35894             this.tree.innerCt.setWidth(w);
35895             this.tree.innerCt.setHeight(h);
35896             this.tree.innerCt.setStyle('overflow-y', 'auto');
35897     });
35898
35899         
35900     
35901 };
35902
35903 Roo.extend(Roo.TreePanel, Roo.ContentPanel);
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918  
35919
35920
35921
35922 Roo.ReaderLayout = function(A, B){
35923     var  c = A || {size:{}};
35924     Roo.ReaderLayout.superclass.constructor.call(this, B || document.body, {
35925         north: c.north !== false ? Roo.apply({
35926             split:false,
35927             initialSize: 32,
35928             titlebar: false
35929         }, c.north) : false,
35930         west: c.west !== false ? Roo.apply({
35931             split:true,
35932             initialSize: 200,
35933             minSize: 175,
35934             maxSize: 400,
35935             titlebar: true,
35936             collapsible: true,
35937             animate: true,
35938             margins:{left:5,right:0,bottom:5,top:5},
35939             cmargins:{left:5,right:5,bottom:5,top:5}
35940         }, c.west) : false,
35941         east: c.east !== false ? Roo.apply({
35942             split:true,
35943             initialSize: 200,
35944             minSize: 175,
35945             maxSize: 400,
35946             titlebar: true,
35947             collapsible: true,
35948             animate: true,
35949             margins:{left:0,right:5,bottom:5,top:5},
35950             cmargins:{left:5,right:5,bottom:5,top:5}
35951         }, c.east) : false,
35952         center: Roo.apply({
35953             tabPosition: 'top',
35954             autoScroll:false,
35955             closeOnTab: true,
35956             titlebar:false,
35957             margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
35958         }, c.center)
35959     });
35960
35961     this.el.addClass('x-reader');
35962
35963     this.beginUpdate();
35964
35965     var  C = new  Roo.BorderLayout(Roo.get(document.body).createChild(), {
35966         south: c.preview !== false ? Roo.apply({
35967             split:true,
35968             initialSize: 200,
35969             minSize: 100,
35970             autoScroll:true,
35971             collapsible:true,
35972             titlebar: true,
35973             cmargins:{top:5,left:0, right:0, bottom:0}
35974         }, c.preview) : false,
35975         center: Roo.apply({
35976             autoScroll:false,
35977             titlebar:false,
35978             minHeight:200
35979         }, c.listView)
35980     });
35981     this.add('center', new  Roo.NestedLayoutPanel(C,
35982             Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
35983
35984     this.endUpdate();
35985
35986     this.regions.preview = C.getRegion('south');
35987     this.regions.listView = C.getRegion('center');
35988 };
35989
35990 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);
35991
35992
35993  
35994
35995
35996 Roo.grid.Grid = function(A, B){
35997         
35998         this.container = Roo.get(A);
35999         this.container.update("");
36000         this.container.setStyle("overflow", "hidden");
36001     this.container.addClass('x-grid-container');
36002
36003     this.id = this.container.id;
36004
36005     Roo.apply(this, B);
36006     
36007     if(this.ds){
36008         this.dataSource = this.ds;
36009         delete  this.ds;
36010     }
36011     if(this.cm){
36012         this.colModel = this.cm;
36013         delete  this.cm;
36014     }
36015     if(this.sm){
36016         this.selModel = this.sm;
36017         delete  this.sm;
36018     }
36019
36020     if (this.selModel) {
36021         this.selModel = Roo.factory(this.selModel, Roo.grid);
36022         this.sm = this.selModel;
36023         this.sm.xmodule = this.xmodule || false;
36024     }
36025     if (typeof(this.colModel.config) == 'undefined') {
36026         this.colModel = new  Roo.grid.ColumnModel(this.colModel);
36027         this.cm = this.colModel;
36028         this.cm.xmodule = this.xmodule || false;
36029     }
36030     if (this.dataSource) {
36031         this.dataSource= Roo.factory(this.dataSource, Roo.data);
36032         this.ds = this.dataSource;
36033         this.ds.xmodule = this.xmodule || false;
36034         
36035     }
36036     
36037     
36038     
36039     if(this.width){
36040         this.container.setWidth(this.width);
36041     }
36042
36043     if(this.height){
36044         this.container.setHeight(this.height);
36045     }
36046
36047     
36048
36049         this.addEvents({
36050             
36051             
36052
36053             "click" : true,
36054             
36055
36056             "dblclick" : true,
36057             
36058
36059             "contextmenu" : true,
36060             
36061
36062             "mousedown" : true,
36063             
36064
36065             "mouseup" : true,
36066             
36067
36068             "mouseover" : true,
36069             
36070
36071             "mouseout" : true,
36072             
36073
36074             "keypress" : true,
36075             
36076
36077             "keydown" : true,
36078
36079             
36080
36081             
36082
36083             "cellclick" : true,
36084             
36085
36086             "celldblclick" : true,
36087             
36088
36089             "rowclick" : true,
36090             
36091
36092             "rowdblclick" : true,
36093             
36094
36095             "headerclick" : true,
36096             
36097
36098             "headerdblclick" : true,
36099             
36100
36101             "rowcontextmenu" : true,
36102             
36103
36104          "cellcontextmenu" : true,
36105             
36106
36107             "headercontextmenu" : true,
36108             
36109
36110             "bodyscroll" : true,
36111             
36112
36113             "columnresize" : true,
36114             
36115
36116             "columnmove" : true,
36117             
36118
36119             "startdrag" : true,
36120             
36121
36122             "enddrag" : true,
36123             
36124
36125             "dragdrop" : true,
36126             
36127
36128             "dragover" : true,
36129             
36130
36131             "dragenter" : true,
36132             
36133
36134             "dragout" : true,
36135         
36136
36137         render : true
36138     });
36139
36140     Roo.grid.Grid.superclass.constructor.call(this);
36141 };
36142 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
36143     
36144
36145         minColumnWidth : 25,
36146
36147     
36148
36149         autoSizeColumns : false,
36150
36151         
36152
36153         autoSizeHeaders : true,
36154
36155         
36156
36157         monitorWindowResize : true,
36158
36159         
36160
36161         maxRowsToMeasure : 0,
36162
36163         
36164
36165         trackMouseOver : true,
36166
36167         
36168
36169         enableDragDrop : false,
36170
36171         
36172
36173         enableColumnMove : true,
36174
36175         
36176
36177         enableColumnHide : true,
36178
36179         
36180
36181         enableRowHeightSync : false,
36182
36183         
36184
36185         stripeRows : true,
36186
36187         
36188
36189         autoHeight : false,
36190
36191     
36192
36193     autoExpandColumn : false,
36194
36195     
36196
36197     autoExpandMin : 50,
36198
36199     
36200
36201     autoExpandMax : 1000,
36202
36203     
36204
36205         view : null,
36206
36207         
36208
36209         loadMask : false,
36210
36211     
36212     rendered : false,
36213
36214     
36215
36216     
36217
36218     
36219
36220     render : function(){
36221         var  c = this.container;
36222         
36223         if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
36224             this.autoHeight = true;
36225         }
36226         var  C = this.getView();
36227         C.init(this);
36228
36229         c.on("click", this.onClick, this);
36230         c.on("dblclick", this.onDblClick, this);
36231         c.on("contextmenu", this.onContextMenu, this);
36232         c.on("keydown", this.onKeyDown, this);
36233
36234         this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
36235
36236         this.getSelectionModel().init(this);
36237
36238         C.render();
36239
36240         if(this.loadMask){
36241             this.loadMask = new  Roo.LoadMask(this.container,
36242                     Roo.apply({store:this.dataSource}, this.loadMask));
36243         }
36244         
36245         
36246         if (this.toolbar && this.toolbar.xtype) {
36247             this.toolbar.container = this.getView().getHeaderPanel(true);
36248             this.toolbar = new  Ext.Toolbar(this.toolbar);
36249         }
36250         if (this.footer && this.footer.xtype) {
36251             this.footer.dataSource = this.getDataSource();
36252             this.footer.container = this.getView().getFooterPanel(true);
36253             this.footer = Roo.factory(this.footer, Roo);
36254         }
36255
36256         this.rendered = true;
36257         this.fireEvent('render', this);
36258         return  this;
36259     },
36260
36261         
36262
36263     reconfigure : function(D, E){
36264         if(this.loadMask){
36265             this.loadMask.destroy();
36266             this.loadMask = new  Roo.LoadMask(this.container,
36267                     Roo.apply({store:D}, this.loadMask));
36268         }
36269
36270         this.view.bind(D, E);
36271         this.dataSource = D;
36272         this.colModel = E;
36273         this.view.refresh(true);
36274     },
36275
36276     
36277     onKeyDown : function(e){
36278         this.fireEvent("keydown", e);
36279     },
36280
36281     
36282
36283     destroy : function(F, G){
36284         if(this.loadMask){
36285             this.loadMask.destroy();
36286         }
36287         var  c = this.container;
36288         c.removeAllListeners();
36289         this.view.destroy();
36290         this.colModel.purgeListeners();
36291         if(!G){
36292             this.purgeListeners();
36293         }
36294
36295         c.update("");
36296         if(F === true){
36297             c.remove();
36298         }
36299     },
36300
36301     
36302     processEvent : function(H, e){
36303         this.fireEvent(H, e);
36304         var  t = e.getTarget();
36305         var  v = this.view;
36306         var  I = v.findHeaderIndex(t);
36307         if(I !== false){
36308             this.fireEvent("header" + H, this, I, e);
36309         }else {
36310             var  row = v.findRowIndex(t);
36311             var  cell = v.findCellIndex(t);
36312             if(row !== false){
36313                 this.fireEvent("row" + H, this, row, e);
36314                 if(cell !== false){
36315                     this.fireEvent("cell" + H, this, row, cell, e);
36316                 }
36317             }
36318         }
36319     },
36320
36321     
36322     onClick : function(e){
36323         this.processEvent("click", e);
36324     },
36325
36326     
36327     onContextMenu : function(e, t){
36328         this.processEvent("contextmenu", e);
36329     },
36330
36331     
36332     onDblClick : function(e){
36333         this.processEvent("dblclick", e);
36334     },
36335
36336     
36337     walkCells : function(J, K, L, fn, M){
36338         var  cm = this.colModel, N = cm.getColumnCount();
36339         var  ds = this.dataSource, O = ds.getCount(), P = true;
36340         if(L < 0){
36341             if(K < 0){
36342                 J--;
36343                 P = false;
36344             }
36345             while(J >= 0){
36346                 if(!P){
36347                     K = N-1;
36348                 }
36349
36350                 P = false;
36351                 while(K >= 0){
36352                     if(fn.call(M || this, J, K, cm) === true){
36353                         return  [J, K];
36354                     }
36355
36356                     K--;
36357                 }
36358
36359                 J--;
36360             }
36361         } else  {
36362             if(K >= N){
36363                 J++;
36364                 P = false;
36365             }
36366             while(J < O){
36367                 if(!P){
36368                     K = 0;
36369                 }
36370
36371                 P = false;
36372                 while(K < N){
36373                     if(fn.call(M || this, J, K, cm) === true){
36374                         return  [J, K];
36375                     }
36376
36377                     K++;
36378                 }
36379
36380                 J++;
36381             }
36382         }
36383         return  null;
36384     },
36385
36386     
36387     getSelections : function(){
36388         return  this.selModel.getSelections();
36389     },
36390
36391     
36392
36393     autoSize : function(){
36394         if(this.rendered){
36395             this.view.layout();
36396             if(this.view.adjustForScroll){
36397                 this.view.adjustForScroll();
36398             }
36399         }
36400     },
36401
36402     
36403
36404     getGridEl : function(){
36405         return  this.container;
36406     },
36407
36408     
36409     stopEditing : function(){},
36410
36411     
36412
36413     getSelectionModel : function(){
36414         if(!this.selModel){
36415             this.selModel = new  Roo.grid.RowSelectionModel();
36416         }
36417         return  this.selModel;
36418     },
36419
36420     
36421
36422     getDataSource : function(){
36423         return  this.dataSource;
36424     },
36425
36426     
36427
36428     getColumnModel : function(){
36429         return  this.colModel;
36430     },
36431
36432     
36433
36434     getView : function(){
36435         if(!this.view){
36436             this.view = new  Roo.grid.GridView(this.viewConfig);
36437         }
36438         return  this.view;
36439     },
36440     
36441
36442     getDragDropText : function(){
36443         var  Q = this.selModel.getCount();
36444         return  String.format(this.ddText, Q, Q == 1 ? '' : 's');
36445     }
36446 });
36447
36448
36449 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";
36450
36451
36452  
36453 Roo.grid.AbstractGridView = function(){
36454         this.grid = null;
36455         
36456         this.events = {
36457             "beforerowremoved" : true,
36458             "beforerowsinserted" : true,
36459             "beforerefresh" : true,
36460             "rowremoved" : true,
36461             "rowsinserted" : true,
36462             "rowupdated" : true,
36463             "refresh" : true
36464         };
36465     Roo.grid.AbstractGridView.superclass.constructor.call(this);
36466 };
36467
36468 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
36469     rowClass : "x-grid-row",
36470     cellClass : "x-grid-cell",
36471     tdClass : "x-grid-td",
36472     hdClass : "x-grid-hd",
36473     splitClass : "x-grid-hd-split",
36474     
36475         init: function(A){
36476         this.grid = A;
36477                 var  B = this.grid.getGridEl().id;
36478         this.colSelector = "#" + B + " ." + this.cellClass + "-";
36479         this.tdSelector = "#" + B + " ." + this.tdClass + "-";
36480         this.hdSelector = "#" + B + " ." + this.hdClass + "-";
36481         this.splitSelector = "#" + B + " ." + this.splitClass + "-";
36482         },
36483         
36484         getColumnRenderers : function(){
36485         var  C = [];
36486         var  cm = this.grid.colModel;
36487         var  D = cm.getColumnCount();
36488         for(var  i = 0; i < D; i++){
36489             C[i] = cm.getRenderer(i);
36490         }
36491         return  C;
36492     },
36493     
36494     getColumnIds : function(){
36495         var  E = [];
36496         var  cm = this.grid.colModel;
36497         var  F = cm.getColumnCount();
36498         for(var  i = 0; i < F; i++){
36499             E[i] = cm.getColumnId(i);
36500         }
36501         return  E;
36502     },
36503     
36504     getDataIndexes : function(){
36505         if(!this.indexMap){
36506             this.indexMap = this.buildIndexMap();
36507         }
36508         return  this.indexMap.colToData;
36509     },
36510     
36511     getColumnIndexByDataIndex : function(G){
36512         if(!this.indexMap){
36513             this.indexMap = this.buildIndexMap();
36514         }
36515         return  this.indexMap.dataToCol[G];
36516     },
36517     
36518     
36519
36520     setCSSStyle : function(H, I, J){
36521         var  K = "#" + this.grid.id + " .x-grid-col-" + H;
36522         Roo.util.CSS.updateRule(K, I, J);
36523     },
36524     
36525     generateRules : function(cm){
36526         var  L = [], M = this.grid.id + '-cssrules';
36527         Roo.util.CSS.removeStyleSheet(M);
36528         for(var  i = 0, len = cm.getColumnCount(); i < len; i++){
36529             var  B = cm.getColumnId(i);
36530             L.push(this.colSelector, B, " {\n", cm.config[i].css, "}\n",
36531                          this.tdSelector, B, " {\n}\n",
36532                          this.hdSelector, B, " {\n}\n",
36533                          this.splitSelector, B, " {\n}\n");
36534         }
36535         return  Roo.util.CSS.createStyleSheet(L.join(""), M);
36536     }
36537 });
36538
36539
36540
36541
36542
36543 Roo.grid.HeaderDragZone = function(A, hd, B){
36544     this.grid = A;
36545     this.view = A.getView();
36546     this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
36547     Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
36548     if(B){
36549         this.setHandleElId(Roo.id(hd));
36550         this.setOuterHandleElId(Roo.id(B));
36551     }
36552
36553     this.scroll = false;
36554 };
36555 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
36556     maxDragWidth: 120,
36557     getDragData : function(e){
36558         var  t = Roo.lib.Event.getTarget(e);
36559         var  h = this.view.findHeaderCell(t);
36560         if(h){
36561             return  {ddel: h.firstChild, header:h};
36562         }
36563         return  false;
36564     },
36565
36566     onInitDrag : function(e){
36567         this.view.headersDisabled = true;
36568         var  C = this.dragData.ddel.cloneNode(true);
36569         C.id = Roo.id();
36570         C.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
36571         this.proxy.update(C);
36572         return  true;
36573     },
36574
36575     afterValidDrop : function(){
36576         var  v = this.view;
36577         setTimeout(function(){
36578             v.headersDisabled = false;
36579         }, 50);
36580     },
36581
36582     afterInvalidDrop : function(){
36583         var  v = this.view;
36584         setTimeout(function(){
36585             v.headersDisabled = false;
36586         }, 50);
36587     }
36588 });
36589
36590
36591
36592
36593
36594 Roo.grid.HeaderDropZone = function(A, hd, B){
36595     this.grid = A;
36596     this.view = A.getView();
36597     
36598     this.proxyTop = Roo.DomHelper.append(document.body, {
36599         cls:"col-move-top", html:"&#160;"
36600     }, true);
36601     this.proxyBottom = Roo.DomHelper.append(document.body, {
36602         cls:"col-move-bottom", html:"&#160;"
36603     }, true);
36604     this.proxyTop.hide = this.proxyBottom.hide = function(){
36605         this.setLeftTop(-100,-100);
36606         this.setStyle("visibility", "hidden");
36607     };
36608     this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
36609     
36610     
36611     Roo.grid.HeaderDropZone.superclass.constructor.call(this, A.getGridEl().dom);
36612 };
36613 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
36614     proxyOffsets : [-4, -9],
36615     fly: Roo.Element.fly,
36616
36617     getTargetFromEvent : function(e){
36618         var  t = Roo.lib.Event.getTarget(e);
36619         var  C = this.view.findCellIndex(t);
36620         if(C !== false){
36621             return  this.view.getHeaderCell(C);
36622         }
36623     },
36624
36625     nextVisible : function(h){
36626         var  v = this.view, cm = this.grid.colModel;
36627         h = h.nextSibling;
36628         while(h){
36629             if(!cm.isHidden(v.getCellIndex(h))){
36630                 return  h;
36631             }
36632
36633             h = h.nextSibling;
36634         }
36635         return  null;
36636     },
36637
36638     prevVisible : function(h){
36639         var  v = this.view, cm = this.grid.colModel;
36640         h = h.prevSibling;
36641         while(h){
36642             if(!cm.isHidden(v.getCellIndex(h))){
36643                 return  h;
36644             }
36645
36646             h = h.prevSibling;
36647         }
36648         return  null;
36649     },
36650
36651     positionIndicator : function(h, n, e){
36652         var  x = Roo.lib.Event.getPageX(e);
36653         var  r = Roo.lib.Dom.getRegion(n.firstChild);
36654         var  px, pt, py = r.top + this.proxyOffsets[1];
36655         if((r.right - x) <= (r.right-r.left)/2){
36656             px = r.right+this.view.borderWidth;
36657             pt = "after";
36658         }else {
36659             px = r.left;
36660             pt = "before";
36661         }
36662         var  D = this.view.getCellIndex(h);
36663         var  E = this.view.getCellIndex(n);
36664
36665         if(this.grid.colModel.isFixed(E)){
36666             return  false;
36667         }
36668
36669         var  F = this.grid.colModel.isLocked(E);
36670
36671         if(pt == "after"){
36672             E++;
36673         }
36674         if(D < E){
36675             E--;
36676         }
36677         if(D == E && (F == this.grid.colModel.isLocked(D))){
36678             return  false;
36679         }
36680
36681         px +=  this.proxyOffsets[0];
36682         this.proxyTop.setLeftTop(px, py);
36683         this.proxyTop.show();
36684         if(!this.bottomOffset){
36685             this.bottomOffset = this.view.mainHd.getHeight();
36686         }
36687
36688         this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
36689         this.proxyBottom.show();
36690         return  pt;
36691     },
36692
36693     onNodeEnter : function(n, dd, e, G){
36694         if(G.header != n){
36695             this.positionIndicator(G.header, n, e);
36696         }
36697     },
36698
36699     onNodeOver : function(n, dd, e, H){
36700         var  I = false;
36701         if(H.header != n){
36702             I = this.positionIndicator(H.header, n, e);
36703         }
36704         if(!I){
36705             this.proxyTop.hide();
36706             this.proxyBottom.hide();
36707         }
36708         return  I ? this.dropAllowed : this.dropNotAllowed;
36709     },
36710
36711     onNodeOut : function(n, dd, e, J){
36712         this.proxyTop.hide();
36713         this.proxyBottom.hide();
36714     },
36715
36716     onNodeDrop : function(n, dd, e, K){
36717         var  h = K.header;
36718         if(h != n){
36719             var  cm = this.grid.colModel;
36720             var  x = Roo.lib.Event.getPageX(e);
36721             var  r = Roo.lib.Dom.getRegion(n.firstChild);
36722             var  pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
36723             var  D = this.view.getCellIndex(h);
36724             var  E = this.view.getCellIndex(n);
36725             var  F = cm.isLocked(E);
36726             if(pt == "after"){
36727                 E++;
36728             }
36729             if(D < E){
36730                 E--;
36731             }
36732             if(D == E && (F == cm.isLocked(D))){
36733                 return  false;
36734             }
36735
36736             cm.setLocked(D, F, true);
36737             cm.moveColumn(D, E);
36738             this.grid.fireEvent("columnmove", D, E);
36739             return  true;
36740         }
36741         return  false;
36742     }
36743 });
36744
36745
36746
36747   
36748
36749
36750 Roo.grid.GridView = function(A){
36751     Roo.grid.GridView.superclass.constructor.call(this);
36752     this.el = null;
36753
36754     Roo.apply(this, A);
36755 };
36756
36757 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
36758
36759     
36760
36761     rowClass : "x-grid-row",
36762
36763     cellClass : "x-grid-col",
36764
36765     tdClass : "x-grid-td",
36766
36767     hdClass : "x-grid-hd",
36768
36769     splitClass : "x-grid-split",
36770
36771     sortClasses : ["sort-asc", "sort-desc"],
36772
36773     enableMoveAnim : false,
36774
36775     hlColor: "C3DAF9",
36776
36777     dh : Roo.DomHelper,
36778
36779     fly : Roo.Element.fly,
36780
36781     css : Roo.util.CSS,
36782
36783     borderWidth: 1,
36784
36785     splitOffset: 3,
36786
36787     scrollIncrement : 22,
36788
36789     cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
36790
36791     findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
36792
36793     bind : function(ds, cm){
36794         if(this.ds){
36795             this.ds.un("load", this.onLoad, this);
36796             this.ds.un("datachanged", this.onDataChange, this);
36797             this.ds.un("add", this.onAdd, this);
36798             this.ds.un("remove", this.onRemove, this);
36799             this.ds.un("update", this.onUpdate, this);
36800             this.ds.un("clear", this.onClear, this);
36801         }
36802         if(ds){
36803             ds.on("load", this.onLoad, this);
36804             ds.on("datachanged", this.onDataChange, this);
36805             ds.on("add", this.onAdd, this);
36806             ds.on("remove", this.onRemove, this);
36807             ds.on("update", this.onUpdate, this);
36808             ds.on("clear", this.onClear, this);
36809         }
36810
36811         this.ds = ds;
36812
36813         if(this.cm){
36814             this.cm.un("widthchange", this.onColWidthChange, this);
36815             this.cm.un("headerchange", this.onHeaderChange, this);
36816             this.cm.un("hiddenchange", this.onHiddenChange, this);
36817             this.cm.un("columnmoved", this.onColumnMove, this);
36818             this.cm.un("columnlockchange", this.onColumnLock, this);
36819         }
36820         if(cm){
36821             this.generateRules(cm);
36822             cm.on("widthchange", this.onColWidthChange, this);
36823             cm.on("headerchange", this.onHeaderChange, this);
36824             cm.on("hiddenchange", this.onHiddenChange, this);
36825             cm.on("columnmoved", this.onColumnMove, this);
36826             cm.on("columnlockchange", this.onColumnLock, this);
36827         }
36828
36829         this.cm = cm;
36830     },
36831
36832     init: function(B){
36833                 Roo.grid.GridView.superclass.init.call(this, B);
36834
36835                 this.bind(B.dataSource, B.colModel);
36836
36837             B.on("headerclick", this.handleHeaderClick, this);
36838
36839         if(B.trackMouseOver){
36840             B.on("mouseover", this.onRowOver, this);
36841                 B.on("mouseout", this.onRowOut, this);
36842             }
36843
36844             B.cancelTextSelection = function(){};
36845                 this.gridId = B.id;
36846
36847                 var  C = this.templates || {};
36848
36849                 if(!C.master){
36850                     C.master = new  Roo.Template(
36851                        '<div class="x-grid" hidefocus="true">',
36852                           '<div class="x-grid-topbar"></div>',
36853                           '<div class="x-grid-scroller"><div></div></div>',
36854                           '<div class="x-grid-locked">',
36855                               '<div class="x-grid-header">{lockedHeader}</div>',
36856                               '<div class="x-grid-body">{lockedBody}</div>',
36857                           "</div>",
36858                           '<div class="x-grid-viewport">',
36859                               '<div class="x-grid-header">{header}</div>',
36860                               '<div class="x-grid-body">{body}</div>',
36861                           "</div>",
36862                           '<div class="x-grid-bottombar"></div>',
36863                           '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
36864                           '<div class="x-grid-resize-proxy">&#160;</div>',
36865                        "</div>"
36866                     );
36867                     C.master.disableformats = true;
36868                 }
36869
36870                 if(!C.header){
36871                     C.header = new  Roo.Template(
36872                        '<table border="0" cellspacing="0" cellpadding="0">',
36873                        '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
36874                        "</table>{splits}"
36875                     );
36876                     C.header.disableformats = true;
36877                 }
36878
36879                 C.header.compile();
36880
36881                 if(!C.hcell){
36882                     C.hcell = new  Roo.Template(
36883                         '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
36884                         '<div class="x-grid-hd-text" unselectable="on">{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
36885                         "</div></td>"
36886                      );
36887                      C.hcell.disableFormats = true;
36888                 }
36889
36890                 C.hcell.compile();
36891
36892                 if(!C.hsplit){
36893                     C.hsplit = new  Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style}" unselectable="on">&#160;</div>');
36894                     C.hsplit.disableFormats = true;
36895                 }
36896
36897                 C.hsplit.compile();
36898
36899                 if(!C.body){
36900                     C.body = new  Roo.Template(
36901                        '<table border="0" cellspacing="0" cellpadding="0">',
36902                        "<tbody>{rows}</tbody>",
36903                        "</table>"
36904                     );
36905                     C.body.disableFormats = true;
36906                 }
36907
36908                 C.body.compile();
36909
36910                 if(!C.row){
36911                     C.row = new  Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
36912                     C.row.disableFormats = true;
36913                 }
36914
36915                 C.row.compile();
36916
36917                 if(!C.cell){
36918                     C.cell = new  Roo.Template(
36919                         '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
36920                         '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text" unselectable="on" {attr}>{value}</div></div>',
36921                         "</td>"
36922                     );
36923             C.cell.disableFormats = true;
36924         }
36925
36926                 C.cell.compile();
36927
36928                 this.templates = C;
36929         },
36930
36931         
36932     onColWidthChange : function(){
36933         this.updateColumns.apply(this, arguments);
36934     },
36935     onHeaderChange : function(){
36936         this.updateHeaders.apply(this, arguments);
36937     }, 
36938     onHiddenChange : function(){
36939         this.handleHiddenChange.apply(this, arguments);
36940     },
36941     onColumnMove : function(){
36942         this.handleColumnMove.apply(this, arguments);
36943     },
36944     onColumnLock : function(){
36945         this.handleLockChange.apply(this, arguments);
36946     },
36947
36948     onDataChange : function(){
36949         this.refresh();
36950         this.updateHeaderSortState();
36951     },
36952
36953         onClear : function(){
36954         this.refresh();
36955     },
36956
36957         onUpdate : function(ds, D){
36958         this.refreshRow(D);
36959     },
36960
36961     refreshRow : function(E){
36962         var  ds = this.ds, F;
36963         if(typeof  E == 'number'){
36964             F = E;
36965             E = ds.getAt(F);
36966         }else {
36967             F = ds.indexOf(E);
36968         }
36969
36970         this.insertRows(ds, F, F, true);
36971         this.onRemove(ds, E, F+1, true);
36972         this.syncRowHeights(F, F);
36973         this.layout();
36974         this.fireEvent("rowupdated", this, F, E);
36975     },
36976
36977     onAdd : function(ds, G, H){
36978         this.insertRows(ds, H, H + (G.length-1));
36979     },
36980
36981     onRemove : function(ds, I, J, K){
36982         if(K !== true){
36983             this.fireEvent("beforerowremoved", this, J, I);
36984         }
36985         var  bt = this.getBodyTable(), lt = this.getLockedTable();
36986         if(bt.rows[J]){
36987             bt.firstChild.removeChild(bt.rows[J]);
36988         }
36989         if(lt.rows[J]){
36990             lt.firstChild.removeChild(lt.rows[J]);
36991         }
36992         if(K !== true){
36993             this.stripeRows(J);
36994             this.syncRowHeights(J, J);
36995             this.layout();
36996             this.fireEvent("rowremoved", this, J, I);
36997         }
36998     },
36999
37000     onLoad : function(){
37001         this.scrollToTop();
37002     },
37003
37004     
37005
37006     scrollToTop : function(){
37007         if(this.scroller){
37008             this.scroller.dom.scrollTop = 0;
37009             this.syncScroll();
37010         }
37011     },
37012
37013     
37014
37015     getHeaderPanel : function(L){
37016         if(L){
37017             this.headerPanel.show();
37018         }
37019         return  this.headerPanel;
37020         },
37021
37022         
37023
37024     getFooterPanel : function(M){
37025         if(M){
37026             this.footerPanel.show();
37027         }
37028         return  this.footerPanel;
37029         },
37030
37031         initElements : function(){
37032             var  E = Roo.Element;
37033             var  el = this.grid.getGridEl().dom.firstChild;
37034             var  cs = el.childNodes;
37035
37036             this.el = new  E(el);
37037             this.headerPanel = new  E(el.firstChild);
37038             this.headerPanel.enableDisplayMode("block");
37039
37040         this.scroller = new  E(cs[1]);
37041             this.scrollSizer = new  E(this.scroller.dom.firstChild);
37042
37043             this.lockedWrap = new  E(cs[2]);
37044             this.lockedHd = new  E(this.lockedWrap.dom.firstChild);
37045             this.lockedBody = new  E(this.lockedWrap.dom.childNodes[1]);
37046
37047             this.mainWrap = new  E(cs[3]);
37048             this.mainHd = new  E(this.mainWrap.dom.firstChild);
37049             this.mainBody = new  E(this.mainWrap.dom.childNodes[1]);
37050
37051             this.footerPanel = new  E(cs[4]);
37052             this.footerPanel.enableDisplayMode("block");
37053
37054         this.focusEl = new  E(cs[5]);
37055         this.focusEl.swallowEvent("click", true);
37056         this.resizeProxy = new  E(cs[6]);
37057
37058             this.headerSelector = String.format(
37059                '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
37060                this.lockedHd.id, this.mainHd.id
37061             );
37062
37063             this.splitterSelector = String.format(
37064                '#{0} div.x-grid-split, #{1} div.x-grid-split',
37065                this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
37066             );
37067     },
37068     idToCssName : function(s)
37069     {
37070         return  s.replace(/[^a-z0-9]+/ig, '-');
37071     },
37072
37073         getHeaderCell : function(N){
37074             return  Roo.DomQuery.select(this.headerSelector)[N];
37075         },
37076
37077         getHeaderCellMeasure : function(O){
37078             return  this.getHeaderCell(O).firstChild;
37079         },
37080
37081         getHeaderCellText : function(P){
37082             return  this.getHeaderCell(P).firstChild.firstChild;
37083         },
37084
37085         getLockedTable : function(){
37086             return  this.lockedBody.dom.firstChild;
37087         },
37088
37089         getBodyTable : function(){
37090             return  this.mainBody.dom.firstChild;
37091         },
37092
37093         getLockedRow : function(Q){
37094             return  this.getLockedTable().rows[Q];
37095         },
37096
37097         getRow : function(R){
37098             return  this.getBodyTable().rows[R];
37099         },
37100
37101         getRowComposite : function(S){
37102             if(!this.rowEl){
37103                 this.rowEl = new  Roo.CompositeElementLite();
37104             }
37105         var  T = [], U, V;
37106         if(U = this.getLockedRow(S)){
37107             T.push(U);
37108         }
37109         if(V = this.getRow(S)){
37110             T.push(V);
37111         }
37112
37113         this.rowEl.elements = T;
37114             return  this.rowEl;
37115         },
37116
37117         getCell : function(W, X){
37118             var  Y = this.cm.getLockedCount();
37119             var  Z;
37120             if(X < Y){
37121                 Z = this.lockedBody.dom.firstChild;
37122             }else {
37123                 Z = this.mainBody.dom.firstChild;
37124                 X -= Y;
37125             }
37126         return  Z.rows[W].childNodes[X];
37127         },
37128
37129         getCellText : function(a, b){
37130             return  this.getCell(a, b).firstChild.firstChild;
37131         },
37132
37133         getCellBox : function(c){
37134             var  b = this.fly(c).getBox();
37135         if(Roo.isOpera){ 
37136             b.y = c.offsetTop + this.mainBody.getY();
37137         }
37138         return  b;
37139     },
37140
37141     getCellIndex : function(d){
37142         var  id = String(d.className).match(this.cellRE);
37143         if(id){
37144             return  parseInt(id[1], 10);
37145         }
37146         return  0;
37147     },
37148
37149     findHeaderIndex : function(n){
37150         var  r = Roo.fly(n).findParent("td." + this.hdClass, 6);
37151         return  r ? this.getCellIndex(r) : false;
37152     },
37153
37154     findHeaderCell : function(n){
37155         var  r = Roo.fly(n).findParent("td." + this.hdClass, 6);
37156         return  r ? r : false;
37157     },
37158
37159     findRowIndex : function(n){
37160         if(!n){
37161             return  false;
37162         }
37163         var  r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
37164         return  r ? r.rowIndex : false;
37165     },
37166
37167     findCellIndex : function(e){
37168         var  f = this.el.dom;
37169         while(e && e != f){
37170             if(this.findRE.test(e.className)){
37171                 return  this.getCellIndex(e);
37172             }
37173
37174             e = e.parentNode;
37175         }
37176         return  false;
37177     },
37178
37179     getColumnId : function(g){
37180             return  this.cm.getColumnId(g);
37181         },
37182
37183         getSplitters : function(){
37184             if(this.splitterSelector){
37185                return  Roo.DomQuery.select(this.splitterSelector);
37186             }else {
37187                 return  null;
37188             }
37189         },
37190
37191         getSplitter : function(k){
37192             return  this.getSplitters()[k];
37193         },
37194
37195     onRowOver : function(e, t){
37196         var  o;
37197         if((o = this.findRowIndex(t)) !== false){
37198             this.getRowComposite(o).addClass("x-grid-row-over");
37199         }
37200     },
37201
37202     onRowOut : function(e, t){
37203         var  p;
37204         if((p = this.findRowIndex(t)) !== false && p !== this.findRowIndex(e.getRelatedTarget())){
37205             this.getRowComposite(p).removeClass("x-grid-row-over");
37206         }
37207     },
37208
37209     renderHeaders : function(){
37210             var  cm = this.cm;
37211         var  ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
37212         var  cb = [], lb = [], sb = [], q = [], p = {};
37213         for(var  i = 0, len = cm.getColumnCount(); i < len; i++){
37214             p.cellId = "x-grid-hd-0-" + i;
37215             p.splitId = "x-grid-csplit-0-" + i;
37216             p.id = cm.getColumnId(i);
37217             p.title = cm.getColumnTooltip(i) || "";
37218             p.value = cm.getColumnHeader(i) || "";
37219             p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
37220             if(!cm.isLocked(i)){
37221                 cb[cb.length] = ct.apply(p);
37222                 sb[sb.length] = st.apply(p);
37223             }else {
37224                 lb[lb.length] = ct.apply(p);
37225                 q[q.length] = st.apply(p);
37226             }
37227         }
37228         return  [ht.apply({cells: lb.join(""), splits:q.join("")}),
37229                 ht.apply({cells: cb.join(""), splits:sb.join("")})];
37230         },
37231
37232         updateHeaders : function(){
37233         var  u = this.renderHeaders();
37234         this.lockedHd.update(u[0]);
37235         this.mainHd.update(u[1]);
37236     },
37237
37238     
37239
37240     focusRow : function(v){
37241         var  x = this.scroller.dom.scrollLeft;
37242         this.focusCell(v, 0, false);
37243         this.scroller.dom.scrollLeft = x;
37244     },
37245
37246     
37247
37248     focusCell : function(y, z, AA){
37249         var  el = this.ensureVisible(y, z, AA);
37250         this.focusEl.alignTo(el, "tl-tl");
37251         if(Roo.isGecko){
37252             this.focusEl.focus();
37253         }else {
37254             this.focusEl.focus.defer(1, this.focusEl);
37255         }
37256     },
37257
37258     
37259
37260     ensureVisible : function(AB, AC, AD){
37261         if(typeof  AB != "number"){
37262             AB = AB.rowIndex;
37263         }
37264         if(AB < 0 && AB >= this.ds.getCount()){
37265             return;
37266         }
37267
37268         AC = (AC !== undefined ? AC : 0);
37269         var  cm = this.grid.colModel;
37270         while(cm.isHidden(AC)){
37271             AC++;
37272         }
37273
37274         var  el = this.getCell(AB, AC);
37275         if(!el){
37276             return;
37277         }
37278         var  c = this.scroller.dom;
37279
37280         var  AE = parseInt(el.offsetTop, 10);
37281         var  AF = parseInt(el.offsetLeft, 10);
37282         var  AG = AE + el.offsetHeight;
37283         var  AH = AF + el.offsetWidth;
37284
37285         var  ch = c.clientHeight - this.mainHd.dom.offsetHeight;
37286         var  AI = parseInt(c.scrollTop, 10);
37287         var  AJ = parseInt(c.scrollLeft, 10);
37288         var  AK = AI + ch;
37289         var  AL = AJ + c.clientWidth;
37290
37291         if(AE < AI){
37292                 c.scrollTop = AE;
37293         }else  if(AG > AK){
37294             c.scrollTop = AG-ch;
37295         }
37296
37297         if(AD !== false){
37298             if(AF < AJ){
37299                 c.scrollLeft = AF;
37300             }else  if(AH > AL){
37301                 c.scrollLeft = AH-c.clientWidth;
37302             }
37303         }
37304         return  el;
37305     },
37306
37307     updateColumns : function(){
37308         this.grid.stopEditing();
37309         var  cm = this.grid.colModel, AM = this.getColumnIds();
37310         
37311         var  AN = 0;
37312         for(var  i = 0, len = cm.getColumnCount(); i < len; i++){
37313             
37314             var  w = cm.getColumnWidth(i);
37315             this.css.updateRule(this.colSelector+this.idToCssName(AM[i]), "width", (w - this.borderWidth) + "px");
37316             this.css.updateRule(this.hdSelector+this.idToCssName(AM[i]), "width", (w - this.borderWidth) + "px");
37317         }
37318
37319         this.updateSplitters();
37320     },
37321
37322     generateRules : function(cm){
37323         var  AO = [], AP = this.idToCssName(this.grid.id)+ '-cssrules';
37324         Roo.util.CSS.removeStyleSheet(AP);
37325         for(var  i = 0, len = cm.getColumnCount(); i < len; i++){
37326             var  cid = cm.getColumnId(i);
37327             var  align = '';
37328             if(cm.config[i].align){
37329                 align = 'text-align:'+cm.config[i].align+';';
37330             }
37331             var  hidden = '';
37332             if(cm.isHidden(i)){
37333                 hidden = 'display:none;';
37334             }
37335             var  width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
37336             AO.push(
37337                     this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
37338                     this.hdSelector, cid, " {\n", align, width, "}\n",
37339                     this.tdSelector, cid, " {\n",hidden,"\n}\n",
37340                     this.splitSelector, cid, " {\n", hidden , "\n}\n");
37341         }
37342         return  Roo.util.CSS.createStyleSheet(AO.join(""), AP);
37343     },
37344
37345     updateSplitters : function(){
37346         var  cm = this.cm, s = this.getSplitters();
37347         if(s){ 
37348             var  AN = 0, Y = true;
37349             for(var  i = 0, len = cm.getColumnCount(); i < len; i++){
37350                 if(cm.isHidden(i)) continue;
37351                 var  w = cm.getColumnWidth(i);
37352                 if(!cm.isLocked(i) && Y){
37353                     AN = 0;
37354                     Y = false;
37355                 }
37356
37357                 AN += w;
37358                 s[i].style.left = (AN-this.splitOffset) + "px";
37359             }
37360         }
37361     },
37362
37363     handleHiddenChange : function(AQ, AR, AS){
37364         if(AS){
37365             this.hideColumn(AR);
37366         }else {
37367             this.unhideColumn(AR);
37368         }
37369     },
37370
37371     hideColumn : function(AT){
37372         var  AU = this.getColumnId(AT);
37373         this.css.updateRule(this.tdSelector+this.idToCssName(AU), "display", "none");
37374         this.css.updateRule(this.splitSelector+this.idToCssName(AU), "display", "none");
37375         if(Roo.isSafari){
37376             this.updateHeaders();
37377         }
37378
37379         this.updateSplitters();
37380         this.layout();
37381     },
37382
37383     unhideColumn : function(AV){
37384         var  AW = this.getColumnId(AV);
37385         this.css.updateRule(this.tdSelector+this.idToCssName(AW), "display", "");
37386         this.css.updateRule(this.splitSelector+this.idToCssName(AW), "display", "");
37387
37388         if(Roo.isSafari){
37389             this.updateHeaders();
37390         }
37391
37392         this.updateSplitters();
37393         this.layout();
37394     },
37395
37396     insertRows : function(dm, AX, AY, AZ){
37397         if(AX == 0 && AY == dm.getCount()-1){
37398             this.refresh();
37399         }else {
37400             if(!AZ){
37401                 this.fireEvent("beforerowsinserted", this, AX, AY);
37402             }
37403             var  s = this.getScrollState();
37404             var  markup = this.renderRows(AX, AY);
37405             this.bufferRows(markup[0], this.getLockedTable(), AX);
37406             this.bufferRows(markup[1], this.getBodyTable(), AX);
37407             this.restoreScroll(s);
37408             if(!AZ){
37409                 this.fireEvent("rowsinserted", this, AX, AY);
37410                 this.syncRowHeights(AX, AY);
37411                 this.stripeRows(AX);
37412                 this.layout();
37413             }
37414         }
37415     },
37416
37417     bufferRows : function(Aa, Ab, Ac){
37418         var  Ad = null, Ae = Ab.rows, Af = Ab.tBodies[0];
37419         if(Ac < Ae.length){
37420             Ad = Ae[Ac];
37421         }
37422         var  b = document.createElement("div");
37423         b.innerHTML = "<table><tbody>"+Aa+"</tbody></table>";
37424         var  Ag = b.firstChild.rows;
37425         for(var  i = 0, len = Ag.length; i < len; i++){
37426             if(Ad){
37427                 Af.insertBefore(Ag[0], Ad);
37428             }else {
37429                 Af.appendChild(Ag[0]);
37430             }
37431         }
37432
37433         b.innerHTML = "";
37434         b = null;
37435     },
37436
37437     deleteRows : function(dm, Ah, Ai){
37438         if(dm.getRowCount()<1){
37439             this.fireEvent("beforerefresh", this);
37440             this.mainBody.update("");
37441             this.lockedBody.update("");
37442             this.fireEvent("refresh", this);
37443         }else {
37444             this.fireEvent("beforerowsdeleted", this, Ah, Ai);
37445             var  bt = this.getBodyTable();
37446             var  Af = bt.firstChild;
37447             var  Ag = bt.rows;
37448             for(var  a = Ah; a <= Ai; a++){
37449                 Af.removeChild(Ag[Ah]);
37450             }
37451
37452             this.stripeRows(Ah);
37453             this.fireEvent("rowsdeleted", this, Ah, Ai);
37454         }
37455     },
37456
37457     updateRows : function(Aj, Ak, Al){
37458         var  s = this.getScrollState();
37459         this.refresh();
37460         this.restoreScroll(s);
37461     },
37462
37463     handleSort : function(Am, An, Ao, Ap){
37464         if(!Ap){
37465            this.refresh();
37466         }
37467
37468         this.updateHeaderSortState();
37469     },
37470
37471     getScrollState : function(){
37472         var  sb = this.scroller.dom;
37473         return  {left: sb.scrollLeft, top: sb.scrollTop};
37474     },
37475
37476     stripeRows : function(Aq){
37477         if(!this.grid.stripeRows || this.ds.getCount() < 1){
37478             return;
37479         }
37480
37481         Aq = Aq || 0;
37482         var  Ar = this.getBodyTable().rows;
37483         var  As = this.getLockedTable().rows;
37484         var  At = ' x-grid-row-alt ';
37485         for(var  i = Aq, len = Ar.length; i < len; i++){
37486             var  AB = Ar[i], U = As[i];
37487             var  isAlt = ((i+1) % 2 == 0);
37488             var  hasAlt = (' '+AB.className + ' ').indexOf(At) != -1;
37489             if(isAlt == hasAlt){
37490                 continue;
37491             }
37492             if(isAlt){
37493                 AB.className += " x-grid-row-alt";
37494             }else {
37495                 AB.className = AB.className.replace("x-grid-row-alt", "");
37496             }
37497             if(U){
37498                 U.className = AB.className;
37499             }
37500         }
37501     },
37502
37503     restoreScroll : function(Au){
37504         var  sb = this.scroller.dom;
37505         sb.scrollLeft = Au.left;
37506         sb.scrollTop = Au.top;
37507         this.syncScroll();
37508     },
37509
37510     syncScroll : function(){
37511         var  sb = this.scroller.dom;
37512         var  sh = this.mainHd.dom;
37513         var  bs = this.mainBody.dom;
37514         var  lv = this.lockedBody.dom;
37515         sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
37516         lv.scrollTop = bs.scrollTop = sb.scrollTop;
37517     },
37518
37519     handleScroll : function(e){
37520         this.syncScroll();
37521         var  sb = this.scroller.dom;
37522         this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
37523         e.stopEvent();
37524     },
37525
37526     handleWheel : function(e){
37527         var  d = e.getWheelDelta();
37528         this.scroller.dom.scrollTop -= d*22;
37529         
37530         this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
37531         e.stopEvent();
37532     },
37533
37534     renderRows : function(Av, Aw){
37535         
37536         var  g = this.grid, cm = g.colModel, ds = g.dataSource, Ax = g.stripeRows;
37537         var  Ay = cm.getColumnCount();
37538
37539         if(ds.getCount() < 1){
37540             return  ["", ""];
37541         }
37542
37543         
37544         var  cs = [];
37545         for(var  i = 0; i < Ay; i++){
37546             var  name = cm.getDataIndex(i);
37547             cs[i] = {
37548                 name : typeof  name == 'undefined' ? ds.fields.get(i).name : name,
37549                 renderer : cm.getRenderer(i),
37550                 id : cm.getColumnId(i),
37551                 locked : cm.isLocked(i)
37552             };
37553         }
37554
37555
37556         Av = Av || 0;
37557         Aw = typeof  Aw == "undefined"? ds.getCount()-1 : Aw;
37558
37559         
37560         var  rs = ds.getRange(Av, Aw);
37561
37562         return  this.doRender(cs, rs, ds, Av, Ay, Ax);
37563     },
37564
37565     
37566     
37567     
37568     doRender : Roo.isGecko ?
37569             function(cs, rs, ds, Az, A0, A1){
37570                 var  ts = this.templates, ct = ts.cell, rt = ts.row;
37571                 
37572                 var  A2 = "", A3 = "", cb, A4, c, p = {}, rp = {}, r, a;
37573                 for(var  j = 0, len = rs.length; j < len; j++){
37574                     r = rs[j]; cb = ""; A4 = ""; a = (j+Az);
37575                     for(var  i = 0; i < A0; i++){
37576                         c = cs[i];
37577                         p.cellId = "x-grid-cell-" + a + "-" + i;
37578                         p.id = c.id;
37579                         p.css = p.attr = "";
37580                         p.value = c.renderer(r.data[c.name], p, r, a, i, ds);
37581                         if(p.value == undefined || p.value === "") p.value = "&#160;";
37582                         if(r.dirty && typeof  r.modified[c.name] !== 'undefined'){
37583                             p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
37584                         }
37585                         var  Aa = ct.apply(p);
37586                         if(!c.locked){
37587                             cb+= Aa;
37588                         }else {
37589                             A4+= Aa;
37590                         }
37591                     }
37592                     var  alt = [];
37593                     if(A1 && ((a+1) % 2 == 0)){
37594                         alt[0] = "x-grid-row-alt";
37595                     }
37596                     if(r.dirty){
37597                         alt[1] = " x-grid-dirty-row";
37598                     }
37599
37600                     rp.cells = A4;
37601                     if(this.getRowClass){
37602                         alt[2] = this.getRowClass(r, a);
37603                     }
37604
37605                     rp.alt = alt.join(" ");
37606                     A3+= rt.apply(rp);
37607                     rp.cells = cb;
37608                     A2+=  rt.apply(rp);
37609                 }
37610                 return  [A3, A2];
37611             } :
37612             function(cs, rs, ds, A5, A6, A7){
37613                 var  ts = this.templates, ct = ts.cell, rt = ts.row;
37614                 
37615                 var  A8 = [], A9 = [], cb, BA, c, p = {}, rp = {}, r, a;
37616                 for(var  j = 0, len = rs.length; j < len; j++){
37617                     r = rs[j]; cb = []; BA = []; a = (j+A5);
37618                     for(var  i = 0; i < A6; i++){
37619                         c = cs[i];
37620                         p.cellId = "x-grid-cell-" + a + "-" + i;
37621                         p.id = c.id;
37622                         p.css = p.attr = "";
37623                         p.value = c.renderer(r.data[c.name], p, r, a, i, ds);
37624                         if(p.value == undefined || p.value === "") p.value = "&#160;";
37625                         if(r.dirty && typeof  r.modified[c.name] !== 'undefined'){
37626                             p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
37627                         }
37628                         var  Aa = ct.apply(p);
37629                         if(!c.locked){
37630                             cb[cb.length] = Aa;
37631                         }else {
37632                             BA[BA.length] = Aa;
37633                         }
37634                     }
37635                     var  alt = [];
37636                     if(A7 && ((a+1) % 2 == 0)){
37637                         alt[0] = "x-grid-row-alt";
37638                     }
37639                     if(r.dirty){
37640                         alt[1] = " x-grid-dirty-row";
37641                     }
37642
37643                     rp.cells = BA;
37644                     if(this.getRowClass){
37645                         alt[2] = this.getRowClass(r, a);
37646                     }
37647
37648                     rp.alt = alt.join(" ");
37649                     rp.cells = BA.join("");
37650                     A9[A9.length] = rt.apply(rp);
37651                     rp.cells = cb.join("");
37652                     A8[A8.length] =  rt.apply(rp);
37653                 }
37654                 return  [A9.join(""), A8.join("")];
37655             },
37656
37657     renderBody : function(){
37658         var  BB = this.renderRows();
37659         var  bt = this.templates.body;
37660         return  [bt.apply({rows: BB[0]}), bt.apply({rows: BB[1]})];
37661     },
37662
37663     
37664
37665     refresh : function(BC){
37666         this.fireEvent("beforerefresh", this);
37667         this.grid.stopEditing();
37668         var  BD = this.renderBody();
37669         this.lockedBody.update(BD[0]);
37670         this.mainBody.update(BD[1]);
37671         if(BC === true){
37672             this.updateHeaders();
37673             this.updateColumns();
37674             this.updateSplitters();
37675             this.updateHeaderSortState();
37676         }
37677
37678         this.syncRowHeights();
37679         this.layout();
37680         this.fireEvent("refresh", this);
37681     },
37682
37683     handleColumnMove : function(cm, BE, BF){
37684         this.indexMap = null;
37685         var  s = this.getScrollState();
37686         this.refresh(true);
37687         this.restoreScroll(s);
37688         this.afterMove(BF);
37689     },
37690
37691     afterMove : function(BG){
37692         if(this.enableMoveAnim && Roo.enableFx){
37693             this.fly(this.getHeaderCell(BG).firstChild).highlight(this.hlColor);
37694         }
37695     },
37696
37697     updateCell : function(dm, BH, BI){
37698         var  BJ = this.getColumnIndexByDataIndex(BI);
37699         if(typeof  BJ == "undefined"){ 
37700             return;
37701         }
37702         var  cm = this.grid.colModel;
37703         var  BK = this.getCell(BH, BJ);
37704         var  BL = this.getCellText(BH, BJ);
37705
37706         var  p = {
37707             cellId : "x-grid-cell-" + BH + "-" + BJ,
37708             id : cm.getColumnId(BJ),
37709             css: BJ == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
37710         };
37711         var  BM = cm.getRenderer(BJ);
37712         var  BN = BM(dm.getValueAt(BH, BI), p, BH, BJ, dm);
37713         if(typeof  BN == "undefined" || BN === "") BN = "&#160;";
37714         BL.innerHTML = BN;
37715         BK.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
37716         this.syncRowHeights(BH, BH);
37717     },
37718
37719     calcColumnWidth : function(BO, BP){
37720         var  BQ = 0;
37721         if(this.grid.autoSizeHeaders){
37722             var  h = this.getHeaderCellMeasure(BO);
37723             BQ = Math.max(BQ, h.scrollWidth);
37724         }
37725         var  tb, BR;
37726         if(this.cm.isLocked(BO)){
37727             tb = this.getLockedTable();
37728             BR = BO;
37729         }else {
37730             tb = this.getBodyTable();
37731             BR = BO - this.cm.getLockedCount();
37732         }
37733         if(tb && tb.rows){
37734             var  Ar = tb.rows;
37735             var  stopIndex = Math.min(BP || Ar.length, Ar.length);
37736             for(var  i = 0; i < stopIndex; i++){
37737                 var  BK = Ar[i].childNodes[BR].firstChild;
37738                 BQ = Math.max(BQ, BK.scrollWidth);
37739             }
37740         }
37741         return  BQ + 
37742  5;
37743     },
37744     
37745
37746      autoSizeColumn : function(BS, BT, BU){
37747          if(this.cm.isHidden(BS)){
37748              return; 
37749          }
37750         if(BT){
37751             var  AW = this.cm.getColumnId(BS);
37752             this.css.updateRule(this.colSelector +this.idToCssName( AW), "width", this.grid.minColumnWidth + "px");
37753            if(this.grid.autoSizeHeaders){
37754                this.css.updateRule(this.hdSelector + this.idToCssName(AW), "width", this.grid.minColumnWidth + "px");
37755            }
37756         }
37757         var  BV = this.calcColumnWidth(BS);
37758         this.cm.setColumnWidth(BS,
37759             Math.max(this.grid.minColumnWidth, BV), BU);
37760         if(!BU){
37761             this.grid.fireEvent("columnresize", BS, BV);
37762         }
37763     },
37764
37765     
37766
37767      autoSizeColumns : function(){
37768         var  cm = this.grid.colModel;
37769         var  BW = cm.getColumnCount();
37770         for(var  i = 0; i < BW; i++){
37771             this.autoSizeColumn(i, true, true);
37772         }
37773         if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
37774             this.fitColumns();
37775         }else {
37776             this.updateColumns();
37777             this.layout();
37778         }
37779     },
37780
37781     
37782
37783     fitColumns : function(BX){
37784         var  cm = this.grid.colModel;
37785         var  BY = cm.getColumnCount();
37786         var  BZ = [];
37787         var  Ba = 0;
37788         var  i, w;
37789         for (i = 0; i < BY; i++){
37790             if(!cm.isHidden(i) && !cm.isFixed(i)){
37791                 w = cm.getColumnWidth(i);
37792                 BZ.push(i);
37793                 BZ.push(w);
37794                 Ba += w;
37795             }
37796         }
37797         var  Bb = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
37798         if(BX){
37799             Bb -= 17;
37800         }
37801         var  Bc = (Bb - cm.getTotalWidth())/Ba;
37802         while (BZ.length){
37803             w = BZ.pop();
37804             i = BZ.pop();
37805             cm.setColumnWidth(i, Math.floor(w + w*Bc), true);
37806         }
37807
37808         this.updateColumns();
37809         this.layout();
37810     },
37811
37812     onRowSelect : function(Bd){
37813         var  Be = this.getRowComposite(Bd);
37814         Be.addClass("x-grid-row-selected");
37815     },
37816
37817     onRowDeselect : function(Bf){
37818         var  Bg = this.getRowComposite(Bf);
37819         Bg.removeClass("x-grid-row-selected");
37820     },
37821
37822     onCellSelect : function(Bh, Bi){
37823         var  Bj = this.getCell(Bh, Bi);
37824         if(Bj){
37825             Roo.fly(Bj).addClass("x-grid-cell-selected");
37826         }
37827     },
37828
37829     onCellDeselect : function(Bk, Bl){
37830         var  Bm = this.getCell(Bk, Bl);
37831         if(Bm){
37832             Roo.fly(Bm).removeClass("x-grid-cell-selected");
37833         }
37834     },
37835
37836     updateHeaderSortState : function(){
37837         var  Bn = this.ds.getSortState();
37838         if(!Bn){
37839             return;
37840         }
37841
37842         this.sortState = Bn;
37843         var  Bo = this.cm.findColumnIndex(Bn.field);
37844         if(Bo != -1){
37845             var  Ao = Bn.direction;
37846             var  sc = this.sortClasses;
37847             var  hds = this.el.select(this.headerSelector).removeClass(sc);
37848             hds.item(Bo).addClass(sc[Ao == "DESC" ? 1 : 0]);
37849         }
37850     },
37851
37852     handleHeaderClick : function(g, Bp){
37853         if(this.headersDisabled){
37854             return;
37855         }
37856         var  dm = g.dataSource, cm = g.colModel;
37857             if(!cm.isSortable(Bp)){
37858             return;
37859         }
37860
37861             g.stopEditing();
37862         dm.sort(cm.getDataIndex(Bp));
37863     },
37864
37865
37866     destroy : function(){
37867         if(this.colMenu){
37868             this.colMenu.removeAll();
37869             Roo.menu.MenuMgr.unregister(this.colMenu);
37870             this.colMenu.getEl().remove();
37871             delete  this.colMenu;
37872         }
37873         if(this.hmenu){
37874             this.hmenu.removeAll();
37875             Roo.menu.MenuMgr.unregister(this.hmenu);
37876             this.hmenu.getEl().remove();
37877             delete  this.hmenu;
37878         }
37879         if(this.grid.enableColumnMove){
37880             var  dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
37881             if(dds){
37882                 for(var  dd  in  dds){
37883                     if(!dds[dd].config.isTarget && dds[dd].dragElId){
37884                         var  elid = dds[dd].dragElId;
37885                         dds[dd].unreg();
37886                         Roo.get(elid).remove();
37887                     } else  if(dds[dd].config.isTarget){
37888                         dds[dd].proxyTop.remove();
37889                         dds[dd].proxyBottom.remove();
37890                         dds[dd].unreg();
37891                     }
37892                     if(Roo.dd.DDM.locationCache[dd]){
37893                         delete  Roo.dd.DDM.locationCache[dd];
37894                     }
37895                 }
37896                 delete  Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
37897             }
37898         }
37899
37900         Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
37901         this.bind(null, null);
37902         Roo.EventManager.removeResizeListener(this.onWindowResize, this);
37903     },
37904
37905     handleLockChange : function(){
37906         this.refresh(true);
37907     },
37908
37909     onDenyColumnLock : function(){
37910
37911     },
37912
37913     onDenyColumnHide : function(){
37914
37915     },
37916
37917     handleHdMenuClick : function(Bq){
37918         var  Br = this.hdCtxIndex;
37919         var  cm = this.cm, ds = this.ds;
37920         switch(Bq.id){
37921             case  "asc":
37922                 ds.sort(cm.getDataIndex(Br), "ASC");
37923                 break;
37924             case  "desc":
37925                 ds.sort(cm.getDataIndex(Br), "DESC");
37926                 break;
37927             case  "lock":
37928                 var  lc = cm.getLockedCount();
37929                 if(cm.getColumnCount(true) <= lc+1){
37930                     this.onDenyColumnLock();
37931                     return;
37932                 }
37933                 if(lc != Br){
37934                     cm.setLocked(Br, true, true);
37935                     cm.moveColumn(Br, lc);
37936                     this.grid.fireEvent("columnmove", Br, lc);
37937                 }else {
37938                     cm.setLocked(Br, true);
37939                 }
37940             break;
37941             case  "unlock":
37942                 var  lc = cm.getLockedCount();
37943                 if((lc-1) != Br){
37944                     cm.setLocked(Br, false, true);
37945                     cm.moveColumn(Br, lc-1);
37946                     this.grid.fireEvent("columnmove", Br, lc-1);
37947                 }else {
37948                     cm.setLocked(Br, false);
37949                 }
37950             break;
37951             default:
37952                 Br = cm.getIndexById(Bq.id.substr(4));
37953                 if(Br != -1){
37954                     if(Bq.checked && cm.getColumnCount(true) <= 1){
37955                         this.onDenyColumnHide();
37956                         return  false;
37957                     }
37958
37959                     cm.setHidden(Br, Bq.checked);
37960                 }
37961         }
37962         return  true;
37963     },
37964
37965     beforeColMenuShow : function(){
37966         var  cm = this.cm,  Bs = cm.getColumnCount();
37967         this.colMenu.removeAll();
37968         for(var  i = 0; i < Bs; i++){
37969             this.colMenu.add(new  Roo.menu.CheckItem({
37970                 id: "col-"+cm.getColumnId(i),
37971                 text: cm.getColumnHeader(i),
37972                 checked: !cm.isHidden(i),
37973                 hideOnClick:false
37974             }));
37975         }
37976     },
37977
37978     handleHdCtx : function(g, Bt, e){
37979         e.stopEvent();
37980         var  hd = this.getHeaderCell(Bt);
37981         this.hdCtxIndex = Bt;
37982         var  ms = this.hmenu.items, cm = this.cm;
37983         ms.get("asc").setDisabled(!cm.isSortable(Bt));
37984         ms.get("desc").setDisabled(!cm.isSortable(Bt));
37985         if(this.grid.enableColLock !== false){
37986             ms.get("lock").setDisabled(cm.isLocked(Bt));
37987             ms.get("unlock").setDisabled(!cm.isLocked(Bt));
37988         }
37989
37990         this.hmenu.show(hd, "tl-bl");
37991     },
37992
37993     handleHdOver : function(e){
37994         var  hd = this.findHeaderCell(e.getTarget());
37995         if(hd && !this.headersDisabled){
37996             if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
37997                this.fly(hd).addClass("x-grid-hd-over");
37998             }
37999         }
38000     },
38001
38002     handleHdOut : function(e){
38003         var  hd = this.findHeaderCell(e.getTarget());
38004         if(hd){
38005             this.fly(hd).removeClass("x-grid-hd-over");
38006         }
38007     },
38008
38009     handleSplitDblClick : function(e, t){
38010         var  i = this.getCellIndex(t);
38011         if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
38012             this.autoSizeColumn(i, true);
38013             this.layout();
38014         }
38015     },
38016
38017     render : function(){
38018
38019         var  cm = this.cm;
38020         var  Bu = cm.getColumnCount();
38021
38022         if(this.grid.monitorWindowResize === true){
38023             Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
38024         }
38025         var  Bv = this.renderHeaders();
38026         var  Bw = this.templates.body.apply({rows:""});
38027         var  Bx = this.templates.master.apply({
38028             lockedBody: Bw,
38029             body: Bw,
38030             lockedHeader: Bv[0],
38031             header: Bv[1]
38032         });
38033
38034         
38035
38036         this.grid.getGridEl().dom.innerHTML = Bx;
38037
38038         this.initElements();
38039
38040         this.scroller.on("scroll", this.handleScroll, this);
38041         this.lockedBody.on("mousewheel", this.handleWheel, this);
38042         this.mainBody.on("mousewheel", this.handleWheel, this);
38043
38044         this.mainHd.on("mouseover", this.handleHdOver, this);
38045         this.mainHd.on("mouseout", this.handleHdOut, this);
38046         this.mainHd.on("dblclick", this.handleSplitDblClick, this,
38047                 {delegate: "."+this.splitClass});
38048
38049         this.lockedHd.on("mouseover", this.handleHdOver, this);
38050         this.lockedHd.on("mouseout", this.handleHdOut, this);
38051         this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
38052                 {delegate: "."+this.splitClass});
38053
38054         if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
38055             new  Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
38056         }
38057
38058
38059         this.updateSplitters();
38060
38061         if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
38062             new  Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
38063             new  Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
38064         }
38065
38066         if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
38067             this.hmenu = new  Roo.menu.Menu({id: this.grid.id + "-hctx"});
38068             this.hmenu.add(
38069                 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
38070                 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
38071             );
38072             if(this.grid.enableColLock !== false){
38073                 this.hmenu.add('-',
38074                     {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
38075                     {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
38076                 );
38077             }
38078             if(this.grid.enableColumnHide !== false){
38079
38080                 this.colMenu = new  Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
38081                 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
38082                 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
38083
38084                 this.hmenu.add('-',
38085                     {id:"columns", text: this.columnsText, menu: this.colMenu}
38086                 );
38087             }
38088
38089             this.hmenu.on("itemclick", this.handleHdMenuClick, this);
38090
38091             this.grid.on("headercontextmenu", this.handleHdCtx, this);
38092         }
38093
38094         if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
38095             this.dd = new  Roo.grid.GridDragZone(this.grid, {
38096                 ddGroup : this.grid.ddGroup || 'GridDD'
38097             });
38098         }
38099
38100
38101         
38102
38103         
38104         this.updateHeaderSortState();
38105
38106         this.beforeInitialResize();
38107         this.layout(true);
38108
38109         
38110         this.renderPhase2.defer(1, this);
38111     },
38112
38113     renderPhase2 : function(){
38114         
38115         this.refresh();
38116         if(this.grid.autoSizeColumns){
38117             this.autoSizeColumns();
38118         }
38119     },
38120
38121     beforeInitialResize : function(){
38122
38123     },
38124
38125     onColumnSplitterMoved : function(i, w){
38126         this.userResized = true;
38127         var  cm = this.grid.colModel;
38128         cm.setColumnWidth(i, w, true);
38129         var  By = cm.getColumnId(i);
38130         this.css.updateRule(this.colSelector + this.idToCssName(By), "width", (w-this.borderWidth) + "px");
38131         this.css.updateRule(this.hdSelector + this.idToCssName(By), "width", (w-this.borderWidth) + "px");
38132         this.updateSplitters();
38133         this.layout();
38134         this.grid.fireEvent("columnresize", i, w);
38135     },
38136
38137     syncRowHeights : function(Bz, B0){
38138         if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
38139             Bz = Bz || 0;
38140             var  mrows = this.getBodyTable().rows;
38141             var  As = this.getLockedTable().rows;
38142             var  len = mrows.length-1;
38143             B0 = Math.min(B0 || len, len);
38144             for(var  i = Bz; i <= B0; i++){
38145                 var  m = mrows[i], l = As[i];
38146                 var  h = Math.max(m.offsetHeight, l.offsetHeight);
38147                 m.style.height = l.style.height = h + "px";
38148             }
38149         }
38150     },
38151
38152     layout : function(B1, B2){
38153         var  g = this.grid;
38154         var  B3 = g.autoHeight;
38155         var  B4 = 16;
38156         var  c = g.getGridEl(), cm = this.cm,
38157                 B5 = g.autoExpandColumn,
38158                 gv = this;
38159         
38160
38161         if(!c.dom.offsetWidth){ 
38162             if(B1){
38163                 this.lockedWrap.show();
38164                 this.mainWrap.show();
38165             }
38166             return;
38167         }
38168
38169         var  B6 = this.cm.isLocked(0);
38170
38171         var  B7 = this.headerPanel.getHeight();
38172         var  B8 = this.footerPanel.getHeight();
38173
38174         if(B3){
38175             var  ch = this.getBodyTable().offsetHeight + B7 + B8 + this.mainHd.getHeight();
38176             var  newHeight = ch + c.getBorderWidth("tb");
38177             if(g.maxHeight){
38178                 newHeight = Math.min(g.maxHeight, newHeight);
38179             }
38180
38181             c.setHeight(newHeight);
38182         }
38183
38184         if(g.autoWidth){
38185             c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
38186         }
38187
38188         var  s = this.scroller;
38189
38190         var  B9 = c.getSize(true);
38191
38192         this.el.setSize(B9.width, B9.height);
38193
38194         this.headerPanel.setWidth(B9.width);
38195         this.footerPanel.setWidth(B9.width);
38196
38197         var  CA = this.mainHd.getHeight();
38198         var  vw = B9.width;
38199         var  vh = B9.height - (B7 + B8);
38200
38201         s.setSize(vw, vh);
38202
38203         var  bt = this.getBodyTable();
38204         var  CB = B6 ?
38205                       Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
38206
38207         var  CC = bt.offsetHeight;
38208         var  CD = CB + bt.offsetWidth;
38209         var  CE = false, CF = false;
38210
38211         this.scrollSizer.setSize(CD, CC+CA);
38212
38213         var  lw = this.lockedWrap, mw = this.mainWrap;
38214         var  lb = this.lockedBody, mb = this.mainBody;
38215
38216         setTimeout(function(){
38217             var  t = s.dom.offsetTop;
38218             var  w = s.dom.clientWidth,
38219                 h = s.dom.clientHeight;
38220
38221             lw.setTop(t);
38222             lw.setSize(CB, h);
38223
38224             mw.setLeftTop(CB, t);
38225             mw.setSize(w-CB, h);
38226
38227             lb.setHeight(h-CA);
38228             mb.setHeight(h-CA);
38229
38230             if(B2 !== true && !gv.userResized && B5){
38231                 
38232                 
38233                 var  ci = cm.getIndexById(B5);
38234                 if (ci < 0) {
38235                     ci = cm.findColumnIndex(B5);
38236                 }
38237
38238                 ci = Math.max(0, ci); 
38239                 var  expandId = cm.getColumnId(ci);
38240                 var   tw = cm.getTotalWidth(false);
38241                 var  currentWidth = cm.getColumnWidth(ci);
38242                 var  cw = Math.min(Math.max(((w-tw)+currentWidth-2)-
38243 (w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
38244                 if(currentWidth != cw){
38245                     cm.setColumnWidth(ci, cw, true);
38246                     gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
38247                     gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
38248                     gv.updateSplitters();
38249                     gv.layout(false, true);
38250                 }
38251             }
38252
38253             if(B1){
38254                 lw.show();
38255                 mw.show();
38256             }
38257             
38258         }, 10);
38259     },
38260
38261     onWindowResize : function(){
38262         if(!this.grid.monitorWindowResize || this.grid.autoHeight){
38263             return;
38264         }
38265
38266         this.layout();
38267     },
38268
38269     appendFooter : function(CG){
38270         return  null;
38271     },
38272
38273     sortAscText : "Sort Ascending",
38274     sortDescText : "Sort Descending",
38275     lockText : "Lock Column",
38276     unlockText : "Unlock Column",
38277     columnsText : "Columns"
38278 });
38279
38280
38281 Roo.grid.GridView.ColumnDragZone = function(CH, hd){
38282     Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, CH, hd, null);
38283     this.proxy.el.addClass('x-grid3-col-dd');
38284 };
38285
38286 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
38287     handleMouseDown : function(e){
38288
38289     },
38290
38291     callHandleMouseDown : function(e){
38292         Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
38293     }
38294 });
38295
38296
38297
38298  
38299
38300
38301 Roo.grid.SplitDragZone = function(A, hd, B){
38302     this.grid = A;
38303     this.view = A.getView();
38304     this.proxy = this.view.resizeProxy;
38305     Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
38306         "gridSplitters" + this.grid.getGridEl().id, {
38307         dragElId : Roo.id(this.proxy.dom), resizeFrame:false
38308     });
38309     this.setHandleElId(Roo.id(hd));
38310     this.setOuterHandleElId(Roo.id(B));
38311     this.scroll = false;
38312 };
38313 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
38314     fly: Roo.Element.fly,
38315
38316     b4StartDrag : function(x, y){
38317         this.view.headersDisabled = true;
38318         this.proxy.setHeight(this.view.mainWrap.getHeight());
38319         var  w = this.cm.getColumnWidth(this.cellIndex);
38320         var  C = Math.max(w-this.grid.minColumnWidth, 0);
38321         this.resetConstraints();
38322         this.setXConstraint(C, 1000);
38323         this.setYConstraint(0, 0);
38324         this.minX = x - C;
38325         this.maxX = x + 1000;
38326         this.startPos = x;
38327         Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
38328     },
38329
38330
38331     handleMouseDown : function(e){
38332         ev = Roo.EventObject.setEvent(e);
38333         var  t = this.fly(ev.getTarget());
38334         if(t.hasClass("x-grid-split")){
38335             this.cellIndex = this.view.getCellIndex(t.dom);
38336             this.split = t.dom;
38337             this.cm = this.grid.colModel;
38338             if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
38339                 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
38340             }
38341         }
38342     },
38343
38344     endDrag : function(e){
38345         this.view.headersDisabled = false;
38346         var  D = Math.max(this.minX, Roo.lib.Event.getPageX(e));
38347         var  E = D - this.startPos;
38348         this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+E);
38349     },
38350
38351     autoOffset : function(){
38352         this.setDelta(0,0);
38353     }
38354 });
38355
38356
38357  
38358
38359
38360 Roo.grid.GridDragZone = function(A, B){
38361     this.view = A.getView();
38362     Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, B);
38363     if(this.view.lockedBody){
38364         this.setHandleElId(Roo.id(this.view.mainBody.dom));
38365         this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
38366     }
38367
38368     this.scroll = false;
38369     this.grid = A;
38370     this.ddel = document.createElement('div');
38371     this.ddel.className = 'x-grid-dd-wrap';
38372 };
38373
38374 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
38375     ddGroup : "GridDD",
38376
38377     getDragData : function(e){
38378         var  t = Roo.lib.Event.getTarget(e);
38379         var  C = this.view.findRowIndex(t);
38380         if(C !== false){
38381             var  sm = this.grid.selModel;
38382             
38383               
38384             
38385             if (e.hasModifier()){
38386                 sm.handleMouseDown(e, t); 
38387             }
38388             return  {grid: this.grid, ddel: this.ddel, rowIndex: C, selections:sm.getSelections()};
38389         }
38390         return  false;
38391     },
38392
38393     onInitDrag : function(e){
38394         var  D = this.dragData;
38395         this.ddel.innerHTML = this.grid.getDragDropText();
38396         this.proxy.update(this.ddel);
38397         
38398     },
38399
38400     afterRepair : function(){
38401         this.dragging = false;
38402     },
38403
38404     getRepairXY : function(e, E){
38405         return  false;
38406     },
38407
38408     onEndDrag : function(F, e){
38409         
38410     },
38411
38412     onValidDrop : function(dd, e, id){
38413         
38414         this.hideProxy();
38415     },
38416
38417     beforeInvalidDrop : function(e, id){
38418
38419     }
38420 });
38421
38422
38423  
38424
38425
38426
38427 Roo.grid.ColumnModel = function(A){
38428         
38429
38430     this.config = A;
38431     this.lookup = {};
38432
38433     
38434     
38435     
38436     for(var  i = 0, len = A.length; i < len; i++){
38437         var  c = A[i];
38438         if(typeof  c.dataIndex == "undefined"){
38439             c.dataIndex = i;
38440         }
38441         if(typeof  c.renderer == "string"){
38442             c.renderer = Roo.util.Format[c.renderer];
38443         }
38444         if(typeof  c.id == "undefined"){
38445             c.id = Roo.id();
38446         }
38447         if(c.editor && c.editor.xtype){
38448             c.editor  = Roo.factory(c.editor, Roo.grid);
38449         }
38450         if(c.editor && c.editor.isFormField){
38451             c.editor = new  Roo.grid.GridEditor(c.editor);
38452         }
38453
38454         this.lookup[c.id] = c;
38455     }
38456
38457
38458     
38459
38460     this.defaultWidth = 100;
38461
38462     
38463
38464     this.defaultSortable = false;
38465
38466     this.addEvents({
38467         
38468
38469             "widthchange": true,
38470         
38471
38472             "headerchange": true,
38473         
38474
38475             "hiddenchange": true,
38476             
38477
38478         "columnmoved" : true,
38479         
38480
38481         "columnlockchange" : true
38482     });
38483     Roo.grid.ColumnModel.superclass.constructor.call(this);
38484 };
38485 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
38486     
38487
38488     
38489
38490     
38491
38492     
38493
38494     
38495
38496     
38497
38498     
38499
38500     
38501
38502     
38503
38504        
38505
38506     
38507
38508
38509     
38510
38511     getColumnId : function(B){
38512         return  this.config[B].id;
38513     },
38514
38515     
38516
38517     getColumnById : function(id){
38518         return  this.lookup[id];
38519     },
38520
38521     
38522
38523     getIndexById : function(id){
38524         for(var  i = 0, len = this.config.length; i < len; i++){
38525             if(this.config[i].id == id){
38526                 return  i;
38527             }
38528         }
38529         return  -1;
38530     },
38531     
38532
38533     
38534     findColumnIndex : function(C){
38535         for(var  i = 0, len = this.config.length; i < len; i++){
38536             if(this.config[i].dataIndex == C){
38537                 return  i;
38538             }
38539         }
38540         return  -1;
38541     },
38542     
38543     
38544     moveColumn : function(D, E){
38545         var  c = this.config[D];
38546         this.config.splice(D, 1);
38547         this.config.splice(E, 0, c);
38548         this.dataMap = null;
38549         this.fireEvent("columnmoved", this, D, E);
38550     },
38551
38552     isLocked : function(F){
38553         return  this.config[F].locked === true;
38554     },
38555
38556     setLocked : function(G, H, I){
38557         if(this.isLocked(G) == H){
38558             return;
38559         }
38560
38561         this.config[G].locked = H;
38562         if(!I){
38563             this.fireEvent("columnlockchange", this, G, H);
38564         }
38565     },
38566
38567     getTotalLockedWidth : function(){
38568         var  J = 0;
38569         for(var  i = 0; i < this.config.length; i++){
38570             if(this.isLocked(i) && !this.isHidden(i)){
38571                 this.totalWidth += this.getColumnWidth(i);
38572             }
38573         }
38574         return  J;
38575     },
38576
38577     getLockedCount : function(){
38578         for(var  i = 0, len = this.config.length; i < len; i++){
38579             if(!this.isLocked(i)){
38580                 return  i;
38581             }
38582         }
38583     },
38584
38585     
38586
38587     getColumnCount : function(K){
38588         if(K === true){
38589             var  c = 0;
38590             for(var  i = 0, len = this.config.length; i < len; i++){
38591                 if(!this.isHidden(i)){
38592                     c++;
38593                 }
38594             }
38595             return  c;
38596         }
38597         return  this.config.length;
38598     },
38599
38600     
38601
38602     getColumnsBy : function(fn, L){
38603         var  r = [];
38604         for(var  i = 0, len = this.config.length; i < len; i++){
38605             var  c = this.config[i];
38606             if(fn.call(L||this, c, i) === true){
38607                 r[r.length] = c;
38608             }
38609         }
38610         return  r;
38611     },
38612
38613     
38614
38615     isSortable : function(M){
38616         if(typeof  this.config[M].sortable == "undefined"){
38617             return  this.defaultSortable;
38618         }
38619         return  this.config[M].sortable;
38620     },
38621
38622     
38623
38624     getRenderer : function(N){
38625         if(!this.config[N].renderer){
38626             return  Roo.grid.ColumnModel.defaultRenderer;
38627         }
38628         return  this.config[N].renderer;
38629     },
38630
38631     
38632
38633     setRenderer : function(O, fn){
38634         this.config[O].renderer = fn;
38635     },
38636
38637     
38638
38639     getColumnWidth : function(P){
38640         return  this.config[P].width || this.defaultWidth;
38641     },
38642
38643     
38644
38645     setColumnWidth : function(Q, R, S){
38646         this.config[Q].width = R;
38647         this.totalWidth = null;
38648         if(!S){
38649              this.fireEvent("widthchange", this, Q, R);
38650         }
38651     },
38652
38653     
38654
38655     getTotalWidth : function(T){
38656         if(!this.totalWidth){
38657             this.totalWidth = 0;
38658             for(var  i = 0, len = this.config.length; i < len; i++){
38659                 if(T || !this.isHidden(i)){
38660                     this.totalWidth += this.getColumnWidth(i);
38661                 }
38662             }
38663         }
38664         return  this.totalWidth;
38665     },
38666
38667     
38668
38669     getColumnHeader : function(U){
38670         return  this.config[U].header;
38671     },
38672
38673     
38674
38675     setColumnHeader : function(V, W){
38676         this.config[V].header = W;
38677         this.fireEvent("headerchange", this, V, W);
38678     },
38679
38680     
38681
38682     getColumnTooltip : function(X){
38683             return  this.config[X].tooltip;
38684     },
38685     
38686
38687     setColumnTooltip : function(Y, Z){
38688             this.config[Y].tooltip = Z;
38689     },
38690
38691     
38692
38693     getDataIndex : function(a){
38694         return  this.config[a].dataIndex;
38695     },
38696
38697     
38698
38699     setDataIndex : function(b, d){
38700         this.config[b].dataIndex = d;
38701     },
38702
38703     
38704     
38705     
38706
38707     isCellEditable : function(e, f){
38708         return  (this.config[e].editable || (typeof  this.config[e].editable == "undefined" && this.config[e].editor)) ? true : false;
38709     },
38710
38711     
38712
38713     getCellEditor : function(g, h){
38714         return  this.config[g].editor;
38715     },
38716
38717     
38718
38719     setEditable : function(j, k){
38720         this.config[j].editable = k;
38721     },
38722
38723
38724     
38725
38726     isHidden : function(l){
38727         return  this.config[l].hidden;
38728     },
38729
38730
38731     
38732
38733     isFixed : function(m){
38734         return  this.config[m].fixed;
38735     },
38736
38737     
38738
38739     isResizable : function(n){
38740         return  n >= 0 && this.config[n].resizable !== false && this.config[n].fixed !== true;
38741     },
38742     
38743
38744     setHidden : function(o, p){
38745         this.config[o].hidden = p;
38746         this.totalWidth = null;
38747         this.fireEvent("hiddenchange", this, o, p);
38748     },
38749
38750     
38751
38752     setEditor : function(q, s){
38753         this.config[q].editor = s;
38754     }
38755 });
38756
38757 Roo.grid.ColumnModel.defaultRenderer = function(t){
38758         if(typeof  t == "string" && t.length < 1){
38759             return  "&#160;";
38760         }
38761         return  t;
38762 };
38763
38764
38765 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
38766
38767
38768
38769
38770
38771
38772 Roo.grid.AbstractSelectionModel = function(){
38773     this.locked = false;
38774     Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
38775 };
38776
38777 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable,  {
38778     
38779
38780     init : function(A){
38781         this.grid = A;
38782         this.initEvents();
38783     },
38784
38785     
38786
38787     lock : function(){
38788         this.locked = true;
38789     },
38790
38791     
38792
38793     unlock : function(){
38794         this.locked = false;
38795     },
38796
38797     
38798
38799     isLocked : function(){
38800         return  this.locked;
38801     }
38802 });
38803
38804
38805
38806
38807 Roo.grid.RowSelectionModel = function(A){
38808     Roo.apply(this, A);
38809     this.selections = new  Roo.util.MixedCollection(false, function(o){
38810         return  o.id;
38811     });
38812
38813     this.last = false;
38814     this.lastActive = false;
38815
38816     this.addEvents({
38817         
38818
38819             "selectionchange" : true,
38820         
38821
38822             "afterselectionchange" : true,
38823         
38824
38825             "beforerowselect" : true,
38826         
38827
38828             "rowselect" : true,
38829         
38830
38831         "rowdeselect" : true
38832     });
38833     Roo.grid.RowSelectionModel.superclass.constructor.call(this);
38834     this.locked = false;
38835 };
38836
38837 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel,  {
38838     
38839
38840     singleSelect : false,
38841
38842     
38843     initEvents : function(){
38844
38845         if(!this.grid.enableDragDrop && !this.grid.enableDrag){
38846             this.grid.on("mousedown", this.handleMouseDown, this);
38847         }else { 
38848             this.grid.on("rowclick", this.handleDragableRowClick, this);
38849         }
38850
38851
38852         this.rowNav = new  Roo.KeyNav(this.grid.getGridEl(), {
38853             "up" : function(e){
38854                 if(!e.shiftKey){
38855                     this.selectPrevious(e.shiftKey);
38856                 }else  if(this.last !== false && this.lastActive !== false){
38857                     var  last = this.last;
38858                     this.selectRange(this.last,  this.lastActive-1);
38859                     this.grid.getView().focusRow(this.lastActive);
38860                     if(last !== false){
38861                         this.last = last;
38862                     }
38863                 }else {
38864                     this.selectFirstRow();
38865                 }
38866
38867                 this.fireEvent("afterselectionchange", this);
38868             },
38869             "down" : function(e){
38870                 if(!e.shiftKey){
38871                     this.selectNext(e.shiftKey);
38872                 }else  if(this.last !== false && this.lastActive !== false){
38873                     var  last = this.last;
38874                     this.selectRange(this.last,  this.lastActive+1);
38875                     this.grid.getView().focusRow(this.lastActive);
38876                     if(last !== false){
38877                         this.last = last;
38878                     }
38879                 }else {
38880                     this.selectFirstRow();
38881                 }
38882
38883                 this.fireEvent("afterselectionchange", this);
38884             },
38885             scope: this
38886         });
38887
38888         var  B = this.grid.view;
38889         B.on("refresh", this.onRefresh, this);
38890         B.on("rowupdated", this.onRowUpdated, this);
38891         B.on("rowremoved", this.onRemove, this);
38892     },
38893
38894     
38895     onRefresh : function(){
38896         var  ds = this.grid.dataSource, i, v = this.grid.view;
38897         var  s = this.selections;
38898         s.each(function(r){
38899             if((i = ds.indexOfId(r.id)) != -1){
38900                 v.onRowSelect(i);
38901             }else {
38902                 s.remove(r);
38903             }
38904         });
38905     },
38906
38907     
38908     onRemove : function(v, C, r){
38909         this.selections.remove(r);
38910     },
38911
38912     
38913     onRowUpdated : function(v, D, r){
38914         if(this.isSelected(r)){
38915             v.onRowSelect(D);
38916         }
38917     },
38918
38919     
38920
38921     selectRecords : function(E, F){
38922         if(!F){
38923             this.clearSelections();
38924         }
38925         var  ds = this.grid.dataSource;
38926         for(var  i = 0, len = E.length; i < len; i++){
38927             this.selectRow(ds.indexOf(E[i]), true);
38928         }
38929     },
38930
38931     
38932
38933     getCount : function(){
38934         return  this.selections.length;
38935     },
38936
38937     
38938
38939     selectFirstRow : function(){
38940         this.selectRow(0);
38941     },
38942
38943     
38944
38945     selectLastRow : function(G){
38946         this.selectRow(this.grid.dataSource.getCount() - 1, G);
38947     },
38948
38949     
38950
38951     selectNext : function(H){
38952         if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
38953             this.selectRow(this.last+1, H);
38954             this.grid.getView().focusRow(this.last);
38955         }
38956     },
38957
38958     
38959
38960     selectPrevious : function(I){
38961         if(this.last){
38962             this.selectRow(this.last-1, I);
38963             this.grid.getView().focusRow(this.last);
38964         }
38965     },
38966
38967     
38968
38969     getSelections : function(){
38970         return  [].concat(this.selections.items);
38971     },
38972
38973     
38974
38975     getSelected : function(){
38976         return  this.selections.itemAt(0);
38977     },
38978
38979
38980     
38981
38982     clearSelections : function(J){
38983         if(this.locked) return;
38984         if(J !== true){
38985             var  ds = this.grid.dataSource;
38986             var  s = this.selections;
38987             s.each(function(r){
38988                 this.deselectRow(ds.indexOfId(r.id));
38989             }, this);
38990             s.clear();
38991         }else {
38992             this.selections.clear();
38993         }
38994
38995         this.last = false;
38996     },
38997
38998
38999     
39000
39001     selectAll : function(){
39002         if(this.locked) return;
39003         this.selections.clear();
39004         for(var  i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
39005             this.selectRow(i, true);
39006         }
39007     },
39008
39009     
39010
39011     hasSelection : function(){
39012         return  this.selections.length > 0;
39013     },
39014
39015     
39016
39017     isSelected : function(K){
39018         var  r = typeof  K == "number" ? this.grid.dataSource.getAt(K) : K;
39019         return  (r && this.selections.key(r.id) ? true : false);
39020     },
39021
39022     
39023
39024     isIdSelected : function(id){
39025         return  (this.selections.key(id) ? true : false);
39026     },
39027
39028     
39029     handleMouseDown : function(e, t){
39030         var  L = this.grid.getView(), M;
39031         if(this.isLocked() || (M = L.findRowIndex(t)) === false){
39032             return;
39033         };
39034         if(e.shiftKey && this.last !== false){
39035             var  last = this.last;
39036             this.selectRange(last, M, e.ctrlKey);
39037             this.last = last; 
39038             L.focusRow(M);
39039         }else {
39040             var  isSelected = this.isSelected(M);
39041             if(e.button !== 0 && isSelected){
39042                 L.focusRow(M);
39043             }else  if(e.ctrlKey && isSelected){
39044                 this.deselectRow(M);
39045             }else  if(!isSelected){
39046                 this.selectRow(M, e.button === 0 && (e.ctrlKey || e.shiftKey));
39047                 L.focusRow(M);
39048             }
39049         }
39050
39051         this.fireEvent("afterselectionchange", this);
39052     },
39053     
39054     handleDragableRowClick :  function(N, O, e) 
39055     {
39056         if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
39057             this.selectRow(O, false);
39058             N.view.focusRow(O);
39059              this.fireEvent("afterselectionchange", this);
39060         }
39061     },
39062     
39063     
39064
39065     selectRows : function(P, Q){
39066         if(!Q){
39067             this.clearSelections();
39068         }
39069         for(var  i = 0, len = P.length; i < len; i++){
39070             this.selectRow(P[i], true);
39071         }
39072     },
39073
39074     
39075
39076     selectRange : function(R, S, T){
39077         if(this.locked) return;
39078         if(!T){
39079             this.clearSelections();
39080         }
39081         if(R <= S){
39082             for(var  i = R; i <= S; i++){
39083                 this.selectRow(i, true);
39084             }
39085         }else {
39086             for(var  i = R; i >= S; i--){
39087                 this.selectRow(i, true);
39088             }
39089         }
39090     },
39091
39092     
39093
39094     deselectRange : function(U, V, W){
39095         if(this.locked) return;
39096         for(var  i = U; i <= V; i++){
39097             this.deselectRow(i, W);
39098         }
39099     },
39100
39101     
39102
39103     selectRow : function(X, Y, Z){
39104         if(this.locked || (X < 0 || X >= this.grid.dataSource.getCount())) return;
39105         if(this.fireEvent("beforerowselect", this, X, Y) !== false){
39106             if(!Y || this.singleSelect){
39107                 this.clearSelections();
39108             }
39109             var  r = this.grid.dataSource.getAt(X);
39110             this.selections.add(r);
39111             this.last = this.lastActive = X;
39112             if(!Z){
39113                 this.grid.getView().onRowSelect(X);
39114             }
39115
39116             this.fireEvent("rowselect", this, X, r);
39117             this.fireEvent("selectionchange", this);
39118         }
39119     },
39120
39121     
39122
39123     deselectRow : function(a, b){
39124         if(this.locked) return;
39125         if(this.last == a){
39126             this.last = false;
39127         }
39128         if(this.lastActive == a){
39129             this.lastActive = false;
39130         }
39131         var  r = this.grid.dataSource.getAt(a);
39132         this.selections.remove(r);
39133         if(!b){
39134             this.grid.getView().onRowDeselect(a);
39135         }
39136
39137         this.fireEvent("rowdeselect", this, a);
39138         this.fireEvent("selectionchange", this);
39139     },
39140
39141     
39142     restoreLast : function(){
39143         if(this._last){
39144             this.last = this._last;
39145         }
39146     },
39147
39148     
39149     acceptsNav : function(c, d, cm){
39150         return  !cm.isHidden(d) && cm.isCellEditable(d, c);
39151     },
39152
39153     
39154     onEditorKey : function(f, e){
39155         var  k = e.getKey(), h, g = this.grid, ed = g.activeEditor;
39156         if(k == e.TAB){
39157             e.stopEvent();
39158             ed.completeEdit();
39159             if(e.shiftKey){
39160                 h = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
39161             }else {
39162                 h = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
39163             }
39164         }else  if(k == e.ENTER && !e.ctrlKey){
39165             e.stopEvent();
39166             ed.completeEdit();
39167             if(e.shiftKey){
39168                 h = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
39169             }else {
39170                 h = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
39171             }
39172         }else  if(k == e.ESC){
39173             ed.cancelEdit();
39174         }
39175         if(h){
39176             g.startEditing(h[0], h[1]);
39177         }
39178     }
39179 });
39180
39181
39182
39183
39184 Roo.grid.CellSelectionModel = function(A){
39185     Roo.apply(this, A);
39186
39187     this.selection = null;
39188
39189     this.addEvents({
39190         
39191
39192             "beforecellselect" : true,
39193         
39194
39195             "cellselect" : true,
39196         
39197
39198             "selectionchange" : true
39199     });
39200     Roo.grid.CellSelectionModel.superclass.constructor.call(this);
39201 };
39202
39203 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
39204
39205     
39206
39207     initEvents : function(){
39208         this.grid.on("mousedown", this.handleMouseDown, this);
39209         this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
39210         var  B = this.grid.view;
39211         B.on("refresh", this.onViewChange, this);
39212         B.on("rowupdated", this.onRowUpdated, this);
39213         B.on("beforerowremoved", this.clearSelections, this);
39214         B.on("beforerowsinserted", this.clearSelections, this);
39215         if(this.grid.isEditor){
39216             this.grid.on("beforeedit", this.beforeEdit,  this);
39217         }
39218     },
39219
39220         
39221     beforeEdit : function(e){
39222         this.select(e.row, e.column, false, true, e.record);
39223     },
39224
39225         
39226     onRowUpdated : function(v, C, r){
39227         if(this.selection && this.selection.record == r){
39228             v.onCellSelect(C, this.selection.cell[1]);
39229         }
39230     },
39231
39232         
39233     onViewChange : function(){
39234         this.clearSelections(true);
39235     },
39236
39237         
39238
39239     getSelectedCell : function(){
39240         return  this.selection ? this.selection.cell : null;
39241     },
39242
39243     
39244
39245     clearSelections : function(D){
39246         var  s = this.selection;
39247         if(s){
39248             if(D !== true){
39249                 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
39250             }
39251
39252             this.selection = null;
39253             this.fireEvent("selectionchange", this, null);
39254         }
39255     },
39256
39257     
39258
39259     hasSelection : function(){
39260         return  this.selection ? true : false;
39261     },
39262
39263     
39264
39265     handleMouseDown : function(e, t){
39266         var  v = this.grid.getView();
39267         if(this.isLocked()){
39268             return;
39269         };
39270         var  E = v.findRowIndex(t);
39271         var  F = v.findCellIndex(t);
39272         if(E !== false && F !== false){
39273             this.select(E, F);
39274         }
39275     },
39276
39277     
39278
39279     select : function(G, H, I, J, 
39280  r){
39281         if(this.fireEvent("beforecellselect", this, G, H) !== false){
39282             this.clearSelections();
39283             r = r || this.grid.dataSource.getAt(G);
39284             this.selection = {
39285                 record : r,
39286                 cell : [G, H]
39287             };
39288             if(!I){
39289                 var  v = this.grid.getView();
39290                 v.onCellSelect(G, H);
39291                 if(J !== true){
39292                     v.focusCell(G, H);
39293                 }
39294             }
39295
39296             this.fireEvent("cellselect", this, G, H);
39297             this.fireEvent("selectionchange", this, this.selection);
39298         }
39299     },
39300
39301         
39302     isSelectable : function(K, L, cm){
39303         return  !cm.isHidden(L);
39304     },
39305
39306     
39307
39308     handleKeyDown : function(e){
39309         if(!e.isNavKeyPress()){
39310             return;
39311         }
39312         var  g = this.grid, s = this.selection;
39313         if(!s){
39314             e.stopEvent();
39315             var  F = g.walkCells(0, 0, 1, this.isSelectable,  this);
39316             if(F){
39317                 this.select(F[0], F[1]);
39318             }
39319             return;
39320         }
39321         var  sm = this;
39322         var  M = function(O, P, Q){
39323             return  g.walkCells(O, P, Q, sm.isSelectable,  sm);
39324         };
39325         var  k = e.getKey(), r = s.cell[0], c = s.cell[1];
39326         var  N;
39327
39328         switch(k){
39329              case  e.TAB:
39330                  if(e.shiftKey){
39331                      N = M(r, c-1, -1);
39332                  }else {
39333                      N = M(r, c+1, 1);
39334                  }
39335              break;
39336              case  e.DOWN:
39337                  N = M(r+1, c, 1);
39338              break;
39339              case  e.UP:
39340                  N = M(r-1, c, -1);
39341              break;
39342              case  e.RIGHT:
39343                  N = M(r, c+1, 1);
39344              break;
39345              case  e.LEFT:
39346                  N = M(r, c-1, -1);
39347              break;
39348              case  e.ENTER:
39349                  if(g.isEditor && !g.editing){
39350                     g.startEditing(r, c);
39351                     e.stopEvent();
39352                     return;
39353                 }
39354              break;
39355         };
39356         if(N){
39357             this.select(N[0], N[1]);
39358             e.stopEvent();
39359         }
39360     },
39361
39362     acceptsNav : function(O, P, cm){
39363         return  !cm.isHidden(P) && cm.isCellEditable(P, O);
39364     },
39365
39366     onEditorKey : function(Q, e){
39367         var  k = e.getKey(), R, g = this.grid, ed = g.activeEditor;
39368         if(k == e.TAB){
39369             if(e.shiftKey){
39370                 R = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
39371             }else {
39372                 R = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
39373             }
39374
39375             e.stopEvent();
39376         }else  if(k == e.ENTER && !e.ctrlKey){
39377             ed.completeEdit();
39378             e.stopEvent();
39379         }else  if(k == e.ESC){
39380             ed.cancelEdit();
39381         }
39382         if(R){
39383             g.startEditing(R[0], R[1]);
39384         }
39385     }
39386 });
39387
39388
39389  
39390
39391
39392 Roo.grid.EditorGrid = function(A, B){
39393     Roo.grid.EditorGrid.superclass.constructor.call(this, A, B);
39394     this.getGridEl().addClass("xedit-grid");
39395
39396     if(!this.selModel){
39397         this.selModel = new  Roo.grid.CellSelectionModel();
39398     }
39399
39400
39401     this.activeEditor = null;
39402
39403         this.addEvents({
39404             
39405
39406             "beforeedit" : true,
39407             
39408
39409             "afteredit" : true,
39410             
39411
39412             "validateedit" : true
39413         });
39414     this.on("bodyscroll", this.stopEditing,  this);
39415     this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick,  this);
39416 };
39417
39418 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
39419     
39420
39421     clicksToEdit: 2,
39422
39423     
39424     isEditor : true,
39425     
39426     trackMouseOver: false, 
39427
39428     onCellDblClick : function(g, C, D){
39429         this.startEditing(C, D);
39430     },
39431
39432     onEditComplete : function(ed, E, F){
39433         this.editing = false;
39434         this.activeEditor = null;
39435         ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
39436         var  r = ed.record;
39437         var  G = this.colModel.getDataIndex(ed.col);
39438         var  e = {
39439             grid: this,
39440             record: r,
39441             field: G,
39442             originalValue: F,
39443             value: E,
39444             row: ed.row,
39445             column: ed.col,
39446             cancel:false,
39447             editor: ed
39448         };
39449         if(String(E) !== String(F)){
39450             
39451             if(this.fireEvent("validateedit", e) !== false && !e.cancel){
39452                 r.set(G, e.value);
39453                 delete  e.cancel; 
39454                 this.fireEvent("afteredit", e);
39455             }
39456         } else  {
39457             this.fireEvent("afteredit", e); 
39458         }
39459
39460         this.view.focusCell(ed.row, ed.col);
39461     },
39462
39463     
39464
39465     startEditing : function(H, I){
39466         this.stopEditing();
39467         if(this.colModel.isCellEditable(I, H)){
39468             this.view.ensureVisible(H, I, true);
39469             var  r = this.dataSource.getAt(H);
39470             var  G = this.colModel.getDataIndex(I);
39471             var  e = {
39472                 grid: this,
39473                 record: r,
39474                 field: G,
39475                 value: r.data[G],
39476                 row: H,
39477                 column: I,
39478                 cancel:false
39479             };
39480             if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
39481                 this.editing = true;
39482                 var  ed = this.colModel.getCellEditor(I, H);
39483                 
39484                 if (!ed) {
39485                     return;
39486                 }
39487                 if(!ed.rendered){
39488                     ed.render(ed.parentEl || document.body);
39489                 }
39490
39491                 ed.field.reset();
39492                 (function(){ 
39493                     ed.row = H;
39494                     ed.col = I;
39495                     ed.record = r;
39496                     ed.on("complete", this.onEditComplete, this, {single: true});
39497                     ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
39498                     this.activeEditor = ed;
39499                     var  v = r.data[G];
39500                     ed.startEdit(this.view.getCell(H, I), v);
39501                 }).defer(50, this);
39502             }
39503         }
39504     },
39505         
39506     
39507
39508     stopEditing : function(){
39509         if(this.activeEditor){
39510             this.activeEditor.completeEdit();
39511         }
39512
39513         this.activeEditor = null;
39514     }
39515 });
39516
39517
39518
39519
39520
39521
39522
39523
39524 Roo.grid.GridEditor = function(A, B){
39525     if (!B && A.field) {
39526         B = A;
39527         A = Roo.factory(B.field, Roo.form);
39528     }
39529
39530     Roo.grid.GridEditor.superclass.constructor.call(this, A, B);
39531     A.monitorTab = false;
39532 };
39533
39534 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
39535     
39536     
39537
39538     
39539     alignment: "tl-tl",
39540     autoSize: "width",
39541     hideEl : false,
39542     cls: "x-small-editor x-grid-editor",
39543     shim:false,
39544     shadow:"frame"
39545 });
39546
39547
39548   
39549
39550   
39551 Roo.grid.PropertyRecord = Roo.data.Record.create([
39552     {name:'name',type:'string'},  'value'
39553 ]);
39554
39555
39556 Roo.grid.PropertyStore = function(A, B){
39557     this.grid = A;
39558     this.store = new  Roo.data.Store({
39559         recordType : Roo.grid.PropertyRecord
39560     });
39561     this.store.on('update', this.onUpdate,  this);
39562     if(B){
39563         this.setSource(B);
39564     }
39565
39566     Roo.grid.PropertyStore.superclass.constructor.call(this);
39567 };
39568
39569
39570
39571 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
39572     setSource : function(o){
39573         this.source = o;
39574         this.store.removeAll();
39575         var  C = [];
39576         for(var  k  in  o){
39577             if(this.isEditableValue(o[k])){
39578                 C.push(new  Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
39579             }
39580         }
39581
39582         this.store.loadRecords({records: C}, {}, true);
39583     },
39584
39585     onUpdate : function(ds, D, E){
39586         if(E == Roo.data.Record.EDIT){
39587             var  v = D.data['value'];
39588             var  oldValue = D.modified['value'];
39589             if(this.grid.fireEvent('beforepropertychange', this.source, D.id, v, oldValue) !== false){
39590                 this.source[D.id] = v;
39591                 D.commit();
39592                 this.grid.fireEvent('propertychange', this.source, D.id, v, oldValue);
39593             }else {
39594                 D.reject();
39595             }
39596         }
39597     },
39598
39599     getProperty : function(F){
39600        return  this.store.getAt(F);
39601     },
39602
39603     isEditableValue: function(G){
39604         if(G && G  instanceof  Date){
39605             return  true;
39606         }else  if(typeof  G == 'object' || typeof  G == 'function'){
39607             return  false;
39608         }
39609         return  true;
39610     },
39611
39612     setValue : function(H, I){
39613         this.source[H] = I;
39614         this.store.getById(H).set('value', I);
39615     },
39616
39617     getSource : function(){
39618         return  this.source;
39619     }
39620 });
39621
39622 Roo.grid.PropertyColumnModel = function(J, K){
39623     this.grid = J;
39624     var  g = Roo.grid;
39625     g.PropertyColumnModel.superclass.constructor.call(this, [
39626         {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
39627         {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
39628     ]);
39629     this.store = K;
39630     this.bselect = Roo.DomHelper.append(document.body, {
39631         tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
39632             {tag: 'option', value: 'true', html: 'true'},
39633             {tag: 'option', value: 'false', html: 'false'}
39634         ]
39635     });
39636     Roo.id(this.bselect);
39637     var  f = Roo.form;
39638     this.editors = {
39639         'date' : new  g.GridEditor(new  f.DateField({selectOnFocus:true})),
39640         'string' : new  g.GridEditor(new  f.TextField({selectOnFocus:true})),
39641         'number' : new  g.GridEditor(new  f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
39642         'int' : new  g.GridEditor(new  f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
39643         'boolean' : new  g.GridEditor(new  f.Field({el:this.bselect,selectOnFocus:true}))
39644     };
39645     this.renderCellDelegate = this.renderCell.createDelegate(this);
39646     this.renderPropDelegate = this.renderProp.createDelegate(this);
39647 };
39648
39649 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
39650     
39651     
39652     nameText : 'Name',
39653     valueText : 'Value',
39654     
39655     dateFormat : 'm/j/Y',
39656     
39657     
39658     renderDate : function(L){
39659         return  L.dateFormat(this.dateFormat);
39660     },
39661
39662     renderBool : function(M){
39663         return  M ? 'true' : 'false';
39664     },
39665
39666     isCellEditable : function(N, O){
39667         return  N == 1;
39668     },
39669
39670     getRenderer : function(P){
39671         return  P == 1 ?
39672             this.renderCellDelegate : this.renderPropDelegate;
39673     },
39674
39675     renderProp : function(v){
39676         return  this.getPropertyName(v);
39677     },
39678
39679     renderCell : function(Q){
39680         var  rv = Q;
39681         if(Q  instanceof  Date){
39682             rv = this.renderDate(Q);
39683         }else  if(typeof  Q == 'boolean'){
39684             rv = this.renderBool(Q);
39685         }
39686         return  Roo.util.Format.htmlEncode(rv);
39687     },
39688
39689     getPropertyName : function(R){
39690         var  pn = this.grid.propertyNames;
39691         return  pn && pn[R] ? pn[R] : R;
39692     },
39693
39694     getCellEditor : function(S, T){
39695         var  p = this.store.getProperty(T);
39696         var  n = p.data['name'], U = p.data['value'];
39697         
39698         if(typeof(this.grid.customEditors[n]) == 'string'){
39699             return  this.editors[this.grid.customEditors[n]];
39700         }
39701         if(typeof(this.grid.customEditors[n]) != 'undefined'){
39702             return  this.grid.customEditors[n];
39703         }
39704         if(U  instanceof  Date){
39705             return  this.editors['date'];
39706         }else  if(typeof  U == 'number'){
39707             return  this.editors['number'];
39708         }else  if(typeof  U == 'boolean'){
39709             return  this.editors['boolean'];
39710         }else {
39711             return  this.editors['string'];
39712         }
39713     }
39714 });
39715
39716
39717
39718 Roo.grid.PropertyGrid = function(V, W){
39719     W = W || {};
39720     var  X = new  Roo.grid.PropertyStore(this);
39721     this.store = X;
39722     var  cm = new  Roo.grid.PropertyColumnModel(this, X);
39723     X.store.sort('name', 'ASC');
39724     Roo.grid.PropertyGrid.superclass.constructor.call(this, V, Roo.apply({
39725         ds: X.store,
39726         cm: cm,
39727         enableColLock:false,
39728         enableColumnMove:false,
39729         stripeRows:false,
39730         trackMouseOver: false,
39731         clicksToEdit:1
39732     }, W));
39733     this.getGridEl().addClass('x-props-grid');
39734     this.lastEditRow = null;
39735     this.on('columnresize', this.onColumnResize, this);
39736     this.addEvents({
39737          
39738
39739         "beforepropertychange": true,
39740         
39741
39742         "propertychange": true
39743     });
39744     this.customEditors = this.customEditors || {};
39745 };
39746 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
39747     
39748      
39749
39750     
39751       
39752
39753     
39754     render : function(){
39755         Roo.grid.PropertyGrid.superclass.render.call(this);
39756         this.autoSize.defer(100, this);
39757     },
39758
39759     autoSize : function(){
39760         Roo.grid.PropertyGrid.superclass.autoSize.call(this);
39761         if(this.view){
39762             this.view.fitColumns();
39763         }
39764     },
39765
39766     onColumnResize : function(){
39767         this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
39768         this.autoSize();
39769     },
39770     
39771
39772     setSource : function(Y){
39773         this.store.setSource(Y);
39774         
39775     },
39776     
39777
39778     getSource : function(){
39779         return  this.store.getSource();
39780     }
39781 });
39782
39783
39784  
39785
39786
39787 Roo.LoadMask = function(el, A){
39788     this.el = Roo.get(el);
39789     Roo.apply(this, A);
39790     if(this.store){
39791         this.store.on('beforeload', this.onBeforeLoad, this);
39792         this.store.on('load', this.onLoad, this);
39793         this.store.on('loadexception', this.onLoad, this);
39794         this.removeMask = false;
39795     }else {
39796         var  um = this.el.getUpdateManager();
39797         um.showLoadIndicator = false; 
39798         um.on('beforeupdate', this.onBeforeLoad, this);
39799         um.on('update', this.onLoad, this);
39800         um.on('failure', this.onLoad, this);
39801         this.removeMask = true;
39802     }
39803 };
39804
39805 Roo.LoadMask.prototype = {
39806     
39807
39808     
39809
39810     msg : 'Loading...',
39811     
39812
39813     msgCls : 'x-mask-loading',
39814
39815     
39816
39817     disabled: false,
39818
39819     
39820
39821     disable : function(){
39822        this.disabled = true;
39823     },
39824
39825     
39826
39827     enable : function(){
39828         this.disabled = false;
39829     },
39830
39831     
39832     onLoad : function(){
39833         this.el.unmask(this.removeMask);
39834     },
39835
39836     
39837     onBeforeLoad : function(){
39838         if(!this.disabled){
39839             this.el.mask(this.msg, this.msgCls);
39840         }
39841     },
39842
39843     
39844     destroy : function(){
39845         if(this.store){
39846             this.store.un('beforeload', this.onBeforeLoad, this);
39847             this.store.un('load', this.onLoad, this);
39848             this.store.un('loadexception', this.onLoad, this);
39849         }else {
39850             var  um = this.el.getUpdateManager();
39851             um.un('beforeupdate', this.onBeforeLoad, this);
39852             um.un('update', this.onLoad, this);
39853             um.un('failure', this.onLoad, this);
39854         }
39855     }
39856 };
39857
39858
39859 Roo.XTemplate = function(){
39860     Roo.XTemplate.superclass.constructor.apply(this, arguments);
39861     var  s = this.html;
39862
39863     s = ['<tpl>', s, '</tpl>'].join('');
39864
39865     var  re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;
39866
39867     var  A = /^<tpl\b[^>]*?for="(.*?)"/;
39868     var  B = /^<tpl\b[^>]*?if="(.*?)"/;
39869     var  C = /^<tpl\b[^>]*?exec="(.*?)"/;
39870     var  m, id = 0;
39871     var  D = [];
39872
39873     while(m = s.match(re)){
39874        var  m2 = m[0].match(A);
39875        var  m3 = m[0].match(B);
39876        var  m4 = m[0].match(C);
39877        var  exp = null, fn = null, exec = null;
39878        var  name = m2 && m2[1] ? m2[1] : '';
39879        if(m3){
39880            exp = m3 && m3[1] ? m3[1] : null;
39881            if(exp){
39882                fn = new  Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
39883            }
39884        }
39885        if(m4){
39886            exp = m4 && m4[1] ? m4[1] : null;
39887            if(exp){
39888                exec = new  Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
39889            }
39890        }
39891        if(name){
39892            switch(name){
39893                case  '.': name = new  Function('values', 'parent', 'with(values){ return values; }'); break;
39894                case  '..': name = new  Function('values', 'parent', 'with(values){ return parent; }'); break;
39895                default: name = new  Function('values', 'parent', 'with(values){ return '+name+'; }');
39896            }
39897        }
39898
39899        D.push({
39900             id: id,
39901             target: name,
39902             exec: exec,
39903             test: fn,
39904             body: m[1]||''
39905         });
39906        s = s.replace(m[0], '{xtpl'+ id + '}');
39907        ++id;
39908     }
39909     for(var  i = D.length-1; i >= 0; --i){
39910         this.compileTpl(D[i]);
39911     }
39912
39913     this.master = D[D.length-1];
39914     this.tpls = D;
39915 };
39916 Roo.extend(Roo.XTemplate, Roo.Template, {
39917
39918     re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
39919
39920     applySubTemplate : function(id, E, F){
39921         var  t = this.tpls[id];
39922         if(t.test && !t.test.call(this, E, F)){
39923             return  '';
39924         }
39925         if(t.exec && t.exec.call(this, E, F)){
39926             return  '';
39927         }
39928         var  vs = t.target ? t.target.call(this, E, F) : E;
39929         F = t.target ? E : F;
39930         if(t.target && vs  instanceof  Array){
39931             var  buf = [];
39932             for(var  i = 0, len = vs.length; i < len; i++){
39933                 buf[buf.length] = t.compiled.call(this, vs[i], F);
39934             }
39935             return  buf.join('');
39936         }
39937         return  t.compiled.call(this, vs, F);
39938     },
39939
39940     compileTpl : function(G){
39941         var  fm = Roo.util.Format;
39942         var  H = this.disableFormats !== true;
39943         var  I = Roo.isGecko ? "+" : ",";
39944         var  fn = function(m, K, L, M){
39945             if(K.substr(0, 4) == 'xtpl'){
39946                 return  "'"+ I +'this.applySubTemplate('+K.substr(4)+', values, parent)'+I+"'";
39947             }
39948             var  v;
39949             if(K.indexOf('.') != -1){
39950                 v = K;
39951             }else {
39952                 v = "values['" + K + "']";
39953             }
39954             if(L && H){
39955                 M = M ? ',' + M : "";
39956                 if(L.substr(0, 5) != "this."){
39957                     L = "fm." + L + '(';
39958                 }else {
39959                     L = 'this.call("'+ L.substr(5) + '", ';
39960                     M = ", values";
39961                 }
39962             }else {
39963                 M= ''; L = "("+v+" === undefined ? '' : ";
39964             }
39965             return  "'"+ I + L + v + M + ")"+I+"'";
39966         };
39967         var  J;
39968         
39969         if(Roo.isGecko){
39970             J = "tpl.compiled = function(values, parent){ return '" +
39971                    G.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
39972                     "';};";
39973         }else {
39974             J = ["tpl.compiled = function(values, parent){ return ['"];
39975             J.push(G.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
39976             J.push("'].join('');};");
39977             J = J.join('');
39978         }
39979         
39980
39981         eval(J);
39982         return  this;
39983     },
39984
39985     applyTemplate : function(K){
39986         return  this.master.compiled.call(this, K, {});
39987         var  s = this.subs;
39988     },
39989
39990     apply : function(){
39991         return  this.applyTemplate.apply(this, arguments);
39992     },
39993
39994     compile : function(){return  this;}
39995 });
39996
39997 Roo.XTemplate.from = function(el){
39998     el = Roo.getDom(el);
39999     return  new  Roo.XTemplate(el.value || el.innerHTML);
40000 };
40001
40002
40003  
40004
40005
40006 Roo.XComponent = function(A) {
40007     Roo.apply(this, A);
40008     this.addEvents({ 
40009         
40010
40011         'built' : true,
40012         
40013
40014         'buildcomplete' : true,
40015         
40016     });
40017     
40018     Roo.XComponent.register(this);
40019     this.modules = false;
40020     this.el = false; 
40021     
40022     
40023 }
40024
40025 Roo.extend(Roo.XComponent, Roo.util.Observable, {
40026     
40027
40028     el  : false,
40029     
40030     
40031
40032     panel : false,
40033     
40034     
40035
40036     layout : false,
40037     
40038      
40039
40040     disabled : false,
40041     
40042     
40043
40044     parent: false,
40045     
40046     
40047
40048     
40049     order : false,
40050     
40051
40052     name : false,
40053     
40054
40055     items : false,
40056      
40057      
40058     
40059 });
40060
40061 Roo.apply(Roo.XComponent, {
40062     
40063     
40064
40065     buildCompleted : false,
40066      
40067     
40068
40069      
40070     topModule  : false,
40071       
40072     
40073
40074     
40075     modules : [],
40076       
40077     
40078     
40079
40080     register : function(B) {
40081         this.modules.push(B);
40082          
40083     },
40084     
40085
40086     
40087     toObject : function(C)
40088     {
40089         if (!C || typeof(C) == 'object') {
40090             return  C;
40091         }
40092         var  ar = C.split('.');
40093         var  rt, o;
40094         rt = ar.shift();
40095             
40096
40097         eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
40098         if (o === false) {
40099             throw  "Module not found : " + C;
40100         }
40101
40102         Roo.each(ar, function(e) {
40103             if (typeof(o[e]) == 'undefined') {
40104                 throw  "Module not found : " + C;
40105             }
40106
40107             o = o[e];
40108         });
40109         return  o;
40110         
40111     },
40112     
40113     
40114     
40115
40116     preBuild : function ()
40117     {
40118         
40119         Roo.each(this.modules , function (D)
40120         {
40121             D.parent = this.toObject(D.parent);
40122             
40123             if (!D.parent) {
40124                 this.topModule = D;
40125                 return;
40126             }
40127             
40128             if (!D.parent.modules) {
40129                 D.parent.modules = new  Roo.util.MixedCollection(false, 
40130                     function(o) { return  o.order + '' }
40131                 );
40132             }
40133
40134             
40135             D.parent.modules.add(D);
40136         }, this);
40137     },
40138     
40139      
40140  
40141     
40142     buildOrder : function()
40143     {
40144         var  D = this;
40145         var  E = function(a,b) {   
40146             return  String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
40147         };
40148         
40149         if (!this.topModule || !this.topModule.modules) {
40150             throw  "No top level modules to build";
40151         }
40152        
40153         
40154         var  F = [ this.topModule ];
40155         
40156         
40157         
40158         var  G = function(m) {
40159            
40160             
40161             F.push(m);
40162             if (m.modules) {
40163                 m.modules.keySort('ASC',  E );
40164                 m.modules.each(G);
40165             }
40166             
40167             if (m.finalize) {
40168                 m.finalize.name = m.name + " (clean up) ";
40169                 F.push(m.finalize);
40170             }
40171             
40172         }
40173
40174         this.topModule.modules.keySort('ASC',  E );
40175         this.topModule.modules.each(G);
40176         return  F;
40177     },
40178     
40179      
40180  
40181    
40182     build : function() 
40183     {
40184         
40185         this.preBuild();
40186         var  H = this.buildOrder();
40187       
40188         
40189         
40190         
40191         if (!H.length) { 
40192             throw  "NO modules!!!";
40193         }
40194
40195         
40196         
40197         
40198         
40199         Roo.MessageBox.show({ title: 'loading' });
40200         Roo.MessageBox.show({
40201            title: "Please wait...",
40202            msg: "Building Interface...",
40203            width:450,
40204            progress:true,
40205            closable:false,
40206            modal: false
40207           
40208         });
40209         var  I = H.length;
40210         
40211         var  J = this;
40212         var  K = function() {
40213             if (!H.length) {
40214                 console.log('hide?');
40215                 Roo.MessageBox.hide();
40216                 J.topModule.fireEvent('buildcomplete', J.topModule);
40217                 return;    
40218             }
40219             
40220             var  m = H.shift();
40221             console.log(m);
40222             if (typeof(m) == 'function') { 
40223                 m.call(this);
40224                 return  K.defer(10, J);
40225             } 
40226             
40227             Roo.MessageBox.updateProgress(
40228                 (I  - H.length)/I,  "Building Interface " + (I  - H.length) + 
40229                     " of " + I + 
40230                     (m.name ? (' - ' + m.name) : '')
40231                     );
40232             
40233          
40234             
40235             var  L = (typeof(m.disabled) == 'function') ?
40236                 m.disabled.call(m.module.disabled) : m.disabled;    
40237             
40238             
40239             if (L) {
40240                 return  K(); 
40241             }
40242             
40243             if (!m.parent) {
40244                 
40245                 var  layoutbase = new  Ext.BorderLayout(document.body, {
40246                
40247                     center: {
40248                          titlebar: false,
40249                          autoScroll:false,
40250                          closeOnTab: true,
40251                          tabPosition: 'top',
40252                          
40253                          alwaysShowTabs: true,
40254                          minTabWidth: 140
40255                     }
40256                 });
40257                 var  M = m.tree();
40258                 M.region = 'center';
40259                 m.el = layoutbase.addxtype(M);
40260                 m.panel = m.el;
40261                 m.layout = m.panel.layout;    
40262                 return  K.defer(10, J);
40263             }
40264             
40265             var  M = m.tree();
40266             M.region = M.region || m.region;
40267             m.el = m.parent.el.addxtype(M);
40268             m.fireEvent('built', m);
40269             m.panel = m.el;
40270             m.layout = m.panel.layout;    
40271             K.defer(10, J); 
40272             
40273         }
40274
40275         K.defer(1, J);
40276      
40277         
40278         
40279     }
40280      
40281    
40282     
40283     
40284 });
40285  
40286
40287
40288
40289
40290
40291  
40292 Roo.Login = function(A)
40293 {
40294     this.addEvents({
40295         'refreshed' : true,
40296     });
40297     
40298     Roo.apply(this,A);
40299     
40300     Roo.onReady(function() {
40301         this.onLoad();
40302     }, this);
40303     
40304     
40305    
40306     Roo.Login.superclass.constructor.call(this, this);
40307     
40308     
40309     
40310 }
40311
40312
40313
40314 Roo.extend(Roo.Login, Roo.LayoutDialog, {
40315     
40316     
40317
40318     
40319     method : 'POST',
40320     
40321
40322     url : '',
40323     
40324     
40325
40326     user : false,
40327     
40328
40329     checkFails : 0,
40330       
40331
40332     intervalID : 0,
40333     
40334     
40335     onLoad : function() 
40336     {
40337         
40338          
40339         if (Roo.get('loading')) { 
40340             Roo.get('loading').remove();
40341         }
40342
40343         
40344         
40345        
40346         this.check({
40347             success:  function(B, C)  {  
40348             
40349                 var  D = this.processResponse(B);
40350                 this.checkFails =0;
40351                 if (!D.success) { 
40352                     this.checkFails = 5;
40353                     
40354                     return  this.failure(B,C);
40355                 }
40356                 
40357                 if (!D.data.id) { 
40358                     return  this.show();
40359                 }
40360
40361                 
40362                               
40363                         
40364                 this.fillAuth(D.data);   
40365                 this.checkFails =0;
40366                 Roo.XComponent.build();
40367             },
40368             failure : this.show
40369         });
40370         
40371     }, 
40372     
40373     
40374     check: function(B) 
40375     {
40376         if (B.again) { 
40377             this.checkFails++;
40378         } else  {
40379             this.checkFails = 0;
40380         }
40381         var  C = this;
40382         if (this.sending) {
40383             if ( this.checkFails > 4) {
40384                 Roo.MessageBox.alert("Error",  
40385                     "Error getting authentication status. - try reloading, or wait a while", function() {
40386                         C.sending = false;
40387                     }); 
40388                 return;
40389             }
40390
40391             B.again = true;
40392             C.check.defer(10000, C, [ B ]); 
40393             return;
40394         }
40395
40396         this.sending = true;
40397         
40398         Roo.Ajax.request({  
40399             url: this.url,
40400             params: {
40401                 getAuthUser: true
40402             },  
40403             method: this.method,
40404             success:  B.success || this.success,
40405             failure : B.failure || this.failure,
40406             scope : this,
40407             callCfg : B
40408               
40409         });  
40410     }, 
40411     
40412     
40413     logout: function()
40414     {
40415         window.onbeforeunload = function() { }; 
40416         this.user = false;
40417         var  D = this;
40418         
40419         Roo.Ajax.request({  
40420             url: this.url,
40421             params: {
40422                 logout: 1
40423             },  
40424             method: 'GET',
40425             failure : function() {
40426                 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
40427                     document.location = document.location.toString() + '?ts=' + Math.random();
40428                 });
40429                 
40430             },
40431             success : function() {
40432                 D.user = false;
40433                 this.checkFails =0;
40434                 
40435                 document.location = document.location.toString() + '?ts=' + Math.random();
40436             }
40437               
40438               
40439         }); 
40440     },
40441     
40442     processResponse : function (E)
40443     {
40444         var  F = '';
40445         try {
40446             F = Roo.decode(E.responseText);
40447             
40448             if (typeof(F) != 'object') {
40449                 F = { success : false, errorMsg : F, errors : true };
40450             }
40451             if (typeof(F.success) == 'undefined') {
40452                 F.success = false;
40453             }
40454             
40455         } catch(e) {
40456             res = { success : false,  errorMsg : response.responseText, errors : true };
40457         }
40458         return  F;
40459     },
40460     
40461     success : function(G, H)  
40462     {  
40463         this.sending = false;
40464         var  I = this.processResponse(G);
40465         if (!I.success) {
40466             return  this.failure(G, H);
40467         }
40468         if (!I.data || !I.data.id) {
40469             return  this.failure(G,H);
40470         }
40471
40472         
40473         this.fillAuth(I.data);
40474         
40475         this.checkFails =0;
40476         
40477     },
40478     
40479     
40480     failure : function (J, K) 
40481     {
40482         this.authUser = -1;
40483         this.sending = false;
40484         var  L = this.processResponse(J);
40485         
40486         if ( this.checkFails > 2) {
40487         
40488             Roo.MessageBox.alert("Error", L.errorMsg ? L.errorMsg : 
40489                 "Error getting authentication status. - try reloading"); 
40490             return;
40491         }
40492
40493         K.callCfg.again = true;
40494         this.check.defer(1000, this, [ K.callCfg ]);
40495         return;  
40496     },
40497     
40498     
40499     
40500     fillAuth: function(au) {
40501         this.startAuthCheck();
40502         this.authUserId = au.id;
40503         this.authUser = au;
40504         this.lastChecked = new  Date();
40505         this.fireEvent('refreshed', au);
40506         
40507         
40508         au.lang = au.lang || 'en';
40509         
40510         Roo.state.Manager.set( this.realm + 'lang' , au.lang);
40511         this.switchLang(au.lang );
40512         
40513      
40514         
40515         if (this.authUserId  < 0) {
40516             Roo.MessageBox.alert("Warning", 
40517                 "This is an open system - please set up a admin user with a password.");  
40518         }
40519          
40520         
40521         
40522              
40523     },
40524     
40525     startAuthCheck : function() 
40526     {
40527         if (this.intervalID) { 
40528             return  false;
40529         }
40530         var  M = this;
40531         this.intervalID =  window.setInterval(function() {
40532               M.check(false);
40533             }, 120000); 
40534         
40535         
40536     },
40537          
40538     
40539     switchLang : function (N) 
40540     {
40541         _T = typeof(_T) == 'undefined' ? false : _T;
40542           if (!_T || !N.length) {
40543             return;
40544         }
40545         
40546         if (!_T && N != 'en') {
40547             Roo.MessageBox.alert("Sorry", "Language not available yet (" + N +')');
40548             return;
40549         }
40550         
40551         if (typeof(_T.en) == 'undefined') {
40552             _T.en = {};
40553             Roo.apply(_T.en, _T);
40554         }
40555         
40556         if (typeof(_T[N]) == 'undefined') {
40557             Roo.MessageBox.alert("Sorry", "Language not available yet (" + N +')');
40558             return;
40559         }
40560
40561         
40562         
40563         Roo.apply(_T, _T[N]);
40564         
40565         var  O = this;
40566         
40567
40568         
40569         
40570     },
40571     
40572     
40573     title: "Login",
40574     modal: true,
40575     width:  350,
40576     
40577     height: 180,
40578     shadow: true,
40579     minWidth:200,
40580     minHeight:180,
40581     
40582     closable: false,
40583     draggable: false,
40584     collapsible: false,
40585     resizable: false,
40586     center: {  
40587         autoScroll:false,
40588         titlebar: false,
40589        
40590         hideTabs: true,
40591         closeOnTab: true,
40592         alwaysShowTabs: false
40593     } ,
40594     listeners : {
40595         
40596         show  : function(P)
40597         {
40598             
40599             this.form = this.layout.getRegion('center').activePanel.form;
40600             this.form.dialog = P;
40601             this.buttons[0].form = this.form;
40602             this.buttons[0].dialog = P
40603             this.buttons[1].form = this.form;
40604             this.buttons[1].dialog = P;
40605            
40606            
40607             
40608             
40609            
40610              
40611              
40612            
40613             
40614             
40615             
40616             
40617             if (this.disabled) {
40618                 this.hide();
40619                 return;
40620             }
40621             
40622             if (this.user.id < 0) { 
40623                 return;
40624             }
40625             
40626             if (this.intervalID) {
40627                 
40628                 window.clearInterval(this.intervalID);
40629                 this.intervalID = false;
40630             }
40631             
40632             
40633             if (Roo.get('loading')) {
40634                 Roo.get('loading').remove();
40635             }
40636             if (Roo.get('loading-mask')) {
40637                 Roo.get('loading-mask').hide();
40638             }
40639
40640             
40641             
40642             this.form.reset();
40643             
40644             
40645             this.el.unmask(); 
40646             
40647             
40648             this.form.setValues({
40649                 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
40650                 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
40651             });
40652             
40653             this.switchLang(Roo.state.Manager.get(this.realm + '.lang', 'en'));
40654             if (this.form.findField('username').getValue().length > 0 ){
40655                 this.form.findField('password').focus();
40656             } else  {
40657                this.form.findField('username').focus();
40658             }
40659     
40660         }
40661     },
40662     items : [
40663          {
40664        
40665             xtype : 'ContentPanel',
40666             xns : Roo,
40667             region: 'center',
40668             fitToFrame : true,
40669             
40670             items : [
40671     
40672                 {
40673                
40674                     xtype : 'Form',
40675                     xns : Roo.form,
40676                     labelWidth: 100,
40677                     style : 'margin: 10px;',
40678                     
40679                     listeners : {
40680                         actionfailed : function(f, Q) {
40681                             
40682                                 
40683                             
40684                             
40685                             
40686                             this.dialog.el.unmask();
40687                             Roo.MessageBox.alert("Error", Q.result.errorMsg ? Q.result.errorMsg : 
40688                                         "Login failed - communication error - try again.");
40689                                       
40690                         },
40691                         actioncomplete: function(re, R) {
40692                              
40693                             Roo.state.Manager.set(
40694                                 this.dialog.realm + '.username',  
40695                                     this.findField('username').getValue()
40696                             );
40697                             Roo.state.Manager.set(
40698                                 this.dialog.realm + '.lang',  
40699                                 this.findField('lang').getValue() 
40700                             );
40701                             
40702                             this.dialog.fillAuth(R.result.data);
40703                               
40704                             this.dialog.hide();
40705                             
40706                             if (Roo.get('loading-mask')) {
40707                                 Roo.get('loading-mask').show();
40708                             }
40709
40710                             Roo.XComponent.build();
40711                             
40712                              
40713                             
40714                         }
40715                     },
40716                     items : [
40717                         {
40718                             xtype : 'TextField',
40719                             xns : Roo.form,
40720                             fieldLabel: "Email Address",
40721                             name: 'username',
40722                             width:200,
40723                             autoCreate : {tag: "input", type: "text", size: "20"}
40724                         },
40725                         {
40726                             xtype : 'TextField',
40727                             xns : Roo.form,
40728                             fieldLabel: "Password",
40729                             inputType: 'password',
40730                             name: 'password',
40731                             width:200,
40732                             autoCreate : {tag: "input", type: "text", size: "20"},
40733                             listeners : {
40734                                 specialkey : function(e,ev) {
40735                                     if (ev.keyCode == 13) {
40736                                         this.form.dialog.el.mask("Logging in");
40737                                         this.form.doAction('submit', {
40738                                             url: this.form.dialog.url,
40739                                             method: this.form.dialog.method,
40740                                         });
40741                                     }
40742                                 }
40743                             }  
40744                         },
40745                         {
40746                             xtype : 'ComboBox',
40747                             xns : Roo.form,
40748                             fieldLabel: "Language",
40749                             name : 'langdisp',
40750                             store: {
40751                                 xtype : 'SimpleStore',
40752                                 fields: ['lang', 'ldisp'],
40753                                 data : [
40754                                     [ 'en', 'English' ],
40755                                     [ 'zh_HK' , '\u7E41\u4E2D' ],
40756                                     [ 'zh_CN', '\u7C21\u4E2D' ]
40757                                 ]
40758                             },
40759                             
40760                             valueField : 'lang',
40761                             hiddenName:  'lang',
40762                             width: 200,
40763                             displayField:'ldisp',
40764                             typeAhead: false,
40765                             editable: false,
40766                             mode: 'local',
40767                             triggerAction: 'all',
40768                             emptyText:'Select a Language...',
40769                             selectOnFocus:true,
40770                             listeners : {
40771                                 select :  function(cb, S, ix) {
40772                                     this.form.switchLang(S.data.lang);
40773                                 }
40774                             }
40775                         
40776                         }
40777                     ]
40778                 }
40779                   
40780                 
40781             ]
40782         }
40783     ],
40784     buttons : [
40785         {
40786             xtype : 'Button',
40787             xns : 'Roo',
40788             text : "Forgot Password",
40789             listeners : {
40790                 click : function() {
40791                     
40792                     var  n = this.form.findField('username').getValue();
40793                     if (!n.length) {
40794                         Roo.MessageBox.alert("Error", "Fill in your email address");
40795                         return;
40796                     }
40797
40798                     Roo.Ajax.request({
40799                         url: this.dialog.url,
40800                         params: {
40801                             passwordRequest: n
40802                         },
40803                         method: this.dialog.method,
40804                         success:  function(T, U)  {  
40805                         
40806                             var  V = this.dialog.processResponse(T);
40807                             if (!V.success) { 
40808                                Roo.MessageBox.alert("Error" ,
40809                                     V.errorMsg ? V.errorMsg  : "Problem Requesting Password Reset");
40810                                return;
40811                             }
40812
40813                             Roo.MessageBox.alert("Notice" ,
40814                                 "Please check you email for the Password Reset message");
40815                         },
40816                         failure : function() {
40817                             Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
40818                         }
40819                         
40820                     });
40821                 }
40822             }
40823         },
40824         {
40825             xtype : 'Button',
40826             xns : 'Roo',
40827             text : "Login",
40828             listeners : {
40829                 
40830                 click : function () {
40831                         
40832                     this.dialog.el.mask("Logging in");
40833                     this.form.doAction('submit', {
40834                             url: this.dialog.url,
40835                             method: this.dialog.method
40836                     });
40837                 }
40838             }
40839         }
40840     ]
40841   
40842   
40843 })
40844  
40845
40846
40847