
var f_createShadowRoot = Element.prototype.createShadowRoot;

if (!f_createShadowRoot) {
	Element.prototype.createShadowRoot = function() {
		return this.attachShadow({ mode: "open" });
	};
}

Ext.define("Ext.overrides.data.Connection", {
	override: "Ext.data.Connection",

	request: function(o_options) {

		var i_self = this;

		if (Ext.manifest.singleSession) {
			var s_session = sessionStorage.getItem("session");

			if (s_session) {
				document.cookie = s_session;
			}
			else {
				document.cookie = "sys_sesid=";
			}
		}

		if (Portfolio.hasOwnProperty("util")) {

			var i_user = Portfolio.util.Handler.getUser();

			if (i_user) {

				var s_profile = i_user.get("X-PROFILE") || i_user.get("x-profile");

				if (s_profile) {
					i_user.set("X-PROFILE", s_profile);
					i_self.setDefaultHeaders({
						"x-profile": s_profile
					});
				}
			}
		}

		var i_request = i_self.callOverridden(arguments);
		return i_request;
	},


	createResponse: function(i_request) {

		var i_self = this;
		var i_response = i_self.callOverridden(arguments);

		if (Ext.manifest.singleSession) {
			var s_session = sessionStorage.getItem("session");

			if (!s_session) {
				s_session = document.cookie;
				sessionStorage.setItem("session", s_session);
			}
		}

		if (i_response.getResponseHeader("x-anonymous")) {
			Ext.GlobalEvents.fireEvent("logout");
		}

		i_self.callOverridden(arguments);
	}
});


// Ext.define("Ext.overrides.Component", {
// 	override: "Ext.Component",

// 	onRender: function() {
// 		this.callOverridden(arguments);
// 		if (this.callouts) {
// 			var callouts = this.callouts;
// 			var callout;
// 			var i;
// 			delete this.callouts;
// 			for (i = 0; i < callouts.length; i++) {
// 				callout = callouts[i];
// 				callout.target = this;
// 				Ext.create("Ext.ux.Callout", callout);
// 			}
// 		}
// 	},

// 	destroy: function() {
// 		this.destroyCallouts();
// 		this.callOverridden(arguments);
// 	},

// 	destroyCallouts: function() {
// 		if (this.callouts) {
// 			for (i = 0; i < this.callouts.length; i++) {
// 				var callout = this.callouts[i];
// 				if (!callout.destroyed) {
// 					callout.destroyFromCmp = true;
// 					callout.destroy();
// 				}
// 			}
// 			delete this.callouts;
// 		}
// 	}
// });

Ext.define("Ext.overrides.Editor", {
	override: "Ext.Editor",
	compatibility: [
		"5.1.0",
		"6.6.0"
	],
	startEdit: function(i_elment, value) {

		var i_editor = this;
		var i_field = i_editor.field;
		var i_context = i_editor.context;
		var dom;
		var ownerCt;
		var renderTo;
		var fieldValue = value;

		i_editor.completeEdit();
		i_editor.boundEl = Ext.get(i_elment);
		dom = i_editor.boundEl.dom;
		value = Ext.isDefined(value) ? value : Ext.String.trim(dom.textContent || dom.innerText || "");

		if (i_editor.fireEvent("beforestartedit", i_editor, i_editor.boundEl, value) !== false) {

			Ext.suspendLayouts();
			if (!i_editor.rendered) {
				ownerCt = i_editor.ownerCt;
				renderTo = i_editor.renderTo || (ownerCt && ownerCt.getEl()) || Ext.getBody();
				Ext.fly(renderTo).position();
				i_editor.renderTo = renderTo;
			}

			if (i_context) {
				var i_record = i_context.record;
				if (i_record) {
					if (i_field.map2) {
						fieldValue = i_record.get(i_field.map2) || value;
					}
				}
			}

			i_editor.startValue = value;
			i_editor.show();
			i_editor.realign(true);

			i_field.suspendEvents();
			i_field.setValue(fieldValue);
			i_field.resetOriginalValue();
			i_field.resumeEvents();
			i_field.focus(i_field.selectOnFocus ? true : [
				Number.MAX_VALUE
			]);
			if (i_field.autoSize) {
				i_field.autoSize();
			}
			Ext.resumeLayouts(true);
			i_editor.toggleBoundEl(false);
			i_editor.editing = true;
		}
	},

	onHide: function (animateTarget, callback, scope) {
		var me = this,
			ghostPanel, fromSize, toBox;
		if (!me.ariaStaticRoles[me.ariaRole] && !me.destroying && !me.destroyed) {
			me.ariaEl.dom.setAttribute("aria-hidden", true);
		}
		// Part of the Focusable mixin API.
		// If we have focus now, move focus back to whatever had it before.
		me.revertFocus();
		// Default to configured animate target if none passed
		animateTarget = me.getAnimateTarget(animateTarget);
		// Need to be able to ghost the Component
		if (!me.ghost) {
			animateTarget = null;
		}
		// If we"re animating, kick off an animation of the ghost down to the target
		if (animateTarget) {
			toBox = {
				x: animateTarget.getX(),
				y: animateTarget.getY(),
				width: animateTarget.dom.offsetWidth,
				height: animateTarget.dom.offsetHeight
			};
			ghostPanel = me.ghost();
			ghostPanel.el.stopAnimation();
			fromSize = me.getSize();
			ghostPanel.el.animate({
				to: toBox,
				listeners: {
					afteranimate: function () {
						if (!me.destroying) {
							ghostPanel.componentLayout.lastComponentSize = null;
							me.unghost(false);
							ghostPanel.el.setSize(fromSize);
							me.afterHide(callback, scope);
						}
					}
				}
			});
		} else {
			if (!me.destroyed) {
				me.el.hide();
			}
		}
		if (!animateTarget) {
			me.afterHide(callback, scope);
		}
	}
});

