(function(){Ext.util.Observable.prototype.constructor=Ext.util.Observable.prototype.constructor.createInterceptor(function(){if(this.initialConfig){var id=this.initialConfig.proxyId||this.initialConfig.id;if(!Ext.isEmpty(id,false)){window[id]=this;}}});Ext.util.Observable.prototype.constructor.prototype=Ext.util.Observable.prototype;var fns={},v;for(var i in Ext.util.Observable){v=Ext.util.Observable[i];if(typeof v=="function"){fns[i]=v;}}
Ext.util.Observable=Ext.util.Observable.prototype.constructor;Ext.applyIf(Ext.util.Observable,fns);})();

Ext.override(Ext.util.Observable,{
			 fireEvent:function(){
				if(!(this.isAjaxInit||false)){
					this.isAjaxInit=true;
					this.ajaxListeners={};
					if(this.ajaxEvents){this.addAjaxListener(this.ajaxEvents);}
				}
				if(this.eventsSuspended!==true){
					var ce=this.events[arguments[0].toLowerCase()],answer=true;
					if(typeof ce=="object"){answer=ce.fire.apply(ce,Array.prototype.slice.call(arguments,1));}
					if(answer!==false){
						var ace=this.ajaxListeners[arguments[0].toLowerCase()];
						if(typeof ace=="object"){return ace.fire.apply(ace,Array.prototype.slice.call(arguments,1));}
					}
					return answer;
				}
				return true;
			},
			addAjaxListener:function(eventName,fn,scope,o){
				if(typeof eventName=="object"){
					o=eventName;
					for(var e in o){
						if(this.filterOptRe.test(e)){continue;}
						if(typeof o[e]=="function"){this.addAjaxListener(e,o[e],o.scope,o);}
						else{this.addAjaxListener(e,o[e].fn,o[e].scope,o[e]);}
					}
					return;
				}
				o=(!o||typeof o=="boolean")?{}:o;eventName=eventName.toLowerCase();
				var ce=this.ajaxListeners[eventName]||true;
				if(typeof ce=="boolean"){ce=new Ext.util.Event(this,eventName);this.ajaxListeners[eventName]=ce;}
				if(Ext.isEmpty(o.delay)){o.delay=20;}
				ce.addListener(fn,scope,o);
			}
		});

Ext.isEmptyObj=function(obj){if(!(!Ext.isEmpty(obj)&&typeof obj=="object")){return false;}for(var p in obj){return false;}return true;};


Ext.apply(Ext.form.VTypes,{daterange:function(val,field){var date=field.parseDate(val),dispUpd=function(picker){var ad=picker.activeDate;if(ad){picker.activeDate=null;picker.update(ad);}};if(field.startDateField){var sd=Ext.getCmp(field.startDateField);sd.maxValue=date;if(sd.menu&&sd.menu.picker){sd.menu.picker.maxDate=date;dispUpd(sd.menu.picker);}}else if(field.endDateField){var ed=Ext.getCmp(field.endDateField);ed.minValue=date;if(ed.menu&&ed.menu.picker){ed.menu.picker.minDate=date;dispUpd(ed.menu.picker);}}
return true;}});

Ext.override(Ext.Component,{addPlugins:function(plugins){if(Ext.isEmpty(this.plugins)){this.plugins=[];}else if(!Ext.isArray(this.plugins)){this.plugins=[this.plugins];}
if(Ext.isArray(plugins)){for(var i=0;i<plugins.length;i++){this.plugins.push(this.initPlugin(plugins[i]));}}else{this.plugins.push(this.initPlugin(plugins));}},getForm:function(id){var form=Ext.isEmpty(id)?this.el.up("form"):Ext.get(id);if(!Ext.isEmpty(form)){Ext.apply(form,form.dom);form.submit=function(){form.dom.submit();};}
return form;},setFieldLabel:function(text){try{this.container.parent().child("label").update(text);}catch(e){}}});

Ext.BoxComponent.override({getWidth:function(){return this.getSize().width;},getHeight:function(){return this.getSize().height;}});

Ext.Panel.override(
				   {
				       addButton: function (config, handler, scope) {
				           var bc = { handler: handler, scope: scope, minWidth: this.minButtonWidth, hideParent: true };
				           if (typeof config == "string") { bc.text = config; } else { Ext.apply(bc, config); }
				           var btn = Ext.ComponentMgr.create(bc, "button");
				           btn.ownerCt = this;
				           if (!this.buttons) { this.buttons = []; }
				           this.buttons.push(btn);
				           return btn;
				       },
				       getCollapsedField: function () {
				           if (!this.collapsedField) {
				               this.collapsedField = new Ext.form.Hidden({ id: this.id + "_Collapsed", name: this.id + "_Collapsed", value: this.collapsed || false });
				               this.collapsedField.render(this.el.parent() || this.el);
				           }
				           return this.collapsedField.el;
				       },
				       getBody: function () {
				           if (this.iframe) { return this.iframe.dom.contentWindow; }
				           return Ext.get(this.id + "_Body") || this.body;
				       },
				       setAutoScroll: function () {
				           if (this.rendered && this.autoScroll) { var el = this.body || this.el; if (el) { el.setOverflow("auto"); el.dom.style.position = "relative"; } }
				           return this;
				       },
				       isIFrame: function (cfg) {
				           var frame = false; if (typeof cfg == "string" && cfg.indexOf("://") >= 0) { frame = true; }
				           else if (cfg.mode) { if (cfg.mode == "iframe") { frame = true; } }
				           else if (cfg.url && cfg.url.indexOf("://") >= 0) { frame = true; }
				           else if ((this.getAutoLoad().url && this.autoLoad.url.indexOf("://") >= 0) || (this.getAutoLoad().mode && this.autoLoad.mode == "iframe")) { frame = true; }
				           return frame;
				       },
				       load: function (config) {
				           if (!Ext.isEmpty(config) && !Ext.isEmptyObj(config)) {
				               if (config.passParentSize) {
				                   config.params = config.params || {};
				                   config.params.width = this.body.getWidth(true);
				                   config.params.height = this.body.getHeight(true);
				               }
				               if (this.isIFrame(config)) { return this.loadIFrame(config); }
				               var um = this.body.getUpdater();
				               um.update.apply(um, arguments);
				           }
				           return this;
				       },
				       doAutoLoad: function () { },
				       reload: function (nocache) { this.getAutoLoad().nocache = nocache || this.autoLoad.nocache; this.load(this.getAutoLoad()); },
				       getAutoLoad: function () { this.autoLoad = this.autoLoad || {}; return this.autoLoad; },
				       loadContent: function (config) { this.load(config); },
				       clearContent: function () {
				           if (this.iframe) {
				               this.iframe.un("load", this.afterLoad, this);
				               this.iframe.remove();
				               delete this.iframe;
				               if (this.body.isMasked()) { this.body.unmask(); }
				           } else { this.body.innerHTML = ""; }
				       },
				       loadIFrame: function (config) {
				           var al = this.getAutoLoad(), url;
				           if (typeof config == "string") { al.url = config; } else if (typeof config == "object") { Ext.apply(al, config); }
				           if (Ext.isEmpty(al.url)) { return; }
				           url = al.url;
				           if (al.nocache === true) { url = url + ((url.indexOf("?") > -1) ? "&" : "?") + new Date().getTime(); }
				           if (al.params) {
				               var params = {};
				               for (var key in al.params) {
				                   var ov = al.params[key]; if (typeof ov == "function") { params[key] = ov.call(window); } else { params[key] = ov; }
				               }
				               params = Ext.urlEncode(params);
				               url = url + ((url.indexOf("?") > -1) ? "&" : "?") + params;
				           }
				           if (al.showMask && Ext.isGecko) { this.body.mask(al.maskMsg || "Loading...", al.maskCls || "x-mask-loading"); }
				           if (Ext.isEmpty(this.iframe)) {
				               var iframeObj = { tag: "iframe", width: "100%", height: "100%", frameborder: 0, id: this.id + "_IFrame", name: this.id + "_IFrame", cls: al.cls || "", src: url, scrolling: "auto" };
				               this.iframe = Ext.get(Ext.DomHelper.insertFirst(this.body, iframeObj));
				               this.iframe.on("load", this.afterLoad, this);
				               this.fireEvent("beforeupdate", this, { url: url, iframe: this.iframe });
				           } else {
				               this.iframe.dom.src = String.format("java{0}", "script:false");
				               this.fireEvent("beforeupdate", this, { url: this.iframe.dom.src, iframe: this.iframe });
				               this.iframe.dom.src = url;
				           }
				           if (al.showMask && !Ext.isGecko) { this.body.mask(al.maskMsg || "Loading...", al.maskCls || "x-mask-loading"); }
				           this.autoLoad = al; return this;
				       }, afterLoad: function () {
				           if (this.autoLoad.showMask) { this.body.unmask(); }
				           this.fireEvent("update", this, { iframe: this.iframe, url: this.iframe.dom.src });
				       },
				       autoLoadBeforeUpdate: function (el, url, params) {
				           this.fireEvent("beforeupdate", this, { url: url, params: params });
				           if (this.autoLoad.showMask) { this.body.mask(this.autoLoad.maskMsg || "Loading...", this.autoLoad.maskCls || "x-mask-loading"); }
				       },
				       autoLoadUpdate: function (el, response) {
				           if (this.autoLoad.showMask) { this.body.unmask(); }
				           this.fireEvent("update", this, { response: response });
				       },
				       autoLoadFailure: function (el, response) {
				           if (this.autoLoad.showMask) { this.body.unmask(); }
				           this.fireEvent("failure", this, { response: response });
				       },
				       show: function () {
				           Ext.Panel.superclass.show.call(this);
				           if (Ext.isIE && this.hideMode == "offsets" && this.el) { this.el.repaint(); }
				           return this;
				       }
				   }
				);