Ext.define("Ext.overrides.form.field.Base", {

	override: "Ext.form.field.Base",
	iconCls: "",

	onRender: function() {
		var i_self = this;
		var a_excludedTypes = ["checkbox", "radio", "slider"];
		i_self.callParent(arguments);
		if (i_self.inputEl && a_excludedTypes.indexOf(i_self.inputType) == -1 && i_self.iconCls) {
			i_self.inputEl.addCls(i_self.iconCls + " x-ux-icon-bg");
		}
	},

	setIconCls: function(cls) {
		var a_excludedTypes = ["checkbox", "radio", "slider"];
		var i_self = this;
		if (i_self.inputEl && a_excludedTypes.indexOf(i_self.inputType) == -1) {
			var oldCls = i_self.iconCls || "";
			if (cls == "") {
				i_self.inputEl.removeCls("x-ux-icon-bg " + oldCls);
				i_self.iconCls = cls;
			}
			else {
				i_self.iconCls = cls;
				i_self.inputEl.removeCls("x-ux-icon-bg " + oldCls);
				i_self.inputEl.addCls("x-ux-icon-bg " + cls);
			}
			i_self.fireEvent("iconchange", i_self, oldCls, cls);
		}
		else {
			i_self.iconCls = cls;
		}
	},

	getIconCls: function() {
		var i_self = this;
		return i_self.iconCls || "";
	}
});

Ext.define("Ext.overrides.form.field.Number2", {

	override: "Ext.form.field.Number",

	decimalPrecision: 0,

	valueToRaw: function (value) {

		var i_self = this;
		var decimalSeparator = i_self.decimalSeparator;
		var n_precision = i_self.decimalPrecision;

		value = i_self.parseValue(value);
		value = i_self.fixPrecision(value);
		value = Ext.isNumber(value) ? value : parseFloat(String(value).replace(decimalSeparator, "."));
		if (!isNaN(value)) {
			if (!Ext.isEmpty(value)) {
				value = parseFloat(String(isNaN(value) ? 0 : value)).toFixed(n_precision);
				value = String(value).replace(".", decimalSeparator);
			}
			else {
				value = null;
			}
		}
		else {
			value = null;
		}
		return value;
	}
});

Ext.define("Ext.overrides.form.field.Text", {
	override: "Ext.form.field.Text",

	invokeTriggers: function(s_methode, args) {

		var i_self = this;
		i_self.callOverridden(arguments);

		var o_triggers = i_self.getTriggers();

		Ext.Object.each(o_triggers, function(s_key, i_trigger) {
			if (i_trigger && i_trigger.tooltip) {
				var i_element = i_trigger.getEl();
				if (i_element) {
					i_element.dom.setAttribute("data-qtip", i_trigger.tooltip);
				}
			}
		});
	},

	setReadOnly: function(b_readOnly) {

		var i_self = this;
		var o_triggers = i_self.getTriggers();
		var b_hideTriggers = i_self.getHideTrigger();
		var b_readOnly = !!b_readOnly;

		i_self.callSuper([
			b_readOnly
		]);

		if (i_self.rendered) {
			i_self.setReadOnlyAttr(b_readOnly || !i_self.editable);
		}

		if (o_triggers) {

			Ext.Object.each(o_triggers, function(s_key, i_trigger) {
				if (i_trigger.hideOnReadOnly === true || (i_trigger.hideOnReadOnly !== false && !b_hideTriggers)) {
					i_trigger.setVisible(!b_readOnly);
				}
			});
		}
	},

	disable: function() {

		var i_self = this;
		i_self.callParent(arguments);

		if (i_self.isDisabled()) {
			if (i_self.rendered) {
				i_self.setReadOnly(true);
			}
			else {
				i_self.on({
					afterrender: {
						fn: function(item) {
							if (i_self.isDisabled()) {
								i_self.setReadOnly(true);
							}
						},
						single: true
					}
				});
			}
		}
		return i_self;
	},

	enable: function() {

		var i_self = this;
		i_self.callParent(arguments);
		if (!i_self.isDisabled()) {
			if (i_self.rendered) {
				i_self.setReadOnly(false);
			}
			else {
				i_self.on({
					afterrender: {
						fn: function(item) {
							if (i_self.isDisabled()) {
								i_self.setReadOnly(false);
							}
						},
						single: true
					}
				});
			}
		}
		return i_self;
	}
});