Ext.Panel.prototype.beforeDestroy=Ext.Panel.prototype.beforeDestroy.createInterceptor(function(){
				if(this.iframe){
					if(Ext.isIE){
						this.iframe.dom.src=String.format("java{0}","script:false");
						Ext.removeNode(this.iframe.dom);
					}
					this.iframe.remove();
				}
			});
Ext.Panel.prototype.initComponent=Ext.Panel.prototype.initComponent.createSequence(function(){
				this.addEvents("beforeupdate","update","failure");
				if(this.autoLoad){
					this.on("render",function(){
						var udr=this.getUpdater();
						udr.showLoadIndicator=false;
						udr.on("beforeupdate",this.autoLoadBeforeUpdate,this);
						udr.on("update",this.autoLoadUpdate,this);
						udr.on("failure",this.autoLoadFailure,this);
					},this);
					var loadConfig={delay:10,single:true},triggerEvent=this.autoLoad.triggerEvent||"render";
					loadConfig.single=!(this.autoLoad.reloadOnEvent||false);
					if(Ext.isEmpty(this.autoLoad.manuallyTriggered)||this.autoLoad.manuallyTriggered!==true){
						this.on(triggerEvent,function(){this.load(this.getAutoLoad());},
						this,loadConfig);
					}
				}
				var refreshBars=function(){
					var bar=this.getBottomToolbar();
					if(bar&&bar.el){bar.el.repaint();}
					bar=this.getTopToolbar();
					if(bar&&bar.el){bar.el.repaint();}
				};
				if(Ext.isIE){
					this.on("show",refreshBars,this,{buffer:100});
					this.on("resize",refreshBars,this,{buffer:100});
				}
			});
Ext.Panel.prototype.onCollapse=Ext.Panel.prototype.onCollapse.createSequence(function(doAnim,animArg){	var f=this.getCollapsedField();if(!Ext.isEmpty(f)){f.dom.value="true";}});
Ext.Panel.prototype.onExpand=Ext.Panel.prototype.onExpand.createSequence(function(doAnim,animArg){var f=this.getCollapsedField();if(!Ext.isEmpty(f)){f.dom.value="false";}});


Ext.override(Ext.menu.Menu, {
    lastTargetIn: function (cmp) { return Ext.fly(cmp.getEl ? cmp.getEl() : cmp).contains(this.trg); },
    createEl: function () {
        var frm = document.body; if (document.forms.length == 1) { frm = document.forms[0]; }
        return new Ext.Layer({ cls: "x-menu", shadow: this.shadow, shim: this.shim || true, constrain: false, parentEl: this.parentEl || frm, zindex: 15000 });
    }, autoWidth: function () {
        var el = this.el, ul = this.ul, w = this.width, m = this.minWidth, t; if (!el) { return; }
        if (w) { el.setWidth(w); } else if (Ext.isIE && !Ext.isIE8) { el.setWidth(this.minWidth); t = el.dom.offsetWidth; el.setWidth(ul.getWidth() + el.getFrameWidth("lr")); }
         else if (m && m > (el.getWidth() + el.getFrameWidth("lr"))) { el.setWidth(m); } 
    }
 });