Ext.define("Ext.overrides.form.field.ComboBox", {

	override: "Ext.form.field.ComboBox",

	constructor: function(o_config) {

		var i_self = this;

		if (o_config.multiSelect) {
			o_config.typeAhead = false;
		}
		else if (o_config.typeAhead) {
			o_config.multiSelect = false;
		}

		i_self.callOverridden([o_config]);

		var i_picker = i_self.getPicker();

		i_picker.on({
			resize: {
				fn: function () {

					var i_self = this;
					var i_toolbar = i_self.pagingToolbar;

					if (i_self.rendered && i_toolbar && i_toolbar.rendered) {

						if (i_self.getStore().getTotalCount() <= i_self.pageSize) {
							i_self.el.last().setHeight(0);
							i_self.pagingToolbar.setHeight(0);
							i_self.pagingToolbar.el.dom.style.setProperty("display", "none");

						}
						else {
							i_self.pagingToolbar.el.dom.style.setProperty("display", "");
							i_toolbar.setSize(null, null);
							i_self.el.last().setHeight(null);

						}
					}
				}
			}
		});
	},

	onFocusLeave: function(e) {

		var i_self = this;
		var i_picker = i_self.getPicker();

		var i_event = e.within ? e : e.event;

		if (!i_event.within(i_self.el) && !i_event.within(i_picker.el)) {

			i_self.collapse();

			i_self.callParent([
				e
			]);
		}
		else {
			i_self.focus();
		}
	},

	collapseIf: function(e) {

		var i_self = this;
		var i_picker = i_self.getPicker();

		var i_event = e.within ? e : e.event;

		if (!i_self.isDestroyed && !i_event.within(i_self.getEl()) && !i_event.within(i_picker.getEl())) {
			i_self.collapse();
		}
	},

	getDisplayValue: function () {

		var i_self = this;
		if (i_self.displayTpl) {
			var s_value = i_self.callOverridden(arguments);
			if (s_value) {
				s_value = ip2.i18n(s_value);
			}
			if (s_value === "0" && i_self.value === null) {
				s_value = "";
			}
			return s_value;
		}
	},

	getSubTplData: function(fieldData) {

		var me = this;
		var value = me.getRawValue();
		var isEmpty = me.emptyText && value.length < 1;
		var maxLength = me.maxLength;
		var placeholder;

		if (me.enforceMaxLength) {
			if (maxLength === Number.MAX_VALUE) {
				maxLength = undefined;
			}
		}
		else {
			maxLength = undefined;
		}
		if (isEmpty) {
			if (Ext.supports.Placeholder) {
				placeholder = me.emptyText;
			}
			else {
				value = me.emptyText;
				me.valueContainsPlaceholder = true;
			}
		}
		var o_data = me.callParent(arguments);
		if (navigator.userAgent.indexOf("Epiphany") > -1) {
			o_data.role = "textbox";
		}
		return Ext.apply(o_data, {
			triggerWrapCls: me.triggerWrapCls,
			inputWrapCls: me.inputWrapCls,
			triggers: me.orderedTriggers,
			maxLength: maxLength,
			readOnly: !me.editable || me.readOnly,
			placeholder: placeholder,
			value: value,
			fieldCls: me.fieldCls + ((isEmpty && (placeholder || value)) ? " " + me.emptyUICls : "") + (me.allowBlank ? "" : " " + me.requiredCls)
		});
	}

});

Ext.define("Ext.overrides.data.Model", {
	override: "Ext.data.Model",

	constructor: function(data, session) {
		var me = this;
		var cls = me.self;
		var identifier = cls.identifier;
		var Model = Ext.data.Model;
		var modelIdentifier = Model.identifier;
		var idProperty = me.idField.name;
		var array;
		var id;
		var initializeFn;
		var internalId;
		var len;
		var i;
		var fields;
		me.data = data || (data = {});
		me.session = session || null;
		me.internalId = internalId = modelIdentifier.generate();
		var dataId = data[idProperty];
		if (session && !session.isSession) {
			Ext.Error.raise("Bad Model constructor argument 2 - \"session\" is not a Session");
		}
		if ((array = data) instanceof Array) {
			me.data = data = {};
			fields = me.getFields();
			len = Math.min(fields.length, array.length);
			for (i = 0; i < len; ++i) {
				data[fields[i].name] = array[i];
			}
		}
		if (!(initializeFn = cls.initializeFn)) {
			cls.initializeFn = initializeFn = Model.makeInitializeFn(cls);
		}
		if (!initializeFn.$nullFn) {
			cls.initializeFn(me);
		}
		if (!(me.id = id = data[idProperty]) && id !== 0) {
			if (dataId) {
				Ext.Error.raise("The model ID configured in data (\"" + dataId + "\") has been rejected by the " +
					me.fieldsMap[idProperty].type + " field converter for the " + idProperty + " field");
			}
			if (session) {
				identifier = session.getIdentifier(cls);
				id = identifier.generate();
			}
			else if (modelIdentifier === identifier) {
				id = internalId;
			}
			else {
				id = identifier.generate();
			}
			me.id = id;
			me.phantom = true;
		}
		if (session) {
			session.add(me);
		}
		if (me.init && Ext.isFunction(me.init)) {
			me.init();
		}
	}
});