Ext.MenuPanel = function (config) {
    Ext.MenuPanel.superclass.constructor.call(this, config);
    this.menu.on("itemclick", this.setSelection, this);
};
Ext.extend(Ext.MenuPanel, Ext.Panel, {
    saveSelection: true, selectedIndex: -1, fitHeight: true, initComponent: function () {
        Ext.MenuPanel.superclass.initComponent.call(this); 
        if (this.selectedIndex > -1) { this.menu.items.get(this.selectedIndex).ctCls = "x-menu-item-active"; this.getSelIndexField().setValue(this.selectedIndex); }
        this.menu.on("mouseout", this.onMenuMouseOut, this);
    },
    onMenuMouseOut: function (menu, e, t) {
        if (!this.saveSelection) { return; }
        var index = this.menu.items.indexOf(t), selIndex = this.getSelIndexField().getValue();
        if (selIndex.length > 0 && index == selIndex) { t.container.addClass("x-menu-item-active"); }
    },
    setSelectedIndex: function (index) { this.setSelection(this.menu.items.get(index)); }, getSelIndexField: function () {
        if (!this.selIndexField) { this.selIndexField = new Ext.form.Hidden({ id: this.id + "_SelIndex", name: this.id + "_SelIndex" }); }
        return this.selIndexField;
    },
    setSelection: function (item, e) {
        if (this.saveSelection) { this.menu.items.each(function (item) { item.container.removeClass("x-menu-item-active"); }, this.menu); item.container.addClass("x-menu-item-active"); }
        this.getSelIndexField().setValue(this.menu.items.indexOf(item));
    },
    afterRender: function () {
        Ext.MenuPanel.superclass.afterRender.call(this);
        var lay = this.menu.getEl();
        if (Ext.isIE) { lay.shadow = false; }
        this.body.appendChild(lay);
        lay.clearPositioning("auto");
        if (this.fitHeight) { lay.setSize("auto", "100%"); } else { lay.setWidth("auto"); }
        lay.applyStyles({ border: "0px" });
        lay.show();
        this.getSelIndexField().render(this.el.parent() || this.el);
    }
});
Ext.reg("msxiumenupanel", Ext.MenuPanel);

Ext.BLANK_IMAGE_URL = 'ExtJs/s.gif';
Ext.TriggerComboBox = Ext.extend(Ext.form.ComboBox, {
	initComponent: function () {
		Ext.TriggerComboBox.superclass.initComponent.call(this);
		this.addEvents("triggerclick");
		if (this.triggersConfig) {
			var cn = [], triggerCfg; for (var i = 0; i < this.triggersConfig.length; i++) {
				var trigger = this.triggersConfig[i];
				triggerCfg = { tag: "img", "ext:qtip": trigger.qtip || "", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger" + (trigger.triggerCls || "") + " " + (trigger.iconCls || "x-form-ellipsis-trigger") };
				if (trigger.hideTrigger) { Ext.apply(triggerCfg, { style: "display:none" }); }
				cn.push(triggerCfg);
			}
			triggerCfg = { tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger" };
			if (this.hideTrigger) { Ext.apply(triggerCfg, { style: "display:none" }); }
			cn.push(triggerCfg);
			this.triggerConfig = { tag: "span", cls: "x-form-twin-triggers", cn: cn };
		}
	},
	getTrigger: function (index) { return this.triggers[index]; },
	initTrigger: function () {
		if (!this.triggersConfig) { Ext.TriggerComboBox.superclass.initTrigger.call(this); return; }
		var ts = this.trigger.select(".x-form-trigger", true), triggerField = this; this.wrap.setStyle("overflow", "hidden");
		ts.each(function (t, all, index, length) {
			t.hide = function () { var w = triggerField.wrap.getWidth(); this.dom.style.display = "none"; triggerField.el.setWidth(w - triggerField.trigger.getWidth()); };
			t.show = function () { var w = triggerField.wrap.getWidth(); this.dom.style.display = ""; triggerField.el.setWidth(w - triggerField.trigger.getWidth()); };
			if (index == (all.getCount() - 1)) { t.on("click", this.onTriggerClick, this); }
			else { t.on("click", this.onCustomTriggerClick, this, { index: index, t: t, preventDefault: true }); }
			t.addClassOnOver("x-form-trigger-over"); t.addClassOnClick("x-form-trigger-click");
		}, this); this.triggers = ts.elements;
	},
	onCustomTriggerClick: function (evt, el, o) { if (!this.disabled) { this.fireEvent("triggerclick", this, o.t, o.index, evt); } },
	setValue: function (v) { Ext.TriggerComboBox.superclass.setValue.call(this, v); },
	listeners: {
		triggerclick: { fn: function (el, trigger, index, e) { if (index == 0) { this.clearValue(); this.triggers[0].hide(); } } },
		select: { fn: function (el, record, index) { this.triggers[0].show(); } },
		beforequery: { fn: function (queryEvent) { this.triggers[0][this.getRawValue().toString().length == 0 ? 'hide' : 'show'](); } }
	}
});