Ext.define("Ext.overrides.data.BufferedStore", {
	override: "Ext.data.BufferedStore",

	compatibility: [
		"5.1.0",
		"5.1.1",
		"6.6.0"
	],

	reload: function(options) {
		var me = this;
		var startIdx;
		var endIdx;
		var startPage;
		var endPage;
		var i;
		var waitForReload;
		var bufferZone;
		var records;
		var data = me.getData();

		if (me.loading) {
			return;
		}
		if (!options) {
			options = {};
		}

		delete me.totalCount;

		data.clear(true);
		waitForReload = function() {
			if (me.rangeCached(startIdx, Math.min(endIdx, me.getTotalCount()))) {
				me.loading = false;
				data.un("pageadd", waitForReload);
				records = data.getRange(startIdx, startIdx + 1);
				me.fireEvent("load", me, records, true);
				me.fireEvent("refresh", me);
			}
		};
		bufferZone = Math.ceil((me.getLeadingBufferZone() + me.getTrailingBufferZone()) / 2);

		if (!me.lastRequestStart) {
			startIdx = options.start || 0;
			endIdx = startIdx + (options.count || me.getPageSize()) - 1;
		}
		else {
			startIdx = me.lastRequestStart;
			endIdx = me.lastRequestEnd;
		}

		startIdx = Math.max(startIdx - bufferZone, 0);
		endIdx += bufferZone;
		startPage = me.getPageFromRecordIndex(startIdx);
		endPage = me.getPageFromRecordIndex(endIdx);
		if (me.fireEvent("beforeload", me, options) !== false) {
			me.loading = true;

			data.on("pageadd", waitForReload);

			for (i = startPage; i <= endPage; i++) {
				me.prefetchPage(i, options);
			}
		}
	},

	onRangeAvailable: function(options) {
		var me = this;
		var totalCount = me.getTotalCount();
		var start = options.prefetchStart;
		var end = (options.prefetchEnd > totalCount - 1) ? totalCount - 1 : options.prefetchEnd;
		var range;
		end = Math.max(-1, end);
		if (start > end && end > 0) {
			Ext.log({
				level: "warn",
				msg: "Start (" + start + ") was greater than end (" + end + ") for the range of records requested (" + start + "-" + options.prefetchEnd + ")" +
				(this.storeId ? " from store \"" + this.storeId + "\"" : "")
			});
		}
		range = me.getData().getRange(start, end + 1);
		if (options.fireEvent !== false) {
			me.fireEvent("guaranteedrange", range, start, end, options);
		}
		if (options.callback) {
			options.callback.call(options.scope || me, range, start, end, options);
		}
	},

	loadToPrefetch: function(options) {

		var me = this;
		var prefetchOptions = options;
		var purgePageCount = me.getPurgePageCount();
		var i;
		var records;
		var dataSetSize;
		var startIdx = options.start;
		var endIdx = options.start + options.limit - 1;
		var loadEndIdx = Math.min(endIdx, options.start + (me.getViewSize() || options.limit) - 1);
		var startPage = me.getPageFromRecordIndex(Math.max(startIdx - me.getTrailingBufferZone(), 0));
		var endPage = me.getPageFromRecordIndex(endIdx + me.getLeadingBufferZone());
		var data = me.getData();

		var callbackFn = function () {
			// See comments in load() for why we need this.
			records = records || [];
			if (options.loadCallback) {
				options.loadCallback.call(options.scope || me, records, operation, true);
			}
			if (options.callback) {
				options.callback.call(options.scope || me, records, startIdx || 0, endIdx || 0, options);
			}
		};

		var fireEventsFn = function () {
			me.loadCount = (me.loadCount || 0) + 1;
			me.fireEvent("datachanged", me);
			me.fireEvent("refresh", me);
			me.fireEvent("load", me, records, true);
		};

		var waitForRequestedRange = function() {
			if (me.rangeCached(startIdx, loadEndIdx)) {
				me.loading = false;
				records = data.getRange(startIdx, loadEndIdx + 1);
				data.un("pageadd", waitForRequestedRange);

				if (me.hasListeners.guaranteedrange) {
					me.guaranteeRange(startIdx, loadEndIdx, options.callback, options.scope);
				}

				if (options.loadCallback) {
					options.loadCallback.call(options.scope || me, records, operation, true);
				}
				if (options.callback) {
					options.callback.call(options.scope || me, records, startIdx, endIdx, options);
				}
				me.fireEvent("datachanged", me);
				me.fireEvent("refresh", me);
				me.fireEvent("load", me, records, true);
			}
		};

		var operation;

		if (isNaN(me.pageSize) || !me.pageSize) {
			Ext.Error.raise("Buffered store configured without a pageSize", me);
		}

		if (purgePageCount) {
			data.setMaxSize(purgePageCount ? (endPage - startPage + 1) + purgePageCount : 0);
		}
		if (me.fireEvent("beforeload", me, options) !== false) {

			delete me.totalCount;
			me.loading = true;

			if (options.callback) {
				prefetchOptions = Ext.apply({}, options);
				delete prefetchOptions.callback;
			}

			me.on("prefetch", function(store, records, successful, op) {
				if (successful) {

					operation = op;

					if ((dataSetSize = me.getTotalCount())) {

						data.on("pageadd", waitForRequestedRange);

						loadEndIdx = Math.min(loadEndIdx, dataSetSize - 1);

						endPage = me.getPageFromRecordIndex(Math.min(loadEndIdx + me.getLeadingBufferZone(), dataSetSize - 1));
						if (startPage + 1 <= endPage) {
							for (i = startPage + 1; i <= endPage; ++i) {
								me.prefetchPage(i, prefetchOptions);
							}
						}
					}
					else {
						callbackFn();
						fireEventsFn();
					}
				}
				else {
					me.loading = false;
					callbackFn();
					me.fireEvent("load", me, records, false);
				}
			}, null, {
				single: true
			});
			me.prefetchPage(startPage, prefetchOptions);
		}
	},

	onSorterEndUpdate: function() {
		var i_self = this;
		var i_sorter = i_self.getSorters();
		var a_sorters = i_sorter.getRange();

		if (a_sorters.length) {
			i_self.fireEvent("beforesort", i_self, a_sorters);
			i_self.clearAndLoad({
				callback: function() {
					i_self.fireEvent("sort", i_self, a_sorters);
				}
			});
		}
		else {
			i_self.fireEvent("sort", i_self, a_sorters);
		}
	},

	getUpdatedRecords: function() {

		var i_self = this;

		var a_range = i_self.getData().getPage(i_self.currentPage);

		var a_filtered = Ext.Array.filter(a_range, function(i_record) {
			return i_record.dirty;
		});

		return a_filtered;
	},

	contains: function(i_record) {

		var i_self = this;
		var i_found = i_self.getById(i_record.get(i_record.idProperty));

		return i_found ? true : false;
	},

	getRange: function (start, end, options) {

		var me = this;
		var maxIndex = me.totalCount - 1;
		var lastRequestStart = me.lastRequestStart;
		var result = [];
		var data = me.getData();
		var pageAddHandler;
		var requiredStart;
		var requiredEnd;
		var requiredStartPage;
		var requiredEndPage;

		start = start || 0;

		if (end)  {
			if (end > me.totalCount) {
				end = maxIndex;
			}
		}
		else {
			if (maxIndex === 0) {
				end = maxIndex;
			}
			else {
				end = Math.floor((this.getPageSize() + me.getLeadingBufferZone()) / this.getPageSize()) + 1;
			}
		}

        options = Ext.apply({
            prefetchStart: start,
            prefetchEnd: end
		}, options);




		requiredStart = start === 0 ? 0 : start - 1;
		requiredEnd = end === maxIndex ? end : end + 1;

		me.lastRequestStart = start;
		me.lastRequestEnd = end;

		if (me.rangeCached(requiredStart, requiredEnd)) {
			me.onRangeAvailable(options);
			result = data.getRange(start, end + 1);
		}
		else {

			me.fireEvent("cachemiss", me, start, end);
			requiredStartPage = me.getPageFromRecordIndex(requiredStart);
			requiredEndPage = me.getPageFromRecordIndex(requiredEnd);

			pageAddHandler = function (pageMap, page, records) {
				if (page >= requiredStartPage && page <= requiredEndPage && me.rangeCached(requiredStart, requiredEnd)) {

					me.fireEvent("cachefilled", me, start, end);
					data.un("pageadd", pageAddHandler);
					me.onRangeAvailable(options);
				}
			};
			data.on("pageadd", pageAddHandler);



			me.prefetchRange(start, end);
		}

		me.primeCache(start, end, start < lastRequestStart ? -1 : 1);
		return result;
	}
});

Ext.define("Ext.overrides.data.PageMap", {
	override: "Ext.data.PageMap",

	compatibility: [
		"5.1.0",
		"5.1.1",
		"6.6.0"
	],

	hasRange: function (start, end) {

		start = isNaN(start) ? 1 : start;
		end = isNaN(end) ? 1 : end;

		var me = this,
			pageNumber = me.getPageFromRecordIndex(start) || 1,
			endPageNumber = me.getPageFromRecordIndex(end) || 1;
		for (; pageNumber <= endPageNumber; pageNumber++) {
			if (!me.hasPage(pageNumber)) {
				return false;
			}
		}

		endPageNumber = isNaN(endPageNumber) ? 1 : endPageNumber;

		var a_result = me.getPage(endPageNumber) || [];

		// Check that the last page is filled enough to encapsulate the range.
		return (endPageNumber - 1) * me._pageSize + a_result.length > end;
	},

	getRange: function(start, end) {

		end--;

		var me = this;
		var pageSize = me.getPageSize();
		var startPageNumber = me.getPageFromRecordIndex(start);
		var endPageNumber = me.getPageFromRecordIndex(end);
		var dataStart = (startPageNumber - 1) * pageSize;
		var dataEnd = (endPageNumber * pageSize) - 1;
		var pageNumber = startPageNumber;
		var result = [];
		var sliceBegin;
		var sliceEnd;
		var doSlice;

		for (; pageNumber <= endPageNumber; pageNumber++) {

			if (pageNumber === startPageNumber) {
				sliceBegin = start - dataStart;
				doSlice = true;
			}
			else {
				sliceBegin = 0;
				doSlice = false;
			}
			if (pageNumber === endPageNumber) {
				sliceEnd = pageSize - (dataEnd - end);
				doSlice = true;
			}

			if (doSlice) {
				var a_values = me.getPage(pageNumber) || [];
				if (a_values.length > 0) {
					var a_sliced = me.getPage(pageNumber).slice(sliceBegin, sliceEnd);
					result = result.concat(a_sliced);
				}
				else {
					result = a_values;
				}
			}
			else {
				var a_values = me.getPage(pageNumber) || [];
				result = a_values;
			}
		}
		return result;
	}
});

Ext.define("Ext.overrides.grid.property.Reader", {
	override: "Ext.grid.property.Reader",

	isEditableValue: function(val) {
		var i_self = this;
		var b_valid = i_self.callOverridden(arguments);
		if (!b_valid) {
			if (Ext.isObject(val)) {
				b_valid = true;
			}
			if (Ext.isArray(val)) {
				b_valid = true;
			}
			if (Ext.isEmpty(val)) {
				b_valid = true;
			}
		}
		return b_valid;
	}
});

Ext.define("Ext.overrides.data.ProxyStore", {
	override: "Ext.data.ProxyStore",

	getRemovedRecords: function() {
		return this.removed || [];
	}

});

Ext.define("Ext.overrides.window.Window", {
	override: "Ext.window.Window",

	constrain: true,

	afterRender: function(i_window) {

		var i_self = this;
		i_self.callOverridden(arguments);

		if (Ext.browser.is.IE) {

			var i_elment = i_self.getEl();

			Ext.DomHelper.append(i_elment, {
				tag: "iframe",
				src: "about:blank",
				style: {
					border: "none",
					left: "0px",
					top: "0px",
					width: "100%",
					height: "100%",
					position: "absolute",
					"z-index": -1
				}
			});
		}

		var i_header = i_self.getHeader();

		if (i_header) {

			var a_tools = i_header.query("tool");

			Ext.Array.each(a_tools, function (i_tool) {

				if (i_tool.type) {

					switch (i_tool.type) {
						case "minimize":
							i_tool.el.dom.setAttribute("data-qtip", "Minimize window");
							break;
						case "maximize":

							i_tool.el.dom.setAttribute("data-qtip", "Maximize window");

							i_self.on({
								restore: {
									fn: function (i_window) {
										i_tool.el.dom.setAttribute("data-qtip", "Maximize window");
									}
								},
								maximize: {
									fn: function (i_window) {
										i_tool.el.dom.setAttribute("data-qtip", "Restore window");
									}
								}
							});
							break;
						default:
							break;
					}
				}
			});
		}
	}
});

Ext.define("Ext.overrides.Component", {
	override: "Ext.Component",
	onHide: function (animateTarget, callback, scope) {
		var me = this,
			ghostPanel, fromSize, toBox;
		if (!me.ariaStaticRoles[me.ariaRole] && !me.destroying && !me.destroyed) {
			me.ariaEl.dom.setAttribute("aria-hidden", true);
		}
		// Part of the Focusable mixin API.
		// If we have focus now, move focus back to whatever had it before.
		me.revertFocus();
		// Default to configured animate target if none passed
		animateTarget = me.getAnimateTarget(animateTarget);
		// Need to be able to ghost the Component
		if (!me.ghost) {
			animateTarget = null;
		}
		// If we"re animating, kick off an animation of the ghost down to the target
		if (animateTarget) {
			toBox = {
				x: animateTarget.getX(),
				y: animateTarget.getY(),
				width: animateTarget.dom.offsetWidth,
				height: animateTarget.dom.offsetHeight
			};
			ghostPanel = me.ghost();
			ghostPanel.el.stopAnimation();
			fromSize = me.getSize();
			ghostPanel.el.animate({
				to: toBox,
				listeners: {
					afteranimate: function () {
						if (!me.destroying) {
							ghostPanel.componentLayout.lastComponentSize = null;
							me.unghost(false);
							ghostPanel.el.setSize(fromSize);
							me.afterHide(callback, scope);
						}
					}
				}
			});
		} else {
			if (!me.el.destroyed) {
				me.el.hide();
			}
		}
		if (!animateTarget) {
			me.afterHide(callback, scope);
		}
	},
	privates: {
		attachChildEls: function (el, owner) {
			var me = this,
				childEls = me.getChildEls(),
				comp = me || owner,

				baseId = comp.id + '-',
				unframed = !comp.frame,
				childName, elements, entry, k, selector, value, id;
			for (childName in childEls) {

				entry = childEls[childName];
				if (unframed && entry.frame) {

					continue;
				}
				selector = entry.select;
				if (selector) {
					value = el.select(selector, true);
				}

				else if (!(selector = entry.selectNode)) {
					if (!(id = entry.id)) {



						id = baseId + entry.itemId;
						value = Ext.cache[id];
						if (!value && me.data && me.data.id) {
							id = me.data.id + "-" + entry.itemId;
							value = Ext.cache[id];
						}
					} else {

						value = Ext.cache[id] || el.getById(id);
					}
				} else {
					value = el.selectNode(selector, false);
				}
				if (value) {
					if (value.isElement) {
						value.component = comp;
					} else if (value.isComposite && !value.isLite) {
						elements = value.elements;
						for (k = elements.length; k--;) {
							elements[k].component = comp;
						}
					}
				}
				me[childName] = value || null;
			}
		}
	}
});

Ext.define("Ext.override.dom.Element", {

	override: "Ext.dom.Element",

	compatibility: "6.6.0",

	setZIndex: function (zindex) {

		var me = this;
		if (!me.destroyed) {
			if (me.shadow) {
				me.shadow.setZIndex(zindex);
			}
			if (me.shim) {
				me.shim.setZIndex(zindex);
			}
			return me.setStyle("z-index", zindex);
		}
	}
});

Ext.define("Ext.override.feature.GroupStore", {

	override: "Ext.grid.feature.GroupStore",

	compatibility: [
		"6.6.0",
	],

	processStore: function (store) {
		var me = this,
			groupingFeature = me.groupingFeature,
			collapseAll = groupingFeature.startCollapsed,
			data = me.data,
			groups = store.getGroups(),
			groupCount = groups ? groups.length : 0,
			groupField = store.getGroupField(),
			metaGroup, i, featureGrouper, group, key;
		if (data) {
			data.clear();
		} else {
			data = me.data = new Ext.util.Collection({
				rootProperty: "data",
				extraKeys: {
					byInternalId: {
						property: "internalId",
						rootProperty: ""
					}
				}
			});
		}
		if (store.getCount()) {

			if (groupCount > 0) {

				// Upon first process of a loaded store, clear the "always" collapse" flag
				groupingFeature.startCollapsed = false;

				if (!groupingFeature.hasOwnProperty("originalState")) {
					groupingFeature.originalState = collapseAll;
				}
				else {
					collapseAll = groupingFeature.originalState;
				}

				for (i = 0; i < groupCount; i++) {
					group = groups.getAt(i);
					// Cache group information by group name.
					key = group.getGroupKey();
					// If there is no store grouper and the groupField looks up a complex data type, the store will stringify it and
					// the group name will be '[object Object]'. To fix this, groupers can be defined in the feature config, so we'll
					// simply do a lookup here and re-group the store.
					//
					// Note that if a grouper wasn't defined on the feature that we'll just default to the old behavior and still try
					// to group.
					if (me.badGrouperKey === key && (featureGrouper = groupingFeature.getGrouper(groupField))) {
						// We must reset the value b/c store.group() will call into this method again!
						store.getGroups().remove(group);
						groupingFeature.startCollapsed = groupingFeature.originalState;
						store.group(featureGrouper);
						return;
					}
					metaGroup = groupingFeature.getMetaGroup(group);
					// This is only set at initialization time to handle startCollapsed
					if (!metaGroup.hasOwnProperty("isInitialized")) {
						metaGroup.isCollapsed = collapseAll;
						metaGroup.isInitialized = true;
					}
					// Collapsed group - add the group's placeholder.
					if (metaGroup.isCollapsed) {
						data.add(metaGroup.placeholder);
					} else // Expanded group - add the group's child records.
					{
						data.insert(me.data.length, group.items);
					}
				}

			} else {
				data.add(store.getRange());
			}
		}
	}
});

Ext.define("Ext.override.grid.plugin.Clipboard", {

	override: "Ext.grid.plugin.Clipboard",

	compatibility: [
		"6.6.0"
	],

	putCellData: function (data, format) {
		// We pass null as field quote here to override default TSV decoding behavior
		// that will try to unquote fields and break if double quote character is
		// encountered in the data. TSV format does not support any kind of field quoting
		// but Ext.util.TSV mistakenly assumed otherwise pre-6.5.3
		var values = Ext.util.TSV.decode(data, undefined, null),
			row,
			recCount = values.length,
			colCount = recCount ? values[0].length : 0,
			sourceRowIdx, sourceColIdx,
			view = this.getCmp().getView(),
			maxRowIdx = view.dataSource.getCount() - 1,
			maxColIdx = view.getVisibleColumnManager().getColumns().length - 1,
			selModel = view.getSelectionModel(),
			selected = selModel.getSelected(),
			navModel = view.getNavigationModel(),
			destination = selected.startCell || navModel.getPosition(),
			dataIndex, destinationStartColumn,
			dataObject = {};
		// If the view is not focused, use the first cell of the selection as the destination.
		if (!destination && selected) {
			selected.eachCell(function (c) {
				destination = c;
				return false;
			});
		}
		if (destination) {
			// Create a new Context based upon the outermost View.
			// NavigationModel works on local views. TODO: remove this step when NavModel is fixed to use outermost view in locked grid.
			// At that point, we can use navModel.getPosition()
			destination = new Ext.grid.CellContext(view).setPosition(destination.record, destination.column);
		} else {
			destination = new Ext.grid.CellContext(view).setPosition(0, 0);
		}
		destinationStartColumn = destination.colIdx;
		for (sourceRowIdx = 0; sourceRowIdx < recCount; sourceRowIdx++) {
			row = values[sourceRowIdx];
			// Collect new values in dataObject
			for (sourceColIdx = 0; sourceColIdx < colCount; sourceColIdx++) {
				dataIndex = destination.column.dataIndex;
				if (dataIndex) {
					switch (format) {
						// Raw field values
						case 'raw':
							dataObject[dataIndex] = row[sourceColIdx];
							break;
						// Textual data with HTML tags stripped
						case 'text':
							dataObject[dataIndex] = row[sourceColIdx];
							break;
						// innerHTML from the cell inner
						case 'html':
							break;
					}
				}
				// If we are at the end of the destination row, break the column loop.
				if (destination.colIdx === maxColIdx) {
					break;
				}
				destination.setColumn(destination.colIdx + 1);
			}
			// Update the record in one go.
			destination.record.set(dataObject);
			// If we are at the end of the destination store, break the row loop.
			if (destination.rowIdx === maxRowIdx) {
				break;
			}
			// Jump to next row in destination
			destination.setPosition(destination.rowIdx + 1, destinationStartColumn);
		}

		view.refresh();
	}
});

Ext.define("Ext.overrides.legend.SpriteLegend", {

	override: "Ext.chart.legend.SpriteLegend",

	compatibility: [
		"6.6.0"
	],

	// WE NEED THIS SINCE EXTJS QUERYSELECTOR CAN GET THE OBJECT
	isXType: function() {
		return false;
	}
});
